xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool_util.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 /*
13  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
14  */
15 
16 #ifndef	ZPOOL_UTIL_H
17 #define	ZPOOL_UTIL_H
18 
19 #include <libnvpair.h>
20 #include <libzfs.h>
21 #include <libzutil.h>
22 
23 #ifdef	__cplusplus
24 extern "C" {
25 #endif
26 
27 /* Path to scripts you can run with "zpool status/iostat -c" */
28 #define	ZPOOL_SCRIPTS_DIR SYSCONFDIR"/zfs/zpool.d"
29 
30 /*
31  * Basic utility functions
32  */
33 void *safe_malloc(size_t);
34 void *safe_realloc(void *, size_t);
35 void zpool_no_memory(void);
36 uint_t num_logs(nvlist_t *nv);
37 uint64_t array64_max(uint64_t array[], unsigned int len);
38 
39 /*
40  * Misc utility functions
41  */
42 char *zpool_get_cmd_search_path(void);
43 
44 /*
45  * Virtual device functions
46  */
47 
48 nvlist_t *make_root_vdev(zpool_handle_t *zhp, nvlist_t *props, int force,
49     int check_rep, boolean_t replacing, boolean_t dryrun, int argc,
50     char **argv);
51 nvlist_t *split_mirror_vdev(zpool_handle_t *zhp, char *newname,
52     nvlist_t *props, splitflags_t flags, int argc, char **argv);
53 
54 /*
55  * Pool list functions
56  */
57 int for_each_pool(int, char **, boolean_t unavail, zprop_list_t **, zfs_type_t,
58     boolean_t, zpool_iter_f, void *);
59 
60 /* Vdev list functions */
61 int for_each_vdev(zpool_handle_t *zhp, pool_vdev_iter_f func, void *data);
62 
63 typedef struct zpool_list zpool_list_t;
64 
65 zpool_list_t *pool_list_get(int, char **, zprop_list_t **, zfs_type_t,
66     boolean_t, int *);
67 int pool_list_refresh(zpool_list_t *);
68 int pool_list_iter(zpool_list_t *, int unavail, zpool_iter_f, void *);
69 void pool_list_free(zpool_list_t *);
70 int pool_list_count(zpool_list_t *);
71 
72 extern libzfs_handle_t *g_zfs;
73 
74 
75 typedef	struct vdev_cmd_data
76 {
77 	char **lines;	/* Array of lines of output, minus the column name */
78 	int lines_cnt;	/* Number of lines in the array */
79 
80 	char **cols;	/* Array of column names */
81 	int cols_cnt;	/* Number of column names */
82 
83 
84 	char *path;	/* vdev path */
85 	char *upath;	/* vdev underlying path */
86 	char *pool;	/* Pool name */
87 	char *cmd;	/* backpointer to cmd */
88 	char *vdev_enc_sysfs_path;	/* enclosure sysfs path (if any) */
89 } vdev_cmd_data_t;
90 
91 typedef struct vdev_cmd_data_list
92 {
93 	char *cmd;		/* Command to run */
94 	unsigned int count;	/* Number of vdev_cmd_data items (vdevs) */
95 
96 	/* fields used to select only certain vdevs, if requested */
97 	libzfs_handle_t *g_zfs;
98 	char **vdev_names;
99 	int vdev_names_count;
100 	int cb_name_flags;
101 
102 	vdev_cmd_data_t *data;	/* Array of vdevs */
103 
104 	/* List of unique column names and widths */
105 	char **uniq_cols;
106 	int uniq_cols_cnt;
107 	int *uniq_cols_width;
108 
109 } vdev_cmd_data_list_t;
110 
111 vdev_cmd_data_list_t *all_pools_for_each_vdev_run(int argc, char **argv,
112     char *cmd, libzfs_handle_t *g_zfs, char **vdev_names, int vdev_names_count,
113     int cb_name_flags);
114 
115 void free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl);
116 
117 void free_vdev_cmd_data(vdev_cmd_data_t *data);
118 
119 int vdev_run_cmd_simple(char *path, char *cmd);
120 
121 int check_device(const char *path, boolean_t force,
122     boolean_t isspare, boolean_t iswholedisk);
123 boolean_t check_sector_size_database(char *path, int *sector_size);
124 void vdev_error(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
125 int check_file(const char *file, boolean_t force, boolean_t isspare);
126 void after_zpool_upgrade(zpool_handle_t *zhp);
127 int check_file_generic(const char *file, boolean_t force, boolean_t isspare);
128 
129 int zpool_power(zpool_handle_t *zhp, char *vdev, boolean_t turn_on);
130 int zpool_power_current_state(zpool_handle_t *zhp, char *vdev);
131 
132 #ifdef	__cplusplus
133 }
134 #endif
135 
136 #endif	/* ZPOOL_UTIL_H */
137