usr/src/uts/common/fs/zfs/zil.c
author perrin
Thu, 24 Jul 2008 11:23:47 -0700
changeset 7181 8d299641aa23
parent 7046 361307ae060d
child 7294 c9c31ef4c960
permissions -rw-r--r--
6719934 assertion failed: ((&zh->zh_log)->blk_birth == 0), file: ../../common/fs/zfs/zil.c, line: 1336 6724738 ztest fails assertion in txg_list_destroy(): txg_list_empty(tl, t)
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
/*
5809
084c69fe7d0a 6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents: 5712
diff changeset
    22
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/arc.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/zil_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/vdev.h>
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
    39
#include <sys/dmu_tx.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * The zfs intent log (ZIL) saves transaction records of system calls
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 * that change the file system in memory with enough information
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 * to be able to replay them. These are stored in memory until
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 * either the DMU transaction group (txg) commits them to the stable pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
 * and they can be discarded, or they are flushed to the stable log
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
 * (also in the pool) due to a fsync, O_DSYNC or other synchronous
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
 * requirement. In the event of a panic or power fail then those log
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
 * records (transactions) are replayed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 * There is one ZIL per file system. Its on-disk (pool) format consists
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 * of 3 parts:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
 * 	- ZIL header
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
 * 	- ZIL blocks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
 * 	- ZIL records
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 * A log record holds a system call transaction. Log blocks can
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 * hold many log records and the blocks are chained together.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * Each ZIL block contains a block pointer (blkptr_t) to the next
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 * ZIL block in the chain. The ZIL header points to the first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 * block in the chain. Note there is not a fixed place in the pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 * to hold blocks. They are dynamically allocated and freed as
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
 * needed from the blocks available. Figure X shows the ZIL structure:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
/*
2986
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    68
 * This global ZIL switch affects all pools
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
int zil_disable = 0;	/* disable intent logging */
2986
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    71
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    72
/*
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    73
 * Tunable parameter for debugging or performance analysis.  Setting
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    74
 * zfs_nocacheflush will cause corruption on power loss if a volatile
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    75
 * out-of-order write cache is enabled.
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    76
 */
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
    77
