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 9271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0. 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> 306ba2210eSMartin 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 */ 68681ce946SMartin Matuska int for_each_pool(int, char **, boolean_t unavail, zprop_list_t **, zfs_type_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 76681ce946SMartin Matuska zpool_list_t *pool_list_get(int, char **, zprop_list_t **, zfs_type_t, 77681ce946SMartin Matuska boolean_t, int *); 78eda14cbcSMatt Macy void pool_list_update(zpool_list_t *); 79eda14cbcSMatt Macy int pool_list_iter(zpool_list_t *, int unavail, zpool_iter_f, void *); 80eda14cbcSMatt Macy void pool_list_free(zpool_list_t *); 81eda14cbcSMatt Macy int pool_list_count(zpool_list_t *); 82eda14cbcSMatt Macy void pool_list_remove(zpool_list_t *, zpool_handle_t *); 83eda14cbcSMatt Macy 84eda14cbcSMatt Macy extern libzfs_handle_t *g_zfs; 85eda14cbcSMatt Macy 86eda14cbcSMatt Macy 87eda14cbcSMatt Macy typedef struct vdev_cmd_data 88eda14cbcSMatt Macy { 89eda14cbcSMatt Macy char **lines; /* Array of lines of output, minus the column name */ 90eda14cbcSMatt Macy int lines_cnt; /* Number of lines in the array */ 91eda14cbcSMatt Macy 92eda14cbcSMatt Macy char **cols; /* Array of column names */ 93eda14cbcSMatt Macy int cols_cnt; /* Number of column names */ 94eda14cbcSMatt Macy 95eda14cbcSMatt Macy 96eda14cbcSMatt Macy char *path; /* vdev path */ 97eda14cbcSMatt Macy char *upath; /* vdev underlying path */ 98eda14cbcSMatt Macy char *pool; /* Pool name */ 99eda14cbcSMatt Macy char *cmd; /* backpointer to cmd */ 100eda14cbcSMatt Macy char *vdev_enc_sysfs_path; /* enclosure sysfs path (if any) */ 101eda14cbcSMatt Macy } vdev_cmd_data_t; 102eda14cbcSMatt Macy 103eda14cbcSMatt Macy typedef struct vdev_cmd_data_list 104eda14cbcSMatt Macy { 105eda14cbcSMatt Macy char *cmd; /* Command to run */ 106eda14cbcSMatt Macy unsigned int count; /* Number of vdev_cmd_data items (vdevs) */ 107eda14cbcSMatt Macy 108eda14cbcSMatt Macy /* fields used to select only certain vdevs, if requested */ 109eda14cbcSMatt Macy libzfs_handle_t *g_zfs; 110eda14cbcSMatt Macy char **vdev_names; 111eda14cbcSMatt Macy int vdev_names_count; 112eda14cbcSMatt Macy int cb_name_flags; 113eda14cbcSMatt Macy 114eda14cbcSMatt Macy vdev_cmd_data_t *data; /* Array of vdevs */ 115eda14cbcSMatt Macy 116eda14cbcSMatt Macy /* List of unique column names and widths */ 117eda14cbcSMatt Macy char **uniq_cols; 118eda14cbcSMatt Macy int uniq_cols_cnt; 119eda14cbcSMatt Macy int *uniq_cols_width; 120eda14cbcSMatt Macy 121eda14cbcSMatt Macy } vdev_cmd_data_list_t; 122eda14cbcSMatt Macy 123eda14cbcSMatt Macy vdev_cmd_data_list_t *all_pools_for_each_vdev_run(int argc, char **argv, 124eda14cbcSMatt Macy char *cmd, libzfs_handle_t *g_zfs, char **vdev_names, int vdev_names_count, 125eda14cbcSMatt Macy int cb_name_flags); 126eda14cbcSMatt Macy 127eda14cbcSMatt Macy void free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl); 128eda14cbcSMatt Macy 129abcdc1b9SMartin Matuska void free_vdev_cmd_data(vdev_cmd_data_t *data); 130abcdc1b9SMartin Matuska 131abcdc1b9SMartin Matuska int vdev_run_cmd_simple(char *path, char *cmd); 132abcdc1b9SMartin Matuska 133eda14cbcSMatt Macy int check_device(const char *path, boolean_t force, 134eda14cbcSMatt Macy boolean_t isspare, boolean_t iswholedisk); 135eda14cbcSMatt Macy boolean_t check_sector_size_database(char *path, int *sector_size); 1361f88aa09SMartin Matuska void vdev_error(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 137eda14cbcSMatt Macy int check_file(const char *file, boolean_t force, boolean_t isspare); 13816038816SMartin Matuska void after_zpool_upgrade(zpool_handle_t *zhp); 1391f88aa09SMartin Matuska int check_file_generic(const char *file, boolean_t force, boolean_t isspare); 140eda14cbcSMatt Macy 141*b356da80SMartin Matuska int zpool_power(zpool_handle_t *zhp, char *vdev, boolean_t turn_on); 142*b356da80SMartin Matuska int zpool_power_current_state(zpool_handle_t *zhp, char *vdev); 143*b356da80SMartin Matuska 144eda14cbcSMatt Macy #ifdef __cplusplus 145eda14cbcSMatt Macy } 146eda14cbcSMatt Macy #endif 147eda14cbcSMatt Macy 148eda14cbcSMatt Macy #endif /* ZPOOL_UTIL_H */ 149