usr/src/uts/common/fs/zfs/dsl_synctask.c
author Joshua M. Clulow <jmc@joyent.com>
Mon, 04 Mar 2013 23:52:56 +0000
changeset 14188 afe390b9f1e0
parent 13980 d7059eb1884c
permissions -rw-r--r--
4020 Make ldi_ev_remove_callbacks safe to use in LDI callbacks Reviewed by: Robert Mustacchi <[email protected]> Approved by: Dan McDonald <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     1
/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     3
 *
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     7
 *
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    12
 *
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    18
 *
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    20
 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    21
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11823
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13973
diff changeset
    23
 * Copyright (c) 2013 by Delphix. All rights reserved.
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    24
 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    25
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    26
#include <sys/dmu.h>
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    27
#include <sys/dmu_tx.h>
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    28
#include <sys/dsl_pool.h>
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    29
#include <sys/dsl_dir.h>
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    30
#include <sys/dsl_synctask.h>
11822
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
    31
#include <sys/metaslab.h>
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    32
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    33
#define	DST_AVG_BLKSHIFT 14
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    34
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    35
/* ARGSUSED */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    36
static int
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    37
dsl_null_checkfunc(void *arg, dmu_tx_t *tx)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    38
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    39
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    40
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    41
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    42
/*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    43
 * Called from open context to perform a callback in syncing context.  Waits
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    44
 * for the operation to complete.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    45
 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    46
 * The checkfunc will be called from open context as a preliminary check
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    47
 * which can quickly fail.  If it succeeds, it will be called again from
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    48
 * syncing context.  The checkfunc should generally be designed to work
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    49
 * properly in either context, but if necessary it can check
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    50
 * dmu_tx_is_syncing(tx).
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    51
 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    52
 * The synctask infrastructure enforces proper locking strategy with respect
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    53
 * to the dp_config_rwlock -- the lock will always be held when the callbacks
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    54
 * are called.  It will be held for read during the open-context (preliminary)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    55
 * call to the checkfunc, and then held for write from syncing context during
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    56
 * the calls to the check and sync funcs.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    57
 *
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    58
 * A dataset or pool name can be passed as the first argument.  Typically,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    59
 * the check func will hold, check the return value of the hold, and then
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    60
 * release the dataset.  The sync func will VERIFYO(hold()) the dataset.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    61
 * This is safe because no changes can be made between the check and sync funcs,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    62
 * and the sync func will only be called if the check func successfully opened
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    63
 * the dataset.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    64
 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    65
int
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    66
dsl_sync_task(const char *pool, dsl_checkfunc_t *checkfunc,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    67
    dsl_syncfunc_t *syncfunc, void *arg, int blocks_modified)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    68
{
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    69
	spa_t *spa;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    70
	dmu_tx_t *tx;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    71
	int err;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    72
	dsl_sync_task_t dst = { 0 };
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    73
	dsl_pool_t *dp;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    74
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    75
	err = spa_open(pool, &spa, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    76
	if (err != 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    77
		return (err);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    78
	dp = spa_get_dsl(spa);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    79
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    80
top:
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    81
	tx = dmu_tx_create_dd(dp->dp_mos_dir);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    82
	VERIFY0(dmu_tx_assign(tx, TXG_WAIT));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    83
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    84
	dst.dst_pool = dp;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    85
	dst.dst_txg = dmu_tx_get_txg(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    86
	dst.dst_space = blocks_modified << DST_AVG_BLKSHIFT;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    87
	dst.dst_checkfunc = checkfunc != NULL ? checkfunc : dsl_null_checkfunc;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    88
	dst.dst_syncfunc = syncfunc;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    89
	dst.dst_arg = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    90
	dst.dst_error = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    91
	dst.dst_nowaiter = B_FALSE;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
    92
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    93
	dsl_pool_config_enter(dp, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    94
	err = dst.dst_checkfunc(arg, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    95
	dsl_pool_config_exit(dp, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    96
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    97
	if (err != 0) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    98
		dmu_tx_commit(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
    99
		spa_close(spa, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   100
		return (err);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   101
	}
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   102
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   103
	VERIFY(txg_list_add_tail(&dp->dp_sync_tasks, &dst, dst.dst_txg));
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   104
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   105
	dmu_tx_commit(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   106
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   107
	txg_wait_synced(dp, dst.dst_txg);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   108
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   109
	if (dst.dst_error == EAGAIN) {
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   110
		txg_wait_synced(dp, dst.dst_txg + TXG_DEFER_SIZE);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   111
		goto top;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   112
	}
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   113
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   114
	spa_close(spa, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   115
	return (dst.dst_error);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   116
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   117
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   118
void
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   119
dsl_sync_task_nowait(dsl_pool_t *dp, dsl_syncfunc_t *syncfunc, void *arg,
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   120
    int blocks_modified, dmu_tx_t *tx)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   121
{
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   122
	dsl_sync_task_t *dst = kmem_zalloc(sizeof (*dst), KM_SLEEP);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   123
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   124
	dst->dst_pool = dp;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   125
	dst->dst_txg = dmu_tx_get_txg(tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   126
	dst->dst_space = blocks_modified << DST_AVG_BLKSHIFT;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   127
	dst->dst_checkfunc = dsl_null_checkfunc;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   128
	dst->dst_syncfunc = syncfunc;
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   129
	dst->dst_arg = arg;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   130
	dst->dst_error = 0;
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   131
	dst->dst_nowaiter = B_TRUE;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   132
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   133
	VERIFY(txg_list_add_tail(&dp->dp_sync_tasks, dst, dst->dst_txg));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   134
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   135
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   136
/*
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   137
 * Called in syncing context to execute the synctask.
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   138
 */
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   139
void
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   140
dsl_sync_task_sync(dsl_sync_task_t *dst, dmu_tx_t *tx)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   141
{
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   142
	dsl_pool_t *dp = dst->dst_pool;
11822
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   143
	uint64_t quota, used;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   144
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   145
	ASSERT0(dst->dst_error);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   146
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   147
	/*
11822
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   148
	 * Check for sufficient space.  We just check against what's
11823
c756cd80d532 6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11822
diff changeset
   149
	 * on-disk; we don't want any in-flight accounting to get in our
11822
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   150
	 * way, because open context may have already used up various
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   151
	 * in-core limits (arc_tempreserve, dsl_pool_tempreserve).
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   152
	 */
11822
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   153
	quota = dsl_pool_adjustedsize(dp, B_FALSE) -
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   154
	    metaslab_class_get_deferred(spa_normal_class(dp->dp_spa));
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   155
	used = dp->dp_root_dir->dd_phys->dd_used_bytes;
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   156
	/* MOS space is triple-dittoed, so we multiply by 3. */
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   157
	if (dst->dst_space > 0 && used + dst->dst_space * 3 > quota) {
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13973
diff changeset
   158
		dst->dst_error = SET_ERROR(ENOSPC);
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   159
		if (dst->dst_nowaiter)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   160
			kmem_free(dst, sizeof (*dst));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   161
		return;
11822
9195ca3173d2 6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11816
diff changeset
   162
	}
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   163
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   164
	/*
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   165
	 * Check for errors by calling checkfunc.
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   166
	 */
13973
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   167
	rrw_enter(&dp->dp_config_rwlock, RW_WRITER, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   168
	dst->dst_error = dst->dst_checkfunc(dst->dst_arg, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   169
	if (dst->dst_error == 0)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   170
		dst->dst_syncfunc(dst->dst_arg, tx);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   171
	rrw_exit(&dp->dp_config_rwlock, FTAG);
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   172
	if (dst->dst_nowaiter)
4972ab336f54 3464 zfs synctask code needs restructuring
Matthew Ahrens <mahrens@delphix.com>
parents: 13805
diff changeset
   173
		kmem_free(dst, sizeof (*dst));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents:
diff changeset
   174
}