Deleted Added
full compact
bpobj.c (228103) bpobj.c (239774)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011 by Delphix. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 */
25
26#include <sys/bpobj.h>
27#include <sys/zfs_context.h>
28#include <sys/refcount.h>
29#include <sys/dsl_pool.h>
24 */
25
26#include <sys/bpobj.h>
27#include <sys/zfs_context.h>
28#include <sys/refcount.h>
29#include <sys/dsl_pool.h>
30#include <sys/zfeature.h>
31#include <sys/zap.h>
30
32
33/*
34 * Return an empty bpobj, preferably the empty dummy one (dp_empty_bpobj).
35 */
31uint64_t
36uint64_t
37bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx)
38{
39 zfeature_info_t *empty_bpobj_feat =
40 &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ];
41 spa_t *spa = dmu_objset_spa(os);
42 dsl_pool_t *dp = dmu_objset_pool(os);
43
44 if (spa_feature_is_enabled(spa, empty_bpobj_feat)) {
45 if (!spa_feature_is_active(spa, empty_bpobj_feat)) {
46 ASSERT3U(dp->dp_empty_bpobj, ==, 0);
47 dp->dp_empty_bpobj =
48 bpobj_alloc(os, SPA_MAXBLOCKSIZE, tx);
49 VERIFY(zap_add(os,
50 DMU_POOL_DIRECTORY_OBJECT,
51 DMU_POOL_EMPTY_BPOBJ, sizeof (uint64_t), 1,
52 &dp->dp_empty_bpobj, tx) == 0);
53 }
54 spa_feature_incr(spa, empty_bpobj_feat, tx);
55 ASSERT(dp->dp_empty_bpobj != 0);
56 return (dp->dp_empty_bpobj);
57 } else {
58 return (bpobj_alloc(os, blocksize, tx));
59 }
60}
61
62void
63bpobj_decr_empty(objset_t *os, dmu_tx_t *tx)
64{
65 zfeature_info_t *empty_bpobj_feat =
66 &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ];
67 dsl_pool_t *dp = dmu_objset_pool(os);
68
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)) {
71 VERIFY3U(0, ==, zap_remove(dp->dp_meta_objset,
72 DMU_POOL_DIRECTORY_OBJECT,
73 DMU_POOL_EMPTY_BPOBJ, tx));
74 VERIFY3U(0, ==, dmu_object_free(os, dp->dp_empty_bpobj, tx));
75 dp->dp_empty_bpobj = 0;
76 }
77}
78
79uint64_t
32bpobj_alloc(objset_t *os, int blocksize, dmu_tx_t *tx)
33{
34 int size;
35
36 if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_BPOBJ_ACCOUNT)
37 size = BPOBJ_SIZE_V0;
38 else if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_DEADLISTS)
39 size = BPOBJ_SIZE_V1;

--- 8 unchanged lines hidden (view full) ---

48bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
49{
50 int64_t i;
51 bpobj_t bpo;
52 dmu_object_info_t doi;
53 int epb;
54 dmu_buf_t *dbuf = NULL;
55
80bpobj_alloc(objset_t *os, int blocksize, dmu_tx_t *tx)
81{
82 int size;
83
84 if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_BPOBJ_ACCOUNT)
85 size = BPOBJ_SIZE_V0;
86 else if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_DEADLISTS)
87 size = BPOBJ_SIZE_V1;

--- 8 unchanged lines hidden (view full) ---

96bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
97{
98 int64_t i;
99 bpobj_t bpo;
100 dmu_object_info_t doi;
101 int epb;
102 dmu_buf_t *dbuf = NULL;
103
104 ASSERT(obj != dmu_objset_pool(os)->dp_empty_bpobj);
56 VERIFY3U(0, ==, bpobj_open(&bpo, os, obj));
57
58 mutex_enter(&bpo.bpo_lock);
59
60 if (!bpo.bpo_havesubobj || bpo.bpo_phys->bpo_subobjs == 0)
61 goto out;
62
63 VERIFY3U(0, ==, dmu_object_info(os, bpo.bpo_phys->bpo_subobjs, &doi));

--- 251 unchanged lines hidden (view full) ---

315void
316bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx)
317{
318 bpobj_t subbpo;
319 uint64_t used, comp, uncomp, subsubobjs;
320
321 ASSERT(bpo->bpo_havesubobj);
322 ASSERT(bpo->bpo_havecomp);
105 VERIFY3U(0, ==, bpobj_open(&bpo, os, obj));
106
107 mutex_enter(&bpo.bpo_lock);
108
109 if (!bpo.bpo_havesubobj || bpo.bpo_phys->bpo_subobjs == 0)
110 goto out;
111
112 VERIFY3U(0, ==, dmu_object_info(os, bpo.bpo_phys->bpo_subobjs, &doi));

--- 251 unchanged lines hidden (view full) ---

364void
365bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx)
366{
367 bpobj_t subbpo;
368 uint64_t used, comp, uncomp, subsubobjs;
369
370 ASSERT(bpo->bpo_havesubobj);
371 ASSERT(bpo->bpo_havecomp);
372 ASSERT(bpo->bpo_object != dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj);
323
373
374 if (subobj == dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj) {
375 bpobj_decr_empty(bpo->bpo_os, tx);
376 return;
377 }
378
324 VERIFY3U(0, ==, bpobj_open(&subbpo, bpo->bpo_os, subobj));
325 VERIFY3U(0, ==, bpobj_space(&subbpo, &used, &comp, &uncomp));
326
327 if (used == 0) {
328 /* No point in having an empty subobj. */
329 bpobj_close(&subbpo);
330 bpobj_free(bpo->bpo_os, subobj, tx);
331 return;

--- 51 unchanged lines hidden (view full) ---

383bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx)
384{
385 blkptr_t stored_bp = *bp;
386 uint64_t offset;
387 int blkoff;
388 blkptr_t *bparray;
389
390 ASSERT(!BP_IS_HOLE(bp));
379 VERIFY3U(0, ==, bpobj_open(&subbpo, bpo->bpo_os, subobj));
380 VERIFY3U(0, ==, bpobj_space(&subbpo, &used, &comp, &uncomp));
381
382 if (used == 0) {
383 /* No point in having an empty subobj. */
384 bpobj_close(&subbpo);
385 bpobj_free(bpo->bpo_os, subobj, tx);
386 return;

--- 51 unchanged lines hidden (view full) ---

438bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx)
439{
440 blkptr_t stored_bp = *bp;
441 uint64_t offset;
442 int blkoff;
443 blkptr_t *bparray;
444
445 ASSERT(!BP_IS_HOLE(bp));
446 ASSERT(bpo->bpo_object != dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj);
391
392 /* We never need the fill count. */
393 stored_bp.blk_fill = 0;
394
395 /* The bpobj will compress better if we can leave off the checksum */
396 if (!BP_GET_DEDUP(bp))
397 bzero(&stored_bp.blk_cksum, sizeof (stored_bp.blk_cksum));
398

--- 102 unchanged lines hidden ---
447
448 /* We never need the fill count. */
449 stored_bp.blk_fill = 0;
450
451 /* The bpobj will compress better if we can leave off the checksum */
452 if (!BP_GET_DEDUP(bp))
453 bzero(&stored_bp.blk_cksum, sizeof (stored_bp.blk_cksum));
454

--- 102 unchanged lines hidden ---