Skip to content

Commit f741c84

Browse files
tonyhutterixhamza
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 637f918 commit f741c84

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
@@ -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,20 @@ zfs_resolve_shortname(const char *name, char *path, size_t len)
8586
}
8687
}
8788

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

0 commit comments

Comments
 (0)