Skip to content
Permalink
Browse files

Add 'zpool import --load-meta-thresh [n]' option

When attempting to import a pool, spa_load_verify() fails if there are
any metadata errors.  This commit adds a new 'zpool import
--load-meta-thresh [n]' option, which allows you to specify how many
metadata errors to permit when importing.

Signed-off-by: Steve Mokris <smokris@softpixel.com>
  • Loading branch information...
smokris committed Jul 11, 2019
1 parent d230a65 commit 62d5babceb7c4c1a52deb9aaba7df414d6cb1818
Showing with 48 additions and 1 deletion.
  1. +24 −1 cmd/zpool/zpool_main.c
  2. +14 −0 man/man8/zpool.8
  3. +10 −0 module/zfs/spa.c
@@ -354,7 +354,8 @@ get_usage(zpool_help_t idx)
"\timport [-o mntopts] [-o property=value] ... \n"
"\t [-d dir | -c cachefile] [-D] [-l] [-f] [-m] [-N] "
"[-R root] [-F [-n]]\n"
"\t [--rewind-to-checkpoint] <pool | id> [newpool]\n"));
"\t [--rewind-to-checkpoint] [--load-meta-thresh n] "
"<pool | id> [newpool]\n"));
case HELP_IOSTAT:
return (gettext("\tiostat [[[-c [script1,script2,...]"
"[-lq]]|[-rw]] [-T d | u] [-ghHLpPvy]\n"
@@ -2939,6 +2940,7 @@ zpool_do_checkpoint(int argc, char **argv)
}

#define CHECKPOINT_OPT 1024
#define LOAD_META_THRESH_OPT 1025

/*
* zpool import [-d dir] [-D]
@@ -2989,6 +2991,10 @@ zpool_do_checkpoint(int argc, char **argv)
* --rewind-to-checkpoint
* Import the pool and revert back to the checkpoint.
*
* --load-meta-thresh [n]
* Permit up to n metadata errors before giving up on the import.
* Default 0.
*
* The import command scans for pools to import, and import pools based on pool
* name and GUID. The pool can also be renamed as part of the import process.
*/
@@ -3024,9 +3030,12 @@ zpool_do_import(int argc, char **argv)
char *cachefile = NULL;
importargs_t idata = { 0 };
char *endptr;
int load_meta_thresh = 0;

struct option long_options[] = {
{"rewind-to-checkpoint", no_argument, NULL, CHECKPOINT_OPT},
{"load-meta-thresh", required_argument, NULL,
LOAD_META_THRESH_OPT},
{0, 0, 0, 0}
};

@@ -3122,6 +3131,15 @@ zpool_do_import(int argc, char **argv)
case CHECKPOINT_OPT:
flags |= ZFS_IMPORT_CHECKPOINT;
break;
case LOAD_META_THRESH_OPT:
errno = 0;
load_meta_thresh = strtoull(optarg, &endptr, 0);
if (errno != 0 || *endptr != '\0') {
(void) fprintf(stderr, gettext("invalid "
"load-meta-thresh value\n"));
usage(B_FALSE);
}
break;
case ':':
(void) fprintf(stderr, gettext("missing argument for "
"'%c' option\n"), optopt);
@@ -3172,6 +3190,11 @@ zpool_do_import(int argc, char **argv)
rewind_policy) != 0)
goto error;

if (load_meta_thresh)
if (nvlist_add_uint64(policy, ZPOOL_LOAD_META_THRESH,
load_meta_thresh) != 0)
goto error;

/* check argument count */
if (do_all) {
if (argc != 0) {
@@ -98,6 +98,7 @@
.Op Fl DflmN
.Op Fl F Oo Fl n Oc Oo Fl T Oc Oo Fl X Oc
.Op Fl -rewind-to-checkpoint
.Op Fl -load-meta-thresh Ar n
.Op Fl c Ar cachefile Ns | Ns Fl d Ar dir Ns | Ns device
.Op Fl o Ar mntopts
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
@@ -107,6 +108,7 @@
.Op Fl Dflm
.Op Fl F Oo Fl n Oc Oo Fl T Oc Oo Fl X Oc
.Op Fl -rewind-to-checkpoint
.Op Fl -load-meta-thresh Ar n
.Op Fl c Ar cachefile Ns | Ns Fl d Ar dir Ns | Ns device
.Op Fl o Ar mntopts
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
@@ -1417,6 +1419,7 @@ Lists destroyed pools only.
.Fl a
.Op Fl DflmN
.Op Fl F Oo Fl n Oc Oo Fl T Oc Oo Fl X Oc
.Op Fl -load-meta-thresh Ar n
.Op Fl c Ar cachefile Ns | Ns Fl d Ar dir Ns | Ns device
.Op Fl o Ar mntopts
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
@@ -1521,6 +1524,11 @@ mounting option is enabled.
In this case, the checkpointed state of the pool is opened and an
administrator can see how the pool would look like if they were
to fully rewind.
.It Fl -load-meta-thresh Ar n
Permits up to
.Sy n
metadata errors before giving up on the import.
Default 0.
.It Fl s
Scan using the default search path, the libblkid cache will not be
consulted. A custom search path may be specified by setting the
@@ -1550,6 +1558,7 @@ health of your pool and should only be used as a last resort.
.Cm import
.Op Fl Dflm
.Op Fl F Oo Fl n Oc Oo Fl t Oc Oo Fl T Oc Oo Fl X Oc
.Op Fl -load-meta-thresh Ar n
.Op Fl c Ar cachefile Ns | Ns Fl d Ar dir Ns | Ns device
.Op Fl o Ar mntopts
.Oo Fl o Ar property Ns = Ns Ar value Oc Ns ...
@@ -1650,6 +1659,11 @@ and the
.Sy altroot
property to
.Ar root .
.It Fl -load-meta-thresh Ar n
Permits up to
.Sy n
metadata errors before giving up on the import.
Default 0.
.It Fl s
Scan using the default search path, the libblkid cache will not be
consulted. A custom search path may be specified by setting the
@@ -2198,6 +2198,16 @@ spa_load_verify(spa_t *spa)
spa_load_note(spa, "spa_load_verify found %llu metadata errors "
"and %llu data errors", (u_longlong_t)sle.sle_meta_count,
(u_longlong_t)sle.sle_data_count);

// If the policy allows metadata errors,
// ignore the error returned by traverse_pool.
if (error == EINVAL &&
policy.zlp_maxmeta > 0 &&
sle.sle_meta_count <= policy.zlp_maxmeta) {
spa_load_note(spa, "spa_load_verify continuing "
"even though there are metadata errors");
error = 0;
}
}

if (spa_load_verify_dryrun ||

0 comments on commit 62d5bab

Please sign in to comment.
You can’t perform that action at this time.