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 24, 2025
1 parent b8c73ab commit f7b4fca
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 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,19 @@ zfs_resolve_shortname(const char *name, char *path, size_t len)
}
}

/*
* The user can pass a relative path like ./file1 for the vdev. The path
* must contain a directory prefix like './file1' or '../file1'. Simply
* passing 'file1' is not allowed, as it may match a block device name.
*/
if (strstr(name, "./") != NULL && realpath(name, resolved_path) != NULL) {

Check failure on line 94 in lib/libzutil/zutil_device_path.c

View workflow job for this annotation

GitHub Actions / checkstyle

line > 80 characters
if (access(resolved_path, F_OK) == 0) {
if (strlen(resolved_path) + 1 <= len) {
if (strlcpy(path, resolved_path, len) < len)
return (0); /* success */
}
}
}
return (errno = ENOENT);
}

Expand Down

0 comments on commit f7b4fca

Please sign in to comment.