]>
git.proxmox.com Git - mirror_zfs.git/blob - module/zfs/ddt_zap.c
8f6397a6d108a8c95cb7e013daa387f89e9d76a2
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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2018 by Delphix. All rights reserved.
27 #include <sys/zfs_context.h>
32 #include <sys/dmu_tx.h>
34 static unsigned int ddt_zap_default_bs
= 15;
35 static unsigned int ddt_zap_default_ibs
= 15;
38 ddt_zap_create(objset_t
*os
, uint64_t *objectp
, dmu_tx_t
*tx
, boolean_t prehash
)
40 zap_flags_t flags
= ZAP_FLAG_HASH64
| ZAP_FLAG_UINT64_KEY
;
43 flags
|= ZAP_FLAG_PRE_HASHED_KEY
;
45 *objectp
= zap_create_flags(os
, 0, flags
, DMU_OT_DDT_ZAP
,
46 ddt_zap_default_bs
, ddt_zap_default_ibs
,
49 return (*objectp
== 0 ? SET_ERROR(ENOTSUP
) : 0);
53 ddt_zap_destroy(objset_t
*os
, uint64_t object
, dmu_tx_t
*tx
)
55 return (zap_destroy(os
, object
, tx
));
59 ddt_zap_lookup(objset_t
*os
, uint64_t object
, ddt_entry_t
*dde
)
65 cbuf
= kmem_alloc(sizeof (dde
->dde_phys
) + 1, KM_SLEEP
);
67 error
= zap_length_uint64(os
, object
, (uint64_t *)&dde
->dde_key
,
68 DDT_KEY_WORDS
, &one
, &csize
);
73 ASSERT(csize
<= (sizeof (dde
->dde_phys
) + 1));
75 error
= zap_lookup_uint64(os
, object
, (uint64_t *)&dde
->dde_key
,
76 DDT_KEY_WORDS
, 1, csize
, cbuf
);
80 ddt_decompress(cbuf
, dde
->dde_phys
, csize
, sizeof (dde
->dde_phys
));
82 kmem_free(cbuf
, sizeof (dde
->dde_phys
) + 1);
88 ddt_zap_prefetch(objset_t
*os
, uint64_t object
, ddt_entry_t
*dde
)
90 (void) zap_prefetch_uint64(os
, object
, (uint64_t *)&dde
->dde_key
,
95 ddt_zap_update(objset_t
*os
, uint64_t object
, ddt_entry_t
*dde
, dmu_tx_t
*tx
)
97 uchar_t cbuf
[sizeof (dde
->dde_phys
) + 1];
100 csize
= ddt_compress(dde
->dde_phys
, cbuf
,
101 sizeof (dde
->dde_phys
), sizeof (cbuf
));
103 return (zap_update_uint64(os
, object
, (uint64_t *)&dde
->dde_key
,
104 DDT_KEY_WORDS
, 1, csize
, cbuf
, tx
));
108 ddt_zap_remove(objset_t
*os
, uint64_t object
, ddt_entry_t
*dde
, dmu_tx_t
*tx
)
110 return (zap_remove_uint64(os
, object
, (uint64_t *)&dde
->dde_key
,
115 ddt_zap_walk(objset_t
*os
, uint64_t object
, ddt_entry_t
*dde
, uint64_t *walk
)
123 * We don't want to prefetch the entire ZAP object, because
124 * it can be enormous. Also the primary use of DDT iteration
125 * is for scrubbing, in which case we will be issuing many
126 * scrub I/Os for each ZAP block that we read in, so
127 * reading the ZAP is unlikely to be the bottleneck.
129 zap_cursor_init_noprefetch(&zc
, os
, object
);
131 zap_cursor_init_serialized(&zc
, os
, object
, *walk
);
133 if ((error
= zap_cursor_retrieve(&zc
, &za
)) == 0) {
134 uchar_t cbuf
[sizeof (dde
->dde_phys
) + 1];
135 uint64_t csize
= za
.za_num_integers
;
136 ASSERT(za
.za_integer_length
== 1);
137 error
= zap_lookup_uint64(os
, object
, (uint64_t *)za
.za_name
,
138 DDT_KEY_WORDS
, 1, csize
, cbuf
);
141 ddt_decompress(cbuf
, dde
->dde_phys
, csize
,
142 sizeof (dde
->dde_phys
));
143 dde
->dde_key
= *(ddt_key_t
*)za
.za_name
;
145 zap_cursor_advance(&zc
);
146 *walk
= zap_cursor_serialize(&zc
);
148 zap_cursor_fini(&zc
);
153 ddt_zap_count(objset_t
*os
, uint64_t object
, uint64_t *count
)
155 return (zap_count(os
, object
, count
));
158 const ddt_ops_t ddt_zap_ops
= {
171 ZFS_MODULE_PARAM(zfs_dedup
, , ddt_zap_default_bs
, UINT
, ZMOD_RW
,
172 "DDT ZAP leaf blockshift");
173 ZFS_MODULE_PARAM(zfs_dedup
, , ddt_zap_default_ibs
, UINT
, ZMOD_RW
,
174 "DDT ZAP indirect blockshift");