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*c8ee1847SVictor Latushkin * Copyright 2010 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> 34468c413aSTim Haley #else 35468c413aSTim Haley #include <string.h> 36b7b97454Sperrin #endif 37b7b97454Sperrin 38b7b97454Sperrin #include <sys/types.h> 39b7b97454Sperrin #include <sys/fs/zfs.h> 40468c413aSTim 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 } 67468c413aSTim Haley 68468c413aSTim Haley void 69468c413aSTim Haley zpool_get_rewind_policy(nvlist_t *nvl, zpool_rewind_policy_t *zrpp) 70468c413aSTim Haley { 71468c413aSTim Haley nvlist_t *policy; 72468c413aSTim Haley nvpair_t *elem; 73468c413aSTim Haley char *nm; 74468c413aSTim Haley 75468c413aSTim Haley /* Defaults */ 76468c413aSTim Haley zrpp->zrp_request = ZPOOL_NO_REWIND; 77468c413aSTim Haley zrpp->zrp_maxmeta = 0; 78*c8ee1847SVictor Latushkin zrpp->zrp_maxdata = UINT64_MAX; 79468c413aSTim Haley zrpp->zrp_txg = UINT64_MAX; 80468c413aSTim Haley 81468c413aSTim Haley if (nvl == NULL) 82468c413aSTim Haley return; 83468c413aSTim Haley 84468c413aSTim Haley elem = NULL; 85468c413aSTim Haley while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) { 86468c413aSTim Haley nm = nvpair_name(elem); 87468c413aSTim Haley if (strcmp(nm, ZPOOL_REWIND_POLICY) == 0) { 88468c413aSTim Haley if (nvpair_value_nvlist(elem, &policy) == 0) 89468c413aSTim Haley zpool_get_rewind_policy(policy, zrpp); 90468c413aSTim Haley return; 91468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_REQUEST) == 0) { 92*c8ee1847SVictor Latushkin if (nvpair_value_uint32(elem, &zrpp->zrp_request) == 0) 93*c8ee1847SVictor Latushkin if (zrpp->zrp_request & ~ZPOOL_REWIND_POLICIES) 94468c413aSTim Haley zrpp->zrp_request = ZPOOL_NO_REWIND; 95468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_REQUEST_TXG) == 0) { 96468c413aSTim Haley (void) nvpair_value_uint64(elem, &zrpp->zrp_txg); 97468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_META_THRESH) == 0) { 98*c8ee1847SVictor Latushkin (void) nvpair_value_uint64(elem, &zrpp->zrp_maxmeta); 99468c413aSTim Haley } else if (strcmp(nm, ZPOOL_REWIND_DATA_THRESH) == 0) { 100*c8ee1847SVictor Latushkin (void) nvpair_value_uint64(elem, &zrpp->zrp_maxdata); 101468c413aSTim Haley } 102468c413aSTim Haley } 103*c8ee1847SVictor Latushkin if (zrpp->zrp_request == 0) 104*c8ee1847SVictor Latushkin zrpp->zrp_request = ZPOOL_NO_REWIND; 105468c413aSTim Haley } 106