Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/fs/zfs/dsl_synctask.c @ 13805:e3a9ae14a119
3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Reviewed by Matt Ahrens <matthew.ahrens@delphix.com>
Reviewed by George Wilson <george.wilson@delphix.com>
Approved by Eric Schrock <eric.schrock@delphix.com>
author | Madhav Suresh <madhav.suresh@delphix.com> |
---|---|
date | Fri, 07 Sep 2012 07:19:55 -0700 |
parents | ac6eff781c67 |
children | 4972ab336f54 |
rev | line source |
---|---|
2199 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
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 /* | |
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. |
13743
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
23 * Copyright (c) 2012 by Delphix. All rights reserved. |
2199 | 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> | |
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 | 32 |
33 #define DST_AVG_BLKSHIFT 14 | |
34 | |
35 /* ARGSUSED */ | |
36 static int | |
37 dsl_null_checkfunc(void *arg1, void *arg2, dmu_tx_t *tx) | |
38 { | |
39 return (0); | |
40 } | |
41 | |
42 dsl_sync_task_group_t * | |
43 dsl_sync_task_group_create(dsl_pool_t *dp) | |
44 { | |
45 dsl_sync_task_group_t *dstg; | |
46 | |
47 dstg = kmem_zalloc(sizeof (dsl_sync_task_group_t), KM_SLEEP); | |
48 list_create(&dstg->dstg_tasks, sizeof (dsl_sync_task_t), | |
49 offsetof(dsl_sync_task_t, dst_node)); | |
50 dstg->dstg_pool = dp; | |
51 | |
52 return (dstg); | |
53 } | |
54 | |
55 void | |
56 dsl_sync_task_create(dsl_sync_task_group_t *dstg, | |
57 dsl_checkfunc_t *checkfunc, dsl_syncfunc_t *syncfunc, | |
58 void *arg1, void *arg2, int blocks_modified) | |
59 { | |
60 dsl_sync_task_t *dst; | |
61 | |
62 if (checkfunc == NULL) | |
63 checkfunc = dsl_null_checkfunc; | |
64 dst = kmem_zalloc(sizeof (dsl_sync_task_t), KM_SLEEP); | |
65 dst->dst_checkfunc = checkfunc; | |
66 dst->dst_syncfunc = syncfunc; | |
67 dst->dst_arg1 = arg1; | |
68 dst->dst_arg2 = arg2; | |
69 list_insert_tail(&dstg->dstg_tasks, dst); | |
70 | |
71 dstg->dstg_space += blocks_modified << DST_AVG_BLKSHIFT; | |
72 } | |
73 | |
74 int | |
75 dsl_sync_task_group_wait(dsl_sync_task_group_t *dstg) | |
76 { | |
77 dmu_tx_t *tx; | |
78 uint64_t txg; | |
79 dsl_sync_task_t *dst; | |
80 | |
81 top: | |
82 tx = dmu_tx_create_dd(dstg->dstg_pool->dp_mos_dir); | |
83 VERIFY(0 == dmu_tx_assign(tx, TXG_WAIT)); | |
84 | |
85 txg = dmu_tx_get_txg(tx); | |
86 | |
87 /* Do a preliminary error check. */ | |
88 dstg->dstg_err = 0; | |
13743
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
89 #ifdef ZFS_DEBUG |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
90 /* |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
91 * Only check half the time, otherwise, the sync-context |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
92 * check will almost never fail. |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
93 */ |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
94 if (spa_get_random(2) == 0) |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
95 goto skip; |
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
96 #endif |
2199 | 97 rw_enter(&dstg->dstg_pool->dp_config_rwlock, RW_READER); |
98 for (dst = list_head(&dstg->dstg_tasks); dst; | |
99 dst = list_next(&dstg->dstg_tasks, dst)) { | |
100 dst->dst_err = | |
101 dst->dst_checkfunc(dst->dst_arg1, dst->dst_arg2, tx); | |
102 if (dst->dst_err) | |
103 dstg->dstg_err = dst->dst_err; | |
104 } | |
105 rw_exit(&dstg->dstg_pool->dp_config_rwlock); | |
106 | |
107 if (dstg->dstg_err) { | |
108 dmu_tx_commit(tx); | |
109 return (dstg->dstg_err); | |
110 } | |
13743
95aba6e49b9f
2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents:
13061
diff
changeset
|
111 skip: |
2199 | 112 |
11816
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
113 /* |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
114 * We don't generally have many sync tasks, so pay the price of |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
115 * add_tail to get the tasks executed in the right order. |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
116 */ |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
117 VERIFY(0 == txg_list_add_tail(&dstg->dstg_pool->dp_sync_tasks, |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
118 dstg, txg)); |
2199 | 119 |
120 dmu_tx_commit(tx); | |
121 | |
122 txg_wait_synced(dstg->dstg_pool, txg); | |
123 | |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
5378
diff
changeset
|
124 if (dstg->dstg_err == EAGAIN) { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
5378
diff
changeset
|
125 txg_wait_synced(dstg->dstg_pool, txg + TXG_DEFER_SIZE); |
2199 | 126 goto top; |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
5378
diff
changeset
|
127 } |
2199 | 128 |
129 return (dstg->dstg_err); | |
130 } | |
131 | |
132 void | |
4577 | 133 dsl_sync_task_group_nowait(dsl_sync_task_group_t *dstg, dmu_tx_t *tx) |
134 { | |
135 uint64_t txg; | |
136 | |
137 dstg->dstg_nowaiter = B_TRUE; | |
138 txg = dmu_tx_get_txg(tx); | |
11816
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
139 /* |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
140 * We don't generally have many sync tasks, so pay the price of |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
141 * add_tail to get the tasks executed in the right order. |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
142 */ |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
143 VERIFY(0 == txg_list_add_tail(&dstg->dstg_pool->dp_sync_tasks, |
a30797f77200
6928246 spa_history_log should use dsl_sync_task_do_nowait
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10922
diff
changeset
|
144 dstg, txg)); |
4577 | 145 } |
146 | |
147 void | |
2199 | 148 dsl_sync_task_group_destroy(dsl_sync_task_group_t *dstg) |
149 { | |
150 dsl_sync_task_t *dst; | |
151 | |
152 while (dst = list_head(&dstg->dstg_tasks)) { | |
153 list_remove(&dstg->dstg_tasks, dst); | |
154 kmem_free(dst, sizeof (dsl_sync_task_t)); | |
155 } | |
156 kmem_free(dstg, sizeof (dsl_sync_task_group_t)); | |
157 } | |
158 | |
159 void | |
160 dsl_sync_task_group_sync(dsl_sync_task_group_t *dstg, dmu_tx_t *tx) | |
161 { | |
162 dsl_sync_task_t *dst; | |
11822
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
163 dsl_pool_t *dp = dstg->dstg_pool; |
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
164 uint64_t quota, used; |
2199 | 165 |
13805
e3a9ae14a119
3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents:
13790
diff
changeset
|
166 ASSERT0(dstg->dstg_err); |
2199 | 167 |
168 /* | |
11822
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
169 * 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
|
170 * 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
|
171 * 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
|
172 * in-core limits (arc_tempreserve, dsl_pool_tempreserve). |
2199 | 173 */ |
11822
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 /* MOS space is triple-dittoed, so we multiply by 3. */ |
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
178 if (dstg->dstg_space > 0 && used + dstg->dstg_space * 3 > quota) { |
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
179 dstg->dstg_err = ENOSPC; |
2199 | 180 return; |
11822
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
181 } |
2199 | 182 |
183 /* | |
184 * Check for errors by calling checkfuncs. | |
185 */ | |
11822
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
186 rw_enter(&dp->dp_config_rwlock, RW_WRITER); |
2199 | 187 for (dst = list_head(&dstg->dstg_tasks); dst; |
188 dst = list_next(&dstg->dstg_tasks, dst)) { | |
189 dst->dst_err = | |
190 dst->dst_checkfunc(dst->dst_arg1, dst->dst_arg2, tx); | |
191 if (dst->dst_err) | |
192 dstg->dstg_err = dst->dst_err; | |
193 } | |
194 | |
195 if (dstg->dstg_err == 0) { | |
196 /* | |
197 * Execute sync tasks. | |
198 */ | |
199 for (dst = list_head(&dstg->dstg_tasks); dst; | |
200 dst = list_next(&dstg->dstg_tasks, dst)) { | |
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
11823
diff
changeset
|
201 dst->dst_syncfunc(dst->dst_arg1, dst->dst_arg2, tx); |
2199 | 202 } |
203 } | |
11822
9195ca3173d2
6929652 dsl_sync_task_group_wait() can wait too long
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11816
diff
changeset
|
204 rw_exit(&dp->dp_config_rwlock); |
4577 | 205 |
206 if (dstg->dstg_nowaiter) | |
207 dsl_sync_task_group_destroy(dstg); | |
2199 | 208 } |
209 | |
210 int | |
211 dsl_sync_task_do(dsl_pool_t *dp, | |
212 dsl_checkfunc_t *checkfunc, dsl_syncfunc_t *syncfunc, | |
213 void *arg1, void *arg2, int blocks_modified) | |
214 { | |
215 dsl_sync_task_group_t *dstg; | |
216 int err; | |
217 | |
13061
bda0decf867b
PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents:
12296
diff
changeset
|
218 ASSERT(spa_writeable(dp->dp_spa)); |
bda0decf867b
PSARC 2010/306 Read-only ZFS pools
George Wilson <George.Wilson@Sun.COM>
parents:
12296
diff
changeset
|
219 |
2199 | 220 dstg = dsl_sync_task_group_create(dp); |
221 dsl_sync_task_create(dstg, checkfunc, syncfunc, | |
222 arg1, arg2, blocks_modified); | |
223 err = dsl_sync_task_group_wait(dstg); | |
224 dsl_sync_task_group_destroy(dstg); | |
225 return (err); | |
226 } | |
4577 | 227 |
228 void | |
229 dsl_sync_task_do_nowait(dsl_pool_t *dp, | |
230 dsl_checkfunc_t *checkfunc, dsl_syncfunc_t *syncfunc, | |
231 void *arg1, void *arg2, int blocks_modified, dmu_tx_t *tx) | |
232 { | |
13790
ac6eff781c67
3112 ztest does not honor ZFS_DEBUG
Matthew Ahrens <mahrens@delphix.com>
parents:
13765
diff
changeset
|
233 dsl_sync_task_group_t *dstg = dsl_sync_task_group_create(dp); |
4577 | 234 dsl_sync_task_create(dstg, checkfunc, syncfunc, |
235 arg1, arg2, blocks_modified); | |
236 dsl_sync_task_group_nowait(dstg, tx); | |
237 } |