1b7b97454Sperrin /* 2b7b97454Sperrin * CDDL HEADER START 3b7b97454Sperrin * 4b7b97454Sperrin * The contents of this file are subject to the terms of the 5b7b97454Sperrin * Common Development and Distribution License (the "License"). 6b7b97454Sperrin * You may not use this file except in compliance with the License. 7b7b97454Sperrin * 8b7b97454Sperrin * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9b7b97454Sperrin * or http://www.opensolaris.org/os/licensing. 10b7b97454Sperrin * See the License for the specific language governing permissions 11b7b97454Sperrin * and limitations under the License. 12b7b97454Sperrin * 13b7b97454Sperrin * When distributing Covered Code, include this CDDL HEADER in each 14b7b97454Sperrin * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15b7b97454Sperrin * If applicable, add the following below this CDDL HEADER, with the 16b7b97454Sperrin * fields enclosed by brackets "[]" replaced with your own identifying 17b7b97454Sperrin * information: Portions Copyright [yyyy] [name of copyright owner] 18b7b97454Sperrin * 19b7b97454Sperrin * CDDL HEADER END 20b7b97454Sperrin */ 21b7b97454Sperrin /* 22*468c413aSTim Haley * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23b7b97454Sperrin * Use is subject to license terms. 24b7b97454Sperrin */ 25b7b97454Sperrin 26b7b97454Sperrin /* 27b7b97454Sperrin * This file is intended for functions that ought to be common between user 28b7b97454Sperrin * land (libzfs) and the kernel. When many common routines need to be shared 29b7b97454Sperrin * then a separate file should to be created. 30b7b97454Sperrin */ 31b7b97454Sperrin 32b7b97454Sperrin #if defined(_KERNEL) 33b7b97454Sperrin #include <sys/systm.h> 34*468c413aSTim Haley #else 35*468c413aSTim Haley #include <string.h> 36b7b97454Sperrin #endif 37b7b97454Sperrin 38b7b97454Sperrin #include <sys/types.h> 39b7b97454Sperrin #include <sys/fs/zfs.h> 40*468c413aSTim Haley #include <sys/int_limits.h> 41b7b97454Sperrin #include <sys/nvpair.h> 42b7b97454Sperrin 43b7b97454Sperrin /* 44b7b97454Sperrin * Are there allocatable vdevs? 45b7b97454Sperrin */ 46b7b97454Sperrin boolean_t 47b7b97454Sperrin zfs_allocatable_devs(nvlist_t *nv) 48b7b97454Sperrin { 49b7b97454Sperrin uint64_t is_log; 50b7b97454Sperrin uint_t c; 51b7b97454Sperrin nvlist_t **child; 52b7b97454Sperrin uint_t children; 53b7b97454Sperrin 54b7b97454Sperrin if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, 55b7b97454Sperrin &child, &children) != 0) { 56b7b97454Sperrin return (B_FALSE); 57b7b97454Sperrin } 58b7b97454Sperrin for (c = 0; c < children; c++) { 59b7b97454Sperrin is_log = 0; 60b7b97454Sperrin (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG, 61b7b97454Sperrin &is_log); 62b7b97454Sperrin if (!is_log) 63b7b97454Sperrin return (B_TRUE); 64b7b97454Sperrin } 65b7b97454Sperrin return (B_FALSE); 66b7b97454Sperrin } 67*468c413aSTim Haley 68*468c413aSTim Haley void 69*468c413aSTim Haley zpool_get_rewind_policy(nvlist_t *nvl, zpool_rewind_policy_t *zrpp) 70*468c413aSTim Haley { 71*468c413aSTim Haley nvlist_t *policy; 72*468c413aSTim Haley nvpair_t *elem; 73*468c413aSTim Haley char *nm; 74*468c413aSTim Haley 75*468c413aSTim Haley /* Defaults */ 76*468c413aSTim Haley zrpp->zrp_request = ZPOOL_NO_REWIND; 77*468c413aSTim Haley zrpp->zrp_maxmeta = 0; 78*468c413aSTim Haley zrpp->zrp_maxdata = UINT32_MAX; 79*468c413aSTim Haley zrpp->zrp_txg = UINT64_MAX; 80*468c413aSTim Haley 81*468c413aSTim Haley if (nvl == NULL) 82*468c413aSTim Haley return; 83*468c413aSTim Haley 84*468c413aSTim Haley elem = NULL; 85*468c413aSTim Haley while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) { 86*468c413aSTim Haley nm = nvpair_name(elem); 87*468c413aSTim Haley if (strcmp(nm, ZPOOL_REWIND_POLICY) == 0) { 88*468c413aSTim Haley if (nvpair_value_nvlist(elem, &policy) == 0) 89*468c413aSTim Haley zpool_get_rewind_policy(policy, zrpp); 90*468c413aSTim Haley return; 91*468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_REQUEST) == 0) { 92*468c413aSTim Haley if (nvpair_value_uint32(elem, 93*468c413aSTim Haley &zrpp->zrp_request) == 0) 94*468c413aSTim Haley if (zrpp->zrp_request & ~ZPOOL_REWIND_MASK) 95*468c413aSTim Haley zrpp->zrp_request = ZPOOL_NO_REWIND; 96*468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_REQUEST_TXG) == 0) { 97*468c413aSTim Haley (void) nvpair_value_uint64(elem, &zrpp->zrp_txg); 98*468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_META_THRESH) == 0) { 99*468c413aSTim Haley (void) nvpair_value_uint32(elem, &zrpp->zrp_maxmeta); 100*468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_DATA_THRESH) == 0) { 101*468c413aSTim Haley (void) nvpair_value_uint32(elem, &zrpp->zrp_maxdata); 102*468c413aSTim Haley } 103*468c413aSTim Haley } 104*468c413aSTim Haley } 105