Skip to content

Commit 022ec58

Browse files
tonyhutterlundman
authored andcommitted
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. Reviewed-by: Tino Reichardt <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Tony Hutter <[email protected]> Closes openzfs#17042
1 parent a79c6ab commit 022ec58

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/libzutil/zutil_device_path.c

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

6263
if (env) {
6364
for (;;) {
@@ -86,6 +87,20 @@ zfs_resolve_shortname(const char *name, char *path, size_t len)
8687
}
8788
}
8889

90+
/*
91+
* The user can pass a relative path like ./file1 for the vdev. The path
92+
* must contain a directory prefix like './file1' or '../file1'. Simply
93+
* passing 'file1' is not allowed, as it may match a block device name.
94+
*/
95+
if ((strncmp(name, "./", 2) == 0 || strncmp(name, "../", 3) == 0) &&
96+
realpath(name, resolved_path) != NULL) {
97+
if (access(resolved_path, F_OK) == 0) {
98+
if (strlen(resolved_path) + 1 <= len) {
99+
if (strlcpy(path, resolved_path, len) < len)
100+
return (0); /* success */
101+
}
102+
}
103+
}
89104
return (errno = ENOENT);
90105
}
91106

0 commit comments

Comments
 (0)