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