Skip to content

Commit

Permalink
zpool import -m also removing spare and cache when log dev is missing
Browse files Browse the repository at this point in the history
spa_import() relies on a pool config fetched by spa_try_import().
Import flags are not passed to spa_try_import(), which makes it
return early due to a missing log device and missing retrieving the
cache device and spare eventually. In this patch, we pass missing
log flag as part of config to spa_try_import().

Signed-off-by: Ameer Hamza <[email protected]>
  • Loading branch information
ixhamza committed Apr 25, 2023
1 parent 6b6aaf6 commit cd50c7b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3549,6 +3549,7 @@ zpool_do_import(int argc, char **argv)
boolean_t do_scan = B_FALSE;
boolean_t pool_exists = B_FALSE;
boolean_t pool_specified = B_FALSE;
boolean_t missing_log = B_FALSE;
uint64_t txg = -1ULL;
char *cachefile = NULL;
importargs_t idata = { 0 };
Expand Down Expand Up @@ -3588,6 +3589,7 @@ zpool_do_import(int argc, char **argv)
break;
case 'm':
flags |= ZFS_IMPORT_MISSING_LOG;
missing_log = B_TRUE;
break;
case 'n':
dryrun = B_TRUE;
Expand Down Expand Up @@ -3780,6 +3782,7 @@ zpool_do_import(int argc, char **argv)
idata.cachefile = cachefile;
idata.scan = do_scan;
idata.policy = policy;
idata.missing_log = missing_log;

libpc_handle_t lpch = {
.lpc_lib_handle = g_zfs,
Expand Down
1 change: 1 addition & 0 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct importargs {
const char *cachefile; /* cachefile to use for import */
boolean_t can_be_active; /* can the pool be active? */
boolean_t scan; /* prefer scanning to libblkid cache */
boolean_t missing_log; /* pass missing log flag if supplied */
nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
} importargs_t;

Expand Down
1 change: 1 addition & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ typedef struct zpool_load_policy {
#define ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS "com.delphix:has_per_vdev_zaps"
#define ZPOOL_CONFIG_RESILVER_DEFER "com.datto:resilver_defer"
#define ZPOOL_CONFIG_CACHEFILE "cachefile" /* not stored on disk */
#define ZPOOL_CONFIG_MISSING_LOG "missing_log" /* not stored on disk */
#define ZPOOL_CONFIG_MMP_STATE "mmp_state" /* not stored on disk */
#define ZPOOL_CONFIG_MMP_TXG "mmp_txg" /* not stored on disk */
#define ZPOOL_CONFIG_MMP_SEQ "mmp_seq" /* not stored on disk */
Expand Down
11 changes: 9 additions & 2 deletions lib/libzutil/zutil_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ vdev_is_hole(uint64_t *hole_array, uint_t holes, uint_t id)
*/
static nvlist_t *
get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
nvlist_t *policy)
nvlist_t *policy, boolean_t missing_log)
{
pool_entry_t *pe;
vdev_entry_t *ve;
Expand Down Expand Up @@ -834,6 +834,12 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
goto nomem;
}

if (missing_log == B_TRUE) {
if (nvlist_add_boolean(config, ZPOOL_CONFIG_MISSING_LOG)
!= 0)
goto nomem;
}

if ((nvl = zutil_refresh_config(hdl, config)) == NULL) {
nvlist_free(config);
config = NULL;
Expand Down Expand Up @@ -1515,7 +1521,8 @@ zpool_find_import_impl(libpc_handle_t *hdl, importargs_t *iarg,
avl_destroy(cache);
free(cache);

ret = get_configs(hdl, &pools, iarg->can_be_active, iarg->policy);
ret = get_configs(hdl, &pools, iarg->can_be_active, iarg->policy,
iarg->missing_log);

for (pe = pools.pools; pe != NULL; pe = penext) {
penext = pe->pe_next;
Expand Down
3 changes: 3 additions & 0 deletions module/zfs/spa.c
Original file line number Diff line number Diff line change
Expand Up @@ -6378,6 +6378,9 @@ spa_tryimport(nvlist_t *tryconfig)
spa->spa_config_source = SPA_CONFIG_SRC_SCAN;
}

if (nvlist_lookup_boolean(tryconfig, ZPOOL_CONFIG_MISSING_LOG) == 0)
spa->spa_import_flags |= ZFS_IMPORT_MISSING_LOG;

error = spa_load(spa, SPA_LOAD_TRYIMPORT, SPA_IMPORT_EXISTING);

/*
Expand Down

0 comments on commit cd50c7b

Please sign in to comment.