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