usr/src/uts/common/fs/zfs/zio.c
author Darren Moffat <Darren.Moffat@Sun.COM>
Mon, 06 Oct 2008 14:09:06 +0100
changeset 13396 485224e23eb9
parent 13395 6aa29333ca54
child 13399 24f53bc2622e
permissions -rw-r--r--
6756231 Read and Write of encrytped data fundamentally broken post onnv_100
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
/*
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5688
diff changeset
    22
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <sys/zfs_context.h>
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    27
#include <sys/fm/fs/zfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/zio_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#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
    34
#include <sys/zio_crypt.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
    37
#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
    38
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
 * I/O priority table
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
	0,	/* ZIO_PRIORITY_NOW		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
	0,	/* ZIO_PRIORITY_SYNC_READ	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
	0,	/* ZIO_PRIORITY_SYNC_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
	6,	/* ZIO_PRIORITY_ASYNC_READ	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
	4,	/* ZIO_PRIORITY_ASYNC_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
	4,	/* ZIO_PRIORITY_FREE		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
	0,	/* ZIO_PRIORITY_CACHE_FILL	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
	0,	/* ZIO_PRIORITY_LOG_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
	10,	/* ZIO_PRIORITY_RESILVER	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
	20,	/* ZIO_PRIORITY_SCRUB		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
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
 * I/O type descriptions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
char *zio_type_name[ZIO_TYPES] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
	"null", "read", "write", "free", "claim", "ioctl" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
    65
#define	SYNC_PASS_DEFERRED_FREE	1	/* defer frees after this pass */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
    66
#define	SYNC_PASS_DONT_COMPRESS	4	/* don't compress after this pass */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
    67
#define	SYNC_PASS_REWRITE	1	/* rewrite new bps after this pass */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    68
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
 * I/O kmem caches
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
 */
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
    74
kmem_cache_t *zio_cache;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
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
    76
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
    77
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    78
#ifdef _KERNEL
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    79
extern vmem_t *zio_alloc_arena;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    80
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    82
/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
    83
 * An allocating zio is one that either currently has the DVA allocate
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
    84
 * stage set or will have it later in its lifetime.
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    85
 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    86
#define	IO_IS_ALLOCATING(zio) \
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5530
diff changeset
    87
	((zio)->io_orig_pipeline & (1U << ZIO_STAGE_DVA_ALLOCATE))
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
    88
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
zio_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	size_t c;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    93
	vmem_t *data_alloc_arena = NULL;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    94
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    95
#ifdef _KERNEL
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    96
	data_alloc_arena = zio_alloc_arena;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    97
