Skip to content

Commit

Permalink
Make zpool import -d|-c behave consistently
Browse files Browse the repository at this point in the history
When importing pools with zpool import -aN there is inconsistent
behavior between '-d /dev/disk/by-id' (or another path) and
'-c /etc/zfs/zpool.cache'.

The difference in behavior is caused by zpool_find_import_cached()
returning an empty nvlist_t when there are no pools to import but
zpool_find_import_impl() returns NULL for the same situation. The
behavior of zpool_find_import_cached() is arguably more correct
because it allows returning NULL to be used for an error case and
not an empty set.

This change resolves the issue by updating get_configs() such that
it returns an empty set instead of NULL when no config is found.
The updated behavior will now always return 0 for this case.

$ zpool import -aN; echo $?
no pools available to import
0

$ zpool import -aN -d /var/tmp/; echo $?
no pools available to import
0

$ zpool import -aN -c /etc/zfs/zpool.cache; echo $?
no pools available to import
0

Signed-off-by: Brian Behlendorf <[email protected]>
Closes openzfs#2080
  • Loading branch information
behlendorf committed Jan 28, 2015
1 parent a485efc commit 6466b61
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions lib/libzfs/libzfs_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok)
boolean_t isactive;
uint64_t hostid;
nvlist_t *nvl;
boolean_t found_one = B_FALSE;
boolean_t valid_top_config = B_FALSE;

if (nvlist_alloc(&ret, 0, 0) != 0)
Expand Down Expand Up @@ -813,16 +812,10 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok)
if (nvlist_add_nvlist(ret, name, config) != 0)
goto nomem;

found_one = B_TRUE;
nvlist_free(config);
config = NULL;
}

if (!found_one) {
nvlist_free(ret);
ret = NULL;
}

return (ret);

nomem:
Expand Down

0 comments on commit 6466b61

Please sign in to comment.