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