usr/src/uts/common/fs/zfs/bpobj.c
author Matthew Ahrens <Matthew.Ahrens@Sun.COM>
Wed, 09 Jun 2010 16:52:05 -0700
changeset 12593 3c3a4d3d1dda
parent 12587 16aef3d16470
child 13509 04570f5cbeca
permissions -rw-r--r--
6959054 stack overflow due to nested bpobj's while deleting a share
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     1
/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     2
 * CDDL HEADER START
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     3
 *
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     7
 *
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    11
 * and limitations under the License.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    12
 *
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    18
 *
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    19
 * CDDL HEADER END
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    20
 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    21
/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    23
 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    24
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    25
#include <sys/bpobj.h>
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    26
#include <sys/zfs_context.h>
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    27
#include <sys/refcount.h>
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    28
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    29
uint64_t
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    30
bpobj_alloc(objset_t *os, int blocksize, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    31
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    32
	int size;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    33
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    34
	if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_BPOBJ_ACCOUNT)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    35
		size = BPOBJ_SIZE_V0;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    36
	else if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_DEADLISTS)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    37
		size = BPOBJ_SIZE_V1;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    38
	else
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    39
		size = sizeof (bpobj_phys_t);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    40
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    41
	return (dmu_object_alloc(os, DMU_OT_BPOBJ, blocksize,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    42
	    DMU_OT_BPOBJ_HDR, size, tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    43
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    44
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    45
void
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    46
bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    47
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    48
	int64_t i;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    49
	bpobj_t bpo;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    50
	dmu_object_info_t doi;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    51
	int epb;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    52
	dmu_buf_t *dbuf = NULL;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    53
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    54
	VERIFY3U(0, ==, bpobj_open(&bpo, os, obj));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    55
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    56
	mutex_enter(&bpo.bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    57
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    58
	if (!bpo.bpo_havesubobj || bpo.bpo_phys->bpo_subobjs == 0)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    59
		goto out;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    60
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    61
	VERIFY3U(0, ==, dmu_object_info(os, bpo.bpo_phys->bpo_subobjs, &doi));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    62
	epb = doi.doi_data_block_size / sizeof (uint64_t);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    63
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    64
	for (i = bpo.bpo_phys->bpo_num_subobjs - 1; i >= 0; i--) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    65
		uint64_t *objarray;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    66
		uint64_t offset, blkoff;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    67
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    68
		offset = i * sizeof (uint64_t);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    69
		blkoff = P2PHASE(i, epb);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    70
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    71
		if (dbuf == NULL || dbuf->db_offset > offset) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    72
			if (dbuf)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    73
				dmu_buf_rele(dbuf, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    74
			VERIFY3U(0, ==, dmu_buf_hold(os,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    75
			    bpo.bpo_phys->bpo_subobjs, offset, FTAG, &dbuf, 0));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    76
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    77
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    78
		ASSERT3U(offset, >=, dbuf->db_offset);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    79
		ASSERT3U(offset, <, dbuf->db_offset + dbuf->db_size);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    80
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    81
		objarray = dbuf->db_data;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    82
		bpobj_free(os, objarray[blkoff], tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    83
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    84
	if (dbuf) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    85
		dmu_buf_rele(dbuf, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    86
		dbuf = NULL;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    87
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    88
	VERIFY3U(0, ==, dmu_object_free(os, bpo.bpo_phys->bpo_subobjs, tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    89
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    90
out:
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    91
	mutex_exit(&bpo.bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    92
	bpobj_close(&bpo);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    93
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    94
	VERIFY3U(0, ==, dmu_object_free(os, obj, tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    95
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    96
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    97
int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    98
bpobj_open(bpobj_t *bpo, objset_t *os, uint64_t object)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
    99
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   100
	dmu_object_info_t doi;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   101
	int err;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   102
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   103
	err = dmu_object_info(os, object, &doi);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   104
	if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   105
		return (err);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   106
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   107
	bzero(bpo, sizeof (*bpo));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   108
	mutex_init(&bpo->bpo_lock, NULL, MUTEX_DEFAULT, NULL);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   109
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   110
	ASSERT(bpo->bpo_dbuf == NULL);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   111
	ASSERT(bpo->bpo_phys == NULL);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   112
	ASSERT(object != 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   113
	ASSERT3U(doi.doi_type, ==, DMU_OT_BPOBJ);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   114
	ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_BPOBJ_HDR);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   115
12587
16aef3d16470 6957090 ddt_zap_prefetch() induces deadlock, panic
George Wilson <George.Wilson@Sun.COM>
parents: 12538
diff changeset
   116
	err = dmu_bonus_hold(os, object, bpo, &bpo->bpo_dbuf);
16aef3d16470 6957090 ddt_zap_prefetch() induces deadlock, panic
George Wilson <George.Wilson@Sun.COM>
parents: 12538
diff changeset
   117
	if (err)
16aef3d16470 6957090 ddt_zap_prefetch() induces deadlock, panic
George Wilson <George.Wilson@Sun.COM>
parents: 12538
diff changeset
   118
		return (err);
16aef3d16470 6957090 ddt_zap_prefetch() induces deadlock, panic
George Wilson <George.Wilson@Sun.COM>
parents: 12538
diff changeset
   119
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   120
	bpo->bpo_os = os;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   121
	bpo->bpo_object = object;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   122
	bpo->bpo_epb = doi.doi_data_block_size >> SPA_BLKPTRSHIFT;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   123
	bpo->bpo_havecomp = (doi.doi_bonus_size > BPOBJ_SIZE_V0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   124
	bpo->bpo_havesubobj = (doi.doi_bonus_size > BPOBJ_SIZE_V1);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   125
	bpo->bpo_phys = bpo->bpo_dbuf->db_data;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   126
	return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   127
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   128
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   129
void
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   130
bpobj_close(bpobj_t *bpo)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   131
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   132
	/* Lame workaround for closing a bpobj that was never opened. */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   133
	if (bpo->bpo_object == 0)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   134
		return;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   135
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   136
	dmu_buf_rele(bpo->bpo_dbuf, bpo);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   137
	if (bpo->bpo_cached_dbuf != NULL)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   138
		dmu_buf_rele(bpo->bpo_cached_dbuf, bpo);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   139
	bpo->bpo_dbuf = NULL;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   140
	bpo->bpo_phys = NULL;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   141
	bpo->bpo_cached_dbuf = NULL;
12587
16aef3d16470 6957090 ddt_zap_prefetch() induces deadlock, panic
George Wilson <George.Wilson@Sun.COM>
parents: 12538
diff changeset
   142
	bpo->bpo_object = 0;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   143
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   144
	mutex_destroy(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   145
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   146
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   147
static int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   148
bpobj_iterate_impl(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   149
    boolean_t free)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   150
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   151
	dmu_object_info_t doi;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   152
	int epb;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   153
	int64_t i;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   154
	int err = 0;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   155
	dmu_buf_t *dbuf = NULL;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   156
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   157
	mutex_enter(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   158
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   159
	if (free)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   160
		dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   161
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   162
	for (i = bpo->bpo_phys->bpo_num_blkptrs - 1; i >= 0; i--) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   163
		blkptr_t *bparray;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   164
		blkptr_t *bp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   165
		uint64_t offset, blkoff;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   166
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   167
		offset = i * sizeof (blkptr_t);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   168
		blkoff = P2PHASE(i, bpo->bpo_epb);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   169
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   170
		if (dbuf == NULL || dbuf->db_offset > offset) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   171
			if (dbuf)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   172
				dmu_buf_rele(dbuf, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   173
			err = dmu_buf_hold(bpo->bpo_os, bpo->bpo_object, offset,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   174
			    FTAG, &dbuf, 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   175
			if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   176
				break;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   177
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   178
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   179
		ASSERT3U(offset, >=, dbuf->db_offset);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   180
		ASSERT3U(offset, <, dbuf->db_offset + dbuf->db_size);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   181
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   182
		bparray = dbuf->db_data;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   183
		bp = &bparray[blkoff];
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   184
		err = func(arg, bp, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   185
		if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   186
			break;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   187
		if (free) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   188
			bpo->bpo_phys->bpo_bytes -=
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   189
			    bp_get_dsize_sync(dmu_objset_spa(bpo->bpo_os), bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   190
			ASSERT3S(bpo->bpo_phys->bpo_bytes, >=, 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   191
			if (bpo->bpo_havecomp) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   192
				bpo->bpo_phys->bpo_comp -= BP_GET_PSIZE(bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   193
				bpo->bpo_phys->bpo_uncomp -= BP_GET_UCSIZE(bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   194
			}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   195
			bpo->bpo_phys->bpo_num_blkptrs--;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   196
			ASSERT3S(bpo->bpo_phys->bpo_num_blkptrs, >=, 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   197
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   198
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   199
	if (dbuf) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   200
		dmu_buf_rele(dbuf, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   201
		dbuf = NULL;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   202
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   203
	if (free) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   204
		i++;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   205
		VERIFY3U(0, ==, dmu_free_range(bpo->bpo_os, bpo->bpo_object,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   206
		    i * sizeof (blkptr_t), -1ULL, tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   207
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   208
	if (err || !bpo->bpo_havesubobj || bpo->bpo_phys->bpo_subobjs == 0)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   209
		goto out;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   210
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   211
	ASSERT(bpo->bpo_havecomp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   212
	err = dmu_object_info(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs, &doi);
12538
bb02b9cd2b96 6956280 mutex problem in bpobj_iterate_impl()
Lin Ling <Lin.Ling@Sun.COM>
parents: 12470
diff changeset
   213
	if (err) {
bb02b9cd2b96 6956280 mutex problem in bpobj_iterate_impl()
Lin Ling <Lin.Ling@Sun.COM>
parents: 12470
diff changeset
   214
		mutex_exit(&bpo->bpo_lock);
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   215
		return (err);
12538
bb02b9cd2b96 6956280 mutex problem in bpobj_iterate_impl()
Lin Ling <Lin.Ling@Sun.COM>
parents: 12470
diff changeset
   216
	}
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   217
	epb = doi.doi_data_block_size / sizeof (uint64_t);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   218
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   219
	for (i = bpo->bpo_phys->bpo_num_subobjs - 1; i >= 0; i--) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   220
		uint64_t *objarray;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   221
		uint64_t offset, blkoff;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   222
		bpobj_t sublist;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   223
		uint64_t used_before, comp_before, uncomp_before;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   224
		uint64_t used_after, comp_after, uncomp_after;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   225
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   226
		offset = i * sizeof (uint64_t);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   227
		blkoff = P2PHASE(i, epb);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   228
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   229
		if (dbuf == NULL || dbuf->db_offset > offset) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   230
			if (dbuf)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   231
				dmu_buf_rele(dbuf, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   232
			err = dmu_buf_hold(bpo->bpo_os,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   233
			    bpo->bpo_phys->bpo_subobjs, offset, FTAG, &dbuf, 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   234
			if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   235
				break;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   236
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   237
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   238
		ASSERT3U(offset, >=, dbuf->db_offset);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   239
		ASSERT3U(offset, <, dbuf->db_offset + dbuf->db_size);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   240
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   241
		objarray = dbuf->db_data;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   242
		err = bpobj_open(&sublist, bpo->bpo_os, objarray[blkoff]);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   243
		if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   244
			break;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   245
		if (free) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   246
			err = bpobj_space(&sublist,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   247
			    &used_before, &comp_before, &uncomp_before);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   248
			if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   249
				break;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   250
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   251
		err = bpobj_iterate_impl(&sublist, func, arg, tx, free);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   252
		if (free) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   253
			VERIFY3U(0, ==, bpobj_space(&sublist,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   254
			    &used_after, &comp_after, &uncomp_after));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   255
			bpo->bpo_phys->bpo_bytes -= used_before - used_after;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   256
			ASSERT3S(bpo->bpo_phys->bpo_bytes, >=, 0);
12593
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   257
			bpo->bpo_phys->bpo_comp -= comp_before - comp_after;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   258
			bpo->bpo_phys->bpo_uncomp -=
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   259
			    uncomp_before - uncomp_after;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   260
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   261
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   262
		bpobj_close(&sublist);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   263
		if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   264
			break;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   265
		if (free) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   266
			err = dmu_object_free(bpo->bpo_os,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   267
			    objarray[blkoff], tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   268
			if (err)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   269
				break;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   270
			bpo->bpo_phys->bpo_num_subobjs--;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   271
			ASSERT3S(bpo->bpo_phys->bpo_num_subobjs, >=, 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   272
		}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   273
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   274
	if (dbuf) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   275
		dmu_buf_rele(dbuf, FTAG);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   276
		dbuf = NULL;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   277
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   278
	if (free) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   279
		VERIFY3U(0, ==, dmu_free_range(bpo->bpo_os,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   280
		    bpo->bpo_phys->bpo_subobjs,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   281
		    (i + 1) * sizeof (uint64_t), -1ULL, tx));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   282
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   283
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   284
out:
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   285
	/* If there are no entries, there should be no bytes. */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   286
	ASSERT(bpo->bpo_phys->bpo_num_blkptrs > 0 ||
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   287
	    (bpo->bpo_havesubobj && bpo->bpo_phys->bpo_num_subobjs > 0) ||
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   288
	    bpo->bpo_phys->bpo_bytes == 0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   289
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   290
	mutex_exit(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   291
	return (err);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   292
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   293
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   294
/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   295
 * Iterate and remove the entries.  If func returns nonzero, iteration
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   296
 * will stop and that entry will not be removed.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   297
 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   298
int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   299
bpobj_iterate(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   300
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   301
	return (bpobj_iterate_impl(bpo, func, arg, tx, B_TRUE));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   302
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   303
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   304
/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   305
 * Iterate the entries.  If func returns nonzero, iteration will stop.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   306
 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   307
int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   308
bpobj_iterate_nofree(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   309
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   310
	return (bpobj_iterate_impl(bpo, func, arg, tx, B_FALSE));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   311
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   312
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   313
void
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   314
bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   315
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   316
	bpobj_t subbpo;
12593
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   317
	uint64_t used, comp, uncomp, subsubobjs;
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   318
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   319
	ASSERT(bpo->bpo_havesubobj);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   320
	ASSERT(bpo->bpo_havecomp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   321
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   322
	VERIFY3U(0, ==, bpobj_open(&subbpo, bpo->bpo_os, subobj));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   323
	VERIFY3U(0, ==, bpobj_space(&subbpo, &used, &comp, &uncomp));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   324
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   325
	if (used == 0) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   326
		/* No point in having an empty subobj. */
12593
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   327
		bpobj_close(&subbpo);
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   328
		bpobj_free(bpo->bpo_os, subobj, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   329
		return;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   330
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   331
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   332
	dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   333
	if (bpo->bpo_phys->bpo_subobjs == 0) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   334
		bpo->bpo_phys->bpo_subobjs = dmu_object_alloc(bpo->bpo_os,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   335
		    DMU_OT_BPOBJ_SUBOBJ, SPA_MAXBLOCKSIZE, DMU_OT_NONE, 0, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   336
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   337
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   338
	mutex_enter(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   339
	dmu_write(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   340
	    bpo->bpo_phys->bpo_num_subobjs * sizeof (subobj),
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   341
	    sizeof (subobj), &subobj, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   342
	bpo->bpo_phys->bpo_num_subobjs++;
12593
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   343
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   344
	/*
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   345
	 * If subobj has only one block of subobjs, then move subobj's
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   346
	 * subobjs to bpo's subobj list directly.  This reduces
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   347
	 * recursion in bpobj_iterate due to nested subobjs.
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   348
	 */
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   349
	subsubobjs = subbpo.bpo_phys->bpo_subobjs;
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   350
	if (subsubobjs != 0) {
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   351
		dmu_object_info_t doi;
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   352
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   353
		VERIFY3U(0, ==, dmu_object_info(bpo->bpo_os, subsubobjs, &doi));
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   354
		if (doi.doi_max_offset == doi.doi_data_block_size) {
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   355
			dmu_buf_t *subdb;
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   356
			uint64_t numsubsub = subbpo.bpo_phys->bpo_num_subobjs;
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   357
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   358
			VERIFY3U(0, ==, dmu_buf_hold(bpo->bpo_os, subsubobjs,
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   359
			    0, FTAG, &subdb, 0));
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   360
			dmu_write(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs,
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   361
			    bpo->bpo_phys->bpo_num_subobjs * sizeof (subobj),
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   362
			    numsubsub * sizeof (subobj), subdb->db_data, tx);
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   363
			dmu_buf_rele(subdb, FTAG);
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   364
			bpo->bpo_phys->bpo_num_subobjs += numsubsub;
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   365
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   366
			dmu_buf_will_dirty(subbpo.bpo_dbuf, tx);
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   367
			subbpo.bpo_phys->bpo_subobjs = 0;
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   368
			VERIFY3U(0, ==, dmu_object_free(bpo->bpo_os,
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   369
			    subsubobjs, tx));
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   370
		}
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   371
	}
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   372
	bpo->bpo_phys->bpo_bytes += used;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   373
	bpo->bpo_phys->bpo_comp += comp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   374
	bpo->bpo_phys->bpo_uncomp += uncomp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   375
	mutex_exit(&bpo->bpo_lock);
12593
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   376
3c3a4d3d1dda 6959054 stack overflow due to nested bpobj's while deleting a share
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 12587
diff changeset
   377
	bpobj_close(&subbpo);
12470
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   378
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   379
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   380
void
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   381
bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   382
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   383
	blkptr_t stored_bp = *bp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   384
	uint64_t offset;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   385
	int blkoff;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   386
	blkptr_t *bparray;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   387
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   388
	ASSERT(!BP_IS_HOLE(bp));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   389
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   390
	/* We never need the fill count. */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   391
	stored_bp.blk_fill = 0;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   392
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   393
	/* The bpobj will compress better if we can leave off the checksum */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   394
	if (!BP_GET_DEDUP(bp))
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   395
		bzero(&stored_bp.blk_cksum, sizeof (stored_bp.blk_cksum));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   396
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   397
	mutex_enter(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   398
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   399
	offset = bpo->bpo_phys->bpo_num_blkptrs * sizeof (stored_bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   400
	blkoff = P2PHASE(bpo->bpo_phys->bpo_num_blkptrs, bpo->bpo_epb);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   401
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   402
	if (bpo->bpo_cached_dbuf == NULL ||
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   403
	    offset < bpo->bpo_cached_dbuf->db_offset ||
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   404
	    offset >= bpo->bpo_cached_dbuf->db_offset +
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   405
	    bpo->bpo_cached_dbuf->db_size) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   406
		if (bpo->bpo_cached_dbuf)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   407
			dmu_buf_rele(bpo->bpo_cached_dbuf, bpo);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   408
		VERIFY3U(0, ==, dmu_buf_hold(bpo->bpo_os, bpo->bpo_object,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   409
		    offset, bpo, &bpo->bpo_cached_dbuf, 0));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   410
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   411
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   412
	dmu_buf_will_dirty(bpo->bpo_cached_dbuf, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   413
	bparray = bpo->bpo_cached_dbuf->db_data;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   414
	bparray[blkoff] = stored_bp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   415
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   416
	dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   417
	bpo->bpo_phys->bpo_num_blkptrs++;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   418
	bpo->bpo_phys->bpo_bytes +=
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   419
	    bp_get_dsize_sync(dmu_objset_spa(bpo->bpo_os), bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   420
	if (bpo->bpo_havecomp) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   421
		bpo->bpo_phys->bpo_comp += BP_GET_PSIZE(bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   422
		bpo->bpo_phys->bpo_uncomp += BP_GET_UCSIZE(bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   423
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   424
	mutex_exit(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   425
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   426
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   427
struct space_range_arg {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   428
	spa_t *spa;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   429
	uint64_t mintxg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   430
	uint64_t maxtxg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   431
	uint64_t used;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   432
	uint64_t comp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   433
	uint64_t uncomp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   434
};
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   435
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   436
/* ARGSUSED */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   437
static int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   438
space_range_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   439
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   440
	struct space_range_arg *sra = arg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   441
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   442
	if (bp->blk_birth > sra->mintxg && bp->blk_birth <= sra->maxtxg) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   443
		sra->used += bp_get_dsize_sync(sra->spa, bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   444
		sra->comp += BP_GET_PSIZE(bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   445
		sra->uncomp += BP_GET_UCSIZE(bp);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   446
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   447
	return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   448
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   449
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   450
int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   451
bpobj_space(bpobj_t *bpo, uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   452
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   453
	mutex_enter(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   454
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   455
	*usedp = bpo->bpo_phys->bpo_bytes;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   456
	if (bpo->bpo_havecomp) {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   457
		*compp = bpo->bpo_phys->bpo_comp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   458
		*uncompp = bpo->bpo_phys->bpo_uncomp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   459
		mutex_exit(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   460
		return (0);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   461
	} else {
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   462
		mutex_exit(&bpo->bpo_lock);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   463
		return (bpobj_space_range(bpo, 0, UINT64_MAX,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   464
		    usedp, compp, uncompp));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   465
	}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   466
}
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   467
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   468
/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   469
 * Return the amount of space in the bpobj which is:
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   470
 * mintxg < blk_birth <= maxtxg
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   471
 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   472
int
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   473
bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg,
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   474
    uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   475
{
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   476
	struct space_range_arg sra = { 0 };
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   477
	int err;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   478
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   479
	/*
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   480
	 * As an optimization, if they want the whole txg range, just
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   481
	 * get bpo_bytes rather than iterating over the bps.
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   482
	 */
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   483
	if (mintxg < TXG_INITIAL && maxtxg == UINT64_MAX && bpo->bpo_havecomp)
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   484
		return (bpobj_space(bpo, usedp, compp, uncompp));
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   485
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   486
	sra.spa = dmu_objset_spa(bpo->bpo_os);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   487
	sra.mintxg = mintxg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   488
	sra.maxtxg = maxtxg;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   489
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   490
	err = bpobj_iterate_nofree(bpo, space_range_cb, &sra, NULL);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   491
	*usedp = sra.used;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   492
	*compp = sra.comp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   493
	*uncompp = sra.uncomp;
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   494
	return (err);
54258108784b 6948890 snapshot deletion can induce pathologically long spa_sync() times
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
diff changeset
   495
}