Skip to content

Commit

Permalink
Add a linux and freebsd compat function for opening the kstat
Browse files Browse the repository at this point in the history
Signed-off-by: Olaf Faaland <[email protected]>
  • Loading branch information
ofaaland committed Oct 20, 2021
1 parent a24c100 commit e930c99
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3465,7 +3465,7 @@ typedef struct import_progress_args {
static void *
report_import_progress_thread(void *arg)
{
char path[] = "/proc/spl/kstat/zfs/import_progress";
char kstat_path[] = "import_progress";
import_progress_args_t *pa = arg;
struct timespec start = {0};
struct timespec last_report = {0};
Expand All @@ -3475,7 +3475,7 @@ report_import_progress_thread(void *arg)
int rc = 0;
int import_kstat;

import_kstat = open(path, O_RDONLY);
import_kstat = open_kstat(kstat_path);
if (import_kstat < 0)
rc = -1;

Expand Down Expand Up @@ -3581,9 +3581,9 @@ report_import_progress_thread(void *arg)
}

if (rc < 0) {
fprintf(stderr, "%s is not available to monitor the "
fprintf(stderr, "kstat %s is not available to monitor the "
"progress of the import. The import is "
"continuing.\n", path);
"continuing.\n", kstat_path);
}

if (import_kstat > 0)
Expand Down
1 change: 1 addition & 0 deletions include/libzutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ int for_each_vdev_cb(void *zhp, nvlist_t *nv, pool_vdev_iter_f func,
int for_each_vdev_in_nvlist(nvlist_t *nvroot, pool_vdev_iter_f func,
void *data);
void update_vdevs_config_dev_sysfs_path(nvlist_t *config);
int open_kstat(char *path_suffix);
#ifdef __cplusplus
}
#endif
Expand Down
17 changes: 17 additions & 0 deletions lib/libzutil/os/freebsd/zutil_import_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,20 @@ void
update_vdevs_config_dev_sysfs_path(nvlist_t *config)
{
}

/*
* Open a kstat and return the filehandle or error.
*/
int
open_kstat(char *path_suffix)
{
char kstat_prefix[] = "/dev/kstat/zfs/";
char path[MAXPATHLEN];

if (strlcpy(path, kstat_prefix, sizeof (path)) >= sizeof (path))
return (-ENAMETOOLONG);
if (strlcat(path, path_suffix, sizeof (path)) >= sizeof (path))
return (-ENAMETOOLONG);

return (open(path, O_RDONLY));
}
17 changes: 17 additions & 0 deletions lib/libzutil/os/linux/zutil_import_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,23 @@ update_vdevs_config_dev_sysfs_path(nvlist_t *config)
for_each_vdev_in_nvlist(nvroot, sysfs_path_pool_vdev_iter_f, NULL);
}

/*
* Open a kstat and return the filehandle or error.
*/
int
open_kstat(char *path_suffix)
{
char kstat_prefix[] = "/proc/spl/kstat/zfs/";
char path[MAXPATHLEN];

if (strlcpy(path, kstat_prefix, sizeof (path)) >= sizeof (path))
return (-ENAMETOOLONG);
if (strlcat(path, path_suffix, sizeof (path)) >= sizeof (path))
return (-ENAMETOOLONG);

return (open(path, O_RDONLY));
}

/*
* Update a leaf vdev's persistent device strings
*
Expand Down

0 comments on commit e930c99

Please sign in to comment.