#endif
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
    98
	zio_cache = kmem_cache_create("zio_cache", sizeof (zio_t), 0,
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
    99
	    NULL, NULL, NULL, NULL, NULL, 0);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   100
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	 * For small buffers, we want a cache for each multiple of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	 * SPA_MINBLOCKSIZE.  For medium-size buffers, we want a cache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	 * for each quarter-power of 2.  For large buffers, we want
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	 * a cache for each multiple of PAGESIZE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
	for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
		size_t size = (c + 1) << SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
		size_t p2 = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
		size_t align = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
		while (p2 & (p2 - 1))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
			p2 &= p2 - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
		if (size <= 4 * SPA_MINBLOCKSIZE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
			align = SPA_MINBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
		} else if (P2PHASE(size, PAGESIZE) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
			align = PAGESIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
		} else if (P2PHASE(size, p2 >> 2) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
			align = p2 >> 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
		if (align != 0) {
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   124
			char name[36];
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2082
diff changeset
   125
			(void) sprintf(name, "zio_buf_%lu", (ulong_t)size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
			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
   127
			    align, NULL, NULL, NULL, NULL, NULL, KMC_NODEBUG);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   128
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   129
			(void) sprintf(name, "zio_data_buf_%lu", (ulong_t)size);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   130
			zio_data_buf_cache[c] = kmem_cache_create(name, size,
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   131
			    align, NULL, NULL, NULL, NULL, data_alloc_arena,
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   132
			    KMC_NODEBUG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	while (--c != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
		ASSERT(zio_buf_cache[c] != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
		if (zio_buf_cache[c - 1] == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
			zio_buf_cache[c - 1] = zio_buf_cache[c];
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   140
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   141
		ASSERT(zio_data_buf_cache[c] != NULL);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   142
		if (zio_data_buf_cache[c - 1] == NULL)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   143
			zio_data_buf_cache[c - 1] = zio_data_buf_cache[c];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   145
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   146
	zio_inject_init();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
zio_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
	size_t c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
	kmem_cache_t *last_cache = NULL;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   154
	kmem_cache_t *last_data_cache = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
	for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
		if (zio_buf_cache[c] != last_cache) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
			last_cache = zio_buf_cache[c];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
			kmem_cache_destroy(zio_buf_cache[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
		zio_buf_cache[c] = NULL;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   162
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   163
		if (zio_data_buf_cache[c] != last_data_cache) {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   164
			last_data_cache = zio_data_buf_cache[c];
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   165
			kmem_cache_destroy(zio_data_buf_cache[c]);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   166
		}
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   167
		zio_data_buf_cache[c] = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   169
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   170
	kmem_cache_destroy(zio_cache);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   171
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   172
	zio_inject_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
 * Allocate and free I/O buffers
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
 */
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   180
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   181
/*
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   182
 * 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
   183
 * 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
   184
 * 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
   185
 * excess / transient data in-core during a crashdump.
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   186
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
void *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
zio_buf_alloc(size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5688
diff changeset
   194
	return (kmem_cache_alloc(zio_buf_cache[c], KM_PUSHPAGE));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   197
/*
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   198
 * 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
   199
 * 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
   200
 * 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
   201
 * of kernel heap dumped to disk when the kernel panics)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   202
 */
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   203
void *
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   204
zio_data_buf_alloc(size_t size)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   205
{
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   206
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   207
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   208
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   209
6245
1a2a7cfb9f26 6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents: 5688
diff changeset
   210
	return (kmem_cache_alloc(zio_data_buf_cache[c], KM_PUSHPAGE));
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   211
}
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   212
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
zio_buf_free(void *buf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
	kmem_cache_free(zio_buf_cache[c], buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   223
void
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   224
zio_data_buf_free(void *buf, size_t size)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   225
{
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   226
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   227
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   228
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   229
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   230
	kmem_cache_free(zio_data_buf_cache[c], buf);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   231
}
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   232
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
 * Push and pop I/O transform buffers
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
static void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   239
zio_push_transform(zio_t *zio, void *data, uint64_t size, uint64_t bufsize,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   240
	zio_transform_func_t *transform)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
	zio_transform_t *zt = kmem_alloc(sizeof (zio_transform_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   244
	zt->zt_orig_data = zio->io_data;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   245
	zt->zt_orig_size = zio->io_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	zt->zt_bufsize = bufsize;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   247
	zt->zt_transform = transform;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
	zt->zt_next = zio->io_transform_stack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
	zio->io_transform_stack = zt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	zio->io_data = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	zio->io_size = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
static void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   257
zio_pop_transforms(zio_t *zio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   259
	zio_transform_t *zt;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   261
	while ((zt = zio->io_transform_stack) != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   262
		if (zt->zt_transform != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   263
			zt->zt_transform(zio,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   264
			    zt->zt_orig_data, zt->zt_orig_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   266
		zio_buf_free(zio->io_data, zt->zt_bufsize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   268
		zio->io_data = zt->zt_orig_data;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   269
		zio->io_size = zt->zt_orig_size;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   270
		zio->io_transform_stack = zt->zt_next;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   272
		kmem_free(zt, sizeof (zio_transform_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
 * ==========================================================================
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   278
 * I/O transform callbacks for subblocks, decompression and decryption
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   279
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   280
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   281
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   282
zio_subblock(zio_t *zio, void *data, uint64_t size)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   283
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   284
	ASSERT(zio->io_size > size);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   285
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   286
	if (zio->io_type == ZIO_TYPE_READ)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   287
		bcopy(zio->io_data, data, size);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   288
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   289
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   290
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   291
zio_decompress(zio_t *zio, void *data, uint64_t size)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   292
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   293
	if (zio->io_error == 0 &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   294
	    zio_decompress_data(BP_GET_COMPRESS(zio->io_bp),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   295
	    zio->io_data, zio->io_size, data, size) != 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   296
		zio->io_error = EIO;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   297
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   298
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
   299
static void
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   300
zio_decrypt(zio_t *zio, void *data, uint64_t size)
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   301
{
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   302
	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
   303
	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
   304
	uint64_t bufsize;
13307
3d90d41b6103 1551 data decryption cross architecture fails in AES_CCM
Darren Moffat <darrenm@opensolaris.org>
parents: 13301
diff changeset
   305
	uint64_t mac[2];
13355
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   306
	int crypt_error = 0;
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   307
	boolean_t isdnode = B_FALSE;
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   308
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   309
	ASSERT3U(spa_version(zio->io_spa), >=, SPA_VERSION_CRYPTO);
13326
00ca5372f202 6719684 zfs destroy on clear text can cause panic
Darren Moffat <darrenm@opensolaris.org>
parents: 13323
diff changeset
   310
	ASSERT3U(crypt, !=, ZIO_CRYPT_OFF);
00ca5372f202 6719684 zfs destroy on clear text can cause panic
Darren Moffat <darrenm@opensolaris.org>
parents: 13323
diff changeset
   311
	ASSERT3U(crypt, !=, ZIO_CRYPT_INHERIT);
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   312
13371
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   313
	/*
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   314
	 * These asserts are a problem for ZVOLS, remove them for now
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   315
	 * but we should be able to assert at least the checksum case,
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   316
	 * even for ZVOL, is problem that they didn't go through
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   317
	 * the write_policy() call ?
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   318
	 *
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   319
	 * ASSERT3U(BP_GET_CHECKSUM(bp), ==, ZIO_CHECKSUM_SHA256_CCM_MAC);
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   320
	 * ASSERT3U(BP_GET_LEVEL(bp), ==, 0);
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   321
	 */
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   322
	
13355
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   323
	/* MAC is stored in the blkptr as the top two words of the checksum */
13308
b11402c5f64b 2207 scrub/resilver says pools have errors when key not present
Darren Moffat <darrenm@opensolaris.org>
parents: 13307
diff changeset
   324
	ASSERT3U(16, ==, zio_crypt_table[crypt].ci_maclen);
13307
3d90d41b6103 1551 data decryption cross architecture fails in AES_CCM
Darren Moffat <darrenm@opensolaris.org>
parents: 13301
diff changeset
   325
	mac[0] = BE_64(bp->blk_cksum.zc_word[2]);
3d90d41b6103 1551 data decryption cross architecture fails in AES_CCM
Darren Moffat <darrenm@opensolaris.org>
parents: 13301
diff changeset
   326
	mac[1] = BE_64(bp->blk_cksum.zc_word[3]);
13160
e8b02045519a 295 mac+checksum in zio_checksum_t (initial draft)
Darren Moffat <darrenm@opensolaris.org>
parents: 13158
diff changeset
   327
13347
90a127dff2c5 6719749 dnode dn_bonus needs to be encrypted
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13338
diff changeset
   328
	isdnode = (BP_GET_TYPE(bp) == DMU_OT_DNODE) && (BP_GET_LEVEL(bp) == 0);
90a127dff2c5 6719749 dnode dn_bonus needs to be encrypted
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13338
diff changeset
   329
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   330
	crypt_error = zio_decrypt_data(crypt, zio->io_spa,
13355
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   331
		    &zio->io_bookmark, bp->blk_birth, isdnode,
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   332
		    zio->io_data, zio->io_size, &mac, data, size);
13371
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   333
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   334
	/*
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   335
	 * 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
   336
	 * key material that the zboookmark_t says we needed,
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   337
	 * In that case we got EAGAIN so post an FMA event, we do this
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   338
	 * here so that we don't need to pass the full zio downwards into
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   339
	 * the crypto functions.
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   340
	 */ 
13355
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   341
	if (crypt_error != 0) {
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   342
		if (crypt_error == EAGAIN) {
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   343
			zfs_ereport_post(FM_EREPORT_ZFS_CRYPTO_KEY_UNAVAIL,
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   344
			    zio->io_spa, zio->io_vd, zio, 0, 0);
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   345
			/*
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   346
			 * If it is a dnode we were looking for we need the
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   347
			 * clear text parts to be passed on.
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   348
			 */
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   349
			if (isdnode) {
13371
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   350
				DTRACE_PROBE2(zio__ciphertext__dnode, 
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   351
				    blkptr_t *, bp, zbookmark_t *, 
45507bab8d65 6745678 zio->io_checksum == ZIO_CHECKSUM_SHA256_CCM_MAC (0x5 == 0x9), file: zio.c, line: 1498
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13369
diff changeset
   352
				    &zio->io_bookmark);
13355
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   353
				crypt_error = 0;
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   354
			}
03a8bd0e481a pass keys to zio_encrypt_date/zio_decrypt_data not the spa
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13347
diff changeset
   355
		}
13150
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   356
		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
   357
	}
4d89e6c6d8c8 Import ZFS Crypto Alpha+ bits into refesh repository due to Mecurial screwup.
Darren Moffat <darrenm@opensolaris.org>
parents: 5450
diff changeset
   358
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   359
	return;
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   360
}
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   361
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   362
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   363
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   364
 * I/O parent/child relationships and pipeline interlocks
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   365
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   366
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   367
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   368
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   369
zio_add_child(zio_t *pio, zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   370
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   371
	mutex_enter(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   372
	if (zio->io_stage < ZIO_STAGE_READY)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   373
		pio->io_children[zio->io_child_type][ZIO_WAIT_READY]++;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   374
	if (zio->io_stage < ZIO_STAGE_DONE)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   375
		pio->io_children[zio->io_child_type][ZIO_WAIT_DONE]++;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   376
	zio->io_sibling_prev = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   377
	zio->io_sibling_next = pio->io_child;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   378
	if (pio->io_child != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   379
		pio->io_child->io_sibling_prev = zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   380
	pio->io_child = zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   381
	zio->io_parent = pio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   382
	mutex_exit(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   383
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   384
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   385
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   386
zio_remove_child(zio_t *pio, zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   387
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   388
	zio_t *next, *prev;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   389
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   390
	ASSERT(zio->io_parent == pio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   391
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   392
	mutex_enter(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   393
	next = zio->io_sibling_next;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   394
	prev = zio->io_sibling_prev;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   395
	if (next != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   396
		next->io_sibling_prev = prev;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   397
	if (prev != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   398
		prev->io_sibling_next = next;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   399
	if (pio->io_child == zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   400
		pio->io_child = next;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   401
	mutex_exit(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   402
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   403
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   404
static boolean_t
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   405
zio_wait_for_children(zio_t *zio, enum zio_child child, enum zio_wait_type wait)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   406
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   407
	uint64_t *countp = &zio->io_children[child][wait];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   408
	boolean_t waiting = B_FALSE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   409
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   410
	mutex_enter(&zio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   411
	ASSERT(zio->io_stall == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   412
	if (*countp != 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   413
		zio->io_stage--;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   414
		zio->io_stall = countp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   415
		waiting = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   416
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   417
	mutex_exit(&zio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   418
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   419
	return (waiting);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   420
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   421
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   422
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   423
zio_notify_parent(zio_t *pio, zio_t *zio, enum zio_wait_type wait)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   424
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   425
	uint64_t *countp = &pio->io_children[zio->io_child_type][wait];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   426
	int *errorp = &pio->io_child_error[zio->io_child_type];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   427
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   428
	mutex_enter(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   429
	if (zio->io_error && !(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   430
		*errorp = zio_worst_error(*errorp, zio->io_error);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   431
	pio->io_reexecute |= zio->io_reexecute;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   432
	ASSERT3U(*countp, >, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   433
	if (--*countp == 0 && pio->io_stall == countp) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   434
		pio->io_stall = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   435
		mutex_exit(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   436
		zio_execute(pio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   437
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   438
		mutex_exit(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   439
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   440
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   441
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   442
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   443
zio_inherit_child_errors(zio_t *zio, enum zio_child c)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   444
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   445
	if (zio->io_child_error[c] != 0 && zio->io_error == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   446
		zio->io_error = zio->io_child_error[c];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   447
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   448
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   449
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   450
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   451
 * Create the various types of I/O (read, write, free, etc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
static zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
zio_create(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
    void *data, uint64_t size, zio_done_func_t *done, void *private,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   457
    zio_type_t type, int priority, int flags, vdev_t *vd, uint64_t offset,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   458
    const zbookmark_t *zb, uint8_t stage, uint32_t pipeline)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
	ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   464
	ASSERT(P2PHASE(offset, SPA_MINBLOCKSIZE) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   466
	ASSERT(!vd || spa_config_held(spa, SCL_STATE_ALL, RW_READER));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   467
	ASSERT(!bp || !(flags & ZIO_FLAG_CONFIG_WRITER));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   468
	ASSERT(vd || stage == ZIO_STAGE_OPEN);
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   469
4055
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   470
	zio = kmem_cache_alloc(zio_cache, KM_SLEEP);
9b8dd5af941d 6536445 want ::zio to show zio tree
eschrock
parents: 3882
diff changeset
   471
	bzero(zio, sizeof (zio_t));
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   472
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   473
	mutex_init(&zio->io_lock, NULL, MUTEX_DEFAULT, NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   474
	cv_init(&zio->io_cv, NULL, CV_DEFAULT, NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   475
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   476
	if (vd != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   477
		zio->io_child_type = ZIO_CHILD_VDEV;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   478
	else if (flags & ZIO_FLAG_GANG_CHILD)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   479
		zio->io_child_type = ZIO_CHILD_GANG;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   480
	else
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   481
		zio->io_child_type = ZIO_CHILD_LOGICAL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   482
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
	if (bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
		zio->io_bp = bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
		zio->io_bp_copy = *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
		zio->io_bp_orig = *bp;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   487
		if (type != ZIO_TYPE_WRITE)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   488
			zio->io_bp = &zio->io_bp_copy;	/* so caller can free */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   489
		if (zio->io_child_type == ZIO_CHILD_LOGICAL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   490
			if (BP_IS_GANG(bp))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   491
				pipeline |= ZIO_GANG_STAGES;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   492
			zio->io_logical = zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   493
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   495
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   496
	zio->io_spa = spa;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   497
	zio->io_txg = txg;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   498
	zio->io_data = data;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   499
	zio->io_size = size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	zio->io_done = done;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	zio->io_private = private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	zio->io_type = type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	zio->io_priority = priority;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   504
	zio->io_vd = vd;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   505
	zio->io_offset = offset;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   506
	zio->io_orig_flags = zio->io_flags = flags;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   507
	zio->io_orig_stage = zio->io_stage = stage;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   508
	zio->io_orig_pipeline = zio->io_pipeline = pipeline;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   509
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   510
	if (zb != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   511
		zio->io_bookmark = *zb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   513
	if (pio != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   514
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   515
		 * Logical I/Os can have logical, gang, or vdev children.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   516
		 * Gang I/Os can have gang or vdev children.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   517
		 * Vdev I/Os can only have vdev children.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   518
		 * The following ASSERT captures all of these constraints.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   519
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   520
		ASSERT(zio->io_child_type <= pio->io_child_type);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   521
		if (zio->io_logical == NULL)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   522
			zio->io_logical = pio->io_logical;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   523
		zio_add_child(pio, zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   529
static void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   530
zio_destroy(zio_t *zio)
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   531
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   532
	spa_t *spa = zio->io_spa;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   533
	uint8_t async_root = zio->io_async_root;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   534
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   535
	mutex_destroy(&zio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   536
	cv_destroy(&zio->io_cv);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   537
	kmem_cache_free(zio_cache, zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   538
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   539
	if (async_root) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   540
		mutex_enter(&spa->spa_async_root_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   541
		if (--spa->spa_async_root_count == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   542
			cv_broadcast(&spa->spa_async_root_cv);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   543
		mutex_exit(&spa->spa_async_root_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   544
	}
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   545
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   546
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
zio_null(zio_t *pio, spa_t *spa, zio_done_func_t *done, void *private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   554
	    ZIO_TYPE_NULL, ZIO_PRIORITY_NOW, flags, NULL, 0, NULL,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   555
	    ZIO_STAGE_OPEN, ZIO_INTERLOCK_PIPELINE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
zio_root(spa_t *spa, zio_done_func_t *done, void *private, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
	return (zio_null(NULL, spa, done, private, flags));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
zio_t *
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   567
zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   568
    void *data, uint64_t size, zio_done_func_t *done, void *private,
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   569
    int priority, int flags, const zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   573
	zio = zio_create(pio, spa, bp->blk_birth, (blkptr_t *)bp,
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   574
	    data, size, done, private,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   575
	    ZIO_TYPE_READ, priority, flags, NULL, 0, zb,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   576
	    ZIO_STAGE_OPEN, ZIO_READ_PIPELINE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
zio_t *
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   582
zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   583
    void *data, uint64_t size, zio_prop_t *zp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   584
    zio_done_func_t *ready, zio_done_func_t *done, void *private,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   585
    int priority, int flags, const zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   589
	ASSERT(zp->zp_checksum >= ZIO_CHECKSUM_OFF &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   590
	    zp->zp_checksum < ZIO_CHECKSUM_FUNCTIONS &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   591
	    zp->zp_compress >= ZIO_COMPRESS_OFF &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   592
	    zp->zp_compress < ZIO_COMPRESS_FUNCTIONS &&
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   593
	    zp->zp_crypt >= ZIO_CRYPT_OFF &&
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   594
	    zp->zp_crypt < ZIO_CRYPT_FUNCTIONS &&
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   595
	    zp->zp_type < DMU_OT_NUMTYPES &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   596
	    zp->zp_level < 32 &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   597
	    zp->zp_ndvas > 0 &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   598
	    zp->zp_ndvas <= spa_max_replication(spa));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   599
	ASSERT(ready != NULL);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   600
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   602
	    ZIO_TYPE_WRITE, priority, flags, NULL, 0, zb,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
	    ZIO_STAGE_OPEN, ZIO_WRITE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
3547
e396e0a440b1 6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents: 3463
diff changeset
   605
	zio->io_ready = ready;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   606
	zio->io_prop = *zp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
zio_t *
13395
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
   612
zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
   613
    void *data, uint64_t size, zio_prop_t *zp, zio_done_func_t *done,
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
   614
    void *private, int priority,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   615
    int flags, zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
7181
8d299641aa23 6719934 assertion failed: ((&zh->zh_log)->blk_birth == 0), file: ../../common/fs/zfs/zil.c, line: 1336
perrin
parents: 7046
diff changeset
   619
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   620
	    ZIO_TYPE_WRITE, priority, flags, NULL, 0, zb,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   621
	    ZIO_STAGE_OPEN, ZIO_REWRITE_PIPELINE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
13395
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
   623
	if (zp != NULL) {
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
   624
		zio->io_prop = *zp;
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
   625
	}
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
   626
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   632
    zio_done_func_t *done, void *private, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
	ASSERT(!BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   638
	if (bp->blk_fill == BLK_FILL_ALREADY_FREED)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   639
		return (zio_null(pio, spa, NULL, NULL, flags));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   640
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
	if (txg == spa->spa_syncing_txg &&
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   642
	    spa_sync_pass(spa) > SYNC_PASS_DEFERRED_FREE) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
		bplist_enqueue_deferred(&spa->spa_sync_bplist, bp);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   644
		return (zio_null(pio, spa, NULL, NULL, flags));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   647
	zio = zio_create(pio, spa, txg, bp, NULL, BP_GET_PSIZE(bp),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   648
	    done, private, ZIO_TYPE_FREE, ZIO_PRIORITY_FREE, flags,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   649
	    NULL, 0, NULL, ZIO_STAGE_OPEN, ZIO_FREE_PIPELINE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   656
    zio_done_func_t *done, void *private, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
	 * A claim is an allocation of a specific block.  Claims are needed
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
	 * to support immediate writes in the intent log.  The issue is that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
	 * immediate writes contain committed data, but in a txg that was
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	 * *not* committed.  Upon opening the pool after an unclean shutdown,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
	 * the intent log claims all blocks that contain immediate write data
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
	 * so that the SPA knows they're in use.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
	 * All claims *must* be resolved in the first txg -- before the SPA
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
	 * starts allocating blocks -- so that nothing is allocated twice.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
	ASSERT3U(spa->spa_uberblock.ub_rootbp.blk_birth, <, spa_first_txg(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
	ASSERT3U(spa_first_txg(spa), <=, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   674
	zio = zio_create(pio, spa, txg, bp, NULL, BP_GET_PSIZE(bp),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   675
	    done, private, ZIO_TYPE_CLAIM, ZIO_PRIORITY_NOW, flags,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   676
	    NULL, 0, NULL, ZIO_STAGE_OPEN, ZIO_CLAIM_PIPELINE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
    zio_done_func_t *done, void *private, int priority, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
	if (vd->vdev_children == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
		zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   690
		    ZIO_TYPE_IOCTL, priority, flags, vd, 0, NULL,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
		    ZIO_STAGE_OPEN, ZIO_IOCTL_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
		zio->io_cmd = cmd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
		zio = zio_null(pio, spa, NULL, NULL, flags);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
		for (c = 0; c < vd->vdev_children; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
			zio_nowait(zio_ioctl(zio, spa, vd->vdev_child[c], cmd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
			    done, private, priority, flags));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
    void *data, int checksum, zio_done_func_t *done, void *private,
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   708
    int priority, int flags, boolean_t labels)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
	zio_t *zio;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   711
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   712
	ASSERT(vd->vdev_children == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   713
	ASSERT(!labels || offset + size <= VDEV_LABEL_START_SIZE ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   714
	    offset >= vd->vdev_psize - VDEV_LABEL_END_SIZE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   715
	ASSERT3U(offset + size, <=, vd->vdev_psize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   717
	zio = zio_create(pio, vd->vdev_spa, 0, NULL, data, size, done, private,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   718
	    ZIO_TYPE_READ, priority, flags, vd, offset, NULL,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	    ZIO_STAGE_OPEN, ZIO_READ_PHYS_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   721
	zio->io_prop.zp_checksum = checksum;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
    void *data, int checksum, zio_done_func_t *done, void *private,
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5403
diff changeset
   729
    int priority, int flags, boolean_t labels)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   733
	ASSERT(vd->vdev_children == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   734
	ASSERT(!labels || offset + size <= VDEV_LABEL_START_SIZE ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   735
	    offset >= vd->vdev_psize - VDEV_LABEL_END_SIZE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   736
	ASSERT3U(offset + size, <=, vd->vdev_psize);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
   737
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   738
	zio = zio_create(pio, vd->vdev_spa, 0, NULL, data, size, done, private,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   739
	    ZIO_TYPE_WRITE, priority, flags, vd, offset, NULL,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   740
	    ZIO_STAGE_OPEN, ZIO_WRITE_PHYS_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   742
	zio->io_prop.zp_checksum = checksum;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
	if (zio_checksum_table[checksum].ci_zbt) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
		 * zbt checksums are necessarily destructive -- they modify
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   747
		 * the end of the write buffer to hold the verifier/checksum.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
		 * Therefore, we must make a local copy in case the data is
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   749
		 * being written to multiple places in parallel.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
		 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   751
		void *wbuf = zio_buf_alloc(size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
		bcopy(data, wbuf, size);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   753
		zio_push_transform(zio, wbuf, size, size, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   760
 * Create a child I/O to do some work for us.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
zio_t *
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   763
zio_vdev_child_io(zio_t *pio, blkptr_t *bp, vdev_t *vd, uint64_t offset,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	void *data, uint64_t size, int type, int priority, int flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
	zio_done_func_t *done, void *private)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
	uint32_t pipeline = ZIO_VDEV_CHILD_PIPELINE;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   768
	zio_t *zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   769
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   770
	ASSERT(vd->vdev_parent ==
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   771
	    (pio->io_vd ? pio->io_vd : pio->io_spa->spa_root_vdev));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	if (type == ZIO_TYPE_READ && bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
		 * If we have the bp, then the child should perform the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
		 * checksum and the parent need not.  This pushes error
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
		 * detection as close to the leaves as possible and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
		 * eliminates redundant checksums in the interior nodes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
		pipeline |= 1U << ZIO_STAGE_CHECKSUM_VERIFY;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   781
		pio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   782
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   783
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   784
	if (vd->vdev_children == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   785
		offset += VDEV_LABEL_START_SIZE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   786
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   787
	zio = zio_create(pio, pio->io_spa, pio->io_txg, bp, data, size,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   788
	    done, private, type, priority,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   789
	    (pio->io_flags & ZIO_FLAG_VDEV_INHERIT) |
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   790
	    ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_PROPAGATE | flags,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   791
	    vd, offset, &pio->io_bookmark,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   792
	    ZIO_STAGE_VDEV_IO_START - 1, pipeline);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   793
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   794
	return (zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   795
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   796
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   797
zio_t *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   798
zio_vdev_delegated_io(vdev_t *vd, uint64_t offset, void *data, uint64_t size,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   799
	int type, int priority, int flags, zio_done_func_t *done, void *private)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   800
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   801
	zio_t *zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   802
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   803
	ASSERT(vd->vdev_ops->vdev_op_leaf);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   804
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   805
	zio = zio_create(NULL, vd->vdev_spa, 0, NULL,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   806
	    data, size, done, private, type, priority,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   807
	    flags | ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_RETRY,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   808
	    vd, offset, NULL,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   809
	    ZIO_STAGE_VDEV_IO_START - 1, ZIO_VDEV_CHILD_PIPELINE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   810
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   811
	return (zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   812
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   813
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   814
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   815
zio_flush(zio_t *zio, vdev_t *vd)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   816
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   817
	zio_nowait(zio_ioctl(zio, zio->io_spa, vd, DKIOCFLUSHWRITECACHE,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   818
	    NULL, NULL, ZIO_PRIORITY_NOW,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   819
	    ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   820
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   821
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   822
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   823
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   824
 * Prepare to read and write logical blocks
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   825
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   826
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   827
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   828
static int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   829
zio_read_bp_init(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   830
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   831
	blkptr_t *bp = zio->io_bp;
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   832
	int crypt = BP_GET_CRYPT(bp);
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   833
	uint64_t csize = BP_GET_PSIZE(bp);
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   834
	void *cbuf;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   835
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   836
	/*
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   837
	 * XXX TO(re)DO
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   838
	 * Don't add crypto to the pipeline if this is a scrub/resilver
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   839
	 * because we don't need the actual data in that case and the
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   840
	 * decrypt could fail due to a lack of a key (in which case the
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   841
	 * datasets wouldn't be mounted but still need to be scrubbed).
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   842
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   843
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   844
	if ((spa_version(zio->io_spa) >= SPA_VERSION_CRYPTO) &&
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   845
	    (crypt != ZIO_CRYPT_OFF && crypt != ZIO_CRYPT_INHERIT)) {
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   846
		cbuf = zio_buf_alloc(csize);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   847
		zio_push_transform(zio, cbuf, csize, csize,
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   848
		    zio_decrypt);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   849
	}
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   850
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   851
	if (zio->io_logical == zio) {
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   852
		if (BP_GET_COMPRESS(bp) != ZIO_COMPRESS_OFF) {
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   853
			cbuf = zio_buf_alloc(csize);
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   854
			zio_push_transform(zio, cbuf, csize, csize,
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   855
			    zio_decompress);
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   856
		}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   857
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   858
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   859
	if (!dmu_ot[BP_GET_TYPE(bp)].ot_metadata && BP_GET_LEVEL(bp) == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   860
		zio->io_flags |= ZIO_FLAG_DONT_CACHE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   861
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   862
	return (ZIO_PIPELINE_CONTINUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   863
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   864
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   865
static int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   866
zio_write_bp_init(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   867
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   868
	zio_prop_t *zp = &zio->io_prop;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   869
	int compress = zp->zp_compress;
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   870
	int crypt = zp->zp_crypt;
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   871
	int checksum = zp->zp_checksum;
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   872
	int type = zp->zp_type;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   873
	blkptr_t *bp = zio->io_bp;
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   874
	void *cbuf, *encbuf;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   875
	uint64_t lsize = zio->io_size;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   876
	uint64_t csize = lsize;
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   877
	uint64_t cbufsize = 0, encbufsize = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   878
	int pass = 1;
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   879
	zio_cksum_t *mac = NULL;
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   880
	size_t maclen = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   881
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   882
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   883
	 * If our children haven't all reached the ready stage,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   884
	 * wait for them and then repeat this pipeline stage.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   885
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   886
	if (zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_READY) ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   887
	    zio_wait_for_children(zio, ZIO_CHILD_LOGICAL, ZIO_WAIT_READY))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   888
		return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   889
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   890
	if (!IO_IS_ALLOCATING(zio) && (type != DMU_OT_INTENT_LOG)) {
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   891
		return (ZIO_PIPELINE_CONTINUE);
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   892
	}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   893
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   894
	ASSERT(compress != ZIO_COMPRESS_INHERIT);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   895
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   896
	if (bp->blk_birth == zio->io_txg) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   897
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   898
		 * We're rewriting an existing block, which means we're
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   899
		 * working on behalf of spa_sync().  For spa_sync() to
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   900
		 * converge, it must eventually be the case that we don't
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   901
		 * have to allocate new blocks.  But compression changes
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   902
		 * the blocksize, which forces a reallocate, and makes
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   903
		 * convergence take longer.  Therefore, after the first
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   904
		 * few passes, stop compressing to ensure convergence.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   905
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   906
		pass = spa_sync_pass(zio->io_spa);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   907
		ASSERT(pass > 1);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   908
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   909
		if (pass > SYNC_PASS_DONT_COMPRESS)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   910
			compress = ZIO_COMPRESS_OFF;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   911
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   912
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   913
		 * Only MOS (objset 0) data should need to be rewritten.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   914
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   915
		ASSERT(zio->io_logical->io_bookmark.zb_objset == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   916
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   917
		/* Make sure someone doesn't change their mind on overwrites */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   918
		ASSERT(MIN(zp->zp_ndvas + BP_IS_GANG(bp),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   919
		    spa_max_replication(zio->io_spa)) == BP_GET_NDVAS(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   920
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   921
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   922
	if (compress != ZIO_COMPRESS_OFF) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   923
		if (!zio_compress_data(compress, zio->io_data, zio->io_size,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   924
		    &cbuf, &csize, &cbufsize)) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   925
			compress = ZIO_COMPRESS_OFF;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   926
		} else if (csize != 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   927
			zio_push_transform(zio, cbuf, csize, cbufsize, NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   928
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   931
	if (spa_version(zio->io_spa) >= SPA_VERSION_CRYPTO &&
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   932
	    crypt != ZIO_CRYPT_OFF) {
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   933
		int crypt_error;
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   934
		boolean_t isdnode = (type == DMU_OT_DNODE);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   935
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   936
		ASSERT(crypt != ZIO_CRYPT_INHERIT);
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   937
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   938
		if (isdnode && (zio->io_bookmark.zb_blkid == 0 ||
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   939
		    zio->io_bookmark.zb_level != 0)) {
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   940
			/* Meta dnode ? Something special about this dnode ? */
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   941
			crypt = ZIO_CRYPT_OFF;
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   942
			goto crypt_done;
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   943
		}
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   944
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   945
		crypt_error = zio_encrypt_data(crypt, zio->io_spa,
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   946
		    &zio->io_bookmark, zio->io_txg, isdnode,
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   947
		    zio->io_data, zio->io_size,
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   948
		    &encbuf, &encbufsize, (void **)&mac);
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   949
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   950
		if (crypt_error != 0) {
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   951
			if (crypt_error == EAGAIN) {
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   952
				/*
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   953
				 * If we don't have access to the key material
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   954
				 * that the * zboookmark_t says we needed,
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   955
				 * post an FMA event.
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   956
				 */ 
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   957
				zfs_ereport_post(
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   958
				    FM_EREPORT_ZFS_CRYPTO_KEY_UNAVAIL,
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   959
				    zio->io_spa, zio->io_vd, zio, 0, 0);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   960
			}
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   961
			zio->io_error = crypt_error;
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   962
			return (ZIO_PIPELINE_STOP);
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   963
		}
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   964
		ASSERT3U(checksum, ==, ZIO_CHECKSUM_SHA256_CCM_MAC);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   965
		zio_push_transform(zio, encbuf, zio->io_size, encbufsize, NULL);
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   966
	}
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   967
crypt_done:
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
   968
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   969
	/*
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   970
	 * If we aren't encrypting make sure the checksum isn't the 
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   971
	 * truncated SHA256+MAC variant - force to SHA256 instead.
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   972
	 */
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   973
	if (checksum == ZIO_CHECKSUM_SHA256_CCM_MAC &&
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   974
	    (crypt == ZIO_CRYPT_OFF || crypt == ZIO_CRYPT_INHERIT)) {
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   975
		ASSERT3U(spa_version(zio->io_spa), >=, SPA_VERSION_CRYPTO);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   976
		checksum = ZIO_CHECKSUM_SHA256;
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   977
	}
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   978
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   979
	if (type == DMU_OT_INTENT_LOG)
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   980
		return (ZIO_PIPELINE_CONTINUE);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   981
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
   982
	/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   983
	 * The final pass of spa_sync() must be all rewrites, but the first
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   984
	 * few passes offer a trade-off: allocating blocks defers convergence,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   985
	 * but newly allocated blocks are sequential, so they can be written
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   986
	 * to disk faster.  Therefore, we allow the first few passes of
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   987
	 * spa_sync() to allocate new blocks, but force rewrites after that.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   988
	 * There should only be a handful of blocks after pass 1 in any case.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   989
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   990
	if (bp->blk_birth == zio->io_txg && BP_GET_PSIZE(bp) == csize &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   991
	    pass > SYNC_PASS_REWRITE) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   992
		ASSERT(csize != 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   993
		uint32_t gang_stages = zio->io_pipeline & ZIO_GANG_STAGES;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   994
		zio->io_pipeline = ZIO_REWRITE_PIPELINE | gang_stages;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   995
		zio->io_flags |= ZIO_FLAG_IO_REWRITE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   996
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   997
		BP_ZERO(bp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   998
		zio->io_pipeline = ZIO_WRITE_PIPELINE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
   999
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1000
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1001
	if (csize == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1002
		zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1003
	} else {
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1004
		ASSERT(checksum != ZIO_CHECKSUM_GANG_HEADER);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1005
		BP_SET_LSIZE(bp, lsize);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1006
		BP_SET_PSIZE(bp, csize);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1007
		BP_SET_COMPRESS(bp, compress);
13391
7f510a75f086 merge onnv-gate onnv_100 - MAJOR rewrite of zio.c encryption support due to 6754011 and friends
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13385 7754
diff changeset
  1008
		BP_SET_CRYPT(bp, crypt);
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1009
		BP_SET_CHECKSUM(bp, checksum);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1010
		BP_SET_TYPE(bp, zp->zp_type);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1011
		BP_SET_LEVEL(bp, zp->zp_level);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1012
		BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1013
		if (mac != NULL) {
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1014
			/*
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1015
			 * The mac is stored in the blkptr as the top two 
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1016
			 * words of the checksum, in bigendian form 
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1017
			 * (same as the checksum).
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1018
			 *
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1019
			 * Currently all MAC's are 16 bytes and all
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1020
			 * crypto "on" values use a MAC.  If an encryption
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1021
			 * mode is added that doesn't have a MAC or has a MAC 
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1022
			 * of a different size this needs updating.
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1023
			 */
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1024
			maclen = zio_crypt_table[crypt].ci_maclen;
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1025
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1026
			ASSERT3U(maclen, ==, 16);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1027
			ASSERT3U(checksum, ==, ZIO_CHECKSUM_SHA256_CCM_MAC);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1028
			ASSERT3U(crypt, >, ZIO_CRYPT_INHERIT);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1029
			ASSERT3U(crypt, <=, ZIO_CRYPT_FUNCTIONS);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1030
			ASSERT3U(crypt, !=, ZIO_CRYPT_OFF);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1031
			ASSERT3U(spa_version(zio->io_spa), >=,
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1032
			    SPA_VERSION_CRYPTO);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1033
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1034
			bp->blk_cksum.zc_word[2] = BE_64(mac->zc_word[0]);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1035
			bp->blk_cksum.zc_word[3] = BE_64(mac->zc_word[1]);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1036
			kmem_free(mac, maclen);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1037
		} else {
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1038
			ASSERT3U(checksum, !=, ZIO_CHECKSUM_SHA256_CCM_MAC);
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1039
		}
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1040
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1041
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1042
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1043
	return (ZIO_PIPELINE_CONTINUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1044
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1045
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1046
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1047
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1048
 * Execute the I/O pipeline
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1049
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1050
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1051
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1052
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1053
zio_taskq_dispatch(zio_t *zio, enum zio_taskq_type q)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1054
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1055
	zio_type_t t = zio->io_type;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1056
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1057
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1058
	 * If we're a config writer, the normal issue and interrupt threads
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1059
	 * may all be blocked waiting for the config lock.  In this case,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1060
	 * select the otherwise-unused taskq for ZIO_TYPE_NULL.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1061
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1062
	if (zio->io_flags & ZIO_FLAG_CONFIG_WRITER)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1063
		t = ZIO_TYPE_NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1064
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1065
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1066
	 * A similar issue exists for the L2ARC write thread until L2ARC 2.0.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1067
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1068
	if (t == ZIO_TYPE_WRITE && zio->io_vd && zio->io_vd->vdev_aux)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1069
		t = ZIO_TYPE_NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1070
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1071
	(void) taskq_dispatch(zio->io_spa->spa_zio_taskq[t][q],
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1072
	    (task_func_t *)zio_execute, zio, TQ_SLEEP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1073
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1074
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1075
static boolean_t
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1076
zio_taskq_member(zio_t *zio, enum zio_taskq_type q)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1077
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1078
	kthread_t *executor = zio->io_executor;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1079
	spa_t *spa = zio->io_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1081
	for (zio_type_t t = 0; t < ZIO_TYPES; t++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1082
		if (taskq_member(spa->spa_zio_taskq[t][q], executor))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1083
			return (B_TRUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1084
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1085
	return (B_FALSE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1086
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1087
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1088
static int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1089
zio_issue_async(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1090
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1091
	zio_taskq_dispatch(zio, ZIO_TASKQ_ISSUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1092
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1093
	return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1094
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1095
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1096
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1097
zio_interrupt(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1098
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1099
	zio_taskq_dispatch(zio, ZIO_TASKQ_INTERRUPT);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1100
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1101
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1102
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1103
 * Execute the I/O pipeline until one of the following occurs:
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1104
 * (1) the I/O completes; (2) the pipeline stalls waiting for
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1105
 * dependent child I/Os; (3) the I/O issues, so we're waiting
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1106
 * for an I/O completion interrupt; (4) the I/O is delegated by
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1107
 * vdev-level caching or aggregation; (5) the I/O is deferred
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1108
 * due to vdev-level queueing; (6) the I/O is handed off to
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1109
 * another thread.  In all cases, the pipeline stops whenever
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1110
 * there's no CPU work; it never burns a thread in cv_wait().
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1111
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1112
 * There's no locking on io_stage because there's no legitimate way
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1113
 * for multiple threads to be attempting to process the same I/O.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1114
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1115
static zio_pipe_stage_t *zio_pipeline[ZIO_STAGES];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1117
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1118
zio_execute(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1119
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1120
	zio->io_executor = curthread;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1121
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1122
	while (zio->io_stage < ZIO_STAGE_DONE) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1123
		uint32_t pipeline = zio->io_pipeline;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1124
		zio_stage_t stage = zio->io_stage;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1125
		int rv;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1126
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1127
		ASSERT(!MUTEX_HELD(&zio->io_lock));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1128
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1129
		while (((1U << ++stage) & pipeline) == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1130
			continue;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1131
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1132
		ASSERT(stage <= ZIO_STAGE_DONE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1133
		ASSERT(zio->io_stall == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1134
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1135
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1136
		 * If we are in interrupt context and this pipeline stage
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1137
		 * will grab a config lock that is held across I/O,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1138
		 * issue async to avoid deadlock.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1139
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1140
		if (((1U << stage) & ZIO_CONFIG_LOCK_BLOCKING_STAGES) &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1141
		    zio->io_vd == NULL &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1142
		    zio_taskq_member(zio, ZIO_TASKQ_INTERRUPT)) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1143
			zio_taskq_dispatch(zio, ZIO_TASKQ_ISSUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1144
			return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1145
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1146
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1147
		zio->io_stage = stage;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1148
		rv = zio_pipeline[stage](zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1149
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1150
		if (rv == ZIO_PIPELINE_STOP)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1151
			return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1152
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1153
		ASSERT(rv == ZIO_PIPELINE_CONTINUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1154
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
 * Initiate I/O, either sync or async
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
zio_wait(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
	ASSERT(zio->io_stage == ZIO_STAGE_OPEN);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1168
	ASSERT(zio->io_executor == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
	zio->io_waiter = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1172
	zio_execute(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
	mutex_enter(&zio->io_lock);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1175
	while (zio->io_executor != NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
		cv_wait(&zio->io_cv, &zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
	mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
	error = zio->io_error;
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1180
	zio_destroy(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
zio_nowait(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1188
	ASSERT(zio->io_executor == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1189
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1190
	if (zio->io_parent == NULL && zio->io_child_type == ZIO_CHILD_LOGICAL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1191
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1192
		 * This is a logical async I/O with no parent to wait for it.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1193
		 * Attach it to the pool's global async root zio so that
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1194
		 * spa_unload() has a way of waiting for async I/O to finish.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1195
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1196
		spa_t *spa = zio->io_spa;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1197
		zio->io_async_root = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1198
		mutex_enter(&spa->spa_async_root_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1199
		spa->spa_async_root_count++;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1200
		mutex_exit(&spa->spa_async_root_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1201
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1202
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1203
	zio_execute(zio);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1204
}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1205
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1206
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1207
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1208
 * Reexecute or suspend/resume failed I/O
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1209
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1210
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1211
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1212
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1213
zio_reexecute(zio_t *pio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1214
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1215
	zio_t *zio, *zio_next;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1216
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1217
	pio->io_flags = pio->io_orig_flags;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1218
	pio->io_stage = pio->io_orig_stage;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1219
	pio->io_pipeline = pio->io_orig_pipeline;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1220
	pio->io_reexecute = 0;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1221
	pio->io_error = 0;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1222
	for (int c = 0; c < ZIO_CHILD_TYPES; c++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1223
		pio->io_child_error[c] = 0;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1224
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1225
	if (IO_IS_ALLOCATING(pio)) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1226
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1227
		 * Remember the failed bp so that the io_ready() callback
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1228
		 * can update its accounting upon reexecution.  The block
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1229
		 * was already freed in zio_done(); we indicate this with
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1230
		 * a fill count of -1 so that zio_free() knows to skip it.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1231
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1232
		blkptr_t *bp = pio->io_bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1233
		ASSERT(bp->blk_birth == 0 || bp->blk_birth == pio->io_txg);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1234
		bp->blk_fill = BLK_FILL_ALREADY_FREED;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1235
		pio->io_bp_orig = *bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1236
		BP_ZERO(bp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1237
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1238
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1239
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1240
	 * As we reexecute pio's children, new children could be created.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1241
	 * New children go to the head of the io_child list, however,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1242
	 * so we will (correctly) not reexecute them.  The key is that
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1243
	 * the remainder of the io_child list, from 'zio_next' onward,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1244
	 * cannot be affected by any side effects of reexecuting 'zio'.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1245
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1246
	for (zio = pio->io_child; zio != NULL; zio = zio_next) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1247
		zio_next = zio->io_sibling_next;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1248
		mutex_enter(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1249
		pio->io_children[zio->io_child_type][ZIO_WAIT_READY]++;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1250
		pio->io_children[zio->io_child_type][ZIO_WAIT_DONE]++;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1251
		mutex_exit(&pio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1252
		zio_reexecute(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1253
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1254
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1255
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1256
	 * Now that all children have been reexecuted, execute the parent.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1257
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1258
	zio_execute(pio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1259
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1260
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1261
void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1262
zio_suspend(spa_t *spa, zio_t *zio)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1263
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1264
	if (spa_get_failmode(spa) == ZIO_FAILURE_MODE_PANIC)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1265
		fm_panic("Pool '%s' has encountered an uncorrectable I/O "
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1266
		    "failure and the failure mode property for this pool "
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1267
		    "is set to panic.", spa_name(spa));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1268
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1269
	zfs_ereport_post(FM_EREPORT_ZFS_IO_FAILURE, spa, NULL, NULL, 0, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1270
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1271
	mutex_enter(&spa->spa_suspend_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1272
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1273
	if (spa->spa_suspend_zio_root == NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1274
		spa->spa_suspend_zio_root = zio_root(spa, NULL, NULL, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1275
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1276
	spa->spa_suspended = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1277
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1278
	if (zio != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1279
		ASSERT(zio != spa->spa_suspend_zio_root);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1280
		ASSERT(zio->io_child_type == ZIO_CHILD_LOGICAL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1281
		ASSERT(zio->io_parent == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1282
		ASSERT(zio->io_stage == ZIO_STAGE_DONE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1283
		zio_add_child(spa->spa_suspend_zio_root, zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1284
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1285
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1286
	mutex_exit(&spa->spa_suspend_lock);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1287
}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1288
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1289
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1290
zio_resume(spa_t *spa)
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1291
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1292
	zio_t *pio, *zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1293
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1294
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1295
	 * Reexecute all previously suspended i/o.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1296
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1297
	mutex_enter(&spa->spa_suspend_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1298
	spa->spa_suspended = B_FALSE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1299
	cv_broadcast(&spa->spa_suspend_cv);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1300
	pio = spa->spa_suspend_zio_root;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1301
	spa->spa_suspend_zio_root = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1302
	mutex_exit(&spa->spa_suspend_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1303
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1304
	if (pio == NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1305
		return;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1306
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1307
	while ((zio = pio->io_child) != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1308
		zio_remove_child(pio, zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1309
		zio->io_parent = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1310
		zio_reexecute(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1311
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1312
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1313
	ASSERT(pio->io_children[ZIO_CHILD_LOGICAL][ZIO_WAIT_DONE] == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1314
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1315
	(void) zio_wait(pio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1316
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1317
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1318
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1319
zio_resume_wait(spa_t *spa)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1320
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1321
	mutex_enter(&spa->spa_suspend_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1322
	while (spa_suspended(spa))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1323
		cv_wait(&spa->spa_suspend_cv, &spa->spa_suspend_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1324
	mutex_exit(&spa->spa_suspend_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
 * ==========================================================================
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1329
 * Gang blocks.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1330
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1331
 * A gang block is a collection of small blocks that looks to the DMU
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1332
 * like one large block.  When zio_dva_allocate() cannot find a block
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1333
 * of the requested size, due to either severe fragmentation or the pool
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1334
 * being nearly full, it calls zio_write_gang_block() to construct the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1335
 * block from smaller fragments.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1336
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1337
 * A gang block consists of a gang header (zio_gbh_phys_t) and up to
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1338
 * three (SPA_GBH_NBLKPTRS) gang members.  The gang header is just like
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1339
 * an indirect block: it's an array of block pointers.  It consumes
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1340
 * only one sector and hence is allocatable regardless of fragmentation.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1341
 * The gang header's bps point to its gang members, which hold the data.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1342
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1343
 * Gang blocks are self-checksumming, using the bp's <vdev, offset, txg>
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1344
 * as the verifier to ensure uniqueness of the SHA256 checksum.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1345
 * Critically, the gang block bp's blk_cksum is the checksum of the data,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1346
 * not the gang header.  This ensures that data block signatures (needed for
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1347
 * deduplication) are independent of how the block is physically stored.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1348
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1349
 * Gang blocks can be nested: a gang member may itself be a gang block.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1350
 * Thus every gang block is a tree in which root and all interior nodes are
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1351
 * gang headers, and the leaves are normal blocks that contain user data.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1352
 * The root of the gang tree is called the gang leader.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1353
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1354
 * To perform any operation (read, rewrite, free, claim) on a gang block,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1355
 * zio_gang_assemble() first assembles the gang tree (minus data leaves)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1356
 * in the io_gang_tree field of the original logical i/o by recursively
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1357
 * reading the gang leader and all gang headers below it.  This yields
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1358
 * an in-core tree containing the contents of every gang header and the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1359
 * bps for every constituent of the gang block.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1360
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1361
 * With the gang tree now assembled, zio_gang_issue() just walks the gang tree
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1362
 * and invokes a callback on each bp.  To free a gang block, zio_gang_issue()
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1363
 * calls zio_free_gang() -- a trivial wrapper around zio_free() -- for each bp.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1364
 * zio_claim_gang() provides a similarly trivial wrapper for zio_claim().
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1365
 * zio_read_gang() is a wrapper around zio_read() that omits reading gang
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1366
 * headers, since we already have those in io_gang_tree.  zio_rewrite_gang()
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1367
 * performs a zio_rewrite() of the data or, for gang headers, a zio_rewrite()
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1368
 * of the gang header plus zio_checksum_compute() of the data to update the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1369
 * gang header's blk_cksum as described above.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1370
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1371
 * The two-phase assemble/issue model solves the problem of partial failure --
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1372
 * what if you'd freed part of a gang block but then couldn't read the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1373
 * gang header for another part?  Assembling the entire gang tree first
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1374
 * ensures that all the necessary gang header I/O has succeeded before
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1375
 * starting the actual work of free, claim, or write.  Once the gang tree
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1376
 * is assembled, free and claim are in-memory operations that cannot fail.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1377
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1378
 * In the event that a gang write fails, zio_dva_unallocate() walks the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1379
 * gang tree to immediately free (i.e. insert back into the space map)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1380
 * everything we've allocated.  This ensures that we don't get ENOSPC
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1381
 * errors during repeated suspend/resume cycles due to a flaky device.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1382
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1383
 * Gang rewrites only happen during sync-to-convergence.  If we can't assemble
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1384
 * the gang tree, we won't modify the block, so we can safely defer the free
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1385
 * (knowing that the block is still intact).  If we *can* assemble the gang
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1386
 * tree, then even if some of the rewrites fail, zio_dva_unallocate() will free
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1387
 * each constituent bp and we can allocate a new block on the next sync pass.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1388
 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1389
 * In all cases, the gang tree allows complete recovery from partial failure.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1392
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1393
static zio_t *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1394
zio_read_gang(zio_t *pio, blkptr_t *bp, zio_gang_node_t *gn, void *data)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1395
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1396
	if (gn != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1397
		return (pio);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1398
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1399
	return (zio_read(pio, pio->io_spa, bp, data, BP_GET_PSIZE(bp),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1400
	    NULL, NULL, pio->io_priority, ZIO_GANG_CHILD_FLAGS(pio),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1401
	    &pio->io_bookmark));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1404
zio_t *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1405
zio_rewrite_gang(zio_t *pio, blkptr_t *bp, zio_gang_node_t *gn, void *data)
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1406
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1407
	zio_t *zio;
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1408
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1409
	if (gn != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1410
		zio = zio_rewrite(pio, pio->io_spa, pio->io_txg, bp,
13395
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1411
		    gn->gn_gbh, SPA_GANGBLOCKSIZE, NULL, NULL, NULL,
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1412
		    pio->io_priority, ZIO_GANG_CHILD_FLAGS(pio),
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1413
		    &pio->io_bookmark);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1414
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1415
		 * As we rewrite each gang header, the pipeline will compute
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1416
		 * a new gang block header checksum for it; but no one will
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1417
		 * compute a new data checksum, so we do that here.  The one
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1418
		 * exception is the gang leader: the pipeline already computed
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1419
		 * its data checksum because that stage precedes gang assembly.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1420
		 * (Presently, nothing actually uses interior data checksums;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1421
		 * this is just good hygiene.)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1422
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1423
		if (gn != pio->io_logical->io_gang_tree) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1424
			zio_checksum_compute(zio, BP_GET_CHECKSUM(bp),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1425
			    data, BP_GET_PSIZE(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1426
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1427
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1428
		zio = zio_rewrite(pio, pio->io_spa, pio->io_txg, bp,
13395
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1429
		    data, BP_GET_PSIZE(bp), NULL, NULL, NULL, pio->io_priority,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1430
		    ZIO_GANG_CHILD_FLAGS(pio), &pio->io_bookmark);
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1431
	}
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1432
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1433
	return (zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1434
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1435
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1436
/* ARGSUSED */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1437
zio_t *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1438
zio_free_gang(zio_t *pio, blkptr_t *bp, zio_gang_node_t *gn, void *data)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1439
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1440
	return (zio_free(pio, pio->io_spa, pio->io_txg, bp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1441
	    NULL, NULL, ZIO_GANG_CHILD_FLAGS(pio)));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1442
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1443
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1444
/* ARGSUSED */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1445
zio_t *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1446
zio_claim_gang(zio_t *pio, blkptr_t *bp, zio_gang_node_t *gn, void *data)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1447
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1448
	return (zio_claim(pio, pio->io_spa, pio->io_txg, bp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1449
	    NULL, NULL, ZIO_GANG_CHILD_FLAGS(pio)));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1450
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1451
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1452
static zio_gang_issue_func_t *zio_gang_issue_func[ZIO_TYPES] = {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1453
	NULL,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1454
	zio_read_gang,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1455
	zio_rewrite_gang,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1456
	zio_free_gang,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1457
	zio_claim_gang,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1458
	NULL
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1459
};
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1460
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1461
static void zio_gang_tree_assemble_done(zio_t *zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1462
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1463
static zio_gang_node_t *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1464
zio_gang_node_alloc(zio_gang_node_t **gnpp)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1465
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1466
	zio_gang_node_t *gn;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1467
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1468
	ASSERT(*gnpp == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1469
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1470
	gn = kmem_zalloc(sizeof (*gn), KM_SLEEP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1471
	gn->gn_gbh = zio_buf_alloc(SPA_GANGBLOCKSIZE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1472
	*gnpp = gn;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1473
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1474
	return (gn);
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1475
}
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1476
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1477
static void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1478
zio_gang_node_free(zio_gang_node_t **gnpp)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1479
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1480
	zio_gang_node_t *gn = *gnpp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1481
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1482
	for (int g = 0; g < SPA_GBH_NBLKPTRS; g++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1483
		ASSERT(gn->gn_child[g] == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1484
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1485
	zio_buf_free(gn->gn_gbh, SPA_GANGBLOCKSIZE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1486
	kmem_free(gn, sizeof (*gn));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1487
	*gnpp = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1488
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1489
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
 * Gang block support
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1495
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1496
zio_gang_tree_free(zio_gang_node_t **gnpp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1498
	zio_gang_node_t *gn = *gnpp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1499
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1500
	if (gn == NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1501
		return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1502
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1503
	for (int g = 0; g < SPA_GBH_NBLKPTRS; g++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1504
		zio_gang_tree_free(&gn->gn_child[g]);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1505
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1506
	zio_gang_node_free(gnpp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1507
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1508
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1509
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1510
zio_gang_tree_assemble(zio_t *lio, blkptr_t *bp, zio_gang_node_t **gnpp)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1511
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1512
	zio_gang_node_t *gn = zio_gang_node_alloc(gnpp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1514
	ASSERT(lio->io_logical == lio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1515
	ASSERT(BP_IS_GANG(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1516
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1517
	zio_nowait(zio_read(lio, lio->io_spa, bp, gn->gn_gbh,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1518
	    SPA_GANGBLOCKSIZE, zio_gang_tree_assemble_done, gn,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1519
	    lio->io_priority, ZIO_GANG_CHILD_FLAGS(lio), &lio->io_bookmark));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1520
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1521
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1522
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1523
zio_gang_tree_assemble_done(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1524
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1525
	zio_t *lio = zio->io_logical;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1526
	zio_gang_node_t *gn = zio->io_private;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1527
	blkptr_t *bp = zio->io_bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1528
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1529
	ASSERT(zio->io_parent == lio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1530
	ASSERT(zio->io_child == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1531
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1532
	if (zio->io_error)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1533
		return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1534
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1535
	if (BP_SHOULD_BYTESWAP(bp))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1536
		byteswap_uint64_array(zio->io_data, zio->io_size);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1537
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1538
	ASSERT(zio->io_data == gn->gn_gbh);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1539
	ASSERT(zio->io_size == SPA_GANGBLOCKSIZE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1540
	ASSERT(gn->gn_gbh->zg_tail.zbt_magic == ZBT_MAGIC);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1541
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1542
	for (int g = 0; g < SPA_GBH_NBLKPTRS; g++) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1543
		blkptr_t *gbp = &gn->gn_gbh->zg_blkptr[g];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1544
		if (!BP_IS_GANG(gbp))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1545
			continue;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1546
		zio_gang_tree_assemble(lio, gbp, &gn->gn_child[g]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1550
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1551
zio_gang_tree_issue(zio_t *pio, zio_gang_node_t *gn, blkptr_t *bp, void *data)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1552
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1553
	zio_t *lio = pio->io_logical;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1554
	zio_t *zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1555
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1556
	ASSERT(BP_IS_GANG(bp) == !!gn);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1557
	ASSERT(BP_GET_CHECKSUM(bp) == BP_GET_CHECKSUM(lio->io_bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1558
	ASSERT(BP_GET_LSIZE(bp) == BP_GET_PSIZE(bp) || gn == lio->io_gang_tree);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1559
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1560
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1561
	 * If you're a gang header, your data is in gn->gn_gbh.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1562
	 * If you're a gang member, your data is in 'data' and gn == NULL.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1563
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1564
	zio = zio_gang_issue_func[lio->io_type](pio, bp, gn, data);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1566
	if (gn != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1567
		ASSERT(gn->gn_gbh->zg_tail.zbt_magic == ZBT_MAGIC);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1568
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1569
		for (int g = 0; g < SPA_GBH_NBLKPTRS; g++) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1570
			blkptr_t *gbp = &gn->gn_gbh->zg_blkptr[g];
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1571
			if (BP_IS_HOLE(gbp))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1572
				continue;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1573
			zio_gang_tree_issue(zio, gn->gn_child[g], gbp, data);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1574
			data = (char *)data + BP_GET_PSIZE(gbp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1575
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1576
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1577
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1578
	if (gn == lio->io_gang_tree)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1579
		ASSERT3P((char *)lio->io_data + lio->io_size, ==, data);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1580
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1581
	if (zio != pio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1582
		zio_nowait(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1585
static int
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1586
zio_gang_assemble(zio_t *zio)
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1587
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1588
	blkptr_t *bp = zio->io_bp;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1589
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1590
	ASSERT(BP_IS_GANG(bp) && zio == zio->io_logical);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1591
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1592
	zio_gang_tree_assemble(zio, bp, &zio->io_gang_tree);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1594
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1597
static int
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1598
zio_gang_issue(zio_t *zio)
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1599
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1600
	zio_t *lio = zio->io_logical;
6523
c1d2a7f04573 6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents: 6245
diff changeset
  1601
	blkptr_t *bp = zio->io_bp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1603
	if (zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_DONE))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1604
		return (ZIO_PIPELINE_STOP);
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1605
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1606
	ASSERT(BP_IS_GANG(bp) && zio == lio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1608
	if (zio->io_child_error[ZIO_CHILD_GANG] == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1609
		zio_gang_tree_issue(lio, lio->io_gang_tree, bp, lio->io_data);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1610
	else
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1611
		zio_gang_tree_free(&lio->io_gang_tree);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1613
	zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1614
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1615
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
static void
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1619
zio_write_gang_member_ready(zio_t *zio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
	zio_t *pio = zio->io_parent;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1622
	zio_t *lio = zio->io_logical;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1623
	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
  1624
	dva_t *pdva = pio->io_bp->blk_dva;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1625
	uint64_t asize;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1626
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1627
	if (BP_IS_HOLE(zio->io_bp))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1628
		return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1629
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1630
	ASSERT(BP_IS_HOLE(&zio->io_bp_orig));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1632
	ASSERT(zio->io_child_type == ZIO_CHILD_GANG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1633
	ASSERT3U(zio->io_prop.zp_ndvas, ==, lio->io_prop.zp_ndvas);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1634
	ASSERT3U(zio->io_prop.zp_ndvas, <=, BP_GET_NDVAS(zio->io_bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1635
	ASSERT3U(pio->io_prop.zp_ndvas, <=, BP_GET_NDVAS(pio->io_bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1636
	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
  1637
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
	mutex_enter(&pio->io_lock);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1639
	for (int d = 0; d < BP_GET_NDVAS(zio->io_bp); d++) {
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1640
		ASSERT(DVA_GET_GANG(&pdva[d]));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1641
		asize = DVA_GET_ASIZE(&pdva[d]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1642
		asize += DVA_GET_ASIZE(&cdva[d]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1643
		DVA_SET_ASIZE(&pdva[d], asize);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1644
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1648
static int
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1649
zio_write_gang_block(zio_t *pio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1651
	spa_t *spa = pio->io_spa;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1652
	blkptr_t *bp = pio->io_bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1653
	zio_t *lio = pio->io_logical;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1654
	zio_t *zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1655
	zio_gang_node_t *gn, **gnpp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1656
	zio_gbh_phys_t *gbh;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1657
	uint64_t txg = pio->io_txg;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1658
	uint64_t resid = pio->io_size;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1659
	uint64_t lsize;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1660
	int ndvas = lio->io_prop.zp_ndvas;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1661
	int gbh_ndvas = MIN(ndvas + 1, spa_max_replication(spa));
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1662
	zio_prop_t zp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1663
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1664
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1665
	error = metaslab_alloc(spa, spa->spa_normal_class, SPA_GANGBLOCKSIZE,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1666
	    bp, gbh_ndvas, txg, pio == lio ? NULL : lio->io_bp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1667
	    METASLAB_HINTBP_FAVOR | METASLAB_GANG_HEADER);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1668
	if (error) {
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1669
		pio->io_error = error;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1670
		return (ZIO_PIPELINE_CONTINUE);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1671
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1672
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1673
	if (pio == lio) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1674
		gnpp = &lio->io_gang_tree;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1675
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1676
		gnpp = pio->io_private;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1677
		ASSERT(pio->io_ready == zio_write_gang_member_ready);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1678
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1680
	gn = zio_gang_node_alloc(gnpp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1681
	gbh = gn->gn_gbh;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1682
	bzero(gbh, SPA_GANGBLOCKSIZE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1683
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1684
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1685
	 * Create the gang header.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1686
	 */
13395
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1687
	zio = zio_rewrite(pio, spa, txg, bp, gbh, SPA_GANGBLOCKSIZE,
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1688
	    NULL, NULL, NULL, pio->io_priority, 
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1689
	    ZIO_GANG_CHILD_FLAGS(pio), &pio->io_bookmark);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1690
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1691
	/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1692
	 * Create and nowait the gang children.
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1693
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1694
	for (int g = 0; resid != 0; resid -= lsize, g++) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1695
		lsize = P2ROUNDUP(resid / (SPA_GBH_NBLKPTRS - g),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1696
		    SPA_MINBLOCKSIZE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1697
		ASSERT(lsize >= SPA_MINBLOCKSIZE && lsize <= resid);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1698
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1699
		zp.zp_checksum = lio->io_prop.zp_checksum;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1700
		zp.zp_compress = ZIO_COMPRESS_OFF;
13395
6aa29333ca54 WIP 6754666 ZIL writes clear text data to disk post onnv_100 resync
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13394
diff changeset
  1701
		zp.zp_crypt = ZIO_CRYPT_OFF;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1702
		zp.zp_type = DMU_OT_NONE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1703
		zp.zp_level = 0;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1704
		zp.zp_ndvas = lio->io_prop.zp_ndvas;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1705
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1706
		zio_nowait(zio_write(zio, spa, txg, &gbh->zg_blkptr[g],
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1707
		    (char *)pio->io_data + (pio->io_size - resid), lsize, &zp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1708
		    zio_write_gang_member_ready, NULL, &gn->gn_child[g],
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1709
		    pio->io_priority, ZIO_GANG_CHILD_FLAGS(pio),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1710
		    &pio->io_bookmark));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1711
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1712
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1713
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1714
	 * Set pio's pipeline to just wait for zio to finish.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1715
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1716
	pio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1717
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1718
	zio_nowait(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1719
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1720
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
 * Allocate and free blocks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1728
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1729
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1730
zio_dva_allocate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1731
{
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1732
	spa_t *spa = zio->io_spa;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
  1733
	metaslab_class_t *mc = spa->spa_normal_class;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1734
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
	ASSERT(BP_IS_HOLE(bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1738
	ASSERT3U(BP_GET_NDVAS(bp), ==, 0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1739
	ASSERT3U(zio->io_prop.zp_ndvas, >, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1740
	ASSERT3U(zio->io_prop.zp_ndvas, <=, spa_max_replication(spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
	ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1743
	error = metaslab_alloc(spa, mc, zio->io_size, bp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1744
	    zio->io_prop.zp_ndvas, zio->io_txg, NULL, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1745
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1746
	if (error) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1747
		if (error == ENOSPC && zio->io_size > SPA_MINBLOCKSIZE)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1748
			return (zio_write_gang_block(zio));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1749
		zio->io_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1750
	}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1751
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1752
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1753
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1754
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1755
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1756
zio_dva_free(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1757
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1758
	metaslab_free(zio->io_spa, zio->io_bp, zio->io_txg, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1759
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1760
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1761
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1762
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1763
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1764
zio_dva_claim(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1765
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1766
	int error;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1767
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1768
	error = metaslab_claim(zio->io_spa, zio->io_bp, zio->io_txg);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1769
	if (error)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1770
		zio->io_error = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1771
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1772
	return (ZIO_PIPELINE_CONTINUE);
789
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
/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1776
 * Undo an allocation.  This is used by zio_done() when an I/O fails
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1777
 * and we want to give back the block we just allocated.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1778
 * This handles both normal blocks and gang blocks.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1779
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1780
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1781
zio_dva_unallocate(zio_t *zio, zio_gang_node_t *gn, blkptr_t *bp)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1782
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1783
	spa_t *spa = zio->io_spa;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1784
	boolean_t now = !(zio->io_flags & ZIO_FLAG_IO_REWRITE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1785
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1786
	ASSERT(bp->blk_birth == zio->io_txg || BP_IS_HOLE(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1787
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1788
	if (zio->io_bp == bp && !now) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1789
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1790
		 * This is a rewrite for sync-to-convergence.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1791
		 * We can't do a metaslab_free(NOW) because bp wasn't allocated
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1792
		 * during this sync pass, which means that metaslab_sync()
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1793
		 * already committed the allocation.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1794
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1795
		ASSERT(DVA_EQUAL(BP_IDENTITY(bp),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1796
		    BP_IDENTITY(&zio->io_bp_orig)));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1797
		ASSERT(spa_sync_pass(spa) > 1);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1798
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1799
		if (BP_IS_GANG(bp) && gn == NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1800
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1801
			 * This is a gang leader whose gang header(s) we
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1802
			 * couldn't read now, so defer the free until later.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1803
			 * The block should still be intact because without
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1804
			 * the headers, we'd never even start the rewrite.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1805
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1806
			bplist_enqueue_deferred(&spa->spa_sync_bplist, bp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1807
			return;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1808
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1809
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1810
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1811
	if (!BP_IS_HOLE(bp))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1812
		metaslab_free(spa, bp, bp->blk_birth, now);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1813
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1814
	if (gn != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1815
		for (int g = 0; g < SPA_GBH_NBLKPTRS; g++) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1816
			zio_dva_unallocate(zio, gn->gn_child[g],
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1817
			    &gn->gn_gbh->zg_blkptr[g]);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1818
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1819
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1820
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1821
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1822
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1823
 * Try to allocate an intent log block.  Return 0 on success, errno on failure.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1824
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1825
int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1826
zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp, blkptr_t *old_bp,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1827
    uint64_t txg)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1828
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1829
	int error;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1830
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1831
	error = metaslab_alloc(spa, spa->spa_log_class, size,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1832
	    new_bp, 1, txg, old_bp, METASLAB_HINTBP_AVOID);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1833
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1834
	if (error)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1835
		error = metaslab_alloc(spa, spa->spa_normal_class, size,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1836
		    new_bp, 1, txg, old_bp, METASLAB_HINTBP_AVOID);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1837
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1838
	if (error == 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1839
		BP_SET_LSIZE(new_bp, size);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1840
		BP_SET_PSIZE(new_bp, size);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1841
		BP_SET_COMPRESS(new_bp, ZIO_COMPRESS_OFF);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1842
		BP_SET_CHECKSUM(new_bp, ZIO_CHECKSUM_ZILOG);
13396
485224e23eb9 6756231 Read and Write of encrytped data fundamentally broken post onnv_100
Darren Moffat <Darren.Moffat@Sun.COM>
parents: 13395
diff changeset
  1843
		BP_SET_CRYPT(new_bp, ZIO_CRYPT_OFF);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1844
		BP_SET_TYPE(new_bp, DMU_OT_INTENT_LOG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1845
		BP_SET_LEVEL(new_bp, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1846
		BP_SET_BYTEORDER(new_bp, ZFS_HOST_BYTEORDER);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1847
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1848
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1849
	return (error);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1850
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1851
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1852
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1853
 * Free an intent log block.  We know it can't be a gang block, so there's
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1854
 * nothing to do except metaslab_free() it.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1855
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1856
void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1857
zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1858
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1859
	ASSERT(!BP_IS_GANG(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1860
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1861
	metaslab_free(spa, bp, txg, B_FALSE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1862
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1863
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1864
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1865
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
 * Read and write to physical devices
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1867
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1869
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1870
static void
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1871
zio_vdev_io_probe_done(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1872
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1873
	zio_t *dio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1874
	vdev_t *vd = zio->io_private;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1875
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1876
	mutex_enter(&vd->vdev_probe_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1877
	ASSERT(vd->vdev_probe_zio == zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1878
	vd->vdev_probe_zio = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1879
	mutex_exit(&vd->vdev_probe_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1880
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1881
	while ((dio = zio->io_delegate_list) != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1882
		zio->io_delegate_list = dio->io_delegate_next;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1883
		dio->io_delegate_next = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1884
		if (!vdev_accessible(vd, dio))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1885
			dio->io_error = ENXIO;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1886
		zio_execute(dio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1887
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1888
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1889
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1890
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1891
 * Probe the device to determine whether I/O failure is specific to this
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1892
 * zio (e.g. a bad sector) or affects the entire vdev (e.g. unplugged).
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1893
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1894
static int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1895
zio_vdev_io_probe(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1896
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1897
	vdev_t *vd = zio->io_vd;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1898
	zio_t *pio = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1899
	boolean_t created_pio = B_FALSE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1900
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1901
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1902
	 * Don't probe the probe.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1903
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1904
	if (zio->io_flags & ZIO_FLAG_PROBE)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1905
		return (ZIO_PIPELINE_CONTINUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1906
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1907
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1908
	 * To prevent 'probe storms' when a device fails, we create
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1909
	 * just one probe i/o at a time.  All zios that want to probe
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1910
	 * this vdev will join the probe zio's io_delegate_list.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1911
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1912
	mutex_enter(&vd->vdev_probe_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1913
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1914
	if ((pio = vd->vdev_probe_zio) == NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1915
		vd->vdev_probe_zio = pio = zio_root(zio->io_spa,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1916
		    zio_vdev_io_probe_done, vd, ZIO_FLAG_CANFAIL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1917
		created_pio = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1918
		vd->vdev_probe_wanted = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1919
		spa_async_request(zio->io_spa, SPA_ASYNC_PROBE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1920
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1921
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1922
	zio->io_delegate_next = pio->io_delegate_list;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1923
	pio->io_delegate_list = zio;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1924
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1925
	mutex_exit(&vd->vdev_probe_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1926
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1927
	if (created_pio) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1928
		zio_nowait(vdev_probe(vd, pio));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1929
		zio_nowait(pio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1930
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1931
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1932
	return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1933
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1934
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1935
static int
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1936
zio_vdev_io_start(zio_t *zio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1937
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1938
	vdev_t *vd = zio->io_vd;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1939
	uint64_t align;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1940
	spa_t *spa = zio->io_spa;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4831
diff changeset
  1941
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1942
	ASSERT(zio->io_error == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1943
	ASSERT(zio->io_child_error[ZIO_CHILD_VDEV] == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1944
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1945
	if (vd == NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1946
		if (!(zio->io_flags & ZIO_FLAG_CONFIG_WRITER))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1947
			spa_config_enter(spa, SCL_ZIO, zio, RW_READER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1948
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1949
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1950
		 * The mirror_ops handle multiple DVAs in a single BP.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1951
		 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1952
		return (vdev_mirror_ops.vdev_op_io_start(zio));
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1953
	}
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1954
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1955
	align = 1ULL << vd->vdev_top->vdev_ashift;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1956
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1957
	if (P2PHASE(zio->io_size, align) != 0) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1958
		uint64_t asize = P2ROUNDUP(zio->io_size, align);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1959
		char *abuf = zio_buf_alloc(asize);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1960
		ASSERT(vd == vd->vdev_top);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1961
		if (zio->io_type == ZIO_TYPE_WRITE) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1962
			bcopy(zio->io_data, abuf, zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1963
			bzero(abuf + zio->io_size, asize - zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1964
		}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1965
		zio_push_transform(zio, abuf, asize, asize, zio_subblock);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1966
	}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1967
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1968
	ASSERT(P2PHASE(zio->io_offset, align) == 0);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1969
	ASSERT(P2PHASE(zio->io_size, align) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1970
	ASSERT(zio->io_type != ZIO_TYPE_WRITE || (spa_mode & FWRITE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1971
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1972
	if (vd->vdev_ops->vdev_op_leaf &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1973
	    (zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE)) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1974
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1975
		if (zio->io_type == ZIO_TYPE_READ && vdev_cache_read(zio) == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1976
			return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1977
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1978
		if ((zio = vdev_queue_io(zio)) == NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1979
			return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1980
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1981
		if (!vdev_accessible(vd, zio)) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1982
			zio->io_error = ENXIO;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1983
			zio_interrupt(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1984
			return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1985
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1986
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1987
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1988
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1989
	return (vd->vdev_ops->vdev_op_io_start(zio));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1990
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1991
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1992
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
zio_vdev_io_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1994
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1995
	vdev_t *vd = zio->io_vd;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1996
	vdev_ops_t *ops = vd ? vd->vdev_ops : &vdev_mirror_ops;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1997
	boolean_t unexpected_error = B_FALSE;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  1998
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  1999
	if (zio_wait_for_children(zio, ZIO_CHILD_VDEV, ZIO_WAIT_DONE))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2000
		return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2001
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2002
	ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2003
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2004
	if (vd != NULL && vd->vdev_ops->vdev_op_leaf) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2005
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2006
		vdev_queue_io_done(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2007
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2008
		if (zio->io_type == ZIO_TYPE_WRITE)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2009
			vdev_cache_write(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2010
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2011
		if (zio_injection_enabled && zio->io_error == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2012
			zio->io_error = zio_handle_device_injection(vd, EIO);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2014
		if (zio_injection_enabled && zio->io_error == 0)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2015
			zio->io_error = zio_handle_label_injection(zio, EIO);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2016
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2017
		if (zio->io_error) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2018
			if (!vdev_accessible(vd, zio)) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2019
				zio->io_error = ENXIO;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2020
			} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2021
				unexpected_error = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2022
			}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2023
		}
6976
cae5f06df471 PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents: 6523
diff changeset
  2024
	}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2025
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2026
	ops->vdev_op_io_done(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2028
	if (unexpected_error)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2029
		return (zio_vdev_io_probe(zio));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2030
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2031
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2033
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2034
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2035
zio_vdev_io_assess(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2036
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2037
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2038
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2039
	if (zio_wait_for_children(zio, ZIO_CHILD_VDEV, ZIO_WAIT_DONE))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2040
		return (ZIO_PIPELINE_STOP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2041
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2042
	if (vd == NULL && !(zio->io_flags & ZIO_FLAG_CONFIG_WRITER))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2043
		spa_config_exit(zio->io_spa, SCL_ZIO, zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2044
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2045
	if (zio->io_vsd != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2046
		zio->io_vsd_free(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2047
		zio->io_vsd = NULL;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  2048
	}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  2049
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2050
	if (zio_injection_enabled && zio->io_error == 0)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2051
		zio->io_error = zio_handle_fault_injection(zio, EIO);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2052
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2053
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2054
	 * If the I/O failed, determine whether we should attempt to retry it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2055
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2056
	if (zio->io_error && vd == NULL &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2057
	    !(zio->io_flags & (ZIO_FLAG_DONT_RETRY | ZIO_FLAG_IO_RETRY))) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2058
		ASSERT(!(zio->io_flags & ZIO_FLAG_DONT_QUEUE));	/* not a leaf */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2059
		ASSERT(!(zio->io_flags & ZIO_FLAG_IO_BYPASS));	/* not a leaf */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2060
		zio->io_error = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2061
		zio->io_flags |= ZIO_FLAG_IO_RETRY |
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2062
		    ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_AGGREGATE;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2063
		zio->io_stage = ZIO_STAGE_VDEV_IO_START - 1;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2064
		zio_taskq_dispatch(zio, ZIO_TASKQ_ISSUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2065
		return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2066
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2067
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2068
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2069
	 * If we got an error on a leaf device, convert it to ENXIO
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2070
	 * if the device is not accessible at all.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2071
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2072
	if (zio->io_error && vd != NULL && vd->vdev_ops->vdev_op_leaf &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2073
	    !vdev_accessible(vd, zio))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2074
		zio->io_error = ENXIO;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2075
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2076
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2077
	 * If we can't write to an interior vdev (mirror or RAID-Z),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2078
	 * set vdev_cant_write so that we stop trying to allocate from it.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2079
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2080
	if (zio->io_error == ENXIO && zio->io_type == ZIO_TYPE_WRITE &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2081
	    vd != NULL && !vd->vdev_ops->vdev_op_leaf)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2082
		vd->vdev_cant_write = B_TRUE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2083
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2084
	if (zio->io_error)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2085
		zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2086
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2087
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2088
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2089
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2090
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2091
zio_vdev_io_reissue(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2092
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2093
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2094
	ASSERT(zio->io_error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2095
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2096
	zio->io_stage--;
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
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2100
zio_vdev_io_redone(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2101
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2102
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2103
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2104
	zio->io_stage--;
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
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2108
zio_vdev_io_bypass(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2109
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2110
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2111
	ASSERT(zio->io_error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2112
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2113
	zio->io_flags |= ZIO_FLAG_IO_BYPASS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2114
	zio->io_stage = ZIO_STAGE_VDEV_IO_ASSESS - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2115
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2117
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2118
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2119
 * Generate and verify checksums
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2120
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2121
 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2122
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2123
zio_checksum_generate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2125
	blkptr_t *bp = zio->io_bp;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2126
	enum zio_checksum checksum;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2127
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2128
	if (bp == NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2129
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2130
		 * This is zio_write_phys().
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2131
		 * We're either generating a label checksum, or none at all.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2132
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2133
		checksum = zio->io_prop.zp_checksum;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2134
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2135
		if (checksum == ZIO_CHECKSUM_OFF)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2136
			return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2137
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2138
		ASSERT(checksum == ZIO_CHECKSUM_LABEL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2139
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2140
		if (BP_IS_GANG(bp) && zio->io_child_type == ZIO_CHILD_GANG) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2141
			ASSERT(!IO_IS_ALLOCATING(zio));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2142
			checksum = ZIO_CHECKSUM_GANG_HEADER;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2143
		} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2144
			checksum = BP_GET_CHECKSUM(bp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2145
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2146
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2147
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2148
	zio_checksum_compute(zio, checksum, zio->io_data, zio->io_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2149
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2150
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2151
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2152
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2153
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2154
zio_checksum_verify(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2155
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2156
	blkptr_t *bp = zio->io_bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2157
	int error;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2158
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2159
	if (bp == NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2160
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2161
		 * This is zio_read_phys().
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2162
		 * We're either verifying a label checksum, or nothing at all.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2163
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2164
		if (zio->io_prop.zp_checksum == ZIO_CHECKSUM_OFF)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2165
			return (ZIO_PIPELINE_CONTINUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2166
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2167
		ASSERT(zio->io_prop.zp_checksum == ZIO_CHECKSUM_LABEL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2168
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2169
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2170
	if ((error = zio_checksum_error(zio)) != 0) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2171
		zio->io_error = error;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2172
		if (!(zio->io_flags & ZIO_FLAG_SPECULATIVE)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2173
			zfs_ereport_post(FM_EREPORT_ZFS_CHECKSUM,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  2174
			    zio->io_spa, zio->io_vd, zio, 0, 0);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2175
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2176
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2178
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2179
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2182
 * Called by RAID-Z to ensure we don't compute the checksum twice.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2184
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2185
zio_checksum_verified(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2186
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2187
	zio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2188
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2189
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2191
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2192
 * Error rank.  Error are ranked in the order 0, ENXIO, ECKSUM, EIO, other.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2193
 * An error of 0 indictes success.  ENXIO indicates whole-device failure,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2194
 * which may be transient (e.g. unplugged) or permament.  ECKSUM and EIO
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2195
 * indicate errors that are specific to one I/O, and most likely permanent.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2196
 * Any other error is presumed to be worse because we weren't expecting it.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2197
 * ==========================================================================
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2198
 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2199
int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2200
zio_worst_error(int e1, int e2)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2201
{
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2202
	static int zio_error_rank[] = { 0, ENXIO, ECKSUM, EIO };
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2203
	int r1, r2;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2204
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2205
	for (r1 = 0; r1 < sizeof (zio_error_rank) / sizeof (int); r1++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2206
		if (e1 == zio_error_rank[r1])
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2207
			break;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2208
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2209
	for (r2 = 0; r2 < sizeof (zio_error_rank) / sizeof (int); r2++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2210
		if (e2 == zio_error_rank[r2])
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2211
			break;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2212
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2213
	return (r1 > r2 ? e1 : e2);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
 * ==========================================================================
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2218
 * I/O completion
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2219
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2220
 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2221
static int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2222
zio_ready(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2223
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2224
	blkptr_t *bp = zio->io_bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2225
	zio_t *pio = zio->io_parent;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2226
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2227
	if (zio->io_ready) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2228
		if (BP_IS_GANG(bp) &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2229
		    zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_READY))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2230
			return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2231
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2232
		ASSERT(IO_IS_ALLOCATING(zio));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2233
		ASSERT(bp->blk_birth == zio->io_txg || BP_IS_HOLE(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2234
		ASSERT(zio->io_children[ZIO_CHILD_GANG][ZIO_WAIT_READY] == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2235
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2236
		zio->io_ready(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2237
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2238
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2239
	if (bp != NULL && bp != &zio->io_bp_copy)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2240
		zio->io_bp_copy = *bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2241
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2242
	if (zio->io_error)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2243
		zio->io_pipeline = ZIO_INTERLOCK_PIPELINE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2244
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2245
	if (pio != NULL)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2246
		zio_notify_parent(pio, zio, ZIO_WAIT_READY);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2247
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2248
	return (ZIO_PIPELINE_CONTINUE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2249
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2250
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2251
static int
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2252
zio_done(zio_t *zio)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2253
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2254
	spa_t *spa = zio->io_spa;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2255
	zio_t *pio = zio->io_parent;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2256
	zio_t *lio = zio->io_logical;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2257
	blkptr_t *bp = zio->io_bp;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2258
	vdev_t *vd = zio->io_vd;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2259
	uint64_t psize = zio->io_size;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2260
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2261
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2262
	 * If our of children haven't all completed,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2263
	 * wait for them and then repeat this pipeline stage.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2264
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2265
	if (zio_wait_for_children(zio, ZIO_CHILD_VDEV, ZIO_WAIT_DONE) ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2266
	    zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_DONE) ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2267
	    zio_wait_for_children(zio, ZIO_CHILD_LOGICAL, ZIO_WAIT_DONE))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2268
		return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2269
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2270
	for (int c = 0; c < ZIO_CHILD_TYPES; c++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2271
		for (int w = 0; w < ZIO_WAIT_TYPES; w++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2272
			ASSERT(zio->io_children[c][w] == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2273
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2274
	if (bp != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2275
		ASSERT(bp->blk_pad[0] == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2276
		ASSERT(bp->blk_pad[1] == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2277
		ASSERT(bcmp(bp, &zio->io_bp_copy, sizeof (blkptr_t)) == 0 ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2278
		    (pio != NULL && bp == pio->io_bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2279
		if (zio->io_type == ZIO_TYPE_WRITE && !BP_IS_HOLE(bp) &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2280
		    !(zio->io_flags & ZIO_FLAG_IO_REPAIR)) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2281
			ASSERT(!BP_SHOULD_BYTESWAP(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2282
			ASSERT3U(zio->io_prop.zp_ndvas, <=, BP_GET_NDVAS(bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2283
			ASSERT(BP_COUNT_GANG(bp) == 0 ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2284
			    (BP_COUNT_GANG(bp) == BP_GET_NDVAS(bp)));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2285
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2286
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2287
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2288
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2289
	 * If there were child vdev or gang errors, they apply to us now.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2290
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2291
	zio_inherit_child_errors(zio, ZIO_CHILD_VDEV);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2292
	zio_inherit_child_errors(zio, ZIO_CHILD_GANG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2293
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2294
	zio_pop_transforms(zio);	/* note: may set zio->io_error */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2295
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2296
	vdev_stat_update(zio, psize);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2297
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2298
	if (zio->io_error) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2299
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2300
		 * If this I/O is attached to a particular vdev,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2301
		 * generate an error message describing the I/O failure
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2302
		 * at the block level.  We ignore these errors if the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2303
		 * device is currently unavailable.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2304
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2305
		if (zio->io_error != ECKSUM && vd != NULL && !vdev_is_dead(vd))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2306
			zfs_ereport_post(FM_EREPORT_ZFS_IO, spa, vd, zio, 0, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2307
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2308
		if ((zio->io_error == EIO ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2309
		    !(zio->io_flags & ZIO_FLAG_SPECULATIVE)) && zio == lio) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2310
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2311
			 * For logical I/O requests, tell the SPA to log the
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2312
			 * error and generate a logical data ereport.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2313
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2314
			spa_log_error(spa, zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2315
			zfs_ereport_post(FM_EREPORT_ZFS_DATA, spa, NULL, zio,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2316
			    0, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2317
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2318
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2319
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2320
	if (zio->io_error && zio == lio) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2321
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2322
		 * Determine whether zio should be reexecuted.  This will
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2323
		 * propagate all the way to the root via zio_notify_parent().
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2324
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2325
		ASSERT(vd == NULL && bp != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2326
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2327
		if (IO_IS_ALLOCATING(zio))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2328
			if (zio->io_error != ENOSPC)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2329
				zio->io_reexecute |= ZIO_REEXECUTE_NOW;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2330
			else
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2331
				zio->io_reexecute |= ZIO_REEXECUTE_SUSPEND;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2332
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2333
		if ((zio->io_type == ZIO_TYPE_READ ||
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2334
		    zio->io_type == ZIO_TYPE_FREE) &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2335
		    zio->io_error == ENXIO &&
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2336
		    spa_get_failmode(spa) != ZIO_FAILURE_MODE_CONTINUE)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2337
			zio->io_reexecute |= ZIO_REEXECUTE_SUSPEND;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2338
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2339
		if (!(zio->io_flags & ZIO_FLAG_CANFAIL) && !zio->io_reexecute)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2340
			zio->io_reexecute |= ZIO_REEXECUTE_SUSPEND;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2341
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2342
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2343
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2344
	 * If there were logical child errors, they apply to us now.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2345
	 * We defer this until now to avoid conflating logical child
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2346
	 * errors with errors that happened to the zio itself when
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2347
	 * updating vdev stats and reporting FMA events above.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2348
	 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2349
	zio_inherit_child_errors(zio, ZIO_CHILD_LOGICAL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2350
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2351
	if (zio->io_reexecute) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2352
		/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2353
		 * This is a logical I/O that wants to reexecute.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2354
		 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2355
		 * Reexecute is top-down.  When an i/o fails, if it's not
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2356
		 * the root, it simply notifies its parent and sticks around.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2357
		 * The parent, seeing that it still has children in zio_done(),
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2358
		 * does the same.  This percolates all the way up to the root.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2359
		 * The root i/o will reexecute or suspend the entire tree.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2360
		 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2361
		 * This approach ensures that zio_reexecute() honors
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2362
		 * all the original i/o dependency relationships, e.g.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2363
		 * parents not executing until children are ready.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2364
		 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2365
		ASSERT(zio->io_child_type == ZIO_CHILD_LOGICAL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2366
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2367
		if (IO_IS_ALLOCATING(zio))
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2368
			zio_dva_unallocate(zio, zio->io_gang_tree, bp);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2369
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2370
		zio_gang_tree_free(&zio->io_gang_tree);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2371
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2372
		if (pio != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2373
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2374
			 * We're not a root i/o, so there's nothing to do
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2375
			 * but notify our parent.  Don't propagate errors
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2376
			 * upward since we haven't permanently failed yet.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2377
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2378
			zio->io_flags |= ZIO_FLAG_DONT_PROPAGATE;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2379
			zio_notify_parent(pio, zio, ZIO_WAIT_DONE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2380
		} else if (zio->io_reexecute & ZIO_REEXECUTE_SUSPEND) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2381
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2382
			 * We'd fail again if we reexecuted now, so suspend
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2383
			 * until conditions improve (e.g. device comes online).
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2384
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2385
			zio_suspend(spa, zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2386
		} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2387
			/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2388
			 * Reexecution is potentially a huge amount of work.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2389
			 * Hand it off to the otherwise-unused claim taskq.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2390
			 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2391
			(void) taskq_dispatch(
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2392
			    spa->spa_zio_taskq[ZIO_TYPE_CLAIM][ZIO_TASKQ_ISSUE],
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2393
			    (task_func_t *)zio_reexecute, zio, TQ_SLEEP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2394
		}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2395
		return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2396
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2397
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2398
	ASSERT(zio->io_child == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2399
	ASSERT(zio->io_reexecute == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2400
	ASSERT(zio->io_error == 0 || (zio->io_flags & ZIO_FLAG_CANFAIL));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2401
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2402
	if (zio->io_done)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2403
		zio->io_done(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2404
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2405
	zio_gang_tree_free(&zio->io_gang_tree);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2406
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2407
	ASSERT(zio->io_delegate_list == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2408
	ASSERT(zio->io_delegate_next == NULL);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2409
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2410
	if (pio != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2411
		zio_remove_child(pio, zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2412
		zio_notify_parent(pio, zio, ZIO_WAIT_DONE);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2413
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2414
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2415
	if (zio->io_waiter != NULL) {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2416
		mutex_enter(&zio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2417
		zio->io_executor = NULL;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2418
		cv_broadcast(&zio->io_cv);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2419
		mutex_exit(&zio->io_lock);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2420
	} else {
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2421
		zio_destroy(zio);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2422
	}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2423
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2424
	return (ZIO_PIPELINE_STOP);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2425
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2426
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2427
/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2428
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2429
 * I/O pipeline definition
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2430
 * ==========================================================================
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2431
 */
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2432
static zio_pipe_stage_t *zio_pipeline[ZIO_STAGES] = {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2433
	NULL,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5450
diff changeset
  2434
	zio_issue_async,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2435
	zio_read_bp_init,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2436
	zio_write_bp_init,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2437
	zio_checksum_generate,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2438
	zio_gang_assemble,
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2439
	zio_gang_issue,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2440
	zio_dva_allocate,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2441
	zio_dva_free,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2442
	zio_dva_claim,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2443
	zio_ready,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2444
	zio_vdev_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2445
	zio_vdev_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2446
	zio_vdev_io_assess,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2447
	zio_checksum_verify,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7181
diff changeset
  2448
	zio_done
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2449
};