Print this page
2619 asynchronous destruction of ZFS file systems
2747 SPA versioning with zfs feature flags
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <gwilson@delphix.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Dan Kruchinin <dan.kruchinin@gmail.com>
Approved by: Dan McDonald <danmcd@nexenta.com>
   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
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  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 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*




  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 
  35 #include <errno.h>
  36 #include <sys/stat.h>
  37 #include <fcntl.h>
  38 #include <stddef.h>
  39 #include <string.h>
  40 #include <unistd.h>
  41 #include <libintl.h>
  42 #include <libuutil.h>
  43 
  44 #include "libzfs_impl.h"
  45 
  46 typedef struct config_node {


 200 
 201                 uu_avl_insert(hdl->libzfs_ns_avl, cn, where);
 202         }
 203 
 204         nvlist_free(config);
 205         return (0);
 206 }
 207 
 208 /*
 209  * Retrieve the configuration for the given pool.  The configuration is a nvlist
 210  * describing the vdevs, as well as the statistics associated with each one.
 211  */
 212 nvlist_t *
 213 zpool_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 /*
 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  */
 226 int
 227 zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing)
 228 {
 229         zfs_cmd_t zc = { 0 };
 230         int error;
 231         nvlist_t *config;
 232         libzfs_handle_t *hdl = zhp->zpool_hdl;
 233 
 234         *missing = B_FALSE;
 235         (void) strcpy(zc.zc_name, zhp->zpool_name);
 236 
 237         if (zhp->zpool_config_size == 0)
 238                 zhp->zpool_config_size = 1 << 16;
 239 


   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
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  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 
  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 /*
  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 
  40 #include <errno.h>
  41 #include <sys/stat.h>
  42 #include <fcntl.h>
  43 #include <stddef.h>
  44 #include <string.h>
  45 #include <unistd.h>
  46 #include <libintl.h>
  47 #include <libuutil.h>
  48 
  49 #include "libzfs_impl.h"
  50 
  51 typedef struct config_node {


 205 
 206                 uu_avl_insert(hdl->libzfs_ns_avl, cn, where);
 207         }
 208 
 209         nvlist_free(config);
 210         return (0);
 211 }
 212 
 213 /*
 214  * Retrieve the configuration for the given pool.  The configuration is a nvlist
 215  * describing the vdevs, as well as the statistics associated with each one.
 216  */
 217 nvlist_t *
 218 zpool_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  */
 229 nvlist_t *
 230 zpool_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 /*
 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  */
 261 int
 262 zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing)
 263 {
 264         zfs_cmd_t zc = { 0 };
 265         int error;
 266         nvlist_t *config;
 267         libzfs_handle_t *hdl = zhp->zpool_hdl;
 268 
 269         *missing = B_FALSE;
 270         (void) strcpy(zc.zc_name, zhp->zpool_name);
 271 
 272         if (zhp->zpool_config_size == 0)
 273                 zhp->zpool_config_size = 1 << 16;
 274