Skip to content

Commit

Permalink
Changes to common code from macos branch
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewc12 committed Nov 15, 2023
1 parent e45dcb7 commit e4f68af
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
29 changes: 27 additions & 2 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <libintl.h>
#include <libnvpair.h>
#include <libzutil.h>
Expand Down Expand Up @@ -272,6 +273,9 @@ static nvlist_t *
make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary)
{
char path[MAXPATHLEN];
char *d, *b;
char *dpath;
const char *bname;
struct stat64 statbuf;
nvlist_t *vdev = NULL;
const char *type = NULL;
Expand Down Expand Up @@ -307,8 +311,29 @@ make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary)
return (NULL);
}

/* After whole disk check restore original passed path */
strlcpy(path, arg, sizeof (path));
/*
* After whole disk check restore original passed path and use
* the realpath of the directory.
*/
d = strdup(arg);
b = strdup(arg);
int idx = zfs_dirnamelen(d);
if (idx != -1)
d[idx] = 0;
dpath = d;
bname = zfs_basename(b);
if (realpath(dpath, path) == NULL) {
(void) fprintf(stderr,
gettext("cannot resolve path '%s'\n"), dpath);
free(d);
free(b);
return (NULL);
}

strlcat(path, "/", sizeof (path));
strlcat(path, bname, sizeof (path));
free(d);
free(b);
} else if (zpool_is_draid_spare(arg)) {
if (!is_primary) {
(void) fprintf(stderr,
Expand Down
40 changes: 37 additions & 3 deletions lib/libzutil/zutil_device_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include <errno.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -158,6 +159,8 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk)
char path_name[MAXPATHLEN];
char cmp_name[MAXPATHLEN];
char *dir, *tmp = NULL;
char *d, *b;
const char *dpath, *bname;

/* Strip redundant slashes if they exist due to ZPOOL_IMPORT_PATH */
cmp_name[0] = '\0';
Expand All @@ -182,8 +185,39 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk)
return (ENOMEM);
}

if ((path_len != cmp_len) || strcmp(path_name, cmp_name))
return (ENOENT);
if ((path_len == cmp_len) && strcmp(path_name, cmp_name) == 0)
return (0);
else {
int idx;
d = strdup(path_name);
b = strdup(path_name);
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) {
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));
free(d);
free(b);

if ((path_len == cmp_len) && strcmp(path_name, cmp_name) == 0)
return (0);
}

return (0);
return (ENOENT);
}

0 comments on commit e4f68af

Please sign in to comment.