Skip to content

Commit cd50c7b

Browse files
committed
zpool import -m also removing spare and cache when log dev is missing
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]>
1 parent 6b6aaf6 commit cd50c7b

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

cmd/zpool/zpool_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,6 +3549,7 @@ zpool_do_import(int argc, char **argv)
35493549
boolean_t do_scan = B_FALSE;
35503550
boolean_t pool_exists = B_FALSE;
35513551
boolean_t pool_specified = B_FALSE;
3552+
boolean_t missing_log = B_FALSE;
35523553
uint64_t txg = -1ULL;
35533554
char *cachefile = NULL;
35543555
importargs_t idata = { 0 };
@@ -3588,6 +3589,7 @@ zpool_do_import(int argc, char **argv)
35883589
break;
35893590
case 'm':
35903591
flags |= ZFS_IMPORT_MISSING_LOG;
3592+
missing_log = B_TRUE;
35913593
break;
35923594
case 'n':
35933595
dryrun = B_TRUE;
@@ -3780,6 +3782,7 @@ zpool_do_import(int argc, char **argv)
37803782
idata.cachefile = cachefile;
37813783
idata.scan = do_scan;
37823784
idata.policy = policy;
3785+
idata.missing_log = missing_log;
37833786

37843787
libpc_handle_t lpch = {
37853788
.lpc_lib_handle = g_zfs,

include/libzutil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ typedef struct importargs {
7676
const char *cachefile; /* cachefile to use for import */
7777
boolean_t can_be_active; /* can the pool be active? */
7878
boolean_t scan; /* prefer scanning to libblkid cache */
79+
boolean_t missing_log; /* pass missing log flag if supplied */
7980
nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
8081
} importargs_t;
8182

include/sys/fs/zfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ typedef struct zpool_load_policy {
822822
#define ZPOOL_CONFIG_HAS_PER_VDEV_ZAPS "com.delphix:has_per_vdev_zaps"
823823
#define ZPOOL_CONFIG_RESILVER_DEFER "com.datto:resilver_defer"
824824
#define ZPOOL_CONFIG_CACHEFILE "cachefile" /* not stored on disk */
825+
#define ZPOOL_CONFIG_MISSING_LOG "missing_log" /* not stored on disk */
825826
#define ZPOOL_CONFIG_MMP_STATE "mmp_state" /* not stored on disk */
826827
#define ZPOOL_CONFIG_MMP_TXG "mmp_txg" /* not stored on disk */
827828
#define ZPOOL_CONFIG_MMP_SEQ "mmp_seq" /* not stored on disk */

lib/libzutil/zutil_import.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ vdev_is_hole(uint64_t *hole_array, uint_t holes, uint_t id)
487487
*/
488488
static nvlist_t *
489489
get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
490-
nvlist_t *policy)
490+
nvlist_t *policy, boolean_t missing_log)
491491
{
492492
pool_entry_t *pe;
493493
vdev_entry_t *ve;
@@ -834,6 +834,12 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
834834
goto nomem;
835835
}
836836

837+
if (missing_log == B_TRUE) {
838+
if (nvlist_add_boolean(config, ZPOOL_CONFIG_MISSING_LOG)
839+
!= 0)
840+
goto nomem;
841+
}
842+
837843
if ((nvl = zutil_refresh_config(hdl, config)) == NULL) {
838844
nvlist_free(config);
839845
config = NULL;
@@ -1515,7 +1521,8 @@ zpool_find_import_impl(libpc_handle_t *hdl, importargs_t *iarg,
15151521
avl_destroy(cache);
15161522
free(cache);
15171523

1518-
ret = get_configs(hdl, &pools, iarg->can_be_active, iarg->policy);
1524+
ret = get_configs(hdl, &pools, iarg->can_be_active, iarg->policy,
1525+
iarg->missing_log);
15191526

15201527
for (pe = pools.pools; pe != NULL; pe = penext) {
15211528
penext = pe->pe_next;

module/zfs/spa.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6378,6 +6378,9 @@ spa_tryimport(nvlist_t *tryconfig)
63786378
spa->spa_config_source = SPA_CONFIG_SRC_SCAN;
63796379
}
63806380

6381+
if (nvlist_lookup_boolean(tryconfig, ZPOOL_CONFIG_MISSING_LOG) == 0)
6382+
spa->spa_import_flags |= ZFS_IMPORT_MISSING_LOG;
6383+
63816384
error = spa_load(spa, SPA_LOAD_TRYIMPORT, SPA_IMPORT_EXISTING);
63826385

63836386
/*

0 commit comments

Comments
 (0)