Print this page
NEX-9406 Add a property to show that a dataset has been modified since a snapshot
Reviewed by: Alexey Komarov <alexey.komarov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Fixup merge results
re #12585 rb4049 ZFS++ work port - refactoring to improve separation of open/closed code, bug fixes, performance improvements - open code
Bug 11205: add missing libzfs_closed_stubs.c to fix opensource-only build.
ZFS plus work: special vdevs, cos, cos/vdev properties
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/common/zfs/zprop_common.c
+++ new/usr/src/common/zfs/zprop_common.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
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
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 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 - */
25 -/*
26 24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
27 26 */
28 27
29 28 /*
30 29 * Common routines used by zfs and zpool property management.
31 30 */
32 31
33 32 #include <sys/zio.h>
34 33 #include <sys/spa.h>
35 34 #include <sys/zfs_acl.h>
36 35 #include <sys/zfs_ioctl.h>
37 36 #include <sys/zfs_znode.h>
38 37 #include <sys/fs/zfs.h>
39 38
40 39 #include "zfs_prop.h"
41 40 #include "zfs_deleg.h"
42 41
43 42 #if defined(_KERNEL)
44 43 #include <sys/systm.h>
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
45 44 #include <util/qsort.h>
46 45 #else
47 46 #include <stdlib.h>
48 47 #include <string.h>
49 48 #include <ctype.h>
50 49 #endif
51 50
52 51 static zprop_desc_t *
53 52 zprop_get_proptable(zfs_type_t type)
54 53 {
55 - if (type == ZFS_TYPE_POOL)
54 + switch (type) {
55 + case ZFS_TYPE_POOL:
56 56 return (zpool_prop_get_table());
57 - else
57 + case ZFS_TYPE_VDEV:
58 + return (vdev_prop_get_table());
59 + case ZFS_TYPE_COS:
60 + return (cos_prop_get_table());
61 + default:
58 62 return (zfs_prop_get_table());
63 + }
59 64 }
60 65
61 66 static int
62 67 zprop_get_numprops(zfs_type_t type)
63 68 {
64 - if (type == ZFS_TYPE_POOL)
69 + switch (type) {
70 + case ZFS_TYPE_POOL:
65 71 return (ZPOOL_NUM_PROPS);
66 - else
72 + case ZFS_TYPE_VDEV:
73 + return (VDEV_NUM_PROPS);
74 + case ZFS_TYPE_COS:
75 + return (COS_NUM_PROPS);
76 + default:
67 77 return (ZFS_NUM_PROPS);
78 + }
68 79 }
69 80
70 81 void
71 82 zprop_register_impl(int prop, const char *name, zprop_type_t type,
72 83 uint64_t numdefault, const char *strdefault, zprop_attr_t attr,
73 84 int objset_types, const char *values, const char *colname,
74 85 boolean_t rightalign, boolean_t visible, const zprop_index_t *idx_tbl)
75 86 {
76 87 zprop_desc_t *prop_tbl = zprop_get_proptable(objset_types);
77 88 zprop_desc_t *pd;
78 89
79 90 pd = &prop_tbl[prop];
80 91
81 92 ASSERT(pd->pd_name == NULL || pd->pd_name == name);
82 93 ASSERT(name != NULL);
83 94 ASSERT(colname != NULL);
84 95
85 96 pd->pd_name = name;
86 97 pd->pd_propnum = prop;
87 98 pd->pd_proptype = type;
88 99 pd->pd_numdefault = numdefault;
89 100 pd->pd_strdefault = strdefault;
90 101 pd->pd_attr = attr;
91 102 pd->pd_types = objset_types;
92 103 pd->pd_values = values;
93 104 pd->pd_colname = colname;
94 105 pd->pd_rightalign = rightalign;
95 106 pd->pd_visible = visible;
96 107 pd->pd_table = idx_tbl;
97 108 pd->pd_table_size = 0;
98 109 while (idx_tbl && (idx_tbl++)->pi_name != NULL)
99 110 pd->pd_table_size++;
100 111 }
101 112
102 113 void
103 114 zprop_register_string(int prop, const char *name, const char *def,
104 115 zprop_attr_t attr, int objset_types, const char *values,
105 116 const char *colname)
106 117 {
107 118 zprop_register_impl(prop, name, PROP_TYPE_STRING, 0, def, attr,
108 119 objset_types, values, colname, B_FALSE, B_TRUE, NULL);
109 120
110 121 }
111 122
112 123 void
113 124 zprop_register_number(int prop, const char *name, uint64_t def,
114 125 zprop_attr_t attr, int objset_types, const char *values,
115 126 const char *colname)
116 127 {
117 128 zprop_register_impl(prop, name, PROP_TYPE_NUMBER, def, NULL, attr,
118 129 objset_types, values, colname, B_TRUE, B_TRUE, NULL);
119 130 }
|
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
120 131
121 132 void
122 133 zprop_register_index(int prop, const char *name, uint64_t def,
123 134 zprop_attr_t attr, int objset_types, const char *values,
124 135 const char *colname, const zprop_index_t *idx_tbl)
125 136 {
126 137 zprop_register_impl(prop, name, PROP_TYPE_INDEX, def, NULL, attr,
127 138 objset_types, values, colname, B_TRUE, B_TRUE, idx_tbl);
128 139 }
129 140
141 +/* Same as zprop_register_index, except the property is hidden */
142 +void
143 +zprop_register_index_hidden(int prop, const char *name, uint64_t def,
144 + zprop_attr_t attr, int objset_types, const char *values,
145 + const char *colname, const zprop_index_t *idx_tbl)
146 +{
147 + zprop_register_impl(prop, name, PROP_TYPE_INDEX, def, NULL, attr,
148 + objset_types, values, colname, B_TRUE, B_FALSE, idx_tbl);
149 +}
150 +
130 151 void
131 152 zprop_register_hidden(int prop, const char *name, zprop_type_t type,
132 153 zprop_attr_t attr, int objset_types, const char *colname)
133 154 {
134 155 zprop_register_impl(prop, name, type, 0, NULL, attr,
135 156 objset_types, NULL, colname,
136 157 type == PROP_TYPE_NUMBER, B_FALSE, NULL);
137 158 }
138 159
139 160
140 161 /*
141 162 * A comparison function we can use to order indexes into property tables.
142 163 */
143 164 static int
144 165 zprop_compare(const void *arg1, const void *arg2)
145 166 {
146 167 const zprop_desc_t *p1 = *((zprop_desc_t **)arg1);
147 168 const zprop_desc_t *p2 = *((zprop_desc_t **)arg2);
148 169 boolean_t p1ro, p2ro;
149 170
150 171 p1ro = (p1->pd_attr == PROP_READONLY);
151 172 p2ro = (p2->pd_attr == PROP_READONLY);
152 173
153 174 if (p1ro == p2ro)
154 175 return (strcmp(p1->pd_name, p2->pd_name));
155 176
156 177 return (p1ro ? -1 : 1);
157 178 }
158 179
159 180 /*
160 181 * Iterate over all properties in the given property table, calling back
161 182 * into the specified function for each property. We will continue to
162 183 * iterate until we either reach the end or the callback function returns
163 184 * something other than ZPROP_CONT.
164 185 */
165 186 int
166 187 zprop_iter_common(zprop_func func, void *cb, boolean_t show_all,
167 188 boolean_t ordered, zfs_type_t type)
168 189 {
169 190 int i, num_props, size, prop;
170 191 zprop_desc_t *prop_tbl;
171 192 zprop_desc_t **order;
172 193
173 194 prop_tbl = zprop_get_proptable(type);
174 195 num_props = zprop_get_numprops(type);
175 196 size = num_props * sizeof (zprop_desc_t *);
176 197
177 198 #if defined(_KERNEL)
178 199 order = kmem_alloc(size, KM_SLEEP);
179 200 #else
180 201 if ((order = malloc(size)) == NULL)
181 202 return (ZPROP_CONT);
182 203 #endif
183 204
184 205 for (int j = 0; j < num_props; j++)
185 206 order[j] = &prop_tbl[j];
186 207
187 208 if (ordered) {
188 209 qsort((void *)order, num_props, sizeof (zprop_desc_t *),
189 210 zprop_compare);
190 211 }
191 212
192 213 prop = ZPROP_CONT;
193 214 for (i = 0; i < num_props; i++) {
194 215 if ((order[i]->pd_visible || show_all) &&
195 216 (func(order[i]->pd_propnum, cb) != ZPROP_CONT)) {
196 217 prop = order[i]->pd_propnum;
197 218 break;
198 219 }
199 220 }
200 221
201 222 #if defined(_KERNEL)
202 223 kmem_free(order, size);
203 224 #else
204 225 free(order);
205 226 #endif
206 227 return (prop);
207 228 }
208 229
209 230 static boolean_t
210 231 propname_match(const char *p, size_t len, zprop_desc_t *prop_entry)
211 232 {
212 233 const char *propname = prop_entry->pd_name;
213 234 #ifndef _KERNEL
214 235 const char *colname = prop_entry->pd_colname;
215 236 int c;
216 237 #endif
217 238
218 239 if (len == strlen(propname) &&
219 240 strncmp(p, propname, len) == 0)
220 241 return (B_TRUE);
221 242
222 243 #ifndef _KERNEL
223 244 if (colname == NULL || len != strlen(colname))
224 245 return (B_FALSE);
225 246
226 247 for (c = 0; c < len; c++)
227 248 if (p[c] != tolower(colname[c]))
228 249 break;
229 250
230 251 return (colname[c] == '\0');
231 252 #else
232 253 return (B_FALSE);
233 254 #endif
234 255 }
235 256
236 257 typedef struct name_to_prop_cb {
237 258 const char *propname;
238 259 zprop_desc_t *prop_tbl;
239 260 } name_to_prop_cb_t;
240 261
241 262 static int
242 263 zprop_name_to_prop_cb(int prop, void *cb_data)
243 264 {
244 265 name_to_prop_cb_t *data = cb_data;
245 266
246 267 if (propname_match(data->propname, strlen(data->propname),
247 268 &data->prop_tbl[prop]))
248 269 return (prop);
249 270
250 271 return (ZPROP_CONT);
251 272 }
252 273
253 274 int
254 275 zprop_name_to_prop(const char *propname, zfs_type_t type)
255 276 {
256 277 int prop;
257 278 name_to_prop_cb_t cb_data;
258 279
259 280 cb_data.propname = propname;
260 281 cb_data.prop_tbl = zprop_get_proptable(type);
261 282
262 283 prop = zprop_iter_common(zprop_name_to_prop_cb, &cb_data,
263 284 B_TRUE, B_FALSE, type);
264 285
265 286 return (prop == ZPROP_CONT ? ZPROP_INVAL : prop);
266 287 }
267 288
268 289 int
269 290 zprop_string_to_index(int prop, const char *string, uint64_t *index,
270 291 zfs_type_t type)
271 292 {
272 293 zprop_desc_t *prop_tbl;
273 294 const zprop_index_t *idx_tbl;
274 295 int i;
275 296
276 297 if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
277 298 return (-1);
278 299
279 300 ASSERT(prop < zprop_get_numprops(type));
280 301 prop_tbl = zprop_get_proptable(type);
281 302 if ((idx_tbl = prop_tbl[prop].pd_table) == NULL)
282 303 return (-1);
283 304
284 305 for (i = 0; idx_tbl[i].pi_name != NULL; i++) {
285 306 if (strcmp(string, idx_tbl[i].pi_name) == 0) {
286 307 *index = idx_tbl[i].pi_value;
287 308 return (0);
288 309 }
289 310 }
290 311
291 312 return (-1);
292 313 }
293 314
294 315 int
295 316 zprop_index_to_string(int prop, uint64_t index, const char **string,
296 317 zfs_type_t type)
297 318 {
298 319 zprop_desc_t *prop_tbl;
299 320 const zprop_index_t *idx_tbl;
300 321 int i;
301 322
302 323 if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
303 324 return (-1);
304 325
305 326 ASSERT(prop < zprop_get_numprops(type));
306 327 prop_tbl = zprop_get_proptable(type);
307 328 if ((idx_tbl = prop_tbl[prop].pd_table) == NULL)
308 329 return (-1);
309 330
310 331 for (i = 0; idx_tbl[i].pi_name != NULL; i++) {
311 332 if (idx_tbl[i].pi_value == index) {
312 333 *string = idx_tbl[i].pi_name;
313 334 return (0);
314 335 }
315 336 }
316 337
317 338 return (-1);
318 339 }
319 340
320 341 /*
321 342 * Return a random valid property value. Used by ztest.
322 343 */
323 344 uint64_t
324 345 zprop_random_value(int prop, uint64_t seed, zfs_type_t type)
325 346 {
326 347 zprop_desc_t *prop_tbl;
327 348 const zprop_index_t *idx_tbl;
328 349
329 350 ASSERT((uint_t)prop < zprop_get_numprops(type));
330 351 prop_tbl = zprop_get_proptable(type);
331 352 idx_tbl = prop_tbl[prop].pd_table;
332 353
333 354 if (idx_tbl == NULL)
334 355 return (seed);
335 356
336 357 return (idx_tbl[seed % prop_tbl[prop].pd_table_size].pi_value);
337 358 }
338 359
339 360 const char *
340 361 zprop_values(int prop, zfs_type_t type)
341 362 {
342 363 zprop_desc_t *prop_tbl;
343 364
344 365 ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
345 366 ASSERT(prop < zprop_get_numprops(type));
346 367
347 368 prop_tbl = zprop_get_proptable(type);
348 369
349 370 return (prop_tbl[prop].pd_values);
350 371 }
351 372
352 373 /*
353 374 * Returns TRUE if the property applies to any of the given dataset types.
354 375 */
355 376 boolean_t
356 377 zprop_valid_for_type(int prop, zfs_type_t type)
357 378 {
358 379 zprop_desc_t *prop_tbl;
359 380
360 381 if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
361 382 return (B_FALSE);
362 383
363 384 ASSERT(prop < zprop_get_numprops(type));
364 385 prop_tbl = zprop_get_proptable(type);
365 386 return ((prop_tbl[prop].pd_types & type) != 0);
366 387 }
367 388
368 389 #ifndef _KERNEL
369 390
370 391 /*
371 392 * Determines the minimum width for the column, and indicates whether it's fixed
372 393 * or not. Only string columns are non-fixed.
373 394 */
374 395 size_t
375 396 zprop_width(int prop, boolean_t *fixed, zfs_type_t type)
376 397 {
377 398 zprop_desc_t *prop_tbl, *pd;
378 399 const zprop_index_t *idx;
379 400 size_t ret;
380 401 int i;
381 402
382 403 ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
383 404 ASSERT(prop < zprop_get_numprops(type));
384 405
385 406 prop_tbl = zprop_get_proptable(type);
386 407 pd = &prop_tbl[prop];
387 408
388 409 *fixed = B_TRUE;
389 410
390 411 /*
391 412 * Start with the width of the column name.
392 413 */
393 414 ret = strlen(pd->pd_colname);
394 415
395 416 /*
396 417 * For fixed-width values, make sure the width is large enough to hold
397 418 * any possible value.
398 419 */
399 420 switch (pd->pd_proptype) {
400 421 case PROP_TYPE_NUMBER:
401 422 /*
402 423 * The maximum length of a human-readable number is 5 characters
403 424 * ("20.4M", for example).
404 425 */
405 426 if (ret < 5)
406 427 ret = 5;
407 428 /*
408 429 * 'creation' is handled specially because it's a number
409 430 * internally, but displayed as a date string.
410 431 */
411 432 if (prop == ZFS_PROP_CREATION)
412 433 *fixed = B_FALSE;
413 434 break;
414 435 case PROP_TYPE_INDEX:
415 436 idx = prop_tbl[prop].pd_table;
416 437 for (i = 0; idx[i].pi_name != NULL; i++) {
417 438 if (strlen(idx[i].pi_name) > ret)
418 439 ret = strlen(idx[i].pi_name);
419 440 }
420 441 break;
421 442
422 443 case PROP_TYPE_STRING:
423 444 *fixed = B_FALSE;
424 445 break;
425 446 }
426 447
427 448 return (ret);
428 449 }
429 450
430 451 #endif
|
↓ open down ↓ |
291 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX