Print this page
4171 clean up spa_feature_*() interfaces
4172 implement extensible_dataset feature for use by other zpool features
Reviewed by: Max Grossman <max.grossman@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/bpobj.c
+++ new/usr/src/uts/common/fs/zfs/bpobj.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #include <sys/bpobj.h>
27 27 #include <sys/zfs_context.h>
28 28 #include <sys/refcount.h>
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
29 29 #include <sys/dsl_pool.h>
30 30 #include <sys/zfeature.h>
31 31 #include <sys/zap.h>
32 32
33 33 /*
34 34 * Return an empty bpobj, preferably the empty dummy one (dp_empty_bpobj).
35 35 */
36 36 uint64_t
37 37 bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx)
38 38 {
39 - zfeature_info_t *empty_bpobj_feat =
40 - &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ];
41 39 spa_t *spa = dmu_objset_spa(os);
42 40 dsl_pool_t *dp = dmu_objset_pool(os);
43 41
44 - if (spa_feature_is_enabled(spa, empty_bpobj_feat)) {
45 - if (!spa_feature_is_active(spa, empty_bpobj_feat)) {
42 + if (spa_feature_is_enabled(spa, SPA_FEATURE_EMPTY_BPOBJ)) {
43 + if (!spa_feature_is_active(spa, SPA_FEATURE_EMPTY_BPOBJ)) {
46 44 ASSERT0(dp->dp_empty_bpobj);
47 45 dp->dp_empty_bpobj =
48 46 bpobj_alloc(os, SPA_MAXBLOCKSIZE, tx);
49 47 VERIFY(zap_add(os,
50 48 DMU_POOL_DIRECTORY_OBJECT,
51 49 DMU_POOL_EMPTY_BPOBJ, sizeof (uint64_t), 1,
52 50 &dp->dp_empty_bpobj, tx) == 0);
53 51 }
54 - spa_feature_incr(spa, empty_bpobj_feat, tx);
52 + spa_feature_incr(spa, SPA_FEATURE_EMPTY_BPOBJ, tx);
55 53 ASSERT(dp->dp_empty_bpobj != 0);
56 54 return (dp->dp_empty_bpobj);
57 55 } else {
58 56 return (bpobj_alloc(os, blocksize, tx));
59 57 }
60 58 }
61 59
62 60 void
63 61 bpobj_decr_empty(objset_t *os, dmu_tx_t *tx)
64 62 {
65 - zfeature_info_t *empty_bpobj_feat =
66 - &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ];
67 63 dsl_pool_t *dp = dmu_objset_pool(os);
68 64
69 - spa_feature_decr(dmu_objset_spa(os), empty_bpobj_feat, tx);
70 - if (!spa_feature_is_active(dmu_objset_spa(os), empty_bpobj_feat)) {
65 + spa_feature_decr(dmu_objset_spa(os), SPA_FEATURE_EMPTY_BPOBJ, tx);
66 + if (!spa_feature_is_active(dmu_objset_spa(os),
67 + SPA_FEATURE_EMPTY_BPOBJ)) {
71 68 VERIFY3U(0, ==, zap_remove(dp->dp_meta_objset,
72 69 DMU_POOL_DIRECTORY_OBJECT,
73 70 DMU_POOL_EMPTY_BPOBJ, tx));
74 71 VERIFY3U(0, ==, dmu_object_free(os, dp->dp_empty_bpobj, tx));
75 72 dp->dp_empty_bpobj = 0;
76 73 }
77 74 }
78 75
79 76 uint64_t
80 77 bpobj_alloc(objset_t *os, int blocksize, dmu_tx_t *tx)
81 78 {
82 79 int size;
83 80
84 81 if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_BPOBJ_ACCOUNT)
85 82 size = BPOBJ_SIZE_V0;
86 83 else if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_DEADLISTS)
87 84 size = BPOBJ_SIZE_V1;
88 85 else
89 86 size = sizeof (bpobj_phys_t);
90 87
91 88 return (dmu_object_alloc(os, DMU_OT_BPOBJ, blocksize,
92 89 DMU_OT_BPOBJ_HDR, size, tx));
93 90 }
94 91
95 92 void
96 93 bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
97 94 {
98 95 int64_t i;
99 96 bpobj_t bpo;
100 97 dmu_object_info_t doi;
101 98 int epb;
102 99 dmu_buf_t *dbuf = NULL;
103 100
104 101 ASSERT(obj != dmu_objset_pool(os)->dp_empty_bpobj);
105 102 VERIFY3U(0, ==, bpobj_open(&bpo, os, obj));
106 103
107 104 mutex_enter(&bpo.bpo_lock);
108 105
109 106 if (!bpo.bpo_havesubobj || bpo.bpo_phys->bpo_subobjs == 0)
110 107 goto out;
111 108
112 109 VERIFY3U(0, ==, dmu_object_info(os, bpo.bpo_phys->bpo_subobjs, &doi));
113 110 epb = doi.doi_data_block_size / sizeof (uint64_t);
114 111
115 112 for (i = bpo.bpo_phys->bpo_num_subobjs - 1; i >= 0; i--) {
116 113 uint64_t *objarray;
117 114 uint64_t offset, blkoff;
118 115
119 116 offset = i * sizeof (uint64_t);
120 117 blkoff = P2PHASE(i, epb);
121 118
122 119 if (dbuf == NULL || dbuf->db_offset > offset) {
123 120 if (dbuf)
124 121 dmu_buf_rele(dbuf, FTAG);
125 122 VERIFY3U(0, ==, dmu_buf_hold(os,
126 123 bpo.bpo_phys->bpo_subobjs, offset, FTAG, &dbuf, 0));
127 124 }
128 125
129 126 ASSERT3U(offset, >=, dbuf->db_offset);
130 127 ASSERT3U(offset, <, dbuf->db_offset + dbuf->db_size);
131 128
132 129 objarray = dbuf->db_data;
133 130 bpobj_free(os, objarray[blkoff], tx);
134 131 }
135 132 if (dbuf) {
136 133 dmu_buf_rele(dbuf, FTAG);
137 134 dbuf = NULL;
138 135 }
139 136 VERIFY3U(0, ==, dmu_object_free(os, bpo.bpo_phys->bpo_subobjs, tx));
140 137
141 138 out:
142 139 mutex_exit(&bpo.bpo_lock);
143 140 bpobj_close(&bpo);
144 141
145 142 VERIFY3U(0, ==, dmu_object_free(os, obj, tx));
146 143 }
147 144
148 145 int
149 146 bpobj_open(bpobj_t *bpo, objset_t *os, uint64_t object)
150 147 {
151 148 dmu_object_info_t doi;
152 149 int err;
153 150
154 151 err = dmu_object_info(os, object, &doi);
155 152 if (err)
156 153 return (err);
157 154
158 155 bzero(bpo, sizeof (*bpo));
159 156 mutex_init(&bpo->bpo_lock, NULL, MUTEX_DEFAULT, NULL);
160 157
161 158 ASSERT(bpo->bpo_dbuf == NULL);
162 159 ASSERT(bpo->bpo_phys == NULL);
163 160 ASSERT(object != 0);
164 161 ASSERT3U(doi.doi_type, ==, DMU_OT_BPOBJ);
165 162 ASSERT3U(doi.doi_bonus_type, ==, DMU_OT_BPOBJ_HDR);
166 163
167 164 err = dmu_bonus_hold(os, object, bpo, &bpo->bpo_dbuf);
168 165 if (err)
169 166 return (err);
170 167
171 168 bpo->bpo_os = os;
172 169 bpo->bpo_object = object;
173 170 bpo->bpo_epb = doi.doi_data_block_size >> SPA_BLKPTRSHIFT;
174 171 bpo->bpo_havecomp = (doi.doi_bonus_size > BPOBJ_SIZE_V0);
175 172 bpo->bpo_havesubobj = (doi.doi_bonus_size > BPOBJ_SIZE_V1);
176 173 bpo->bpo_phys = bpo->bpo_dbuf->db_data;
177 174 return (0);
178 175 }
179 176
180 177 void
181 178 bpobj_close(bpobj_t *bpo)
182 179 {
183 180 /* Lame workaround for closing a bpobj that was never opened. */
184 181 if (bpo->bpo_object == 0)
185 182 return;
186 183
187 184 dmu_buf_rele(bpo->bpo_dbuf, bpo);
188 185 if (bpo->bpo_cached_dbuf != NULL)
189 186 dmu_buf_rele(bpo->bpo_cached_dbuf, bpo);
190 187 bpo->bpo_dbuf = NULL;
191 188 bpo->bpo_phys = NULL;
192 189 bpo->bpo_cached_dbuf = NULL;
193 190 bpo->bpo_object = 0;
194 191
195 192 mutex_destroy(&bpo->bpo_lock);
196 193 }
197 194
198 195 static int
199 196 bpobj_iterate_impl(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx,
200 197 boolean_t free)
201 198 {
202 199 dmu_object_info_t doi;
203 200 int epb;
204 201 int64_t i;
205 202 int err = 0;
206 203 dmu_buf_t *dbuf = NULL;
207 204
208 205 mutex_enter(&bpo->bpo_lock);
209 206
210 207 if (free)
211 208 dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
212 209
213 210 for (i = bpo->bpo_phys->bpo_num_blkptrs - 1; i >= 0; i--) {
214 211 blkptr_t *bparray;
215 212 blkptr_t *bp;
216 213 uint64_t offset, blkoff;
217 214
218 215 offset = i * sizeof (blkptr_t);
219 216 blkoff = P2PHASE(i, bpo->bpo_epb);
220 217
221 218 if (dbuf == NULL || dbuf->db_offset > offset) {
222 219 if (dbuf)
223 220 dmu_buf_rele(dbuf, FTAG);
224 221 err = dmu_buf_hold(bpo->bpo_os, bpo->bpo_object, offset,
225 222 FTAG, &dbuf, 0);
226 223 if (err)
227 224 break;
228 225 }
229 226
230 227 ASSERT3U(offset, >=, dbuf->db_offset);
231 228 ASSERT3U(offset, <, dbuf->db_offset + dbuf->db_size);
232 229
233 230 bparray = dbuf->db_data;
234 231 bp = &bparray[blkoff];
235 232 err = func(arg, bp, tx);
236 233 if (err)
237 234 break;
238 235 if (free) {
239 236 bpo->bpo_phys->bpo_bytes -=
240 237 bp_get_dsize_sync(dmu_objset_spa(bpo->bpo_os), bp);
241 238 ASSERT3S(bpo->bpo_phys->bpo_bytes, >=, 0);
242 239 if (bpo->bpo_havecomp) {
243 240 bpo->bpo_phys->bpo_comp -= BP_GET_PSIZE(bp);
244 241 bpo->bpo_phys->bpo_uncomp -= BP_GET_UCSIZE(bp);
245 242 }
246 243 bpo->bpo_phys->bpo_num_blkptrs--;
247 244 ASSERT3S(bpo->bpo_phys->bpo_num_blkptrs, >=, 0);
248 245 }
249 246 }
250 247 if (dbuf) {
251 248 dmu_buf_rele(dbuf, FTAG);
252 249 dbuf = NULL;
253 250 }
254 251 if (free) {
255 252 i++;
256 253 VERIFY3U(0, ==, dmu_free_range(bpo->bpo_os, bpo->bpo_object,
257 254 i * sizeof (blkptr_t), -1ULL, tx));
↓ open down ↓ |
177 lines elided |
↑ open up ↑ |
258 255 }
259 256 if (err || !bpo->bpo_havesubobj || bpo->bpo_phys->bpo_subobjs == 0)
260 257 goto out;
261 258
262 259 ASSERT(bpo->bpo_havecomp);
263 260 err = dmu_object_info(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs, &doi);
264 261 if (err) {
265 262 mutex_exit(&bpo->bpo_lock);
266 263 return (err);
267 264 }
265 + ASSERT3U(doi.doi_type, ==, DMU_OT_BPOBJ_SUBOBJ);
268 266 epb = doi.doi_data_block_size / sizeof (uint64_t);
269 267
270 268 for (i = bpo->bpo_phys->bpo_num_subobjs - 1; i >= 0; i--) {
271 269 uint64_t *objarray;
272 270 uint64_t offset, blkoff;
273 271 bpobj_t sublist;
274 272 uint64_t used_before, comp_before, uncomp_before;
275 273 uint64_t used_after, comp_after, uncomp_after;
276 274
277 275 offset = i * sizeof (uint64_t);
278 276 blkoff = P2PHASE(i, epb);
279 277
280 278 if (dbuf == NULL || dbuf->db_offset > offset) {
281 279 if (dbuf)
282 280 dmu_buf_rele(dbuf, FTAG);
283 281 err = dmu_buf_hold(bpo->bpo_os,
284 282 bpo->bpo_phys->bpo_subobjs, offset, FTAG, &dbuf, 0);
285 283 if (err)
286 284 break;
287 285 }
288 286
289 287 ASSERT3U(offset, >=, dbuf->db_offset);
290 288 ASSERT3U(offset, <, dbuf->db_offset + dbuf->db_size);
291 289
292 290 objarray = dbuf->db_data;
293 291 err = bpobj_open(&sublist, bpo->bpo_os, objarray[blkoff]);
294 292 if (err)
295 293 break;
296 294 if (free) {
297 295 err = bpobj_space(&sublist,
298 296 &used_before, &comp_before, &uncomp_before);
299 297 if (err)
300 298 break;
301 299 }
302 300 err = bpobj_iterate_impl(&sublist, func, arg, tx, free);
303 301 if (free) {
304 302 VERIFY3U(0, ==, bpobj_space(&sublist,
305 303 &used_after, &comp_after, &uncomp_after));
306 304 bpo->bpo_phys->bpo_bytes -= used_before - used_after;
307 305 ASSERT3S(bpo->bpo_phys->bpo_bytes, >=, 0);
308 306 bpo->bpo_phys->bpo_comp -= comp_before - comp_after;
309 307 bpo->bpo_phys->bpo_uncomp -=
310 308 uncomp_before - uncomp_after;
311 309 }
312 310
313 311 bpobj_close(&sublist);
314 312 if (err)
315 313 break;
316 314 if (free) {
317 315 err = dmu_object_free(bpo->bpo_os,
318 316 objarray[blkoff], tx);
319 317 if (err)
320 318 break;
321 319 bpo->bpo_phys->bpo_num_subobjs--;
322 320 ASSERT3S(bpo->bpo_phys->bpo_num_subobjs, >=, 0);
323 321 }
324 322 }
325 323 if (dbuf) {
326 324 dmu_buf_rele(dbuf, FTAG);
327 325 dbuf = NULL;
328 326 }
329 327 if (free) {
330 328 VERIFY3U(0, ==, dmu_free_range(bpo->bpo_os,
331 329 bpo->bpo_phys->bpo_subobjs,
332 330 (i + 1) * sizeof (uint64_t), -1ULL, tx));
333 331 }
334 332
335 333 out:
336 334 /* If there are no entries, there should be no bytes. */
337 335 ASSERT(bpo->bpo_phys->bpo_num_blkptrs > 0 ||
338 336 (bpo->bpo_havesubobj && bpo->bpo_phys->bpo_num_subobjs > 0) ||
339 337 bpo->bpo_phys->bpo_bytes == 0);
340 338
341 339 mutex_exit(&bpo->bpo_lock);
342 340 return (err);
343 341 }
344 342
345 343 /*
346 344 * Iterate and remove the entries. If func returns nonzero, iteration
347 345 * will stop and that entry will not be removed.
348 346 */
349 347 int
350 348 bpobj_iterate(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx)
351 349 {
352 350 return (bpobj_iterate_impl(bpo, func, arg, tx, B_TRUE));
353 351 }
354 352
355 353 /*
356 354 * Iterate the entries. If func returns nonzero, iteration will stop.
357 355 */
358 356 int
359 357 bpobj_iterate_nofree(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx)
360 358 {
361 359 return (bpobj_iterate_impl(bpo, func, arg, tx, B_FALSE));
362 360 }
363 361
364 362 void
365 363 bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx)
366 364 {
367 365 bpobj_t subbpo;
368 366 uint64_t used, comp, uncomp, subsubobjs;
369 367
370 368 ASSERT(bpo->bpo_havesubobj);
371 369 ASSERT(bpo->bpo_havecomp);
372 370 ASSERT(bpo->bpo_object != dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj);
373 371
374 372 if (subobj == dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj) {
375 373 bpobj_decr_empty(bpo->bpo_os, tx);
376 374 return;
377 375 }
378 376
379 377 VERIFY3U(0, ==, bpobj_open(&subbpo, bpo->bpo_os, subobj));
380 378 VERIFY3U(0, ==, bpobj_space(&subbpo, &used, &comp, &uncomp));
381 379
382 380 if (used == 0) {
383 381 /* No point in having an empty subobj. */
384 382 bpobj_close(&subbpo);
385 383 bpobj_free(bpo->bpo_os, subobj, tx);
386 384 return;
387 385 }
388 386
389 387 dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
390 388 if (bpo->bpo_phys->bpo_subobjs == 0) {
391 389 bpo->bpo_phys->bpo_subobjs = dmu_object_alloc(bpo->bpo_os,
392 390 DMU_OT_BPOBJ_SUBOBJ, SPA_MAXBLOCKSIZE, DMU_OT_NONE, 0, tx);
393 391 }
394 392
395 393 dmu_object_info_t doi;
396 394 ASSERT0(dmu_object_info(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs, &doi));
397 395 ASSERT3U(doi.doi_type, ==, DMU_OT_BPOBJ_SUBOBJ);
398 396
399 397 mutex_enter(&bpo->bpo_lock);
400 398 dmu_write(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs,
401 399 bpo->bpo_phys->bpo_num_subobjs * sizeof (subobj),
402 400 sizeof (subobj), &subobj, tx);
403 401 bpo->bpo_phys->bpo_num_subobjs++;
404 402
405 403 /*
406 404 * If subobj has only one block of subobjs, then move subobj's
407 405 * subobjs to bpo's subobj list directly. This reduces
408 406 * recursion in bpobj_iterate due to nested subobjs.
409 407 */
410 408 subsubobjs = subbpo.bpo_phys->bpo_subobjs;
411 409 if (subsubobjs != 0) {
412 410 dmu_object_info_t doi;
413 411
414 412 VERIFY3U(0, ==, dmu_object_info(bpo->bpo_os, subsubobjs, &doi));
415 413 if (doi.doi_max_offset == doi.doi_data_block_size) {
416 414 dmu_buf_t *subdb;
417 415 uint64_t numsubsub = subbpo.bpo_phys->bpo_num_subobjs;
418 416
419 417 VERIFY3U(0, ==, dmu_buf_hold(bpo->bpo_os, subsubobjs,
420 418 0, FTAG, &subdb, 0));
421 419 /*
422 420 * Make sure that we are not asking dmu_write()
423 421 * to write more data than we have in our buffer.
424 422 */
425 423 VERIFY3U(subdb->db_size, >=,
426 424 numsubsub * sizeof (subobj));
427 425 dmu_write(bpo->bpo_os, bpo->bpo_phys->bpo_subobjs,
428 426 bpo->bpo_phys->bpo_num_subobjs * sizeof (subobj),
429 427 numsubsub * sizeof (subobj), subdb->db_data, tx);
430 428 dmu_buf_rele(subdb, FTAG);
431 429 bpo->bpo_phys->bpo_num_subobjs += numsubsub;
432 430
433 431 dmu_buf_will_dirty(subbpo.bpo_dbuf, tx);
434 432 subbpo.bpo_phys->bpo_subobjs = 0;
435 433 VERIFY3U(0, ==, dmu_object_free(bpo->bpo_os,
436 434 subsubobjs, tx));
437 435 }
438 436 }
439 437 bpo->bpo_phys->bpo_bytes += used;
440 438 bpo->bpo_phys->bpo_comp += comp;
441 439 bpo->bpo_phys->bpo_uncomp += uncomp;
442 440 mutex_exit(&bpo->bpo_lock);
443 441
444 442 bpobj_close(&subbpo);
445 443 }
446 444
447 445 void
448 446 bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx)
449 447 {
450 448 blkptr_t stored_bp = *bp;
451 449 uint64_t offset;
452 450 int blkoff;
453 451 blkptr_t *bparray;
454 452
455 453 ASSERT(!BP_IS_HOLE(bp));
456 454 ASSERT(bpo->bpo_object != dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj);
457 455
458 456 /* We never need the fill count. */
459 457 stored_bp.blk_fill = 0;
460 458
461 459 /* The bpobj will compress better if we can leave off the checksum */
462 460 if (!BP_GET_DEDUP(bp))
463 461 bzero(&stored_bp.blk_cksum, sizeof (stored_bp.blk_cksum));
464 462
465 463 mutex_enter(&bpo->bpo_lock);
466 464
467 465 offset = bpo->bpo_phys->bpo_num_blkptrs * sizeof (stored_bp);
468 466 blkoff = P2PHASE(bpo->bpo_phys->bpo_num_blkptrs, bpo->bpo_epb);
469 467
470 468 if (bpo->bpo_cached_dbuf == NULL ||
471 469 offset < bpo->bpo_cached_dbuf->db_offset ||
472 470 offset >= bpo->bpo_cached_dbuf->db_offset +
473 471 bpo->bpo_cached_dbuf->db_size) {
474 472 if (bpo->bpo_cached_dbuf)
475 473 dmu_buf_rele(bpo->bpo_cached_dbuf, bpo);
476 474 VERIFY3U(0, ==, dmu_buf_hold(bpo->bpo_os, bpo->bpo_object,
477 475 offset, bpo, &bpo->bpo_cached_dbuf, 0));
478 476 }
479 477
480 478 dmu_buf_will_dirty(bpo->bpo_cached_dbuf, tx);
481 479 bparray = bpo->bpo_cached_dbuf->db_data;
482 480 bparray[blkoff] = stored_bp;
483 481
484 482 dmu_buf_will_dirty(bpo->bpo_dbuf, tx);
485 483 bpo->bpo_phys->bpo_num_blkptrs++;
486 484 bpo->bpo_phys->bpo_bytes +=
487 485 bp_get_dsize_sync(dmu_objset_spa(bpo->bpo_os), bp);
488 486 if (bpo->bpo_havecomp) {
489 487 bpo->bpo_phys->bpo_comp += BP_GET_PSIZE(bp);
490 488 bpo->bpo_phys->bpo_uncomp += BP_GET_UCSIZE(bp);
491 489 }
492 490 mutex_exit(&bpo->bpo_lock);
493 491 }
494 492
495 493 struct space_range_arg {
496 494 spa_t *spa;
497 495 uint64_t mintxg;
498 496 uint64_t maxtxg;
499 497 uint64_t used;
500 498 uint64_t comp;
501 499 uint64_t uncomp;
502 500 };
503 501
504 502 /* ARGSUSED */
505 503 static int
506 504 space_range_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
507 505 {
508 506 struct space_range_arg *sra = arg;
509 507
510 508 if (bp->blk_birth > sra->mintxg && bp->blk_birth <= sra->maxtxg) {
511 509 if (dsl_pool_sync_context(spa_get_dsl(sra->spa)))
512 510 sra->used += bp_get_dsize_sync(sra->spa, bp);
513 511 else
514 512 sra->used += bp_get_dsize(sra->spa, bp);
515 513 sra->comp += BP_GET_PSIZE(bp);
516 514 sra->uncomp += BP_GET_UCSIZE(bp);
517 515 }
518 516 return (0);
519 517 }
520 518
521 519 int
522 520 bpobj_space(bpobj_t *bpo, uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
523 521 {
524 522 mutex_enter(&bpo->bpo_lock);
525 523
526 524 *usedp = bpo->bpo_phys->bpo_bytes;
527 525 if (bpo->bpo_havecomp) {
528 526 *compp = bpo->bpo_phys->bpo_comp;
529 527 *uncompp = bpo->bpo_phys->bpo_uncomp;
530 528 mutex_exit(&bpo->bpo_lock);
531 529 return (0);
532 530 } else {
533 531 mutex_exit(&bpo->bpo_lock);
534 532 return (bpobj_space_range(bpo, 0, UINT64_MAX,
535 533 usedp, compp, uncompp));
536 534 }
537 535 }
538 536
539 537 /*
540 538 * Return the amount of space in the bpobj which is:
541 539 * mintxg < blk_birth <= maxtxg
542 540 */
543 541 int
544 542 bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg,
545 543 uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
546 544 {
547 545 struct space_range_arg sra = { 0 };
548 546 int err;
549 547
550 548 /*
551 549 * As an optimization, if they want the whole txg range, just
552 550 * get bpo_bytes rather than iterating over the bps.
553 551 */
554 552 if (mintxg < TXG_INITIAL && maxtxg == UINT64_MAX && bpo->bpo_havecomp)
555 553 return (bpobj_space(bpo, usedp, compp, uncompp));
556 554
557 555 sra.spa = dmu_objset_spa(bpo->bpo_os);
558 556 sra.mintxg = mintxg;
559 557 sra.maxtxg = maxtxg;
560 558
561 559 err = bpobj_iterate_nofree(bpo, space_range_cb, &sra, NULL);
562 560 *usedp = sra.used;
563 561 *compp = sra.comp;
564 562 *uncompp = sra.uncomp;
565 563 return (err);
566 564 }
↓ open down ↓ |
289 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX