Skip to content

Commit

Permalink
zpool: allow relative vdev paths
Browse files Browse the repository at this point in the history
`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 <hutter2@llnl.gov>
  • Loading branch information
tonyhutter committed Feb 10, 2025
1 parent b8c73ab commit 6b535be
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/libzutil/zutil_device_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 6b535be

Please sign in to comment.