summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2012-09-15 13:25:21 -0700
committerBrian Behlendorf <[email protected]>2012-09-17 13:49:07 -0700
commit44867b6d6effc1628dd00c36821ab044f89fb988 (patch)
treec5167dfd31770d970d4b798393ef84112de08656 /cmd
parentba367276d84e126dc3a13677c286539d0019e3b8 (diff)
Improve `zpool import` search behavior
The goal of this change is to make 'zpool import' prefer to use the peristent /dev/mapper or /dev/disk/by-* paths. These are far preferable to the devices in /dev/ whos names are not persistent and are determined by the order in which a device is detected. This patch improves things by changing the default search path from just to the top level /dev/ directory to (in order): /dev/disk/by-vdev - Custom rules, use first if they exist /dev/disk/zpool - Custom rules, use first if they exist /dev/mapper - Use multipath devices before components /dev/disk/by-uuid - Single unique entry and persistent /dev/disk/by-id - May be multiple entries and persistent /dev/disk/by-path - Encodes physical location and persistent /dev/disk/by-label - Custom persistent labels /dev - UNSAFE device names will change The default search path can be overriden by setting the ZPOOL_IMPORT_PATH environment variable. This must be a colon delimited list of paths which are searched for vdevs. If the 'zpool import -d' option is specified only those listed paths will be searched. Finally, when multiple paths to the same device are found. If one of the paths is an exact match for the path used last time to import the pool it will be used. When there are no exact matches the prefered path will be determined by the provided search order. This means you can still import a pool and force specific names by providing the -d <path> option. And the prefered names will persist as long as those paths exist on your system. Signed-off-by: Brian Behlendorf <[email protected]> Closes #965
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zpool/zpool_main.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 312f15753..cf8d5ed60 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -1647,6 +1647,7 @@ int
zpool_do_import(int argc, char **argv)
{
char **searchdirs = NULL;
+ char *env, *envdup = NULL;
int nsearch = 0;
int c;
int err = 0;
@@ -1846,6 +1847,30 @@ zpool_do_import(int argc, char **argv)
idata.unique = B_TRUE;
}
+ /*
+ * Check the environment for the preferred search path.
+ */
+ if ((searchdirs == NULL) && (env = getenv("ZPOOL_IMPORT_PATH"))) {
+ char *dir;
+
+ envdup = strdup(env);
+
+ dir = strtok(envdup, ":");
+ while (dir != NULL) {
+ if (searchdirs == NULL) {
+ searchdirs = safe_malloc(sizeof (char *));
+ } else {
+ char **tmp = safe_malloc((nsearch + 1) *
+ sizeof (char *));
+ bcopy(searchdirs, tmp, nsearch *
+ sizeof (char *));
+ free(searchdirs);
+ searchdirs = tmp;
+ }
+ searchdirs[nsearch++] = dir;
+ dir = strtok(NULL, ":");
+ }
+ }
idata.path = searchdirs;
idata.paths = nsearch;
@@ -1882,6 +1907,8 @@ zpool_do_import(int argc, char **argv)
if (err == 1) {
if (searchdirs != NULL)
free(searchdirs);
+ if (envdup != NULL)
+ free(envdup);
nvlist_free(policy);
return (1);
}
@@ -1984,6 +2011,8 @@ error:
nvlist_free(policy);
if (searchdirs != NULL)
free(searchdirs);
+ if (envdup != NULL)
+ free(envdup);
return (err ? 1 : 0);
}