From 6b535be212aaf5c90485bc175d3a4b1b66c30a3f Mon Sep 17 00:00:00 2001 From: Tony Hutter Date: Mon, 10 Feb 2025 12:09:16 -0800 Subject: [PATCH] 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 --- lib/libzutil/zutil_device_path.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/libzutil/zutil_device_path.c b/lib/libzutil/zutil_device_path.c index 0425018e1022..90d099a50bb8 100644 --- a/lib/libzutil/zutil_device_path.c +++ b/lib/libzutil/zutil_device_path.c @@ -57,6 +57,7 @@ int zfs_resolve_shortname(const char *name, char *path, size_t len) { const char *env = getenv("ZPOOL_IMPORT_PATH"); + char resolved_path[PATH_MAX]; if (env) { for (;;) { @@ -85,6 +86,15 @@ zfs_resolve_shortname(const char *name, char *path, size_t len) } } + /* The user may have passed a relative path like ./file1 for the vdev */ + if (realpath(name, resolved_path) != NULL) { + if (access(resolved_path, F_OK) == 0) { + if (strlen(resolved_path) + 1 <= len) { + strncpy(path, resolved_path, len); + return (0); + } + } + } return (errno = ENOENT); }