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>


1311 vdev_validate(vdev_t *vd, boolean_t strict)
1312 {
1313         spa_t *spa = vd->vdev_spa;
1314         nvlist_t *label;
1315         uint64_t guid = 0, top_guid;
1316         uint64_t state;
1317 
1318         for (int c = 0; c < vd->vdev_children; c++)
1319                 if (vdev_validate(vd->vdev_child[c], strict) != 0)
1320                         return (EBADF);
1321 
1322         /*
1323          * If the device has already failed, or was marked offline, don't do
1324          * any further validation.  Otherwise, label I/O will fail and we will
1325          * overwrite the previous state.
1326          */
1327         if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) {
1328                 uint64_t aux_guid = 0;
1329                 nvlist_t *nvl;
1330 
1331                 if ((label = vdev_label_read_config(vd)) == NULL) {

1332                         vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1333                             VDEV_AUX_BAD_LABEL);
1334                         return (0);
1335                 }
1336 
1337                 /*
1338                  * Determine if this vdev has been split off into another
1339                  * pool.  If so, then refuse to open it.
1340                  */
1341                 if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_SPLIT_GUID,
1342                     &aux_guid) == 0 && aux_guid == spa_guid(spa)) {
1343                         vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1344                             VDEV_AUX_SPLIT_POOL);
1345                         nvlist_free(label);
1346                         return (0);
1347                 }
1348 
1349                 if (strict && (nvlist_lookup_uint64(label,
1350                     ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1351                     guid != spa_guid(spa))) {


1952                     VDEV_AUX_CORRUPT_DATA);
1953 }
1954 
1955 /*
1956  * The special vdev case is used for hot spares and l2cache devices.  Its
1957  * sole purpose it to set the vdev state for the associated vdev.  To do this,
1958  * we make sure that we can open the underlying device, then try to read the
1959  * label, and make sure that the label is sane and that it hasn't been
1960  * repurposed to another pool.
1961  */
1962 int
1963 vdev_validate_aux(vdev_t *vd)
1964 {
1965         nvlist_t *label;
1966         uint64_t guid, version;
1967         uint64_t state;
1968 
1969         if (!vdev_readable(vd))
1970                 return (0);
1971 
1972         if ((label = vdev_label_read_config(vd)) == NULL) {
1973                 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1974                     VDEV_AUX_CORRUPT_DATA);
1975                 return (-1);
1976         }
1977 
1978         if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_VERSION, &version) != 0 ||
1979             version > SPA_VERSION ||
1980             nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) != 0 ||
1981             guid != vd->vdev_guid ||
1982             nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, &state) != 0) {
1983                 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1984                     VDEV_AUX_CORRUPT_DATA);
1985                 nvlist_free(label);
1986                 return (-1);
1987         }
1988 
1989         /*
1990          * We don't actually check the pool state here.  If it's in fact in
1991          * use by another pool, we update this fact on the fly when requested.
1992          */
1993         nvlist_free(label);
1994         return (0);
1995 }
1996 
1997 void
1998 vdev_remove(vdev_t *vd, uint64_t txg)
1999 {




1311 vdev_validate(vdev_t *vd, boolean_t strict)
1312 {
1313         spa_t *spa = vd->vdev_spa;
1314         nvlist_t *label;
1315         uint64_t guid = 0, top_guid;
1316         uint64_t state;
1317 
1318         for (int c = 0; c < vd->vdev_children; c++)
1319                 if (vdev_validate(vd->vdev_child[c], strict) != 0)
1320                         return (EBADF);
1321 
1322         /*
1323          * If the device has already failed, or was marked offline, don't do
1324          * any further validation.  Otherwise, label I/O will fail and we will
1325          * overwrite the previous state.
1326          */
1327         if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) {
1328                 uint64_t aux_guid = 0;
1329                 nvlist_t *nvl;
1330 
1331                 if ((label = vdev_label_read_config(vd, VDEV_BEST_LABEL)) ==
1332                     NULL) {
1333                         vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1334                             VDEV_AUX_BAD_LABEL);
1335                         return (0);
1336                 }
1337 
1338                 /*
1339                  * Determine if this vdev has been split off into another
1340                  * pool.  If so, then refuse to open it.
1341                  */
1342                 if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_SPLIT_GUID,
1343                     &aux_guid) == 0 && aux_guid == spa_guid(spa)) {
1344                         vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1345                             VDEV_AUX_SPLIT_POOL);
1346                         nvlist_free(label);
1347                         return (0);
1348                 }
1349 
1350                 if (strict && (nvlist_lookup_uint64(label,
1351                     ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1352                     guid != spa_guid(spa))) {


1953                     VDEV_AUX_CORRUPT_DATA);
1954 }
1955 
1956 /*
1957  * The special vdev case is used for hot spares and l2cache devices.  Its
1958  * sole purpose it to set the vdev state for the associated vdev.  To do this,
1959  * we make sure that we can open the underlying device, then try to read the
1960  * label, and make sure that the label is sane and that it hasn't been
1961  * repurposed to another pool.
1962  */
1963 int
1964 vdev_validate_aux(vdev_t *vd)
1965 {
1966         nvlist_t *label;
1967         uint64_t guid, version;
1968         uint64_t state;
1969 
1970         if (!vdev_readable(vd))
1971                 return (0);
1972 
1973         if ((label = vdev_label_read_config(vd, VDEV_BEST_LABEL)) == NULL) {
1974                 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1975                     VDEV_AUX_CORRUPT_DATA);
1976                 return (-1);
1977         }
1978 
1979         if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_VERSION, &version) != 0 ||
1980             !SPA_VERSION_IS_SUPPORTED(version) ||
1981             nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) != 0 ||
1982             guid != vd->vdev_guid ||
1983             nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, &state) != 0) {
1984                 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1985                     VDEV_AUX_CORRUPT_DATA);
1986                 nvlist_free(label);
1987                 return (-1);
1988         }
1989 
1990         /*
1991          * We don't actually check the pool state here.  If it's in fact in
1992          * use by another pool, we update this fact on the fly when requested.
1993          */
1994         nvlist_free(label);
1995         return (0);
1996 }
1997 
1998 void
1999 vdev_remove(vdev_t *vd, uint64_t txg)
2000 {