Skip to content

Commit

Permalink
Upstream: dirname -> zfs_dirnamelen [squash]
Browse files Browse the repository at this point in the history
Forgot to actually change it to zfs_dirnamelen

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Jun 22, 2021
1 parent db7495e commit 84848e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
12 changes: 9 additions & 3 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary)
{
char path[MAXPATHLEN];
char *d, *b;
char *dpath, *bname;
char *dpath;
const char *bname;
struct stat64 statbuf;
nvlist_t *vdev = NULL;
char *type = NULL;
Expand Down Expand Up @@ -317,9 +318,14 @@ make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary)
*/
d = strdup(arg);
b = strdup(arg);
dpath = dirname(d);
bname = basename(b);
int idx = zfs_dirnamelen(d);
if (idx != -1)
d[idx] = 0;
dpath = d;
bname = zfs_basename(b);
if (realpath(dpath, path) == NULL) {
free(d);
free(b);
(void) fprintf(stderr,
gettext("cannot resolve path '%s'\n"), dpath);
return (NULL);
Expand Down
17 changes: 13 additions & 4 deletions lib/libzutil/zutil_device_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk)
char cmp_name[MAXPATHLEN];
char *dir, *tmp = NULL;
char *d, *b;
char *dpath, *bname;
const char *dpath, *bname;

/* Strip redundant slashes if they exist due to ZPOOL_IMPORT_PATH */
cmp_name[0] = '\0';
Expand Down Expand Up @@ -187,18 +187,27 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk)
if ((path_len == cmp_len) && strcmp(path_name, cmp_name) == 0)
return (0);
else {
int idx;
d = strdup(path_name);
b = strdup(path_name);
dpath = dirname(d);
bname = basename(b);
idx = zfs_dirnamelen(d);
if (idx != -1)
d[idx] = 0;
dpath = d;
bname = zfs_basename(b);
if (realpath(dpath, path_name) == NULL) {
(void) fprintf(stderr, "cannot resolve path '%s'\n",
dpath);
free(d);
free(b);
return (ENOENT);
}

if (strcmp(dpath, path_name) == 0)
if (strcmp(dpath, path_name) == 0) {
free(d);
free(b);
return (ENOENT); // We already tried this path
}

strlcat(path_name, "/", sizeof (path_name));
path_len = strlcat(path_name, bname, sizeof (path_name));
Expand Down

0 comments on commit 84848e9

Please sign in to comment.