diff options
author | Chunwei Chen <[email protected]> | 2018-02-01 16:36:40 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2018-02-09 10:11:34 -0800 |
commit | eb9c4532dda34bcf0612c2c797cb3fcab9a21b4f (patch) | |
tree | 54660cc9cc34123d0916bc915db406c190bf8920 /cmd/zdb | |
parent | 5e3bd0e684a3c32bd22647938247ac3699c5372a (diff) |
Fix zdb -ed on objset for exported pool
zdb -ed on objset for exported pool would failed with:
failed to own dataset 'qq/fs0': No such file or directory
The reason is that zdb pass objset name to spa_import, it uses that
name to create a spa. Later, when dmu_objset_own tries to lookup the spa
using real pool name, it can't find one.
We fix this by make sure we pass pool name rather than objset name to
spa_import.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: loli10K <[email protected]>
Signed-off-by: Chunwei Chen <[email protected]>
Closes #7099
Closes #6464
Diffstat (limited to 'cmd/zdb')
-rw-r--r-- | cmd/zdb/zdb.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 7f2cab382..063358a04 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -4273,7 +4273,7 @@ main(int argc, char **argv) int error = 0; char **searchdirs = NULL; int nsearch = 0; - char *target; + char *target, *target_pool; nvlist_t *policy = NULL; uint64_t max_txg = UINT64_MAX; int flags = ZFS_IMPORT_MISSING_LOG; @@ -4476,6 +4476,20 @@ main(int argc, char **argv) error = 0; target = argv[0]; + if (strpbrk(target, "/@") != NULL) { + size_t targetlen; + + target_pool = strdup(target); + *strpbrk(target_pool, "/@") = '\0'; + + target_is_spa = B_FALSE; + targetlen = strlen(target); + if (targetlen && target[targetlen - 1] == '/') + target[targetlen - 1] = '\0'; + } else { + target_pool = target; + } + if (dump_opt['e']) { importargs_t args = { 0 }; nvlist_t *cfg = NULL; @@ -4484,8 +4498,10 @@ main(int argc, char **argv) args.path = searchdirs; args.can_be_active = B_TRUE; - error = zpool_tryimport(g_zfs, target, &cfg, &args); + error = zpool_tryimport(g_zfs, target_pool, &cfg, &args); + if (error == 0) { + if (nvlist_add_nvlist(cfg, ZPOOL_REWIND_POLICY, policy) != 0) { fatal("can't open '%s': %s", @@ -4500,19 +4516,13 @@ main(int argc, char **argv) (void) printf("\nConfiguration for import:\n"); dump_nvlist(cfg, 8); } - error = spa_import(target, cfg, NULL, + error = spa_import(target_pool, cfg, NULL, flags | ZFS_IMPORT_SKIP_MMP); } } - if (strpbrk(target, "/@") != NULL) { - size_t targetlen; - - target_is_spa = B_FALSE; - targetlen = strlen(target); - if (targetlen && target[targetlen - 1] == '/') - target[targetlen - 1] = '\0'; - } + if (target_pool != target) + free(target_pool); if (error == 0) { if (target_is_spa || dump_opt['R']) { |