1711890bcSjc156560 /* 2711890bcSjc156560 * CDDL HEADER START 3711890bcSjc156560 * 4711890bcSjc156560 * The contents of this file are subject to the terms of the 5711890bcSjc156560 * Common Development and Distribution License (the "License"). 6711890bcSjc156560 * You may not use this file except in compliance with the License. 7711890bcSjc156560 * 8711890bcSjc156560 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9711890bcSjc156560 * or http://www.opensolaris.org/os/licensing. 10711890bcSjc156560 * See the License for the specific language governing permissions 11711890bcSjc156560 * and limitations under the License. 12711890bcSjc156560 * 13711890bcSjc156560 * When distributing Covered Code, include this CDDL HEADER in each 14711890bcSjc156560 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15711890bcSjc156560 * If applicable, add the following below this CDDL HEADER, with the 16711890bcSjc156560 * fields enclosed by brackets "[]" replaced with your own identifying 17711890bcSjc156560 * information: Portions Copyright [yyyy] [name of copyright owner] 18711890bcSjc156560 * 19711890bcSjc156560 * CDDL HEADER END 20711890bcSjc156560 */ 21711890bcSjc156560 22711890bcSjc156560 /* 23*edabaf6fSMilan Jurik * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24711890bcSjc156560 * Use is subject to license terms. 25711890bcSjc156560 */ 26711890bcSjc156560 27711890bcSjc156560 #include <fcntl.h> 28711890bcSjc156560 #include <sys/types.h> 29711890bcSjc156560 #include <sys/stat.h> 30711890bcSjc156560 #include <stddef.h> 31711890bcSjc156560 #include <stdlib.h> 32711890bcSjc156560 #include <dirent.h> 33711890bcSjc156560 #include <dlfcn.h> 34711890bcSjc156560 #include <link.h> 35711890bcSjc156560 #include <strings.h> 36711890bcSjc156560 #include <stdio.h> 37711890bcSjc156560 #include <unistd.h> 38711890bcSjc156560 #include <sys/mnttab.h> 39711890bcSjc156560 #include <config_admin.h> 40711890bcSjc156560 #include <sys/param.h> 41711890bcSjc156560 #include <libintl.h> 42711890bcSjc156560 #include <libdevinfo.h> 43711890bcSjc156560 #include <raidcfg.h> 44711890bcSjc156560 #include <thread.h> 45711890bcSjc156560 #include <synch.h> 46711890bcSjc156560 47711890bcSjc156560 #ifndef TEXT_DOMAIN 48711890bcSjc156560 #define TEXT_DOMAIN "SYS_TEST" 49711890bcSjc156560 #endif 50711890bcSjc156560 51711890bcSjc156560 #define HASH_SLOTS 16 52711890bcSjc156560 #define HANDLER_SLOTS 256 53711890bcSjc156560 54711890bcSjc156560 /* 55711890bcSjc156560 * Raid object status; 56711890bcSjc156560 */ 57711890bcSjc156560 #define OBJ_STATUS_CMD_CLEAN -1 58711890bcSjc156560 #define OBJ_STATUS_OPENED 1 59711890bcSjc156560 #define OBJ_STATUS_SCANCOMP 1 << 1 60711890bcSjc156560 61711890bcSjc156560 #if defined(__sparcv9) 62711890bcSjc156560 #define SUPP_PLUGIN_DIR "/usr/lib/raidcfg/sparcv9" 63711890bcSjc156560 #elif defined(__amd64) 64711890bcSjc156560 #define SUPP_PLUGIN_DIR "/usr/lib/raidcfg/amd64" 65711890bcSjc156560 #else 66711890bcSjc156560 #define SUPP_PLUGIN_DIR "/usr/lib/raidcfg" 67711890bcSjc156560 #endif 68711890bcSjc156560 69711890bcSjc156560 /* 70711890bcSjc156560 * Basic types 71711890bcSjc156560 */ 72711890bcSjc156560 typedef int raid_obj_id_t; 73711890bcSjc156560 typedef int raid_obj_status_t; 74711890bcSjc156560 75711890bcSjc156560 /* 76711890bcSjc156560 * Data structures used for object maintennance 77711890bcSjc156560 */ 78711890bcSjc156560 typedef struct { 79711890bcSjc156560 void *head; 80711890bcSjc156560 void *tail; 81711890bcSjc156560 size_t offset; /* offset of double-linked element (raid_list_el_t) */ 82711890bcSjc156560 /* in the linked data structures (objects) */ 83711890bcSjc156560 } raid_list_t; 84711890bcSjc156560 85711890bcSjc156560 typedef struct { 86711890bcSjc156560 void *prev; 87711890bcSjc156560 void *next; 88711890bcSjc156560 } raid_list_el_t; 89711890bcSjc156560 90711890bcSjc156560 typedef struct { 91711890bcSjc156560 raid_obj_id_t obj_id_cnt; /* id 0 is reserved */ 92711890bcSjc156560 size_t slots; /* How many lists linked by *table */ 93711890bcSjc156560 raid_list_t *table; 94711890bcSjc156560 } raid_obj_tab_t; 95711890bcSjc156560 96711890bcSjc156560 /* 97711890bcSjc156560 * Object type structure containing function pointers; 98711890bcSjc156560 */ 99711890bcSjc156560 typedef struct { 100711890bcSjc156560 int (*compnum)(raid_obj_tab_t *, raid_obj_id_t, raid_obj_type_id_t); 101711890bcSjc156560 int (*complist)(raid_obj_tab_t *, raid_obj_id_t, int, raid_obj_id_t *, 102711890bcSjc156560 raid_obj_type_id_t); 103711890bcSjc156560 int (*get_attr)(raid_obj_tab_t *, raid_obj_id_t); 104711890bcSjc156560 int (*set_attr)(raid_obj_tab_t *, raid_obj_id_t, uint32_t, uint32_t *, 105711890bcSjc156560 char **); 106711890bcSjc156560 int (*act)(raid_obj_tab_t *, raid_obj_id_t, uint32_t, void *, char **); 107711890bcSjc156560 int (*create_obj)(raid_obj_tab_t *, raid_obj_id_t, int, 108711890bcSjc156560 raid_obj_id_t *, char **); 109711890bcSjc156560 int (*delete_obj)(raid_obj_tab_t *, raid_obj_id_t, char **); 1105c9d25d2SYu-Bo Ryan Wang int (*bind_obj)(raid_obj_tab_t *, raid_obj_id_t *, char **); 1115c9d25d2SYu-Bo Ryan Wang int (*unbind_obj)(raid_obj_tab_t *, raid_obj_id_t *, char **); 112711890bcSjc156560 } raid_obj_op_t; 113711890bcSjc156560 114711890bcSjc156560 /* 115711890bcSjc156560 * Common object data structure 116711890bcSjc156560 */ 117711890bcSjc156560 typedef struct { 118711890bcSjc156560 raid_list_el_t el; /* double-links */ 119711890bcSjc156560 120711890bcSjc156560 raid_obj_type_id_t obj_type_id; 121711890bcSjc156560 raid_obj_id_t obj_id; 122711890bcSjc156560 raid_obj_status_t status; 123711890bcSjc156560 124711890bcSjc156560 raid_obj_id_t container; 125711890bcSjc156560 raid_obj_id_t sibling; 126711890bcSjc156560 raid_obj_id_t component; 127711890bcSjc156560 128711890bcSjc156560 void *data; /* Pointer to attribute structure */ 129711890bcSjc156560 raid_obj_handle_t handle; 130711890bcSjc156560 } raid_obj_t; 131711890bcSjc156560 132711890bcSjc156560 /* 133711890bcSjc156560 * Definition about handle 134711890bcSjc156560 */ 135711890bcSjc156560 typedef struct { 136711890bcSjc156560 uint32_t next; 137711890bcSjc156560 uint32_t type; 138711890bcSjc156560 uint32_t controller_id; 139711890bcSjc156560 uint32_t array_id; 140711890bcSjc156560 uint32_t disk_id; 141711890bcSjc156560 uint64_t seq_id; 142711890bcSjc156560 uint32_t task_id; 143b449fa8aSyw161884 uint32_t prop_id; 144711890bcSjc156560 uint32_t fd; /* Only for controller */ 145711890bcSjc156560 raid_lib_t *raid_lib; /* Only for controller */ 146711890bcSjc156560 } handle_attr_t; 147711890bcSjc156560 148711890bcSjc156560 #define LIST_OBJ_TO_EL(list, obj) \ 149711890bcSjc156560 ((void *)((char *)(obj) + (list)->offset)) 150711890bcSjc156560 #define OBJ_TAB_SLOT(tab, id) \ 151711890bcSjc156560 ((tab)->table + ((id)%(tab)->slots)) 152711890bcSjc156560 153711890bcSjc156560 #pragma init(raidcfg_init) 154711890bcSjc156560 #pragma fini(raidcfg_fini) 155711890bcSjc156560 156711890bcSjc156560 /* 157711890bcSjc156560 * Function prototypes 158711890bcSjc156560 */ 159711890bcSjc156560 static int intcompare(const void *p1, const void *p2); 160711890bcSjc156560 static uint64_t raid_space_noalign(raid_obj_tab_t *, uint32_t, int, 161711890bcSjc156560 raid_obj_id_t *, arraypart_attr_t *); 162711890bcSjc156560 static int raid_handle_init(); 163711890bcSjc156560 static void raid_handle_fini(); 164711890bcSjc156560 static raid_obj_handle_t raid_handle_new(raid_obj_type_id_t); 165711890bcSjc156560 static void raid_handle_delete(raid_obj_handle_t); 166711890bcSjc156560 static void raid_handle_delete_controller_comp(uint32_t); 167711890bcSjc156560 static raid_obj_id_t raid_handle_to_obj(raid_obj_tab_t *, 168711890bcSjc156560 raid_obj_handle_t); 169711890bcSjc156560 static raid_obj_handle_t raid_obj_to_handle(raid_obj_tab_t *, 170711890bcSjc156560 raid_obj_id_t); 171711890bcSjc156560 static raid_lib_t *raid_obj_get_lib(raid_obj_tab_t *, raid_obj_id_t); 172711890bcSjc156560 static int raid_obj_set_lib(raid_obj_tab_t *, raid_obj_id_t, raid_lib_t *); 173711890bcSjc156560 static int raid_obj_get_fd(raid_obj_tab_t *, raid_obj_id_t); 174711890bcSjc156560 static int raid_obj_set_fd(raid_obj_tab_t *, raid_obj_id_t, int); 175711890bcSjc156560 static int obj_scan_comp(raid_obj_tab_t *, raid_obj_id_t); 176711890bcSjc156560 static int obj_rescan(raid_obj_tab_t *); 177711890bcSjc156560 static raid_obj_id_t obj_get_comp(raid_obj_tab_t *, raid_obj_id_t, 178711890bcSjc156560 raid_obj_type_id_t); 179711890bcSjc156560 static raid_obj_id_t obj_get_sibling(raid_obj_tab_t *, raid_obj_id_t); 180711890bcSjc156560 static int obj_get_attr(raid_obj_tab_t *, raid_obj_id_t, void **); 181711890bcSjc156560 static raid_obj_id_t obj_locate_controller(raid_obj_tab_t *, uint32_t); 182711890bcSjc156560 static raid_obj_id_t obj_locate_array(raid_obj_tab_t *, uint32_t, uint32_t); 183711890bcSjc156560 static raid_obj_id_t obj_locate_array_recur(raid_obj_tab_t *, raid_obj_id_t, 184711890bcSjc156560 uint32_t); 185711890bcSjc156560 static raid_obj_id_t obj_locate_hsp(raid_obj_tab_t *, uint32_t, 186711890bcSjc156560 uint32_t, uint32_t); 187711890bcSjc156560 static raid_obj_id_t obj_locate_disk(raid_obj_tab_t *, uint32_t, uint32_t); 188711890bcSjc156560 static raid_obj_id_t obj_locate_arraypart(raid_obj_tab_t *, uint32_t, 189711890bcSjc156560 uint32_t, uint32_t); 190711890bcSjc156560 static raid_obj_id_t obj_locate_diskseg(raid_obj_tab_t *, uint32_t, 191711890bcSjc156560 uint32_t, uint32_t); 192711890bcSjc156560 static raid_obj_id_t obj_locate_task(raid_obj_tab_t *, uint32_t, uint32_t); 193b449fa8aSyw161884 static raid_obj_id_t obj_locate_prop(raid_obj_tab_t *, uint32_t, uint32_t, 194b449fa8aSyw161884 uint32_t); 195711890bcSjc156560 static raid_obj_id_t obj_get_controller(raid_obj_tab_t *, raid_obj_id_t); 196711890bcSjc156560 197711890bcSjc156560 static int obj_sys_compnum(raid_obj_tab_t *, raid_obj_id_t, 198711890bcSjc156560 raid_obj_type_id_t); 199711890bcSjc156560 static int obj_sys_complist(raid_obj_tab_t *, raid_obj_id_t, int, 200711890bcSjc156560 raid_obj_id_t *, raid_obj_type_id_t); 201711890bcSjc156560 static int obj_controller_compnum(raid_obj_tab_t *, raid_obj_id_t, 202711890bcSjc156560 raid_obj_type_id_t); 203711890bcSjc156560 static int obj_controller_complist(raid_obj_tab_t *, raid_obj_id_t, int, 204711890bcSjc156560 raid_obj_id_t *, raid_obj_type_id_t); 205711890bcSjc156560 static int obj_controller_get_attr(raid_obj_tab_t *, raid_obj_id_t); 206711890bcSjc156560 static int obj_controller_act(raid_obj_tab_t *, raid_obj_id_t, 207711890bcSjc156560 uint32_t, void *, char **); 208711890bcSjc156560 static int obj_array_compnum(raid_obj_tab_t *, raid_obj_id_t, 209711890bcSjc156560 raid_obj_type_id_t); 210711890bcSjc156560 static int obj_array_complist(raid_obj_tab_t *, raid_obj_id_t, int, 211711890bcSjc156560 raid_obj_id_t *, raid_obj_type_id_t); 212711890bcSjc156560 static int obj_array_get_attr(raid_obj_tab_t *, raid_obj_id_t); 213711890bcSjc156560 static int obj_array_set_attr(raid_obj_tab_t *, raid_obj_id_t, 214711890bcSjc156560 uint32_t, uint32_t *, char **); 215711890bcSjc156560 static int obj_disk_compnum(raid_obj_tab_t *, raid_obj_id_t, 216711890bcSjc156560 raid_obj_type_id_t); 217711890bcSjc156560 static int obj_disk_complist(raid_obj_tab_t *, raid_obj_id_t, int, 218711890bcSjc156560 raid_obj_id_t *, raid_obj_type_id_t); 219711890bcSjc156560 static int obj_disk_get_attr(raid_obj_tab_t *, raid_obj_id_t); 220711890bcSjc156560 static int obj_hsp_get_attr(raid_obj_tab_t *, raid_obj_id_t); 221711890bcSjc156560 static int obj_arraypart_get_attr(raid_obj_tab_t *, raid_obj_id_t); 222711890bcSjc156560 static int obj_diskseg_get_attr(raid_obj_tab_t *, raid_obj_id_t); 223711890bcSjc156560 static int obj_task_get_attr(raid_obj_tab_t *, raid_obj_id_t); 224b449fa8aSyw161884 static int obj_prop_get_attr(raid_obj_tab_t *, raid_obj_id_t); 225711890bcSjc156560 static int obj_array_create(raid_obj_tab_t *, raid_obj_id_t, int, 226711890bcSjc156560 raid_obj_id_t *, char **); 227711890bcSjc156560 static int obj_array_delete(raid_obj_tab_t *, raid_obj_id_t, char **); 2285c9d25d2SYu-Bo Ryan Wang static int obj_hsp_bind(raid_obj_tab_t *, raid_obj_id_t *, char **); 2295c9d25d2SYu-Bo Ryan Wang static int obj_hsp_unbind(raid_obj_tab_t *, raid_obj_id_t *, char **); 230711890bcSjc156560 231711890bcSjc156560 static int raid_obj_create_system_obj(raid_obj_tab_t *); 232711890bcSjc156560 static raid_obj_id_t raid_obj_id_new(raid_obj_tab_t *); 233711890bcSjc156560 static void *raid_obj_attr_new(raid_obj_type_id_t); 234711890bcSjc156560 static raid_obj_id_t raid_obj_create(raid_obj_tab_t *, raid_obj_type_id_t); 235711890bcSjc156560 static int raid_obj_delete(raid_obj_tab_t *, raid_obj_id_t); 236711890bcSjc156560 static int raid_obj_add_org(raid_obj_tab_t *, raid_obj_id_t, raid_obj_id_t); 237711890bcSjc156560 static raid_obj_type_id_t raid_obj_get_type(raid_obj_tab_t *, raid_obj_id_t); 238711890bcSjc156560 static int raid_obj_set_type(raid_obj_tab_t *, raid_obj_id_t, 239711890bcSjc156560 raid_obj_type_id_t); 240711890bcSjc156560 static raid_obj_status_t raid_obj_get_status(raid_obj_tab_t *, raid_obj_id_t); 241711890bcSjc156560 static int raid_obj_set_status(raid_obj_tab_t *, raid_obj_id_t, 242711890bcSjc156560 raid_obj_status_t); 243711890bcSjc156560 static int raid_obj_clear_status(raid_obj_tab_t *, raid_obj_id_t, 244711890bcSjc156560 raid_obj_status_t); 245711890bcSjc156560 static raid_obj_id_t raid_obj_get_container(raid_obj_tab_t *, raid_obj_id_t); 246711890bcSjc156560 static int raid_obj_set_container(raid_obj_tab_t *, raid_obj_id_t, 247711890bcSjc156560 raid_obj_id_t); 248711890bcSjc156560 static raid_obj_id_t raid_obj_get_comp(raid_obj_tab_t *, raid_obj_id_t); 249711890bcSjc156560 static int raid_obj_set_comp(raid_obj_tab_t *, raid_obj_id_t, raid_obj_id_t); 250711890bcSjc156560 static raid_obj_id_t raid_obj_get_sibling(raid_obj_tab_t *, raid_obj_id_t); 251711890bcSjc156560 static int raid_obj_set_sibling(raid_obj_tab_t *, raid_obj_id_t, 252711890bcSjc156560 raid_obj_id_t); 253711890bcSjc156560 static void *raid_obj_get_data_ptr(raid_obj_tab_t *, raid_obj_id_t); 254711890bcSjc156560 static int raid_obj_set_data_ptr(raid_obj_tab_t *, raid_obj_id_t, void *); 255711890bcSjc156560 static raid_obj_handle_t raid_obj_get_handle(raid_obj_tab_t *, 256711890bcSjc156560 raid_obj_id_t); 257711890bcSjc156560 static int raid_obj_set_handle(raid_obj_tab_t *, raid_obj_id_t, 258711890bcSjc156560 raid_obj_handle_t); 259711890bcSjc156560 260711890bcSjc156560 static void raid_list_create(raid_list_t *, size_t); 261711890bcSjc156560 static void *raid_list_head(raid_list_t *); 262711890bcSjc156560 static void *raid_list_next(raid_list_t *, void *); 263711890bcSjc156560 static void raid_list_insert_tail(raid_list_t *, void *); 264711890bcSjc156560 static void raid_list_remove(raid_list_t *, void *); 265711890bcSjc156560 static void *raid_list_remove_head(raid_list_t *); 266711890bcSjc156560 static void *raid_list_find(raid_list_t *, raid_obj_id_t); 267711890bcSjc156560 static int raid_obj_tab_create(raid_obj_tab_t *, size_t); 268711890bcSjc156560 static void raid_obj_tab_destroy(raid_obj_tab_t *); 269711890bcSjc156560 static int raid_obj_tab_insert(raid_obj_tab_t *, raid_obj_id_t, void *); 270711890bcSjc156560 static void *raid_obj_tab_remove(raid_obj_tab_t *, raid_obj_id_t); 271711890bcSjc156560 static void *raid_obj_tab_find(raid_obj_tab_t *, raid_obj_id_t); 272711890bcSjc156560 static void raid_list_destroy(raid_list_t *); 273711890bcSjc156560 274711890bcSjc156560 static int controller_id_to_path(uint32_t, char *); 275711890bcSjc156560 static char *controller_id_to_driver_name(uint32_t); 276711890bcSjc156560 static void raid_plugin_init(); 277711890bcSjc156560 static raid_lib_t *raid_plugin_load(char *); 278711890bcSjc156560 static raid_lib_t *raid_find_lib(raid_obj_tab_t *, raid_obj_id_t); 279711890bcSjc156560 280711890bcSjc156560 /* Global object table */ 281711890bcSjc156560 static raid_obj_tab_t raid_tab_sys = {0, 0, NULL}; 282711890bcSjc156560 283711890bcSjc156560 /* Plug-in modules maintenance data structures */ 284711890bcSjc156560 static raid_lib_t *raid_lib_sys = NULL; 285711890bcSjc156560 286711890bcSjc156560 /* Handle table definition */ 287711890bcSjc156560 static struct { 288711890bcSjc156560 int handle_num; 289711890bcSjc156560 int used; 290711890bcSjc156560 int unused; 291711890bcSjc156560 handle_attr_t *handles; 292711890bcSjc156560 } raid_handle_sys = {0, 0, 0, NULL}; 293711890bcSjc156560 294711890bcSjc156560 /* 295711890bcSjc156560 * RAID object method table definition 296711890bcSjc156560 */ 297711890bcSjc156560 static raid_obj_op_t raid_obj_op_sys[OBJ_TYPE_ALL] = { 298711890bcSjc156560 {obj_sys_compnum, obj_sys_complist, NULL, NULL, NULL, 299711890bcSjc156560 NULL, NULL, NULL, NULL}, /* system object methods */ 300711890bcSjc156560 {obj_controller_compnum, obj_controller_complist, 301711890bcSjc156560 obj_controller_get_attr, NULL, obj_controller_act, 302711890bcSjc156560 NULL, NULL, NULL, NULL}, /* controller object methods */ 303711890bcSjc156560 {obj_array_compnum, obj_array_complist, obj_array_get_attr, 304711890bcSjc156560 obj_array_set_attr, NULL, obj_array_create, 305711890bcSjc156560 obj_array_delete, NULL, NULL}, /* array object methods */ 306711890bcSjc156560 {obj_disk_compnum, obj_disk_complist, obj_disk_get_attr, NULL, 307711890bcSjc156560 NULL, NULL, NULL, NULL, NULL}, /* disk object methods */ 308711890bcSjc156560 {NULL, NULL, obj_hsp_get_attr, NULL, NULL, NULL, NULL, obj_hsp_bind, 309711890bcSjc156560 obj_hsp_unbind}, /* hsp object methods */ 310711890bcSjc156560 {NULL, NULL, obj_arraypart_get_attr, NULL, NULL, NULL, NULL, 311711890bcSjc156560 NULL, NULL}, /* array part object methods */ 312711890bcSjc156560 {NULL, NULL, obj_diskseg_get_attr, NULL, NULL, NULL, NULL, NULL, NULL}, 313711890bcSjc156560 {NULL, NULL, obj_task_get_attr, NULL, NULL, NULL, NULL, 314b449fa8aSyw161884 NULL, NULL}, /* disk seg object methods */ 315b449fa8aSyw161884 {NULL, NULL, obj_prop_get_attr, NULL, NULL, NULL, NULL, 316b449fa8aSyw161884 NULL, NULL} /* property object methods */ 317711890bcSjc156560 }; 318711890bcSjc156560 319711890bcSjc156560 /* 320711890bcSjc156560 * Mutex for multithread safe 321711890bcSjc156560 */ 322711890bcSjc156560 static mutex_t raidcfg_mp; 323711890bcSjc156560 324711890bcSjc156560 /* 325711890bcSjc156560 * RaidCfg library APIs 326711890bcSjc156560 */ 327711890bcSjc156560 const char * 328711890bcSjc156560 raidcfg_errstr(int err_code) 329711890bcSjc156560 { 330711890bcSjc156560 char *ret_val; 331711890bcSjc156560 332711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 333711890bcSjc156560 switch (err_code) { 334711890bcSjc156560 case SUCCESS: 335711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Operation succeeded.\n"); 336711890bcSjc156560 break; 337711890bcSjc156560 case STD_IOCTL: 338711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 339711890bcSjc156560 "Request standard IOCTL service.\n"); 340711890bcSjc156560 break; 341711890bcSjc156560 case ERR_DRIVER_NOT_FOUND: 342711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 343711890bcSjc156560 "Controller device can not be found.\n"); 344711890bcSjc156560 break; 345711890bcSjc156560 case ERR_DRIVER_OPEN: 346711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Can not open controller.\n"); 347711890bcSjc156560 break; 348711890bcSjc156560 case ERR_DRIVER_LOCK: 349711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Controller is locked.\n"); 350711890bcSjc156560 break; 351711890bcSjc156560 case ERR_DRIVER_CLOSED: 352711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Controller is not opened.\n"); 353711890bcSjc156560 break; 354711890bcSjc156560 case ERR_DRIVER_ACROSS: 355711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 356711890bcSjc156560 "Operation across multiple controllers.\n"); 357711890bcSjc156560 break; 358711890bcSjc156560 case ERR_ARRAY_LEVEL: 359711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 360711890bcSjc156560 "Operation not support with volume of this level.\n"); 361711890bcSjc156560 break; 362711890bcSjc156560 case ERR_ARRAY_SIZE: 363711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 364711890bcSjc156560 "Capacity of array out of range.\n"); 365711890bcSjc156560 break; 366711890bcSjc156560 case ERR_ARRAY_STRIPE_SIZE: 367711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Illegal stripe size.\n"); 368711890bcSjc156560 break; 369711890bcSjc156560 case ERR_ARRAY_CACHE_POLICY: 370711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 371711890bcSjc156560 "Illegal cache-write policy.\n"); 372711890bcSjc156560 break; 373711890bcSjc156560 case ERR_ARRAY_IN_USE: 374474adcbbSyw161884 ret_val = dgettext(TEXT_DOMAIN, "Array or disk in use.\n"); 375711890bcSjc156560 break; 376711890bcSjc156560 case ERR_ARRAY_TASK: 377711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Array has background task.\n"); 378711890bcSjc156560 break; 379711890bcSjc156560 case ERR_ARRAY_CONFIG: 380711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 381711890bcSjc156560 "Configuration over device node failed.\n"); 382711890bcSjc156560 break; 383711890bcSjc156560 case ERR_ARRAY_DISKNUM: 384711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Incorrect number of disks.\n"); 385711890bcSjc156560 break; 386711890bcSjc156560 case ERR_ARRAY_LAYOUT: 387711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Illegal array layout.\n"); 388711890bcSjc156560 break; 389711890bcSjc156560 case ERR_ARRAY_AMOUNT: 390711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Too many arrays.\n"); 391711890bcSjc156560 break; 392711890bcSjc156560 case ERR_DISK_STATE: 393711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 394711890bcSjc156560 "Incorrect disk status for current operation.\n"); 395711890bcSjc156560 break; 396711890bcSjc156560 case ERR_DISK_SPACE: 397711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "No enough disk space.\n"); 398711890bcSjc156560 break; 399711890bcSjc156560 case ERR_DISK_SEG_AMOUNT: 400711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Too many disk segments.\n"); 401711890bcSjc156560 break; 402711890bcSjc156560 case ERR_DISK_NOT_EMPTY: 403711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Disk has occupied space.\n"); 404711890bcSjc156560 break; 405711890bcSjc156560 case ERR_DISK_TASK: 406711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Disk has background task.\n"); 407711890bcSjc156560 break; 408711890bcSjc156560 case ERR_TASK_STATE: 409711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 410711890bcSjc156560 "Incorrect task state for current operation.\n"); 411711890bcSjc156560 break; 412711890bcSjc156560 case ERR_OP_ILLEGAL: 413711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Illegal operation.\n"); 414711890bcSjc156560 break; 415711890bcSjc156560 case ERR_OP_NO_IMPL: 416711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 417711890bcSjc156560 "Operation is not implemented.\n"); 418711890bcSjc156560 break; 419711890bcSjc156560 case ERR_OP_FAILED: 420474adcbbSyw161884 ret_val = dgettext(TEXT_DOMAIN, "Operation failed.\n"); 421711890bcSjc156560 break; 422711890bcSjc156560 case ERR_DEVICE_NOENT: 423711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Device not found.\n"); 424711890bcSjc156560 break; 425711890bcSjc156560 case ERR_DEVICE_TYPE: 426711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Illegal type of device.\n"); 427711890bcSjc156560 break; 428711890bcSjc156560 case ERR_DEVICE_DUP: 429711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Device record duplicated.\n"); 430711890bcSjc156560 break; 431711890bcSjc156560 case ERR_DEVICE_OVERFLOW: 432711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Too many devices.\n"); 433711890bcSjc156560 break; 434711890bcSjc156560 case ERR_DEVICE_UNCLEAN: 435711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Device pool is not clean.\n"); 436711890bcSjc156560 break; 437711890bcSjc156560 case ERR_DEVICE_INVALID: 438711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Device record is invalid.\n"); 439711890bcSjc156560 break; 440711890bcSjc156560 case ERR_NOMEM: 441711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, 442711890bcSjc156560 "Can not allocate more memory space.\n"); 443711890bcSjc156560 break; 444711890bcSjc156560 case ERR_PRIV: 445711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "No privilege.\n"); 446711890bcSjc156560 break; 447711890bcSjc156560 default: 448711890bcSjc156560 ret_val = dgettext(TEXT_DOMAIN, "Undefined error.\n"); 449711890bcSjc156560 } 450711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 451711890bcSjc156560 452711890bcSjc156560 return (ret_val); 453711890bcSjc156560 } 454711890bcSjc156560 455711890bcSjc156560 int 456711890bcSjc156560 raidcfg_get_controller(uint32_t controller_id) 457711890bcSjc156560 { 458711890bcSjc156560 raid_obj_id_t obj_id; 459711890bcSjc156560 int ret_val; 460711890bcSjc156560 461711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 462711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 463711890bcSjc156560 obj_id = obj_locate_controller(&raid_tab_sys, controller_id); 464711890bcSjc156560 if (obj_id < OBJ_NONE) { 465711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 466711890bcSjc156560 return (obj_id); 467711890bcSjc156560 } 468711890bcSjc156560 469711890bcSjc156560 if (obj_id == OBJ_NONE) { 470711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 471711890bcSjc156560 return (ERR_DEVICE_NOENT); 472711890bcSjc156560 } 473711890bcSjc156560 ret_val = raid_obj_to_handle(&raid_tab_sys, obj_id); 474711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 475711890bcSjc156560 476711890bcSjc156560 return (ret_val); 477711890bcSjc156560 } 478711890bcSjc156560 479711890bcSjc156560 int 480711890bcSjc156560 raidcfg_get_array(int controller_handle, uint64_t target_id, uint64_t lun) 481711890bcSjc156560 { 482711890bcSjc156560 raid_obj_id_t obj_id; 483711890bcSjc156560 raidcfg_array_t *attr; 484711890bcSjc156560 int ret_val; 485711890bcSjc156560 486711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 487711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 488711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, controller_handle); 489711890bcSjc156560 if (obj_id < OBJ_NONE) { 490711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 491711890bcSjc156560 return (obj_id); 492711890bcSjc156560 } 493711890bcSjc156560 494711890bcSjc156560 obj_id = obj_get_comp(&raid_tab_sys, obj_id, OBJ_TYPE_ARRAY); 495711890bcSjc156560 496711890bcSjc156560 while (obj_id > OBJ_NONE) { 497711890bcSjc156560 (void) obj_get_attr(&raid_tab_sys, obj_id, (void **)(&attr)); 498711890bcSjc156560 if (attr->tag.idl.target_id == target_id && 499711890bcSjc156560 attr->tag.idl.lun == lun) 500711890bcSjc156560 break; 501711890bcSjc156560 502711890bcSjc156560 obj_id = obj_get_sibling(&raid_tab_sys, obj_id); 503711890bcSjc156560 } 504711890bcSjc156560 505711890bcSjc156560 if (obj_id < OBJ_NONE) { 506711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 507711890bcSjc156560 return (obj_id); 508711890bcSjc156560 } 509711890bcSjc156560 if (obj_id == OBJ_NONE) { 510711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 511711890bcSjc156560 return (ERR_DEVICE_NOENT); 512711890bcSjc156560 } 513711890bcSjc156560 ret_val = raid_obj_to_handle(&raid_tab_sys, obj_id); 514711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 515711890bcSjc156560 516711890bcSjc156560 return (ret_val); 517711890bcSjc156560 } 518711890bcSjc156560 519711890bcSjc156560 int 520711890bcSjc156560 raidcfg_get_disk(int controller_handle, disk_tag_t tag) 521711890bcSjc156560 { 522711890bcSjc156560 raid_obj_id_t obj_id; 523711890bcSjc156560 raidcfg_disk_t *attr; 524711890bcSjc156560 int ret_val; 525711890bcSjc156560 526711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 527711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 528711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, controller_handle); 529711890bcSjc156560 if (obj_id < OBJ_NONE) { 530711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 531711890bcSjc156560 return (obj_id); 532711890bcSjc156560 } 533711890bcSjc156560 534711890bcSjc156560 obj_id = obj_get_comp(&raid_tab_sys, obj_id, OBJ_TYPE_DISK); 535711890bcSjc156560 536711890bcSjc156560 while (obj_id > OBJ_NONE) { 537711890bcSjc156560 (void) obj_get_attr(&raid_tab_sys, obj_id, (void **)(&attr)); 538711890bcSjc156560 if (attr->tag.cidl.bus == tag.cidl.bus && 539711890bcSjc156560 attr->tag.cidl.target_id == tag.cidl.target_id && 540711890bcSjc156560 attr->tag.cidl.lun == tag.cidl.lun) 541711890bcSjc156560 break; 542711890bcSjc156560 543711890bcSjc156560 obj_id = obj_get_sibling(&raid_tab_sys, obj_id); 544711890bcSjc156560 } 545711890bcSjc156560 546711890bcSjc156560 if (obj_id < OBJ_NONE) { 547711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 548711890bcSjc156560 return (obj_id); 549711890bcSjc156560 } 550711890bcSjc156560 if (obj_id == OBJ_NONE) { 551711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 552711890bcSjc156560 return (ERR_DEVICE_NOENT); 553711890bcSjc156560 } 554711890bcSjc156560 ret_val = raid_obj_to_handle(&raid_tab_sys, obj_id); 555711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 556711890bcSjc156560 557711890bcSjc156560 return (ret_val); 558711890bcSjc156560 } 559711890bcSjc156560 560711890bcSjc156560 int 561711890bcSjc156560 raidcfg_open_controller(int handle, char **plugin_err_str) 562711890bcSjc156560 { 563711890bcSjc156560 raid_obj_id_t obj_id; 564711890bcSjc156560 int ret; 565711890bcSjc156560 566711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 567711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 568711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 569711890bcSjc156560 if (obj_id < OBJ_NONE) { 570711890bcSjc156560 raid_handle_delete(handle); 571711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 572711890bcSjc156560 return (ERR_DEVICE_NOENT); 573711890bcSjc156560 } 574711890bcSjc156560 575711890bcSjc156560 ret = obj_controller_act(&raid_tab_sys, obj_id, 576711890bcSjc156560 ACT_CONTROLLER_OPEN, NULL, plugin_err_str); 577711890bcSjc156560 if (ret < SUCCESS) { 578711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 579711890bcSjc156560 return (ret); 580711890bcSjc156560 } 581711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 582711890bcSjc156560 583711890bcSjc156560 return (SUCCESS); 584711890bcSjc156560 } 585711890bcSjc156560 586711890bcSjc156560 int 587711890bcSjc156560 raidcfg_close_controller(int handle, char **plugin_err_str) 588711890bcSjc156560 { 589711890bcSjc156560 raid_obj_id_t obj_id; 590711890bcSjc156560 int ret; 591711890bcSjc156560 592711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 593711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 594711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 595711890bcSjc156560 if (obj_id < OBJ_NONE) { 596711890bcSjc156560 raid_handle_delete(handle); 597711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 598711890bcSjc156560 return (ERR_DEVICE_NOENT); 599711890bcSjc156560 } 600711890bcSjc156560 601711890bcSjc156560 ret = obj_controller_act(&raid_tab_sys, obj_id, 602711890bcSjc156560 ACT_CONTROLLER_CLOSE, NULL, plugin_err_str); 603711890bcSjc156560 if (ret < SUCCESS) { 604711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 605711890bcSjc156560 return (ret); 606711890bcSjc156560 } 607711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 608711890bcSjc156560 609711890bcSjc156560 return (SUCCESS); 610711890bcSjc156560 } 611711890bcSjc156560 612711890bcSjc156560 int 613711890bcSjc156560 raidcfg_get_type(int handle) 614711890bcSjc156560 { 615711890bcSjc156560 raid_obj_id_t obj_id; 616711890bcSjc156560 int ret_val; 617711890bcSjc156560 618711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 619711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 620711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 621711890bcSjc156560 if (obj_id < OBJ_NONE) { 622711890bcSjc156560 raid_handle_delete(handle); 623711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 624711890bcSjc156560 return (ERR_DEVICE_NOENT); 625711890bcSjc156560 } 626711890bcSjc156560 ret_val = raid_obj_get_type(&raid_tab_sys, obj_id); 627711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 628711890bcSjc156560 629711890bcSjc156560 return (ret_val); 630711890bcSjc156560 } 631711890bcSjc156560 632711890bcSjc156560 int 633711890bcSjc156560 raidcfg_get_attr(int handle, void *attr) 634711890bcSjc156560 { 635711890bcSjc156560 raid_obj_id_t obj_id; 636711890bcSjc156560 raid_obj_type_id_t type; 637711890bcSjc156560 void *data; 638711890bcSjc156560 int ret, size; 639711890bcSjc156560 640711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 641711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 642711890bcSjc156560 if (attr == NULL) { 643711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 644711890bcSjc156560 return (ERR_DEVICE_INVALID); 645711890bcSjc156560 } 646711890bcSjc156560 647711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 648711890bcSjc156560 if (obj_id < OBJ_NONE) { 649711890bcSjc156560 raid_handle_delete(handle); 650711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 651711890bcSjc156560 return (ERR_DEVICE_NOENT); 652711890bcSjc156560 } 653711890bcSjc156560 654711890bcSjc156560 type = raid_obj_get_type(&raid_tab_sys, obj_id); 655711890bcSjc156560 ret = obj_get_attr(&raid_tab_sys, obj_id, &data); 656711890bcSjc156560 if (ret < SUCCESS) { 657711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 658711890bcSjc156560 return (ret); 659711890bcSjc156560 } 660711890bcSjc156560 661711890bcSjc156560 switch (type) { 662711890bcSjc156560 case OBJ_TYPE_CONTROLLER: 663711890bcSjc156560 size = sizeof (controller_attr_t); 664711890bcSjc156560 break; 665711890bcSjc156560 case OBJ_TYPE_ARRAY: 666711890bcSjc156560 size = sizeof (array_attr_t); 667711890bcSjc156560 break; 668711890bcSjc156560 case OBJ_TYPE_HSP: 669711890bcSjc156560 { 670711890bcSjc156560 raidcfg_hsp_t *dst = attr; 671711890bcSjc156560 hsp_attr_t *src = data; 672711890bcSjc156560 controller_attr_t *ctlr_attr; 673711890bcSjc156560 array_attr_t *array_attr; 674711890bcSjc156560 675711890bcSjc156560 dst->associated_id = src->associated_id; 676711890bcSjc156560 dst->type = src->type; 677711890bcSjc156560 678711890bcSjc156560 obj_id = obj_get_controller(&raid_tab_sys, obj_id); 679711890bcSjc156560 ret = obj_get_attr(&raid_tab_sys, obj_id, 680711890bcSjc156560 (void **)(&ctlr_attr)); 681711890bcSjc156560 if (ret < SUCCESS) { 682711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 683711890bcSjc156560 return (ret); 684711890bcSjc156560 } 685711890bcSjc156560 686711890bcSjc156560 if (src->type == HSP_TYPE_LOCAL) { 687711890bcSjc156560 obj_id = obj_locate_array(&raid_tab_sys, 688711890bcSjc156560 ctlr_attr->controller_id, 689711890bcSjc156560 src->associated_id); 690711890bcSjc156560 ret = obj_get_attr(&raid_tab_sys, obj_id, 691711890bcSjc156560 (void **)(&array_attr)); 692711890bcSjc156560 if (ret < SUCCESS) { 693711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 694711890bcSjc156560 return (ret); 695711890bcSjc156560 } 696711890bcSjc156560 697711890bcSjc156560 dst->tag.idl.target_id = 698711890bcSjc156560 array_attr->tag.idl.target_id; 699711890bcSjc156560 dst->tag.idl.lun = array_attr->tag.idl.lun; 700711890bcSjc156560 } 701711890bcSjc156560 } 702711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 703711890bcSjc156560 return (SUCCESS); 704711890bcSjc156560 case OBJ_TYPE_DISK: 705711890bcSjc156560 size = sizeof (disk_attr_t); 706711890bcSjc156560 break; 707711890bcSjc156560 case OBJ_TYPE_ARRAY_PART: 708711890bcSjc156560 { 709711890bcSjc156560 raidcfg_arraypart_t *dst = attr; 710711890bcSjc156560 arraypart_attr_t *src = data; 711711890bcSjc156560 controller_attr_t *ctlr_attr; 712711890bcSjc156560 disk_attr_t *disk_attr; 713711890bcSjc156560 714711890bcSjc156560 dst->disk_id = src->disk_id; 715711890bcSjc156560 dst->offset = src->offset; 716711890bcSjc156560 dst->size = src->size; 717711890bcSjc156560 dst->state = src->state; 718711890bcSjc156560 719711890bcSjc156560 obj_id = obj_get_controller(&raid_tab_sys, obj_id); 720711890bcSjc156560 ret = obj_get_attr(&raid_tab_sys, obj_id, 721711890bcSjc156560 (void **)(&ctlr_attr)); 722711890bcSjc156560 if (ret < SUCCESS) { 723711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 724711890bcSjc156560 return (ret); 725711890bcSjc156560 } 726711890bcSjc156560 727711890bcSjc156560 obj_id = obj_locate_disk(&raid_tab_sys, 728711890bcSjc156560 ctlr_attr->controller_id, src->disk_id); 729711890bcSjc156560 if (obj_id <= OBJ_NONE) { 730711890bcSjc156560 dst->tag.cidl.bus = (uint64_t)OBJ_ATTR_NONE; 731711890bcSjc156560 dst->tag.cidl.target_id = 732711890bcSjc156560 (uint64_t)OBJ_ATTR_NONE; 733711890bcSjc156560 dst->tag.cidl.lun = (uint64_t)OBJ_ATTR_NONE; 734711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 735711890bcSjc156560 return (SUCCESS); 736711890bcSjc156560 } 737711890bcSjc156560 738711890bcSjc156560 ret = obj_get_attr(&raid_tab_sys, obj_id, 739711890bcSjc156560 (void **)(&disk_attr)); 740711890bcSjc156560 if (ret < SUCCESS) { 741711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 742711890bcSjc156560 return (ret); 743711890bcSjc156560 } 744711890bcSjc156560 745711890bcSjc156560 dst->tag.cidl.bus = disk_attr->tag.cidl.bus; 746711890bcSjc156560 dst->tag.cidl.target_id = disk_attr->tag.cidl.target_id; 747711890bcSjc156560 dst->tag.cidl.lun = disk_attr->tag.cidl.lun; 748711890bcSjc156560 } 749711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 750711890bcSjc156560 return (SUCCESS); 751711890bcSjc156560 case OBJ_TYPE_DISK_SEG: 752711890bcSjc156560 size = sizeof (diskseg_attr_t); 753711890bcSjc156560 break; 754711890bcSjc156560 case OBJ_TYPE_TASK: 755711890bcSjc156560 size = sizeof (task_attr_t); 756711890bcSjc156560 break; 757b449fa8aSyw161884 case OBJ_TYPE_PROP: 758b449fa8aSyw161884 { 759b449fa8aSyw161884 property_attr_t *src = data, *dst = attr; 760b449fa8aSyw161884 761b449fa8aSyw161884 dst->prop_id = src->prop_id; 762b449fa8aSyw161884 dst->prop_type = src->prop_type; 763b449fa8aSyw161884 if (dst->prop_size == 0) { 764b449fa8aSyw161884 dst->prop_size = src->prop_size; 765b449fa8aSyw161884 (void) mutex_unlock(&raidcfg_mp); 766b449fa8aSyw161884 return (SUCCESS); 767b449fa8aSyw161884 } 768b449fa8aSyw161884 769b449fa8aSyw161884 if (dst->prop_size < src->prop_size) 770b449fa8aSyw161884 size = dst->prop_size; 771b449fa8aSyw161884 else 772b449fa8aSyw161884 size = src->prop_size; 773b449fa8aSyw161884 774b449fa8aSyw161884 (void) memcpy(dst->prop, src->prop, size); 775b449fa8aSyw161884 (void) mutex_unlock(&raidcfg_mp); 776b449fa8aSyw161884 return (SUCCESS); 777b449fa8aSyw161884 } 778b449fa8aSyw161884 break; 779711890bcSjc156560 default: 780711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 781711890bcSjc156560 return (ERR_DEVICE_TYPE); 782711890bcSjc156560 } 783711890bcSjc156560 784711890bcSjc156560 (void) memcpy(attr, data, size); 785711890bcSjc156560 786711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 787711890bcSjc156560 return (ret); 788711890bcSjc156560 } 789711890bcSjc156560 790711890bcSjc156560 int 791711890bcSjc156560 raidcfg_get_container(int handle) 792711890bcSjc156560 { 793711890bcSjc156560 raid_obj_id_t obj_id; 794711890bcSjc156560 int ret_val; 795711890bcSjc156560 796711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 797711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 798711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 799711890bcSjc156560 if (obj_id < OBJ_NONE) { 800711890bcSjc156560 raid_handle_delete(handle); 801711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 802711890bcSjc156560 return (ERR_DEVICE_NOENT); 803711890bcSjc156560 } 804711890bcSjc156560 805711890bcSjc156560 obj_id = raid_obj_get_container(&raid_tab_sys, obj_id); 806711890bcSjc156560 if (obj_id < OBJ_NONE) { 807711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 808711890bcSjc156560 return (obj_id); 809711890bcSjc156560 } 810711890bcSjc156560 ret_val = raid_obj_to_handle(&raid_tab_sys, obj_id); 811711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 812711890bcSjc156560 813711890bcSjc156560 return (ret_val); 814711890bcSjc156560 } 815711890bcSjc156560 816711890bcSjc156560 int 817711890bcSjc156560 raidcfg_list_head(int handle, raid_obj_type_id_t type) 818711890bcSjc156560 { 819711890bcSjc156560 raid_obj_id_t obj_id; 820711890bcSjc156560 int ret_val; 821711890bcSjc156560 822711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 823711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 824711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 825711890bcSjc156560 if (obj_id < OBJ_NONE) { 826711890bcSjc156560 raid_handle_delete(handle); 827711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 828711890bcSjc156560 return (ERR_DEVICE_NOENT); 829711890bcSjc156560 } 830711890bcSjc156560 831711890bcSjc156560 obj_id = obj_get_comp(&raid_tab_sys, obj_id, type); 832711890bcSjc156560 if (obj_id < OBJ_NONE) { 833711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 834711890bcSjc156560 return (obj_id); 835711890bcSjc156560 } 836711890bcSjc156560 ret_val = raid_obj_to_handle(&raid_tab_sys, obj_id); 837711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 838711890bcSjc156560 839711890bcSjc156560 return (ret_val); 840711890bcSjc156560 } 841711890bcSjc156560 842711890bcSjc156560 int 843711890bcSjc156560 raidcfg_list_next(int handle) 844711890bcSjc156560 { 845711890bcSjc156560 raid_obj_id_t obj_id; 846711890bcSjc156560 int ret_val; 847711890bcSjc156560 848711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 849711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 850711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 851711890bcSjc156560 if (obj_id < OBJ_NONE) { 852711890bcSjc156560 raid_handle_delete(handle); 853711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 854711890bcSjc156560 return (ERR_DEVICE_NOENT); 855711890bcSjc156560 } 856711890bcSjc156560 857711890bcSjc156560 obj_id = obj_get_sibling(&raid_tab_sys, obj_id); 858711890bcSjc156560 if (obj_id < OBJ_NONE) { 859711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 860711890bcSjc156560 return (obj_id); 861711890bcSjc156560 } 862711890bcSjc156560 ret_val = raid_obj_to_handle(&raid_tab_sys, obj_id); 863711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 864711890bcSjc156560 865711890bcSjc156560 return (ret_val); 866711890bcSjc156560 } 867711890bcSjc156560 868711890bcSjc156560 int 869711890bcSjc156560 raidcfg_set_attr(int handle, uint32_t set_cmd, void *value, 870711890bcSjc156560 char **plugin_err_str) 871711890bcSjc156560 { 872711890bcSjc156560 raid_obj_id_t obj_id; 873711890bcSjc156560 raid_obj_type_id_t type; 874711890bcSjc156560 int ret; 875711890bcSjc156560 876711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 877711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 878711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 879711890bcSjc156560 if (obj_id < OBJ_NONE) { 880711890bcSjc156560 raid_handle_delete(handle); 881711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 882711890bcSjc156560 return (ERR_DEVICE_NOENT); 883711890bcSjc156560 } 884711890bcSjc156560 885711890bcSjc156560 type = raid_obj_get_type(&raid_tab_sys, obj_id); 886711890bcSjc156560 if (raid_obj_op_sys[type].set_attr == NULL) { 887711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 888711890bcSjc156560 return (ERR_OP_NO_IMPL); 889711890bcSjc156560 } 890711890bcSjc156560 891711890bcSjc156560 ret = raid_obj_op_sys[type].set_attr(&raid_tab_sys, 892711890bcSjc156560 obj_id, set_cmd, value, plugin_err_str); 893711890bcSjc156560 894711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 895711890bcSjc156560 return (ret); 896711890bcSjc156560 } 897711890bcSjc156560 898711890bcSjc156560 int 899711890bcSjc156560 raidcfg_update_fw(int handle, char *file, char **plugin_err_str) 900711890bcSjc156560 { 901711890bcSjc156560 raid_obj_id_t obj_id; 902711890bcSjc156560 int ret; 903711890bcSjc156560 904711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 905711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 906711890bcSjc156560 obj_id = raid_handle_to_obj(&raid_tab_sys, handle); 907711890bcSjc156560 if (obj_id < OBJ_NONE) { 908711890bcSjc156560 raid_handle_delete(handle); 909711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 910711890bcSjc156560 return (ERR_DEVICE_NOENT); 911711890bcSjc156560 } 912711890bcSjc156560 913711890bcSjc156560 if (raid_obj_get_type(&raid_tab_sys, obj_id) != OBJ_TYPE_CONTROLLER) { 914711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 915711890bcSjc156560 return (ERR_OP_NO_IMPL); 916711890bcSjc156560 } 917711890bcSjc156560 918711890bcSjc156560 ret = raid_obj_op_sys[OBJ_TYPE_CONTROLLER].act(&raid_tab_sys, 919711890bcSjc156560 obj_id, ACT_CONTROLLER_FLASH_FW, file, plugin_err_str); 920711890bcSjc156560 921711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 922711890bcSjc156560 return (ret); 923711890bcSjc156560 } 924711890bcSjc156560 925711890bcSjc156560 int 926711890bcSjc156560 raidcfg_create_array(int num_of_comps, int *disk_handles, 927711890bcSjc156560 uint32_t raid_level, uint64_t size, uint32_t stripe_size, 928711890bcSjc156560 char **plugin_err_str) 929711890bcSjc156560 { 930711890bcSjc156560 raid_obj_id_t *disk_obj_ids, obj_id; 931711890bcSjc156560 array_attr_t *array_attr; 932711890bcSjc156560 raid_obj_handle_t array_handle; 933711890bcSjc156560 int i, ret; 934711890bcSjc156560 935711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 936711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 937711890bcSjc156560 938711890bcSjc156560 disk_obj_ids = calloc(num_of_comps, sizeof (raid_obj_id_t)); 939711890bcSjc156560 if (disk_obj_ids == NULL) { 940711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 941711890bcSjc156560 return (ERR_NOMEM); 942711890bcSjc156560 } 943711890bcSjc156560 944711890bcSjc156560 /* convert disk handles into disk object ids; */ 945711890bcSjc156560 for (i = 0; i < num_of_comps; ++i) { 946711890bcSjc156560 if (*(disk_handles + i) == OBJ_SEPARATOR_BEGIN || 947711890bcSjc156560 *(disk_handles + i) == OBJ_SEPARATOR_END) { 948711890bcSjc156560 *(disk_obj_ids + i) = *(disk_handles + i); 949711890bcSjc156560 continue; 950711890bcSjc156560 } 951711890bcSjc156560 952711890bcSjc156560 *(disk_obj_ids + i) = raid_handle_to_obj(&raid_tab_sys, 953711890bcSjc156560 *(disk_handles + i)); 954711890bcSjc156560 if (raid_obj_get_type(&raid_tab_sys, *(disk_obj_ids + i)) != 955711890bcSjc156560 OBJ_TYPE_DISK) { 956711890bcSjc156560 free(disk_obj_ids); 957711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 958711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 959711890bcSjc156560 return (ERR_DEVICE_TYPE); 960711890bcSjc156560 } 961711890bcSjc156560 } 962711890bcSjc156560 963711890bcSjc156560 /* Create an empty array object */ 964711890bcSjc156560 obj_id = raid_obj_create(&raid_tab_sys, OBJ_TYPE_ARRAY); 965711890bcSjc156560 if (obj_id < OBJ_NONE) { 966711890bcSjc156560 free(disk_obj_ids); 967711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 968711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 969711890bcSjc156560 return (obj_id); 970711890bcSjc156560 } 971711890bcSjc156560 (void) raid_obj_clear_status(&raid_tab_sys, obj_id, 972711890bcSjc156560 OBJ_STATUS_CMD_CLEAN); 973711890bcSjc156560 974711890bcSjc156560 array_attr = raid_obj_get_data_ptr(&raid_tab_sys, obj_id); 975711890bcSjc156560 array_attr->array_id = (uint32_t)OBJ_ATTR_NONE; 976711890bcSjc156560 array_attr->raid_level = raid_level; 977711890bcSjc156560 array_attr->capacity = size; 978711890bcSjc156560 array_attr->stripe_size = stripe_size; 979711890bcSjc156560 array_attr->write_policy = CACHE_WR_ON; 980711890bcSjc156560 array_attr->read_policy = CACHE_RD_ON; 981711890bcSjc156560 982711890bcSjc156560 ret = raid_obj_op_sys[OBJ_TYPE_ARRAY].create_obj(&raid_tab_sys, obj_id, 983711890bcSjc156560 num_of_comps, disk_obj_ids, plugin_err_str); 984711890bcSjc156560 free(disk_obj_ids); 985711890bcSjc156560 986711890bcSjc156560 if (ret < SUCCESS) { 987711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 988711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 989711890bcSjc156560 return (ret); 990711890bcSjc156560 } 991711890bcSjc156560 992711890bcSjc156560 /* create_obj() method should put the array object in the device tree */ 993711890bcSjc156560 array_handle = raid_obj_to_handle(&raid_tab_sys, obj_id); 994711890bcSjc156560 995711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 996711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 997711890bcSjc156560 return (array_handle); 998711890bcSjc156560 } 999711890bcSjc156560 1000711890bcSjc156560 int 1001711890bcSjc156560 raidcfg_delete_array(int array_handle, char **plugin_err_str) 1002711890bcSjc156560 { 1003711890bcSjc156560 raid_obj_id_t array_obj_id; 1004711890bcSjc156560 int ret; 1005711890bcSjc156560 1006711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 1007711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1008711890bcSjc156560 1009711890bcSjc156560 if (raidcfg_get_type(array_handle) != OBJ_TYPE_ARRAY) { 1010711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1011711890bcSjc156560 return (ERR_DEVICE_TYPE); 1012711890bcSjc156560 } 1013711890bcSjc156560 1014711890bcSjc156560 array_obj_id = raid_handle_to_obj(&raid_tab_sys, array_handle); 1015711890bcSjc156560 if (array_obj_id < OBJ_NONE) { 1016711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1017711890bcSjc156560 return (array_obj_id); 1018711890bcSjc156560 } 1019711890bcSjc156560 if (array_obj_id == OBJ_NONE) { 1020711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1021711890bcSjc156560 return (ERR_DEVICE_INVALID); 1022711890bcSjc156560 } 1023711890bcSjc156560 1024711890bcSjc156560 ret = raid_obj_op_sys[OBJ_TYPE_ARRAY].delete_obj(&raid_tab_sys, 1025711890bcSjc156560 array_obj_id, plugin_err_str); 1026711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1027711890bcSjc156560 1028711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1029711890bcSjc156560 return (ret); 1030711890bcSjc156560 } 1031711890bcSjc156560 1032711890bcSjc156560 int 10335c9d25d2SYu-Bo Ryan Wang raidcfg_set_hsp(raidcfg_hsp_relation_t *hsp_relations, 1034711890bcSjc156560 char **plugin_err_str) 1035711890bcSjc156560 { 1036711890bcSjc156560 raid_obj_id_t disk_obj_id, array_obj_id; 1037711890bcSjc156560 raid_obj_id_t *hsp_relation_objs; 10385c9d25d2SYu-Bo Ryan Wang int ret; 1039711890bcSjc156560 1040711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 1041711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 10425c9d25d2SYu-Bo Ryan Wang if (hsp_relations == NULL) { 1043711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1044711890bcSjc156560 return (ERR_OP_ILLEGAL); 1045711890bcSjc156560 } 1046711890bcSjc156560 10475c9d25d2SYu-Bo Ryan Wang hsp_relation_objs = malloc(2 * sizeof (raid_obj_id_t)); 1048711890bcSjc156560 if (hsp_relation_objs == NULL) { 1049711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1050711890bcSjc156560 return (ERR_NOMEM); 1051711890bcSjc156560 } 1052711890bcSjc156560 1053711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1054711890bcSjc156560 1055711890bcSjc156560 if (hsp_relations->array_handle != OBJ_ATTR_NONE) { 1056711890bcSjc156560 array_obj_id = raid_handle_to_obj(&raid_tab_sys, 10575c9d25d2SYu-Bo Ryan Wang hsp_relations->array_handle); 1058711890bcSjc156560 if (array_obj_id < OBJ_NONE) { 1059711890bcSjc156560 free(hsp_relation_objs); 1060711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1061711890bcSjc156560 return (array_obj_id); 1062711890bcSjc156560 } 1063711890bcSjc156560 if (array_obj_id == OBJ_NONE) { 1064711890bcSjc156560 (void) free(hsp_relation_objs); 1065711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1066711890bcSjc156560 return (ERR_DEVICE_NOENT); 1067711890bcSjc156560 } 10685c9d25d2SYu-Bo Ryan Wang if (raidcfg_get_type(hsp_relations->array_handle) != 1069711890bcSjc156560 OBJ_TYPE_ARRAY) { 1070711890bcSjc156560 free(hsp_relation_objs); 1071711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1072711890bcSjc156560 return (ERR_DEVICE_TYPE); 1073711890bcSjc156560 } 1074711890bcSjc156560 } else 1075711890bcSjc156560 array_obj_id = OBJ_ATTR_NONE; 1076711890bcSjc156560 1077711890bcSjc156560 disk_obj_id = raid_handle_to_obj(&raid_tab_sys, 10785c9d25d2SYu-Bo Ryan Wang hsp_relations->disk_handle); 1079711890bcSjc156560 if (disk_obj_id < OBJ_NONE) { 1080711890bcSjc156560 free(hsp_relation_objs); 1081711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1082711890bcSjc156560 return (disk_obj_id); 1083711890bcSjc156560 } 1084711890bcSjc156560 if (disk_obj_id == OBJ_NONE) { 1085711890bcSjc156560 free(hsp_relation_objs); 1086711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1087711890bcSjc156560 return (ERR_DEVICE_NOENT); 1088711890bcSjc156560 } 10895c9d25d2SYu-Bo Ryan Wang if (raidcfg_get_type(hsp_relations->disk_handle) != 1090711890bcSjc156560 OBJ_TYPE_DISK) { 1091711890bcSjc156560 free(hsp_relation_objs); 1092711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1093711890bcSjc156560 return (ERR_DEVICE_TYPE); 1094711890bcSjc156560 } 1095711890bcSjc156560 10965c9d25d2SYu-Bo Ryan Wang hsp_relation_objs[0] = array_obj_id; 10975c9d25d2SYu-Bo Ryan Wang hsp_relation_objs[1] = disk_obj_id; 1098711890bcSjc156560 10995c9d25d2SYu-Bo Ryan Wang ret = raid_obj_op_sys[OBJ_TYPE_HSP].bind_obj(&raid_tab_sys, 1100711890bcSjc156560 hsp_relation_objs, plugin_err_str); 1101711890bcSjc156560 1102711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1103711890bcSjc156560 free(hsp_relation_objs); 1104711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1105711890bcSjc156560 1106711890bcSjc156560 return (ret); 1107711890bcSjc156560 } 1108711890bcSjc156560 1109711890bcSjc156560 int 11105c9d25d2SYu-Bo Ryan Wang raidcfg_unset_hsp(raidcfg_hsp_relation_t *hsp_relations, 1111711890bcSjc156560 char **plugin_err_str) 1112711890bcSjc156560 { 1113711890bcSjc156560 raid_obj_id_t disk_obj_id, array_obj_id; 1114711890bcSjc156560 raid_obj_id_t *hsp_relation_objs; 11155c9d25d2SYu-Bo Ryan Wang int ret; 1116711890bcSjc156560 1117711890bcSjc156560 (void) mutex_lock(&raidcfg_mp); 1118711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 11195c9d25d2SYu-Bo Ryan Wang if (hsp_relations == NULL) { 1120711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1121711890bcSjc156560 return (ERR_OP_ILLEGAL); 1122711890bcSjc156560 } 1123711890bcSjc156560 11245c9d25d2SYu-Bo Ryan Wang hsp_relation_objs = malloc(2 * sizeof (raid_obj_id_t)); 1125711890bcSjc156560 if (hsp_relation_objs == NULL) { 1126711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1127711890bcSjc156560 return (ERR_NOMEM); 1128711890bcSjc156560 } 1129711890bcSjc156560 1130711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1131711890bcSjc156560 1132711890bcSjc156560 if (hsp_relations->array_handle != OBJ_ATTR_NONE) { 1133711890bcSjc156560 array_obj_id = raid_handle_to_obj(&raid_tab_sys, 11345c9d25d2SYu-Bo Ryan Wang hsp_relations->array_handle); 1135711890bcSjc156560 if (array_obj_id < OBJ_NONE) { 1136711890bcSjc156560 free(hsp_relation_objs); 1137711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1138711890bcSjc156560 return (array_obj_id); 1139711890bcSjc156560 } 1140711890bcSjc156560 if (array_obj_id == OBJ_NONE) { 1141711890bcSjc156560 free(hsp_relation_objs); 1142711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1143711890bcSjc156560 return (ERR_DEVICE_NOENT); 1144711890bcSjc156560 } 11455c9d25d2SYu-Bo Ryan Wang if (raidcfg_get_type(hsp_relations->array_handle) != 1146711890bcSjc156560 OBJ_TYPE_ARRAY) { 1147711890bcSjc156560 free(hsp_relation_objs); 1148711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1149711890bcSjc156560 return (ERR_DEVICE_TYPE); 1150711890bcSjc156560 } 1151711890bcSjc156560 } else 1152711890bcSjc156560 array_obj_id = OBJ_ATTR_NONE; 1153711890bcSjc156560 1154711890bcSjc156560 disk_obj_id = raid_handle_to_obj(&raid_tab_sys, 11555c9d25d2SYu-Bo Ryan Wang hsp_relations->disk_handle); 1156711890bcSjc156560 if (disk_obj_id < OBJ_NONE) { 1157711890bcSjc156560 free(hsp_relation_objs); 1158711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1159711890bcSjc156560 return (disk_obj_id); 1160711890bcSjc156560 } 1161711890bcSjc156560 if (disk_obj_id == OBJ_NONE) { 1162711890bcSjc156560 free(hsp_relation_objs); 1163711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1164711890bcSjc156560 return (ERR_DEVICE_NOENT); 1165711890bcSjc156560 } 11665c9d25d2SYu-Bo Ryan Wang if (raidcfg_get_type(hsp_relations->disk_handle) != 1167711890bcSjc156560 OBJ_TYPE_DISK) { 1168711890bcSjc156560 free(hsp_relation_objs); 1169711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1170711890bcSjc156560 return (ERR_DEVICE_TYPE); 1171711890bcSjc156560 } 1172711890bcSjc156560 11735c9d25d2SYu-Bo Ryan Wang hsp_relation_objs[0] = array_obj_id; 11745c9d25d2SYu-Bo Ryan Wang hsp_relation_objs[1] = disk_obj_id; 1175711890bcSjc156560 1176711890bcSjc156560 ret = raid_obj_op_sys[OBJ_TYPE_HSP].unbind_obj(&raid_tab_sys, 11775c9d25d2SYu-Bo Ryan Wang hsp_relation_objs, plugin_err_str); 1178711890bcSjc156560 1179711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1180711890bcSjc156560 free(hsp_relation_objs); 1181711890bcSjc156560 (void) mutex_unlock(&raidcfg_mp); 1182711890bcSjc156560 1183711890bcSjc156560 return (ret); 1184711890bcSjc156560 } 1185711890bcSjc156560 1186711890bcSjc156560 /* 1187711890bcSjc156560 * RaidCfg lib routines 1188711890bcSjc156560 */ 1189711890bcSjc156560 void 1190711890bcSjc156560 raidcfg_init(void) 1191711890bcSjc156560 { 1192711890bcSjc156560 (void) mutex_init(&raidcfg_mp, NULL, NULL); 1193711890bcSjc156560 raid_plugin_init(); 1194711890bcSjc156560 (void) raid_handle_init(); 1195711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1196711890bcSjc156560 } 1197711890bcSjc156560 1198711890bcSjc156560 void 1199711890bcSjc156560 raidcfg_fini(void) 1200711890bcSjc156560 { 1201711890bcSjc156560 /* 1202711890bcSjc156560 * Need to close all opened controllers before destroying object table 1203711890bcSjc156560 */ 1204711890bcSjc156560 (void) obj_rescan(&raid_tab_sys); 1205711890bcSjc156560 raid_handle_fini(); 1206711890bcSjc156560 raid_obj_tab_destroy(&raid_tab_sys); 1207711890bcSjc156560 raid_plugin_init(); 1208711890bcSjc156560 (void) mutex_destroy(&raidcfg_mp); 1209711890bcSjc156560 } 1210711890bcSjc156560 1211711890bcSjc156560 /* 1212711890bcSjc156560 * Support routines 1213711890bcSjc156560 */ 1214711890bcSjc156560 static int 1215711890bcSjc156560 intcompare(const void *p1, const void *p2) 1216711890bcSjc156560 { 1217711890bcSjc156560 int i, j; 1218711890bcSjc156560 i = *((int *)p1); 1219711890bcSjc156560 j = *((int *)p2); 1220711890bcSjc156560 return (i - j); 1221711890bcSjc156560 } 1222711890bcSjc156560 1223711890bcSjc156560 static uint64_t 1224711890bcSjc156560 raid_space_noalign(raid_obj_tab_t *raid_tab, uint32_t raid_level, int num, 1225711890bcSjc156560 raid_obj_id_t *disk_objs, arraypart_attr_t *arraypart_attrs) 1226711890bcSjc156560 { 1227711890bcSjc156560 disk_attr_t *disk_attr; 1228711890bcSjc156560 diskseg_attr_t *diskseg_attr; 1229711890bcSjc156560 raid_obj_id_t obj_id; 1230711890bcSjc156560 uint64_t offset, capacity; 1231711890bcSjc156560 int i, disk_num, sub_array_num, disk_layer; 1232711890bcSjc156560 1233711890bcSjc156560 /* Find out the maximum available space for all disks */ 1234711890bcSjc156560 for (i = 0; i < num; ++i) { 1235711890bcSjc156560 if ((disk_objs[i] == OBJ_SEPARATOR_BEGIN) || 1236711890bcSjc156560 (disk_objs[i] == OBJ_SEPARATOR_END)) 1237711890bcSjc156560 continue; 1238711890bcSjc156560 1239711890bcSjc156560 (void) obj_get_attr(raid_tab, disk_objs[i], 1240711890bcSjc156560 (void **)(&disk_attr)); 1241711890bcSjc156560 obj_id = obj_get_comp(raid_tab, disk_objs[i], 1242711890bcSjc156560 OBJ_TYPE_DISK_SEG); 1243711890bcSjc156560 if (obj_id == OBJ_NONE) { 1244711890bcSjc156560 arraypart_attrs[i].offset = 0; 1245711890bcSjc156560 arraypart_attrs[i].size = disk_attr->capacity; 1246711890bcSjc156560 continue; 1247711890bcSjc156560 } 1248711890bcSjc156560 1249711890bcSjc156560 (void) obj_get_attr(raid_tab, obj_id, (void **) 1250711890bcSjc156560 (&diskseg_attr)); 1251711890bcSjc156560 arraypart_attrs[i].offset = 0; 1252711890bcSjc156560 arraypart_attrs[i].size = diskseg_attr->offset; 1253711890bcSjc156560 offset = diskseg_attr->offset + diskseg_attr->size; 1254711890bcSjc156560 1255711890bcSjc156560 while ((obj_id = obj_get_sibling(raid_tab, obj_id)) != 1256711890bcSjc156560 OBJ_NONE) { 1257711890bcSjc156560 (void) obj_get_attr(raid_tab, obj_id, 1258711890bcSjc156560 (void **)(&diskseg_attr)); 1259711890bcSjc156560 if ((diskseg_attr->offset - offset) > 1260711890bcSjc156560 arraypart_attrs[i].size) { 1261711890bcSjc156560 arraypart_attrs[i].offset = offset; 1262700682b8Syw161884 arraypart_attrs[i].size = diskseg_attr->offset - 1263700682b8Syw161884 offset; 1264711890bcSjc156560 } 1265711890bcSjc156560 1266711890bcSjc156560 offset = diskseg_attr->offset + diskseg_attr->size; 1267711890bcSjc156560 } 1268711890bcSjc156560 1269711890bcSjc156560 if ((disk_attr->capacity - offset) > arraypart_attrs[i].size) { 1270711890bcSjc156560 arraypart_attrs[i].offset = offset; 1271700682b8Syw161884 arraypart_attrs[i].size = disk_attr->capacity - 1272700682b8Syw161884 offset; 1273711890bcSjc156560 } 1274711890bcSjc156560 } 1275711890bcSjc156560 1276711890bcSjc156560 capacity = OBJ_ATTR_NONE; 1277711890bcSjc156560 disk_num = 0; 1278711890bcSjc156560 disk_layer = 0; 1279711890bcSjc156560 sub_array_num = 0; 1280711890bcSjc156560 for (i = 0; i < num; ++i) { 1281711890bcSjc156560 if (disk_objs[i] == OBJ_SEPARATOR_BEGIN) { 1282711890bcSjc156560 ++ disk_layer; 1283711890bcSjc156560 continue; 1284711890bcSjc156560 } 1285711890bcSjc156560 if (disk_objs[i] == OBJ_SEPARATOR_END) { 1286711890bcSjc156560 -- disk_layer; 1287711890bcSjc156560 if (disk_layer != 0) 1288711890bcSjc156560 ++ sub_array_num; 1289711890bcSjc156560 continue; 1290711890bcSjc156560 } 1291711890bcSjc156560 1292711890bcSjc156560 if (capacity > arraypart_attrs[i].size) 1293711890bcSjc156560 capacity = arraypart_attrs[i].size; 1294711890bcSjc156560 ++disk_num; 1295711890bcSjc156560 } 1296711890bcSjc156560 1297711890bcSjc156560 switch (raid_level) { 1298711890bcSjc156560 case RAID_LEVEL_0: 1299711890bcSjc156560 capacity = capacity * disk_num; 1300711890bcSjc156560 break; 1301711890bcSjc156560 case RAID_LEVEL_1: 1302711890bcSjc156560 capacity = capacity * disk_num / 2; 1303711890bcSjc156560 break; 1304711890bcSjc156560 case RAID_LEVEL_1E: 1305711890bcSjc156560 capacity = capacity * disk_num / 2; 1306711890bcSjc156560 break; 1307711890bcSjc156560 case RAID_LEVEL_5: 1308711890bcSjc156560 capacity = capacity * (disk_num - 1); 1309711890bcSjc156560 break; 1310711890bcSjc156560 case RAID_LEVEL_10: 1311711890bcSjc156560 capacity = capacity * disk_num / 2; 1312711890bcSjc156560 break; 1313711890bcSjc156560 case RAID_LEVEL_50: 1314711890bcSjc156560 capacity = capacity * (disk_num - sub_array_num); 1315711890bcSjc156560 break; 1316711890bcSjc156560 default: 1317711890bcSjc156560 return (ERR_ARRAY_LEVEL); 1318711890bcSjc156560 break; 1319711890bcSjc156560 } 1320711890bcSjc156560 1321711890bcSjc156560 return (capacity); 1322711890bcSjc156560 } 1323711890bcSjc156560 1324711890bcSjc156560 /* 1325711890bcSjc156560 * Raid handle maintenance routines 1326711890bcSjc156560 */ 1327711890bcSjc156560 static int 1328711890bcSjc156560 raid_handle_init() 1329711890bcSjc156560 { 1330711890bcSjc156560 int i; 1331711890bcSjc156560 void *ptr; 1332711890bcSjc156560 1333711890bcSjc156560 raid_handle_sys.handle_num += HANDLER_SLOTS; 1334711890bcSjc156560 ptr = realloc(raid_handle_sys.handles, 1335711890bcSjc156560 raid_handle_sys.handle_num * sizeof (handle_attr_t)); 1336711890bcSjc156560 if (ptr == NULL) 1337711890bcSjc156560 return (ERR_NOMEM); 1338711890bcSjc156560 raid_handle_sys.handles = ptr; 1339711890bcSjc156560 1340711890bcSjc156560 /* Clean up the new allocated handles */ 1341711890bcSjc156560 for (i = raid_handle_sys.handle_num - HANDLER_SLOTS; 1342711890bcSjc156560 i < raid_handle_sys.handle_num; ++i) { 1343ee992693SZach Kissel bzero(&raid_handle_sys.handles[i], sizeof (handle_attr_t)); 1344711890bcSjc156560 raid_handle_sys.handles[i].type = OBJ_TYPE_ALL; 1345711890bcSjc156560 raid_handle_sys.handles[i].next = i + 1; 1346711890bcSjc156560 } 1347711890bcSjc156560 1348711890bcSjc156560 /* For the first time of allocation, set up the system object handle */ 1349711890bcSjc156560 if (raid_handle_sys.handle_num == HANDLER_SLOTS) { 1350711890bcSjc156560 raid_handle_sys.handles[0].type = OBJ_TYPE_SYSTEM; 1351711890bcSjc156560 raid_handle_sys.handles[0].next = 0; 1352711890bcSjc156560 raid_handle_sys.unused = 1; 1353711890bcSjc156560 raid_handle_sys.used = 0; 1354711890bcSjc156560 } 1355711890bcSjc156560 return (SUCCESS); 1356711890bcSjc156560 } 1357711890bcSjc156560 1358711890bcSjc156560 static void 1359711890bcSjc156560 raid_handle_fini() 1360711890bcSjc156560 { 1361711890bcSjc156560 raid_obj_handle_t i; 1362711890bcSjc156560 1363711890bcSjc156560 i = raid_handle_sys.used; 1364711890bcSjc156560 1365711890bcSjc156560 /* Close all opened controllers */ 1366711890bcSjc156560 while (i != 0) { 1367711890bcSjc156560 if ((raid_handle_sys.handles[i].type == OBJ_TYPE_CONTROLLER) && 1368711890bcSjc156560 (raid_handle_sys.handles[i].fd != 0) && 1369711890bcSjc156560 (raid_handle_sys.handles[i].raid_lib != NULL)) 1370711890bcSjc156560 raid_handle_sys.handles[i].raid_lib->close_controller( 1371711890bcSjc156560 raid_handle_sys.handles[i].controller_id, NULL); 1372711890bcSjc156560 i = raid_handle_sys.handles[i].next; 1373711890bcSjc156560 } 1374711890bcSjc156560 1375711890bcSjc156560 /* Clean up handle space */ 1376711890bcSjc156560 raid_handle_sys.handle_num = 0; 1377711890bcSjc156560 raid_handle_sys.unused = 0; 1378711890bcSjc156560 raid_handle_sys.used = 0; 1379711890bcSjc156560 free(raid_handle_sys.handles); 1380711890bcSjc156560 raid_handle_sys.handles = NULL; 1381711890bcSjc156560 } 1382711890bcSjc156560 1383711890bcSjc156560 static raid_obj_handle_t 1384711890bcSjc156560 raid_handle_new(raid_obj_type_id_t type) 1385711890bcSjc156560 { 1386711890bcSjc156560 int ret; 1387711890bcSjc156560 1388711890bcSjc156560 if (raid_handle_sys.unused == raid_handle_sys.handle_num - 1) { 1389711890bcSjc156560 ret = raid_handle_init(); 1390711890bcSjc156560 if (ret < SUCCESS) 1391711890bcSjc156560 return (ret); 1392711890bcSjc156560 } 1393711890bcSjc156560 1394711890bcSjc156560 ret = raid_handle_sys.unused; 1395711890bcSjc156560 raid_handle_sys.unused = raid_handle_sys.handles[ret].next; 1396711890bcSjc156560 1397711890bcSjc156560 raid_handle_sys.handles[ret].next = raid_handle_sys.used; 1398711890bcSjc156560 raid_handle_sys.used = ret; 1399711890bcSjc156560 raid_handle_sys.handles[ret].type = type; 1400711890bcSjc156560 1401711890bcSjc156560 return (ret); 1402711890bcSjc156560 } 1403711890bcSjc156560 1404711890bcSjc156560 static void 1405711890bcSjc156560 raid_handle_delete(raid_obj_handle_t handle) 1406711890bcSjc156560 { 1407711890bcSjc156560 int i = raid_handle_sys.used, j = 0; 1408711890bcSjc156560 1409711890bcSjc156560 if (handle == 0) 1410711890bcSjc156560 return; 1411711890bcSjc156560 1412711890bcSjc156560 while (i != 0 && i != handle) { 1413711890bcSjc156560 j = i; 1414711890bcSjc156560 i = raid_handle_sys.handles[i].next; 1415711890bcSjc156560 } 1416711890bcSjc156560 1417711890bcSjc156560 if (i == handle) { 1418711890bcSjc156560 if (j != 0) 1419711890bcSjc156560 raid_handle_sys.handles[j].next = 1420711890bcSjc156560 raid_handle_sys.handles[i].next; 1421711890bcSjc156560 else 1422711890bcSjc156560 raid_handle_sys.used = 1423711890bcSjc156560 raid_handle_sys.handles[i].next; 1424711890bcSjc156560 1425711890bcSjc156560 raid_handle_sys.handles[i].type = OBJ_TYPE_ALL; 1426711890bcSjc156560 raid_handle_sys.handles[i].next = 1427711890bcSjc156560 raid_handle_sys.unused; 1428711890bcSjc156560 raid_handle_sys.unused = i; 1429711890bcSjc156560 } 1430711890bcSjc156560 } 1431711890bcSjc156560 1432711890bcSjc156560 static void 1433711890bcSjc156560 raid_handle_delete_controller_comp(uint32_t controller_id) 1434711890bcSjc156560 { 1435711890bcSjc156560 int i = raid_handle_sys.used, j; 1436711890bcSjc156560 1437711890bcSjc156560 while (i != 0) { 1438711890bcSjc156560 j = i; 1439711890bcSjc156560 i = raid_handle_sys.handles[i].next; 1440700682b8Syw161884 if ((raid_handle_sys.handles[j].controller_id == 1441700682b8Syw161884 controller_id) && 1442700682b8Syw161884 (raid_handle_sys.handles[j].type != 1443700682b8Syw161884 OBJ_TYPE_CONTROLLER)) 1444711890bcSjc156560 raid_handle_delete(j); 1445711890bcSjc156560 } 1446711890bcSjc156560 } 1447711890bcSjc156560 1448711890bcSjc156560 static raid_obj_id_t 1449711890bcSjc156560 raid_handle_to_obj(raid_obj_tab_t *raid_tab, raid_obj_handle_t handle) 1450711890bcSjc156560 { 1451711890bcSjc156560 handle_attr_t *handle_attr; 1452711890bcSjc156560 raid_obj_id_t obj_id; 1453711890bcSjc156560 1454711890bcSjc156560 if (handle == OBJ_SYSTEM) 1455711890bcSjc156560 return (OBJ_SYSTEM); 1456711890bcSjc156560 1457711890bcSjc156560 handle_attr = raid_handle_sys.handles + handle; 1458711890bcSjc156560 1459711890bcSjc156560 switch (handle_attr->type) { 1460711890bcSjc156560 case OBJ_TYPE_SYSTEM: 1461711890bcSjc156560 return (OBJ_SYSTEM); 1462711890bcSjc156560 case OBJ_TYPE_CONTROLLER: 1463711890bcSjc156560 obj_id = obj_locate_controller(raid_tab, 1464711890bcSjc156560 handle_attr->controller_id); 1465711890bcSjc156560 break; 1466711890bcSjc156560 case OBJ_TYPE_ARRAY: 1467711890bcSjc156560 obj_id = obj_locate_array(raid_tab, 1468711890bcSjc156560 handle_attr->controller_id, handle_attr->array_id); 1469711890bcSjc156560 break; 1470711890bcSjc156560 case OBJ_TYPE_HSP: 1471711890bcSjc156560 obj_id = obj_locate_hsp(raid_tab, 1472711890bcSjc156560 handle_attr->controller_id, handle_attr->disk_id, 1473711890bcSjc156560 handle_attr->array_id); 1474711890bcSjc156560 break; 1475711890bcSjc156560 case OBJ_TYPE_DISK: 1476711890bcSjc156560 obj_id = obj_locate_disk(raid_tab, 1477711890bcSjc156560 handle_attr->controller_id, handle_attr->disk_id); 1478711890bcSjc156560 break; 1479711890bcSjc156560 case OBJ_TYPE_ARRAY_PART: 1480711890bcSjc156560 obj_id = obj_locate_arraypart(raid_tab, 1481711890bcSjc156560 handle_attr->controller_id, handle_attr->array_id, 1482711890bcSjc156560 handle_attr->disk_id); 1483711890bcSjc156560 break; 1484711890bcSjc156560 case OBJ_TYPE_DISK_SEG: 1485711890bcSjc156560 obj_id = obj_locate_diskseg(raid_tab, 1486711890bcSjc156560 handle_attr->controller_id, 1487711890bcSjc156560 handle_attr->disk_id, handle_attr->seq_id); 1488711890bcSjc156560 break; 1489711890bcSjc156560 case OBJ_TYPE_TASK: 1490711890bcSjc156560 obj_id = obj_locate_task(raid_tab, 1491711890bcSjc156560 handle_attr->controller_id, handle_attr->task_id); 1492711890bcSjc156560 break; 1493b449fa8aSyw161884 case OBJ_TYPE_PROP: 1494b449fa8aSyw161884 obj_id = obj_locate_prop(raid_tab, 1495b449fa8aSyw161884 handle_attr->controller_id, handle_attr->disk_id, 1496b449fa8aSyw161884 handle_attr->prop_id); 1497b449fa8aSyw161884 break; 1498711890bcSjc156560 default: 1499711890bcSjc156560 return (ERR_DEVICE_INVALID); 1500711890bcSjc156560 } 1501711890bcSjc156560 1502711890bcSjc156560 if (obj_id < OBJ_NONE) 1503711890bcSjc156560 return (obj_id); 1504711890bcSjc156560 if (obj_id == OBJ_NONE) 1505711890bcSjc156560 return (ERR_DEVICE_NOENT); 1506711890bcSjc156560 1507711890bcSjc156560 (void) raid_obj_set_handle(raid_tab, obj_id, handle); 1508711890bcSjc156560 return (obj_id); 1509711890bcSjc156560 } 1510711890bcSjc156560 1511711890bcSjc156560 static raid_obj_handle_t 1512711890bcSjc156560 raid_obj_to_handle(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 1513711890bcSjc156560 { 1514711890bcSjc156560 raid_obj_id_t obj_id_backup = obj_id; 1515711890bcSjc156560 raid_obj_type_id_t type; 1516711890bcSjc156560 raid_obj_handle_t handle; 1517711890bcSjc156560 controller_attr_t *controller_attr; 1518711890bcSjc156560 array_attr_t *array_attr; 1519711890bcSjc156560 hsp_attr_t *hsp_attr; 1520711890bcSjc156560 disk_attr_t *disk_attr; 1521711890bcSjc156560 arraypart_attr_t *arraypart_attr; 1522711890bcSjc156560 diskseg_attr_t *diskseg_attr; 1523711890bcSjc156560 task_attr_t *task_attr; 1524b449fa8aSyw161884 property_attr_t *prop_attr; 1525711890bcSjc156560 1526711890bcSjc156560 if (obj_id == OBJ_SYSTEM) 1527711890bcSjc156560 return (OBJ_SYSTEM); 1528711890bcSjc156560 1529711890bcSjc156560 /* If the object mapped by a handle */ 1530711890bcSjc156560 handle = raid_obj_get_handle(raid_tab, obj_id); 1531711890bcSjc156560 if (handle != 0) 1532711890bcSjc156560 return (handle); 1533711890bcSjc156560 1534711890bcSjc156560 /* Search for existing handles */ 1535711890bcSjc156560 for (handle = raid_handle_sys.used; handle != 0; 1536711890bcSjc156560 handle = raid_handle_sys.handles[handle].next) 1537711890bcSjc156560 if (raid_handle_to_obj(raid_tab, handle) == obj_id) 1538711890bcSjc156560 break; 1539711890bcSjc156560 1540711890bcSjc156560 if (handle != 0) 1541711890bcSjc156560 return (handle); 1542711890bcSjc156560 1543711890bcSjc156560 /* Allocate new handle for this object */ 1544711890bcSjc156560 type = raid_obj_get_type(raid_tab, obj_id); 1545711890bcSjc156560 handle = raid_handle_new(type); 1546711890bcSjc156560 (void) raid_obj_set_handle(raid_tab, obj_id, handle); 1547711890bcSjc156560 raid_handle_sys.handles[handle].type = type; 1548711890bcSjc156560 1549711890bcSjc156560 switch (type) { 1550711890bcSjc156560 case OBJ_TYPE_SYSTEM: 1551711890bcSjc156560 break; 1552711890bcSjc156560 case OBJ_TYPE_CONTROLLER: 1553711890bcSjc156560 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1554711890bcSjc156560 raid_handle_sys.handles[handle].controller_id = 1555711890bcSjc156560 controller_attr->controller_id; 1556711890bcSjc156560 break; 1557711890bcSjc156560 case OBJ_TYPE_ARRAY: 1558711890bcSjc156560 array_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1559711890bcSjc156560 raid_handle_sys.handles[handle].array_id = array_attr->array_id; 1560711890bcSjc156560 obj_id = obj_get_controller(raid_tab, obj_id); 1561711890bcSjc156560 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1562711890bcSjc156560 raid_handle_sys.handles[handle].controller_id = 1563711890bcSjc156560 controller_attr->controller_id; 1564711890bcSjc156560 break; 1565711890bcSjc156560 case OBJ_TYPE_HSP: 1566711890bcSjc156560 hsp_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1567711890bcSjc156560 raid_handle_sys.handles[handle].array_id = 1568711890bcSjc156560 hsp_attr->associated_id; 1569711890bcSjc156560 obj_id = raid_obj_get_container(raid_tab, obj_id); 1570711890bcSjc156560 disk_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1571711890bcSjc156560 raid_handle_sys.handles[handle].disk_id = disk_attr->disk_id; 1572711890bcSjc156560 obj_id = obj_get_controller(raid_tab, obj_id); 1573711890bcSjc156560 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1574711890bcSjc156560 raid_handle_sys.handles[handle].controller_id = 1575711890bcSjc156560 controller_attr->controller_id; 1576711890bcSjc156560 break; 1577711890bcSjc156560 case OBJ_TYPE_DISK: 1578711890bcSjc156560 disk_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1579711890bcSjc156560 raid_handle_sys.handles[handle].disk_id = disk_attr->disk_id; 1580711890bcSjc156560 obj_id = obj_get_controller(raid_tab, obj_id); 1581711890bcSjc156560 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1582711890bcSjc156560 raid_handle_sys.handles[handle].controller_id = 1583711890bcSjc156560 controller_attr->controller_id; 1584711890bcSjc156560 break; 1585711890bcSjc156560 case OBJ_TYPE_ARRAY_PART: 1586711890bcSjc156560 arraypart_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1587711890bcSjc156560 raid_handle_sys.handles[handle].disk_id = 1588711890bcSjc156560 arraypart_attr->disk_id; 1589711890bcSjc156560 obj_id = raid_obj_get_container(raid_tab, obj_id); 1590711890bcSjc156560 array_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1591711890bcSjc156560 raid_handle_sys.handles[handle].array_id = 1592711890bcSjc156560 array_attr->array_id; 1593711890bcSjc156560 obj_id = obj_get_controller(raid_tab, obj_id); 1594711890bcSjc156560 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1595711890bcSjc156560 raid_handle_sys.handles[handle].controller_id = 1596711890bcSjc156560 controller_attr->controller_id; 1597711890bcSjc156560 break; 1598711890bcSjc156560 case OBJ_TYPE_DISK_SEG: 1599711890bcSjc156560 diskseg_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1600711890bcSjc156560 raid_handle_sys.handles[handle].seq_id = diskseg_attr->seq_no; 1601711890bcSjc156560 obj_id = raid_obj_get_container(raid_tab, obj_id); 1602711890bcSjc156560 disk_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1603711890bcSjc156560 raid_handle_sys.handles[handle].disk_id = 1604711890bcSjc156560 disk_attr->disk_id; 1605711890bcSjc156560 obj_id = obj_get_controller(raid_tab, obj_id); 1606711890bcSjc156560 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1607711890bcSjc156560 raid_handle_sys.handles[handle].controller_id = 1608711890bcSjc156560 controller_attr->controller_id; 1609711890bcSjc156560 break; 1610711890bcSjc156560 case OBJ_TYPE_TASK: 1611711890bcSjc156560 task_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1612711890bcSjc156560 raid_handle_sys.handles[handle].task_id = task_attr->task_id; 1613711890bcSjc156560 obj_id = obj_get_controller(raid_tab, obj_id); 1614711890bcSjc156560 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1615711890bcSjc156560 raid_handle_sys.handles[handle].controller_id = 1616711890bcSjc156560 controller_attr->controller_id; 1617711890bcSjc156560 break; 1618b449fa8aSyw161884 case OBJ_TYPE_PROP: 1619b449fa8aSyw161884 prop_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1620b449fa8aSyw161884 raid_handle_sys.handles[handle].prop_id = 1621b449fa8aSyw161884 prop_attr->prop_id; 1622b449fa8aSyw161884 obj_id = raid_obj_get_container(raid_tab, obj_id); 1623b449fa8aSyw161884 disk_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1624b449fa8aSyw161884 raid_handle_sys.handles[handle].disk_id = disk_attr->disk_id; 1625b449fa8aSyw161884 obj_id = obj_get_controller(raid_tab, obj_id); 1626b449fa8aSyw161884 controller_attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1627b449fa8aSyw161884 raid_handle_sys.handles[handle].controller_id = 1628b449fa8aSyw161884 controller_attr->controller_id; 1629b449fa8aSyw161884 break; 1630711890bcSjc156560 default: 1631711890bcSjc156560 return (ERR_DEVICE_INVALID); 1632711890bcSjc156560 } 1633711890bcSjc156560 1634711890bcSjc156560 (void) raid_obj_set_handle(raid_tab, obj_id_backup, handle); 1635711890bcSjc156560 return (handle); 1636711890bcSjc156560 } 1637711890bcSjc156560 1638711890bcSjc156560 static raid_lib_t * 1639711890bcSjc156560 raid_obj_get_lib(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 1640711890bcSjc156560 { 1641711890bcSjc156560 raid_obj_handle_t handle; 1642711890bcSjc156560 controller_attr_t *attr; 1643711890bcSjc156560 1644711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 1645711890bcSjc156560 return (NULL); 1646711890bcSjc156560 1647711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1648711890bcSjc156560 handle = raid_handle_sys.used; 1649711890bcSjc156560 while (raid_handle_sys.handles[handle].type != OBJ_TYPE_CONTROLLER || 1650711890bcSjc156560 raid_handle_sys.handles[handle].controller_id != 1651711890bcSjc156560 attr->controller_id) 1652711890bcSjc156560 handle = raid_handle_sys.handles[handle].next; 1653711890bcSjc156560 1654711890bcSjc156560 if (handle == 0) 1655711890bcSjc156560 return (NULL); 1656711890bcSjc156560 1657711890bcSjc156560 return (raid_handle_sys.handles[handle].raid_lib); 1658711890bcSjc156560 } 1659711890bcSjc156560 1660711890bcSjc156560 static int 1661711890bcSjc156560 raid_obj_set_lib(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 1662711890bcSjc156560 raid_lib_t *raid_lib) 1663711890bcSjc156560 { 1664711890bcSjc156560 raid_obj_handle_t handle; 1665711890bcSjc156560 controller_attr_t *attr; 1666711890bcSjc156560 1667711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 1668711890bcSjc156560 return (ERR_DEVICE_TYPE); 1669711890bcSjc156560 1670711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1671711890bcSjc156560 handle = raid_handle_sys.used; 1672711890bcSjc156560 while (raid_handle_sys.handles[handle].type != OBJ_TYPE_CONTROLLER || 1673711890bcSjc156560 raid_handle_sys.handles[handle].controller_id != 1674711890bcSjc156560 attr->controller_id) 1675711890bcSjc156560 handle = raid_handle_sys.handles[handle].next; 1676711890bcSjc156560 1677711890bcSjc156560 if (handle == 0) 1678711890bcSjc156560 return (ERR_DEVICE_NOENT); 1679711890bcSjc156560 1680711890bcSjc156560 raid_handle_sys.handles[handle].raid_lib = raid_lib; 1681711890bcSjc156560 return (SUCCESS); 1682711890bcSjc156560 } 1683711890bcSjc156560 1684711890bcSjc156560 static int 1685711890bcSjc156560 raid_obj_get_fd(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 1686711890bcSjc156560 { 1687711890bcSjc156560 raid_obj_handle_t handle; 1688711890bcSjc156560 controller_attr_t *attr; 1689711890bcSjc156560 1690711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 1691711890bcSjc156560 return (ERR_DEVICE_TYPE); 1692711890bcSjc156560 1693711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1694711890bcSjc156560 handle = raid_handle_sys.used; 1695711890bcSjc156560 while (raid_handle_sys.handles[handle].type != OBJ_TYPE_CONTROLLER || 1696711890bcSjc156560 raid_handle_sys.handles[handle].controller_id != 1697711890bcSjc156560 attr->controller_id) 1698711890bcSjc156560 handle = raid_handle_sys.handles[handle].next; 1699711890bcSjc156560 1700711890bcSjc156560 if (handle == 0) 1701711890bcSjc156560 return (ERR_DEVICE_NOENT); 1702711890bcSjc156560 1703711890bcSjc156560 return (raid_handle_sys.handles[handle].fd); 1704711890bcSjc156560 } 1705711890bcSjc156560 1706711890bcSjc156560 static int 1707711890bcSjc156560 raid_obj_set_fd(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, int fd) 1708711890bcSjc156560 { 1709711890bcSjc156560 raid_obj_handle_t handle; 1710711890bcSjc156560 controller_attr_t *attr; 1711711890bcSjc156560 1712711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 1713711890bcSjc156560 return (ERR_DEVICE_TYPE); 1714711890bcSjc156560 1715711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1716711890bcSjc156560 handle = raid_handle_sys.used; 1717711890bcSjc156560 while (raid_handle_sys.handles[handle].type != OBJ_TYPE_CONTROLLER || 1718711890bcSjc156560 raid_handle_sys.handles[handle].controller_id != 1719711890bcSjc156560 attr->controller_id) 1720711890bcSjc156560 handle = raid_handle_sys.handles[handle].next; 1721711890bcSjc156560 1722711890bcSjc156560 if (handle == 0) 1723711890bcSjc156560 return (ERR_DEVICE_NOENT); 1724711890bcSjc156560 1725711890bcSjc156560 raid_handle_sys.handles[handle].fd = fd; 1726711890bcSjc156560 return (SUCCESS); 1727711890bcSjc156560 } 1728711890bcSjc156560 1729711890bcSjc156560 /* 1730711890bcSjc156560 * Raid object maintenance routines 1731711890bcSjc156560 */ 1732711890bcSjc156560 static int 1733711890bcSjc156560 obj_scan_comp(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 1734711890bcSjc156560 { 1735711890bcSjc156560 raid_obj_status_t status; 1736711890bcSjc156560 raid_obj_type_id_t type; 1737711890bcSjc156560 int ret, i, obj_type_cnt, comp_num; 1738711890bcSjc156560 raid_obj_id_t *comp_list; 1739711890bcSjc156560 1740711890bcSjc156560 status = raid_obj_get_status(raid_tab, obj_id); 1741711890bcSjc156560 if (status < SUCCESS) 1742711890bcSjc156560 return (status); 1743711890bcSjc156560 1744711890bcSjc156560 if (status & OBJ_STATUS_SCANCOMP) 1745711890bcSjc156560 return (SUCCESS); 1746711890bcSjc156560 1747711890bcSjc156560 type = raid_obj_get_type(raid_tab, obj_id); 1748*edabaf6fSMilan Jurik /* type less than OBJ_TYPE_SYSTEM means error */ 1749*edabaf6fSMilan Jurik if (type < OBJ_TYPE_SYSTEM) 1750711890bcSjc156560 return (ERR_DEVICE_INVALID); 1751711890bcSjc156560 1752711890bcSjc156560 for (obj_type_cnt = OBJ_SYSTEM; obj_type_cnt < OBJ_TYPE_ALL; 1753711890bcSjc156560 ++obj_type_cnt) { 1754711890bcSjc156560 if (raid_obj_op_sys[type].compnum != NULL) 1755711890bcSjc156560 comp_num = raid_obj_op_sys[type].compnum( 1756711890bcSjc156560 raid_tab, obj_id, obj_type_cnt); 1757711890bcSjc156560 else 1758711890bcSjc156560 comp_num = 0; 1759711890bcSjc156560 1760711890bcSjc156560 if (comp_num < SUCCESS) 1761711890bcSjc156560 return (comp_num); 1762711890bcSjc156560 if (comp_num == 0) 1763711890bcSjc156560 continue; 1764711890bcSjc156560 1765711890bcSjc156560 comp_list = calloc(comp_num, sizeof (raid_obj_id_t)); 1766711890bcSjc156560 if (comp_list == NULL) 1767711890bcSjc156560 return (ERR_NOMEM); 1768711890bcSjc156560 1769711890bcSjc156560 for (i = 0; i < comp_num; ++i) { 1770711890bcSjc156560 *(comp_list + i) = raid_obj_create(raid_tab, 1771711890bcSjc156560 obj_type_cnt); 1772711890bcSjc156560 if (*(comp_list + i) < SUCCESS) { 1773711890bcSjc156560 ret = *(comp_list + i); 1774711890bcSjc156560 free(comp_list); 1775711890bcSjc156560 return (ret); 1776711890bcSjc156560 } 1777711890bcSjc156560 1778711890bcSjc156560 (void) raid_obj_clear_status(raid_tab, 1779711890bcSjc156560 *(comp_list + i), OBJ_STATUS_CMD_CLEAN); 1780711890bcSjc156560 (void) raid_obj_add_org(raid_tab, *(comp_list + i), 1781711890bcSjc156560 obj_id); 1782711890bcSjc156560 } 1783711890bcSjc156560 1784711890bcSjc156560 if (raid_obj_op_sys[type].complist != NULL) 1785711890bcSjc156560 raid_obj_op_sys[type].complist(raid_tab, 1786711890bcSjc156560 obj_id, comp_num, comp_list, obj_type_cnt); 1787711890bcSjc156560 free(comp_list); 1788711890bcSjc156560 } 1789711890bcSjc156560 1790711890bcSjc156560 (void) raid_obj_set_status(raid_tab, obj_id, OBJ_STATUS_SCANCOMP); 1791711890bcSjc156560 return (SUCCESS); 1792711890bcSjc156560 } 1793711890bcSjc156560 1794711890bcSjc156560 static int 1795711890bcSjc156560 obj_rescan(raid_obj_tab_t *raid_tab) 1796711890bcSjc156560 { 1797711890bcSjc156560 int ret; 1798711890bcSjc156560 1799711890bcSjc156560 raid_obj_tab_destroy(raid_tab); 1800711890bcSjc156560 1801711890bcSjc156560 if (raid_obj_tab_create(raid_tab, HASH_SLOTS) != SUCCESS) 1802711890bcSjc156560 return (ERR_NOMEM); 1803711890bcSjc156560 1804711890bcSjc156560 if ((ret = raid_obj_create_system_obj(raid_tab)) != SUCCESS) { 1805711890bcSjc156560 raid_obj_tab_destroy(raid_tab); 1806711890bcSjc156560 return (ret); 1807711890bcSjc156560 } 1808711890bcSjc156560 1809711890bcSjc156560 return (SUCCESS); 1810711890bcSjc156560 } 1811711890bcSjc156560 1812711890bcSjc156560 static raid_obj_id_t 1813711890bcSjc156560 obj_get_comp(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 1814711890bcSjc156560 raid_obj_type_id_t obj_type) 1815711890bcSjc156560 { 1816711890bcSjc156560 raid_obj_id_t id; 1817711890bcSjc156560 raid_obj_type_id_t type; 1818711890bcSjc156560 raid_obj_status_t status; 1819711890bcSjc156560 int ret; 1820711890bcSjc156560 1821711890bcSjc156560 if ((obj_type < OBJ_TYPE_SYSTEM) || (obj_type > OBJ_TYPE_ALL)) 1822711890bcSjc156560 return (ERR_DEVICE_TYPE); 1823711890bcSjc156560 1824711890bcSjc156560 status = raid_obj_get_status(raid_tab, obj_id); 1825711890bcSjc156560 if (status < SUCCESS) 1826711890bcSjc156560 return (status); 1827711890bcSjc156560 1828711890bcSjc156560 if (!(status & OBJ_STATUS_SCANCOMP)) { 1829711890bcSjc156560 ret = obj_scan_comp(raid_tab, obj_id); 1830711890bcSjc156560 if (ret < SUCCESS) 1831711890bcSjc156560 return (ret); 1832711890bcSjc156560 } 1833711890bcSjc156560 1834711890bcSjc156560 id = raid_obj_get_comp(raid_tab, obj_id); 1835711890bcSjc156560 if (id <= OBJ_NONE) 1836711890bcSjc156560 return (id); 1837711890bcSjc156560 1838711890bcSjc156560 type = raid_obj_get_type(raid_tab, id); 1839711890bcSjc156560 if (type < OBJ_TYPE_SYSTEM) 1840711890bcSjc156560 return (type); 1841711890bcSjc156560 1842711890bcSjc156560 if (type == obj_type) 1843711890bcSjc156560 return (id); 1844711890bcSjc156560 1845711890bcSjc156560 while (id > OBJ_NONE) { 1846711890bcSjc156560 id = raid_obj_get_sibling(raid_tab, id); 1847711890bcSjc156560 if (id <= OBJ_NONE) 1848711890bcSjc156560 return (id); 1849711890bcSjc156560 1850711890bcSjc156560 type = raid_obj_get_type(raid_tab, id); 1851711890bcSjc156560 if (type < OBJ_TYPE_SYSTEM) 1852711890bcSjc156560 return (type); 1853711890bcSjc156560 1854711890bcSjc156560 if (type == obj_type) 1855711890bcSjc156560 break; 1856711890bcSjc156560 }; 1857711890bcSjc156560 1858711890bcSjc156560 return (id); 1859711890bcSjc156560 } 1860711890bcSjc156560 1861711890bcSjc156560 static raid_obj_id_t 1862711890bcSjc156560 obj_get_sibling(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 1863711890bcSjc156560 { 1864711890bcSjc156560 raid_obj_id_t id; 1865711890bcSjc156560 raid_obj_type_id_t type, obj_type; 1866711890bcSjc156560 1867711890bcSjc156560 id = obj_id; 1868711890bcSjc156560 obj_type = raid_obj_get_type(raid_tab, id); 1869711890bcSjc156560 if (obj_type < OBJ_TYPE_SYSTEM) 1870711890bcSjc156560 return (obj_type); 1871711890bcSjc156560 1872711890bcSjc156560 do { 1873711890bcSjc156560 id = raid_obj_get_sibling(raid_tab, id); 1874711890bcSjc156560 if (id < OBJ_NONE) 1875711890bcSjc156560 return (id); 1876711890bcSjc156560 1877711890bcSjc156560 type = raid_obj_get_type(raid_tab, id); 1878711890bcSjc156560 if (type < OBJ_TYPE_SYSTEM) 1879711890bcSjc156560 return (type); 1880711890bcSjc156560 } while ((type != obj_type) && (id != OBJ_NONE)); 1881711890bcSjc156560 1882711890bcSjc156560 return (id); 1883711890bcSjc156560 } 1884711890bcSjc156560 1885711890bcSjc156560 static int 1886711890bcSjc156560 obj_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, void **data) 1887711890bcSjc156560 { 1888711890bcSjc156560 raid_obj_type_id_t type; 1889711890bcSjc156560 raid_obj_status_t status; 1890711890bcSjc156560 void *attr; 1891711890bcSjc156560 int ret = SUCCESS; 1892711890bcSjc156560 1893711890bcSjc156560 status = raid_obj_get_status(raid_tab, obj_id); 1894711890bcSjc156560 if (status < SUCCESS) 1895711890bcSjc156560 return (status); 1896711890bcSjc156560 1897711890bcSjc156560 type = raid_obj_get_type(raid_tab, obj_id); 1898711890bcSjc156560 if (type < OBJ_TYPE_SYSTEM) 1899711890bcSjc156560 return (type); 1900711890bcSjc156560 1901711890bcSjc156560 if (!(status & OBJ_STATUS_OPENED)) { 1902711890bcSjc156560 if (raid_obj_op_sys[type].get_attr == NULL) 1903711890bcSjc156560 (void) raid_obj_set_status(raid_tab, obj_id, 1904711890bcSjc156560 OBJ_STATUS_OPENED); 1905711890bcSjc156560 else 1906711890bcSjc156560 ret = raid_obj_op_sys[type].get_attr(raid_tab, obj_id); 1907711890bcSjc156560 } 1908711890bcSjc156560 if (ret < SUCCESS) 1909711890bcSjc156560 return (ret); 1910711890bcSjc156560 1911711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1912711890bcSjc156560 if (attr == NULL && type != OBJ_TYPE_SYSTEM) 1913711890bcSjc156560 return (ERR_DEVICE_INVALID); 1914711890bcSjc156560 1915711890bcSjc156560 *data = attr; 1916711890bcSjc156560 return (SUCCESS); 1917711890bcSjc156560 } 1918711890bcSjc156560 1919711890bcSjc156560 static raid_obj_id_t 1920711890bcSjc156560 obj_locate_controller(raid_obj_tab_t *raid_tab, uint32_t controller_id) 1921711890bcSjc156560 { 1922711890bcSjc156560 raid_obj_id_t obj_id; 1923711890bcSjc156560 controller_attr_t *attr; 1924711890bcSjc156560 1925711890bcSjc156560 obj_id = obj_get_comp(raid_tab, OBJ_SYSTEM, OBJ_TYPE_CONTROLLER); 1926711890bcSjc156560 if (obj_id <= OBJ_NONE) 1927711890bcSjc156560 return (obj_id); 1928711890bcSjc156560 1929711890bcSjc156560 do { 1930711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1931711890bcSjc156560 if (attr == NULL) 1932711890bcSjc156560 return (ERR_DEVICE_INVALID); 1933711890bcSjc156560 1934711890bcSjc156560 if (attr->controller_id == controller_id) 1935711890bcSjc156560 break; 1936711890bcSjc156560 } while ((obj_id = obj_get_sibling(raid_tab, obj_id)) != OBJ_NONE); 1937711890bcSjc156560 1938711890bcSjc156560 return (obj_id); 1939711890bcSjc156560 } 1940711890bcSjc156560 1941711890bcSjc156560 static raid_obj_id_t 1942711890bcSjc156560 obj_locate_array(raid_obj_tab_t *raid_tab, uint32_t controller_id, 1943711890bcSjc156560 uint32_t array_id) 1944711890bcSjc156560 { 1945711890bcSjc156560 raid_obj_id_t obj_id; 1946711890bcSjc156560 1947711890bcSjc156560 obj_id = obj_locate_controller(raid_tab, controller_id); 1948711890bcSjc156560 if (obj_id < OBJ_NONE) 1949711890bcSjc156560 return (obj_id); 1950711890bcSjc156560 1951711890bcSjc156560 obj_id = obj_locate_array_recur(raid_tab, obj_id, array_id); 1952711890bcSjc156560 1953711890bcSjc156560 return (obj_id); 1954711890bcSjc156560 } 1955711890bcSjc156560 1956711890bcSjc156560 static raid_obj_id_t 1957711890bcSjc156560 obj_locate_array_recur(raid_obj_tab_t *raid_tab, 1958711890bcSjc156560 raid_obj_id_t container_obj_id, uint32_t array_id) 1959711890bcSjc156560 { 1960711890bcSjc156560 raid_obj_id_t obj_id, ret; 1961711890bcSjc156560 array_attr_t *attr; 1962711890bcSjc156560 1963711890bcSjc156560 obj_id = obj_get_comp(raid_tab, container_obj_id, OBJ_TYPE_ARRAY); 1964711890bcSjc156560 if (obj_id <= OBJ_NONE) 1965711890bcSjc156560 return (obj_id); 1966711890bcSjc156560 1967711890bcSjc156560 do { 1968711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 1969711890bcSjc156560 if (attr == NULL) 1970711890bcSjc156560 return (ERR_DEVICE_INVALID); 1971711890bcSjc156560 1972711890bcSjc156560 if (attr->array_id == array_id) 1973711890bcSjc156560 break; 1974711890bcSjc156560 1975711890bcSjc156560 ret = obj_locate_array_recur(raid_tab, obj_id, array_id); 1976711890bcSjc156560 if (ret != OBJ_NONE) 1977711890bcSjc156560 return (ret); 1978711890bcSjc156560 1979711890bcSjc156560 } while ((obj_id = obj_get_sibling(raid_tab, obj_id)) > OBJ_NONE); 1980711890bcSjc156560 1981711890bcSjc156560 return (obj_id); 1982711890bcSjc156560 } 1983711890bcSjc156560 1984711890bcSjc156560 static raid_obj_id_t 1985711890bcSjc156560 obj_locate_hsp(raid_obj_tab_t *raid_tab, uint32_t controller_id, 1986711890bcSjc156560 uint32_t disk_id, uint32_t array_id) 1987711890bcSjc156560 { 1988711890bcSjc156560 raid_obj_id_t obj_id; 1989711890bcSjc156560 hsp_attr_t *hsp_attr; 1990711890bcSjc156560 1991711890bcSjc156560 obj_id = obj_locate_disk(raid_tab, controller_id, disk_id); 1992711890bcSjc156560 if (obj_id <= OBJ_NONE) 1993711890bcSjc156560 return (obj_id); 1994711890bcSjc156560 1995711890bcSjc156560 obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_HSP); 1996711890bcSjc156560 if (obj_id <= OBJ_NONE) 1997711890bcSjc156560 return (obj_id); 1998711890bcSjc156560 1999711890bcSjc156560 do { 2000711890bcSjc156560 (void) obj_get_attr(raid_tab, obj_id, (void **)(&hsp_attr)); 2001711890bcSjc156560 if (hsp_attr->associated_id == array_id) 2002711890bcSjc156560 break; 2003711890bcSjc156560 2004711890bcSjc156560 obj_id = obj_get_sibling(raid_tab, obj_id); 2005711890bcSjc156560 if (obj_id < OBJ_NONE) 2006711890bcSjc156560 return (obj_id); 2007711890bcSjc156560 } while (obj_id > OBJ_NONE); 2008711890bcSjc156560 2009711890bcSjc156560 return (obj_id); 2010711890bcSjc156560 } 2011711890bcSjc156560 2012711890bcSjc156560 static raid_obj_id_t 2013711890bcSjc156560 obj_locate_disk(raid_obj_tab_t *raid_tab, uint32_t controller_id, 2014711890bcSjc156560 uint32_t disk_id) 2015711890bcSjc156560 { 2016711890bcSjc156560 raid_obj_id_t obj_id; 2017711890bcSjc156560 disk_attr_t *attr; 2018711890bcSjc156560 2019711890bcSjc156560 obj_id = obj_locate_controller(raid_tab, controller_id); 2020711890bcSjc156560 if (obj_id <= OBJ_NONE) 2021711890bcSjc156560 return (obj_id); 2022711890bcSjc156560 2023711890bcSjc156560 obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_DISK); 2024711890bcSjc156560 if (obj_id <= OBJ_NONE) 2025711890bcSjc156560 return (obj_id); 2026711890bcSjc156560 2027711890bcSjc156560 do { 2028711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2029711890bcSjc156560 if (attr == NULL) 2030711890bcSjc156560 return (ERR_DEVICE_INVALID); 2031711890bcSjc156560 2032711890bcSjc156560 if (attr->disk_id == disk_id) 2033711890bcSjc156560 break; 2034711890bcSjc156560 } while ((obj_id = obj_get_sibling(raid_tab, obj_id)) > OBJ_NONE); 2035711890bcSjc156560 2036711890bcSjc156560 return (obj_id); 2037711890bcSjc156560 } 2038711890bcSjc156560 2039711890bcSjc156560 static raid_obj_id_t 2040711890bcSjc156560 obj_locate_arraypart(raid_obj_tab_t *raid_tab, uint32_t controller_id, 2041711890bcSjc156560 uint32_t array_id, uint32_t disk_id) 2042711890bcSjc156560 { 2043711890bcSjc156560 raid_obj_id_t obj_id; 2044711890bcSjc156560 2045711890bcSjc156560 arraypart_attr_t *attr; 2046711890bcSjc156560 2047711890bcSjc156560 obj_id = obj_locate_array(raid_tab, controller_id, array_id); 2048711890bcSjc156560 if (obj_id <= OBJ_NONE) 2049711890bcSjc156560 return (obj_id); 2050711890bcSjc156560 2051711890bcSjc156560 obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_ARRAY_PART); 2052711890bcSjc156560 if (obj_id <= OBJ_NONE) 2053711890bcSjc156560 return (obj_id); 2054711890bcSjc156560 2055711890bcSjc156560 do { 2056711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2057711890bcSjc156560 if (attr == NULL) 2058711890bcSjc156560 return (ERR_DEVICE_INVALID); 2059711890bcSjc156560 2060711890bcSjc156560 if (attr->disk_id == disk_id) 2061711890bcSjc156560 break; 2062711890bcSjc156560 } while ((obj_id = obj_get_sibling(raid_tab, obj_id)) > 2063711890bcSjc156560 OBJ_NONE); 2064711890bcSjc156560 2065711890bcSjc156560 return (obj_id); 2066711890bcSjc156560 } 2067711890bcSjc156560 2068711890bcSjc156560 static raid_obj_id_t 2069711890bcSjc156560 obj_locate_diskseg(raid_obj_tab_t *raid_tab, uint32_t controller_id, 2070711890bcSjc156560 uint32_t disk_id, uint32_t seq_no) 2071711890bcSjc156560 { 2072711890bcSjc156560 raid_obj_id_t obj_id; 2073711890bcSjc156560 diskseg_attr_t *attr; 2074711890bcSjc156560 2075711890bcSjc156560 obj_id = obj_locate_disk(raid_tab, controller_id, disk_id); 2076711890bcSjc156560 if (obj_id <= OBJ_NONE) 2077711890bcSjc156560 return (obj_id); 2078711890bcSjc156560 2079711890bcSjc156560 obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_DISK_SEG); 2080711890bcSjc156560 if (obj_id <= OBJ_NONE) 2081711890bcSjc156560 return (obj_id); 2082711890bcSjc156560 2083711890bcSjc156560 do { 2084711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2085711890bcSjc156560 if (attr == NULL) 2086711890bcSjc156560 return (ERR_DEVICE_INVALID); 2087711890bcSjc156560 2088711890bcSjc156560 if (attr->seq_no == seq_no) 2089711890bcSjc156560 break; 2090711890bcSjc156560 } while ((obj_id = obj_get_sibling(raid_tab, obj_id)) > OBJ_NONE); 2091711890bcSjc156560 2092711890bcSjc156560 return (obj_id); 2093711890bcSjc156560 } 2094711890bcSjc156560 2095711890bcSjc156560 static raid_obj_id_t 2096711890bcSjc156560 obj_locate_task(raid_obj_tab_t *raid_tab, uint32_t controller_id, 2097711890bcSjc156560 uint32_t task_id) 2098711890bcSjc156560 { 2099711890bcSjc156560 raid_obj_id_t obj_id, obj_id2, task_obj_id; 2100711890bcSjc156560 task_attr_t *attr; 2101711890bcSjc156560 2102711890bcSjc156560 obj_id = obj_locate_controller(raid_tab, controller_id); 2103711890bcSjc156560 if (obj_id <= OBJ_NONE) 2104711890bcSjc156560 return (obj_id); 2105711890bcSjc156560 2106711890bcSjc156560 obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_ARRAY); 2107711890bcSjc156560 if (obj_id < OBJ_NONE) 2108711890bcSjc156560 return (obj_id); 2109711890bcSjc156560 2110711890bcSjc156560 do { 2111711890bcSjc156560 obj_id2 = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_ARRAY); 2112711890bcSjc156560 while (obj_id2 != OBJ_NONE) { 2113711890bcSjc156560 task_obj_id = obj_get_comp(raid_tab, obj_id2, 2114711890bcSjc156560 OBJ_TYPE_TASK); 2115711890bcSjc156560 2116711890bcSjc156560 if (task_obj_id < OBJ_NONE) 2117711890bcSjc156560 return (task_obj_id); 2118711890bcSjc156560 2119711890bcSjc156560 if (task_obj_id == OBJ_NONE) { 2120711890bcSjc156560 obj_id2 = obj_get_sibling(raid_tab, obj_id2); 2121711890bcSjc156560 continue; 2122711890bcSjc156560 } 2123711890bcSjc156560 2124711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, task_obj_id); 2125711890bcSjc156560 if (attr == NULL) 2126711890bcSjc156560 return (ERR_DEVICE_INVALID); 2127711890bcSjc156560 2128711890bcSjc156560 if (attr->task_id == task_id) 2129711890bcSjc156560 return (task_obj_id); 2130711890bcSjc156560 2131711890bcSjc156560 obj_id2 = obj_get_sibling(raid_tab, obj_id2); 2132711890bcSjc156560 } 2133711890bcSjc156560 2134711890bcSjc156560 task_obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_TASK); 2135711890bcSjc156560 if (task_obj_id < OBJ_NONE) 2136711890bcSjc156560 return (task_obj_id); 2137711890bcSjc156560 2138711890bcSjc156560 if (task_obj_id == OBJ_NONE) 2139711890bcSjc156560 continue; 2140711890bcSjc156560 2141711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, task_obj_id); 2142711890bcSjc156560 if (attr == NULL) 2143711890bcSjc156560 return (ERR_DEVICE_INVALID); 2144711890bcSjc156560 2145711890bcSjc156560 if (attr->task_id == task_id) 2146711890bcSjc156560 return (task_obj_id); 2147711890bcSjc156560 } while ((obj_id = obj_get_sibling(raid_tab, obj_id)) > OBJ_NONE); 2148711890bcSjc156560 2149711890bcSjc156560 if (obj_id < OBJ_NONE) 2150711890bcSjc156560 return (obj_id); 2151711890bcSjc156560 2152711890bcSjc156560 obj_id = obj_locate_controller(raid_tab, controller_id); 2153711890bcSjc156560 obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_DISK); 2154711890bcSjc156560 if (obj_id < OBJ_NONE) 2155711890bcSjc156560 return (obj_id); 2156711890bcSjc156560 2157711890bcSjc156560 do { 2158711890bcSjc156560 task_obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_TASK); 2159711890bcSjc156560 if (task_obj_id < OBJ_NONE) 2160711890bcSjc156560 return (task_obj_id); 2161711890bcSjc156560 2162711890bcSjc156560 if (task_obj_id == OBJ_NONE) 2163711890bcSjc156560 continue; 2164711890bcSjc156560 2165711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, task_obj_id); 2166711890bcSjc156560 if (attr == NULL) 2167711890bcSjc156560 return (ERR_DEVICE_INVALID); 2168711890bcSjc156560 2169711890bcSjc156560 if (attr->task_id == task_id) 2170711890bcSjc156560 return (task_obj_id); 2171711890bcSjc156560 } while ((obj_id = obj_get_sibling(raid_tab, obj_id)) > OBJ_NONE); 2172711890bcSjc156560 2173711890bcSjc156560 return (obj_id); 2174b449fa8aSyw161884 } 2175711890bcSjc156560 2176b449fa8aSyw161884 static raid_obj_id_t 2177b449fa8aSyw161884 obj_locate_prop(raid_obj_tab_t *raid_tab, uint32_t controller_id, 2178b449fa8aSyw161884 uint32_t disk_id, uint32_t prop_id) 2179b449fa8aSyw161884 { 2180b449fa8aSyw161884 raid_obj_id_t obj_id; 2181b449fa8aSyw161884 property_attr_t *prop_attr; 2182b449fa8aSyw161884 2183b449fa8aSyw161884 obj_id = obj_locate_disk(raid_tab, controller_id, disk_id); 2184b449fa8aSyw161884 if (obj_id < OBJ_NONE) 2185b449fa8aSyw161884 return (obj_id); 2186b449fa8aSyw161884 2187b449fa8aSyw161884 obj_id = obj_get_comp(raid_tab, obj_id, OBJ_TYPE_PROP); 2188b449fa8aSyw161884 if (obj_id <= OBJ_NONE) 2189b449fa8aSyw161884 return (obj_id); 2190b449fa8aSyw161884 2191b449fa8aSyw161884 do { 2192b449fa8aSyw161884 (void) obj_get_attr(raid_tab, obj_id, (void **)(&prop_attr)); 2193b449fa8aSyw161884 if (prop_attr->prop_id == prop_id) 2194b449fa8aSyw161884 break; 2195b449fa8aSyw161884 2196b449fa8aSyw161884 obj_id = obj_get_sibling(raid_tab, obj_id); 2197b449fa8aSyw161884 if (obj_id < OBJ_NONE) 2198b449fa8aSyw161884 return (obj_id); 2199b449fa8aSyw161884 } while (obj_id > OBJ_NONE); 2200b449fa8aSyw161884 2201b449fa8aSyw161884 return (obj_id); 2202711890bcSjc156560 } 2203711890bcSjc156560 2204711890bcSjc156560 static raid_obj_id_t 2205711890bcSjc156560 obj_get_controller(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 2206711890bcSjc156560 { 2207711890bcSjc156560 raid_obj_id_t id = obj_id; 2208711890bcSjc156560 2209711890bcSjc156560 while (raid_obj_get_type(raid_tab, id) != OBJ_TYPE_CONTROLLER) { 2210711890bcSjc156560 id = raid_obj_get_container(raid_tab, id); 2211711890bcSjc156560 if ((id == OBJ_SYSTEM) || (id < OBJ_NONE)) 2212711890bcSjc156560 return (ERR_DEVICE_INVALID); 2213711890bcSjc156560 } 2214711890bcSjc156560 2215711890bcSjc156560 return (id); 2216711890bcSjc156560 } 2217711890bcSjc156560 2218711890bcSjc156560 /* 2219711890bcSjc156560 * Raid object operation routines 2220711890bcSjc156560 */ 2221711890bcSjc156560 static int 2222711890bcSjc156560 obj_sys_compnum(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2223711890bcSjc156560 raid_obj_type_id_t comp_type) 2224711890bcSjc156560 { 2225711890bcSjc156560 DIR *dir; 2226711890bcSjc156560 struct dirent *dp; 2227711890bcSjc156560 int num = 0; 2228711890bcSjc156560 2229711890bcSjc156560 if ((raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_SYSTEM)) 2230711890bcSjc156560 return (ERR_DEVICE_TYPE); 2231711890bcSjc156560 2232711890bcSjc156560 if (comp_type != OBJ_TYPE_CONTROLLER) 2233711890bcSjc156560 return (0); 2234711890bcSjc156560 2235711890bcSjc156560 if ((dir = opendir(CFGDIR)) == NULL) 2236711890bcSjc156560 return (ERR_DRIVER_NOT_FOUND); 2237711890bcSjc156560 2238711890bcSjc156560 while ((dp = readdir(dir)) != NULL) { 2239711890bcSjc156560 uint32_t controller_id; 2240711890bcSjc156560 char path[MAX_PATH_LEN]; 2241711890bcSjc156560 2242711890bcSjc156560 if (strcmp(dp->d_name, ".") == 0 || 2243711890bcSjc156560 strcmp(dp->d_name, "..") == 0) 2244711890bcSjc156560 continue; 2245711890bcSjc156560 2246711890bcSjc156560 if (sscanf(dp->d_name, "c%u", &controller_id) != 1) 2247711890bcSjc156560 continue; 2248711890bcSjc156560 2249711890bcSjc156560 if (controller_id_to_path(controller_id, path) == SUCCESS) 2250711890bcSjc156560 ++ num; 2251711890bcSjc156560 } 2252711890bcSjc156560 2253711890bcSjc156560 (void) closedir(dir); 2254711890bcSjc156560 return (num); 2255711890bcSjc156560 } 2256711890bcSjc156560 2257711890bcSjc156560 static int 2258711890bcSjc156560 obj_sys_complist(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2259711890bcSjc156560 int num, raid_obj_id_t *comp_list, raid_obj_type_id_t comp_type) 2260711890bcSjc156560 { 2261711890bcSjc156560 DIR *dir; 2262711890bcSjc156560 struct dirent *dp; 2263711890bcSjc156560 controller_attr_t *attr; 2264711890bcSjc156560 uint32_t controller_id; 2265711890bcSjc156560 uint32_t *tmplist; 2266711890bcSjc156560 char path[MAX_PATH_LEN]; 2267711890bcSjc156560 int i = 0; 2268711890bcSjc156560 2269711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_SYSTEM) 2270711890bcSjc156560 return (ERR_DEVICE_TYPE); 2271711890bcSjc156560 if ((num <= 0) || (comp_list == NULL)) 2272711890bcSjc156560 return (ERR_OP_ILLEGAL); 2273711890bcSjc156560 2274711890bcSjc156560 if (comp_type != OBJ_TYPE_CONTROLLER) 2275711890bcSjc156560 return (0); 2276711890bcSjc156560 2277711890bcSjc156560 if ((dir = opendir(CFGDIR)) == NULL) 2278711890bcSjc156560 return (ERR_DRIVER_NOT_FOUND); 2279711890bcSjc156560 tmplist = calloc(num, sizeof (uint32_t)); 2280711890bcSjc156560 if (tmplist == NULL) { 2281711890bcSjc156560 return (ERR_NOMEM); 2282711890bcSjc156560 } 2283711890bcSjc156560 while ((dp = readdir(dir)) != NULL) { 2284711890bcSjc156560 if (strcmp(dp->d_name, ".") == 0 || 2285711890bcSjc156560 strcmp(dp->d_name, "..") == 0) 2286711890bcSjc156560 continue; 2287711890bcSjc156560 2288711890bcSjc156560 if (sscanf(dp->d_name, "c%u", &controller_id) != 1) 2289711890bcSjc156560 continue; 2290711890bcSjc156560 2291711890bcSjc156560 if (controller_id_to_path(controller_id, path) == SUCCESS) { 2292711890bcSjc156560 tmplist[i] = controller_id; 2293711890bcSjc156560 ++ i; 2294711890bcSjc156560 } 2295711890bcSjc156560 } 2296711890bcSjc156560 qsort((void *)tmplist, num, sizeof (uint32_t), intcompare); 2297711890bcSjc156560 for (i = 0; i < num; i++) { 2298711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, 2299711890bcSjc156560 *(comp_list + i)); 2300711890bcSjc156560 2301711890bcSjc156560 if (attr == NULL) { 2302711890bcSjc156560 free(tmplist); 2303711890bcSjc156560 return (ERR_DEVICE_INVALID); 2304711890bcSjc156560 } 2305711890bcSjc156560 2306711890bcSjc156560 attr->controller_id = tmplist[i]; 2307711890bcSjc156560 } 2308711890bcSjc156560 free(tmplist); 2309711890bcSjc156560 (void) closedir(dir); 2310711890bcSjc156560 return (SUCCESS); 2311711890bcSjc156560 } 2312711890bcSjc156560 2313711890bcSjc156560 static int 2314711890bcSjc156560 obj_controller_compnum(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2315711890bcSjc156560 raid_obj_type_id_t comp_type) 2316711890bcSjc156560 { 2317711890bcSjc156560 raid_lib_t *raid_lib; 2318711890bcSjc156560 int ret = SUCCESS, fd; 2319711890bcSjc156560 controller_attr_t *ctl_attrp; 2320711890bcSjc156560 2321711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 2322711890bcSjc156560 return (ERR_DEVICE_TYPE); 2323711890bcSjc156560 2324711890bcSjc156560 if ((comp_type != OBJ_TYPE_ARRAY) && (comp_type != OBJ_TYPE_DISK)) 2325711890bcSjc156560 return (0); 2326711890bcSjc156560 2327711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, obj_id); 2328711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, obj_id); 2329711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, obj_id); 2330711890bcSjc156560 if ((raid_lib == NULL) || (ctl_attrp == NULL) || (fd == 0)) 2331711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2332711890bcSjc156560 2333711890bcSjc156560 ret = raid_lib->compnum(ctl_attrp->controller_id, 0, 2334711890bcSjc156560 OBJ_TYPE_CONTROLLER, comp_type); 2335711890bcSjc156560 2336711890bcSjc156560 return (ret); 2337711890bcSjc156560 } 2338711890bcSjc156560 2339711890bcSjc156560 static int 2340711890bcSjc156560 obj_controller_complist(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2341711890bcSjc156560 int comp_num, raid_obj_id_t *comp_list, raid_obj_type_id_t comp_type) 2342711890bcSjc156560 { 2343711890bcSjc156560 raid_lib_t *raid_lib; 2344711890bcSjc156560 controller_attr_t *ctl_attrp; 2345711890bcSjc156560 int ret, i, fd; 2346711890bcSjc156560 uint32_t *ids; 2347711890bcSjc156560 2348711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 2349711890bcSjc156560 return (ERR_DEVICE_TYPE); 2350711890bcSjc156560 2351711890bcSjc156560 if ((comp_type != OBJ_TYPE_ARRAY) && (comp_type != OBJ_TYPE_DISK)) 2352711890bcSjc156560 return (0); 2353711890bcSjc156560 2354711890bcSjc156560 if ((comp_num <= 0) || (comp_list == NULL)) 2355711890bcSjc156560 return (ERR_OP_ILLEGAL); 2356711890bcSjc156560 2357711890bcSjc156560 for (i = 0; i < comp_num; ++i) 2358711890bcSjc156560 if (raid_obj_get_type(raid_tab, *(comp_list + i)) != 2359711890bcSjc156560 comp_type) 2360711890bcSjc156560 return (ERR_DEVICE_TYPE); 2361711890bcSjc156560 2362711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, obj_id); 2363711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, obj_id); 2364711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, obj_id); 2365711890bcSjc156560 if ((raid_lib == NULL) || (ctl_attrp == NULL)|| (fd == 0)) 2366711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2367711890bcSjc156560 2368711890bcSjc156560 ids = malloc(comp_num * sizeof (uint32_t)); 2369711890bcSjc156560 if (ids == NULL) 2370711890bcSjc156560 return (ERR_NOMEM); 2371711890bcSjc156560 2372711890bcSjc156560 ret = raid_lib->complist(ctl_attrp->controller_id, 0, 2373711890bcSjc156560 OBJ_TYPE_CONTROLLER, comp_type, comp_num, ids); 2374711890bcSjc156560 if (ret < SUCCESS) { 2375711890bcSjc156560 free(ids); 2376711890bcSjc156560 return (ret); 2377711890bcSjc156560 } 2378711890bcSjc156560 qsort((void *)ids, comp_num, sizeof (uint32_t), intcompare); 2379711890bcSjc156560 for (i = 0; i < comp_num; ++ i) { 2380711890bcSjc156560 array_attr_t *array_attr; 2381711890bcSjc156560 disk_attr_t *disk_attr; 2382711890bcSjc156560 void *attr_buf; 2383711890bcSjc156560 2384711890bcSjc156560 attr_buf = raid_obj_get_data_ptr(raid_tab, *(comp_list + i)); 2385711890bcSjc156560 if (attr_buf == NULL) { 2386711890bcSjc156560 free(ids); 2387711890bcSjc156560 return (ERR_DEVICE_INVALID); 2388711890bcSjc156560 } 2389711890bcSjc156560 2390711890bcSjc156560 switch (comp_type) { 2391711890bcSjc156560 case OBJ_TYPE_ARRAY: 2392711890bcSjc156560 array_attr = attr_buf; 2393711890bcSjc156560 array_attr->array_id = *(ids + i); 2394711890bcSjc156560 break; 2395711890bcSjc156560 case OBJ_TYPE_DISK: 2396711890bcSjc156560 disk_attr = attr_buf; 2397711890bcSjc156560 disk_attr->disk_id = *(ids + i); 2398711890bcSjc156560 break; 2399711890bcSjc156560 default: 2400711890bcSjc156560 free(ids); 2401711890bcSjc156560 return (ERR_DEVICE_INVALID); 2402711890bcSjc156560 } 2403711890bcSjc156560 } 2404711890bcSjc156560 2405711890bcSjc156560 free(ids); 2406711890bcSjc156560 return (SUCCESS); 2407711890bcSjc156560 } 2408711890bcSjc156560 2409711890bcSjc156560 static int 2410711890bcSjc156560 obj_controller_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 2411711890bcSjc156560 { 2412711890bcSjc156560 controller_attr_t *attr; 2413711890bcSjc156560 raid_lib_t *raid_lib; 2414711890bcSjc156560 int ret = SUCCESS, fd; 2415711890bcSjc156560 2416711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 2417711890bcSjc156560 return (ERR_DEVICE_TYPE); 2418711890bcSjc156560 2419711890bcSjc156560 if (raid_obj_get_status(raid_tab, obj_id) & OBJ_STATUS_OPENED) 2420711890bcSjc156560 return (SUCCESS); 2421711890bcSjc156560 2422711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2423711890bcSjc156560 if (attr == NULL) 2424711890bcSjc156560 return (ERR_DEVICE_INVALID); 2425711890bcSjc156560 2426711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, obj_id); 2427711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, obj_id); 2428711890bcSjc156560 2429711890bcSjc156560 /* 2430711890bcSjc156560 * For a controller, even it's not opened, we can still 2431711890bcSjc156560 * get the driver name 2432711890bcSjc156560 */ 2433711890bcSjc156560 2434711890bcSjc156560 if (fd == 0) 2435711890bcSjc156560 return (SUCCESS); 2436711890bcSjc156560 2437711890bcSjc156560 if (raid_lib == NULL) { 2438711890bcSjc156560 return (SUCCESS); 2439711890bcSjc156560 } 2440711890bcSjc156560 2441711890bcSjc156560 ret = raid_lib->get_attr(attr->controller_id, OBJ_ATTR_NONE, 2442711890bcSjc156560 OBJ_ATTR_NONE, OBJ_TYPE_CONTROLLER, attr); 2443711890bcSjc156560 if (ret < SUCCESS) 2444711890bcSjc156560 return (ret); 2445711890bcSjc156560 2446711890bcSjc156560 (void) raid_obj_set_status(raid_tab, obj_id, OBJ_STATUS_OPENED); 2447711890bcSjc156560 2448711890bcSjc156560 return (ret); 2449711890bcSjc156560 } 2450711890bcSjc156560 2451711890bcSjc156560 static int 2452711890bcSjc156560 obj_controller_act(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2453711890bcSjc156560 uint32_t sub_cmd, void *prop_list, char **plugin_err_str) 2454711890bcSjc156560 { 2455711890bcSjc156560 controller_attr_t *attr; 2456711890bcSjc156560 raid_lib_t *raid_lib; 2457711890bcSjc156560 int ret, fd; 2458711890bcSjc156560 2459711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_CONTROLLER) 2460711890bcSjc156560 return (ERR_DEVICE_TYPE); 2461711890bcSjc156560 2462711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2463711890bcSjc156560 2464711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, obj_id); 2465711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, obj_id); 2466711890bcSjc156560 2467711890bcSjc156560 switch (sub_cmd) { 2468711890bcSjc156560 case ACT_CONTROLLER_OPEN: 2469711890bcSjc156560 /* Check if already opened */ 2470711890bcSjc156560 2471711890bcSjc156560 if (fd > 0) 2472711890bcSjc156560 return (SUCCESS); 2473711890bcSjc156560 2474711890bcSjc156560 /* Check if plugin is already attached */ 2475711890bcSjc156560 if (raid_lib == NULL) { 2476711890bcSjc156560 raid_lib = raid_find_lib(raid_tab, obj_id); 2477711890bcSjc156560 if (raid_lib == NULL) 2478711890bcSjc156560 return (ERR_DRIVER_NOT_FOUND); 2479711890bcSjc156560 } 2480711890bcSjc156560 2481711890bcSjc156560 ret = raid_lib->open_controller(attr->controller_id, 2482711890bcSjc156560 plugin_err_str); 2483711890bcSjc156560 if (ret == SUCCESS) { 2484711890bcSjc156560 (void) raid_obj_set_lib(raid_tab, obj_id, raid_lib); 2485711890bcSjc156560 (void) raid_obj_set_fd(raid_tab, obj_id, 1); 2486711890bcSjc156560 } 2487711890bcSjc156560 break; 2488711890bcSjc156560 case ACT_CONTROLLER_CLOSE: 2489711890bcSjc156560 2490711890bcSjc156560 if (fd <= 0) 2491711890bcSjc156560 return (SUCCESS); 2492711890bcSjc156560 2493711890bcSjc156560 if (raid_lib == NULL) { 2494711890bcSjc156560 return (SUCCESS); 2495711890bcSjc156560 } 2496711890bcSjc156560 ret = raid_lib->close_controller(attr->controller_id, 2497711890bcSjc156560 plugin_err_str); 2498711890bcSjc156560 if (ret == SUCCESS) { 2499711890bcSjc156560 (void) raid_obj_set_fd(raid_tab, obj_id, 0); 2500711890bcSjc156560 (void) raid_obj_set_lib(raid_tab, obj_id, NULL); 2501711890bcSjc156560 raid_handle_delete_controller_comp(attr->controller_id); 2502711890bcSjc156560 } 2503711890bcSjc156560 break; 2504711890bcSjc156560 case ACT_CONTROLLER_FLASH_FW: 2505711890bcSjc156560 { 2506711890bcSjc156560 char *filebuf; 2507711890bcSjc156560 int image_fd; 2508711890bcSjc156560 uint32_t size; 2509711890bcSjc156560 struct stat statbuf; 2510711890bcSjc156560 2511711890bcSjc156560 if (prop_list == NULL) 2512711890bcSjc156560 return (ERR_OP_ILLEGAL); 2513711890bcSjc156560 2514711890bcSjc156560 /* Open firmware image file */ 2515711890bcSjc156560 image_fd = open((const char *)prop_list, 2516711890bcSjc156560 O_RDONLY | O_NDELAY); 2517711890bcSjc156560 if (image_fd == -1) 2518711890bcSjc156560 return (ERR_OP_FAILED); 2519711890bcSjc156560 2520711890bcSjc156560 if (fstat(image_fd, &statbuf) != 0) { 2521711890bcSjc156560 (void) close(image_fd); 2522711890bcSjc156560 return (ERR_OP_FAILED); 2523711890bcSjc156560 } 2524711890bcSjc156560 2525711890bcSjc156560 filebuf = malloc(statbuf.st_size); 2526711890bcSjc156560 if (filebuf == NULL) { 2527711890bcSjc156560 (void) close(image_fd); 2528711890bcSjc156560 return (ERR_NOMEM); 2529711890bcSjc156560 } 2530711890bcSjc156560 2531711890bcSjc156560 size = read(image_fd, filebuf, statbuf.st_size); 2532711890bcSjc156560 if (size != statbuf.st_size) { 2533711890bcSjc156560 (void) close(image_fd); 2534711890bcSjc156560 free(filebuf); 2535711890bcSjc156560 return (ERR_OP_FAILED); 2536711890bcSjc156560 } 2537711890bcSjc156560 2538711890bcSjc156560 if (fd <= 0) { 2539711890bcSjc156560 (void) close(image_fd); 2540711890bcSjc156560 free(filebuf); 2541711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2542711890bcSjc156560 } 2543711890bcSjc156560 2544711890bcSjc156560 if (raid_lib == NULL) { 2545711890bcSjc156560 (void) close(image_fd); 2546711890bcSjc156560 free(filebuf); 2547711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2548711890bcSjc156560 } 2549711890bcSjc156560 if (raid_lib->flash_fw == NULL) { 2550711890bcSjc156560 (void) close(image_fd); 2551711890bcSjc156560 free(filebuf); 2552711890bcSjc156560 return (ERR_OP_NO_IMPL); 2553711890bcSjc156560 } 2554711890bcSjc156560 2555711890bcSjc156560 ret = raid_lib->flash_fw(attr->controller_id, 2556711890bcSjc156560 filebuf, size, plugin_err_str); 2557711890bcSjc156560 } 2558711890bcSjc156560 break; 2559711890bcSjc156560 default: 2560711890bcSjc156560 return (ERR_OP_ILLEGAL); 2561711890bcSjc156560 } 2562711890bcSjc156560 2563711890bcSjc156560 return (ret); 2564711890bcSjc156560 } 2565711890bcSjc156560 2566711890bcSjc156560 static int 2567711890bcSjc156560 obj_array_compnum(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2568711890bcSjc156560 raid_obj_type_id_t comp_type) 2569711890bcSjc156560 { 2570711890bcSjc156560 array_attr_t *attr; 2571711890bcSjc156560 controller_attr_t *ctl_attrp; 2572711890bcSjc156560 raid_obj_id_t controller_obj_id; 2573711890bcSjc156560 raid_lib_t *raid_lib; 2574711890bcSjc156560 int ret = SUCCESS, fd; 2575711890bcSjc156560 2576711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_ARRAY) 2577711890bcSjc156560 return (ERR_DEVICE_TYPE); 2578711890bcSjc156560 2579711890bcSjc156560 if (comp_type != OBJ_TYPE_ARRAY_PART && 2580711890bcSjc156560 comp_type != OBJ_TYPE_ARRAY && 2581711890bcSjc156560 comp_type != OBJ_TYPE_TASK) 2582711890bcSjc156560 return (0); 2583711890bcSjc156560 2584711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2585711890bcSjc156560 if (attr == NULL) 2586711890bcSjc156560 return (ERR_DEVICE_INVALID); 2587711890bcSjc156560 2588711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 2589711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 2590711890bcSjc156560 return (ERR_DEVICE_INVALID); 2591711890bcSjc156560 2592711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 2593711890bcSjc156560 if (ctl_attrp == NULL) { 2594711890bcSjc156560 return (ERR_DEVICE_INVALID); 2595711890bcSjc156560 } 2596711890bcSjc156560 2597711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 2598711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 2599711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 2600711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2601711890bcSjc156560 2602711890bcSjc156560 ret = raid_lib->compnum(ctl_attrp->controller_id, attr->array_id, 2603711890bcSjc156560 OBJ_TYPE_ARRAY, comp_type); 2604711890bcSjc156560 2605711890bcSjc156560 return (ret); 2606711890bcSjc156560 } 2607711890bcSjc156560 2608711890bcSjc156560 static int 2609711890bcSjc156560 obj_array_complist(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2610711890bcSjc156560 int comp_num, raid_obj_id_t *comp_list, raid_obj_type_id_t comp_type) 2611711890bcSjc156560 { 2612711890bcSjc156560 array_attr_t *attr; 2613711890bcSjc156560 controller_attr_t *ctl_attrp; 2614711890bcSjc156560 raid_obj_id_t controller_obj_id; 2615711890bcSjc156560 raid_lib_t *raid_lib; 2616711890bcSjc156560 int ret, i, fd; 2617711890bcSjc156560 uint32_t *ids; 2618711890bcSjc156560 2619711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_ARRAY) 2620711890bcSjc156560 return (ERR_DEVICE_TYPE); 2621711890bcSjc156560 2622711890bcSjc156560 if (comp_type != OBJ_TYPE_ARRAY_PART && 2623711890bcSjc156560 comp_type != OBJ_TYPE_ARRAY && 2624711890bcSjc156560 comp_type != OBJ_TYPE_TASK) 2625711890bcSjc156560 return (0); 2626711890bcSjc156560 2627711890bcSjc156560 if (comp_num <= 0 || comp_list == NULL) 2628711890bcSjc156560 return (ERR_OP_ILLEGAL); 2629711890bcSjc156560 2630711890bcSjc156560 for (i = 0; i < comp_num; ++i) 2631711890bcSjc156560 if (raid_obj_get_type(raid_tab, *(comp_list + i)) != 2632711890bcSjc156560 comp_type) 2633711890bcSjc156560 return (ERR_DEVICE_TYPE); 2634711890bcSjc156560 2635711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2636711890bcSjc156560 if (attr == NULL) 2637711890bcSjc156560 return (ERR_DEVICE_INVALID); 2638711890bcSjc156560 2639711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 2640711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 2641711890bcSjc156560 return (ERR_DEVICE_INVALID); 2642711890bcSjc156560 2643711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 2644711890bcSjc156560 if (ctl_attrp == NULL) { 2645711890bcSjc156560 return (ERR_DEVICE_INVALID); 2646711890bcSjc156560 } 2647711890bcSjc156560 2648711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 2649711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 2650711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 2651711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2652711890bcSjc156560 2653711890bcSjc156560 ids = malloc(comp_num * sizeof (uint32_t)); 2654711890bcSjc156560 if (ids == NULL) 2655711890bcSjc156560 return (ERR_NOMEM); 2656711890bcSjc156560 2657711890bcSjc156560 ret = raid_lib->complist(ctl_attrp->controller_id, 2658711890bcSjc156560 attr->array_id, OBJ_TYPE_ARRAY, comp_type, comp_num, ids); 2659711890bcSjc156560 2660711890bcSjc156560 if (ret < SUCCESS) { 2661711890bcSjc156560 free(ids); 2662711890bcSjc156560 return (ret); 2663711890bcSjc156560 } 2664711890bcSjc156560 2665711890bcSjc156560 for (i = 0; i < comp_num; ++ i) { 2666711890bcSjc156560 array_attr_t *array_attr; 2667711890bcSjc156560 arraypart_attr_t *arraypart_attr; 2668711890bcSjc156560 task_attr_t *task_attr; 2669711890bcSjc156560 void *attr_buf; 2670711890bcSjc156560 2671711890bcSjc156560 attr_buf = raid_obj_get_data_ptr(raid_tab, *(comp_list + i)); 2672711890bcSjc156560 if (attr_buf == NULL) { 2673711890bcSjc156560 free(ids); 2674711890bcSjc156560 return (ERR_DEVICE_INVALID); 2675711890bcSjc156560 } 2676711890bcSjc156560 2677711890bcSjc156560 switch (comp_type) { 2678711890bcSjc156560 case OBJ_TYPE_ARRAY: 2679711890bcSjc156560 array_attr = attr_buf; 2680711890bcSjc156560 array_attr->array_id = *(ids + i); 2681711890bcSjc156560 break; 2682711890bcSjc156560 case OBJ_TYPE_ARRAY_PART: 2683711890bcSjc156560 arraypart_attr = attr_buf; 2684711890bcSjc156560 arraypart_attr->disk_id = *(ids + i); 2685711890bcSjc156560 break; 2686711890bcSjc156560 case OBJ_TYPE_TASK: 2687711890bcSjc156560 task_attr = attr_buf; 2688711890bcSjc156560 task_attr->task_id = *(ids + i); 2689711890bcSjc156560 break; 2690711890bcSjc156560 default: 2691711890bcSjc156560 free(ids); 2692711890bcSjc156560 return (ERR_DEVICE_INVALID); 2693711890bcSjc156560 } 2694711890bcSjc156560 } 2695711890bcSjc156560 2696711890bcSjc156560 2697711890bcSjc156560 free(ids); 2698711890bcSjc156560 return (ret); 2699711890bcSjc156560 } 2700711890bcSjc156560 2701711890bcSjc156560 static int 2702711890bcSjc156560 obj_array_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 2703711890bcSjc156560 { 2704711890bcSjc156560 array_attr_t *attr; 2705711890bcSjc156560 controller_attr_t *ctl_attrp; 2706711890bcSjc156560 raid_lib_t *raid_lib; 2707711890bcSjc156560 int ret = SUCCESS, fd; 2708711890bcSjc156560 raid_obj_id_t controller_obj_id; 2709711890bcSjc156560 2710711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_ARRAY) 2711711890bcSjc156560 return (ERR_DEVICE_TYPE); 2712711890bcSjc156560 2713711890bcSjc156560 if (raid_obj_get_status(raid_tab, obj_id) & OBJ_STATUS_OPENED) 2714711890bcSjc156560 return (SUCCESS); 2715711890bcSjc156560 2716711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2717711890bcSjc156560 if (attr == NULL) 2718711890bcSjc156560 return (ERR_DEVICE_INVALID); 2719711890bcSjc156560 2720711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 2721711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 2722711890bcSjc156560 return (ERR_DEVICE_INVALID); 2723711890bcSjc156560 2724711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 2725711890bcSjc156560 if (ctl_attrp == NULL) { 2726711890bcSjc156560 return (ERR_DEVICE_INVALID); 2727711890bcSjc156560 } 2728711890bcSjc156560 2729711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 2730711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 2731711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 2732711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2733711890bcSjc156560 2734711890bcSjc156560 ret = raid_lib->get_attr(ctl_attrp->controller_id, 2735711890bcSjc156560 attr->array_id, 0, OBJ_TYPE_ARRAY, attr); 2736711890bcSjc156560 2737711890bcSjc156560 if (ret < SUCCESS) 2738711890bcSjc156560 return (ret); 2739711890bcSjc156560 2740711890bcSjc156560 (void) raid_obj_set_status(raid_tab, obj_id, OBJ_STATUS_OPENED); 2741711890bcSjc156560 2742711890bcSjc156560 return (ret); 2743711890bcSjc156560 } 2744711890bcSjc156560 2745711890bcSjc156560 static int 2746711890bcSjc156560 obj_array_set_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2747711890bcSjc156560 uint32_t sub_cmd, uint32_t *value, char **plugin_err_str) 2748711890bcSjc156560 { 2749711890bcSjc156560 array_attr_t *attr; 2750711890bcSjc156560 controller_attr_t *ctl_attrp; 2751711890bcSjc156560 raid_lib_t *raid_lib; 2752711890bcSjc156560 int ret = SUCCESS, fd; 2753711890bcSjc156560 raid_obj_id_t controller_obj_id; 2754711890bcSjc156560 2755711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_ARRAY) 2756711890bcSjc156560 return (ERR_DEVICE_TYPE); 2757711890bcSjc156560 2758711890bcSjc156560 switch (sub_cmd) { 2759711890bcSjc156560 case SET_CACHE_WR_PLY: 2760711890bcSjc156560 if (*value != CACHE_WR_OFF && 2761711890bcSjc156560 *value != CACHE_WR_ON) 2762711890bcSjc156560 return (ERR_OP_ILLEGAL); 2763711890bcSjc156560 break; 2764711890bcSjc156560 case SET_CACHE_RD_PLY: 2765711890bcSjc156560 if (*value != CACHE_RD_OFF && 2766711890bcSjc156560 *value != CACHE_RD_ON) 2767711890bcSjc156560 return (ERR_OP_ILLEGAL); 2768711890bcSjc156560 break; 2769b449fa8aSyw161884 case SET_ACTIVATION_PLY: 2770b449fa8aSyw161884 if (*value != ARRAY_ACT_ACTIVATE) 2771b449fa8aSyw161884 return (ERR_OP_ILLEGAL); 2772b449fa8aSyw161884 break; 2773711890bcSjc156560 default: 2774711890bcSjc156560 return (ERR_OP_ILLEGAL); 2775711890bcSjc156560 } 2776711890bcSjc156560 2777711890bcSjc156560 (void) obj_get_attr(raid_tab, obj_id, (void **)(&attr)); 2778711890bcSjc156560 2779711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 2780711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 2781711890bcSjc156560 return (ERR_DEVICE_INVALID); 2782711890bcSjc156560 2783711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 2784711890bcSjc156560 if (ctl_attrp == NULL) { 2785711890bcSjc156560 return (ERR_DEVICE_INVALID); 2786711890bcSjc156560 } 2787711890bcSjc156560 2788711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 2789711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 2790711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 2791711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2792711890bcSjc156560 2793711890bcSjc156560 if (raid_lib->set_attr == NULL) 2794711890bcSjc156560 return (ERR_OP_NO_IMPL); 2795711890bcSjc156560 2796711890bcSjc156560 ret = raid_lib->set_attr(ctl_attrp->controller_id, 2797711890bcSjc156560 attr->array_id, sub_cmd, value, plugin_err_str); 2798711890bcSjc156560 2799711890bcSjc156560 return (ret); 2800711890bcSjc156560 } 2801711890bcSjc156560 2802711890bcSjc156560 static int 2803711890bcSjc156560 obj_disk_compnum(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2804711890bcSjc156560 raid_obj_type_id_t comp_type) 2805711890bcSjc156560 { 2806711890bcSjc156560 disk_attr_t *attr; 2807711890bcSjc156560 controller_attr_t *ctl_attrp; 2808711890bcSjc156560 raid_obj_id_t controller_obj_id; 2809711890bcSjc156560 raid_lib_t *raid_lib; 2810711890bcSjc156560 int ret = SUCCESS, fd; 2811711890bcSjc156560 2812711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_DISK) 2813711890bcSjc156560 return (ERR_DEVICE_TYPE); 2814711890bcSjc156560 2815711890bcSjc156560 if (comp_type != OBJ_TYPE_DISK_SEG && 2816711890bcSjc156560 comp_type != OBJ_TYPE_HSP && 2817b449fa8aSyw161884 comp_type != OBJ_TYPE_TASK && 2818b449fa8aSyw161884 comp_type != OBJ_TYPE_PROP) 2819711890bcSjc156560 return (0); 2820711890bcSjc156560 ret = obj_get_attr(raid_tab, obj_id, (void **)(&attr)); 2821711890bcSjc156560 if ((ret != SUCCESS) || (attr == NULL)) { 2822711890bcSjc156560 return (ERR_DEVICE_INVALID); 2823711890bcSjc156560 } 2824711890bcSjc156560 if (attr->state == DISK_STATE_FAILED) { 2825711890bcSjc156560 return (SUCCESS); 2826711890bcSjc156560 } 2827711890bcSjc156560 2828711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 2829711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 2830711890bcSjc156560 return (ERR_DEVICE_INVALID); 2831711890bcSjc156560 2832711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 2833711890bcSjc156560 if (ctl_attrp == NULL) { 2834711890bcSjc156560 return (ERR_DEVICE_INVALID); 2835711890bcSjc156560 } 2836711890bcSjc156560 2837711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 2838711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 2839711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 2840711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2841711890bcSjc156560 2842711890bcSjc156560 ret = raid_lib->compnum(ctl_attrp->controller_id, 2843711890bcSjc156560 attr->disk_id, OBJ_TYPE_DISK, comp_type); 2844711890bcSjc156560 2845711890bcSjc156560 return (ret); 2846711890bcSjc156560 } 2847711890bcSjc156560 2848711890bcSjc156560 static int 2849711890bcSjc156560 obj_disk_complist(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 2850711890bcSjc156560 int comp_num, raid_obj_id_t *comp_list, raid_obj_type_id_t comp_type) 2851711890bcSjc156560 { 2852711890bcSjc156560 disk_attr_t *attr; 2853711890bcSjc156560 controller_attr_t *ctl_attrp; 2854711890bcSjc156560 raid_obj_id_t controller_obj_id; 2855711890bcSjc156560 raid_lib_t *raid_lib; 2856711890bcSjc156560 int ret, i, fd; 2857711890bcSjc156560 uint32_t *ids; 2858711890bcSjc156560 2859711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_DISK) 2860711890bcSjc156560 return (ERR_DEVICE_TYPE); 2861711890bcSjc156560 2862711890bcSjc156560 if (comp_type != OBJ_TYPE_DISK_SEG && 2863711890bcSjc156560 comp_type != OBJ_TYPE_HSP && 2864b449fa8aSyw161884 comp_type != OBJ_TYPE_TASK && 2865b449fa8aSyw161884 comp_type != OBJ_TYPE_PROP) 2866711890bcSjc156560 return (0); 2867711890bcSjc156560 2868711890bcSjc156560 if (comp_num <= 0 || comp_list == NULL) 2869711890bcSjc156560 return (ERR_OP_ILLEGAL); 2870711890bcSjc156560 2871711890bcSjc156560 for (i = 0; i < comp_num; ++i) 2872711890bcSjc156560 if (raid_obj_get_type(raid_tab, *(comp_list + i)) != 2873711890bcSjc156560 comp_type) 2874711890bcSjc156560 return (ERR_DEVICE_TYPE); 2875711890bcSjc156560 ret = obj_get_attr(raid_tab, obj_id, (void **)(&attr)); 2876711890bcSjc156560 if ((ret != SUCCESS) || (attr == NULL)) { 2877711890bcSjc156560 return (ERR_DEVICE_INVALID); 2878711890bcSjc156560 } 2879711890bcSjc156560 if (attr->state == DISK_STATE_FAILED) { 2880711890bcSjc156560 return (SUCCESS); 2881711890bcSjc156560 } 2882711890bcSjc156560 2883711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 2884711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 2885711890bcSjc156560 return (ERR_DEVICE_INVALID); 2886711890bcSjc156560 2887711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 2888711890bcSjc156560 if (ctl_attrp == NULL) { 2889711890bcSjc156560 return (ERR_DEVICE_INVALID); 2890711890bcSjc156560 } 2891711890bcSjc156560 2892711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 2893711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 2894711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 2895711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2896711890bcSjc156560 2897711890bcSjc156560 ids = malloc(comp_num * sizeof (uint32_t)); 2898711890bcSjc156560 if (ids == NULL) 2899711890bcSjc156560 return (ERR_NOMEM); 2900711890bcSjc156560 2901711890bcSjc156560 ret = raid_lib->complist(ctl_attrp->controller_id, 2902711890bcSjc156560 attr->disk_id, OBJ_TYPE_DISK, comp_type, comp_num, ids); 2903711890bcSjc156560 2904711890bcSjc156560 if (ret < SUCCESS) { 2905711890bcSjc156560 free(ids); 2906711890bcSjc156560 return (ret); 2907711890bcSjc156560 } 2908711890bcSjc156560 2909711890bcSjc156560 for (i = 0; i < comp_num; ++ i) { 2910711890bcSjc156560 diskseg_attr_t *diskseg_attr; 2911711890bcSjc156560 hsp_attr_t *hsp_attr; 2912711890bcSjc156560 task_attr_t *task_attr; 2913b449fa8aSyw161884 property_attr_t *prop_attr; 2914711890bcSjc156560 void *attr_buf; 2915711890bcSjc156560 2916711890bcSjc156560 attr_buf = raid_obj_get_data_ptr(raid_tab, *(comp_list + i)); 2917711890bcSjc156560 if (attr_buf == NULL) { 2918711890bcSjc156560 free(ids); 2919711890bcSjc156560 return (ERR_DEVICE_INVALID); 2920711890bcSjc156560 } 2921711890bcSjc156560 2922711890bcSjc156560 switch (comp_type) { 2923711890bcSjc156560 case OBJ_TYPE_DISK_SEG: 2924711890bcSjc156560 diskseg_attr = attr_buf; 2925711890bcSjc156560 diskseg_attr->seq_no = *(ids + i); 2926711890bcSjc156560 break; 2927711890bcSjc156560 case OBJ_TYPE_HSP: 2928711890bcSjc156560 hsp_attr = attr_buf; 2929711890bcSjc156560 hsp_attr->associated_id = *(ids + i); 2930711890bcSjc156560 break; 2931711890bcSjc156560 case OBJ_TYPE_TASK: 2932711890bcSjc156560 task_attr = attr_buf; 2933711890bcSjc156560 task_attr->task_id = *(ids + i); 2934711890bcSjc156560 break; 2935b449fa8aSyw161884 case OBJ_TYPE_PROP: 2936b449fa8aSyw161884 prop_attr = attr_buf; 2937b449fa8aSyw161884 prop_attr->prop_id = *(ids + i); 2938b449fa8aSyw161884 break; 2939711890bcSjc156560 default: 2940711890bcSjc156560 free(ids); 2941711890bcSjc156560 return (ERR_DEVICE_INVALID); 2942711890bcSjc156560 } 2943711890bcSjc156560 } 2944711890bcSjc156560 2945711890bcSjc156560 2946711890bcSjc156560 free(ids); 2947711890bcSjc156560 return (ret); 2948711890bcSjc156560 } 2949711890bcSjc156560 2950711890bcSjc156560 static int 2951711890bcSjc156560 obj_disk_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 2952711890bcSjc156560 { 2953711890bcSjc156560 disk_attr_t *attr; 2954711890bcSjc156560 controller_attr_t *ctl_attrp; 2955711890bcSjc156560 raid_lib_t *raid_lib; 2956711890bcSjc156560 int ret = SUCCESS, fd; 2957711890bcSjc156560 raid_obj_id_t controller_obj_id; 2958711890bcSjc156560 2959711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_DISK) 2960711890bcSjc156560 return (ERR_DEVICE_TYPE); 2961711890bcSjc156560 2962711890bcSjc156560 if (raid_obj_get_status(raid_tab, obj_id) & OBJ_STATUS_OPENED) 2963711890bcSjc156560 return (SUCCESS); 2964711890bcSjc156560 2965711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 2966711890bcSjc156560 if (attr == NULL) 2967711890bcSjc156560 return (ERR_DEVICE_INVALID); 2968711890bcSjc156560 2969711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 2970711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 2971711890bcSjc156560 return (ERR_DEVICE_INVALID); 2972711890bcSjc156560 2973711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 2974711890bcSjc156560 if (ctl_attrp == NULL) { 2975711890bcSjc156560 return (ERR_DEVICE_INVALID); 2976711890bcSjc156560 } 2977711890bcSjc156560 2978711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 2979711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 2980711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 2981711890bcSjc156560 return (ERR_DRIVER_CLOSED); 2982711890bcSjc156560 2983711890bcSjc156560 ret = raid_lib->get_attr(ctl_attrp->controller_id, 2984711890bcSjc156560 attr->disk_id, 0, OBJ_TYPE_DISK, attr); 2985711890bcSjc156560 2986711890bcSjc156560 if (ret < SUCCESS) 2987711890bcSjc156560 return (ret); 2988711890bcSjc156560 2989711890bcSjc156560 (void) raid_obj_set_status(raid_tab, obj_id, OBJ_STATUS_OPENED); 2990711890bcSjc156560 2991711890bcSjc156560 return (ret); 2992711890bcSjc156560 } 2993711890bcSjc156560 2994711890bcSjc156560 static int 2995711890bcSjc156560 obj_hsp_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 2996711890bcSjc156560 { 2997711890bcSjc156560 hsp_attr_t *attr; 2998711890bcSjc156560 2999711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_HSP) 3000711890bcSjc156560 return (ERR_DEVICE_TYPE); 3001711890bcSjc156560 3002711890bcSjc156560 if (raid_obj_get_status(raid_tab, obj_id) & OBJ_STATUS_OPENED) 3003711890bcSjc156560 return (SUCCESS); 3004711890bcSjc156560 3005711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 3006711890bcSjc156560 if (attr == NULL) 3007711890bcSjc156560 return (ERR_DEVICE_INVALID); 3008711890bcSjc156560 3009711890bcSjc156560 if (attr->associated_id == (uint32_t)OBJ_ATTR_NONE) 3010711890bcSjc156560 attr->type = HSP_TYPE_GLOBAL; 3011711890bcSjc156560 else 3012711890bcSjc156560 attr->type = HSP_TYPE_LOCAL; 3013711890bcSjc156560 3014711890bcSjc156560 return (SUCCESS); 3015711890bcSjc156560 } 3016711890bcSjc156560 3017711890bcSjc156560 static int 3018711890bcSjc156560 obj_arraypart_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 3019711890bcSjc156560 { 3020711890bcSjc156560 arraypart_attr_t *attr; 3021711890bcSjc156560 array_attr_t *array_attr; 3022711890bcSjc156560 controller_attr_t *ctl_attrp; 3023711890bcSjc156560 raid_lib_t *raid_lib; 3024711890bcSjc156560 int ret = SUCCESS, fd; 3025711890bcSjc156560 raid_obj_id_t controller_obj_id, array_obj_id; 3026711890bcSjc156560 3027711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_ARRAY_PART) 3028711890bcSjc156560 return (ERR_DEVICE_TYPE); 3029711890bcSjc156560 3030711890bcSjc156560 if (raid_obj_get_status(raid_tab, obj_id) & OBJ_STATUS_OPENED) 3031711890bcSjc156560 return (SUCCESS); 3032711890bcSjc156560 3033711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 3034711890bcSjc156560 if (attr == NULL) 3035711890bcSjc156560 return (ERR_DEVICE_INVALID); 3036711890bcSjc156560 3037711890bcSjc156560 array_obj_id = raid_obj_get_container(raid_tab, obj_id); 3038711890bcSjc156560 if (array_obj_id < OBJ_NONE) 3039711890bcSjc156560 return (ERR_DEVICE_INVALID); 3040711890bcSjc156560 3041711890bcSjc156560 array_attr = raid_obj_get_data_ptr(raid_tab, array_obj_id); 3042711890bcSjc156560 if (array_attr == NULL) 3043711890bcSjc156560 return (ERR_DEVICE_INVALID); 3044711890bcSjc156560 3045711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 3046711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 3047711890bcSjc156560 return (ERR_DEVICE_INVALID); 3048711890bcSjc156560 3049711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 3050711890bcSjc156560 if (ctl_attrp == NULL) { 3051711890bcSjc156560 return (ERR_DEVICE_INVALID); 3052711890bcSjc156560 } 3053711890bcSjc156560 3054711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3055711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3056711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 3057711890bcSjc156560 return (ERR_DRIVER_CLOSED); 3058711890bcSjc156560 3059711890bcSjc156560 ret = raid_lib->get_attr(ctl_attrp->controller_id, 3060711890bcSjc156560 array_attr->array_id, attr->disk_id, 3061711890bcSjc156560 OBJ_TYPE_ARRAY_PART, attr); 3062711890bcSjc156560 3063711890bcSjc156560 if (ret < SUCCESS) 3064711890bcSjc156560 return (ret); 3065711890bcSjc156560 3066711890bcSjc156560 (void) raid_obj_set_status(raid_tab, obj_id, OBJ_STATUS_OPENED); 3067711890bcSjc156560 3068711890bcSjc156560 return (ret); 3069711890bcSjc156560 } 3070711890bcSjc156560 3071711890bcSjc156560 static int 3072711890bcSjc156560 obj_diskseg_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 3073711890bcSjc156560 { 3074711890bcSjc156560 diskseg_attr_t *attr; 3075711890bcSjc156560 disk_attr_t *disk_attr; 3076711890bcSjc156560 controller_attr_t *ctl_attrp; 3077711890bcSjc156560 raid_lib_t *raid_lib; 3078711890bcSjc156560 int ret = SUCCESS, fd; 3079711890bcSjc156560 raid_obj_id_t controller_obj_id, disk_obj_id; 3080711890bcSjc156560 3081711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_DISK_SEG) 3082711890bcSjc156560 return (ERR_DEVICE_TYPE); 3083711890bcSjc156560 3084711890bcSjc156560 if (raid_obj_get_status(raid_tab, obj_id) & OBJ_STATUS_OPENED) 3085711890bcSjc156560 return (SUCCESS); 3086711890bcSjc156560 3087711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 3088711890bcSjc156560 if (attr == NULL) 3089711890bcSjc156560 return (ERR_DEVICE_INVALID); 3090711890bcSjc156560 3091711890bcSjc156560 disk_obj_id = raid_obj_get_container(raid_tab, obj_id); 3092711890bcSjc156560 if (disk_obj_id < OBJ_NONE) 3093711890bcSjc156560 return (ERR_DEVICE_INVALID); 3094711890bcSjc156560 3095711890bcSjc156560 disk_attr = raid_obj_get_data_ptr(raid_tab, disk_obj_id); 3096711890bcSjc156560 if (disk_attr == NULL) 3097711890bcSjc156560 return (ERR_DEVICE_INVALID); 3098711890bcSjc156560 3099711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 3100711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 3101711890bcSjc156560 return (ERR_DEVICE_INVALID); 3102711890bcSjc156560 3103711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 3104711890bcSjc156560 if (ctl_attrp == NULL) { 3105711890bcSjc156560 return (ERR_DEVICE_INVALID); 3106711890bcSjc156560 } 3107711890bcSjc156560 3108711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3109711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3110711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 3111711890bcSjc156560 return (ERR_DRIVER_CLOSED); 3112711890bcSjc156560 3113711890bcSjc156560 ret = raid_lib->get_attr(ctl_attrp->controller_id, 3114711890bcSjc156560 disk_attr->disk_id, attr->seq_no, OBJ_TYPE_DISK_SEG, attr); 3115711890bcSjc156560 3116711890bcSjc156560 if (ret < SUCCESS) 3117711890bcSjc156560 return (ret); 3118711890bcSjc156560 3119711890bcSjc156560 (void) raid_obj_set_status(raid_tab, obj_id, OBJ_STATUS_OPENED); 3120711890bcSjc156560 3121711890bcSjc156560 return (ret); 3122711890bcSjc156560 } 3123711890bcSjc156560 3124711890bcSjc156560 static int 3125711890bcSjc156560 obj_task_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 3126711890bcSjc156560 { 3127711890bcSjc156560 task_attr_t *attr; 3128711890bcSjc156560 controller_attr_t *ctl_attrp; 3129711890bcSjc156560 raid_lib_t *raid_lib; 3130711890bcSjc156560 int ret = SUCCESS, fd; 3131711890bcSjc156560 raid_obj_id_t controller_obj_id; 3132711890bcSjc156560 3133711890bcSjc156560 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_TASK) 3134711890bcSjc156560 return (ERR_DEVICE_TYPE); 3135711890bcSjc156560 3136711890bcSjc156560 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 3137711890bcSjc156560 if (attr == NULL) 3138711890bcSjc156560 return (ERR_DEVICE_INVALID); 3139711890bcSjc156560 3140711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, obj_id); 3141711890bcSjc156560 if (controller_obj_id < OBJ_NONE) 3142711890bcSjc156560 return (ERR_DEVICE_INVALID); 3143711890bcSjc156560 3144711890bcSjc156560 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 3145711890bcSjc156560 if (ctl_attrp == NULL) { 3146711890bcSjc156560 return (ERR_DEVICE_INVALID); 3147711890bcSjc156560 } 3148711890bcSjc156560 3149711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3150711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3151711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 3152711890bcSjc156560 return (ERR_DRIVER_CLOSED); 3153711890bcSjc156560 3154711890bcSjc156560 ret = raid_lib->get_attr(ctl_attrp->controller_id, 3155711890bcSjc156560 attr->task_id, OBJ_ATTR_NONE, OBJ_TYPE_TASK, attr); 3156711890bcSjc156560 3157711890bcSjc156560 return (ret); 3158711890bcSjc156560 } 3159711890bcSjc156560 3160711890bcSjc156560 static int 3161b449fa8aSyw161884 obj_prop_get_attr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 3162b449fa8aSyw161884 { 3163b449fa8aSyw161884 property_attr_t *attr, *attr_new; 3164b449fa8aSyw161884 disk_attr_t *disk_attr; 3165b449fa8aSyw161884 controller_attr_t *ctl_attrp; 3166b449fa8aSyw161884 raid_lib_t *raid_lib; 3167b449fa8aSyw161884 int ret = SUCCESS, fd; 3168b449fa8aSyw161884 raid_obj_id_t controller_obj_id, disk_obj_id; 3169b449fa8aSyw161884 3170b449fa8aSyw161884 if (raid_obj_get_type(raid_tab, obj_id) != OBJ_TYPE_PROP) 3171b449fa8aSyw161884 return (ERR_DEVICE_TYPE); 3172b449fa8aSyw161884 3173b449fa8aSyw161884 if (raid_obj_get_status(raid_tab, obj_id) & OBJ_STATUS_OPENED) 3174b449fa8aSyw161884 return (SUCCESS); 3175b449fa8aSyw161884 3176b449fa8aSyw161884 attr = raid_obj_get_data_ptr(raid_tab, obj_id); 3177b449fa8aSyw161884 if (attr == NULL) 3178b449fa8aSyw161884 return (ERR_DEVICE_INVALID); 3179b449fa8aSyw161884 3180b449fa8aSyw161884 disk_obj_id = raid_obj_get_container(raid_tab, obj_id); 3181b449fa8aSyw161884 if (disk_obj_id < OBJ_NONE) 3182b449fa8aSyw161884 return (ERR_DEVICE_INVALID); 3183b449fa8aSyw161884 3184b449fa8aSyw161884 disk_attr = raid_obj_get_data_ptr(raid_tab, disk_obj_id); 3185b449fa8aSyw161884 if (disk_attr == NULL) 3186b449fa8aSyw161884 return (ERR_DEVICE_INVALID); 3187b449fa8aSyw161884 3188b449fa8aSyw161884 controller_obj_id = obj_get_controller(raid_tab, obj_id); 3189b449fa8aSyw161884 if (controller_obj_id < OBJ_NONE) 3190b449fa8aSyw161884 return (ERR_DEVICE_INVALID); 3191b449fa8aSyw161884 3192b449fa8aSyw161884 ctl_attrp = raid_obj_get_data_ptr(raid_tab, controller_obj_id); 3193b449fa8aSyw161884 if (ctl_attrp == NULL) { 3194b449fa8aSyw161884 return (ERR_DEVICE_INVALID); 3195b449fa8aSyw161884 } 3196b449fa8aSyw161884 3197b449fa8aSyw161884 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3198b449fa8aSyw161884 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3199b449fa8aSyw161884 if ((raid_lib == NULL) || (fd == 0)) 3200b449fa8aSyw161884 return (ERR_DRIVER_CLOSED); 3201b449fa8aSyw161884 3202b449fa8aSyw161884 /* Get the property size at first */ 3203b449fa8aSyw161884 attr->prop_size = 0; 3204b449fa8aSyw161884 ret = raid_lib->get_attr(ctl_attrp->controller_id, 3205b449fa8aSyw161884 disk_attr->disk_id, OBJ_ATTR_NONE, OBJ_TYPE_PROP, attr); 3206b449fa8aSyw161884 3207b449fa8aSyw161884 if (ret < SUCCESS) 3208b449fa8aSyw161884 return (ret); 3209b449fa8aSyw161884 3210b449fa8aSyw161884 /* Allocate memory for property and fill the buffer */ 3211b449fa8aSyw161884 attr_new = realloc(attr, sizeof (property_attr_t) + attr->prop_size); 3212b449fa8aSyw161884 if (attr_new == NULL) 3213b449fa8aSyw161884 return (ERR_NOMEM); 3214b449fa8aSyw161884 3215b449fa8aSyw161884 (void) raid_obj_set_data_ptr(raid_tab, obj_id, attr_new); 3216b449fa8aSyw161884 3217b449fa8aSyw161884 ret = raid_lib->get_attr(ctl_attrp->controller_id, 3218b449fa8aSyw161884 disk_attr->disk_id, OBJ_ATTR_NONE, OBJ_TYPE_PROP, attr_new); 3219b449fa8aSyw161884 3220b449fa8aSyw161884 if (ret < SUCCESS) 3221b449fa8aSyw161884 return (ret); 3222b449fa8aSyw161884 3223b449fa8aSyw161884 (void) raid_obj_set_status(raid_tab, obj_id, OBJ_STATUS_OPENED); 3224b449fa8aSyw161884 3225b449fa8aSyw161884 return (ret); 3226b449fa8aSyw161884 } 3227b449fa8aSyw161884 3228b449fa8aSyw161884 static int 3229711890bcSjc156560 obj_array_create(raid_obj_tab_t *raid_tab, raid_obj_id_t array_obj_id, 3230711890bcSjc156560 int num_of_comp, raid_obj_id_t *disk_list, char **plugin_err_str) 3231711890bcSjc156560 { 3232711890bcSjc156560 controller_attr_t *controller_attr; 3233711890bcSjc156560 array_attr_t *array_attr, array_attr2; 3234711890bcSjc156560 disk_attr_t *disk_attr; 3235711890bcSjc156560 arraypart_attr_t *arraypart_attrs; 3236711890bcSjc156560 raid_obj_id_t obj_id, controller_obj_id = OBJ_NONE; 3237711890bcSjc156560 raid_lib_t *raid_lib; 3238711890bcSjc156560 int i, j, ret, fd; 3239711890bcSjc156560 int disk_cnt = 0, disk_set_num = 0, set_num = 0, layer_cnt = 0; 3240711890bcSjc156560 uint64_t min_disk_capacity = 0; 3241711890bcSjc156560 3242711890bcSjc156560 array_attr = raid_obj_get_data_ptr(raid_tab, array_obj_id); 3243711890bcSjc156560 if (array_attr == NULL) 3244711890bcSjc156560 return (ERR_DEVICE_INVALID); 3245711890bcSjc156560 3246711890bcSjc156560 /* Check the disk layout expression */ 3247711890bcSjc156560 if (disk_list[0] != OBJ_SEPARATOR_BEGIN || 3248711890bcSjc156560 disk_list[num_of_comp - 1] != OBJ_SEPARATOR_END) 3249711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3250711890bcSjc156560 for (i = 0; i < num_of_comp; ++i) { 3251711890bcSjc156560 if (disk_list[i] == OBJ_SEPARATOR_BEGIN) { 3252711890bcSjc156560 if (disk_cnt != 0) 3253711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3254711890bcSjc156560 ++layer_cnt; 3255711890bcSjc156560 continue; 3256711890bcSjc156560 } 3257711890bcSjc156560 if (disk_list[i] == OBJ_SEPARATOR_END) { 3258711890bcSjc156560 if (disk_set_num == 0) 3259711890bcSjc156560 disk_set_num = disk_cnt; 3260711890bcSjc156560 else if (disk_set_num != disk_cnt && disk_cnt != 0) 3261711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3262711890bcSjc156560 disk_cnt = 0; 3263711890bcSjc156560 ++set_num; 3264711890bcSjc156560 --layer_cnt; 3265711890bcSjc156560 continue; 3266711890bcSjc156560 } 3267711890bcSjc156560 switch (array_attr->raid_level) { 3268711890bcSjc156560 case RAID_LEVEL_0: 3269711890bcSjc156560 case RAID_LEVEL_1: 3270711890bcSjc156560 case RAID_LEVEL_1E: 3271711890bcSjc156560 case RAID_LEVEL_5: 3272711890bcSjc156560 if (layer_cnt != 1) 3273711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3274711890bcSjc156560 break; 3275711890bcSjc156560 case RAID_LEVEL_10: 3276711890bcSjc156560 case RAID_LEVEL_50: 3277711890bcSjc156560 if (layer_cnt != 2) 3278711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3279711890bcSjc156560 break; 3280711890bcSjc156560 default: 3281711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3282711890bcSjc156560 } 3283711890bcSjc156560 ++disk_cnt; 3284711890bcSjc156560 } 3285711890bcSjc156560 3286711890bcSjc156560 if (layer_cnt != 0) 3287711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3288711890bcSjc156560 3289711890bcSjc156560 switch (array_attr->raid_level) { 3290711890bcSjc156560 case RAID_LEVEL_0: 3291711890bcSjc156560 if (disk_set_num < 2 || set_num != 1) 3292711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3293711890bcSjc156560 break; 3294711890bcSjc156560 case RAID_LEVEL_1: 3295711890bcSjc156560 if (disk_set_num != 2 || set_num != 1) 3296711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3297711890bcSjc156560 break; 3298711890bcSjc156560 case RAID_LEVEL_1E: 3299711890bcSjc156560 case RAID_LEVEL_5: 3300711890bcSjc156560 if (disk_set_num < 3 || set_num != 1) 3301711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3302711890bcSjc156560 break; 3303711890bcSjc156560 case RAID_LEVEL_10: 3304711890bcSjc156560 if (disk_set_num != 2 || set_num < 2) 3305711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3306711890bcSjc156560 break; 3307711890bcSjc156560 case RAID_LEVEL_50: 3308711890bcSjc156560 if (disk_set_num < 3 || set_num < 2) 3309711890bcSjc156560 return (ERR_ARRAY_LAYOUT); 3310711890bcSjc156560 break; 3311711890bcSjc156560 default: 3312711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3313711890bcSjc156560 } 3314711890bcSjc156560 3315711890bcSjc156560 arraypart_attrs = calloc(num_of_comp, sizeof (arraypart_attr_t)); 3316711890bcSjc156560 if (arraypart_attrs == NULL) 3317711890bcSjc156560 return (ERR_NOMEM); 3318711890bcSjc156560 3319711890bcSjc156560 for (i = 0; i < num_of_comp; ++i) { 3320711890bcSjc156560 /* Keep seperators */ 3321711890bcSjc156560 if (*(disk_list + i) == OBJ_SEPARATOR_BEGIN) { 3322711890bcSjc156560 arraypart_attrs[i].disk_id = 3323711890bcSjc156560 (uint32_t)OBJ_SEPARATOR_BEGIN; 3324711890bcSjc156560 continue; 3325711890bcSjc156560 } 3326711890bcSjc156560 3327711890bcSjc156560 if (*(disk_list + i) == OBJ_SEPARATOR_END) { 3328711890bcSjc156560 arraypart_attrs[i].disk_id = 3329711890bcSjc156560 (uint32_t)OBJ_SEPARATOR_END; 3330711890bcSjc156560 continue; 3331711890bcSjc156560 } 3332711890bcSjc156560 3333711890bcSjc156560 disk_cnt++; 3334711890bcSjc156560 /* Check if it's a disk */ 3335711890bcSjc156560 if (raid_obj_get_type(raid_tab, *(disk_list + i)) != 3336711890bcSjc156560 OBJ_TYPE_DISK) 3337711890bcSjc156560 return (ERR_DEVICE_TYPE); 3338711890bcSjc156560 3339711890bcSjc156560 /* Check if it's duplicated with other disks */ 3340711890bcSjc156560 for (j = 0; j < i; ++j) 3341711890bcSjc156560 if (*(disk_list + j) == *(disk_list + i)) { 3342711890bcSjc156560 free(arraypart_attrs); 3343711890bcSjc156560 return (ERR_DEVICE_DUP); 3344711890bcSjc156560 } 3345711890bcSjc156560 3346711890bcSjc156560 /* Check disk status */ 3347711890bcSjc156560 ret = obj_get_attr(raid_tab, *(disk_list + i), 3348711890bcSjc156560 (void **)(&disk_attr)); 3349711890bcSjc156560 if (ret != SUCCESS) 3350711890bcSjc156560 return (ret); 3351711890bcSjc156560 3352711890bcSjc156560 if (disk_attr->state != DISK_STATE_GOOD) { 3353711890bcSjc156560 free(arraypart_attrs); 3354711890bcSjc156560 return (ERR_DISK_STATE); 3355711890bcSjc156560 } 3356711890bcSjc156560 3357711890bcSjc156560 /* All disks must belong to the same controller */ 3358711890bcSjc156560 obj_id = obj_get_controller(raid_tab, *(disk_list + i)); 3359711890bcSjc156560 if (obj_id <= OBJ_NONE) 3360711890bcSjc156560 return (obj_id); 3361711890bcSjc156560 if (controller_obj_id == OBJ_NONE) { 3362711890bcSjc156560 controller_obj_id = obj_id; 3363711890bcSjc156560 ret = obj_get_attr(raid_tab, controller_obj_id, 3364711890bcSjc156560 (void **)(&controller_attr)); 3365711890bcSjc156560 } else if (obj_id != controller_obj_id) { 3366711890bcSjc156560 free(arraypart_attrs); 3367711890bcSjc156560 return (ERR_DRIVER_ACROSS); 3368711890bcSjc156560 } 3369711890bcSjc156560 3370711890bcSjc156560 /* Check if the disk contains too many segments */ 3371711890bcSjc156560 obj_id = obj_get_comp(raid_tab, *(disk_list + i), 3372711890bcSjc156560 OBJ_TYPE_DISK_SEG); 3373711890bcSjc156560 j = 0; 3374711890bcSjc156560 while (obj_id > OBJ_NONE) { 3375711890bcSjc156560 ++j; 3376711890bcSjc156560 obj_id = obj_get_sibling(raid_tab, obj_id); 3377711890bcSjc156560 } 3378711890bcSjc156560 if (j > controller_attr->max_seg_per_disk) { 3379711890bcSjc156560 free(arraypart_attrs); 3380711890bcSjc156560 return (ERR_DISK_SEG_AMOUNT); 3381711890bcSjc156560 } 3382711890bcSjc156560 3383711890bcSjc156560 /* Check if controller is a hostraid controller */ 3384711890bcSjc156560 if (controller_attr->capability & RAID_CAP_DISK_TRANS) { 3385711890bcSjc156560 /* 3386711890bcSjc156560 * For hostraid, the first disk should 3387711890bcSjc156560 * be with of minimum capacity 3388711890bcSjc156560 */ 3389711890bcSjc156560 if (min_disk_capacity == 0) { 3390711890bcSjc156560 min_disk_capacity = disk_attr->capacity; 3391711890bcSjc156560 3392711890bcSjc156560 /* Can not specify capacity for hostraid */ 3393711890bcSjc156560 if (array_attr->capacity != 0) { 3394711890bcSjc156560 free(arraypart_attrs); 3395700682b8Syw161884 return (ERR_OP_ILLEGAL); 3396711890bcSjc156560 } 3397711890bcSjc156560 } else if (min_disk_capacity > disk_attr->capacity) { 3398711890bcSjc156560 free(arraypart_attrs); 3399711890bcSjc156560 return (ERR_DISK_SPACE); 3400711890bcSjc156560 } 3401711890bcSjc156560 3402711890bcSjc156560 /* Disk should not be used for hostraid */ 3403711890bcSjc156560 obj_id = obj_get_comp(raid_tab, *(disk_list + i), 3404711890bcSjc156560 OBJ_TYPE_DISK_SEG); 3405711890bcSjc156560 if (obj_id < OBJ_NONE) { 3406711890bcSjc156560 free(arraypart_attrs); 3407711890bcSjc156560 return (obj_id); 3408711890bcSjc156560 } else if (obj_id > OBJ_NONE) { 3409711890bcSjc156560 free(arraypart_attrs); 3410711890bcSjc156560 return (ERR_DISK_NOT_EMPTY); 3411711890bcSjc156560 } 3412711890bcSjc156560 } 3413711890bcSjc156560 3414711890bcSjc156560 arraypart_attrs[i].disk_id = disk_attr->disk_id; 3415711890bcSjc156560 arraypart_attrs[i].offset = OBJ_ATTR_NONE; 3416711890bcSjc156560 arraypart_attrs[i].size = OBJ_ATTR_NONE; 3417711890bcSjc156560 } 3418711890bcSjc156560 3419711890bcSjc156560 /* Check if array amount exceeds limit */ 3420711890bcSjc156560 if (controller_attr->max_array_num <= 3421711890bcSjc156560 obj_controller_compnum(raid_tab, controller_obj_id, 3422711890bcSjc156560 OBJ_TYPE_ARRAY)) 3423711890bcSjc156560 return (ERR_ARRAY_AMOUNT); 3424711890bcSjc156560 3425711890bcSjc156560 3426711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3427711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3428711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 3429711890bcSjc156560 return (ERR_DRIVER_CLOSED); 3430711890bcSjc156560 3431711890bcSjc156560 /* Check if the controller can support the array RAID level */ 3432711890bcSjc156560 switch (array_attr->raid_level) { 3433711890bcSjc156560 case RAID_LEVEL_0: 3434711890bcSjc156560 if (!(controller_attr->capability & RAID_CAP_RAID0)) { 3435711890bcSjc156560 free(arraypart_attrs); 3436711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3437711890bcSjc156560 } 3438711890bcSjc156560 break; 3439711890bcSjc156560 case RAID_LEVEL_1: 3440711890bcSjc156560 if (!(controller_attr->capability & RAID_CAP_RAID1)) { 3441711890bcSjc156560 free(arraypart_attrs); 3442711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3443711890bcSjc156560 } 3444711890bcSjc156560 break; 3445711890bcSjc156560 case RAID_LEVEL_1E: 3446711890bcSjc156560 if (!(controller_attr->capability & RAID_CAP_RAID1E)) { 3447711890bcSjc156560 free(arraypart_attrs); 3448711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3449711890bcSjc156560 } 3450711890bcSjc156560 break; 3451711890bcSjc156560 case RAID_LEVEL_5: 3452711890bcSjc156560 if (!(controller_attr->capability & RAID_CAP_RAID5)) { 3453711890bcSjc156560 free(arraypart_attrs); 3454711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3455711890bcSjc156560 } 3456711890bcSjc156560 break; 3457711890bcSjc156560 case RAID_LEVEL_10: 3458711890bcSjc156560 if (!(controller_attr->capability & RAID_CAP_RAID10)) { 3459711890bcSjc156560 free(arraypart_attrs); 3460711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3461711890bcSjc156560 } 3462711890bcSjc156560 break; 3463711890bcSjc156560 case RAID_LEVEL_50: 3464711890bcSjc156560 if (!(controller_attr->capability & RAID_CAP_RAID50)) { 3465711890bcSjc156560 free(arraypart_attrs); 3466711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3467711890bcSjc156560 } 3468711890bcSjc156560 break; 3469711890bcSjc156560 default: 3470711890bcSjc156560 free(arraypart_attrs); 3471711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3472711890bcSjc156560 } 3473711890bcSjc156560 3474711890bcSjc156560 /* Check if plug in can calculate the maximum size */ 3475711890bcSjc156560 (void) memcpy(&array_attr2, array_attr, sizeof (array_attr_t)); 3476711890bcSjc156560 array_attr2.capacity = OBJ_ATTR_NONE; 3477711890bcSjc156560 ret = raid_lib->array_create(controller_attr->controller_id, 3478711890bcSjc156560 &array_attr2, num_of_comp, arraypart_attrs, plugin_err_str); 3479711890bcSjc156560 3480711890bcSjc156560 /* If plugin/driver will not calculate space */ 3481711890bcSjc156560 if (ret == ERR_OP_NO_IMPL) { 3482711890bcSjc156560 /* Calculate the maximum capacity */ 3483711890bcSjc156560 array_attr2.capacity = raid_space_noalign(raid_tab, 3484711890bcSjc156560 array_attr2.raid_level, num_of_comp, disk_list, 3485711890bcSjc156560 arraypart_attrs); 3486711890bcSjc156560 3487711890bcSjc156560 /* 3488711890bcSjc156560 * If controller is capable to allocate space, 3489711890bcSjc156560 * set offset and size attributes to OBJ_ATTR_NONE 3490711890bcSjc156560 * and let the controller to determine these value 3491711890bcSjc156560 */ 3492711890bcSjc156560 if (controller_attr->capability & RAID_CAP_SMART_ALLOC) 3493711890bcSjc156560 for (i = 0; i < num_of_comp; ++i) { 3494711890bcSjc156560 arraypart_attrs[i].offset = 3495711890bcSjc156560 OBJ_ATTR_NONE; 3496711890bcSjc156560 arraypart_attrs[i].size = 3497711890bcSjc156560 OBJ_ATTR_NONE; 3498711890bcSjc156560 } 3499711890bcSjc156560 3500711890bcSjc156560 /* There's no enough space for specified capacity */ 3501711890bcSjc156560 if (array_attr->capacity > array_attr2.capacity) { 3502711890bcSjc156560 free(arraypart_attrs); 3503711890bcSjc156560 return (ERR_ARRAY_SIZE); 3504711890bcSjc156560 } 3505711890bcSjc156560 3506711890bcSjc156560 /* capacity == 0, allocate maximum space */ 3507711890bcSjc156560 if (array_attr->capacity == 0) 3508711890bcSjc156560 array_attr->capacity = array_attr2.capacity; 3509711890bcSjc156560 } else if (ret < SUCCESS) { 3510711890bcSjc156560 free(arraypart_attrs); 3511711890bcSjc156560 return (ret); 3512711890bcSjc156560 } else if (array_attr2.capacity < array_attr->capacity) { 3513711890bcSjc156560 /* Return the maximum size */ 3514711890bcSjc156560 array_attr->capacity = array_attr2.capacity; 3515711890bcSjc156560 free(arraypart_attrs); 3516711890bcSjc156560 return (ERR_ARRAY_SIZE); 3517711890bcSjc156560 } 3518711890bcSjc156560 3519711890bcSjc156560 if (array_attr->capacity < ARRAYPART_MIN_SIZE * disk_cnt) { 3520711890bcSjc156560 free(arraypart_attrs); 3521711890bcSjc156560 return (ERR_ARRAY_SIZE); 3522711890bcSjc156560 } 3523711890bcSjc156560 3524711890bcSjc156560 3525711890bcSjc156560 ret = raid_lib->array_create(controller_attr->controller_id, 3526711890bcSjc156560 array_attr, num_of_comp, arraypart_attrs, plugin_err_str); 3527711890bcSjc156560 free(arraypart_attrs); 3528711890bcSjc156560 3529711890bcSjc156560 if (ret != SUCCESS) 3530711890bcSjc156560 return (ret); 3531711890bcSjc156560 3532711890bcSjc156560 /* Add array object into device tree so that we can map the handle */ 3533711890bcSjc156560 (void) raid_obj_add_org(raid_tab, array_obj_id, controller_obj_id); 3534711890bcSjc156560 3535711890bcSjc156560 return (ret); 3536711890bcSjc156560 } 3537711890bcSjc156560 3538711890bcSjc156560 static int 3539711890bcSjc156560 obj_array_delete(raid_obj_tab_t *raid_tab, raid_obj_id_t array_obj_id, 3540711890bcSjc156560 char **plugin_err_str) 3541711890bcSjc156560 { 3542711890bcSjc156560 raid_obj_id_t controller_obj_id; 3543711890bcSjc156560 controller_attr_t *controller_attr; 3544711890bcSjc156560 array_attr_t *array_attr; 3545711890bcSjc156560 raid_lib_t *raid_lib; 354672e1c055Sjc156560 int ret, fd; 3547711890bcSjc156560 uint32_t *disk_ids = NULL; 3548711890bcSjc156560 3549711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, array_obj_id); 3550711890bcSjc156560 if (controller_obj_id <= OBJ_NONE) 3551711890bcSjc156560 return (controller_obj_id); 3552711890bcSjc156560 3553711890bcSjc156560 ret = obj_get_attr(raid_tab, controller_obj_id, 3554711890bcSjc156560 (void **)(&controller_attr)); 3555711890bcSjc156560 if (ret < SUCCESS) { 3556711890bcSjc156560 return (ret); 3557711890bcSjc156560 } 3558711890bcSjc156560 ret = obj_get_attr(raid_tab, array_obj_id, (void **)(&array_attr)); 3559711890bcSjc156560 if (ret < SUCCESS) 3560711890bcSjc156560 return (ret); 3561711890bcSjc156560 3562711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3563711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3564711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 3565711890bcSjc156560 return (ERR_DRIVER_CLOSED); 3566711890bcSjc156560 3567711890bcSjc156560 ret = raid_lib->array_delete(controller_attr->controller_id, 3568711890bcSjc156560 array_attr->array_id, plugin_err_str); 3569711890bcSjc156560 if (ret < SUCCESS) { 3570711890bcSjc156560 if (disk_ids) 3571711890bcSjc156560 free(disk_ids); 3572711890bcSjc156560 return (ret); 3573711890bcSjc156560 } 3574711890bcSjc156560 3575711890bcSjc156560 if (disk_ids) 3576711890bcSjc156560 free(disk_ids); 3577711890bcSjc156560 return (ret); 3578711890bcSjc156560 } 3579711890bcSjc156560 3580711890bcSjc156560 static int 35815c9d25d2SYu-Bo Ryan Wang obj_hsp_bind(raid_obj_tab_t *raid_tab, raid_obj_id_t *obj_ids, 3582711890bcSjc156560 char **plugin_err_str) 3583711890bcSjc156560 { 3584711890bcSjc156560 raid_obj_id_t obj_id, controller_obj_id = OBJ_NONE; 3585711890bcSjc156560 raid_obj_id_t array_obj_id, disk_obj_id; 3586711890bcSjc156560 hsp_relation_t *hsp_relation; 3587711890bcSjc156560 controller_attr_t *controller_attr; 3588711890bcSjc156560 array_attr_t *array_attr; 3589711890bcSjc156560 arraypart_attr_t *arraypart_attr; 3590711890bcSjc156560 disk_attr_t *disk_attr; 3591711890bcSjc156560 diskseg_attr_t *diskseg_attr; 3592711890bcSjc156560 hsp_attr_t *hsp_attr; 3593711890bcSjc156560 raid_lib_t *raid_lib; 35945c9d25d2SYu-Bo Ryan Wang int ret, fd; 3595711890bcSjc156560 35965c9d25d2SYu-Bo Ryan Wang hsp_relation = malloc(sizeof (hsp_relation_t)); 3597711890bcSjc156560 if (hsp_relation == NULL) 3598711890bcSjc156560 return (ERR_NOMEM); 3599711890bcSjc156560 36005c9d25d2SYu-Bo Ryan Wang array_obj_id = *(obj_ids); 36015c9d25d2SYu-Bo Ryan Wang disk_obj_id = *(obj_ids + 1); 3602711890bcSjc156560 3603711890bcSjc156560 if (raid_obj_get_type(raid_tab, disk_obj_id) != OBJ_TYPE_DISK || 3604711890bcSjc156560 (array_obj_id != OBJ_ATTR_NONE && 3605711890bcSjc156560 raid_obj_get_type(raid_tab, array_obj_id) != 3606711890bcSjc156560 OBJ_TYPE_ARRAY)) { 3607711890bcSjc156560 free(hsp_relation); 3608711890bcSjc156560 return (ERR_DEVICE_TYPE); 3609711890bcSjc156560 } 3610711890bcSjc156560 3611711890bcSjc156560 /* Get controller attributes */ 3612711890bcSjc156560 if (controller_obj_id == OBJ_NONE) 3613711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, 3614711890bcSjc156560 disk_obj_id); 3615711890bcSjc156560 else if (controller_obj_id != obj_get_controller(raid_tab, 3616711890bcSjc156560 disk_obj_id)) { 3617711890bcSjc156560 free(hsp_relation); 3618711890bcSjc156560 return (ERR_DRIVER_ACROSS); 3619711890bcSjc156560 } 3620711890bcSjc156560 3621711890bcSjc156560 ret = obj_get_attr(raid_tab, controller_obj_id, 3622711890bcSjc156560 (void **)(&controller_attr)); 3623711890bcSjc156560 3624711890bcSjc156560 /* Get disk attributes */ 3625711890bcSjc156560 ret = obj_get_attr(raid_tab, disk_obj_id, 3626711890bcSjc156560 (void **)(&disk_attr)); 3627711890bcSjc156560 if (disk_attr->state == DISK_STATE_FAILED) { 3628711890bcSjc156560 free(hsp_relation); 3629711890bcSjc156560 return (ERR_DISK_STATE); 3630711890bcSjc156560 } 3631711890bcSjc156560 3632711890bcSjc156560 /* If it's not a hsp disk, check if there's occupied space */ 3633711890bcSjc156560 if (obj_get_comp(raid_tab, disk_obj_id, OBJ_TYPE_HSP) == 3634711890bcSjc156560 OBJ_NONE) { 3635711890bcSjc156560 obj_id = obj_get_comp(raid_tab, disk_obj_id, 3636711890bcSjc156560 OBJ_TYPE_DISK_SEG); 3637711890bcSjc156560 while (obj_id != OBJ_NONE) { 3638711890bcSjc156560 ret = obj_get_attr(raid_tab, obj_id, 3639711890bcSjc156560 (void **)(&diskseg_attr)); 3640711890bcSjc156560 if (!(diskseg_attr->state & 3641711890bcSjc156560 DISKSEG_STATE_RESERVED)) { 3642711890bcSjc156560 free(hsp_relation); 3643711890bcSjc156560 return (ERR_DISK_NOT_EMPTY); 3644711890bcSjc156560 } 3645711890bcSjc156560 obj_id = obj_get_sibling(raid_tab, obj_id); 3646711890bcSjc156560 } 3647711890bcSjc156560 } 3648711890bcSjc156560 3649711890bcSjc156560 if (array_obj_id != OBJ_ATTR_NONE) { 3650711890bcSjc156560 /* If local hsp is supported */ 3651711890bcSjc156560 if (!(controller_attr->capability & RAID_CAP_L_HSP)) { 3652711890bcSjc156560 free(hsp_relation); 3653711890bcSjc156560 return (ERR_OP_ILLEGAL); 3654711890bcSjc156560 } 3655711890bcSjc156560 3656711890bcSjc156560 if (raid_obj_get_type(raid_tab, array_obj_id) != 3657711890bcSjc156560 OBJ_TYPE_ARRAY) { 3658711890bcSjc156560 free(hsp_relation); 3659711890bcSjc156560 return (ERR_DEVICE_TYPE); 3660711890bcSjc156560 } 3661711890bcSjc156560 3662711890bcSjc156560 /* Get array attributes */ 3663711890bcSjc156560 ret = obj_get_attr(raid_tab, array_obj_id, 3664711890bcSjc156560 (void **)(&array_attr)); 3665711890bcSjc156560 /* RAID 0 array can not use hsp */ 3666711890bcSjc156560 if (array_attr->raid_level == RAID_LEVEL_0) { 3667711890bcSjc156560 free(hsp_relation); 3668711890bcSjc156560 return (ERR_ARRAY_LEVEL); 3669711890bcSjc156560 } 3670711890bcSjc156560 3671711890bcSjc156560 /* If It's belong to another controller */ 3672711890bcSjc156560 if (controller_obj_id != obj_get_controller(raid_tab, 3673711890bcSjc156560 array_obj_id)) { 3674711890bcSjc156560 free(hsp_relation); 3675711890bcSjc156560 return (ERR_DRIVER_ACROSS); 3676711890bcSjc156560 } 3677711890bcSjc156560 3678711890bcSjc156560 /* Get an array part attributes */ 3679711890bcSjc156560 if ((array_attr->raid_level == RAID_LEVEL_10) || 3680711890bcSjc156560 (array_attr->raid_level == RAID_LEVEL_50)) 3681711890bcSjc156560 obj_id = obj_get_comp(raid_tab, array_obj_id, 3682711890bcSjc156560 OBJ_TYPE_ARRAY); 3683711890bcSjc156560 else 3684711890bcSjc156560 obj_id = array_obj_id; 3685711890bcSjc156560 obj_id = obj_get_comp(raid_tab, obj_id, 3686711890bcSjc156560 OBJ_TYPE_ARRAY_PART); 3687711890bcSjc156560 ret = obj_get_attr(raid_tab, obj_id, 3688711890bcSjc156560 (void **)(&arraypart_attr)); 3689711890bcSjc156560 3690711890bcSjc156560 /* Check if disk space is enough for array */ 3691711890bcSjc156560 if (arraypart_attr->size > disk_attr->capacity) { 3692711890bcSjc156560 free(hsp_relation); 3693711890bcSjc156560 return (ERR_DISK_SPACE); 3694711890bcSjc156560 } 3695711890bcSjc156560 if (controller_attr->capability & RAID_CAP_ARRAY_ALIGN) 3696711890bcSjc156560 if ((arraypart_attr->size + 3697711890bcSjc156560 arraypart_attr->offset) > 3698711890bcSjc156560 disk_attr->capacity) { 3699711890bcSjc156560 free(hsp_relation); 3700711890bcSjc156560 return (ERR_DISK_SPACE); 3701711890bcSjc156560 } 3702711890bcSjc156560 } else if (!(controller_attr->capability & RAID_CAP_G_HSP)) { 3703711890bcSjc156560 /* if global hsp is supported */ 3704711890bcSjc156560 free(hsp_relation); 3705711890bcSjc156560 return (ERR_OP_ILLEGAL); 3706711890bcSjc156560 } 3707711890bcSjc156560 3708711890bcSjc156560 /* 3709711890bcSjc156560 * If the array is already associated with the 3710711890bcSjc156560 * local hsp, or it's a global hsp, ignore it 3711711890bcSjc156560 */ 3712711890bcSjc156560 obj_id = obj_get_comp(raid_tab, disk_obj_id, OBJ_TYPE_HSP); 3713711890bcSjc156560 if (obj_id > OBJ_NONE) { 3714711890bcSjc156560 if (obj_get_attr(raid_tab, obj_id, 3715711890bcSjc156560 (void **)&hsp_attr) >= SUCCESS) { 3716711890bcSjc156560 if (((hsp_attr->type == HSP_TYPE_GLOBAL) && 3717711890bcSjc156560 (array_obj_id != OBJ_ATTR_NONE)) || 3718711890bcSjc156560 ((hsp_attr->type == HSP_TYPE_LOCAL) && 3719711890bcSjc156560 (array_obj_id == OBJ_ATTR_NONE))) { 3720711890bcSjc156560 free(hsp_relation); 3721711890bcSjc156560 return (ERR_OP_ILLEGAL); 3722711890bcSjc156560 } 3723711890bcSjc156560 } 3724711890bcSjc156560 } 3725711890bcSjc156560 3726711890bcSjc156560 if (array_obj_id != OBJ_ATTR_NONE) 37275c9d25d2SYu-Bo Ryan Wang hsp_relation->array_id = array_attr->array_id; 3728711890bcSjc156560 else 37295c9d25d2SYu-Bo Ryan Wang hsp_relation->array_id = (uint32_t)OBJ_ATTR_NONE; 37305c9d25d2SYu-Bo Ryan Wang hsp_relation->disk_id = disk_attr->disk_id; 3731711890bcSjc156560 3732711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3733711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3734711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 3735711890bcSjc156560 return (ERR_DRIVER_CLOSED); 3736711890bcSjc156560 3737711890bcSjc156560 if (raid_lib->hsp_bind == NULL) { 3738711890bcSjc156560 free(hsp_relation); 3739711890bcSjc156560 return (ERR_OP_NO_IMPL); 3740711890bcSjc156560 } 3741711890bcSjc156560 3742711890bcSjc156560 ret = raid_lib->hsp_bind(controller_attr->controller_id, 37435c9d25d2SYu-Bo Ryan Wang hsp_relation, plugin_err_str); 3744711890bcSjc156560 3745711890bcSjc156560 free(hsp_relation); 3746711890bcSjc156560 return (ret); 3747711890bcSjc156560 } 3748711890bcSjc156560 3749711890bcSjc156560 static int 37505c9d25d2SYu-Bo Ryan Wang obj_hsp_unbind(raid_obj_tab_t *raid_tab, raid_obj_id_t *obj_ids, 3751711890bcSjc156560 char **plugin_err_str) 3752711890bcSjc156560 { 3753711890bcSjc156560 raid_obj_id_t obj_id, controller_obj_id = OBJ_NONE; 3754711890bcSjc156560 raid_obj_id_t array_obj_id, disk_obj_id; 3755711890bcSjc156560 hsp_relation_t *hsp_relation; 3756711890bcSjc156560 controller_attr_t *controller_attr; 3757711890bcSjc156560 array_attr_t *array_attr; 3758711890bcSjc156560 disk_attr_t *disk_attr; 3759711890bcSjc156560 hsp_attr_t *hsp_attr; 3760711890bcSjc156560 raid_lib_t *raid_lib; 37615c9d25d2SYu-Bo Ryan Wang int ret, fd; 3762711890bcSjc156560 37635c9d25d2SYu-Bo Ryan Wang hsp_relation = malloc(sizeof (hsp_relation_t)); 3764711890bcSjc156560 if (hsp_relation == NULL) 3765711890bcSjc156560 return (ERR_NOMEM); 3766711890bcSjc156560 37675c9d25d2SYu-Bo Ryan Wang array_obj_id = *(obj_ids); 37685c9d25d2SYu-Bo Ryan Wang disk_obj_id = *(obj_ids + 1); 3769711890bcSjc156560 3770711890bcSjc156560 if (raid_obj_get_type(raid_tab, disk_obj_id) != OBJ_TYPE_DISK) { 3771711890bcSjc156560 free(hsp_relation); 3772711890bcSjc156560 return (ERR_DEVICE_TYPE); 3773711890bcSjc156560 } 3774711890bcSjc156560 3775711890bcSjc156560 /* Get controller attributes */ 3776711890bcSjc156560 if (controller_obj_id == OBJ_NONE) 3777711890bcSjc156560 controller_obj_id = obj_get_controller(raid_tab, 3778711890bcSjc156560 disk_obj_id); 3779711890bcSjc156560 else if (controller_obj_id != obj_get_controller(raid_tab, 3780711890bcSjc156560 disk_obj_id)) { 3781711890bcSjc156560 free(hsp_relation); 3782711890bcSjc156560 return (ERR_DRIVER_ACROSS); 3783711890bcSjc156560 } 3784711890bcSjc156560 3785711890bcSjc156560 ret = obj_get_attr(raid_tab, controller_obj_id, 3786711890bcSjc156560 (void **)(&controller_attr)); 3787711890bcSjc156560 3788711890bcSjc156560 /* Get disk attributes */ 3789711890bcSjc156560 ret = obj_get_attr(raid_tab, disk_obj_id, 3790711890bcSjc156560 (void **)(&disk_attr)); 3791711890bcSjc156560 if (disk_attr->state == DISK_STATE_FAILED) { 3792711890bcSjc156560 free(hsp_relation); 3793711890bcSjc156560 return (ERR_DISK_STATE); 3794711890bcSjc156560 } 3795711890bcSjc156560 3796711890bcSjc156560 /* If it's not a hsp disk */ 3797711890bcSjc156560 obj_id = obj_get_comp(raid_tab, disk_obj_id, OBJ_TYPE_HSP); 3798711890bcSjc156560 if (obj_id == OBJ_NONE) { 3799711890bcSjc156560 free(hsp_relation); 3800711890bcSjc156560 return (ERR_DISK_STATE); 3801711890bcSjc156560 } 3802711890bcSjc156560 ret = obj_get_attr(raid_tab, obj_id, (void **)(&hsp_attr)); 3803711890bcSjc156560 3804711890bcSjc156560 if (array_obj_id != OBJ_ATTR_NONE) { 3805711890bcSjc156560 if (raid_obj_get_type(raid_tab, array_obj_id) != 3806711890bcSjc156560 OBJ_TYPE_ARRAY) { 3807711890bcSjc156560 free(hsp_relation); 3808711890bcSjc156560 return (ERR_DEVICE_TYPE); 3809711890bcSjc156560 } 3810711890bcSjc156560 3811711890bcSjc156560 /* Get array attributes */ 3812711890bcSjc156560 ret = obj_get_attr(raid_tab, array_obj_id, 3813711890bcSjc156560 (void **)(&array_attr)); 3814711890bcSjc156560 3815711890bcSjc156560 /* If It's belong to another controller */ 3816711890bcSjc156560 if (controller_obj_id != obj_get_controller(raid_tab, 3817711890bcSjc156560 array_obj_id)) { 3818711890bcSjc156560 free(hsp_relation); 3819711890bcSjc156560 return (ERR_DRIVER_ACROSS); 3820711890bcSjc156560 } 3821711890bcSjc156560 3822711890bcSjc156560 /* If want to remove an array from a global hsp */ 3823711890bcSjc156560 if (hsp_attr->type == HSP_TYPE_GLOBAL) { 3824711890bcSjc156560 free(hsp_relation); 3825711890bcSjc156560 return (ERR_OP_ILLEGAL); 3826711890bcSjc156560 } 3827711890bcSjc156560 3828711890bcSjc156560 do { 3829711890bcSjc156560 (void) obj_get_attr(raid_tab, obj_id, 3830711890bcSjc156560 (void **)(&hsp_attr)); 3831711890bcSjc156560 3832711890bcSjc156560 if (hsp_attr->associated_id == 3833711890bcSjc156560 array_attr->array_id || 3834711890bcSjc156560 hsp_attr->type == HSP_TYPE_GLOBAL) 3835711890bcSjc156560 break; 3836711890bcSjc156560 3837711890bcSjc156560 obj_id = obj_get_sibling(raid_tab, obj_id); 3838711890bcSjc156560 } while (obj_id > OBJ_NONE); 3839711890bcSjc156560 } else if (hsp_attr->type != HSP_TYPE_GLOBAL) { 3840711890bcSjc156560 /* if global hsp is supported */ 3841711890bcSjc156560 free(hsp_relation); 3842711890bcSjc156560 return (ERR_OP_ILLEGAL); 3843711890bcSjc156560 } 3844711890bcSjc156560 3845711890bcSjc156560 /* 3846711890bcSjc156560 * If array is associated with a local hsp, or remove a 3847711890bcSjc156560 * global hsp disk 3848711890bcSjc156560 */ 3849711890bcSjc156560 if ((obj_id && (array_obj_id != OBJ_ATTR_NONE)) || 3850711890bcSjc156560 (array_obj_id == OBJ_ATTR_NONE)) { 3851711890bcSjc156560 if (array_obj_id != OBJ_ATTR_NONE) 38525c9d25d2SYu-Bo Ryan Wang hsp_relation->array_id = array_attr->array_id; 3853711890bcSjc156560 else 38545c9d25d2SYu-Bo Ryan Wang hsp_relation->array_id = 3855711890bcSjc156560 (uint32_t)OBJ_ATTR_NONE; 38565c9d25d2SYu-Bo Ryan Wang hsp_relation->disk_id = disk_attr->disk_id; 3857711890bcSjc156560 } else { 3858711890bcSjc156560 free(hsp_relation); 3859711890bcSjc156560 return (ERR_OP_ILLEGAL); 3860711890bcSjc156560 } 3861711890bcSjc156560 3862711890bcSjc156560 raid_lib = raid_obj_get_lib(raid_tab, controller_obj_id); 3863711890bcSjc156560 fd = raid_obj_get_fd(raid_tab, controller_obj_id); 3864711890bcSjc156560 if ((raid_lib == NULL) || (fd == 0)) 3865711890bcSjc156560 return (ERR_DRIVER_CLOSED); 3866711890bcSjc156560 3867711890bcSjc156560 if (raid_lib->hsp_unbind == NULL) { 3868711890bcSjc156560 free(hsp_relation); 3869711890bcSjc156560 return (ERR_OP_NO_IMPL); 3870711890bcSjc156560 } 3871711890bcSjc156560 3872711890bcSjc156560 ret = raid_lib->hsp_unbind(controller_attr->controller_id, 38735c9d25d2SYu-Bo Ryan Wang hsp_relation, plugin_err_str); 3874711890bcSjc156560 3875711890bcSjc156560 free(hsp_relation); 3876711890bcSjc156560 return (ret); 3877711890bcSjc156560 } 3878711890bcSjc156560 3879711890bcSjc156560 /* 3880711890bcSjc156560 * Object maintennance routines 3881711890bcSjc156560 */ 3882711890bcSjc156560 static int 3883711890bcSjc156560 raid_obj_create_system_obj(raid_obj_tab_t *raid_tab) 3884711890bcSjc156560 { 3885711890bcSjc156560 raid_obj_t *raid_obj; 3886711890bcSjc156560 int ret; 3887711890bcSjc156560 3888711890bcSjc156560 raid_obj = calloc(1, sizeof (raid_obj_t)); 3889711890bcSjc156560 if (raid_obj == NULL) 3890711890bcSjc156560 return (ERR_NOMEM); 3891711890bcSjc156560 3892711890bcSjc156560 raid_obj->obj_id = OBJ_SYSTEM; 3893711890bcSjc156560 raid_obj->obj_type_id = OBJ_TYPE_SYSTEM; 3894711890bcSjc156560 raid_obj->data = NULL; 3895711890bcSjc156560 3896711890bcSjc156560 ret = raid_obj_tab_insert(raid_tab, raid_obj->obj_id, raid_obj); 3897711890bcSjc156560 if (ret == ERR_DEVICE_DUP) { 3898711890bcSjc156560 free(raid_obj); 3899711890bcSjc156560 return (ERR_DEVICE_UNCLEAN); 3900711890bcSjc156560 } 3901711890bcSjc156560 3902711890bcSjc156560 return (SUCCESS); 3903711890bcSjc156560 } 3904711890bcSjc156560 3905711890bcSjc156560 static raid_obj_id_t 3906711890bcSjc156560 raid_obj_id_new(raid_obj_tab_t *raid_tab) 3907711890bcSjc156560 { 3908711890bcSjc156560 ++ raid_tab->obj_id_cnt; 3909711890bcSjc156560 if (raid_tab->obj_id_cnt <= 0) 3910711890bcSjc156560 return (ERR_DEVICE_OVERFLOW); 3911711890bcSjc156560 3912711890bcSjc156560 return (raid_tab->obj_id_cnt); 3913711890bcSjc156560 } 3914711890bcSjc156560 3915711890bcSjc156560 static void * 3916711890bcSjc156560 raid_obj_attr_new(raid_obj_type_id_t obj_type) 3917711890bcSjc156560 { 3918711890bcSjc156560 void *obj_attr = NULL; 3919711890bcSjc156560 3920711890bcSjc156560 switch (obj_type) { 3921711890bcSjc156560 case OBJ_TYPE_CONTROLLER: 3922711890bcSjc156560 obj_attr = calloc(1, sizeof (controller_attr_t)); 3923711890bcSjc156560 break; 3924711890bcSjc156560 case OBJ_TYPE_ARRAY: 3925711890bcSjc156560 obj_attr = calloc(1, sizeof (array_attr_t)); 3926711890bcSjc156560 break; 3927711890bcSjc156560 case OBJ_TYPE_DISK: 3928711890bcSjc156560 obj_attr = calloc(1, sizeof (disk_attr_t)); 3929711890bcSjc156560 break; 3930711890bcSjc156560 case OBJ_TYPE_HSP: 3931711890bcSjc156560 obj_attr = calloc(1, sizeof (hsp_attr_t)); 3932711890bcSjc156560 break; 3933711890bcSjc156560 case OBJ_TYPE_ARRAY_PART: 3934711890bcSjc156560 obj_attr = calloc(1, sizeof (arraypart_attr_t)); 3935711890bcSjc156560 break; 3936711890bcSjc156560 case OBJ_TYPE_DISK_SEG: 3937711890bcSjc156560 obj_attr = calloc(1, sizeof (diskseg_attr_t)); 3938711890bcSjc156560 break; 3939711890bcSjc156560 case OBJ_TYPE_TASK: 3940711890bcSjc156560 obj_attr = calloc(1, sizeof (task_attr_t)); 3941711890bcSjc156560 break; 3942b449fa8aSyw161884 case OBJ_TYPE_PROP: 3943b449fa8aSyw161884 obj_attr = calloc(1, sizeof (property_attr_t)); 3944b449fa8aSyw161884 break; 3945711890bcSjc156560 default: 3946711890bcSjc156560 break; 3947711890bcSjc156560 } 3948711890bcSjc156560 3949711890bcSjc156560 return (obj_attr); 3950711890bcSjc156560 } 3951711890bcSjc156560 3952711890bcSjc156560 static raid_obj_id_t 3953711890bcSjc156560 raid_obj_create(raid_obj_tab_t *raid_tab, raid_obj_type_id_t obj_type) 3954711890bcSjc156560 { 3955711890bcSjc156560 raid_obj_t *raid_obj; 3956711890bcSjc156560 int ret; 3957711890bcSjc156560 void *data_ptr; 3958711890bcSjc156560 3959711890bcSjc156560 raid_obj = calloc(1, sizeof (raid_obj_t)); 3960711890bcSjc156560 if (raid_obj == NULL) 3961711890bcSjc156560 return (ERR_NOMEM); 3962711890bcSjc156560 3963711890bcSjc156560 raid_obj->obj_id = raid_obj_id_new(raid_tab); 3964711890bcSjc156560 if (raid_obj->obj_id < OBJ_NONE) 3965711890bcSjc156560 return (ERR_DEVICE_OVERFLOW); 3966711890bcSjc156560 3967711890bcSjc156560 ret = raid_obj_tab_insert(raid_tab, raid_obj->obj_id, raid_obj); 3968711890bcSjc156560 if (ret == ERR_DEVICE_DUP) { 3969711890bcSjc156560 free(raid_obj); 3970711890bcSjc156560 return (ERR_DEVICE_DUP); 3971711890bcSjc156560 } 3972711890bcSjc156560 3973711890bcSjc156560 data_ptr = raid_obj_attr_new(obj_type); 3974711890bcSjc156560 if (data_ptr == NULL) { 3975711890bcSjc156560 (void) raid_obj_delete(raid_tab, raid_obj->obj_id); 3976711890bcSjc156560 return (ERR_NOMEM); 3977711890bcSjc156560 } 3978711890bcSjc156560 3979711890bcSjc156560 (void) raid_obj_set_data_ptr(raid_tab, raid_obj->obj_id, data_ptr); 3980711890bcSjc156560 3981711890bcSjc156560 (void) raid_obj_set_type(raid_tab, raid_obj->obj_id, obj_type); 3982711890bcSjc156560 return (raid_obj->obj_id); 3983711890bcSjc156560 } 3984711890bcSjc156560 3985711890bcSjc156560 static int 3986711890bcSjc156560 raid_obj_delete(raid_obj_tab_t *raid_tab, raid_obj_id_t raid_obj_id) 3987711890bcSjc156560 { 3988711890bcSjc156560 raid_obj_t *obj; 3989711890bcSjc156560 3990711890bcSjc156560 obj = raid_obj_tab_remove(raid_tab, raid_obj_id); 3991711890bcSjc156560 if (obj != NULL) { 3992711890bcSjc156560 free(obj->data); 3993711890bcSjc156560 free(obj); 3994711890bcSjc156560 return (SUCCESS); 3995711890bcSjc156560 } 3996711890bcSjc156560 3997711890bcSjc156560 return (ERR_DEVICE_NOENT); 3998711890bcSjc156560 } 3999711890bcSjc156560 4000711890bcSjc156560 static int 4001711890bcSjc156560 raid_obj_add_org(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4002711890bcSjc156560 raid_obj_id_t container_id) 4003711890bcSjc156560 { 4004711890bcSjc156560 raid_obj_id_t tmp, tmp1; 4005711890bcSjc156560 4006711890bcSjc156560 tmp = raid_obj_get_comp(raid_tab, container_id); 4007711890bcSjc156560 if (tmp < OBJ_NONE) 4008711890bcSjc156560 return (ERR_DEVICE_NOENT); 4009711890bcSjc156560 4010711890bcSjc156560 if (tmp == OBJ_NONE) { 4011711890bcSjc156560 (void) raid_obj_set_container(raid_tab, obj_id, container_id); 4012711890bcSjc156560 (void) raid_obj_set_comp(raid_tab, container_id, obj_id); 4013711890bcSjc156560 return (SUCCESS); 4014711890bcSjc156560 } 4015711890bcSjc156560 4016711890bcSjc156560 while ((tmp1 = raid_obj_get_sibling(raid_tab, tmp)) != OBJ_NONE) 4017711890bcSjc156560 tmp = tmp1; 4018711890bcSjc156560 4019711890bcSjc156560 if (raid_obj_set_sibling(raid_tab, tmp, obj_id) < SUCCESS) 4020711890bcSjc156560 return (ERR_DEVICE_NOENT); 4021711890bcSjc156560 (void) raid_obj_set_container(raid_tab, obj_id, container_id); 4022711890bcSjc156560 4023711890bcSjc156560 return (SUCCESS); 4024711890bcSjc156560 } 4025711890bcSjc156560 4026711890bcSjc156560 static raid_obj_type_id_t 4027711890bcSjc156560 raid_obj_get_type(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 4028711890bcSjc156560 { 4029711890bcSjc156560 raid_obj_t *obj; 4030711890bcSjc156560 4031711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4032711890bcSjc156560 if (obj == NULL) 4033711890bcSjc156560 return (ERR_DEVICE_NOENT); 4034711890bcSjc156560 4035711890bcSjc156560 if ((obj->obj_type_id < OBJ_TYPE_SYSTEM) || 4036711890bcSjc156560 (obj->obj_type_id >= OBJ_TYPE_ALL)) 4037711890bcSjc156560 return (ERR_DEVICE_INVALID); 4038711890bcSjc156560 4039711890bcSjc156560 return (obj->obj_type_id); 4040711890bcSjc156560 } 4041711890bcSjc156560 4042711890bcSjc156560 static int 4043711890bcSjc156560 raid_obj_set_type(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4044711890bcSjc156560 raid_obj_type_id_t type) 4045711890bcSjc156560 { 4046711890bcSjc156560 raid_obj_t *obj; 4047711890bcSjc156560 4048711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4049711890bcSjc156560 if (obj == NULL) 4050711890bcSjc156560 return (ERR_DEVICE_NOENT); 4051711890bcSjc156560 4052711890bcSjc156560 if ((type < OBJ_TYPE_SYSTEM) || (type >= OBJ_TYPE_ALL)) 4053711890bcSjc156560 return (ERR_DEVICE_TYPE); 4054711890bcSjc156560 4055711890bcSjc156560 obj->obj_type_id = type; 4056711890bcSjc156560 return (SUCCESS); 4057711890bcSjc156560 } 4058711890bcSjc156560 4059711890bcSjc156560 static raid_obj_status_t 4060711890bcSjc156560 raid_obj_get_status(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 4061711890bcSjc156560 { 4062711890bcSjc156560 raid_obj_t *obj; 4063711890bcSjc156560 4064711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4065711890bcSjc156560 if (obj == NULL) 4066711890bcSjc156560 return (ERR_DEVICE_NOENT); 4067711890bcSjc156560 4068711890bcSjc156560 return (obj->status); 4069711890bcSjc156560 } 4070711890bcSjc156560 4071711890bcSjc156560 static int 4072711890bcSjc156560 raid_obj_set_status(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4073711890bcSjc156560 raid_obj_status_t status) 4074711890bcSjc156560 { 4075711890bcSjc156560 raid_obj_t *obj; 4076711890bcSjc156560 4077711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4078711890bcSjc156560 if (obj == NULL) 4079711890bcSjc156560 return (ERR_DEVICE_NOENT); 4080711890bcSjc156560 4081711890bcSjc156560 obj->status = obj->status | status; 4082711890bcSjc156560 4083711890bcSjc156560 return (SUCCESS); 4084711890bcSjc156560 } 4085711890bcSjc156560 4086711890bcSjc156560 static int 4087711890bcSjc156560 raid_obj_clear_status(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4088711890bcSjc156560 raid_obj_status_t status) 4089711890bcSjc156560 { 4090711890bcSjc156560 raid_obj_t *obj; 4091711890bcSjc156560 4092711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4093711890bcSjc156560 if (obj == NULL) 4094711890bcSjc156560 return (ERR_DEVICE_NOENT); 4095711890bcSjc156560 4096711890bcSjc156560 obj->status = obj->status & ~status; 4097711890bcSjc156560 4098711890bcSjc156560 return (SUCCESS); 4099711890bcSjc156560 } 4100711890bcSjc156560 4101711890bcSjc156560 static raid_obj_id_t 4102711890bcSjc156560 raid_obj_get_container(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 4103711890bcSjc156560 { 4104711890bcSjc156560 raid_obj_t *obj; 4105711890bcSjc156560 4106711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4107711890bcSjc156560 if (obj == NULL) 4108711890bcSjc156560 return (ERR_DEVICE_NOENT); 4109711890bcSjc156560 4110711890bcSjc156560 return (obj->container); 4111711890bcSjc156560 } 4112711890bcSjc156560 4113711890bcSjc156560 static int 4114711890bcSjc156560 raid_obj_set_container(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4115711890bcSjc156560 raid_obj_id_t container_id) 4116711890bcSjc156560 { 4117711890bcSjc156560 raid_obj_t *obj; 4118711890bcSjc156560 4119711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4120711890bcSjc156560 if (obj == NULL) 4121711890bcSjc156560 return (ERR_DEVICE_NOENT); 4122711890bcSjc156560 4123711890bcSjc156560 obj->container = container_id; 4124711890bcSjc156560 return (SUCCESS); 4125711890bcSjc156560 } 4126711890bcSjc156560 4127711890bcSjc156560 static raid_obj_id_t 4128711890bcSjc156560 raid_obj_get_comp(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 4129711890bcSjc156560 { 4130711890bcSjc156560 raid_obj_t *obj; 4131711890bcSjc156560 4132711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4133711890bcSjc156560 if (obj == NULL) 4134711890bcSjc156560 return (ERR_DEVICE_NOENT); 4135711890bcSjc156560 4136711890bcSjc156560 return (obj->component); 4137711890bcSjc156560 } 4138711890bcSjc156560 4139711890bcSjc156560 static int 4140711890bcSjc156560 raid_obj_set_comp(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4141711890bcSjc156560 raid_obj_id_t comp) 4142711890bcSjc156560 { 4143711890bcSjc156560 raid_obj_t *obj; 4144711890bcSjc156560 4145711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4146711890bcSjc156560 if (obj == NULL) 4147711890bcSjc156560 return (ERR_DEVICE_NOENT); 4148711890bcSjc156560 4149711890bcSjc156560 obj->component = comp; 4150711890bcSjc156560 return (SUCCESS); 4151711890bcSjc156560 } 4152711890bcSjc156560 4153711890bcSjc156560 static raid_obj_id_t 4154711890bcSjc156560 raid_obj_get_sibling(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 4155711890bcSjc156560 { 4156711890bcSjc156560 raid_obj_t *obj; 4157711890bcSjc156560 4158711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4159711890bcSjc156560 if (obj == NULL) 4160711890bcSjc156560 return (ERR_DEVICE_NOENT); 4161711890bcSjc156560 4162711890bcSjc156560 return (obj->sibling); 4163711890bcSjc156560 } 4164711890bcSjc156560 4165711890bcSjc156560 static int 4166711890bcSjc156560 raid_obj_set_sibling(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4167711890bcSjc156560 raid_obj_id_t sibling) 4168711890bcSjc156560 { 4169711890bcSjc156560 raid_obj_t *obj; 4170711890bcSjc156560 4171711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4172711890bcSjc156560 if (obj == NULL) 4173711890bcSjc156560 return (ERR_DEVICE_NOENT); 4174711890bcSjc156560 4175711890bcSjc156560 obj->sibling = sibling; 4176711890bcSjc156560 4177711890bcSjc156560 return (SUCCESS); 4178711890bcSjc156560 } 4179711890bcSjc156560 4180711890bcSjc156560 static void * 4181711890bcSjc156560 raid_obj_get_data_ptr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 4182711890bcSjc156560 { 4183711890bcSjc156560 raid_obj_t *obj; 4184711890bcSjc156560 4185711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4186711890bcSjc156560 if (obj == NULL) 4187711890bcSjc156560 return (NULL); 4188711890bcSjc156560 4189711890bcSjc156560 return (obj->data); 4190711890bcSjc156560 } 4191711890bcSjc156560 4192711890bcSjc156560 static int 4193711890bcSjc156560 raid_obj_set_data_ptr(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4194711890bcSjc156560 void *data) 4195711890bcSjc156560 { 4196711890bcSjc156560 raid_obj_t *obj; 4197711890bcSjc156560 4198711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4199711890bcSjc156560 if (obj == NULL) 4200711890bcSjc156560 return (ERR_DEVICE_NOENT); 4201711890bcSjc156560 4202711890bcSjc156560 obj->data = data; 4203711890bcSjc156560 4204711890bcSjc156560 return (SUCCESS); 4205711890bcSjc156560 } 4206711890bcSjc156560 4207711890bcSjc156560 static raid_obj_handle_t 4208711890bcSjc156560 raid_obj_get_handle(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id) 4209711890bcSjc156560 { 4210711890bcSjc156560 raid_obj_t *obj; 4211711890bcSjc156560 4212711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4213711890bcSjc156560 if (obj == NULL) 4214711890bcSjc156560 return (ERR_DEVICE_NOENT); 4215711890bcSjc156560 4216711890bcSjc156560 return (obj->handle); 4217711890bcSjc156560 } 4218711890bcSjc156560 4219711890bcSjc156560 static int 4220711890bcSjc156560 raid_obj_set_handle(raid_obj_tab_t *raid_tab, raid_obj_id_t obj_id, 4221711890bcSjc156560 raid_obj_handle_t handle) 4222711890bcSjc156560 { 4223711890bcSjc156560 raid_obj_t *obj; 4224711890bcSjc156560 4225711890bcSjc156560 obj = raid_obj_tab_find(raid_tab, obj_id); 4226711890bcSjc156560 if (obj == NULL) 4227711890bcSjc156560 return (ERR_DEVICE_NOENT); 4228711890bcSjc156560 4229711890bcSjc156560 obj->handle = handle; 4230711890bcSjc156560 return (SUCCESS); 4231711890bcSjc156560 } 4232711890bcSjc156560 /* 4233711890bcSjc156560 * Object list maintennance routines 4234711890bcSjc156560 */ 4235711890bcSjc156560 static void 4236711890bcSjc156560 raid_list_create(raid_list_t *list, size_t offset) 4237711890bcSjc156560 { 4238711890bcSjc156560 list->head = NULL; 4239711890bcSjc156560 list->tail = NULL; 4240711890bcSjc156560 list->offset = offset; 4241711890bcSjc156560 } 4242711890bcSjc156560 4243711890bcSjc156560 static void * 4244711890bcSjc156560 raid_list_head(raid_list_t *list) 4245711890bcSjc156560 { 4246711890bcSjc156560 return (list->head); 4247711890bcSjc156560 } 4248711890bcSjc156560 4249711890bcSjc156560 static void * 4250711890bcSjc156560 raid_list_next(raid_list_t *list, void *obj) 4251711890bcSjc156560 { 4252711890bcSjc156560 raid_list_el_t *el = LIST_OBJ_TO_EL(list, obj); 4253711890bcSjc156560 4254711890bcSjc156560 return (el->next); 4255711890bcSjc156560 } 4256711890bcSjc156560 4257711890bcSjc156560 static void 4258711890bcSjc156560 raid_list_insert_tail(raid_list_t *list, void *obj) 4259711890bcSjc156560 { 4260711890bcSjc156560 raid_list_el_t *el = LIST_OBJ_TO_EL(list, obj), *el1; 4261711890bcSjc156560 4262711890bcSjc156560 el->prev = list->tail; 4263711890bcSjc156560 list->tail = obj; 4264711890bcSjc156560 4265711890bcSjc156560 el->next = NULL; 4266711890bcSjc156560 4267711890bcSjc156560 if (list->head == NULL) 4268711890bcSjc156560 list->head = obj; 4269711890bcSjc156560 4270711890bcSjc156560 if (el->prev != NULL) { 4271711890bcSjc156560 el1 = LIST_OBJ_TO_EL(list, el->prev); 4272711890bcSjc156560 el1->next = obj; 4273711890bcSjc156560 } 4274711890bcSjc156560 } 4275711890bcSjc156560 4276711890bcSjc156560 static void 4277711890bcSjc156560 raid_list_remove(raid_list_t *list, void *obj) 4278711890bcSjc156560 { 4279711890bcSjc156560 raid_list_el_t *el = LIST_OBJ_TO_EL(list, obj), *el1; 4280711890bcSjc156560 4281711890bcSjc156560 if (list->head == obj) 4282711890bcSjc156560 list->head = el->next; 4283711890bcSjc156560 4284711890bcSjc156560 if (list->tail == obj) 4285711890bcSjc156560 list->tail = el->prev; 4286711890bcSjc156560 4287711890bcSjc156560 if (el->next != NULL) { 4288711890bcSjc156560 el1 = LIST_OBJ_TO_EL(list, el->next); 4289711890bcSjc156560 el1->prev = el->prev; 4290711890bcSjc156560 } 4291711890bcSjc156560 4292711890bcSjc156560 if (el->prev != NULL) { 4293711890bcSjc156560 el1 = LIST_OBJ_TO_EL(list, el->prev); 4294711890bcSjc156560 el1->next = el->next; 4295711890bcSjc156560 } 4296711890bcSjc156560 4297711890bcSjc156560 el->prev = el->next = NULL; 4298711890bcSjc156560 } 4299711890bcSjc156560 4300711890bcSjc156560 static void * 4301711890bcSjc156560 raid_list_remove_head(raid_list_t *list) 4302711890bcSjc156560 { 4303711890bcSjc156560 void *obj = list->head; 4304711890bcSjc156560 4305711890bcSjc156560 if (obj != NULL) 4306711890bcSjc156560 raid_list_remove(list, obj); 4307711890bcSjc156560 4308711890bcSjc156560 return (obj); 4309711890bcSjc156560 } 4310711890bcSjc156560 4311711890bcSjc156560 static void * 4312711890bcSjc156560 raid_list_find(raid_list_t *list, raid_obj_id_t obj_id) 4313711890bcSjc156560 { 4314711890bcSjc156560 raid_obj_t *obj; 4315711890bcSjc156560 4316711890bcSjc156560 for (obj = raid_list_head(list); obj != NULL; 4317711890bcSjc156560 obj = raid_list_next(list, obj)) 4318711890bcSjc156560 if (obj->obj_id == obj_id) 4319711890bcSjc156560 break; 4320711890bcSjc156560 4321711890bcSjc156560 return (obj); 4322711890bcSjc156560 } 4323711890bcSjc156560 4324711890bcSjc156560 static int 4325711890bcSjc156560 raid_obj_tab_create(raid_obj_tab_t *tab, size_t hash_slots) 4326711890bcSjc156560 { 4327711890bcSjc156560 unsigned i; 4328711890bcSjc156560 4329711890bcSjc156560 if (hash_slots == 0) 4330711890bcSjc156560 return (ERR_OP_ILLEGAL); 4331711890bcSjc156560 4332711890bcSjc156560 tab->slots = hash_slots; 4333711890bcSjc156560 4334711890bcSjc156560 if ((tab->table = calloc(hash_slots, sizeof (raid_list_t))) == NULL) 4335711890bcSjc156560 return (ERR_NOMEM); 4336711890bcSjc156560 4337711890bcSjc156560 for (i = 0; i < hash_slots; i++) 4338711890bcSjc156560 raid_list_create(&tab->table[i], offsetof(raid_obj_t, el)); 4339711890bcSjc156560 4340711890bcSjc156560 return (SUCCESS); 4341711890bcSjc156560 } 4342711890bcSjc156560 4343711890bcSjc156560 static void 4344711890bcSjc156560 raid_obj_tab_destroy(raid_obj_tab_t *tab) 4345711890bcSjc156560 { 4346711890bcSjc156560 unsigned i; 4347711890bcSjc156560 4348711890bcSjc156560 for (i = 0; i < tab->slots; i++) { 4349711890bcSjc156560 struct raid_obj_t *obj; 4350711890bcSjc156560 4351711890bcSjc156560 while ((obj = raid_list_remove_head(&tab->table[i])) != NULL) 4352711890bcSjc156560 free(obj); 4353711890bcSjc156560 4354711890bcSjc156560 raid_list_destroy(&tab->table[i]); 4355711890bcSjc156560 } 4356711890bcSjc156560 4357711890bcSjc156560 if (tab->table) 4358711890bcSjc156560 free(tab->table); 4359711890bcSjc156560 4360711890bcSjc156560 tab->table = NULL; 4361711890bcSjc156560 tab->slots = 0; 4362711890bcSjc156560 tab->obj_id_cnt = 0; 4363711890bcSjc156560 } 4364711890bcSjc156560 4365711890bcSjc156560 static int 4366711890bcSjc156560 raid_obj_tab_insert(raid_obj_tab_t *tab, raid_obj_id_t id, void *obj) 4367711890bcSjc156560 { 4368711890bcSjc156560 raid_list_t *list; 4369711890bcSjc156560 4370711890bcSjc156560 list = OBJ_TAB_SLOT(tab, id); 4371711890bcSjc156560 4372711890bcSjc156560 if (raid_list_find(list, id) != NULL) 4373711890bcSjc156560 return (ERR_DEVICE_DUP); 4374711890bcSjc156560 4375711890bcSjc156560 raid_list_insert_tail(list, obj); 4376711890bcSjc156560 4377711890bcSjc156560 return (SUCCESS); 4378711890bcSjc156560 } 4379711890bcSjc156560 4380711890bcSjc156560 static void * 4381711890bcSjc156560 raid_obj_tab_remove(raid_obj_tab_t *tab, raid_obj_id_t id) 4382711890bcSjc156560 { 4383711890bcSjc156560 raid_list_t *list; 4384711890bcSjc156560 raid_obj_t *obj; 4385711890bcSjc156560 4386711890bcSjc156560 list = OBJ_TAB_SLOT(tab, id); 4387711890bcSjc156560 4388711890bcSjc156560 if ((obj = raid_list_find(list, id)) != NULL) 4389711890bcSjc156560 raid_list_remove(list, obj); 4390711890bcSjc156560 4391711890bcSjc156560 return (obj); 4392711890bcSjc156560 } 4393711890bcSjc156560 4394711890bcSjc156560 static void * 4395711890bcSjc156560 raid_obj_tab_find(raid_obj_tab_t *tab, raid_obj_id_t id) 4396711890bcSjc156560 { 4397711890bcSjc156560 raid_list_t *list; 4398711890bcSjc156560 raid_obj_t *obj; 4399711890bcSjc156560 4400711890bcSjc156560 list = OBJ_TAB_SLOT(tab, id); 4401711890bcSjc156560 obj = raid_list_find(list, id); 4402711890bcSjc156560 4403711890bcSjc156560 return (obj); 4404711890bcSjc156560 } 4405711890bcSjc156560 4406711890bcSjc156560 static void 4407711890bcSjc156560 raid_list_destroy(raid_list_t *list) 4408711890bcSjc156560 { 4409711890bcSjc156560 list->head = NULL; 4410711890bcSjc156560 list->tail = NULL; 4411711890bcSjc156560 list->offset = 0; 4412711890bcSjc156560 } 4413711890bcSjc156560 4414711890bcSjc156560 /* 4415711890bcSjc156560 * Plug-in maintennance routines 4416711890bcSjc156560 */ 4417711890bcSjc156560 static int 4418711890bcSjc156560 controller_id_to_path(uint32_t controller_id, char *path) 4419711890bcSjc156560 { 4420317fb4acSYu-Bo Ryan Wang int fd; 4421711890bcSjc156560 char buf[MAX_PATH_LEN] = {0}, buf1[MAX_PATH_LEN] = {0}, *colon; 4422711890bcSjc156560 4423711890bcSjc156560 (void) snprintf(buf, MAX_PATH_LEN, "%s/c%d", CFGDIR, controller_id); 4424711890bcSjc156560 if (readlink(buf, buf1, sizeof (buf1)) < 0) 4425711890bcSjc156560 return (ERR_DRIVER_NOT_FOUND); 4426711890bcSjc156560 4427711890bcSjc156560 if (buf1[0] != '/') 4428711890bcSjc156560 (void) snprintf(buf, sizeof (buf), "%s/", CFGDIR); 4429711890bcSjc156560 else 4430711890bcSjc156560 buf[0] = 0; 4431711890bcSjc156560 (void) strlcat(buf, buf1, MAX_PATH_LEN); 4432711890bcSjc156560 4433711890bcSjc156560 colon = strrchr(buf, ':'); 4434711890bcSjc156560 if (colon == NULL) 4435711890bcSjc156560 return (ERR_DRIVER_NOT_FOUND); 4436711890bcSjc156560 else 4437711890bcSjc156560 *colon = 0; 4438711890bcSjc156560 4439711890bcSjc156560 (void) snprintf(path, MAX_PATH_LEN, "%s:devctl", buf); 4440711890bcSjc156560 4441317fb4acSYu-Bo Ryan Wang fd = open(path, O_RDONLY | O_NDELAY); 4442317fb4acSYu-Bo Ryan Wang 4443317fb4acSYu-Bo Ryan Wang if (fd < 0) 4444711890bcSjc156560 return (ERR_DRIVER_NOT_FOUND); 4445711890bcSjc156560 4446317fb4acSYu-Bo Ryan Wang (void) close(fd); 4447317fb4acSYu-Bo Ryan Wang 4448711890bcSjc156560 return (SUCCESS); 4449711890bcSjc156560 } 4450711890bcSjc156560 4451711890bcSjc156560 static char * 4452711890bcSjc156560 controller_id_to_driver_name(uint32_t controller_id) 4453711890bcSjc156560 { 4454711890bcSjc156560 char buf[MAX_PATH_LEN]; 4455711890bcSjc156560 di_node_t di_node; 4456711890bcSjc156560 char *name, *tmp; 4457711890bcSjc156560 int ret; 4458711890bcSjc156560 4459711890bcSjc156560 ret = controller_id_to_path(controller_id, buf); 4460711890bcSjc156560 if (ret < SUCCESS) 4461711890bcSjc156560 return (NULL); 4462711890bcSjc156560 4463711890bcSjc156560 tmp = strrchr(buf, ':'); 4464711890bcSjc156560 if (tmp != NULL) 4465711890bcSjc156560 *tmp = 0; 4466711890bcSjc156560 4467711890bcSjc156560 tmp = strstr(buf, "pci"); 4468711890bcSjc156560 if (tmp == NULL) 4469711890bcSjc156560 return (NULL); 4470711890bcSjc156560 4471711890bcSjc156560 di_node = di_init(tmp, DINFOPROP); 4472711890bcSjc156560 if (di_node == DI_NODE_NIL) 4473711890bcSjc156560 return (NULL); 4474711890bcSjc156560 4475711890bcSjc156560 name = di_driver_name(di_node); 4476711890bcSjc156560 4477711890bcSjc156560 return (name); 4478711890bcSjc156560 } 4479711890bcSjc156560 4480711890bcSjc156560 static void 4481711890bcSjc156560 raid_plugin_init() 4482711890bcSjc156560 { 4483711890bcSjc156560 raid_lib_t *raid_lib = raid_lib_sys; 4484711890bcSjc156560 4485711890bcSjc156560 while (raid_lib) { 4486711890bcSjc156560 raid_lib_sys = raid_lib->next; 4487711890bcSjc156560 (void) dlclose(raid_lib->lib_handle); 4488711890bcSjc156560 free(raid_lib); 4489711890bcSjc156560 raid_lib = raid_lib_sys; 4490711890bcSjc156560 } 4491711890bcSjc156560 } 4492711890bcSjc156560 4493711890bcSjc156560 static raid_lib_t * 4494711890bcSjc156560 raid_plugin_load(char *driver_name) 4495711890bcSjc156560 { 4496711890bcSjc156560 char buf[MAX_PATH_LEN] = {0}; 4497711890bcSjc156560 raid_lib_t *supplib; 4498711890bcSjc156560 void *sym; 4499711890bcSjc156560 4500711890bcSjc156560 supplib = calloc(1, sizeof (raid_lib_t)); 4501711890bcSjc156560 if (supplib == NULL) 4502711890bcSjc156560 return (NULL); 4503711890bcSjc156560 4504711890bcSjc156560 (void) snprintf(buf, MAX_PATH_LEN, "%s/%s.so.1", 4505711890bcSjc156560 SUPP_PLUGIN_DIR, driver_name); 4506711890bcSjc156560 4507711890bcSjc156560 supplib->lib_handle = dlopen(buf, RTLD_LAZY); 4508711890bcSjc156560 if (supplib->lib_handle == NULL) { 4509711890bcSjc156560 free(supplib); 4510711890bcSjc156560 return (NULL); 4511711890bcSjc156560 } 4512711890bcSjc156560 4513711890bcSjc156560 supplib->name = driver_name; 4514711890bcSjc156560 4515711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_version")) == NULL) 4516711890bcSjc156560 supplib->version = RDCFG_PLUGIN_V1; 4517711890bcSjc156560 else { 4518711890bcSjc156560 supplib->version = *((uint32_t *)sym); 4519711890bcSjc156560 if (supplib->version != RDCFG_PLUGIN_V1) { 4520711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4521711890bcSjc156560 free(supplib); 4522711890bcSjc156560 return (NULL); 4523711890bcSjc156560 } 4524711890bcSjc156560 } 4525711890bcSjc156560 4526711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_open_controller")) == 4527711890bcSjc156560 NULL) { 4528711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4529711890bcSjc156560 free(supplib); 4530711890bcSjc156560 return (NULL); 4531711890bcSjc156560 } else 4532711890bcSjc156560 supplib->open_controller = (int(*)(uint32_t, char **))sym; 4533711890bcSjc156560 4534711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_close_controller")) == 4535711890bcSjc156560 NULL) { 4536711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4537711890bcSjc156560 free(supplib); 4538711890bcSjc156560 return (NULL); 4539711890bcSjc156560 } else 4540711890bcSjc156560 supplib->close_controller = (int (*)(uint32_t, char **))sym; 4541711890bcSjc156560 4542711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_compnum")) == NULL) { 4543711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4544711890bcSjc156560 free(supplib); 4545711890bcSjc156560 return (NULL); 4546711890bcSjc156560 } else 4547711890bcSjc156560 supplib->compnum = (int (*)(uint32_t, uint32_t, 4548711890bcSjc156560 raid_obj_type_id_t, raid_obj_type_id_t))sym; 4549711890bcSjc156560 4550711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_complist")) == NULL) { 4551711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4552711890bcSjc156560 free(supplib); 4553711890bcSjc156560 return (NULL); 4554711890bcSjc156560 } else 4555711890bcSjc156560 supplib->complist = (int (*)(uint32_t, uint32_t, 4556711890bcSjc156560 raid_obj_type_id_t, raid_obj_type_id_t, int, void *))sym; 4557711890bcSjc156560 4558711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_get_attr")) == NULL) { 4559711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4560711890bcSjc156560 free(supplib); 4561711890bcSjc156560 return (NULL); 4562711890bcSjc156560 } else 4563711890bcSjc156560 supplib->get_attr = (int (*)(uint32_t, uint32_t, uint32_t, 4564711890bcSjc156560 raid_obj_type_id_t, void*))sym; 4565711890bcSjc156560 4566711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_array_create")) == NULL) { 4567711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4568711890bcSjc156560 free(supplib); 4569711890bcSjc156560 return (NULL); 4570711890bcSjc156560 } else 4571711890bcSjc156560 supplib->array_create = (int (*)(uint32_t, array_attr_t *, int, 4572711890bcSjc156560 arraypart_attr_t *, char **))sym; 4573711890bcSjc156560 4574711890bcSjc156560 if ((sym = dlsym(supplib->lib_handle, "rdcfg_array_delete")) == NULL) { 4575711890bcSjc156560 (void) dlclose(supplib->lib_handle); 4576711890bcSjc156560 free(supplib); 4577711890bcSjc156560 return (NULL); 4578711890bcSjc156560 } else 4579711890bcSjc156560 supplib->array_delete = 4580711890bcSjc156560 (int (*)(uint32_t, uint32_t, char **))sym; 4581711890bcSjc156560 45825c9d25d2SYu-Bo Ryan Wang supplib->hsp_bind = (int (*)(uint32_t, hsp_relation_t *, 4583711890bcSjc156560 char **))dlsym(supplib->lib_handle, "rdcfg_hsp_bind"); 45845c9d25d2SYu-Bo Ryan Wang supplib->hsp_unbind = (int (*)(uint32_t, hsp_relation_t *, 4585711890bcSjc156560 char **))dlsym(supplib->lib_handle, "rdcfg_hsp_unbind"); 4586711890bcSjc156560 supplib->set_attr = (int (*)(uint32_t, uint32_t, uint32_t, uint32_t *, 4587711890bcSjc156560 char **))dlsym(supplib->lib_handle, "rdcfg_set_attr"); 4588711890bcSjc156560 supplib->flash_fw = (int (*)(uint32_t, char *, uint32_t, char **)) 4589711890bcSjc156560 dlsym(supplib->lib_handle, "rdcfg_flash_fw"); 4590711890bcSjc156560 4591711890bcSjc156560 supplib->next = raid_lib_sys; 4592711890bcSjc156560 raid_lib_sys = supplib; 4593711890bcSjc156560 return (supplib); 4594711890bcSjc156560 } 4595711890bcSjc156560 4596711890bcSjc156560 static raid_lib_t * 4597711890bcSjc156560 raid_find_lib(raid_obj_tab_t *raid_tab, raid_obj_id_t controller_obj_id) 4598711890bcSjc156560 { 4599711890bcSjc156560 controller_attr_t *controller_attr; 4600711890bcSjc156560 raid_lib_t *raid_lib; 4601711890bcSjc156560 char *driver_name; 4602711890bcSjc156560 raid_obj_handle_t handle; 4603711890bcSjc156560 4604711890bcSjc156560 /* Check if it's mapped to handle structure */ 4605711890bcSjc156560 handle = raid_obj_to_handle(raid_tab, controller_obj_id); 4606711890bcSjc156560 if (raid_handle_sys.handles[handle].raid_lib != NULL) 4607711890bcSjc156560 return (raid_handle_sys.handles[handle].raid_lib); 4608711890bcSjc156560 4609711890bcSjc156560 (void) obj_get_attr(raid_tab, controller_obj_id, 4610711890bcSjc156560 (void **)(&controller_attr)); 4611711890bcSjc156560 4612711890bcSjc156560 /* Check if the plugin module is already loaded */ 4613711890bcSjc156560 driver_name = controller_id_to_driver_name( 4614711890bcSjc156560 controller_attr->controller_id); 4615711890bcSjc156560 if (driver_name == NULL) 4616711890bcSjc156560 return (NULL); 4617711890bcSjc156560 4618711890bcSjc156560 raid_lib = raid_lib_sys; 4619711890bcSjc156560 while (raid_lib != NULL) { 4620711890bcSjc156560 if (raid_lib->name != NULL && 4621711890bcSjc156560 strcmp(driver_name, raid_lib->name) == 0) 4622711890bcSjc156560 return (raid_lib); 4623711890bcSjc156560 4624711890bcSjc156560 raid_lib = raid_lib->next; 4625711890bcSjc156560 } 4626711890bcSjc156560 4627711890bcSjc156560 /* Loading the plugin module */ 4628711890bcSjc156560 raid_lib = raid_plugin_load(driver_name); 4629711890bcSjc156560 4630711890bcSjc156560 return (raid_lib); 4631711890bcSjc156560 } 4632