diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 317342abfcc4..e6fca8a8ff2d 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -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}; @@ -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; @@ -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) diff --git a/include/libzutil.h b/include/libzutil.h index c0a660ea7067..badc563353b7 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -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 diff --git a/lib/libzutil/os/freebsd/zutil_import_os.c b/lib/libzutil/os/freebsd/zutil_import_os.c index 3da661f4c557..d10ec6ac39cb 100644 --- a/lib/libzutil/os/freebsd/zutil_import_os.c +++ b/lib/libzutil/os/freebsd/zutil_import_os.c @@ -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)); +} diff --git a/lib/libzutil/os/linux/zutil_import_os.c b/lib/libzutil/os/linux/zutil_import_os.c index ab692401d88e..d321abf250e5 100644 --- a/lib/libzutil/os/linux/zutil_import_os.c +++ b/lib/libzutil/os/linux/zutil_import_os.c @@ -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 *