1eda14cbcSMatt Macy /* 2eda14cbcSMatt Macy * CDDL HEADER START 3eda14cbcSMatt Macy * 4eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 5eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 6eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 7eda14cbcSMatt Macy * 8eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9eda14cbcSMatt Macy * or http://www.opensolaris.org/os/licensing. 10eda14cbcSMatt Macy * See the License for the specific language governing permissions 11eda14cbcSMatt Macy * and limitations under the License. 12eda14cbcSMatt Macy * 13eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 14eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 16eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 17eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 18eda14cbcSMatt Macy * 19eda14cbcSMatt Macy * CDDL HEADER END 20eda14cbcSMatt Macy */ 21eda14cbcSMatt Macy /* 22eda14cbcSMatt Macy * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23eda14cbcSMatt Macy */ 24eda14cbcSMatt Macy 25eda14cbcSMatt Macy #ifndef ZPOOL_UTIL_H 26eda14cbcSMatt Macy #define ZPOOL_UTIL_H 27eda14cbcSMatt Macy 28eda14cbcSMatt Macy #include <libnvpair.h> 29eda14cbcSMatt Macy #include <libzfs.h> 30*6ba2210eSMartin Matuska #include <libzutil.h> 31eda14cbcSMatt Macy 32eda14cbcSMatt Macy #ifdef __cplusplus 33eda14cbcSMatt Macy extern "C" { 34eda14cbcSMatt Macy #endif 35eda14cbcSMatt Macy 36eda14cbcSMatt Macy /* Path to scripts you can run with "zpool status/iostat -c" */ 37eda14cbcSMatt Macy #define ZPOOL_SCRIPTS_DIR SYSCONFDIR"/zfs/zpool.d" 38eda14cbcSMatt Macy 39eda14cbcSMatt Macy /* 40eda14cbcSMatt Macy * Basic utility functions 41eda14cbcSMatt Macy */ 42eda14cbcSMatt Macy void *safe_malloc(size_t); 4316038816SMartin Matuska void *safe_realloc(void *, size_t); 44eda14cbcSMatt Macy void zpool_no_memory(void); 45eda14cbcSMatt Macy uint_t num_logs(nvlist_t *nv); 46eda14cbcSMatt Macy uint64_t array64_max(uint64_t array[], unsigned int len); 47eda14cbcSMatt Macy int highbit64(uint64_t i); 48eda14cbcSMatt Macy int lowbit64(uint64_t i); 49eda14cbcSMatt Macy 50eda14cbcSMatt Macy /* 51eda14cbcSMatt Macy * Misc utility functions 52eda14cbcSMatt Macy */ 53eda14cbcSMatt Macy char *zpool_get_cmd_search_path(void); 54eda14cbcSMatt Macy 55eda14cbcSMatt Macy /* 56eda14cbcSMatt Macy * Virtual device functions 57eda14cbcSMatt Macy */ 58eda14cbcSMatt Macy 59eda14cbcSMatt Macy nvlist_t *make_root_vdev(zpool_handle_t *zhp, nvlist_t *props, int force, 60eda14cbcSMatt Macy int check_rep, boolean_t replacing, boolean_t dryrun, int argc, 61eda14cbcSMatt Macy char **argv); 62eda14cbcSMatt Macy nvlist_t *split_mirror_vdev(zpool_handle_t *zhp, char *newname, 63eda14cbcSMatt Macy nvlist_t *props, splitflags_t flags, int argc, char **argv); 64eda14cbcSMatt Macy 65eda14cbcSMatt Macy /* 66eda14cbcSMatt Macy * Pool list functions 67eda14cbcSMatt Macy */ 68eda14cbcSMatt Macy int for_each_pool(int, char **, boolean_t unavail, zprop_list_t **, 697877fdebSMatt Macy boolean_t, zpool_iter_f, void *); 70eda14cbcSMatt Macy 71eda14cbcSMatt Macy /* Vdev list functions */ 72eda14cbcSMatt Macy int for_each_vdev(zpool_handle_t *zhp, pool_vdev_iter_f func, void *data); 73eda14cbcSMatt Macy 74eda14cbcSMatt Macy typedef struct zpool_list zpool_list_t; 75eda14cbcSMatt Macy 767877fdebSMatt Macy zpool_list_t *pool_list_get(int, char **, zprop_list_t **, boolean_t, int *); 77eda14cbcSMatt Macy void pool_list_update(zpool_list_t *); 78eda14cbcSMatt Macy int pool_list_iter(zpool_list_t *, int unavail, zpool_iter_f, void *); 79eda14cbcSMatt Macy void pool_list_free(zpool_list_t *); 80eda14cbcSMatt Macy int pool_list_count(zpool_list_t *); 81eda14cbcSMatt Macy void pool_list_remove(zpool_list_t *, zpool_handle_t *); 82eda14cbcSMatt Macy 83eda14cbcSMatt Macy extern libzfs_handle_t *g_zfs; 84eda14cbcSMatt Macy 85eda14cbcSMatt Macy 86eda14cbcSMatt Macy typedef struct vdev_cmd_data 87eda14cbcSMatt Macy { 88eda14cbcSMatt Macy char **lines; /* Array of lines of output, minus the column name */ 89eda14cbcSMatt Macy int lines_cnt; /* Number of lines in the array */ 90eda14cbcSMatt Macy 91eda14cbcSMatt Macy char **cols; /* Array of column names */ 92eda14cbcSMatt Macy int cols_cnt; /* Number of column names */ 93eda14cbcSMatt Macy 94eda14cbcSMatt Macy 95eda14cbcSMatt Macy char *path; /* vdev path */ 96eda14cbcSMatt Macy char *upath; /* vdev underlying path */ 97eda14cbcSMatt Macy char *pool; /* Pool name */ 98eda14cbcSMatt Macy char *cmd; /* backpointer to cmd */ 99eda14cbcSMatt Macy char *vdev_enc_sysfs_path; /* enclosure sysfs path (if any) */ 100eda14cbcSMatt Macy } vdev_cmd_data_t; 101eda14cbcSMatt Macy 102eda14cbcSMatt Macy typedef struct vdev_cmd_data_list 103eda14cbcSMatt Macy { 104eda14cbcSMatt Macy char *cmd; /* Command to run */ 105eda14cbcSMatt Macy unsigned int count; /* Number of vdev_cmd_data items (vdevs) */ 106eda14cbcSMatt Macy 107eda14cbcSMatt Macy /* fields used to select only certain vdevs, if requested */ 108eda14cbcSMatt Macy libzfs_handle_t *g_zfs; 109eda14cbcSMatt Macy char **vdev_names; 110eda14cbcSMatt Macy int vdev_names_count; 111eda14cbcSMatt Macy int cb_name_flags; 112eda14cbcSMatt Macy 113eda14cbcSMatt Macy vdev_cmd_data_t *data; /* Array of vdevs */ 114eda14cbcSMatt Macy 115eda14cbcSMatt Macy /* List of unique column names and widths */ 116eda14cbcSMatt Macy char **uniq_cols; 117eda14cbcSMatt Macy int uniq_cols_cnt; 118eda14cbcSMatt Macy int *uniq_cols_width; 119eda14cbcSMatt Macy 120eda14cbcSMatt Macy } vdev_cmd_data_list_t; 121eda14cbcSMatt Macy 122eda14cbcSMatt Macy vdev_cmd_data_list_t *all_pools_for_each_vdev_run(int argc, char **argv, 123eda14cbcSMatt Macy char *cmd, libzfs_handle_t *g_zfs, char **vdev_names, int vdev_names_count, 124eda14cbcSMatt Macy int cb_name_flags); 125eda14cbcSMatt Macy 126eda14cbcSMatt Macy void free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl); 127eda14cbcSMatt Macy 128eda14cbcSMatt Macy int check_device(const char *path, boolean_t force, 129eda14cbcSMatt Macy boolean_t isspare, boolean_t iswholedisk); 130eda14cbcSMatt Macy boolean_t check_sector_size_database(char *path, int *sector_size); 1311f88aa09SMartin Matuska void vdev_error(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 132eda14cbcSMatt Macy int check_file(const char *file, boolean_t force, boolean_t isspare); 13316038816SMartin Matuska void after_zpool_upgrade(zpool_handle_t *zhp); 1341f88aa09SMartin Matuska int check_file_generic(const char *file, boolean_t force, boolean_t isspare); 135eda14cbcSMatt Macy 136eda14cbcSMatt Macy #ifdef __cplusplus 137eda14cbcSMatt Macy } 138eda14cbcSMatt Macy #endif 139eda14cbcSMatt Macy 140eda14cbcSMatt Macy #endif /* ZPOOL_UTIL_H */ 141