libzfs_config.c (225736) | libzfs_config.c (243674) |
---|---|
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 --- 4 unchanged lines hidden (view full) --- 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 */ | 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 --- 4 unchanged lines hidden (view full) --- 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 |
|
21/* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26/* | 22/* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27/* |
28 * Copyright (c) 2012 by Delphix. All rights reserved. 29 */ 30 31/* |
|
27 * The pool configuration repository is stored in /etc/zfs/zpool.cache as a 28 * single packed nvlist. While it would be nice to just read in this 29 * file from userland, this wouldn't work from a local zone. So we have to have 30 * a zpool ioctl to return the complete configuration for all pools. In the 31 * global zone, this will be identical to reading the file and unpacking it in 32 * userland. 33 */ 34 --- 178 unchanged lines hidden (view full) --- 213zpool_get_config(zpool_handle_t *zhp, nvlist_t **oldconfig) 214{ 215 if (oldconfig) 216 *oldconfig = zhp->zpool_old_config; 217 return (zhp->zpool_config); 218} 219 220/* | 32 * The pool configuration repository is stored in /etc/zfs/zpool.cache as a 33 * single packed nvlist. While it would be nice to just read in this 34 * file from userland, this wouldn't work from a local zone. So we have to have 35 * a zpool ioctl to return the complete configuration for all pools. In the 36 * global zone, this will be identical to reading the file and unpacking it in 37 * userland. 38 */ 39 --- 178 unchanged lines hidden (view full) --- 218zpool_get_config(zpool_handle_t *zhp, nvlist_t **oldconfig) 219{ 220 if (oldconfig) 221 *oldconfig = zhp->zpool_old_config; 222 return (zhp->zpool_config); 223} 224 225/* |
226 * Retrieves a list of enabled features and their refcounts and caches it in 227 * the pool handle. 228 */ 229nvlist_t * 230zpool_get_features(zpool_handle_t *zhp) 231{ 232 nvlist_t *config, *features; 233 234 config = zpool_get_config(zhp, NULL); 235 236 if (config == NULL || !nvlist_exists(config, 237 ZPOOL_CONFIG_FEATURE_STATS)) { 238 int error; 239 boolean_t missing = B_FALSE; 240 241 error = zpool_refresh_stats(zhp, &missing); 242 243 if (error != 0 || missing) 244 return (NULL); 245 246 config = zpool_get_config(zhp, NULL); 247 } 248 249 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_FEATURE_STATS, 250 &features) == 0); 251 252 return (features); 253} 254 255/* |
|
221 * Refresh the vdev statistics associated with the given pool. This is used in 222 * iostat to show configuration changes and determine the delta from the last 223 * time the function was called. This function can fail, in case the pool has 224 * been destroyed. 225 */ 226int 227zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing) 228{ --- 68 unchanged lines hidden (view full) --- 297 zhp->zpool_state = POOL_STATE_UNAVAIL; 298 else 299 zhp->zpool_state = POOL_STATE_ACTIVE; 300 301 return (0); 302} 303 304/* | 256 * Refresh the vdev statistics associated with the given pool. This is used in 257 * iostat to show configuration changes and determine the delta from the last 258 * time the function was called. This function can fail, in case the pool has 259 * been destroyed. 260 */ 261int 262zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing) 263{ --- 68 unchanged lines hidden (view full) --- 332 zhp->zpool_state = POOL_STATE_UNAVAIL; 333 else 334 zhp->zpool_state = POOL_STATE_ACTIVE; 335 336 return (0); 337} 338 339/* |
340 * If the __ZFS_POOL_RESTRICT environment variable is set we only iterate over 341 * pools it lists. 342 * 343 * This is an undocumented feature for use during testing only. 344 * 345 * This function returns B_TRUE if the pool should be skipped 346 * during iteration. 347 */ 348static boolean_t 349check_restricted(const char *poolname) 350{ 351 static boolean_t initialized = B_FALSE; 352 static char *restricted = NULL; 353 354 const char *cur, *end; 355 int len, namelen; 356 357 if (!initialized) { 358 initialized = B_TRUE; 359 restricted = getenv("__ZFS_POOL_RESTRICT"); 360 } 361 362 if (NULL == restricted) 363 return (B_FALSE); 364 365 cur = restricted; 366 namelen = strlen(poolname); 367 do { 368 end = strchr(cur, ' '); 369 len = (NULL == end) ? strlen(cur) : (end - cur); 370 371 if (len == namelen && 0 == strncmp(cur, poolname, len)) { 372 return (B_FALSE); 373 } 374 375 cur += (len + 1); 376 } while (NULL != end); 377 378 return (B_TRUE); 379} 380 381/* |
|
305 * Iterate over all pools in the system. 306 */ 307int 308zpool_iter(libzfs_handle_t *hdl, zpool_iter_f func, void *data) 309{ 310 config_node_t *cn; 311 zpool_handle_t *zhp; 312 int ret; --- 6 unchanged lines hidden (view full) --- 319 */ 320 if (!hdl->libzfs_pool_iter && namespace_reload(hdl) != 0) 321 return (-1); 322 323 hdl->libzfs_pool_iter++; 324 for (cn = uu_avl_first(hdl->libzfs_ns_avl); cn != NULL; 325 cn = uu_avl_next(hdl->libzfs_ns_avl, cn)) { 326 | 382 * Iterate over all pools in the system. 383 */ 384int 385zpool_iter(libzfs_handle_t *hdl, zpool_iter_f func, void *data) 386{ 387 config_node_t *cn; 388 zpool_handle_t *zhp; 389 int ret; --- 6 unchanged lines hidden (view full) --- 396 */ 397 if (!hdl->libzfs_pool_iter && namespace_reload(hdl) != 0) 398 return (-1); 399 400 hdl->libzfs_pool_iter++; 401 for (cn = uu_avl_first(hdl->libzfs_ns_avl); cn != NULL; 402 cn = uu_avl_next(hdl->libzfs_ns_avl, cn)) { 403 |
404 if (check_restricted(cn->cn_name)) 405 continue; 406 |
|
327 if (zpool_open_silent(hdl, cn->cn_name, &zhp) != 0) { 328 hdl->libzfs_pool_iter--; 329 return (-1); 330 } 331 332 if (zhp == NULL) 333 continue; 334 --- 19 unchanged lines hidden (view full) --- 354 int ret; 355 356 if (namespace_reload(hdl) != 0) 357 return (-1); 358 359 for (cn = uu_avl_first(hdl->libzfs_ns_avl); cn != NULL; 360 cn = uu_avl_next(hdl->libzfs_ns_avl, cn)) { 361 | 407 if (zpool_open_silent(hdl, cn->cn_name, &zhp) != 0) { 408 hdl->libzfs_pool_iter--; 409 return (-1); 410 } 411 412 if (zhp == NULL) 413 continue; 414 --- 19 unchanged lines hidden (view full) --- 434 int ret; 435 436 if (namespace_reload(hdl) != 0) 437 return (-1); 438 439 for (cn = uu_avl_first(hdl->libzfs_ns_avl); cn != NULL; 440 cn = uu_avl_next(hdl->libzfs_ns_avl, cn)) { 441 |
442 if (check_restricted(cn->cn_name)) 443 continue; 444 |
|
362 if ((zhp = make_dataset_handle(hdl, cn->cn_name)) == NULL) 363 continue; 364 365 if ((ret = func(zhp, data)) != 0) 366 return (ret); 367 } 368 369 return (0); 370} | 445 if ((zhp = make_dataset_handle(hdl, cn->cn_name)) == NULL) 446 continue; 447 448 if ((ret = func(zhp, data)) != 0) 449 return (ret); 450 } 451 452 return (0); 453} |