usr/src/uts/common/fs/zfs/bplist.c
author Jeff Bonwick <Jeff.Bonwick@Sun.COM>
Sun, 01 Nov 2009 14:14:46 -0800
changeset 10922 e2081f502306
parent 7390 6d408f0a5fbd
child 11932 197b866a8e44
permissions -rw-r--r--
PSARC 2009/571 ZFS Deduplication Properties 6677093 zfs should have dedup capability
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
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
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    22
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <sys/bplist.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    29
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    30
bplist_init(bplist_t *bpl)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    31
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    32
	bzero(bpl, sizeof (*bpl));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    33
	mutex_init(&bpl->bpl_lock, NULL, MUTEX_DEFAULT, NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    34
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    35
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    36
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    37
bplist_fini(bplist_t *bpl)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    38
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    39
	ASSERT(bpl->bpl_queue == NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    40
	mutex_destroy(&bpl->bpl_lock);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    41
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
    42
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    43
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
bplist_hold(bplist_t *bpl)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
	ASSERT(MUTEX_HELD(&bpl->bpl_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
	if (bpl->bpl_dbuf == NULL) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    48
		int err = dmu_bonus_hold(bpl->bpl_mos,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    49
		    bpl->bpl_object, bpl, &bpl->bpl_dbuf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    50
		if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    51
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
		bpl->bpl_phys = bpl->bpl_dbuf->db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    54
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
bplist_create(objset_t *mos, int blocksize, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
    60
	int size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 2082
diff changeset
    62
	size = spa_version(dmu_objset_spa(mos)) < SPA_VERSION_BPLIST_ACCOUNT ?
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
    63
	    BPLIST_SIZE_V0 : sizeof (bplist_phys_t);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
    65
	return (dmu_object_alloc(mos, DMU_OT_BPLIST, blocksize,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
    66
	    DMU_OT_BPLIST_HDR, size, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
bplist_destroy(objset_t *mos, uint64_t object, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
	VERIFY(dmu_object_free(mos, object, tx) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    75
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
bplist_open(bplist_t *bpl, objset_t *mos, uint64_t object)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	dmu_object_info_t doi;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    79
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    81
	err = dmu_object_info(mos, object, &doi);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    82
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
    83
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
	mutex_enter(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
	ASSERT(bpl->bpl_dbuf == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
	ASSERT(bpl->bpl_phys == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	ASSERT(bpl->bpl_cached_dbuf == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	ASSERT(bpl->bpl_queue == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	ASSERT(object != 0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
    92
	ASSERT3U(doi.doi_type, ==, DMU_OT_BPLIST);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
    93
	ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_BPLIST_HDR);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
	bpl->bpl_mos = mos;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
	bpl->bpl_object = object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	bpl->bpl_blockshift = highbit(doi.doi_data_block_size - 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	bpl->bpl_bpshift = bpl->bpl_blockshift - SPA_BLKPTRSHIFT;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
    99
	bpl->bpl_havecomp = (doi.doi_bonus_size == sizeof (bplist_phys_t));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	mutex_exit(&bpl->bpl_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   102
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
bplist_close(bplist_t *bpl)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	mutex_enter(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	ASSERT(bpl->bpl_queue == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	if (bpl->bpl_cached_dbuf) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   113
		dmu_buf_rele(bpl->bpl_cached_dbuf, bpl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
		bpl->bpl_cached_dbuf = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	if (bpl->bpl_dbuf) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   117
		dmu_buf_rele(bpl->bpl_dbuf, bpl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
		bpl->bpl_dbuf = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
		bpl->bpl_phys = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	mutex_exit(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
boolean_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
bplist_empty(bplist_t *bpl)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	boolean_t rv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	if (bpl->bpl_object == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
		return (B_TRUE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	mutex_enter(&bpl->bpl_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   134
	VERIFY(0 == bplist_hold(bpl)); /* XXX */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
	rv = (bpl->bpl_phys->bpl_entries == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	mutex_exit(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
	return (rv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   141
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   142
bplist_cache(bplist_t *bpl, uint64_t blkid)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   143
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   144
	int err = 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   145
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   146
	if (bpl->bpl_cached_dbuf == NULL ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   147
	    bpl->bpl_cached_dbuf->db_offset != (blkid << bpl->bpl_blockshift)) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   148
		if (bpl->bpl_cached_dbuf != NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   149
			dmu_buf_rele(bpl->bpl_cached_dbuf, bpl);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   150
		err = dmu_buf_hold(bpl->bpl_mos,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   151
		    bpl->bpl_object, blkid << bpl->bpl_blockshift,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   152
		    bpl, &bpl->bpl_cached_dbuf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   153
		ASSERT(err || bpl->bpl_cached_dbuf->db_size ==
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   154
		    1ULL << bpl->bpl_blockshift);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   155
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   156
	return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   157
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   158
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
bplist_iterate(bplist_t *bpl, uint64_t *itorp, blkptr_t *bp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
	uint64_t blk, off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
	blkptr_t *bparray;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   164
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
	mutex_enter(&bpl->bpl_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   167
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   168
	err = bplist_hold(bpl);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   169
	if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   170
		mutex_exit(&bpl->bpl_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   171
		return (err);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   172
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
	if (*itorp >= bpl->bpl_phys->bpl_entries) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
		mutex_exit(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
	blk = *itorp >> bpl->bpl_bpshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	off = P2PHASE(*itorp, 1ULL << bpl->bpl_bpshift);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   182
	err = bplist_cache(bpl, blk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   183
	if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   184
		mutex_exit(&bpl->bpl_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   185
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   188
	bparray = bpl->bpl_cached_dbuf->db_data;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	*bp = bparray[off];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	(*itorp)++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	mutex_exit(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   195
int
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5367
diff changeset
   196
bplist_enqueue(bplist_t *bpl, const blkptr_t *bp, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
	uint64_t blk, off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
	blkptr_t *bparray;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   200
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
	ASSERT(!BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
	mutex_enter(&bpl->bpl_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   204
	err = bplist_hold(bpl);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   205
	if (err)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   206
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
	blk = bpl->bpl_phys->bpl_entries >> bpl->bpl_bpshift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
	off = P2PHASE(bpl->bpl_phys->bpl_entries, 1ULL << bpl->bpl_bpshift);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   211
	err = bplist_cache(bpl, blk);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   212
	if (err) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   213
		mutex_exit(&bpl->bpl_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   214
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   217
	dmu_buf_will_dirty(bpl->bpl_cached_dbuf, tx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   218
	bparray = bpl->bpl_cached_dbuf->db_data;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
	bparray[off] = *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	/* We never need the fill count. */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	bparray[off].blk_fill = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
	/* The bplist will compress better if we can leave off the checksum */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   225
	if (!BP_GET_DEDUP(&bparray[off]))
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   226
		bzero(&bparray[off].blk_cksum, sizeof (bparray[off].blk_cksum));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	dmu_buf_will_dirty(bpl->bpl_dbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	bpl->bpl_phys->bpl_entries++;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   230
	bpl->bpl_phys->bpl_bytes +=
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   231
	    bp_get_dsize_sync(dmu_objset_spa(bpl->bpl_mos), bp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   232
	if (bpl->bpl_havecomp) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   233
		bpl->bpl_phys->bpl_comp += BP_GET_PSIZE(bp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   234
		bpl->bpl_phys->bpl_uncomp += BP_GET_UCSIZE(bp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   235
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
	mutex_exit(&bpl->bpl_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   237
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   238
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   241
void
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   242
bplist_enqueue_cb(void *bpl, const blkptr_t *bp, dmu_tx_t *tx)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   243
{
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   244
	VERIFY(bplist_enqueue(bpl, bp, tx) == 0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   245
}
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   246
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   248
 * Deferred entry; will be processed later by bplist_sync().
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
void
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 5367
diff changeset
   251
bplist_enqueue_deferred(bplist_t *bpl, const blkptr_t *bp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	bplist_q_t *bpq = kmem_alloc(sizeof (*bpq), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	ASSERT(!BP_IS_HOLE(bp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
	mutex_enter(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
	bpq->bpq_blk = *bp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
	bpq->bpq_next = bpl->bpl_queue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
	bpl->bpl_queue = bpq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
	mutex_exit(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   264
bplist_sync(bplist_t *bpl, bplist_sync_cb_t *func, void *arg, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	bplist_q_t *bpq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
	mutex_enter(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
	while ((bpq = bpl->bpl_queue) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
		bpl->bpl_queue = bpq->bpq_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
		mutex_exit(&bpl->bpl_lock);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   272
		func(arg, &bpq->bpq_blk, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
		kmem_free(bpq, sizeof (*bpq));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
		mutex_enter(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	mutex_exit(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
bplist_vacate(bplist_t *bpl, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
	mutex_enter(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	ASSERT3P(bpl->bpl_queue, ==, NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   284
	VERIFY(0 == bplist_hold(bpl));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	dmu_buf_will_dirty(bpl->bpl_dbuf, tx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   286
	VERIFY(0 == dmu_free_range(bpl->bpl_mos,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   287
	    bpl->bpl_object, 0, -1ULL, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	bpl->bpl_phys->bpl_entries = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
	bpl->bpl_phys->bpl_bytes = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   290
	if (bpl->bpl_havecomp) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   291
		bpl->bpl_phys->bpl_comp = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   292
		bpl->bpl_phys->bpl_uncomp = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   293
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
	mutex_exit(&bpl->bpl_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   296
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   297
int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   298
bplist_space(bplist_t *bpl, uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   299
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   300
	int err;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   301
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   302
	mutex_enter(&bpl->bpl_lock);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   303
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   304
	err = bplist_hold(bpl);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   305
	if (err) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   306
		mutex_exit(&bpl->bpl_lock);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   307
		return (err);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   308
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   309
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   310
	*usedp = bpl->bpl_phys->bpl_bytes;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   311
	if (bpl->bpl_havecomp) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   312
		*compp = bpl->bpl_phys->bpl_comp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   313
		*uncompp = bpl->bpl_phys->bpl_uncomp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   314
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   315
	mutex_exit(&bpl->bpl_lock);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   316
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   317
	if (!bpl->bpl_havecomp) {
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 4577
diff changeset
   318
		uint64_t itor = 0, comp = 0, uncomp = 0;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 4577
diff changeset
   319
		blkptr_t bp;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 4577
diff changeset
   320
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   321
		while ((err = bplist_iterate(bpl, &itor, &bp)) == 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   322
			comp += BP_GET_PSIZE(&bp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   323
			uncomp += BP_GET_UCSIZE(&bp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   324
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   325
		if (err == ENOENT)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   326
			err = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   327
		*compp = comp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   328
		*uncompp = uncomp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   329
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   330
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   331
	return (err);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   332
}
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   333
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   334
/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   335
 * Return (in *dsizep) the amount of space on the deadlist which is:
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   336
 * mintxg < blk_birth <= maxtxg
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   337
 */
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   338
int
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   339
bplist_space_birthrange(bplist_t *bpl, uint64_t mintxg, uint64_t maxtxg,
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   340
    uint64_t *dsizep)
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   341
{
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   342
	uint64_t size = 0;
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   343
	uint64_t itor = 0;
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   344
	blkptr_t bp;
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   345
	int err;
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   346
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   347
	/*
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   348
	 * As an optimization, if they want the whole txg range, just
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   349
	 * get bpl_bytes rather than iterating over the bps.
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   350
	 */
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   351
	if (mintxg < TXG_INITIAL && maxtxg == UINT64_MAX) {
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   352
		mutex_enter(&bpl->bpl_lock);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   353
		err = bplist_hold(bpl);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   354
		if (err == 0)
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   355
			*dsizep = bpl->bpl_phys->bpl_bytes;
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   356
		mutex_exit(&bpl->bpl_lock);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   357
		return (err);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   358
	}
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   359
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   360
	while ((err = bplist_iterate(bpl, &itor, &bp)) == 0) {
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   361
		if (bp.blk_birth > mintxg && bp.blk_birth <= maxtxg) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   362
			size += bp_get_dsize(dmu_objset_spa(bpl->bpl_mos), &bp);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   363
		}
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   364
	}
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   365
	if (err == ENOENT)
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   366
		err = 0;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7390
diff changeset
   367
	*dsizep = size;
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   368
	return (err);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7046
diff changeset
   369
}