Deleted Added
full compact
ddt.c (236884) ddt.c (245264)
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

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

84
85static void
86ddt_object_destroy(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
87 dmu_tx_t *tx)
88{
89 spa_t *spa = ddt->ddt_spa;
90 objset_t *os = ddt->ddt_os;
91 uint64_t *objectp = &ddt->ddt_object[type][class];
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

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

84
85static void
86ddt_object_destroy(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
87 dmu_tx_t *tx)
88{
89 spa_t *spa = ddt->ddt_spa;
90 objset_t *os = ddt->ddt_os;
91 uint64_t *objectp = &ddt->ddt_object[type][class];
92 uint64_t count;
92 char name[DDT_NAMELEN];
93
94 ddt_object_name(ddt, type, class, name);
95
96 ASSERT(*objectp != 0);
93 char name[DDT_NAMELEN];
94
95 ddt_object_name(ddt, type, class, name);
96
97 ASSERT(*objectp != 0);
97 ASSERT(ddt_object_count(ddt, type, class) == 0);
98 VERIFY(ddt_object_count(ddt, type, class, &count) == 0 && count == 0);
98 ASSERT(ddt_histogram_empty(&ddt->ddt_histogram[type][class]));
99 VERIFY(zap_remove(os, DMU_POOL_DIRECTORY_OBJECT, name, tx) == 0);
100 VERIFY(zap_remove(os, spa->spa_ddt_stat_object, name, tx) == 0);
101 VERIFY(ddt_ops[type]->ddt_op_destroy(os, *objectp, tx) == 0);
102 bzero(&ddt->ddt_object_stats[type][class], sizeof (ddt_object_t));
103
104 *objectp = 0;
105}
106
107static int
108ddt_object_load(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
109{
110 ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
111 dmu_object_info_t doi;
99 ASSERT(ddt_histogram_empty(&ddt->ddt_histogram[type][class]));
100 VERIFY(zap_remove(os, DMU_POOL_DIRECTORY_OBJECT, name, tx) == 0);
101 VERIFY(zap_remove(os, spa->spa_ddt_stat_object, name, tx) == 0);
102 VERIFY(ddt_ops[type]->ddt_op_destroy(os, *objectp, tx) == 0);
103 bzero(&ddt->ddt_object_stats[type][class], sizeof (ddt_object_t));
104
105 *objectp = 0;
106}
107
108static int
109ddt_object_load(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
110{
111 ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
112 dmu_object_info_t doi;
113 uint64_t count;
112 char name[DDT_NAMELEN];
113 int error;
114
115 ddt_object_name(ddt, type, class, name);
116
117 error = zap_lookup(ddt->ddt_os, DMU_POOL_DIRECTORY_OBJECT, name,
118 sizeof (uint64_t), 1, &ddt->ddt_object[type][class]);
119

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

124 sizeof (uint64_t), sizeof (ddt_histogram_t) / sizeof (uint64_t),
125 &ddt->ddt_histogram[type][class]);
126
127 /*
128 * Seed the cached statistics.
129 */
130 VERIFY(ddt_object_info(ddt, type, class, &doi) == 0);
131
114 char name[DDT_NAMELEN];
115 int error;
116
117 ddt_object_name(ddt, type, class, name);
118
119 error = zap_lookup(ddt->ddt_os, DMU_POOL_DIRECTORY_OBJECT, name,
120 sizeof (uint64_t), 1, &ddt->ddt_object[type][class]);
121

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

126 sizeof (uint64_t), sizeof (ddt_histogram_t) / sizeof (uint64_t),
127 &ddt->ddt_histogram[type][class]);
128
129 /*
130 * Seed the cached statistics.
131 */
132 VERIFY(ddt_object_info(ddt, type, class, &doi) == 0);
133
132 ddo->ddo_count = ddt_object_count(ddt, type, class);
134 error = ddt_object_count(ddt, type, class, &count);
135 if (error)
136 return error;
137
138 ddo->ddo_count = count;
133 ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
134 ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
135
136 ASSERT(error == 0);
137 return (error);
138}
139
140static void
141ddt_object_sync(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
142 dmu_tx_t *tx)
143{
144 ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
145 dmu_object_info_t doi;
139 ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
140 ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
141
142 ASSERT(error == 0);
143 return (error);
144}
145
146static void
147ddt_object_sync(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
148 dmu_tx_t *tx)
149{
150 ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
151 dmu_object_info_t doi;
152 uint64_t count;
146 char name[DDT_NAMELEN];
147
148 ddt_object_name(ddt, type, class, name);
149
150 VERIFY(zap_update(ddt->ddt_os, ddt->ddt_spa->spa_ddt_stat_object, name,
151 sizeof (uint64_t), sizeof (ddt_histogram_t) / sizeof (uint64_t),
152 &ddt->ddt_histogram[type][class], tx) == 0);
153
154 /*
155 * Cache DDT statistics; this is the only time they'll change.
156 */
157 VERIFY(ddt_object_info(ddt, type, class, &doi) == 0);
153 char name[DDT_NAMELEN];
154
155 ddt_object_name(ddt, type, class, name);
156
157 VERIFY(zap_update(ddt->ddt_os, ddt->ddt_spa->spa_ddt_stat_object, name,
158 sizeof (uint64_t), sizeof (ddt_histogram_t) / sizeof (uint64_t),
159 &ddt->ddt_histogram[type][class], tx) == 0);
160
161 /*
162 * Cache DDT statistics; this is the only time they'll change.
163 */
164 VERIFY(ddt_object_info(ddt, type, class, &doi) == 0);
165 VERIFY(ddt_object_count(ddt, type, class, &count) == 0);
158
166
159 ddo->ddo_count = ddt_object_count(ddt, type, class);
167 ddo->ddo_count = count;
160 ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
161 ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
162}
163
164static int
165ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
166 ddt_entry_t *dde)
167{

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

208 uint64_t *walk, ddt_entry_t *dde)
209{
210 ASSERT(ddt_object_exists(ddt, type, class));
211
212 return (ddt_ops[type]->ddt_op_walk(ddt->ddt_os,
213 ddt->ddt_object[type][class], dde, walk));
214}
215
168 ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
169 ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
170}
171
172static int
173ddt_object_lookup(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
174 ddt_entry_t *dde)
175{

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

216 uint64_t *walk, ddt_entry_t *dde)
217{
218 ASSERT(ddt_object_exists(ddt, type, class));
219
220 return (ddt_ops[type]->ddt_op_walk(ddt->ddt_os,
221 ddt->ddt_object[type][class], dde, walk));
222}
223
216uint64_t
217ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
224int
225ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class, uint64_t *count)
218{
219 ASSERT(ddt_object_exists(ddt, type, class));
220
221 return (ddt_ops[type]->ddt_op_count(ddt->ddt_os,
226{
227 ASSERT(ddt_object_exists(ddt, type, class));
228
229 return (ddt_ops[type]->ddt_op_count(ddt->ddt_os,
222 ddt->ddt_object[type][class]));
230 ddt->ddt_object[type][class], count));
223}
224
225int
226ddt_object_info(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
227 dmu_object_info_t *doi)
228{
229 if (!ddt_object_exists(ddt, type, class))
230 return (ENOENT);

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

1074 }
1075
1076 while ((dde = avl_destroy_nodes(&ddt->ddt_tree, &cookie)) != NULL) {
1077 ddt_sync_entry(ddt, dde, tx, txg);
1078 ddt_free(dde);
1079 }
1080
1081 for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
231}
232
233int
234ddt_object_info(ddt_t *ddt, enum ddt_type type, enum ddt_class class,
235 dmu_object_info_t *doi)
236{
237 if (!ddt_object_exists(ddt, type, class))
238 return (ENOENT);

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

1082 }
1083
1084 while ((dde = avl_destroy_nodes(&ddt->ddt_tree, &cookie)) != NULL) {
1085 ddt_sync_entry(ddt, dde, tx, txg);
1086 ddt_free(dde);
1087 }
1088
1089 for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
1082 uint64_t count = 0;
1090 uint64_t add, count = 0;
1083 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1084 if (ddt_object_exists(ddt, type, class)) {
1085 ddt_object_sync(ddt, type, class, tx);
1091 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1092 if (ddt_object_exists(ddt, type, class)) {
1093 ddt_object_sync(ddt, type, class, tx);
1086 count += ddt_object_count(ddt, type, class);
1094 VERIFY(ddt_object_count(ddt, type, class,
1095 &add) == 0);
1096 count += add;
1087 }
1088 }
1089 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1090 if (count == 0 && ddt_object_exists(ddt, type, class))
1091 ddt_object_destroy(ddt, type, class, tx);
1092 }
1093 }
1094

--- 57 unchanged lines hidden ---
1097 }
1098 }
1099 for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
1100 if (count == 0 && ddt_object_exists(ddt, type, class))
1101 ddt_object_destroy(ddt, type, class, tx);
1102 }
1103 }
1104

--- 57 unchanged lines hidden ---