Skip to content

Commit 6b535be

Browse files
committed
zpool: allow relative vdev paths
`zpool create` won't let you use relative paths to disks. This is annoying when you want to do: zpool create tank ./diskfile But have to do.. zpool create tank `pwd`/diskfile This fixes it. Signed-off-by: Tony Hutter <[email protected]>
1 parent b8c73ab commit 6b535be

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/libzutil/zutil_device_path.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ int
5757
zfs_resolve_shortname(const char *name, char *path, size_t len)
5858
{
5959
const char *env = getenv("ZPOOL_IMPORT_PATH");
60+
char resolved_path[PATH_MAX];
6061

6162
if (env) {
6263
for (;;) {
@@ -85,6 +86,15 @@ zfs_resolve_shortname(const char *name, char *path, size_t len)
8586
}
8687
}
8788

89+
/* The user may have passed a relative path like ./file1 for the vdev */
90+
if (realpath(name, resolved_path) != NULL) {
91+
if (access(resolved_path, F_OK) == 0) {
92+
if (strlen(resolved_path) + 1 <= len) {
93+
strncpy(path, resolved_path, len);
94+
return (0);
95+
}
96+
}
97+
}
8898
return (errno = ENOENT);
8999
}
90100

0 commit comments

Comments
 (0)