usr/src/uts/common/fs/zfs/zil.c
author Matthew Ahrens <Matthew.Ahrens@Sun.COM>
Mon, 30 Nov 2009 11:36:36 -0800
changeset 11209 462283cb4096
parent 11066 cebb50cbe4f9
child 11670 1d964fb5d948
permissions -rw-r--r--
6905188 panic: kernel heap corruption when doing "zfs rename -r"
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
1472
6d54521a5237 6381994 zfs_putpage() serializes I/O unnecessarily
perrin
parents: 1362
diff changeset
     5
 * Common Development and Distribution License (the "License").
6d54521a5237 6381994 zfs_putpage() serializes I/O unnecessarily
perrin
parents: 1362
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
8746
e1d96ca6808c 6796377 panic on rollback in space_map_add()
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8227
diff changeset
    22
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/arc.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/zil_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/vdev.h>
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
    37
#include <sys/dmu_tx.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 * The zfs intent log (ZIL) saves transaction records of system calls
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
 * that change the file system in memory with enough information
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * to be able to replay them. These are stored in memory until
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 * either the DMU transaction group (txg) commits them to the stable pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 * and they can be discarded, or they are flushed to the stable log
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 * (also in the pool) due to a fsync, O_DSYNC or other synchronous
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
 * requirement. In the event of a panic or power fail then those log
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
 * records (transactions) are replayed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
 * There is one ZIL per file system. Its on-disk (pool) format consists
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
 * of 3 parts:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 * 	- ZIL header
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 * 	- ZIL blocks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
 * 	- ZIL records
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
 * A log record holds a system call transaction. Log blocks can
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
 * hold many log records and the blocks are chained together.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 * Each ZIL block contains a block pointer (blkptr_t) to the next
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 * ZIL block in the chain. The ZIL header points to the first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * block in the chain. Note there is not a fixed place in the pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 * to hold blocks. They are dynamically allocated and freed as
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 * needed from the blocks available. Figure X shows the ZIL structure:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
/*
2986
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    66
 * This global ZIL switch affects all pools
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
int zil_disable = 0;	/* disable intent logging */
2986
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    69
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    70
/*
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    71
 * Tunable parameter for debugging or performance analysis.  Setting
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    72
 * zfs_nocacheflush will cause corruption on power loss if a volatile
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    73
 * out-of-order write cache is enabled.
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    74
 */
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    75
boolean_t zfs_nocacheflush = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
static kmem_cache_t *zil_lwb_cache;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10310
diff changeset
    79
static boolean_t zil_empty(zilog_t *zilog);
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10310
diff changeset
    80
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
static int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
    82
zil_bp_compare(const void *x1, const void *x2)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
    84
	const dva_t *dva1 = &((zil_bp_node_t *)x1)->zn_dva;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
    85
	const dva_t *dva2 = &((zil_bp_node_t *)x2)->zn_dva;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
	if (DVA_GET_VDEV(dva1) < DVA_GET_VDEV(dva2))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	if (DVA_GET_VDEV(dva1) > DVA_GET_VDEV(dva2))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	if (DVA_GET_OFFSET(dva1) < DVA_GET_OFFSET(dva2))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
	if (DVA_GET_OFFSET(dva1) > DVA_GET_OFFSET(dva2))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   101
zil_bp_tree_init(zilog_t *zilog)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   103
	avl_create(&zilog->zl_bp_tree, zil_bp_compare,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   104
	    sizeof (zil_bp_node_t), offsetof(zil_bp_node_t, zn_node));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
