usr/src/cmd/ztest/ztest.c
author Christopher Siden <chris.siden@delphix.com>
Mon, 21 May 2012 12:11:39 -0700
changeset 13700 2889e2596bd6
parent 13571 a5771a96228c
child 13743 95aba6e49b9f
permissions -rw-r--r--
2619 asynchronous destruction of ZFS file systems 2747 SPA versioning with zfs feature flags Reviewed by: Matt Ahrens <[email protected]> Reviewed by: George Wilson <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Dan Kruchinin <[email protected]> Approved by: Eric Schrock <[email protected]>
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
/*
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    23
 * Copyright (c) 2012 by Delphix. All rights reserved.
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
    24
 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
 * The objective of this program is to provide a DMU/ZAP/SPA stress test
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
 * that runs entirely in userland, is easy to use, and easy to extend.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
 * The overall design of the ztest program is as follows:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
 * (1) For each major functional area (e.g. adding vdevs to a pool,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
 *     creating and destroying datasets, reading and writing objects, etc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
 *     we have a simple routine to test that functionality.  These
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 *     individual routines do not have to do anything "stressful".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 * (2) We turn these simple functionality tests into a stress test by
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
 *     running them all in parallel, with as many threads as desired,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 *     and spread across as many datasets, objects, and vdevs as desired.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * (3) While all this is happening, we inject faults into the pool to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 *     verify that self-healing data really works.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 * (4) Every time we open a dataset, we change its checksum and compression
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
 *     functions.  Thus even individual objects vary from block to block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
 *     in which checksum they use and whether they're compressed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
 * (5) To verify that we never lose on-disk consistency after a crash,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
 *     we run the entire test in a child of the main process.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 *     At random times, the child self-immolates with a SIGKILL.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 *     This is the software equivalent of pulling the power cord.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 *     The parent then runs the test again, using the existing
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    54
 *     storage pool, as many times as desired. If backwards compatability
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    55
 *     testing is enabled ztest will sometimes run the "older" version
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    56
 *     of ztest after a SIGKILL.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 * (6) To verify that we don't have future leaks or temporal incursions,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 *     many of the functional tests record the transaction group number
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 *     as part of their data.  When reading old data, they verify that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 *     the transaction group number is less than the current, open txg.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 *     If you add a new test, please do this if applicable.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
 * When run with no arguments, ztest runs for about five minutes and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
 * produces no output if successful.  To get a little bit of information,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
 * specify -V.  To get more information, specify -VV, and so on.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
 * To turn this into an overnight stress test, use -T to specify run time.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
 * You can ask more more vdevs [-v], datasets [-d], or threads [-t]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
 * to increase the pool capacity, fanout, and overall stress level.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
 *
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    73
 * Use the -k option to set the desired frequency of kills.
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    74
 *
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    75
 * When ztest invokes itself it passes all relevant information through a
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    76
 * temporary file which is mmap-ed in the child process. This allows shared
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    77
 * memory to survive the exec syscall. The ztest_shared_hdr_t struct is always
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    78
 * stored at offset 0 of this file and contains information on the size and
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    79
 * number of shared structures in the file. The information stored in this file
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    80
 * must remain backwards compatible with older versions of ztest so that
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
    81
 * ztest can invoke them during backwards compatibility testing (-B).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
#include <sys/txg.h>
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
    88
#include <sys/dbuf.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
#include <sys/poll.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
#include <sys/time.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
#include <sys/wait.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
#include <sys/mman.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
#include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
#include <sys/zil.h>
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
    99
#include <sys/zil_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
#include <sys/vdev_impl.h>
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   101
#include <sys/vdev_file.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
#include <sys/spa_impl.h>
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
   103
#include <sys/metaslab_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
#include <sys/dsl_prop.h>
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
   105
#include <sys/dsl_dataset.h>
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   106
#include <sys/dsl_scan.h>
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
   107
#include <sys/zio_checksum.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
#include <sys/refcount.h>
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
   109
#include <sys/zfeature.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
#include <stdio.h>
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1807
diff changeset
   111
#include <stdio_ext.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
#include <stdlib.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
#include <unistd.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
#include <signal.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
#include <umem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
#include <dlfcn.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
#include <ctype.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
#include <math.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
#include <sys/fs/zfs.h>
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   120
#include <libnvpair.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   122
#define	ZTEST_FD_DATA 3
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   123
#define	ZTEST_FD_RAND 4
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   124
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   125
typedef struct ztest_shared_hdr {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   126
	uint64_t	zh_hdr_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   127
	uint64_t	zh_opts_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   128
	uint64_t	zh_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   129
	uint64_t	zh_stats_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   130
	uint64_t	zh_stats_count;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   131
	uint64_t	zh_ds_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   132
	uint64_t	zh_ds_count;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   133
} ztest_shared_hdr_t;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   134
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   135
static ztest_shared_hdr_t *ztest_shared_hdr;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   136
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   137
typedef struct ztest_shared_opts {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   138
	char zo_pool[MAXNAMELEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   139
	char zo_dir[MAXNAMELEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   140
	char zo_alt_ztest[MAXNAMELEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   141
	char zo_alt_libpath[MAXNAMELEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   142
	uint64_t zo_vdevs;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   143
	uint64_t zo_vdevtime;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   144
	size_t zo_vdev_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   145
	int zo_ashift;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   146
	int zo_mirrors;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   147
	int zo_raidz;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   148
	int zo_raidz_parity;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   149
	int zo_datasets;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   150
	int zo_threads;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   151
	uint64_t zo_passtime;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   152
	uint64_t zo_killrate;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   153
	int zo_verbose;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   154
	int zo_init;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   155
	uint64_t zo_time;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   156
	uint64_t zo_maxloops;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   157
	uint64_t zo_metaslab_gang_bang;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   158
} ztest_shared_opts_t;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   159
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   160
static const ztest_shared_opts_t ztest_opts_defaults = {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   161
	.zo_pool = { 'z', 't', 'e', 's', 't', '\0' },
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   162
	.zo_dir = { '/', 't', 'm', 'p', '\0' },
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   163
	.zo_alt_ztest = { '\0' },
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   164
	.zo_alt_libpath = { '\0' },
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   165
	.zo_vdevs = 5,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   166
	.zo_ashift = SPA_MINBLOCKSHIFT,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   167
	.zo_mirrors = 2,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   168
	.zo_raidz = 4,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   169
	.zo_raidz_parity = 1,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   170
	.zo_vdev_size = SPA_MINDEVSIZE,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   171
	.zo_datasets = 7,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   172
	.zo_threads = 23,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   173
	.zo_passtime = 60,		/* 60 seconds */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   174
	.zo_killrate = 70,		/* 70% kill rate */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   175
	.zo_verbose = 0,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   176
	.zo_init = 1,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   177
	.zo_time = 300,			/* 5 minutes */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   178
	.zo_maxloops = 50,		/* max loops during spa_freeze() */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   179
	.zo_metaslab_gang_bang = 32 << 10
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   180
};
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   181
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   182
extern uint64_t metaslab_gang_bang;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   183
extern uint64_t metaslab_df_alloc_threshold;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   184
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   185
static ztest_shared_opts_t *ztest_shared_opts;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   186
static ztest_shared_opts_t ztest_opts;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   187
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   188
typedef struct ztest_shared_ds {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   189
	uint64_t	zd_seq;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   190
} ztest_shared_ds_t;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   191
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   192
static ztest_shared_ds_t *ztest_shared_ds;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   193
#define	ZTEST_GET_SHARED_DS(d) (&ztest_shared_ds[d])
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   195
#define	BT_MAGIC	0x123456789abcdefULL
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   196
#define	MAXFAULTS() \
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   197
	(MAX(zs->zs_mirrors, 1) * (ztest_opts.zo_raidz_parity + 1) - 1)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   198
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   199
enum ztest_io_type {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   200
	ZTEST_IO_WRITE_TAG,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   201
	ZTEST_IO_WRITE_PATTERN,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   202
	ZTEST_IO_WRITE_ZEROES,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   203
	ZTEST_IO_TRUNCATE,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   204
	ZTEST_IO_SETATTR,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   205
	ZTEST_IO_TYPES
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   206
};
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   207
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   208
typedef struct ztest_block_tag {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   209
	uint64_t	bt_magic;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   210
	uint64_t	bt_objset;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   211
	uint64_t	bt_object;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   212
	uint64_t	bt_offset;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   213
	uint64_t	bt_gen;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   214
	uint64_t	bt_txg;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   215
	uint64_t	bt_crtxg;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   216
} ztest_block_tag_t;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   217
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   218
typedef struct bufwad {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   219
	uint64_t	bw_index;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   220
	uint64_t	bw_txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   221
	uint64_t	bw_data;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   222
} bufwad_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   223
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   224
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   225
 * XXX -- fix zfs range locks to be generic so we can use them here.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   226
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   227
typedef enum {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   228
	RL_READER,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   229
	RL_WRITER,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   230
	RL_APPEND
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   231
} rl_type_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   232
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   233
typedef struct rll {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   234
	void		*rll_writer;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   235
	int		rll_readers;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   236
	mutex_t		rll_lock;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   237
	cond_t		rll_cv;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   238
} rll_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   239
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   240
typedef struct rl {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   241
	uint64_t	rl_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   242
	uint64_t	rl_offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   243
	uint64_t	rl_size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   244
	rll_t		*rl_lock;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   245
} rl_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   246
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   247
#define	ZTEST_RANGE_LOCKS	64
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   248
#define	ZTEST_OBJECT_LOCKS	64
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   249
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   250
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   251
 * Object descriptor.  Used as a template for object lookup/create/remove.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   252
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   253
typedef struct ztest_od {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   254
	uint64_t	od_dir;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   255
	uint64_t	od_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   256
	dmu_object_type_t od_type;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   257
	dmu_object_type_t od_crtype;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   258
	uint64_t	od_blocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   259
	uint64_t	od_crblocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   260
	uint64_t	od_gen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   261
	uint64_t	od_crgen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   262
	char		od_name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   263
} ztest_od_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   264
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   265
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   266
 * Per-dataset state.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   267
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   268
typedef struct ztest_ds {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   269
	ztest_shared_ds_t *zd_shared;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   270
	objset_t	*zd_os;
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
   271
	rwlock_t	zd_zilog_lock;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   272
	zilog_t		*zd_zilog;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   273
	ztest_od_t	*zd_od;		/* debugging aid */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   274
	char		zd_name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   275
	mutex_t		zd_dirobj_lock;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   276
	rll_t		zd_object_lock[ZTEST_OBJECT_LOCKS];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   277
	rll_t		zd_range_lock[ZTEST_RANGE_LOCKS];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   278
} ztest_ds_t;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   279
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   280
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   281
 * Per-iteration state.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   282
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   283
typedef void ztest_func_t(ztest_ds_t *zd, uint64_t id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   284
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   285
typedef struct ztest_info {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   286
	ztest_func_t	*zi_func;	/* test function */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   287
	uint64_t	zi_iters;	/* iterations per execution */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   288
	uint64_t	*zi_interval;	/* execute every <interval> seconds */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   289
} ztest_info_t;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   291
typedef struct ztest_shared_callstate {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   292
	uint64_t	zc_count;	/* per-pass count */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   293
	uint64_t	zc_time;	/* per-pass time */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   294
	uint64_t	zc_next;	/* next time to call this function */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   295
} ztest_shared_callstate_t;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   296
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   297
static ztest_shared_callstate_t *ztest_shared_callstate;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   298
#define	ZTEST_GET_SHARED_CALLSTATE(c) (&ztest_shared_callstate[c])
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   299
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
 * Note: these aren't static because we want dladdr() to work.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
ztest_func_t ztest_dmu_read_write;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
ztest_func_t ztest_dmu_write_parallel;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
ztest_func_t ztest_dmu_object_alloc_free;
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   306
ztest_func_t ztest_dmu_commit_callbacks;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
ztest_func_t ztest_zap;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   308
ztest_func_t ztest_zap_parallel;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   309
ztest_func_t ztest_zil_commit;
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
   310
ztest_func_t ztest_zil_remount;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   311
ztest_func_t ztest_dmu_read_write_zcopy;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   312
ztest_func_t ztest_dmu_objset_create_destroy;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   313
ztest_func_t ztest_dmu_prealloc;
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
   314
ztest_func_t ztest_fzap;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   315
ztest_func_t ztest_dmu_snapshot_create_destroy;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
ztest_func_t ztest_dsl_prop_get_set;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   317
ztest_func_t ztest_spa_prop_get_set;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
ztest_func_t ztest_spa_create_destroy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
ztest_func_t ztest_fault_inject;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   320
ztest_func_t ztest_ddt_repair;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   321
ztest_func_t ztest_dmu_snapshot_hold;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   322
ztest_func_t ztest_spa_rename;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   323
ztest_func_t ztest_scrub;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   324
ztest_func_t ztest_dsl_dataset_promote_busy;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
ztest_func_t ztest_vdev_attach_detach;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
ztest_func_t ztest_vdev_LUN_growth;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
ztest_func_t ztest_vdev_add_remove;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   328
ztest_func_t ztest_vdev_aux_add_remove;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
   329
ztest_func_t ztest_split_pool;
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
   330
ztest_func_t ztest_reguid;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   331
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   332
uint64_t zopt_always = 0ULL * NANOSEC;		/* all the time */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   333
uint64_t zopt_incessant = 1ULL * NANOSEC / 10;	/* every 1/10 second */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   334
uint64_t zopt_often = 1ULL * NANOSEC;		/* every second */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   335
uint64_t zopt_sometimes = 10ULL * NANOSEC;	/* every 10 seconds */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   336
uint64_t zopt_rarely = 60ULL * NANOSEC;		/* every 60 seconds */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
ztest_info_t ztest_info[] = {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   339
	{ ztest_dmu_read_write,			1,	&zopt_always	},
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   340
	{ ztest_dmu_write_parallel,		10,	&zopt_always	},
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   341
	{ ztest_dmu_object_alloc_free,		1,	&zopt_always	},
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   342
	{ ztest_dmu_commit_callbacks,		1,	&zopt_always	},
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   343
	{ ztest_zap,				30,	&zopt_always	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   344
	{ ztest_zap_parallel,			100,	&zopt_always	},
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
   345
	{ ztest_split_pool,			1,	&zopt_always	},
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   346
	{ ztest_zil_commit,			1,	&zopt_incessant	},
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
   347
	{ ztest_zil_remount,			1,	&zopt_sometimes	},
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   348
	{ ztest_dmu_read_write_zcopy,		1,	&zopt_often	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   349
	{ ztest_dmu_objset_create_destroy,	1,	&zopt_often	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   350
	{ ztest_dsl_prop_get_set,		1,	&zopt_often	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   351
	{ ztest_spa_prop_get_set,		1,	&zopt_sometimes	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   352
#if 0
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   353
	{ ztest_dmu_prealloc,			1,	&zopt_sometimes	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   354
#endif
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   355
	{ ztest_fzap,				1,	&zopt_sometimes	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   356
	{ ztest_dmu_snapshot_create_destroy,	1,	&zopt_sometimes	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   357
	{ ztest_spa_create_destroy,		1,	&zopt_sometimes	},
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   358
	{ ztest_fault_inject,			1,	&zopt_sometimes	},
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   359
	{ ztest_ddt_repair,			1,	&zopt_sometimes	},
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
   360
	{ ztest_dmu_snapshot_hold,		1,	&zopt_sometimes	},
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
   361
	{ ztest_reguid,				1,	&zopt_sometimes },
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   362
	{ ztest_spa_rename,			1,	&zopt_rarely	},
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   363
	{ ztest_scrub,				1,	&zopt_rarely	},
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   364
	{ ztest_dsl_dataset_promote_busy,	1,	&zopt_rarely	},
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
   365
	{ ztest_vdev_attach_detach,		1,	&zopt_rarely },
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   366
	{ ztest_vdev_LUN_growth,		1,	&zopt_rarely	},
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   367
	{ ztest_vdev_add_remove,		1,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   368
	    &ztest_opts.zo_vdevtime				},
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   369
	{ ztest_vdev_aux_add_remove,		1,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   370
	    &ztest_opts.zo_vdevtime				},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
#define	ZTEST_FUNCS	(sizeof (ztest_info) / sizeof (ztest_info_t))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
/*
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   376
 * The following struct is used to hold a list of uncalled commit callbacks.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   377
 * The callbacks are ordered by txg number.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   378
 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   379
typedef struct ztest_cb_list {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   380
	mutex_t	zcl_callbacks_lock;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   381
	list_t	zcl_callbacks;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   382
} ztest_cb_list_t;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   383
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   384
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
 * Stuff we need to share writably between parent and child.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
typedef struct ztest_shared {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   388
	boolean_t	zs_do_init;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   389
	hrtime_t	zs_proc_start;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   390
	hrtime_t	zs_proc_stop;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   391
	hrtime_t	zs_thread_start;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   392
	hrtime_t	zs_thread_stop;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   393
	hrtime_t	zs_thread_kill;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   394
	uint64_t	zs_enospc_count;
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
   395
	uint64_t	zs_vdev_next_leaf;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   396
	uint64_t	zs_vdev_aux;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
	uint64_t	zs_alloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
	uint64_t	zs_space;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
   399
	uint64_t	zs_splits;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
   400
	uint64_t	zs_mirrors;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   401
	uint64_t	zs_metaslab_sz;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   402
	uint64_t	zs_metaslab_df_alloc_threshold;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   403
	uint64_t	zs_guid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
} ztest_shared_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   406
#define	ID_PARALLEL	-1ULL
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   407
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
static char ztest_dev_template[] = "%s/%s.%llua";
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   409
static char ztest_aux_template[] = "%s/%s.%s.%llu";
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   410
ztest_shared_t *ztest_shared;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   411
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   412
static spa_t *ztest_spa = NULL;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   413
static ztest_ds_t *ztest_ds;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   414
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   415
static mutex_t ztest_vdev_lock;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   416
static rwlock_t ztest_name_lock;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   417
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   418
static boolean_t ztest_dump_core = B_TRUE;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   419
static boolean_t ztest_exiting;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   420
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   421
/* Global commit callback list */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   422
static ztest_cb_list_t zcl;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
   423
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   424
enum ztest_object {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   425
	ZTEST_META_DNODE = 0,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   426
	ZTEST_DIROBJ,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   427
	ZTEST_OBJECTS
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   428
};
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
4008
a95c00c4179a 6543732 fix for 6524407 broke the nightly build with gcc
raf
parents: 3972
diff changeset
   430
static void usage(boolean_t) __NORETURN;
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   431
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
 * These libumem hooks provide a reasonable set of defaults for the allocator's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
 * debugging facilities.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
_umem_debug_init()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
	return ("default,verbose"); /* $UMEM_DEBUG setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
_umem_logging_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	return ("fail,contents"); /* $UMEM_LOGGING setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
#define	FATAL_MSG_SZ	1024
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
char *fatal_msg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
fatal(int do_perror, char *message, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
	va_list args;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
	int save_errno = errno;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	char buf[FATAL_MSG_SZ];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	(void) fflush(stdout);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	va_start(args, message);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	(void) sprintf(buf, "ztest: ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
	/* LINTED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	(void) vsprintf(buf + strlen(buf), message, args);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
	va_end(args);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
	if (do_perror) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
		(void) snprintf(buf + strlen(buf), FATAL_MSG_SZ - strlen(buf),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
		    ": %s", strerror(save_errno));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
	(void) fprintf(stderr, "%s\n", buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
	fatal_msg = buf;			/* to ease debugging */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
	if (ztest_dump_core)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
		abort();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
	exit(3);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
str2shift(const char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
	const char *ends = "BKMGTPEZ";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
	if (buf[0] == '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
	for (i = 0; i < strlen(ends); i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
		if (toupper(buf[0]) == ends[i])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
	}
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   489
	if (i == strlen(ends)) {
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   490
		(void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n",
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   491
		    buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   492
		usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   493
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	if (buf[1] == '\0' || (toupper(buf[1]) == 'B' && buf[2] == '\0')) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
		return (10*i);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
	}
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   497
	(void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n", buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   498
	usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   499
	/* NOTREACHED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
static uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
nicenumtoull(const char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
	char *end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
	uint64_t val;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	val = strtoull(buf, &end, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	if (end == buf) {
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   510
		(void) fprintf(stderr, "ztest: bad numeric value: %s\n", buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   511
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
	} else if (end[0] == '.') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
		double fval = strtod(buf, &end);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
		fval *= pow(2, str2shift(end));
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   515
		if (fval > UINT64_MAX) {
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   516
			(void) fprintf(stderr, "ztest: value too large: %s\n",
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   517
			    buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   518
			usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   519
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
		val = (uint64_t)fval;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
		int shift = str2shift(end);
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   523
		if (shift >= 64 || (val << shift) >> shift != val) {
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   524
			(void) fprintf(stderr, "ztest: value too large: %s\n",
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   525
			    buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   526
			usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   527
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
		val <<= shift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	return (val);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
static void
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   534
usage(boolean_t requested)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   536
	const ztest_shared_opts_t *zo = &ztest_opts_defaults;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   537
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	char nice_vdev_size[10];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	char nice_gang_bang[10];
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   540
	FILE *fp = requested ? stdout : stderr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   542
	nicenum(zo->zo_vdev_size, nice_vdev_size);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   543
	nicenum(zo->zo_metaslab_gang_bang, nice_gang_bang);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   545
	(void) fprintf(fp, "Usage: %s\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
	    "\t[-v vdevs (default: %llu)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
	    "\t[-s size_of_each_vdev (default: %s)]\n"
11818
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   548
	    "\t[-a alignment_shift (default: %d)] use 0 for random\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	    "\t[-m mirror_copies (default: %d)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
	    "\t[-r raidz_disks (default: %d)]\n"
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   551
	    "\t[-R raidz_parity (default: %d)]\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
	    "\t[-d datasets (default: %d)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	    "\t[-t threads (default: %d)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
	    "\t[-g gang_block_threshold (default: %s)]\n"
11818
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   555
	    "\t[-i init_count (default: %d)] initialize pool i times\n"
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   556
	    "\t[-k kill_percentage (default: %llu%%)]\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	    "\t[-p pool_name (default: %s)]\n"
11818
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   558
	    "\t[-f dir (default: %s)] file directory for vdev files\n"
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   559
	    "\t[-V] verbose (use multiple times for ever more blather)\n"
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   560
	    "\t[-E] use existing pool instead of creating new one\n"
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   561
	    "\t[-T time (default: %llu sec)] total run time\n"
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   562
	    "\t[-F freezeloops (default: %llu)] max loops in spa_freeze()\n"
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   563
	    "\t[-P passtime (default: %llu sec)] time per pass\n"
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   564
	    "\t[-B alt_ztest (default: <none>)] alternate ztest path\n"
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   565
	    "\t[-h] (print help)\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
	    "",
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   567
	    zo->zo_pool,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   568
	    (u_longlong_t)zo->zo_vdevs,			/* -v */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   569
	    nice_vdev_size,				/* -s */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   570
	    zo->zo_ashift,				/* -a */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   571
	    zo->zo_mirrors,				/* -m */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   572
	    zo->zo_raidz,				/* -r */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   573
	    zo->zo_raidz_parity,			/* -R */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   574
	    zo->zo_datasets,				/* -d */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   575
	    zo->zo_threads,				/* -t */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   576
	    nice_gang_bang,				/* -g */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   577
	    zo->zo_init,				/* -i */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   578
	    (u_longlong_t)zo->zo_killrate,		/* -k */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   579
	    zo->zo_pool,				/* -p */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   580
	    zo->zo_dir,					/* -f */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   581
	    (u_longlong_t)zo->zo_time,			/* -T */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   582
	    (u_longlong_t)zo->zo_maxloops,		/* -F */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   583
	    (u_longlong_t)zo->zo_passtime);
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   584
	exit(requested ? 0 : 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
process_options(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   590
	char *path;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   591
	ztest_shared_opts_t *zo = &ztest_opts;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   592
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	int opt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
	uint64_t value;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   595
	char altdir[MAXNAMELEN] = { 0 };
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   596
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   597
	bcopy(&ztest_opts_defaults, zo, sizeof (*zo));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
	while ((opt = getopt(argc, argv,
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   600
	    "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:hF:B:")) != EOF) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
		value = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
		switch (opt) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   603
		case 'v':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   604
		case 's':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   605
		case 'a':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   606
		case 'm':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   607
		case 'r':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   608
		case 'R':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   609
		case 'd':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   610
		case 't':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   611
		case 'g':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   612
		case 'i':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   613
		case 'k':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   614
		case 'T':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   615
		case 'P':
11818
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   616
		case 'F':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
			value = nicenumtoull(optarg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
		switch (opt) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   620
		case 'v':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   621
			zo->zo_vdevs = value;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   623
		case 's':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   624
			zo->zo_vdev_size = MAX(SPA_MINDEVSIZE, value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   626
		case 'a':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   627
			zo->zo_ashift = value;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   628
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   629
		case 'm':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   630
			zo->zo_mirrors = value;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   632
		case 'r':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   633
			zo->zo_raidz = MAX(1, value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   635
		case 'R':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   636
			zo->zo_raidz_parity = MIN(MAX(value, 1), 3);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   637
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   638
		case 'd':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   639
			zo->zo_datasets = MAX(1, value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   641
		case 't':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   642
			zo->zo_threads = MAX(1, value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   644
		case 'g':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   645
			zo->zo_metaslab_gang_bang = MAX(SPA_MINBLOCKSIZE << 1,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   646
			    value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   648
		case 'i':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   649
			zo->zo_init = value;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   651
		case 'k':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   652
			zo->zo_killrate = value;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   654
		case 'p':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   655
			(void) strlcpy(zo->zo_pool, optarg,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   656
			    sizeof (zo->zo_pool));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   658
		case 'f':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   659
			path = realpath(optarg, NULL);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   660
			if (path == NULL) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   661
				(void) fprintf(stderr, "error: %s: %s\n",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   662
				    optarg, strerror(errno));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   663
				usage(B_FALSE);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   664
			} else {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   665
				(void) strlcpy(zo->zo_dir, path,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   666
				    sizeof (zo->zo_dir));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   667
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   669
		case 'V':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   670
			zo->zo_verbose++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   672
		case 'E':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   673
			zo->zo_init = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   675
		case 'T':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   676
			zo->zo_time = value;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   678
		case 'P':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   679
			zo->zo_passtime = MAX(1, value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
			break;
11818
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   681
		case 'F':
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   682
			zo->zo_maxloops = MAX(1, value);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   683
			break;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   684
		case 'B':
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   685
			(void) strlcpy(altdir, optarg, sizeof (altdir));
11818
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
   686
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   687
		case 'h':
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   688
			usage(B_TRUE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   689
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   690
		case '?':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   691
		default:
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   692
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   697
	zo->zo_raidz_parity = MIN(zo->zo_raidz_parity, zo->zo_raidz - 1);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   698
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   699
	zo->zo_vdevtime =
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   700
	    (zo->zo_vdevs > 0 ? zo->zo_time * NANOSEC / zo->zo_vdevs :
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   701
	    UINT64_MAX >> 2);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   702
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   703
	if (strlen(altdir) > 0) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   704
		char cmd[MAXNAMELEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   705
		char realaltdir[MAXNAMELEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   706
		char *bin;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   707
		char *ztest;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   708
		char *isa;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   709
		int isalen;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   710
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   711
		(void) realpath(getexecname(), cmd);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   712
		if (0 != access(altdir, F_OK)) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   713
			ztest_dump_core = B_FALSE;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   714
			fatal(B_TRUE, "invalid alternate ztest path: %s",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   715
			    altdir);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   716
		}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   717
		VERIFY(NULL != realpath(altdir, realaltdir));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   718
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   719
		/*
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   720
		 * 'cmd' should be of the form "<anything>/usr/bin/<isa>/ztest".
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   721
		 * We want to extract <isa> to determine if we should use
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   722
		 * 32 or 64 bit binaries.
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   723
		 */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   724
		bin = strstr(cmd, "/usr/bin/");
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   725
		ztest = strstr(bin, "/ztest");
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   726
		isa = bin + 9;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   727
		isalen = ztest - isa;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   728
		(void) snprintf(zo->zo_alt_ztest, sizeof (zo->zo_alt_ztest),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   729
		    "%s/usr/bin/%.*s/ztest", realaltdir, isalen, isa);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   730
		(void) snprintf(zo->zo_alt_libpath, sizeof (zo->zo_alt_libpath),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   731
		    "%s/usr/lib/%.*s", realaltdir, isalen, isa);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   732
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   733
		if (0 != access(zo->zo_alt_ztest, X_OK)) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   734
			ztest_dump_core = B_FALSE;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   735
			fatal(B_TRUE, "invalid alternate ztest: %s",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   736
			    zo->zo_alt_ztest);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   737
		} else if (0 != access(zo->zo_alt_libpath, X_OK)) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   738
			ztest_dump_core = B_FALSE;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   739
			fatal(B_TRUE, "invalid alternate lib directory %s",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   740
			    zo->zo_alt_libpath);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   741
		}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   742
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   745
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   746
ztest_kill(ztest_shared_t *zs)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   747
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   748
	zs->zs_alloc = metaslab_class_get_alloc(spa_normal_class(ztest_spa));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   749
	zs->zs_space = metaslab_class_get_space(spa_normal_class(ztest_spa));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   750
	(void) kill(getpid(), SIGKILL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   751
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   752
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   753
static uint64_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   754
ztest_random(uint64_t range)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   755
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   756
	uint64_t r;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   757
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   758
	if (range == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   759
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   760
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   761
	if (read(ZTEST_FD_RAND, &r, sizeof (r)) != sizeof (r))
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   762
		fatal(1, "short read from /dev/urandom");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   763
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   764
	return (r % range);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   765
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   766
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   767
/* ARGSUSED */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   768
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   769
ztest_record_enospc(const char *s)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   770
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   771
	ztest_shared->zs_enospc_count++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   772
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   773
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   774
static uint64_t
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   775
ztest_get_ashift(void)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   776
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   777
	if (ztest_opts.zo_ashift == 0)
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   778
		return (SPA_MINBLOCKSHIFT + ztest_random(3));
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   779
	return (ztest_opts.zo_ashift);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   780
}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   781
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
static nvlist_t *
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   783
make_vdev_file(char *path, char *aux, size_t size, uint64_t ashift)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   785
	char pathbuf[MAXPATHLEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	uint64_t vdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
	nvlist_t *file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   789
	if (ashift == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   790
		ashift = ztest_get_ashift();
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   791
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   792
	if (path == NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   793
		path = pathbuf;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   794
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   795
		if (aux != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   796
			vdev = ztest_shared->zs_vdev_aux;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   797
			(void) snprintf(path, sizeof (pathbuf),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   798
			    ztest_aux_template, ztest_opts.zo_dir,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   799
			    ztest_opts.zo_pool, aux, vdev);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   800
		} else {
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
   801
			vdev = ztest_shared->zs_vdev_next_leaf++;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   802
			(void) snprintf(path, sizeof (pathbuf),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   803
			    ztest_dev_template, ztest_opts.zo_dir,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   804
			    ztest_opts.zo_pool, vdev);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   805
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   806
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   807
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   808
	if (size != 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   809
		int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
		if (fd == -1)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   811
			fatal(1, "can't open %s", path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
		if (ftruncate(fd, size) != 0)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   813
			fatal(1, "can't ftruncate %s", path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
		(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   819
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, path) == 0);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   820
	VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
	return (file);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
static nvlist_t *
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   826
make_vdev_raidz(char *path, char *aux, size_t size, uint64_t ashift, int r)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
	nvlist_t *raidz, **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
	if (r < 2)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   832
		return (make_vdev_file(path, aux, size, ashift));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
	child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   835
	for (c = 0; c < r; c++)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   836
		child[c] = make_vdev_file(path, aux, size, ashift);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   837
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
	VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
	VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
	    VDEV_TYPE_RAIDZ) == 0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   841
	VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY,
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   842
	    ztest_opts.zo_raidz_parity) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
	VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
	    child, r) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
	for (c = 0; c < r; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
		nvlist_free(child[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
	umem_free(child, r * sizeof (nvlist_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
	return (raidz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
static nvlist_t *
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   855
make_vdev_mirror(char *path, char *aux, size_t size, uint64_t ashift,
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   856
	int r, int m)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
	nvlist_t *mirror, **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
	if (m < 1)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   862
		return (make_vdev_raidz(path, aux, size, ashift, r));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
	child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
	for (c = 0; c < m; c++)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   867
		child[c] = make_vdev_raidz(path, aux, size, ashift, r);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
	    VDEV_TYPE_MIRROR) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
	    child, m) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
	for (c = 0; c < m; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
		nvlist_free(child[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
	umem_free(child, m * sizeof (nvlist_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
	return (mirror);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
static nvlist_t *
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   884
make_vdev_root(char *path, char *aux, size_t size, uint64_t ashift,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   885
	int log, int r, int m, int t)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
	nvlist_t *root, **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
	ASSERT(t > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
	child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   894
	for (c = 0; c < t; c++) {
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   895
		child[c] = make_vdev_mirror(path, aux, size, ashift, r, m);
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   896
		VERIFY(nvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   897
		    log) == 0);
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
   898
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
	VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
	VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   902
	VERIFY(nvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
	    child, t) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
	for (c = 0; c < t; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
		nvlist_free(child[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
	umem_free(child, t * sizeof (nvlist_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
	return (root);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   913
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   914
ztest_random_blocksize(void)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   916
	return (1 << (SPA_MINBLOCKSHIFT +
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   917
	    ztest_random(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
static int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   921
ztest_random_ibshift(void)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   922
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   923
	return (DN_MIN_INDBLKSHIFT +
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   924
	    ztest_random(DN_MAX_INDBLKSHIFT - DN_MIN_INDBLKSHIFT + 1));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   925
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   926
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   927
static uint64_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   928
ztest_random_vdev_top(spa_t *spa, boolean_t log_ok)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   930
	uint64_t top;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   931
	vdev_t *rvd = spa->spa_root_vdev;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   932
	vdev_t *tvd;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   933
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   934
	ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   935
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   936
	do {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   937
		top = ztest_random(rvd->vdev_children);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   938
		tvd = rvd->vdev_child[top];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   939
	} while (tvd->vdev_ishole || (tvd->vdev_islog && !log_ok) ||
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   940
	    tvd->vdev_mg == NULL || tvd->vdev_mg->mg_class == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   941
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   942
	return (top);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   943
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   944
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   945
static uint64_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   946
ztest_random_dsl_prop(zfs_prop_t prop)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   947
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   948
	uint64_t value;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   949
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   950
	do {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   951
		value = zfs_prop_random_value(prop, ztest_random(-1ULL));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   952
	} while (prop == ZFS_PROP_CHECKSUM && value == ZIO_CHECKSUM_OFF);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   953
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   954
	return (value);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   955
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   956
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   957
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   958
ztest_dsl_prop_set_uint64(char *osname, zfs_prop_t prop, uint64_t value,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   959
    boolean_t inherit)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   960
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   961
	const char *propname = zfs_prop_to_name(prop);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   962
	const char *valname;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   963
	char setpoint[MAXPATHLEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   964
	uint64_t curval;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10945
diff changeset
   967
	error = dsl_prop_set(osname, propname,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10945
diff changeset
   968
	    (inherit ? ZPROP_SRC_NONE : ZPROP_SRC_LOCAL),
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10945
diff changeset
   969
	    sizeof (value), 1, &value);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   970
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   971
	if (error == ENOSPC) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   972
		ztest_record_enospc(FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   975
	ASSERT3U(error, ==, 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   976
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   977
	VERIFY3U(dsl_prop_get(osname, propname, sizeof (curval),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   978
	    1, &curval, setpoint), ==, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   979
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   980
	if (ztest_opts.zo_verbose >= 6) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   981
		VERIFY(zfs_prop_index_to_string(prop, curval, &valname) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   982
		(void) printf("%s %s = %s at '%s'\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   983
		    osname, propname, valname, setpoint);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
static int
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   990
ztest_spa_prop_set_uint64(zpool_prop_t prop, uint64_t value)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   991
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
   992
	spa_t *spa = ztest_spa;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   993
	nvlist_t *props = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   994
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   995
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   996
	VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   997
	VERIFY(nvlist_add_uint64(props, zpool_prop_to_name(prop), value) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   998
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
   999
	error = spa_prop_set(spa, props);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1000
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1001
	nvlist_free(props);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1002
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1003
	if (error == ENOSPC) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1004
		ztest_record_enospc(FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1005
		return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1006
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1007
	ASSERT3U(error, ==, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1008
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1009
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1010
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1011
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1012
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1013
ztest_rll_init(rll_t *rll)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1014
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1015
	rll->rll_writer = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1016
	rll->rll_readers = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1017
	VERIFY(_mutex_init(&rll->rll_lock, USYNC_THREAD, NULL) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1018
	VERIFY(cond_init(&rll->rll_cv, USYNC_THREAD, NULL) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1019
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1020
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1021
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1022
ztest_rll_destroy(rll_t *rll)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1023
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1024
	ASSERT(rll->rll_writer == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1025
	ASSERT(rll->rll_readers == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1026
	VERIFY(_mutex_destroy(&rll->rll_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1027
	VERIFY(cond_destroy(&rll->rll_cv) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1028
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1029
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1030
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1031
ztest_rll_lock(rll_t *rll, rl_type_t type)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1032
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1033
	VERIFY(mutex_lock(&rll->rll_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1034
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1035
	if (type == RL_READER) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1036
		while (rll->rll_writer != NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1037
			(void) cond_wait(&rll->rll_cv, &rll->rll_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1038
		rll->rll_readers++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1039
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1040
		while (rll->rll_writer != NULL || rll->rll_readers)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1041
			(void) cond_wait(&rll->rll_cv, &rll->rll_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1042
		rll->rll_writer = curthread;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1043
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1044
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1045
	VERIFY(mutex_unlock(&rll->rll_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1046
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1047
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1048
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1049
ztest_rll_unlock(rll_t *rll)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1050
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1051
	VERIFY(mutex_lock(&rll->rll_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1052
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1053
	if (rll->rll_writer) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1054
		ASSERT(rll->rll_readers == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1055
		rll->rll_writer = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1056
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1057
		ASSERT(rll->rll_readers != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1058
		ASSERT(rll->rll_writer == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1059
		rll->rll_readers--;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1060
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1061
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1062
	if (rll->rll_writer == NULL && rll->rll_readers == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1063
		VERIFY(cond_broadcast(&rll->rll_cv) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1064
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1065
	VERIFY(mutex_unlock(&rll->rll_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1066
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1067
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1068
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1069
ztest_object_lock(ztest_ds_t *zd, uint64_t object, rl_type_t type)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1070
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1071
	rll_t *rll = &zd->zd_object_lock[object & (ZTEST_OBJECT_LOCKS - 1)];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1072
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1073
	ztest_rll_lock(rll, type);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1074
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1075
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1076
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1077
ztest_object_unlock(ztest_ds_t *zd, uint64_t object)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1078
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1079
	rll_t *rll = &zd->zd_object_lock[object & (ZTEST_OBJECT_LOCKS - 1)];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1080
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1081
	ztest_rll_unlock(rll);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1082
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1083
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1084
static rl_t *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1085
ztest_range_lock(ztest_ds_t *zd, uint64_t object, uint64_t offset,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1086
    uint64_t size, rl_type_t type)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1087
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1088
	uint64_t hash = object ^ (offset % (ZTEST_RANGE_LOCKS + 1));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1089
	rll_t *rll = &zd->zd_range_lock[hash & (ZTEST_RANGE_LOCKS - 1)];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1090
	rl_t *rl;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1091
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1092
	rl = umem_alloc(sizeof (*rl), UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1093
	rl->rl_object = object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1094
	rl->rl_offset = offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1095
	rl->rl_size = size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1096
	rl->rl_lock = rll;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1097
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1098
	ztest_rll_lock(rll, type);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1099
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1100
	return (rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1101
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1102
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1103
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1104
ztest_range_unlock(rl_t *rl)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1105
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1106
	rll_t *rll = rl->rl_lock;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1107
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1108
	ztest_rll_unlock(rll);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1109
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1110
	umem_free(rl, sizeof (*rl));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1111
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1112
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1113
static void
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  1114
ztest_zd_init(ztest_ds_t *zd, ztest_shared_ds_t *szd, objset_t *os)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1115
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1116
	zd->zd_os = os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1117
	zd->zd_zilog = dmu_objset_zil(os);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  1118
	zd->zd_shared = szd;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1119
	dmu_objset_name(os, zd->zd_name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1120
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  1121
	if (zd->zd_shared != NULL)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  1122
		zd->zd_shared->zd_seq = 0;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  1123
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  1124
	VERIFY(rwlock_init(&zd->zd_zilog_lock, USYNC_THREAD, NULL) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1125
	VERIFY(_mutex_init(&zd->zd_dirobj_lock, USYNC_THREAD, NULL) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1126
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1127
	for (int l = 0; l < ZTEST_OBJECT_LOCKS; l++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1128
		ztest_rll_init(&zd->zd_object_lock[l]);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1129
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1130
	for (int l = 0; l < ZTEST_RANGE_LOCKS; l++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1131
		ztest_rll_init(&zd->zd_range_lock[l]);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1132
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1133
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1134
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1135
ztest_zd_fini(ztest_ds_t *zd)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1136
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1137
	VERIFY(_mutex_destroy(&zd->zd_dirobj_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1138
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1139
	for (int l = 0; l < ZTEST_OBJECT_LOCKS; l++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1140
		ztest_rll_destroy(&zd->zd_object_lock[l]);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1141
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1142
	for (int l = 0; l < ZTEST_RANGE_LOCKS; l++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1143
		ztest_rll_destroy(&zd->zd_range_lock[l]);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1144
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1145
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1146
#define	TXG_MIGHTWAIT	(ztest_random(10) == 0 ? TXG_NOWAIT : TXG_WAIT)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1147
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1148
static uint64_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1149
ztest_tx_assign(dmu_tx_t *tx, uint64_t txg_how, const char *tag)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1151
	uint64_t txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1152
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1153
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1154
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1155
	 * Attempt to assign tx to some transaction group.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1156
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1157
	error = dmu_tx_assign(tx, txg_how);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1158
	if (error) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1159
		if (error == ERESTART) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1160
			ASSERT(txg_how == TXG_NOWAIT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1161
			dmu_tx_wait(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1162
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1163
			ASSERT3U(error, ==, ENOSPC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1164
			ztest_record_enospc(tag);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1165
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1166
		dmu_tx_abort(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1167
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1168
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1169
	txg = dmu_tx_get_txg(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1170
	ASSERT(txg != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1171
	return (txg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1172
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1173
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1174
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1175
ztest_pattern_set(void *buf, uint64_t size, uint64_t value)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1176
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1177
	uint64_t *ip = buf;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1178
	uint64_t *ip_end = (uint64_t *)((uintptr_t)buf + (uintptr_t)size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1179
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1180
	while (ip < ip_end)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1181
		*ip++ = value;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1182
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1183
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1184
static boolean_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1185
ztest_pattern_match(void *buf, uint64_t size, uint64_t value)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1186
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1187
	uint64_t *ip = buf;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1188
	uint64_t *ip_end = (uint64_t *)((uintptr_t)buf + (uintptr_t)size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1189
	uint64_t diff = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1190
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1191
	while (ip < ip_end)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1192
		diff |= (value - *ip++);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1193
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1194
	return (diff == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1195
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1196
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1197
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1198
ztest_bt_generate(ztest_block_tag_t *bt, objset_t *os, uint64_t object,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1199
    uint64_t offset, uint64_t gen, uint64_t txg, uint64_t crtxg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1200
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1201
	bt->bt_magic = BT_MAGIC;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1202
	bt->bt_objset = dmu_objset_id(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1203
	bt->bt_object = object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1204
	bt->bt_offset = offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1205
	bt->bt_gen = gen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1206
	bt->bt_txg = txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1207
	bt->bt_crtxg = crtxg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1208
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1209
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1210
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1211
ztest_bt_verify(ztest_block_tag_t *bt, objset_t *os, uint64_t object,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1212
    uint64_t offset, uint64_t gen, uint64_t txg, uint64_t crtxg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1213
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1214
	ASSERT(bt->bt_magic == BT_MAGIC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1215
	ASSERT(bt->bt_objset == dmu_objset_id(os));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1216
	ASSERT(bt->bt_object == object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1217
	ASSERT(bt->bt_offset == offset);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1218
	ASSERT(bt->bt_gen <= gen);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1219
	ASSERT(bt->bt_txg <= txg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1220
	ASSERT(bt->bt_crtxg == crtxg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1221
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1222
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1223
static ztest_block_tag_t *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1224
ztest_bt_bonus(dmu_buf_t *db)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1225
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1226
	dmu_object_info_t doi;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1227
	ztest_block_tag_t *bt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1228
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1229
	dmu_object_info_from_db(db, &doi);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1230
	ASSERT3U(doi.doi_bonus_size, <=, db->db_size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1231
	ASSERT3U(doi.doi_bonus_size, >=, sizeof (*bt));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1232
	bt = (void *)((char *)db->db_data + doi.doi_bonus_size - sizeof (*bt));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1233
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1234
	return (bt);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1235
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1236
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1237
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1238
 * ZIL logging ops
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1239
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1240
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1241
#define	lrz_type	lr_mode
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1242
#define	lrz_blocksize	lr_uid
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1243
#define	lrz_ibshift	lr_gid
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1244
#define	lrz_bonustype	lr_rdev
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1245
#define	lrz_bonuslen	lr_crtime[1]
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1246
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1247
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1248
ztest_log_create(ztest_ds_t *zd, dmu_tx_t *tx, lr_create_t *lr)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1249
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1250
	char *name = (void *)(lr + 1);		/* name follows lr */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1251
	size_t namesize = strlen(name) + 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1252
	itx_t *itx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1253
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1254
	if (zil_replaying(zd->zd_zilog, tx))
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1255
		return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1256
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1257
	itx = zil_itx_create(TX_CREATE, sizeof (*lr) + namesize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1258
	bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1259
	    sizeof (*lr) + namesize - sizeof (lr_t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1260
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1261
	zil_itx_assign(zd->zd_zilog, itx, tx);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1262
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1263
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1264
static void
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1265
ztest_log_remove(ztest_ds_t *zd, dmu_tx_t *tx, lr_remove_t *lr, uint64_t object)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1266
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1267
	char *name = (void *)(lr + 1);		/* name follows lr */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1268
	size_t namesize = strlen(name) + 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1269
	itx_t *itx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1270
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1271
	if (zil_replaying(zd->zd_zilog, tx))
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1272
		return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1273
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1274
	itx = zil_itx_create(TX_REMOVE, sizeof (*lr) + namesize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1275
	bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1276
	    sizeof (*lr) + namesize - sizeof (lr_t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1277
12700
0f31afc2abec 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c (fix 32bit build)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12699
diff changeset
  1278
	itx->itx_oid = object;
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1279
	zil_itx_assign(zd->zd_zilog, itx, tx);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1280
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1281
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1282
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1283
ztest_log_write(ztest_ds_t *zd, dmu_tx_t *tx, lr_write_t *lr)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1284
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1285
	itx_t *itx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1286
	itx_wr_state_t write_state = ztest_random(WR_NUM_STATES);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1287
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1288
	if (zil_replaying(zd->zd_zilog, tx))
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1289
		return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1290
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1291
	if (lr->lr_length > ZIL_MAX_LOG_DATA)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1292
		write_state = WR_INDIRECT;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1293
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1294
	itx = zil_itx_create(TX_WRITE,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1295
	    sizeof (*lr) + (write_state == WR_COPIED ? lr->lr_length : 0));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1296
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1297
	if (write_state == WR_COPIED &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1298
	    dmu_read(zd->zd_os, lr->lr_foid, lr->lr_offset, lr->lr_length,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1299
	    ((lr_write_t *)&itx->itx_lr) + 1, DMU_READ_NO_PREFETCH) != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1300
		zil_itx_destroy(itx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1301
		itx = zil_itx_create(TX_WRITE, sizeof (*lr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1302
		write_state = WR_NEED_COPY;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1303
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1304
	itx->itx_private = zd;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1305
	itx->itx_wr_state = write_state;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1306
	itx->itx_sync = (ztest_random(8) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1307
	itx->itx_sod += (write_state == WR_NEED_COPY ? lr->lr_length : 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1308
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1309
	bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1310
	    sizeof (*lr) - sizeof (lr_t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1311
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1312
	zil_itx_assign(zd->zd_zilog, itx, tx);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1313
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1314
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1315
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1316
ztest_log_truncate(ztest_ds_t *zd, dmu_tx_t *tx, lr_truncate_t *lr)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1317
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1318
	itx_t *itx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1319
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1320
	if (zil_replaying(zd->zd_zilog, tx))
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1321
		return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1322
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1323
	itx = zil_itx_create(TX_TRUNCATE, sizeof (*lr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1324
	bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1325
	    sizeof (*lr) - sizeof (lr_t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1326
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1327
	itx->itx_sync = B_FALSE;
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1328
	zil_itx_assign(zd->zd_zilog, itx, tx);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1329
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1330
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1331
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1332
ztest_log_setattr(ztest_ds_t *zd, dmu_tx_t *tx, lr_setattr_t *lr)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1333
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1334
	itx_t *itx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1335
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1336
	if (zil_replaying(zd->zd_zilog, tx))
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1337
		return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1338
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1339
	itx = zil_itx_create(TX_SETATTR, sizeof (*lr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1340
	bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1341
	    sizeof (*lr) - sizeof (lr_t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1342
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1343
	itx->itx_sync = B_FALSE;
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1344
	zil_itx_assign(zd->zd_zilog, itx, tx);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1345
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1346
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1347
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1348
 * ZIL replay ops
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1349
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1350
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1351
ztest_replay_create(ztest_ds_t *zd, lr_create_t *lr, boolean_t byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1352
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1353
	char *name = (void *)(lr + 1);		/* name follows lr */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1354
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1355
	ztest_block_tag_t *bbt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1356
	dmu_buf_t *db;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1357
	dmu_tx_t *tx;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1358
	uint64_t txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1359
	int error = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
	if (byteswap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
		byteswap_uint64_array(lr, sizeof (*lr));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1364
	ASSERT(lr->lr_doid == ZTEST_DIROBJ);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1365
	ASSERT(name[0] != '\0');
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1366
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
	tx = dmu_tx_create(os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1368
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1369
	dmu_tx_hold_zap(tx, lr->lr_doid, B_TRUE, name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1370
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1371
	if (lr->lrz_type == DMU_OT_ZAP_OTHER) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1372
		dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, B_TRUE, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1373
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1374
		dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1375
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1376
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1377
	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1378
	if (txg == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1379
		return (ENOSPC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1380
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1381
	ASSERT(dmu_objset_zil(os)->zl_replay == !!lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1382
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1383
	if (lr->lrz_type == DMU_OT_ZAP_OTHER) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1384
		if (lr->lr_foid == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1385
			lr->lr_foid = zap_create(os,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1386
			    lr->lrz_type, lr->lrz_bonustype,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1387
			    lr->lrz_bonuslen, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1388
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1389
			error = zap_create_claim(os, lr->lr_foid,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1390
			    lr->lrz_type, lr->lrz_bonustype,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1391
			    lr->lrz_bonuslen, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1392
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1393
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1394
		if (lr->lr_foid == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1395
			lr->lr_foid = dmu_object_alloc(os,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1396
			    lr->lrz_type, 0, lr->lrz_bonustype,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1397
			    lr->lrz_bonuslen, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1398
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1399
			error = dmu_object_claim(os, lr->lr_foid,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1400
			    lr->lrz_type, 0, lr->lrz_bonustype,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1401
			    lr->lrz_bonuslen, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1402
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1403
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1404
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
	if (error) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1406
		ASSERT3U(error, ==, EEXIST);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1407
		ASSERT(zd->zd_zilog->zl_replay);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1408
		dmu_tx_commit(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1412
	ASSERT(lr->lr_foid != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1413
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1414
	if (lr->lrz_type != DMU_OT_ZAP_OTHER)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1415
		VERIFY3U(0, ==, dmu_object_set_blocksize(os, lr->lr_foid,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1416
		    lr->lrz_blocksize, lr->lrz_ibshift, tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1417
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1418
	VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1419
	bbt = ztest_bt_bonus(db);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1420
	dmu_buf_will_dirty(db, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1421
	ztest_bt_generate(bbt, os, lr->lr_foid, -1ULL, lr->lr_gen, txg, txg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1422
	dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1423
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1424
	VERIFY3U(0, ==, zap_add(os, lr->lr_doid, name, sizeof (uint64_t), 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1425
	    &lr->lr_foid, tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1426
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1427
	(void) ztest_log_create(zd, tx, lr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1428
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1429
	dmu_tx_commit(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1430
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1431
	return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1432
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1433
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1434
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1435
ztest_replay_remove(ztest_ds_t *zd, lr_remove_t *lr, boolean_t byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1436
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1437
	char *name = (void *)(lr + 1);		/* name follows lr */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1438
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1439
	dmu_object_info_t doi;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1440
	dmu_tx_t *tx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1441
	uint64_t object, txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1442
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1443
	if (byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1444
		byteswap_uint64_array(lr, sizeof (*lr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1445
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1446
	ASSERT(lr->lr_doid == ZTEST_DIROBJ);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1447
	ASSERT(name[0] != '\0');
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1448
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1449
	VERIFY3U(0, ==,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1450
	    zap_lookup(os, lr->lr_doid, name, sizeof (object), 1, &object));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1451
	ASSERT(object != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1452
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1453
	ztest_object_lock(zd, object, RL_WRITER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1454
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1455
	VERIFY3U(0, ==, dmu_object_info(os, object, &doi));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1456
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1457
	tx = dmu_tx_create(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1458
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1459
	dmu_tx_hold_zap(tx, lr->lr_doid, B_FALSE, name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1460
	dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1461
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1462
	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1463
	if (txg == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1464
		ztest_object_unlock(zd, object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1465
		return (ENOSPC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1466
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1467
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1468
	if (doi.doi_type == DMU_OT_ZAP_OTHER) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1469
		VERIFY3U(0, ==, zap_destroy(os, object, tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1470
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1471
		VERIFY3U(0, ==, dmu_object_free(os, object, tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1472
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1473
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1474
	VERIFY3U(0, ==, zap_remove(os, lr->lr_doid, name, tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1475
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  1476
	(void) ztest_log_remove(zd, tx, lr, object);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1477
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1480
	ztest_object_unlock(zd, object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1481
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1482
	return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1483
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1484
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1485
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1486
ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1487
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1488
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1489
	void *data = lr + 1;			/* data follows lr */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1490
	uint64_t offset, length;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1491
	ztest_block_tag_t *bt = data;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1492
	ztest_block_tag_t *bbt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1493
	uint64_t gen, txg, lrtxg, crtxg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1494
	dmu_object_info_t doi;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1495
	dmu_tx_t *tx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1496
	dmu_buf_t *db;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1497
	arc_buf_t *abuf = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1498
	rl_t *rl;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1499
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1500
	if (byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1501
		byteswap_uint64_array(lr, sizeof (*lr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1502
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1503
	offset = lr->lr_offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1504
	length = lr->lr_length;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1505
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1506
	/* If it's a dmu_sync() block, write the whole block */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1507
	if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1508
		uint64_t blocksize = BP_GET_LSIZE(&lr->lr_blkptr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1509
		if (length < blocksize) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1510
			offset -= offset % blocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1511
			length = blocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1512
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1513
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1514
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1515
	if (bt->bt_magic == BSWAP_64(BT_MAGIC))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1516
		byteswap_uint64_array(bt, sizeof (*bt));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1517
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1518
	if (bt->bt_magic != BT_MAGIC)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1519
		bt = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1520
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1521
	ztest_object_lock(zd, lr->lr_foid, RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1522
	rl = ztest_range_lock(zd, lr->lr_foid, offset, length, RL_WRITER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1523
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1524
	VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1525
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1526
	dmu_object_info_from_db(db, &doi);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1527
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1528
	bbt = ztest_bt_bonus(db);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1529
	ASSERT3U(bbt->bt_magic, ==, BT_MAGIC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1530
	gen = bbt->bt_gen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1531
	crtxg = bbt->bt_crtxg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1532
	lrtxg = lr->lr_common.lrc_txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1533
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1534
	tx = dmu_tx_create(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1535
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1536
	dmu_tx_hold_write(tx, lr->lr_foid, offset, length);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1537
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1538
	if (ztest_random(8) == 0 && length == doi.doi_data_block_size &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1539
	    P2PHASE(offset, length) == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1540
		abuf = dmu_request_arcbuf(db, length);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1541
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1542
	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1543
	if (txg == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1544
		if (abuf != NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1545
			dmu_return_arcbuf(abuf);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1546
		dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1547
		ztest_range_unlock(rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1548
		ztest_object_unlock(zd, lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1549
		return (ENOSPC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1550
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1551
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1552
	if (bt != NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1553
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1554
		 * Usually, verify the old data before writing new data --
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1555
		 * but not always, because we also want to verify correct
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1556
		 * behavior when the data was not recently read into cache.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1557
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1558
		ASSERT(offset % doi.doi_data_block_size == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1559
		if (ztest_random(4) != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1560
			int prefetch = ztest_random(2) ?
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1561
			    DMU_READ_PREFETCH : DMU_READ_NO_PREFETCH;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1562
			ztest_block_tag_t rbt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1563
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1564
			VERIFY(dmu_read(os, lr->lr_foid, offset,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1565
			    sizeof (rbt), &rbt, prefetch) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1566
			if (rbt.bt_magic == BT_MAGIC) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1567
				ztest_bt_verify(&rbt, os, lr->lr_foid,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1568
				    offset, gen, txg, crtxg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1569
			}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1570
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1571
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1572
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1573
		 * Writes can appear to be newer than the bonus buffer because
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1574
		 * the ztest_get_data() callback does a dmu_read() of the
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1575
		 * open-context data, which may be different than the data
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1576
		 * as it was when the write was generated.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1577
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1578
		if (zd->zd_zilog->zl_replay) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1579
			ztest_bt_verify(bt, os, lr->lr_foid, offset,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1580
			    MAX(gen, bt->bt_gen), MAX(txg, lrtxg),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1581
			    bt->bt_crtxg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1582
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1583
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1584
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1585
		 * Set the bt's gen/txg to the bonus buffer's gen/txg
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1586
		 * so that all of the usual ASSERTs will work.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1587
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1588
		ztest_bt_generate(bt, os, lr->lr_foid, offset, gen, txg, crtxg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1589
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1590
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1591
	if (abuf == NULL) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1592
		dmu_write(os, lr->lr_foid, offset, length, data, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1593
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1594
		bcopy(data, abuf->b_data, length);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1595
		dmu_assign_arcbuf(db, offset, abuf, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1596
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1597
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1598
	(void) ztest_log_write(zd, tx, lr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1599
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1600
	dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1601
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1602
	dmu_tx_commit(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1603
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1604
	ztest_range_unlock(rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1605
	ztest_object_unlock(zd, lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1606
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1607
	return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1608
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1609
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1610
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1611
ztest_replay_truncate(ztest_ds_t *zd, lr_truncate_t *lr, boolean_t byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1612
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1613
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1614
	dmu_tx_t *tx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1615
	uint64_t txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1616
	rl_t *rl;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1617
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1618
	if (byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1619
		byteswap_uint64_array(lr, sizeof (*lr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1620
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1621
	ztest_object_lock(zd, lr->lr_foid, RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1622
	rl = ztest_range_lock(zd, lr->lr_foid, lr->lr_offset, lr->lr_length,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1623
	    RL_WRITER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1624
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1625
	tx = dmu_tx_create(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1626
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1627
	dmu_tx_hold_free(tx, lr->lr_foid, lr->lr_offset, lr->lr_length);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1628
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1629
	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1630
	if (txg == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1631
		ztest_range_unlock(rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1632
		ztest_object_unlock(zd, lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1633
		return (ENOSPC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1634
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1635
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1636
	VERIFY(dmu_free_range(os, lr->lr_foid, lr->lr_offset,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1637
	    lr->lr_length, tx) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1638
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1639
	(void) ztest_log_truncate(zd, tx, lr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1640
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1641
	dmu_tx_commit(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1642
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1643
	ztest_range_unlock(rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1644
	ztest_object_unlock(zd, lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1645
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1646
	return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1647
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1648
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1649
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1650
ztest_replay_setattr(ztest_ds_t *zd, lr_setattr_t *lr, boolean_t byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1651
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1652
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1653
	dmu_tx_t *tx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1654
	dmu_buf_t *db;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1655
	ztest_block_tag_t *bbt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1656
	uint64_t txg, lrtxg, crtxg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1657
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1658
	if (byteswap)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1659
		byteswap_uint64_array(lr, sizeof (*lr));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1660
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1661
	ztest_object_lock(zd, lr->lr_foid, RL_WRITER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1662
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1663
	VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1664
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1665
	tx = dmu_tx_create(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1666
	dmu_tx_hold_bonus(tx, lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1667
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1668
	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1669
	if (txg == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1670
		dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1671
		ztest_object_unlock(zd, lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1672
		return (ENOSPC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1673
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1674
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1675
	bbt = ztest_bt_bonus(db);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1676
	ASSERT3U(bbt->bt_magic, ==, BT_MAGIC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1677
	crtxg = bbt->bt_crtxg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1678
	lrtxg = lr->lr_common.lrc_txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1679
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1680
	if (zd->zd_zilog->zl_replay) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1681
		ASSERT(lr->lr_size != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1682
		ASSERT(lr->lr_mode != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1683
		ASSERT(lrtxg != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1684
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1685
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1686
		 * Randomly change the size and increment the generation.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1687
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1688
		lr->lr_size = (ztest_random(db->db_size / sizeof (*bbt)) + 1) *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1689
		    sizeof (*bbt);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1690
		lr->lr_mode = bbt->bt_gen + 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1691
		ASSERT(lrtxg == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1692
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1693
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1694
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1695
	 * Verify that the current bonus buffer is not newer than our txg.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1696
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1697
	ztest_bt_verify(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1698
	    MAX(txg, lrtxg), crtxg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1699
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1700
	dmu_buf_will_dirty(db, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1701
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1702
	ASSERT3U(lr->lr_size, >=, sizeof (*bbt));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1703
	ASSERT3U(lr->lr_size, <=, db->db_size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1704
	VERIFY3U(dmu_set_bonus(db, lr->lr_size, tx), ==, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1705
	bbt = ztest_bt_bonus(db);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1706
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1707
	ztest_bt_generate(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode, txg, crtxg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1708
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1709
	dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1710
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1711
	(void) ztest_log_setattr(zd, tx, lr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1712
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1713
	dmu_tx_commit(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1714
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1715
	ztest_object_unlock(zd, lr->lr_foid);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1716
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1717
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1718
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
zil_replay_func_t *ztest_replay_vector[TX_MAX_TYPE] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
	NULL,			/* 0 no such transaction type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
	ztest_replay_create,	/* TX_CREATE */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
	NULL,			/* TX_MKDIR */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
	NULL,			/* TX_MKXATTR */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
	NULL,			/* TX_SYMLINK */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
	ztest_replay_remove,	/* TX_REMOVE */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
	NULL,			/* TX_RMDIR */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1728
	NULL,			/* TX_LINK */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
	NULL,			/* TX_RENAME */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1730
	ztest_replay_write,	/* TX_WRITE */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1731
	ztest_replay_truncate,	/* TX_TRUNCATE */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1732
	ztest_replay_setattr,	/* TX_SETATTR */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
	NULL,			/* TX_ACL */
10800
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10693
diff changeset
  1734
	NULL,			/* TX_CREATE_ACL */
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10693
diff changeset
  1735
	NULL,			/* TX_CREATE_ATTR */
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10693
diff changeset
  1736
	NULL,			/* TX_CREATE_ACL_ATTR */
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10693
diff changeset
  1737
	NULL,			/* TX_MKDIR_ACL */
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10693
diff changeset
  1738
	NULL,			/* TX_MKDIR_ATTR */
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10693
diff changeset
  1739
	NULL,			/* TX_MKDIR_ACL_ATTR */
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10693
diff changeset
  1740
	NULL,			/* TX_WRITE2 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1744
 * ZIL get_data callbacks
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1745
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1746
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1747
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1748
ztest_get_done(zgd_t *zgd, int error)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1749
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1750
	ztest_ds_t *zd = zgd->zgd_private;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1751
	uint64_t object = zgd->zgd_rl->rl_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1752
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1753
	if (zgd->zgd_db)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1754
		dmu_buf_rele(zgd->zgd_db, zgd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1755
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1756
	ztest_range_unlock(zgd->zgd_rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1757
	ztest_object_unlock(zd, object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1758
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1759
	if (error == 0 && zgd->zgd_bp)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1760
		zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1761
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1762
	umem_free(zgd, sizeof (*zgd));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1763
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1764
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1765
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1766
ztest_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1767
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1768
	ztest_ds_t *zd = arg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1769
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1770
	uint64_t object = lr->lr_foid;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1771
	uint64_t offset = lr->lr_offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1772
	uint64_t size = lr->lr_length;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1773
	blkptr_t *bp = &lr->lr_blkptr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1774
	uint64_t txg = lr->lr_common.lrc_txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1775
	uint64_t crtxg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1776
	dmu_object_info_t doi;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1777
	dmu_buf_t *db;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1778
	zgd_t *zgd;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1779
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1780
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1781
	ztest_object_lock(zd, object, RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1782
	error = dmu_bonus_hold(os, object, FTAG, &db);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1783
	if (error) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1784
		ztest_object_unlock(zd, object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1785
		return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1786
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1787
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1788
	crtxg = ztest_bt_bonus(db)->bt_crtxg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1789
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1790
	if (crtxg == 0 || crtxg > txg) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1791
		dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1792
		ztest_object_unlock(zd, object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1793
		return (ENOENT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1794
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1795
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1796
	dmu_object_info_from_db(db, &doi);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1797
	dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1798
	db = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1799
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1800
	zgd = umem_zalloc(sizeof (*zgd), UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1801
	zgd->zgd_zilog = zd->zd_zilog;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1802
	zgd->zgd_private = zd;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1803
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1804
	if (buf != NULL) {	/* immediate write */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1805
		zgd->zgd_rl = ztest_range_lock(zd, object, offset, size,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1806
		    RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1807
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1808
		error = dmu_read(os, object, offset, size, buf,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1809
		    DMU_READ_NO_PREFETCH);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1810
		ASSERT(error == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1811
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1812
		size = doi.doi_data_block_size;
10945
b3afbf06f20d 6897933 zfs_get_data: assertion failed: db->db_offset == offset
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1813
		if (ISP2(size)) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1814
			offset = P2ALIGN(offset, size);
10945
b3afbf06f20d 6897933 zfs_get_data: assertion failed: db->db_offset == offset
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1815
		} else {
b3afbf06f20d 6897933 zfs_get_data: assertion failed: db->db_offset == offset
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1816
			ASSERT(offset < size);
b3afbf06f20d 6897933 zfs_get_data: assertion failed: db->db_offset == offset
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1817
			offset = 0;
b3afbf06f20d 6897933 zfs_get_data: assertion failed: db->db_offset == offset
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1818
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1819
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1820
		zgd->zgd_rl = ztest_range_lock(zd, object, offset, size,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1821
		    RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1822
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
  1823
		error = dmu_buf_hold(os, object, offset, zgd, &db,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
  1824
		    DMU_READ_NO_PREFETCH);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1825
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1826
		if (error == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1827
			zgd->zgd_db = db;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1828
			zgd->zgd_bp = bp;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1829
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1830
			ASSERT(db->db_offset == offset);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1831
			ASSERT(db->db_size == size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1832
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1833
			error = dmu_sync(zio, lr->lr_common.lrc_txg,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1834
			    ztest_get_done, zgd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1835
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1836
			if (error == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1837
				return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1838
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1839
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1840
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1841
	ztest_get_done(zgd, error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1842
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1843
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1844
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1845
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1846
static void *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1847
ztest_lr_alloc(size_t lrsize, char *name)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1848
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1849
	char *lr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1850
	size_t namesize = name ? strlen(name) + 1 : 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1851
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1852
	lr = umem_zalloc(lrsize + namesize, UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1853
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1854
	if (name)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1855
		bcopy(name, lr + lrsize, namesize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1856
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1857
	return (lr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1858
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1859
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1860
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1861
ztest_lr_free(void *lr, size_t lrsize, char *name)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1862
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1863
	size_t namesize = name ? strlen(name) + 1 : 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1864
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1865
	umem_free(lr, lrsize + namesize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1866
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1867
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1868
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1869
 * Lookup a bunch of objects.  Returns the number of objects not found.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1870
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1871
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1872
ztest_lookup(ztest_ds_t *zd, ztest_od_t *od, int count)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1873
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1874
	int missing = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1875
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1876
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1877
	ASSERT(_mutex_held(&zd->zd_dirobj_lock));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1878
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1879
	for (int i = 0; i < count; i++, od++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1880
		od->od_object = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1881
		error = zap_lookup(zd->zd_os, od->od_dir, od->od_name,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1882
		    sizeof (uint64_t), 1, &od->od_object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1883
		if (error) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1884
			ASSERT(error == ENOENT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1885
			ASSERT(od->od_object == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1886
			missing++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1887
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1888
			dmu_buf_t *db;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1889
			ztest_block_tag_t *bbt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1890
			dmu_object_info_t doi;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1891
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1892
			ASSERT(od->od_object != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1893
			ASSERT(missing == 0);	/* there should be no gaps */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1894
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1895
			ztest_object_lock(zd, od->od_object, RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1896
			VERIFY3U(0, ==, dmu_bonus_hold(zd->zd_os,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1897
			    od->od_object, FTAG, &db));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1898
			dmu_object_info_from_db(db, &doi);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1899
			bbt = ztest_bt_bonus(db);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1900
			ASSERT3U(bbt->bt_magic, ==, BT_MAGIC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1901
			od->od_type = doi.doi_type;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1902
			od->od_blocksize = doi.doi_data_block_size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1903
			od->od_gen = bbt->bt_gen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1904
			dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1905
			ztest_object_unlock(zd, od->od_object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1906
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1907
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1908
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1909
	return (missing);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1910
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1911
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1912
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1913
ztest_create(ztest_ds_t *zd, ztest_od_t *od, int count)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1914
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1915
	int missing = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1916
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1917
	ASSERT(_mutex_held(&zd->zd_dirobj_lock));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1918
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1919
	for (int i = 0; i < count; i++, od++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1920
		if (missing) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1921
			od->od_object = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1922
			missing++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1923
			continue;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1924
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1925
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1926
		lr_create_t *lr = ztest_lr_alloc(sizeof (*lr), od->od_name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1927
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1928
		lr->lr_doid = od->od_dir;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1929
		lr->lr_foid = 0;	/* 0 to allocate, > 0 to claim */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1930
		lr->lrz_type = od->od_crtype;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1931
		lr->lrz_blocksize = od->od_crblocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1932
		lr->lrz_ibshift = ztest_random_ibshift();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1933
		lr->lrz_bonustype = DMU_OT_UINT64_OTHER;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1934
		lr->lrz_bonuslen = dmu_bonus_max();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1935
		lr->lr_gen = od->od_crgen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1936
		lr->lr_crtime[0] = time(NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1937
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1938
		if (ztest_replay_create(zd, lr, B_FALSE) != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1939
			ASSERT(missing == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1940
			od->od_object = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1941
			missing++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1942
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1943
			od->od_object = lr->lr_foid;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1944
			od->od_type = od->od_crtype;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1945
			od->od_blocksize = od->od_crblocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1946
			od->od_gen = od->od_crgen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1947
			ASSERT(od->od_object != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1948
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1949
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1950
		ztest_lr_free(lr, sizeof (*lr), od->od_name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1951
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1952
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1953
	return (missing);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1954
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1955
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1956
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1957
ztest_remove(ztest_ds_t *zd, ztest_od_t *od, int count)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1958
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1959
	int missing = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1960
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1961
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1962
	ASSERT(_mutex_held(&zd->zd_dirobj_lock));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1963
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1964
	od += count - 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1965
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1966
	for (int i = count - 1; i >= 0; i--, od--) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1967
		if (missing) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1968
			missing++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1969
			continue;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1970
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1971
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1972
		if (od->od_object == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1973
			continue;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1974
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1975
		lr_remove_t *lr = ztest_lr_alloc(sizeof (*lr), od->od_name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1976
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1977
		lr->lr_doid = od->od_dir;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1978
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1979
		if ((error = ztest_replay_remove(zd, lr, B_FALSE)) != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1980
			ASSERT3U(error, ==, ENOSPC);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1981
			missing++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1982
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1983
			od->od_object = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1984
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1985
		ztest_lr_free(lr, sizeof (*lr), od->od_name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1986
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1987
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1988
	return (missing);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1989
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1990
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1991
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1992
ztest_write(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1993
    void *data)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1994
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1995
	lr_write_t *lr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1996
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1997
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1998
	lr = ztest_lr_alloc(sizeof (*lr) + size, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  1999
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2000
	lr->lr_foid = object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2001
	lr->lr_offset = offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2002
	lr->lr_length = size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2003
	lr->lr_blkoff = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2004
	BP_ZERO(&lr->lr_blkptr);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2005
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2006
	bcopy(data, lr + 1, size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2007
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2008
	error = ztest_replay_write(zd, lr, B_FALSE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2009
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2010
	ztest_lr_free(lr, sizeof (*lr) + size, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2011
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2012
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2013
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2014
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2015
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2016
ztest_truncate(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2017
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2018
	lr_truncate_t *lr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2019
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2020
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2021
	lr = ztest_lr_alloc(sizeof (*lr), NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2022
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2023
	lr->lr_foid = object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2024
	lr->lr_offset = offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2025
	lr->lr_length = size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2026
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2027
	error = ztest_replay_truncate(zd, lr, B_FALSE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2028
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2029
	ztest_lr_free(lr, sizeof (*lr), NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2030
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2031
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2032
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2033
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2034
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2035
ztest_setattr(ztest_ds_t *zd, uint64_t object)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2036
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2037
	lr_setattr_t *lr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2038
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2039
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2040
	lr = ztest_lr_alloc(sizeof (*lr), NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2041
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2042
	lr->lr_foid = object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2043
	lr->lr_size = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2044
	lr->lr_mode = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2045
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2046
	error = ztest_replay_setattr(zd, lr, B_FALSE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2047
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2048
	ztest_lr_free(lr, sizeof (*lr), NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2049
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2050
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2051
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2052
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2053
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2054
ztest_prealloc(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2055
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2056
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2057
	dmu_tx_t *tx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2058
	uint64_t txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2059
	rl_t *rl;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2060
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2061
	txg_wait_synced(dmu_objset_pool(os), 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2062
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2063
	ztest_object_lock(zd, object, RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2064
	rl = ztest_range_lock(zd, object, offset, size, RL_WRITER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2065
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2066
	tx = dmu_tx_create(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2067
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2068
	dmu_tx_hold_write(tx, object, offset, size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2069
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2070
	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2071
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2072
	if (txg != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2073
		dmu_prealloc(os, object, offset, size, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2074
		dmu_tx_commit(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2075
		txg_wait_synced(dmu_objset_pool(os), txg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2076
	} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2077
		(void) dmu_free_long_range(os, object, offset, size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2078
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2079
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2080
	ztest_range_unlock(rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2081
	ztest_object_unlock(zd, object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2082
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2083
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2084
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2085
ztest_io(ztest_ds_t *zd, uint64_t object, uint64_t offset)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2086
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2087
	ztest_block_tag_t wbt;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2088
	dmu_object_info_t doi;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2089
	enum ztest_io_type io_type;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2090
	uint64_t blocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2091
	void *data;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2092
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2093
	VERIFY(dmu_object_info(zd->zd_os, object, &doi) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2094
	blocksize = doi.doi_data_block_size;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2095
	data = umem_alloc(blocksize, UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2096
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2097
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2098
	 * Pick an i/o type at random, biased toward writing block tags.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2099
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2100
	io_type = ztest_random(ZTEST_IO_TYPES);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2101
	if (ztest_random(2) == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2102
		io_type = ZTEST_IO_WRITE_TAG;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2103
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2104
	(void) rw_rdlock(&zd->zd_zilog_lock);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2105
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2106
	switch (io_type) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2107
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2108
	case ZTEST_IO_WRITE_TAG:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2109
		ztest_bt_generate(&wbt, zd->zd_os, object, offset, 0, 0, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2110
		(void) ztest_write(zd, object, offset, sizeof (wbt), &wbt);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2111
		break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2112
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2113
	case ZTEST_IO_WRITE_PATTERN:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2114
		(void) memset(data, 'a' + (object + offset) % 5, blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2115
		if (ztest_random(2) == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2116
			/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2117
			 * Induce fletcher2 collisions to ensure that
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2118
			 * zio_ddt_collision() detects and resolves them
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2119
			 * when using fletcher2-verify for deduplication.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2120
			 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2121
			((uint64_t *)data)[0] ^= 1ULL << 63;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2122
			((uint64_t *)data)[4] ^= 1ULL << 63;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2123
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2124
		(void) ztest_write(zd, object, offset, blocksize, data);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2125
		break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2126
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2127
	case ZTEST_IO_WRITE_ZEROES:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2128
		bzero(data, blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2129
		(void) ztest_write(zd, object, offset, blocksize, data);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2130
		break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2131
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2132
	case ZTEST_IO_TRUNCATE:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2133
		(void) ztest_truncate(zd, object, offset, blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2134
		break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2135
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2136
	case ZTEST_IO_SETATTR:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2137
		(void) ztest_setattr(zd, object);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2138
		break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2139
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2140
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2141
	(void) rw_unlock(&zd->zd_zilog_lock);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2142
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2143
	umem_free(data, blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2144
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2145
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2146
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2147
 * Initialize an object description template.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2148
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2149
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2150
ztest_od_init(ztest_od_t *od, uint64_t id, char *tag, uint64_t index,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2151
    dmu_object_type_t type, uint64_t blocksize, uint64_t gen)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2152
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2153
	od->od_dir = ZTEST_DIROBJ;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2154
	od->od_object = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2155
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2156
	od->od_crtype = type;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2157
	od->od_crblocksize = blocksize ? blocksize : ztest_random_blocksize();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2158
	od->od_crgen = gen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2159
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2160
	od->od_type = DMU_OT_NONE;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2161
	od->od_blocksize = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2162
	od->od_gen = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2163
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2164
	(void) snprintf(od->od_name, sizeof (od->od_name), "%s(%lld)[%llu]",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2165
	    tag, (int64_t)id, index);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2166
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2167
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2168
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2169
 * Lookup or create the objects for a test using the od template.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2170
 * If the objects do not all exist, or if 'remove' is specified,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2171
 * remove any existing objects and create new ones.  Otherwise,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2172
 * use the existing objects.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2173
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2174
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2175
ztest_object_init(ztest_ds_t *zd, ztest_od_t *od, size_t size, boolean_t remove)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2176
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2177
	int count = size / sizeof (*od);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2178
	int rv = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2179
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2180
	VERIFY(mutex_lock(&zd->zd_dirobj_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2181
	if ((ztest_lookup(zd, od, count) != 0 || remove) &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2182
	    (ztest_remove(zd, od, count) != 0 ||
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2183
	    ztest_create(zd, od, count) != 0))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2184
		rv = -1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2185
	zd->zd_od = od;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2186
	VERIFY(mutex_unlock(&zd->zd_dirobj_lock) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2187
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2188
	return (rv);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2189
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2190
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2191
/* ARGSUSED */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2192
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2193
ztest_zil_commit(ztest_ds_t *zd, uint64_t id)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2194
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2195
	zilog_t *zilog = zd->zd_zilog;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2196
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2197
	(void) rw_rdlock(&zd->zd_zilog_lock);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2198
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  2199
	zil_commit(zilog, ztest_random(ZTEST_OBJECTS));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2200
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2201
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2202
	 * Remember the committed values in zd, which is in parent/child
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2203
	 * shared memory.  If we die, the next iteration of ztest_run()
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2204
	 * will verify that the log really does contain this record.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2205
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2206
	mutex_enter(&zilog->zl_lock);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2207
	ASSERT(zd->zd_shared != NULL);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2208
	ASSERT3U(zd->zd_shared->zd_seq, <=, zilog->zl_commit_lr_seq);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2209
	zd->zd_shared->zd_seq = zilog->zl_commit_lr_seq;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2210
	mutex_exit(&zilog->zl_lock);
13380
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2211
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2212
	(void) rw_unlock(&zd->zd_zilog_lock);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2213
}
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2214
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2215
/*
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2216
 * This function is designed to simulate the operations that occur during a
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2217
 * mount/unmount operation.  We hold the dataset across these operations in an
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2218
 * attempt to expose any implicit assumptions about ZIL management.
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2219
 */
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2220
/* ARGSUSED */
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2221
void
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2222
ztest_zil_remount(ztest_ds_t *zd, uint64_t id)
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2223
{
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2224
	objset_t *os = zd->zd_os;
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2225
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2226
	(void) rw_wrlock(&zd->zd_zilog_lock);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2227
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2228
	/* zfsvfs_teardown() */
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2229
	zil_close(zd->zd_zilog);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2230
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2231
	/* zfsvfs_setup() */
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2232
	VERIFY(zil_open(os, ztest_get_data) == zd->zd_zilog);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2233
	zil_replay(os, zd, ztest_replay_vector);
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2234
161b964a0e10 883 ZIL reuse during remount can lead to data corruption
Eric Schrock <Eric.Schrock@delphix.com>
parents: 13379
diff changeset
  2235
	(void) rw_unlock(&zd->zd_zilog_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2236
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2237
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2238
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2239
 * Verify that we can't destroy an active pool, create an existing pool,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2240
 * or create a pool with a bad vdev spec.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2241
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2242
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2243
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2244
ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2245
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2246
	ztest_shared_opts_t *zo = &ztest_opts;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2250
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2251
	 * Attempt to create using a bad file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2252
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2253
	nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2254
	VERIFY3U(ENOENT, ==,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2255
	    spa_create("ztest_bad_file", nvroot, NULL, NULL, NULL));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2256
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2257
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2258
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2259
	 * Attempt to create using a bad mirror.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2260
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2261
	nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 2, 1);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2262
	VERIFY3U(ENOENT, ==,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2263
	    spa_create("ztest_bad_mirror", nvroot, NULL, NULL, NULL));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2265
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2266
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2267
	 * Attempt to create an existing pool.  It shouldn't matter
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
	 * what's in the nvroot; we should fail with EEXIST.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2270
	(void) rw_rdlock(&ztest_name_lock);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2271
	nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2272
	VERIFY3U(EEXIST, ==, spa_create(zo->zo_pool, nvroot, NULL, NULL, NULL));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2273
	nvlist_free(nvroot);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2274
	VERIFY3U(0, ==, spa_open(zo->zo_pool, &spa, FTAG));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2275
	VERIFY3U(EBUSY, ==, spa_destroy(zo->zo_pool));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2276
	spa_close(spa, FTAG);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2277
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2278
	(void) rw_unlock(&ztest_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2279
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2280
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2281
static vdev_t *
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2282
vdev_lookup_by_path(vdev_t *vd, const char *path)
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2283
{
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2284
	vdev_t *mvd;
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2285
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2286
	if (vd->vdev_path != NULL && strcmp(path, vd->vdev_path) == 0)
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2287
		return (vd);
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2288
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2289
	for (int c = 0; c < vd->vdev_children; c++)
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2290
		if ((mvd = vdev_lookup_by_path(vd->vdev_child[c], path)) !=
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2291
		    NULL)
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2292
			return (mvd);
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2293
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2294
	return (NULL);
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2295
}
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2296
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2297
/*
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2298
 * Find the first available hole which can be used as a top-level.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2299
 */
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2300
int
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2301
find_vdev_hole(spa_t *spa)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2302
{
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2303
	vdev_t *rvd = spa->spa_root_vdev;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2304
	int c;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2305
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2306
	ASSERT(spa_config_held(spa, SCL_VDEV, RW_READER) == SCL_VDEV);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2307
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2308
	for (c = 0; c < rvd->vdev_children; c++) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2309
		vdev_t *cvd = rvd->vdev_child[c];
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2310
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2311
		if (cvd->vdev_ishole)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2312
			break;
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2313
	}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2314
	return (c);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2315
}
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2316
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2317
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2318
 * Verify that vdev_add() works as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2319
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2320
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2321
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2322
ztest_vdev_add_remove(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2323
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2324
	ztest_shared_t *zs = ztest_shared;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2325
	spa_t *spa = ztest_spa;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2326
	uint64_t leaves;
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2327
	uint64_t guid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2330
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2331
	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2332
	leaves =
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2333
	    MAX(zs->zs_mirrors + zs->zs_splits, 1) * ztest_opts.zo_raidz;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2334
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2335
	spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2336
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2337
	ztest_shared->zs_vdev_next_leaf = find_vdev_hole(spa) * leaves;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2338
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2339
	/*
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2340
	 * If we have slogs then remove them 1/4 of the time.
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2341
	 */
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2342
	if (spa_has_slogs(spa) && ztest_random(4) == 0) {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2343
		/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2344
		 * Grab the guid from the head of the log class rotor.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2345
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2346
		guid = spa_log_class(spa)->mc_rotor->mg_vd->vdev_guid;
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2347
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2348
		spa_config_exit(spa, SCL_VDEV, FTAG);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2349
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2350
		/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2351
		 * We have to grab the zs_name_lock as writer to
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2352
		 * prevent a race between removing a slog (dmu_objset_find)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2353
		 * and destroying a dataset. Removing the slog will
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2354
		 * grab a reference on the dataset which may cause
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2355
		 * dmu_objset_destroy() to fail with EBUSY thus
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2356
		 * leaving the dataset in an inconsistent state.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2357
		 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2358
		VERIFY(rw_wrlock(&ztest_name_lock) == 0);
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2359
		error = spa_vdev_remove(spa, guid, B_FALSE);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2360
		VERIFY(rw_unlock(&ztest_name_lock) == 0);
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2361
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2362
		if (error && error != EEXIST)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2363
			fatal(0, "spa_vdev_remove() = %d", error);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2364
	} else {
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2365
		spa_config_exit(spa, SCL_VDEV, FTAG);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2366
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2367
		/*
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2368
		 * Make 1/4 of the devices be log devices.
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2369
		 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2370
		nvroot = make_vdev_root(NULL, NULL,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2371
		    ztest_opts.zo_vdev_size, 0,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2372
		    ztest_random(4) == 0, ztest_opts.zo_raidz,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2373
		    zs->zs_mirrors, 1);
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2374
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2375
		error = spa_vdev_add(spa, nvroot);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2376
		nvlist_free(nvroot);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2377
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2378
		if (error == ENOSPC)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2379
			ztest_record_enospc("spa_vdev_add");
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2380
		else if (error != 0)
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2381
			fatal(0, "spa_vdev_add() = %d", error);
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  2382
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2383
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2384
	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2385
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2386
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2387
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2388
 * Verify that adding/removing aux devices (l2arc, hot spare) works as expected.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2389
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2390
/* ARGSUSED */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2391
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2392
ztest_vdev_aux_add_remove(ztest_ds_t *zd, uint64_t id)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2393
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2394
	ztest_shared_t *zs = ztest_shared;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2395
	spa_t *spa = ztest_spa;
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2396
	vdev_t *rvd = spa->spa_root_vdev;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2397
	spa_aux_vdev_t *sav;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2398
	char *aux;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2399
	uint64_t guid = 0;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2400
	int error;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2401
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2402
	if (ztest_random(2) == 0) {
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2403
		sav = &spa->spa_spares;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2404
		aux = ZPOOL_CONFIG_SPARES;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2405
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2406
		sav = &spa->spa_l2cache;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2407
		aux = ZPOOL_CONFIG_L2CACHE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2408
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2409
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2410
	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2411
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2412
	spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2413
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2414
	if (sav->sav_count != 0 && ztest_random(4) == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2415
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2416
		 * Pick a random device to remove.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2417
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2418
		guid = sav->sav_vdevs[ztest_random(sav->sav_count)]->vdev_guid;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2419
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2420
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2421
		 * Find an unused device we can add.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2422
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2423
		zs->zs_vdev_aux = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2424
		for (;;) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2425
			char path[MAXPATHLEN];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2426
			int c;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2427
			(void) snprintf(path, sizeof (path), ztest_aux_template,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2428
			    ztest_opts.zo_dir, ztest_opts.zo_pool, aux,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2429
			    zs->zs_vdev_aux);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2430
			for (c = 0; c < sav->sav_count; c++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2431
				if (strcmp(sav->sav_vdevs[c]->vdev_path,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2432
				    path) == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2433
					break;
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2434
			if (c == sav->sav_count &&
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2435
			    vdev_lookup_by_path(rvd, path) == NULL)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2436
				break;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2437
			zs->zs_vdev_aux++;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2438
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2439
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2440
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2441
	spa_config_exit(spa, SCL_VDEV, FTAG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2442
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2443
	if (guid == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2444
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2445
		 * Add a new device.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2446
		 */
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2447
		nvlist_t *nvroot = make_vdev_root(NULL, aux,
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2448
		    (ztest_opts.zo_vdev_size * 5) / 4, 0, 0, 0, 0, 1);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2449
		error = spa_vdev_add(spa, nvroot);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2450
		if (error != 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2451
			fatal(0, "spa_vdev_add(%p) = %d", nvroot, error);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2452
		nvlist_free(nvroot);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2453
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2454
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2455
		 * Remove an existing device.  Sometimes, dirty its
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2456
		 * vdev state first to make sure we handle removal
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2457
		 * of devices that have pending state changes.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2458
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2459
		if (ztest_random(2) == 0)
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2460
			(void) vdev_online(spa, guid, 0, NULL);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2461
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2462
		error = spa_vdev_remove(spa, guid, B_FALSE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2463
		if (error != 0 && error != EBUSY)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2464
			fatal(0, "spa_vdev_remove(%llu) = %d", guid, error);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2465
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2466
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2467
	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2468
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2469
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2470
/*
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2471
 * split a pool if it has mirror tlvdevs
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2472
 */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2473
/* ARGSUSED */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2474
void
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2475
ztest_split_pool(ztest_ds_t *zd, uint64_t id)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2476
{
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2477
	ztest_shared_t *zs = ztest_shared;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2478
	spa_t *spa = ztest_spa;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2479
	vdev_t *rvd = spa->spa_root_vdev;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2480
	nvlist_t *tree, **child, *config, *split, **schild;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2481
	uint_t c, children, schildren = 0, lastlogid = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2482
	int error = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2483
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2484
	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2485
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2486
	/* ensure we have a useable config; mirrors of raidz aren't supported */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2487
	if (zs->zs_mirrors < 3 || ztest_opts.zo_raidz > 1) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2488
		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2489
		return;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2490
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2491
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2492
	/* clean up the old pool, if any */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2493
	(void) spa_destroy("splitp");
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2494
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2495
	spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2496
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2497
	/* generate a config from the existing config */
11864
2f59639f6ea4 6923241 'zpool split' set dedupditto as invalid value cause device offline
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11818
diff changeset
  2498
	mutex_enter(&spa->spa_props_lock);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2499
	VERIFY(nvlist_lookup_nvlist(spa->spa_config, ZPOOL_CONFIG_VDEV_TREE,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2500
	    &tree) == 0);
11864
2f59639f6ea4 6923241 'zpool split' set dedupditto as invalid value cause device offline
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11818
diff changeset
  2501
	mutex_exit(&spa->spa_props_lock);
2f59639f6ea4 6923241 'zpool split' set dedupditto as invalid value cause device offline
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11818
diff changeset
  2502
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2503
	VERIFY(nvlist_lookup_nvlist_array(tree, ZPOOL_CONFIG_CHILDREN, &child,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2504
	    &children) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2505
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2506
	schild = malloc(rvd->vdev_children * sizeof (nvlist_t *));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2507
	for (c = 0; c < children; c++) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2508
		vdev_t *tvd = rvd->vdev_child[c];
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2509
		nvlist_t **mchild;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2510
		uint_t mchildren;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2511
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2512
		if (tvd->vdev_islog || tvd->vdev_ops == &vdev_hole_ops) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2513
			VERIFY(nvlist_alloc(&schild[schildren], NV_UNIQUE_NAME,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2514
			    0) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2515
			VERIFY(nvlist_add_string(schild[schildren],
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2516
			    ZPOOL_CONFIG_TYPE, VDEV_TYPE_HOLE) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2517
			VERIFY(nvlist_add_uint64(schild[schildren],
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2518
			    ZPOOL_CONFIG_IS_HOLE, 1) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2519
			if (lastlogid == 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2520
				lastlogid = schildren;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2521
			++schildren;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2522
			continue;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2523
		}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2524
		lastlogid = 0;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2525
		VERIFY(nvlist_lookup_nvlist_array(child[c],
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2526
		    ZPOOL_CONFIG_CHILDREN, &mchild, &mchildren) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2527
		VERIFY(nvlist_dup(mchild[0], &schild[schildren++], 0) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2528
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2529
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2530
	/* OK, create a config that can be used to split */
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2531
	VERIFY(nvlist_alloc(&split, NV_UNIQUE_NAME, 0) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2532
	VERIFY(nvlist_add_string(split, ZPOOL_CONFIG_TYPE,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2533
	    VDEV_TYPE_ROOT) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2534
	VERIFY(nvlist_add_nvlist_array(split, ZPOOL_CONFIG_CHILDREN, schild,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2535
	    lastlogid != 0 ? lastlogid : schildren) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2536
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2537
	VERIFY(nvlist_alloc(&config, NV_UNIQUE_NAME, 0) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2538
	VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, split) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2539
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2540
	for (c = 0; c < schildren; c++)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2541
		nvlist_free(schild[c]);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2542
	free(schild);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2543
	nvlist_free(split);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2544
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2545
	spa_config_exit(spa, SCL_VDEV, FTAG);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2546
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2547
	(void) rw_wrlock(&ztest_name_lock);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2548
	error = spa_vdev_split_mirror(spa, "splitp", config, NULL, B_FALSE);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2549
	(void) rw_unlock(&ztest_name_lock);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2550
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2551
	nvlist_free(config);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2552
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2553
	if (error == 0) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2554
		(void) printf("successful split - results:\n");
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2555
		mutex_enter(&spa_namespace_lock);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2556
		show_pool_stats(spa);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2557
		show_pool_stats(spa_lookup("splitp"));
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2558
		mutex_exit(&spa_namespace_lock);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2559
		++zs->zs_splits;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2560
		--zs->zs_mirrors;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2561
	}
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2562
	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2563
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2564
}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2565
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2566
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2567
 * Verify that we can attach and detach devices.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2569
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2570
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2571
ztest_vdev_attach_detach(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2573
	ztest_shared_t *zs = ztest_shared;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2574
	spa_t *spa = ztest_spa;
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2575
	spa_aux_vdev_t *sav = &spa->spa_spares;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2576
	vdev_t *rvd = spa->spa_root_vdev;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2577
	vdev_t *oldvd, *newvd, *pvd;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2578
	nvlist_t *root;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2579
	uint64_t leaves;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2580
	uint64_t leaf, top;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2581
	uint64_t ashift = ztest_get_ashift();
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2582
	uint64_t oldguid, pguid;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2583
	size_t oldsize, newsize;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2584
	char oldpath[MAXPATHLEN], newpath[MAXPATHLEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2585
	int replacing;
7793
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2586
	int oldvd_has_siblings = B_FALSE;
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2587
	int newvd_is_spare = B_FALSE;
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2588
	int oldvd_is_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
	int error, expected_error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2591
	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2592
	leaves = MAX(zs->zs_mirrors, 1) * ztest_opts.zo_raidz;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2593
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2594
	spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2596
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2597
	 * Decide whether to do an attach or a replace.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2598
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2599
	replacing = ztest_random(2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2600
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2601
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2602
	 * Pick a random top-level vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2603
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2604
	top = ztest_random_vdev_top(spa, B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2605
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2606
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2607
	 * Pick a random leaf within it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2608
	 */
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11422
diff changeset
  2609
	leaf = ztest_random(leaves);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2611
	/*
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2612
	 * Locate this vdev.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2613
	 */
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2614
	oldvd = rvd->vdev_child[top];
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2615
	if (zs->zs_mirrors >= 1) {
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2616
		ASSERT(oldvd->vdev_ops == &vdev_mirror_ops);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  2617
		ASSERT(oldvd->vdev_children >= zs->zs_mirrors);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2618
		oldvd = oldvd->vdev_child[leaf / ztest_opts.zo_raidz];
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2619
	}
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2620
	if (ztest_opts.zo_raidz > 1) {
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2621
		ASSERT(oldvd->vdev_ops == &vdev_raidz_ops);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2622
		ASSERT(oldvd->vdev_children == ztest_opts.zo_raidz);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2623
		oldvd = oldvd->vdev_child[leaf % ztest_opts.zo_raidz];
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2624
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2625
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2626
	/*
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2627
	 * If we're already doing an attach or replace, oldvd may be a
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2628
	 * mirror vdev -- in which case, pick a random child.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2629
	 */
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2630
	while (oldvd->vdev_children != 0) {
7793
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2631
		oldvd_has_siblings = B_TRUE;
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2632
		ASSERT(oldvd->vdev_children >= 2);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2633
		oldvd = oldvd->vdev_child[ztest_random(oldvd->vdev_children)];
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2634
	}
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2635
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2636
	oldguid = oldvd->vdev_guid;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2637
	oldsize = vdev_get_min_asize(oldvd);
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2638
	oldvd_is_log = oldvd->vdev_top->vdev_islog;
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2639
	(void) strcpy(oldpath, oldvd->vdev_path);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2640
	pvd = oldvd->vdev_parent;
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2641
	pguid = pvd->vdev_guid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2642
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2643
	/*
7793
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2644
	 * If oldvd has siblings, then half of the time, detach it.
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2645
	 */
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2646
	if (oldvd_has_siblings && ztest_random(2) == 0) {
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2647
		spa_config_exit(spa, SCL_VDEV, FTAG);
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2648
		error = spa_vdev_detach(spa, oldguid, pguid, B_FALSE);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2649
		if (error != 0 && error != ENODEV && error != EBUSY &&
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2650
		    error != ENOTSUP)
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  2651
			fatal(0, "detach (%s) returned %d", oldpath, error);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2652
		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
7793
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2653
		return;
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2654
	}
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2655
4dbbc0a3f135 6755897 recursive mutex enter in spa_vdev_enter when running test suite
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7768
diff changeset
  2656
	/*
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2657
	 * For the new vdev, choose with equal probability between the two
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2658
	 * standard paths (ending in either 'a' or 'b') or a random hot spare.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2659
	 */
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2660
	if (sav->sav_count != 0 && ztest_random(3) == 0) {
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2661
		newvd = sav->sav_vdevs[ztest_random(sav->sav_count)];
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2662
		newvd_is_spare = B_TRUE;
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2663
		(void) strcpy(newpath, newvd->vdev_path);
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2664
	} else {
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2665
		(void) snprintf(newpath, sizeof (newpath), ztest_dev_template,
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2666
		    ztest_opts.zo_dir, ztest_opts.zo_pool,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2667
		    top * leaves + leaf);
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2668
		if (ztest_random(2) == 0)
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2669
			newpath[strlen(newpath) - 1] = 'b';
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2670
		newvd = vdev_lookup_by_path(rvd, newpath);
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2671
	}
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2672
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2673
	if (newvd) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2674
		newsize = vdev_get_min_asize(newvd);
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2675
	} else {
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2676
		/*
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2677
		 * Make newsize a little bigger or smaller than oldsize.
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2678
		 * If it's smaller, the attach should fail.
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2679
		 * If it's larger, and we're doing a replace,
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2680
		 * we should get dynamic LUN growth when we're done.
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2681
		 */
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2682
		newsize = 10 * oldsize / (9 + ztest_random(3));
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2683
	}
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
	 * If pvd is not a mirror or root, the attach should fail with ENOTSUP,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2687
	 * unless it's a replace; in that case any non-replacing parent is OK.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2688
	 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2689
	 * If newvd is already part of the pool, it should fail with EBUSY.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2690
	 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2691
	 * If newvd is too small, it should fail with EOVERFLOW.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2692
	 */
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2693
	if (pvd->vdev_ops != &vdev_mirror_ops &&
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2694
	    pvd->vdev_ops != &vdev_root_ops && (!replacing ||
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2695
	    pvd->vdev_ops == &vdev_replacing_ops ||
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2696
	    pvd->vdev_ops == &vdev_spare_ops))
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2697
		expected_error = ENOTSUP;
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2698
	else if (newvd_is_spare && (!replacing || oldvd_is_log))
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2699
		expected_error = ENOTSUP;
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2700
	else if (newvd == oldvd)
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2701
		expected_error = replacing ? 0 : EBUSY;
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2702
	else if (vdev_lookup_by_path(rvd, newpath) != NULL)
2174
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2113
diff changeset
  2703
		expected_error = EBUSY;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2704
	else if (newsize < oldsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2705
		expected_error = EOVERFLOW;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2706
	else if (ashift > oldvd->vdev_top->vdev_ashift)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2707
		expected_error = EDOM;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2708
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2709
		expected_error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2710
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2711
	spa_config_exit(spa, SCL_VDEV, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2712
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2713
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2714
	 * Build the nvlist describing newpath.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2715
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2716
	root = make_vdev_root(newpath, NULL, newvd == NULL ? newsize : 0,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  2717
	    ashift, 0, 0, 0, 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2718
7768
7d2fd61355d7 6754946 assertion failure in vdev_label_init() under zpool_remove_003_pos test
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7762
diff changeset
  2719
	error = spa_vdev_attach(spa, oldguid, root, replacing);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2720
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
	nvlist_free(root);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2723
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
	 * If our parent was the replacing vdev, but the replace completed,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2725
	 * then instead of failing with ENOTSUP we may either succeed,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2726
	 * fail with ENODEV, or fail with EOVERFLOW.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2727
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2728
	if (expected_error == ENOTSUP &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
	    (error == 0 || error == ENODEV || error == EOVERFLOW))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2730
		expected_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2731
797
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  2732
	/*
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  2733
	 * 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
  2734
	 */
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6689
diff changeset
  2735
	if (error == EOVERFLOW || error == EBUSY)
797
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  2736
		expected_error = error;
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  2737
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6689
diff changeset
  2738
	/* XXX workaround 6690467 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6689
diff changeset
  2739
	if (error != expected_error && expected_error != EBUSY) {
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6689
diff changeset
  2740
		fatal(0, "attach (%s %llu, %s %llu, %d) "
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6689
diff changeset
  2741
		    "returned %d, expected %d",
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6689
diff changeset
  2742
		    oldpath, (longlong_t)oldsize, newpath,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6689
diff changeset
  2743
		    (longlong_t)newsize, replacing, error, expected_error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2744
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2745
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2746
	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2747
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2749
/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2750
 * Callback function which expands the physical size of the vdev.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2751
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2752
vdev_t *
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2753
grow_vdev(vdev_t *vd, void *arg)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2754
{
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2755
	spa_t *spa = vd->vdev_spa;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2756
	size_t *newsize = arg;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2757
	size_t fsize;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2758
	int fd;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2759
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2760
	ASSERT(spa_config_held(spa, SCL_STATE, RW_READER) == SCL_STATE);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2761
	ASSERT(vd->vdev_ops->vdev_op_leaf);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2762
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2763
	if ((fd = open(vd->vdev_path, O_RDWR)) == -1)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2764
		return (vd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2765
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2766
	fsize = lseek(fd, 0, SEEK_END);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2767
	(void) ftruncate(fd, *newsize);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2768
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2769
	if (ztest_opts.zo_verbose >= 6) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2770
		(void) printf("%s grew from %lu to %lu bytes\n",
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2771
		    vd->vdev_path, (ulong_t)fsize, (ulong_t)*newsize);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2772
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2773
	(void) close(fd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2774
	return (NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2775
}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2776
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2777
/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2778
 * Callback function which expands a given vdev by calling vdev_online().
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2779
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2780
/* ARGSUSED */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2781
vdev_t *
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2782
online_vdev(vdev_t *vd, void *arg)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2783
{
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2784
	spa_t *spa = vd->vdev_spa;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2785
	vdev_t *tvd = vd->vdev_top;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2786
	uint64_t guid = vd->vdev_guid;
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2787
	uint64_t generation = spa->spa_config_generation + 1;
10850
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2788
	vdev_state_t newstate = VDEV_STATE_UNKNOWN;
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2789
	int error;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2790
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2791
	ASSERT(spa_config_held(spa, SCL_STATE, RW_READER) == SCL_STATE);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2792
	ASSERT(vd->vdev_ops->vdev_op_leaf);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2793
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2794
	/* Calling vdev_online will initialize the new metaslabs */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2795
	spa_config_exit(spa, SCL_STATE, spa);
10850
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2796
	error = vdev_online(spa, guid, ZFS_ONLINE_EXPAND, &newstate);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2797
	spa_config_enter(spa, SCL_STATE, spa, RW_READER);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2798
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2799
	/*
10850
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2800
	 * If vdev_online returned an error or the underlying vdev_open
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2801
	 * failed then we abort the expand. The only way to know that
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2802
	 * vdev_open fails is by checking the returned newstate.
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2803
	 */
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2804
	if (error || newstate != VDEV_STATE_HEALTHY) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2805
		if (ztest_opts.zo_verbose >= 5) {
10850
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2806
			(void) printf("Unable to expand vdev, state %llu, "
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2807
			    "error %d\n", (u_longlong_t)newstate, error);
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2808
		}
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2809
		return (vd);
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2810
	}
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2811
	ASSERT3U(newstate, ==, VDEV_STATE_HEALTHY);
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2812
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10801
diff changeset
  2813
	/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2814
	 * Since we dropped the lock we need to ensure that we're
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2815
	 * still talking to the original vdev. It's possible this
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2816
	 * vdev may have been detached/replaced while we were
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2817
	 * trying to online it.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2818
	 */
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2819
	if (generation != spa->spa_config_generation) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2820
		if (ztest_opts.zo_verbose >= 5) {
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2821
			(void) printf("vdev configuration has changed, "
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2822
			    "guid %llu, state %llu, expected gen %llu, "
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2823
			    "got gen %llu\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2824
			    (u_longlong_t)guid,
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2825
			    (u_longlong_t)tvd->vdev_state,
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2826
			    (u_longlong_t)generation,
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2827
			    (u_longlong_t)spa->spa_config_generation);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2828
		}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2829
		return (vd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2830
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2831
	return (NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2832
}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2833
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2834
/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2835
 * Traverse the vdev tree calling the supplied function.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2836
 * We continue to walk the tree until we either have walked all
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2837
 * children or we receive a non-NULL return from the callback.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2838
 * If a NULL callback is passed, then we just return back the first
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2839
 * leaf vdev we encounter.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2840
 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2841
vdev_t *
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2842
vdev_walk_tree(vdev_t *vd, vdev_t *(*func)(vdev_t *, void *), void *arg)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2843
{
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2844
	if (vd->vdev_ops->vdev_op_leaf) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2845
		if (func == NULL)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2846
			return (vd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2847
		else
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2848
			return (func(vd, arg));
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2849
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2850
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2851
	for (uint_t c = 0; c < vd->vdev_children; c++) {
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2852
		vdev_t *cvd = vd->vdev_child[c];
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2853
		if ((cvd = vdev_walk_tree(cvd, func, arg)) != NULL)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2854
			return (cvd);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2855
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2856
	return (NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2857
}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2858
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2859
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2860
 * Verify that dynamic LUN growth works as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2861
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2862
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2863
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2864
ztest_vdev_LUN_growth(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2865
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2866
	spa_t *spa = ztest_spa;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2867
	vdev_t *vd, *tvd;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2868
	metaslab_class_t *mc;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2869
	metaslab_group_t *mg;
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2870
	size_t psize, newsize;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2871
	uint64_t top;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2872
	uint64_t old_class_space, new_class_space, old_ms_count, new_ms_count;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2873
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2874
	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2875
	spa_config_enter(spa, SCL_STATE, spa, RW_READER);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2876
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2877
	top = ztest_random_vdev_top(spa, B_TRUE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2878
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2879
	tvd = spa->spa_root_vdev->vdev_child[top];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2880
	mg = tvd->vdev_mg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2881
	mc = mg->mg_class;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2882
	old_ms_count = tvd->vdev_ms_count;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2883
	old_class_space = metaslab_class_get_space(mc);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2884
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2885
	/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2886
	 * Determine the size of the first leaf vdev associated with
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2887
	 * our top-level device.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2888
	 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2889
	vd = vdev_walk_tree(tvd, NULL, NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2890
	ASSERT3P(vd, !=, NULL);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2891
	ASSERT(vd->vdev_ops->vdev_op_leaf);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2892
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2893
	psize = vd->vdev_psize;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2894
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2895
	/*
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2896
	 * We only try to expand the vdev if it's healthy, less than 4x its
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2897
	 * original size, and it has a valid psize.
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2898
	 */
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2899
	if (tvd->vdev_state != VDEV_STATE_HEALTHY ||
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2900
	    psize == 0 || psize >= 4 * ztest_opts.zo_vdev_size) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2901
		spa_config_exit(spa, SCL_STATE, spa);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2902
		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2903
		return;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2904
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2905
	ASSERT(psize > 0);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2906
	newsize = psize + psize / 8;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2907
	ASSERT3U(newsize, >, psize);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2908
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2909
	if (ztest_opts.zo_verbose >= 6) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2910
		(void) printf("Expanding LUN %s from %lu to %lu\n",
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2911
		    vd->vdev_path, (ulong_t)psize, (ulong_t)newsize);
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2912
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2913
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2914
	/*
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2915
	 * Growing the vdev is a two step process:
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2916
	 *	1). expand the physical size (i.e. relabel)
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2917
	 *	2). online the vdev to create the new metaslabs
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2918
	 */
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2919
	if (vdev_walk_tree(tvd, grow_vdev, &newsize) != NULL ||
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2920
	    vdev_walk_tree(tvd, online_vdev, NULL) != NULL ||
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2921
	    tvd->vdev_state != VDEV_STATE_HEALTHY) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2922
		if (ztest_opts.zo_verbose >= 5) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2923
			(void) printf("Could not expand LUN because "
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  2924
			    "the vdev configuration changed.\n");
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2925
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2926
		spa_config_exit(spa, SCL_STATE, spa);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2927
		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2928
		return;
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2929
	}
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2930
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2931
	spa_config_exit(spa, SCL_STATE, spa);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2932
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2933
	/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2934
	 * Expanding the LUN will update the config asynchronously,
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2935
	 * thus we must wait for the async thread to complete any
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2936
	 * pending tasks before proceeding.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2937
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2938
	for (;;) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2939
		boolean_t done;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2940
		mutex_enter(&spa->spa_async_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2941
		done = (spa->spa_async_thread == NULL && !spa->spa_async_tasks);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2942
		mutex_exit(&spa->spa_async_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2943
		if (done)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2944
			break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2945
		txg_wait_synced(spa_get_dsl(spa), 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2946
		(void) poll(NULL, 0, 100);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2947
	}
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2948
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2949
	spa_config_enter(spa, SCL_STATE, spa, RW_READER);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2950
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2951
	tvd = spa->spa_root_vdev->vdev_child[top];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2952
	new_ms_count = tvd->vdev_ms_count;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2953
	new_class_space = metaslab_class_get_space(mc);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2954
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2955
	if (tvd->vdev_mg != mg || mg->mg_class != mc) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2956
		if (ztest_opts.zo_verbose >= 5) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2957
			(void) printf("Could not verify LUN expansion due to "
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2958
			    "intervening vdev offline or remove.\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2959
		}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2960
		spa_config_exit(spa, SCL_STATE, spa);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2961
		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2962
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2963
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2964
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2965
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2966
	 * Make sure we were able to grow the vdev.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2967
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2968
	if (new_ms_count <= old_ms_count)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2969
		fatal(0, "LUN expansion failed: ms_count %llu <= %llu\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2970
		    old_ms_count, new_ms_count);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2971
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2972
	/*
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2973
	 * Make sure we were able to grow the pool.
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2974
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2975
	if (new_class_space <= old_class_space)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2976
		fatal(0, "LUN expansion failed: class_space %llu <= %llu\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2977
		    old_class_space, new_class_space);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2978
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2979
	if (ztest_opts.zo_verbose >= 5) {
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2980
		char oldnumbuf[6], newnumbuf[6];
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2981
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2982
		nicenum(old_class_space, oldnumbuf);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2983
		nicenum(new_class_space, newnumbuf);
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2984
		(void) printf("%s grew from %s to %s\n",
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2985
		    spa->spa_name, oldnumbuf, newnumbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2986
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2987
9816
847676ec1c5b PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents: 9691
diff changeset
  2988
	spa_config_exit(spa, SCL_STATE, spa);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  2989
	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2990
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2991
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2992
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2993
 * Verify that dmu_objset_{create,destroy,open,close} work as expected.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2994
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2995
/* ARGSUSED */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2996
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2997
ztest_objset_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2998
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  2999
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3000
	 * Create the objects common to all ztest datasets.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3001
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3002
	VERIFY(zap_create_claim(os, ZTEST_DIROBJ,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3003
	    DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3004
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3005
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3006
static int
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3007
ztest_dataset_create(char *dsname)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3008
{
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3009
	uint64_t zilset = ztest_random(100);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3010
	int err = dmu_objset_create(dsname, DMU_OST_OTHER, 0,
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3011
	    ztest_objset_create_cb, NULL);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3012
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3013
	if (err || zilset < 80)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3014
		return (err);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3015
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3016
	if (ztest_opts.zo_verbose >= 6)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3017
		(void) printf("Setting dataset %s to sync always\n", dsname);
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3018
	return (ztest_dsl_prop_set_uint64(dsname, ZFS_PROP_SYNC,
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3019
	    ZFS_SYNC_ALWAYS, B_FALSE));
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3020
}
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3021
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3022
/* ARGSUSED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3023
static int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11125
diff changeset
  3024
ztest_objset_destroy_cb(const char *name, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3025
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3026
	objset_t *os;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3027
	dmu_object_info_t doi;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3028
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3029
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3030
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3031
	 * Verify that the dataset contains a directory object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3032
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3033
	VERIFY3U(0, ==, dmu_objset_hold(name, FTAG, &os));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3034
	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
  3035
	if (error != ENOENT) {
1efa8b3d1296 6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents: 1646
diff changeset
  3036
		/* 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
  3037
		ASSERT3U(error, ==, 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3038
		ASSERT3U(doi.doi_type, ==, DMU_OT_ZAP_OTHER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3039
		ASSERT3S(doi.doi_physical_blocks_512, >=, 0);
1731
1efa8b3d1296 6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents: 1646
diff changeset
  3040
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3041
	dmu_objset_rele(os, FTAG);
789
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
	 * Destroy the dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3045
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3046
	VERIFY3U(0, ==, dmu_objset_destroy(name, B_FALSE));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2174
diff changeset
  3047
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3048
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3049
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3050
static boolean_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3051
ztest_snapshot_create(char *osname, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3052
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3053
	char snapname[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3054
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3055
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3056
	(void) snprintf(snapname, MAXNAMELEN, "%s@%llu", osname,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3057
	    (u_longlong_t)id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3058
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3059
	error = dmu_objset_snapshot(osname, strchr(snapname, '@') + 1,
13055
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  3060
	    NULL, NULL, B_FALSE, B_FALSE, -1);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3061
	if (error == ENOSPC) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3062
		ztest_record_enospc(FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3063
		return (B_FALSE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3064
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3065
	if (error != 0 && error != EEXIST)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3066
		fatal(0, "ztest_snapshot_create(%s) = %d", snapname, error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3067
	return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3068
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3069
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3070
static boolean_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3071
ztest_snapshot_destroy(char *osname, uint64_t id)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3072
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3073
	char snapname[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3074
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3075
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3076
	(void) snprintf(snapname, MAXNAMELEN, "%s@%llu", osname,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3077
	    (u_longlong_t)id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3078
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3079
	error = dmu_objset_destroy(snapname, B_FALSE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3080
	if (error != 0 && error != ENOENT)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3081
		fatal(0, "ztest_snapshot_destroy(%s) = %d", snapname, error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3082
	return (B_TRUE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3083
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3084
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3085
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3086
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3087
ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3088
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3089
	ztest_ds_t zdtmp;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3090
	int iters;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3091
	int error;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3092
	objset_t *os, *os2;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3093
	char name[MAXNAMELEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3094
	zilog_t *zilog;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3095
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3096
	(void) rw_rdlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3097
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3098
	(void) snprintf(name, MAXNAMELEN, "%s/temp_%llu",
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3099
	    ztest_opts.zo_pool, (u_longlong_t)id);
789
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
	 * If this dataset exists from a previous run, process its replay log
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3103
	 * half of the time.  If we don't replay it, then dmu_objset_destroy()
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3104
	 * (invoked from ztest_objset_destroy_cb()) should just throw it away.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3105
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3106
	if (ztest_random(2) == 0 &&
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3107
	    dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, FTAG, &os) == 0) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3108
		ztest_zd_init(&zdtmp, NULL, os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3109
		zil_replay(os, &zdtmp, ztest_replay_vector);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3110
		ztest_zd_fini(&zdtmp);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3111
		dmu_objset_disown(os, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3112
	}
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
	 * There may be an old instance of the dataset we're about to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3116
	 * create lying around from a previous run.  If so, destroy it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3117
	 * and all of its snapshots.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3118
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3119
	(void) dmu_objset_find(name, ztest_objset_destroy_cb, NULL,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2237
diff changeset
  3120
	    DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3122
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3123
	 * Verify that the destroyed dataset is no longer in the namespace.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3124
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3125
	VERIFY3U(ENOENT, ==, dmu_objset_hold(name, FTAG, &os));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3126
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3127
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3128
	 * Verify that we can create a new dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3129
	 */
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3130
	error = ztest_dataset_create(name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3131
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3132
		if (error == ENOSPC) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3133
			ztest_record_enospc(FTAG);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3134
			(void) rw_unlock(&ztest_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3135
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3136
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3137
		fatal(0, "dmu_objset_create(%s) = %d", name, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3138
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3139
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3140
	VERIFY3U(0, ==,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3141
	    dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, FTAG, &os));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3142
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3143
	ztest_zd_init(&zdtmp, NULL, os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3145
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3146
	 * Open the intent log for it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3147
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3148
	zilog = zil_open(os, ztest_get_data);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3149
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3150
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3151
	 * Put some objects in there, do a little I/O to them,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3152
	 * and randomly take a couple of snapshots along the way.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3153
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3154
	iters = ztest_random(5);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3155
	for (int i = 0; i < iters; i++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3156
		ztest_dmu_object_alloc_free(&zdtmp, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3157
		if (ztest_random(iters) == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3158
			(void) ztest_snapshot_create(name, i);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3159
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3160
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3161
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3162
	 * Verify that we cannot create an existing dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3163
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3164
	VERIFY3U(EEXIST, ==,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3165
	    dmu_objset_create(name, DMU_OST_OTHER, 0, NULL, NULL));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3166
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3167
	/*
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3168
	 * Verify that we can hold an objset that is also owned.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3169
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3170
	VERIFY3U(0, ==, dmu_objset_hold(name, FTAG, &os2));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3171
	dmu_objset_rele(os2, FTAG);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3172
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3173
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3174
	 * Verify that we cannot own an objset that is already owned.
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3175
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3176
	VERIFY3U(EBUSY, ==,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3177
	    dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, FTAG, &os2));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3179
	zil_close(zilog);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3180
	dmu_objset_disown(os, FTAG);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3181
	ztest_zd_fini(&zdtmp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3182
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3183
	(void) rw_unlock(&ztest_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3184
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3185
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3186
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3187
 * Verify that dmu_snapshot_{create,destroy,open,close} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3188
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3189
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3190
ztest_dmu_snapshot_create_destroy(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3191
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3192
	(void) rw_rdlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3193
	(void) ztest_snapshot_destroy(zd->zd_name, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3194
	(void) ztest_snapshot_create(zd->zd_name, id);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3195
	(void) rw_unlock(&ztest_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3196
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3197
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3198
/*
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3199
 * Cleanup non-standard snapshots and clones.
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3200
 */
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3201
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3202
ztest_dsl_dataset_cleanup(char *osname, uint64_t id)
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3203
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3204
	char snap1name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3205
	char clone1name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3206
	char snap2name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3207
	char clone2name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3208
	char snap3name[MAXNAMELEN];
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3209
	int error;
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3210
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3211
	(void) snprintf(snap1name, MAXNAMELEN, "%s@s1_%llu", osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3212
	(void) snprintf(clone1name, MAXNAMELEN, "%s/c1_%llu", osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3213
	(void) snprintf(snap2name, MAXNAMELEN, "%s@s2_%llu", clone1name, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3214
	(void) snprintf(clone2name, MAXNAMELEN, "%s/c2_%llu", osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3215
	(void) snprintf(snap3name, MAXNAMELEN, "%s@s3_%llu", clone1name, id);
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3216
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10105
diff changeset
  3217
	error = dmu_objset_destroy(clone2name, B_FALSE);
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3218
	if (error && error != ENOENT)
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3219
		fatal(0, "dmu_objset_destroy(%s) = %d", clone2name, error);
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10105
diff changeset
  3220
	error = dmu_objset_destroy(snap3name, B_FALSE);
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3221
	if (error && error != ENOENT)
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3222
		fatal(0, "dmu_objset_destroy(%s) = %d", snap3name, error);
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10105
diff changeset
  3223
	error = dmu_objset_destroy(snap2name, B_FALSE);
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3224
	if (error && error != ENOENT)
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3225
		fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10105
diff changeset
  3226
	error = dmu_objset_destroy(clone1name, B_FALSE);
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3227
	if (error && error != ENOENT)
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3228
		fatal(0, "dmu_objset_destroy(%s) = %d", clone1name, error);
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10105
diff changeset
  3229
	error = dmu_objset_destroy(snap1name, B_FALSE);
9691
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3230
	if (error && error != ENOENT)
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3231
		fatal(0, "dmu_objset_destroy(%s) = %d", snap1name, error);
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3232
}
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3233
9b3f29ab739f 6843568 ztest fails when calling dmu_objset_destroy()
George Wilson <George.Wilson@Sun.COM>
parents: 9512
diff changeset
  3234
/*
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3235
 * Verify dsl_dataset_promote handles EBUSY
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3236
 */
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3237
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3238
ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id)
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3239
{
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3240
	objset_t *clone;
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3241
	dsl_dataset_t *ds;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3242
	char snap1name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3243
	char clone1name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3244
	char snap2name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3245
	char clone2name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3246
	char snap3name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3247
	char *osname = zd->zd_name;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3248
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3249
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3250
	(void) rw_rdlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3251
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3252
	ztest_dsl_dataset_cleanup(osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3253
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3254
	(void) snprintf(snap1name, MAXNAMELEN, "%s@s1_%llu", osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3255
	(void) snprintf(clone1name, MAXNAMELEN, "%s/c1_%llu", osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3256
	(void) snprintf(snap2name, MAXNAMELEN, "%s@s2_%llu", clone1name, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3257
	(void) snprintf(clone2name, MAXNAMELEN, "%s/c2_%llu", osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3258
	(void) snprintf(snap3name, MAXNAMELEN, "%s@s3_%llu", clone1name, id);
8837
f54f5a565b91 6805079 ztest fails immediately
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8779
diff changeset
  3259
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  3260
	error = dmu_objset_snapshot(osname, strchr(snap1name, '@')+1,
13055
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  3261
	    NULL, NULL, B_FALSE, B_FALSE, -1);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3262
	if (error && error != EEXIST) {
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3263
		if (error == ENOSPC) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3264
			ztest_record_enospc(FTAG);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3265
			goto out;
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3266
		}
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3267
		fatal(0, "dmu_take_snapshot(%s) = %d", snap1name, error);
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3268
	}
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3269
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3270
	error = dmu_objset_hold(snap1name, FTAG, &clone);
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3271
	if (error)
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3272
		fatal(0, "dmu_open_snapshot(%s) = %d", snap1name, error);
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3273
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3274
	error = dmu_objset_clone(clone1name, dmu_objset_ds(clone), 0);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3275
	dmu_objset_rele(clone, FTAG);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3276
	if (error) {
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3277
		if (error == ENOSPC) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3278
			ztest_record_enospc(FTAG);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3279
			goto out;
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3280
		}
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3281
		fatal(0, "dmu_objset_create(%s) = %d", clone1name, error);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3282
	}
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3283
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3284
	error = dmu_objset_snapshot(clone1name, strchr(snap2name, '@')+1,
13055
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  3285
	    NULL, NULL, B_FALSE, B_FALSE, -1);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3286
	if (error && error != EEXIST) {
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3287
		if (error == ENOSPC) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3288
			ztest_record_enospc(FTAG);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3289
			goto out;
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3290
		}
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3291
		fatal(0, "dmu_open_snapshot(%s) = %d", snap2name, error);
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3292
	}
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3293
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3294
	error = dmu_objset_snapshot(clone1name, strchr(snap3name, '@')+1,
13055
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  3295
	    NULL, NULL, B_FALSE, B_FALSE, -1);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3296
	if (error && error != EEXIST) {
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3297
		if (error == ENOSPC) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3298
			ztest_record_enospc(FTAG);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3299
			goto out;
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3300
		}
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3301
		fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3302
	}
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3303
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3304
	error = dmu_objset_hold(snap3name, FTAG, &clone);
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3305
	if (error)
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3306
		fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3307
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3308
	error = dmu_objset_clone(clone2name, dmu_objset_ds(clone), 0);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3309
	dmu_objset_rele(clone, FTAG);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3310
	if (error) {
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3311
		if (error == ENOSPC) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3312
			ztest_record_enospc(FTAG);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3313
			goto out;
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3314
		}
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3315
		fatal(0, "dmu_objset_create(%s) = %d", clone2name, error);
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3316
	}
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3317
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  3318
	error = dsl_dataset_own(snap2name, B_FALSE, FTAG, &ds);
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3319
	if (error)
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12296
diff changeset
  3320
		fatal(0, "dsl_dataset_own(%s) = %d", snap2name, error);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10437
diff changeset
  3321
	error = dsl_dataset_promote(clone2name, NULL);
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3322
	if (error != EBUSY)
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3323
		fatal(0, "dsl_dataset_promote(%s), %d, not EBUSY", clone2name,
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3324
		    error);
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3325
	dsl_dataset_disown(ds, FTAG);
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3326
9229
e3f8b41e5db4 6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC
George Wilson <George.Wilson@Sun.COM>
parents: 8837
diff changeset
  3327
out:
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3328
	ztest_dsl_dataset_cleanup(osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3329
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3330
	(void) rw_unlock(&ztest_name_lock);
8779
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3331
}
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3332
f164e0e90508 6784924 panic while ludelete (zfs destroy)
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  3333
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3334
 * Verify that dmu_object_{alloc,free} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3335
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3336
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3337
ztest_dmu_object_alloc_free(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3338
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3339
	ztest_od_t od[4];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3340
	int batchsize = sizeof (od) / sizeof (od[0]);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3341
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3342
	for (int b = 0; b < batchsize; b++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3343
		ztest_od_init(&od[b], id, FTAG, b, DMU_OT_UINT64_OTHER, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3344
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3345
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3346
	 * Destroy the previous batch of objects, create a new batch,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3347
	 * and do some I/O on the new objects.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3348
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3349
	if (ztest_object_init(zd, od, sizeof (od), B_TRUE) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3350
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3351
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3352
	while (ztest_random(4 * batchsize) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3353
		ztest_io(zd, od[ztest_random(batchsize)].od_object,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3354
		    ztest_random(ZTEST_RANGE_LOCKS) << SPA_MAXBLOCKSHIFT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3355
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3356
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3357
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3358
 * Verify that dmu_{read,write} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3359
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3360
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3361
ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3362
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3363
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3364
	ztest_od_t od[2];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3365
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3366
	int i, freeit, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3367
	uint64_t n, s, txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3368
	bufwad_t *packbuf, *bigbuf, *pack, *bigH, *bigT;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3369
	uint64_t packobj, packoff, packsize, bigobj, bigoff, bigsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3370
	uint64_t chunksize = (1000 + ztest_random(1000)) * sizeof (uint64_t);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3371
	uint64_t regions = 997;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3372
	uint64_t stride = 123456789ULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3373
	uint64_t width = 40;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3374
	int free_percent = 5;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3375
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3376
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3377
	 * This test uses two objects, packobj and bigobj, that are always
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3378
	 * updated together (i.e. in the same tx) so that their contents are
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3379
	 * in sync and can be compared.  Their contents relate to each other
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3380
	 * in a simple way: packobj is a dense array of 'bufwad' structures,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3381
	 * while bigobj is a sparse array of the same bufwads.  Specifically,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3382
	 * for any index n, there are three bufwads that should be identical:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3383
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3384
	 *	packobj, at offset n * sizeof (bufwad_t)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3385
	 *	bigobj, at the head of the nth chunk
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3386
	 *	bigobj, at the tail of the nth chunk
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3387
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3388
	 * The chunk size is arbitrary. It doesn't have to be a power of two,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3389
	 * and it doesn't have any relation to the object blocksize.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3390
	 * The only requirement is that it can hold at least two bufwads.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3391
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3392
	 * Normally, we write the bufwad to each of these locations.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3393
	 * However, free_percent of the time we instead write zeroes to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3394
	 * packobj and perform a dmu_free_range() on bigobj.  By comparing
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3395
	 * bigobj to packobj, we can verify that the DMU is correctly
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3396
	 * tracking which parts of an object are allocated and free,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3397
	 * and that the contents of the allocated blocks are correct.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3398
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3399
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3400
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3401
	 * Read the directory info.  If it's the first time, set things up.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3402
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3403
	ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, 0, chunksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3404
	ztest_od_init(&od[1], id, FTAG, 1, DMU_OT_UINT64_OTHER, 0, chunksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3405
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3406
	if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3407
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3408
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3409
	bigobj = od[0].od_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3410
	packobj = od[1].od_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3411
	chunksize = od[0].od_gen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3412
	ASSERT(chunksize == od[1].od_gen);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3413
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3414
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3415
	 * Prefetch a random chunk of the big object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3416
	 * Our aim here is to get some async reads in flight
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3417
	 * for blocks that we may free below; the DMU should
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3418
	 * handle this race correctly.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3419
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3420
	n = ztest_random(regions) * stride + ztest_random(width);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3421
	s = 1 + ztest_random(2 * width - 1);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3422
	dmu_prefetch(os, bigobj, n * chunksize, s * chunksize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3423
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3424
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3425
	 * Pick a random index and compute the offsets into packobj and bigobj.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3426
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3427
	n = ztest_random(regions) * stride + ztest_random(width);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3428
	s = 1 + ztest_random(width - 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3429
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3430
	packoff = n * sizeof (bufwad_t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3431
	packsize = s * sizeof (bufwad_t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3432
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3433
	bigoff = n * chunksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3434
	bigsize = s * chunksize;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3436
	packbuf = umem_alloc(packsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3437
	bigbuf = umem_alloc(bigsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3438
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3439
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3440
	 * free_percent of the time, free a range of bigobj rather than
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3441
	 * overwriting it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3442
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3443
	freeit = (ztest_random(100) < free_percent);
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
	 * Read the current contents of our objects.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3447
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3448
	error = dmu_read(os, packobj, packoff, packsize, packbuf,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3449
	    DMU_READ_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3450
	ASSERT3U(error, ==, 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3451
	error = dmu_read(os, bigobj, bigoff, bigsize, bigbuf,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3452
	    DMU_READ_PREFETCH);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3453
	ASSERT3U(error, ==, 0);
789
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
	 * Get a tx for the mods to both packobj and bigobj.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3457
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3458
	tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3459
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3460
	dmu_tx_hold_write(tx, packobj, packoff, packsize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3461
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3462
	if (freeit)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3463
		dmu_tx_hold_free(tx, bigobj, bigoff, bigsize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3464
	else
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3465
		dmu_tx_hold_write(tx, bigobj, bigoff, bigsize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3466
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3467
	txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3468
	if (txg == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3469
		umem_free(packbuf, packsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3470
		umem_free(bigbuf, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3471
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3472
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3473
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3474
	dmu_object_set_checksum(os, bigobj,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3475
	    (enum zio_checksum)ztest_random_dsl_prop(ZFS_PROP_CHECKSUM), tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3476
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3477
	dmu_object_set_compress(os, bigobj,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3478
	    (enum zio_compress)ztest_random_dsl_prop(ZFS_PROP_COMPRESSION), tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3479
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3480
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3481
	 * For each index from n to n + s, verify that the existing bufwad
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3482
	 * in packobj matches the bufwads at the head and tail of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3483
	 * corresponding chunk in bigobj.  Then update all three bufwads
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3484
	 * with the new values we want to write out.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3485
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3486
	for (i = 0; i < s; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3487
		/* LINTED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3488
		pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3489
		/* LINTED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3490
		bigH = (bufwad_t *)((char *)bigbuf + i * chunksize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3491
		/* LINTED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3492
		bigT = (bufwad_t *)((char *)bigH + chunksize) - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3494
		ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3495
		ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3496
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3497
		if (pack->bw_txg > txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3498
			fatal(0, "future leak: got %llx, open txg is %llx",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3499
			    pack->bw_txg, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3500
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3501
		if (pack->bw_data != 0 && pack->bw_index != n + i)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3502
			fatal(0, "wrong index: got %llx, wanted %llx+%llx",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3503
			    pack->bw_index, n, i);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3504
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3505
		if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3506
			fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3507
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3508
		if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3509
			fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3510
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3511
		if (freeit) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3512
			bzero(pack, sizeof (bufwad_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3513
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3514
			pack->bw_index = n + i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3515
			pack->bw_txg = txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3516
			pack->bw_data = 1 + ztest_random(-2ULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3517
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3518
		*bigH = *pack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3519
		*bigT = *pack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3520
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3521
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3522
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3523
	 * We've verified all the old bufwads, and made new ones.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3524
	 * Now write them out.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3525
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3526
	dmu_write(os, packobj, packoff, packsize, packbuf, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3528
	if (freeit) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3529
		if (ztest_opts.zo_verbose >= 7) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3530
			(void) printf("freeing offset %llx size %llx"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3531
			    " txg %llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3532
			    (u_longlong_t)bigoff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3533
			    (u_longlong_t)bigsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3534
			    (u_longlong_t)txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3535
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3536
		VERIFY(0 == dmu_free_range(os, bigobj, bigoff, bigsize, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3537
	} else {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3538
		if (ztest_opts.zo_verbose >= 7) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3539
			(void) printf("writing offset %llx size %llx"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3540
			    " txg %llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3541
			    (u_longlong_t)bigoff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3542
			    (u_longlong_t)bigsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3543
			    (u_longlong_t)txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3544
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3545
		dmu_write(os, bigobj, bigoff, bigsize, bigbuf, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3546
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3547
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3548
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3549
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3550
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3551
	 * Sanity check the stuff we just wrote.
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
		void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3555
		void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3556
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3557
		VERIFY(0 == dmu_read(os, packobj, packoff,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3558
		    packsize, packcheck, DMU_READ_PREFETCH));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3559
		VERIFY(0 == dmu_read(os, bigobj, bigoff,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3560
		    bigsize, bigcheck, DMU_READ_PREFETCH));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3561
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3562
		ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3563
		ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3564
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3565
		umem_free(packcheck, packsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3566
		umem_free(bigcheck, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3567
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3569
	umem_free(packbuf, packsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3570
	umem_free(bigbuf, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3571
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3572
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3573
void
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3574
compare_and_update_pbbufs(uint64_t s, bufwad_t *packbuf, bufwad_t *bigbuf,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3575
    uint64_t bigsize, uint64_t n, uint64_t chunksize, uint64_t txg)
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3576
{
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3577
	uint64_t i;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3578
	bufwad_t *pack;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3579
	bufwad_t *bigH;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3580
	bufwad_t *bigT;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3581
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3582
	/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3583
	 * For each index from n to n + s, verify that the existing bufwad
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3584
	 * in packobj matches the bufwads at the head and tail of the
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3585
	 * corresponding chunk in bigobj.  Then update all three bufwads
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3586
	 * with the new values we want to write out.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3587
	 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3588
	for (i = 0; i < s; i++) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3589
		/* LINTED */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3590
		pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3591
		/* LINTED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3592
		bigH = (bufwad_t *)((char *)bigbuf + i * chunksize);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3593
		/* LINTED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3594
		bigT = (bufwad_t *)((char *)bigH + chunksize) - 1;
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3595
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3596
		ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3597
		ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3598
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3599
		if (pack->bw_txg > txg)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3600
			fatal(0, "future leak: got %llx, open txg is %llx",
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3601
			    pack->bw_txg, txg);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3602
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3603
		if (pack->bw_data != 0 && pack->bw_index != n + i)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3604
			fatal(0, "wrong index: got %llx, wanted %llx+%llx",
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3605
			    pack->bw_index, n, i);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3606
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3607
		if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3608
			fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3609
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3610
		if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3611
			fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3612
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3613
		pack->bw_index = n + i;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3614
		pack->bw_txg = txg;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3615
		pack->bw_data = 1 + ztest_random(-2ULL);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3616
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3617
		*bigH = *pack;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3618
		*bigT = *pack;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3619
	}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3620
}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3621
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3622
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3623
ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3624
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3625
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3626
	ztest_od_t od[2];
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3627
	dmu_tx_t *tx;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3628
	uint64_t i;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3629
	int error;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3630
	uint64_t n, s, txg;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3631
	bufwad_t *packbuf, *bigbuf;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3632
	uint64_t packobj, packoff, packsize, bigobj, bigoff, bigsize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3633
	uint64_t blocksize = ztest_random_blocksize();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3634
	uint64_t chunksize = blocksize;
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3635
	uint64_t regions = 997;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3636
	uint64_t stride = 123456789ULL;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3637
	uint64_t width = 9;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3638
	dmu_buf_t *bonus_db;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3639
	arc_buf_t **bigbuf_arcbufs;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3640
	dmu_object_info_t doi;
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3641
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3642
	/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3643
	 * This test uses two objects, packobj and bigobj, that are always
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3644
	 * updated together (i.e. in the same tx) so that their contents are
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3645
	 * in sync and can be compared.  Their contents relate to each other
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3646
	 * in a simple way: packobj is a dense array of 'bufwad' structures,
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3647
	 * while bigobj is a sparse array of the same bufwads.  Specifically,
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3648
	 * for any index n, there are three bufwads that should be identical:
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3649
	 *
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3650
	 *	packobj, at offset n * sizeof (bufwad_t)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3651
	 *	bigobj, at the head of the nth chunk
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3652
	 *	bigobj, at the tail of the nth chunk
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3653
	 *
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3654
	 * The chunk size is set equal to bigobj block size so that
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3655
	 * dmu_assign_arcbuf() can be tested for object updates.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3656
	 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3657
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3658
	/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3659
	 * Read the directory info.  If it's the first time, set things up.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3660
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3661
	ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, blocksize, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3662
	ztest_od_init(&od[1], id, FTAG, 1, DMU_OT_UINT64_OTHER, 0, chunksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3663
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3664
	if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3665
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3666
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3667
	bigobj = od[0].od_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3668
	packobj = od[1].od_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3669
	blocksize = od[0].od_blocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3670
	chunksize = blocksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3671
	ASSERT(chunksize == od[1].od_gen);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3672
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3673
	VERIFY(dmu_object_info(os, bigobj, &doi) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3674
	VERIFY(ISP2(doi.doi_data_block_size));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3675
	VERIFY(chunksize == doi.doi_data_block_size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3676
	VERIFY(chunksize >= 2 * sizeof (bufwad_t));
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3677
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3678
	/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3679
	 * Pick a random index and compute the offsets into packobj and bigobj.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3680
	 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3681
	n = ztest_random(regions) * stride + ztest_random(width);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3682
	s = 1 + ztest_random(width - 1);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3683
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3684
	packoff = n * sizeof (bufwad_t);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3685
	packsize = s * sizeof (bufwad_t);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3686
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3687
	bigoff = n * chunksize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3688
	bigsize = s * chunksize;
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3689
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3690
	packbuf = umem_zalloc(packsize, UMEM_NOFAIL);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3691
	bigbuf = umem_zalloc(bigsize, UMEM_NOFAIL);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3692
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3693
	VERIFY3U(0, ==, dmu_bonus_hold(os, bigobj, FTAG, &bonus_db));
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3694
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3695
	bigbuf_arcbufs = umem_zalloc(2 * s * sizeof (arc_buf_t *), UMEM_NOFAIL);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3696
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3697
	/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3698
	 * Iteration 0 test zcopy for DB_UNCACHED dbufs.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3699
	 * Iteration 1 test zcopy to already referenced dbufs.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3700
	 * Iteration 2 test zcopy to dirty dbuf in the same txg.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3701
	 * Iteration 3 test zcopy to dbuf dirty in previous txg.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3702
	 * Iteration 4 test zcopy when dbuf is no longer dirty.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3703
	 * Iteration 5 test zcopy when it can't be done.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3704
	 * Iteration 6 one more zcopy write.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3705
	 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3706
	for (i = 0; i < 7; i++) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3707
		uint64_t j;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3708
		uint64_t off;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3709
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3710
		/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3711
		 * In iteration 5 (i == 5) use arcbufs
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3712
		 * that don't match bigobj blksz to test
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3713
		 * dmu_assign_arcbuf() when it can't directly
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3714
		 * assign an arcbuf to a dbuf.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3715
		 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3716
		for (j = 0; j < s; j++) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3717
			if (i != 5) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3718
				bigbuf_arcbufs[j] =
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3719
				    dmu_request_arcbuf(bonus_db, chunksize);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3720
			} else {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3721
				bigbuf_arcbufs[2 * j] =
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3722
				    dmu_request_arcbuf(bonus_db, chunksize / 2);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3723
				bigbuf_arcbufs[2 * j + 1] =
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3724
				    dmu_request_arcbuf(bonus_db, chunksize / 2);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3725
			}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3726
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3727
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3728
		/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3729
		 * Get a tx for the mods to both packobj and bigobj.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3730
		 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3731
		tx = dmu_tx_create(os);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3732
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3733
		dmu_tx_hold_write(tx, packobj, packoff, packsize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3734
		dmu_tx_hold_write(tx, bigobj, bigoff, bigsize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3735
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3736
		txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3737
		if (txg == 0) {
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3738
			umem_free(packbuf, packsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3739
			umem_free(bigbuf, bigsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3740
			for (j = 0; j < s; j++) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3741
				if (i != 5) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3742
					dmu_return_arcbuf(bigbuf_arcbufs[j]);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3743
				} else {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3744
					dmu_return_arcbuf(
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3745
					    bigbuf_arcbufs[2 * j]);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3746
					dmu_return_arcbuf(
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3747
					    bigbuf_arcbufs[2 * j + 1]);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3748
				}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3749
			}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3750
			umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3751
			dmu_buf_rele(bonus_db, FTAG);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3752
			return;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3753
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3754
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3755
		/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3756
		 * 50% of the time don't read objects in the 1st iteration to
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3757
		 * test dmu_assign_arcbuf() for the case when there're no
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3758
		 * existing dbufs for the specified offsets.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3759
		 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3760
		if (i != 0 || ztest_random(2) != 0) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3761
			error = dmu_read(os, packobj, packoff,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3762
			    packsize, packbuf, DMU_READ_PREFETCH);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3763
			ASSERT3U(error, ==, 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3764
			error = dmu_read(os, bigobj, bigoff, bigsize,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3765
			    bigbuf, DMU_READ_PREFETCH);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3766
			ASSERT3U(error, ==, 0);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3767
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3768
		compare_and_update_pbbufs(s, packbuf, bigbuf, bigsize,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3769
		    n, chunksize, txg);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3770
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3771
		/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3772
		 * We've verified all the old bufwads, and made new ones.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3773
		 * Now write them out.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3774
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3775
		dmu_write(os, packobj, packoff, packsize, packbuf, tx);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  3776
		if (ztest_opts.zo_verbose >= 7) {
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3777
			(void) printf("writing offset %llx size %llx"
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3778
			    " txg %llx\n",
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3779
			    (u_longlong_t)bigoff,
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3780
			    (u_longlong_t)bigsize,
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3781
			    (u_longlong_t)txg);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3782
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3783
		for (off = bigoff, j = 0; j < s; j++, off += chunksize) {
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3784
			dmu_buf_t *dbt;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3785
			if (i != 5) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3786
				bcopy((caddr_t)bigbuf + (off - bigoff),
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3787
				    bigbuf_arcbufs[j]->b_data, chunksize);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3788
			} else {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3789
				bcopy((caddr_t)bigbuf + (off - bigoff),
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3790
				    bigbuf_arcbufs[2 * j]->b_data,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3791
				    chunksize / 2);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3792
				bcopy((caddr_t)bigbuf + (off - bigoff) +
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3793
				    chunksize / 2,
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3794
				    bigbuf_arcbufs[2 * j + 1]->b_data,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3795
				    chunksize / 2);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3796
			}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3797
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3798
			if (i == 1) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3799
				VERIFY(dmu_buf_hold(os, bigobj, off,
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
  3800
				    FTAG, &dbt, DMU_READ_NO_PREFETCH) == 0);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3801
			}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3802
			if (i != 5) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3803
				dmu_assign_arcbuf(bonus_db, off,
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3804
				    bigbuf_arcbufs[j], tx);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3805
			} else {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3806
				dmu_assign_arcbuf(bonus_db, off,
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3807
				    bigbuf_arcbufs[2 * j], tx);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3808
				dmu_assign_arcbuf(bonus_db,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3809
				    off + chunksize / 2,
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3810
				    bigbuf_arcbufs[2 * j + 1], tx);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3811
			}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3812
			if (i == 1) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3813
				dmu_buf_rele(dbt, FTAG);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3814
			}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3815
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3816
		dmu_tx_commit(tx);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3817
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3818
		/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3819
		 * Sanity check the stuff we just wrote.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3820
		 */
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3821
		{
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3822
			void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3823
			void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3824
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3825
			VERIFY(0 == dmu_read(os, packobj, packoff,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3826
			    packsize, packcheck, DMU_READ_PREFETCH));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3827
			VERIFY(0 == dmu_read(os, bigobj, bigoff,
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9480
diff changeset
  3828
			    bigsize, bigcheck, DMU_READ_PREFETCH));
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3829
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3830
			ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3831
			ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3832
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3833
			umem_free(packcheck, packsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3834
			umem_free(bigcheck, bigsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3835
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3836
		if (i == 2) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3837
			txg_wait_open(dmu_objset_pool(os), 0);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3838
		} else if (i == 3) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3839
			txg_wait_synced(dmu_objset_pool(os), 0);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3840
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3841
	}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3842
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3843
	dmu_buf_rele(bonus_db, FTAG);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3844
	umem_free(packbuf, packsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3845
	umem_free(bigbuf, bigsize);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3846
	umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3847
}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3848
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3849
/* ARGSUSED */
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9355
diff changeset
  3850
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3851
ztest_dmu_write_parallel(ztest_ds_t *zd, uint64_t id)
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3852
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3853
	ztest_od_t od[1];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3854
	uint64_t offset = (1ULL << (ztest_random(20) + 43)) +
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3855
	    (ztest_random(ZTEST_RANGE_LOCKS) << SPA_MAXBLOCKSHIFT);
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3856
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3857
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3858
	 * Have multiple threads write to large offsets in an object
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3859
	 * to verify that parallel writes to an object -- even to the
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3860
	 * same blocks within the object -- doesn't cause any trouble.
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3861
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3862
	ztest_od_init(&od[0], ID_PARALLEL, FTAG, 0, DMU_OT_UINT64_OTHER, 0, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3863
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3864
	if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3865
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3866
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3867
	while (ztest_random(10) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3868
		ztest_io(zd, od[0].od_object, offset);
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3869
}
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3870
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3871
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3872
ztest_dmu_prealloc(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3873
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3874
	ztest_od_t od[1];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3875
	uint64_t offset = (1ULL << (ztest_random(4) + SPA_MAXBLOCKSHIFT)) +
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3876
	    (ztest_random(ZTEST_RANGE_LOCKS) << SPA_MAXBLOCKSHIFT);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3877
	uint64_t count = ztest_random(20) + 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3878
	uint64_t blocksize = ztest_random_blocksize();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3879
	void *data;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3880
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3881
	ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, blocksize, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3882
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3883
	if (ztest_object_init(zd, od, sizeof (od), !ztest_random(2)) != 0)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3884
		return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3885
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3886
	if (ztest_truncate(zd, od[0].od_object, offset, count * blocksize) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3887
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3888
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3889
	ztest_prealloc(zd, od[0].od_object, offset, count * blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3890
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3891
	data = umem_zalloc(blocksize, UMEM_NOFAIL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3892
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3893
	while (ztest_random(count) != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3894
		uint64_t randoff = offset + (ztest_random(count) * blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3895
		if (ztest_write(zd, od[0].od_object, randoff, blocksize,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3896
		    data) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3897
			break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3898
		while (ztest_random(4) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3899
			ztest_io(zd, od[0].od_object, randoff);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3900
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3901
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3902
	umem_free(data, blocksize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3903
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3904
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3905
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3906
 * Verify that zap_{create,destroy,add,remove,update} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3907
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3908
#define	ZTEST_ZAP_MIN_INTS	1
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3909
#define	ZTEST_ZAP_MAX_INTS	4
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3910
#define	ZTEST_ZAP_MAX_PROPS	1000
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3911
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3912
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3913
ztest_zap(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3914
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3915
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3916
	ztest_od_t od[1];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3917
	uint64_t object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3918
	uint64_t txg, last_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3919
	uint64_t value[ZTEST_ZAP_MAX_INTS];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3920
	uint64_t zl_ints, zl_intsize, prop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3921
	int i, ints;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3922
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3923
	char propname[100], txgname[100];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3924
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3925
	char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3926
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3927
	ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_ZAP_OTHER, 0, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3928
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3929
	if (ztest_object_init(zd, od, sizeof (od), !ztest_random(2)) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3930
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3931
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3932
	object = od[0].od_object;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3933
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3934
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3935
	 * Generate a known hash collision, and verify that
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3936
	 * we can lookup and remove both entries.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3937
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3938
	tx = dmu_tx_create(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3939
	dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3940
	txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3941
	if (txg == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3942
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3943
	for (i = 0; i < 2; i++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3944
		value[i] = i;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3945
		VERIFY3U(0, ==, zap_add(os, object, hc[i], sizeof (uint64_t),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3946
		    1, &value[i], tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3947
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3948
	for (i = 0; i < 2; i++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3949
		VERIFY3U(EEXIST, ==, zap_add(os, object, hc[i],
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3950
		    sizeof (uint64_t), 1, &value[i], tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3951
		VERIFY3U(0, ==,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3952
		    zap_length(os, object, hc[i], &zl_intsize, &zl_ints));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3953
		ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3954
		ASSERT3U(zl_ints, ==, 1);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3955
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3956
	for (i = 0; i < 2; i++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3957
		VERIFY3U(0, ==, zap_remove(os, object, hc[i], tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3958
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3959
	dmu_tx_commit(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3960
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3961
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3962
	 * Generate a buch of random entries.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  3963
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3964
	ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3965
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3966
	prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3967
	(void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3968
	(void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3969
	bzero(value, sizeof (value));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3970
	last_txg = 0;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3971
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3972
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3973
	 * If these zap entries already exist, validate their contents.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3974
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3975
	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
  3976
	if (error == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3977
		ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3978
		ASSERT3U(zl_ints, ==, 1);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3979
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3980
		VERIFY(zap_lookup(os, object, txgname, zl_intsize,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3981
		    zl_ints, &last_txg) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3982
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3983
		VERIFY(zap_length(os, object, propname, &zl_intsize,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3984
		    &zl_ints) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3985
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3986
		ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3987
		ASSERT3U(zl_ints, ==, ints);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3988
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3989
		VERIFY(zap_lookup(os, object, propname, zl_intsize,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3990
		    zl_ints, value) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3991
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3992
		for (i = 0; i < ints; i++) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3993
			ASSERT3U(value[i], ==, last_txg + object + i);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3994
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3995
	} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3996
		ASSERT3U(error, ==, ENOENT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3997
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3998
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3999
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4000
	 * Atomically update two entries in our zap object.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4001
	 * 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
  4002
	 * in which the property was last updated.  The second
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4003
	 * 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
  4004
	 * should be txg + object + n.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4005
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4006
	tx = dmu_tx_create(os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4007
	dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4008
	txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4009
	if (txg == 0)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4010
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4011
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4012
	if (last_txg > txg)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4013
		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
  4014
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4015
	for (i = 0; i < ints; i++)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4016
		value[i] = txg + object + i;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4017
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4018
	VERIFY3U(0, ==, zap_update(os, object, txgname, sizeof (uint64_t),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4019
	    1, &txg, tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4020
	VERIFY3U(0, ==, zap_update(os, object, propname, sizeof (uint64_t),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4021
	    ints, value, tx));
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4022
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4023
	dmu_tx_commit(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4024
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4025
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4026
	 * Remove a random pair of entries.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4027
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4028
	prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4029
	(void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4030
	(void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4031
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4032
	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
  4033
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4034
	if (error == ENOENT)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4035
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4036
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4037
	ASSERT3U(error, ==, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4038
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4039
	tx = dmu_tx_create(os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4040
	dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4041
	txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4042
	if (txg == 0)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4043
		return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4044
	VERIFY3U(0, ==, zap_remove(os, object, txgname, tx));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4045
	VERIFY3U(0, ==, zap_remove(os, object, propname, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4046
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4047
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4048
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4049
/*
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4050
 * Testcase to test the upgrading of a microzap to fatzap.
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4051
 */
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4052
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4053
ztest_fzap(ztest_ds_t *zd, uint64_t id)
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4054
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4055
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4056
	ztest_od_t od[1];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4057
	uint64_t object, txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4058
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4059
	ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_ZAP_OTHER, 0, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4060
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4061
	if (ztest_object_init(zd, od, sizeof (od), !ztest_random(2)) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4062
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4063
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4064
	object = od[0].od_object;
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4065
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4066
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4067
	 * Add entries to this ZAP and make sure it spills over
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4068
	 * and gets upgraded to a fatzap. Also, since we are adding
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4069
	 * 2050 entries we should see ptrtbl growth and leaf-block split.
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4070
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4071
	for (int i = 0; i < 2050; i++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4072
		char name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4073
		uint64_t value = i;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4074
		dmu_tx_t *tx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4075
		int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4076
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4077
		(void) snprintf(name, sizeof (name), "fzap-%llu-%llu",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4078
		    id, value);
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4079
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4080
		tx = dmu_tx_create(os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4081
		dmu_tx_hold_zap(tx, object, B_TRUE, name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4082
		txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4083
		if (txg == 0)
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4084
			return;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4085
		error = zap_add(os, object, name, sizeof (uint64_t), 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4086
		    &value, tx);
10431
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4087
		ASSERT(error == 0 || error == EEXIST);
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4088
		dmu_tx_commit(tx);
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4089
	}
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4090
}
a4572ce3df84 6870347 assertion failure in dmu_tx_willuse_space(): refcount_count(&tx->tx_space_written) + delta <= tx->tx
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 10298
diff changeset
  4091
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4092
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4093
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4094
ztest_zap_parallel(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4095
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4096
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4097
	ztest_od_t od[1];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4098
	uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4099
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4100
	int i, namelen, error;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4101
	int micro = ztest_random(2);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4102
	char name[20], string_value[20];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4103
	void *data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4104
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4105
	ztest_od_init(&od[0], ID_PARALLEL, FTAG, micro, DMU_OT_ZAP_OTHER, 0, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4106
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4107
	if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4108
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4109
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4110
	object = od[0].od_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4111
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4112
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4113
	 * 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
  4114
	 * 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
  4115
	 * 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
  4116
	 * 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
  4117
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4118
	namelen = ztest_random(sizeof (name) - 5) + 5 + 1;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4119
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4120
	for (i = 0; i < 3; i++)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4121
		name[i] = '!' + ztest_random('~' - '!' + 1);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4122
	for (; i < namelen - 1; i++)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4123
		name[i] = '.';
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4124
	name[i] = '\0';
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4125
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4126
	if ((namelen & 1) || micro) {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4127
		wsize = sizeof (txg);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4128
		wc = 1;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4129
		data = &txg;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4130
	} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4131
		wsize = 1;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4132
		wc = namelen;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4133
		data = string_value;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4134
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4135
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4136
	count = -1ULL;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4137
	VERIFY(zap_count(os, object, &count) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4138
	ASSERT(count != -1ULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4139
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4140
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4141
	 * Select an operation: length, lookup, add, update, remove.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4142
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4143
	i = ztest_random(5);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4144
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4145
	if (i >= 2) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4146
		tx = dmu_tx_create(os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4147
		dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4148
		txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4149
		if (txg == 0)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4150
			return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4151
		bcopy(name, string_value, namelen);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4152
	} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4153
		tx = NULL;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4154
		txg = 0;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4155
		bzero(string_value, namelen);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4156
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4157
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4158
	switch (i) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4159
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4160
	case 0:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4161
		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
  4162
		if (error == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4163
			ASSERT3U(wsize, ==, zl_wsize);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4164
			ASSERT3U(wc, ==, zl_wc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4165
		} else {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4166
			ASSERT3U(error, ==, ENOENT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4167
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4168
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4169
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4170
	case 1:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4171
		error = zap_lookup(os, object, name, wsize, wc, data);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4172
		if (error == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4173
			if (data == string_value &&
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4174
			    bcmp(name, data, namelen) != 0)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4175
				fatal(0, "name '%s' != val '%s' len %d",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4176
				    name, data, namelen);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4177
		} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4178
			ASSERT3U(error, ==, ENOENT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4179
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4180
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4181
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4182
	case 2:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4183
		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
  4184
		ASSERT(error == 0 || error == EEXIST);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4185
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4186
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4187
	case 3:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4188
		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
  4189
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4190
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4191
	case 4:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4192
		error = zap_remove(os, object, name, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4193
		ASSERT(error == 0 || error == ENOENT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4194
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4195
	}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4196
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4197
	if (tx != NULL)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  4198
		dmu_tx_commit(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4199
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4200
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4201
/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4202
 * Commit callback data.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4203
 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4204
typedef struct ztest_cb_data {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4205
	list_node_t		zcd_node;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4206
	uint64_t		zcd_txg;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4207
	int			zcd_expected_err;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4208
	boolean_t		zcd_added;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4209
	boolean_t		zcd_called;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4210
	spa_t			*zcd_spa;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4211
} ztest_cb_data_t;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4212
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4213
/* This is the actual commit callback function */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4214
static void
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4215
ztest_commit_callback(void *arg, int error)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4216
{
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4217
	ztest_cb_data_t *data = arg;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4218
	uint64_t synced_txg;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4219
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4220
	VERIFY(data != NULL);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4221
	VERIFY3S(data->zcd_expected_err, ==, error);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4222
	VERIFY(!data->zcd_called);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4223
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4224
	synced_txg = spa_last_synced_txg(data->zcd_spa);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4225
	if (data->zcd_txg > synced_txg)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4226
		fatal(0, "commit callback of txg %" PRIu64 " called prematurely"
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4227
		    ", last synced txg = %" PRIu64 "\n", data->zcd_txg,
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4228
		    synced_txg);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4229
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4230
	data->zcd_called = B_TRUE;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4231
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4232
	if (error == ECANCELED) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4233
		ASSERT3U(data->zcd_txg, ==, 0);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4234
		ASSERT(!data->zcd_added);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4235
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4236
		/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4237
		 * The private callback data should be destroyed here, but
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4238
		 * since we are going to check the zcd_called field after
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4239
		 * dmu_tx_abort(), we will destroy it there.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4240
		 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4241
		return;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4242
	}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4243
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4244
	/* Was this callback added to the global callback list? */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4245
	if (!data->zcd_added)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4246
		goto out;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4247
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4248
	ASSERT3U(data->zcd_txg, !=, 0);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4249
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4250
	/* Remove our callback from the list */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4251
	(void) mutex_lock(&zcl.zcl_callbacks_lock);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4252
	list_remove(&zcl.zcl_callbacks, data);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4253
	(void) mutex_unlock(&zcl.zcl_callbacks_lock);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4254
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4255
out:
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4256
	umem_free(data, sizeof (ztest_cb_data_t));
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4257
}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4258
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4259
/* Allocate and initialize callback data structure */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4260
static ztest_cb_data_t *
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4261
ztest_create_cb_data(objset_t *os, uint64_t txg)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4262
{
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4263
	ztest_cb_data_t *cb_data;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4264
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4265
	cb_data = umem_zalloc(sizeof (ztest_cb_data_t), UMEM_NOFAIL);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4266
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4267
	cb_data->zcd_txg = txg;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4268
	cb_data->zcd_spa = dmu_objset_spa(os);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4269
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4270
	return (cb_data);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4271
}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4272
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4273
/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4274
 * If a number of txgs equal to this threshold have been created after a commit
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4275
 * callback has been registered but not called, then we assume there is an
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4276
 * implementation bug.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4277
 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4278
#define	ZTEST_COMMIT_CALLBACK_THRESH	(TXG_CONCURRENT_STATES + 2)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4279
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4280
/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4281
 * Commit callback test.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4282
 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4283
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4284
ztest_dmu_commit_callbacks(ztest_ds_t *zd, uint64_t id)
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4285
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4286
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4287
	ztest_od_t od[1];
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4288
	dmu_tx_t *tx;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4289
	ztest_cb_data_t *cb_data[3], *tmp_cb;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4290
	uint64_t old_txg, txg;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4291
	int i, error;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4292
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4293
	ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, 0, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4294
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4295
	if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4296
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4297
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4298
	tx = dmu_tx_create(os);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4299
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4300
	cb_data[0] = ztest_create_cb_data(os, 0);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4301
	dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[0]);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4302
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4303
	dmu_tx_hold_write(tx, od[0].od_object, 0, sizeof (uint64_t));
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4304
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4305
	/* Every once in a while, abort the transaction on purpose */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4306
	if (ztest_random(100) == 0)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4307
		error = -1;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4308
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4309
	if (!error)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4310
		error = dmu_tx_assign(tx, TXG_NOWAIT);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4311
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4312
	txg = error ? 0 : dmu_tx_get_txg(tx);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4313
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4314
	cb_data[0]->zcd_txg = txg;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4315
	cb_data[1] = ztest_create_cb_data(os, txg);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4316
	dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[1]);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4317
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4318
	if (error) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4319
		/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4320
		 * It's not a strict requirement to call the registered
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4321
		 * callbacks from inside dmu_tx_abort(), but that's what
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4322
		 * it's supposed to happen in the current implementation
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4323
		 * so we will check for that.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4324
		 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4325
		for (i = 0; i < 2; i++) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4326
			cb_data[i]->zcd_expected_err = ECANCELED;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4327
			VERIFY(!cb_data[i]->zcd_called);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4328
		}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4329
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4330
		dmu_tx_abort(tx);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4331
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4332
		for (i = 0; i < 2; i++) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4333
			VERIFY(cb_data[i]->zcd_called);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4334
			umem_free(cb_data[i], sizeof (ztest_cb_data_t));
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4335
		}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4336
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4337
		return;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4338
	}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4339
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4340
	cb_data[2] = ztest_create_cb_data(os, txg);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4341
	dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[2]);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4342
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4343
	/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4344
	 * Read existing data to make sure there isn't a future leak.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4345
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4346
	VERIFY(0 == dmu_read(os, od[0].od_object, 0, sizeof (uint64_t),
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4347
	    &old_txg, DMU_READ_PREFETCH));
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4348
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4349
	if (old_txg > txg)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4350
		fatal(0, "future leak: got %" PRIu64 ", open txg is %" PRIu64,
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4351
		    old_txg, txg);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4352
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4353
	dmu_write(os, od[0].od_object, 0, sizeof (uint64_t), &txg, tx);
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4354
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4355
	(void) mutex_lock(&zcl.zcl_callbacks_lock);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4356
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4357
	/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4358
	 * Since commit callbacks don't have any ordering requirement and since
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4359
	 * it is theoretically possible for a commit callback to be called
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4360
	 * after an arbitrary amount of time has elapsed since its txg has been
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4361
	 * synced, it is difficult to reliably determine whether a commit
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4362
	 * callback hasn't been called due to high load or due to a flawed
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4363
	 * implementation.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4364
	 *
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4365
	 * In practice, we will assume that if after a certain number of txgs a
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4366
	 * commit callback hasn't been called, then most likely there's an
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4367
	 * implementation bug..
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4368
	 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4369
	tmp_cb = list_head(&zcl.zcl_callbacks);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4370
	if (tmp_cb != NULL &&
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4371
	    tmp_cb->zcd_txg > txg - ZTEST_COMMIT_CALLBACK_THRESH) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4372
		fatal(0, "Commit callback threshold exceeded, oldest txg: %"
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4373
		    PRIu64 ", open txg: %" PRIu64 "\n", tmp_cb->zcd_txg, txg);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4374
	}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4375
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4376
	/*
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4377
	 * Let's find the place to insert our callbacks.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4378
	 *
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4379
	 * Even though the list is ordered by txg, it is possible for the
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4380
	 * insertion point to not be the end because our txg may already be
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4381
	 * quiescing at this point and other callbacks in the open txg
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4382
	 * (from other objsets) may have sneaked in.
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4383
	 */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4384
	tmp_cb = list_tail(&zcl.zcl_callbacks);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4385
	while (tmp_cb != NULL && tmp_cb->zcd_txg > txg)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4386
		tmp_cb = list_prev(&zcl.zcl_callbacks, tmp_cb);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4387
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4388
	/* Add the 3 callbacks to the list */
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4389
	for (i = 0; i < 3; i++) {
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4390
		if (tmp_cb == NULL)
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4391
			list_insert_head(&zcl.zcl_callbacks, cb_data[i]);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4392
		else
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4393
			list_insert_after(&zcl.zcl_callbacks, tmp_cb,
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4394
			    cb_data[i]);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4395
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4396
		cb_data[i]->zcd_added = B_TRUE;
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4397
		VERIFY(!cb_data[i]->zcd_called);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4398
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4399
		tmp_cb = cb_data[i];
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4400
	}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4401
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4402
	(void) mutex_unlock(&zcl.zcl_callbacks_lock);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4403
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4404
	dmu_tx_commit(tx);
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4405
}
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  4406
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4407
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4408
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4409
ztest_dsl_prop_get_set(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4410
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4411
	zfs_prop_t proplist[] = {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4412
		ZFS_PROP_CHECKSUM,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4413
		ZFS_PROP_COMPRESSION,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4414
		ZFS_PROP_COPIES,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4415
		ZFS_PROP_DEDUP
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4416
	};
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4417
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4418
	(void) rw_rdlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4419
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4420
	for (int p = 0; p < sizeof (proplist) / sizeof (proplist[0]); p++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4421
		(void) ztest_dsl_prop_set_uint64(zd->zd_name, proplist[p],
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4422
		    ztest_random_dsl_prop(proplist[p]), (int)ztest_random(2));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4423
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4424
	(void) rw_unlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4425
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4426
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4427
/* ARGSUSED */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4428
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4429
ztest_spa_prop_get_set(ztest_ds_t *zd, uint64_t id)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4430
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4431
	nvlist_t *props = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4432
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4433
	(void) rw_rdlock(&ztest_name_lock);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4434
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4435
	(void) ztest_spa_prop_set_uint64(ZPOOL_PROP_DEDUPDITTO,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4436
	    ZIO_DEDUPDITTO_MIN + ztest_random(ZIO_DEDUPDITTO_MIN));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4437
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4438
	VERIFY3U(spa_prop_get(ztest_spa, &props), ==, 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4439
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4440
	if (ztest_opts.zo_verbose >= 6)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4441
		dump_nvlist(props, 4);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4442
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4443
	nvlist_free(props);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4444
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4445
	(void) rw_unlock(&ztest_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4446
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4447
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4448
/*
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4449
 * Test snapshot hold/release and deferred destroy.
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4450
 */
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4451
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4452
ztest_dmu_snapshot_hold(ztest_ds_t *zd, uint64_t id)
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4453
{
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4454
	int error;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4455
	objset_t *os = zd->zd_os;
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4456
	objset_t *origin;
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4457
	char snapname[100];
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4458
	char fullname[100];
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4459
	char clonename[100];
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4460
	char tag[100];
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4461
	char osname[MAXNAMELEN];
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4462
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4463
	(void) rw_rdlock(&ztest_name_lock);
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4464
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4465
	dmu_objset_name(os, osname);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4466
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4467
	(void) snprintf(snapname, 100, "sh1_%llu", id);
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4468
	(void) snprintf(fullname, 100, "%s@%s", osname, snapname);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4469
	(void) snprintf(clonename, 100, "%s/ch1_%llu", osname, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4470
	(void) snprintf(tag, 100, "%tag_%llu", id);
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4471
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4472
	/*
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4473
	 * Clean up from any previous run.
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4474
	 */
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4475
	(void) dmu_objset_destroy(clonename, B_FALSE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4476
	(void) dsl_dataset_user_release(osname, snapname, tag, B_FALSE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4477
	(void) dmu_objset_destroy(fullname, B_FALSE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4478
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4479
	/*
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4480
	 * Create snapshot, clone it, mark snap for deferred destroy,
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4481
	 * destroy clone, verify snap was also destroyed.
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4482
	 */
13055
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  4483
	error = dmu_objset_snapshot(osname, snapname, NULL, NULL, FALSE,
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  4484
	    FALSE, -1);
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4485
	if (error) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4486
		if (error == ENOSPC) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4487
			ztest_record_enospc("dmu_objset_snapshot");
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4488
			goto out;
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4489
		}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4490
		fatal(0, "dmu_objset_snapshot(%s) = %d", fullname, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4491
	}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4492
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4493
	error = dmu_objset_hold(fullname, FTAG, &origin);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4494
	if (error)
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4495
		fatal(0, "dmu_objset_hold(%s) = %d", fullname, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4496
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4497
	error = dmu_objset_clone(clonename, dmu_objset_ds(origin), 0);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4498
	dmu_objset_rele(origin, FTAG);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4499
	if (error) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4500
		if (error == ENOSPC) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4501
			ztest_record_enospc("dmu_objset_clone");
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4502
			goto out;
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4503
		}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4504
		fatal(0, "dmu_objset_clone(%s) = %d", clonename, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4505
	}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4506
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4507
	error = dmu_objset_destroy(fullname, B_TRUE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4508
	if (error) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4509
		fatal(0, "dmu_objset_destroy(%s, B_TRUE) = %d",
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4510
		    fullname, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4511
	}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4512
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4513
	error = dmu_objset_destroy(clonename, B_FALSE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4514
	if (error)
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4515
		fatal(0, "dmu_objset_destroy(%s) = %d", clonename, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4516
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4517
	error = dmu_objset_hold(fullname, FTAG, &origin);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4518
	if (error != ENOENT)
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4519
		fatal(0, "dmu_objset_hold(%s) = %d", fullname, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4520
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4521
	/*
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4522
	 * Create snapshot, add temporary hold, verify that we can't
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4523
	 * destroy a held snapshot, mark for deferred destroy,
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4524
	 * release hold, verify snapshot was destroyed.
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4525
	 */
13055
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  4526
	error = dmu_objset_snapshot(osname, snapname, NULL, NULL, FALSE,
8c712bbb18ea PSARC 2010/105 zfs diff
Tim Haley <Tim.Haley@Sun.COM>
parents: 12961
diff changeset
  4527
	    FALSE, -1);
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4528
	if (error) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4529
		if (error == ENOSPC) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4530
			ztest_record_enospc("dmu_objset_snapshot");
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4531
			goto out;
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4532
		}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4533
		fatal(0, "dmu_objset_snapshot(%s) = %d", fullname, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4534
	}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4535
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12470
diff changeset
  4536
	error = dsl_dataset_user_hold(osname, snapname, tag, B_FALSE,
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12470
diff changeset
  4537
	    B_TRUE, -1);
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4538
	if (error)
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4539
		fatal(0, "dsl_dataset_user_hold(%s)", fullname, tag);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4540
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4541
	error = dmu_objset_destroy(fullname, B_FALSE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4542
	if (error != EBUSY) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4543
		fatal(0, "dmu_objset_destroy(%s, B_FALSE) = %d",
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4544
		    fullname, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4545
	}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4546
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4547
	error = dmu_objset_destroy(fullname, B_TRUE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4548
	if (error) {
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4549
		fatal(0, "dmu_objset_destroy(%s, B_TRUE) = %d",
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4550
		    fullname, error);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4551
	}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4552
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4553
	error = dsl_dataset_user_release(osname, snapname, tag, B_FALSE);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4554
	if (error)
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4555
		fatal(0, "dsl_dataset_user_release(%s)", fullname, tag);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4556
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4557
	VERIFY(dmu_objset_hold(fullname, FTAG, &origin) == ENOENT);
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4558
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4559
out:
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4560
	(void) rw_unlock(&ztest_name_lock);
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4561
}
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4562
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  4563
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4564
 * Inject random faults into the on-disk data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4565
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4566
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4567
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4568
ztest_fault_inject(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4569
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4570
	ztest_shared_t *zs = ztest_shared;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4571
	spa_t *spa = ztest_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4572
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4573
	uint64_t offset;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4574
	uint64_t leaves;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4575
	uint64_t bad = 0x1990c0ffeedecade;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4576
	uint64_t top, leaf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4577
	char path0[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4578
	char pathrand[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4579
	size_t fsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4580
	int bshift = SPA_MAXBLOCKSHIFT + 2;	/* don't scrog all labels */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4581
	int iters = 1000;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4582
	int maxfaults;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4583
	int mirror_save;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4584
	vdev_t *vd0 = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  4585
	uint64_t guid0 = 0;
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4586
	boolean_t islog = B_FALSE;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  4587
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4588
	VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4589
	maxfaults = MAXFAULTS();
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4590
	leaves = MAX(zs->zs_mirrors, 1) * ztest_opts.zo_raidz;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4591
	mirror_save = zs->zs_mirrors;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4592
	VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4593
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4594
	ASSERT(leaves >= 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4596
	/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4597
	 * We need SCL_STATE here because we're going to look at vd0->vdev_tsd.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4598
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4599
	spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4600
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4601
	if (ztest_random(2) == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4602
		/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4603
		 * Inject errors on a normal data device or slog device.
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4604
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4605
		top = ztest_random_vdev_top(spa, B_TRUE);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4606
		leaf = ztest_random(leaves) + zs->zs_splits;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4607
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4608
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4609
		 * Generate paths to the first leaf in this top-level vdev,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4610
		 * and to the random leaf we selected.  We'll induce transient
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4611
		 * write failures and random online/offline activity on leaf 0,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4612
		 * and we'll write random garbage to the randomly chosen leaf.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4613
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4614
		(void) snprintf(path0, sizeof (path0), ztest_dev_template,
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4615
		    ztest_opts.zo_dir, ztest_opts.zo_pool,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4616
		    top * leaves + zs->zs_splits);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4617
		(void) snprintf(pathrand, sizeof (pathrand), ztest_dev_template,
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4618
		    ztest_opts.zo_dir, ztest_opts.zo_pool,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4619
		    top * leaves + leaf);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4620
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4621
		vd0 = vdev_lookup_by_path(spa->spa_root_vdev, path0);
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4622
		if (vd0 != NULL && vd0->vdev_top->vdev_islog)
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4623
			islog = B_TRUE;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4624
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4625
		if (vd0 != NULL && maxfaults != 1) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4626
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4627
			 * Make vd0 explicitly claim to be unreadable,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4628
			 * or unwriteable, or reach behind its back
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4629
			 * and close the underlying fd.  We can do this if
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4630
			 * maxfaults == 0 because we'll fail and reexecute,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4631
			 * and we can do it if maxfaults >= 2 because we'll
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4632
			 * have enough redundancy.  If maxfaults == 1, the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4633
			 * combination of this with injection of random data
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4634
			 * corruption below exceeds the pool's fault tolerance.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4635
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4636
			vdev_file_t *vf = vd0->vdev_tsd;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4637
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4638
			if (vf != NULL && ztest_random(3) == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4639
				(void) close(vf->vf_vnode->v_fd);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4640
				vf->vf_vnode->v_fd = -1;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4641
			} else if (ztest_random(2) == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4642
				vd0->vdev_cant_read = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4643
			} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4644
				vd0->vdev_cant_write = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4645
			}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4646
			guid0 = vd0->vdev_guid;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4647
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4648
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4649
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4650
		 * Inject errors on an l2cache device.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4651
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4652
		spa_aux_vdev_t *sav = &spa->spa_l2cache;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4653
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4654
		if (sav->sav_count == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4655
			spa_config_exit(spa, SCL_STATE, FTAG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4656
			return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4657
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4658
		vd0 = sav->sav_vdevs[ztest_random(sav->sav_count)];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4659
		guid0 = vd0->vdev_guid;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4660
		(void) strcpy(path0, vd0->vdev_path);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4661
		(void) strcpy(pathrand, vd0->vdev_path);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4662
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4663
		leaf = 0;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4664
		leaves = 1;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4665
		maxfaults = INT_MAX;	/* no limit on cache devices */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4666
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4667
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4668
	spa_config_exit(spa, SCL_STATE, FTAG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  4669
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  4670
	/*
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4671
	 * If we can tolerate two or more faults, or we're dealing
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4672
	 * with a slog, randomly online/offline vd0.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  4673
	 */
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4674
	if ((maxfaults >= 2 || islog) && guid0 != 0) {
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  4675
		if (ztest_random(10) < 6) {
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  4676
			int flags = (ztest_random(2) == 0 ?
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  4677
			    ZFS_OFFLINE_TEMPORARY : 0);
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4678
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4679
			/*
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4680
			 * We have to grab the zs_name_lock as writer to
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4681
			 * prevent a race between offlining a slog and
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4682
			 * destroying a dataset. Offlining the slog will
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4683
			 * grab a reference on the dataset which may cause
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4684
			 * dmu_objset_destroy() to fail with EBUSY thus
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4685
			 * leaving the dataset in an inconsistent state.
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4686
			 */
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4687
			if (islog)
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4688
				(void) rw_wrlock(&ztest_name_lock);
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4689
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  4690
			VERIFY(vdev_offline(spa, guid0, flags) != EBUSY);
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4691
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4692
			if (islog)
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4693
				(void) rw_unlock(&ztest_name_lock);
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  4694
		} else {
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  4695
			(void) vdev_online(spa, guid0, 0, NULL);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  4696
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4697
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4698
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4699
	if (maxfaults == 0)
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4700
		return;
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
  4701
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4702
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  4703
	 * We have at least single-fault tolerance, so inject data corruption.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4704
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4705
	fd = open(pathrand, O_RDWR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4706
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4707
	if (fd == -1)	/* we hit a gap in the device namespace */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4708
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4709
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4710
	fsize = lseek(fd, 0, SEEK_END);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4711
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4712
	while (--iters != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4713
		offset = ztest_random(fsize / (leaves << bshift)) *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4714
		    (leaves << bshift) + (leaf << bshift) +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4715
		    (ztest_random(1ULL << (bshift - 1)) & -8ULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4716
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4717
		if (offset >= fsize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4718
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4719
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4720
		VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4721
		if (mirror_save != zs->zs_mirrors) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4722
			VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4723
			(void) close(fd);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4724
			return;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4725
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4726
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4727
		if (pwrite(fd, &bad, sizeof (bad), offset) != sizeof (bad))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4728
			fatal(1, "can't inject bad word at 0x%llx in %s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4729
			    offset, pathrand);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4730
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4731
		VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4732
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4733
		if (ztest_opts.zo_verbose >= 7)
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4734
			(void) printf("injected bad word into %s,"
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  4735
			    " offset 0x%llx\n", pathrand, (u_longlong_t)offset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4736
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4737
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4738
	(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4739
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4740
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4741
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4742
 * Verify that DDT repair works as expected.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4743
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4744
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4745
ztest_ddt_repair(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4746
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4747
	ztest_shared_t *zs = ztest_shared;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4748
	spa_t *spa = ztest_spa;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4749
	objset_t *os = zd->zd_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4750
	ztest_od_t od[1];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4751
	uint64_t object, blocksize, txg, pattern, psize;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4752
	enum zio_checksum checksum = spa_dedup_checksum(spa);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4753
	dmu_buf_t *db;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4754
	dmu_tx_t *tx;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4755
	void *buf;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4756
	blkptr_t blk;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4757
	int copies = 2 * ZIO_DEDUPDITTO_MIN;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4758
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4759
	blocksize = ztest_random_blocksize();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4760
	blocksize = MIN(blocksize, 2048);	/* because we write so many */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4761
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4762
	ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, blocksize, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4763
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4764
	if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4765
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4766
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4767
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4768
	 * Take the name lock as writer to prevent anyone else from changing
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4769
	 * the pool and dataset properies we need to maintain during this test.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4770
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4771
	(void) rw_wrlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4772
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4773
	if (ztest_dsl_prop_set_uint64(zd->zd_name, ZFS_PROP_DEDUP, checksum,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4774
	    B_FALSE) != 0 ||
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4775
	    ztest_dsl_prop_set_uint64(zd->zd_name, ZFS_PROP_COPIES, 1,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4776
	    B_FALSE) != 0) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4777
		(void) rw_unlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4778
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4779
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4780
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4781
	object = od[0].od_object;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4782
	blocksize = od[0].od_blocksize;
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4783
	pattern = zs->zs_guid ^ dmu_objset_fsid_guid(os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4784
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4785
	ASSERT(object != 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4786
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4787
	tx = dmu_tx_create(os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4788
	dmu_tx_hold_write(tx, object, 0, copies * blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4789
	txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4790
	if (txg == 0) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4791
		(void) rw_unlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4792
		return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4793
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4794
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4795
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4796
	 * Write all the copies of our block.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4797
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4798
	for (int i = 0; i < copies; i++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4799
		uint64_t offset = i * blocksize;
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
  4800
		VERIFY(dmu_buf_hold(os, object, offset, FTAG, &db,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
  4801
		    DMU_READ_NO_PREFETCH) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4802
		ASSERT(db->db_offset == offset);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4803
		ASSERT(db->db_size == blocksize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4804
		ASSERT(ztest_pattern_match(db->db_data, db->db_size, pattern) ||
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4805
		    ztest_pattern_match(db->db_data, db->db_size, 0ULL));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4806
		dmu_buf_will_fill(db, tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4807
		ztest_pattern_set(db->db_data, db->db_size, pattern);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4808
		dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4809
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4810
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4811
	dmu_tx_commit(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4812
	txg_wait_synced(spa_get_dsl(spa), txg);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4813
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4814
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4815
	 * Find out what block we got.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4816
	 */
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
  4817
	VERIFY(dmu_buf_hold(os, object, 0, FTAG, &db,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11864
diff changeset
  4818
	    DMU_READ_NO_PREFETCH) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4819
	blk = *((dmu_buf_impl_t *)db)->db_blkptr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4820
	dmu_buf_rele(db, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4821
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4822
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4823
	 * Damage the block.  Dedup-ditto will save us when we read it later.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4824
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4825
	psize = BP_GET_PSIZE(&blk);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4826
	buf = zio_buf_alloc(psize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4827
	ztest_pattern_set(buf, psize, ~pattern);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4828
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4829
	(void) zio_wait(zio_rewrite(NULL, spa, 0, &blk,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4830
	    buf, psize, NULL, NULL, ZIO_PRIORITY_SYNC_WRITE,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4831
	    ZIO_FLAG_CANFAIL | ZIO_FLAG_INDUCE_DAMAGE, NULL));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4832
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4833
	zio_buf_free(buf, psize);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4834
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4835
	(void) rw_unlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4836
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4837
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4838
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4839
 * Scrub the pool.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4840
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4841
/* ARGSUSED */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4842
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4843
ztest_scrub(ztest_ds_t *zd, uint64_t id)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4844
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4845
	spa_t *spa = ztest_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4846
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
  4847
	(void) spa_scan(spa, POOL_SCAN_SCRUB);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4848
	(void) poll(NULL, 0, 100); /* wait a moment, then force a restart */
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
  4849
	(void) spa_scan(spa, POOL_SCAN_SCRUB);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4850
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4851
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4852
/*
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4853
 * Change the guid for the pool.
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4854
 */
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4855
/* ARGSUSED */
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4856
void
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4857
ztest_reguid(ztest_ds_t *zd, uint64_t id)
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4858
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4859
	spa_t *spa = ztest_spa;
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4860
	uint64_t orig, load;
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4861
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4862
	orig = spa_guid(spa);
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4863
	load = spa_load_guid(spa);
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4864
	if (spa_change_guid(spa) != 0)
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4865
		return;
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4866
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4867
	if (ztest_opts.zo_verbose >= 3) {
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4868
		(void) printf("Changed guid old %llu -> %llu\n",
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4869
		    (u_longlong_t)orig, (u_longlong_t)spa_guid(spa));
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4870
	}
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4871
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4872
	VERIFY3U(orig, !=, spa_guid(spa));
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4873
	VERIFY3U(load, ==, spa_load_guid(spa));
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4874
}
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4875
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  4876
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4877
 * Rename the pool to a different name and then rename it back.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4878
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4879
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4880
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4881
ztest_spa_rename(ztest_ds_t *zd, uint64_t id)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4882
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4883
	char *oldname, *newname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4884
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4885
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4886
	(void) rw_wrlock(&ztest_name_lock);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4887
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4888
	oldname = ztest_opts.zo_pool;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4889
	newname = umem_alloc(strlen(oldname) + 5, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4890
	(void) strcpy(newname, oldname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4891
	(void) strcat(newname, "_tmp");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4892
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4893
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4894
	 * Do the rename
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4895
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4896
	VERIFY3U(0, ==, spa_rename(oldname, newname));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4897
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4898
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4899
	 * Try to open it under the old name, which shouldn't exist
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4900
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4901
	VERIFY3U(ENOENT, ==, spa_open(oldname, &spa, FTAG));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4902
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4903
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4904
	 * 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
  4905
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4906
	VERIFY3U(0, ==, spa_open(newname, &spa, FTAG));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4907
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4908
	ASSERT(spa == ztest_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4909
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4910
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4911
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4912
	 * Rename it back to the original
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4913
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4914
	VERIFY3U(0, ==, spa_rename(newname, oldname));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4915
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4916
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4917
	 * Make sure it can still be opened
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4918
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4919
	VERIFY3U(0, ==, spa_open(oldname, &spa, FTAG));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4920
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4921
	ASSERT(spa == ztest_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4922
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4923
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4924
	umem_free(newname, strlen(newname) + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4925
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4926
	(void) rw_unlock(&ztest_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4927
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4928
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4929
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4930
 * Verify pool integrity by running zdb.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4931
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4932
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  4933
ztest_run_zdb(char *pool)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4934
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4935
	int status;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4936
	char zdb[MAXPATHLEN + MAXNAMELEN + 20];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4937
	char zbuf[1024];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4938
	char *bin;
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4939
	char *ztest;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4940
	char *isa;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4941
	int isalen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4942
	FILE *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4943
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4944
	(void) realpath(getexecname(), zdb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4945
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4946
	/* zdb lives in /usr/sbin, while ztest lives in /usr/bin */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4947
	bin = strstr(zdb, "/usr/bin/");
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4948
	ztest = strstr(bin, "/ztest");
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4949
	isa = bin + 8;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4950
	isalen = ztest - isa;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4951
	isa = strdup(isa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4952
	/* LINTED */
5994
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5530
diff changeset
  4953
	(void) sprintf(bin,
11811
b25d9f1b5d8e 6914746 sprintf_blkptr() causes NULL pointer dereference
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11497
diff changeset
  4954
	    "/usr/sbin%.*s/zdb -bcc%s%s -U %s %s",
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4955
	    isalen,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4956
	    isa,
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4957
	    ztest_opts.zo_verbose >= 3 ? "s" : "",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4958
	    ztest_opts.zo_verbose >= 4 ? "v" : "",
11811
b25d9f1b5d8e 6914746 sprintf_blkptr() causes NULL pointer dereference
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11497
diff changeset
  4959
	    spa_config_path,
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7793
diff changeset
  4960
	    pool);
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  4961
	free(isa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4962
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4963
	if (ztest_opts.zo_verbose >= 5)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4964
		(void) printf("Executing %s\n", strstr(zdb, "zdb "));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4965
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4966
	fp = popen(zdb, "r");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4967
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4968
	while (fgets(zbuf, sizeof (zbuf), fp) != NULL)
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4969
		if (ztest_opts.zo_verbose >= 3)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4970
			(void) printf("%s", zbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4971
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4972
	status = pclose(fp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4973
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4974
	if (status == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4975
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4976
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4977
	ztest_dump_core = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4978
	if (WIFEXITED(status))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4979
		fatal(0, "'%s' exit code %d", zdb, WEXITSTATUS(status));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4980
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4981
		fatal(0, "'%s' died with signal %d", zdb, WTERMSIG(status));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4982
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4983
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4984
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4985
ztest_walk_pool_directory(char *header)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4986
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4987
	spa_t *spa = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4988
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4989
	if (ztest_opts.zo_verbose >= 6)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4990
		(void) printf("%s\n", header);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4991
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4992
	mutex_enter(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4993
	while ((spa = spa_next(spa)) != NULL)
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  4994
		if (ztest_opts.zo_verbose >= 6)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4995
			(void) printf("\t%s\n", spa_name(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4996
	mutex_exit(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4997
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4998
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4999
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5000
ztest_spa_import_export(char *oldname, char *newname)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5001
{
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5002
	nvlist_t *config, *newconfig;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5003
	uint64_t pool_guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5004
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5005
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5006
	if (ztest_opts.zo_verbose >= 4) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5007
		(void) printf("import/export: old = %s, new = %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5008
		    oldname, newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5009
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5011
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5012
	 * Clean up from previous runs.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5013
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5014
	(void) spa_destroy(newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5015
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5016
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5017
	 * Get the pool's configuration and guid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5018
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5019
	VERIFY3U(0, ==, spa_open(oldname, &spa, FTAG));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5020
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5021
	/*
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5022
	 * Kick off a scrub to tickle scrub/export races.
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5023
	 */
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5024
	if (ztest_random(2) == 0)
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 12294
diff changeset
  5025
		(void) spa_scan(spa, POOL_SCAN_SCRUB);
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5026
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5027
	pool_guid = spa_guid(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5028
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5029
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5030
	ztest_walk_pool_directory("pools before export");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5031
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5032
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5033
	 * Export it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5034
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5035
	VERIFY3U(0, ==, spa_export(oldname, &config, B_FALSE, B_FALSE));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5036
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5037
	ztest_walk_pool_directory("pools after export");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5038
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5039
	/*
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5040
	 * Try to import it.
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5041
	 */
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5042
	newconfig = spa_tryimport(config);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5043
	ASSERT(newconfig != NULL);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5044
	nvlist_free(newconfig);
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5045
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5046
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5047
	 * Import it under the new name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5048
	 */
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12754
diff changeset
  5049
	VERIFY3U(0, ==, spa_import(newname, config, NULL, 0));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5050
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5051
	ztest_walk_pool_directory("pools after import");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5052
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5053
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5054
	 * Try to import it again -- should fail with EEXIST.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5055
	 */
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12754
diff changeset
  5056
	VERIFY3U(EEXIST, ==, spa_import(newname, config, NULL, 0));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5057
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5058
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5059
	 * Try to import it under a different name -- should fail with EEXIST.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5060
	 */
12961
b521d551715f 6733267 Allow a pool to be imported with a missing slog
George Wilson <George.Wilson@Sun.COM>
parents: 12754
diff changeset
  5061
	VERIFY3U(EEXIST, ==, spa_import(oldname, config, NULL, 0));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5062
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5063
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5064
	 * Verify that the pool is no longer visible under the old name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5065
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5066
	VERIFY3U(ENOENT, ==, spa_open(oldname, &spa, FTAG));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5067
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5068
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5069
	 * Verify that we can open and close the pool using the new name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5070
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5071
	VERIFY3U(0, ==, spa_open(newname, &spa, FTAG));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5072
	ASSERT(pool_guid == spa_guid(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5073
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5074
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5075
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5076
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5077
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5078
static void
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5079
ztest_resume(spa_t *spa)
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5080
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5081
	if (spa_suspended(spa) && ztest_opts.zo_verbose >= 6)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5082
		(void) printf("resuming from suspended state\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5083
	spa_vdev_state_enter(spa, SCL_NONE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5084
	vdev_clear(spa, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5085
	(void) spa_vdev_state_exit(spa, NULL, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5086
	(void) zio_resume(spa);
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5087
}
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5088
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5089
static void *
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5090
ztest_resume_thread(void *arg)
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5091
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5092
	spa_t *spa = arg;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5093
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5094
	while (!ztest_exiting) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5095
		if (spa_suspended(spa))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5096
			ztest_resume(spa);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5097
		(void) poll(NULL, 0, 100);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5098
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5099
	return (NULL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5100
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5101
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5102
static void *
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5103
ztest_deadman_thread(void *arg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5104
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5105
	ztest_shared_t *zs = arg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5106
	int grace = 300;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5107
	hrtime_t delta;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5108
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5109
	delta = (zs->zs_thread_stop - zs->zs_thread_start) / NANOSEC + grace;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5110
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5111
	(void) poll(NULL, 0, (int)(1000 * delta));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5112
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5113
	fatal(0, "failed to complete within %d seconds of deadline", grace);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5114
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5115
	return (NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5116
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5117
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5118
static void
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5119
ztest_execute(int test, ztest_info_t *zi, uint64_t id)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5120
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5121
	ztest_ds_t *zd = &ztest_ds[id % ztest_opts.zo_datasets];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5122
	ztest_shared_callstate_t *zc = ZTEST_GET_SHARED_CALLSTATE(test);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5123
	hrtime_t functime = gethrtime();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5124
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5125
	for (int i = 0; i < zi->zi_iters; i++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5126
		zi->zi_func(zd, id);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5127
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5128
	functime = gethrtime() - functime;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5129
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5130
	atomic_add_64(&zc->zc_count, 1);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5131
	atomic_add_64(&zc->zc_time, functime);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5132
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5133
	if (ztest_opts.zo_verbose >= 4) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5134
		Dl_info dli;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5135
		(void) dladdr((void *)zi->zi_func, &dli);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5136
		(void) printf("%6.2f sec in %s\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5137
		    (double)functime / NANOSEC, dli.dli_sname);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5138
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5139
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5140
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5141
static void *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5142
ztest_thread(void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5143
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5144
	int rand;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5145
	uint64_t id = (uintptr_t)arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5146
	ztest_shared_t *zs = ztest_shared;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5147
	uint64_t call_next;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5148
	hrtime_t now;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5149
	ztest_info_t *zi;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5150
	ztest_shared_callstate_t *zc;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5151
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5152
	while ((now = gethrtime()) < zs->zs_thread_stop) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5153
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5154
		 * See if it's time to force a crash.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5155
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5156
		if (now > zs->zs_thread_kill)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5157
			ztest_kill(zs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5158
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5159
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5160
		 * If we're getting ENOSPC with some regularity, stop.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5161
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5162
		if (zs->zs_enospc_count > 10)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5163
			break;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5164
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5165
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5166
		 * Pick a random function to execute.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5167
		 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5168
		rand = ztest_random(ZTEST_FUNCS);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5169
		zi = &ztest_info[rand];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5170
		zc = ZTEST_GET_SHARED_CALLSTATE(rand);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5171
		call_next = zc->zc_next;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5172
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5173
		if (now >= call_next &&
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5174
		    atomic_cas_64(&zc->zc_next, call_next, call_next +
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5175
		    ztest_random(2 * zi->zi_interval[0] + 1)) == call_next) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5176
			ztest_execute(rand, zi, id);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5177
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5178
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5180
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5181
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5182
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5183
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5184
ztest_dataset_name(char *dsname, char *pool, int d)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5185
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5186
	(void) snprintf(dsname, MAXNAMELEN, "%s/ds_%d", pool, d);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5187
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5188
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5189
static void
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5190
ztest_dataset_destroy(int d)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5191
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5192
	char name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5193
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5194
	ztest_dataset_name(name, ztest_opts.zo_pool, d);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5195
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5196
	if (ztest_opts.zo_verbose >= 3)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5197
		(void) printf("Destroying %s to free up space\n", name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5198
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5199
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5200
	 * Cleanup any non-standard clones and snapshots.  In general,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5201
	 * ztest thread t operates on dataset (t % zopt_datasets),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5202
	 * so there may be more than one thing to clean up.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5203
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5204
	for (int t = d; t < ztest_opts.zo_threads;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5205
	    t += ztest_opts.zo_datasets) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5206
		ztest_dsl_dataset_cleanup(name, t);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5207
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5208
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5209
	(void) dmu_objset_find(name, ztest_objset_destroy_cb, NULL,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5210
	    DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5211
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5212
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5213
static void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5214
ztest_dataset_dirobj_verify(ztest_ds_t *zd)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5215
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5216
	uint64_t usedobjs, dirobjs, scratch;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5217
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5218
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5219
	 * ZTEST_DIROBJ is the object directory for the entire dataset.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5220
	 * Therefore, the number of objects in use should equal the
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5221
	 * number of ZTEST_DIROBJ entries, +1 for ZTEST_DIROBJ itself.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5222
	 * If not, we have an object leak.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5223
	 *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5224
	 * Note that we can only check this in ztest_dataset_open(),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5225
	 * when the open-context and syncing-context values agree.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5226
	 * That's because zap_count() returns the open-context value,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5227
	 * while dmu_objset_space() returns the rootbp fill count.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5228
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5229
	VERIFY3U(0, ==, zap_count(zd->zd_os, ZTEST_DIROBJ, &dirobjs));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5230
	dmu_objset_space(zd->zd_os, &scratch, &scratch, &usedobjs, &scratch);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5231
	ASSERT3U(dirobjs + 1, ==, usedobjs);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5232
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5233
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5234
static int
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5235
ztest_dataset_open(int d)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5236
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5237
	ztest_ds_t *zd = &ztest_ds[d];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5238
	uint64_t committed_seq = ZTEST_GET_SHARED_DS(d)->zd_seq;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5239
	objset_t *os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5240
	zilog_t *zilog;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5241
	char name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5242
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5243
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5244
	ztest_dataset_name(name, ztest_opts.zo_pool, d);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5245
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5246
	(void) rw_rdlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5247
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  5248
	error = ztest_dataset_create(name);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5249
	if (error == ENOSPC) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5250
		(void) rw_unlock(&ztest_name_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5251
		ztest_record_enospc(FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5252
		return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5253
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5254
	ASSERT(error == 0 || error == EEXIST);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5255
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5256
	VERIFY3U(dmu_objset_hold(name, zd, &os), ==, 0);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5257
	(void) rw_unlock(&ztest_name_lock);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5258
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5259
	ztest_zd_init(zd, ZTEST_GET_SHARED_DS(d), os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5260
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5261
	zilog = zd->zd_zilog;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5262
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5263
	if (zilog->zl_header->zh_claim_lr_seq != 0 &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5264
	    zilog->zl_header->zh_claim_lr_seq < committed_seq)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5265
		fatal(0, "missing log records: claimed %llu < committed %llu",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5266
		    zilog->zl_header->zh_claim_lr_seq, committed_seq);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5267
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5268
	ztest_dataset_dirobj_verify(zd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5269
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5270
	zil_replay(os, zd, ztest_replay_vector);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5271
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5272
	ztest_dataset_dirobj_verify(zd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5273
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5274
	if (ztest_opts.zo_verbose >= 6)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5275
		(void) printf("%s replay %llu blocks, %llu records, seq %llu\n",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5276
		    zd->zd_name,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5277
		    (u_longlong_t)zilog->zl_parse_blk_count,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5278
		    (u_longlong_t)zilog->zl_parse_lr_count,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5279
		    (u_longlong_t)zilog->zl_replaying_seq);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5280
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5281
	zilog = zil_open(os, ztest_get_data);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5282
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5283
	if (zilog->zl_replaying_seq != 0 &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5284
	    zilog->zl_replaying_seq < committed_seq)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5285
		fatal(0, "missing log records: replayed %llu < committed %llu",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5286
		    zilog->zl_replaying_seq, committed_seq);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5287
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5288
	return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5289
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5290
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5291
static void
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5292
ztest_dataset_close(int d)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5293
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5294
	ztest_ds_t *zd = &ztest_ds[d];
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5295
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5296
	zil_close(zd->zd_zilog);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5297
	dmu_objset_rele(zd->zd_os, zd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5298
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5299
	ztest_zd_fini(zd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5300
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5301
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5302
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5303
 * Kick off threads to run tests on all datasets in parallel.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5304
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5305
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5306
ztest_run(ztest_shared_t *zs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5307
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5308
	thread_t *tid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5309
	spa_t *spa;
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  5310
	objset_t *os;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5311
	thread_t resume_tid;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5312
	int error;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5313
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5314
	ztest_exiting = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5315
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5316
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5317
	 * Initialize parent/child shared state.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5318
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5319
	VERIFY(_mutex_init(&ztest_vdev_lock, USYNC_THREAD, NULL) == 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5320
	VERIFY(rwlock_init(&ztest_name_lock, USYNC_THREAD, NULL) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5321
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5322
	zs->zs_thread_start = gethrtime();
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5323
	zs->zs_thread_stop =
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5324
	    zs->zs_thread_start + ztest_opts.zo_passtime * NANOSEC;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5325
	zs->zs_thread_stop = MIN(zs->zs_thread_stop, zs->zs_proc_stop);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5326
	zs->zs_thread_kill = zs->zs_thread_stop;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5327
	if (ztest_random(100) < ztest_opts.zo_killrate) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5328
		zs->zs_thread_kill -=
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5329
		    ztest_random(ztest_opts.zo_passtime * NANOSEC);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5330
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5331
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5332
	(void) _mutex_init(&zcl.zcl_callbacks_lock, USYNC_THREAD, NULL);
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  5333
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  5334
	list_create(&zcl.zcl_callbacks, sizeof (ztest_cb_data_t),
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  5335
	    offsetof(ztest_cb_data_t, zcd_node));
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10594
diff changeset
  5336
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5337
	/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5338
	 * Open our pool.
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5339
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5340
	kernel_init(FREAD | FWRITE);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5341
	VERIFY(spa_open(ztest_opts.zo_pool, &spa, FTAG) == 0);
13379
4df42cc92254 1051 zfs should handle imbalanced luns
George Wilson <George.Wilson@delphix.com>
parents: 13055
diff changeset
  5342
	spa->spa_debug = B_TRUE;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5343
	ztest_spa = spa;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5344
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5345
	VERIFY3U(0, ==, dmu_objset_hold(ztest_opts.zo_pool, FTAG, &os));
13514
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  5346
	zs->zs_guid = dmu_objset_fsid_guid(os);
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  5347
	dmu_objset_rele(os, FTAG);
417c34452f03 1748 desire support for reguid in zfs
Garrett D'Amore <garrett@nexenta.com>
parents: 13380
diff changeset
  5348
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5349
	spa->spa_dedup_ditto = 2 * ZIO_DEDUPDITTO_MIN;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5350
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  5351
	/*
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5352
	 * We don't expect the pool to suspend unless maxfaults == 0,
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5353
	 * in which case ztest_fault_inject() temporarily takes away
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5354
	 * the only valid replica.
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5355
	 */
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5356
	if (MAXFAULTS() == 0)
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5357
		spa->spa_failmode = ZIO_FAILURE_MODE_WAIT;
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5358
	else
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5359
		spa->spa_failmode = ZIO_FAILURE_MODE_PANIC;
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5360
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5361
	/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5362
	 * Create a thread to periodically resume suspended I/O.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5363
	 */
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5364
	VERIFY(thr_create(0, 0, ztest_resume_thread, spa, THR_BOUND,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5365
	    &resume_tid) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5366
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5367
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5368
	 * Create a deadman thread to abort() if we hang.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5369
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5370
	VERIFY(thr_create(0, 0, ztest_deadman_thread, zs, THR_BOUND,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5371
	    NULL) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5372
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5373
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5374
	 * Verify that we can safely inquire about about any object,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5375
	 * whether it's allocated or not.  To make it interesting,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5376
	 * we probe a 5-wide window around each power of two.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5377
	 * This hits all edge cases, including zero and the max.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5378
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5379
	for (int t = 0; t < 64; t++) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5380
		for (int d = -5; d <= 5; d++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5381
			error = dmu_object_info(spa->spa_meta_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5382
			    (1ULL << t) + d, NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  5383
			ASSERT(error == 0 || error == ENOENT ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  5384
			    error == EINVAL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5385
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5386
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5387
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5388
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5389
	 * If we got any ENOSPC errors on the previous run, destroy something.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5390
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5391
	if (zs->zs_enospc_count != 0) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5392
		int d = ztest_random(ztest_opts.zo_datasets);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5393
		ztest_dataset_destroy(d);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5394
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5395
	zs->zs_enospc_count = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5396
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5397
	tid = umem_zalloc(ztest_opts.zo_threads * sizeof (thread_t),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5398
	    UMEM_NOFAIL);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5399
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5400
	if (ztest_opts.zo_verbose >= 4)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5401
		(void) printf("starting main threads...\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5402
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5403
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5404
	 * Kick off all the tests that run in parallel.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5405
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5406
	for (int t = 0; t < ztest_opts.zo_threads; t++) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5407
		if (t < ztest_opts.zo_datasets &&
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5408
		    ztest_dataset_open(t) != 0)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5409
			return;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5410
		VERIFY(thr_create(0, 0, ztest_thread, (void *)(uintptr_t)t,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5411
		    THR_BOUND, &tid[t]) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5412
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5413
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5414
	/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5415
	 * Wait for all of the tests to complete.  We go in reverse order
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5416
	 * so we don't close datasets while threads are still using them.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5417
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5418
	for (int t = ztest_opts.zo_threads - 1; t >= 0; t--) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5419
		VERIFY(thr_join(tid[t], NULL, NULL) == 0);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5420
		if (t < ztest_opts.zo_datasets)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5421
			ztest_dataset_close(t);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5422
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5423
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  5424
	txg_wait_synced(spa_get_dsl(spa), 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5425
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5426
	zs->zs_alloc = metaslab_class_get_alloc(spa_normal_class(spa));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5427
	zs->zs_space = metaslab_class_get_space(spa_normal_class(spa));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5428
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5429
	umem_free(tid, ztest_opts.zo_threads * sizeof (thread_t));
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5430
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5431
	/* Kill the resume thread */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5432
	ztest_exiting = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5433
	VERIFY(thr_join(resume_tid, NULL, NULL) == 0);
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8227
diff changeset
  5434
	ztest_resume(spa);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  5435
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5436
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5437
	 * Right before closing the pool, kick off a bunch of async I/O;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5438
	 * spa_close() should wait for it to complete.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5439
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5440
	for (uint64_t object = 1; object < 50; object++)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5441
		dmu_prefetch(spa->spa_meta_objset, object, 0, 1ULL << 20);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5442
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  5443
	spa_close(spa, FTAG);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  5444
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5445
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5446
	 * Verify that we can loop over all pools.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5447
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5448
	mutex_enter(&spa_namespace_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5449
	for (spa = spa_next(NULL); spa != NULL; spa = spa_next(spa))
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5450
		if (ztest_opts.zo_verbose > 3)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5451
			(void) printf("spa_next: found %s\n", spa_name(spa));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5452
	mutex_exit(&spa_namespace_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5453
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5454
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5455
	 * Verify that we can export the pool and reimport it under a
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5456
	 * different name.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5457
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5458
	if (ztest_random(2) == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5459
		char name[MAXNAMELEN];
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5460
		(void) snprintf(name, MAXNAMELEN, "%s_import",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5461
		    ztest_opts.zo_pool);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5462
		ztest_spa_import_export(ztest_opts.zo_pool, name);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5463
		ztest_spa_import_export(name, ztest_opts.zo_pool);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5464
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5465
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5466
	kernel_fini();
12754
d8e9c68f95f4 6966214 ztest_freeze(): Assertion failed: list->list_head.list_next == node
George Wilson <George.Wilson@Sun.COM>
parents: 12700
diff changeset
  5467
d8e9c68f95f4 6966214 ztest_freeze(): Assertion failed: list->list_head.list_next == node
George Wilson <George.Wilson@Sun.COM>
parents: 12700
diff changeset
  5468
	list_destroy(&zcl.zcl_callbacks);
d8e9c68f95f4 6966214 ztest_freeze(): Assertion failed: list->list_head.list_next == node
George Wilson <George.Wilson@Sun.COM>
parents: 12700
diff changeset
  5469
d8e9c68f95f4 6966214 ztest_freeze(): Assertion failed: list->list_head.list_next == node
George Wilson <George.Wilson@Sun.COM>
parents: 12700
diff changeset
  5470
	(void) _mutex_destroy(&zcl.zcl_callbacks_lock);
d8e9c68f95f4 6966214 ztest_freeze(): Assertion failed: list->list_head.list_next == node
George Wilson <George.Wilson@Sun.COM>
parents: 12700
diff changeset
  5471
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5472
	(void) rwlock_destroy(&ztest_name_lock);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5473
	(void) _mutex_destroy(&ztest_vdev_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5474
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5475
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5476
static void
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5477
ztest_freeze(void)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5478
{
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5479
	ztest_ds_t *zd = &ztest_ds[0];
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5480
	spa_t *spa;
11818
579d80da300a 6917573 ztest hangs on dsl_pool_sync()
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11811
diff changeset
  5481
	int numloops = 0;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5482
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5483
	if (ztest_opts.zo_verbose >= 3)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5484
		(void) printf("testing spa_freeze()...\n");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5485
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5486
	kernel_init(FREAD | FWRITE);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5487
	VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5488
	VERIFY3U(0, ==, ztest_dataset_open(0));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5489
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5490
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5491
	 * Force the first log block to be transactionally allocated.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5492
	 * We have to do this before we freeze the pool -- otherwise
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5493
	 * the log chain won't be anchored.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5494
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5495
	while (BP_IS_HOLE(&zd->zd_zilog->zl_header->zh_log)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5496
		ztest_dmu_object_alloc_free(zd, 0);
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  5497
		zil_commit(zd->zd_zilog, 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5498
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5499
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5500
	txg_wait_synced(spa_get_dsl(spa), 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5501
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5502
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5503
	 * Freeze the pool.  This stops spa_sync() from doing anything,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5504
	 * so that the only way to record changes from now on is the ZIL.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5505
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5506
	spa_freeze(spa);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5507
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5508
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5509
	 * Run tests that generate log records but don't alter the pool config
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5510
	 * or depend on DSL sync tasks (snapshots, objset create/destroy, etc).
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5511
	 * We do a txg_wait_synced() after each iteration to force the txg
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5512
	 * to increase well beyond the last synced value in the uberblock.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5513
	 * The ZIL should be OK with that.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5514
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5515
	while (ztest_random(10) != 0 &&
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5516
	    numloops++ < ztest_opts.zo_maxloops) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5517
		ztest_dmu_write_parallel(zd, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5518
		ztest_dmu_object_alloc_free(zd, 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5519
		txg_wait_synced(spa_get_dsl(spa), 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5520
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5521
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5522
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5523
	 * Commit all of the changes we just generated.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5524
	 */
12699
36aebb51164a 6913010 assertion failed: error||lr->lr_length <= zp->z_blksz, file: ../../common/fs/zfs/zfs_vnops.c
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 12527
diff changeset
  5525
	zil_commit(zd->zd_zilog, 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5526
	txg_wait_synced(spa_get_dsl(spa), 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5527
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5528
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5529
	 * Close our dataset and close the pool.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5530
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5531
	ztest_dataset_close(0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5532
	spa_close(spa, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5533
	kernel_fini();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5534
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5535
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5536
	 * Open and close the pool and dataset to induce log replay.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5537
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5538
	kernel_init(FREAD | FWRITE);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5539
	VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5540
	VERIFY3U(0, ==, ztest_dataset_open(0));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5541
	ztest_dataset_close(0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5542
	spa_close(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5543
	kernel_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5544
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5545
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5546
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5547
print_time(hrtime_t t, char *timebuf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5548
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5549
	hrtime_t s = t / NANOSEC;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5550
	hrtime_t m = s / 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5551
	hrtime_t h = m / 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5552
	hrtime_t d = h / 24;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5553
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5554
	s -= m * 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5555
	m -= h * 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5556
	h -= d * 24;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5557
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5558
	timebuf[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5559
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5560
	if (d)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5561
		(void) sprintf(timebuf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5562
		    "%llud%02lluh%02llum%02llus", d, h, m, s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5563
	else if (h)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5564
		(void) sprintf(timebuf, "%lluh%02llum%02llus", h, m, s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5565
	else if (m)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5566
		(void) sprintf(timebuf, "%llum%02llus", m, s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5567
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5568
		(void) sprintf(timebuf, "%llus", s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5569
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5570
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5571
static nvlist_t *
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5572
make_random_props()
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5573
{
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5574
	nvlist_t *props;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5575
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5576
	VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5577
	if (ztest_random(2) == 0)
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5578
		return (props);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5579
	VERIFY(nvlist_add_uint64(props, "autoreplace", 1) == 0);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5580
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5581
	return (props);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5582
}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5583
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5584
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5585
 * Create a storage pool with the given name and initial vdev size.
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5586
 * Then test spa_freeze() functionality.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5587
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5588
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5589
ztest_init(ztest_shared_t *zs)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5590
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5591
	spa_t *spa;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5592
	nvlist_t *nvroot, *props;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5593
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5594
	VERIFY(_mutex_init(&ztest_vdev_lock, USYNC_THREAD, NULL) == 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5595
	VERIFY(rwlock_init(&ztest_name_lock, USYNC_THREAD, NULL) == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5596
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5597
	kernel_init(FREAD | FWRITE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5598
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5599
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5600
	 * Create the storage pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5601
	 */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5602
	(void) spa_destroy(ztest_opts.zo_pool);
10594
986cb68d2347 6574286 removing a slog doesn't work
George Wilson <George.Wilson@Sun.COM>
parents: 10588
diff changeset
  5603
	ztest_shared->zs_vdev_next_leaf = 0;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5604
	zs->zs_splits = 0;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5605
	zs->zs_mirrors = ztest_opts.zo_mirrors;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5606
	nvroot = make_vdev_root(NULL, NULL, ztest_opts.zo_vdev_size, 0,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5607
	    0, ztest_opts.zo_raidz, zs->zs_mirrors, 1);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11209
diff changeset
  5608
	props = make_random_props();
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5609
	for (int i = 0; i < SPA_FEATURES; i++) {
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5610
		char buf[1024];
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5611
		(void) snprintf(buf, sizeof (buf), "feature@%s",
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5612
		    spa_feature_table[i].fi_uname);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5613
		VERIFY3U(0, ==, nvlist_add_uint64(props, buf, 0));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5614
	}
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5615
	VERIFY3U(0, ==, spa_create(ztest_opts.zo_pool, nvroot, props,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5616
	    NULL, NULL));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5617
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5618
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5619
	VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5620
	zs->zs_metaslab_sz =
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5621
	    1ULL << spa->spa_root_vdev->vdev_child[0]->vdev_ms_shift;
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5622
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5623
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5624
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5625
	kernel_fini();
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5626
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5627
	ztest_run_zdb(ztest_opts.zo_pool);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5628
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5629
	ztest_freeze();
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5630
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5631
	ztest_run_zdb(ztest_opts.zo_pool);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5632
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5633
	(void) rwlock_destroy(&ztest_name_lock);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5634
	(void) _mutex_destroy(&ztest_vdev_lock);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5635
}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5636
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5637
static void
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5638
setup_fds(void)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5639
{
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5640
	int fd;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5641
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5642
	char *tmp = tempnam(NULL, NULL);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5643
	fd = open(tmp, O_RDWR | O_CREAT, 0700);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5644
	ASSERT3U(fd, ==, ZTEST_FD_DATA);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5645
	(void) unlink(tmp);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5646
	free(tmp);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5647
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5648
	fd = open("/dev/urandom", O_RDONLY);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5649
	ASSERT3U(fd, ==, ZTEST_FD_RAND);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5650
}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5651
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5652
static int
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5653
shared_data_size(ztest_shared_hdr_t *hdr)
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5654
{
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5655
	int size;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5656
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5657
	size = hdr->zh_hdr_size;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5658
	size += hdr->zh_opts_size;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5659
	size += hdr->zh_size;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5660
	size += hdr->zh_stats_size * hdr->zh_stats_count;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5661
	size += hdr->zh_ds_size * hdr->zh_ds_count;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5662
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5663
	return (size);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5664
}
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5665
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5666
static void
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5667
setup_hdr(void)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5668
{
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5669
	int size;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5670
	ztest_shared_hdr_t *hdr;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5671
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5672
	hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5673
	    PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5674
	ASSERT(hdr != MAP_FAILED);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5675
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5676
	VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, sizeof (ztest_shared_hdr_t)));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5677
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5678
	hdr->zh_hdr_size = sizeof (ztest_shared_hdr_t);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5679
	hdr->zh_opts_size = sizeof (ztest_shared_opts_t);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5680
	hdr->zh_size = sizeof (ztest_shared_t);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5681
	hdr->zh_stats_size = sizeof (ztest_shared_callstate_t);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5682
	hdr->zh_stats_count = ZTEST_FUNCS;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5683
	hdr->zh_ds_size = sizeof (ztest_shared_ds_t);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5684
	hdr->zh_ds_count = ztest_opts.zo_datasets;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5685
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5686
	size = shared_data_size(hdr);
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5687
	VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, size));
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5688
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5689
	(void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5690
}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5691
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5692
static void
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5693
setup_data(void)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5694
{
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5695
	int size, offset;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5696
	ztest_shared_hdr_t *hdr;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5697
	uint8_t *buf;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5698
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5699
	hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5700
	    PROT_READ, MAP_SHARED, ZTEST_FD_DATA, 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5701
	ASSERT(hdr != MAP_FAILED);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5702
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13571
diff changeset
  5703
	size = shared_data_size(hdr);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5704
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5705
	(void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5706
	hdr = ztest_shared_hdr = (void *)mmap(0, P2ROUNDUP(size, getpagesize()),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5707
	    PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5708
	ASSERT(hdr != MAP_FAILED);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5709
	buf = (uint8_t *)hdr;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5710
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5711
	offset = hdr->zh_hdr_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5712
	ztest_shared_opts = (void *)&buf[offset];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5713
	offset += hdr->zh_opts_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5714
	ztest_shared = (void *)&buf[offset];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5715
	offset += hdr->zh_size;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5716
	ztest_shared_callstate = (void *)&buf[offset];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5717
	offset += hdr->zh_stats_size * hdr->zh_stats_count;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5718
	ztest_shared_ds = (void *)&buf[offset];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5719
}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5720
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5721
static boolean_t
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5722
exec_child(char *cmd, char *libpath, boolean_t ignorekill, int *statusp)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5723
{
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5724
	pid_t pid;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5725
	int status;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5726
	char cmdbuf[MAXPATHLEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5727
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5728
	pid = fork();
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5729
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5730
	if (cmd == NULL) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5731
		(void) strlcpy(cmdbuf, getexecname(), sizeof (cmdbuf));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5732
		cmd = cmdbuf;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5733
	}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5734
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5735
	if (pid == -1)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5736
		fatal(1, "fork failed");
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5737
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5738
	if (pid == 0) {	/* child */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5739
		char *emptyargv[2] = { cmd, NULL };
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5740
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5741
		struct rlimit rl = { 1024, 1024 };
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5742
		(void) setrlimit(RLIMIT_NOFILE, &rl);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5743
		(void) enable_extended_FILE_stdio(-1, -1);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5744
		if (libpath != NULL)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5745
			VERIFY(0 == setenv("LD_LIBRARY_PATH", libpath, 1));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5746
		(void) execv(cmd, emptyargv);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5747
		ztest_dump_core = B_FALSE;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5748
		fatal(B_TRUE, "exec failed: %s", cmd);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5749
	}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5750
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5751
	while (waitpid(pid, &status, 0) != pid)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5752
		continue;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5753
	if (statusp != NULL)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5754
		*statusp = status;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5755
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5756
	if (WIFEXITED(status)) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5757
		if (WEXITSTATUS(status) != 0) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5758
			(void) fprintf(stderr, "child exited with code %d\n",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5759
			    WEXITSTATUS(status));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5760
			exit(2);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5761
		}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5762
		return (B_FALSE);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5763
	} else if (WIFSIGNALED(status)) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5764
		if (!ignorekill || WTERMSIG(status) != SIGKILL) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5765
			(void) fprintf(stderr, "child died with signal %d\n",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5766
			    WTERMSIG(status));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5767
			exit(3);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5768
		}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5769
		return (B_TRUE);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5770
	} else {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5771
		(void) fprintf(stderr, "something strange happened to child\n");
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5772
		exit(4);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5773
		/* NOTREACHED */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5774
	}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5775
}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5776
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5777
static void
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5778
ztest_run_init(void)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5779
{
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5780
	ztest_shared_t *zs = ztest_shared;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5781
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5782
	ASSERT(ztest_opts.zo_init != 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5783
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5784
	/*
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5785
	 * Blow away any existing copy of zpool.cache
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5786
	 */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5787
	(void) remove(spa_config_path);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5788
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5789
	/*
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5790
	 * Create and initialize our storage pool.
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5791
	 */
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5792
	for (int i = 1; i <= ztest_opts.zo_init; i++) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5793
		bzero(zs, sizeof (ztest_shared_t));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5794
		if (ztest_opts.zo_verbose >= 3 &&
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5795
		    ztest_opts.zo_init != 1) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5796
			(void) printf("ztest_init(), pass %d\n", i);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5797
		}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5798
		ztest_init(zs);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5799
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5800
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5801
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5802
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5803
main(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5804
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5805
	int kills = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5806
	int iters = 0;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5807
	int older = 0;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5808
	int newer = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5809
	ztest_shared_t *zs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5810
	ztest_info_t *zi;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5811
	ztest_shared_callstate_t *zc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5812
	char timebuf[100];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5813
	char numbuf[6];
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5814
	spa_t *spa;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5815
	char cmd[MAXNAMELEN];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5816
	boolean_t hasalt;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5817
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5818
	boolean_t ischild = (0 == lseek(ZTEST_FD_DATA, 0, SEEK_CUR));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5819
	ASSERT(ischild || errno == EBADF);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5820
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5821
	(void) setvbuf(stdout, NULL, _IOLBF, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5822
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5823
	if (!ischild) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5824
		process_options(argc, argv);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5825
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5826
		setup_fds();
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5827
		setup_hdr();
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5828
		setup_data();
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5829
		bcopy(&ztest_opts, ztest_shared_opts,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5830
		    sizeof (*ztest_shared_opts));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5831
	} else {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5832
		setup_data();
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5833
		bcopy(ztest_shared_opts, &ztest_opts, sizeof (ztest_opts));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5834
	}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5835
	ASSERT3U(ztest_opts.zo_datasets, ==, ztest_shared_hdr->zh_ds_count);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5836
11811
b25d9f1b5d8e 6914746 sprintf_blkptr() causes NULL pointer dereference
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 11497
diff changeset
  5837
	/* Override location of zpool.cache */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5838
	(void) asprintf((char **)&spa_config_path, "%s/zpool.cache",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5839
	    ztest_opts.zo_dir);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5840
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5841
	ztest_ds = umem_alloc(ztest_opts.zo_datasets * sizeof (ztest_ds_t),
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5842
	    UMEM_NOFAIL);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5843
	zs = ztest_shared;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5844
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5845
	if (ischild) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5846
		metaslab_gang_bang = ztest_opts.zo_metaslab_gang_bang;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5847
		metaslab_df_alloc_threshold =
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5848
		    zs->zs_metaslab_df_alloc_threshold;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5849
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5850
		if (zs->zs_do_init)
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5851
			ztest_run_init();
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5852
		else
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5853
			ztest_run(zs);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5854
		exit(0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5855
	}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5856
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5857
	hasalt = (strlen(ztest_opts.zo_alt_ztest) != 0);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5858
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5859
	if (ztest_opts.zo_verbose >= 1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5860
		(void) printf("%llu vdevs, %d datasets, %d threads,"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5861
		    " %llu seconds...\n",
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5862
		    (u_longlong_t)ztest_opts.zo_vdevs,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5863
		    ztest_opts.zo_datasets,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5864
		    ztest_opts.zo_threads,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5865
		    (u_longlong_t)ztest_opts.zo_time);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5866
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5867
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5868
	(void) strlcpy(cmd, getexecname(), sizeof (cmd));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5869
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5870
	zs->zs_do_init = B_TRUE;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5871
	if (strlen(ztest_opts.zo_alt_ztest) != 0) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5872
		if (ztest_opts.zo_verbose >= 1) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5873
			(void) printf("Executing older ztest for "
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5874
			    "initialization: %s\n", ztest_opts.zo_alt_ztest);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5875
		}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5876
		VERIFY(!exec_child(ztest_opts.zo_alt_ztest,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5877
		    ztest_opts.zo_alt_libpath, B_FALSE, NULL));
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5878
	} else {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5879
		VERIFY(!exec_child(NULL, NULL, B_FALSE, NULL));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5880
	}
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5881
	zs->zs_do_init = B_FALSE;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5882
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5883
	zs->zs_proc_start = gethrtime();
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5884
	zs->zs_proc_stop = zs->zs_proc_start + ztest_opts.zo_time * NANOSEC;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5885
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5886
	for (int f = 0; f < ZTEST_FUNCS; f++) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5887
		zi = &ztest_info[f];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5888
		zc = ZTEST_GET_SHARED_CALLSTATE(f);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5889
		if (zs->zs_proc_start + zi->zi_interval[0] > zs->zs_proc_stop)
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5890
			zc->zc_next = UINT64_MAX;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5891
		else
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5892
			zc->zc_next = zs->zs_proc_start +
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5893
			    ztest_random(2 * zi->zi_interval[0] + 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5894
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5895
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5896
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5897
	 * Run the tests in a loop.  These tests include fault injection
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5898
	 * to verify that self-healing data works, and forced crashes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5899
	 * to verify that we never lose on-disk consistency.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5900
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5901
	while (gethrtime() < zs->zs_proc_stop) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5902
		int status;
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5903
		boolean_t killed;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5904
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5905
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5906
		 * Initialize the workload counters for each function.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5907
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5908
		for (int f = 0; f < ZTEST_FUNCS; f++) {
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5909
			zc = ZTEST_GET_SHARED_CALLSTATE(f);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5910
			zc->zc_count = 0;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5911
			zc->zc_time = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5912
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5913
9480
fcff33da767f 6596237 Stop looking and start ganging
George Wilson <George.Wilson@Sun.COM>
parents: 9463
diff changeset
  5914
		/* Set the allocation switch size */
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5915
		zs->zs_metaslab_df_alloc_threshold =
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5916
		    ztest_random(zs->zs_metaslab_sz / 4) + 1;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5917
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5918
		if (!hasalt || ztest_random(2) == 0) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5919
			if (hasalt && ztest_opts.zo_verbose >= 1) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5920
				(void) printf("Executing newer ztest: %s\n",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5921
				    cmd);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5922
			}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5923
			newer++;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5924
			killed = exec_child(cmd, NULL, B_TRUE, &status);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5925
		} else {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5926
			if (hasalt && ztest_opts.zo_verbose >= 1) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5927
				(void) printf("Executing older ztest: %s\n",
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5928
				    ztest_opts.zo_alt_ztest);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5929
			}
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5930
			older++;
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5931
			killed = exec_child(ztest_opts.zo_alt_ztest,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5932
			    ztest_opts.zo_alt_libpath, B_TRUE, &status);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5933
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5934
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5935
		if (killed)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5936
			kills++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5937
		iters++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5938
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5939
		if (ztest_opts.zo_verbose >= 1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5940
			hrtime_t now = gethrtime();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5941
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5942
			now = MIN(now, zs->zs_proc_stop);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5943
			print_time(zs->zs_proc_stop - now, timebuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5944
			nicenum(zs->zs_space, numbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5945
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5946
			(void) printf("Pass %3d, %8s, %3llu ENOSPC, "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5947
			    "%4.1f%% of %5s used, %3.0f%% done, %8s to go\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5948
			    iters,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5949
			    WIFEXITED(status) ? "Complete" : "SIGKILL",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5950
			    (u_longlong_t)zs->zs_enospc_count,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5951
			    100.0 * zs->zs_alloc / zs->zs_space,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5952
			    numbuf,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5953
			    100.0 * (now - zs->zs_proc_start) /
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5954
			    (ztest_opts.zo_time * NANOSEC), timebuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5955
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5956
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5957
		if (ztest_opts.zo_verbose >= 2) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5958
			(void) printf("\nWorkload summary:\n\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5959
			(void) printf("%7s %9s   %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5960
			    "Calls", "Time", "Function");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5961
			(void) printf("%7s %9s   %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5962
			    "-----", "----", "--------");
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5963
			for (int f = 0; f < ZTEST_FUNCS; f++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5964
				Dl_info dli;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5965
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5966
				zi = &ztest_info[f];
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5967
				zc = ZTEST_GET_SHARED_CALLSTATE(f);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5968
				print_time(zc->zc_time, timebuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5969
				(void) dladdr((void *)zi->zi_func, &dli);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5970
				(void) printf("%7llu %9s   %s\n",
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5971
				    (u_longlong_t)zc->zc_count, timebuf,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5972
				    dli.dli_sname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5973
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5974
			(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5975
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5976
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5977
		/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5978
		 * It's possible that we killed a child during a rename test,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5979
		 * in which case we'll have a 'ztest_tmp' pool lying around
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5980
		 * instead of 'ztest'.  Do a blind rename in case this happened.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5981
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5982
		kernel_init(FREAD);
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5983
		if (spa_open(ztest_opts.zo_pool, &spa, FTAG) == 0) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5984
			spa_close(spa, FTAG);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5985
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5986
			char tmpname[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5987
			kernel_fini();
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5988
			kernel_init(FREAD | FWRITE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5989
			(void) snprintf(tmpname, sizeof (tmpname), "%s_tmp",
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5990
			    ztest_opts.zo_pool);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5991
			(void) spa_rename(tmpname, ztest_opts.zo_pool);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5992
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5993
		kernel_fini();
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10850
diff changeset
  5994
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5995
		ztest_run_zdb(ztest_opts.zo_pool);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5996
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5997
13571
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5998
	if (ztest_opts.zo_verbose >= 1) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  5999
		if (hasalt) {
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  6000
			(void) printf("%d runs of older ztest: %s\n", older,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  6001
			    ztest_opts.zo_alt_ztest);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  6002
			(void) printf("%d runs of newer ztest: %s\n", newer,
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  6003
			    cmd);
a5771a96228c 1950 ztest backwards compatibility testing option
Chris Siden <chris.siden@delphix.com>
parents: 13514
diff changeset
  6004
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  6005
		(void) printf("%d killed, %d completed, %.0f%% kill rate\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  6006
		    kills, iters - kills, (100.0 * kills) / MAX(1, iters));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  6007
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  6008
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  6009
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  6010
}