boolean_t zfs_nocacheflush = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
static kmem_cache_t *zil_lwb_cache;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
zil_dva_compare(const void *x1, const void *x2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
	const dva_t *dva1 = x1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
	const dva_t *dva2 = x2;
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
zil_dva_tree_init(avl_tree_t *t)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	avl_create(t, zil_dva_compare, sizeof (zil_dva_node_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	    offsetof(zil_dva_node_t, zn_node));
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
zil_dva_tree_fini(avl_tree_t *t)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	zil_dva_node_t *zn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	void *cookie = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	while ((zn = avl_destroy_nodes(t, &cookie)) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
		kmem_free(zn, sizeof (zil_dva_node_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	avl_destroy(t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
zil_dva_tree_add(avl_tree_t *t, dva_t *dva)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	zil_dva_node_t *zn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	avl_index_t where;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	if (avl_find(t, dva, &where) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	zn = kmem_alloc(sizeof (zil_dva_node_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	zn->zn_dva = *dva;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	avl_insert(t, zn, where);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   135
static zil_header_t *
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   136
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
   137
{
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   138
	return ((zil_header_t *)zilog->zl_header);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   139
}
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
static void
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   142
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
   143
{
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   144
	zio_cksum_t *zc = &bp->blk_cksum;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   145
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   146
	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
   147
	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
   148
	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
   149
	zc->zc_word[ZIL_ZC_SEQ] = 1ULL;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   150
}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   151
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
 * Read a log block, make sure it's valid, and byteswap it if necessary.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
static int
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   156
zil_read_log_block(zilog_t *zilog, const blkptr_t *bp, arc_buf_t **abufpp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   158
	blkptr_t blk = *bp;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   159
	zbookmark_t zb;
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
   160
	uint32_t aflags = ARC_WAIT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   163
	zb.zb_objset = bp->blk_cksum.zc_word[ZIL_ZC_OBJSET];
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   164
	zb.zb_object = 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   165
	zb.zb_level = -1;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   166
	zb.zb_blkid = bp->blk_cksum.zc_word[ZIL_ZC_SEQ];
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   167
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   168
	*abufpp = NULL;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   169
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   170
	/*
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   171
	 * We shouldn't be doing any scrubbing while we're doing log
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   172
	 * replay, it's OK to not lock.
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   173
	 */
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7030
diff changeset
   174
	error = arc_read_nolock(NULL, zilog->zl_spa, &blk,
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   175
	    arc_getbuf_func, abufpp, ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL |
2391
2fa3fd1db808 6447377 ZFS prefetch is inconsistant
maybee
parents: 2237
diff changeset
   176
	    ZIO_FLAG_SPECULATIVE | ZIO_FLAG_SCRUB, &aflags, &zb);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   177
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   178
	if (error == 0) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   179
		char *data = (*abufpp)->b_data;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   180
		uint64_t blksz = BP_GET_LSIZE(bp);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   181
		zil_trailer_t *ztp = (zil_trailer_t *)(data + blksz) - 1;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   182
		zio_cksum_t cksum = bp->blk_cksum;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   183
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   184
		/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   185
		 * Sequence numbers should be... sequential.  The checksum
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   186
		 * verifier for the next block should be bp's checksum plus 1.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   187
		 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   188
		cksum.zc_word[ZIL_ZC_SEQ]++;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   189
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   190
		if (bcmp(&cksum, &ztp->zit_next_blk.blk_cksum, sizeof (cksum)))
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   191
			error = ESTALE;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   192
		else if (BP_IS_HOLE(&ztp->zit_next_blk))
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   193
			error = ENOENT;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   194
		else if (ztp->zit_nused > (blksz - sizeof (zil_trailer_t)))
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   195
			error = EOVERFLOW;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   196
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   197
		if (error) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   198
			VERIFY(arc_buf_remove_ref(*abufpp, abufpp) == 1);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   199
			*abufpp = NULL;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   200
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   203
	dprintf("error %d on %llu:%llu\n", error, zb.zb_objset, zb.zb_blkid);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   205
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
 * Parse the intent log, and call parse_func for each valid record within.
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   210
 * Return the highest sequence number.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
 */
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   212
uint64_t
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
zil_parse(zilog_t *zilog, zil_parse_blk_func_t *parse_blk_func,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
    zil_parse_lr_func_t *parse_lr_func, void *arg, uint64_t txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   216
	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
   217
	uint64_t claim_seq = zh->zh_claim_seq;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   218
	uint64_t seq = 0;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   219
	uint64_t max_seq = 0;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   220
	blkptr_t blk = zh->zh_log;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   221
	arc_buf_t *abuf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	char *lrbuf, *lrp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	zil_trailer_t *ztp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
	int reclen, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	if (BP_IS_HOLE(&blk))
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   227
		return (max_seq);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
	 * Starting at the block pointed to by zh_log we read the log chain.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
	 * For each block in the chain we strongly check that block to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
	 * ensure its validity.  We stop when an invalid block is found.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	 * For each block pointer in the chain we call parse_blk_func().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
	 * 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
   235
	 * 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
   236
	 * number greater than the highest claimed sequence number.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
	zil_dva_tree_init(&zilog->zl_dva_tree);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
	for (;;) {
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   240
		seq = blk.blk_cksum.zc_word[ZIL_ZC_SEQ];
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   241
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   242
		if (claim_seq != 0 && seq > claim_seq)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   243
			break;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   244
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   245
		ASSERT(max_seq < seq);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   246
		max_seq = seq;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   247
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   248
		error = zil_read_log_block(zilog, &blk, &abuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
		if (parse_blk_func != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
			parse_blk_func(zilog, &blk, arg, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
		if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   256
		lrbuf = abuf->b_data;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
		ztp = (zil_trailer_t *)(lrbuf + BP_GET_LSIZE(&blk)) - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
		blk = ztp->zit_next_blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   260
		if (parse_lr_func == NULL) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   261
			VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
			continue;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   263
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
		for (lrp = lrbuf; lrp < lrbuf + ztp->zit_nused; lrp += reclen) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
			lr_t *lr = (lr_t *)lrp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
			reclen = lr->lrc_reclen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
			ASSERT3U(reclen, >=, sizeof (lr_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
			parse_lr_func(zilog, lr, arg, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
		}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   271
		VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	zil_dva_tree_fini(&zilog->zl_dva_tree);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   274
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   275
	return (max_seq);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
zil_claim_log_block(zilog_t *zilog, blkptr_t *bp, void *tx, uint64_t first_txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
	spa_t *spa = zilog->zl_spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
	 * Claim log block if not already committed and not already claimed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	if (bp->blk_birth >= first_txg &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
	    zil_dva_tree_add(&zilog->zl_dva_tree, BP_IDENTITY(bp)) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
		err = zio_wait(zio_claim(NULL, spa, first_txg, bp, NULL, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
		ASSERT(err == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
zil_claim_log_record(zilog_t *zilog, lr_t *lrc, void *tx, uint64_t first_txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	if (lrc->lrc_txtype == TX_WRITE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
		lr_write_t *lr = (lr_write_t *)lrc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
		zil_claim_log_block(zilog, &lr->lr_blkptr, tx, first_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
zil_free_log_block(zilog_t *zilog, blkptr_t *bp, void *tx, uint64_t claim_txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
	zio_free_blk(zilog->zl_spa, bp, dmu_tx_get_txg(tx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
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
   313
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
	 * If we previously claimed it, we need to free it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
	if (claim_txg != 0 && lrc->lrc_txtype == TX_WRITE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
		lr_write_t *lr = (lr_write_t *)lrc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
		blkptr_t *bp = &lr->lr_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
		if (bp->blk_birth >= claim_txg &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
		    !zil_dva_tree_add(&zilog->zl_dva_tree, BP_IDENTITY(bp))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
			(void) arc_free(NULL, zilog->zl_spa,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
			    dmu_tx_get_txg(tx), bp, NULL, NULL, ARC_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
 * Create an on-disk intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
zil_create(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   334
	const zil_header_t *zh = zilog->zl_header;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	lwb_t *lwb;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   336
	uint64_t txg = 0;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   337
	dmu_tx_t *tx = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	blkptr_t blk;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   339
	int error = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
	/*
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   342
	 * Wait for any previous destroy to complete.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
	 */
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   344
	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
   345
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   346
	ASSERT(zh->zh_claim_txg == 0);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   347
	ASSERT(zh->zh_replay_seq == 0);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   348
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   349
	blk = zh->zh_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
	/*
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   352
	 * If we don't already have an initial log block, allocate one now.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
	 */
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   354
	if (BP_IS_HOLE(&blk)) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   355
		tx = dmu_tx_create(zilog->zl_os);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   356
		(void) dmu_tx_assign(tx, TXG_WAIT);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   357
		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
   358
		txg = dmu_tx_get_txg(tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   359
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   360
		error = zio_alloc_blk(zilog->zl_spa, ZIL_MIN_BLKSZ, &blk,
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   361
		    NULL, txg);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   362
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   363
		if (error == 0)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   364
			zil_init_log_chain(zilog, &blk);
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
   365
	}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   366
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   367
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   368
	 * 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
   369
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
		lwb = kmem_cache_alloc(zil_lwb_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
		lwb->lwb_zilog = zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
		lwb->lwb_blk = blk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
		lwb->lwb_nused = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
		lwb->lwb_sz = BP_GET_LSIZE(&lwb->lwb_blk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
		lwb->lwb_buf = zio_buf_alloc(lwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
		lwb->lwb_max_txg = txg;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   378
		lwb->lwb_zio = NULL;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   379
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
		mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
		list_insert_tail(&zilog->zl_lwb_list, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
		mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   385
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   386
	 * 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
   387
	 * 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
   388
	 * (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
   389
	 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   390
	if (tx != NULL) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   391
		dmu_tx_commit(tx);
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
   392
		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
   393
	}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   394
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   395
	ASSERT(bcmp(&blk, &zh->zh_log, sizeof (blk)) == 0);
789
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
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
 * 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
   400
 * 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
   401
 * 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
   402
 * 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
   403
 * 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
   404
 * 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
   405
 * will wait for any in-progress destroys to complete.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
void
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   408
zil_destroy(zilog_t *zilog, boolean_t keep_first)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   410
	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
   411
	lwb_t *lwb;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
	uint64_t txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   415
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   416
	 * Wait for any previous destroy to complete.
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
	txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   420
	if (BP_IS_HOLE(&zh->zh_log))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	tx = dmu_tx_create(zilog->zl_os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
	(void) dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
	dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
	txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   428
	mutex_enter(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   429
5223
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   430
	/*
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   431
	 * It is possible for the ZIL to get the previously mounted zilog
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   432
	 * structure of the same dataset if quickly remounted and the dbuf
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   433
	 * eviction has not completed. In this case we can see a non
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   434
	 * empty lwb list and keep_first will be set. We fix this by
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   435
	 * clearing the keep_first. This will be slower but it's very rare.
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   436
	 */
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   437
	if (!list_is_empty(&zilog->zl_lwb_list) && keep_first)
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   438
		keep_first = B_FALSE;
ca2e1fd5ee29 6603147 Machines fail with: "assertion failed: !keep_first, file: ../../common/fs/zfs/zil.c, line: 432"
perrin
parents: 4935
diff changeset
   439
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   440
	ASSERT3U(zilog->zl_destroy_txg, <, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	zilog->zl_destroy_txg = txg;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   442
	zilog->zl_keep_first = keep_first;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   443
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   444
	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
   445
		ASSERT(zh->zh_claim_txg == 0);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   446
		ASSERT(!keep_first);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   447
		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
   448
			list_remove(&zilog->zl_lwb_list, lwb);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   449
			if (lwb->lwb_buf != NULL)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   450
				zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   451
			zio_free_blk(zilog->zl_spa, &lwb->lwb_blk, txg);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   452
			kmem_cache_free(zil_lwb_cache, lwb);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   453
		}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   454
	} else {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   455
		if (!keep_first) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   456
			(void) zil_parse(zilog, zil_free_log_block,
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   457
			    zil_free_log_record, tx, zh->zh_claim_txg);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   458
		}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   459
	}
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   460
	mutex_exit(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
4935
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   465
/*
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   466
 * zil_rollback_destroy() is only called by the rollback code.
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   467
 * We already have a syncing tx. Rollback has exclusive access to the
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   468
 * dataset, so we don't have to worry about concurrent zil access.
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   469
 * The actual freeing of any log blocks occurs in zil_sync() later in
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   470
 * this txg syncing phase.
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   471
 */
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   472
void
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   473
zil_rollback_destroy(zilog_t *zilog, dmu_tx_t *tx)
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   474
{
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   475
	const zil_header_t *zh = zilog->zl_header;
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   476
	uint64_t txg;
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   477
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   478
	if (BP_IS_HOLE(&zh->zh_log))
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   479
		return;
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   480
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   481
	txg = dmu_tx_get_txg(tx);
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   482
	ASSERT3U(zilog->zl_destroy_txg, <, txg);
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   483
	zilog->zl_destroy_txg = txg;
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   484
	zilog->zl_keep_first = B_FALSE;
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   485
5809
084c69fe7d0a 6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents: 5712
diff changeset
   486
	/*
084c69fe7d0a 6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents: 5712
diff changeset
   487
	 * Ensure there's no outstanding ZIL IO.  No lwbs or just the
084c69fe7d0a 6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents: 5712
diff changeset
   488
	 * unused one that allocated in advance is ok.
084c69fe7d0a 6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents: 5712
diff changeset
   489
	 */
084c69fe7d0a 6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents: 5712
diff changeset
   490
	ASSERT(zilog->zl_lwb_list.list_head.list_next ==
084c69fe7d0a 6627433 ASSERT: list_is_empty(&zilog->zl_lwb_list), zil.c, line 488
perrin
parents: 5712
diff changeset
   491
	    zilog->zl_lwb_list.list_head.list_prev);
4935
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   492
	(void) zil_parse(zilog, zil_free_log_block, zil_free_log_record,
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   493
	    tx, zh->zh_claim_txg);
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   494
}
c80bf0e6f4aa 6534949 Stale need for range locking comment in zvol.c
perrin
parents: 4527
diff changeset
   495
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 1842
diff changeset
   496
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
zil_claim(char *osname, void *txarg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
	dmu_tx_t *tx = txarg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	uint64_t first_txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	zilog_t *zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	zil_header_t *zh;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	objset_t *os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6101
diff changeset
   506
	error = dmu_objset_open(osname, DMU_OST_ANY, DS_MODE_USER, &os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
		cmn_err(CE_WARN, "can't process intent log for %s", osname);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 1842
diff changeset
   509
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
	zilog = dmu_objset_zil(os);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   513
	zh = zil_header_in_syncing_context(zilog);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
	/*
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   516
	 * 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
   517
	 * 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
   518
	 * 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
   519
	 * 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
   520
	 * or destroy beyond the last block we successfully claimed.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
	ASSERT3U(zh->zh_claim_txg, <=, first_txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
	if (zh->zh_claim_txg == 0 && !BP_IS_HOLE(&zh->zh_log)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
		zh->zh_claim_txg = first_txg;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   525
		zh->zh_claim_seq = zil_parse(zilog, zil_claim_log_block,
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   526
		    zil_claim_log_record, tx, first_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
		dsl_dataset_dirty(dmu_objset_ds(os), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   529
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	ASSERT3U(first_txg, ==, (spa_last_synced_txg(zilog->zl_spa) + 1));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	dmu_objset_close(os);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 1842
diff changeset
   532
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   535
static int
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   536
zil_vdev_compare(const void *x1, const void *x2)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
{
5875
599b7007a9cd 6653210 zil_vdev_compare() compares pointers instead of vdev ids
perrin
parents: 5809
diff changeset
   538
	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
   539
	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
   540
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   541
	if (v1 < v2)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   542
		return (-1);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   543
	if (v1 > v2)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   544
		return (1);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   545
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   546
	return (0);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   547
}
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   548
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   549
void
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   550
zil_add_block(zilog_t *zilog, blkptr_t *bp)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   551
{
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   552
	avl_tree_t *t = &zilog->zl_vdev_tree;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   553
	avl_index_t where;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   554
	zil_vdev_node_t *zv, zvsearch;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   555
	int ndvas = BP_GET_NDVAS(bp);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   556
	int i;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
2986
c782fcf7a319 6485204 more tuneable tweakin
ek110237
parents: 2856
diff changeset
   558
	if (zfs_nocacheflush)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   561
	ASSERT(zilog->zl_writer);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   562
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   563
	/*
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   564
	 * 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
   565
	 * 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
   566
	 * that will run concurrently.
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   567
	 */
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   568
	mutex_enter(&zilog->zl_vdev_lock);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   569
	for (i = 0; i < ndvas; i++) {
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   570
		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
   571
		if (avl_find(t, &zvsearch, &where) == NULL) {
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   572
			zv = kmem_alloc(sizeof (*zv), KM_SLEEP);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   573
			zv->zv_vdev = zvsearch.zv_vdev;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   574
			avl_insert(t, zv, where);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   575
		}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   576
	}
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   577
	mutex_exit(&zilog->zl_vdev_lock);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   578
}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   579
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
void
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   581
zil_flush_vdevs(zilog_t *zilog)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
{
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   583
	spa_t *spa = zilog->zl_spa;
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   584
	avl_tree_t *t = &zilog->zl_vdev_tree;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   585
	void *cookie = NULL;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   586
	zil_vdev_node_t *zv;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   587
	zio_t *zio;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   588
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   589
	ASSERT(zilog->zl_writer);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   591
	/*
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   592
	 * 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
   593
	 * and all zl_get_data() callbacks are done.
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   594
	 */
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   595
	if (avl_numnodes(t) == 0)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   596
		return;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   597
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   598
	spa_config_enter(spa, RW_READER, FTAG);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   599
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   600
	zio = zio_root(spa, NULL, NULL,
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   601
	    ZIO_FLAG_CONFIG_HELD | ZIO_FLAG_CANFAIL);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   602
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   603
	while ((zv = avl_destroy_nodes(t, &cookie)) != NULL) {
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   604
		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
   605
		if (vd != NULL)
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   606
			zio_flush(zio, vd);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   607
		kmem_free(zv, sizeof (*zv));
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   608
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
	 * Wait for all the flushes to complete.  Not all devices actually
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
	 * support the DKIOCFLUSHWRITECACHE ioctl, so it's OK if it fails.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
	 */
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   614
	(void) zio_wait(zio);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   615
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   616
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
 * Function called when a log block write completes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
zil_lwb_write_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
	lwb_t *lwb = zio->io_private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
	zilog_t *zilog = lwb->lwb_zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
	 * Now that we've written this log block, we have a stable pointer
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
	 * to the next block in the chain, so it's OK to let the txg in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
	 * which we allocated the next block sync.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
	txg_rele_to_sync(&lwb->lwb_txgh);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
	zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
	lwb->lwb_buf = NULL;
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
   638
	if (zio->io_error)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
		zilog->zl_log_error = B_TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
/*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   644
 * Initialize the io for a log block.
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   645
 *
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   646
 * Note, we should not initialize the IO until we are about
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   647
 * to use it, since zio_rewrite() does a spa_config_enter().
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   648
 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   649
static void
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   650
zil_lwb_write_init(zilog_t *zilog, lwb_t *lwb)
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   651
{
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   652
	zbookmark_t zb;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   653
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   654
	zb.zb_objset = lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_OBJSET];
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   655
	zb.zb_object = 0;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   656
	zb.zb_level = -1;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   657
	zb.zb_blkid = lwb->lwb_blk.blk_cksum.zc_word[ZIL_ZC_SEQ];
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   658
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   659
	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
   660
		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
   661
		    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
   662
	}
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   663
	if (lwb->lwb_zio == NULL) {
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   664
		lwb->lwb_zio = zio_rewrite(zilog->zl_root_zio, zilog->zl_spa,
7181
8d299641aa23 6719934 assertion failed: ((&zh->zh_log)->blk_birth == 0), file: ../../common/fs/zfs/zil.c, line: 1336
perrin
parents: 7046
diff changeset
   665
		    ZIO_CHECKSUM_ZILOG, 0, &lwb->lwb_blk, lwb->lwb_buf,
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   666
		    lwb->lwb_sz, zil_lwb_write_done, lwb,
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4469
diff changeset
   667
		    ZIO_PRIORITY_LOG_WRITE, ZIO_FLAG_CANFAIL, &zb);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   668
	}
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   669
}
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   670
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   671
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
 * Start a log block write and advance to the next log block.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
 * Calls are serialized.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
static lwb_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
zil_lwb_write_start(zilog_t *zilog, lwb_t *lwb)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
	lwb_t *nlwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
	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
   680
	spa_t *spa = zilog->zl_spa;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   681
	blkptr_t *bp = &ztp->zit_next_blk;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
	uint64_t txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
	uint64_t zil_blksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
	ASSERT(lwb->lwb_nused <= ZIL_BLK_DATA_SZ(lwb));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
	 * Allocate the next block and save its address in this block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
	 * before writing it in order to establish the log chain.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
	 * Note that if the allocation of nlwb synced before we wrote
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
	 * the block that points at it (lwb), we'd leak it if we crashed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
	 * Therefore, we don't do txg_rele_to_sync() until zil_lwb_write_done().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
	txg = txg_hold_open(zilog->zl_dmu_pool, &lwb->lwb_txgh);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
	txg_rele_to_quiesce(&lwb->lwb_txgh);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
	/*
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   699
	 * Pick a ZIL blocksize. We request a size that is the
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   700
	 * maximum of the previous used size, the current used size and
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   701
	 * the amount waiting in the queue.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
	 */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   703
	zil_blksz = MAX(zilog->zl_prev_used,
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   704
	    zilog->zl_cur_used + sizeof (*ztp));
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   705
	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
   706
	zil_blksz = P2ROUNDUP_TYPED(zil_blksz, ZIL_MIN_BLKSZ, uint64_t);
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   707
	if (zil_blksz > ZIL_MAX_BLKSZ)
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
   708
		zil_blksz = ZIL_MAX_BLKSZ;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   710
	BP_ZERO(bp);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   711
	/* pass the old blkptr in order to spread log blocks across devs */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   712
	error = zio_alloc_blk(spa, zil_blksz, bp, &lwb->lwb_blk, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
	if (error) {
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   714
		dmu_tx_t *tx = dmu_tx_create_assigned(zilog->zl_dmu_pool, txg);
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   715
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   716
		/*
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   717
		 * We dirty the dataset to ensure that zil_sync() will
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   718
		 * be called to remove this lwb from our zl_lwb_list.
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   719
		 * Failing to do so, may leave an lwb with a NULL lwb_buf
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   720
		 * hanging around on the zl_lwb_list.
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   721
		 */
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   722
		dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
3848
abf146257cf9 6495013 Loops and recursion in metaslab_ff_alloc can kill performance, even on a pool with lots of free data
gw25295
parents: 3778
diff changeset
   723
		dmu_tx_commit(tx);
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   724
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   725
		/*
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   726
		 * Since we've just experienced an allocation failure so we
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   727
		 * terminate the current lwb and send it on its way.
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   728
		 */
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   729
		ztp->zit_pad = 0;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   730
		ztp->zit_nused = lwb->lwb_nused;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   731
		ztp->zit_bt.zbt_cksum = lwb->lwb_blk.blk_cksum;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   732
		zio_nowait(lwb->lwb_zio);
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   733
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   734
		/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   735
		 * By returning NULL the caller will call tx_wait_synced()
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   736
		 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   740
	ASSERT3U(bp->blk_birth, ==, txg);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
   741
	ztp->zit_pad = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
	ztp->zit_nused = lwb->lwb_nused;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
	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
   744
	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
   745
	bp->blk_cksum.zc_word[ZIL_ZC_SEQ]++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
	 * Allocate a new log write buffer (lwb).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
	nlwb = kmem_cache_alloc(zil_lwb_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
	nlwb->lwb_zilog = zilog;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
   753
	nlwb->lwb_blk = *bp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
	nlwb->lwb_nused = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
	nlwb->lwb_sz = BP_GET_LSIZE(&nlwb->lwb_blk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	nlwb->lwb_buf = zio_buf_alloc(nlwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
	nlwb->lwb_max_txg = txg;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   758
	nlwb->lwb_zio = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
	/*
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   761
	 * Put new lwb at the end of the log chain
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	list_insert_tail(&zilog->zl_lwb_list, nlwb);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   765
	mutex_exit(&zilog->zl_lock);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   766
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   767
	/* Record the block for later vdev flushing */
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
   768
	zil_add_block(zilog, &lwb->lwb_blk);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
	/*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   771
	 * kick off the write for the old log block
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
	 */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   773
	dprintf_bp(&lwb->lwb_blk, "lwb %p txg %llu: ", lwb, txg);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   774
	ASSERT(lwb->lwb_zio);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   775
	zio_nowait(lwb->lwb_zio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
	return (nlwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
static lwb_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
zil_lwb_commit(zilog_t *zilog, itx_t *itx, lwb_t *lwb)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	lr_t *lrc = &itx->itx_lr; /* common log record */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   784
	lr_write_t *lr = (lr_write_t *)lrc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	uint64_t txg = lrc->lrc_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	uint64_t reclen = lrc->lrc_reclen;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   787
	uint64_t dlen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
	if (lwb == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
	ASSERT(lwb->lwb_buf != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   793
	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
   794
		dlen = P2ROUNDUP_TYPED(
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   795
		    lr->lr_length, sizeof (uint64_t), uint64_t);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   796
	else
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   797
		dlen = 0;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   798
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   799
	zilog->zl_cur_used += (reclen + dlen);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   800
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   801
	zil_lwb_write_init(zilog, lwb);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   802
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   803
	/*
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   804
	 * 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
   805
	 */
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   806
	if (lwb->lwb_nused + reclen + dlen > ZIL_BLK_DATA_SZ(lwb)) {
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   807
		lwb = zil_lwb_write_start(zilog, lwb);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   808
		if (lwb == NULL)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   809
			return (NULL);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   810
		zil_lwb_write_init(zilog, lwb);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   811
		ASSERT(lwb->lwb_nused == 0);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   812
		if (reclen + dlen > ZIL_BLK_DATA_SZ(lwb)) {
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   813
			txg_wait_synced(zilog->zl_dmu_pool, txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
			return (lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   818
	/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   819
	 * Update the lrc_seq, to be log record sequence number. See zil.h
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   820
	 * Then copy the record to the log buffer.
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   821
	 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   822
	lrc->lrc_seq = ++zilog->zl_lr_seq; /* we are single threaded */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
	bcopy(lrc, lwb->lwb_buf + lwb->lwb_nused, reclen);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   824
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   825
	/*
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   826
	 * 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
   827
	 */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   828
	if (lrc->lrc_txtype == TX_WRITE) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   829
		if (txg > spa_freeze_txg(zilog->zl_spa))
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   830
			txg_wait_synced(zilog->zl_dmu_pool, txg);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   831
		if (itx->itx_wr_state != WR_COPIED) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   832
			char *dbuf;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   833
			int error;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   834
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   835
			/* alignment is guaranteed */
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   836
			lr = (lr_write_t *)(lwb->lwb_buf + lwb->lwb_nused);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   837
			if (dlen) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   838
				ASSERT(itx->itx_wr_state == WR_NEED_COPY);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   839
				dbuf = lwb->lwb_buf + lwb->lwb_nused + reclen;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   840
				lr->lr_common.lrc_reclen += dlen;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   841
			} else {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   842
				ASSERT(itx->itx_wr_state == WR_INDIRECT);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   843
				dbuf = NULL;
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   844
			}
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   845
			error = zilog->zl_get_data(
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   846
			    itx->itx_private, lr, dbuf, lwb->lwb_zio);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   847
			if (error) {
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   848
				ASSERT(error == ENOENT || error == EEXIST ||
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   849
				    error == EALREADY);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   850
				return (lwb);
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   851
			}
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   852
		}
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1646
diff changeset
   853
	}
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   854
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2199
diff changeset
   855
	lwb->lwb_nused += reclen + dlen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
	lwb->lwb_max_txg = MAX(lwb->lwb_max_txg, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
	ASSERT3U(lwb->lwb_nused, <=, ZIL_BLK_DATA_SZ(lwb));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
	ASSERT3U(P2PHASE(lwb->lwb_nused, sizeof (uint64_t)), ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
	return (lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
itx_t *
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
   864
zil_itx_create(uint64_t txtype, size_t lrsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
1842
1712a484fc9d 6413731 pathologically slower fsync on 32 bit systems
perrin
parents: 1807
diff changeset
   868
	lrsize = P2ROUNDUP_TYPED(lrsize, sizeof (uint64_t), size_t);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	itx = kmem_alloc(offsetof(itx_t, itx_lr) + lrsize, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
	itx->itx_lr.lrc_txtype = txtype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	itx->itx_lr.lrc_reclen = lrsize;
6101
915df4cedbc9 6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents: 5913
diff changeset
   873
	itx->itx_sod = lrsize; /* if write & WR_NEED_COPY will be increased */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
	itx->itx_lr.lrc_seq = 0;	/* defensive */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
	return (itx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
zil_itx_assign(zilog_t *zilog, itx_t *itx, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
	ASSERT(itx->itx_lr.lrc_seq == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
	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
   888
	zilog->zl_itx_list_sz += itx->itx_sod;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
	itx->itx_lr.lrc_txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
	itx->itx_lr.lrc_seq = seq = ++zilog->zl_itx_seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
	return (seq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
 * Free up all in-memory intent log transactions that have now been synced.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
zil_itx_clean(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
	uint64_t synced_txg = spa_last_synced_txg(zilog->zl_spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
	uint64_t freeze_txg = spa_freeze_txg(zilog->zl_spa);
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   904
	list_t clean_list;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   907
	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
   908
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
	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
   910
	/* 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
   911
	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
   912
		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
   913
	}
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   914
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   915
	/*
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   916
	 * 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
   917
	 * kmem_free without holding the zl_lock.
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   918
	 *
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   919
	 * 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
   920
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
	while ((itx = list_head(&zilog->zl_itx_list)) != NULL &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
	    itx->itx_lr.lrc_txg <= MIN(synced_txg, freeze_txg)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
		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
   924
		zilog->zl_itx_list_sz -= itx->itx_sod;
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   925
		list_insert_tail(&clean_list, itx);
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   926
	}
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   927
	cv_broadcast(&zilog->zl_cv_writer);
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   928
	mutex_exit(&zilog->zl_lock);
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   929
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   930
	/* destroy sync'd log transactions */
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   931
	while ((itx = list_head(&clean_list)) != NULL) {
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   932
		list_remove(&clean_list, itx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
		kmem_free(itx, offsetof(itx_t, itx_lr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
		    + itx->itx_lr.lrc_reclen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
	}
3778
7ea2cf578078 6452589 zl_lock still held excessively long
johansen
parents: 3668
diff changeset
   936
	list_destroy(&clean_list);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   939
/*
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   940
 * 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
   941
 * 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
   942
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
zil_clean(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
{
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   946
	itx_t *itx;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   947
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
	mutex_enter(&zilog->zl_lock);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   949
	itx = list_head(&zilog->zl_itx_list);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   950
	if ((itx != NULL) &&
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   951
	    (itx->itx_lr.lrc_txg <= spa_last_synced_txg(zilog->zl_spa))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
		(void) taskq_dispatch(zilog->zl_clean_taskq,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
		    (void (*)(void *))zil_itx_clean, zilog, TQ_NOSLEEP);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   954
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
void
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   959
zil_commit_writer(zilog_t *zilog, uint64_t seq, uint64_t foid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
	uint64_t txg;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   962
	uint64_t commit_seq = 0;
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   963
	itx_t *itx, *itx_next = (itx_t *)-1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
	lwb_t *lwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   967
	zilog->zl_writer = B_TRUE;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   968
	zilog->zl_root_zio = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
	spa = zilog->zl_spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
	if (zilog->zl_suspend) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
		lwb = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
		lwb = list_tail(&zilog->zl_lwb_list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
		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
   976
			/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   977
			 * 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
   978
			 * 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
   979
			 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   980
			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
   981
				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
   982
				return;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   983
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
			mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
			zil_create(zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
			mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
			lwb = list_tail(&zilog->zl_lwb_list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
   991
	/* 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
   992
	DTRACE_PROBE1(zil__cw1, zilog_t *, zilog);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
	for (;;) {
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   994
		/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   995
		 * Find the next itx to push:
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   996
		 * Push all transactions related to specified foid and all
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   997
		 * other transactions except TX_WRITE, TX_TRUNCATE,
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   998
		 * TX_SETATTR and TX_ACL for all other files.
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
   999
		 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1000
		if (itx_next != (itx_t *)-1)
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1001
			itx = itx_next;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1002
		else
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1003
			itx = list_head(&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
  1004
		for (; itx != NULL; itx = list_next(&zilog->zl_itx_list, itx)) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1005
			if (foid == 0) /* push all foids? */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1006
				break;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1007
			if (itx->itx_sync) /* push all O_[D]SYNC */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1008
				break;
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1009
			switch (itx->itx_lr.lrc_txtype) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1010
			case TX_SETATTR:
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1011
			case TX_WRITE:
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1012
			case TX_TRUNCATE:
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1013
			case TX_ACL:
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1014
				/* lr_foid is same offset for these records */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1015
				if (((lr_write_t *)&itx->itx_lr)->lr_foid
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1016
				    != foid) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1017
					continue; /* skip this record */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1018
				}
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1019
			}
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1020
			break;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1021
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
		if (itx == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
		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
  1026
		    ((lwb == NULL) || (lwb->lwb_nused == 0) ||
6101
915df4cedbc9 6658511 zl_itx_list_sz incorrect for WR_NEED_COPY writes
perrin
parents: 5913
diff changeset
  1027
		    (lwb->lwb_nused + itx->itx_sod > ZIL_BLK_DATA_SZ(lwb)))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
			break;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1029
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1031
		/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1032
		 * Save the next pointer.  Even though we soon drop
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1033
		 * zl_lock all threads that may change the list
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1034
		 * (another writer or zil_itx_clean) can't do so until
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1035
		 * they have zl_writer.
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1036
		 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1037
		itx_next = list_next(&zilog->zl_itx_list, itx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
		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
  1039
		zilog->zl_itx_list_sz -= itx->itx_sod;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1040
		mutex_exit(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
		txg = itx->itx_lr.lrc_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
		ASSERT(txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
		if (txg > spa_last_synced_txg(spa) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
		    txg > spa_freeze_txg(spa))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
			lwb = zil_lwb_commit(zilog, itx, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
		kmem_free(itx, offsetof(itx_t, itx_lr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
		    + itx->itx_lr.lrc_reclen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
		mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
	}
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1051
	DTRACE_PROBE1(zil__cw2, zilog_t *, zilog);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1052
	/* determine commit sequence number */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1053
	itx = list_head(&zilog->zl_itx_list);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1054
	if (itx)
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1055
		commit_seq = itx->itx_lr.lrc_seq;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1056
	else
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1057
		commit_seq = zilog->zl_itx_seq;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1060
	/* write the last block out */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1061
	if (lwb != NULL && lwb->lwb_zio != NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
		lwb = zil_lwb_write_start(zilog, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1064
	zilog->zl_prev_used = zilog->zl_cur_used;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1065
	zilog->zl_cur_used = 0;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1066
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1067
	/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1068
	 * 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
  1069
	 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1070
	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
  1071
		DTRACE_PROBE1(zil__cw3, zilog_t *, zilog);
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1072
		(void) zio_wait(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
  1073
		DTRACE_PROBE1(zil__cw4, zilog_t *, zilog);
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1074
		zil_flush_vdevs(zilog);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
	}
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1076
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
	if (zilog->zl_log_error || lwb == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
		zilog->zl_log_error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
		txg_wait_synced(zilog->zl_dmu_pool, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	}
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1081
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1082
	mutex_enter(&zilog->zl_lock);
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 789
diff changeset
  1083
	zilog->zl_writer = B_FALSE;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1084
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1085
	ASSERT3U(commit_seq, >=, zilog->zl_commit_seq);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1086
	zilog->zl_commit_seq = commit_seq;
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1087
}
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1088
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1089
/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1090
 * 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
  1091
 * 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
  1092
 * 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
  1093
 */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1094
void
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1095
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
  1096
{
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1097
	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
  1098
		return;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1099
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1100
	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
  1101
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1102
	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
  1103
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1104
	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
  1105
		cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1106
		if (seq < zilog->zl_commit_seq) {
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1107
			mutex_exit(&zilog->zl_lock);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1108
			return;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1109
		}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1110
	}
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1111
	zil_commit_writer(zilog, seq, foid); /* drops zl_lock */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1112
	/* wake up others waiting on the commit */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1113
	cv_broadcast(&zilog->zl_cv_writer);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1114
	mutex_exit(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
 * Called in syncing context to free committed log blocks and update log header.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
zil_sync(zilog_t *zilog, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1123
	zil_header_t *zh = zil_header_in_syncing_context(zilog);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
	uint64_t txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1125
	spa_t *spa = zilog->zl_spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1126
	lwb_t *lwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1127
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1128
	mutex_enter(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1129
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
	ASSERT(zilog->zl_stop_sync == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1131
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1132
	zh->zh_replay_seq = zilog->zl_replay_seq[txg & TXG_MASK];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
	if (zilog->zl_destroy_txg == txg) {
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1135
		blkptr_t blk = zh->zh_log;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1136
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1137
		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
  1138
		ASSERT(spa_sync_pass(spa) == 1);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1139
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1140
		bzero(zh, sizeof (zil_header_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
		bzero(zilog->zl_replay_seq, sizeof (zilog->zl_replay_seq));
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1142
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1143
		if (zilog->zl_keep_first) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1144
			/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1145
			 * 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
  1146
			 * 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
  1147
			 * zil_claim(), but that device later returns,
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1148
			 * then this block could erroneously appear valid.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1149
			 * 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
  1150
			 * 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
  1151
			 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1152
			zil_init_log_chain(zilog, &blk);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1153
			zh->zh_log = blk;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1154
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
	for (;;) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
		lwb = list_head(&zilog->zl_lwb_list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
		if (lwb == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
			mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
		}
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1163
		zh->zh_log = lwb->lwb_blk;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
		if (lwb->lwb_buf != NULL || lwb->lwb_max_txg > txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
		list_remove(&zilog->zl_lwb_list, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
		zio_free_blk(spa, &lwb->lwb_blk, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
		kmem_cache_free(zil_lwb_cache, lwb);
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1169
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1170
		/*
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1171
		 * 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
  1172
		 * we've had an allocation failure and we need to zero
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1173
		 * out the zil_header blkptr so that we don't end
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1174
		 * up freeing the same block twice.
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1175
		 */
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1176
		if (list_head(&zilog->zl_lwb_list) == NULL)
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
  1177
			BP_ZERO(&zh->zh_log);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
zil_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
	zil_lwb_cache = kmem_cache_create("zil_lwb_cache",
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1186
	    sizeof (struct lwb), 0, NULL, NULL, NULL, NULL, NULL, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
zil_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
	kmem_cache_destroy(zil_lwb_cache);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
zilog_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
zil_alloc(objset_t *os, zil_header_t *zh_phys)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
	zilog_t *zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
	zilog = kmem_zalloc(sizeof (zilog_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	zilog->zl_header = zh_phys;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
	zilog->zl_os = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	zilog->zl_spa = dmu_objset_spa(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	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
  1206
	zilog->zl_destroy_txg = TXG_INITIAL - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1208
	mutex_init(&zilog->zl_lock, NULL, MUTEX_DEFAULT, NULL);
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1209
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
	list_create(&zilog->zl_itx_list, sizeof (itx_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
	    offsetof(itx_t, itx_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
	list_create(&zilog->zl_lwb_list, sizeof (lwb_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	    offsetof(lwb_t, lwb_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1216
	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
  1217
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1218
	avl_create(&zilog->zl_vdev_tree, zil_vdev_compare,
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1219
	    sizeof (zil_vdev_node_t), offsetof(zil_vdev_node_t, zv_node));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
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
  1221
	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
  1222
	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
  1223
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
	return (zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
zil_free(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
	lwb_t *lwb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
	zilog->zl_stop_sync = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
	while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
		list_remove(&zilog->zl_lwb_list, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
		if (lwb->lwb_buf != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
			zio_buf_free(lwb->lwb_buf, lwb->lwb_sz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
		kmem_cache_free(zil_lwb_cache, lwb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
	list_destroy(&zilog->zl_lwb_list);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1241
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1242
	avl_destroy(&zilog->zl_vdev_tree);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5676
diff changeset
  1243
	mutex_destroy(&zilog->zl_vdev_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1244
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1245
	ASSERT(list_head(&zilog->zl_itx_list) == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1246
	list_destroy(&zilog->zl_itx_list);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  1247
	mutex_destroy(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
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
  1249
	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
  1250
	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
  1251
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1252
	kmem_free(zilog, sizeof (zilog_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
/*
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1256
 * return true if the initial log block is not valid
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1257
 */
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1258
static int
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1259
zil_empty(zilog_t *zilog)
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1260
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1261
	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
  1262
	arc_buf_t *abuf = NULL;
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1263
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1264
	if (BP_IS_HOLE(&zh->zh_log))
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1265
		return (1);
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1266
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1267
	if (zil_read_log_block(zilog, &zh->zh_log, &abuf) != 0)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1268
		return (1);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1269
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1270
	VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1271
	return (0);
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1272
}
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1273
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1274
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
 * Open an intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1276
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
zilog_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1278
zil_open(objset_t *os, zil_get_data_t *get_data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1279
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1280
	zilog_t *zilog = dmu_objset_zil(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1281
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1282
	zilog->zl_get_data = get_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1283
	zilog->zl_clean_taskq = taskq_create("zil_clean", 1, minclsyspri,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1284
	    2, 2, TASKQ_PREPOPULATE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1285
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1286
	return (zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1287
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1288
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1289
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1290
 * Close an intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1293
zil_close(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1294
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1295
	/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1296
	 * 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
  1297
	 * (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
  1298
	 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1299
	if (!zil_is_committed(zilog)) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1300
		uint64_t txg;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1301
		dmu_tx_t *tx = dmu_tx_create(zilog->zl_os);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1302
		(void) dmu_tx_assign(tx, TXG_WAIT);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1303
		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
  1304
		txg = dmu_tx_get_txg(tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1305
		dmu_tx_commit(tx);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1306
		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
  1307
	}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1308
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
	taskq_destroy(zilog->zl_clean_taskq);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
	zilog->zl_clean_taskq = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
	zilog->zl_get_data = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
	zil_itx_clean(zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
	ASSERT(list_head(&zilog->zl_itx_list) == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1317
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
 * Suspend an intent log.  While in suspended mode, we still honor
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
 * synchronous semantics, but we rely on txg_wait_synced() to do it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
 * We suspend the log briefly when taking a snapshot so that the snapshot
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1321
 * contains all the data it's supposed to, and has an empty intent log.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
zil_suspend(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
{
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1326
	const zil_header_t *zh = zilog->zl_header;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
	mutex_enter(&zilog->zl_lock);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1329
	if (zh->zh_claim_txg != 0) {		/* unplayed log */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
		mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1331
		return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
	}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1333
	if (zilog->zl_suspend++ != 0) {
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1334
		/*
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1335
		 * Someone else already began a suspend.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1336
		 * Just wait for them to finish.
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1337
		 */
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1338
		while (zilog->zl_suspending)
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1339
			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
  1340
		mutex_exit(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1341
		return (0);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1342
	}
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1343
	zilog->zl_suspending = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1344
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1346
	zil_commit(zilog, UINT64_MAX, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1347
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1348
	/*
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1349
	 * 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
  1350
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1351
	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
  1352
	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
  1353
		cv_wait(&zilog->zl_cv_writer, &zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1354
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1356
	zil_destroy(zilog, B_FALSE);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1357
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1358
	mutex_enter(&zilog->zl_lock);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1359
	zilog->zl_suspending = B_FALSE;
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1360
	cv_broadcast(&zilog->zl_cv_suspend);
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1361
	mutex_exit(&zilog->zl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1365
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1366
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
zil_resume(zilog_t *zilog)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1368
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1369
	mutex_enter(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1370
	ASSERT(zilog->zl_suspend != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1371
	zilog->zl_suspend--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
	mutex_exit(&zilog->zl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1373
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1374
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
typedef struct zil_replay_arg {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1376
	objset_t	*zr_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1377
	zil_replay_func_t **zr_replay;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1378
	void		*zr_arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1379
	uint64_t	*zr_txgp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
	boolean_t	zr_byteswap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1381
	char		*zr_lrbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1382
} zil_replay_arg_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1383
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1385
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
  1386
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
	zil_replay_arg_t *zr = zra;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1388
	const zil_header_t *zh = zilog->zl_header;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
	uint64_t reclen = lr->lrc_reclen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
	uint64_t txtype = lr->lrc_txtype;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1391
	char *name;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1392
	int pass, error, sunk;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
	if (zilog->zl_stop_replay)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1395
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1396
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
	if (lr->lrc_txg < claim_txg)		/* already committed */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1400
	if (lr->lrc_seq <= zh->zh_replay_seq)	/* already replayed */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1401
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1403
	/* Strip case-insensitive bit, still present in log record */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1404
	txtype &= ~TX_CI;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1405
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
	 * Make a copy of the data so we can revise and extend it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
	bcopy(lr, zr->zr_lrbuf, reclen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
	 * The log block containing this lr may have been byteswapped
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
	 * so that we can easily examine common fields like lrc_txtype.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
	 * However, the log is a mix of different data types, and only the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1415
	 * replay vectors know how to byteswap their records.  Therefore, if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1416
	 * the lr was byteswapped, undo it before invoking the replay vector.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
	if (zr->zr_byteswap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1419
		byteswap_uint64_array(zr->zr_lrbuf, reclen);
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
	 * If this is a TX_WRITE with a blkptr, suck in the data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
	if (txtype == TX_WRITE && reclen == sizeof (lr_write_t)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
		lr_write_t *lrw = (lr_write_t *)lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
		blkptr_t *wbp = &lrw->lr_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
		uint64_t wlen = lrw->lr_length;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
		char *wbuf = zr->zr_lrbuf + reclen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
		if (BP_IS_HOLE(wbp)) {	/* compressed to a hole */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
			bzero(wbuf, wlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
			 * A subsequent write may have overwritten this block,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
			 * in which case wbp may have been been freed and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
			 * reallocated, and our read of wbp may fail with a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
			 * checksum error.  We can safely ignore this because
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1438
			 * the later write will provide the correct data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1439
			 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1440
			zbookmark_t zb;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1441
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1442
			zb.zb_objset = dmu_objset_id(zilog->zl_os);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1443
			zb.zb_object = lrw->lr_foid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1444
			zb.zb_level = -1;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1445
			zb.zb_blkid = lrw->lr_offset / BP_GET_LSIZE(wbp);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1446
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1447
			(void) zio_wait(zio_read(NULL, zilog->zl_spa,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1448
			    wbp, wbuf, BP_GET_LSIZE(wbp), NULL, NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1449
			    ZIO_PRIORITY_SYNC_READ,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1472
diff changeset
  1450
			    ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE, &zb));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
			(void) memmove(wbuf, wbuf + lrw->lr_blkoff, wlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
	 * We must now do two things atomically: replay this log record,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1457
	 * and update the log header to reflect the fact that we did so.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1458
	 * We use the DMU's ability to assign into a specific txg to do this.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1459
	 */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1460
	for (pass = 1, sunk = B_FALSE; /* CONSTANTCONDITION */; pass++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1461
		uint64_t replay_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1462
		dmu_tx_t *replay_tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1463
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
		replay_tx = dmu_tx_create(zr->zr_os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
		error = dmu_tx_assign(replay_tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1467
			dmu_tx_abort(replay_tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1468
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1470
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1471
		replay_txg = dmu_tx_get_txg(replay_tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1473
		if (txtype == 0 || txtype >= TX_MAX_TYPE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1474
			error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1475
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1476
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1477
			 * On the first pass, arrange for the replay vector
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
			 * to fail its dmu_tx_assign().  That's the only way
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
			 * to ensure that those code paths remain well tested.
5676
22a9bf570263 6628612 Replay on different endianess fails.
perrin
parents: 5331
diff changeset
  1480
			 *
22a9bf570263 6628612 Replay on different endianess fails.
perrin
parents: 5331
diff changeset
  1481
			 * Only byteswap (if needed) on the 1st pass.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1482
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
			*zr->zr_txgp = replay_txg - (pass == 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
			error = zr->zr_replay[txtype](zr->zr_arg, zr->zr_lrbuf,
5676
22a9bf570263 6628612 Replay on different endianess fails.
perrin
parents: 5331
diff changeset
  1485
			    zr->zr_byteswap && pass == 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
			*zr->zr_txgp = TXG_NOWAIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
		if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
			dsl_dataset_dirty(dmu_objset_ds(zr->zr_os), replay_tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
			zilog->zl_replay_seq[replay_txg & TXG_MASK] =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
			    lr->lrc_seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
		dmu_tx_commit(replay_tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1497
		if (!error)
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1498
			return;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1499
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1500
		/*
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1501
		 * 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
  1502
		 * commits, so a subsequent claim can spuriously fail with
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1503
		 * EEXIST. So if we receive any error other than ERESTART
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1504
		 * we try syncing out any removes then retrying the
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1505
		 * transaction.
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1506
		 */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1507
		if (error != ERESTART && !sunk) {
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1508
			txg_wait_synced(spa_get_dsl(zilog->zl_spa), 0);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1509
			sunk = B_TRUE;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1510
			continue; /* retry */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1511
		}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1512
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
		if (error != ERESTART)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
		if (pass != 1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
			txg_wait_open(spa_get_dsl(zilog->zl_spa),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
			    replay_txg + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1520
		dprintf("pass %d, retrying\n", pass);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1521
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1522
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1523
	ASSERT(error && error != ERESTART);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1524
	name = kmem_alloc(MAXNAMELEN, KM_SLEEP);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1525
	dmu_objset_name(zr->zr_os, name);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1526
	cmn_err(CE_WARN, "ZFS replay transaction error %d, "
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1527
	    "dataset %s, seq 0x%llx, txtype %llu %s\n",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1528
	    error, name, (u_longlong_t)lr->lrc_seq, (u_longlong_t)txtype,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5223
diff changeset
  1529
	    (lr->lrc_txtype & TX_CI) ? "CI" : "");
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1530
	zilog->zl_stop_replay = 1;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1531
	kmem_free(name, MAXNAMELEN);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1532
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1533
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1534
/* ARGSUSED */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1535
static void
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1536
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
  1537
{
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1538
	zilog->zl_replay_blks++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1539
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1540
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1541
/*
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1542
 * If this dataset has a non-empty intent log, replay it and destroy it.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1544
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1545
zil_replay(objset_t *os, void *arg, uint64_t *txgp,
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3063
diff changeset
  1546
	zil_replay_func_t *replay_func[TX_MAX_TYPE])
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1547
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1548
	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
  1549
	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
  1550
	zil_replay_arg_t zr;
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1551
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1552
	if (zil_empty(zilog)) {
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1553
		zil_destroy(zilog, B_TRUE);
1362
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1554
		return;
2b3ee2467364 6377670 zil_replay() does unnecessary txg_wait_synced(), slowing down mount
perrin
parents: 1141
diff changeset
  1555
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1556
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1557
	zr.zr_os = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1558
	zr.zr_replay = replay_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1559
	zr.zr_arg = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1560
	zr.zr_txgp = txgp;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1561
	zr.zr_byteswap = BP_SHOULD_BYTESWAP(&zh->zh_log);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1562
	zr.zr_lrbuf = kmem_alloc(2 * SPA_MAXBLOCKSIZE, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
	 * Wait for in-progress removes to sync before starting replay.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
	txg_wait_synced(zilog->zl_dmu_pool, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
	zilog->zl_stop_replay = 0;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1570
	zilog->zl_replay_time = lbolt;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1571
	ASSERT(zilog->zl_replay_blks == 0);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2986
diff changeset
  1572
	(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
  1573
	    zh->zh_claim_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
	kmem_free(zr.zr_lrbuf, 2 * SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1669
diff changeset
  1576
	zil_destroy(zilog, B_FALSE);
5712
81f1af42bafc 6628232 zfs snapshot -r is very slow, causes systemic slowdown
ahrens
parents: 5688
diff changeset
  1577
	txg_wait_synced(zilog->zl_dmu_pool, zilog->zl_destroy_txg);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
}
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1579
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1580
/*
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1581
 * Report whether all transactions are committed
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1582
 */
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1583
int
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1584
zil_is_committed(zilog_t *zilog)
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1585
{
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1586
	lwb_t *lwb;
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1587
	int ret;
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1588
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1589
	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
  1590
	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
  1591
		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
  1592
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1593
	/* recent unpushed intent log transactions? */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1594
	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
  1595
		ret = B_FALSE;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1596
		goto out;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1597
	}
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1598
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1599
	/* intent log never used? */
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1600
	lwb = list_head(&zilog->zl_lwb_list);
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1601
	if (lwb == NULL) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1602
		ret = B_TRUE;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1603
		goto out;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1604
	}
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1605
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1606
	/*
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1607
	 * more than 1 log buffer means zil_sync() hasn't yet freed
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1608
	 * entries after a txg has committed
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1609
	 */
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1610
	if (list_next(&zilog->zl_lwb_list, lwb)) {
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1611
		ret = B_FALSE;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1612
		goto out;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1613
	}
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1614
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1615
	ASSERT(zil_empty(zilog));
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1616
	ret = B_TRUE;
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1617
out:
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1618
	cv_broadcast(&zilog->zl_cv_writer);
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2391
diff changeset
  1619
	mutex_exit(&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
  1620
	return (ret);
1646
b4e43ae19fff 6393443 Remove remaining txg_wait_synced() from zfs unmount path.
perrin
parents: 1544
diff changeset
  1621
}