]> git.proxmox.com Git - mirror_zfs.git/blame - include/libzutil.h
Expose libzutil error info in libpc_handle_t
[mirror_zfs.git] / include / libzutil.h
CommitLineData
e89f1295
DB
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1d3ba0bf 9 * or https://opensource.org/licenses/CDDL-1.0.
e89f1295
DB
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2018 by Delphix. All rights reserved.
24 */
25
26#ifndef _LIBZUTIL_H
739cfb96 27#define _LIBZUTIL_H extern __attribute__((visibility("default")))
e89f1295
DB
28
29#include <sys/nvpair.h>
30#include <sys/fs/zfs.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/*
37 * Default wait time for a device name to be created.
38 */
39#define DISK_LABEL_WAIT (30 * 1000) /* 30 seconds */
40
41
42/*
43 * Pool Config Operations
44 *
45 * These are specific to the library libzfs or libzpool instance.
46 */
47typedef nvlist_t *refresh_config_func_t(void *, nvlist_t *);
48
49typedef int pool_active_func_t(void *, const char *, uint64_t, boolean_t *);
50
51typedef const struct pool_config_ops {
52 refresh_config_func_t *pco_refresh_config;
53 pool_active_func_t *pco_pool_active;
54} pool_config_ops_t;
55
56/*
57 * An instance of pool_config_ops_t is expected in the caller's binary.
58 */
a2d5643f
TR
59_LIBZUTIL_H pool_config_ops_t libzfs_config_ops;
60_LIBZUTIL_H pool_config_ops_t libzpool_config_ops;
e89f1295 61
d9ac17a5
US
62typedef enum lpc_error {
63 LPC_SUCCESS = 0, /* no error -- success */
64 LPC_BADCACHE = 2000, /* out of memory */
65 LPC_BADPATH, /* must be an absolute path */
66 LPC_NOMEM, /* out of memory */
67 LPC_EACCESS, /* some devices require root privileges */
68 LPC_UNKNOWN
69} lpc_error_t;
70
e89f1295
DB
71typedef struct importargs {
72 char **path; /* a list of paths to search */
73 int paths; /* number of paths to search */
74 const char *poolname; /* name of a pool to find */
75 uint64_t guid; /* guid of a pool to find */
76 const char *cachefile; /* cachefile to use for import */
77 boolean_t can_be_active; /* can the pool be active? */
78 boolean_t scan; /* prefer scanning to libblkid cache */
79 nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
80} importargs_t;
81
d9ac17a5
US
82typedef struct libpc_handle {
83 int lpc_error;
84 boolean_t lpc_printerr;
85 boolean_t lpc_open_access_error;
86 boolean_t lpc_desc_active;
87 char lpc_desc[1024];
88 pool_config_ops_t *lpc_ops;
89 void *lpc_lib_handle;
90} libpc_handle_t;
91
92_LIBZUTIL_H const char *libpc_error_description(libpc_handle_t *);
93_LIBZUTIL_H nvlist_t *zpool_search_import(libpc_handle_t *, importargs_t *);
94_LIBZUTIL_H int zpool_find_config(libpc_handle_t *, const char *, nvlist_t **,
95 importargs_t *);
e89f1295 96
739cfb96
AZ
97_LIBZUTIL_H const char * const * zpool_default_search_paths(size_t *count);
98_LIBZUTIL_H int zpool_read_label(int, nvlist_t **, int *);
99_LIBZUTIL_H int zpool_label_disk_wait(const char *, int);
e89f1295
DB
100
101struct udev_device;
102
739cfb96
AZ
103_LIBZUTIL_H int zfs_device_get_devid(struct udev_device *, char *, size_t);
104_LIBZUTIL_H int zfs_device_get_physical(struct udev_device *, char *, size_t);
95692927 105
739cfb96 106_LIBZUTIL_H void update_vdev_config_dev_strs(nvlist_t *);
e89f1295
DB
107
108/*
109 * Default device paths
110 */
111#define DISK_ROOT "/dev"
112#define UDISK_ROOT "/dev/disk"
113#define ZVOL_ROOT "/dev/zvol"
114
739cfb96
AZ
115_LIBZUTIL_H int zfs_append_partition(char *path, size_t max_len);
116_LIBZUTIL_H int zfs_resolve_shortname(const char *name, char *path,
117 size_t pathlen);
e89f1295 118
5ac80603
AZ
119_LIBZUTIL_H char *zfs_strip_partition(const char *);
120_LIBZUTIL_H const char *zfs_strip_path(const char *);
e89f1295 121
739cfb96 122_LIBZUTIL_H int zfs_strcmp_pathname(const char *, const char *, int);
e89f1295 123
739cfb96
AZ
124_LIBZUTIL_H boolean_t zfs_dev_is_dm(const char *);
125_LIBZUTIL_H boolean_t zfs_dev_is_whole_disk(const char *);
126_LIBZUTIL_H int zfs_dev_flush(int);
127_LIBZUTIL_H char *zfs_get_underlying_path(const char *);
128_LIBZUTIL_H char *zfs_get_enclosure_sysfs_path(const char *);
e89f1295 129
739cfb96 130_LIBZUTIL_H boolean_t is_mpath_whole_disk(const char *);
e89f1295 131
739cfb96 132_LIBZUTIL_H boolean_t zfs_isnumber(const char *);
3283f137 133
e89f1295
DB
134/*
135 * Formats for iostat numbers. Examples: "12K", "30ms", "4B", "2321234", "-".
136 *
137 * ZFS_NICENUM_1024: Print kilo, mega, tera, peta, exa..
138 * ZFS_NICENUM_BYTES: Print single bytes ("13B"), kilo, mega, tera...
139 * ZFS_NICENUM_TIME: Print nanosecs, microsecs, millisecs, seconds...
140 * ZFS_NICENUM_RAW: Print the raw number without any formatting
141 * ZFS_NICENUM_RAWTIME: Same as RAW, but print dashes ('-') for zero.
142 */
143enum zfs_nicenum_format {
144 ZFS_NICENUM_1024 = 0,
145 ZFS_NICENUM_BYTES = 1,
146 ZFS_NICENUM_TIME = 2,
147 ZFS_NICENUM_RAW = 3,
148 ZFS_NICENUM_RAWTIME = 4
149};
150
151/*
152 * Convert a number to a human-readable form.
153 */
739cfb96
AZ
154_LIBZUTIL_H void zfs_nicebytes(uint64_t, char *, size_t);
155_LIBZUTIL_H void zfs_nicenum(uint64_t, char *, size_t);
156_LIBZUTIL_H void zfs_nicenum_format(uint64_t, char *, size_t,
e89f1295 157 enum zfs_nicenum_format);
739cfb96
AZ
158_LIBZUTIL_H void zfs_nicetime(uint64_t, char *, size_t);
159_LIBZUTIL_H void zfs_niceraw(uint64_t, char *, size_t);
e89f1295
DB
160
161#define nicenum(num, buf, size) zfs_nicenum(num, buf, size)
162
739cfb96
AZ
163_LIBZUTIL_H void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
164_LIBZUTIL_H int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
e89f1295
DB
165 uint_t *);
166
1f2f46be 167struct zfs_cmd;
1f2f46be 168
9fb2771a
TH
169/*
170 * List of colors to use
171 */
172#define ANSI_RED "\033[0;31m"
173#define ANSI_YELLOW "\033[0;33m"
174#define ANSI_RESET "\033[0m"
175#define ANSI_BOLD "\033[1m"
176
a926aab9 177_LIBZUTIL_H void color_start(const char *color);
739cfb96 178_LIBZUTIL_H void color_end(void);
a926aab9 179_LIBZUTIL_H int printf_color(const char *color, const char *format, ...);
9fb2771a 180
0854d4c1
AZ
181_LIBZUTIL_H const char *zfs_basename(const char *path);
182_LIBZUTIL_H ssize_t zfs_dirnamelen(const char *path);
183
2a8430a2
TH
184/*
185 * These functions are used by the ZFS libraries and cmd/zpool code, but are
186 * not exported in the ABI.
187 */
188typedef int (*pool_vdev_iter_f)(void *, nvlist_t *, void *);
189int for_each_vdev_cb(void *zhp, nvlist_t *nv, pool_vdev_iter_f func,
190 void *data);
191int for_each_vdev_in_nvlist(nvlist_t *nvroot, pool_vdev_iter_f func,
192 void *data);
193void update_vdevs_config_dev_sysfs_path(nvlist_t *config);
e89f1295
DB
194#ifdef __cplusplus
195}
196#endif
197
198#endif /* _LIBZUTIL_H */