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