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
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
22 /*
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <sys/zfs_context.h>
27 #include <sys/spa.h>
28 #include <sys/zio.h>
29 #include <sys/ddt.h>
30 #include <sys/zap.h>
31 #include <sys/dmu_tx.h>
32 #include <util/sscanf.h>
33
34 int ddt_zap_leaf_blockshift = 12;
35 int ddt_zap_indirect_blockshift = 12;
36
37 static int
38 ddt_zap_create(objset_t *os, uint64_t *objectp, dmu_tx_t *tx, boolean_t prehash)
39 {
40 zap_flags_t flags = ZAP_FLAG_HASH64 | ZAP_FLAG_UINT64_KEY;
41
42 if (prehash)
43 flags |= ZAP_FLAG_PRE_HASHED_KEY;
117 zap_cursor_init_serialized(&zc, os, object, *walk);
118 if ((error = zap_cursor_retrieve(&zc, &za)) == 0) {
119 uchar_t cbuf[sizeof (dde->dde_phys) + 1];
120 uint64_t csize = za.za_num_integers;
121 ASSERT(za.za_integer_length == 1);
122 error = zap_lookup_uint64(os, object, (uint64_t *)za.za_name,
123 DDT_KEY_WORDS, 1, csize, cbuf);
124 ASSERT(error == 0);
125 if (error == 0) {
126 ddt_decompress(cbuf, dde->dde_phys, csize,
127 sizeof (dde->dde_phys));
128 dde->dde_key = *(ddt_key_t *)za.za_name;
129 }
130 zap_cursor_advance(&zc);
131 *walk = zap_cursor_serialize(&zc);
132 }
133 zap_cursor_fini(&zc);
134 return (error);
135 }
136
137 static uint64_t
138 ddt_zap_count(objset_t *os, uint64_t object)
139 {
140 uint64_t count = 0;
141
142 VERIFY(zap_count(os, object, &count) == 0);
143
144 return (count);
145 }
146
147 const ddt_ops_t ddt_zap_ops = {
148 "zap",
149 ddt_zap_create,
150 ddt_zap_destroy,
151 ddt_zap_lookup,
152 ddt_zap_prefetch,
153 ddt_zap_update,
154 ddt_zap_remove,
155 ddt_zap_walk,
156 ddt_zap_count,
157 };
|
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
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
22 /*
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 */
26
27 #include <sys/zfs_context.h>
28 #include <sys/spa.h>
29 #include <sys/zio.h>
30 #include <sys/ddt.h>
31 #include <sys/zap.h>
32 #include <sys/dmu_tx.h>
33 #include <util/sscanf.h>
34
35 int ddt_zap_leaf_blockshift = 12;
36 int ddt_zap_indirect_blockshift = 12;
37
38 static int
39 ddt_zap_create(objset_t *os, uint64_t *objectp, dmu_tx_t *tx, boolean_t prehash)
40 {
41 zap_flags_t flags = ZAP_FLAG_HASH64 | ZAP_FLAG_UINT64_KEY;
42
43 if (prehash)
44 flags |= ZAP_FLAG_PRE_HASHED_KEY;
118 zap_cursor_init_serialized(&zc, os, object, *walk);
119 if ((error = zap_cursor_retrieve(&zc, &za)) == 0) {
120 uchar_t cbuf[sizeof (dde->dde_phys) + 1];
121 uint64_t csize = za.za_num_integers;
122 ASSERT(za.za_integer_length == 1);
123 error = zap_lookup_uint64(os, object, (uint64_t *)za.za_name,
124 DDT_KEY_WORDS, 1, csize, cbuf);
125 ASSERT(error == 0);
126 if (error == 0) {
127 ddt_decompress(cbuf, dde->dde_phys, csize,
128 sizeof (dde->dde_phys));
129 dde->dde_key = *(ddt_key_t *)za.za_name;
130 }
131 zap_cursor_advance(&zc);
132 *walk = zap_cursor_serialize(&zc);
133 }
134 zap_cursor_fini(&zc);
135 return (error);
136 }
137
138 static int
139 ddt_zap_count(objset_t *os, uint64_t object, uint64_t *count)
140 {
141 int error = zap_count(os, object, count);
142 ASSERT(error == 0);
143
144 return (error);
145 }
146
147 const ddt_ops_t ddt_zap_ops = {
148 "zap",
149 ddt_zap_create,
150 ddt_zap_destroy,
151 ddt_zap_lookup,
152 ddt_zap_prefetch,
153 ddt_zap_update,
154 ddt_zap_remove,
155 ddt_zap_walk,
156 ddt_zap_count,
157 };
|