4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24 */
25
26 #include <sys/dmu.h>
27 #include <sys/dmu_tx.h>
28 #include <sys/dsl_pool.h>
29 #include <sys/dsl_dir.h>
30 #include <sys/dsl_synctask.h>
31 #include <sys/metaslab.h>
32
33 #define DST_AVG_BLKSHIFT 14
34
35 /* ARGSUSED */
36 static int
37 dsl_null_checkfunc(void *arg, dmu_tx_t *tx)
38 {
39 return (0);
40 }
41
42 /*
43 * Called from open context to perform a callback in syncing context. Waits
44 * for the operation to complete.
45 *
46 * The checkfunc will be called from open context as a preliminary check
47 * which can quickly fail. If it succeeds, it will be called again from
48 * syncing context. The checkfunc should generally be designed to work
49 * properly in either context, but if necessary it can check
50 * dmu_tx_is_syncing(tx).
51 *
52 * The synctask infrastructure enforces proper locking strategy with respect
53 * to the dp_config_rwlock -- the lock will always be held when the callbacks
54 * are called. It will be held for read during the open-context (preliminary)
95 dsl_pool_config_enter(dp, FTAG);
96 err = dst.dst_checkfunc(arg, tx);
97 dsl_pool_config_exit(dp, FTAG);
98
99 if (err != 0) {
100 dmu_tx_commit(tx);
101 spa_close(spa, FTAG);
102 return (err);
103 }
104
105 VERIFY(txg_list_add_tail(&dp->dp_sync_tasks, &dst, dst.dst_txg));
106
107 dmu_tx_commit(tx);
108
109 txg_wait_synced(dp, dst.dst_txg);
110
111 if (dst.dst_error == EAGAIN) {
112 txg_wait_synced(dp, dst.dst_txg + TXG_DEFER_SIZE);
113 goto top;
114 }
115
116 spa_close(spa, FTAG);
117 return (dst.dst_error);
118 }
119
120 void
121 dsl_sync_task_nowait(dsl_pool_t *dp, dsl_syncfunc_t *syncfunc, void *arg,
122 int blocks_modified, zfs_space_check_t space_check, dmu_tx_t *tx)
123 {
124 dsl_sync_task_t *dst = kmem_zalloc(sizeof (*dst), KM_SLEEP);
125
126 dst->dst_pool = dp;
127 dst->dst_txg = dmu_tx_get_txg(tx);
128 dst->dst_space = blocks_modified << DST_AVG_BLKSHIFT;
129 dst->dst_space_check = space_check;
130 dst->dst_checkfunc = dsl_null_checkfunc;
131 dst->dst_syncfunc = syncfunc;
132 dst->dst_arg = arg;
133 dst->dst_error = 0;
134 dst->dst_nowaiter = B_TRUE;
135
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #include <sys/dmu.h>
28 #include <sys/dmu_tx.h>
29 #include <sys/dsl_pool.h>
30 #include <sys/dsl_dir.h>
31 #include <sys/dsl_synctask.h>
32 #include <sys/metaslab.h>
33
34 /* ARGSUSED */
35 static int
36 dsl_null_checkfunc(void *arg, dmu_tx_t *tx)
37 {
38 return (0);
39 }
40
41 /*
42 * Called from open context to perform a callback in syncing context. Waits
43 * for the operation to complete.
44 *
45 * The checkfunc will be called from open context as a preliminary check
46 * which can quickly fail. If it succeeds, it will be called again from
47 * syncing context. The checkfunc should generally be designed to work
48 * properly in either context, but if necessary it can check
49 * dmu_tx_is_syncing(tx).
50 *
51 * The synctask infrastructure enforces proper locking strategy with respect
52 * to the dp_config_rwlock -- the lock will always be held when the callbacks
53 * are called. It will be held for read during the open-context (preliminary)
94 dsl_pool_config_enter(dp, FTAG);
95 err = dst.dst_checkfunc(arg, tx);
96 dsl_pool_config_exit(dp, FTAG);
97
98 if (err != 0) {
99 dmu_tx_commit(tx);
100 spa_close(spa, FTAG);
101 return (err);
102 }
103
104 VERIFY(txg_list_add_tail(&dp->dp_sync_tasks, &dst, dst.dst_txg));
105
106 dmu_tx_commit(tx);
107
108 txg_wait_synced(dp, dst.dst_txg);
109
110 if (dst.dst_error == EAGAIN) {
111 txg_wait_synced(dp, dst.dst_txg + TXG_DEFER_SIZE);
112 goto top;
113 }
114 spa_close(spa, FTAG);
115 return (dst.dst_error);
116 }
117
118 void
119 dsl_sync_task_nowait(dsl_pool_t *dp, dsl_syncfunc_t *syncfunc, void *arg,
120 int blocks_modified, zfs_space_check_t space_check, dmu_tx_t *tx)
121 {
122 dsl_sync_task_t *dst = kmem_zalloc(sizeof (*dst), KM_SLEEP);
123
124 dst->dst_pool = dp;
125 dst->dst_txg = dmu_tx_get_txg(tx);
126 dst->dst_space = blocks_modified << DST_AVG_BLKSHIFT;
127 dst->dst_space_check = space_check;
128 dst->dst_checkfunc = dsl_null_checkfunc;
129 dst->dst_syncfunc = syncfunc;
130 dst->dst_arg = arg;
131 dst->dst_error = 0;
132 dst->dst_nowaiter = B_TRUE;
133
|