usr/src/uts/common/fs/zfs/zio.c
author Darren Moffat <darrenm@opensolaris.org>
Tue, 20 Nov 2007 16:43:41 +0000
changeset 13150 4d89e6c6d8c8
parent 5450 b25030891c44
child 13152 b2ac0409282f
permissions -rw-r--r--
Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
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
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
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
/*
3459
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
    22
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/zfs_context.h>
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    29
#include <sys/fm/fs/zfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/zio_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zio_compress.h>
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
    36
#include <sys/zio_crypt.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
    39
#include <sys/sdt.h>
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
    40
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 * I/O priority table
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
	0,	/* ZIO_PRIORITY_NOW		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
	0,	/* ZIO_PRIORITY_SYNC_READ	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
	0,	/* ZIO_PRIORITY_SYNC_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
	6,	/* ZIO_PRIORITY_ASYNC_READ	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
	4,	/* ZIO_PRIORITY_ASYNC_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
	4,	/* ZIO_PRIORITY_FREE		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
	0,	/* ZIO_PRIORITY_CACHE_FILL	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
	0,	/* ZIO_PRIORITY_LOG_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
	10,	/* ZIO_PRIORITY_RESILVER	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
	20,	/* ZIO_PRIORITY_SCRUB		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 * I/O type descriptions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
char *zio_type_name[ZIO_TYPES] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
	"null", "read", "write", "free", "claim", "ioctl" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
/* At or above this size, force gang blocking - for testing */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
uint64_t zio_gang_bang = SPA_MAXBLOCKSIZE + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
    70
/* Force an allocation failure when non-zero */
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
    71
uint16_t zio_zil_fail_shift = 0;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    72
uint16_t zio_io_fail_shift = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    73
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    74
/* Enable/disable the write-retry logic */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    75
int zio_write_retry = 1;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    76
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    77
/* Taskq to handle reissuing of I/Os */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    78
taskq_t *zio_taskq;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    79
int zio_resume_threads = 4;
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
    80
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
typedef struct zio_sync_pass {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
	int	zp_defer_free;		/* defer frees after this pass */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
	int	zp_dontcompress;	/* don't compress after this pass */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
	int	zp_rewrite;		/* rewrite new bps after this pass */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
} zio_sync_pass_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
zio_sync_pass_t zio_sync_pass = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
	1,	/* zp_defer_free */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	4,	/* zp_dontcompress */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	1,	/* zp_rewrite */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    93
static boolean_t zio_io_should_fail(uint16_t);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    94
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
 * I/O kmem caches
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
 */
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   100
kmem_cache_t *zio_cache;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
kmem_cache_t *zio_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT];
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   102
kmem_cache_t *zio_data_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT];
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   103
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   104
#ifdef _KERNEL
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   105
extern vmem_t *zio_alloc_arena;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   106
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   108
/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   109
 * Determine if we are allowed to issue the IO based on the
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   110
 * pool state. If we must wait then block until we are told
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   111
 * that we may continue.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   112
 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   113
#define	ZIO_ENTER(spa) {						\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   114
	if (spa->spa_state == POOL_STATE_IO_FAILURE) {			\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   115
		mutex_enter(&spa->spa_zio_lock);			\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   116
		while (spa->spa_state == POOL_STATE_IO_FAILURE)		\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   117
			cv_wait(&spa->spa_zio_cv, &spa->spa_zio_lock);	\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   118
		mutex_exit(&spa->spa_zio_lock);				\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   119
	}								\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   120
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   121
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   122
/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   123
 * An allocation zio is one that either currently has the DVA allocate
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   124
 * stage set or will have it later in it's lifetime.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   125
 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   126
