xref: /illumos-gate/usr/src/lib/libzutil/common/libzutil.h (revision 1fa2a66491e7d8ae0be84e7da4da8e812480c710)
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  * Copyright 2020 Joyent, Inc.
25  */
26 
27 #ifndef	_LIBZUTIL_H
28 #define	_LIBZUTIL_H
29 
30 #include <sys/nvpair.h>
31 #include <sys/fs/zfs.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Default wait time for a device name to be created.
39  */
40 #define	DISK_LABEL_WAIT		(30 * 1000)  /* 30 seconds */
41 
42 
43 /*
44  * Pool Config Operations
45  *
46  * These are specific to the library libzfs or libzpool instance.
47  */
48 typedef nvlist_t *refresh_config_func_t(void *, nvlist_t *);
49 
50 typedef int pool_active_func_t(void *, const char *, uint64_t, boolean_t *);
51 
52 typedef struct pool_config_ops {
53 	refresh_config_func_t	*pco_refresh_config;
54 	pool_active_func_t	*pco_pool_active;
55 } pool_config_ops_t;
56 
57 /*
58  * An instance of pool_config_ops_t is expected in the caller's binary.
59  */
60 extern const pool_config_ops_t libzfs_config_ops;
61 extern const pool_config_ops_t libzpool_config_ops;
62 
63 typedef struct importargs {
64 	char **path;		/* a list of paths to search		*/
65 	int paths;		/* number of paths to search		*/
66 	const char *poolname;	/* name of a pool to find		*/
67 	uint64_t guid;		/* guid of a pool to find		*/
68 	const char *cachefile;	/* cachefile to use for import		*/
69 	boolean_t can_be_active; /* can the pool be active?		*/
70 	boolean_t scan;		/* prefer scanning to libblkid cache    */
71 	nvlist_t *policy;	/* load policy (max txg, rewind, etc.)	*/
72 } importargs_t;
73 
74 extern nvlist_t *zpool_search_import(void *, importargs_t *,
75     const pool_config_ops_t *);
76 extern int zpool_find_config(void *, const char *, nvlist_t **, importargs_t *,
77     const pool_config_ops_t *);
78 
79 extern int zpool_read_label(int, nvlist_t **, int *);
80 
81 extern boolean_t zfs_isnumber(const char *);
82 
83 /*
84  * Formats for iostat numbers.  Examples: "12K", "30ms", "4B", "2321234", "-".
85  *
86  * ZFS_NICENUM_1024:	Print kilo, mega, tera, peta, exa..
87  * ZFS_NICENUM_BYTES:	Print single bytes ("13B"), kilo, mega, tera...
88  * ZFS_NICENUM_TIME:	Print nanosecs, microsecs, millisecs, seconds...
89  * ZFS_NICENUM_RAW:	Print the raw number without any formatting
90  * ZFS_NICENUM_RAWTIME:	Same as RAW, but print dashes ('-') for zero.
91  */
92 enum zfs_nicenum_format {
93 	ZFS_NICENUM_1024 = 0,
94 	ZFS_NICENUM_BYTES = 1,
95 	ZFS_NICENUM_TIME = 2,
96 	ZFS_NICENUM_RAW = 3,
97 	ZFS_NICENUM_RAWTIME = 4
98 };
99 
100 /*
101  * Convert a number to a human-readable form.
102  */
103 extern void zfs_nicebytes(uint64_t, char *, size_t);
104 extern void zfs_nicenum(uint64_t, char *, size_t);
105 extern void zfs_nicenum_format(uint64_t, char *, size_t,
106     enum zfs_nicenum_format);
107 extern void zfs_nicetime(uint64_t, char *, size_t);
108 
109 #define	nicenum(num, buf, size)	zfs_nicenum(num, buf, size)
110 
111 extern void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
112 extern int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
113     uint_t *);
114 
115 /* Part of SPL in OpenZFS */
116 extern ulong_t get_system_hostid(void);
117 
118 #ifdef	__cplusplus
119 }
120 #endif
121 
122 #endif	/* _LIBZUTIL_H */
123