usr/src/uts/common/fs/zfs/zio.c
author ahrens
Mon, 22 Jan 2007 14:33:31 -0800
changeset 3463 5007f15d5674
parent 3459 358b6bdb15b6
child 3547 e396e0a440b1
permissions -rw-r--r--
6480626 contention on spa_config_lock on niagra
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
3459
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
    22
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/zfs_context.h>
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
    29
#include <sys/fm/fs/zfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/zio_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zio_compress.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 * I/O priority table
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
	0,	/* ZIO_PRIORITY_NOW		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
	0,	/* ZIO_PRIORITY_SYNC_READ	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
	0,	/* ZIO_PRIORITY_SYNC_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
	6,	/* ZIO_PRIORITY_ASYNC_READ	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
	4,	/* ZIO_PRIORITY_ASYNC_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
	4,	/* ZIO_PRIORITY_FREE		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
	0,	/* ZIO_PRIORITY_CACHE_FILL	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
	0,	/* ZIO_PRIORITY_LOG_WRITE	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
	10,	/* ZIO_PRIORITY_RESILVER	*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
	20,	/* ZIO_PRIORITY_SCRUB		*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 * I/O type descriptions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
char *zio_type_name[ZIO_TYPES] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	"null", "read", "write", "free", "claim", "ioctl" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
/* At or above this size, force gang blocking - for testing */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
uint64_t zio_gang_bang = SPA_MAXBLOCKSIZE + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
typedef struct zio_sync_pass {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
	int	zp_defer_free;		/* defer frees after this pass */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	int	zp_dontcompress;	/* don't compress after this pass */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
	int	zp_rewrite;		/* rewrite new bps after this pass */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
} zio_sync_pass_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
zio_sync_pass_t zio_sync_pass = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	1,	/* zp_defer_free */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	4,	/* zp_dontcompress */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	1,	/* zp_rewrite */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
 * I/O kmem caches
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
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
    85
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
    86
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    87
#ifdef _KERNEL
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    88
extern vmem_t *zio_alloc_arena;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    89
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
zio_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
	size_t c;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    95
	vmem_t *data_alloc_arena = NULL;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    96
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    97
#ifdef _KERNEL
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    98
	data_alloc_arena = zio_alloc_arena;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
    99
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	 * For small buffers, we want a cache for each multiple of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	 * SPA_MINBLOCKSIZE.  For medium-size buffers, we want a cache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	 * for each quarter-power of 2.  For large buffers, we want
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	 * a cache for each multiple of PAGESIZE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
	for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
		size_t size = (c + 1) << SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
		size_t p2 = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
		size_t align = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
		while (p2 & (p2 - 1))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
			p2 &= p2 - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
		if (size <= 4 * SPA_MINBLOCKSIZE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
			align = SPA_MINBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
		} else if (P2PHASE(size, PAGESIZE) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
			align = PAGESIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
		} else if (P2PHASE(size, p2 >> 2) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
			align = p2 >> 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
		if (align != 0) {
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   124
			char name[36];
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2082
diff changeset
   125
			(void) sprintf(name, "zio_buf_%lu", (ulong_t)size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
			zio_buf_cache[c] = kmem_cache_create(name, size,
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
   127
			    align, NULL, NULL, NULL, NULL, NULL, KMC_NODEBUG);
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   128
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   129
			(void) sprintf(name, "zio_data_buf_%lu", (ulong_t)size);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   130
			zio_data_buf_cache[c] = kmem_cache_create(name, size,
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   131
			    align, NULL, NULL, NULL, NULL, data_alloc_arena,
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   132
			    KMC_NODEBUG);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   133
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
			dprintf("creating cache for size %5lx align %5lx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
			    size, align);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
	while (--c != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
		ASSERT(zio_buf_cache[c] != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
		if (zio_buf_cache[c - 1] == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
			zio_buf_cache[c - 1] = zio_buf_cache[c];
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   143
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   144
		ASSERT(zio_data_buf_cache[c] != NULL);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   145
		if (zio_data_buf_cache[c - 1] == NULL)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   146
			zio_data_buf_cache[c - 1] = zio_data_buf_cache[c];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   148
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   149
	zio_inject_init();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
zio_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
	size_t c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
	kmem_cache_t *last_cache = NULL;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   157
	kmem_cache_t *last_data_cache = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
	for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
		if (zio_buf_cache[c] != last_cache) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
			last_cache = zio_buf_cache[c];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
			kmem_cache_destroy(zio_buf_cache[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
		zio_buf_cache[c] = NULL;
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   165
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   166
		if (zio_data_buf_cache[c] != last_data_cache) {
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   167
			last_data_cache = zio_data_buf_cache[c];
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   168
			kmem_cache_destroy(zio_data_buf_cache[c]);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   169
		}
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   170
		zio_data_buf_cache[c] = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   172
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   173
	zio_inject_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
 * Allocate and free I/O buffers
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
 */
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   181
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   182
/*
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   183
 * 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
   184
 * 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
   185
 * 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
   186
 * excess / transient data in-core during a crashdump.
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   187
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
void *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
zio_buf_alloc(size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
	return (kmem_cache_alloc(zio_buf_cache[c], KM_SLEEP));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
3290
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   198
/*
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   199
 * 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
   200
 * 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
   201
 * 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
   202
 * of kernel heap dumped to disk when the kernel panics)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   203
 */
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   204
void *
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   205
zio_data_buf_alloc(size_t size)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   206
{
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   207
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
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
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   210
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   211
	return (kmem_cache_alloc(zio_data_buf_cache[c], KM_SLEEP));
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   212
}
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   213
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
zio_buf_free(void *buf, size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	kmem_cache_free(zio_buf_cache[c], buf);
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
void
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   225
zio_data_buf_free(void *buf, size_t size)
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   226
{
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   227
	size_t c = (size - 1) >> SPA_MINBLOCKSHIFT;
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   228
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   229
	ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   230
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   231
	kmem_cache_free(zio_data_buf_cache[c], buf);
256464cbb73c 4894692 caching data in heap inflates crash dump
johansen
parents: 3063
diff changeset
   232
}
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   233
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
 * Push and pop I/O transform buffers
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
zio_push_transform(zio_t *zio, void *data, uint64_t size, uint64_t bufsize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
	zio_transform_t *zt = kmem_alloc(sizeof (zio_transform_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
	zt->zt_data = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
	zt->zt_size = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	zt->zt_bufsize = bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
	zt->zt_next = zio->io_transform_stack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
	zio->io_transform_stack = zt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
	zio->io_data = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	zio->io_size = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
zio_pop_transform(zio_t *zio, void **data, uint64_t *size, uint64_t *bufsize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
	zio_transform_t *zt = zio->io_transform_stack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
	*data = zt->zt_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
	*size = zt->zt_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	*bufsize = zt->zt_bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
	zio->io_transform_stack = zt->zt_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
	kmem_free(zt, sizeof (zio_transform_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
	if ((zt = zio->io_transform_stack) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
		zio->io_data = zt->zt_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
		zio->io_size = zt->zt_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
zio_clear_transform_stack(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	void *data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
	uint64_t size, bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
	ASSERT(zio->io_transform_stack != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	zio_pop_transform(zio, &data, &size, &bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
	while (zio->io_transform_stack != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
		zio_buf_free(data, bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
		zio_pop_transform(zio, &data, &size, &bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
 * Create the various types of I/O (read, write, free)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
static zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
zio_create(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
    void *data, uint64_t size, zio_done_func_t *done, void *private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
    zio_type_t type, int priority, int flags, uint8_t stage, uint32_t pipeline)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	zio = kmem_zalloc(sizeof (zio_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	zio->io_parent = pio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
	zio->io_spa = spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
	zio->io_txg = txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	if (bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
		zio->io_bp = bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
		zio->io_bp_copy = *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
		zio->io_bp_orig = *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
	zio->io_done = done;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
	zio->io_private = private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	zio->io_type = type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
	zio->io_priority = priority;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
	zio->io_stage = stage;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
	zio->io_pipeline = pipeline;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
	zio->io_async_stages = ZIO_ASYNC_PIPELINE_STAGES;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	zio->io_timestamp = lbolt64;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
	zio->io_flags = flags;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2082
diff changeset
   321
	mutex_init(&zio->io_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
	zio_push_transform(zio, data, size, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   324
	/*
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   325
	 * Note on config lock:
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   326
	 *
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   327
	 * 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
   328
	 * lock, so we don't need it for this io.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   329
	 *
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   330
	 * 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
   331
	 * 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
   332
	 * in zio_done.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   333
	 *
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   334
	 * 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
   335
	 * 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
   336
	 * 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
   337
	 * 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
   338
	 * 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
   339
	 * 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
   340
	 * contention on the config lock.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   341
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
	if (pio == NULL) {
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   343
		if (type != ZIO_TYPE_NULL &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   344
		    !(flags & ZIO_FLAG_CONFIG_HELD)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   345
			spa_config_enter(zio->io_spa, RW_READER, zio);
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   346
			zio->io_flags |= ZIO_FLAG_CONFIG_GRABBED;
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   347
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
		zio->io_root = zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
		zio->io_root = pio->io_root;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   351
		if (!(flags & ZIO_FLAG_NOBOOKMARK))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   352
			zio->io_logical = pio->io_logical;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
		mutex_enter(&pio->io_lock);
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   354
		if (pio->io_parent == NULL &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   355
		    pio->io_type == ZIO_TYPE_NULL &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   356
		    !(pio->io_flags & ZIO_FLAG_CONFIG_GRABBED) &&
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   357
		    !(pio->io_flags & ZIO_FLAG_CONFIG_HELD)) {
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   358
			pio->io_flags |= ZIO_FLAG_CONFIG_GRABBED;
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   359
			spa_config_enter(zio->io_spa, RW_READER, pio);
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   360
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
		if (stage < ZIO_STAGE_READY)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
			pio->io_children_notready++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
		pio->io_children_notdone++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
		zio->io_sibling_next = pio->io_child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
		zio->io_sibling_prev = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
		if (pio->io_child != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
			pio->io_child->io_sibling_prev = zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
		pio->io_child = zio;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   369
		zio->io_ndvas = pio->io_ndvas;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
zio_null(zio_t *pio, spa_t *spa, zio_done_func_t *done, void *private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
	int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
	zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	    ZIO_TYPE_NULL, ZIO_PRIORITY_NOW, flags, ZIO_STAGE_OPEN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
	    ZIO_WAIT_FOR_CHILDREN_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
zio_root(spa_t *spa, zio_done_func_t *done, void *private, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   392
	return (zio_null(NULL, spa, done, private, flags));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
    uint64_t size, zio_done_func_t *done, void *private,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   398
    int priority, int flags, zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
	ASSERT3U(size, ==, BP_GET_LSIZE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
	zio = zio_create(pio, spa, bp->blk_birth, bp, data, size, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   405
	    ZIO_TYPE_READ, priority, flags | ZIO_FLAG_USER,
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   406
	    ZIO_STAGE_OPEN, ZIO_READ_PIPELINE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   407
	zio->io_bookmark = *zb;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   408
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   409
	zio->io_logical = zio;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
	 * Work off our copy of the bp so the caller can free it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
	if (BP_GET_COMPRESS(bp) != ZIO_COMPRESS_OFF) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
		uint64_t csize = BP_GET_PSIZE(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
		void *cbuf = zio_buf_alloc(csize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
		zio_push_transform(zio, cbuf, csize, csize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
		zio->io_pipeline |= 1U << ZIO_STAGE_READ_DECOMPRESS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   424
	if (BP_IS_GANG(bp)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
		uint64_t gsize = SPA_GANGBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
		void *gbuf = zio_buf_alloc(gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
		zio_push_transform(zio, gbuf, gsize, gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
		zio->io_pipeline |= 1U << ZIO_STAGE_READ_GANG_MEMBERS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
zio_t *
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   436
zio_write(zio_t *pio, spa_t *spa, int checksum, int compress, int ncopies,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
    uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   438
    zio_done_func_t *done, void *private, int priority, int flags,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   439
    zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	ASSERT(checksum >= ZIO_CHECKSUM_OFF &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
	    checksum < ZIO_CHECKSUM_FUNCTIONS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
	ASSERT(compress >= ZIO_COMPRESS_OFF &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
	    compress < ZIO_COMPRESS_FUNCTIONS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   450
	    ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_USER,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
	    ZIO_STAGE_OPEN, ZIO_WRITE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   453
	zio->io_bookmark = *zb;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   454
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   455
	zio->io_logical = zio;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   456
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	zio->io_compress = compress;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   459
	zio->io_ndvas = ncopies;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	if (compress != ZIO_COMPRESS_OFF)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
		zio->io_async_stages |= 1U << ZIO_STAGE_WRITE_COMPRESS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	if (bp->blk_birth != txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
		/* XXX the bp usually (always?) gets re-zeroed later */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
		BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
		BP_SET_LSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
		BP_SET_PSIZE(bp, size);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   469
	} else {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   470
		/* 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
   471
		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
   472
		    spa_max_replication(spa)) == BP_GET_NDVAS(bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
zio_rewrite(zio_t *pio, spa_t *spa, int checksum,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
    uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   481
    zio_done_func_t *done, void *private, int priority, int flags,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   482
    zbookmark_t *zb)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   487
	    ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_USER,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
	    ZIO_STAGE_OPEN, ZIO_REWRITE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   490
	zio->io_bookmark = *zb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	zio->io_compress = ZIO_COMPRESS_OFF;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   494
	if (pio != NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   495
		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
   496
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
static zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
zio_write_allocate(zio_t *pio, spa_t *spa, int checksum,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
    uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
    zio_done_func_t *done, void *private, int priority, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
	BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	BP_SET_LSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	BP_SET_PSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
	BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
	zio = zio_create(pio, spa, txg, bp, data, size, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
	    ZIO_TYPE_WRITE, priority, flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
	    ZIO_STAGE_OPEN, ZIO_WRITE_ALLOCATE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
	zio->io_compress = ZIO_COMPRESS_OFF;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
    zio_done_func_t *done, void *private)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	ASSERT(!BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	if (txg == spa->spa_syncing_txg &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	    spa->spa_sync_pass > zio_sync_pass.zp_defer_free) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
		bplist_enqueue_deferred(&spa->spa_sync_bplist, bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
		return (zio_null(pio, spa, NULL, NULL, 0));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
	zio = zio_create(pio, spa, txg, bp, NULL, 0, done, private,
2981
b80f5da0b8ed 6485955 need more dtrace probes
ahrens
parents: 2885
diff changeset
   537
	    ZIO_TYPE_FREE, ZIO_PRIORITY_FREE, ZIO_FLAG_USER,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	    ZIO_STAGE_OPEN, ZIO_FREE_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
    zio_done_func_t *done, void *private)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
	 * A claim is an allocation of a specific block.  Claims are needed
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	 * to support immediate writes in the intent log.  The issue is that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
	 * immediate writes contain committed data, but in a txg that was
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
	 * *not* committed.  Upon opening the pool after an unclean shutdown,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
	 * the intent log claims all blocks that contain immediate write data
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	 * so that the SPA knows they're in use.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
	 * All claims *must* be resolved in the first txg -- before the SPA
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
	 * starts allocating blocks -- so that nothing is allocated twice.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
	ASSERT3U(spa->spa_uberblock.ub_rootbp.blk_birth, <, spa_first_txg(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
	ASSERT3U(spa_first_txg(spa), <=, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	zio = zio_create(pio, spa, txg, bp, NULL, 0, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
	    ZIO_TYPE_CLAIM, ZIO_PRIORITY_NOW, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
	    ZIO_STAGE_OPEN, ZIO_CLAIM_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
    zio_done_func_t *done, void *private, int priority, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
	if (vd->vdev_children == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
		zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
		    ZIO_TYPE_IOCTL, priority, flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
		    ZIO_STAGE_OPEN, ZIO_IOCTL_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
		zio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
		zio->io_cmd = cmd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
		zio = zio_null(pio, spa, NULL, NULL, flags);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
		for (c = 0; c < vd->vdev_children; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
			zio_nowait(zio_ioctl(zio, spa, vd->vdev_child[c], cmd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
			    done, private, priority, flags));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
zio_phys_bp_init(vdev_t *vd, blkptr_t *bp, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
    int checksum)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
	ASSERT(vd->vdev_children == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
	ASSERT(size <= SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
	ASSERT(P2PHASE(offset, SPA_MINBLOCKSIZE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
	ASSERT(offset + size <= VDEV_LABEL_START_SIZE ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
	    offset >= vd->vdev_psize - VDEV_LABEL_END_SIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
	ASSERT3U(offset + size, <=, vd->vdev_psize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
	BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
	BP_SET_LSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
	BP_SET_PSIZE(bp, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
	BP_SET_CHECKSUM(bp, checksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
	BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
	BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
	if (checksum != ZIO_CHECKSUM_OFF)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
		ZIO_SET_CHECKSUM(&bp->blk_cksum, offset, 0, 0, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
    void *data, int checksum, zio_done_func_t *done, void *private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
    int priority, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
	blkptr_t blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
	zio_phys_bp_init(vd, &blk, offset, size, checksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
	zio = zio_create(pio, vd->vdev_spa, 0, &blk, data, size, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
	    ZIO_TYPE_READ, priority, flags | ZIO_FLAG_PHYSICAL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
	    ZIO_STAGE_OPEN, ZIO_READ_PHYS_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
	zio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
	zio->io_offset = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
	 * Work off our copy of the bp so the caller can free it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
    void *data, int checksum, zio_done_func_t *done, void *private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
    int priority, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
	zio_block_tail_t *zbt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
	void *wbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
	zio_t *zio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
	blkptr_t blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
	zio_phys_bp_init(vd, &blk, offset, size, checksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
	zio = zio_create(pio, vd->vdev_spa, 0, &blk, data, size, done, private,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	    ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_PHYSICAL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
	    ZIO_STAGE_OPEN, ZIO_WRITE_PHYS_PIPELINE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
	zio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
	zio->io_offset = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
	zio->io_bp = &zio->io_bp_copy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
	zio->io_checksum = checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
	if (zio_checksum_table[checksum].ci_zbt) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
		 * zbt checksums are necessarily destructive -- they modify
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
		 * one word of the write buffer to hold the verifier/checksum.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
		 * Therefore, we must make a local copy in case the data is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
		 * being written to multiple places.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
		wbuf = zio_buf_alloc(size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
		bcopy(data, wbuf, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
		zio_push_transform(zio, wbuf, size, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
		zbt = (zio_block_tail_t *)((char *)wbuf + size) - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
		zbt->zbt_cksum = blk.blk_cksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
	return (zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
 * 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
   693
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
zio_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
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
   696
	void *data, uint64_t size, int type, int priority, int flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
	zio_done_func_t *done, void *private)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
	uint32_t pipeline = ZIO_VDEV_CHILD_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
	zio_t *cio;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
	if (type == ZIO_TYPE_READ && bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
		 * If we have the bp, then the child should perform the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
		 * checksum and the parent need not.  This pushes error
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
		 * detection as close to the leaves as possible and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
		 * eliminates redundant checksums in the interior nodes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
		pipeline |= 1U << ZIO_STAGE_CHECKSUM_VERIFY;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
		zio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
	cio = zio_create(zio, zio->io_spa, zio->io_txg, bp, data, size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
	    done, private, type, priority,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
	    (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
   716
	    ZIO_STAGE_VDEV_IO_START - 1, pipeline);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
	cio->io_vd = vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	cio->io_offset = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
	return (cio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
 * Initiate I/O, either sync or async
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
zio_wait(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
	ASSERT(zio->io_stage == ZIO_STAGE_OPEN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	zio->io_waiter = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
	zio_next_stage_async(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   740
	mutex_enter(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
	while (zio->io_stalled != ZIO_STAGE_DONE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
		cv_wait(&zio->io_cv, &zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
	mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
	error = zio->io_error;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2082
diff changeset
   746
	mutex_destroy(&zio->io_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
	kmem_free(zio, sizeof (zio_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
zio_nowait(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
	zio_next_stage_async(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
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
 * I/O pipeline interlocks: parent/child dependency scoreboarding
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
zio_wait_for_children(zio_t *zio, uint32_t stage, uint64_t *countp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
	mutex_enter(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
	if (*countp == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
		ASSERT(zio->io_stalled == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
		mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
		zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
		zio->io_stalled = stage;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
		mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
zio_notify_parent(zio_t *zio, uint32_t stage, uint64_t *countp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
	zio_t *pio = zio->io_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	mutex_enter(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	if (pio->io_error == 0 && !(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
		pio->io_error = zio->io_error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	if (--*countp == 0 && pio->io_stalled == stage) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
		pio->io_stalled = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
		zio_next_stage_async(pio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
zio_wait_children_ready(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
	zio_wait_for_children(zio, ZIO_STAGE_WAIT_CHILDREN_READY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	    &zio->io_children_notready);
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
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
zio_wait_children_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
	zio_wait_for_children(zio, ZIO_STAGE_WAIT_CHILDREN_DONE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
	    &zio->io_children_notdone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
zio_ready(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
	zio_t *pio = zio->io_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
	if (pio != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
		zio_notify_parent(zio, ZIO_STAGE_WAIT_CHILDREN_READY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
		    &pio->io_children_notready);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	if (zio->io_bp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
		zio->io_bp_copy = *zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
zio_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
	zio_t *pio = zio->io_parent;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
	spa_t *spa = zio->io_spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
	ASSERT(zio->io_children_notready == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
	ASSERT(zio->io_children_notdone == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
	if (bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   835
		ASSERT(bp->blk_pad[0] == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   836
		ASSERT(bp->blk_pad[1] == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   837
		ASSERT(bp->blk_pad[2] == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
		ASSERT(bcmp(bp, &zio->io_bp_copy, sizeof (blkptr_t)) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
		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
   840
		    !(zio->io_flags & ZIO_FLAG_IO_REPAIR)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
			ASSERT(!BP_SHOULD_BYTESWAP(bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   842
			if (zio->io_ndvas != 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   843
				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
   844
			ASSERT(BP_COUNT_GANG(bp) == 0 ||
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
   845
			    (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
   846
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
	if (vd != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
		vdev_stat_update(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
	if (zio->io_error) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   853
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   854
		 * If this I/O is attached to a particular vdev,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   855
		 * generate an error message describing the I/O failure
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   856
		 * at the block level.  We ignore these errors if the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   857
		 * device is currently unavailable.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   858
		 */
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   859
		if (zio->io_error != ECKSUM && vd != NULL && !vdev_is_dead(vd))
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   860
			zfs_ereport_post(FM_EREPORT_ZFS_IO,
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
   861
			    zio->io_spa, vd, zio, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   863
		if ((zio->io_error == EIO ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   864
		    !(zio->io_flags & ZIO_FLAG_SPECULATIVE)) &&
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   865
		    zio->io_logical == zio) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   866
			/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   867
			 * For root I/O requests, tell the SPA to log the error
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   868
			 * appropriately.  Also, generate a logical data
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   869
			 * ereport.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   870
			 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   871
			spa_log_error(zio->io_spa, zio);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   872
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   873
			zfs_ereport_post(FM_EREPORT_ZFS_DATA,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   874
			    zio->io_spa, NULL, zio, 0, 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   875
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   877
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   878
		 * For I/O requests that cannot fail, panic appropriately.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   879
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   880
		if (!(zio->io_flags & ZIO_FLAG_CANFAIL)) {
3459
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   881
			char *blkbuf;
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   882
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   883
			blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_NOSLEEP);
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   884
			if (blkbuf) {
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   885
				sprintf_blkptr(blkbuf, BP_SPRINTF_LEN,
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   886
				    bp ? bp : &zio->io_bp_copy);
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   887
			}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   888
			panic("ZFS: %s (%s on %s off %llx: zio %p %s): error "
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   889
			    "%d", zio->io_error == ECKSUM ?
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   890
			    "bad checksum" : "I/O failure",
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   891
			    zio_type_name[zio->io_type],
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   892
			    vdev_description(vd),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   893
			    (u_longlong_t)zio->io_offset,
3459
358b6bdb15b6 6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents: 3290
diff changeset
   894
			    zio, blkbuf ? blkbuf : "", zio->io_error);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   895
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
	zio_clear_transform_stack(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
	if (zio->io_done)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
		zio->io_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
	ASSERT(zio->io_delegate_list == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
	ASSERT(zio->io_delegate_next == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
	if (pio != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
		zio_t *next, *prev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
		mutex_enter(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
		next = zio->io_sibling_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
		prev = zio->io_sibling_prev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
		if (next != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
			next->io_sibling_prev = prev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   913
		if (prev != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
			prev->io_sibling_next = next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
		if (pio->io_child == zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
			pio->io_child = next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
		mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
		zio_notify_parent(zio, ZIO_STAGE_WAIT_CHILDREN_DONE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
		    &pio->io_children_notdone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   923
	/*
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   924
	 * Note: this I/O is now done, and will shortly be
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   925
	 * kmem_free()'d, so there is no need to clear this (or any
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   926
	 * other) flag.
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   927
	 */
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
   928
	if (zio->io_flags & ZIO_FLAG_CONFIG_GRABBED)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
   929
		spa_config_exit(spa, zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
	if (zio->io_waiter != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
		mutex_enter(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
		ASSERT(zio->io_stage == ZIO_STAGE_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
		zio->io_stalled = zio->io_stage;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
		cv_broadcast(&zio->io_cv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
		mutex_exit(&zio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
		kmem_free(zio, sizeof (zio_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
 * Compression support
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
zio_write_compress(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
	int compress = zio->io_compress;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
	void *cbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
	uint64_t lsize = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
	uint64_t csize = lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
	uint64_t cbufsize = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
	int pass;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
	if (bp->blk_birth == zio->io_txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
		 * We're rewriting an existing block, which means we're
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
		 * working on behalf of spa_sync().  For spa_sync() to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
		 * converge, it must eventually be the case that we don't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
		 * have to allocate new blocks.  But compression changes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
		 * the blocksize, which forces a reallocate, and makes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
		 * convergence take longer.  Therefore, after the first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
		 * few passes, stop compressing to ensure convergence.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
		pass = spa_sync_pass(zio->io_spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
		if (pass > zio_sync_pass.zp_dontcompress)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
			compress = ZIO_COMPRESS_OFF;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
		ASSERT(BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
		pass = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
	if (compress != ZIO_COMPRESS_OFF)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
		if (!zio_compress_data(compress, zio->io_data, zio->io_size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
		    &cbuf, &csize, &cbufsize))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
			compress = ZIO_COMPRESS_OFF;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
	if (compress != ZIO_COMPRESS_OFF && csize != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
		zio_push_transform(zio, cbuf, csize, cbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
	 * The final pass of spa_sync() must be all rewrites, but the first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
	 * few passes offer a trade-off: allocating blocks defers convergence,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
	 * but newly allocated blocks are sequential, so they can be written
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
	 * to disk faster.  Therefore, we allow the first few passes of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
	 * spa_sync() to reallocate new blocks, but force rewrites after that.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
	 * There should only be a handful of blocks after pass 1 in any case.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
	if (bp->blk_birth == zio->io_txg && BP_GET_PSIZE(bp) == csize &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
	    pass > zio_sync_pass.zp_rewrite) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
		ASSERT(csize != 0);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   995
		BP_SET_LSIZE(bp, lsize);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   996
		BP_SET_COMPRESS(bp, compress);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
		zio->io_pipeline = ZIO_REWRITE_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
		if (bp->blk_birth == zio->io_txg) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
			ASSERT3U(BP_GET_LSIZE(bp), ==, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
			bzero(bp, sizeof (blkptr_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
		if (csize == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
			BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
			zio->io_pipeline = ZIO_WAIT_FOR_CHILDREN_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1006
		} else {
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1007
			ASSERT3U(BP_GET_NDVAS(bp), ==, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
			BP_SET_LSIZE(bp, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
			BP_SET_PSIZE(bp, csize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
			BP_SET_COMPRESS(bp, compress);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
			zio->io_pipeline = ZIO_WRITE_ALLOCATE_PIPELINE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
zio_read_decompress(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1020
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
	void *data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
	uint64_t size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
	uint64_t bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
	int compress = BP_GET_COMPRESS(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	ASSERT(compress != ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
	zio_pop_transform(zio, &data, &size, &bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
	if (zio_decompress_data(compress, data, size,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
	    zio->io_data, zio->io_size))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
		zio->io_error = EIO;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
	zio_buf_free(data, bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
 * Gang block support
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
zio_gang_pipeline(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
	 * By default, the pipeline assumes that we're dealing with a gang
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
	 * block.  If we're not, strip out any gang-specific stages.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
	 */
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1052
	if (!BP_IS_GANG(zio->io_bp))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
		zio->io_pipeline &= ~ZIO_GANG_STAGES;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
zio_gang_byteswap(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1060
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
	ASSERT(zio->io_size == SPA_GANGBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
	if (BP_SHOULD_BYTESWAP(zio->io_bp))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
		byteswap_uint64_array(zio->io_data, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
zio_get_gang_header(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
	uint64_t gsize = SPA_GANGBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
	void *gbuf = zio_buf_alloc(gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1074
	ASSERT(BP_IS_GANG(bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
	zio_push_transform(zio, gbuf, gsize, gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
	zio_nowait(zio_create(zio, zio->io_spa, bp->blk_birth, bp, gbuf, gsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
	    NULL, NULL, ZIO_TYPE_READ, zio->io_priority,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	    zio->io_flags & ZIO_FLAG_GANG_INHERIT,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
	    ZIO_STAGE_OPEN, ZIO_READ_PIPELINE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
	zio_wait_children_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
zio_read_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	uint64_t gsize, gbufsize, loff, lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1093
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
	for (loff = 0, i = 0; loff != zio->io_size; loff += lsize, i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
		lsize = BP_GET_PSIZE(gbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
		ASSERT(BP_GET_COMPRESS(gbp) == ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
		ASSERT3U(lsize, ==, BP_GET_LSIZE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
		ASSERT3U(loff + lsize, <=, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
		ASSERT(i < SPA_GBH_NBLKPTRS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
		ASSERT(!BP_IS_HOLE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
		zio_nowait(zio_read(zio, zio->io_spa, gbp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
		    (char *)zio->io_data + loff, lsize, NULL, NULL,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1110
		    zio->io_priority, zio->io_flags & ZIO_FLAG_GANG_INHERIT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1111
		    &zio->io_bookmark));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
	zio_buf_free(gbh, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
	zio_wait_children_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
zio_rewrite_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
	uint64_t gsize, gbufsize, loff, lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1125
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1126
	ASSERT3U(zio->io_size, ==, SPA_GANGBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1127
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1128
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1129
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1131
	ASSERT(gsize == gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
	for (loff = 0, i = 0; loff != zio->io_size; loff += lsize, i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
		lsize = BP_GET_PSIZE(gbp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
		ASSERT(BP_GET_COMPRESS(gbp) == ZIO_COMPRESS_OFF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
		ASSERT3U(lsize, ==, BP_GET_LSIZE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
		ASSERT3U(loff + lsize, <=, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
		ASSERT(i < SPA_GBH_NBLKPTRS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
		ASSERT(!BP_IS_HOLE(gbp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
		zio_nowait(zio_rewrite(zio, zio->io_spa, zio->io_checksum,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
		    zio->io_txg, gbp, (char *)zio->io_data + loff, lsize,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1145
		    NULL, NULL, zio->io_priority, zio->io_flags,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1146
		    &zio->io_bookmark));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
	zio_push_transform(zio, gbh, gsize, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
	zio_wait_children_ready(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
zio_free_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
	uint64_t gsize, gbufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1160
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
	for (i = 0; i < SPA_GBH_NBLKPTRS; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
		if (BP_IS_HOLE(gbp))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
		zio_nowait(zio_free(zio, zio->io_spa, zio->io_txg,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
		    gbp, NULL, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
	zio_buf_free(gbh, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
zio_claim_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
	zio_gbh_phys_t *gbh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
	uint64_t gsize, gbufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1185
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
	zio_gang_byteswap(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
	zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
	for (i = 0; i < SPA_GBH_NBLKPTRS; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
		blkptr_t *gbp = &gbh->zg_blkptr[i];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
		if (BP_IS_HOLE(gbp))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
		zio_nowait(zio_claim(zio, zio->io_spa, zio->io_txg,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
		    gbp, NULL, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
	zio_buf_free(gbh, gbufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
zio_write_allocate_gang_member_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	zio_t *pio = zio->io_parent;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1206
	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
  1207
	dva_t *pdva = pio->io_bp->blk_dva;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
	uint64_t asize;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1209
	int d;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1211
	ASSERT3U(pio->io_ndvas, ==, zio->io_ndvas);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1212
	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
  1213
	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
  1214
	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
  1215
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
	mutex_enter(&pio->io_lock);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1217
	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
  1218
		ASSERT(DVA_GET_GANG(&pdva[d]));
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1219
		asize = DVA_GET_ASIZE(&pdva[d]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1220
		asize += DVA_GET_ASIZE(&cdva[d]);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1221
		DVA_SET_ASIZE(&pdva[d], asize);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1222
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
	mutex_exit(&pio->io_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
zio_write_allocate_gang_members(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
	blkptr_t *bp = zio->io_bp;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1230
	dva_t *dva = bp->blk_dva;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1231
	spa_t *spa = zio->io_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
	zio_gbh_phys_t *gbh;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1233
	uint64_t txg = zio->io_txg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
	uint64_t resid = zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
	uint64_t maxalloc = P2ROUNDUP(zio->io_size >> 1, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
	uint64_t gsize, loff, lsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
	uint32_t gbps_left;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1238
	int ndvas = zio->io_ndvas;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1239
	int gbh_ndvas = MIN(ndvas + 1, spa_max_replication(spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
	int error;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1241
	int i, d;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1243
	gsize = SPA_GANGBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1244
	gbps_left = SPA_GBH_NBLKPTRS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1245
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1246
	error = metaslab_alloc(spa, gsize, bp, gbh_ndvas, txg, NULL, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1247
	if (error == ENOSPC)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
		panic("can't allocate gang block header");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1251
	for (d = 0; d < gbh_ndvas; d++)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1252
		DVA_SET_GANG(&dva[d], 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1254
	bp->blk_birth = txg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1256
	gbh = zio_buf_alloc(gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1257
	bzero(gbh, gsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1258
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1259
	/* We need to test multi-level gang blocks */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1260
	if (maxalloc >= zio_gang_bang && (lbolt & 0x1) == 0)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1261
		maxalloc = MAX(maxalloc >> 2, SPA_MINBLOCKSIZE);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1262
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
	for (loff = 0, i = 0; loff != zio->io_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1264
	    loff += lsize, resid -= lsize, gbps_left--, i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1265
		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
  1266
		dva = gbp->blk_dva;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
		ASSERT(gbps_left != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
		maxalloc = MIN(maxalloc, resid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
		while (resid <= maxalloc * gbps_left) {
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1272
			error = metaslab_alloc(spa, maxalloc, gbp, ndvas,
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1273
			    txg, bp, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
			if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1276
			ASSERT3U(error, ==, ENOSPC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
			if (maxalloc == SPA_MINBLOCKSIZE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1278
				panic("really out of space");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1279
			maxalloc = P2ROUNDUP(maxalloc >> 1, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1280
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1281
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1282
		if (resid <= maxalloc * gbps_left) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1283
			lsize = maxalloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1284
			BP_SET_LSIZE(gbp, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1285
			BP_SET_PSIZE(gbp, lsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1286
			BP_SET_COMPRESS(gbp, ZIO_COMPRESS_OFF);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1287
			gbp->blk_birth = txg;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1288
			zio_nowait(zio_rewrite(zio, spa,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1289
			    zio->io_checksum, txg, gbp,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1290
			    (char *)zio->io_data + loff, lsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
			    zio_write_allocate_gang_member_done, NULL,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1292
			    zio->io_priority, zio->io_flags,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1293
			    &zio->io_bookmark));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1294
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1295
			lsize = P2ROUNDUP(resid / gbps_left, SPA_MINBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1296
			ASSERT(lsize != SPA_MINBLOCKSIZE);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1297
			zio_nowait(zio_write_allocate(zio, spa,
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1298
			    zio->io_checksum, txg, gbp,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1299
			    (char *)zio->io_data + loff, lsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1300
			    zio_write_allocate_gang_member_done, NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1301
			    zio->io_priority, zio->io_flags));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1302
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1303
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1304
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1305
	ASSERT(resid == 0 && loff == zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1307
	zio->io_pipeline |= 1U << ZIO_STAGE_GANG_CHECKSUM_GENERATE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
	zio_push_transform(zio, gbh, gsize, gsize);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1310
	/*
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1311
	 * As much as we'd like this to be zio_wait_children_ready(),
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1312
	 * 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
  1313
	 * 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
  1314
	 * to be stable.
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1315
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
	zio_wait_children_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1317
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1321
 * Allocate and free blocks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
zio_dva_allocate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1326
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
	ASSERT(BP_IS_HOLE(bp));
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1331
	ASSERT3U(BP_GET_NDVAS(bp), ==, 0);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1332
	ASSERT3U(zio->io_ndvas, >, 0);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1333
	ASSERT3U(zio->io_ndvas, <=, spa_max_replication(zio->io_spa));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1334
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1335
	/* For testing, make some blocks above a certain size be gang blocks */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
	if (zio->io_size >= zio_gang_bang && (lbolt & 0x3) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
		zio_write_allocate_gang_members(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1340
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1341
	ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1342
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1343
	error = metaslab_alloc(zio->io_spa, zio->io_size, bp, zio->io_ndvas,
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1344
	    zio->io_txg, NULL, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1346
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1347
		bp->blk_birth = zio->io_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1348
	} else if (error == ENOSPC) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
		if (zio->io_size == SPA_MINBLOCKSIZE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1350
			panic("really, truly out of space");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1351
		zio_write_allocate_gang_members(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1352
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1353
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1354
		zio->io_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1356
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1357
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1358
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
zio_dva_free(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  1364
	metaslab_free(zio->io_spa, bp, zio->io_txg, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1365
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1366
	BP_ZERO(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1368
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1369
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1370
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1371
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
zio_dva_claim(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1373
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  1374
	zio->io_error = metaslab_claim(zio->io_spa, zio->io_bp, zio->io_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1376
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1377
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1378
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1379
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1381
 * Read and write to physical devices
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1382
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1383
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1385
static void
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1386
zio_vdev_io_start(zio_t *zio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
	vdev_t *vd = zio->io_vd;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1389
	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
  1390
	blkptr_t *bp = zio->io_bp;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1391
	uint64_t align;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1393
	if (vd == NULL) {
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1394
		/* The mirror_ops handle multiple DVAs in a single BP */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1395
		vdev_mirror_ops.vdev_op_io_start(zio);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1396
		return;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1397
	}
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1398
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1399
	align = 1ULL << tvd->vdev_ashift;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1400
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1401
	if (zio->io_retries == 0 && vd == tvd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
		zio->io_flags |= ZIO_FLAG_FAILFAST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1404
	if (!(zio->io_flags & ZIO_FLAG_PHYSICAL) &&
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1405
	    vd->vdev_children == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
		zio->io_flags |= ZIO_FLAG_PHYSICAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
		zio->io_offset += VDEV_LABEL_START_SIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1410
	if (P2PHASE(zio->io_size, align) != 0) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1411
		uint64_t asize = P2ROUNDUP(zio->io_size, align);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1412
		char *abuf = zio_buf_alloc(asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1413
		ASSERT(vd == tvd);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1414
		if (zio->io_type == ZIO_TYPE_WRITE) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1415
			bcopy(zio->io_data, abuf, zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1416
			bzero(abuf + zio->io_size, asize - zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1417
		}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1418
		zio_push_transform(zio, abuf, asize, asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1419
		ASSERT(!(zio->io_flags & ZIO_FLAG_SUBBLOCK));
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1420
		zio->io_flags |= ZIO_FLAG_SUBBLOCK;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1421
	}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1422
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1423
	ASSERT(P2PHASE(zio->io_offset, align) == 0);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1424
	ASSERT(P2PHASE(zio->io_size, align) == 0);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1425
	ASSERT(bp == NULL ||
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1426
	    P2ROUNDUP(ZIO_GET_IOSIZE(zio), align) == zio->io_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
	ASSERT(zio->io_type != ZIO_TYPE_WRITE || (spa_mode & FWRITE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
	vdev_io_start(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
	/* zio_next_stage_async() gets called from io completion interrupt */
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
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
zio_vdev_io_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
{
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1437
	if (zio->io_vd == NULL)
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1438
		/* The mirror_ops handle multiple DVAs in a single BP */
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1439
		vdev_mirror_ops.vdev_op_io_done(zio);
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1440
	else
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1441
		vdev_io_done(zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
/* XXPOLICY */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1445
boolean_t
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
zio_should_retry(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1447
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1448
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1449
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1450
	if (zio->io_error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
	if (zio->io_delegate_list != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
		return (B_FALSE);
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1454
	if (vd && vd != vd->vdev_top)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
	if (zio->io_flags & ZIO_FLAG_DONT_RETRY)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1457
		return (B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1458
	if (zio->io_retries > 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1459
		return (B_FALSE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1460
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1461
	return (B_TRUE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1462
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1463
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
zio_vdev_io_assess(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1467
	vdev_t *vd = zio->io_vd;
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1468
	vdev_t *tvd = vd ? vd->vdev_top : NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1470
	ASSERT(zio->io_vsd == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1471
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1472
	if (zio->io_flags & ZIO_FLAG_SUBBLOCK) {
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1473
		void *abuf;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1474
		uint64_t asize;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1475
		ASSERT(vd == tvd);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1476
		zio_pop_transform(zio, &abuf, &asize, &asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1477
		if (zio->io_type == ZIO_TYPE_READ)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1478
			bcopy(abuf, zio->io_data, zio->io_size);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1479
		zio_buf_free(abuf, asize);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1480
		zio->io_flags &= ~ZIO_FLAG_SUBBLOCK;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1481
	}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1482
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1483
	if (zio_injection_enabled && !zio->io_error)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1484
		zio->io_error = zio_handle_fault_injection(zio, EIO);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
	 * If the I/O failed, determine whether we should attempt to retry it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
	/* XXPOLICY */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
	if (zio_should_retry(zio)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
		ASSERT(tvd == vd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
		zio->io_retries++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
		zio->io_error = 0;
3463
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
  1495
		zio->io_flags &= ZIO_FLAG_VDEV_INHERIT |
5007f15d5674 6480626 contention on spa_config_lock on niagra
ahrens
parents: 3459
diff changeset
  1496
		    ZIO_FLAG_CONFIG_GRABBED;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
		/* XXPOLICY */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
		zio->io_flags &= ~ZIO_FLAG_FAILFAST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
		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
  1500
		zio->io_stage = ZIO_STAGE_VDEV_IO_START - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
		dprintf("retry #%d for %s to %s offset %llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
		    zio->io_retries, zio_type_name[zio->io_type],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
		    vdev_description(vd), zio->io_offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1506
		zio_next_stage_async(zio);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1507
		return;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1508
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1510
	if (zio->io_error != 0 && zio->io_error != ECKSUM &&
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1511
	    !(zio->io_flags & ZIO_FLAG_SPECULATIVE) && vd) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1512
		/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1513
		 * Poor man's hotplug support.  Even if we're done retrying this
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1514
		 * I/O, try to reopen the vdev to see if it's still attached.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1515
		 * To avoid excessive thrashing, we only try it once a minute.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1516
		 * This also has the effect of detecting when missing devices
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1517
		 * have come back, by polling the device once a minute.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1518
		 *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1519
		 * We need to do this asynchronously because we can't grab
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1520
		 * all the necessary locks way down here.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1521
		 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1522
		if (gethrtime() - vd->vdev_last_try > 60ULL * NANOSEC) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1523
			vd->vdev_last_try = gethrtime();
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1524
			tvd->vdev_reopen_wanted = 1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1525
			spa_async_request(vd->vdev_spa, SPA_ASYNC_REOPEN);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1526
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1527
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1528
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1529
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1530
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1531
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1532
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1533
zio_vdev_io_reissue(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1534
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1535
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
	ASSERT(zio->io_error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1537
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1538
	zio->io_stage--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1539
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1540
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1541
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1542
zio_vdev_io_redone(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1544
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1545
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1546
	zio->io_stage--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1550
zio_vdev_io_bypass(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1551
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1552
	ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1553
	ASSERT(zio->io_error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1554
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1555
	zio->io_flags |= ZIO_FLAG_IO_BYPASS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1556
	zio->io_stage = ZIO_STAGE_VDEV_IO_ASSESS - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1557
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1558
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1559
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1560
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1561
 * Generate and verify checksums
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1562
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
zio_checksum_generate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
	int checksum = zio->io_checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
	blkptr_t *bp = zio->io_bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
	ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
	BP_SET_CHECKSUM(bp, checksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
	BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
	zio_checksum(checksum, &bp->blk_cksum, zio->io_data, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1576
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
zio_gang_checksum_generate(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
	zio_cksum_t zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
	zio_gbh_phys_t *gbh = zio->io_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1586
	ASSERT(BP_IS_GANG(zio->io_bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
	ASSERT3U(zio->io_size, ==, SPA_GANGBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
	zio_set_gang_verifier(zio, &gbh->zg_tail.zbt_cksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
	zio_checksum(ZIO_CHECKSUM_GANG_HEADER, &zc, zio->io_data, zio->io_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1594
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
zio_checksum_verify(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
	if (zio->io_bp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
		zio->io_error = zio_checksum_error(zio);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1601
		if (zio->io_error && !(zio->io_flags & ZIO_FLAG_SPECULATIVE))
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1602
			zfs_ereport_post(FM_EREPORT_ZFS_CHECKSUM,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1603
			    zio->io_spa, zio->io_vd, zio, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1604
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1605
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1606
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1608
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1609
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1610
 * Called by RAID-Z to ensure we don't compute the checksum twice.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
zio_checksum_verified(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
	zio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
 * Set the external verifier for a gang block based on stuff in the bp
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
{
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1624
	blkptr_t *bp = zio->io_bp;
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1625
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1626
	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
  1627
	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
  1628
	zcp->zc_word[2] = bp->blk_birth;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
	zcp->zc_word[3] = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1634
 * Define the pipeline
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1635
 * ==========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1636
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
typedef void zio_pipe_stage_t(zio_t *zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
zio_badop(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
	panic("Invalid I/O pipeline stage %u for zio %p", zio->io_stage, zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
zio_pipe_stage_t *zio_pipeline[ZIO_STAGE_DONE + 2] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
	zio_badop,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	zio_wait_children_ready,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
	zio_write_compress,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1649
	zio_checksum_generate,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
	zio_gang_pipeline,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1651
	zio_get_gang_header,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
	zio_rewrite_gang_members,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1653
	zio_free_gang_members,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
	zio_claim_gang_members,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1655
	zio_dva_allocate,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1656
	zio_dva_free,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1657
	zio_dva_claim,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1658
	zio_gang_checksum_generate,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
	zio_ready,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1660
	zio_vdev_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1661
	zio_vdev_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1662
	zio_vdev_io_assess,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1663
	zio_wait_children_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1664
	zio_checksum_verify,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1665
	zio_read_gang_members,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1666
	zio_read_decompress,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
	zio_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1668
	zio_badop
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1669
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1670
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1671
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1672
 * Move an I/O to the next stage of the pipeline and execute that stage.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1673
 * There's no locking on io_stage because there's no legitimate way for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1674
 * multiple threads to be attempting to process the same I/O.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1675
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1676
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
zio_next_stage(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1678
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
	uint32_t pipeline = zio->io_pipeline;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1680
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1681
	ASSERT(!MUTEX_HELD(&zio->io_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1682
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1683
	if (zio->io_error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1684
		dprintf("zio %p vdev %s offset %llx stage %d error %d\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1685
		    zio, vdev_description(zio->io_vd),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1686
		    zio->io_offset, zio->io_stage, zio->io_error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1687
		if (((1U << zio->io_stage) & ZIO_VDEV_IO_PIPELINE) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
			pipeline &= ZIO_ERROR_PIPELINE_MASK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1689
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
	while (((1U << ++zio->io_stage) & pipeline) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
		continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
	ASSERT(zio->io_stage <= ZIO_STAGE_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1695
	ASSERT(zio->io_stalled == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1696
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1697
	zio_pipeline[zio->io_stage](zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1698
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1699
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1700
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1701
zio_next_stage_async(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1702
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1703
	taskq_t *tq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
	uint32_t pipeline = zio->io_pipeline;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1705
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1706
	ASSERT(!MUTEX_HELD(&zio->io_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
	if (zio->io_error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
		dprintf("zio %p vdev %s offset %llx stage %d error %d\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
		    zio, vdev_description(zio->io_vd),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1711
		    zio->io_offset, zio->io_stage, zio->io_error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1712
		if (((1U << zio->io_stage) & ZIO_VDEV_IO_PIPELINE) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1713
			pipeline &= ZIO_ERROR_PIPELINE_MASK;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1714
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1715
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
	while (((1U << ++zio->io_stage) & pipeline) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1717
		continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
	ASSERT(zio->io_stage <= ZIO_STAGE_DONE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
	ASSERT(zio->io_stalled == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
	 * For performance, we'll probably want two sets of task queues:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
	 * per-CPU issue taskqs and per-CPU completion taskqs.  The per-CPU
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
	 * part is for read performance: since we have to make a pass over
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
	 * the data to checksum it anyway, we want to do this on the same CPU
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
	 * that issued the read, because (assuming CPU scheduling affinity)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1728
	 * that thread is probably still there.  Getting this optimization
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
	 * right avoids performance-hostile cache-to-cache transfers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1730
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1731
	 * Note that having two sets of task queues is also necessary for
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1732
	 * correctness: if all of the issue threads get bogged down waiting
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
	 * for dependent reads (e.g. metaslab freelist) to complete, then
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1734
	 * there won't be any threads available to service I/O completion
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
	 * interrupts.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
	if ((1U << zio->io_stage) & zio->io_async_stages) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1738
		if (zio->io_stage < ZIO_STAGE_VDEV_IO_DONE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1739
			tq = zio->io_spa->spa_zio_issue_taskq[zio->io_type];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1740
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
			tq = zio->io_spa->spa_zio_intr_taskq[zio->io_type];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
		(void) taskq_dispatch(tq,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
		    (task_func_t *)zio_pipeline[zio->io_stage], zio, TQ_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1744
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1745
		zio_pipeline[zio->io_stage](zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1746
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1747
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1749
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1750
 * Try to allocate an intent log block.  Return 0 on success, errno on failure.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1751
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1752
int
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1753
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
  1754
    uint64_t txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1755
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1756
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1757
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1758
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1759
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1760
	/*
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1761
	 * We were passed the previous log blocks dva_t in bp->blk_dva[0].
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1762
	 */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1763
	error = metaslab_alloc(spa, size, new_bp, 1, txg, old_bp, B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1764
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1765
	if (error == 0) {
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1766
		BP_SET_LSIZE(new_bp, size);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1767
		BP_SET_PSIZE(new_bp, size);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1768
		BP_SET_COMPRESS(new_bp, ZIO_COMPRESS_OFF);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1769
		BP_SET_CHECKSUM(new_bp, ZIO_CHECKSUM_ZILOG);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1770
		BP_SET_TYPE(new_bp, DMU_OT_INTENT_LOG);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1771
		BP_SET_LEVEL(new_bp, 0);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1772
		BP_SET_BYTEORDER(new_bp, ZFS_HOST_BYTEORDER);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2981
diff changeset
  1773
		new_bp->blk_birth = txg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1774
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1775
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1776
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1777
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1779
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1780
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1781
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
 * 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
  1783
 * nothing to do except metaslab_free() it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1784
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1785
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1786
zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1787
{
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1788
	ASSERT(!BP_IS_GANG(bp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1789
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1790
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  1792
	metaslab_free(spa, bp, txg, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1793
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 896
diff changeset
  1794
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
}