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 01aa777376e84adfa6e32dbe089cd97ed8997a27
Showing with 22 additions and 0 deletions.
  1. +16 −0 cmd/zpool/zpool_main.c
  2. +6 −0 module/zfs/spa.c
@@ -2939,6 +2939,7 @@ zpool_do_checkpoint(int argc, char **argv)
}

#define CHECKPOINT_OPT 1024
#define LOAD_META_THRESH_OPT 1025

/*
* zpool import [-d dir] [-D]
@@ -3024,9 +3025,11 @@ 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 +3125,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 +3184,10 @@ 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) {
@@ -2198,6 +2198,12 @@ 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 01aa777

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