Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ratson committed Jun 13, 2018
1 parent e972e34 commit 626dbc4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,14 @@ show_import(nvlist_t *config)
"imported. Attach the missing\n\tdevices and try "
"again.\n"));
break;
case ZPOOL_STATUS_CORRUPT_LABEL_R:
case ZPOOL_STATUS_CORRUPT_LABEL_NR:
(void) printf(gettext(" action: The pool cannot be "
"imported due to a corrupt or missing label.\n\t"
"It may be possible to reconstruct the label "
"from the cache file.\n\tImport the pool with "
"\"-F -o readonly=on -c <cache-file>\".\n"));
break;
default:
(void) printf(gettext(" action: The pool cannot be "
"imported due to damaged devices or data.\n"));
Expand Down
17 changes: 15 additions & 2 deletions module/zfs/vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,13 @@ vdev_validate(vdev_t *vd)
else
txg = spa_last_synced_txg(spa);

if ((label = vdev_label_read_config(vd, txg)) == NULL) {
label = vdev_label_read_config(vd, txg);
if (label == NULL && spa->spa_load_state == SPA_LOAD_RECOVER) {
dprintf("generating label for %s\n", vd->vdev_path);
label = spa_config_generate(spa, vd, -1ULL, 0);
}

if (label == NULL) {
vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
VDEV_AUX_BAD_LABEL);
vdev_dbgmsg(vd, "vdev_validate: failed reading config for "
Expand Down Expand Up @@ -2780,14 +2786,21 @@ vdev_load(vdev_t *vd)
int
vdev_validate_aux(vdev_t *vd)
{
spa_t *spa = vd->vdev_spa;
nvlist_t *label;
uint64_t guid, version;
uint64_t state;

if (!vdev_readable(vd))
return (0);

if ((label = vdev_label_read_config(vd, -1ULL)) == NULL) {
label = vdev_label_read_config(vd, -1ULL);
if (label == NULL && spa->spa_load_state == SPA_LOAD_RECOVER) {
dprintf("generating label for %s\n", vd->vdev_path);
label = spa_config_generate(spa, vd, -1ULL, 0);
}

if (label == NULL) {
vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
VDEV_AUX_CORRUPT_DATA);
return (-1);
Expand Down
8 changes: 6 additions & 2 deletions module/zfs/vdev_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ vdev_label_read_config(vdev_t *vd, uint64_t txg)
if ((error || label_txg == 0) && !config) {
config = label;
break;
} else if (label_txg <= txg && label_txg > best_txg) {
} else if (label_txg > best_txg) {
best_txg = label_txg;
nvlist_free(config);
config = fnvlist_dup(label);
Expand Down Expand Up @@ -1234,7 +1234,11 @@ vdev_uberblock_load(vdev_t *rvd, uberblock_t *ub, nvlist_t **config)
"txg %llu", spa->spa_name, (u_longlong_t)ub->ub_txg);

*config = vdev_label_read_config(cb.ubl_vd, ub->ub_txg);
if (*config == NULL && spa->spa_extreme_rewind) {
if (*config == NULL && spa->spa_load_state == SPA_LOAD_RECOVER) {
dprintf("generating label for %s, txg=%llu\n",
cb.ubl_vd->vdev_path, ub->ub_txg);
*config = spa_config_generate(spa, cb.ubl_vd, -1ULL, 0);
} else if (*config == NULL && spa->spa_extreme_rewind) {
vdev_dbgmsg(cb.ubl_vd, "failed to read label config. "
"Trying again without txg restrictions.");
*config = vdev_label_read_config(cb.ubl_vd, UINT64_MAX);
Expand Down

0 comments on commit 626dbc4

Please sign in to comment.