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