]> git.proxmox.com Git - mirror_zfs.git/blame - include/libzutil.h
ztest: scrub ddt repair
[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
9 * or http://www.opensolaris.org/os/licensing.
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
27#define _LIBZUTIL_H
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 */
59extern const pool_config_ops_t libzfs_config_ops;
60extern const pool_config_ops_t libzpool_config_ops;
61
62typedef struct importargs {
63 char **path; /* a list of paths to search */
64 int paths; /* number of paths to search */
65 const char *poolname; /* name of a pool to find */
66 uint64_t guid; /* guid of a pool to find */
67 const char *cachefile; /* cachefile to use for import */
68 boolean_t can_be_active; /* can the pool be active? */
69 boolean_t scan; /* prefer scanning to libblkid cache */
70 nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
71} importargs_t;
72
73extern nvlist_t *zpool_search_import(void *, importargs_t *,
74 const pool_config_ops_t *);
75extern int zpool_find_config(void *, const char *, nvlist_t **, importargs_t *,
76 const pool_config_ops_t *);
77
78extern const char * const * zpool_default_search_paths(size_t *count);
79extern int zpool_read_label(int, nvlist_t **, int *);
80extern int zpool_label_disk_wait(const char *, int);
81
95692927 82#ifdef HAVE_LIBUDEV
e89f1295
DB
83struct udev_device;
84
85extern int zfs_device_get_devid(struct udev_device *, char *, size_t);
86extern int zfs_device_get_physical(struct udev_device *, char *, size_t);
95692927
DB
87#else
88#define zfs_device_get_devid(dev, bufptr, buflen) (ENODATA)
89#define zfs_device_get_physical(dev, bufptr, buflen) (ENODATA)
90#endif
91
e89f1295
DB
92extern void update_vdev_config_dev_strs(nvlist_t *);
93
94/*
95 * Default device paths
96 */
97#define DISK_ROOT "/dev"
98#define UDISK_ROOT "/dev/disk"
99#define ZVOL_ROOT "/dev/zvol"
100
101extern int zfs_append_partition(char *path, size_t max_len);
102extern int zfs_resolve_shortname(const char *name, char *path, size_t pathlen);
103
104extern char *zfs_strip_partition(char *);
105extern char *zfs_strip_partition_path(char *);
106
107extern int zfs_strcmp_pathname(const char *, const char *, int);
108
109extern int zfs_dev_is_dm(const char *);
110extern int zfs_dev_is_whole_disk(const char *);
111extern char *zfs_get_underlying_path(const char *);
112extern char *zfs_get_enclosure_sysfs_path(const char *);
113
114#ifdef HAVE_LIBUDEV
115extern boolean_t is_mpath_whole_disk(const char *);
116#else
95692927 117#define is_mpath_whole_disk(path) (B_FALSE)
e89f1295
DB
118#endif
119
120/*
121 * Formats for iostat numbers. Examples: "12K", "30ms", "4B", "2321234", "-".
122 *
123 * ZFS_NICENUM_1024: Print kilo, mega, tera, peta, exa..
124 * ZFS_NICENUM_BYTES: Print single bytes ("13B"), kilo, mega, tera...
125 * ZFS_NICENUM_TIME: Print nanosecs, microsecs, millisecs, seconds...
126 * ZFS_NICENUM_RAW: Print the raw number without any formatting
127 * ZFS_NICENUM_RAWTIME: Same as RAW, but print dashes ('-') for zero.
128 */
129enum zfs_nicenum_format {
130 ZFS_NICENUM_1024 = 0,
131 ZFS_NICENUM_BYTES = 1,
132 ZFS_NICENUM_TIME = 2,
133 ZFS_NICENUM_RAW = 3,
134 ZFS_NICENUM_RAWTIME = 4
135};
136
137/*
138 * Convert a number to a human-readable form.
139 */
140extern void zfs_nicebytes(uint64_t, char *, size_t);
141extern void zfs_nicenum(uint64_t, char *, size_t);
142extern void zfs_nicenum_format(uint64_t, char *, size_t,
143 enum zfs_nicenum_format);
144extern void zfs_nicetime(uint64_t, char *, size_t);
145
146#define nicenum(num, buf, size) zfs_nicenum(num, buf, size)
147
148extern void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
149extern int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
150 uint_t *);
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif /* _LIBZUTIL_H */