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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 
  25 /*
  26  * This file contains the functions which analyze the status of a pool.  This
  27  * include both the status of an active pool, as well as the status exported
  28  * pools.  Returns one of the ZPOOL_STATUS_* defines describing the status of
  29  * the pool.  This status is independent (to a certain degree) from the state of
  30  * the pool.  A pool's state describes only whether or not it is capable of
  31  * providing the necessary fault tolerance for data.  The status describes the
  32  * overall status of devices.  A pool that is online can still have a device
  33  * that is experiencing errors.
  34  *
  35  * Only a subset of the possible faults can be detected using 'zpool status',
  36  * and not all possible errors correspond to a FMA message ID.  The explanation
  37  * is left up to the caller, depending on whether it is a live pool or an
  38  * import.
  39  */
  40 
  41 #include <libzfs.h>
  42 #include <string.h>


 197         if (ps && ps->pss_func == POOL_SCAN_RESILVER &&
 198             ps->pss_state == DSS_SCANNING)
 199                 return (ZPOOL_STATUS_RESILVERING);
 200 
 201         /*
 202          * Pool last accessed by another system.
 203          */
 204         (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
 205         if (hostid != 0 && (unsigned long)hostid != gethostid() &&
 206             stateval == POOL_STATE_ACTIVE)
 207                 return (ZPOOL_STATUS_HOSTID_MISMATCH);
 208 
 209         /*
 210          * Newer on-disk version.
 211          */
 212         if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
 213             vs->vs_aux == VDEV_AUX_VERSION_NEWER)
 214                 return (ZPOOL_STATUS_VERSION_NEWER);
 215 
 216         /*














 217          * Check that the config is complete.
 218          */
 219         if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
 220             vs->vs_aux == VDEV_AUX_BAD_GUID_SUM)
 221                 return (ZPOOL_STATUS_BAD_GUID_SUM);
 222 
 223         /*
 224          * Check whether the pool has suspended due to failed I/O.
 225          */
 226         if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED,
 227             &suspended) == 0) {
 228                 if (suspended == ZIO_FAILURE_MODE_CONTINUE)
 229                         return (ZPOOL_STATUS_IO_FAILURE_CONTINUE);
 230                 return (ZPOOL_STATUS_IO_FAILURE_WAIT);
 231         }
 232 
 233         /*
 234          * Could not read a log.
 235          */
 236         if (vs->vs_state == VDEV_STATE_CANT_OPEN &&


 283          * Devices with errors
 284          */
 285         if (!isimport && find_vdev_problem(nvroot, vdev_errors))
 286                 return (ZPOOL_STATUS_FAILING_DEV);
 287 
 288         /*
 289          * Offlined devices
 290          */
 291         if (find_vdev_problem(nvroot, vdev_offlined))
 292                 return (ZPOOL_STATUS_OFFLINE_DEV);
 293 
 294         /*
 295          * Removed device
 296          */
 297         if (find_vdev_problem(nvroot, vdev_removed))
 298                 return (ZPOOL_STATUS_REMOVED_DEV);
 299 
 300         /*
 301          * Outdated, but usable, version
 302          */
 303         if (version < SPA_VERSION)
 304                 return (ZPOOL_STATUS_VERSION_OLDER);
 305 
 306         return (ZPOOL_STATUS_OK);
 307 }
 308 
 309 zpool_status_t
 310 zpool_get_status(zpool_handle_t *zhp, char **msgid)
 311 {
 312         zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE);
 313 
 314         if (ret >= NMSGID)
 315                 *msgid = NULL;
 316         else
 317                 *msgid = zfs_msgid_table[ret];
 318 
 319         return (ret);
 320 }
 321 
 322 zpool_status_t
 323 zpool_import_status(nvlist_t *config, char **msgid)


   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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  */
  26 
  27 /*
  28  * This file contains the functions which analyze the status of a pool.  This
  29  * include both the status of an active pool, as well as the status exported
  30  * pools.  Returns one of the ZPOOL_STATUS_* defines describing the status of
  31  * the pool.  This status is independent (to a certain degree) from the state of
  32  * the pool.  A pool's state describes only whether or not it is capable of
  33  * providing the necessary fault tolerance for data.  The status describes the
  34  * overall status of devices.  A pool that is online can still have a device
  35  * that is experiencing errors.
  36  *
  37  * Only a subset of the possible faults can be detected using 'zpool status',
  38  * and not all possible errors correspond to a FMA message ID.  The explanation
  39  * is left up to the caller, depending on whether it is a live pool or an
  40  * import.
  41  */
  42 
  43 #include <libzfs.h>
  44 #include <string.h>


 199         if (ps && ps->pss_func == POOL_SCAN_RESILVER &&
 200             ps->pss_state == DSS_SCANNING)
 201                 return (ZPOOL_STATUS_RESILVERING);
 202 
 203         /*
 204          * Pool last accessed by another system.
 205          */
 206         (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
 207         if (hostid != 0 && (unsigned long)hostid != gethostid() &&
 208             stateval == POOL_STATE_ACTIVE)
 209                 return (ZPOOL_STATUS_HOSTID_MISMATCH);
 210 
 211         /*
 212          * Newer on-disk version.
 213          */
 214         if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
 215             vs->vs_aux == VDEV_AUX_VERSION_NEWER)
 216                 return (ZPOOL_STATUS_VERSION_NEWER);
 217 
 218         /*
 219          * Unsupported feature(s).
 220          */
 221         if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
 222             vs->vs_aux == VDEV_AUX_UNSUP_FEAT) {
 223                 nvlist_t *nvinfo;
 224 
 225                 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,
 226                     &nvinfo) == 0);
 227                 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY))
 228                         return (ZPOOL_STATUS_UNSUP_FEAT_WRITE);
 229                 return (ZPOOL_STATUS_UNSUP_FEAT_READ);
 230         }
 231 
 232         /*
 233          * Check that the config is complete.
 234          */
 235         if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
 236             vs->vs_aux == VDEV_AUX_BAD_GUID_SUM)
 237                 return (ZPOOL_STATUS_BAD_GUID_SUM);
 238 
 239         /*
 240          * Check whether the pool has suspended due to failed I/O.
 241          */
 242         if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED,
 243             &suspended) == 0) {
 244                 if (suspended == ZIO_FAILURE_MODE_CONTINUE)
 245                         return (ZPOOL_STATUS_IO_FAILURE_CONTINUE);
 246                 return (ZPOOL_STATUS_IO_FAILURE_WAIT);
 247         }
 248 
 249         /*
 250          * Could not read a log.
 251          */
 252         if (vs->vs_state == VDEV_STATE_CANT_OPEN &&


 299          * Devices with errors
 300          */
 301         if (!isimport && find_vdev_problem(nvroot, vdev_errors))
 302                 return (ZPOOL_STATUS_FAILING_DEV);
 303 
 304         /*
 305          * Offlined devices
 306          */
 307         if (find_vdev_problem(nvroot, vdev_offlined))
 308                 return (ZPOOL_STATUS_OFFLINE_DEV);
 309 
 310         /*
 311          * Removed device
 312          */
 313         if (find_vdev_problem(nvroot, vdev_removed))
 314                 return (ZPOOL_STATUS_REMOVED_DEV);
 315 
 316         /*
 317          * Outdated, but usable, version
 318          */
 319         if (SPA_VERSION_IS_SUPPORTED(version) && version != SPA_VERSION)
 320                 return (ZPOOL_STATUS_VERSION_OLDER);
 321 
 322         return (ZPOOL_STATUS_OK);
 323 }
 324 
 325 zpool_status_t
 326 zpool_get_status(zpool_handle_t *zhp, char **msgid)
 327 {
 328         zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE);
 329 
 330         if (ret >= NMSGID)
 331                 *msgid = NULL;
 332         else
 333                 *msgid = zfs_msgid_table[ret];
 334 
 335         return (ret);
 336 }
 337 
 338 zpool_status_t
 339 zpool_import_status(nvlist_t *config, char **msgid)