2018-11-05 19:22:33 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
2022-07-11 21:16:13 +00:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2018-11-05 19:22:33 +00:00
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* Copyright (c) 2018 by Delphix. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LIBZUTIL_H
|
2021-05-15 09:53:14 +00:00
|
|
|
#define _LIBZUTIL_H extern __attribute__((visibility("default")))
|
2018-11-05 19:22:33 +00:00
|
|
|
|
|
|
|
#include <sys/nvpair.h>
|
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2023-10-20 16:29:02 +00:00
|
|
|
* Default wait time in milliseconds for a device name to be created.
|
2018-11-05 19:22:33 +00:00
|
|
|
*/
|
|
|
|
#define DISK_LABEL_WAIT (30 * 1000) /* 30 seconds */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pool Config Operations
|
|
|
|
*
|
|
|
|
* These are specific to the library libzfs or libzpool instance.
|
|
|
|
*/
|
|
|
|
typedef nvlist_t *refresh_config_func_t(void *, nvlist_t *);
|
|
|
|
|
|
|
|
typedef int pool_active_func_t(void *, const char *, uint64_t, boolean_t *);
|
|
|
|
|
|
|
|
typedef const struct pool_config_ops {
|
|
|
|
refresh_config_func_t *pco_refresh_config;
|
|
|
|
pool_active_func_t *pco_pool_active;
|
|
|
|
} pool_config_ops_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An instance of pool_config_ops_t is expected in the caller's binary.
|
|
|
|
*/
|
2022-09-30 22:34:39 +00:00
|
|
|
_LIBZUTIL_H pool_config_ops_t libzfs_config_ops;
|
|
|
|
_LIBZUTIL_H pool_config_ops_t libzpool_config_ops;
|
2018-11-05 19:22:33 +00:00
|
|
|
|
2022-09-26 13:40:43 +00:00
|
|
|
typedef enum lpc_error {
|
|
|
|
LPC_SUCCESS = 0, /* no error -- success */
|
|
|
|
LPC_BADCACHE = 2000, /* out of memory */
|
|
|
|
LPC_BADPATH, /* must be an absolute path */
|
|
|
|
LPC_NOMEM, /* out of memory */
|
|
|
|
LPC_EACCESS, /* some devices require root privileges */
|
|
|
|
LPC_UNKNOWN
|
|
|
|
} lpc_error_t;
|
|
|
|
|
2018-11-05 19:22:33 +00:00
|
|
|
typedef struct importargs {
|
|
|
|
char **path; /* a list of paths to search */
|
|
|
|
int paths; /* number of paths to search */
|
|
|
|
const char *poolname; /* name of a pool to find */
|
|
|
|
uint64_t guid; /* guid of a pool to find */
|
|
|
|
const char *cachefile; /* cachefile to use for import */
|
|
|
|
boolean_t can_be_active; /* can the pool be active? */
|
|
|
|
boolean_t scan; /* prefer scanning to libblkid cache */
|
|
|
|
nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
|
|
|
|
} importargs_t;
|
|
|
|
|
2022-09-26 13:40:43 +00:00
|
|
|
typedef struct libpc_handle {
|
|
|
|
int lpc_error;
|
|
|
|
boolean_t lpc_printerr;
|
|
|
|
boolean_t lpc_open_access_error;
|
|
|
|
boolean_t lpc_desc_active;
|
|
|
|
char lpc_desc[1024];
|
|
|
|
pool_config_ops_t *lpc_ops;
|
|
|
|
void *lpc_lib_handle;
|
|
|
|
} libpc_handle_t;
|
|
|
|
|
|
|
|
_LIBZUTIL_H const char *libpc_error_description(libpc_handle_t *);
|
|
|
|
_LIBZUTIL_H nvlist_t *zpool_search_import(libpc_handle_t *, importargs_t *);
|
|
|
|
_LIBZUTIL_H int zpool_find_config(libpc_handle_t *, const char *, nvlist_t **,
|
|
|
|
importargs_t *);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H const char * const * zpool_default_search_paths(size_t *count);
|
|
|
|
_LIBZUTIL_H int zpool_read_label(int, nvlist_t **, int *);
|
|
|
|
_LIBZUTIL_H int zpool_label_disk_wait(const char *, int);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
|
|
|
struct udev_device;
|
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H int zfs_device_get_devid(struct udev_device *, char *, size_t);
|
|
|
|
_LIBZUTIL_H int zfs_device_get_physical(struct udev_device *, char *, size_t);
|
2018-11-07 01:47:52 +00:00
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H void update_vdev_config_dev_strs(nvlist_t *);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Default device paths
|
|
|
|
*/
|
|
|
|
#define DISK_ROOT "/dev"
|
|
|
|
#define UDISK_ROOT "/dev/disk"
|
|
|
|
#define ZVOL_ROOT "/dev/zvol"
|
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H int zfs_append_partition(char *path, size_t max_len);
|
|
|
|
_LIBZUTIL_H int zfs_resolve_shortname(const char *name, char *path,
|
|
|
|
size_t pathlen);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
2022-05-03 17:56:12 +00:00
|
|
|
_LIBZUTIL_H char *zfs_strip_partition(const char *);
|
|
|
|
_LIBZUTIL_H const char *zfs_strip_path(const char *);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H int zfs_strcmp_pathname(const char *, const char *, int);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H boolean_t zfs_dev_is_dm(const char *);
|
|
|
|
_LIBZUTIL_H boolean_t zfs_dev_is_whole_disk(const char *);
|
|
|
|
_LIBZUTIL_H int zfs_dev_flush(int);
|
|
|
|
_LIBZUTIL_H char *zfs_get_underlying_path(const char *);
|
|
|
|
_LIBZUTIL_H char *zfs_get_enclosure_sysfs_path(const char *);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H boolean_t is_mpath_whole_disk(const char *);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H boolean_t zfs_isnumber(const char *);
|
2019-09-30 19:16:06 +00:00
|
|
|
|
2018-11-05 19:22:33 +00:00
|
|
|
/*
|
|
|
|
* Formats for iostat numbers. Examples: "12K", "30ms", "4B", "2321234", "-".
|
|
|
|
*
|
|
|
|
* ZFS_NICENUM_1024: Print kilo, mega, tera, peta, exa..
|
|
|
|
* ZFS_NICENUM_BYTES: Print single bytes ("13B"), kilo, mega, tera...
|
|
|
|
* ZFS_NICENUM_TIME: Print nanosecs, microsecs, millisecs, seconds...
|
|
|
|
* ZFS_NICENUM_RAW: Print the raw number without any formatting
|
|
|
|
* ZFS_NICENUM_RAWTIME: Same as RAW, but print dashes ('-') for zero.
|
|
|
|
*/
|
|
|
|
enum zfs_nicenum_format {
|
|
|
|
ZFS_NICENUM_1024 = 0,
|
|
|
|
ZFS_NICENUM_BYTES = 1,
|
|
|
|
ZFS_NICENUM_TIME = 2,
|
|
|
|
ZFS_NICENUM_RAW = 3,
|
|
|
|
ZFS_NICENUM_RAWTIME = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a number to a human-readable form.
|
|
|
|
*/
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H void zfs_nicebytes(uint64_t, char *, size_t);
|
|
|
|
_LIBZUTIL_H void zfs_nicenum(uint64_t, char *, size_t);
|
|
|
|
_LIBZUTIL_H void zfs_nicenum_format(uint64_t, char *, size_t,
|
2018-11-05 19:22:33 +00:00
|
|
|
enum zfs_nicenum_format);
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H void zfs_nicetime(uint64_t, char *, size_t);
|
|
|
|
_LIBZUTIL_H void zfs_niceraw(uint64_t, char *, size_t);
|
2018-11-05 19:22:33 +00:00
|
|
|
|
|
|
|
#define nicenum(num, buf, size) zfs_nicenum(num, buf, size)
|
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
|
|
|
|
_LIBZUTIL_H int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
|
2018-11-05 19:22:33 +00:00
|
|
|
uint_t *);
|
|
|
|
|
2019-11-12 18:40:39 +00:00
|
|
|
struct zfs_cmd;
|
|
|
|
|
2019-12-20 00:26:07 +00:00
|
|
|
/*
|
|
|
|
* List of colors to use
|
|
|
|
*/
|
2023-03-13 22:23:04 +00:00
|
|
|
#define ANSI_BLACK "\033[0;30m"
|
2019-12-20 00:26:07 +00:00
|
|
|
#define ANSI_RED "\033[0;31m"
|
2022-12-12 23:30:51 +00:00
|
|
|
#define ANSI_GREEN "\033[0;32m"
|
2019-12-20 00:26:07 +00:00
|
|
|
#define ANSI_YELLOW "\033[0;33m"
|
2022-12-12 23:30:51 +00:00
|
|
|
#define ANSI_BLUE "\033[0;34m"
|
2023-03-13 22:23:04 +00:00
|
|
|
#define ANSI_BOLD_BLUE "\033[1;34m" /* light blue */
|
|
|
|
#define ANSI_MAGENTA "\033[0;35m"
|
|
|
|
#define ANSI_CYAN "\033[0;36m"
|
|
|
|
#define ANSI_GRAY "\033[0;37m"
|
|
|
|
|
2019-12-20 00:26:07 +00:00
|
|
|
#define ANSI_RESET "\033[0m"
|
|
|
|
#define ANSI_BOLD "\033[1m"
|
|
|
|
|
2023-04-05 16:57:01 +00:00
|
|
|
_LIBZUTIL_H int use_color(void);
|
2022-04-19 18:38:30 +00:00
|
|
|
_LIBZUTIL_H void color_start(const char *color);
|
2021-05-15 09:53:14 +00:00
|
|
|
_LIBZUTIL_H void color_end(void);
|
2022-04-19 18:38:30 +00:00
|
|
|
_LIBZUTIL_H int printf_color(const char *color, const char *format, ...);
|
2019-12-20 00:26:07 +00:00
|
|
|
|
2021-06-03 15:17:09 +00:00
|
|
|
_LIBZUTIL_H const char *zfs_basename(const char *path);
|
|
|
|
_LIBZUTIL_H ssize_t zfs_dirnamelen(const char *path);
|
2023-01-17 18:17:35 +00:00
|
|
|
#ifdef __linux__
|
2023-02-02 23:16:40 +00:00
|
|
|
extern char **environ;
|
2023-01-17 18:17:35 +00:00
|
|
|
_LIBZUTIL_H void zfs_setproctitle_init(int argc, char *argv[], char *envp[]);
|
|
|
|
_LIBZUTIL_H void zfs_setproctitle(const char *fmt, ...);
|
|
|
|
#else
|
|
|
|
#define zfs_setproctitle(fmt, ...) setproctitle(fmt, ##__VA_ARGS__)
|
|
|
|
#define zfs_setproctitle_init(x, y, z) ((void)0)
|
|
|
|
#endif
|
2021-06-03 15:17:09 +00:00
|
|
|
|
2021-10-04 19:32:16 +00:00
|
|
|
/*
|
|
|
|
* These functions are used by the ZFS libraries and cmd/zpool code, but are
|
|
|
|
* not exported in the ABI.
|
|
|
|
*/
|
|
|
|
typedef int (*pool_vdev_iter_f)(void *, nvlist_t *, void *);
|
|
|
|
int for_each_vdev_cb(void *zhp, nvlist_t *nv, pool_vdev_iter_f func,
|
|
|
|
void *data);
|
|
|
|
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);
|
2023-11-07 17:09:24 +00:00
|
|
|
_LIBZUTIL_H void update_vdev_config_dev_sysfs_path(nvlist_t *nv,
|
|
|
|
const char *path, const char *key);
|
2018-11-05 19:22:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _LIBZUTIL_H */
|