15913Sperrin /* 25913Sperrin * CDDL HEADER START 35913Sperrin * 45913Sperrin * The contents of this file are subject to the terms of the 55913Sperrin * Common Development and Distribution License (the "License"). 65913Sperrin * You may not use this file except in compliance with the License. 75913Sperrin * 85913Sperrin * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95913Sperrin * or http://www.opensolaris.org/os/licensing. 105913Sperrin * See the License for the specific language governing permissions 115913Sperrin * and limitations under the License. 125913Sperrin * 135913Sperrin * When distributing Covered Code, include this CDDL HEADER in each 145913Sperrin * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155913Sperrin * If applicable, add the following below this CDDL HEADER, with the 165913Sperrin * fields enclosed by brackets "[]" replaced with your own identifying 175913Sperrin * information: Portions Copyright [yyyy] [name of copyright owner] 185913Sperrin * 195913Sperrin * CDDL HEADER END 205913Sperrin */ 215913Sperrin /* 22*10921STim.Haley@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 235913Sperrin * Use is subject to license terms. 245913Sperrin */ 255913Sperrin 265913Sperrin /* 275913Sperrin * This file is intended for functions that ought to be common between user 285913Sperrin * land (libzfs) and the kernel. When many common routines need to be shared 295913Sperrin * then a separate file should to be created. 305913Sperrin */ 315913Sperrin 325913Sperrin #if defined(_KERNEL) 335913Sperrin #include <sys/systm.h> 34*10921STim.Haley@Sun.COM #else 35*10921STim.Haley@Sun.COM #include <string.h> 365913Sperrin #endif 375913Sperrin 385913Sperrin #include <sys/types.h> 395913Sperrin #include <sys/fs/zfs.h> 40*10921STim.Haley@Sun.COM #include <sys/int_limits.h> 415913Sperrin #include <sys/nvpair.h> 425913Sperrin 435913Sperrin /* 445913Sperrin * Are there allocatable vdevs? 455913Sperrin */ 465913Sperrin boolean_t 475913Sperrin zfs_allocatable_devs(nvlist_t *nv) 485913Sperrin { 495913Sperrin uint64_t is_log; 505913Sperrin uint_t c; 515913Sperrin nvlist_t **child; 525913Sperrin uint_t children; 535913Sperrin 545913Sperrin if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, 555913Sperrin &child, &children) != 0) { 565913Sperrin return (B_FALSE); 575913Sperrin } 585913Sperrin for (c = 0; c < children; c++) { 595913Sperrin is_log = 0; 605913Sperrin (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG, 615913Sperrin &is_log); 625913Sperrin if (!is_log) 635913Sperrin return (B_TRUE); 645913Sperrin } 655913Sperrin return (B_FALSE); 665913Sperrin } 67*10921STim.Haley@Sun.COM 68*10921STim.Haley@Sun.COM void 69*10921STim.Haley@Sun.COM zpool_get_rewind_policy(nvlist_t *nvl, zpool_rewind_policy_t *zrpp) 70*10921STim.Haley@Sun.COM { 71*10921STim.Haley@Sun.COM nvlist_t *policy; 72*10921STim.Haley@Sun.COM nvpair_t *elem; 73*10921STim.Haley@Sun.COM char *nm; 74*10921STim.Haley@Sun.COM 75*10921STim.Haley@Sun.COM /* Defaults */ 76*10921STim.Haley@Sun.COM zrpp->zrp_request = ZPOOL_NO_REWIND; 77*10921STim.Haley@Sun.COM zrpp->zrp_maxmeta = 0; 78*10921STim.Haley@Sun.COM zrpp->zrp_maxdata = UINT32_MAX; 79*10921STim.Haley@Sun.COM zrpp->zrp_txg = UINT64_MAX; 80*10921STim.Haley@Sun.COM 81*10921STim.Haley@Sun.COM if (nvl == NULL) 82*10921STim.Haley@Sun.COM return; 83*10921STim.Haley@Sun.COM 84*10921STim.Haley@Sun.COM elem = NULL; 85*10921STim.Haley@Sun.COM while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) { 86*10921STim.Haley@Sun.COM nm = nvpair_name(elem); 87*10921STim.Haley@Sun.COM if (strcmp(nm, ZPOOL_REWIND_POLICY) == 0) { 88*10921STim.Haley@Sun.COM if (nvpair_value_nvlist(elem, &policy) == 0) 89*10921STim.Haley@Sun.COM zpool_get_rewind_policy(policy, zrpp); 90*10921STim.Haley@Sun.COM return; 91*10921STim.Haley@Sun.COM } else if (strcmp(nm, ZPOOL_REWIND_REQUEST) == 0) { 92*10921STim.Haley@Sun.COM if (nvpair_value_uint32(elem, 93*10921STim.Haley@Sun.COM &zrpp->zrp_request) == 0) 94*10921STim.Haley@Sun.COM if (zrpp->zrp_request & ~ZPOOL_REWIND_MASK) 95*10921STim.Haley@Sun.COM zrpp->zrp_request = ZPOOL_NO_REWIND; 96*10921STim.Haley@Sun.COM } else if (strcmp(nm, ZPOOL_REWIND_REQUEST_TXG) == 0) { 97*10921STim.Haley@Sun.COM (void) nvpair_value_uint64(elem, &zrpp->zrp_txg); 98*10921STim.Haley@Sun.COM } else if (strcmp(nm, ZPOOL_REWIND_META_THRESH) == 0) { 99*10921STim.Haley@Sun.COM (void) nvpair_value_uint32(elem, &zrpp->zrp_maxmeta); 100*10921STim.Haley@Sun.COM } else if (strcmp(nm, ZPOOL_REWIND_DATA_THRESH) == 0) { 101*10921STim.Haley@Sun.COM (void) nvpair_value_uint32(elem, &zrpp->zrp_maxdata); 102*10921STim.Haley@Sun.COM } 103*10921STim.Haley@Sun.COM } 104*10921STim.Haley@Sun.COM } 105