static void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   108
zil_bp_tree_fini(zilog_t *zilog)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   110
	avl_tree_t *t = &zilog->zl_bp_tree;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   111
	zil_bp_node_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	void *cookie = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	while ((zn = avl_destroy_nodes(t, &cookie)) != NULL)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   115
		kmem_free(zn, sizeof (zil_bp_node_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	avl_destroy(t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   120
int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   121
zil_bp_tree_add(zilog_t *zilog, const blkptr_t *bp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   123
	avl_tree_t *t = &zilog->zl_bp_tree;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   124
	const dva_t *dva = BP_IDENTITY(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   125
	zil_bp_node_t *zn;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	avl_index_t where;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	if (avl_find(t, dva, &where) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   131
	zn = kmem_alloc(sizeof (zil_bp_node_t), KM_SLEEP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	zn->zn_dva = *dva;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	avl_insert(t, zn, where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   138
static zil_header_t *
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   139
zil_header_in_syncing_context(zilog_t *zilog)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   140
{
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   141
	return ((zil_header_t *)zilog->zl_header);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   142
}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   143
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   144
static void
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   145
zil_init_log_chain(zilog_t *zilog, blkptr_t *bp)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   146
{
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   147
	zio_cksum_t *zc = &bp->blk_cksum;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   148
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   149
	zc->zc_word[ZIL_ZC_GUID_0] = spa_get_random(-1ULL);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   150
	zc->zc_word[ZIL_ZC_GUID_1] = spa_get_random(-1ULL);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   151
	zc->zc_word[ZIL_ZC_OBJSET] = dmu_objset_id(zilog->zl_os);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   152
	zc->zc_word[ZIL_ZC_SEQ] = 1ULL;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   153
}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   154
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   156
 * Read a log block and make sure it's valid.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
static int
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   159
zil_read_log_block(zilog_t *zilog, const blkptr_t *bp, blkptr_t *nbp, void *dst)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   161
	enum zio_flag zio_flags = ZIO_FLAG_CANFAIL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   162
	uint32_t aflags = ARC_WAIT;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   163
	arc_buf_t *abuf = NULL;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   164
	zbookmark_t zb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   167
	if (zilog->zl_header->zh_claim_txg == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   168
		zio_flags |= ZIO_FLAG_SPECULATIVE | ZIO_FLAG_SCRUB;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   169
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   170
	if (!(zilog->zl_header->zh_flags & ZIL_CLAIM_LR_SEQ_VALID))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   171
		zio_flags |= ZIO_FLAG_SPECULATIVE;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   172
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   173
	SET_BOOKMARK(&zb, bp->blk_cksum.zc_word[ZIL_ZC_OBJSET],
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   174
	    ZB_ZIL_OBJECT, ZB_ZIL_LEVEL, bp->blk_cksum.zc_word[ZIL_ZC_SEQ]);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   175
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   176
	error = arc_read_nolock(NULL, zilog->zl_spa, bp, arc_getbuf_func, &abuf,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   177
	    ZIO_PRIORITY_SYNC_READ, zio_flags, &aflags, &zb);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   178
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   179
	if (error == 0) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   180
		char *data = abuf->b_data;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   181
		uint64_t size = BP_GET_LSIZE(bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   182
		zil_trailer_t *ztp = (zil_trailer_t *)(data + size) - 1;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   183
		zio_cksum_t cksum = bp->blk_cksum;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   184
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   185
		bcopy(data, dst, size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   186
		*nbp = ztp->zit_next_blk;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   187
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   188
		/*
7522
555dd20e19cf 6744440 zloop/ztest fails: "zdb: can't open ztest: No such device or address"
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7294
diff changeset
   189
		 * Validate the checksummed log block.
555dd20e19cf 6744440 zloop/ztest fails: "zdb: can't open ztest: No such device or address"
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7294
diff changeset
   190
		 *
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   191
		 * Sequence numbers should be... sequential.  The checksum
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   192
		 * verifier for the next block should be bp's checksum plus 1.
7522
555dd20e19cf 6744440 zloop/ztest fails: "zdb: can't open ztest: No such device or address"
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7294
diff changeset
   193
		 *
555dd20e19cf 6744440 zloop/ztest fails: "zdb: can't open ztest: No such device or address"
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7294
diff changeset
   194
		 * Also check the log chain linkage and size used.
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   195
		 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   196
		cksum.zc_word[ZIL_ZC_SEQ]++;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   197
7522
555dd20e19cf 6744440 zloop/ztest fails: "zdb: can't open ztest: No such device or address"
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7294
diff changeset
   198
		if (bcmp(&cksum, &ztp->zit_next_blk.blk_cksum,
555dd20e19cf 6744440 zloop/ztest fails: "zdb: can't open ztest: No such device or address"
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7294
diff changeset
   199
		    sizeof (cksum)) || BP_IS_HOLE(&ztp->zit_next_blk) ||
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   200
		    (ztp->zit_nused > (size - sizeof (zil_trailer_t))))
7522
555dd20e19cf 6744440 zloop/ztest fails: "zdb: can't open ztest: No such device or address"
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7294
diff changeset
   201
			error = ECKSUM;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   202
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   203
		VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   206
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   207
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   208
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   209
/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   210
 * Read a TX_WRITE log data block.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   211
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   212
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   213
zil_read_log_data(zilog_t *zilog, const lr_write_t *lr, void *wbuf)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   214
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   215
	enum zio_flag zio_flags = ZIO_FLAG_CANFAIL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   216
	const blkptr_t *bp = &lr->lr_blkptr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   217
	uint32_t aflags = ARC_WAIT;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   218
	arc_buf_t *abuf = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   219
	zbookmark_t zb;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   220
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   221
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   222
	if (BP_IS_HOLE(bp)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   223
		if (wbuf != NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   224
			bzero(wbuf, MAX(BP_GET_LSIZE(bp), lr->lr_length));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   225
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   226
	}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   227
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   228
	if (zilog->zl_header->zh_claim_txg == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   229
		zio_flags |= ZIO_FLAG_SPECULATIVE | ZIO_FLAG_SCRUB;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   230
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   231
	SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os), lr->lr_foid,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   232
	    ZB_ZIL_LEVEL, lr->lr_offset / BP_GET_LSIZE(bp));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   233
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   234
	error = arc_read_nolock(NULL, zilog->zl_spa, bp, arc_getbuf_func, &abuf,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   235
	    ZIO_PRIORITY_SYNC_READ, zio_flags, &aflags, &zb);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   236
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   237
	if (error == 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   238
		if (wbuf != NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   239
			bcopy(abuf->b_data, wbuf, arc_buf_size(abuf));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   240
		(void) arc_buf_remove_ref(abuf, &abuf);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   241
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   243
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
 * Parse the intent log, and call parse_func for each valid record within.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   249
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
    zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   253
	const zil_header_t *zh = zilog->zl_header;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   254
	boolean_t claimed = !!zh->zh_claim_txg;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   255
	uint64_t claim_blk_seq = claimed ? zh->zh_claim_blk_seq : UINT64_MAX;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   256
	uint64_t claim_lr_seq = claimed ? zh->zh_claim_lr_seq : UINT64_MAX;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   257
	uint64_t max_blk_seq = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   258
	uint64_t max_lr_seq = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   259
	uint64_t blk_count = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   260
	uint64_t lr_count = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   261
	blkptr_t blk, next_blk;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	char *lrbuf, *lrp;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   263
	int error = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   265
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   266
	 * Old logs didn't record the maximum zh_claim_lr_seq.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   267
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   268
	if (!(zh->zh_flags & ZIL_CLAIM_LR_SEQ_VALID))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   269
		claim_lr_seq = UINT64_MAX;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	 * Starting at the block pointed to by zh_log we read the log chain.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	 * For each block in the chain we strongly check that block to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	 * ensure its validity.  We stop when an invalid block is found.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	 * For each block pointer in the chain we call parse_blk_func().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	 * For each record in each valid block we call parse_lr_func().
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   277
	 * If the log has been claimed, stop if we encounter a sequence
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   278
	 * number greater than the highest claimed sequence number.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   280
	lrbuf = zio_buf_alloc(SPA_MAXBLOCKSIZE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   281
	zil_bp_tree_init(zilog);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   282
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   283
	for (blk = zh->zh_log; !BP_IS_HOLE(&blk); blk = next_blk) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   284
		zil_trailer_t *ztp =
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   285
		    (zil_trailer_t *)(lrbuf + BP_GET_LSIZE(&blk)) - 1;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   286
		uint64_t blk_seq = blk.blk_cksum.zc_word[ZIL_ZC_SEQ];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   287
		int reclen;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   288
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   289
		if (blk_seq > claim_blk_seq)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   290
			break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   291
		if ((error = parse_blk_func(zilog, &blk, arg, txg)) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   292
			break;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   293
		ASSERT(max_blk_seq < blk_seq);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   294
		max_blk_seq = blk_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   295
		blk_count++;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   296
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   297
		if (max_lr_seq == claim_lr_seq && max_blk_seq == claim_blk_seq)
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   298
			break;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   299
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   300
		error = zil_read_log_block(zilog, &blk, &next_blk, lrbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
		if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
		for (lrp = lrbuf; lrp < lrbuf + ztp->zit_nused; lrp += reclen) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
			lr_t *lr = (lr_t *)lrp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
			reclen = lr->lrc_reclen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
			ASSERT3U(reclen, >=, sizeof (lr_t));
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   308
			if (lr->lrc_seq > claim_lr_seq)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   309
				goto done;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   310
			if ((error = parse_lr_func(zilog, lr, arg, txg)) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   311
				goto done;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   312
			ASSERT(max_lr_seq < lr->lrc_seq);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   313
			max_lr_seq = lr->lrc_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   314
			lr_count++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   317
done:
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   318
	zilog->zl_parse_error = error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   319
	zilog->zl_parse_blk_seq = max_blk_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   320
	zilog->zl_parse_lr_seq = max_lr_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   321
	zilog->zl_parse_blk_count = blk_count;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   322
	zilog->zl_parse_lr_count = lr_count;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   323
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   324
	ASSERT(!claimed || !(zh->zh_flags & ZIL_CLAIM_LR_SEQ_VALID) ||
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   325
	    (max_blk_seq == claim_blk_seq && max_lr_seq == claim_lr_seq));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   326
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   327
	zil_bp_tree_fini(zilog);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   328
	zio_buf_free(lrbuf, SPA_MAXBLOCKSIZE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   329
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   330
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   331
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   332
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   333
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   334
zil_claim_log_block(zilog_t *zilog, blkptr_t *bp, void *tx, uint64_t first_txg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   335
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   336
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   337
	 * Claim log block if not already committed and not already claimed.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   338
	 * If tx == NULL, just verify that the block is claimable.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   339
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   340
	if (bp->blk_birth < first_txg || zil_bp_tree_add(zilog, bp) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   341
		return (0);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   342
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   343
	return (zio_wait(zio_claim(NULL, zilog->zl_spa,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   344
	    tx == NULL ? 0 : first_txg, bp, spa_claim_notify, NULL,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   345
	    ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE | ZIO_FLAG_SCRUB)));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   346
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   347
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   348
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   349
zil_claim_log_record(zilog_t *zilog, lr_t *lrc, void *tx, uint64_t first_txg)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   350
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   351
	lr_write_t *lr = (lr_write_t *)lrc;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   352
	int error;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   353
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   354
	if (lrc->lrc_txtype != TX_WRITE)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   355
		return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   356
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   357
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   358
	 * If the block is not readable, don't claim it.  This can happen
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   359
	 * in normal operation when a log block is written to disk before
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   360
	 * some of the dmu_sync() blocks it points to.  In this case, the
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   361
	 * transaction cannot have been committed to anyone (we would have
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   362
	 * waited for all writes to be stable first), so it is semantically
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   363
	 * correct to declare this the end of the log.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   364
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   365
	if (lr->lr_blkptr.blk_birth >= first_txg &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   366
	    (error = zil_read_log_data(zilog, lr, NULL)) != 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   367
		return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   368
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   369
	return (zil_claim_log_block(zilog, &lr->lr_blkptr, tx, first_txg));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
/* ARGSUSED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   373
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   374
zil_free_log_block(zilog_t *zilog, blkptr_t *bp, void *tx, uint64_t claim_txg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   376
	zio_free_zil(zilog->zl_spa, dmu_tx_get_txg(tx), bp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   378
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   381
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
zil_free_log_record(zilog_t *zilog, lr_t *lrc, void *tx, uint64_t claim_txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   384
	lr_write_t *lr = (lr_write_t *)lrc;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   385
	blkptr_t *bp = &lr->lr_blkptr;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   386
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
	 * If we previously claimed it, we need to free it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   390
	if (claim_txg != 0 && lrc->lrc_txtype == TX_WRITE &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   391
	    bp->blk_birth >= claim_txg && zil_bp_tree_add(zilog, bp) == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   392
		zio_free(zilog->zl_spa, dmu_tx_get_txg(tx), bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   393
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   394
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
 * Create an on-disk intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
zil_create(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   403
	const zil_header_t *zh = zilog->zl_header;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
	lwb_t *lwb;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   405
	uint64_t txg = 0;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   406
	dmu_tx_t *tx = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
	blkptr_t blk;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   408
	int error = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
	/*
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   411
	 * Wait for any previous destroy to complete.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
	 */
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   413
	txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   414
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   415
	ASSERT(zh->zh_claim_txg == 0);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   416
	ASSERT(zh->zh_replay_seq == 0);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   417
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   418
	blk = zh->zh_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
	/*
8109
6147a1bdd359 6760048 assertion failed: !BP_SHOULD_BYTESWAP(bp)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7904
diff changeset
   421
	 * If we don't already have an initial log block or we have one
6147a1bdd359 6760048 assertion failed: !BP_SHOULD_BYTESWAP(bp)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7904
diff changeset
   422
	 * but it's the wrong endianness then allocate one.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	 */
8109
6147a1bdd359 6760048 assertion failed: !BP_SHOULD_BYTESWAP(bp)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7904
diff changeset
   424
	if (BP_IS_HOLE(&blk) || BP_SHOULD_BYTESWAP(&blk)) {
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   425
		tx = dmu_tx_create(zilog->zl_os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   426
		VERIFY(dmu_tx_assign(tx, TXG_WAIT) == 0);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   427
		dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   428
		txg = dmu_tx_get_txg(tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   429
8109
6147a1bdd359 6760048 assertion failed: !BP_SHOULD_BYTESWAP(bp)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7904
diff changeset
   430
		if (!BP_IS_HOLE(&blk)) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   431
			zio_free_zil(zilog->zl_spa, txg, &blk);
8109
6147a1bdd359 6760048 assertion failed: !BP_SHOULD_BYTESWAP(bp)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7904
diff changeset
   432
			BP_ZERO(&blk);
6147a1bdd359 6760048 assertion failed: !BP_SHOULD_BYTESWAP(bp)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7904
diff changeset
   433
		}
6147a1bdd359 6760048 assertion failed: !BP_SHOULD_BYTESWAP(bp)
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7904
diff changeset
   434
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   435
		error = zio_alloc_zil(zilog->zl_spa, txg, &blk, NULL,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   436
		    ZIL_MIN_BLKSZ, zilog->zl_logbias == ZFS_LOGBIAS_LATENCY);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   437
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   438
		if (error == 0)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   439
			zil_init_log_chain(zilog, &blk);
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
   440
	}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   441
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   442
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   443
	 * Allocate a log write buffer (lwb) for the first log block.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   444
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
		lwb = kmem_cache_alloc(zil_lwb_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
		lwb->lwb_zilog = zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
		lwb->lwb_blk = blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
		lwb->lwb_nused = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
		lwb->lwb_sz = BP_GET_LSIZE(&lwb->lwb_blk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
		lwb->lwb_buf = zio_buf_alloc(lwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
		lwb->lwb_max_txg = txg;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   453
		lwb->lwb_zio = NULL;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   454
		lwb->lwb_tx = NULL;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   455
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
		mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
		list_insert_tail(&zilog->zl_lwb_list, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
		mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   461
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   462
	 * If we just allocated the first log block, commit our transaction
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   463
	 * and wait for zil_sync() to stuff the block poiner into zh_log.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   464
	 * (zh is part of the MOS, so we cannot modify it in open context.)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   465
	 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   466
	if (tx != NULL) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   467
		dmu_tx_commit(tx);
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
   468
		txg_wait_synced(zilog->zl_dmu_pool, txg);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   469
	}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   470
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   471
	ASSERT(bcmp(&blk, &zh->zh_log, sizeof (blk)) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
 * In one tx, free all log blocks and clear the log header.
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   476
 * If keep_first is set, then we're replaying a log with no content.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   477
 * We want to keep the first block, however, so that the first
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   478
 * synchronous transaction doesn't require a txg_wait_synced()
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   479
 * in zil_create().  We don't need to txg_wait_synced() here either
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   480
 * when keep_first is set, because both zil_create() and zil_destroy()
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   481
 * will wait for any in-progress destroys to complete.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
void
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   484
zil_destroy(zilog_t *zilog, boolean_t keep_first)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   486
	const zil_header_t *zh = zilog->zl_header;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   487
	lwb_t *lwb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
	uint64_t txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   491
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   492
	 * Wait for any previous destroy to complete.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   493
	 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   494
	txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   496
	zilog->zl_old_header = *zh;		/* debugging aid */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   497
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   498
	if (BP_IS_HOLE(&zh->zh_log))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	tx = dmu_tx_create(zilog->zl_os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   502
	VERIFY(dmu_tx_assign(tx, TXG_WAIT) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
	txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   506
	mutex_enter(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   507
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   508
	ASSERT3U(zilog->zl_destroy_txg, <, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	zilog->zl_destroy_txg = txg;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   510
	zilog->zl_keep_first = keep_first;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   511
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   512
	if (!list_is_empty(&zilog->zl_lwb_list)) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   513
		ASSERT(zh->zh_claim_txg == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   514
		ASSERT(!keep_first);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   515
		while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   516
			list_remove(&zilog->zl_lwb_list, lwb);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   517
			if (lwb->lwb_buf != NULL)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   518
				zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   519
			zio_free_zil(zilog->zl_spa, txg, &lwb->lwb_blk);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   520
			kmem_cache_free(zil_lwb_cache, lwb);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   521
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   522
	} else if (!keep_first) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   523
		(void) zil_parse(zilog, zil_free_log_block,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   524
		    zil_free_log_record, tx, zh->zh_claim_txg);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   525
	}
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   526
	mutex_exit(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 1842
diff changeset
   531
int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11066
diff changeset
   532
zil_claim(const char *osname, void *txarg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	dmu_tx_t *tx = txarg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
	uint64_t first_txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
	zilog_t *zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
	zil_header_t *zh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	objset_t *os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10209
diff changeset
   541
	error = dmu_objset_hold(osname, FTAG, &os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
	if (error) {
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   543
		cmn_err(CE_WARN, "can't open objset for %s", osname);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 1842
diff changeset
   544
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
	zilog = dmu_objset_zil(os);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   548
	zh = zil_header_in_syncing_context(zilog);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   550
	if (spa_get_log_state(zilog->zl_spa) == SPA_LOG_CLEAR) {
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
   551
		if (!BP_IS_HOLE(&zh->zh_log))
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   552
			zio_free_zil(zilog->zl_spa, first_txg, &zh->zh_log);
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
   553
		BP_ZERO(&zh->zh_log);
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
   554
		dsl_dataset_dirty(dmu_objset_ds(os), tx);
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10879
diff changeset
   555
		dmu_objset_rele(os, FTAG);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10879
diff changeset
   556
		return (0);
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
   557
	}
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
   558
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
	/*
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   560
	 * Claim all log blocks if we haven't already done so, and remember
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   561
	 * the highest claimed sequence number.  This ensures that if we can
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   562
	 * read only part of the log now (e.g. due to a missing device),
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   563
	 * but we can read the entire log later, we will not try to replay
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   564
	 * or destroy beyond the last block we successfully claimed.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
	ASSERT3U(zh->zh_claim_txg, <=, first_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
	if (zh->zh_claim_txg == 0 && !BP_IS_HOLE(&zh->zh_log)) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   568
		(void) zil_parse(zilog, zil_claim_log_block,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   569
		    zil_claim_log_record, tx, first_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
		zh->zh_claim_txg = first_txg;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   571
		zh->zh_claim_blk_seq = zilog->zl_parse_blk_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   572
		zh->zh_claim_lr_seq = zilog->zl_parse_lr_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   573
		if (zilog->zl_parse_lr_count || zilog->zl_parse_blk_count > 1)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   574
			zh->zh_flags |= ZIL_REPLAY_NEEDED;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   575
		zh->zh_flags |= ZIL_CLAIM_LR_SEQ_VALID;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
		dsl_dataset_dirty(dmu_objset_ds(os), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
	}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   578
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
	ASSERT3U(first_txg, ==, (spa_last_synced_txg(zilog->zl_spa) + 1));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10209
diff changeset
   580
	dmu_objset_rele(os, FTAG);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 1842
diff changeset
   581
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   584
/*
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   585
 * Check the log by walking the log chain.
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   586
 * Checksum errors are ok as they indicate the end of the chain.
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   587
 * Any other error (no device or read failure) returns an error.
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   588
 */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   589
int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11066
diff changeset
   590
zil_check_log_chain(const char *osname, void *tx)
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   591
{
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   592
	zilog_t *zilog;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   593
	objset_t *os;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   594
	int error;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   595
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   596
	ASSERT(tx == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   597
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10209
diff changeset
   598
	error = dmu_objset_hold(osname, FTAG, &os);
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   599
	if (error) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   600
		cmn_err(CE_WARN, "can't open objset for %s", osname);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   601
		return (0);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   602
	}
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   603
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   604
	zilog = dmu_objset_zil(os);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   605
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   606
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   607
	 * Because tx == NULL, zil_claim_log_block() will not actually claim
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   608
	 * any blocks, but just determine whether it is possible to do so.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   609
	 * In addition to checking the log chain, zil_claim_log_block()
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   610
	 * will invoke zio_claim() with a done func of spa_claim_notify(),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   611
	 * which will update spa_max_claim_txg.  See spa_load() for details.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   612
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   613
	error = zil_parse(zilog, zil_claim_log_block, zil_claim_log_record, tx,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   614
	    zilog->zl_header->zh_claim_txg ? -1ULL : spa_first_txg(os->os_spa));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   615
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10209
diff changeset
   616
	dmu_objset_rele(os, FTAG);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   617
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   618
	return ((error == ECKSUM || error == ENOENT) ? 0 : error);
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   619
}
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7181
diff changeset
   620
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   621
static int
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   622
zil_vdev_compare(const void *x1, const void *x2)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
{
5875
599b7007a9cd 6653210 zil_vdev_compare() compares pointers instead of vdev ids
perrin
parents: 5809
diff changeset
   624
	uint64_t v1 = ((zil_vdev_node_t *)x1)->zv_vdev;
599b7007a9cd 6653210 zil_vdev_compare() compares pointers instead of vdev ids
perrin
parents: 5809
diff changeset
   625
	uint64_t v2 = ((zil_vdev_node_t *)x2)->zv_vdev;
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   626
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   627
	if (v1 < v2)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   628
		return (-1);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   629
	if (v1 > v2)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   630
		return (1);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   631
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   632
	return (0);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   633
}
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   634
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   635
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   636
zil_add_block(zilog_t *zilog, const blkptr_t *bp)
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   637
{
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   638
	avl_tree_t *t = &zilog->zl_vdev_tree;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   639
	avl_index_t where;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   640
	zil_vdev_node_t *zv, zvsearch;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   641
	int ndvas = BP_GET_NDVAS(bp);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   642
	int i;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
2986
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
   644
	if (zfs_nocacheflush)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   647
	ASSERT(zilog->zl_writer);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   648
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   649
	/*
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   650
	 * Even though we're zl_writer, we still need a lock because the
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   651
	 * zl_get_data() callbacks may have dmu_sync() done callbacks
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   652
	 * that will run concurrently.
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   653
	 */
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   654
	mutex_enter(&zilog->zl_vdev_lock);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   655
	for (i = 0; i < ndvas; i++) {
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   656
		zvsearch.zv_vdev = DVA_GET_VDEV(&bp->blk_dva[i]);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   657
		if (avl_find(t, &zvsearch, &where) == NULL) {
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   658
			zv = kmem_alloc(sizeof (*zv), KM_SLEEP);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   659
			zv->zv_vdev = zvsearch.zv_vdev;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   660
			avl_insert(t, zv, where);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   661
		}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   662
	}
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   663
	mutex_exit(&zilog->zl_vdev_lock);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   664
}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   665
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
void
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   667
zil_flush_vdevs(zilog_t *zilog)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
{
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   669
	spa_t *spa = zilog->zl_spa;
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   670
	avl_tree_t *t = &zilog->zl_vdev_tree;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   671
	void *cookie = NULL;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   672
	zil_vdev_node_t *zv;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   673
	zio_t *zio;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   674
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   675
	ASSERT(zilog->zl_writer);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   677
	/*
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   678
	 * We don't need zl_vdev_lock here because we're the zl_writer,
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   679
	 * and all zl_get_data() callbacks are done.
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   680
	 */
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   681
	if (avl_numnodes(t) == 0)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   682
		return;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   683
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   684
	spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   685
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   686
	zio = zio_root(spa, NULL, NULL, ZIO_FLAG_CANFAIL);
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   687
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   688
	while ((zv = avl_destroy_nodes(t, &cookie)) != NULL) {
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   689
		vdev_t *vd = vdev_lookup_top(spa, zv->zv_vdev);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   690
		if (vd != NULL)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   691
			zio_flush(zio, vd);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   692
		kmem_free(zv, sizeof (*zv));
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   693
	}
789
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
	 * Wait for all the flushes to complete.  Not all devices actually
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
	 * support the DKIOCFLUSHWRITECACHE ioctl, so it's OK if it fails.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
	 */
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   699
	(void) zio_wait(zio);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   700
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   701
	spa_config_exit(spa, SCL_STATE, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
 * Function called when a log block write completes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
zil_lwb_write_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
	lwb_t *lwb = zio->io_private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
	zilog_t *zilog = lwb->lwb_zilog;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   712
	dmu_tx_t *tx = lwb->lwb_tx;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   714
	ASSERT(BP_GET_COMPRESS(zio->io_bp) == ZIO_COMPRESS_OFF);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   715
	ASSERT(BP_GET_CHECKSUM(zio->io_bp) == ZIO_CHECKSUM_ZILOG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   716
	ASSERT(BP_GET_TYPE(zio->io_bp) == DMU_OT_INTENT_LOG);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   717
	ASSERT(BP_GET_LEVEL(zio->io_bp) == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   718
	ASSERT(BP_GET_BYTEORDER(zio->io_bp) == ZFS_HOST_BYTEORDER);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   719
	ASSERT(!BP_IS_GANG(zio->io_bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   720
	ASSERT(!BP_IS_HOLE(zio->io_bp));
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   721
	ASSERT(zio->io_bp->blk_fill == 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
   722
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
	/*
9493
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   724
	 * Ensure the lwb buffer pointer is cleared before releasing
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   725
	 * the txg. If we have had an allocation failure and
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   726
	 * the txg is waiting to sync then we want want zil_sync()
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   727
	 * to remove the lwb so that it's not picked up as the next new
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   728
	 * one in zil_commit_writer(). zil_sync() will only remove
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   729
	 * the lwb if lwb_buf is null.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
	zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
	lwb->lwb_buf = NULL;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   734
	lwb->lwb_tx = NULL;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   735
	mutex_exit(&zilog->zl_lock);
9493
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   736
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   737
	/*
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   738
	 * Now that we've written this log block, we have a stable pointer
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   739
	 * to the next block in the chain, so it's OK to let the txg in
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   740
	 * which we allocated the next block sync.
9493
9933d599bc93 6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9396
diff changeset
   741
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   742
	dmu_tx_commit(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
/*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   746
 * Initialize the io for a log block.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   747
 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   748
static void
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   749
zil_lwb_write_init(zilog_t *zilog, lwb_t *lwb)
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   750
{
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   751
	zbookmark_t zb;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   752
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   753
	SET_BOOKMARK(&zb, lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_OBJSET],
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   754
	    ZB_ZIL_OBJECT, ZB_ZIL_LEVEL,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   755
	    lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_SEQ]);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   756
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   757
	if (zilog->zl_root_zio == NULL) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   758
		zilog->zl_root_zio = zio_root(zilog->zl_spa, NULL, NULL,
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   759
		    ZIO_FLAG_CANFAIL);
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   760
	}
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   761
	if (lwb->lwb_zio == NULL) {
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   762
		lwb->lwb_zio = zio_rewrite(zilog->zl_root_zio, zilog->zl_spa,
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
   763
		    0, &lwb->lwb_blk, lwb->lwb_buf, lwb->lwb_sz,
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
   764
		    zil_lwb_write_done, lwb, ZIO_PRIORITY_LOG_WRITE,
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10310
diff changeset
   765
		    ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_PROPAGATE, &zb);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   766
	}
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   767
}
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   768
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   769
/*
10879
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   770
 * Use the slog as long as the logbias is 'latency' and the current commit size
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   771
 * is less than the limit or the total list size is less than 2X the limit.
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   772
 * Limit checking is disabled by setting zil_slog_limit to UINT64_MAX.
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   773
 */
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   774
uint64_t zil_slog_limit = 1024 * 1024;
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   775
#define	USE_SLOG(zilog) (((zilog)->zl_logbias == ZFS_LOGBIAS_LATENCY) && \
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   776
	(((zilog)->zl_cur_used < zil_slog_limit) || \
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   777
	((zilog)->zl_itx_list_sz < (zil_slog_limit << 1))))
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   778
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   779
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
 * Start a log block write and advance to the next log block.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
 * Calls are serialized.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
static lwb_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
zil_lwb_write_start(zilog_t *zilog, lwb_t *lwb)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	lwb_t *nlwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
	zil_trailer_t *ztp = (zil_trailer_t *)(lwb->lwb_buf + lwb->lwb_sz) - 1;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   788
	spa_t *spa = zilog->zl_spa;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   789
	blkptr_t *bp = &ztp->zit_next_blk;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   790
	dmu_tx_t *tx;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
	uint64_t txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
	uint64_t zil_blksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
	ASSERT(lwb->lwb_nused <= ZIL_BLK_DATA_SZ(lwb));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	 * Allocate the next block and save its address in this block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
	 * before writing it in order to establish the log chain.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
	 * Note that if the allocation of nlwb synced before we wrote
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
	 * the block that points at it (lwb), we'd leak it if we crashed.
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   802
	 * Therefore, we don't do dmu_tx_commit() until zil_lwb_write_done().
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   803
	 * We dirty the dataset to ensure that zil_sync() will be called
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   804
	 * to clean up in the event of allocation failure or I/O failure.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   806
	tx = dmu_tx_create(zilog->zl_os);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   807
	VERIFY(dmu_tx_assign(tx, TXG_WAIT) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   808
	dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   809
	txg = dmu_tx_get_txg(tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   810
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   811
	lwb->lwb_tx = tx;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
	/*
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   814
	 * Pick a ZIL blocksize. We request a size that is the
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   815
	 * maximum of the previous used size, the current used size and
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   816
	 * the amount waiting in the queue.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	 */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   818
	zil_blksz = MAX(zilog->zl_prev_used,
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   819
	    zilog->zl_cur_used + sizeof (*ztp));
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   820
	zil_blksz = MAX(zil_blksz, zilog->zl_itx_list_sz + sizeof (*ztp));
1842
1712a484fc9d 6413731 pathologically slower fsync on 32 bit systems
perrin
parents: 1807
diff changeset
   821
	zil_blksz = P2ROUNDUP_TYPED(zil_blksz, ZIL_MIN_BLKSZ, uint64_t);
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   822
	if (zil_blksz > ZIL_MAX_BLKSZ)
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   823
		zil_blksz = ZIL_MAX_BLKSZ;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   825
	BP_ZERO(bp);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   826
	/* pass the old blkptr in order to spread log blocks across devs */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   827
	error = zio_alloc_zil(spa, txg, bp, &lwb->lwb_blk, zil_blksz,
10879
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
   828
	    USE_SLOG(zilog));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
	if (error) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   830
		/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   831
		 * Since we've just experienced an allocation failure,
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   832
		 * terminate the current lwb and send it on its way.
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   833
		 */
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   834
		ztp->zit_pad = 0;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   835
		ztp->zit_nused = lwb->lwb_nused;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   836
		ztp->zit_bt.zbt_cksum = lwb->lwb_blk.blk_cksum;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   837
		zio_nowait(lwb->lwb_zio);
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   838
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   839
		/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   840
		 * By returning NULL the caller will call tx_wait_synced()
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   841
		 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   845
	ASSERT3U(bp->blk_birth, ==, txg);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   846
	ztp->zit_pad = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
	ztp->zit_nused = lwb->lwb_nused;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
	ztp->zit_bt.zbt_cksum = lwb->lwb_blk.blk_cksum;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   849
	bp->blk_cksum = lwb->lwb_blk.blk_cksum;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   850
	bp->blk_cksum.zc_word[ZIL_ZC_SEQ]++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
	 * Allocate a new log write buffer (lwb).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
	nlwb = kmem_cache_alloc(zil_lwb_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
	nlwb->lwb_zilog = zilog;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   857
	nlwb->lwb_blk = *bp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
	nlwb->lwb_nused = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
	nlwb->lwb_sz = BP_GET_LSIZE(&nlwb->lwb_blk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
	nlwb->lwb_buf = zio_buf_alloc(nlwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
	nlwb->lwb_max_txg = txg;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   862
	nlwb->lwb_zio = NULL;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   863
	nlwb->lwb_tx = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
	/*
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   866
	 * Put new lwb at the end of the log chain
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	list_insert_tail(&zilog->zl_lwb_list, nlwb);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   870
	mutex_exit(&zilog->zl_lock);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   871
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   872
	/* Record the block for later vdev flushing */
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   873
	zil_add_block(zilog, &lwb->lwb_blk);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
	/*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   876
	 * kick off the write for the old log block
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
	 */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   878
	ASSERT(lwb->lwb_zio);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   879
	zio_nowait(lwb->lwb_zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
	return (nlwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
static lwb_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
zil_lwb_commit(zilog_t *zilog, itx_t *itx, lwb_t *lwb)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
	lr_t *lrc = &itx->itx_lr; /* common log record */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   888
	lr_write_t *lrw = (lr_write_t *)lrc;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   889
	char *lr_buf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
	uint64_t txg = lrc->lrc_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
	uint64_t reclen = lrc->lrc_reclen;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   892
	uint64_t dlen = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
	if (lwb == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
		return (NULL);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   896
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
	ASSERT(lwb->lwb_buf != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   899
	if (lrc->lrc_txtype == TX_WRITE && itx->itx_wr_state == WR_NEED_COPY)
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   900
		dlen = P2ROUNDUP_TYPED(
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   901
		    lrw->lr_length, sizeof (uint64_t), uint64_t);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   902
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   903
	zilog->zl_cur_used += (reclen + dlen);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   904
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   905
	zil_lwb_write_init(zilog, lwb);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   906
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   907
	/*
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   908
	 * If this record won't fit in the current log block, start a new one.
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   909
	 */
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   910
	if (lwb->lwb_nused + reclen + dlen > ZIL_BLK_DATA_SZ(lwb)) {
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   911
		lwb = zil_lwb_write_start(zilog, lwb);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   912
		if (lwb == NULL)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   913
			return (NULL);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   914
		zil_lwb_write_init(zilog, lwb);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   915
		ASSERT(lwb->lwb_nused == 0);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   916
		if (reclen + dlen > ZIL_BLK_DATA_SZ(lwb)) {
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   917
			txg_wait_synced(zilog->zl_dmu_pool, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
			return (lwb);
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
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   922
	lr_buf = lwb->lwb_buf + lwb->lwb_nused;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   923
	bcopy(lrc, lr_buf, reclen);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   924
	lrc = (lr_t *)lr_buf;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   925
	lrw = (lr_write_t *)lrc;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   926
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   927
	/*
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   928
	 * If it's a write, fetch the data or get its blkptr as appropriate.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   929
	 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   930
	if (lrc->lrc_txtype == TX_WRITE) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   931
		if (txg > spa_freeze_txg(zilog->zl_spa))
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   932
			txg_wait_synced(zilog->zl_dmu_pool, txg);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   933
		if (itx->itx_wr_state != WR_COPIED) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   934
			char *dbuf;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   935
			int error;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   936
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   937
			if (dlen) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   938
				ASSERT(itx->itx_wr_state == WR_NEED_COPY);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   939
				dbuf = lr_buf + reclen;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   940
				lrw->lr_common.lrc_reclen += dlen;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   941
			} else {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   942
				ASSERT(itx->itx_wr_state == WR_INDIRECT);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   943
				dbuf = NULL;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   944
			}
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   945
			error = zilog->zl_get_data(
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   946
			    itx->itx_private, lrw, dbuf, lwb->lwb_zio);
10209
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9904
diff changeset
   947
			if (error == EIO) {
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9904
diff changeset
   948
				txg_wait_synced(zilog->zl_dmu_pool, txg);
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9904
diff changeset
   949
				return (lwb);
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 9904
diff changeset
   950
			}
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   951
			if (error) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   952
				ASSERT(error == ENOENT || error == EEXIST ||
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   953
				    error == EALREADY);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   954
				return (lwb);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   955
			}
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   956
		}
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   957
	}
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   958
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   959
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   960
	 * We're actually making an entry, so update lrc_seq to be the
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   961
	 * log record sequence number.  Note that this is generally not
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   962
	 * equal to the itx sequence number because not all transactions
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   963
	 * are synchronous, and sometimes spa_sync() gets there first.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   964
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   965
	lrc->lrc_seq = ++zilog->zl_lr_seq; /* we are single threaded */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   966
	lwb->lwb_nused += reclen + dlen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
	lwb->lwb_max_txg = MAX(lwb->lwb_max_txg, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
	ASSERT3U(lwb->lwb_nused, <=, ZIL_BLK_DATA_SZ(lwb));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
	ASSERT3U(P2PHASE(lwb->lwb_nused, sizeof (uint64_t)), ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
	return (lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
itx_t *
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
   975
zil_itx_create(uint64_t txtype, size_t lrsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
1842
1712a484fc9d 6413731 pathologically slower fsync on 32 bit systems
perrin
parents: 1807
diff changeset
   979
	lrsize = P2ROUNDUP_TYPED(lrsize, sizeof (uint64_t), size_t);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
	itx = kmem_alloc(offsetof(itx_t, itx_lr) + lrsize, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
	itx->itx_lr.lrc_txtype = txtype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
	itx->itx_lr.lrc_reclen = lrsize;
6101
915df4cedbc9 6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents: 5913
diff changeset
   984
	itx->itx_sod = lrsize; /* if write & WR_NEED_COPY will be increased */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
	itx->itx_lr.lrc_seq = 0;	/* defensive */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
	return (itx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   990
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   991
zil_itx_destroy(itx_t *itx)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   992
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   993
	kmem_free(itx, offsetof(itx_t, itx_lr) + itx->itx_lr.lrc_reclen);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   994
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   995
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
	ASSERT(itx->itx_lr.lrc_seq == 0);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1002
	ASSERT(!zilog->zl_replay);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
	list_insert_tail(&zilog->zl_itx_list, itx);
6101
915df4cedbc9 6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents: 5913
diff changeset
  1006
	zilog->zl_itx_list_sz += itx->itx_sod;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
	itx->itx_lr.lrc_txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
	itx->itx_lr.lrc_seq = seq = ++zilog->zl_itx_seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
 * Free up all in-memory intent log transactions that have now been synced.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
zil_itx_clean(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1020
	uint64_t synced_txg = spa_last_synced_txg(zilog->zl_spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
	uint64_t freeze_txg = spa_freeze_txg(zilog->zl_spa);
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1022
	list_t clean_list;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1025
	list_create(&clean_list, sizeof (itx_t), offsetof(itx_t, itx_node));
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1026
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	mutex_enter(&zilog->zl_lock);
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1028
	/* wait for a log writer to finish walking list */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1029
	while (zilog->zl_writer) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1030
		cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock);
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1031
	}
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1032
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1033
	/*
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1034
	 * Move the sync'd log transactions to a separate list so we can call
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1035
	 * kmem_free without holding the zl_lock.
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1036
	 *
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1037
	 * There is no need to set zl_writer as we don't drop zl_lock here
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1038
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
	while ((itx = list_head(&zilog->zl_itx_list)) != NULL &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
	    itx->itx_lr.lrc_txg <= MIN(synced_txg, freeze_txg)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
		list_remove(&zilog->zl_itx_list, itx);
6101
915df4cedbc9 6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents: 5913
diff changeset
  1042
		zilog->zl_itx_list_sz -= itx->itx_sod;
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1043
		list_insert_tail(&clean_list, itx);
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1044
	}
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1045
	cv_broadcast(&zilog->zl_cv_writer);
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1046
	mutex_exit(&zilog->zl_lock);
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1047
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1048
	/* destroy sync'd log transactions */
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1049
	while ((itx = list_head(&clean_list)) != NULL) {
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1050
		list_remove(&clean_list, itx);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1051
		zil_itx_destroy(itx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
	}
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
  1053
	list_destroy(&clean_list);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1056
/*
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1057
 * If there are any in-memory intent log transactions which have now been
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1058
 * synced then start up a taskq to free them.
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1059
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1060
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
zil_clean(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
{
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1063
	itx_t *itx;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1064
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
	mutex_enter(&zilog->zl_lock);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1066
	itx = list_head(&zilog->zl_itx_list);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1067
	if ((itx != NULL) &&
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1068
	    (itx->itx_lr.lrc_txg <= spa_last_synced_txg(zilog->zl_spa))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
		(void) taskq_dispatch(zilog->zl_clean_taskq,
10879
420834d9266b 6849167 40% write regression with multiple shares
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10800
diff changeset
  1070
		    (task_func_t *)zil_itx_clean, zilog, TQ_NOSLEEP);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1071
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  1075
static void
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1076
zil_commit_writer(zilog_t *zilog, uint64_t seq, uint64_t foid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
	uint64_t txg;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1079
	uint64_t commit_seq = 0;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1080
	itx_t *itx, *itx_next;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
	lwb_t *lwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
	spa_t *spa;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1083
	int error = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1085
	zilog->zl_writer = B_TRUE;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  1086
	ASSERT(zilog->zl_root_zio == NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
	spa = zilog->zl_spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	if (zilog->zl_suspend) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
		lwb = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
		lwb = list_tail(&zilog->zl_lwb_list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
		if (lwb == NULL) {
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1094
			/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1095
			 * Return if there's nothing to flush before we
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1096
			 * dirty the fs by calling zil_create()
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1097
			 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1098
			if (list_is_empty(&zilog->zl_itx_list)) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1099
				zilog->zl_writer = B_FALSE;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1100
				return;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1101
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
			mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
			zil_create(zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
			mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
			lwb = list_tail(&zilog->zl_lwb_list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1109
	/* Loop through in-memory log transactions filling log blocks. */
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1110
	DTRACE_PROBE1(zil__cw1, zilog_t *, zilog);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1111
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1112
	for (itx = list_head(&zilog->zl_itx_list); itx; itx = itx_next) {
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1113
		/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1114
		 * Save the next pointer.  Even though we drop zl_lock below,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1115
		 * all threads that can remove itx list entries (other writers
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1116
		 * and zil_itx_clean()) can't do so until they have zl_writer.
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1117
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1118
		itx_next = list_next(&zilog->zl_itx_list, itx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1119
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1120
		/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1121
		 * Determine whether to push this itx.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1122
		 * Push all transactions related to specified foid and
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1123
		 * all other transactions except those that can be logged
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1124
		 * out of order (TX_WRITE, TX_TRUNCATE, TX_SETATTR, TX_ACL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1125
		 * for all other files.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1126
		 *
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1127
		 * If foid == 0 (meaning "push all foids") or
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1128
		 * itx->itx_sync is set (meaning O_[D]SYNC), push regardless.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1129
		 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1130
		if (foid != 0 && !itx->itx_sync &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1131
		    TX_OOO(itx->itx_lr.lrc_txtype) &&
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1132
		    ((lr_ooo_t *)&itx->itx_lr)->lr_foid != foid)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1133
			continue; /* skip this record */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
		if ((itx->itx_lr.lrc_seq > seq) &&
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1136
		    ((lwb == NULL) || (lwb->lwb_nused == 0) ||
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1137
		    (lwb->lwb_nused + itx->itx_sod > ZIL_BLK_DATA_SZ(lwb))))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
		list_remove(&zilog->zl_itx_list, itx);
6101
915df4cedbc9 6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents: 5913
diff changeset
  1141
		zilog->zl_itx_list_sz -= itx->itx_sod;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1142
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1143
		mutex_exit(&zilog->zl_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1144
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
		txg = itx->itx_lr.lrc_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
		ASSERT(txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
		if (txg > spa_last_synced_txg(spa) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
		    txg > spa_freeze_txg(spa))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
			lwb = zil_lwb_commit(zilog, itx, lwb);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1151
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1152
		zil_itx_destroy(itx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1153
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
		mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
	}
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1156
	DTRACE_PROBE1(zil__cw2, zilog_t *, zilog);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1157
	/* determine commit sequence number */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1158
	itx = list_head(&zilog->zl_itx_list);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1159
	if (itx)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1160
		commit_seq = itx->itx_lr.lrc_seq - 1;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1161
	else
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1162
		commit_seq = zilog->zl_itx_seq;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
	/* write the last block out */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1166
	if (lwb != NULL && lwb->lwb_zio != NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
		lwb = zil_lwb_write_start(zilog, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1169
	zilog->zl_prev_used = zilog->zl_cur_used;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1170
	zilog->zl_cur_used = 0;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1171
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1172
	/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1173
	 * Wait if necessary for the log blocks to be on stable storage.
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1174
	 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1175
	if (zilog->zl_root_zio) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1176
		DTRACE_PROBE1(zil__cw3, zilog_t *, zilog);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1177
		error = zio_wait(zilog->zl_root_zio);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  1178
		zilog->zl_root_zio = NULL;
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1179
		DTRACE_PROBE1(zil__cw4, zilog_t *, zilog);
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1180
		zil_flush_vdevs(zilog);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
	}
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1182
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1183
	if (error || lwb == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
		txg_wait_synced(zilog->zl_dmu_pool, 0);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1185
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1186
	mutex_enter(&zilog->zl_lock);
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1187
	zilog->zl_writer = B_FALSE;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1188
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1189
	ASSERT3U(commit_seq, >=, zilog->zl_commit_seq);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1190
	zilog->zl_commit_seq = commit_seq;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1191
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1192
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1193
	 * Remember the highest committed log sequence number for ztest.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1194
	 * We only update this value when all the log writes succeeded,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1195
	 * because ztest wants to ASSERT that it got the whole log chain.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1196
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1197
	if (error == 0 && lwb != NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1198
		zilog->zl_commit_lr_seq = zilog->zl_lr_seq;
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1199
}
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1200
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1201
/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1202
 * Push zfs transactions to stable storage up to the supplied sequence number.
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1203
 * If foid is 0 push out all transactions, otherwise push only those
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1204
 * for that file or might have been used to create that file.
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1205
 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1206
void
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1207
zil_commit(zilog_t *zilog, uint64_t seq, uint64_t foid)
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1208
{
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1209
	if (zilog == NULL || seq == 0)
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1210
		return;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1211
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1212
	mutex_enter(&zilog->zl_lock);
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1213
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1214
	seq = MIN(seq, zilog->zl_itx_seq);	/* cap seq at largest itx seq */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1215
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1216
	while (zilog->zl_writer) {
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1217
		cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1218
		if (seq <= zilog->zl_commit_seq) {
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1219
			mutex_exit(&zilog->zl_lock);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1220
			return;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1221
		}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1222
	}
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1223
	zil_commit_writer(zilog, seq, foid); /* drops zl_lock */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1224
	/* wake up others waiting on the commit */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1225
	cv_broadcast(&zilog->zl_cv_writer);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1226
	mutex_exit(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1230
 * Report whether all transactions are committed.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1231
 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1232
static boolean_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1233
zil_is_committed(zilog_t *zilog)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1234
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1235
	lwb_t *lwb;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1236
	boolean_t committed;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1237
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1238
	mutex_enter(&zilog->zl_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1239
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1240
	while (zilog->zl_writer)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1241
		cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1242
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1243
	if (!list_is_empty(&zilog->zl_itx_list))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1244
		committed = B_FALSE;		/* unpushed transactions */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1245
	else if ((lwb = list_head(&zilog->zl_lwb_list)) == NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1246
		committed = B_TRUE;		/* intent log never used */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1247
	else if (list_next(&zilog->zl_lwb_list, lwb) != NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1248
		committed = B_FALSE;		/* zil_sync() not done yet */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1249
	else
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1250
		committed = B_TRUE;		/* everything synced */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1251
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1252
	mutex_exit(&zilog->zl_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1253
	return (committed);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1254
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1255
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1256
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1257
 * Called in syncing context to free committed log blocks and update log header.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1258
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1259
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
zil_sync(zilog_t *zilog, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1261
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1262
	zil_header_t *zh = zil_header_in_syncing_context(zilog);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
	uint64_t txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1264
	spa_t *spa = zilog->zl_spa;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1265
	uint64_t *replayed_seq = &zilog->zl_replayed_seq[txg & TXG_MASK];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
	lwb_t *lwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1268
	/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1269
	 * We don't zero out zl_destroy_txg, so make sure we don't try
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1270
	 * to destroy it twice.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1271
	 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1272
	if (spa_sync_pass(spa) != 1)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1273
		return;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1274
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1275
	mutex_enter(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1276
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
	ASSERT(zilog->zl_stop_sync == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1278
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1279
	if (*replayed_seq != 0) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1280
		ASSERT(zh->zh_replay_seq < *replayed_seq);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1281
		zh->zh_replay_seq = *replayed_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1282
		*replayed_seq = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1283
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1284
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1285
	if (zilog->zl_destroy_txg == txg) {
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1286
		blkptr_t blk = zh->zh_log;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1287
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1288
		ASSERT(list_head(&zilog->zl_lwb_list) == NULL);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1289
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1290
		bzero(zh, sizeof (zil_header_t));
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1291
		bzero(zilog->zl_replayed_seq, sizeof (zilog->zl_replayed_seq));
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1292
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1293
		if (zilog->zl_keep_first) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1294
			/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1295
			 * If this block was part of log chain that couldn't
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1296
			 * be claimed because a device was missing during
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1297
			 * zil_claim(), but that device later returns,
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1298
			 * then this block could erroneously appear valid.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1299
			 * To guard against this, assign a new GUID to the new
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1300
			 * log chain so it doesn't matter what blk points to.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1301
			 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1302
			zil_init_log_chain(zilog, &blk);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1303
			zh->zh_log = blk;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1304
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1305
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1307
	while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) {
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1308
		zh->zh_log = lwb->lwb_blk;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
		if (lwb->lwb_buf != NULL || lwb->lwb_max_txg > txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
		list_remove(&zilog->zl_lwb_list, lwb);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1312
		zio_free_zil(spa, txg, &lwb->lwb_blk);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
		kmem_cache_free(zil_lwb_cache, lwb);
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1314
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1315
		/*
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1316
		 * If we don't have anything left in the lwb list then
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1317
		 * we've had an allocation failure and we need to zero
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1318
		 * out the zil_header blkptr so that we don't end
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1319
		 * up freeing the same block twice.
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1320
		 */
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1321
		if (list_head(&zilog->zl_lwb_list) == NULL)
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1322
			BP_ZERO(&zh->zh_log);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
zil_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
	zil_lwb_cache = kmem_cache_create("zil_lwb_cache",
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1331
	    sizeof (struct lwb), 0, NULL, NULL, NULL, NULL, NULL, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1333
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1334
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1335
zil_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
	kmem_cache_destroy(zil_lwb_cache);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
  1340
void
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
  1341
zil_set_logbias(zilog_t *zilog, uint64_t logbias)
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
  1342
{
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
  1343
	zilog->zl_logbias = logbias;
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
  1344
}
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
  1345
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1346
zilog_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1347
zil_alloc(objset_t *os, zil_header_t *zh_phys)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1348
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
	zilog_t *zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1350
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1351
	zilog = kmem_zalloc(sizeof (zilog_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1352
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1353
	zilog->zl_header = zh_phys;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1354
	zilog->zl_os = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
	zilog->zl_spa = dmu_objset_spa(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1356
	zilog->zl_dmu_pool = dmu_objset_pool(os);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1357
	zilog->zl_destroy_txg = TXG_INITIAL - 1;
10310
ba87b3315737 PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10298
diff changeset
  1358
	zilog->zl_logbias = dmu_objset_logbias(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1360
	mutex_init(&zilog->zl_lock, NULL, MUTEX_DEFAULT, NULL);
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1361
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
	list_create(&zilog->zl_itx_list, sizeof (itx_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
	    offsetof(itx_t, itx_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1365
	list_create(&zilog->zl_lwb_list, sizeof (lwb_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1366
	    offsetof(lwb_t, lwb_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1368
	mutex_init(&zilog->zl_vdev_lock, NULL, MUTEX_DEFAULT, NULL);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1369
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1370
	avl_create(&zilog->zl_vdev_tree, zil_vdev_compare,
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1371
	    sizeof (zil_vdev_node_t), offsetof(zil_vdev_node_t, zv_node));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
5913
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5886
diff changeset
  1373
	cv_init(&zilog->zl_cv_writer, NULL, CV_DEFAULT, NULL);
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5886
diff changeset
  1374
	cv_init(&zilog->zl_cv_suspend, NULL, CV_DEFAULT, NULL);
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5886
diff changeset
  1375
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1376
	return (zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1377
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1378
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1379
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
zil_free(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1381
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1382
	lwb_t *lwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1383
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
	zilog->zl_stop_sync = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1385
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1386
	while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
		list_remove(&zilog->zl_lwb_list, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
		if (lwb->lwb_buf != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
			zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
		kmem_cache_free(zil_lwb_cache, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
	list_destroy(&zilog->zl_lwb_list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1394
	avl_destroy(&zilog->zl_vdev_tree);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1395
	mutex_destroy(&zilog->zl_vdev_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1396
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
	ASSERT(list_head(&zilog->zl_itx_list) == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
	list_destroy(&zilog->zl_itx_list);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1399
	mutex_destroy(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1400
5913
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5886
diff changeset
  1401
	cv_destroy(&zilog->zl_cv_writer);
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5886
diff changeset
  1402
	cv_destroy(&zilog->zl_cv_suspend);
a77f8ad2ce63 6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents: 5886
diff changeset
  1403
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
	kmem_free(zilog, sizeof (zilog_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
 * Open an intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
zilog_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
zil_open(objset_t *os, zil_get_data_t *get_data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
	zilog_t *zilog = dmu_objset_zil(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1415
	zilog->zl_get_data = get_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1416
	zilog->zl_clean_taskq = taskq_create("zil_clean", 1, minclsyspri,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
	    2, 2, TASKQ_PREPOPULATE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1419
	return (zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
 * Close an intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
zil_close(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1428
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1429
	 * If the log isn't already committed, mark the objset dirty
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1430
	 * (so zil_sync() will be called) and wait for that txg to sync.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1431
	 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1432
	if (!zil_is_committed(zilog)) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1433
		uint64_t txg;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1434
		dmu_tx_t *tx = dmu_tx_create(zilog->zl_os);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1435
		VERIFY(dmu_tx_assign(tx, TXG_WAIT) == 0);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1436
		dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1437
		txg = dmu_tx_get_txg(tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1438
		dmu_tx_commit(tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1439
		txg_wait_synced(zilog->zl_dmu_pool, txg);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1440
	}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1441
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
	taskq_destroy(zilog->zl_clean_taskq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
	zilog->zl_clean_taskq = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
	zilog->zl_get_data = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1445
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
	zil_itx_clean(zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1447
	ASSERT(list_head(&zilog->zl_itx_list) == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1448
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1449
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1450
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
 * Suspend an intent log.  While in suspended mode, we still honor
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
 * synchronous semantics, but we rely on txg_wait_synced() to do it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
 * We suspend the log briefly when taking a snapshot so that the snapshot
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
 * contains all the data it's supposed to, and has an empty intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1457
zil_suspend(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1458
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1459
	const zil_header_t *zh = zilog->zl_header;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1460
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1461
	mutex_enter(&zilog->zl_lock);
8989
cfce31f4eebf 6462803 zfs snapshot -r failed because filesystem was busy
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8746
diff changeset
  1462
	if (zh->zh_flags & ZIL_REPLAY_NEEDED) {		/* unplayed log */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1463
		mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
		return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
	}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1466
	if (zilog->zl_suspend++ != 0) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1467
		/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1468
		 * Someone else already began a suspend.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1469
		 * Just wait for them to finish.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1470
		 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1471
		while (zilog->zl_suspending)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1472
			cv_wait(&zilog->zl_cv_suspend, &zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1473
		mutex_exit(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1474
		return (0);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1475
	}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1476
	zilog->zl_suspending = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1477
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1479
	zil_commit(zilog, UINT64_MAX, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1480
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1481
	/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1482
	 * Wait for any in-flight log writes to complete.
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1483
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
	mutex_enter(&zilog->zl_lock);
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1485
	while (zilog->zl_writer)
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1486
		cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1489
	zil_destroy(zilog, B_FALSE);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1490
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1491
	mutex_enter(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1492
	zilog->zl_suspending = B_FALSE;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1493
	cv_broadcast(&zilog->zl_cv_suspend);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1494
	mutex_exit(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
zil_resume(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
	ASSERT(zilog->zl_suspend != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
	zilog->zl_suspend--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
typedef struct zil_replay_arg {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
	zil_replay_func_t **zr_replay;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
	void		*zr_arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1511
	boolean_t	zr_byteswap;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1512
	char		*zr_lr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
} zil_replay_arg_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1515
static int
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1516
zil_replay_error(zilog_t *zilog, lr_t *lr, int error)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1517
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1518
	char name[MAXNAMELEN];
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1519
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1520
	zilog->zl_replaying_seq--;	/* didn't actually replay this one */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1521
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1522
	dmu_objset_name(zilog->zl_os, name);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1523
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1524
	cmn_err(CE_WARN, "ZFS replay transaction error %d, "
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1525
	    "dataset %s, seq 0x%llx, txtype %llu %s\n", error, name,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1526
	    (u_longlong_t)lr->lrc_seq,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1527
	    (u_longlong_t)(lr->lrc_txtype & ~TX_CI),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1528
	    (lr->lrc_txtype & TX_CI) ? "CI" : "");
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1529
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1530
	return (error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1531
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1532
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1533
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1534
zil_replay_log_record(zilog_t *zilog, lr_t *lr, void *zra, uint64_t claim_txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1535
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
	zil_replay_arg_t *zr = zra;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1537
	const zil_header_t *zh = zilog->zl_header;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1538
	uint64_t reclen = lr->lrc_reclen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1539
	uint64_t txtype = lr->lrc_txtype;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1540
	int error = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1541
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1542
	zilog->zl_replaying_seq = lr->lrc_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1543
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1544
	if (lr->lrc_seq <= zh->zh_replay_seq)	/* already replayed */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1545
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1546
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
	if (lr->lrc_txg < claim_txg)		/* already committed */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1548
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1550
	/* Strip case-insensitive bit, still present in log record */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1551
	txtype &= ~TX_CI;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1552
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1553
	if (txtype == 0 || txtype >= TX_MAX_TYPE)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1554
		return (zil_replay_error(zilog, lr, EINVAL));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1555
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1556
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1557
	 * If this record type can be logged out of order, the object
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1558
	 * (lr_foid) may no longer exist.  That's legitimate, not an error.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1559
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1560
	if (TX_OOO(txtype)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1561
		error = dmu_object_info(zilog->zl_os,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1562
		    ((lr_ooo_t *)lr)->lr_foid, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1563
		if (error == ENOENT || error == EEXIST)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1564
			return (0);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1565
	}
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1566
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
	 * Make a copy of the data so we can revise and extend it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1570
	bcopy(lr, zr->zr_lr, reclen);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1571
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1572
	/*
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1573
	 * If this is a TX_WRITE with a blkptr, suck in the data.
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1574
	 */
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1575
	if (txtype == TX_WRITE && reclen == sizeof (lr_write_t)) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1576
		error = zil_read_log_data(zilog, (lr_write_t *)lr,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1577
		    zr->zr_lr + reclen);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1578
		if (error)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1579
			return (zil_replay_error(zilog, lr, error));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1580
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
	 * The log block containing this lr may have been byteswapped
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
	 * so that we can easily examine common fields like lrc_txtype.
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1585
	 * However, the log is a mix of different record types, and only the
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
	 * replay vectors know how to byteswap their records.  Therefore, if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
	 * the lr was byteswapped, undo it before invoking the replay vector.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
	if (zr->zr_byteswap)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1590
		byteswap_uint64_array(zr->zr_lr, reclen);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
	 * We must now do two things atomically: replay this log record,
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1594
	 * and update the log header sequence number to reflect the fact that
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1595
	 * we did so. At the end of each replay function the sequence number
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1596
	 * is updated if we are in replay mode.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1598
	error = zr->zr_replay[txtype](zr->zr_arg, zr->zr_lr, zr->zr_byteswap);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1599
	if (error) {
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1600
		/*
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1601
		 * The DMU's dnode layer doesn't see removes until the txg
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1602
		 * commits, so a subsequent claim can spuriously fail with
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1603
		 * EEXIST. So if we receive any error we try syncing out
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1604
		 * any removes then retry the transaction.  Note that we
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1605
		 * specify B_FALSE for byteswap now, so we don't do it twice.
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1606
		 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1607
		txg_wait_synced(spa_get_dsl(zilog->zl_spa), 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1608
		error = zr->zr_replay[txtype](zr->zr_arg, zr->zr_lr, B_FALSE);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1609
		if (error)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1610
			return (zil_replay_error(zilog, lr, error));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1612
	return (0);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1613
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1615
/* ARGSUSED */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1616
static int
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1617
zil_incr_blks(zilog_t *zilog, blkptr_t *bp, void *arg, uint64_t claim_txg)
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1618
{
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1619
	zilog->zl_replay_blks++;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1620
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1621
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
/*
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1625
 * If this dataset has a non-empty intent log, replay it and destroy it.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1626
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
void
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1628
zil_replay(objset_t *os, void *arg, zil_replay_func_t *replay_func[TX_MAX_TYPE])
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
	zilog_t *zilog = dmu_objset_zil(os);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1631
	const zil_header_t *zh = zilog->zl_header;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1632
	zil_replay_arg_t zr;
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1633
8989
cfce31f4eebf 6462803 zfs snapshot -r failed because filesystem was busy
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8746
diff changeset
  1634
	if ((zh->zh_flags & ZIL_REPLAY_NEEDED) == 0) {
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1635
		zil_destroy(zilog, B_TRUE);
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1636
		return;
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1637
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
	zr.zr_replay = replay_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
	zr.zr_arg = arg;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1641
	zr.zr_byteswap = BP_SHOULD_BYTESWAP(&zh->zh_log);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1642
	zr.zr_lr = kmem_alloc(2 * SPA_MAXBLOCKSIZE, KM_SLEEP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	 * Wait for in-progress removes to sync before starting replay.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	txg_wait_synced(zilog->zl_dmu_pool, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1649
	zilog->zl_replay = B_TRUE;
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10922
diff changeset
  1650
	zilog->zl_replay_time = ddi_get_lbolt();
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1651
	ASSERT(zilog->zl_replay_blks == 0);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1652
	(void) zil_parse(zilog, zil_incr_blks, zil_replay_log_record, &zr,
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1653
	    zh->zh_claim_txg);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1654
	kmem_free(zr.zr_lr, 2 * SPA_MAXBLOCKSIZE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1655
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1656
	zil_destroy(zilog, B_FALSE);
5712
81f1af42bafc 6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents: 5688
diff changeset
  1657
	txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8109
diff changeset
  1658
	zilog->zl_replay = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
}
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1660
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1661
boolean_t
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1662
zil_replaying(zilog_t *zilog, dmu_tx_t *tx)
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1663
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1664
	if (zilog == NULL)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1665
		return (B_TRUE);
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1666
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1667
	if (zilog->zl_replay) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1668
		dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1669
		zilog->zl_replayed_seq[dmu_tx_get_txg(tx) & TXG_MASK] =
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1670
		    zilog->zl_replaying_seq;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1671
		return (B_TRUE);
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1672
	}
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1673
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1674
	return (B_FALSE);
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1675
}
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1676
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1677
/* ARGSUSED */
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1678
int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11066
diff changeset
  1679
zil_vdev_offline(const char *osname, void *arg)
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1680
{
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1681
	objset_t *os;
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1682
	zilog_t *zilog;
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1683
	int error;
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1684
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10209
diff changeset
  1685
	error = dmu_objset_hold(osname, FTAG, &os);
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1686
	if (error)
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1687
		return (error);
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1688
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1689
	zilog = dmu_objset_zil(os);
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1690
	if (zil_suspend(zilog) != 0)
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1691
		error = EEXIST;
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1692
	else
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1693
		zil_resume(zilog);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10209
diff changeset
  1694
	dmu_objset_rele(os, FTAG);
9701
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1695
	return (error);
cc5b64682e64 6803605 should be able to offline log devices
George Wilson <George.Wilson@Sun.COM>
parents: 9493
diff changeset
  1696
}