#define	IO_IS_ALLOCATING(zio) \
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   127
	((zio)->io_orig_pipeline == ZIO_WRITE_PIPELINE ||		\
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   128
	(zio)->io_pipeline & (1U << ZIO_STAGE_DVA_ALLOCATE))
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   129
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
zio_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	size_t c;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   134
	vmem_t *data_alloc_arena = NULL;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   135
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   136
#ifdef _KERNEL
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   137
	data_alloc_arena = zio_alloc_arena;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   138
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   140
	zio_cache = kmem_cache_create("zio_cache", sizeof (zio_t), 0,
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   141
	    NULL, NULL, NULL, NULL, NULL, 0);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   142
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	 * For small buffers, we want a cache for each multiple of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	 * SPA_MINBLOCKSIZE.  For medium-size buffers, we want a cache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
	 * for each quarter-power of 2.  For large buffers, we want
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
	 * a cache for each multiple of PAGESIZE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
	for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
		size_t size = (c + 1) << SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
		size_t p2 = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
		size_t align = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
		while (p2 & (p2 - 1))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
			p2 &= p2 - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
		if (size <= 4 * SPA_MINBLOCKSIZE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
			align = SPA_MINBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
		} else if (P2PHASE(size, PAGESIZE) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
			align = PAGESIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
		} else if (P2PHASE(size, p2 >> 2) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
			align = p2 >> 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
		if (align != 0) {
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   166
			char name[36];
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2082
diff changeset
   167
			(void) sprintf(name, "zio_buf_%lu", (ulong_t)size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
			zio_buf_cache[c] = kmem_cache_create(name, size,
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
   169
			    align, NULL, NULL, NULL, NULL, NULL, KMC_NODEBUG);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   170
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   171
			(void) sprintf(name, "zio_data_buf_%lu", (ulong_t)size);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   172
			zio_data_buf_cache[c] = kmem_cache_create(name, size,
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   173
			    align, NULL, NULL, NULL, NULL, data_alloc_arena,
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   174
			    KMC_NODEBUG);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   175
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
			dprintf("creating cache for size %5lx align %5lx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
			    size, align);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
	while (--c != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
		ASSERT(zio_buf_cache[c] != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
		if (zio_buf_cache[c - 1] == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
			zio_buf_cache[c - 1] = zio_buf_cache[c];
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   185
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   186
		ASSERT(zio_data_buf_cache[c] != NULL);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   187
		if (zio_data_buf_cache[c - 1] == NULL)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   188
			zio_data_buf_cache[c - 1] = zio_data_buf_cache[c];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   190
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   191
	zio_taskq = taskq_create("zio_taskq", zio_resume_threads,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   192
	    maxclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   193
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   194
	zio_inject_init();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
zio_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
	size_t c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
	kmem_cache_t *last_cache = NULL;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   202
	kmem_cache_t *last_data_cache = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
	for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
		if (zio_buf_cache[c] != last_cache) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
			last_cache = zio_buf_cache[c];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
			kmem_cache_destroy(zio_buf_cache[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
		zio_buf_cache[c] = NULL;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   210
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   211
		if (zio_data_buf_cache[c] != last_data_cache) {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   212
			last_data_cache = zio_data_buf_cache[c];
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   213
			kmem_cache_destroy(zio_data_buf_cache[c]);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   214
		}
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   215
		zio_data_buf_cache[c] = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   217
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   218
	taskq_destroy(zio_taskq);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   219
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   220
	kmem_cache_destroy(zio_cache);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   221
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   222
	zio_inject_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
 * Allocate and free I/O buffers
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
 */
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   230
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   231
/*
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   232
 * Use zio_buf_alloc to allocate ZFS metadata.  This data will appear in a
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   233
 * crashdump if the kernel panics, so use it judiciously.  Obviously, it's
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   234
 * useful to inspect ZFS metadata, but if possible, we should avoid keeping
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   235
 * excess / transient data in-core during a crashdump.
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   236
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
void *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
zio_buf_alloc(size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
	return (kmem_cache_alloc(zio_buf_cache[c], KM_SLEEP));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   247
/*
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   248
 * Use zio_data_buf_alloc to allocate data.  The data will not appear in a
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   249
 * crashdump if the kernel panics.  This exists so that we will limit the amount
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   250
 * of ZFS data that shows up in a kernel crashdump.  (Thus reducing the amount
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   251
 * of kernel heap dumped to disk when the kernel panics)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   252
 */
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   253
void *
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   254
zio_data_buf_alloc(size_t size)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   255
{
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   256
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   257
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   258
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   259
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   260
	return (kmem_cache_alloc(zio_data_buf_cache[c], KM_SLEEP));
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   261
}
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   262
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
zio_buf_free(void *buf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
	kmem_cache_free(zio_buf_cache[c], buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   273
void
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   274
zio_data_buf_free(void *buf, size_t size)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   275
{
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   276
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   277
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   278
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   279
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   280
	kmem_cache_free(zio_data_buf_cache[c], buf);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   281
}
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   282
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
 * Push and pop I/O transform buffers
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
zio_push_transform(zio_t *zio, void *data, uint64_t size, uint64_t bufsize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
	zio_transform_t *zt = kmem_alloc(sizeof (zio_transform_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
	zt->zt_data = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
	zt->zt_size = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	zt->zt_bufsize = bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	zt->zt_next = zio->io_transform_stack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	zio->io_transform_stack = zt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	zio->io_data = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	zio->io_size = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
zio_pop_transform(zio_t *zio, void **data, uint64_t *size, uint64_t *bufsize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	zio_transform_t *zt = zio->io_transform_stack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
	*data = zt->zt_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	*size = zt->zt_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
	*bufsize = zt->zt_bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
	zio->io_transform_stack = zt->zt_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	kmem_free(zt, sizeof (zio_transform_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
	if ((zt = zio->io_transform_stack) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
		zio->io_data = zt->zt_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
		zio->io_size = zt->zt_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
zio_clear_transform_stack(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	void *data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
	uint64_t size, bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
	ASSERT(zio->io_transform_stack != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
	zio_pop_transform(zio, &data, &size, &bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
	while (zio->io_transform_stack != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
		zio_buf_free(data, bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
		zio_pop_transform(zio, &data, &size, &bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
 * Create the various types of I/O (read, write, free)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
static zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
zio_create(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
    void *data, uint64_t size, zio_done_func_t *done, void *private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
    zio_type_t type, int priority, int flags, uint8_t stage, uint32_t pipeline)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
	ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
	ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   352
	zio = kmem_cache_alloc(zio_cache, KM_SLEEP);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   353
	bzero(zio, sizeof (zio_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
	zio->io_parent = pio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
	zio->io_spa = spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
	zio->io_txg = txg;
4634
39bfb9e90d34 6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents: 4527
diff changeset
   357
	zio->io_flags = flags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
	if (bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
		zio->io_bp = bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
		zio->io_bp_copy = *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
		zio->io_bp_orig = *bp;
4634
39bfb9e90d34 6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents: 4527
diff changeset
   362
		if (dmu_ot[BP_GET_TYPE(bp)].ot_metadata ||
39bfb9e90d34 6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents: 4527
diff changeset
   363
		    BP_GET_LEVEL(bp) != 0)
39bfb9e90d34 6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents: 4527
diff changeset
   364
			zio->io_flags |= ZIO_FLAG_METADATA;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
	zio->io_done = done;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
	zio->io_private = private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
	zio->io_type = type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
	zio->io_priority = priority;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
	zio->io_stage = stage;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
	zio->io_pipeline = pipeline;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
	zio->io_async_stages = ZIO_ASYNC_PIPELINE_STAGES;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
	zio->io_timestamp = lbolt64;
4634
39bfb9e90d34 6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents: 4527
diff changeset
   374
	if (pio != NULL)
39bfb9e90d34 6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents: 4527
diff changeset
   375
		zio->io_flags |= (pio->io_flags & ZIO_FLAG_METADATA);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2082
diff changeset
   376
	mutex_init(&zio->io_lock, NULL, MUTEX_DEFAULT, NULL);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4634
diff changeset
   377
	cv_init(&zio->io_cv, NULL, CV_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
	zio_push_transform(zio, data, size, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   380
	/*
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   381
	 * Note on config lock:
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   382
	 *
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   383
	 * If CONFIG_HELD is set, then the caller already has the config
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   384
	 * lock, so we don't need it for this io.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   385
	 *
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   386
	 * We set CONFIG_GRABBED to indicate that we have grabbed the
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   387
	 * config lock on behalf of this io, so it should be released
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   388
	 * in zio_done.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   389
	 *
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   390
	 * Unless CONFIG_HELD is set, we will grab the config lock for
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   391
	 * any top-level (parent-less) io, *except* NULL top-level ios.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   392
	 * The NULL top-level ios rarely have any children, so we delay
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   393
	 * grabbing the lock until the first child is added (but it is
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   394
	 * still grabbed on behalf of the top-level i/o, so additional
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   395
	 * children don't need to also grab it).  This greatly reduces
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   396
	 * contention on the config lock.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   397
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
	if (pio == NULL) {
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   399
		if (type != ZIO_TYPE_NULL &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   400
		    !(flags & ZIO_FLAG_CONFIG_HELD)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   401
			spa_config_enter(zio->io_spa, RW_READER, zio);
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   402
			zio->io_flags |= ZIO_FLAG_CONFIG_GRABBED;
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   403
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
		zio->io_root = zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
		zio->io_root = pio->io_root;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   407
		if (!(flags & ZIO_FLAG_NOBOOKMARK))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   408
			zio->io_logical = pio->io_logical;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
		mutex_enter(&pio->io_lock);
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   410
		if (pio->io_parent == NULL &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   411
		    pio->io_type == ZIO_TYPE_NULL &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   412
		    !(pio->io_flags & ZIO_FLAG_CONFIG_GRABBED) &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   413
		    !(pio->io_flags & ZIO_FLAG_CONFIG_HELD)) {
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   414
			pio->io_flags |= ZIO_FLAG_CONFIG_GRABBED;
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   415
			spa_config_enter(zio->io_spa, RW_READER, pio);
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   416
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
		if (stage < ZIO_STAGE_READY)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
			pio->io_children_notready++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
		pio->io_children_notdone++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
		zio->io_sibling_next = pio->io_child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
		zio->io_sibling_prev = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
		if (pio->io_child != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
			pio->io_child->io_sibling_prev = zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
		pio->io_child = zio;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   425
		zio->io_ndvas = pio->io_ndvas;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   429
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   430
	 * Save off the original state incase we need to retry later.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   431
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   432
	zio->io_orig_stage = zio->io_stage;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   433
	zio->io_orig_pipeline = zio->io_pipeline;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   434
	zio->io_orig_flags = zio->io_flags;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   435
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   439
static void
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   440
zio_reset(zio_t *zio)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   441
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   442
	zio_clear_transform_stack(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   443
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   444
	zio->io_flags = zio->io_orig_flags;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   445
	zio->io_stage = zio->io_orig_stage;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   446
	zio->io_pipeline = zio->io_orig_pipeline;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   447
	zio_push_transform(zio, zio->io_data, zio->io_size, zio->io_size);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   448
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   449
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
zio_null(zio_t *pio, spa_t *spa, zio_done_func_t *done, void *private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
	int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
	zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	    ZIO_TYPE_NULL, ZIO_PRIORITY_NOW, flags, ZIO_STAGE_OPEN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	    ZIO_WAIT_FOR_CHILDREN_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
zio_root(spa_t *spa, zio_done_func_t *done, void *private, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
	return (zio_null(NULL, spa, done, private, flags));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
    uint64_t size, zio_done_func_t *done, void *private,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   472
    int priority, int flags, zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
	ASSERT3U(size, ==, BP_GET_LSIZE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   478
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   479
	 * If the user has specified that we allow I/Os to continue
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   480
	 * then attempt to satisfy the read.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   481
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   482
	if (spa_get_failmode(spa) != ZIO_FAILURE_MODE_CONTINUE)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   483
		ZIO_ENTER(spa);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   484
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
	zio = zio_create(pio, spa, bp->blk_birth, bp, data, size, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   486
	    ZIO_TYPE_READ, priority, flags | ZIO_FLAG_USER,
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   487
	    ZIO_STAGE_OPEN, ZIO_READ_PIPELINE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   488
	zio->io_bookmark = *zb;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   489
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   490
	zio->io_logical = zio;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
	 * Work off our copy of the bp so the caller can free it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
zio_t *
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   501
zio_write(zio_t *pio, spa_t *spa, int checksum, int compress, int crypt,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   502
    int ncopies, uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   503
    zio_done_func_t *ready, zio_done_func_t *done, void *private, int priority,
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   504
    int flags, zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	ASSERT(checksum >= ZIO_CHECKSUM_OFF &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	    checksum < ZIO_CHECKSUM_FUNCTIONS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
	ASSERT(compress >= ZIO_COMPRESS_OFF &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
	    compress < ZIO_COMPRESS_FUNCTIONS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   514
	ASSERT(crypt >= ZIO_CRYPT_OFF &&
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   515
	    crypt < ZIO_CRYPT_FUNCTIONS);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   516
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   517
	ZIO_ENTER(spa);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   518
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   520
	    ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_USER,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
	    ZIO_STAGE_OPEN, ZIO_WRITE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   523
	zio->io_ready = ready;
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   524
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   525
	zio->io_bookmark = *zb;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   526
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   527
	zio->io_logical = zio;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   528
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	zio->io_compress = compress;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   531
	zio->io_ndvas = ncopies;
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   532
	zio->io_crypt = crypt;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	if (compress != ZIO_COMPRESS_OFF)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
		zio->io_async_stages |= 1U << ZIO_STAGE_WRITE_COMPRESS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   537
	if (crypt != ZIO_CRYPT_OFF) {
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   538
		zio->io_async_stages |= 1U << ZIO_STAGE_WRITE_ENCRYPT;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   539
	}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   540
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
	if (bp->blk_birth != txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
		/* XXX the bp usually (always?) gets re-zeroed later */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
		BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
		BP_SET_LSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
		BP_SET_PSIZE(bp, size);
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   546
		BP_SET_CRYPT(bp, ZIO_CRYPT_OFF); /* XXX why not crypt ? */
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   547
	} else {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   548
		/* Make sure someone doesn't change their mind on overwrites */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   549
		ASSERT(MIN(zio->io_ndvas + BP_IS_GANG(bp),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   550
		    spa_max_replication(spa)) == BP_GET_NDVAS(bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
zio_t *
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   557
zio_rewrite(zio_t *pio, spa_t *spa, int checksum, uint64_t txg,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   558
    blkptr_t *bp, void *data, uint64_t size,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   559
    zio_done_func_t *done, void *private, int priority, int flags,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   560
    zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   565
	    ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_USER,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
	    ZIO_STAGE_OPEN, ZIO_REWRITE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   568
	zio->io_bookmark = *zb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
	zio->io_compress = ZIO_COMPRESS_OFF;
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   571
	zio->io_crypt = ZIO_CRYPT_OFF;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   573
	if (pio != NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   574
		ASSERT3U(zio->io_ndvas, <=, BP_GET_NDVAS(bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   575
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   579
static void
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   580
zio_write_allocate_ready(zio_t *zio)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   581
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   582
	/* Free up the previous block */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   583
	if (!BP_IS_HOLE(&zio->io_bp_orig)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   584
		zio_nowait(zio_free(zio, zio->io_spa, zio->io_txg,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   585
		    &zio->io_bp_orig, NULL, NULL));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   586
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   587
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   588
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
static zio_t *
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   590
zio_write_allocate(zio_t *pio, spa_t *spa, int checksum, uint64_t txg,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   591
    blkptr_t *bp, void *data, uint64_t size,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
    zio_done_func_t *done, void *private, int priority, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
	BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
	BP_SET_LSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
	BP_SET_PSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
	BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF);
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   600
	BP_SET_CRYPT(bp, ZIO_CRYPT_OFF);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
	    ZIO_TYPE_WRITE, priority, flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
	    ZIO_STAGE_OPEN, ZIO_WRITE_ALLOCATE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
	zio->io_compress = ZIO_COMPRESS_OFF;
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   608
	zio->io_crypt = ZIO_CRYPT_OFF;	
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   609
	zio->io_ready = zio_write_allocate_ready;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
    zio_done_func_t *done, void *private)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
	ASSERT(!BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
	if (txg == spa->spa_syncing_txg &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
	    spa->spa_sync_pass > zio_sync_pass.zp_defer_free) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
		bplist_enqueue_deferred(&spa->spa_sync_bplist, bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
		return (zio_null(pio, spa, NULL, NULL, 0));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
	zio = zio_create(pio, spa, txg, bp, NULL, 0, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   629
	    ZIO_TYPE_FREE, ZIO_PRIORITY_FREE, ZIO_FLAG_USER,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
	    ZIO_STAGE_OPEN, ZIO_FREE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
    zio_done_func_t *done, void *private)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
	 * A claim is an allocation of a specific block.  Claims are needed
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	 * to support immediate writes in the intent log.  The issue is that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
	 * immediate writes contain committed data, but in a txg that was
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
	 * *not* committed.  Upon opening the pool after an unclean shutdown,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
	 * the intent log claims all blocks that contain immediate write data
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
	 * so that the SPA knows they're in use.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
	 * All claims *must* be resolved in the first txg -- before the SPA
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
	 * starts allocating blocks -- so that nothing is allocated twice.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
	ASSERT3U(spa->spa_uberblock.ub_rootbp.blk_birth, <, spa_first_txg(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
	ASSERT3U(spa_first_txg(spa), <=, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
	zio = zio_create(pio, spa, txg, bp, NULL, 0, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
	    ZIO_TYPE_CLAIM, ZIO_PRIORITY_NOW, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
	    ZIO_STAGE_OPEN, ZIO_CLAIM_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
    zio_done_func_t *done, void *private, int priority, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
	if (vd->vdev_children == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
		zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
		    ZIO_TYPE_IOCTL, priority, flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
		    ZIO_STAGE_OPEN, ZIO_IOCTL_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
		zio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
		zio->io_cmd = cmd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
		zio = zio_null(pio, spa, NULL, NULL, flags);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
		for (c = 0; c < vd->vdev_children; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
			zio_nowait(zio_ioctl(zio, spa, vd->vdev_child[c], cmd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
			    done, private, priority, flags));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
zio_phys_bp_init(vdev_t *vd, blkptr_t *bp, uint64_t offset, uint64_t size,
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   693
    int checksum, boolean_t labels)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
	ASSERT(vd->vdev_children == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
	ASSERT(size <= SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
	ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
	ASSERT(P2PHASE(offset, SPA_MINBLOCKSIZE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   701
#ifdef ZFS_DEBUG
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   702
	if (labels) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   703
		ASSERT(offset + size <= VDEV_LABEL_START_SIZE ||
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   704
		    offset >= vd->vdev_psize - VDEV_LABEL_END_SIZE);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   705
	}
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   706
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
	ASSERT3U(offset + size, <=, vd->vdev_psize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
	BP_SET_LSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
	BP_SET_PSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
	BP_SET_CHECKSUM(bp, checksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
	BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF);
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   716
	BP_SET_CRYPT(bp, ZIO_CRYPT_OFF);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
	BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	if (checksum != ZIO_CHECKSUM_OFF)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
		ZIO_SET_CHECKSUM(&bp->blk_cksum, offset, 0, 0, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
    void *data, int checksum, zio_done_func_t *done, void *private,
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   726
    int priority, int flags, boolean_t labels)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
	blkptr_t blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   731
	ZIO_ENTER(vd->vdev_spa);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   732
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   733
	zio_phys_bp_init(vd, &blk, offset, size, checksum, labels);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
	zio = zio_create(pio, vd->vdev_spa, 0, &blk, data, size, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	    ZIO_TYPE_READ, priority, flags | ZIO_FLAG_PHYSICAL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
	    ZIO_STAGE_OPEN, ZIO_READ_PHYS_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
	zio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   740
	zio->io_offset = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
	 * Work off our copy of the bp so the caller can free it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
    void *data, int checksum, zio_done_func_t *done, void *private,
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   753
    int priority, int flags, boolean_t labels)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
	zio_block_tail_t *zbt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	void *wbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
	blkptr_t blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   760
	ZIO_ENTER(vd->vdev_spa);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   761
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   762
	zio_phys_bp_init(vd, &blk, offset, size, checksum, labels);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	zio = zio_create(pio, vd->vdev_spa, 0, &blk, data, size, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
	    ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_PHYSICAL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
	    ZIO_STAGE_OPEN, ZIO_WRITE_PHYS_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
	zio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
	zio->io_offset = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
	if (zio_checksum_table[checksum].ci_zbt) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
		 * zbt checksums are necessarily destructive -- they modify
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
		 * one word of the write buffer to hold the verifier/checksum.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
		 * Therefore, we must make a local copy in case the data is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
		 * being written to multiple places.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
		wbuf = zio_buf_alloc(size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
		bcopy(data, wbuf, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
		zio_push_transform(zio, wbuf, size, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
		zbt = (zio_block_tail_t *)((char *)wbuf + size) - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
		zbt->zbt_cksum = blk.blk_cksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
 * Create a child I/O to do some work for us.  It has no associated bp.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, uint64_t offset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
	void *data, uint64_t size, int type, int priority, int flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	zio_done_func_t *done, void *private)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
	uint32_t pipeline = ZIO_VDEV_CHILD_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
	zio_t *cio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
	if (type == ZIO_TYPE_READ && bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
		 * If we have the bp, then the child should perform the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
		 * checksum and the parent need not.  This pushes error
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
		 * detection as close to the leaves as possible and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
		 * eliminates redundant checksums in the interior nodes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
		pipeline |= 1U << ZIO_STAGE_CHECKSUM_VERIFY;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
		zio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
	cio = zio_create(zio, zio->io_spa, zio->io_txg, bp, data, size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
	    done, private, type, priority,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
	    (zio->io_flags & ZIO_FLAG_VDEV_INHERIT) | ZIO_FLAG_CANFAIL | flags,
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   817
	    ZIO_STAGE_VDEV_IO_START - 1, pipeline);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
	cio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
	cio->io_offset = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
	return (cio);
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
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
 * Initiate I/O, either sync or async
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
zio_wait(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   835
	ASSERT(zio->io_stage == ZIO_STAGE_OPEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   836
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   837
	zio->io_waiter = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
	zio_next_stage_async(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
	mutex_enter(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
	while (zio->io_stalled != ZIO_STAGE_DONE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
		cv_wait(&zio->io_cv, &zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
	mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
	error = zio->io_error;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2082
diff changeset
   847
	mutex_destroy(&zio->io_lock);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4634
diff changeset
   848
	cv_destroy(&zio->io_cv);
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   849
	kmem_cache_free(zio_cache, zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
	return (error);
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
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
zio_nowait(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
	zio_next_stage_async(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
 * I/O pipeline interlocks: parent/child dependency scoreboarding
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
zio_wait_for_children(zio_t *zio, uint32_t stage, uint64_t *countp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
	mutex_enter(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	if (*countp == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
		ASSERT(zio->io_stalled == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
		mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
		zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
		zio->io_stalled = stage;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
		mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
zio_notify_parent(zio_t *zio, uint32_t stage, uint64_t *countp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
	zio_t *pio = zio->io_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
	mutex_enter(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
	if (pio->io_error == 0 && !(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
		pio->io_error = zio->io_error;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   887
	ASSERT3U(*countp, >, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
	if (--*countp == 0 && pio->io_stalled == stage) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
		pio->io_stalled = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
		zio_next_stage_async(pio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
zio_wait_children_ready(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
	zio_wait_for_children(zio, ZIO_STAGE_WAIT_CHILDREN_READY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
	    &zio->io_children_notready);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
zio_wait_children_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
	zio_wait_for_children(zio, ZIO_STAGE_WAIT_CHILDREN_DONE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
	    &zio->io_children_notdone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
static void
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   912
zio_read_init(zio_t *zio)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   913
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   914
	if (BP_GET_COMPRESS(zio->io_bp) != ZIO_COMPRESS_OFF) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   915
		uint64_t csize = BP_GET_PSIZE(zio->io_bp);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   916
		void *cbuf = zio_buf_alloc(csize);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   917
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   918
		zio_push_transform(zio, cbuf, csize, csize);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   919
		zio->io_pipeline |= 1U << ZIO_STAGE_READ_DECOMPRESS;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   920
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   921
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   922
	if (BP_IS_GANG(zio->io_bp)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   923
		uint64_t gsize = SPA_GANGBLOCKSIZE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   924
		void *gbuf = zio_buf_alloc(gsize);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   925
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   926
		zio_push_transform(zio, gbuf, gsize, gsize);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   927
		zio->io_pipeline |= 1U << ZIO_STAGE_READ_GANG_MEMBERS;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   928
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   929
	zio_next_stage(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   930
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   931
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   932
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
zio_ready(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
	zio_t *pio = zio->io_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   937
	if (zio->io_ready)
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   938
		zio->io_ready(zio);
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   939
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	if (pio != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
		zio_notify_parent(zio, ZIO_STAGE_WAIT_CHILDREN_READY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
		    &pio->io_children_notready);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
	if (zio->io_bp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
		zio->io_bp_copy = *zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
static void
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   951
zio_vdev_retry_io(zio_t *zio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
	zio_t *pio = zio->io_parent;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   954
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   955
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   956
	 * Preserve the failed bp so that the io_ready() callback can
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   957
	 * update the accounting accordingly. The callback will also be
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   958
	 * responsible for freeing the previously allocated block, if one
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   959
	 * exists.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   960
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   961
	zio->io_bp_orig = *zio->io_bp;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   962
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   963
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   964
	 * We must zero out the old DVA and blk_birth before reallocating
5403
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
   965
	 * the bp.
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   966
	 */
5403
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
   967
	BP_ZERO_DVAS(zio->io_bp);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   968
	zio_reset(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   969
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   970
	if (pio) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   971
		/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   972
		 * Let the parent know that we will
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   973
		 * re-alloc the write (=> new bp info).
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   974
		 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   975
		mutex_enter(&pio->io_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   976
		pio->io_children_notready++;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   977
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   978
		/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   979
		 * If the parent I/O is still in the open stage, then
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   980
		 * don't bother telling it to retry since it hasn't
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   981
		 * progressed far enough for it to care.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   982
		 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   983
		if (pio->io_stage > ZIO_STAGE_OPEN && IO_IS_ALLOCATING(pio))
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   984
			pio->io_flags |= ZIO_FLAG_WRITE_RETRY;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   985
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   986
		ASSERT(pio->io_stage <= ZIO_STAGE_WAIT_CHILDREN_DONE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   987
		mutex_exit(&pio->io_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   988
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   989
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   990
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   991
	 * We are getting ready to process the retry request so clear
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   992
	 * the flag and the zio's current error status.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   993
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   994
	zio->io_flags &= ~ZIO_FLAG_WRITE_RETRY;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   995
	zio->io_error = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   996
	zio_next_stage_async(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   997
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   998
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   999
int
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1000
zio_vdev_resume_io(spa_t *spa)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1001
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1002
	zio_t *zio;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1003
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1004
	mutex_enter(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1005
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1006
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1007
	 * Probe all of vdevs that have experienced an I/O error.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1008
	 * If we are still unable to verify the integrity of the vdev
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1009
	 * then we prevent the resume from proceeeding.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1010
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1011
	for (zio = list_head(&spa->spa_zio_list); zio != NULL;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1012
	    zio = list_next(&spa->spa_zio_list, zio)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1013
		int error = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1014
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1015
		/* We only care about I/Os that must succeed */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1016
		if (zio->io_vd == NULL || zio->io_flags & ZIO_FLAG_CANFAIL)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1017
			continue;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1018
		error = vdev_probe(zio->io_vd);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1019
		if (error) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1020
			mutex_exit(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1021
			return (error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1022
		}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1023
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1024
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1025
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1026
	 * Clear the vdev stats so that I/O can flow.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1027
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1028
	vdev_clear(spa, NULL, B_FALSE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1029
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1030
	spa->spa_state = POOL_STATE_ACTIVE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1031
	while ((zio = list_head(&spa->spa_zio_list)) != NULL) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1032
		list_remove(&spa->spa_zio_list, zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1033
		zio->io_error = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1034
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1035
		/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1036
		 * If we are resuming an allocating I/O then we force it
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1037
		 * to retry and let it resume operation where it left off.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1038
		 * Otherwise, go back to the ready stage and pick up from
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1039
		 * there.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1040
		 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1041
		if (zio_write_retry && IO_IS_ALLOCATING(zio)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1042
			zio->io_flags |= ZIO_FLAG_WRITE_RETRY;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1043
			zio->io_stage--;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1044
		} else {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1045
			zio->io_stage = ZIO_STAGE_READY;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1046
		}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1047
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1048
		(void) taskq_dispatch(zio_taskq, zio_resubmit_stage_async,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1049
		    zio, TQ_SLEEP);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1050
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1051
	mutex_exit(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1052
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1053
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1054
	 * Wait for the taskqs to finish and recheck the pool state since
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1055
	 * it's possible that a resumed I/O has failed again.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1056
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1057
	taskq_wait(zio_taskq);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1058
	if (spa_state(spa) == POOL_STATE_IO_FAILURE)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1059
		return (EIO);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1060
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1061
	mutex_enter(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1062
	cv_broadcast(&spa->spa_zio_cv);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1063
	mutex_exit(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1064
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1065
	return (0);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1066
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1067
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1068
static void
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1069
zio_vdev_suspend_io(zio_t *zio)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1070
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1071
	spa_t *spa = zio->io_spa;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1072
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1073
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1074
	 * We've experienced an unrecoverable failure so
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1075
	 * set the pool state accordingly and queue all
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1076
	 * failed IOs.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1077
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1078
	spa->spa_state = POOL_STATE_IO_FAILURE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1079
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1080
	mutex_enter(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1081
	list_insert_tail(&spa->spa_zio_list, zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1082
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1083
#ifndef _KERNEL
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1084
	/* Used to notify ztest that the pool has suspended */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1085
	cv_broadcast(&spa->spa_zio_cv);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1086
#endif
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1087
	mutex_exit(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1088
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1089
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1090
static void
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1091
zio_assess(zio_t *zio)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1092
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
	spa_t *spa = zio->io_spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
	ASSERT(zio->io_children_notready == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
	ASSERT(zio->io_children_notdone == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
	if (bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
		ASSERT(bp->blk_pad[0] == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
		ASSERT(bp->blk_pad[1] == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
		ASSERT(bcmp(bp, &zio->io_bp_copy, sizeof (blkptr_t)) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
		if (zio->io_type == ZIO_TYPE_WRITE && !BP_IS_HOLE(bp) &&
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1105
		    !(zio->io_flags & ZIO_FLAG_IO_REPAIR)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
			ASSERT(!BP_SHOULD_BYTESWAP(bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1107
			if (zio->io_ndvas != 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1108
				ASSERT3U(zio->io_ndvas, <=, BP_GET_NDVAS(bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1109
			ASSERT(BP_COUNT_GANG(bp) == 0 ||
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1110
			    (BP_COUNT_GANG(bp) == BP_GET_NDVAS(bp)));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1111
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1114
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1115
	 * Some child I/O has indicated that a retry is necessary, so
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1116
	 * we set an error on the I/O and let the logic below do the
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1117
	 * rest.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1118
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1119
	if (zio->io_flags & ZIO_FLAG_WRITE_RETRY)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1120
		zio->io_error = ERESTART;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1121
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
	if (vd != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
		vdev_stat_update(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1125
	if (zio->io_error) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1126
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1127
		 * If this I/O is attached to a particular vdev,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1128
		 * generate an error message describing the I/O failure
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1129
		 * at the block level.  We ignore these errors if the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1130
		 * device is currently unavailable.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1131
		 */
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1132
		if (zio->io_error != ECKSUM && vd != NULL && !vdev_is_dead(vd))
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1133
			zfs_ereport_post(FM_EREPORT_ZFS_IO, spa, vd, zio, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1135
		if ((zio->io_error == EIO ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1136
		    !(zio->io_flags & ZIO_FLAG_SPECULATIVE)) &&
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1137
		    zio->io_logical == zio) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1138
			/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1139
			 * For root I/O requests, tell the SPA to log the error
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1140
			 * appropriately.  Also, generate a logical data
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1141
			 * ereport.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1142
			 */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1143
			spa_log_error(spa, zio);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1144
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1145
			zfs_ereport_post(FM_EREPORT_ZFS_DATA, spa, NULL, zio,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1146
			    0, 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1147
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1149
		/*
5403
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1150
		 * If we are an allocating I/O then we attempt to reissue
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1151
		 * the I/O on another vdev unless the pool is out of space.
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1152
		 * We handle this condition based on the spa's failmode
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1153
		 * property.
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1154
		 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1155
		if (zio_write_retry && zio->io_error != ENOSPC &&
5403
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1156
		    IO_IS_ALLOCATING(zio)) {
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1157
			zio_vdev_retry_io(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1158
			return;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1159
		}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1160
		ASSERT(!(zio->io_flags & ZIO_FLAG_WRITE_RETRY));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1161
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1162
		/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1163
		 * For I/O requests that cannot fail, we carry out
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1164
		 * the requested behavior based on the failmode pool
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1165
		 * property.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1166
		 *
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1167
		 * XXX - Need to differentiate between an ENOSPC as
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1168
		 * a result of vdev failures vs. a full pool.
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1169
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1170
		if (!(zio->io_flags & ZIO_FLAG_CANFAIL)) {
3459
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
  1171
			char *blkbuf;
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
  1172
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1173
#ifdef ZFS_DEBUG
3459
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
  1174
			blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_NOSLEEP);
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
  1175
			if (blkbuf) {
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
  1176
				sprintf_blkptr(blkbuf, BP_SPRINTF_LEN,
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
  1177
				    bp ? bp : &zio->io_bp_copy);
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
  1178
			}
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1179
			cmn_err(CE_WARN, "ZFS: %s (%s on %s off %llx: zio %p "
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1180
			    "%s): error %d", zio->io_error == ECKSUM ?
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1181
			    "bad checksum" : "I/O failure",
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1182
			    zio_type_name[zio->io_type],
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1183
			    vdev_description(vd),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1184
			    (u_longlong_t)zio->io_offset,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1185
			    (void *)zio, blkbuf ? blkbuf : "", zio->io_error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1186
#endif
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1187
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1188
			if (spa_get_failmode(spa) == ZIO_FAILURE_MODE_PANIC) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1189
				fm_panic("Pool '%s' has encountered an "
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1190
				    "uncorrectable I/O failure and the "
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1191
				    "failure mode property for this pool "
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1192
				    "is set to panic.", spa_name(spa));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1193
			} else {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1194
				cmn_err(CE_WARN, "Pool '%s' has encountered "
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1195
				    "an uncorrectable I/O error. Manual "
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1196
				    "intervention is required.",
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1197
				    spa_name(spa));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1198
				zio_vdev_suspend_io(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1199
			}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1200
			return;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1201
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	}
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1203
	ASSERT(!(zio->io_flags & ZIO_FLAG_WRITE_RETRY));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1204
	ASSERT(zio->io_children_notready == 0);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1205
	zio_next_stage(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1206
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1207
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1208
static void
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1209
zio_done(zio_t *zio)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1210
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1211
	zio_t *pio = zio->io_parent;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1212
	spa_t *spa = zio->io_spa;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1213
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1214
	ASSERT(zio->io_children_notready == 0);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1215
	ASSERT(zio->io_children_notdone == 0);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1216
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
	zio_clear_transform_stack(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
	if (zio->io_done)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
		zio->io_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1221
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
	ASSERT(zio->io_delegate_list == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
	ASSERT(zio->io_delegate_next == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
	if (pio != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
		zio_t *next, *prev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
		mutex_enter(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
		next = zio->io_sibling_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
		prev = zio->io_sibling_prev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
		if (next != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
			next->io_sibling_prev = prev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
		if (prev != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
			prev->io_sibling_next = next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
		if (pio->io_child == zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
			pio->io_child = next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
		zio_notify_parent(zio, ZIO_STAGE_WAIT_CHILDREN_DONE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
		    &pio->io_children_notdone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1241
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
  1243
	/*
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
  1244
	 * Note: this I/O is now done, and will shortly be freed, so there is no
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
  1245
	 * need to clear this (or any other) flag.
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
  1246
	 */
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
  1247
	if (zio->io_flags & ZIO_FLAG_CONFIG_GRABBED)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1248
		spa_config_exit(spa, zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
	if (zio->io_waiter != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
		mutex_enter(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1252
		ASSERT(zio->io_stage == ZIO_STAGE_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
		zio->io_stalled = zio->io_stage;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
		cv_broadcast(&zio->io_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
		mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1256
	} else {
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4634
diff changeset
  1257
		mutex_destroy(&zio->io_lock);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4634
diff changeset
  1258
		cv_destroy(&zio->io_cv);
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
  1259
		kmem_cache_free(zio_cache, zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1261
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1264
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1265
 * Compression support
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
zio_write_compress(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
	int compress = zio->io_compress;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1273
	void *cbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
	uint64_t lsize = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
	uint64_t csize = lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1276
	uint64_t cbufsize = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
	int pass;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1279
	if (bp->blk_birth == zio->io_txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1280
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1281
		 * We're rewriting an existing block, which means we're
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1282
		 * working on behalf of spa_sync().  For spa_sync() to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1283
		 * converge, it must eventually be the case that we don't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1284
		 * have to allocate new blocks.  But compression changes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1285
		 * the blocksize, which forces a reallocate, and makes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1286
		 * convergence take longer.  Therefore, after the first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1287
		 * few passes, stop compressing to ensure convergence.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1288
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1289
		pass = spa_sync_pass(zio->io_spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1290
		if (pass > zio_sync_pass.zp_dontcompress)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
			compress = ZIO_COMPRESS_OFF;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1293
		ASSERT(BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1294
		pass = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1295
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1297
	if (compress != ZIO_COMPRESS_OFF)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1298
		if (!zio_compress_data(compress, zio->io_data, zio->io_size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1299
		    &cbuf, &csize, &cbufsize))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1300
			compress = ZIO_COMPRESS_OFF;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1301
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1302
	if (compress != ZIO_COMPRESS_OFF && csize != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1303
		zio_push_transform(zio, cbuf, csize, cbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1304
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1305
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
	 * The final pass of spa_sync() must be all rewrites, but the first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1307
	 * few passes offer a trade-off: allocating blocks defers convergence,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
	 * but newly allocated blocks are sequential, so they can be written
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
	 * to disk faster.  Therefore, we allow the first few passes of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
	 * spa_sync() to reallocate new blocks, but force rewrites after that.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
	 * There should only be a handful of blocks after pass 1 in any case.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
	if (bp->blk_birth == zio->io_txg && BP_GET_PSIZE(bp) == csize &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
	    pass > zio_sync_pass.zp_rewrite) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
		ASSERT(csize != 0);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1316
		BP_SET_LSIZE(bp, lsize);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1317
		BP_SET_COMPRESS(bp, compress);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
		zio->io_pipeline = ZIO_REWRITE_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
	} else {
3882
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3689
diff changeset
  1320
		if (bp->blk_birth == zio->io_txg)
f58e2c1a879e 6520462 assertion failed in zio_write_compress
ahrens
parents: 3689
diff changeset
  1321
			BP_ZERO(bp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
		if (csize == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
			BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
			zio->io_pipeline = ZIO_WAIT_FOR_CHILDREN_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
		} else {
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1326
			ASSERT3U(BP_GET_NDVAS(bp), ==, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
			BP_SET_LSIZE(bp, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
			BP_SET_PSIZE(bp, csize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
			BP_SET_COMPRESS(bp, compress);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
			zio->io_pipeline = ZIO_WRITE_ALLOCATE_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1331
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1333
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1334
	/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1335
	 * XXX this really really shouldn't need to be here but it
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1336
	 * seems like it might because of how special this function
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1337
	 * really is
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1338
	 */
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1339
	if (zio->io_crypt != ZIO_CRYPT_OFF) {
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1340
		zio->io_pipeline |= 1U << ZIO_STAGE_WRITE_ENCRYPT;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1341
		zio->io_async_stages |= 1U << ZIO_STAGE_WRITE_ENCRYPT;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1342
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1344
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1346
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1347
zio_read_decompress(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1348
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1350
	void *data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1351
	uint64_t size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1352
	uint64_t bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1353
	int compress = BP_GET_COMPRESS(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1354
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
	ASSERT(compress != ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1356
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1357
	zio_pop_transform(zio, &data, &size, &bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1358
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
	if (zio_decompress_data(compress, data, size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
	    zio->io_data, zio->io_size))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
		zio->io_error = EIO;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
	zio_buf_free(data, bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1365
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1366
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1368
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1369
/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1370
 * ==========================================================================
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1371
 * Cryptographic support
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1372
 * ==========================================================================
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1373
 */
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1374
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1375
static void
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1376
zio_write_encrypt(zio_t *zio)
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1377
{
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1378
	int crypt = zio->io_crypt;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1379
	int crypt_error;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1380
	blkptr_t *bp = zio->io_bp;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1381
	void *cbuf;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1382
	uint64_t csize = zio->io_size;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1383
	uint64_t cbufsize = 0;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1384
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1385
	ASSERT3U(spa_version(zio->io_spa), >=, SPA_VERSION_CRYPTO);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1386
	
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1387
	/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1388
	 * ZIO_STAGE_WRITE_ENCRYPT is in several pipelines because
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1389
	 * zio_write_compress() messes with zio->io_pipeline, so we
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1390
	 * could be getting called even when we have nothing to do,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1391
	 * in that case just go to the next stage.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1392
	 *
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1393
	 * XXX darrenm
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1394
	 *
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1395
	 * ZIO_CRYPT_INHERIT appears on disk for the root block,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1396
	 * we should probably check that is the only case.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1397
	 */
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1398
	if (crypt == ZIO_CRYPT_OFF || crypt == ZIO_CRYPT_INHERIT) {
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1399
#ifdef DEBUG
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1400
		cmn_err(CE_NOTE, "zio_write_encrypt: called with crypt = %s",
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1401
		    ZIO_CRYPT_OFF ? "ZIO_CRYPT_OFF" : "ZIO_CRYPT_INHERIT");
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1402
#endif
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1403
		zio_next_stage(zio);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1404
	}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1405
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1406
	/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1407
	 * We pass in the zbookmark_t so we can lookup which key
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1408
	 * is needed.  The io_txg is used by some mechansims as input
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1409
	 * into the IV generation routine.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1410
	 */
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1411
	crypt_error = zio_encrypt_data(crypt, zio->io_spa, zio->io_bookmark,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1412
	    zio->io_txg, zio->io_data, zio->io_size, &cbuf, &csize, &cbufsize);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1413
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1414
	/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1415
	 * XXX may need more failure cases.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1416
	 * One possible failure is not having access to the
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1417
	 * key material that the zboookmark_t says we needed,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1418
	 * In that case we got EACCESS so post an FMA event, we do this
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1419
	 * here so that we don't need to pass the full zio downwards into
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1420
	 * the crypto functions.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1421
	 */ 
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1422
	switch (crypt_error) {
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1423
	case 0:
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1424
		zio_push_transform(zio, cbuf, csize, cbufsize);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1425
		ASSERT3U(csize, ==, zio->io_size);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1426
		BP_SET_CRYPT(zio->io_bp, crypt);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1427
		BP_SET_PSIZE(bp, csize);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1428
		break;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1429
	case EACCES:
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1430
		zfs_ereport_post(FM_EREPORT_ZFS_CRYPTO_KEY_UNAVAIL,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1431
		    zio->io_spa, zio->io_vd, zio, 0, 0);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1432
	default:
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1433
		zio->io_error = crypt_error;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1434
	}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1435
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1436
	zio_next_stage(zio);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1437
}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1438
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1439
static void
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1440
zio_read_decrypt(zio_t *zio)
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1441
{
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1442
	blkptr_t *bp = zio->io_bp;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1443
	int crypt = BP_GET_CRYPT(bp);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1444
	void *data;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1445
	uint64_t size;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1446
	uint64_t bufsize;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1447
	int crypt_error;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1448
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1449
	ASSERT3U(spa_version(zio->io_spa), >=, SPA_VERSION_CRYPTO);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1450
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1451
	/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1452
	 * XXX darrenm
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1453
	 *
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1454
	 * ZIO_CRYPT_INHERIT appears on disk for the root block,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1455
	 * we should probably check that is the only case.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1456
	 */
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1457
	if (crypt == ZIO_CRYPT_OFF || crypt == ZIO_CRYPT_INHERIT) {
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1458
#ifdef DEBUG
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1459
		cmn_err(CE_NOTE,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1460
		    "zio_read_decrypt: called with crypt = %s",
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1461
		    ZIO_CRYPT_OFF ? "ZIO_CRYPT_OFF" : "ZIO_CRYPT_INHERIT");
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1462
#endif
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1463
		zio_next_stage(zio);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1464
	}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1465
	
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1466
	zio_pop_transform(zio, &data, &size, &bufsize);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1467
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1468
	crypt_error = zio_decrypt_data(crypt, zio->io_spa, zio->io_bookmark, 
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1469
	    bp->blk_birth, data, size, zio->io_data, zio->io_size);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1470
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1471
	/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1472
	 * XXX may need more failure cases.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1473
	 * One possible failure is not having access to the
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1474
	 * key material that the zboookmark_t says we needed,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1475
	 * In that case we got EACCESS so post an FMA event, we do this
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1476
	 * here so that we don't need to pass the full zio downwards into
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1477
	 * the crypto functions.
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1478
	 */ 
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1479
	switch (crypt_error) {
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1480
	case EACCES:
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1481
		zfs_ereport_post(FM_EREPORT_ZFS_CRYPTO_KEY_UNAVAIL,
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1482
		    zio->io_spa, zio->io_vd, zio, 0, 0);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1483
	default:
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1484
		zio->io_error = crypt_error;
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1485
	}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1486
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1487
	zio_buf_free(data, bufsize);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1488
	zio_next_stage(zio);
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1489
}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  1490
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
 * Gang block support
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
zio_gang_pipeline(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
	 * By default, the pipeline assumes that we're dealing with a gang
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
	 * block.  If we're not, strip out any gang-specific stages.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
	 */
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1503
	if (!BP_IS_GANG(zio->io_bp))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
		zio->io_pipeline &= ~ZIO_GANG_STAGES;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
zio_gang_byteswap(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1511
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1512
	ASSERT(zio->io_size == SPA_GANGBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
	if (BP_SHOULD_BYTESWAP(zio->io_bp))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
		byteswap_uint64_array(zio->io_data, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
zio_get_gang_header(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1520
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1521
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1522
	uint64_t gsize = SPA_GANGBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1523
	void *gbuf = zio_buf_alloc(gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1524
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1525
	ASSERT(BP_IS_GANG(bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1526
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1527
	zio_push_transform(zio, gbuf, gsize, gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1528
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1529
	zio_nowait(zio_create(zio, zio->io_spa, bp->blk_birth, bp, gbuf, gsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1530
	    NULL, NULL, ZIO_TYPE_READ, zio->io_priority,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1531
	    zio->io_flags & ZIO_FLAG_GANG_INHERIT,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1532
	    ZIO_STAGE_OPEN, ZIO_READ_GANG_PIPELINE));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1533
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1534
	zio_wait_children_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1535
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1537
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1538
zio_read_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1539
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1540
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1541
	uint64_t gsize, gbufsize, loff, lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1542
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1544
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1545
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1546
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
	for (loff = 0, i = 0; loff != zio->io_size; loff += lsize, i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1550
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1551
		lsize = BP_GET_PSIZE(gbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1553
		ASSERT(BP_GET_COMPRESS(gbp) == ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1554
		ASSERT3U(lsize, ==, BP_GET_LSIZE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1555
		ASSERT3U(loff + lsize, <=, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1556
		ASSERT(i < SPA_GBH_NBLKPTRS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1557
		ASSERT(!BP_IS_HOLE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1558
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1559
		zio_nowait(zio_read(zio, zio->io_spa, gbp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1560
		    (char *)zio->io_data + loff, lsize, NULL, NULL,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1561
		    zio->io_priority, zio->io_flags & ZIO_FLAG_GANG_INHERIT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1562
		    &zio->io_bookmark));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
	zio_buf_free(gbh, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
	zio_wait_children_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
zio_rewrite_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
	uint64_t gsize, gbufsize, loff, lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1576
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
	ASSERT3U(zio->io_size, ==, SPA_GANGBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
	ASSERT(gsize == gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
	for (loff = 0, i = 0; loff != zio->io_size; loff += lsize, i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
		lsize = BP_GET_PSIZE(gbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
		ASSERT(BP_GET_COMPRESS(gbp) == ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
		ASSERT3U(lsize, ==, BP_GET_LSIZE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
		ASSERT3U(loff + lsize, <=, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
		ASSERT(i < SPA_GBH_NBLKPTRS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
		ASSERT(!BP_IS_HOLE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1594
		zio_nowait(zio_rewrite(zio, zio->io_spa, zio->io_checksum,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
		    zio->io_txg, gbp, (char *)zio->io_data + loff, lsize,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1596
		    NULL, NULL, zio->io_priority, zio->io_flags,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1597
		    &zio->io_bookmark));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
	zio_push_transform(zio, gbh, gsize, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
	zio_wait_children_ready(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1603
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1604
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1605
zio_free_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1606
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1608
	uint64_t gsize, gbufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1609
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1610
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1611
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
	for (i = 0; i < SPA_GBH_NBLKPTRS; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
		if (BP_IS_HOLE(gbp))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
		zio_nowait(zio_free(zio, zio->io_spa, zio->io_txg,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
		    gbp, NULL, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1625
	zio_buf_free(gbh, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1626
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1628
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
zio_claim_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
	uint64_t gsize, gbufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1634
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1635
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1636
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
	for (i = 0; i < SPA_GBH_NBLKPTRS; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
		if (BP_IS_HOLE(gbp))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
		zio_nowait(zio_claim(zio, zio->io_spa, zio->io_txg,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
		    gbp, NULL, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1649
	zio_buf_free(gbh, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1651
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1653
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
zio_write_allocate_gang_member_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1655
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1656
	zio_t *pio = zio->io_parent;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1657
	dva_t *cdva = zio->io_bp->blk_dva;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1658
	dva_t *pdva = pio->io_bp->blk_dva;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
	uint64_t asize;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1660
	int d;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1661
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1662
	ASSERT3U(pio->io_ndvas, ==, zio->io_ndvas);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1663
	ASSERT3U(BP_GET_NDVAS(zio->io_bp), <=, BP_GET_NDVAS(pio->io_bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1664
	ASSERT3U(zio->io_ndvas, <=, BP_GET_NDVAS(zio->io_bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1665
	ASSERT3U(pio->io_ndvas, <=, BP_GET_NDVAS(pio->io_bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1666
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
	mutex_enter(&pio->io_lock);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1668
	for (d = 0; d < BP_GET_NDVAS(pio->io_bp); d++) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1669
		ASSERT(DVA_GET_GANG(&pdva[d]));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1670
		asize = DVA_GET_ASIZE(&pdva[d]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1671
		asize += DVA_GET_ASIZE(&cdva[d]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1672
		DVA_SET_ASIZE(&pdva[d], asize);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1673
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1674
	mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1675
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1676
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1677
static int
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1678
zio_write_allocate_gang_members(zio_t *zio, metaslab_class_t *mc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1680
	blkptr_t *bp = zio->io_bp;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1681
	dva_t *dva = bp->blk_dva;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1682
	spa_t *spa = zio->io_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1683
	zio_gbh_phys_t *gbh;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1684
	uint64_t txg = zio->io_txg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1685
	uint64_t resid = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1686
	uint64_t maxalloc = P2ROUNDUP(zio->io_size >> 1, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1687
	uint64_t gsize, loff, lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
	uint32_t gbps_left;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1689
	int ndvas = zio->io_ndvas;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1690
	int gbh_ndvas = MIN(ndvas + 1, spa_max_replication(spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
	int error;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1692
	int i, d;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
	gsize = SPA_GANGBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1695
	gbps_left = SPA_GBH_NBLKPTRS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1696
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1697
	error = metaslab_alloc(spa, mc, gsize, bp, gbh_ndvas, txg, NULL,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1698
	    B_FALSE);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1699
	if (error)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1700
		return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1701
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1702
	for (d = 0; d < gbh_ndvas; d++)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1703
		DVA_SET_GANG(&dva[d], 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1705
	bp->blk_birth = txg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1706
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
	gbh = zio_buf_alloc(gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
	bzero(gbh, gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1710
	/* We need to test multi-level gang blocks */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1711
	if (maxalloc >= zio_gang_bang && (lbolt & 0x1) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1712
		maxalloc = MAX(maxalloc >> 2, SPA_MINBLOCKSIZE);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1713
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1714
	for (loff = 0, i = 0; loff != zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1715
	    loff += lsize, resid -= lsize, gbps_left--, i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
		blkptr_t *gbp = &gbh->zg_blkptr[i];
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1717
		dva = gbp->blk_dva;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
		ASSERT(gbps_left != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
		maxalloc = MIN(maxalloc, resid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
		while (resid <= maxalloc * gbps_left) {
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1723
			error = metaslab_alloc(spa, mc, maxalloc, gbp, ndvas,
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1724
			    txg, bp, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
			if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
			ASSERT3U(error, ==, ENOSPC);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1728
			/* XXX - free up previous allocations? */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
			if (maxalloc == SPA_MINBLOCKSIZE)
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1730
				return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1731
			maxalloc = P2ROUNDUP(maxalloc >> 1, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1732
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1734
		if (resid <= maxalloc * gbps_left) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
			lsize = maxalloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
			BP_SET_LSIZE(gbp, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
			BP_SET_PSIZE(gbp, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1738
			BP_SET_COMPRESS(gbp, ZIO_COMPRESS_OFF);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1739
			gbp->blk_birth = txg;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1740
			zio_nowait(zio_rewrite(zio, spa,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1741
			    zio->io_checksum, txg, gbp,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
			    (char *)zio->io_data + loff, lsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
			    zio_write_allocate_gang_member_done, NULL,
5403
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1744
			    zio->io_priority,
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1745
			    zio->io_flags & ZIO_FLAG_GANG_INHERIT,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1746
			    &zio->io_bookmark));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1747
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1748
			lsize = P2ROUNDUP(resid / gbps_left, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1749
			ASSERT(lsize != SPA_MINBLOCKSIZE);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1750
			zio_nowait(zio_write_allocate(zio, spa,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1751
			    zio->io_checksum, txg, gbp,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1752
			    (char *)zio->io_data + loff, lsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1753
			    zio_write_allocate_gang_member_done, NULL,
5403
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1754
			    zio->io_priority,
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1755
			    zio->io_flags & ZIO_FLAG_GANG_INHERIT));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1756
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1757
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1758
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1759
	ASSERT(resid == 0 && loff == zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1760
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1761
	zio->io_pipeline |= 1U << ZIO_STAGE_GANG_CHECKSUM_GENERATE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1762
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1763
	zio_push_transform(zio, gbh, gsize, gsize);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1764
	/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1765
	 * As much as we'd like this to be zio_wait_children_ready(),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1766
	 * updating our ASIZE doesn't happen until the io_done callback,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1767
	 * so we have to wait for that to finish in order for our BP
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1768
	 * to be stable.
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1769
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1770
	zio_wait_children_done(zio);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1771
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1772
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1773
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1774
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1775
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1776
 * Allocate and free blocks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1777
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1779
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1780
zio_dva_allocate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1781
{
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1782
	spa_t *spa = zio->io_spa;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1783
	metaslab_class_t *mc = spa->spa_normal_class;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1784
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1785
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1786
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1787
	ASSERT(BP_IS_HOLE(bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1788
	ASSERT3U(BP_GET_NDVAS(bp), ==, 0);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1789
	ASSERT3U(zio->io_ndvas, >, 0);
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1790
	ASSERT3U(zio->io_ndvas, <=, spa_max_replication(spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1792
	/* For testing, make some blocks above a certain size be gang blocks */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1793
	if (zio->io_size >= zio_gang_bang && (lbolt & 0x3) == 0) {
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1794
		error = zio_write_allocate_gang_members(zio, mc);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1795
		if (error)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1796
			zio->io_error = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1797
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1798
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1799
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1800
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1801
	 * For testing purposes, we force I/Os to retry. We don't allow
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1802
	 * retries beyond the first pass since those I/Os are non-allocating
5403
0bfd0977c989 6625167 gang blocks don't need to retry so hard
gw25295
parents: 5369
diff changeset
  1803
	 * writes.
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1804
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1805
	if (zio_io_fail_shift &&
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1806
	    spa_sync_pass(zio->io_spa) <= zio_sync_pass.zp_rewrite &&
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1807
	    zio_io_should_fail(zio_io_fail_shift))
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1808
		zio->io_flags |= ZIO_FLAG_WRITE_RETRY;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1809
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1810
	ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1811
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1812
	error = metaslab_alloc(spa, mc, zio->io_size, bp, zio->io_ndvas,
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1813
	    zio->io_txg, NULL, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1814
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1816
		bp->blk_birth = zio->io_txg;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1817
	} else if (error == ENOSPC && zio->io_size > SPA_MINBLOCKSIZE) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1818
		error = zio_write_allocate_gang_members(zio, mc);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1819
		if (error == 0)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1820
			return;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1821
		zio->io_error = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
		zio->io_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
zio_dva_free(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1830
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1831
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  1833
	metaslab_free(zio->io_spa, bp, zio->io_txg, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1834
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1835
	BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1836
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1837
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1838
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1839
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
zio_dva_claim(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  1843
	zio->io_error = metaslab_claim(zio->io_spa, zio->io_bp, zio->io_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1844
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1845
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1846
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1847
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1848
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1849
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
 * Read and write to physical devices
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1851
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1852
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1853
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1854
static void
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1855
zio_vdev_io_start(zio_t *zio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1857
	vdev_t *vd = zio->io_vd;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1858
	vdev_t *tvd = vd ? vd->vdev_top : NULL;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1859
	blkptr_t *bp = zio->io_bp;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1860
	uint64_t align;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1861
	spa_t *spa = zio->io_spa;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1862
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1863
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1864
	 * If the pool is already in a failure state then just suspend
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1865
	 * this IO until the problem is resolved. We will reissue them
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1866
	 * at that time.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1867
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1868
	if (spa_state(spa) == POOL_STATE_IO_FAILURE &&
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1869
	    zio->io_type == ZIO_TYPE_WRITE) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1870
		zio_vdev_suspend_io(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1871
		return;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1872
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1873
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1874
	if (vd == NULL) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1875
		/* The mirror_ops handle multiple DVAs in a single BP */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1876
		vdev_mirror_ops.vdev_op_io_start(zio);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1877
		return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1878
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1879
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1880
	align = 1ULL << tvd->vdev_ashift;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1881
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1882
	if (zio->io_retries == 0 && vd == tvd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1883
		zio->io_flags |= ZIO_FLAG_FAILFAST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1884
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1885
	if (!(zio->io_flags & ZIO_FLAG_PHYSICAL) &&
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1886
	    vd->vdev_children == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1887
		zio->io_flags |= ZIO_FLAG_PHYSICAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
		zio->io_offset += VDEV_LABEL_START_SIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1889
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1890
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1891
	if (P2PHASE(zio->io_size, align) != 0) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1892
		uint64_t asize = P2ROUNDUP(zio->io_size, align);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1893
		char *abuf = zio_buf_alloc(asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1894
		ASSERT(vd == tvd);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1895
		if (zio->io_type == ZIO_TYPE_WRITE) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1896
			bcopy(zio->io_data, abuf, zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1897
			bzero(abuf + zio->io_size, asize - zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1898
		}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1899
		zio_push_transform(zio, abuf, asize, asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1900
		ASSERT(!(zio->io_flags & ZIO_FLAG_SUBBLOCK));
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1901
		zio->io_flags |= ZIO_FLAG_SUBBLOCK;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1902
	}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1903
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1904
	ASSERT(P2PHASE(zio->io_offset, align) == 0);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1905
	ASSERT(P2PHASE(zio->io_size, align) == 0);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1906
	ASSERT(bp == NULL ||
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1907
	    P2ROUNDUP(ZIO_GET_IOSIZE(zio), align) == zio->io_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1908
	ASSERT(zio->io_type != ZIO_TYPE_WRITE || (spa_mode & FWRITE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1909
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1910
	vdev_io_start(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1911
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1912
	/* zio_next_stage_async() gets called from io completion interrupt */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1913
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1914
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1915
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1916
zio_vdev_io_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1917
{
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1918
	if (zio->io_vd == NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1919
		/* The mirror_ops handle multiple DVAs in a single BP */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1920
		vdev_mirror_ops.vdev_op_io_done(zio);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1921
	else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1922
		vdev_io_done(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1923
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1924
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1925
/* XXPOLICY */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1926
boolean_t
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1927
zio_should_retry(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1928
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1929
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1930
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1931
	if (zio->io_error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1932
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1933
	if (zio->io_delegate_list != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1934
		return (B_FALSE);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1935
	if (vd && vd != vd->vdev_top)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1936
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1937
	if (zio->io_flags & ZIO_FLAG_DONT_RETRY)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1938
		return (B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1939
	if (zio->io_retries > 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1940
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1941
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1942
	return (B_TRUE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1943
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1944
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1945
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1946
zio_vdev_io_assess(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1947
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1948
	vdev_t *vd = zio->io_vd;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1949
	vdev_t *tvd = vd ? vd->vdev_top : NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1950
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1951
	ASSERT(zio->io_vsd == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1952
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1953
	if (zio->io_flags & ZIO_FLAG_SUBBLOCK) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1954
		void *abuf;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1955
		uint64_t asize;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1956
		ASSERT(vd == tvd);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1957
		zio_pop_transform(zio, &abuf, &asize, &asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1958
		if (zio->io_type == ZIO_TYPE_READ)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1959
			bcopy(abuf, zio->io_data, zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1960
		zio_buf_free(abuf, asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1961
		zio->io_flags &= ~ZIO_FLAG_SUBBLOCK;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1962
	}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1963
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1964
	if (zio_injection_enabled && !zio->io_error)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1965
		zio->io_error = zio_handle_fault_injection(zio, EIO);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1966
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1967
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1968
	 * If the I/O failed, determine whether we should attempt to retry it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1969
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1970
	/* XXPOLICY */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1971
	if (zio_should_retry(zio)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1972
		ASSERT(tvd == vd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1973
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1974
		zio->io_retries++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1975
		zio->io_error = 0;
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
  1976
		zio->io_flags &= ZIO_FLAG_VDEV_INHERIT |
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
  1977
		    ZIO_FLAG_CONFIG_GRABBED;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1978
		/* XXPOLICY */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1979
		zio->io_flags &= ~ZIO_FLAG_FAILFAST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1980
		zio->io_flags |= ZIO_FLAG_DONT_CACHE;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1981
		zio->io_stage = ZIO_STAGE_VDEV_IO_START - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1982
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1983
		dprintf("retry #%d for %s to %s offset %llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1984
		    zio->io_retries, zio_type_name[zio->io_type],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1985
		    vdev_description(vd), zio->io_offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1986
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1987
		zio_next_stage_async(zio);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1988
		return;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1989
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1990
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1991
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1992
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1994
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1995
zio_vdev_io_reissue(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1996
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1997
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1998
	ASSERT(zio->io_error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1999
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2000
	zio->io_stage--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2001
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2002
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2003
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2004
zio_vdev_io_redone(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2005
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2006
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2007
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2008
	zio->io_stage--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2009
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2011
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2012
zio_vdev_io_bypass(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2014
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2015
	ASSERT(zio->io_error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2016
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2017
	zio->io_flags |= ZIO_FLAG_IO_BYPASS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2018
	zio->io_stage = ZIO_STAGE_VDEV_IO_ASSESS - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2019
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2020
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2021
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2023
 * Generate and verify checksums
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2025
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
zio_checksum_generate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2028
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2029
	int checksum = zio->io_checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2030
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2031
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
	ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2033
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2034
	BP_SET_CHECKSUM(bp, checksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2035
	BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2036
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2037
	zio_checksum(checksum, &bp->blk_cksum, zio->io_data, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2038
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2039
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2040
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2041
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2042
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2043
zio_gang_checksum_generate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2044
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2045
	zio_cksum_t zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2046
	zio_gbh_phys_t *gbh = zio->io_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2047
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2048
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2049
	ASSERT3U(zio->io_size, ==, SPA_GANGBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2050
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2051
	zio_set_gang_verifier(zio, &gbh->zg_tail.zbt_cksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2052
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2053
	zio_checksum(ZIO_CHECKSUM_GANG_HEADER, &zc, zio->io_data, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2054
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2055
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2056
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2057
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2058
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2059
zio_checksum_verify(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2060
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2061
	if (zio->io_bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2062
		zio->io_error = zio_checksum_error(zio);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2063
		if (zio->io_error && !(zio->io_flags & ZIO_FLAG_SPECULATIVE))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2064
			zfs_ereport_post(FM_EREPORT_ZFS_CHECKSUM,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2065
			    zio->io_spa, zio->io_vd, zio, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2066
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2067
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2068
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2069
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2070
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2071
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2072
 * Called by RAID-Z to ensure we don't compute the checksum twice.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2073
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2074
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2075
zio_checksum_verified(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2076
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2077
	zio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2078
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2079
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2080
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2081
 * Set the external verifier for a gang block based on stuff in the bp
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2082
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2083
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2084
zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2085
{
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2086
	blkptr_t *bp = zio->io_bp;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2087
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2088
	zcp->zc_word[0] = DVA_GET_VDEV(BP_IDENTITY(bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2089
	zcp->zc_word[1] = DVA_GET_OFFSET(BP_IDENTITY(bp));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2090
	zcp->zc_word[2] = bp->blk_birth;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2091
	zcp->zc_word[3] = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2092
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2093
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2094
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2095
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2096
 * Define the pipeline
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2097
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2098
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2099
typedef void zio_pipe_stage_t(zio_t *zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2100
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2101
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2102
zio_badop(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2103
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2104
	panic("Invalid I/O pipeline stage %u for zio %p", zio->io_stage, zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2105
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2106
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2107
zio_pipe_stage_t *zio_pipeline[ZIO_STAGE_DONE + 2] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2108
	zio_badop,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2109
	zio_wait_children_ready,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2110
	zio_write_compress,
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  2111
	zio_write_encrypt,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2112
	zio_checksum_generate,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2113
	zio_gang_pipeline,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2114
	zio_get_gang_header,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2115
	zio_rewrite_gang_members,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2116
	zio_free_gang_members,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2117
	zio_claim_gang_members,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2118
	zio_dva_allocate,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2119
	zio_dva_free,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2120
	zio_dva_claim,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2121
	zio_gang_checksum_generate,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2122
	zio_ready,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2123
	zio_read_init,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
	zio_vdev_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2125
	zio_vdev_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2126
	zio_vdev_io_assess,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2127
	zio_wait_children_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2128
	zio_checksum_verify,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2129
	zio_read_gang_members,
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  2130
	zio_read_decrypt,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2131
	zio_read_decompress,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2132
	zio_assess,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2133
	zio_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2134
	zio_badop
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2135
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2136
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2137
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2138
 * Move an I/O to the next stage of the pipeline and execute that stage.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2139
 * There's no locking on io_stage because there's no legitimate way for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
 * multiple threads to be attempting to process the same I/O.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2141
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
zio_next_stage(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
	uint32_t pipeline = zio->io_pipeline;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2146
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2147
	ASSERT(!MUTEX_HELD(&zio->io_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2149
	if (zio->io_error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2150
		dprintf("zio %p vdev %s offset %llx stage %d error %d\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2151
		    zio, vdev_description(zio->io_vd),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2152
		    zio->io_offset, zio->io_stage, zio->io_error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2153
		if (((1U << zio->io_stage) & ZIO_VDEV_IO_PIPELINE) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2154
			pipeline &= ZIO_ERROR_PIPELINE_MASK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2155
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2157
	while (((1U << ++zio->io_stage) & pipeline) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2158
		continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2159
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2160
	ASSERT(zio->io_stage <= ZIO_STAGE_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2161
	ASSERT(zio->io_stalled == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2162
3689
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2163
	/*
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2164
	 * See the comment in zio_next_stage_async() about per-CPU taskqs.
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2165
	 */
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2166
	if (((1U << zio->io_stage) & zio->io_async_stages) &&
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2167
	    (zio->io_stage == ZIO_STAGE_WRITE_COMPRESS) &&
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2168
	    !(zio->io_flags & ZIO_FLAG_METADATA)) {
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2169
		taskq_t *tq = zio->io_spa->spa_zio_issue_taskq[zio->io_type];
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2170
		(void) taskq_dispatch(tq,
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2171
		    (task_func_t *)zio_pipeline[zio->io_stage], zio, TQ_SLEEP);
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2172
	} else {
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2173
		zio_pipeline[zio->io_stage](zio);
75b45bbf8f18 6460622 zio_nowait() doesn't live up to its name
ek110237
parents: 3668
diff changeset
  2174
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2175
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2178
zio_next_stage_async(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2179
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
	taskq_t *tq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
	uint32_t pipeline = zio->io_pipeline;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2182
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
	ASSERT(!MUTEX_HELD(&zio->io_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2184
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2185
	if (zio->io_error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2186
		dprintf("zio %p vdev %s offset %llx stage %d error %d\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2187
		    zio, vdev_description(zio->io_vd),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2188
		    zio->io_offset, zio->io_stage, zio->io_error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2189
		if (((1U << zio->io_stage) & ZIO_VDEV_IO_PIPELINE) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
			pipeline &= ZIO_ERROR_PIPELINE_MASK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2191
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2192
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2193
	while (((1U << ++zio->io_stage) & pipeline) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2194
		continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2195
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2196
	ASSERT(zio->io_stage <= ZIO_STAGE_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2197
	ASSERT(zio->io_stalled == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2198
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2199
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2200
	 * For performance, we'll probably want two sets of task queues:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2201
	 * per-CPU issue taskqs and per-CPU completion taskqs.  The per-CPU
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2202
	 * part is for read performance: since we have to make a pass over
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2203
	 * the data to checksum it anyway, we want to do this on the same CPU
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2204
	 * that issued the read, because (assuming CPU scheduling affinity)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2205
	 * that thread is probably still there.  Getting this optimization
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2206
	 * right avoids performance-hostile cache-to-cache transfers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2207
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2208
	 * Note that having two sets of task queues is also necessary for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2209
	 * correctness: if all of the issue threads get bogged down waiting
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2210
	 * for dependent reads (e.g. metaslab freelist) to complete, then
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
	 * there won't be any threads available to service I/O completion
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2212
	 * interrupts.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2213
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
	if ((1U << zio->io_stage) & zio->io_async_stages) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
		if (zio->io_stage < ZIO_STAGE_VDEV_IO_DONE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
			tq = zio->io_spa->spa_zio_issue_taskq[zio->io_type];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2218
			tq = zio->io_spa->spa_zio_intr_taskq[zio->io_type];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2219
		(void) taskq_dispatch(tq,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2220
		    (task_func_t *)zio_pipeline[zio->io_stage], zio, TQ_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2221
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2222
		zio_pipeline[zio->io_stage](zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2223
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2224
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2225
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2226
void
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2227
zio_resubmit_stage_async(void *arg)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2228
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2229
	zio_t *zio = (zio_t *)(uintptr_t)arg;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2230
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2231
	zio_next_stage_async(zio);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2232
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2233
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2234
static boolean_t
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2235
zio_io_should_fail(uint16_t range)
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2236
{
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2237
	static uint16_t	allocs = 0;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2238
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2239
	return (P2PHASE(allocs++, 1U<<range) == 0);
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2240
}
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2241
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2242
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2243
 * Try to allocate an intent log block.  Return 0 on success, errno on failure.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2244
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2245
int
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2246
zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp, blkptr_t *old_bp,
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2247
    uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2250
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2251
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2252
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  2253
	if (zio_zil_fail_shift && zio_io_should_fail(zio_zil_fail_shift)) {
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2254
		spa_config_exit(spa, FTAG);
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2255
		return (ENOSPC);
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2256
	}
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3547
diff changeset
  2257
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2258
	/*
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2259
	 * We were passed the previous log block's DVA in bp->blk_dva[0].
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2260
	 * We use that as a hint for which vdev to allocate from next.
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2261
	 */
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2262
	error = metaslab_alloc(spa, spa->spa_log_class, size,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2263
	    new_bp, 1, txg, old_bp, B_TRUE);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2264
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2265
	if (error)
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2266
		error = metaslab_alloc(spa, spa->spa_normal_class, size,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  2267
		    new_bp, 1, txg, old_bp, B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
	if (error == 0) {
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2270
		BP_SET_LSIZE(new_bp, size);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2271
		BP_SET_PSIZE(new_bp, size);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2272
		BP_SET_COMPRESS(new_bp, ZIO_COMPRESS_OFF);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2273
		BP_SET_CHECKSUM(new_bp, ZIO_CHECKSUM_ZILOG);
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
  2274
		BP_SET_CRYPT(new_bp, ZIO_CRYPT_OFF); /* XXX darrenm ZIL crypto */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2275
		BP_SET_TYPE(new_bp, DMU_OT_INTENT_LOG);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2276
		BP_SET_LEVEL(new_bp, 0);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2277
		BP_SET_BYTEORDER(new_bp, ZFS_HOST_BYTEORDER);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  2278
		new_bp->blk_birth = txg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2279
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2280
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2281
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2282
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2283
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2284
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2285
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2286
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2287
 * Free an intent log block.  We know it can't be a gang block, so there's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2288
 * nothing to do except metaslab_free() it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2289
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2290
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2291
zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2292
{
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2293
	ASSERT(!BP_IS_GANG(bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2294
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2295
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2296
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  2297
	metaslab_free(spa, bp, txg, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2298
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2299
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2300
}
4469
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2301
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2302
/*
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2303
 * start an async flush of the write cache for this vdev
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2304
 */
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2305
void
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2306
zio_flush_vdev(spa_t *spa, uint64_t vdev, zio_t **zio)
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2307
{
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2308
	vdev_t *vd;
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2309
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2310
	/*
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2311
	 * Lock out configuration changes.
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2312
	 */
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2313
	spa_config_enter(spa, RW_READER, FTAG);
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2314
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2315
	if (*zio == NULL)
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2316
		*zio = zio_root(spa, NULL, NULL, ZIO_FLAG_CANFAIL);
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2317
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2318
	vd = vdev_lookup_top(spa, vdev);
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2319
	ASSERT(vd);
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2320
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2321
	(void) zio_nowait(zio_ioctl(*zio, spa, vd, DKIOCFLUSHWRITECACHE,
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2322
	    NULL, NULL, ZIO_PRIORITY_NOW,
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2323
	    ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_RETRY));
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2324
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2325
	spa_config_exit(spa, FTAG);
7d15cd6c3854 6566482 panic replacing a pool device whilst intent log being used
perrin
parents: 4451
diff changeset
  2326
}