author | Jeff Bonwick <Jeff.Bonwick@Sun.COM> |
Thu, 29 Apr 2010 13:37:53 -0700 | |
changeset 12285 | d736d62dcca2 |
parent 11823 | c756cd80d532 |
child 12296 | 7cf402a7f374 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 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 |
/* |
|
11823
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
22 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#include <sys/dmu.h> |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
27 |
#include <sys/dmu_objset.h> |
789 | 28 |
#include <sys/dmu_tx.h> |
29 |
#include <sys/dsl_dataset.h> |
|
30 |
#include <sys/dsl_dir.h> |
|
31 |
#include <sys/dsl_prop.h> |
|
2199 | 32 |
#include <sys/dsl_synctask.h> |
4543 | 33 |
#include <sys/dsl_deleg.h> |
789 | 34 |
#include <sys/spa.h> |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
35 |
#include <sys/metaslab.h> |
789 | 36 |
#include <sys/zap.h> |
37 |
#include <sys/zio.h> |
|
38 |
#include <sys/arc.h> |
|
4543 | 39 |
#include <sys/sunddi.h> |
789 | 40 |
#include "zfs_namecheck.h" |
41 |
||
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
42 |
static uint64_t dsl_dir_space_towrite(dsl_dir_t *dd); |
4543 | 43 |
static void dsl_dir_set_reservation_sync(void *arg1, void *arg2, |
44 |
cred_t *cr, dmu_tx_t *tx); |
|
789 | 45 |
|
46 |
||
47 |
/* ARGSUSED */ |
|
48 |
static void |
|
49 |
dsl_dir_evict(dmu_buf_t *db, void *arg) |
|
50 |
{ |
|
51 |
dsl_dir_t *dd = arg; |
|
52 |
dsl_pool_t *dp = dd->dd_pool; |
|
53 |
int t; |
|
54 |
||
55 |
for (t = 0; t < TXG_SIZE; t++) { |
|
56 |
ASSERT(!txg_list_member(&dp->dp_dirty_dirs, dd, t)); |
|
57 |
ASSERT(dd->dd_tempreserved[t] == 0); |
|
58 |
ASSERT(dd->dd_space_towrite[t] == 0); |
|
59 |
} |
|
60 |
||
61 |
if (dd->dd_parent) |
|
62 |
dsl_dir_close(dd->dd_parent, dd); |
|
63 |
||
64 |
spa_close(dd->dd_pool->dp_spa, dd); |
|
65 |
||
66 |
/* |
|
67 |
* The props callback list should be empty since they hold the |
|
68 |
* dir open. |
|
69 |
*/ |
|
70 |
list_destroy(&dd->dd_prop_cbs); |
|
2856 | 71 |
mutex_destroy(&dd->dd_lock); |
789 | 72 |
kmem_free(dd, sizeof (dsl_dir_t)); |
73 |
} |
|
74 |
||
1544 | 75 |
int |
789 | 76 |
dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj, |
1544 | 77 |
const char *tail, void *tag, dsl_dir_t **ddp) |
789 | 78 |
{ |
79 |
dmu_buf_t *dbuf; |
|
80 |
dsl_dir_t *dd; |
|
1544 | 81 |
int err; |
789 | 82 |
|
83 |
ASSERT(RW_LOCK_HELD(&dp->dp_config_rwlock) || |
|
84 |
dsl_pool_sync_context(dp)); |
|
85 |
||
1544 | 86 |
err = dmu_bonus_hold(dp->dp_meta_objset, ddobj, tag, &dbuf); |
87 |
if (err) |
|
88 |
return (err); |
|
789 | 89 |
dd = dmu_buf_get_user(dbuf); |
90 |
#ifdef ZFS_DEBUG |
|
91 |
{ |
|
92 |
dmu_object_info_t doi; |
|
93 |
dmu_object_info_from_db(dbuf, &doi); |
|
928
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
94 |
ASSERT3U(doi.doi_type, ==, DMU_OT_DSL_DIR); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
95 |
ASSERT3U(doi.doi_bonus_size, >=, sizeof (dsl_dir_phys_t)); |
789 | 96 |
} |
97 |
#endif |
|
98 |
if (dd == NULL) { |
|
99 |
dsl_dir_t *winner; |
|
100 |
||
101 |
dd = kmem_zalloc(sizeof (dsl_dir_t), KM_SLEEP); |
|
102 |
dd->dd_object = ddobj; |
|
103 |
dd->dd_dbuf = dbuf; |
|
104 |
dd->dd_pool = dp; |
|
105 |
dd->dd_phys = dbuf->db_data; |
|
2856 | 106 |
mutex_init(&dd->dd_lock, NULL, MUTEX_DEFAULT, NULL); |
789 | 107 |
|
108 |
list_create(&dd->dd_prop_cbs, sizeof (dsl_prop_cb_record_t), |
|
109 |
offsetof(dsl_prop_cb_record_t, cbr_node)); |
|
110 |
||
10373
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
111 |
dsl_dir_snap_cmtime_update(dd); |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
112 |
|
789 | 113 |
if (dd->dd_phys->dd_parent_obj) { |
1544 | 114 |
err = dsl_dir_open_obj(dp, dd->dd_phys->dd_parent_obj, |
115 |
NULL, dd, &dd->dd_parent); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
116 |
if (err) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
117 |
goto errout; |
789 | 118 |
if (tail) { |
119 |
#ifdef ZFS_DEBUG |
|
120 |
uint64_t foundobj; |
|
121 |
||
122 |
err = zap_lookup(dp->dp_meta_objset, |
|
4577 | 123 |
dd->dd_parent->dd_phys->dd_child_dir_zapobj, |
789 | 124 |
tail, sizeof (foundobj), 1, &foundobj); |
1544 | 125 |
ASSERT(err || foundobj == ddobj); |
789 | 126 |
#endif |
127 |
(void) strcpy(dd->dd_myname, tail); |
|
128 |
} else { |
|
129 |
err = zap_value_search(dp->dp_meta_objset, |
|
4577 | 130 |
dd->dd_parent->dd_phys->dd_child_dir_zapobj, |
131 |
ddobj, 0, dd->dd_myname); |
|
1544 | 132 |
} |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
133 |
if (err) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
134 |
goto errout; |
789 | 135 |
} else { |
136 |
(void) strcpy(dd->dd_myname, spa_name(dp->dp_spa)); |
|
137 |
} |
|
138 |
||
139 |
winner = dmu_buf_set_user_ie(dbuf, dd, &dd->dd_phys, |
|
140 |
dsl_dir_evict); |
|
141 |
if (winner) { |
|
142 |
if (dd->dd_parent) |
|
143 |
dsl_dir_close(dd->dd_parent, dd); |
|
2856 | 144 |
mutex_destroy(&dd->dd_lock); |
789 | 145 |
kmem_free(dd, sizeof (dsl_dir_t)); |
146 |
dd = winner; |
|
147 |
} else { |
|
148 |
spa_open_ref(dp->dp_spa, dd); |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
/* |
|
153 |
* The dsl_dir_t has both open-to-close and instantiate-to-evict |
|
154 |
* holds on the spa. We need the open-to-close holds because |
|
155 |
* otherwise the spa_refcnt wouldn't change when we open a |
|
156 |
* dir which the spa also has open, so we could incorrectly |
|
157 |
* think it was OK to unload/export/destroy the pool. We need |
|
158 |
* the instantiate-to-evict hold because the dsl_dir_t has a |
|
159 |
* pointer to the dd_pool, which has a pointer to the spa_t. |
|
160 |
*/ |
|
161 |
spa_open_ref(dp->dp_spa, tag); |
|
162 |
ASSERT3P(dd->dd_pool, ==, dp); |
|
163 |
ASSERT3U(dd->dd_object, ==, ddobj); |
|
164 |
ASSERT3P(dd->dd_dbuf, ==, dbuf); |
|
1544 | 165 |
*ddp = dd; |
166 |
return (0); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
167 |
|
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
168 |
errout: |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
169 |
if (dd->dd_parent) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
170 |
dsl_dir_close(dd->dd_parent, dd); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
171 |
mutex_destroy(&dd->dd_lock); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
172 |
kmem_free(dd, sizeof (dsl_dir_t)); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
173 |
dmu_buf_rele(dbuf, tag); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
174 |
return (err); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
175 |
|
789 | 176 |
} |
177 |
||
178 |
void |
|
179 |
dsl_dir_close(dsl_dir_t *dd, void *tag) |
|
180 |
{ |
|
181 |
dprintf_dd(dd, "%s\n", ""); |
|
182 |
spa_close(dd->dd_pool->dp_spa, tag); |
|
1544 | 183 |
dmu_buf_rele(dd->dd_dbuf, tag); |
789 | 184 |
} |
185 |
||
2467
9829873580a5
6443585 zpool create of poolname > 250 and < 256 characters panics in debug printout
ek110237
parents:
2206
diff
changeset
|
186 |
/* buf must be long enough (MAXNAMELEN + strlen(MOS_DIR_NAME) + 1 should do) */ |
789 | 187 |
void |
188 |
dsl_dir_name(dsl_dir_t *dd, char *buf) |
|
189 |
{ |
|
190 |
if (dd->dd_parent) { |
|
191 |
dsl_dir_name(dd->dd_parent, buf); |
|
192 |
(void) strcat(buf, "/"); |
|
193 |
} else { |
|
194 |
buf[0] = '\0'; |
|
195 |
} |
|
196 |
if (!MUTEX_HELD(&dd->dd_lock)) { |
|
197 |
/* |
|
198 |
* recursive mutex so that we can use |
|
199 |
* dprintf_dd() with dd_lock held |
|
200 |
*/ |
|
201 |
mutex_enter(&dd->dd_lock); |
|
202 |
(void) strcat(buf, dd->dd_myname); |
|
203 |
mutex_exit(&dd->dd_lock); |
|
204 |
} else { |
|
205 |
(void) strcat(buf, dd->dd_myname); |
|
206 |
} |
|
207 |
} |
|
208 |
||
3978
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
209 |
/* Calculate name legnth, avoiding all the strcat calls of dsl_dir_name */ |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
210 |
int |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
211 |
dsl_dir_namelen(dsl_dir_t *dd) |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
212 |
{ |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
213 |
int result = 0; |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
214 |
|
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
215 |
if (dd->dd_parent) { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
216 |
/* parent's name + 1 for the "/" */ |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
217 |
result = dsl_dir_namelen(dd->dd_parent) + 1; |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
218 |
} |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
219 |
|
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
220 |
if (!MUTEX_HELD(&dd->dd_lock)) { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
221 |
/* see dsl_dir_name */ |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
222 |
mutex_enter(&dd->dd_lock); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
223 |
result += strlen(dd->dd_myname); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
224 |
mutex_exit(&dd->dd_lock); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
225 |
} else { |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
226 |
result += strlen(dd->dd_myname); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
227 |
} |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
228 |
|
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
229 |
return (result); |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
230 |
} |
2dd668007b7a
6533813 recursive snapshotting resulted in a bad stack overflow
mmusante
parents:
2885
diff
changeset
|
231 |
|
789 | 232 |
static int |
233 |
getcomponent(const char *path, char *component, const char **nextp) |
|
234 |
{ |
|
235 |
char *p; |
|
8924
5af812f84759
6789318 coredump when issue zdb -uuuu poolname/
Rich Morris <Richard.Morris@Sun.COM>
parents:
8525
diff
changeset
|
236 |
if ((path == NULL) || (path[0] == '\0')) |
2731
2dd6e16860b6
6463349 error message from zpool(1M) is missing a newline
nd150628
parents:
2467
diff
changeset
|
237 |
return (ENOENT); |
789 | 238 |
/* This would be a good place to reserve some namespace... */ |
239 |
p = strpbrk(path, "/@"); |
|
240 |
if (p && (p[1] == '/' || p[1] == '@')) { |
|
241 |
/* two separators in a row */ |
|
242 |
return (EINVAL); |
|
243 |
} |
|
244 |
if (p == NULL || p == path) { |
|
245 |
/* |
|
246 |
* if the first thing is an @ or /, it had better be an |
|
247 |
* @ and it had better not have any more ats or slashes, |
|
248 |
* and it had better have something after the @. |
|
249 |
*/ |
|
250 |
if (p != NULL && |
|
251 |
(p[0] != '@' || strpbrk(path+1, "/@") || p[1] == '\0')) |
|
252 |
return (EINVAL); |
|
253 |
if (strlen(path) >= MAXNAMELEN) |
|
254 |
return (ENAMETOOLONG); |
|
255 |
(void) strcpy(component, path); |
|
256 |
p = NULL; |
|
257 |
} else if (p[0] == '/') { |
|
258 |
if (p-path >= MAXNAMELEN) |
|
259 |
return (ENAMETOOLONG); |
|
260 |
(void) strncpy(component, path, p - path); |
|
261 |
component[p-path] = '\0'; |
|
262 |
p++; |
|
263 |
} else if (p[0] == '@') { |
|
264 |
/* |
|
265 |
* if the next separator is an @, there better not be |
|
266 |
* any more slashes. |
|
267 |
*/ |
|
268 |
if (strchr(path, '/')) |
|
269 |
return (EINVAL); |
|
270 |
if (p-path >= MAXNAMELEN) |
|
271 |
return (ENAMETOOLONG); |
|
272 |
(void) strncpy(component, path, p - path); |
|
273 |
component[p-path] = '\0'; |
|
274 |
} else { |
|
275 |
ASSERT(!"invalid p"); |
|
276 |
} |
|
277 |
*nextp = p; |
|
278 |
return (0); |
|
279 |
} |
|
280 |
||
281 |
/* |
|
282 |
* same as dsl_open_dir, ignore the first component of name and use the |
|
283 |
* spa instead |
|
284 |
*/ |
|
1544 | 285 |
int |
286 |
dsl_dir_open_spa(spa_t *spa, const char *name, void *tag, |
|
287 |
dsl_dir_t **ddp, const char **tailp) |
|
789 | 288 |
{ |
289 |
char buf[MAXNAMELEN]; |
|
290 |
const char *next, *nextnext = NULL; |
|
291 |
int err; |
|
292 |
dsl_dir_t *dd; |
|
293 |
dsl_pool_t *dp; |
|
294 |
uint64_t ddobj; |
|
295 |
int openedspa = FALSE; |
|
296 |
||
297 |
dprintf("%s\n", name); |
|
298 |
||
299 |
err = getcomponent(name, buf, &next); |
|
300 |
if (err) |
|
1544 | 301 |
return (err); |
789 | 302 |
if (spa == NULL) { |
303 |
err = spa_open(buf, &spa, FTAG); |
|
304 |
if (err) { |
|
305 |
dprintf("spa_open(%s) failed\n", buf); |
|
1544 | 306 |
return (err); |
789 | 307 |
} |
308 |
openedspa = TRUE; |
|
309 |
||
310 |
/* XXX this assertion belongs in spa_open */ |
|
311 |
ASSERT(!dsl_pool_sync_context(spa_get_dsl(spa))); |
|
312 |
} |
|
313 |
||
314 |
dp = spa_get_dsl(spa); |
|
315 |
||
316 |
rw_enter(&dp->dp_config_rwlock, RW_READER); |
|
1544 | 317 |
err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj, NULL, tag, &dd); |
318 |
if (err) { |
|
319 |
rw_exit(&dp->dp_config_rwlock); |
|
320 |
if (openedspa) |
|
321 |
spa_close(spa, FTAG); |
|
322 |
return (err); |
|
323 |
} |
|
324 |
||
789 | 325 |
while (next != NULL) { |
326 |
dsl_dir_t *child_ds; |
|
327 |
err = getcomponent(next, buf, &nextnext); |
|
1544 | 328 |
if (err) |
329 |
break; |
|
789 | 330 |
ASSERT(next[0] != '\0'); |
331 |
if (next[0] == '@') |
|
332 |
break; |
|
333 |
dprintf("looking up %s in obj%lld\n", |
|
334 |
buf, dd->dd_phys->dd_child_dir_zapobj); |
|
335 |
||
336 |
err = zap_lookup(dp->dp_meta_objset, |
|
337 |
dd->dd_phys->dd_child_dir_zapobj, |
|
338 |
buf, sizeof (ddobj), 1, &ddobj); |
|
1544 | 339 |
if (err) { |
340 |
if (err == ENOENT) |
|
341 |
err = 0; |
|
789 | 342 |
break; |
343 |
} |
|
344 |
||
1544 | 345 |
err = dsl_dir_open_obj(dp, ddobj, buf, tag, &child_ds); |
346 |
if (err) |
|
347 |
break; |
|
789 | 348 |
dsl_dir_close(dd, tag); |
349 |
dd = child_ds; |
|
350 |
next = nextnext; |
|
351 |
} |
|
352 |
rw_exit(&dp->dp_config_rwlock); |
|
353 |
||
1544 | 354 |
if (err) { |
355 |
dsl_dir_close(dd, tag); |
|
356 |
if (openedspa) |
|
357 |
spa_close(spa, FTAG); |
|
358 |
return (err); |
|
359 |
} |
|
360 |
||
789 | 361 |
/* |
362 |
* It's an error if there's more than one component left, or |
|
363 |
* tailp==NULL and there's any component left. |
|
364 |
*/ |
|
365 |
if (next != NULL && |
|
366 |
(tailp == NULL || (nextnext && nextnext[0] != '\0'))) { |
|
367 |
/* bad path name */ |
|
368 |
dsl_dir_close(dd, tag); |
|
369 |
dprintf("next=%p (%s) tail=%p\n", next, next?next:"", tailp); |
|
1544 | 370 |
err = ENOENT; |
789 | 371 |
} |
372 |
if (tailp) |
|
373 |
*tailp = next; |
|
374 |
if (openedspa) |
|
375 |
spa_close(spa, FTAG); |
|
1544 | 376 |
*ddp = dd; |
377 |
return (err); |
|
789 | 378 |
} |
379 |
||
380 |
/* |
|
381 |
* Return the dsl_dir_t, and possibly the last component which couldn't |
|
382 |
* be found in *tail. Return NULL if the path is bogus, or if |
|
383 |
* tail==NULL and we couldn't parse the whole name. (*tail)[0] == '@' |
|
384 |
* means that the last component is a snapshot. |
|
385 |
*/ |
|
1544 | 386 |
int |
387 |
dsl_dir_open(const char *name, void *tag, dsl_dir_t **ddp, const char **tailp) |
|
789 | 388 |
{ |
1544 | 389 |
return (dsl_dir_open_spa(NULL, name, tag, ddp, tailp)); |
789 | 390 |
} |
391 |
||
2199 | 392 |
uint64_t |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
393 |
dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds, const char *name, |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
394 |
dmu_tx_t *tx) |
789 | 395 |
{ |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
396 |
objset_t *mos = dp->dp_meta_objset; |
789 | 397 |
uint64_t ddobj; |
398 |
dsl_dir_phys_t *dsphys; |
|
399 |
dmu_buf_t *dbuf; |
|
400 |
||
928
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
401 |
ddobj = dmu_object_alloc(mos, DMU_OT_DSL_DIR, 0, |
36d72fe4da29
6349314 dmu_object_type names incorrect for DSL Directories and DSL Datasets
tabriz
parents:
885
diff
changeset
|
402 |
DMU_OT_DSL_DIR, sizeof (dsl_dir_phys_t), tx); |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
403 |
if (pds) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
404 |
VERIFY(0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
405 |
name, sizeof (uint64_t), 1, &ddobj, tx)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
406 |
} else { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
407 |
/* it's the root dir */ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
408 |
VERIFY(0 == zap_add(mos, DMU_POOL_DIRECTORY_OBJECT, |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
409 |
DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1, &ddobj, tx)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
410 |
} |
1544 | 411 |
VERIFY(0 == dmu_bonus_hold(mos, ddobj, FTAG, &dbuf)); |
789 | 412 |
dmu_buf_will_dirty(dbuf, tx); |
413 |
dsphys = dbuf->db_data; |
|
414 |
||
415 |
dsphys->dd_creation_time = gethrestime_sec(); |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
416 |
if (pds) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
417 |
dsphys->dd_parent_obj = pds->dd_object; |
789 | 418 |
dsphys->dd_props_zapobj = zap_create(mos, |
419 |
DMU_OT_DSL_PROPS, DMU_OT_NONE, 0, tx); |
|
420 |
dsphys->dd_child_dir_zapobj = zap_create(mos, |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
789
diff
changeset
|
421 |
DMU_OT_DSL_DIR_CHILD_MAP, DMU_OT_NONE, 0, tx); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
422 |
if (spa_version(dp->dp_spa) >= SPA_VERSION_USED_BREAKDOWN) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
423 |
dsphys->dd_flags |= DD_FLAG_USED_BREAKDOWN; |
1544 | 424 |
dmu_buf_rele(dbuf, FTAG); |
789 | 425 |
|
2199 | 426 |
return (ddobj); |
427 |
} |
|
428 |
||
429 |
/* ARGSUSED */ |
|
430 |
int |
|
431 |
dsl_dir_destroy_check(void *arg1, void *arg2, dmu_tx_t *tx) |
|
432 |
{ |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
433 |
dsl_dataset_t *ds = arg1; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
434 |
dsl_dir_t *dd = ds->ds_dir; |
2199 | 435 |
dsl_pool_t *dp = dd->dd_pool; |
436 |
objset_t *mos = dp->dp_meta_objset; |
|
437 |
int err; |
|
438 |
uint64_t count; |
|
439 |
||
440 |
/* |
|
441 |
* There should be exactly two holds, both from |
|
442 |
* dsl_dataset_destroy: one on the dd directory, and one on its |
|
443 |
* head ds. Otherwise, someone is trying to lookup something |
|
444 |
* inside this dir while we want to destroy it. The |
|
445 |
* config_rwlock ensures that nobody else opens it after we |
|
446 |
* check. |
|
447 |
*/ |
|
448 |
if (dmu_buf_refcount(dd->dd_dbuf) > 2) |
|
449 |
return (EBUSY); |
|
450 |
||
451 |
err = zap_count(mos, dd->dd_phys->dd_child_dir_zapobj, &count); |
|
452 |
if (err) |
|
453 |
return (err); |
|
454 |
if (count != 0) |
|
455 |
return (EEXIST); |
|
789 | 456 |
|
457 |
return (0); |
|
458 |
} |
|
459 |
||
2199 | 460 |
void |
4543 | 461 |
dsl_dir_destroy_sync(void *arg1, void *tag, cred_t *cr, dmu_tx_t *tx) |
789 | 462 |
{ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
463 |
dsl_dataset_t *ds = arg1; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
464 |
dsl_dir_t *dd = ds->ds_dir; |
2199 | 465 |
objset_t *mos = dd->dd_pool->dp_meta_objset; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
466 |
dsl_prop_setarg_t psa; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
467 |
uint64_t value = 0; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
468 |
uint64_t obj; |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
469 |
dd_used_t t; |
789 | 470 |
|
2199 | 471 |
ASSERT(RW_WRITE_HELD(&dd->dd_pool->dp_config_rwlock)); |
789 | 472 |
ASSERT(dd->dd_phys->dd_head_dataset_obj == 0); |
473 |
||
2199 | 474 |
/* Remove our reservation. */ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
475 |
dsl_prop_setarg_init_uint64(&psa, "reservation", |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
476 |
(ZPROP_SRC_NONE | ZPROP_SRC_LOCAL | ZPROP_SRC_RECEIVED), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
477 |
&value); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
478 |
psa.psa_effective_value = 0; /* predict default value */ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
479 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
480 |
dsl_dir_set_reservation_sync(ds, &psa, cr, tx); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
481 |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
482 |
ASSERT3U(dd->dd_phys->dd_used_bytes, ==, 0); |
789 | 483 |
ASSERT3U(dd->dd_phys->dd_reserved, ==, 0); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
484 |
for (t = 0; t < DD_USED_NUM; t++) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
485 |
ASSERT3U(dd->dd_phys->dd_used_breakdown[t], ==, 0); |
789 | 486 |
|
2199 | 487 |
VERIFY(0 == zap_destroy(mos, dd->dd_phys->dd_child_dir_zapobj, tx)); |
488 |
VERIFY(0 == zap_destroy(mos, dd->dd_phys->dd_props_zapobj, tx)); |
|
4543 | 489 |
VERIFY(0 == dsl_deleg_destroy(mos, dd->dd_phys->dd_deleg_zapobj, tx)); |
2199 | 490 |
VERIFY(0 == zap_remove(mos, |
491 |
dd->dd_parent->dd_phys->dd_child_dir_zapobj, dd->dd_myname, tx)); |
|
789 | 492 |
|
2199 | 493 |
obj = dd->dd_object; |
494 |
dsl_dir_close(dd, tag); |
|
495 |
VERIFY(0 == dmu_object_free(mos, obj, tx)); |
|
789 | 496 |
} |
497 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
498 |
boolean_t |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
499 |
dsl_dir_is_clone(dsl_dir_t *dd) |
789 | 500 |
{ |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
501 |
return (dd->dd_phys->dd_origin_obj && |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
502 |
(dd->dd_pool->dp_origin_snap == NULL || |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
503 |
dd->dd_phys->dd_origin_obj != |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
504 |
dd->dd_pool->dp_origin_snap->ds_object)); |
789 | 505 |
} |
506 |
||
507 |
void |
|
2885 | 508 |
dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv) |
789 | 509 |
{ |
510 |
mutex_enter(&dd->dd_lock); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
511 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USED, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
512 |
dd->dd_phys->dd_used_bytes); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
513 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_QUOTA, dd->dd_phys->dd_quota); |
2885 | 514 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_RESERVATION, |
515 |
dd->dd_phys->dd_reserved); |
|
516 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_COMPRESSRATIO, |
|
517 |
dd->dd_phys->dd_compressed_bytes == 0 ? 100 : |
|
518 |
(dd->dd_phys->dd_uncompressed_bytes * 100 / |
|
519 |
dd->dd_phys->dd_compressed_bytes)); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
520 |
if (dd->dd_phys->dd_flags & DD_FLAG_USED_BREAKDOWN) { |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
521 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDSNAP, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
522 |
dd->dd_phys->dd_used_breakdown[DD_USED_SNAP]); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
523 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDDS, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
524 |
dd->dd_phys->dd_used_breakdown[DD_USED_HEAD]); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
525 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDREFRESERV, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
526 |
dd->dd_phys->dd_used_breakdown[DD_USED_REFRSRV]); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
527 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USEDCHILD, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
528 |
dd->dd_phys->dd_used_breakdown[DD_USED_CHILD] + |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
529 |
dd->dd_phys->dd_used_breakdown[DD_USED_CHILD_RSRV]); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
530 |
} |
789 | 531 |
mutex_exit(&dd->dd_lock); |
532 |
||
5446 | 533 |
rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER); |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
6689
diff
changeset
|
534 |
if (dsl_dir_is_clone(dd)) { |
789 | 535 |
dsl_dataset_t *ds; |
2885 | 536 |
char buf[MAXNAMELEN]; |
789 | 537 |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6300
diff
changeset
|
538 |
VERIFY(0 == dsl_dataset_hold_obj(dd->dd_pool, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6300
diff
changeset
|
539 |
dd->dd_phys->dd_origin_obj, FTAG, &ds)); |
2885 | 540 |
dsl_dataset_name(ds, buf); |
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6300
diff
changeset
|
541 |
dsl_dataset_rele(ds, FTAG); |
2885 | 542 |
dsl_prop_nvlist_add_string(nv, ZFS_PROP_ORIGIN, buf); |
789 | 543 |
} |
5446 | 544 |
rw_exit(&dd->dd_pool->dp_config_rwlock); |
789 | 545 |
} |
546 |
||
547 |
void |
|
548 |
dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx) |
|
549 |
{ |
|
550 |
dsl_pool_t *dp = dd->dd_pool; |
|
551 |
||
552 |
ASSERT(dd->dd_phys); |
|
553 |
||
554 |
if (txg_list_add(&dp->dp_dirty_dirs, dd, tx->tx_txg) == 0) { |
|
555 |
/* up the hold count until we can be written out */ |
|
556 |
dmu_buf_add_ref(dd->dd_dbuf, dd); |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
static int64_t |
|
561 |
parent_delta(dsl_dir_t *dd, uint64_t used, int64_t delta) |
|
562 |
{ |
|
563 |
uint64_t old_accounted = MAX(used, dd->dd_phys->dd_reserved); |
|
564 |
uint64_t new_accounted = MAX(used + delta, dd->dd_phys->dd_reserved); |
|
565 |
return (new_accounted - old_accounted); |
|
566 |
} |
|
567 |
||
568 |
void |
|
569 |
dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx) |
|
570 |
{ |
|
571 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
572 |
||
573 |
dmu_buf_will_dirty(dd->dd_dbuf, tx); |
|
574 |
||
575 |
mutex_enter(&dd->dd_lock); |
|
576 |
ASSERT3U(dd->dd_tempreserved[tx->tx_txg&TXG_MASK], ==, 0); |
|
577 |
dprintf_dd(dd, "txg=%llu towrite=%lluK\n", tx->tx_txg, |
|
578 |
dd->dd_space_towrite[tx->tx_txg&TXG_MASK] / 1024); |
|
579 |
dd->dd_space_towrite[tx->tx_txg&TXG_MASK] = 0; |
|
580 |
mutex_exit(&dd->dd_lock); |
|
581 |
||
582 |
/* release the hold from dsl_dir_dirty */ |
|
1544 | 583 |
dmu_buf_rele(dd->dd_dbuf, dd); |
789 | 584 |
} |
585 |
||
586 |
static uint64_t |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
587 |
dsl_dir_space_towrite(dsl_dir_t *dd) |
789 | 588 |
{ |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
589 |
uint64_t space = 0; |
789 | 590 |
int i; |
591 |
||
592 |
ASSERT(MUTEX_HELD(&dd->dd_lock)); |
|
593 |
||
594 |
for (i = 0; i < TXG_SIZE; i++) { |
|
595 |
space += dd->dd_space_towrite[i&TXG_MASK]; |
|
596 |
ASSERT3U(dd->dd_space_towrite[i&TXG_MASK], >=, 0); |
|
597 |
} |
|
598 |
return (space); |
|
599 |
} |
|
600 |
||
601 |
/* |
|
602 |
* How much space would dd have available if ancestor had delta applied |
|
603 |
* to it? If ondiskonly is set, we're only interested in what's |
|
604 |
* on-disk, not estimated pending changes. |
|
605 |
*/ |
|
2885 | 606 |
uint64_t |
789 | 607 |
dsl_dir_space_available(dsl_dir_t *dd, |
608 |
dsl_dir_t *ancestor, int64_t delta, int ondiskonly) |
|
609 |
{ |
|
610 |
uint64_t parentspace, myspace, quota, used; |
|
611 |
||
612 |
/* |
|
613 |
* If there are no restrictions otherwise, assume we have |
|
614 |
* unlimited space available. |
|
615 |
*/ |
|
616 |
quota = UINT64_MAX; |
|
617 |
parentspace = UINT64_MAX; |
|
618 |
||
619 |
if (dd->dd_parent != NULL) { |
|
620 |
parentspace = dsl_dir_space_available(dd->dd_parent, |
|
621 |
ancestor, delta, ondiskonly); |
|
622 |
} |
|
623 |
||
624 |
mutex_enter(&dd->dd_lock); |
|
625 |
if (dd->dd_phys->dd_quota != 0) |
|
626 |
quota = dd->dd_phys->dd_quota; |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
627 |
used = dd->dd_phys->dd_used_bytes; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
628 |
if (!ondiskonly) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
629 |
used += dsl_dir_space_towrite(dd); |
789 | 630 |
|
631 |
if (dd->dd_parent == NULL) { |
|
2082 | 632 |
uint64_t poolsize = dsl_pool_adjustedsize(dd->dd_pool, FALSE); |
789 | 633 |
quota = MIN(quota, poolsize); |
634 |
} |
|
635 |
||
636 |
if (dd->dd_phys->dd_reserved > used && parentspace != UINT64_MAX) { |
|
637 |
/* |
|
638 |
* We have some space reserved, in addition to what our |
|
639 |
* parent gave us. |
|
640 |
*/ |
|
641 |
parentspace += dd->dd_phys->dd_reserved - used; |
|
642 |
} |
|
643 |
||
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
644 |
if (dd == ancestor) { |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
645 |
ASSERT(delta <= 0); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
646 |
ASSERT(used >= -delta); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
647 |
used += delta; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
648 |
if (parentspace != UINT64_MAX) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
649 |
parentspace -= delta; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
650 |
} |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
651 |
|
789 | 652 |
if (used > quota) { |
653 |
/* over quota */ |
|
654 |
myspace = 0; |
|
2082 | 655 |
|
656 |
/* |
|
657 |
* While it's OK to be a little over quota, if |
|
658 |
* we think we are using more space than there |
|
659 |
* is in the pool (which is already 1.6% more than |
|
660 |
* dsl_pool_adjustedsize()), something is very |
|
661 |
* wrong. |
|
662 |
*/ |
|
10974
32d689ba6466
6897958 ASSERT in metaslab_class_space_update() with 8+ exabyte pool
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10922
diff
changeset
|
663 |
ASSERT3U(used, <=, spa_get_dspace(dd->dd_pool->dp_spa)); |
789 | 664 |
} else { |
665 |
/* |
|
2082 | 666 |
* the lesser of the space provided by our parent and |
667 |
* the space left in our quota |
|
789 | 668 |
*/ |
669 |
myspace = MIN(parentspace, quota - used); |
|
670 |
} |
|
671 |
||
672 |
mutex_exit(&dd->dd_lock); |
|
673 |
||
674 |
return (myspace); |
|
675 |
} |
|
676 |
||
677 |
struct tempreserve { |
|
678 |
list_node_t tr_node; |
|
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
679 |
dsl_pool_t *tr_dp; |
789 | 680 |
dsl_dir_t *tr_ds; |
681 |
uint64_t tr_size; |
|
682 |
}; |
|
683 |
||
684 |
static int |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
685 |
dsl_dir_tempreserve_impl(dsl_dir_t *dd, uint64_t asize, boolean_t netfree, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
686 |
boolean_t ignorequota, boolean_t checkrefquota, list_t *tr_list, |
6300 | 687 |
dmu_tx_t *tx, boolean_t first) |
789 | 688 |
{ |
689 |
uint64_t txg = tx->tx_txg; |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
690 |
uint64_t est_inflight, used_on_disk, quota, parent_rsrv; |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
691 |
uint64_t deferred = 0; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
692 |
struct tempreserve *tr; |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
693 |
int retval = EDQUOT; |
789 | 694 |
int txgidx = txg & TXG_MASK; |
695 |
int i; |
|
5831
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5481
diff
changeset
|
696 |
uint64_t ref_rsrv = 0; |
789 | 697 |
|
698 |
ASSERT3U(txg, !=, 0); |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
699 |
ASSERT3S(asize, >, 0); |
789 | 700 |
|
701 |
mutex_enter(&dd->dd_lock); |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
702 |
|
789 | 703 |
/* |
704 |
* Check against the dsl_dir's quota. We don't add in the delta |
|
705 |
* when checking for over-quota because they get one free hit. |
|
706 |
*/ |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
707 |
est_inflight = dsl_dir_space_towrite(dd); |
789 | 708 |
for (i = 0; i < TXG_SIZE; i++) |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
709 |
est_inflight += dd->dd_tempreserved[i]; |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
710 |
used_on_disk = dd->dd_phys->dd_used_bytes; |
789 | 711 |
|
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4577
diff
changeset
|
712 |
/* |
6300 | 713 |
* On the first iteration, fetch the dataset's used-on-disk and |
714 |
* refreservation values. Also, if checkrefquota is set, test if |
|
715 |
* allocating this space would exceed the dataset's refquota. |
|
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4577
diff
changeset
|
716 |
*/ |
6300 | 717 |
if (first && tx->tx_objset) { |
5392 | 718 |
int error; |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10040
diff
changeset
|
719 |
dsl_dataset_t *ds = tx->tx_objset->os_dsl_dataset; |
5392 | 720 |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
721 |
error = dsl_dataset_check_quota(ds, checkrefquota, |
5831
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5481
diff
changeset
|
722 |
asize, est_inflight, &used_on_disk, &ref_rsrv); |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
723 |
if (error) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
724 |
mutex_exit(&dd->dd_lock); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
725 |
return (error); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
726 |
} |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
727 |
} |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
728 |
|
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
729 |
/* |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
730 |
* If this transaction will result in a net free of space, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
731 |
* we want to let it through. |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
732 |
*/ |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
733 |
if (ignorequota || netfree || dd->dd_phys->dd_quota == 0) |
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4577
diff
changeset
|
734 |
quota = UINT64_MAX; |
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4577
diff
changeset
|
735 |
else |
789 | 736 |
quota = dd->dd_phys->dd_quota; |
737 |
||
738 |
/* |
|
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
739 |
* Adjust the quota against the actual pool size at the root |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
740 |
* minus any outstanding deferred frees. |
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4577
diff
changeset
|
741 |
* To ensure that it's possible to remove files from a full |
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4577
diff
changeset
|
742 |
* pool without inducing transient overcommits, we throttle |
789 | 743 |
* netfree transactions against a quota that is slightly larger, |
744 |
* but still within the pool's allocation slop. In cases where |
|
745 |
* we're very close to full, this will allow a steady trickle of |
|
746 |
* removes to get through. |
|
747 |
*/ |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4709
diff
changeset
|
748 |
if (dd->dd_parent == NULL) { |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
749 |
spa_t *spa = dd->dd_pool->dp_spa; |
789 | 750 |
uint64_t poolsize = dsl_pool_adjustedsize(dd->dd_pool, netfree); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10921
diff
changeset
|
751 |
deferred = metaslab_class_get_deferred(spa_normal_class(spa)); |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
752 |
if (poolsize - deferred < quota) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
753 |
quota = poolsize - deferred; |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
754 |
retval = ENOSPC; |
789 | 755 |
} |
756 |
} |
|
757 |
||
758 |
/* |
|
759 |
* If they are requesting more space, and our current estimate |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
760 |
* is over quota, they get to try again unless the actual |
1544 | 761 |
* on-disk is over quota and there are no pending changes (which |
762 |
* may free up space for us). |
|
789 | 763 |
*/ |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
764 |
if (used_on_disk + est_inflight >= quota) { |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
765 |
if (est_inflight > 0 || used_on_disk < quota || |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
766 |
(retval == ENOSPC && used_on_disk < quota + deferred)) |
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
767 |
retval = ERESTART; |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
768 |
dprintf_dd(dd, "failing: used=%lluK inflight = %lluK " |
789 | 769 |
"quota=%lluK tr=%lluK err=%d\n", |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
770 |
used_on_disk>>10, est_inflight>>10, |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
771 |
quota>>10, asize>>10, retval); |
789 | 772 |
mutex_exit(&dd->dd_lock); |
10921
8aac17999e4d
PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents:
10373
diff
changeset
|
773 |
return (retval); |
789 | 774 |
} |
775 |
||
776 |
/* We need to up our estimated delta before dropping dd_lock */ |
|
777 |
dd->dd_tempreserved[txgidx] += asize; |
|
778 |
||
5831
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5481
diff
changeset
|
779 |
parent_rsrv = parent_delta(dd, used_on_disk + est_inflight, |
48655d6b290b
6630761 In sub-filesystem, available space is less than refreservation space
ck153898
parents:
5481
diff
changeset
|
780 |
asize - ref_rsrv); |
789 | 781 |
mutex_exit(&dd->dd_lock); |
782 |
||
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
783 |
tr = kmem_zalloc(sizeof (struct tempreserve), KM_SLEEP); |
789 | 784 |
tr->tr_ds = dd; |
785 |
tr->tr_size = asize; |
|
786 |
list_insert_tail(tr_list, tr); |
|
787 |
||
788 |
/* see if it's OK with our parent */ |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4709
diff
changeset
|
789 |
if (dd->dd_parent && parent_rsrv) { |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4709
diff
changeset
|
790 |
boolean_t ismos = (dd->dd_phys->dd_head_dataset_obj == 0); |
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4709
diff
changeset
|
791 |
|
789 | 792 |
return (dsl_dir_tempreserve_impl(dd->dd_parent, |
6300 | 793 |
parent_rsrv, netfree, ismos, TRUE, tr_list, tx, FALSE)); |
789 | 794 |
} else { |
795 |
return (0); |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
/* |
|
800 |
* Reserve space in this dsl_dir, to be used in this tx's txg. |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
801 |
* After the space has been dirtied (and dsl_dir_willuse_space() |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
802 |
* has been called), the reservation should be canceled, using |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
803 |
* dsl_dir_tempreserve_clear(). |
789 | 804 |
*/ |
805 |
int |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
806 |
dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t lsize, uint64_t asize, |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
807 |
uint64_t fsize, uint64_t usize, void **tr_cookiep, dmu_tx_t *tx) |
789 | 808 |
{ |
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
809 |
int err; |
789 | 810 |
list_t *tr_list; |
811 |
||
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
812 |
if (asize == 0) { |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
813 |
*tr_cookiep = NULL; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
814 |
return (0); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
815 |
} |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
816 |
|
789 | 817 |
tr_list = kmem_alloc(sizeof (list_t), KM_SLEEP); |
818 |
list_create(tr_list, sizeof (struct tempreserve), |
|
819 |
offsetof(struct tempreserve, tr_node)); |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
820 |
ASSERT3S(asize, >, 0); |
1544 | 821 |
ASSERT3S(fsize, >=, 0); |
789 | 822 |
|
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
823 |
err = arc_tempreserve_space(lsize, tx->tx_txg); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
824 |
if (err == 0) { |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
825 |
struct tempreserve *tr; |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
826 |
|
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
827 |
tr = kmem_zalloc(sizeof (struct tempreserve), KM_SLEEP); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
828 |
tr->tr_size = lsize; |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
829 |
list_insert_tail(tr_list, tr); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
830 |
|
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
831 |
err = dsl_pool_tempreserve_space(dd->dd_pool, asize, tx); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
832 |
} else { |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
833 |
if (err == EAGAIN) { |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
834 |
txg_delay(dd->dd_pool, tx->tx_txg, 1); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
835 |
err = ERESTART; |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
836 |
} |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
837 |
dsl_pool_memory_pressure(dd->dd_pool); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
838 |
} |
789 | 839 |
|
840 |
if (err == 0) { |
|
841 |
struct tempreserve *tr; |
|
842 |
||
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
843 |
tr = kmem_zalloc(sizeof (struct tempreserve), KM_SLEEP); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
844 |
tr->tr_dp = dd->dd_pool; |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
845 |
tr->tr_size = asize; |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
846 |
list_insert_tail(tr_list, tr); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
847 |
|
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
848 |
err = dsl_dir_tempreserve_impl(dd, asize, fsize >= asize, |
6300 | 849 |
FALSE, asize > usize, tr_list, tx, TRUE); |
789 | 850 |
} |
851 |
||
852 |
if (err) |
|
853 |
dsl_dir_tempreserve_clear(tr_list, tx); |
|
854 |
else |
|
855 |
*tr_cookiep = tr_list; |
|
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
856 |
|
789 | 857 |
return (err); |
858 |
} |
|
859 |
||
860 |
/* |
|
861 |
* Clear a temporary reservation that we previously made with |
|
862 |
* dsl_dir_tempreserve_space(). |
|
863 |
*/ |
|
864 |
void |
|
865 |
dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx) |
|
866 |
{ |
|
867 |
int txgidx = tx->tx_txg & TXG_MASK; |
|
868 |
list_t *tr_list = tr_cookie; |
|
869 |
struct tempreserve *tr; |
|
870 |
||
871 |
ASSERT3U(tx->tx_txg, !=, 0); |
|
872 |
||
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
873 |
if (tr_cookie == NULL) |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
874 |
return; |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
875 |
|
789 | 876 |
while (tr = list_head(tr_list)) { |
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
877 |
if (tr->tr_dp) { |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
878 |
dsl_pool_tempreserve_clear(tr->tr_dp, tr->tr_size, tx); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
879 |
} else if (tr->tr_ds) { |
789 | 880 |
mutex_enter(&tr->tr_ds->dd_lock); |
881 |
ASSERT3U(tr->tr_ds->dd_tempreserved[txgidx], >=, |
|
882 |
tr->tr_size); |
|
883 |
tr->tr_ds->dd_tempreserved[txgidx] -= tr->tr_size; |
|
884 |
mutex_exit(&tr->tr_ds->dd_lock); |
|
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
885 |
} else { |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
886 |
arc_tempreserve_clear(tr->tr_size); |
789 | 887 |
} |
888 |
list_remove(tr_list, tr); |
|
889 |
kmem_free(tr, sizeof (struct tempreserve)); |
|
890 |
} |
|
891 |
||
892 |
kmem_free(tr_list, sizeof (list_t)); |
|
893 |
} |
|
894 |
||
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
895 |
static void |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
896 |
dsl_dir_willuse_space_impl(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx) |
789 | 897 |
{ |
898 |
int64_t parent_space; |
|
899 |
uint64_t est_used; |
|
900 |
||
901 |
mutex_enter(&dd->dd_lock); |
|
902 |
if (space > 0) |
|
903 |
dd->dd_space_towrite[tx->tx_txg & TXG_MASK] += space; |
|
904 |
||
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
905 |
est_used = dsl_dir_space_towrite(dd) + dd->dd_phys->dd_used_bytes; |
789 | 906 |
parent_space = parent_delta(dd, est_used, space); |
907 |
mutex_exit(&dd->dd_lock); |
|
908 |
||
909 |
/* Make sure that we clean up dd_space_to* */ |
|
910 |
dsl_dir_dirty(dd, tx); |
|
911 |
||
912 |
/* XXX this is potentially expensive and unnecessary... */ |
|
913 |
if (parent_space && dd->dd_parent) |
|
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
914 |
dsl_dir_willuse_space_impl(dd->dd_parent, parent_space, tx); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
915 |
} |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
916 |
|
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
917 |
/* |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
918 |
* Call in open context when we think we're going to write/free space, |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
919 |
* eg. when dirtying data. Be conservative (ie. OK to write less than |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
920 |
* this or free more than this, but don't write more or free less). |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
921 |
*/ |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
922 |
void |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
923 |
dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx) |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
924 |
{ |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
925 |
dsl_pool_willuse_space(dd->dd_pool, space, tx); |
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5831
diff
changeset
|
926 |
dsl_dir_willuse_space_impl(dd, space, tx); |
789 | 927 |
} |
928 |
||
929 |
/* call from syncing context when we actually write/free space for this dd */ |
|
930 |
void |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
931 |
dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type, |
789 | 932 |
int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx) |
933 |
{ |
|
934 |
int64_t accounted_delta; |
|
7595
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
935 |
boolean_t needlock = !MUTEX_HELD(&dd->dd_lock); |
789 | 936 |
|
937 |
ASSERT(dmu_tx_is_syncing(tx)); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
938 |
ASSERT(type < DD_USED_NUM); |
789 | 939 |
|
940 |
dsl_dir_dirty(dd, tx); |
|
941 |
||
7595
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
942 |
if (needlock) |
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
943 |
mutex_enter(&dd->dd_lock); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
944 |
accounted_delta = parent_delta(dd, dd->dd_phys->dd_used_bytes, used); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
945 |
ASSERT(used >= 0 || dd->dd_phys->dd_used_bytes >= -used); |
789 | 946 |
ASSERT(compressed >= 0 || |
947 |
dd->dd_phys->dd_compressed_bytes >= -compressed); |
|
948 |
ASSERT(uncompressed >= 0 || |
|
949 |
dd->dd_phys->dd_uncompressed_bytes >= -uncompressed); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
950 |
dd->dd_phys->dd_used_bytes += used; |
789 | 951 |
dd->dd_phys->dd_uncompressed_bytes += uncompressed; |
952 |
dd->dd_phys->dd_compressed_bytes += compressed; |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
953 |
|
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
954 |
if (dd->dd_phys->dd_flags & DD_FLAG_USED_BREAKDOWN) { |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
955 |
ASSERT(used > 0 || |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
956 |
dd->dd_phys->dd_used_breakdown[type] >= -used); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
957 |
dd->dd_phys->dd_used_breakdown[type] += used; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
958 |
#ifdef DEBUG |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
959 |
dd_used_t t; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
960 |
uint64_t u = 0; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
961 |
for (t = 0; t < DD_USED_NUM; t++) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
962 |
u += dd->dd_phys->dd_used_breakdown[t]; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
963 |
ASSERT3U(u, ==, dd->dd_phys->dd_used_bytes); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
964 |
#endif |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
965 |
} |
7595
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
966 |
if (needlock) |
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
967 |
mutex_exit(&dd->dd_lock); |
789 | 968 |
|
969 |
if (dd->dd_parent != NULL) { |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
970 |
dsl_dir_diduse_space(dd->dd_parent, DD_USED_CHILD, |
789 | 971 |
accounted_delta, compressed, uncompressed, tx); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
972 |
dsl_dir_transfer_space(dd->dd_parent, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
973 |
used - accounted_delta, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
974 |
DD_USED_CHILD_RSRV, DD_USED_CHILD, tx); |
789 | 975 |
} |
976 |
} |
|
977 |
||
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
978 |
void |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
979 |
dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
980 |
dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
981 |
{ |
7595
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
982 |
boolean_t needlock = !MUTEX_HELD(&dd->dd_lock); |
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
983 |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
984 |
ASSERT(dmu_tx_is_syncing(tx)); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
985 |
ASSERT(oldtype < DD_USED_NUM); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
986 |
ASSERT(newtype < DD_USED_NUM); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
987 |
|
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
988 |
if (delta == 0 || !(dd->dd_phys->dd_flags & DD_FLAG_USED_BREAKDOWN)) |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
989 |
return; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
990 |
|
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
991 |
dsl_dir_dirty(dd, tx); |
7595
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
992 |
if (needlock) |
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
993 |
mutex_enter(&dd->dd_lock); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
994 |
ASSERT(delta > 0 ? |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
995 |
dd->dd_phys->dd_used_breakdown[oldtype] >= delta : |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
996 |
dd->dd_phys->dd_used_breakdown[newtype] >= -delta); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
997 |
ASSERT(dd->dd_phys->dd_used_bytes >= ABS(delta)); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
998 |
dd->dd_phys->dd_used_breakdown[oldtype] -= delta; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
999 |
dd->dd_phys->dd_used_breakdown[newtype] += delta; |
7595
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
1000 |
if (needlock) |
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
1001 |
mutex_exit(&dd->dd_lock); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1002 |
} |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1003 |
|
789 | 1004 |
static int |
2199 | 1005 |
dsl_dir_set_quota_check(void *arg1, void *arg2, dmu_tx_t *tx) |
789 | 1006 |
{ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1007 |
dsl_dataset_t *ds = arg1; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1008 |
dsl_dir_t *dd = ds->ds_dir; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1009 |
dsl_prop_setarg_t *psa = arg2; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1010 |
int err; |
2199 | 1011 |
uint64_t towrite; |
1012 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1013 |
if ((err = dsl_prop_predict_sync(ds->ds_dir, psa)) != 0) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1014 |
return (err); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1015 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1016 |
if (psa->psa_effective_value == 0) |
2199 | 1017 |
return (0); |
1018 |
||
1019 |
mutex_enter(&dd->dd_lock); |
|
1020 |
/* |
|
1021 |
* If we are doing the preliminary check in open context, and |
|
1022 |
* there are pending changes, then don't fail it, since the |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1023 |
* pending changes could under-estimate the amount of space to be |
2199 | 1024 |
* freed up. |
1025 |
*/ |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1026 |
towrite = dsl_dir_space_towrite(dd); |
2199 | 1027 |
if ((dmu_tx_is_syncing(tx) || towrite == 0) && |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1028 |
(psa->psa_effective_value < dd->dd_phys->dd_reserved || |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1029 |
psa->psa_effective_value < dd->dd_phys->dd_used_bytes + towrite)) { |
2199 | 1030 |
err = ENOSPC; |
1031 |
} |
|
1032 |
mutex_exit(&dd->dd_lock); |
|
1033 |
return (err); |
|
1034 |
} |
|
1035 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1036 |
extern void dsl_prop_set_sync(void *, void *, cred_t *, dmu_tx_t *); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1037 |
|
4543 | 1038 |
/* ARGSUSED */ |
2199 | 1039 |
static void |
4543 | 1040 |
dsl_dir_set_quota_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2199 | 1041 |
{ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1042 |
dsl_dataset_t *ds = arg1; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1043 |
dsl_dir_t *dd = ds->ds_dir; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1044 |
dsl_prop_setarg_t *psa = arg2; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1045 |
uint64_t effective_value = psa->psa_effective_value; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1046 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1047 |
dsl_prop_set_sync(ds, psa, cr, tx); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1048 |
DSL_PROP_CHECK_PREDICTION(dd, psa); |
789 | 1049 |
|
1050 |
dmu_buf_will_dirty(dd->dd_dbuf, tx); |
|
1051 |
||
1052 |
mutex_enter(&dd->dd_lock); |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1053 |
dd->dd_phys->dd_quota = effective_value; |
789 | 1054 |
mutex_exit(&dd->dd_lock); |
4543 | 1055 |
|
1056 |
spa_history_internal_log(LOG_DS_QUOTA, dd->dd_pool->dp_spa, |
|
1057 |
tx, cr, "%lld dataset = %llu ", |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1058 |
(longlong_t)effective_value, dd->dd_phys->dd_head_dataset_obj); |
789 | 1059 |
} |
1060 |
||
1061 |
int |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1062 |
dsl_dir_set_quota(const char *ddname, zprop_source_t source, uint64_t quota) |
789 | 1063 |
{ |
1064 |
dsl_dir_t *dd; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1065 |
dsl_dataset_t *ds; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1066 |
dsl_prop_setarg_t psa; |
789 | 1067 |
int err; |
1068 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1069 |
dsl_prop_setarg_init_uint64(&psa, "quota", source, "a); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1070 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1071 |
err = dsl_dataset_hold(ddname, FTAG, &ds); |
1544 | 1072 |
if (err) |
1073 |
return (err); |
|
789 | 1074 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1075 |
err = dsl_dir_open(ddname, FTAG, &dd, NULL); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1076 |
if (err) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1077 |
dsl_dataset_rele(ds, FTAG); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1078 |
return (err); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1079 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1080 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1081 |
ASSERT(ds->ds_dir == dd); |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
1082 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1083 |
/* |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1084 |
* If someone removes a file, then tries to set the quota, we want to |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1085 |
* make sure the file freeing takes effect. |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1086 |
*/ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1087 |
txg_wait_open(dd->dd_pool, 0); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1088 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1089 |
err = dsl_sync_task_do(dd->dd_pool, dsl_dir_set_quota_check, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1090 |
dsl_dir_set_quota_sync, ds, &psa, 0); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1091 |
|
789 | 1092 |
dsl_dir_close(dd, FTAG); |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1093 |
dsl_dataset_rele(ds, FTAG); |
789 | 1094 |
return (err); |
1095 |
} |
|
1096 |
||
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1097 |
int |
2199 | 1098 |
dsl_dir_set_reservation_check(void *arg1, void *arg2, dmu_tx_t *tx) |
789 | 1099 |
{ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1100 |
dsl_dataset_t *ds = arg1; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1101 |
dsl_dir_t *dd = ds->ds_dir; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1102 |
dsl_prop_setarg_t *psa = arg2; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1103 |
uint64_t effective_value; |
789 | 1104 |
uint64_t used, avail; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1105 |
int err; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1106 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1107 |
if ((err = dsl_prop_predict_sync(ds->ds_dir, psa)) != 0) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1108 |
return (err); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1109 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1110 |
effective_value = psa->psa_effective_value; |
789 | 1111 |
|
2199 | 1112 |
/* |
1113 |
* If we are doing the preliminary check in open context, the |
|
1114 |
* space estimates may be inaccurate. |
|
1115 |
*/ |
|
1116 |
if (!dmu_tx_is_syncing(tx)) |
|
1117 |
return (0); |
|
1118 |
||
789 | 1119 |
mutex_enter(&dd->dd_lock); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1120 |
used = dd->dd_phys->dd_used_bytes; |
789 | 1121 |
mutex_exit(&dd->dd_lock); |
1122 |
||
1123 |
if (dd->dd_parent) { |
|
1124 |
avail = dsl_dir_space_available(dd->dd_parent, |
|
1125 |
NULL, 0, FALSE); |
|
1126 |
} else { |
|
1127 |
avail = dsl_pool_adjustedsize(dd->dd_pool, B_FALSE) - used; |
|
1128 |
} |
|
1129 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1130 |
if (MAX(used, effective_value) > MAX(used, dd->dd_phys->dd_reserved)) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1131 |
uint64_t delta = MAX(used, effective_value) - |
8525
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1132 |
MAX(used, dd->dd_phys->dd_reserved); |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1133 |
|
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1134 |
if (delta > avail) |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1135 |
return (ENOSPC); |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1136 |
if (dd->dd_phys->dd_quota > 0 && |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1137 |
effective_value > dd->dd_phys->dd_quota) |
8525
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1138 |
return (ENOSPC); |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1139 |
} |
e0e0e525d0f8
6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
7595
diff
changeset
|
1140 |
|
2199 | 1141 |
return (0); |
1142 |
} |
|
1143 |
||
4543 | 1144 |
/* ARGSUSED */ |
2199 | 1145 |
static void |
4543 | 1146 |
dsl_dir_set_reservation_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2199 | 1147 |
{ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1148 |
dsl_dataset_t *ds = arg1; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1149 |
dsl_dir_t *dd = ds->ds_dir; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1150 |
dsl_prop_setarg_t *psa = arg2; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1151 |
uint64_t effective_value = psa->psa_effective_value; |
2199 | 1152 |
uint64_t used; |
1153 |
int64_t delta; |
|
1154 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1155 |
dsl_prop_set_sync(ds, psa, cr, tx); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1156 |
DSL_PROP_CHECK_PREDICTION(dd, psa); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1157 |
|
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1158 |
dmu_buf_will_dirty(dd->dd_dbuf, tx); |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1159 |
|
2199 | 1160 |
mutex_enter(&dd->dd_lock); |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1161 |
used = dd->dd_phys->dd_used_bytes; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1162 |
delta = MAX(used, effective_value) - |
2199 | 1163 |
MAX(used, dd->dd_phys->dd_reserved); |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1164 |
dd->dd_phys->dd_reserved = effective_value; |
789 | 1165 |
|
1166 |
if (dd->dd_parent != NULL) { |
|
1167 |
/* Roll up this additional usage into our ancestors */ |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1168 |
dsl_dir_diduse_space(dd->dd_parent, DD_USED_CHILD_RSRV, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1169 |
delta, 0, 0, tx); |
789 | 1170 |
} |
7595
2ff5700c7efc
6747355 finish closing race condition when setting refreservation
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7525
diff
changeset
|
1171 |
mutex_exit(&dd->dd_lock); |
4543 | 1172 |
|
1173 |
spa_history_internal_log(LOG_DS_RESERVATION, dd->dd_pool->dp_spa, |
|
1174 |
tx, cr, "%lld dataset = %llu", |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1175 |
(longlong_t)effective_value, dd->dd_phys->dd_head_dataset_obj); |
789 | 1176 |
} |
1177 |
||
1178 |
int |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1179 |
dsl_dir_set_reservation(const char *ddname, zprop_source_t source, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1180 |
uint64_t reservation) |
789 | 1181 |
{ |
1182 |
dsl_dir_t *dd; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1183 |
dsl_dataset_t *ds; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1184 |
dsl_prop_setarg_t psa; |
789 | 1185 |
int err; |
1186 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1187 |
dsl_prop_setarg_init_uint64(&psa, "reservation", source, &reservation); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1188 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1189 |
err = dsl_dataset_hold(ddname, FTAG, &ds); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1190 |
if (err) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1191 |
return (err); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1192 |
|
1544 | 1193 |
err = dsl_dir_open(ddname, FTAG, &dd, NULL); |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1194 |
if (err) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1195 |
dsl_dataset_rele(ds, FTAG); |
1544 | 1196 |
return (err); |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1197 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1198 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1199 |
ASSERT(ds->ds_dir == dd); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1200 |
|
2199 | 1201 |
err = dsl_sync_task_do(dd->dd_pool, dsl_dir_set_reservation_check, |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1202 |
dsl_dir_set_reservation_sync, ds, &psa, 0); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1203 |
|
789 | 1204 |
dsl_dir_close(dd, FTAG); |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10974
diff
changeset
|
1205 |
dsl_dataset_rele(ds, FTAG); |
789 | 1206 |
return (err); |
1207 |
} |
|
1208 |
||
1209 |
static dsl_dir_t * |
|
1210 |
closest_common_ancestor(dsl_dir_t *ds1, dsl_dir_t *ds2) |
|
1211 |
{ |
|
1212 |
for (; ds1; ds1 = ds1->dd_parent) { |
|
1213 |
dsl_dir_t *dd; |
|
1214 |
for (dd = ds2; dd; dd = dd->dd_parent) { |
|
1215 |
if (ds1 == dd) |
|
1216 |
return (dd); |
|
1217 |
} |
|
1218 |
} |
|
1219 |
return (NULL); |
|
1220 |
} |
|
1221 |
||
1222 |
/* |
|
1223 |
* If delta is applied to dd, how much of that delta would be applied to |
|
1224 |
* ancestor? Syncing context only. |
|
1225 |
*/ |
|
1226 |
static int64_t |
|
1227 |
would_change(dsl_dir_t *dd, int64_t delta, dsl_dir_t *ancestor) |
|
1228 |
{ |
|
1229 |
if (dd == ancestor) |
|
1230 |
return (delta); |
|
1231 |
||
1232 |
mutex_enter(&dd->dd_lock); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1233 |
delta = parent_delta(dd, dd->dd_phys->dd_used_bytes, delta); |
789 | 1234 |
mutex_exit(&dd->dd_lock); |
1235 |
return (would_change(dd->dd_parent, delta, ancestor)); |
|
1236 |
} |
|
1237 |
||
2199 | 1238 |
struct renamearg { |
1239 |
dsl_dir_t *newparent; |
|
1240 |
const char *mynewname; |
|
1241 |
}; |
|
1242 |
||
4543 | 1243 |
/*ARGSUSED*/ |
2199 | 1244 |
static int |
1245 |
dsl_dir_rename_check(void *arg1, void *arg2, dmu_tx_t *tx) |
|
789 | 1246 |
{ |
2199 | 1247 |
dsl_dir_t *dd = arg1; |
1248 |
struct renamearg *ra = arg2; |
|
789 | 1249 |
dsl_pool_t *dp = dd->dd_pool; |
1250 |
objset_t *mos = dp->dp_meta_objset; |
|
2199 | 1251 |
int err; |
1252 |
uint64_t val; |
|
1253 |
||
11823
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1254 |
/* |
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1255 |
* There should only be one reference, from dmu_objset_rename(). |
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1256 |
* Fleeting holds are also possible (eg, from "zfs list" getting |
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1257 |
* stats), but any that are present in open context will likely |
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1258 |
* be gone by syncing context, so only fail from syncing |
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1259 |
* context. |
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1260 |
*/ |
c756cd80d532
6930022 zfs rename of non-shapshot is slower than necessary
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
11022
diff
changeset
|
1261 |
if (dmu_tx_is_syncing(tx) && dmu_buf_refcount(dd->dd_dbuf) > 1) |
2199 | 1262 |
return (EBUSY); |
789 | 1263 |
|
2199 | 1264 |
/* check for existing name */ |
1265 |
err = zap_lookup(mos, ra->newparent->dd_phys->dd_child_dir_zapobj, |
|
1266 |
ra->mynewname, 8, 1, &val); |
|
1267 |
if (err == 0) |
|
1268 |
return (EEXIST); |
|
1269 |
if (err != ENOENT) |
|
1544 | 1270 |
return (err); |
789 | 1271 |
|
2199 | 1272 |
if (ra->newparent != dd->dd_parent) { |
2082 | 1273 |
/* is there enough space? */ |
1274 |
uint64_t myspace = |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1275 |
MAX(dd->dd_phys->dd_used_bytes, dd->dd_phys->dd_reserved); |
789 | 1276 |
|
2199 | 1277 |
/* no rename into our descendant */ |
1278 |
if (closest_common_ancestor(dd, ra->newparent) == dd) |
|
789 | 1279 |
return (EINVAL); |
2199 | 1280 |
|
1281 |
if (err = dsl_dir_transfer_possible(dd->dd_parent, |
|
1282 |
ra->newparent, myspace)) |
|
1283 |
return (err); |
|
1284 |
} |
|
1285 |
||
1286 |
return (0); |
|
1287 |
} |
|
789 | 1288 |
|
2199 | 1289 |
static void |
4543 | 1290 |
dsl_dir_rename_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
2199 | 1291 |
{ |
1292 |
dsl_dir_t *dd = arg1; |
|
1293 |
struct renamearg *ra = arg2; |
|
1294 |
dsl_pool_t *dp = dd->dd_pool; |
|
1295 |
objset_t *mos = dp->dp_meta_objset; |
|
1296 |
int err; |
|
789 | 1297 |
|
2199 | 1298 |
ASSERT(dmu_buf_refcount(dd->dd_dbuf) <= 2); |
1299 |
||
1300 |
if (ra->newparent != dd->dd_parent) { |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1301 |
dsl_dir_diduse_space(dd->dd_parent, DD_USED_CHILD, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1302 |
-dd->dd_phys->dd_used_bytes, |
789 | 1303 |
-dd->dd_phys->dd_compressed_bytes, |
1304 |
-dd->dd_phys->dd_uncompressed_bytes, tx); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1305 |
dsl_dir_diduse_space(ra->newparent, DD_USED_CHILD, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1306 |
dd->dd_phys->dd_used_bytes, |
789 | 1307 |
dd->dd_phys->dd_compressed_bytes, |
1308 |
dd->dd_phys->dd_uncompressed_bytes, tx); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1309 |
|
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1310 |
if (dd->dd_phys->dd_reserved > dd->dd_phys->dd_used_bytes) { |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1311 |
uint64_t unused_rsrv = dd->dd_phys->dd_reserved - |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1312 |
dd->dd_phys->dd_used_bytes; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1313 |
|
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1314 |
dsl_dir_diduse_space(dd->dd_parent, DD_USED_CHILD_RSRV, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1315 |
-unused_rsrv, 0, 0, tx); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1316 |
dsl_dir_diduse_space(ra->newparent, DD_USED_CHILD_RSRV, |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1317 |
unused_rsrv, 0, 0, tx); |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7046
diff
changeset
|
1318 |
} |
789 | 1319 |
} |
1320 |
||
1321 |
dmu_buf_will_dirty(dd->dd_dbuf, tx); |
|
1322 |
||
1323 |
/* remove from old parent zapobj */ |
|
1324 |
err = zap_remove(mos, dd->dd_parent->dd_phys->dd_child_dir_zapobj, |
|
1325 |
dd->dd_myname, tx); |
|
1326 |
ASSERT3U(err, ==, 0); |
|
1327 |
||
2199 | 1328 |
(void) strcpy(dd->dd_myname, ra->mynewname); |
789 | 1329 |
dsl_dir_close(dd->dd_parent, dd); |
2199 | 1330 |
dd->dd_phys->dd_parent_obj = ra->newparent->dd_object; |
1544 | 1331 |
VERIFY(0 == dsl_dir_open_obj(dd->dd_pool, |
2199 | 1332 |
ra->newparent->dd_object, NULL, dd, &dd->dd_parent)); |
789 | 1333 |
|
1334 |
/* add to new parent zapobj */ |
|
2199 | 1335 |
err = zap_add(mos, ra->newparent->dd_phys->dd_child_dir_zapobj, |
789 | 1336 |
dd->dd_myname, 8, 1, &dd->dd_object, tx); |
1337 |
ASSERT3U(err, ==, 0); |
|
4543 | 1338 |
|
1339 |
spa_history_internal_log(LOG_DS_RENAME, dd->dd_pool->dp_spa, |
|
1340 |
tx, cr, "dataset = %llu", dd->dd_phys->dd_head_dataset_obj); |
|
2199 | 1341 |
} |
789 | 1342 |
|
2199 | 1343 |
int |
1344 |
dsl_dir_rename(dsl_dir_t *dd, const char *newname) |
|
1345 |
{ |
|
1346 |
struct renamearg ra; |
|
1347 |
int err; |
|
1348 |
||
1349 |
/* new parent should exist */ |
|
1350 |
err = dsl_dir_open(newname, FTAG, &ra.newparent, &ra.mynewname); |
|
1351 |
if (err) |
|
1352 |
return (err); |
|
1353 |
||
1354 |
/* can't rename to different pool */ |
|
1355 |
if (dd->dd_pool != ra.newparent->dd_pool) { |
|
1356 |
err = ENXIO; |
|
1357 |
goto out; |
|
1358 |
} |
|
1359 |
||
1360 |
/* new name should not already exist */ |
|
1361 |
if (ra.mynewname == NULL) { |
|
1362 |
err = EEXIST; |
|
1363 |
goto out; |
|
1364 |
} |
|
1365 |
||
1366 |
err = dsl_sync_task_do(dd->dd_pool, |
|
1367 |
dsl_dir_rename_check, dsl_dir_rename_sync, dd, &ra, 3); |
|
1368 |
||
1369 |
out: |
|
1370 |
dsl_dir_close(ra.newparent, FTAG); |
|
1371 |
return (err); |
|
789 | 1372 |
} |
2082 | 1373 |
|
1374 |
int |
|
1375 |
dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, uint64_t space) |
|
1376 |
{ |
|
1377 |
dsl_dir_t *ancestor; |
|
1378 |
int64_t adelta; |
|
1379 |
uint64_t avail; |
|
1380 |
||
1381 |
ancestor = closest_common_ancestor(sdd, tdd); |
|
1382 |
adelta = would_change(sdd, -space, ancestor); |
|
1383 |
avail = dsl_dir_space_available(tdd, ancestor, adelta, FALSE); |
|
1384 |
if (avail < space) |
|
1385 |
return (ENOSPC); |
|
1386 |
||
1387 |
return (0); |
|
1388 |
} |
|
10373
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1389 |
|
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1390 |
timestruc_t |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1391 |
dsl_dir_snap_cmtime(dsl_dir_t *dd) |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1392 |
{ |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1393 |
timestruc_t t; |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1394 |
|
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1395 |
mutex_enter(&dd->dd_lock); |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1396 |
t = dd->dd_snap_cmtime; |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1397 |
mutex_exit(&dd->dd_lock); |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1398 |
|
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1399 |
return (t); |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1400 |
} |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1401 |
|
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1402 |
void |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1403 |
dsl_dir_snap_cmtime_update(dsl_dir_t *dd) |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1404 |
{ |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1405 |
timestruc_t t; |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1406 |
|
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1407 |
gethrestime(&t); |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1408 |
mutex_enter(&dd->dd_lock); |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1409 |
dd->dd_snap_cmtime = t; |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1410 |
mutex_exit(&dd->dd_lock); |
bcf97ee54990
6395956 snapshot dir needs real c/mtime
Chris Kirby <chris.kirby@sun.com>
parents:
10298
diff
changeset
|
1411 |
} |