1fcf3ce44SJohn Forte /* 2fcf3ce44SJohn Forte * CDDL HEADER START 3fcf3ce44SJohn Forte * 4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7fcf3ce44SJohn Forte * 8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11fcf3ce44SJohn Forte * and limitations under the License. 12fcf3ce44SJohn Forte * 13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18fcf3ce44SJohn Forte * 19fcf3ce44SJohn Forte * CDDL HEADER END 20fcf3ce44SJohn Forte */ 21fcf3ce44SJohn Forte /* 228fe96085Stim szeto * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23fcf3ce44SJohn Forte * Use is subject to license terms. 24fcf3ce44SJohn Forte */ 25fcf3ce44SJohn Forte 26fcf3ce44SJohn Forte #include <stdlib.h> 27fcf3ce44SJohn Forte #include <stdio.h> 28fcf3ce44SJohn Forte #include <wchar.h> 29fcf3ce44SJohn Forte #include <strings.h> 30fcf3ce44SJohn Forte #include <sys/types.h> 31fcf3ce44SJohn Forte #include <sys/stat.h> 32fcf3ce44SJohn Forte #include <fcntl.h> 33fcf3ce44SJohn Forte #include <unistd.h> 34fcf3ce44SJohn Forte #include <libintl.h> 35fcf3ce44SJohn Forte #include <errno.h> 36fcf3ce44SJohn Forte #include <string.h> 37fcf3ce44SJohn Forte #include <assert.h> 38fcf3ce44SJohn Forte #include <libnvpair.h> 39fcf3ce44SJohn Forte #include <pthread.h> 40fcf3ce44SJohn Forte #include <syslog.h> 41fcf3ce44SJohn Forte #include <libstmf.h> 42fcf3ce44SJohn Forte #include <netinet/in.h> 43fcf3ce44SJohn Forte #include <inttypes.h> 44fcf3ce44SJohn Forte #include <store.h> 45fcf3ce44SJohn Forte #include <locale.h> 468fe96085Stim szeto #include <math.h> 478fe96085Stim szeto #include <libstmf_impl.h> 48fcf3ce44SJohn Forte #include <sys/stmf_ioctl.h> 498fe96085Stim szeto #include <sys/stmf_sbd_ioctl.h> 50*45039663SJohn Forte #include <sys/pppt_ioctl.h> 51fcf3ce44SJohn Forte 52fcf3ce44SJohn Forte #define STMF_PATH "/devices/pseudo/stmf@0:admin" 538fe96085Stim szeto #define SBD_PATH "/devices/pseudo/stmf_sbd@0:admin" 54*45039663SJohn Forte #define PPPT_PATH "/devices/pseudo/pppt@0:pppt" 55fcf3ce44SJohn Forte 56fcf3ce44SJohn Forte #define EUI "eui." 57fcf3ce44SJohn Forte #define WWN "wwn." 58fcf3ce44SJohn Forte #define IQN "iqn." 598fe96085Stim szeto #define LU_ASCII_GUID_SIZE 32 608fe96085Stim szeto #define LU_GUID_SIZE 16 618fe96085Stim szeto #define OUI_ASCII_SIZE 6 628fe96085Stim szeto #define OUI_SIZE 3 63fcf3ce44SJohn Forte #define IDENT_LENGTH_BYTE 3 64fcf3ce44SJohn Forte 658fe96085Stim szeto /* various initial allocation values */ 668fe96085Stim szeto #define ALLOC_LU 8192 678fe96085Stim szeto #define ALLOC_TARGET_PORT 2048 688fe96085Stim szeto #define ALLOC_PROVIDER 64 698fe96085Stim szeto #define ALLOC_GROUP 2048 708fe96085Stim szeto #define ALLOC_SESSION 2048 718fe96085Stim szeto #define ALLOC_VE 256 728fe96085Stim szeto #define ALLOC_PP_DATA_SIZE 128*1024 738fe96085Stim szeto #define ALLOC_GRP_MEMBER 256 748fe96085Stim szeto 75fcf3ce44SJohn Forte #define MAX_ISCSI_NAME 223 768fe96085Stim szeto #define MAX_SERIAL_SIZE 252 + 1 778fe96085Stim szeto #define MAX_LU_ALIAS_SIZE 256 788fe96085Stim szeto #define MAX_SBD_PROPS MAXPATHLEN + MAX_SERIAL_SIZE + MAX_LU_ALIAS_SIZE 79fcf3ce44SJohn Forte 80fcf3ce44SJohn Forte #define OPEN_STMF 0 81fcf3ce44SJohn Forte #define OPEN_EXCL_STMF O_EXCL 82fcf3ce44SJohn Forte 838fe96085Stim szeto #define OPEN_SBD 0 848fe96085Stim szeto #define OPEN_EXCL_SBD O_EXCL 858fe96085Stim szeto 86*45039663SJohn Forte #define OPEN_PPPT 0 87*45039663SJohn Forte #define OPEN_EXCL_PPPT O_EXCL 88*45039663SJohn Forte 89fcf3ce44SJohn Forte #define LOGICAL_UNIT_TYPE 0 90fcf3ce44SJohn Forte #define TARGET_TYPE 1 91fcf3ce44SJohn Forte #define STMF_SERVICE_TYPE 2 92fcf3ce44SJohn Forte 938fe96085Stim szeto #define HOST_GROUP 1 948fe96085Stim szeto #define TARGET_GROUP 2 958fe96085Stim szeto 968fe96085Stim szeto /* set default persistence here */ 978fe96085Stim szeto #define STMF_DEFAULT_PERSIST STMF_PERSIST_SMF 988fe96085Stim szeto 998fe96085Stim szeto #define MAX_PROVIDER_RETRY 30 1008fe96085Stim szeto 101fcf3ce44SJohn Forte static int openStmf(int, int *fd); 1028fe96085Stim szeto static int openSbd(int, int *fd); 103*45039663SJohn Forte static int openPppt(int, int *fd); 104fcf3ce44SJohn Forte static int groupIoctl(int fd, int cmd, stmfGroupName *); 105fcf3ce44SJohn Forte static int loadStore(int fd); 106fcf3ce44SJohn Forte static int initializeConfig(); 107fcf3ce44SJohn Forte static int groupMemberIoctl(int fd, int cmd, stmfGroupName *, stmfDevid *); 108fcf3ce44SJohn Forte static int guidCompare(const void *, const void *); 109fcf3ce44SJohn Forte static int addViewEntryIoctl(int fd, stmfGuid *, stmfViewEntry *); 110fcf3ce44SJohn Forte static int loadHostGroups(int fd, stmfGroupList *); 111fcf3ce44SJohn Forte static int loadTargetGroups(int fd, stmfGroupList *); 112fcf3ce44SJohn Forte static int getStmfState(stmf_state_desc_t *); 113fcf3ce44SJohn Forte static int setStmfState(int fd, stmf_state_desc_t *, int); 1148fe96085Stim szeto static int setProviderData(int fd, char *, nvlist_t *, int, uint64_t *); 1158fe96085Stim szeto static int createDiskResource(luResourceImpl *); 1168fe96085Stim szeto static int createDiskLu(diskResource *, stmfGuid *); 1178fe96085Stim szeto static int deleteDiskLu(stmfGuid *luGuid); 1188fe96085Stim szeto static int getDiskProp(luResourceImpl *, uint32_t, char *, size_t *); 1198fe96085Stim szeto static int getDiskAllProps(stmfGuid *luGuid, luResource *hdl); 1208fe96085Stim szeto static int loadDiskPropsFromDriver(luResourceImpl *, sbd_lu_props_t *); 1218fe96085Stim szeto static int removeGuidFromDiskStore(stmfGuid *); 1228fe96085Stim szeto static int addGuidToDiskStore(stmfGuid *, char *); 1238fe96085Stim szeto static int persistDiskGuid(stmfGuid *, char *, boolean_t); 1248fe96085Stim szeto static int setDiskProp(luResourceImpl *, uint32_t, const char *); 1258fe96085Stim szeto static int checkHexUpper(char *); 1268fe96085Stim szeto static int strToShift(const char *); 1278fe96085Stim szeto static int niceStrToNum(const char *, uint64_t *); 1288fe96085Stim szeto static void diskError(uint32_t, int *); 1298fe96085Stim szeto static int importDiskLu(char *fname, stmfGuid *); 1308fe96085Stim szeto static int modifyDiskLu(diskResource *, stmfGuid *, const char *); 1318fe96085Stim szeto static int modifyDiskLuProp(stmfGuid *, const char *, uint32_t, const char *); 1328fe96085Stim szeto static int validateModifyDiskProp(uint32_t); 1338fe96085Stim szeto static uint8_t iGetPersistMethod(); 1348fe96085Stim szeto static int groupListIoctl(stmfGroupList **, int); 1358fe96085Stim szeto static int iLoadGroupFromPs(stmfGroupList **, int); 1368fe96085Stim szeto static int groupMemberListIoctl(stmfGroupName *, stmfGroupProperties **, int); 1378fe96085Stim szeto static int getProviderData(char *, nvlist_t **, int, uint64_t *); 138*45039663SJohn Forte static int setDiskStandby(stmfGuid *luGuid); 1398fe96085Stim szeto static int viewEntryCompare(const void *, const void *); 140*45039663SJohn Forte static void deleteNonActiveLus(); 1418fe96085Stim szeto 1428fe96085Stim szeto static pthread_mutex_t persistenceTypeLock = PTHREAD_MUTEX_INITIALIZER; 1438fe96085Stim szeto static int iPersistType = 0; 1448fe96085Stim szeto /* when B_TRUE, no need to access SMF anymore. Just use iPersistType */ 1458fe96085Stim szeto static boolean_t iLibSetPersist = B_FALSE; 146fcf3ce44SJohn Forte 147fcf3ce44SJohn Forte /* 148fcf3ce44SJohn Forte * Open for stmf module 149fcf3ce44SJohn Forte * 150fcf3ce44SJohn Forte * flag - open flag (OPEN_STMF, OPEN_EXCL_STMF) 151fcf3ce44SJohn Forte * fd - pointer to integer. On success, contains the stmf file descriptor 152fcf3ce44SJohn Forte */ 153fcf3ce44SJohn Forte static int 154fcf3ce44SJohn Forte openStmf(int flag, int *fd) 155fcf3ce44SJohn Forte { 156fcf3ce44SJohn Forte int ret = STMF_STATUS_ERROR; 157fcf3ce44SJohn Forte 158fcf3ce44SJohn Forte if ((*fd = open(STMF_PATH, O_NDELAY | O_RDONLY | flag)) != -1) { 159fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 160fcf3ce44SJohn Forte } else { 161fcf3ce44SJohn Forte if (errno == EBUSY) { 162fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 1638fe96085Stim szeto } else if (errno == EACCES) { 1648fe96085Stim szeto ret = STMF_ERROR_PERM; 165fcf3ce44SJohn Forte } else { 166fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 167fcf3ce44SJohn Forte } 168fcf3ce44SJohn Forte syslog(LOG_DEBUG, "openStmf:open failure:%s:errno(%d)", 169fcf3ce44SJohn Forte STMF_PATH, errno); 170fcf3ce44SJohn Forte } 171fcf3ce44SJohn Forte 172fcf3ce44SJohn Forte return (ret); 173fcf3ce44SJohn Forte } 174fcf3ce44SJohn Forte 175fcf3ce44SJohn Forte /* 1768fe96085Stim szeto * Open for sbd module 1778fe96085Stim szeto * 178*45039663SJohn Forte * flag - open flag (OPEN_SBD, OPEN_EXCL_SBD) 1798fe96085Stim szeto * fd - pointer to integer. On success, contains the stmf file descriptor 1808fe96085Stim szeto */ 1818fe96085Stim szeto static int 1828fe96085Stim szeto openSbd(int flag, int *fd) 1838fe96085Stim szeto { 1848fe96085Stim szeto int ret = STMF_STATUS_ERROR; 1858fe96085Stim szeto 1868fe96085Stim szeto if ((*fd = open(SBD_PATH, O_NDELAY | O_RDONLY | flag)) != -1) { 1878fe96085Stim szeto ret = STMF_STATUS_SUCCESS; 1888fe96085Stim szeto } else { 1898fe96085Stim szeto if (errno == EBUSY) { 1908fe96085Stim szeto ret = STMF_ERROR_BUSY; 1918fe96085Stim szeto } else if (errno == EACCES) { 1928fe96085Stim szeto ret = STMF_ERROR_PERM; 1938fe96085Stim szeto } else { 1948fe96085Stim szeto ret = STMF_STATUS_ERROR; 1958fe96085Stim szeto } 1968fe96085Stim szeto syslog(LOG_DEBUG, "openSbd:open failure:%s:errno(%d)", 1978fe96085Stim szeto SBD_PATH, errno); 1988fe96085Stim szeto } 1998fe96085Stim szeto 2008fe96085Stim szeto return (ret); 2018fe96085Stim szeto } 2028fe96085Stim szeto 2038fe96085Stim szeto /* 204*45039663SJohn Forte * Open for pppt module 205*45039663SJohn Forte * 206*45039663SJohn Forte * flag - open flag (OPEN_PPPT, OPEN_EXCL_PPPT) 207*45039663SJohn Forte * fd - pointer to integer. On success, contains the stmf file descriptor 208*45039663SJohn Forte */ 209*45039663SJohn Forte static int 210*45039663SJohn Forte openPppt(int flag, int *fd) 211*45039663SJohn Forte { 212*45039663SJohn Forte int ret = STMF_STATUS_ERROR; 213*45039663SJohn Forte 214*45039663SJohn Forte if ((*fd = open(PPPT_PATH, O_RDONLY | flag)) != -1) { 215*45039663SJohn Forte ret = STMF_STATUS_SUCCESS; 216*45039663SJohn Forte } else { 217*45039663SJohn Forte if (errno == EBUSY) { 218*45039663SJohn Forte ret = STMF_ERROR_BUSY; 219*45039663SJohn Forte } else if (errno == EACCES) { 220*45039663SJohn Forte ret = STMF_ERROR_PERM; 221*45039663SJohn Forte } else { 222*45039663SJohn Forte ret = STMF_STATUS_ERROR; 223*45039663SJohn Forte } 224*45039663SJohn Forte syslog(LOG_DEBUG, "openPppt:open failure:%s:errno(%d)", 225*45039663SJohn Forte PPPT_PATH, errno); 226*45039663SJohn Forte } 227*45039663SJohn Forte 228*45039663SJohn Forte return (ret); 229*45039663SJohn Forte } 230*45039663SJohn Forte 231*45039663SJohn Forte /* 232fcf3ce44SJohn Forte * initializeConfig 233fcf3ce44SJohn Forte * 234fcf3ce44SJohn Forte * This routine should be called before any ioctl requiring initialization 235fcf3ce44SJohn Forte * which is basically everything except stmfGetState(), setStmfState() and 236fcf3ce44SJohn Forte * stmfLoadConfig(). 237fcf3ce44SJohn Forte */ 238fcf3ce44SJohn Forte static int 239fcf3ce44SJohn Forte initializeConfig() 240fcf3ce44SJohn Forte { 241fcf3ce44SJohn Forte int ret; 242fcf3ce44SJohn Forte stmfState state; 243fcf3ce44SJohn Forte 244fcf3ce44SJohn Forte 245fcf3ce44SJohn Forte ret = stmfGetState(&state); 246fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 247fcf3ce44SJohn Forte return (ret); 248fcf3ce44SJohn Forte } 249fcf3ce44SJohn Forte 250fcf3ce44SJohn Forte /* if we've already initialized or in the process, return success */ 251fcf3ce44SJohn Forte if (state.configState == STMF_CONFIG_STATE_INIT_DONE || 252fcf3ce44SJohn Forte state.configState == STMF_CONFIG_STATE_INIT) { 253fcf3ce44SJohn Forte return (STMF_STATUS_SUCCESS); 254fcf3ce44SJohn Forte } 255fcf3ce44SJohn Forte 256fcf3ce44SJohn Forte ret = stmfLoadConfig(); 257fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 258fcf3ce44SJohn Forte syslog(LOG_DEBUG, 259fcf3ce44SJohn Forte "initializeConfig:stmfLoadConfig:error(%d)", ret); 260fcf3ce44SJohn Forte return (ret); 261fcf3ce44SJohn Forte } 262fcf3ce44SJohn Forte 263fcf3ce44SJohn Forte ret = stmfGetState(&state); 264fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 265fcf3ce44SJohn Forte syslog(LOG_DEBUG, 266fcf3ce44SJohn Forte "initializeConfig:stmfGetState:error(%d)", ret); 267fcf3ce44SJohn Forte return (ret); 268fcf3ce44SJohn Forte } 269fcf3ce44SJohn Forte 270fcf3ce44SJohn Forte if (state.configState != STMF_CONFIG_STATE_INIT_DONE) { 271fcf3ce44SJohn Forte syslog(LOG_DEBUG, "initializeConfig:state.configState(%d)", 272fcf3ce44SJohn Forte state.configState); 273fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 274fcf3ce44SJohn Forte } 275fcf3ce44SJohn Forte 276fcf3ce44SJohn Forte return (ret); 277fcf3ce44SJohn Forte } 278fcf3ce44SJohn Forte 279fcf3ce44SJohn Forte 280fcf3ce44SJohn Forte /* 281fcf3ce44SJohn Forte * groupIoctl 282fcf3ce44SJohn Forte * 283fcf3ce44SJohn Forte * Purpose: issue ioctl for create/delete on group 284fcf3ce44SJohn Forte * 285fcf3ce44SJohn Forte * cmd - valid STMF ioctl group cmd 286fcf3ce44SJohn Forte * groupName - groupName to create or delete 287fcf3ce44SJohn Forte */ 288fcf3ce44SJohn Forte static int 289fcf3ce44SJohn Forte groupIoctl(int fd, int cmd, stmfGroupName *groupName) 290fcf3ce44SJohn Forte { 291fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 292fcf3ce44SJohn Forte int ioctlRet; 293fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 294fcf3ce44SJohn Forte stmf_group_name_t iGroupName; 295fcf3ce44SJohn Forte 296fcf3ce44SJohn Forte bzero(&iGroupName, sizeof (iGroupName)); 297fcf3ce44SJohn Forte 298fcf3ce44SJohn Forte bcopy(groupName, &iGroupName.name, strlen((char *)groupName)); 299fcf3ce44SJohn Forte 300fcf3ce44SJohn Forte iGroupName.name_size = strlen((char *)groupName); 301fcf3ce44SJohn Forte 302fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 303fcf3ce44SJohn Forte /* 304fcf3ce44SJohn Forte * Issue ioctl to create the host group 305fcf3ce44SJohn Forte */ 306fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 307fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (iGroupName); 308fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&iGroupName; 309fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 310fcf3ce44SJohn Forte if (ioctlRet != 0) { 311fcf3ce44SJohn Forte switch (errno) { 3128fe96085Stim szeto case EPERM: 313fcf3ce44SJohn Forte case EACCES: 314fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 315fcf3ce44SJohn Forte break; 316fcf3ce44SJohn Forte default: 317fcf3ce44SJohn Forte switch (stmfIoctl.stmf_error) { 318fcf3ce44SJohn Forte case STMF_IOCERR_TG_EXISTS: 319fcf3ce44SJohn Forte case STMF_IOCERR_HG_EXISTS: 320fcf3ce44SJohn Forte ret = STMF_ERROR_EXISTS; 321fcf3ce44SJohn Forte break; 322fcf3ce44SJohn Forte case STMF_IOCERR_TG_IN_USE: 323fcf3ce44SJohn Forte case STMF_IOCERR_HG_IN_USE: 324fcf3ce44SJohn Forte ret = STMF_ERROR_GROUP_IN_USE; 325fcf3ce44SJohn Forte break; 326fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_HG: 327fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_TG: 328fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 329fcf3ce44SJohn Forte break; 330fcf3ce44SJohn Forte default: 331fcf3ce44SJohn Forte syslog(LOG_DEBUG, 332fcf3ce44SJohn Forte "groupIoctl:error(%d)", 333fcf3ce44SJohn Forte stmfIoctl.stmf_error); 334fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 335fcf3ce44SJohn Forte break; 336fcf3ce44SJohn Forte } 337fcf3ce44SJohn Forte break; 338fcf3ce44SJohn Forte } 339fcf3ce44SJohn Forte } 340fcf3ce44SJohn Forte done: 341fcf3ce44SJohn Forte return (ret); 342fcf3ce44SJohn Forte } 343fcf3ce44SJohn Forte 344fcf3ce44SJohn Forte /* 3458fe96085Stim szeto * groupMemberIoctl 346fcf3ce44SJohn Forte * 347fcf3ce44SJohn Forte * Purpose: issue ioctl for add/remove member on group 348fcf3ce44SJohn Forte * 349fcf3ce44SJohn Forte * cmd - valid STMF ioctl group member cmd 350fcf3ce44SJohn Forte * groupName - groupName to add to or remove from 351fcf3ce44SJohn Forte * devid - group member to add or remove 352fcf3ce44SJohn Forte */ 353fcf3ce44SJohn Forte static int 354fcf3ce44SJohn Forte groupMemberIoctl(int fd, int cmd, stmfGroupName *groupName, stmfDevid *devid) 355fcf3ce44SJohn Forte { 356fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 357fcf3ce44SJohn Forte int ioctlRet; 358fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 359fcf3ce44SJohn Forte stmf_group_op_data_t stmfGroupData; 360fcf3ce44SJohn Forte 361fcf3ce44SJohn Forte bzero(&stmfGroupData, sizeof (stmfGroupData)); 362fcf3ce44SJohn Forte 363fcf3ce44SJohn Forte bcopy(groupName, &stmfGroupData.group.name, strlen((char *)groupName)); 364fcf3ce44SJohn Forte 365fcf3ce44SJohn Forte stmfGroupData.group.name_size = strlen((char *)groupName); 366fcf3ce44SJohn Forte stmfGroupData.ident[IDENT_LENGTH_BYTE] = devid->identLength; 367fcf3ce44SJohn Forte bcopy(&(devid->ident), &stmfGroupData.ident[IDENT_LENGTH_BYTE + 1], 368fcf3ce44SJohn Forte devid->identLength); 369fcf3ce44SJohn Forte 370fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 371fcf3ce44SJohn Forte /* 372fcf3ce44SJohn Forte * Issue ioctl to add to the host group 373fcf3ce44SJohn Forte */ 374fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 375fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmfGroupData); 376fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&stmfGroupData; 377fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 378fcf3ce44SJohn Forte if (ioctlRet != 0) { 379fcf3ce44SJohn Forte switch (errno) { 380fcf3ce44SJohn Forte case EBUSY: 3815c8cac22Stim szeto switch (stmfIoctl.stmf_error) { 3825c8cac22Stim szeto case STMF_IOCERR_TG_NEED_TG_OFFLINE: 3835c8cac22Stim szeto ret = STMF_ERROR_TG_ONLINE; 3845c8cac22Stim szeto break; 3855c8cac22Stim szeto default: 386fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 387fcf3ce44SJohn Forte break; 3885c8cac22Stim szeto } 3895c8cac22Stim szeto break; 3908fe96085Stim szeto case EPERM: 391fcf3ce44SJohn Forte case EACCES: 392fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 393fcf3ce44SJohn Forte break; 394fcf3ce44SJohn Forte default: 395fcf3ce44SJohn Forte switch (stmfIoctl.stmf_error) { 396fcf3ce44SJohn Forte case STMF_IOCERR_TG_ENTRY_EXISTS: 397fcf3ce44SJohn Forte case STMF_IOCERR_HG_ENTRY_EXISTS: 398fcf3ce44SJohn Forte ret = STMF_ERROR_EXISTS; 399fcf3ce44SJohn Forte break; 400fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_TG_ENTRY: 401fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_HG_ENTRY: 402fcf3ce44SJohn Forte ret = 403fcf3ce44SJohn Forte STMF_ERROR_MEMBER_NOT_FOUND; 404fcf3ce44SJohn Forte break; 405fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_TG: 406fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_HG: 407fcf3ce44SJohn Forte ret = 408fcf3ce44SJohn Forte STMF_ERROR_GROUP_NOT_FOUND; 409fcf3ce44SJohn Forte break; 410fcf3ce44SJohn Forte default: 411fcf3ce44SJohn Forte syslog(LOG_DEBUG, 412fcf3ce44SJohn Forte "groupMemberIoctl:error" 413fcf3ce44SJohn Forte "(%d)", 414fcf3ce44SJohn Forte stmfIoctl.stmf_error); 415fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 416fcf3ce44SJohn Forte break; 417fcf3ce44SJohn Forte } 418fcf3ce44SJohn Forte break; 419fcf3ce44SJohn Forte } 420fcf3ce44SJohn Forte } 421fcf3ce44SJohn Forte done: 422fcf3ce44SJohn Forte return (ret); 423fcf3ce44SJohn Forte } 424fcf3ce44SJohn Forte 425fcf3ce44SJohn Forte /* 4268fe96085Stim szeto * qsort function 4278fe96085Stim szeto * sort on veIndex 4288fe96085Stim szeto */ 4298fe96085Stim szeto static int 4308fe96085Stim szeto viewEntryCompare(const void *p1, const void *p2) 4318fe96085Stim szeto { 4328fe96085Stim szeto 4338fe96085Stim szeto stmfViewEntry *v1 = (stmfViewEntry *)p1, *v2 = (stmfViewEntry *)p2; 4348fe96085Stim szeto if (v1->veIndex > v2->veIndex) 4358fe96085Stim szeto return (1); 4368fe96085Stim szeto if (v1->veIndex < v2->veIndex) 4378fe96085Stim szeto return (-1); 4388fe96085Stim szeto return (0); 4398fe96085Stim szeto } 4408fe96085Stim szeto 4418fe96085Stim szeto /* 442fcf3ce44SJohn Forte * guidCompare 443fcf3ce44SJohn Forte * 444fcf3ce44SJohn Forte * qsort function 445fcf3ce44SJohn Forte * sort on guid 446fcf3ce44SJohn Forte */ 447fcf3ce44SJohn Forte static int 448fcf3ce44SJohn Forte guidCompare(const void *p1, const void *p2) 449fcf3ce44SJohn Forte { 450fcf3ce44SJohn Forte 451fcf3ce44SJohn Forte stmfGuid *g1 = (stmfGuid *)p1, *g2 = (stmfGuid *)p2; 452fcf3ce44SJohn Forte int i; 453fcf3ce44SJohn Forte 454fcf3ce44SJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) { 455fcf3ce44SJohn Forte if (g1->guid[i] > g2->guid[i]) 456fcf3ce44SJohn Forte return (1); 457fcf3ce44SJohn Forte if (g1->guid[i] < g2->guid[i]) 458fcf3ce44SJohn Forte return (-1); 459fcf3ce44SJohn Forte } 460fcf3ce44SJohn Forte 461fcf3ce44SJohn Forte return (0); 462fcf3ce44SJohn Forte } 463fcf3ce44SJohn Forte 464fcf3ce44SJohn Forte /* 465fcf3ce44SJohn Forte * stmfAddToHostGroup 466fcf3ce44SJohn Forte * 467fcf3ce44SJohn Forte * Purpose: Adds an initiator to an existing host group 468fcf3ce44SJohn Forte * 469fcf3ce44SJohn Forte * hostGroupName - name of an existing host group 470fcf3ce44SJohn Forte * hostName - name of initiator to add 471fcf3ce44SJohn Forte */ 472fcf3ce44SJohn Forte int 473fcf3ce44SJohn Forte stmfAddToHostGroup(stmfGroupName *hostGroupName, stmfDevid *hostName) 474fcf3ce44SJohn Forte { 475fcf3ce44SJohn Forte int ret; 476fcf3ce44SJohn Forte int fd; 477fcf3ce44SJohn Forte 478fcf3ce44SJohn Forte if (hostGroupName == NULL || 479fcf3ce44SJohn Forte (strnlen((char *)hostGroupName, sizeof (stmfGroupName)) 480fcf3ce44SJohn Forte == sizeof (stmfGroupName)) || hostName == NULL) { 481fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 482fcf3ce44SJohn Forte } 483fcf3ce44SJohn Forte 484fcf3ce44SJohn Forte /* call init */ 485fcf3ce44SJohn Forte ret = initializeConfig(); 486fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 487fcf3ce44SJohn Forte return (ret); 488fcf3ce44SJohn Forte } 489fcf3ce44SJohn Forte 490fcf3ce44SJohn Forte /* 491fcf3ce44SJohn Forte * Open control node for stmf 492fcf3ce44SJohn Forte */ 493fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 494fcf3ce44SJohn Forte return (ret); 495fcf3ce44SJohn Forte 496fcf3ce44SJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_HG_ENTRY, hostGroupName, 497fcf3ce44SJohn Forte hostName)) != STMF_STATUS_SUCCESS) { 498fcf3ce44SJohn Forte goto done; 499fcf3ce44SJohn Forte } 500fcf3ce44SJohn Forte 5018fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 5028fe96085Stim szeto goto done; 5038fe96085Stim szeto } 5048fe96085Stim szeto 505fcf3ce44SJohn Forte ret = psAddHostGroupMember((char *)hostGroupName, 506fcf3ce44SJohn Forte (char *)hostName->ident); 507fcf3ce44SJohn Forte switch (ret) { 508fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 509fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 510fcf3ce44SJohn Forte break; 511fcf3ce44SJohn Forte case STMF_PS_ERROR_EXISTS: 512fcf3ce44SJohn Forte ret = STMF_ERROR_EXISTS; 513fcf3ce44SJohn Forte break; 514fcf3ce44SJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND: 515fcf3ce44SJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND; 516fcf3ce44SJohn Forte break; 517fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 518fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 519fcf3ce44SJohn Forte break; 520fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 521fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 522fcf3ce44SJohn Forte break; 523fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 524fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 525fcf3ce44SJohn Forte break; 526fcf3ce44SJohn Forte default: 527fcf3ce44SJohn Forte syslog(LOG_DEBUG, 528fcf3ce44SJohn Forte "stmfAddToHostGroup:psAddHostGroupMember:error(%d)", 529fcf3ce44SJohn Forte ret); 530fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 531fcf3ce44SJohn Forte break; 532fcf3ce44SJohn Forte } 533fcf3ce44SJohn Forte 534fcf3ce44SJohn Forte done: 535fcf3ce44SJohn Forte (void) close(fd); 536fcf3ce44SJohn Forte return (ret); 537fcf3ce44SJohn Forte } 538fcf3ce44SJohn Forte 539fcf3ce44SJohn Forte /* 540fcf3ce44SJohn Forte * stmfAddToTargetGroup 541fcf3ce44SJohn Forte * 542fcf3ce44SJohn Forte * Purpose: Adds a local port to an existing target group 543fcf3ce44SJohn Forte * 544fcf3ce44SJohn Forte * targetGroupName - name of an existing target group 545fcf3ce44SJohn Forte * targetName - name of target to add 546fcf3ce44SJohn Forte */ 547fcf3ce44SJohn Forte int 548fcf3ce44SJohn Forte stmfAddToTargetGroup(stmfGroupName *targetGroupName, stmfDevid *targetName) 549fcf3ce44SJohn Forte { 550fcf3ce44SJohn Forte int ret; 551fcf3ce44SJohn Forte int fd; 552fcf3ce44SJohn Forte 553fcf3ce44SJohn Forte if (targetGroupName == NULL || 554fcf3ce44SJohn Forte (strnlen((char *)targetGroupName, sizeof (stmfGroupName)) 555fcf3ce44SJohn Forte == sizeof (stmfGroupName)) || targetName == NULL) { 556fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 557fcf3ce44SJohn Forte } 558fcf3ce44SJohn Forte 559fcf3ce44SJohn Forte /* call init */ 560fcf3ce44SJohn Forte ret = initializeConfig(); 561fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 562fcf3ce44SJohn Forte return (ret); 563fcf3ce44SJohn Forte } 564fcf3ce44SJohn Forte 565fcf3ce44SJohn Forte /* 566fcf3ce44SJohn Forte * Open control node for stmf 567fcf3ce44SJohn Forte */ 568fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 569fcf3ce44SJohn Forte return (ret); 570fcf3ce44SJohn Forte 571fcf3ce44SJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_TG_ENTRY, 572fcf3ce44SJohn Forte targetGroupName, targetName)) != STMF_STATUS_SUCCESS) { 573fcf3ce44SJohn Forte goto done; 574fcf3ce44SJohn Forte } 575fcf3ce44SJohn Forte 5768fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 5778fe96085Stim szeto goto done; 5788fe96085Stim szeto } 5798fe96085Stim szeto 580fcf3ce44SJohn Forte ret = psAddTargetGroupMember((char *)targetGroupName, 581fcf3ce44SJohn Forte (char *)targetName->ident); 582fcf3ce44SJohn Forte switch (ret) { 583fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 584fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 585fcf3ce44SJohn Forte break; 586fcf3ce44SJohn Forte case STMF_PS_ERROR_EXISTS: 587fcf3ce44SJohn Forte ret = STMF_ERROR_EXISTS; 588fcf3ce44SJohn Forte break; 589fcf3ce44SJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND: 590fcf3ce44SJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND; 591fcf3ce44SJohn Forte break; 592fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 593fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 594fcf3ce44SJohn Forte break; 595fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 596fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 597fcf3ce44SJohn Forte break; 598fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 599fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 600fcf3ce44SJohn Forte break; 601fcf3ce44SJohn Forte default: 602fcf3ce44SJohn Forte syslog(LOG_DEBUG, 603fcf3ce44SJohn Forte "stmfAddToTargetGroup:psAddTargetGroupMember:" 604fcf3ce44SJohn Forte "error(%d)", ret); 605fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 606fcf3ce44SJohn Forte break; 607fcf3ce44SJohn Forte } 608fcf3ce44SJohn Forte 609fcf3ce44SJohn Forte done: 610fcf3ce44SJohn Forte (void) close(fd); 611fcf3ce44SJohn Forte return (ret); 612fcf3ce44SJohn Forte } 613fcf3ce44SJohn Forte 614fcf3ce44SJohn Forte /* 615fcf3ce44SJohn Forte * addViewEntryIoctl 616fcf3ce44SJohn Forte * 617fcf3ce44SJohn Forte * Purpose: Issues ioctl to add a view entry 618fcf3ce44SJohn Forte * 619fcf3ce44SJohn Forte * lu - Logical Unit identifier to which the view entry is added 620fcf3ce44SJohn Forte * viewEntry - view entry to add 621fcf3ce44SJohn Forte * init - When set to B_TRUE, we are in the init state, i.e. don't call open 622fcf3ce44SJohn Forte */ 623fcf3ce44SJohn Forte static int 624fcf3ce44SJohn Forte addViewEntryIoctl(int fd, stmfGuid *lu, stmfViewEntry *viewEntry) 625fcf3ce44SJohn Forte { 626fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 627fcf3ce44SJohn Forte int ioctlRet; 628fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 629fcf3ce44SJohn Forte stmf_view_op_entry_t ioctlViewEntry; 630fcf3ce44SJohn Forte 631fcf3ce44SJohn Forte bzero(&ioctlViewEntry, sizeof (ioctlViewEntry)); 632fcf3ce44SJohn Forte /* 633fcf3ce44SJohn Forte * don't set ve_ndx or ve_ndx_valid as ve_ndx_valid should be 634fcf3ce44SJohn Forte * false on input 635fcf3ce44SJohn Forte */ 636fcf3ce44SJohn Forte ioctlViewEntry.ve_lu_number_valid = viewEntry->luNbrValid; 637fcf3ce44SJohn Forte ioctlViewEntry.ve_all_hosts = viewEntry->allHosts; 638fcf3ce44SJohn Forte ioctlViewEntry.ve_all_targets = viewEntry->allTargets; 639fcf3ce44SJohn Forte 640fcf3ce44SJohn Forte if (viewEntry->allHosts == B_FALSE) { 641fcf3ce44SJohn Forte bcopy(viewEntry->hostGroup, &ioctlViewEntry.ve_host_group.name, 642fcf3ce44SJohn Forte sizeof (stmfGroupName)); 643fcf3ce44SJohn Forte ioctlViewEntry.ve_host_group.name_size = 644fcf3ce44SJohn Forte strlen((char *)viewEntry->hostGroup); 645fcf3ce44SJohn Forte } 646fcf3ce44SJohn Forte if (viewEntry->allTargets == B_FALSE) { 647fcf3ce44SJohn Forte bcopy(viewEntry->targetGroup, 648fcf3ce44SJohn Forte &ioctlViewEntry.ve_target_group.name, 649fcf3ce44SJohn Forte sizeof (stmfGroupName)); 650fcf3ce44SJohn Forte ioctlViewEntry.ve_target_group.name_size = 651fcf3ce44SJohn Forte strlen((char *)viewEntry->targetGroup); 652fcf3ce44SJohn Forte } 653fcf3ce44SJohn Forte if (viewEntry->luNbrValid) { 654fcf3ce44SJohn Forte bcopy(viewEntry->luNbr, &ioctlViewEntry.ve_lu_nbr, 655fcf3ce44SJohn Forte sizeof (ioctlViewEntry.ve_lu_nbr)); 656fcf3ce44SJohn Forte } 657fcf3ce44SJohn Forte bcopy(lu, &ioctlViewEntry.ve_guid, sizeof (stmfGuid)); 658fcf3ce44SJohn Forte 659fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 660fcf3ce44SJohn Forte /* 661fcf3ce44SJohn Forte * Issue ioctl to add to the view entry 662fcf3ce44SJohn Forte */ 663fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 664fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (ioctlViewEntry); 665fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ioctlViewEntry; 666fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = sizeof (ioctlViewEntry); 667fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&ioctlViewEntry; 668fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_ADD_VIEW_ENTRY, &stmfIoctl); 669fcf3ce44SJohn Forte if (ioctlRet != 0) { 670fcf3ce44SJohn Forte switch (errno) { 671fcf3ce44SJohn Forte case EBUSY: 672fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 673fcf3ce44SJohn Forte break; 6748fe96085Stim szeto case EPERM: 6758fe96085Stim szeto ret = STMF_ERROR_PERM; 6768fe96085Stim szeto break; 677fcf3ce44SJohn Forte case EACCES: 678fcf3ce44SJohn Forte switch (stmfIoctl.stmf_error) { 679fcf3ce44SJohn Forte case STMF_IOCERR_UPDATE_NEED_CFG_INIT: 680fcf3ce44SJohn Forte ret = STMF_ERROR_CONFIG_NONE; 681fcf3ce44SJohn Forte break; 682fcf3ce44SJohn Forte default: 683fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 684fcf3ce44SJohn Forte break; 685fcf3ce44SJohn Forte } 686fcf3ce44SJohn Forte break; 687fcf3ce44SJohn Forte default: 688fcf3ce44SJohn Forte switch (stmfIoctl.stmf_error) { 689fcf3ce44SJohn Forte case STMF_IOCERR_LU_NUMBER_IN_USE: 690fcf3ce44SJohn Forte ret = STMF_ERROR_LUN_IN_USE; 691fcf3ce44SJohn Forte break; 692fcf3ce44SJohn Forte case STMF_IOCERR_VIEW_ENTRY_CONFLICT: 693fcf3ce44SJohn Forte ret = STMF_ERROR_VE_CONFLICT; 694fcf3ce44SJohn Forte break; 695fcf3ce44SJohn Forte case STMF_IOCERR_UPDATE_NEED_CFG_INIT: 696fcf3ce44SJohn Forte ret = STMF_ERROR_CONFIG_NONE; 697fcf3ce44SJohn Forte break; 698fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_HG: 699fcf3ce44SJohn Forte ret = STMF_ERROR_INVALID_HG; 700fcf3ce44SJohn Forte break; 701fcf3ce44SJohn Forte case STMF_IOCERR_INVALID_TG: 702fcf3ce44SJohn Forte ret = STMF_ERROR_INVALID_TG; 703fcf3ce44SJohn Forte break; 704fcf3ce44SJohn Forte default: 705fcf3ce44SJohn Forte syslog(LOG_DEBUG, 706fcf3ce44SJohn Forte "addViewEntryIoctl" 707fcf3ce44SJohn Forte ":error(%d)", 708fcf3ce44SJohn Forte stmfIoctl.stmf_error); 709fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 710fcf3ce44SJohn Forte break; 711fcf3ce44SJohn Forte } 712fcf3ce44SJohn Forte break; 713fcf3ce44SJohn Forte } 714fcf3ce44SJohn Forte goto done; 715fcf3ce44SJohn Forte } 716fcf3ce44SJohn Forte 717fcf3ce44SJohn Forte /* copy lu nbr back to caller's view entry on success */ 718fcf3ce44SJohn Forte viewEntry->veIndex = ioctlViewEntry.ve_ndx; 719fcf3ce44SJohn Forte if (ioctlViewEntry.ve_lu_number_valid) { 720fcf3ce44SJohn Forte bcopy(&ioctlViewEntry.ve_lu_nbr, viewEntry->luNbr, 721fcf3ce44SJohn Forte sizeof (ioctlViewEntry.ve_lu_nbr)); 722fcf3ce44SJohn Forte } 723fcf3ce44SJohn Forte viewEntry->luNbrValid = B_TRUE; 724fcf3ce44SJohn Forte 725fcf3ce44SJohn Forte done: 726fcf3ce44SJohn Forte return (ret); 727fcf3ce44SJohn Forte } 728fcf3ce44SJohn Forte 729fcf3ce44SJohn Forte /* 730fcf3ce44SJohn Forte * stmfAddViewEntry 731fcf3ce44SJohn Forte * 732fcf3ce44SJohn Forte * Purpose: Adds a view entry to a logical unit 733fcf3ce44SJohn Forte * 734fcf3ce44SJohn Forte * lu - guid of the logical unit to which the view entry is added 735fcf3ce44SJohn Forte * viewEntry - view entry structure to add 736fcf3ce44SJohn Forte */ 737fcf3ce44SJohn Forte int 738fcf3ce44SJohn Forte stmfAddViewEntry(stmfGuid *lu, stmfViewEntry *viewEntry) 739fcf3ce44SJohn Forte { 740fcf3ce44SJohn Forte int ret; 741fcf3ce44SJohn Forte int fd; 742fcf3ce44SJohn Forte stmfViewEntry iViewEntry; 743fcf3ce44SJohn Forte 744fcf3ce44SJohn Forte if (lu == NULL || viewEntry == NULL) { 745fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 746fcf3ce44SJohn Forte } 747fcf3ce44SJohn Forte 748fcf3ce44SJohn Forte /* initialize and set internal view entry */ 749fcf3ce44SJohn Forte bzero(&iViewEntry, sizeof (iViewEntry)); 750fcf3ce44SJohn Forte 751fcf3ce44SJohn Forte if (!viewEntry->allHosts) { 752fcf3ce44SJohn Forte bcopy(viewEntry->hostGroup, iViewEntry.hostGroup, 753fcf3ce44SJohn Forte sizeof (iViewEntry.hostGroup)); 754fcf3ce44SJohn Forte } else { 755fcf3ce44SJohn Forte iViewEntry.allHosts = B_TRUE; 756fcf3ce44SJohn Forte } 757fcf3ce44SJohn Forte 758fcf3ce44SJohn Forte if (!viewEntry->allTargets) { 759fcf3ce44SJohn Forte bcopy(viewEntry->targetGroup, iViewEntry.targetGroup, 760fcf3ce44SJohn Forte sizeof (iViewEntry.targetGroup)); 761fcf3ce44SJohn Forte } else { 762fcf3ce44SJohn Forte iViewEntry.allTargets = B_TRUE; 763fcf3ce44SJohn Forte } 764fcf3ce44SJohn Forte 765fcf3ce44SJohn Forte if (viewEntry->luNbrValid) { 766fcf3ce44SJohn Forte iViewEntry.luNbrValid = B_TRUE; 767fcf3ce44SJohn Forte bcopy(viewEntry->luNbr, iViewEntry.luNbr, 768fcf3ce44SJohn Forte sizeof (iViewEntry.luNbr)); 769fcf3ce44SJohn Forte } 770fcf3ce44SJohn Forte 771fcf3ce44SJohn Forte /* 772fcf3ce44SJohn Forte * set users return view entry index valid flag to false 773fcf3ce44SJohn Forte * in case of failure 774fcf3ce44SJohn Forte */ 775fcf3ce44SJohn Forte viewEntry->veIndexValid = B_FALSE; 776fcf3ce44SJohn Forte 777fcf3ce44SJohn Forte /* Check to ensure service exists */ 778fcf3ce44SJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) { 779fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND); 780fcf3ce44SJohn Forte } 781fcf3ce44SJohn Forte 782fcf3ce44SJohn Forte /* call init */ 783fcf3ce44SJohn Forte ret = initializeConfig(); 784fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 785fcf3ce44SJohn Forte return (ret); 786fcf3ce44SJohn Forte } 787fcf3ce44SJohn Forte 788fcf3ce44SJohn Forte /* 789fcf3ce44SJohn Forte * Open control node for stmf 790fcf3ce44SJohn Forte */ 791fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 792fcf3ce44SJohn Forte return (ret); 793fcf3ce44SJohn Forte 794fcf3ce44SJohn Forte /* 795fcf3ce44SJohn Forte * First add the view entry to the driver 796fcf3ce44SJohn Forte */ 797fcf3ce44SJohn Forte ret = addViewEntryIoctl(fd, lu, &iViewEntry); 798fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 799fcf3ce44SJohn Forte goto done; 800fcf3ce44SJohn Forte } 801fcf3ce44SJohn Forte 8028fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 8038fe96085Stim szeto goto done; 8048fe96085Stim szeto } 8058fe96085Stim szeto 806fcf3ce44SJohn Forte /* 807fcf3ce44SJohn Forte * If the add to driver was successful, add it to the persistent 808fcf3ce44SJohn Forte * store. 809fcf3ce44SJohn Forte */ 810fcf3ce44SJohn Forte ret = psAddViewEntry(lu, &iViewEntry); 811fcf3ce44SJohn Forte switch (ret) { 812fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 813fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 814fcf3ce44SJohn Forte break; 815fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 816fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 817fcf3ce44SJohn Forte break; 818fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 819fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 820fcf3ce44SJohn Forte break; 821fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 822fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 823fcf3ce44SJohn Forte break; 824fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 825fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 826fcf3ce44SJohn Forte break; 827fcf3ce44SJohn Forte default: 828fcf3ce44SJohn Forte syslog(LOG_DEBUG, 829fcf3ce44SJohn Forte "stmfAddViewEntry:psAddViewEntry:error(%d)", ret); 830fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 831fcf3ce44SJohn Forte break; 832fcf3ce44SJohn Forte } 833fcf3ce44SJohn Forte 834fcf3ce44SJohn Forte done: 835fcf3ce44SJohn Forte (void) close(fd); 836fcf3ce44SJohn Forte 837fcf3ce44SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 838fcf3ce44SJohn Forte /* set caller's view entry on success */ 839fcf3ce44SJohn Forte viewEntry->veIndexValid = iViewEntry.veIndexValid; 840fcf3ce44SJohn Forte viewEntry->veIndex = iViewEntry.veIndex; 841fcf3ce44SJohn Forte viewEntry->luNbrValid = B_TRUE; 842fcf3ce44SJohn Forte bcopy(iViewEntry.luNbr, viewEntry->luNbr, 843fcf3ce44SJohn Forte sizeof (iViewEntry.luNbr)); 844fcf3ce44SJohn Forte } 845fcf3ce44SJohn Forte return (ret); 846fcf3ce44SJohn Forte } 847fcf3ce44SJohn Forte 848fcf3ce44SJohn Forte /* 849fcf3ce44SJohn Forte * stmfClearProviderData 850fcf3ce44SJohn Forte * 851fcf3ce44SJohn Forte * Purpose: delete all provider data for specified provider 852fcf3ce44SJohn Forte * 853fcf3ce44SJohn Forte * providerName - name of provider for which data should be deleted 854fcf3ce44SJohn Forte */ 855fcf3ce44SJohn Forte int 856fcf3ce44SJohn Forte stmfClearProviderData(char *providerName, int providerType) 857fcf3ce44SJohn Forte { 858fcf3ce44SJohn Forte int ret; 859fcf3ce44SJohn Forte int fd; 860fcf3ce44SJohn Forte int ioctlRet; 861fcf3ce44SJohn Forte int savedErrno; 862fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 863fcf3ce44SJohn Forte stmf_ppioctl_data_t ppi; 864fcf3ce44SJohn Forte 865fcf3ce44SJohn Forte /* call init */ 866fcf3ce44SJohn Forte ret = initializeConfig(); 867fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 868fcf3ce44SJohn Forte return (ret); 869fcf3ce44SJohn Forte } 870fcf3ce44SJohn Forte 871fcf3ce44SJohn Forte if (providerName == NULL) { 872fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 873fcf3ce44SJohn Forte } 874fcf3ce44SJohn Forte 875fcf3ce44SJohn Forte if (providerType != STMF_LU_PROVIDER_TYPE && 876fcf3ce44SJohn Forte providerType != STMF_PORT_PROVIDER_TYPE) { 877fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 878fcf3ce44SJohn Forte } 879fcf3ce44SJohn Forte 880fcf3ce44SJohn Forte /* 881fcf3ce44SJohn Forte * Open control node for stmf 882fcf3ce44SJohn Forte */ 883fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 884fcf3ce44SJohn Forte return (ret); 885fcf3ce44SJohn Forte 886fcf3ce44SJohn Forte bzero(&ppi, sizeof (ppi)); 887fcf3ce44SJohn Forte 888fcf3ce44SJohn Forte (void) strncpy(ppi.ppi_name, providerName, sizeof (ppi.ppi_name)); 889fcf3ce44SJohn Forte 890fcf3ce44SJohn Forte switch (providerType) { 891fcf3ce44SJohn Forte case STMF_LU_PROVIDER_TYPE: 892fcf3ce44SJohn Forte ppi.ppi_lu_provider = 1; 893fcf3ce44SJohn Forte break; 894fcf3ce44SJohn Forte case STMF_PORT_PROVIDER_TYPE: 895fcf3ce44SJohn Forte ppi.ppi_port_provider = 1; 896fcf3ce44SJohn Forte break; 897fcf3ce44SJohn Forte default: 898fcf3ce44SJohn Forte ret = STMF_ERROR_INVALID_ARG; 899fcf3ce44SJohn Forte goto done; 900fcf3ce44SJohn Forte } 901fcf3ce44SJohn Forte 902fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 903fcf3ce44SJohn Forte 904fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 905fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmf_ppioctl_data_t); 906fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ppi; 907fcf3ce44SJohn Forte 908fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_CLEAR_PP_DATA, &stmfIoctl); 909fcf3ce44SJohn Forte if (ioctlRet != 0) { 910fcf3ce44SJohn Forte savedErrno = errno; 911fcf3ce44SJohn Forte switch (savedErrno) { 912fcf3ce44SJohn Forte case EBUSY: 913fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 914fcf3ce44SJohn Forte break; 9158fe96085Stim szeto case EPERM: 916fcf3ce44SJohn Forte case EACCES: 917fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 918fcf3ce44SJohn Forte break; 919fcf3ce44SJohn Forte default: 920fcf3ce44SJohn Forte syslog(LOG_DEBUG, 921fcf3ce44SJohn Forte "stmfClearProviderData:ioctl error(%d)", 922fcf3ce44SJohn Forte ioctlRet); 923fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 924fcf3ce44SJohn Forte break; 925fcf3ce44SJohn Forte } 926fcf3ce44SJohn Forte if (savedErrno != ENOENT) { 927fcf3ce44SJohn Forte goto done; 928fcf3ce44SJohn Forte } 929fcf3ce44SJohn Forte } 930fcf3ce44SJohn Forte 9318fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 9328fe96085Stim szeto goto done; 9338fe96085Stim szeto } 9348fe96085Stim szeto 935fcf3ce44SJohn Forte ret = psClearProviderData(providerName, providerType); 936fcf3ce44SJohn Forte switch (ret) { 937fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 938fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 939fcf3ce44SJohn Forte break; 940fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 941fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 942fcf3ce44SJohn Forte break; 943fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 944fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 945fcf3ce44SJohn Forte break; 946fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 947fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 948fcf3ce44SJohn Forte break; 949fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 950fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 951fcf3ce44SJohn Forte break; 952fcf3ce44SJohn Forte default: 953fcf3ce44SJohn Forte syslog(LOG_DEBUG, 954fcf3ce44SJohn Forte "stmfClearProviderData:psClearProviderData" 955fcf3ce44SJohn Forte ":error(%d)", ret); 956fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 957fcf3ce44SJohn Forte break; 958fcf3ce44SJohn Forte } 959fcf3ce44SJohn Forte 960fcf3ce44SJohn Forte done: 961fcf3ce44SJohn Forte (void) close(fd); 962fcf3ce44SJohn Forte return (ret); 963fcf3ce44SJohn Forte } 964fcf3ce44SJohn Forte 965fcf3ce44SJohn Forte /* 966fcf3ce44SJohn Forte * stmfCreateHostGroup 967fcf3ce44SJohn Forte * 968fcf3ce44SJohn Forte * Purpose: Create a new initiator group 969fcf3ce44SJohn Forte * 970fcf3ce44SJohn Forte * hostGroupName - name of host group to create 971fcf3ce44SJohn Forte */ 972fcf3ce44SJohn Forte int 973fcf3ce44SJohn Forte stmfCreateHostGroup(stmfGroupName *hostGroupName) 974fcf3ce44SJohn Forte { 975fcf3ce44SJohn Forte int ret; 976fcf3ce44SJohn Forte int fd; 977fcf3ce44SJohn Forte 978fcf3ce44SJohn Forte if (hostGroupName == NULL || 979fcf3ce44SJohn Forte (strnlen((char *)hostGroupName, sizeof (stmfGroupName)) 980fcf3ce44SJohn Forte == sizeof (stmfGroupName))) { 981fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 982fcf3ce44SJohn Forte } 983fcf3ce44SJohn Forte 984fcf3ce44SJohn Forte /* Check to ensure service exists */ 985fcf3ce44SJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) { 986fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND); 987fcf3ce44SJohn Forte } 988fcf3ce44SJohn Forte 989fcf3ce44SJohn Forte /* call init */ 990fcf3ce44SJohn Forte ret = initializeConfig(); 991fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 992fcf3ce44SJohn Forte return (ret); 993fcf3ce44SJohn Forte } 994fcf3ce44SJohn Forte 995fcf3ce44SJohn Forte /* 996fcf3ce44SJohn Forte * Open control node for stmf 997fcf3ce44SJohn Forte */ 998fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 999fcf3ce44SJohn Forte return (ret); 1000fcf3ce44SJohn Forte 1001fcf3ce44SJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_HOST_GROUP, 1002fcf3ce44SJohn Forte hostGroupName)) != STMF_STATUS_SUCCESS) { 1003fcf3ce44SJohn Forte goto done; 1004fcf3ce44SJohn Forte } 1005fcf3ce44SJohn Forte 10068fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 10078fe96085Stim szeto goto done; 10088fe96085Stim szeto } 10098fe96085Stim szeto 1010fcf3ce44SJohn Forte ret = psCreateHostGroup((char *)hostGroupName); 1011fcf3ce44SJohn Forte switch (ret) { 1012fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 1013fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 1014fcf3ce44SJohn Forte break; 1015fcf3ce44SJohn Forte case STMF_PS_ERROR_EXISTS: 1016fcf3ce44SJohn Forte ret = STMF_ERROR_EXISTS; 1017fcf3ce44SJohn Forte break; 1018fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 1019fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 1020fcf3ce44SJohn Forte break; 1021fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 1022fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 1023fcf3ce44SJohn Forte break; 1024fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 1025fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 1026fcf3ce44SJohn Forte break; 1027fcf3ce44SJohn Forte default: 1028fcf3ce44SJohn Forte syslog(LOG_DEBUG, 1029fcf3ce44SJohn Forte "stmfCreateHostGroup:psCreateHostGroup:error(%d)", 1030fcf3ce44SJohn Forte ret); 1031fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 1032fcf3ce44SJohn Forte break; 1033fcf3ce44SJohn Forte } 1034fcf3ce44SJohn Forte 1035fcf3ce44SJohn Forte done: 1036fcf3ce44SJohn Forte (void) close(fd); 1037fcf3ce44SJohn Forte return (ret); 1038fcf3ce44SJohn Forte } 1039fcf3ce44SJohn Forte 1040fcf3ce44SJohn Forte /* 10418fe96085Stim szeto * stmfCreateLu 10428fe96085Stim szeto * 10438fe96085Stim szeto * Purpose: Create a logical unit 10448fe96085Stim szeto * 10458fe96085Stim szeto * hdl - handle to logical unit resource created via stmfCreateLuResource 10468fe96085Stim szeto * 10478fe96085Stim szeto * luGuid - If non-NULL, on success, contains the guid of the created logical 10488fe96085Stim szeto * unit 10498fe96085Stim szeto */ 10508fe96085Stim szeto int 10518fe96085Stim szeto stmfCreateLu(luResource hdl, stmfGuid *luGuid) 10528fe96085Stim szeto { 10538fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 10548fe96085Stim szeto luResourceImpl *luPropsHdl = hdl; 10558fe96085Stim szeto 10568fe96085Stim szeto if (hdl == NULL) { 10578fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 10588fe96085Stim szeto } 10598fe96085Stim szeto 10608fe96085Stim szeto if (luPropsHdl->type == STMF_DISK) { 10618fe96085Stim szeto ret = createDiskLu((diskResource *)luPropsHdl->resource, 10628fe96085Stim szeto luGuid); 10638fe96085Stim szeto } else { 10648fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 10658fe96085Stim szeto } 10668fe96085Stim szeto 10678fe96085Stim szeto return (ret); 10688fe96085Stim szeto } 10698fe96085Stim szeto 10708fe96085Stim szeto /* 10718fe96085Stim szeto * stmfCreateLuResource 10728fe96085Stim szeto * 10738fe96085Stim szeto * Purpose: Create resource handle for a logical unit 10748fe96085Stim szeto * 10758fe96085Stim szeto * dType - Type of logical unit resource to create 10768fe96085Stim szeto * Can be: STMF_DISK 10778fe96085Stim szeto * 10788fe96085Stim szeto * hdl - pointer to luResource 10798fe96085Stim szeto */ 10808fe96085Stim szeto int 10818fe96085Stim szeto stmfCreateLuResource(uint16_t dType, luResource *hdl) 10828fe96085Stim szeto { 10838fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 10848fe96085Stim szeto 10858fe96085Stim szeto if (dType != STMF_DISK || hdl == NULL) { 10868fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 10878fe96085Stim szeto } 10888fe96085Stim szeto 10898fe96085Stim szeto *hdl = calloc(1, sizeof (luResourceImpl)); 10908fe96085Stim szeto if (*hdl == NULL) { 10918fe96085Stim szeto return (STMF_ERROR_NOMEM); 10928fe96085Stim szeto } 10938fe96085Stim szeto 10948fe96085Stim szeto ret = createDiskResource((luResourceImpl *)*hdl); 10958fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 10968fe96085Stim szeto free(*hdl); 10978fe96085Stim szeto return (ret); 10988fe96085Stim szeto } 10998fe96085Stim szeto 11008fe96085Stim szeto return (STMF_STATUS_SUCCESS); 11018fe96085Stim szeto } 11028fe96085Stim szeto 11038fe96085Stim szeto /* 11048fe96085Stim szeto * Creates a disk logical unit 11058fe96085Stim szeto * 11068fe96085Stim szeto * disk - pointer to diskResource structure that represents the properties 11078fe96085Stim szeto * for the disk logical unit to be created. 11088fe96085Stim szeto */ 11098fe96085Stim szeto static int 11108fe96085Stim szeto createDiskLu(diskResource *disk, stmfGuid *createdGuid) 11118fe96085Stim szeto { 11128fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 11138fe96085Stim szeto int dataFileNameLen = 0; 11148fe96085Stim szeto int metaFileNameLen = 0; 11158fe96085Stim szeto int serialNumLen = 0; 11168fe96085Stim szeto int luAliasLen = 0; 11172f624233SNattuvetty Bhavyan int luMgmtUrlLen = 0; 11188fe96085Stim szeto int sluBufSize = 0; 11198fe96085Stim szeto int bufOffset = 0; 11208fe96085Stim szeto int fd = 0; 11218fe96085Stim szeto int ioctlRet; 11228fe96085Stim szeto int savedErrno; 11238fe96085Stim szeto stmfGuid guid; 11248fe96085Stim szeto stmf_iocdata_t sbdIoctl = {0}; 11258fe96085Stim szeto 11268fe96085Stim szeto sbd_create_and_reg_lu_t *sbdLu = NULL; 11278fe96085Stim szeto 11288fe96085Stim szeto /* 11298fe96085Stim szeto * Open control node for sbd 11308fe96085Stim szeto */ 11318fe96085Stim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS) 11328fe96085Stim szeto return (ret); 11338fe96085Stim szeto 11348fe96085Stim szeto /* data file name must be specified */ 11358fe96085Stim szeto if (disk->luDataFileNameValid) { 11368fe96085Stim szeto dataFileNameLen = strlen(disk->luDataFileName); 11378fe96085Stim szeto } else { 11388fe96085Stim szeto (void) close(fd); 11398fe96085Stim szeto return (STMF_ERROR_MISSING_PROP_VAL); 11408fe96085Stim szeto } 11418fe96085Stim szeto 11428fe96085Stim szeto sluBufSize += dataFileNameLen + 1; 11438fe96085Stim szeto 11448fe96085Stim szeto if (disk->luMetaFileNameValid) { 11458fe96085Stim szeto metaFileNameLen = strlen(disk->luMetaFileName); 11468fe96085Stim szeto sluBufSize += metaFileNameLen + 1; 11478fe96085Stim szeto } 11488fe96085Stim szeto 11498fe96085Stim szeto serialNumLen = strlen(disk->serialNum); 11508fe96085Stim szeto sluBufSize += serialNumLen; 11518fe96085Stim szeto 11528fe96085Stim szeto if (disk->luAliasValid) { 11538fe96085Stim szeto luAliasLen = strlen(disk->luAlias); 11548fe96085Stim szeto sluBufSize += luAliasLen + 1; 11558fe96085Stim szeto } 11568fe96085Stim szeto 11572f624233SNattuvetty Bhavyan if (disk->luMgmtUrlValid) { 11582f624233SNattuvetty Bhavyan luMgmtUrlLen = strlen(disk->luMgmtUrl); 11592f624233SNattuvetty Bhavyan sluBufSize += luMgmtUrlLen + 1; 11602f624233SNattuvetty Bhavyan } 11612f624233SNattuvetty Bhavyan 11628fe96085Stim szeto /* 11638fe96085Stim szeto * 8 is the size of the buffer set aside for 11648fe96085Stim szeto * concatenation of variable length fields 11658fe96085Stim szeto */ 11668fe96085Stim szeto sbdLu = (sbd_create_and_reg_lu_t *)calloc(1, 11678fe96085Stim szeto sizeof (sbd_create_and_reg_lu_t) + sluBufSize - 8); 11688fe96085Stim szeto if (sbdLu == NULL) { 11698fe96085Stim szeto return (STMF_ERROR_NOMEM); 11708fe96085Stim szeto } 11718fe96085Stim szeto 11728fe96085Stim szeto sbdLu->slu_struct_size = sizeof (sbd_create_and_reg_lu_t) + 11738fe96085Stim szeto sluBufSize - 8; 11748fe96085Stim szeto 11758fe96085Stim szeto if (metaFileNameLen) { 11768fe96085Stim szeto sbdLu->slu_meta_fname_valid = 1; 11778fe96085Stim szeto sbdLu->slu_meta_fname_off = bufOffset; 11788fe96085Stim szeto bcopy(disk->luMetaFileName, &(sbdLu->slu_buf[bufOffset]), 11798fe96085Stim szeto metaFileNameLen + 1); 11808fe96085Stim szeto bufOffset += metaFileNameLen + 1; 11818fe96085Stim szeto } 11828fe96085Stim szeto 11838fe96085Stim szeto bcopy(disk->luDataFileName, &(sbdLu->slu_buf[bufOffset]), 11848fe96085Stim szeto dataFileNameLen + 1); 11858fe96085Stim szeto sbdLu->slu_data_fname_off = bufOffset; 11868fe96085Stim szeto bufOffset += dataFileNameLen + 1; 11878fe96085Stim szeto 11888fe96085Stim szeto /* currently, serial # is not passed null terminated to the driver */ 11898fe96085Stim szeto if (disk->serialNumValid) { 11908fe96085Stim szeto sbdLu->slu_serial_valid = 1; 11918fe96085Stim szeto sbdLu->slu_serial_off = bufOffset; 11928fe96085Stim szeto sbdLu->slu_serial_size = serialNumLen; 11938fe96085Stim szeto bcopy(disk->serialNum, &(sbdLu->slu_buf[bufOffset]), 11948fe96085Stim szeto serialNumLen); 11958fe96085Stim szeto bufOffset += serialNumLen; 11968fe96085Stim szeto } 11978fe96085Stim szeto 11988fe96085Stim szeto if (disk->luAliasValid) { 11998fe96085Stim szeto sbdLu->slu_alias_valid = 1; 12008fe96085Stim szeto sbdLu->slu_alias_off = bufOffset; 12018fe96085Stim szeto bcopy(disk->luAlias, &(sbdLu->slu_buf[bufOffset]), 12028fe96085Stim szeto luAliasLen + 1); 12038fe96085Stim szeto bufOffset += luAliasLen + 1; 12048fe96085Stim szeto } 12058fe96085Stim szeto 12062f624233SNattuvetty Bhavyan if (disk->luMgmtUrlValid) { 12072f624233SNattuvetty Bhavyan sbdLu->slu_mgmt_url_valid = 1; 12082f624233SNattuvetty Bhavyan sbdLu->slu_mgmt_url_off = bufOffset; 12092f624233SNattuvetty Bhavyan bcopy(disk->luMgmtUrl, &(sbdLu->slu_buf[bufOffset]), 12102f624233SNattuvetty Bhavyan luMgmtUrlLen + 1); 12112f624233SNattuvetty Bhavyan bufOffset += luMgmtUrlLen + 1; 12122f624233SNattuvetty Bhavyan } 12132f624233SNattuvetty Bhavyan 12148fe96085Stim szeto if (disk->luSizeValid) { 12158fe96085Stim szeto sbdLu->slu_lu_size_valid = 1; 12168fe96085Stim szeto sbdLu->slu_lu_size = disk->luSize; 12178fe96085Stim szeto } 12188fe96085Stim szeto 12198fe96085Stim szeto if (disk->luGuidValid) { 12208fe96085Stim szeto sbdLu->slu_guid_valid = 1; 12218fe96085Stim szeto bcopy(disk->luGuid, sbdLu->slu_guid, sizeof (disk->luGuid)); 12228fe96085Stim szeto } 12238fe96085Stim szeto 12248fe96085Stim szeto if (disk->vidValid) { 12258fe96085Stim szeto sbdLu->slu_vid_valid = 1; 12268fe96085Stim szeto bcopy(disk->vid, sbdLu->slu_vid, sizeof (disk->vid)); 12278fe96085Stim szeto } 12288fe96085Stim szeto 12298fe96085Stim szeto if (disk->pidValid) { 12308fe96085Stim szeto sbdLu->slu_pid_valid = 1; 12318fe96085Stim szeto bcopy(disk->pid, sbdLu->slu_pid, sizeof (disk->pid)); 12328fe96085Stim szeto } 12338fe96085Stim szeto 12348fe96085Stim szeto if (disk->revValid) { 12358fe96085Stim szeto sbdLu->slu_rev_valid = 1; 12368fe96085Stim szeto bcopy(disk->rev, sbdLu->slu_rev, sizeof (disk->rev)); 12378fe96085Stim szeto } 12388fe96085Stim szeto 12398fe96085Stim szeto if (disk->companyIdValid) { 12408fe96085Stim szeto sbdLu->slu_company_id_valid = 1; 12418fe96085Stim szeto sbdLu->slu_company_id = disk->companyId; 12428fe96085Stim szeto } 12438fe96085Stim szeto 12448fe96085Stim szeto if (disk->blkSizeValid) { 12458fe96085Stim szeto sbdLu->slu_blksize_valid = 1; 12468fe96085Stim szeto sbdLu->slu_blksize = disk->blkSize; 12478fe96085Stim szeto } 12488fe96085Stim szeto 12498fe96085Stim szeto if (disk->writeProtectEnableValid) { 12508fe96085Stim szeto if (disk->writeProtectEnable) { 12518fe96085Stim szeto sbdLu->slu_write_protected = 1; 12528fe96085Stim szeto } 12538fe96085Stim szeto } 12548fe96085Stim szeto 12558fe96085Stim szeto if (disk->writebackCacheDisableValid) { 12568fe96085Stim szeto sbdLu->slu_writeback_cache_disable_valid = 1; 12578fe96085Stim szeto if (disk->writebackCacheDisable) { 12588fe96085Stim szeto sbdLu->slu_writeback_cache_disable = 1; 12598fe96085Stim szeto } 12608fe96085Stim szeto } 12618fe96085Stim szeto 12628fe96085Stim szeto sbdIoctl.stmf_version = STMF_VERSION_1; 12638fe96085Stim szeto sbdIoctl.stmf_ibuf_size = sbdLu->slu_struct_size; 12648fe96085Stim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdLu; 12658fe96085Stim szeto sbdIoctl.stmf_obuf_size = sbdLu->slu_struct_size; 12668fe96085Stim szeto sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdLu; 12678fe96085Stim szeto 12688fe96085Stim szeto ioctlRet = ioctl(fd, SBD_IOCTL_CREATE_AND_REGISTER_LU, &sbdIoctl); 12698fe96085Stim szeto if (ioctlRet != 0) { 12708fe96085Stim szeto savedErrno = errno; 12718fe96085Stim szeto switch (savedErrno) { 12728fe96085Stim szeto case EBUSY: 12738fe96085Stim szeto ret = STMF_ERROR_BUSY; 12748fe96085Stim szeto break; 12758fe96085Stim szeto case EPERM: 12768fe96085Stim szeto case EACCES: 12778fe96085Stim szeto ret = STMF_ERROR_PERM; 12788fe96085Stim szeto break; 12798fe96085Stim szeto default: 12808fe96085Stim szeto diskError(sbdIoctl.stmf_error, &ret); 12818fe96085Stim szeto if (ret == STMF_STATUS_ERROR) { 12828fe96085Stim szeto syslog(LOG_DEBUG, 12838fe96085Stim szeto "createDiskLu:ioctl " 12848fe96085Stim szeto "error(%d) (%d) (%d)", ioctlRet, 12858fe96085Stim szeto sbdIoctl.stmf_error, savedErrno); 12868fe96085Stim szeto } 12878fe96085Stim szeto break; 12888fe96085Stim szeto } 12898fe96085Stim szeto } 12908fe96085Stim szeto 12918fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 12928fe96085Stim szeto goto done; 12938fe96085Stim szeto } 12948fe96085Stim szeto 12958fe96085Stim szeto /* 12968fe96085Stim szeto * on success, copy the resulting guid into the caller's guid if not 12978fe96085Stim szeto * NULL 12988fe96085Stim szeto */ 12998fe96085Stim szeto if (createdGuid) { 13008fe96085Stim szeto bcopy(sbdLu->slu_guid, createdGuid->guid, 13018fe96085Stim szeto sizeof (sbdLu->slu_guid)); 13028fe96085Stim szeto } 13038fe96085Stim szeto 13048fe96085Stim szeto bcopy(sbdLu->slu_guid, guid.guid, sizeof (sbdLu->slu_guid)); 13058fe96085Stim szeto if (disk->luMetaFileNameValid) { 13068fe96085Stim szeto ret = addGuidToDiskStore(&guid, disk->luMetaFileName); 13078fe96085Stim szeto } else { 13088fe96085Stim szeto ret = addGuidToDiskStore(&guid, disk->luDataFileName); 13098fe96085Stim szeto } 13108fe96085Stim szeto done: 13118fe96085Stim szeto free(sbdLu); 13128fe96085Stim szeto (void) close(fd); 13138fe96085Stim szeto return (ret); 13148fe96085Stim szeto } 13158fe96085Stim szeto 13168fe96085Stim szeto 13178fe96085Stim szeto /* 13188fe96085Stim szeto * stmfImportLu 13198fe96085Stim szeto * 13208fe96085Stim szeto * Purpose: Import a previously created logical unit 13218fe96085Stim szeto * 13228fe96085Stim szeto * dType - Type of logical unit 13238fe96085Stim szeto * Can be: STMF_DISK 13248fe96085Stim szeto * 13258fe96085Stim szeto * luGuid - If non-NULL, on success, contains the guid of the imported logical 13268fe96085Stim szeto * unit 13278fe96085Stim szeto * 13288fe96085Stim szeto * fname - A file name where the metadata resides 13298fe96085Stim szeto * 13308fe96085Stim szeto */ 13318fe96085Stim szeto int 13328fe96085Stim szeto stmfImportLu(uint16_t dType, char *fname, stmfGuid *luGuid) 13338fe96085Stim szeto { 13348fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 13358fe96085Stim szeto 13368fe96085Stim szeto if (dType == STMF_DISK) { 13378fe96085Stim szeto ret = importDiskLu(fname, luGuid); 13388fe96085Stim szeto } else { 13398fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 13408fe96085Stim szeto } 13418fe96085Stim szeto 13428fe96085Stim szeto return (ret); 13438fe96085Stim szeto } 13448fe96085Stim szeto 13458fe96085Stim szeto /* 13468fe96085Stim szeto * importDiskLu 13478fe96085Stim szeto * 13488fe96085Stim szeto * filename - filename to import 13498fe96085Stim szeto * createdGuid - if not NULL, on success contains the imported guid 13508fe96085Stim szeto * 13518fe96085Stim szeto */ 13528fe96085Stim szeto static int 13538fe96085Stim szeto importDiskLu(char *fname, stmfGuid *createdGuid) 13548fe96085Stim szeto { 13558fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 13568fe96085Stim szeto int fd = 0; 13578fe96085Stim szeto int ioctlRet; 13588fe96085Stim szeto int savedErrno; 13598fe96085Stim szeto int metaFileNameLen; 13608fe96085Stim szeto stmfGuid iGuid; 13618fe96085Stim szeto int iluBufSize = 0; 13628fe96085Stim szeto sbd_import_lu_t *sbdLu = NULL; 13638fe96085Stim szeto stmf_iocdata_t sbdIoctl = {0}; 13648fe96085Stim szeto 13658fe96085Stim szeto if (fname == NULL) { 13668fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 13678fe96085Stim szeto } 13688fe96085Stim szeto 13698fe96085Stim szeto /* 13708fe96085Stim szeto * Open control node for sbd 13718fe96085Stim szeto */ 13728fe96085Stim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS) 13738fe96085Stim szeto return (ret); 13748fe96085Stim szeto 13758fe96085Stim szeto metaFileNameLen = strlen(fname); 13768fe96085Stim szeto iluBufSize += metaFileNameLen + 1; 13778fe96085Stim szeto 13788fe96085Stim szeto /* 13798fe96085Stim szeto * 8 is the size of the buffer set aside for 13808fe96085Stim szeto * concatenation of variable length fields 13818fe96085Stim szeto */ 13828fe96085Stim szeto sbdLu = (sbd_import_lu_t *)calloc(1, 13838fe96085Stim szeto sizeof (sbd_import_lu_t) + iluBufSize - 8); 13848fe96085Stim szeto if (sbdLu == NULL) { 13858fe96085Stim szeto (void) close(fd); 13868fe96085Stim szeto return (STMF_ERROR_NOMEM); 13878fe96085Stim szeto } 13888fe96085Stim szeto 13898fe96085Stim szeto /* 13908fe96085Stim szeto * Accept either a data file or meta data file. 13918fe96085Stim szeto * sbd will do the right thing here either way. 13928fe96085Stim szeto * i.e. if it's a data file, it assumes that the 13938fe96085Stim szeto * meta data is shared with the data. 13948fe96085Stim szeto */ 13958fe96085Stim szeto (void) strncpy(sbdLu->ilu_meta_fname, fname, metaFileNameLen); 13968fe96085Stim szeto 13978fe96085Stim szeto sbdLu->ilu_struct_size = sizeof (sbd_import_lu_t) + iluBufSize - 8; 13988fe96085Stim szeto 13998fe96085Stim szeto sbdIoctl.stmf_version = STMF_VERSION_1; 14008fe96085Stim szeto sbdIoctl.stmf_ibuf_size = sbdLu->ilu_struct_size; 14018fe96085Stim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdLu; 14028fe96085Stim szeto sbdIoctl.stmf_obuf_size = sbdLu->ilu_struct_size; 14038fe96085Stim szeto sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdLu; 14048fe96085Stim szeto 14058fe96085Stim szeto ioctlRet = ioctl(fd, SBD_IOCTL_IMPORT_LU, &sbdIoctl); 14068fe96085Stim szeto if (ioctlRet != 0) { 14078fe96085Stim szeto savedErrno = errno; 14088fe96085Stim szeto switch (savedErrno) { 14098fe96085Stim szeto case EBUSY: 14108fe96085Stim szeto ret = STMF_ERROR_BUSY; 14118fe96085Stim szeto break; 14128fe96085Stim szeto case EPERM: 14138fe96085Stim szeto case EACCES: 14148fe96085Stim szeto ret = STMF_ERROR_PERM; 14158fe96085Stim szeto break; 14168fe96085Stim szeto default: 14178fe96085Stim szeto diskError(sbdIoctl.stmf_error, &ret); 14188fe96085Stim szeto if (ret == STMF_STATUS_ERROR) { 14198fe96085Stim szeto syslog(LOG_DEBUG, 14208fe96085Stim szeto "importDiskLu:ioctl " 14218fe96085Stim szeto "error(%d) (%d) (%d)", ioctlRet, 14228fe96085Stim szeto sbdIoctl.stmf_error, savedErrno); 14238fe96085Stim szeto } 14248fe96085Stim szeto break; 14258fe96085Stim szeto } 14268fe96085Stim szeto } 14278fe96085Stim szeto 14288fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 14298fe96085Stim szeto goto done; 14308fe96085Stim szeto } 14318fe96085Stim szeto 14328fe96085Stim szeto /* 14338fe96085Stim szeto * on success, copy the resulting guid into the caller's guid if not 14348fe96085Stim szeto * NULL and add it to the persistent store for sbd 14358fe96085Stim szeto */ 14368fe96085Stim szeto if (createdGuid) { 14378fe96085Stim szeto bcopy(sbdLu->ilu_ret_guid, createdGuid->guid, 14388fe96085Stim szeto sizeof (sbdLu->ilu_ret_guid)); 14398fe96085Stim szeto ret = addGuidToDiskStore(createdGuid, fname); 14408fe96085Stim szeto } else { 14418fe96085Stim szeto bcopy(sbdLu->ilu_ret_guid, iGuid.guid, 14428fe96085Stim szeto sizeof (sbdLu->ilu_ret_guid)); 14438fe96085Stim szeto ret = addGuidToDiskStore(&iGuid, fname); 14448fe96085Stim szeto } 14458fe96085Stim szeto done: 14468fe96085Stim szeto free(sbdLu); 14478fe96085Stim szeto (void) close(fd); 14488fe96085Stim szeto return (ret); 14498fe96085Stim szeto } 14508fe96085Stim szeto 14518fe96085Stim szeto /* 14528fe96085Stim szeto * diskError 14538fe96085Stim szeto * 14548fe96085Stim szeto * Purpose: Translate sbd driver error 14558fe96085Stim szeto */ 14568fe96085Stim szeto static void 14578fe96085Stim szeto diskError(uint32_t stmfError, int *ret) 14588fe96085Stim szeto { 14598fe96085Stim szeto switch (stmfError) { 14608fe96085Stim szeto case SBD_RET_META_CREATION_FAILED: 14618fe96085Stim szeto case SBD_RET_ZFS_META_CREATE_FAILED: 14628fe96085Stim szeto *ret = STMF_ERROR_META_CREATION; 14638fe96085Stim szeto break; 14648fe96085Stim szeto case SBD_RET_INVALID_BLKSIZE: 14658fe96085Stim szeto *ret = STMF_ERROR_INVALID_BLKSIZE; 14668fe96085Stim szeto break; 14678fe96085Stim szeto case SBD_RET_FILE_ALREADY_REGISTERED: 14688fe96085Stim szeto *ret = STMF_ERROR_FILE_IN_USE; 14698fe96085Stim szeto break; 14708fe96085Stim szeto case SBD_RET_GUID_ALREADY_REGISTERED: 14718fe96085Stim szeto *ret = STMF_ERROR_GUID_IN_USE; 14728fe96085Stim szeto break; 14738fe96085Stim szeto case SBD_RET_META_PATH_NOT_ABSOLUTE: 14748fe96085Stim szeto case SBD_RET_META_FILE_LOOKUP_FAILED: 14758fe96085Stim szeto case SBD_RET_META_FILE_OPEN_FAILED: 14768fe96085Stim szeto case SBD_RET_META_FILE_GETATTR_FAILED: 14778fe96085Stim szeto case SBD_RET_NO_META: 14788fe96085Stim szeto *ret = STMF_ERROR_META_FILE_NAME; 14798fe96085Stim szeto break; 14808fe96085Stim szeto case SBD_RET_DATA_PATH_NOT_ABSOLUTE: 14818fe96085Stim szeto case SBD_RET_DATA_FILE_LOOKUP_FAILED: 14828fe96085Stim szeto case SBD_RET_DATA_FILE_OPEN_FAILED: 14838fe96085Stim szeto case SBD_RET_DATA_FILE_GETATTR_FAILED: 14848fe96085Stim szeto *ret = STMF_ERROR_DATA_FILE_NAME; 14858fe96085Stim szeto break; 14868fe96085Stim szeto case SBD_RET_FILE_SIZE_ERROR: 14878fe96085Stim szeto *ret = STMF_ERROR_FILE_SIZE_INVALID; 14888fe96085Stim szeto break; 14898fe96085Stim szeto case SBD_RET_SIZE_OUT_OF_RANGE: 14908fe96085Stim szeto *ret = STMF_ERROR_SIZE_OUT_OF_RANGE; 14918fe96085Stim szeto break; 14928fe96085Stim szeto case SBD_RET_LU_BUSY: 14938fe96085Stim szeto *ret = STMF_ERROR_LU_BUSY; 14948fe96085Stim szeto break; 14958fe96085Stim szeto case SBD_RET_WRITE_CACHE_SET_FAILED: 14968fe96085Stim szeto *ret = STMF_ERROR_WRITE_CACHE_SET; 14978fe96085Stim szeto break; 1498*45039663SJohn Forte case SBD_RET_ACCESS_STATE_FAILED: 1499*45039663SJohn Forte *ret = STMF_ERROR_ACCESS_STATE_SET; 1500*45039663SJohn Forte break; 15018fe96085Stim szeto default: 15028fe96085Stim szeto *ret = STMF_STATUS_ERROR; 15038fe96085Stim szeto break; 15048fe96085Stim szeto } 15058fe96085Stim szeto } 15068fe96085Stim szeto 15078fe96085Stim szeto /* 15088fe96085Stim szeto * Creates a logical unit resource of type STMF_DISK. 15098fe96085Stim szeto * 15108fe96085Stim szeto * No defaults should be set here as all defaults are derived from the 15118fe96085Stim szeto * driver's default settings. 15128fe96085Stim szeto */ 15138fe96085Stim szeto static int 15148fe96085Stim szeto createDiskResource(luResourceImpl *hdl) 15158fe96085Stim szeto { 15168fe96085Stim szeto hdl->type = STMF_DISK; 15178fe96085Stim szeto 15188fe96085Stim szeto hdl->resource = calloc(1, sizeof (diskResource)); 15198fe96085Stim szeto if (hdl->resource == NULL) { 15208fe96085Stim szeto return (STMF_ERROR_NOMEM); 15218fe96085Stim szeto } 15228fe96085Stim szeto 15238fe96085Stim szeto return (STMF_STATUS_SUCCESS); 15248fe96085Stim szeto } 15258fe96085Stim szeto 15268fe96085Stim szeto /* 15278fe96085Stim szeto * stmfDeleteLu 15288fe96085Stim szeto * 15298fe96085Stim szeto * Purpose: Delete a logical unit 15308fe96085Stim szeto * 15318fe96085Stim szeto * hdl - handle to logical unit resource created via stmfCreateLuResource 15328fe96085Stim szeto * 15338fe96085Stim szeto * luGuid - If non-NULL, on success, contains the guid of the created logical 15348fe96085Stim szeto * unit 15358fe96085Stim szeto */ 15368fe96085Stim szeto int 15378fe96085Stim szeto stmfDeleteLu(stmfGuid *luGuid) 15388fe96085Stim szeto { 15398fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 15408fe96085Stim szeto stmfLogicalUnitProperties luProps; 15418fe96085Stim szeto 15428fe96085Stim szeto if (luGuid == NULL) { 15438fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 15448fe96085Stim szeto } 15458fe96085Stim szeto 15468fe96085Stim szeto /* Check logical unit provider name to call correct dtype function */ 15478fe96085Stim szeto if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps)) 15488fe96085Stim szeto != STMF_STATUS_SUCCESS) { 15498fe96085Stim szeto return (ret); 15508fe96085Stim szeto } else { 15518fe96085Stim szeto if (strcmp(luProps.providerName, "sbd") == 0) { 15528fe96085Stim szeto ret = deleteDiskLu(luGuid); 15538fe96085Stim szeto } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) { 15548fe96085Stim szeto return (STMF_ERROR_NOT_FOUND); 15558fe96085Stim szeto } else { 15568fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 15578fe96085Stim szeto } 15588fe96085Stim szeto } 15598fe96085Stim szeto 15608fe96085Stim szeto return (ret); 15618fe96085Stim szeto } 15628fe96085Stim szeto 15638fe96085Stim szeto static int 15648fe96085Stim szeto deleteDiskLu(stmfGuid *luGuid) 15658fe96085Stim szeto { 15668fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 15678fe96085Stim szeto int fd; 15688fe96085Stim szeto int savedErrno; 15698fe96085Stim szeto int ioctlRet; 15708fe96085Stim szeto sbd_delete_lu_t deleteLu = {0}; 15718fe96085Stim szeto 15728fe96085Stim szeto stmf_iocdata_t sbdIoctl = {0}; 15738fe96085Stim szeto 15748fe96085Stim szeto /* 15758fe96085Stim szeto * Open control node for sbd 15768fe96085Stim szeto */ 15778fe96085Stim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS) 15788fe96085Stim szeto return (ret); 15798fe96085Stim szeto 15808fe96085Stim szeto ret = removeGuidFromDiskStore(luGuid); 15818fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 15828fe96085Stim szeto goto done; 15838fe96085Stim szeto } 15848fe96085Stim szeto 15858fe96085Stim szeto bcopy(luGuid, deleteLu.dlu_guid, sizeof (deleteLu.dlu_guid)); 15868fe96085Stim szeto deleteLu.dlu_by_guid = 1; 15878fe96085Stim szeto 15888fe96085Stim szeto sbdIoctl.stmf_version = STMF_VERSION_1; 15898fe96085Stim szeto sbdIoctl.stmf_ibuf_size = sizeof (deleteLu); 15908fe96085Stim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)&deleteLu; 15918fe96085Stim szeto ioctlRet = ioctl(fd, SBD_IOCTL_DELETE_LU, &sbdIoctl); 15928fe96085Stim szeto if (ioctlRet != 0) { 15938fe96085Stim szeto savedErrno = errno; 15948fe96085Stim szeto switch (savedErrno) { 15958fe96085Stim szeto case EBUSY: 15968fe96085Stim szeto ret = STMF_ERROR_BUSY; 15978fe96085Stim szeto break; 15988fe96085Stim szeto case EPERM: 15998fe96085Stim szeto case EACCES: 16008fe96085Stim szeto ret = STMF_ERROR_PERM; 16018fe96085Stim szeto break; 16028fe96085Stim szeto case ENOENT: 16038fe96085Stim szeto ret = STMF_ERROR_NOT_FOUND; 16048fe96085Stim szeto break; 16058fe96085Stim szeto default: 16068fe96085Stim szeto syslog(LOG_DEBUG, 16078fe96085Stim szeto "deleteDiskLu:ioctl error(%d) (%d) (%d)", 16088fe96085Stim szeto ioctlRet, sbdIoctl.stmf_error, savedErrno); 16098fe96085Stim szeto ret = STMF_STATUS_ERROR; 16108fe96085Stim szeto break; 16118fe96085Stim szeto } 16128fe96085Stim szeto } 16138fe96085Stim szeto 16148fe96085Stim szeto done: 16158fe96085Stim szeto (void) close(fd); 16168fe96085Stim szeto return (ret); 16178fe96085Stim szeto } 16188fe96085Stim szeto 16198fe96085Stim szeto /* 1620*45039663SJohn Forte * stmfLuStandby 1621*45039663SJohn Forte * 1622*45039663SJohn Forte * Purpose: Sets access state to standby 1623*45039663SJohn Forte * 1624*45039663SJohn Forte * luGuid - guid of registered logical unit 1625*45039663SJohn Forte * 1626*45039663SJohn Forte */ 1627*45039663SJohn Forte int 1628*45039663SJohn Forte stmfLuStandby(stmfGuid *luGuid) 1629*45039663SJohn Forte { 1630*45039663SJohn Forte int ret = STMF_STATUS_SUCCESS; 1631*45039663SJohn Forte stmfLogicalUnitProperties luProps; 1632*45039663SJohn Forte 1633*45039663SJohn Forte if (luGuid == NULL) { 1634*45039663SJohn Forte return (STMF_ERROR_INVALID_ARG); 1635*45039663SJohn Forte } 1636*45039663SJohn Forte 1637*45039663SJohn Forte /* Check logical unit provider name to call correct dtype function */ 1638*45039663SJohn Forte if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps)) 1639*45039663SJohn Forte != STMF_STATUS_SUCCESS) { 1640*45039663SJohn Forte return (ret); 1641*45039663SJohn Forte } else { 1642*45039663SJohn Forte if (strcmp(luProps.providerName, "sbd") == 0) { 1643*45039663SJohn Forte ret = setDiskStandby(luGuid); 1644*45039663SJohn Forte } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) { 1645*45039663SJohn Forte return (STMF_ERROR_NOT_FOUND); 1646*45039663SJohn Forte } else { 1647*45039663SJohn Forte return (STMF_ERROR_INVALID_ARG); 1648*45039663SJohn Forte } 1649*45039663SJohn Forte } 1650*45039663SJohn Forte 1651*45039663SJohn Forte return (ret); 1652*45039663SJohn Forte } 1653*45039663SJohn Forte 1654*45039663SJohn Forte static int 1655*45039663SJohn Forte setDiskStandby(stmfGuid *luGuid) 1656*45039663SJohn Forte { 1657*45039663SJohn Forte int ret = STMF_STATUS_SUCCESS; 1658*45039663SJohn Forte stmf_iocdata_t sbdIoctl = {0}; 1659*45039663SJohn Forte sbd_set_lu_standby_t sbdLu = {0}; 1660*45039663SJohn Forte int ioctlRet; 1661*45039663SJohn Forte int savedErrno; 1662*45039663SJohn Forte int fd = 0; 1663*45039663SJohn Forte 1664*45039663SJohn Forte /* 1665*45039663SJohn Forte * Open control node for sbd 1666*45039663SJohn Forte */ 1667*45039663SJohn Forte if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS) 1668*45039663SJohn Forte return (ret); 1669*45039663SJohn Forte 1670*45039663SJohn Forte bcopy(luGuid, &sbdLu.stlu_guid, sizeof (stmfGuid)); 1671*45039663SJohn Forte 1672*45039663SJohn Forte sbdIoctl.stmf_version = STMF_VERSION_1; 1673*45039663SJohn Forte sbdIoctl.stmf_ibuf_size = sizeof (sbd_set_lu_standby_t); 1674*45039663SJohn Forte sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)&sbdLu; 1675*45039663SJohn Forte 1676*45039663SJohn Forte ioctlRet = ioctl(fd, SBD_IOCTL_SET_LU_STANDBY, &sbdIoctl); 1677*45039663SJohn Forte if (ioctlRet != 0) { 1678*45039663SJohn Forte savedErrno = errno; 1679*45039663SJohn Forte switch (savedErrno) { 1680*45039663SJohn Forte case EBUSY: 1681*45039663SJohn Forte ret = STMF_ERROR_BUSY; 1682*45039663SJohn Forte break; 1683*45039663SJohn Forte case EPERM: 1684*45039663SJohn Forte case EACCES: 1685*45039663SJohn Forte ret = STMF_ERROR_PERM; 1686*45039663SJohn Forte break; 1687*45039663SJohn Forte default: 1688*45039663SJohn Forte diskError(sbdIoctl.stmf_error, &ret); 1689*45039663SJohn Forte if (ret == STMF_STATUS_ERROR) { 1690*45039663SJohn Forte syslog(LOG_DEBUG, 1691*45039663SJohn Forte "setDiskStandby:ioctl " 1692*45039663SJohn Forte "error(%d) (%d) (%d)", ioctlRet, 1693*45039663SJohn Forte sbdIoctl.stmf_error, savedErrno); 1694*45039663SJohn Forte } 1695*45039663SJohn Forte break; 1696*45039663SJohn Forte } 1697*45039663SJohn Forte } 1698*45039663SJohn Forte return (ret); 1699*45039663SJohn Forte } 1700*45039663SJohn Forte 1701*45039663SJohn Forte /* 17028fe96085Stim szeto * stmfModifyLu 17038fe96085Stim szeto * 17048fe96085Stim szeto * Purpose: Modify properties of a logical unit 17058fe96085Stim szeto * 17068fe96085Stim szeto * luGuid - guid of registered logical unit 17078fe96085Stim szeto * prop - property to modify 17088fe96085Stim szeto * propVal - property value to set 17098fe96085Stim szeto * 17108fe96085Stim szeto */ 17118fe96085Stim szeto int 17128fe96085Stim szeto stmfModifyLu(stmfGuid *luGuid, uint32_t prop, const char *propVal) 17138fe96085Stim szeto { 17148fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 17158fe96085Stim szeto stmfLogicalUnitProperties luProps; 17168fe96085Stim szeto 17178fe96085Stim szeto if (luGuid == NULL) { 17188fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 17198fe96085Stim szeto } 17208fe96085Stim szeto 17218fe96085Stim szeto /* Check logical unit provider name to call correct dtype function */ 17228fe96085Stim szeto if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps)) 17238fe96085Stim szeto != STMF_STATUS_SUCCESS) { 17248fe96085Stim szeto return (ret); 17258fe96085Stim szeto } else { 17268fe96085Stim szeto if (strcmp(luProps.providerName, "sbd") == 0) { 17278fe96085Stim szeto ret = modifyDiskLuProp(luGuid, NULL, prop, propVal); 17288fe96085Stim szeto } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) { 17298fe96085Stim szeto return (STMF_ERROR_NOT_FOUND); 17308fe96085Stim szeto } else { 17318fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 17328fe96085Stim szeto } 17338fe96085Stim szeto } 17348fe96085Stim szeto 17358fe96085Stim szeto return (ret); 17368fe96085Stim szeto } 17378fe96085Stim szeto 17388fe96085Stim szeto /* 17398fe96085Stim szeto * stmfModifyLuByFname 17408fe96085Stim szeto * 17418fe96085Stim szeto * Purpose: Modify a device by filename. Device does not need to be registered. 17428fe96085Stim szeto * 17438fe96085Stim szeto * dType - type of device to modify 17448fe96085Stim szeto * STMF_DISK 17458fe96085Stim szeto * 17468fe96085Stim szeto * fname - filename or meta filename 17478fe96085Stim szeto * prop - valid property identifier 17488fe96085Stim szeto * propVal - property value 17498fe96085Stim szeto * 17508fe96085Stim szeto */ 17518fe96085Stim szeto int 17528fe96085Stim szeto stmfModifyLuByFname(uint16_t dType, const char *fname, uint32_t prop, 17538fe96085Stim szeto const char *propVal) 17548fe96085Stim szeto { 17558fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 17568fe96085Stim szeto if (fname == NULL) { 17578fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 17588fe96085Stim szeto } 17598fe96085Stim szeto 17608fe96085Stim szeto if (dType == STMF_DISK) { 17618fe96085Stim szeto ret = modifyDiskLuProp(NULL, fname, prop, propVal); 17628fe96085Stim szeto } else { 17638fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 17648fe96085Stim szeto } 17658fe96085Stim szeto 17668fe96085Stim szeto return (ret); 17678fe96085Stim szeto } 17688fe96085Stim szeto 17698fe96085Stim szeto static int 17708fe96085Stim szeto modifyDiskLuProp(stmfGuid *luGuid, const char *fname, uint32_t prop, 17718fe96085Stim szeto const char *propVal) 17728fe96085Stim szeto { 17738fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 17748fe96085Stim szeto luResource hdl = NULL; 17758fe96085Stim szeto luResourceImpl *luPropsHdl; 17768fe96085Stim szeto 17778fe96085Stim szeto ret = stmfCreateLuResource(STMF_DISK, &hdl); 17788fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 17798fe96085Stim szeto return (ret); 17808fe96085Stim szeto } 17818fe96085Stim szeto ret = validateModifyDiskProp(prop); 17828fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 17838fe96085Stim szeto (void) stmfFreeLuResource(hdl); 17848fe96085Stim szeto return (STMF_ERROR_INVALID_PROP); 17858fe96085Stim szeto } 17868fe96085Stim szeto ret = stmfSetLuProp(hdl, prop, propVal); 17878fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 17888fe96085Stim szeto (void) stmfFreeLuResource(hdl); 17898fe96085Stim szeto return (ret); 17908fe96085Stim szeto } 17918fe96085Stim szeto luPropsHdl = hdl; 17928fe96085Stim szeto ret = modifyDiskLu((diskResource *)luPropsHdl->resource, luGuid, fname); 17938fe96085Stim szeto (void) stmfFreeLuResource(hdl); 17948fe96085Stim szeto return (ret); 17958fe96085Stim szeto } 17968fe96085Stim szeto 17978fe96085Stim szeto static int 17988fe96085Stim szeto validateModifyDiskProp(uint32_t prop) 17998fe96085Stim szeto { 18008fe96085Stim szeto switch (prop) { 18018fe96085Stim szeto case STMF_LU_PROP_ALIAS: 18028fe96085Stim szeto case STMF_LU_PROP_SIZE: 18032f624233SNattuvetty Bhavyan case STMF_LU_PROP_MGMT_URL: 18048fe96085Stim szeto case STMF_LU_PROP_WRITE_PROTECT: 18058fe96085Stim szeto case STMF_LU_PROP_WRITE_CACHE_DISABLE: 18068fe96085Stim szeto return (STMF_STATUS_SUCCESS); 18078fe96085Stim szeto break; 18088fe96085Stim szeto default: 18098fe96085Stim szeto return (STMF_STATUS_ERROR); 18108fe96085Stim szeto break; 18118fe96085Stim szeto } 18128fe96085Stim szeto } 18138fe96085Stim szeto 18148fe96085Stim szeto static int 18158fe96085Stim szeto modifyDiskLu(diskResource *disk, stmfGuid *luGuid, const char *fname) 18168fe96085Stim szeto { 18178fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 18188fe96085Stim szeto int luAliasLen = 0; 18192f624233SNattuvetty Bhavyan int luMgmtUrlLen = 0; 18208fe96085Stim szeto int mluBufSize = 0; 18218fe96085Stim szeto int bufOffset = 0; 18228fe96085Stim szeto int fd = 0; 18238fe96085Stim szeto int ioctlRet; 18248fe96085Stim szeto int savedErrno; 18258fe96085Stim szeto int fnameSize = 0; 18268fe96085Stim szeto stmf_iocdata_t sbdIoctl = {0}; 18278fe96085Stim szeto 18288fe96085Stim szeto sbd_modify_lu_t *sbdLu = NULL; 18298fe96085Stim szeto 18308fe96085Stim szeto if (luGuid == NULL && fname == NULL) { 18318fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 18328fe96085Stim szeto } 18338fe96085Stim szeto 18348fe96085Stim szeto if (fname) { 18358fe96085Stim szeto fnameSize = strlen(fname) + 1; 18368fe96085Stim szeto mluBufSize += fnameSize; 18378fe96085Stim szeto } 18388fe96085Stim szeto 18398fe96085Stim szeto /* 18408fe96085Stim szeto * Open control node for sbd 18418fe96085Stim szeto */ 18428fe96085Stim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS) 18438fe96085Stim szeto return (ret); 18448fe96085Stim szeto 18458fe96085Stim szeto if (disk->luAliasValid) { 18468fe96085Stim szeto luAliasLen = strlen(disk->luAlias); 18478fe96085Stim szeto mluBufSize += luAliasLen + 1; 18488fe96085Stim szeto } 18498fe96085Stim szeto 18502f624233SNattuvetty Bhavyan if (disk->luMgmtUrlValid) { 18512f624233SNattuvetty Bhavyan luMgmtUrlLen = strlen(disk->luMgmtUrl); 18522f624233SNattuvetty Bhavyan mluBufSize += luMgmtUrlLen + 1; 18532f624233SNattuvetty Bhavyan } 18542f624233SNattuvetty Bhavyan 18558fe96085Stim szeto /* 18568fe96085Stim szeto * 8 is the size of the buffer set aside for 18578fe96085Stim szeto * concatenation of variable length fields 18588fe96085Stim szeto */ 18598fe96085Stim szeto sbdLu = (sbd_modify_lu_t *)calloc(1, 18608fe96085Stim szeto sizeof (sbd_modify_lu_t) + mluBufSize - 8 + fnameSize); 18618fe96085Stim szeto if (sbdLu == NULL) { 18628fe96085Stim szeto (void) close(fd); 18638fe96085Stim szeto return (STMF_ERROR_NOMEM); 18648fe96085Stim szeto } 18658fe96085Stim szeto 18668fe96085Stim szeto sbdLu->mlu_struct_size = sizeof (sbd_modify_lu_t) + 18678fe96085Stim szeto mluBufSize - 8 + fnameSize; 18688fe96085Stim szeto 18698fe96085Stim szeto if (disk->luAliasValid) { 18708fe96085Stim szeto sbdLu->mlu_alias_valid = 1; 18718fe96085Stim szeto sbdLu->mlu_alias_off = bufOffset; 18728fe96085Stim szeto bcopy(disk->luAlias, &(sbdLu->mlu_buf[bufOffset]), 18738fe96085Stim szeto luAliasLen + 1); 18748fe96085Stim szeto bufOffset += luAliasLen + 1; 18758fe96085Stim szeto } 18768fe96085Stim szeto 18772f624233SNattuvetty Bhavyan if (disk->luMgmtUrlValid) { 18782f624233SNattuvetty Bhavyan sbdLu->mlu_mgmt_url_valid = 1; 18792f624233SNattuvetty Bhavyan sbdLu->mlu_mgmt_url_off = bufOffset; 18802f624233SNattuvetty Bhavyan bcopy(disk->luMgmtUrl, &(sbdLu->mlu_buf[bufOffset]), 18812f624233SNattuvetty Bhavyan luMgmtUrlLen + 1); 18822f624233SNattuvetty Bhavyan bufOffset += luMgmtUrlLen + 1; 18832f624233SNattuvetty Bhavyan } 18842f624233SNattuvetty Bhavyan 18858fe96085Stim szeto if (disk->luSizeValid) { 18868fe96085Stim szeto sbdLu->mlu_lu_size_valid = 1; 18878fe96085Stim szeto sbdLu->mlu_lu_size = disk->luSize; 18888fe96085Stim szeto } 18898fe96085Stim szeto 18908fe96085Stim szeto if (disk->writeProtectEnableValid) { 18918fe96085Stim szeto sbdLu->mlu_write_protected_valid = 1; 18928fe96085Stim szeto if (disk->writeProtectEnable) { 18938fe96085Stim szeto sbdLu->mlu_write_protected = 1; 18948fe96085Stim szeto } 18958fe96085Stim szeto } 18968fe96085Stim szeto 18978fe96085Stim szeto if (disk->writebackCacheDisableValid) { 18988fe96085Stim szeto sbdLu->mlu_writeback_cache_disable_valid = 1; 18998fe96085Stim szeto if (disk->writebackCacheDisable) { 19008fe96085Stim szeto sbdLu->mlu_writeback_cache_disable = 1; 19018fe96085Stim szeto } 19028fe96085Stim szeto } 19038fe96085Stim szeto 19048fe96085Stim szeto if (luGuid) { 19058fe96085Stim szeto bcopy(luGuid, sbdLu->mlu_input_guid, sizeof (stmfGuid)); 19068fe96085Stim szeto sbdLu->mlu_by_guid = 1; 19078fe96085Stim szeto } else { 19088fe96085Stim szeto sbdLu->mlu_fname_off = bufOffset; 19098fe96085Stim szeto bcopy(fname, &(sbdLu->mlu_buf[bufOffset]), fnameSize + 1); 19108fe96085Stim szeto sbdLu->mlu_by_fname = 1; 19118fe96085Stim szeto } 19128fe96085Stim szeto 19138fe96085Stim szeto sbdIoctl.stmf_version = STMF_VERSION_1; 19148fe96085Stim szeto sbdIoctl.stmf_ibuf_size = sbdLu->mlu_struct_size; 19158fe96085Stim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdLu; 19168fe96085Stim szeto 19178fe96085Stim szeto ioctlRet = ioctl(fd, SBD_IOCTL_MODIFY_LU, &sbdIoctl); 19188fe96085Stim szeto if (ioctlRet != 0) { 19198fe96085Stim szeto savedErrno = errno; 19208fe96085Stim szeto switch (savedErrno) { 19218fe96085Stim szeto case EBUSY: 19228fe96085Stim szeto ret = STMF_ERROR_BUSY; 19238fe96085Stim szeto break; 19248fe96085Stim szeto case EPERM: 19258fe96085Stim szeto case EACCES: 19268fe96085Stim szeto ret = STMF_ERROR_PERM; 19278fe96085Stim szeto break; 19288fe96085Stim szeto default: 19298fe96085Stim szeto diskError(sbdIoctl.stmf_error, &ret); 19308fe96085Stim szeto if (ret == STMF_STATUS_ERROR) { 19318fe96085Stim szeto syslog(LOG_DEBUG, 19328fe96085Stim szeto "modifyDiskLu:ioctl " 19338fe96085Stim szeto "error(%d) (%d) (%d)", ioctlRet, 19348fe96085Stim szeto sbdIoctl.stmf_error, savedErrno); 19358fe96085Stim szeto } 19368fe96085Stim szeto break; 19378fe96085Stim szeto } 19388fe96085Stim szeto } 19398fe96085Stim szeto 19408fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 19418fe96085Stim szeto goto done; 19428fe96085Stim szeto } 19438fe96085Stim szeto 19448fe96085Stim szeto done: 19458fe96085Stim szeto free(sbdLu); 19468fe96085Stim szeto (void) close(fd); 19478fe96085Stim szeto return (ret); 19488fe96085Stim szeto } 19498fe96085Stim szeto 19508fe96085Stim szeto /* 19518fe96085Stim szeto * removeGuidFromDiskStore 19528fe96085Stim szeto * 19538fe96085Stim szeto * Purpose: delete a logical unit from the sbd provider data 19548fe96085Stim szeto */ 19558fe96085Stim szeto static int 19568fe96085Stim szeto removeGuidFromDiskStore(stmfGuid *guid) 19578fe96085Stim szeto { 19588fe96085Stim szeto return (persistDiskGuid(guid, NULL, B_FALSE)); 19598fe96085Stim szeto } 19608fe96085Stim szeto 19618fe96085Stim szeto 19628fe96085Stim szeto /* 19638fe96085Stim szeto * addGuidToDiskStore 19648fe96085Stim szeto * 19658fe96085Stim szeto * Purpose: add a logical unit to the sbd provider data 19668fe96085Stim szeto */ 19678fe96085Stim szeto static int 19688fe96085Stim szeto addGuidToDiskStore(stmfGuid *guid, char *filename) 19698fe96085Stim szeto { 19708fe96085Stim szeto return (persistDiskGuid(guid, filename, B_TRUE)); 19718fe96085Stim szeto } 19728fe96085Stim szeto 19738fe96085Stim szeto 19748fe96085Stim szeto /* 19758fe96085Stim szeto * persistDiskGuid 19768fe96085Stim szeto * 19778fe96085Stim szeto * Purpose: Persist or unpersist a guid for the sbd provider data 19788fe96085Stim szeto * 19798fe96085Stim szeto */ 19808fe96085Stim szeto static int 19818fe96085Stim szeto persistDiskGuid(stmfGuid *guid, char *filename, boolean_t persist) 19828fe96085Stim szeto { 19838fe96085Stim szeto char guidAsciiBuf[LU_ASCII_GUID_SIZE + 1] = {0}; 19848fe96085Stim szeto nvlist_t *nvl = NULL; 19858fe96085Stim szeto 19868fe96085Stim szeto uint64_t setToken; 19878fe96085Stim szeto boolean_t retryGetProviderData = B_FALSE; 19888fe96085Stim szeto boolean_t newData = B_FALSE; 19898fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 19908fe96085Stim szeto int retryCnt = 0; 19918fe96085Stim szeto int stmfRet; 19928fe96085Stim szeto 19938fe96085Stim szeto /* if we're persisting a guid, there must be a filename */ 19948fe96085Stim szeto if (persist && !filename) { 19958fe96085Stim szeto return (1); 19968fe96085Stim szeto } 19978fe96085Stim szeto 19988fe96085Stim szeto /* guid is stored in lowercase ascii hex */ 19998fe96085Stim szeto (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf), 20008fe96085Stim szeto "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" 20018fe96085Stim szeto "%02x%02x%02x%02x%02x%02x", 20028fe96085Stim szeto guid->guid[0], guid->guid[1], guid->guid[2], guid->guid[3], 20038fe96085Stim szeto guid->guid[4], guid->guid[5], guid->guid[6], guid->guid[7], 20048fe96085Stim szeto guid->guid[8], guid->guid[9], guid->guid[10], guid->guid[11], 20058fe96085Stim szeto guid->guid[12], guid->guid[13], guid->guid[14], guid->guid[15]); 20068fe96085Stim szeto 20078fe96085Stim szeto 20088fe96085Stim szeto do { 20098fe96085Stim szeto retryGetProviderData = B_FALSE; 20108fe96085Stim szeto stmfRet = stmfGetProviderDataProt("sbd", &nvl, 20118fe96085Stim szeto STMF_LU_PROVIDER_TYPE, &setToken); 20128fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 20138fe96085Stim szeto if (persist && stmfRet == STMF_ERROR_NOT_FOUND) { 20148fe96085Stim szeto ret = nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0); 20158fe96085Stim szeto if (ret != 0) { 20168fe96085Stim szeto syslog(LOG_DEBUG, 20178fe96085Stim szeto "unpersistGuid:nvlist_alloc(%d)", 20188fe96085Stim szeto ret); 20198fe96085Stim szeto ret = STMF_STATUS_ERROR; 20208fe96085Stim szeto goto done; 20218fe96085Stim szeto } 20228fe96085Stim szeto newData = B_TRUE; 20238fe96085Stim szeto } else { 2024*45039663SJohn Forte /* 2025*45039663SJohn Forte * if we're persisting the data, it's 2026*45039663SJohn Forte * an error. Otherwise, just return 2027*45039663SJohn Forte */ 2028*45039663SJohn Forte if (persist) { 20298fe96085Stim szeto ret = stmfRet; 2030*45039663SJohn Forte } 20318fe96085Stim szeto goto done; 20328fe96085Stim szeto } 20338fe96085Stim szeto } 20348fe96085Stim szeto if (persist) { 20358fe96085Stim szeto ret = nvlist_add_string(nvl, guidAsciiBuf, filename); 20368fe96085Stim szeto } else { 20378fe96085Stim szeto ret = nvlist_remove(nvl, guidAsciiBuf, 20388fe96085Stim szeto DATA_TYPE_STRING); 20398fe96085Stim szeto if (ret == ENOENT) { 20408fe96085Stim szeto ret = 0; 20418fe96085Stim szeto } 20428fe96085Stim szeto } 20438fe96085Stim szeto if (ret == 0) { 20448fe96085Stim szeto if (newData) { 20458fe96085Stim szeto stmfRet = stmfSetProviderDataProt("sbd", nvl, 20468fe96085Stim szeto STMF_LU_PROVIDER_TYPE, NULL); 20478fe96085Stim szeto } else { 20488fe96085Stim szeto stmfRet = stmfSetProviderDataProt("sbd", nvl, 20498fe96085Stim szeto STMF_LU_PROVIDER_TYPE, &setToken); 20508fe96085Stim szeto } 20518fe96085Stim szeto if (stmfRet != STMF_STATUS_SUCCESS) { 20528fe96085Stim szeto if (stmfRet == STMF_ERROR_BUSY) { 20538fe96085Stim szeto /* get/set failed, try again */ 20548fe96085Stim szeto retryGetProviderData = B_TRUE; 20558fe96085Stim szeto if (retryCnt++ > MAX_PROVIDER_RETRY) { 20568fe96085Stim szeto ret = stmfRet; 20578fe96085Stim szeto break; 20588fe96085Stim szeto } 20598fe96085Stim szeto continue; 20608fe96085Stim szeto } else if (stmfRet == 20618fe96085Stim szeto STMF_ERROR_PROV_DATA_STALE) { 20628fe96085Stim szeto /* update failed, try again */ 20638fe96085Stim szeto nvlist_free(nvl); 20648fe96085Stim szeto nvl = NULL; 20658fe96085Stim szeto retryGetProviderData = B_TRUE; 20668fe96085Stim szeto if (retryCnt++ > MAX_PROVIDER_RETRY) { 20678fe96085Stim szeto ret = stmfRet; 20688fe96085Stim szeto break; 20698fe96085Stim szeto } 20708fe96085Stim szeto continue; 20718fe96085Stim szeto } else { 20728fe96085Stim szeto syslog(LOG_DEBUG, 20738fe96085Stim szeto "unpersistGuid:error(%x)", stmfRet); 20748fe96085Stim szeto ret = stmfRet; 20758fe96085Stim szeto } 20768fe96085Stim szeto break; 20778fe96085Stim szeto } 20788fe96085Stim szeto } else { 20798fe96085Stim szeto syslog(LOG_DEBUG, 20808fe96085Stim szeto "unpersistGuid:error nvlist_add/remove(%d)", 20818fe96085Stim szeto ret); 20828fe96085Stim szeto ret = STMF_STATUS_ERROR; 20838fe96085Stim szeto } 20848fe96085Stim szeto } while (retryGetProviderData); 20858fe96085Stim szeto 20868fe96085Stim szeto done: 20878fe96085Stim szeto nvlist_free(nvl); 20888fe96085Stim szeto return (ret); 20898fe96085Stim szeto } 20908fe96085Stim szeto 20918fe96085Stim szeto 20928fe96085Stim szeto /* 20938fe96085Stim szeto * stmfGetLuProp 20948fe96085Stim szeto * 20958fe96085Stim szeto * Purpose: Get current value for a resource property 20968fe96085Stim szeto * 20978fe96085Stim szeto * hdl - luResource from a previous call to stmfCreateLuResource 20988fe96085Stim szeto * 20998fe96085Stim szeto * resourceProp - a valid resource property type 21008fe96085Stim szeto * 21018fe96085Stim szeto * propVal - void pointer to a pointer of the value to be retrieved 21028fe96085Stim szeto */ 21038fe96085Stim szeto int 21048fe96085Stim szeto stmfGetLuProp(luResource hdl, uint32_t prop, char *propVal, size_t *propLen) 21058fe96085Stim szeto { 21068fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 21078fe96085Stim szeto luResourceImpl *luPropsHdl = hdl; 21088fe96085Stim szeto if (hdl == NULL || propLen == NULL || propVal == NULL) { 21098fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 21108fe96085Stim szeto } 21118fe96085Stim szeto 21128fe96085Stim szeto if (luPropsHdl->type == STMF_DISK) { 21138fe96085Stim szeto ret = getDiskProp(luPropsHdl, prop, propVal, propLen); 21148fe96085Stim szeto } else { 21158fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 21168fe96085Stim szeto } 21178fe96085Stim szeto 21188fe96085Stim szeto return (ret); 21198fe96085Stim szeto } 21208fe96085Stim szeto 21218fe96085Stim szeto /* 21228fe96085Stim szeto * stmfGetLuResource 21238fe96085Stim szeto * 21248fe96085Stim szeto * Purpose: Get a logical unit resource handle for a given logical unit. 21258fe96085Stim szeto * 21268fe96085Stim szeto * hdl - pointer to luResource 21278fe96085Stim szeto */ 21288fe96085Stim szeto int 21298fe96085Stim szeto stmfGetLuResource(stmfGuid *luGuid, luResource *hdl) 21308fe96085Stim szeto { 21318fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 21328fe96085Stim szeto stmfLogicalUnitProperties luProps; 21338fe96085Stim szeto 21348fe96085Stim szeto 21358fe96085Stim szeto /* Check logical unit provider name to call correct dtype function */ 21368fe96085Stim szeto if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps)) 21378fe96085Stim szeto != STMF_STATUS_SUCCESS) { 21388fe96085Stim szeto return (ret); 21398fe96085Stim szeto } else { 21408fe96085Stim szeto if (strcmp(luProps.providerName, "sbd") == 0) { 21418fe96085Stim szeto ret = getDiskAllProps(luGuid, hdl); 21428fe96085Stim szeto } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) { 21438fe96085Stim szeto return (STMF_ERROR_NOT_FOUND); 21448fe96085Stim szeto } else { 21458fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 21468fe96085Stim szeto } 21478fe96085Stim szeto } 21488fe96085Stim szeto 21498fe96085Stim szeto return (ret); 21508fe96085Stim szeto } 21518fe96085Stim szeto 21528fe96085Stim szeto /* 21538fe96085Stim szeto * getDiskAllProps 21548fe96085Stim szeto * 21558fe96085Stim szeto * Purpose: load all disk properties from sbd driver 21568fe96085Stim szeto * 21578fe96085Stim szeto * luGuid - guid of disk device for which properties are to be retrieved 21588fe96085Stim szeto * hdl - allocated luResource into which properties are to be copied 21598fe96085Stim szeto * 21608fe96085Stim szeto */ 21618fe96085Stim szeto static int 21628fe96085Stim szeto getDiskAllProps(stmfGuid *luGuid, luResource *hdl) 21638fe96085Stim szeto { 21648fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 21658fe96085Stim szeto int fd; 21668fe96085Stim szeto sbd_lu_props_t *sbdProps; 21678fe96085Stim szeto int ioctlRet; 21688fe96085Stim szeto int savedErrno; 21698fe96085Stim szeto int sbdPropsSize = sizeof (*sbdProps) + MAX_SBD_PROPS; 21708fe96085Stim szeto stmf_iocdata_t sbdIoctl = {0}; 21718fe96085Stim szeto 21728fe96085Stim szeto /* 21738fe96085Stim szeto * Open control node for sbd 21748fe96085Stim szeto */ 21758fe96085Stim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS) 21768fe96085Stim szeto return (ret); 21778fe96085Stim szeto 21788fe96085Stim szeto 21798fe96085Stim szeto *hdl = calloc(1, sizeof (luResourceImpl)); 21808fe96085Stim szeto if (*hdl == NULL) { 21818fe96085Stim szeto (void) close(fd); 21828fe96085Stim szeto return (STMF_ERROR_NOMEM); 21838fe96085Stim szeto } 21848fe96085Stim szeto 21858fe96085Stim szeto sbdProps = calloc(1, sbdPropsSize); 21868fe96085Stim szeto if (sbdProps == NULL) { 21878fe96085Stim szeto free(*hdl); 21888fe96085Stim szeto (void) close(fd); 21898fe96085Stim szeto return (STMF_ERROR_NOMEM); 21908fe96085Stim szeto } 21918fe96085Stim szeto 21928fe96085Stim szeto ret = createDiskResource((luResourceImpl *)*hdl); 21938fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 21948fe96085Stim szeto free(*hdl); 2195*45039663SJohn Forte free(sbdProps); 21968fe96085Stim szeto (void) close(fd); 21978fe96085Stim szeto return (ret); 21988fe96085Stim szeto } 21998fe96085Stim szeto 22008fe96085Stim szeto sbdProps->slp_input_guid = 1; 22018fe96085Stim szeto bcopy(luGuid, sbdProps->slp_guid, sizeof (sbdProps->slp_guid)); 22028fe96085Stim szeto 22038fe96085Stim szeto sbdIoctl.stmf_version = STMF_VERSION_1; 22048fe96085Stim szeto sbdIoctl.stmf_ibuf_size = sbdPropsSize; 22058fe96085Stim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdProps; 22068fe96085Stim szeto sbdIoctl.stmf_obuf_size = sbdPropsSize; 22078fe96085Stim szeto sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdProps; 22088fe96085Stim szeto ioctlRet = ioctl(fd, SBD_IOCTL_GET_LU_PROPS, &sbdIoctl); 22098fe96085Stim szeto if (ioctlRet != 0) { 22108fe96085Stim szeto savedErrno = errno; 22118fe96085Stim szeto switch (savedErrno) { 22128fe96085Stim szeto case EBUSY: 22138fe96085Stim szeto ret = STMF_ERROR_BUSY; 22148fe96085Stim szeto break; 22158fe96085Stim szeto case EPERM: 22168fe96085Stim szeto case EACCES: 22178fe96085Stim szeto ret = STMF_ERROR_PERM; 22188fe96085Stim szeto break; 22198fe96085Stim szeto case ENOENT: 22208fe96085Stim szeto ret = STMF_ERROR_NOT_FOUND; 22218fe96085Stim szeto break; 22228fe96085Stim szeto default: 22238fe96085Stim szeto syslog(LOG_DEBUG, 22248fe96085Stim szeto "getDiskAllProps:ioctl error(%d) (%d) (%d)", 22258fe96085Stim szeto ioctlRet, sbdIoctl.stmf_error, savedErrno); 22268fe96085Stim szeto ret = STMF_STATUS_ERROR; 22278fe96085Stim szeto break; 22288fe96085Stim szeto } 22298fe96085Stim szeto } 22308fe96085Stim szeto 22318fe96085Stim szeto if (ret == STMF_STATUS_SUCCESS) { 22328fe96085Stim szeto ret = loadDiskPropsFromDriver((luResourceImpl *)*hdl, sbdProps); 22338fe96085Stim szeto } 22348fe96085Stim szeto 2235*45039663SJohn Forte free(sbdProps); 22368fe96085Stim szeto (void) close(fd); 22378fe96085Stim szeto return (ret); 22388fe96085Stim szeto } 22398fe96085Stim szeto 22408fe96085Stim szeto /* 22418fe96085Stim szeto * loadDiskPropsFromDriver 22428fe96085Stim szeto * 22438fe96085Stim szeto * Purpose: Retrieve all disk type properties from sbd driver 22448fe96085Stim szeto * 22458fe96085Stim szeto * hdl - Allocated luResourceImpl 22468fe96085Stim szeto * sbdProps - sbd_lu_props_t structure returned from sbd driver 22478fe96085Stim szeto * 22488fe96085Stim szeto */ 22498fe96085Stim szeto static int 22508fe96085Stim szeto loadDiskPropsFromDriver(luResourceImpl *hdl, sbd_lu_props_t *sbdProps) 22518fe96085Stim szeto { 22528fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 22538fe96085Stim szeto diskResource *diskLu = hdl->resource; 22548fe96085Stim szeto /* copy guid */ 22558fe96085Stim szeto diskLu->luGuidValid = B_TRUE; 22568fe96085Stim szeto bcopy(sbdProps->slp_guid, diskLu->luGuid, sizeof (sbdProps->slp_guid)); 22578fe96085Stim szeto 22588fe96085Stim szeto if (sbdProps->slp_separate_meta && sbdProps->slp_meta_fname_valid) { 22598fe96085Stim szeto diskLu->luMetaFileNameValid = B_TRUE; 22608fe96085Stim szeto if (strlcpy(diskLu->luMetaFileName, 22618fe96085Stim szeto (char *)&(sbdProps->slp_buf[sbdProps->slp_meta_fname_off]), 22628fe96085Stim szeto sizeof (diskLu->luMetaFileName)) >= 22638fe96085Stim szeto sizeof (diskLu->luMetaFileName)) { 22648fe96085Stim szeto return (STMF_STATUS_ERROR); 22658fe96085Stim szeto } 22668fe96085Stim szeto } 22678fe96085Stim szeto 22688fe96085Stim szeto if (sbdProps->slp_data_fname_valid) { 22698fe96085Stim szeto diskLu->luDataFileNameValid = B_TRUE; 22708fe96085Stim szeto if (strlcpy(diskLu->luDataFileName, 22718fe96085Stim szeto (char *)&(sbdProps->slp_buf[sbdProps->slp_data_fname_off]), 22728fe96085Stim szeto sizeof (diskLu->luDataFileName)) >= 22738fe96085Stim szeto sizeof (diskLu->luDataFileName)) { 22748fe96085Stim szeto return (STMF_STATUS_ERROR); 22758fe96085Stim szeto } 22768fe96085Stim szeto } 22778fe96085Stim szeto 22788fe96085Stim szeto if (sbdProps->slp_serial_valid) { 22798fe96085Stim szeto diskLu->serialNumValid = B_TRUE; 22808fe96085Stim szeto bcopy(&(sbdProps->slp_buf[sbdProps->slp_serial_off]), 22818fe96085Stim szeto diskLu->serialNum, sbdProps->slp_serial_size); 22828fe96085Stim szeto } 22838fe96085Stim szeto 22842f624233SNattuvetty Bhavyan if (sbdProps->slp_mgmt_url_valid) { 22852f624233SNattuvetty Bhavyan diskLu->luMgmtUrlValid = B_TRUE; 22862f624233SNattuvetty Bhavyan if (strlcpy(diskLu->luMgmtUrl, 22872f624233SNattuvetty Bhavyan (char *)&(sbdProps->slp_buf[sbdProps->slp_mgmt_url_off]), 22882f624233SNattuvetty Bhavyan sizeof (diskLu->luMgmtUrl)) >= 22892f624233SNattuvetty Bhavyan sizeof (diskLu->luMgmtUrl)) { 22902f624233SNattuvetty Bhavyan return (STMF_STATUS_ERROR); 22912f624233SNattuvetty Bhavyan } 22922f624233SNattuvetty Bhavyan } 22932f624233SNattuvetty Bhavyan 22948fe96085Stim szeto if (sbdProps->slp_alias_valid) { 22958fe96085Stim szeto diskLu->luAliasValid = B_TRUE; 22968fe96085Stim szeto if (strlcpy(diskLu->luAlias, 22978fe96085Stim szeto (char *)&(sbdProps->slp_buf[sbdProps->slp_alias_off]), 22988fe96085Stim szeto sizeof (diskLu->luAlias)) >= 22998fe96085Stim szeto sizeof (diskLu->luAlias)) { 23008fe96085Stim szeto return (STMF_STATUS_ERROR); 23018fe96085Stim szeto } 23028fe96085Stim szeto } else { /* set alias to data filename if not set */ 23038fe96085Stim szeto if (sbdProps->slp_data_fname_valid) { 23048fe96085Stim szeto diskLu->luAliasValid = B_TRUE; 23058fe96085Stim szeto if (strlcpy(diskLu->luAlias, 23068fe96085Stim szeto (char *)&(sbdProps->slp_buf[ 23078fe96085Stim szeto sbdProps->slp_data_fname_off]), 23088fe96085Stim szeto sizeof (diskLu->luAlias)) >= 23098fe96085Stim szeto sizeof (diskLu->luAlias)) { 23108fe96085Stim szeto return (STMF_STATUS_ERROR); 23118fe96085Stim szeto } 23128fe96085Stim szeto } 23138fe96085Stim szeto } 23148fe96085Stim szeto 23158fe96085Stim szeto diskLu->vidValid = B_TRUE; 23168fe96085Stim szeto bcopy(sbdProps->slp_vid, diskLu->vid, sizeof (diskLu->vid)); 23178fe96085Stim szeto 23188fe96085Stim szeto diskLu->pidValid = B_TRUE; 23198fe96085Stim szeto bcopy(sbdProps->slp_pid, diskLu->pid, sizeof (diskLu->pid)); 23208fe96085Stim szeto 23218fe96085Stim szeto diskLu->revValid = B_TRUE; 23228fe96085Stim szeto bcopy(sbdProps->slp_rev, diskLu->rev, sizeof (diskLu->rev)); 23238fe96085Stim szeto 23248fe96085Stim szeto diskLu->writeProtectEnableValid = B_TRUE; 23258fe96085Stim szeto if (sbdProps->slp_write_protected) { 23268fe96085Stim szeto diskLu->writeProtectEnable = B_TRUE; 23278fe96085Stim szeto } 23288fe96085Stim szeto 23298fe96085Stim szeto diskLu->writebackCacheDisableValid = B_TRUE; 23308fe96085Stim szeto if (sbdProps->slp_writeback_cache_disable_cur) { 23318fe96085Stim szeto diskLu->writebackCacheDisable = B_TRUE; 23328fe96085Stim szeto } 23338fe96085Stim szeto 23348fe96085Stim szeto diskLu->blkSizeValid = B_TRUE; 23358fe96085Stim szeto diskLu->blkSize = sbdProps->slp_blksize; 23368fe96085Stim szeto 23378fe96085Stim szeto diskLu->luSizeValid = B_TRUE; 23388fe96085Stim szeto diskLu->luSize = sbdProps->slp_lu_size; 23398fe96085Stim szeto 2340*45039663SJohn Forte diskLu->accessState = sbdProps->slp_access_state; 2341*45039663SJohn Forte 23428fe96085Stim szeto return (ret); 23438fe96085Stim szeto } 23448fe96085Stim szeto 23458fe96085Stim szeto 23468fe96085Stim szeto /* 23478fe96085Stim szeto * stmfSetLuProp 23488fe96085Stim szeto * 23498fe96085Stim szeto * Purpose: set a property on an luResource 23508fe96085Stim szeto * 23518fe96085Stim szeto * hdl - allocated luResource 23528fe96085Stim szeto * prop - property identifier 23538fe96085Stim szeto * propVal - property value to be set 23548fe96085Stim szeto */ 23558fe96085Stim szeto int 23568fe96085Stim szeto stmfSetLuProp(luResource hdl, uint32_t prop, const char *propVal) 23578fe96085Stim szeto { 23588fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 23598fe96085Stim szeto luResourceImpl *luPropsHdl = hdl; 23608fe96085Stim szeto if (hdl == NULL) { 23618fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 23628fe96085Stim szeto } 23638fe96085Stim szeto 23648fe96085Stim szeto if (luPropsHdl->type == STMF_DISK) { 23658fe96085Stim szeto ret = setDiskProp(luPropsHdl, prop, propVal); 23668fe96085Stim szeto } else { 23678fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 23688fe96085Stim szeto } 23698fe96085Stim szeto 23708fe96085Stim szeto return (ret); 23718fe96085Stim szeto } 23728fe96085Stim szeto 23738fe96085Stim szeto /* 23748fe96085Stim szeto * getDiskProp 23758fe96085Stim szeto * 23768fe96085Stim szeto * Purpose: retrieve a given property from a logical unit resource of type disk 23778fe96085Stim szeto * 23788fe96085Stim szeto * hdl - allocated luResourceImpl 23798fe96085Stim szeto * prop - property identifier 23808fe96085Stim szeto * propVal - pointer to character to contain the retrieved property value 23818fe96085Stim szeto * propLen - On input this is the length of propVal. On failure, it contains the 23828fe96085Stim szeto * number of bytes required for propVal 23838fe96085Stim szeto */ 23848fe96085Stim szeto static int 23858fe96085Stim szeto getDiskProp(luResourceImpl *hdl, uint32_t prop, char *propVal, size_t *propLen) 23868fe96085Stim szeto { 23878fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 23888fe96085Stim szeto diskResource *diskLu = hdl->resource; 2389*45039663SJohn Forte char accessState[20]; 23908fe96085Stim szeto size_t reqLen; 23918fe96085Stim szeto 2392*45039663SJohn Forte if (prop == STMF_LU_PROP_ACCESS_STATE) { 2393*45039663SJohn Forte if (diskLu->accessState == SBD_LU_ACTIVE) { 2394*45039663SJohn Forte (void) strlcpy(accessState, STMF_ACCESS_ACTIVE, 2395*45039663SJohn Forte sizeof (accessState)); 2396*45039663SJohn Forte } else if (diskLu->accessState == SBD_LU_TRANSITION_TO_ACTIVE) { 2397*45039663SJohn Forte (void) strlcpy(accessState, 2398*45039663SJohn Forte STMF_ACCESS_STANDBY_TO_ACTIVE, 2399*45039663SJohn Forte sizeof (accessState)); 2400*45039663SJohn Forte } else if (diskLu->accessState == SBD_LU_STANDBY) { 2401*45039663SJohn Forte (void) strlcpy(accessState, STMF_ACCESS_STANDBY, 2402*45039663SJohn Forte sizeof (accessState)); 2403*45039663SJohn Forte } else if (diskLu->accessState == 2404*45039663SJohn Forte SBD_LU_TRANSITION_TO_STANDBY) { 2405*45039663SJohn Forte (void) strlcpy(accessState, 2406*45039663SJohn Forte STMF_ACCESS_ACTIVE_TO_STANDBY, 2407*45039663SJohn Forte sizeof (accessState)); 2408*45039663SJohn Forte } 2409*45039663SJohn Forte if ((reqLen = strlcpy(propVal, accessState, 2410*45039663SJohn Forte *propLen)) >= *propLen) { 2411*45039663SJohn Forte *propLen = reqLen + 1; 2412*45039663SJohn Forte return (STMF_ERROR_INVALID_ARG); 2413*45039663SJohn Forte } 2414*45039663SJohn Forte return (0); 2415*45039663SJohn Forte } 2416*45039663SJohn Forte 2417*45039663SJohn Forte if (diskLu->accessState != SBD_LU_ACTIVE) { 2418*45039663SJohn Forte return (STMF_ERROR_NO_PROP_STANDBY); 2419*45039663SJohn Forte } 2420*45039663SJohn Forte 24218fe96085Stim szeto switch (prop) { 24228fe96085Stim szeto case STMF_LU_PROP_BLOCK_SIZE: 24238fe96085Stim szeto if (diskLu->blkSizeValid == B_FALSE) { 24248fe96085Stim szeto return (STMF_ERROR_NO_PROP); 24258fe96085Stim szeto } 24268fe96085Stim szeto reqLen = snprintf(propVal, *propLen, "%llu", 24278fe96085Stim szeto (u_longlong_t)diskLu->blkSize); 24288fe96085Stim szeto if (reqLen >= *propLen) { 24298fe96085Stim szeto *propLen = reqLen + 1; 24308fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 24318fe96085Stim szeto } 24328fe96085Stim szeto break; 24338fe96085Stim szeto case STMF_LU_PROP_FILENAME: 24348fe96085Stim szeto if (diskLu->luDataFileNameValid == B_FALSE) { 24358fe96085Stim szeto return (STMF_ERROR_NO_PROP); 24368fe96085Stim szeto } 24378fe96085Stim szeto if ((reqLen = strlcpy(propVal, diskLu->luDataFileName, 24388fe96085Stim szeto *propLen)) >= *propLen) { 24398fe96085Stim szeto *propLen = reqLen + 1; 24408fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 24418fe96085Stim szeto } 24428fe96085Stim szeto break; 24438fe96085Stim szeto case STMF_LU_PROP_META_FILENAME: 24448fe96085Stim szeto if (diskLu->luMetaFileNameValid == B_FALSE) { 24458fe96085Stim szeto return (STMF_ERROR_NO_PROP); 24468fe96085Stim szeto } 24478fe96085Stim szeto if ((reqLen = strlcpy(propVal, diskLu->luMetaFileName, 24488fe96085Stim szeto *propLen)) >= *propLen) { 24498fe96085Stim szeto *propLen = reqLen + 1; 24508fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 24518fe96085Stim szeto } 24528fe96085Stim szeto break; 24532f624233SNattuvetty Bhavyan case STMF_LU_PROP_MGMT_URL: 24542f624233SNattuvetty Bhavyan if (diskLu->luMgmtUrlValid == B_FALSE) { 24552f624233SNattuvetty Bhavyan return (STMF_ERROR_NO_PROP); 24562f624233SNattuvetty Bhavyan } 24572f624233SNattuvetty Bhavyan if ((reqLen = strlcpy(propVal, diskLu->luMgmtUrl, 24582f624233SNattuvetty Bhavyan *propLen)) >= *propLen) { 24592f624233SNattuvetty Bhavyan *propLen = reqLen + 1; 24602f624233SNattuvetty Bhavyan return (STMF_ERROR_INVALID_ARG); 24612f624233SNattuvetty Bhavyan } 24622f624233SNattuvetty Bhavyan break; 24638fe96085Stim szeto case STMF_LU_PROP_GUID: 24648fe96085Stim szeto if (diskLu->luGuidValid == B_FALSE) { 24658fe96085Stim szeto return (STMF_ERROR_NO_PROP); 24668fe96085Stim szeto } 24678fe96085Stim szeto reqLen = snprintf(propVal, *propLen, 24688fe96085Stim szeto "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" 24698fe96085Stim szeto "%02X%02X%02X%02X", 24708fe96085Stim szeto diskLu->luGuid[0], diskLu->luGuid[1], 24718fe96085Stim szeto diskLu->luGuid[2], diskLu->luGuid[3], 24728fe96085Stim szeto diskLu->luGuid[4], diskLu->luGuid[5], 24738fe96085Stim szeto diskLu->luGuid[6], diskLu->luGuid[7], 24748fe96085Stim szeto diskLu->luGuid[8], diskLu->luGuid[9], 24758fe96085Stim szeto diskLu->luGuid[10], diskLu->luGuid[11], 24768fe96085Stim szeto diskLu->luGuid[12], diskLu->luGuid[13], 24778fe96085Stim szeto diskLu->luGuid[14], diskLu->luGuid[15]); 24788fe96085Stim szeto if (reqLen >= *propLen) { 24798fe96085Stim szeto *propLen = reqLen + 1; 24808fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 24818fe96085Stim szeto } 24828fe96085Stim szeto break; 24838fe96085Stim szeto case STMF_LU_PROP_SERIAL_NUM: 24848fe96085Stim szeto if (diskLu->serialNumValid == B_FALSE) { 24858fe96085Stim szeto return (STMF_ERROR_NO_PROP); 24868fe96085Stim szeto } 24878fe96085Stim szeto if ((reqLen = strlcpy(propVal, diskLu->serialNum, 24888fe96085Stim szeto *propLen)) >= *propLen) { 24898fe96085Stim szeto *propLen = reqLen + 1; 24908fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 24918fe96085Stim szeto } 24928fe96085Stim szeto break; 24938fe96085Stim szeto case STMF_LU_PROP_SIZE: 24948fe96085Stim szeto if (diskLu->luSizeValid == B_FALSE) { 24958fe96085Stim szeto return (STMF_ERROR_NO_PROP); 24968fe96085Stim szeto } 24978fe96085Stim szeto (void) snprintf(propVal, *propLen, "%llu", 24988fe96085Stim szeto (u_longlong_t)diskLu->luSize); 24998fe96085Stim szeto break; 25008fe96085Stim szeto case STMF_LU_PROP_ALIAS: 25018fe96085Stim szeto if (diskLu->luAliasValid == B_FALSE) { 25028fe96085Stim szeto return (STMF_ERROR_NO_PROP); 25038fe96085Stim szeto } 25048fe96085Stim szeto if ((reqLen = strlcpy(propVal, diskLu->luAlias, 25058fe96085Stim szeto *propLen)) >= *propLen) { 25068fe96085Stim szeto *propLen = reqLen + 1; 25078fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25088fe96085Stim szeto } 25098fe96085Stim szeto break; 25108fe96085Stim szeto case STMF_LU_PROP_VID: 25118fe96085Stim szeto if (diskLu->vidValid == B_FALSE) { 25128fe96085Stim szeto return (STMF_ERROR_NO_PROP); 25138fe96085Stim szeto } 25148fe96085Stim szeto if (*propLen <= sizeof (diskLu->vid)) { 25158fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25168fe96085Stim szeto } 25178fe96085Stim szeto bcopy(diskLu->vid, propVal, sizeof (diskLu->vid)); 25188fe96085Stim szeto propVal[sizeof (diskLu->vid)] = 0; 25198fe96085Stim szeto break; 25208fe96085Stim szeto case STMF_LU_PROP_PID: 25218fe96085Stim szeto if (diskLu->pidValid == B_FALSE) { 25228fe96085Stim szeto return (STMF_ERROR_NO_PROP); 25238fe96085Stim szeto } 25248fe96085Stim szeto if (*propLen <= sizeof (diskLu->pid)) { 25258fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25268fe96085Stim szeto } 25278fe96085Stim szeto bcopy(diskLu->pid, propVal, sizeof (diskLu->pid)); 25288fe96085Stim szeto propVal[sizeof (diskLu->pid)] = 0; 25298fe96085Stim szeto break; 25308fe96085Stim szeto case STMF_LU_PROP_WRITE_PROTECT: 25318fe96085Stim szeto if (diskLu->writeProtectEnableValid == B_FALSE) { 25328fe96085Stim szeto return (STMF_ERROR_NO_PROP); 25338fe96085Stim szeto } 25348fe96085Stim szeto if (diskLu->writeProtectEnable) { 25358fe96085Stim szeto if ((reqLen = strlcpy(propVal, "true", 25368fe96085Stim szeto *propLen)) >= *propLen) { 25378fe96085Stim szeto *propLen = reqLen + 1; 25388fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25398fe96085Stim szeto } 25408fe96085Stim szeto } else { 25418fe96085Stim szeto if ((reqLen = strlcpy(propVal, "false", 25428fe96085Stim szeto *propLen)) >= *propLen) { 25438fe96085Stim szeto *propLen = reqLen + 1; 25448fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25458fe96085Stim szeto } 25468fe96085Stim szeto } 25478fe96085Stim szeto break; 25488fe96085Stim szeto case STMF_LU_PROP_WRITE_CACHE_DISABLE: 25498fe96085Stim szeto if (diskLu->writebackCacheDisableValid == B_FALSE) { 25508fe96085Stim szeto return (STMF_ERROR_NO_PROP); 25518fe96085Stim szeto } 25528fe96085Stim szeto if (diskLu->writebackCacheDisable) { 25538fe96085Stim szeto if ((reqLen = strlcpy(propVal, "true", 25548fe96085Stim szeto *propLen)) >= *propLen) { 25558fe96085Stim szeto *propLen = reqLen + 1; 25568fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25578fe96085Stim szeto } 25588fe96085Stim szeto } else { 25598fe96085Stim szeto if ((reqLen = strlcpy(propVal, "false", 25608fe96085Stim szeto *propLen)) >= *propLen) { 25618fe96085Stim szeto *propLen = reqLen + 1; 25628fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25638fe96085Stim szeto } 25648fe96085Stim szeto } 25658fe96085Stim szeto break; 25668fe96085Stim szeto default: 25678fe96085Stim szeto ret = STMF_ERROR_NO_PROP; 25688fe96085Stim szeto break; 25698fe96085Stim szeto } 25708fe96085Stim szeto 25718fe96085Stim szeto return (ret); 25728fe96085Stim szeto } 25738fe96085Stim szeto 25748fe96085Stim szeto /* 25758fe96085Stim szeto * setDiskProp 25768fe96085Stim szeto * 25778fe96085Stim szeto * Purpose: set properties for resource of type disk 25788fe96085Stim szeto * 25798fe96085Stim szeto * hdl - allocated luResourceImpl 25808fe96085Stim szeto * resourceProp - valid resource identifier 25818fe96085Stim szeto * propVal - valid resource value 25828fe96085Stim szeto */ 25838fe96085Stim szeto static int 25848fe96085Stim szeto setDiskProp(luResourceImpl *hdl, uint32_t resourceProp, const char *propVal) 25858fe96085Stim szeto { 25868fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 25878fe96085Stim szeto int i; 25888fe96085Stim szeto diskResource *diskLu = hdl->resource; 25898fe96085Stim szeto unsigned long long numericProp = 0; 25908fe96085Stim szeto char guidProp[LU_ASCII_GUID_SIZE + 1]; 25918fe96085Stim szeto char ouiProp[OUI_ASCII_SIZE + 1]; 25928fe96085Stim szeto unsigned int oui[OUI_SIZE]; 25938fe96085Stim szeto unsigned int guid[LU_GUID_SIZE]; 25948fe96085Stim szeto int propSize; 25958fe96085Stim szeto 25968fe96085Stim szeto 25978fe96085Stim szeto if (propVal == NULL) { 25988fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 25998fe96085Stim szeto } 26008fe96085Stim szeto 26018fe96085Stim szeto switch (resourceProp) { 26028fe96085Stim szeto case STMF_LU_PROP_ALIAS: 26038fe96085Stim szeto if (strlcpy(diskLu->luAlias, propVal, 26048fe96085Stim szeto sizeof (diskLu->luAlias)) >= 26058fe96085Stim szeto sizeof (diskLu->luAlias)) { 26068fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 26078fe96085Stim szeto } 26088fe96085Stim szeto diskLu->luAliasValid = B_TRUE; 26098fe96085Stim szeto break; 26108fe96085Stim szeto case STMF_LU_PROP_BLOCK_SIZE: 26118fe96085Stim szeto (void) sscanf(propVal, "%llu", &numericProp); 26128fe96085Stim szeto if (numericProp > UINT16_MAX) { 26138fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 26148fe96085Stim szeto } 26158fe96085Stim szeto diskLu->blkSize = numericProp; 26168fe96085Stim szeto diskLu->blkSizeValid = B_TRUE; 26178fe96085Stim szeto break; 26188fe96085Stim szeto case STMF_LU_PROP_COMPANY_ID: 26198fe96085Stim szeto if ((strlcpy(ouiProp, propVal, sizeof (ouiProp))) >= 26208fe96085Stim szeto sizeof (ouiProp)) { 26218fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 26228fe96085Stim szeto } 26238fe96085Stim szeto if (checkHexUpper(ouiProp) != 0) { 26248fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 26258fe96085Stim szeto } 26268fe96085Stim szeto (void) sscanf(ouiProp, "%2X%2X%2X", 26278fe96085Stim szeto &oui[0], &oui[1], &oui[2]); 26288fe96085Stim szeto 26298fe96085Stim szeto diskLu->companyId = 0; 26308fe96085Stim szeto diskLu->companyId += oui[0] << 16; 26318fe96085Stim szeto diskLu->companyId += oui[1] << 8; 26328fe96085Stim szeto diskLu->companyId += oui[2]; 26338fe96085Stim szeto diskLu->companyIdValid = B_TRUE; 26348fe96085Stim szeto break; 26358fe96085Stim szeto case STMF_LU_PROP_GUID: 26368fe96085Stim szeto if (strlen(propVal) != LU_ASCII_GUID_SIZE) { 26378fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 26388fe96085Stim szeto } 26398fe96085Stim szeto 26408fe96085Stim szeto if ((strlcpy(guidProp, propVal, sizeof (guidProp))) >= 26418fe96085Stim szeto sizeof (guidProp)) { 26428fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 26438fe96085Stim szeto } 26448fe96085Stim szeto 26458fe96085Stim szeto if (checkHexUpper(guidProp) != 0) { 26468fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 26478fe96085Stim szeto } 26488fe96085Stim szeto 26498fe96085Stim szeto (void) sscanf(guidProp, 26508fe96085Stim szeto "%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X", 26518fe96085Stim szeto &guid[0], &guid[1], &guid[2], &guid[3], &guid[4], 26528fe96085Stim szeto &guid[5], &guid[6], &guid[7], &guid[8], &guid[9], 26538fe96085Stim szeto &guid[10], &guid[11], &guid[12], &guid[13], 26548fe96085Stim szeto &guid[14], &guid[15]); 26558fe96085Stim szeto for (i = 0; i < sizeof (diskLu->luGuid); i++) { 26568fe96085Stim szeto diskLu->luGuid[i] = guid[i]; 26578fe96085Stim szeto } 26588fe96085Stim szeto diskLu->luGuidValid = B_TRUE; 26598fe96085Stim szeto break; 26608fe96085Stim szeto case STMF_LU_PROP_FILENAME: 26618fe96085Stim szeto if ((strlcpy(diskLu->luDataFileName, propVal, 26628fe96085Stim szeto sizeof (diskLu->luDataFileName))) >= 26638fe96085Stim szeto sizeof (diskLu->luDataFileName)) { 26648fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 26658fe96085Stim szeto } 26668fe96085Stim szeto diskLu->luDataFileNameValid = B_TRUE; 26678fe96085Stim szeto break; 26688fe96085Stim szeto case STMF_LU_PROP_META_FILENAME: 26698fe96085Stim szeto if ((strlcpy(diskLu->luMetaFileName, propVal, 26708fe96085Stim szeto sizeof (diskLu->luMetaFileName))) >= 26718fe96085Stim szeto sizeof (diskLu->luMetaFileName)) { 26728fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 26738fe96085Stim szeto } 26748fe96085Stim szeto diskLu->luMetaFileNameValid = B_TRUE; 26758fe96085Stim szeto break; 26762f624233SNattuvetty Bhavyan case STMF_LU_PROP_MGMT_URL: 26772f624233SNattuvetty Bhavyan if ((strlcpy(diskLu->luMgmtUrl, propVal, 26782f624233SNattuvetty Bhavyan sizeof (diskLu->luMgmtUrl))) >= 26792f624233SNattuvetty Bhavyan sizeof (diskLu->luMgmtUrl)) { 26802f624233SNattuvetty Bhavyan return (STMF_ERROR_INVALID_PROPSIZE); 26812f624233SNattuvetty Bhavyan } 26822f624233SNattuvetty Bhavyan diskLu->luMgmtUrlValid = B_TRUE; 26832f624233SNattuvetty Bhavyan break; 26848fe96085Stim szeto case STMF_LU_PROP_PID: 26858fe96085Stim szeto if ((propSize = strlen(propVal)) > 26868fe96085Stim szeto sizeof (diskLu->pid)) { 26878fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 26888fe96085Stim szeto } 26898fe96085Stim szeto (void) strncpy(diskLu->pid, propVal, propSize); 26908fe96085Stim szeto diskLu->pidValid = B_TRUE; 26918fe96085Stim szeto break; 26928fe96085Stim szeto case STMF_LU_PROP_SERIAL_NUM: 26938fe96085Stim szeto if ((propSize = strlen(propVal)) > 26948fe96085Stim szeto (sizeof (diskLu->serialNum) - 1)) { 26958fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 26968fe96085Stim szeto } 26978fe96085Stim szeto (void) strncpy(diskLu->serialNum, propVal, propSize); 26988fe96085Stim szeto diskLu->serialNumValid = B_TRUE; 26998fe96085Stim szeto break; 27008fe96085Stim szeto case STMF_LU_PROP_SIZE: 27018fe96085Stim szeto if ((niceStrToNum(propVal, &diskLu->luSize) != 0)) { 27028fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 27038fe96085Stim szeto } 27048fe96085Stim szeto diskLu->luSizeValid = B_TRUE; 27058fe96085Stim szeto break; 27068fe96085Stim szeto case STMF_LU_PROP_VID: 27078fe96085Stim szeto if ((propSize = strlen(propVal)) > 27088fe96085Stim szeto sizeof (diskLu->vid)) { 27098fe96085Stim szeto return (STMF_ERROR_INVALID_PROPSIZE); 27108fe96085Stim szeto } 27118fe96085Stim szeto (void) strncpy(diskLu->vid, propVal, propSize); 27128fe96085Stim szeto diskLu->vidValid = B_TRUE; 27138fe96085Stim szeto break; 27148fe96085Stim szeto case STMF_LU_PROP_WRITE_PROTECT: 27158fe96085Stim szeto if (strcasecmp(propVal, "TRUE") == 0) { 27168fe96085Stim szeto diskLu->writeProtectEnable = B_TRUE; 27178fe96085Stim szeto } else if (strcasecmp(propVal, "FALSE") == 0) { 27188fe96085Stim szeto diskLu->writeProtectEnable = B_FALSE; 27198fe96085Stim szeto } else { 27208fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 27218fe96085Stim szeto } 27228fe96085Stim szeto diskLu->writeProtectEnableValid = B_TRUE; 27238fe96085Stim szeto break; 27248fe96085Stim szeto case STMF_LU_PROP_WRITE_CACHE_DISABLE: 27258fe96085Stim szeto if (strcasecmp(propVal, "TRUE") == 0) { 27268fe96085Stim szeto diskLu->writebackCacheDisable = B_TRUE; 27278fe96085Stim szeto } else if (strcasecmp(propVal, "FALSE") == 0) { 27288fe96085Stim szeto diskLu->writebackCacheDisable = B_FALSE; 27298fe96085Stim szeto } else { 27308fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 27318fe96085Stim szeto } 27328fe96085Stim szeto diskLu->writebackCacheDisableValid = B_TRUE; 27338fe96085Stim szeto break; 2734*45039663SJohn Forte case STMF_LU_PROP_ACCESS_STATE: 2735*45039663SJohn Forte ret = STMF_ERROR_INVALID_PROP; 2736*45039663SJohn Forte break; 27378fe96085Stim szeto default: 27388fe96085Stim szeto ret = STMF_ERROR_NO_PROP; 27398fe96085Stim szeto break; 27408fe96085Stim szeto } 27418fe96085Stim szeto return (ret); 27428fe96085Stim szeto } 27438fe96085Stim szeto 27448fe96085Stim szeto static int 27458fe96085Stim szeto checkHexUpper(char *buf) 27468fe96085Stim szeto { 27478fe96085Stim szeto int i; 27488fe96085Stim szeto 27498fe96085Stim szeto for (i = 0; i < strlen(buf); i++) { 27508fe96085Stim szeto if (isxdigit(buf[i])) { 27518fe96085Stim szeto buf[i] = toupper(buf[i]); 27528fe96085Stim szeto continue; 27538fe96085Stim szeto } 27548fe96085Stim szeto return (-1); 27558fe96085Stim szeto } 27568fe96085Stim szeto 27578fe96085Stim szeto return (0); 27588fe96085Stim szeto } 27598fe96085Stim szeto 27608fe96085Stim szeto /* 27618fe96085Stim szeto * Given a numeric suffix, convert the value into a number of bits that the 27628fe96085Stim szeto * resulting value must be shifted. 27638fe96085Stim szeto * Code lifted from libzfs_util.c 27648fe96085Stim szeto */ 27658fe96085Stim szeto static int 27668fe96085Stim szeto strToShift(const char *buf) 27678fe96085Stim szeto { 27688fe96085Stim szeto const char *ends = "BKMGTPE"; 27698fe96085Stim szeto int i; 27708fe96085Stim szeto 27718fe96085Stim szeto if (buf[0] == '\0') 27728fe96085Stim szeto return (0); 27738fe96085Stim szeto 27748fe96085Stim szeto for (i = 0; i < strlen(ends); i++) { 27758fe96085Stim szeto if (toupper(buf[0]) == ends[i]) 27768fe96085Stim szeto return (10*i); 27778fe96085Stim szeto } 27788fe96085Stim szeto 27798fe96085Stim szeto return (-1); 27808fe96085Stim szeto } 27818fe96085Stim szeto 27828fe96085Stim szeto int 27838fe96085Stim szeto stmfFreeLuResource(luResource hdl) 27848fe96085Stim szeto { 27858fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 27868fe96085Stim szeto if (hdl == NULL) { 27878fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 27888fe96085Stim szeto } 27898fe96085Stim szeto 27908fe96085Stim szeto luResourceImpl *hdlImpl = hdl; 27918fe96085Stim szeto free(hdlImpl->resource); 27928fe96085Stim szeto free(hdlImpl); 27938fe96085Stim szeto return (ret); 27948fe96085Stim szeto } 27958fe96085Stim szeto 27968fe96085Stim szeto /* 27978fe96085Stim szeto * Convert a string of the form '100G' into a real number. Used when setting 27988fe96085Stim szeto * the size of a logical unit. 27998fe96085Stim szeto * Code lifted from libzfs_util.c 28008fe96085Stim szeto */ 28018fe96085Stim szeto static int 28028fe96085Stim szeto niceStrToNum(const char *value, uint64_t *num) 28038fe96085Stim szeto { 28048fe96085Stim szeto char *end; 28058fe96085Stim szeto int shift; 28068fe96085Stim szeto 28078fe96085Stim szeto *num = 0; 28088fe96085Stim szeto 28098fe96085Stim szeto /* Check to see if this looks like a number. */ 28108fe96085Stim szeto if ((value[0] < '0' || value[0] > '9') && value[0] != '.') { 28118fe96085Stim szeto return (-1); 28128fe96085Stim szeto } 28138fe96085Stim szeto 28148fe96085Stim szeto /* Rely on stroull() to process the numeric portion. */ 28158fe96085Stim szeto errno = 0; 28168fe96085Stim szeto *num = strtoull(value, &end, 10); 28178fe96085Stim szeto 28188fe96085Stim szeto /* 28198fe96085Stim szeto * Check for ERANGE, which indicates that the value is too large to fit 28208fe96085Stim szeto * in a 64-bit value. 28218fe96085Stim szeto */ 28228fe96085Stim szeto if (errno == ERANGE) { 28238fe96085Stim szeto return (-1); 28248fe96085Stim szeto } 28258fe96085Stim szeto 28268fe96085Stim szeto /* 28278fe96085Stim szeto * If we have a decimal value, then do the computation with floating 28288fe96085Stim szeto * point arithmetic. Otherwise, use standard arithmetic. 28298fe96085Stim szeto */ 28308fe96085Stim szeto if (*end == '.') { 28318fe96085Stim szeto double fval = strtod(value, &end); 28328fe96085Stim szeto 28338fe96085Stim szeto if ((shift = strToShift(end)) == -1) { 28348fe96085Stim szeto return (-1); 28358fe96085Stim szeto } 28368fe96085Stim szeto 28378fe96085Stim szeto fval *= pow(2, shift); 28388fe96085Stim szeto 28398fe96085Stim szeto if (fval > UINT64_MAX) { 28408fe96085Stim szeto return (-1); 28418fe96085Stim szeto } 28428fe96085Stim szeto 28438fe96085Stim szeto *num = (uint64_t)fval; 28448fe96085Stim szeto } else { 28458fe96085Stim szeto if ((shift = strToShift(end)) == -1) { 28468fe96085Stim szeto return (-1); 28478fe96085Stim szeto } 28488fe96085Stim szeto 28498fe96085Stim szeto /* Check for overflow */ 28508fe96085Stim szeto if (shift >= 64 || (*num << shift) >> shift != *num) { 28518fe96085Stim szeto return (-1); 28528fe96085Stim szeto } 28538fe96085Stim szeto 28548fe96085Stim szeto *num <<= shift; 28558fe96085Stim szeto } 28568fe96085Stim szeto 28578fe96085Stim szeto return (0); 28588fe96085Stim szeto } 28598fe96085Stim szeto 28608fe96085Stim szeto /* 2861fcf3ce44SJohn Forte * stmfCreateTargetGroup 2862fcf3ce44SJohn Forte * 2863fcf3ce44SJohn Forte * Purpose: Create a local port group 2864fcf3ce44SJohn Forte * 2865fcf3ce44SJohn Forte * targetGroupName - name of local port group to create 2866fcf3ce44SJohn Forte */ 2867fcf3ce44SJohn Forte int 2868fcf3ce44SJohn Forte stmfCreateTargetGroup(stmfGroupName *targetGroupName) 2869fcf3ce44SJohn Forte { 2870fcf3ce44SJohn Forte int ret; 2871fcf3ce44SJohn Forte int fd; 2872fcf3ce44SJohn Forte 2873fcf3ce44SJohn Forte if (targetGroupName == NULL || 2874fcf3ce44SJohn Forte (strnlen((char *)targetGroupName, sizeof (stmfGroupName)) 2875fcf3ce44SJohn Forte == sizeof (stmfGroupName))) { 2876fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 2877fcf3ce44SJohn Forte } 2878fcf3ce44SJohn Forte 2879fcf3ce44SJohn Forte /* Check to ensure service exists */ 2880fcf3ce44SJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) { 2881fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND); 2882fcf3ce44SJohn Forte } 2883fcf3ce44SJohn Forte 2884fcf3ce44SJohn Forte /* call init */ 2885fcf3ce44SJohn Forte ret = initializeConfig(); 2886fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 2887fcf3ce44SJohn Forte return (ret); 2888fcf3ce44SJohn Forte } 2889fcf3ce44SJohn Forte 2890fcf3ce44SJohn Forte /* 2891fcf3ce44SJohn Forte * Open control node for stmf 2892fcf3ce44SJohn Forte */ 2893fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 2894fcf3ce44SJohn Forte return (ret); 2895fcf3ce44SJohn Forte 2896fcf3ce44SJohn Forte /* 2897fcf3ce44SJohn Forte * Add the group to the driver 2898fcf3ce44SJohn Forte */ 2899fcf3ce44SJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_TARGET_GROUP, 2900fcf3ce44SJohn Forte targetGroupName)) != STMF_STATUS_SUCCESS) { 2901fcf3ce44SJohn Forte goto done; 2902fcf3ce44SJohn Forte } 2903fcf3ce44SJohn Forte 29048fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 29058fe96085Stim szeto goto done; 29068fe96085Stim szeto } 29078fe96085Stim szeto 2908fcf3ce44SJohn Forte /* 2909fcf3ce44SJohn Forte * If the add to the driver was successful, add it to the persistent 2910fcf3ce44SJohn Forte * store. 2911fcf3ce44SJohn Forte */ 2912fcf3ce44SJohn Forte ret = psCreateTargetGroup((char *)targetGroupName); 2913fcf3ce44SJohn Forte switch (ret) { 2914fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 2915fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 2916fcf3ce44SJohn Forte break; 2917fcf3ce44SJohn Forte case STMF_PS_ERROR_EXISTS: 2918fcf3ce44SJohn Forte ret = STMF_ERROR_EXISTS; 2919fcf3ce44SJohn Forte break; 2920fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 2921fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 2922fcf3ce44SJohn Forte break; 2923fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 2924fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 2925fcf3ce44SJohn Forte break; 2926fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 2927fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 2928fcf3ce44SJohn Forte break; 2929fcf3ce44SJohn Forte default: 2930fcf3ce44SJohn Forte syslog(LOG_DEBUG, 2931fcf3ce44SJohn Forte "stmfCreateTargetGroup:psCreateTargetGroup" 2932fcf3ce44SJohn Forte ":error(%d)", ret); 2933fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 2934fcf3ce44SJohn Forte break; 2935fcf3ce44SJohn Forte } 2936fcf3ce44SJohn Forte 2937fcf3ce44SJohn Forte done: 2938fcf3ce44SJohn Forte (void) close(fd); 2939fcf3ce44SJohn Forte return (ret); 2940fcf3ce44SJohn Forte } 2941fcf3ce44SJohn Forte 2942fcf3ce44SJohn Forte /* 2943fcf3ce44SJohn Forte * stmfDeleteHostGroup 2944fcf3ce44SJohn Forte * 2945fcf3ce44SJohn Forte * Purpose: Delete an initiator or local port group 2946fcf3ce44SJohn Forte * 2947fcf3ce44SJohn Forte * hostGroupName - group to delete 2948fcf3ce44SJohn Forte */ 2949fcf3ce44SJohn Forte int 2950fcf3ce44SJohn Forte stmfDeleteHostGroup(stmfGroupName *hostGroupName) 2951fcf3ce44SJohn Forte { 2952fcf3ce44SJohn Forte int ret; 2953fcf3ce44SJohn Forte int fd; 2954fcf3ce44SJohn Forte 2955fcf3ce44SJohn Forte if (hostGroupName == NULL) { 2956fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 2957fcf3ce44SJohn Forte } 2958fcf3ce44SJohn Forte 2959fcf3ce44SJohn Forte /* Check to ensure service exists */ 2960fcf3ce44SJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) { 2961fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND); 2962fcf3ce44SJohn Forte } 2963fcf3ce44SJohn Forte 2964fcf3ce44SJohn Forte /* call init */ 2965fcf3ce44SJohn Forte ret = initializeConfig(); 2966fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 2967fcf3ce44SJohn Forte return (ret); 2968fcf3ce44SJohn Forte } 2969fcf3ce44SJohn Forte 2970fcf3ce44SJohn Forte /* 2971fcf3ce44SJohn Forte * Open control node for stmf 2972fcf3ce44SJohn Forte */ 2973fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 2974fcf3ce44SJohn Forte return (ret); 2975fcf3ce44SJohn Forte 2976fcf3ce44SJohn Forte /* 2977fcf3ce44SJohn Forte * Remove the group from the driver 2978fcf3ce44SJohn Forte */ 2979fcf3ce44SJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_REMOVE_HOST_GROUP, 2980fcf3ce44SJohn Forte hostGroupName)) != STMF_STATUS_SUCCESS) { 2981fcf3ce44SJohn Forte goto done; 2982fcf3ce44SJohn Forte } 2983fcf3ce44SJohn Forte 29848fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 29858fe96085Stim szeto goto done; 29868fe96085Stim szeto } 29878fe96085Stim szeto 2988fcf3ce44SJohn Forte /* 2989fcf3ce44SJohn Forte * If the remove from the driver was successful, remove it from the 2990fcf3ce44SJohn Forte * persistent store. 2991fcf3ce44SJohn Forte */ 2992fcf3ce44SJohn Forte ret = psDeleteHostGroup((char *)hostGroupName); 2993fcf3ce44SJohn Forte switch (ret) { 2994fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 2995fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 2996fcf3ce44SJohn Forte break; 2997fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 2998fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 2999fcf3ce44SJohn Forte break; 3000fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 3001fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3002fcf3ce44SJohn Forte break; 3003fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 3004fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 3005fcf3ce44SJohn Forte break; 3006fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 3007fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 3008fcf3ce44SJohn Forte break; 3009fcf3ce44SJohn Forte default: 3010fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3011fcf3ce44SJohn Forte "stmfDeleteHostGroup:psDeleteHostGroup:error(%d)", 3012fcf3ce44SJohn Forte ret); 3013fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3014fcf3ce44SJohn Forte break; 3015fcf3ce44SJohn Forte } 3016fcf3ce44SJohn Forte 3017fcf3ce44SJohn Forte done: 3018fcf3ce44SJohn Forte (void) close(fd); 3019fcf3ce44SJohn Forte return (ret); 3020fcf3ce44SJohn Forte } 3021fcf3ce44SJohn Forte 3022fcf3ce44SJohn Forte /* 3023fcf3ce44SJohn Forte * stmfDeleteTargetGroup 3024fcf3ce44SJohn Forte * 3025fcf3ce44SJohn Forte * Purpose: Delete an initiator or local port group 3026fcf3ce44SJohn Forte * 3027fcf3ce44SJohn Forte * targetGroupName - group to delete 3028fcf3ce44SJohn Forte */ 3029fcf3ce44SJohn Forte int 3030fcf3ce44SJohn Forte stmfDeleteTargetGroup(stmfGroupName *targetGroupName) 3031fcf3ce44SJohn Forte { 3032fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 3033fcf3ce44SJohn Forte int fd; 3034fcf3ce44SJohn Forte 3035fcf3ce44SJohn Forte if (targetGroupName == NULL) { 3036fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3037fcf3ce44SJohn Forte } 3038fcf3ce44SJohn Forte 3039fcf3ce44SJohn Forte /* Check to ensure service exists */ 3040fcf3ce44SJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) { 3041fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND); 3042fcf3ce44SJohn Forte } 3043fcf3ce44SJohn Forte 3044fcf3ce44SJohn Forte /* call init */ 3045fcf3ce44SJohn Forte ret = initializeConfig(); 3046fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 3047fcf3ce44SJohn Forte return (ret); 3048fcf3ce44SJohn Forte } 3049fcf3ce44SJohn Forte 3050fcf3ce44SJohn Forte /* 3051fcf3ce44SJohn Forte * Open control node for stmf 3052fcf3ce44SJohn Forte */ 3053fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 3054fcf3ce44SJohn Forte return (ret); 3055fcf3ce44SJohn Forte 3056fcf3ce44SJohn Forte /* 3057fcf3ce44SJohn Forte * Remove the group from the driver 3058fcf3ce44SJohn Forte */ 3059fcf3ce44SJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_REMOVE_TARGET_GROUP, 3060fcf3ce44SJohn Forte targetGroupName)) != STMF_STATUS_SUCCESS) { 3061fcf3ce44SJohn Forte goto done; 3062fcf3ce44SJohn Forte } 3063fcf3ce44SJohn Forte 30648fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 30658fe96085Stim szeto goto done; 30668fe96085Stim szeto } 30678fe96085Stim szeto 3068fcf3ce44SJohn Forte /* 3069fcf3ce44SJohn Forte * If the remove from the driver was successful, remove it from the 3070fcf3ce44SJohn Forte * persistent store. 3071fcf3ce44SJohn Forte */ 3072fcf3ce44SJohn Forte ret = psDeleteTargetGroup((char *)targetGroupName); 3073fcf3ce44SJohn Forte switch (ret) { 3074fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 3075fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 3076fcf3ce44SJohn Forte break; 3077fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 3078fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 3079fcf3ce44SJohn Forte break; 3080fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 3081fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3082fcf3ce44SJohn Forte break; 3083fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 3084fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 3085fcf3ce44SJohn Forte break; 3086fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 3087fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 3088fcf3ce44SJohn Forte break; 3089fcf3ce44SJohn Forte default: 3090fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3091fcf3ce44SJohn Forte "stmfDeleteTargetGroup:psDeleteTargetGroup" 3092fcf3ce44SJohn Forte ":error(%d)", ret); 3093fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3094fcf3ce44SJohn Forte break; 3095fcf3ce44SJohn Forte } 3096fcf3ce44SJohn Forte 3097fcf3ce44SJohn Forte done: 3098fcf3ce44SJohn Forte (void) close(fd); 3099fcf3ce44SJohn Forte return (ret); 3100fcf3ce44SJohn Forte } 3101fcf3ce44SJohn Forte 3102fcf3ce44SJohn Forte /* 3103fcf3ce44SJohn Forte * stmfDevidFromIscsiName 3104fcf3ce44SJohn Forte * 3105fcf3ce44SJohn Forte * Purpose: convert an iSCSI name to an stmf devid 3106fcf3ce44SJohn Forte * 3107fcf3ce44SJohn Forte * iscsiName - unicode nul terminated utf-8 encoded iSCSI name 3108fcf3ce44SJohn Forte * devid - on success, contains the converted iscsi name 3109fcf3ce44SJohn Forte */ 3110fcf3ce44SJohn Forte int 3111fcf3ce44SJohn Forte stmfDevidFromIscsiName(char *iscsiName, stmfDevid *devid) 3112fcf3ce44SJohn Forte { 3113fcf3ce44SJohn Forte if (devid == NULL || iscsiName == NULL) 3114fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3115fcf3ce44SJohn Forte 3116fcf3ce44SJohn Forte bzero(devid, sizeof (stmfDevid)); 3117fcf3ce44SJohn Forte 3118fcf3ce44SJohn Forte /* Validate size of target */ 3119fcf3ce44SJohn Forte if ((devid->identLength = strlen(iscsiName)) > MAX_ISCSI_NAME || 3120fcf3ce44SJohn Forte devid->identLength < strlen(EUI) || 3121fcf3ce44SJohn Forte devid->identLength < strlen(IQN)) { 3122fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3123fcf3ce44SJohn Forte } 3124fcf3ce44SJohn Forte 3125fcf3ce44SJohn Forte if ((strncmp(iscsiName, EUI, strlen(EUI)) != 0) && 3126fcf3ce44SJohn Forte strncmp(iscsiName, IQN, strlen(IQN)) != 0) { 3127fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3128fcf3ce44SJohn Forte } 3129fcf3ce44SJohn Forte 3130fcf3ce44SJohn Forte /* copy UTF-8 bytes to ident */ 3131fcf3ce44SJohn Forte bcopy(iscsiName, devid->ident, devid->identLength); 3132fcf3ce44SJohn Forte 3133fcf3ce44SJohn Forte return (STMF_STATUS_SUCCESS); 3134fcf3ce44SJohn Forte } 3135fcf3ce44SJohn Forte 3136fcf3ce44SJohn Forte /* 3137fcf3ce44SJohn Forte * stmfDevidFromWwn 3138fcf3ce44SJohn Forte * 3139fcf3ce44SJohn Forte * Purpose: convert a WWN to an stmf devid 3140fcf3ce44SJohn Forte * 3141fcf3ce44SJohn Forte * wwn - 8-byte wwn identifier 3142fcf3ce44SJohn Forte * devid - on success, contains the converted wwn 3143fcf3ce44SJohn Forte */ 3144fcf3ce44SJohn Forte int 3145fcf3ce44SJohn Forte stmfDevidFromWwn(uchar_t *wwn, stmfDevid *devid) 3146fcf3ce44SJohn Forte { 3147fcf3ce44SJohn Forte if (wwn == NULL || devid == NULL) 3148fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3149fcf3ce44SJohn Forte 3150fcf3ce44SJohn Forte bzero(devid, sizeof (stmfDevid)); 3151fcf3ce44SJohn Forte 3152fcf3ce44SJohn Forte /* Copy eui prefix */ 3153fcf3ce44SJohn Forte (void) bcopy(WWN, devid->ident, strlen(WWN)); 3154fcf3ce44SJohn Forte 3155fcf3ce44SJohn Forte /* Convert to ASCII uppercase hexadecimal string */ 3156fcf3ce44SJohn Forte (void) snprintf((char *)&devid->ident[strlen(WWN)], 3157fcf3ce44SJohn Forte sizeof (devid->ident), "%02X%02X%02X%02X%02X%02X%02X%02X", 3158fcf3ce44SJohn Forte wwn[0], wwn[1], wwn[2], wwn[3], wwn[4], wwn[5], wwn[6], wwn[7]); 3159fcf3ce44SJohn Forte 3160fcf3ce44SJohn Forte devid->identLength = strlen((char *)devid->ident); 3161fcf3ce44SJohn Forte 3162fcf3ce44SJohn Forte return (STMF_STATUS_SUCCESS); 3163fcf3ce44SJohn Forte } 3164fcf3ce44SJohn Forte 3165fcf3ce44SJohn Forte /* 3166fcf3ce44SJohn Forte * stmfFreeMemory 3167fcf3ce44SJohn Forte * 3168fcf3ce44SJohn Forte * Purpose: Free memory allocated by this library 3169fcf3ce44SJohn Forte * 3170fcf3ce44SJohn Forte * memory - previously allocated pointer of memory managed by library 3171fcf3ce44SJohn Forte */ 3172fcf3ce44SJohn Forte void 3173fcf3ce44SJohn Forte stmfFreeMemory(void *memory) 3174fcf3ce44SJohn Forte { 3175fcf3ce44SJohn Forte free(memory); 3176fcf3ce44SJohn Forte } 3177fcf3ce44SJohn Forte 3178fcf3ce44SJohn Forte /* 31798fe96085Stim szeto * get host group, target group list from stmf 3180fcf3ce44SJohn Forte * 31818fe96085Stim szeto * groupType - HOST_GROUP, TARGET_GROUP 3182fcf3ce44SJohn Forte */ 31838fe96085Stim szeto static int 31848fe96085Stim szeto groupListIoctl(stmfGroupList **groupList, int groupType) 3185fcf3ce44SJohn Forte { 3186fcf3ce44SJohn Forte int ret; 31878fe96085Stim szeto int fd; 31888fe96085Stim szeto int ioctlRet; 31898fe96085Stim szeto int i; 31908fe96085Stim szeto int cmd; 31918fe96085Stim szeto stmf_iocdata_t stmfIoctl; 31928fe96085Stim szeto /* framework group list */ 31938fe96085Stim szeto stmf_group_name_t *iGroupList = NULL; 31948fe96085Stim szeto uint32_t groupListSize; 3195fcf3ce44SJohn Forte 31968fe96085Stim szeto if (groupList == NULL) { 3197fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3198fcf3ce44SJohn Forte } 3199fcf3ce44SJohn Forte 32008fe96085Stim szeto if (groupType == HOST_GROUP) { 32018fe96085Stim szeto cmd = STMF_IOCTL_GET_HG_LIST; 32028fe96085Stim szeto } else if (groupType == TARGET_GROUP) { 32038fe96085Stim szeto cmd = STMF_IOCTL_GET_TG_LIST; 32048fe96085Stim szeto } else { 32058fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 32068fe96085Stim szeto } 32078fe96085Stim szeto 32088fe96085Stim szeto /* call init */ 32098fe96085Stim szeto ret = initializeConfig(); 32108fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 32118fe96085Stim szeto return (ret); 32128fe96085Stim szeto } 32138fe96085Stim szeto 32148fe96085Stim szeto /* 32158fe96085Stim szeto * Open control node for stmf 32168fe96085Stim szeto */ 32178fe96085Stim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 32188fe96085Stim szeto return (ret); 32198fe96085Stim szeto 32208fe96085Stim szeto /* 32218fe96085Stim szeto * Allocate ioctl input buffer 32228fe96085Stim szeto */ 32238fe96085Stim szeto groupListSize = ALLOC_GROUP; 32248fe96085Stim szeto groupListSize = groupListSize * (sizeof (stmf_group_name_t)); 32258fe96085Stim szeto iGroupList = (stmf_group_name_t *)calloc(1, groupListSize); 32268fe96085Stim szeto if (iGroupList == NULL) { 32278fe96085Stim szeto ret = STMF_ERROR_NOMEM; 32288fe96085Stim szeto goto done; 32298fe96085Stim szeto } 32308fe96085Stim szeto 32318fe96085Stim szeto bzero(&stmfIoctl, sizeof (stmfIoctl)); 32328fe96085Stim szeto /* 32338fe96085Stim szeto * Issue ioctl to get the group list 32348fe96085Stim szeto */ 32358fe96085Stim szeto stmfIoctl.stmf_version = STMF_VERSION_1; 32368fe96085Stim szeto stmfIoctl.stmf_obuf_size = groupListSize; 32378fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupList; 32388fe96085Stim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl); 32398fe96085Stim szeto if (ioctlRet != 0) { 32408fe96085Stim szeto switch (errno) { 32418fe96085Stim szeto case EBUSY: 32428fe96085Stim szeto ret = STMF_ERROR_BUSY; 32438fe96085Stim szeto break; 32448fe96085Stim szeto case EPERM: 32458fe96085Stim szeto case EACCES: 32468fe96085Stim szeto ret = STMF_ERROR_PERM; 32478fe96085Stim szeto break; 32488fe96085Stim szeto default: 32498fe96085Stim szeto syslog(LOG_DEBUG, 32508fe96085Stim szeto "groupListIoctl:ioctl errno(%d)", 32518fe96085Stim szeto errno); 32528fe96085Stim szeto ret = STMF_STATUS_ERROR; 32538fe96085Stim szeto break; 32548fe96085Stim szeto } 32558fe96085Stim szeto goto done; 32568fe96085Stim szeto } 32578fe96085Stim szeto /* 32588fe96085Stim szeto * Check whether input buffer was large enough 32598fe96085Stim szeto */ 32608fe96085Stim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_GROUP) { 32618fe96085Stim szeto groupListSize = stmfIoctl.stmf_obuf_max_nentries * 32628fe96085Stim szeto sizeof (stmf_group_name_t); 32638fe96085Stim szeto iGroupList = realloc(iGroupList, groupListSize); 32648fe96085Stim szeto if (iGroupList == NULL) { 32658fe96085Stim szeto ret = STMF_ERROR_NOMEM; 32668fe96085Stim szeto goto done; 32678fe96085Stim szeto } 32688fe96085Stim szeto stmfIoctl.stmf_obuf_size = groupListSize; 32698fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupList; 32708fe96085Stim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl); 32718fe96085Stim szeto if (ioctlRet != 0) { 32728fe96085Stim szeto switch (errno) { 32738fe96085Stim szeto case EBUSY: 32748fe96085Stim szeto ret = STMF_ERROR_BUSY; 32758fe96085Stim szeto break; 32768fe96085Stim szeto case EPERM: 32778fe96085Stim szeto case EACCES: 32788fe96085Stim szeto ret = STMF_ERROR_PERM; 32798fe96085Stim szeto break; 32808fe96085Stim szeto default: 32818fe96085Stim szeto syslog(LOG_DEBUG, 32828fe96085Stim szeto "groupListIoctl:ioctl errno(%d)", 32838fe96085Stim szeto errno); 32848fe96085Stim szeto ret = STMF_STATUS_ERROR; 32858fe96085Stim szeto break; 32868fe96085Stim szeto } 32878fe96085Stim szeto goto done; 32888fe96085Stim szeto } 32898fe96085Stim szeto } 32908fe96085Stim szeto 32918fe96085Stim szeto /* allocate and copy to caller's buffer */ 32924f2997b2Ssrivijitha dugganapalli *groupList = (stmfGroupList *)calloc(1, sizeof (stmfGroupList) + 32934f2997b2Ssrivijitha dugganapalli sizeof (stmfGroupName) * stmfIoctl.stmf_obuf_nentries); 32948fe96085Stim szeto if (*groupList == NULL) { 32958fe96085Stim szeto ret = STMF_ERROR_NOMEM; 32968fe96085Stim szeto goto done; 32978fe96085Stim szeto } 32988fe96085Stim szeto (*groupList)->cnt = stmfIoctl.stmf_obuf_nentries; 32998fe96085Stim szeto for (i = 0; i < stmfIoctl.stmf_obuf_nentries; i++) { 33002f624233SNattuvetty Bhavyan bcopy(iGroupList[i].name, (*groupList)->name[i], 33018fe96085Stim szeto sizeof (stmfGroupName)); 33028fe96085Stim szeto } 33038fe96085Stim szeto 33048fe96085Stim szeto done: 33058fe96085Stim szeto free(iGroupList); 33068fe96085Stim szeto (void) close(fd); 33078fe96085Stim szeto return (ret); 33088fe96085Stim szeto } 33098fe96085Stim szeto 33108fe96085Stim szeto /* 33118fe96085Stim szeto * get host group members, target group members from stmf 33128fe96085Stim szeto * 33138fe96085Stim szeto * groupProps - allocated on success 33148fe96085Stim szeto * 33158fe96085Stim szeto * groupType - HOST_GROUP, TARGET_GROUP 33168fe96085Stim szeto */ 33178fe96085Stim szeto static int 33188fe96085Stim szeto groupMemberListIoctl(stmfGroupName *groupName, stmfGroupProperties **groupProps, 33198fe96085Stim szeto int groupType) 33208fe96085Stim szeto { 33218fe96085Stim szeto int ret; 33228fe96085Stim szeto int fd; 33238fe96085Stim szeto int ioctlRet; 33248fe96085Stim szeto int i; 33258fe96085Stim szeto int cmd; 33268fe96085Stim szeto stmf_iocdata_t stmfIoctl; 33278fe96085Stim szeto /* framework group list */ 33288fe96085Stim szeto stmf_group_name_t iGroupName; 33298fe96085Stim szeto stmf_ge_ident_t *iGroupMembers; 33308fe96085Stim szeto uint32_t groupListSize; 33318fe96085Stim szeto 33328fe96085Stim szeto if (groupName == NULL) { 33338fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 33348fe96085Stim szeto } 33358fe96085Stim szeto 33368fe96085Stim szeto if (groupType == HOST_GROUP) { 33378fe96085Stim szeto cmd = STMF_IOCTL_GET_HG_ENTRIES; 33388fe96085Stim szeto } else if (groupType == TARGET_GROUP) { 33398fe96085Stim szeto cmd = STMF_IOCTL_GET_TG_ENTRIES; 33408fe96085Stim szeto } else { 33418fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 33428fe96085Stim szeto } 33438fe96085Stim szeto 33448fe96085Stim szeto /* call init */ 33458fe96085Stim szeto ret = initializeConfig(); 33468fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 33478fe96085Stim szeto return (ret); 33488fe96085Stim szeto } 33498fe96085Stim szeto 33508fe96085Stim szeto /* 33518fe96085Stim szeto * Open control node for stmf 33528fe96085Stim szeto */ 33538fe96085Stim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 33548fe96085Stim szeto return (ret); 33558fe96085Stim szeto 33568fe96085Stim szeto bzero(&iGroupName, sizeof (iGroupName)); 33578fe96085Stim szeto 33588fe96085Stim szeto bcopy(groupName, &iGroupName.name, strlen((char *)groupName)); 33598fe96085Stim szeto 33608fe96085Stim szeto iGroupName.name_size = strlen((char *)groupName); 33618fe96085Stim szeto 33628fe96085Stim szeto /* 33638fe96085Stim szeto * Allocate ioctl input buffer 33648fe96085Stim szeto */ 33658fe96085Stim szeto groupListSize = ALLOC_GRP_MEMBER; 33668fe96085Stim szeto groupListSize = groupListSize * (sizeof (stmf_ge_ident_t)); 33678fe96085Stim szeto iGroupMembers = (stmf_ge_ident_t *)calloc(1, groupListSize); 33688fe96085Stim szeto if (iGroupMembers == NULL) { 33698fe96085Stim szeto ret = STMF_ERROR_NOMEM; 33708fe96085Stim szeto goto done; 33718fe96085Stim szeto } 33728fe96085Stim szeto 33738fe96085Stim szeto bzero(&stmfIoctl, sizeof (stmfIoctl)); 33748fe96085Stim szeto /* 33758fe96085Stim szeto * Issue ioctl to get the group list 33768fe96085Stim szeto */ 33778fe96085Stim szeto stmfIoctl.stmf_version = STMF_VERSION_1; 33788fe96085Stim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&iGroupName; 33798fe96085Stim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmf_group_name_t); 33808fe96085Stim szeto stmfIoctl.stmf_obuf_size = groupListSize; 33818fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupMembers; 33828fe96085Stim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl); 33838fe96085Stim szeto if (ioctlRet != 0) { 33848fe96085Stim szeto switch (errno) { 33858fe96085Stim szeto case EBUSY: 33868fe96085Stim szeto ret = STMF_ERROR_BUSY; 33878fe96085Stim szeto break; 33888fe96085Stim szeto case EPERM: 33898fe96085Stim szeto case EACCES: 33908fe96085Stim szeto ret = STMF_ERROR_PERM; 33918fe96085Stim szeto break; 33928fe96085Stim szeto default: 33938fe96085Stim szeto syslog(LOG_DEBUG, 33948fe96085Stim szeto "groupListIoctl:ioctl errno(%d)", 33958fe96085Stim szeto errno); 33968fe96085Stim szeto ret = STMF_STATUS_ERROR; 33978fe96085Stim szeto break; 33988fe96085Stim szeto } 33998fe96085Stim szeto goto done; 34008fe96085Stim szeto } 34018fe96085Stim szeto /* 34028fe96085Stim szeto * Check whether input buffer was large enough 34038fe96085Stim szeto */ 34048fe96085Stim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_GRP_MEMBER) { 34058fe96085Stim szeto groupListSize = stmfIoctl.stmf_obuf_max_nentries * 34068fe96085Stim szeto sizeof (stmf_ge_ident_t); 34078fe96085Stim szeto iGroupMembers = realloc(iGroupMembers, groupListSize); 34088fe96085Stim szeto if (iGroupMembers == NULL) { 34098fe96085Stim szeto ret = STMF_ERROR_NOMEM; 34108fe96085Stim szeto goto done; 34118fe96085Stim szeto } 34128fe96085Stim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&iGroupName; 34138fe96085Stim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmf_group_name_t); 34148fe96085Stim szeto stmfIoctl.stmf_obuf_size = groupListSize; 34158fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupMembers; 34168fe96085Stim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl); 34178fe96085Stim szeto if (ioctlRet != 0) { 34188fe96085Stim szeto switch (errno) { 34198fe96085Stim szeto case EBUSY: 34208fe96085Stim szeto ret = STMF_ERROR_BUSY; 34218fe96085Stim szeto break; 34228fe96085Stim szeto case EPERM: 34238fe96085Stim szeto case EACCES: 34248fe96085Stim szeto ret = STMF_ERROR_PERM; 34258fe96085Stim szeto break; 34268fe96085Stim szeto default: 34278fe96085Stim szeto syslog(LOG_DEBUG, 34288fe96085Stim szeto "groupListIoctl:ioctl errno(%d)", 34298fe96085Stim szeto errno); 34308fe96085Stim szeto ret = STMF_STATUS_ERROR; 34318fe96085Stim szeto break; 34328fe96085Stim szeto } 34338fe96085Stim szeto goto done; 34348fe96085Stim szeto } 34358fe96085Stim szeto } 34368fe96085Stim szeto 34378fe96085Stim szeto /* allocate and copy to caller's buffer */ 34388fe96085Stim szeto *groupProps = (stmfGroupProperties *)calloc(1, 34394f2997b2Ssrivijitha dugganapalli sizeof (stmfGroupProperties) + 34404f2997b2Ssrivijitha dugganapalli sizeof (stmfDevid) * stmfIoctl.stmf_obuf_nentries); 34418fe96085Stim szeto if (*groupProps == NULL) { 34428fe96085Stim szeto ret = STMF_ERROR_NOMEM; 34438fe96085Stim szeto goto done; 34448fe96085Stim szeto } 34458fe96085Stim szeto (*groupProps)->cnt = stmfIoctl.stmf_obuf_nentries; 34468fe96085Stim szeto for (i = 0; i < stmfIoctl.stmf_obuf_nentries; i++) { 34478fe96085Stim szeto (*groupProps)->name[i].identLength = 34482f624233SNattuvetty Bhavyan iGroupMembers[i].ident_size; 34492f624233SNattuvetty Bhavyan bcopy(iGroupMembers[i].ident, (*groupProps)->name[i].ident, 34502f624233SNattuvetty Bhavyan iGroupMembers[i].ident_size); 34518fe96085Stim szeto } 34528fe96085Stim szeto 34538fe96085Stim szeto done: 34548fe96085Stim szeto free(iGroupMembers); 34558fe96085Stim szeto (void) close(fd); 34568fe96085Stim szeto return (ret); 34578fe96085Stim szeto } 34588fe96085Stim szeto 34598fe96085Stim szeto /* 34608fe96085Stim szeto * Purpose: access persistent config data for host groups and target groups 34618fe96085Stim szeto */ 34628fe96085Stim szeto static int 34638fe96085Stim szeto iLoadGroupFromPs(stmfGroupList **groupList, int type) 34648fe96085Stim szeto { 34658fe96085Stim szeto int ret; 34668fe96085Stim szeto 34678fe96085Stim szeto if (groupList == NULL) { 34688fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 34698fe96085Stim szeto } 34708fe96085Stim szeto 34718fe96085Stim szeto if (type == HOST_GROUP) { 34728fe96085Stim szeto ret = psGetHostGroupList(groupList); 34738fe96085Stim szeto } else if (type == TARGET_GROUP) { 34748fe96085Stim szeto ret = psGetTargetGroupList(groupList); 34758fe96085Stim szeto } else { 34768fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 34778fe96085Stim szeto } 3478fcf3ce44SJohn Forte switch (ret) { 3479fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 3480fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 3481fcf3ce44SJohn Forte break; 3482fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 3483fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 3484fcf3ce44SJohn Forte break; 3485fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 3486fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3487fcf3ce44SJohn Forte break; 3488fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 3489fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 3490fcf3ce44SJohn Forte break; 3491fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 3492fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 3493fcf3ce44SJohn Forte break; 3494fcf3ce44SJohn Forte default: 3495fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3496fcf3ce44SJohn Forte "stmfGetHostGroupList:psGetHostGroupList:error(%d)", 3497fcf3ce44SJohn Forte ret); 3498fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3499fcf3ce44SJohn Forte break; 3500fcf3ce44SJohn Forte } 3501fcf3ce44SJohn Forte 3502fcf3ce44SJohn Forte return (ret); 3503fcf3ce44SJohn Forte } 3504fcf3ce44SJohn Forte 3505fcf3ce44SJohn Forte /* 35068fe96085Stim szeto * stmfGetHostGroupList 3507fcf3ce44SJohn Forte * 35088fe96085Stim szeto * Purpose: Retrieves the list of initiator group oids 3509fcf3ce44SJohn Forte * 35108fe96085Stim szeto * hostGroupList - pointer to pointer to hostGroupList structure 35118fe96085Stim szeto * on success, this contains the host group list. 3512fcf3ce44SJohn Forte */ 3513fcf3ce44SJohn Forte int 35148fe96085Stim szeto stmfGetHostGroupList(stmfGroupList **hostGroupList) 3515fcf3ce44SJohn Forte { 35168fe96085Stim szeto int ret = STMF_STATUS_ERROR; 3517fcf3ce44SJohn Forte 35188fe96085Stim szeto if (hostGroupList == NULL) { 3519fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3520fcf3ce44SJohn Forte } 3521fcf3ce44SJohn Forte 35228fe96085Stim szeto ret = groupListIoctl(hostGroupList, HOST_GROUP); 35238fe96085Stim szeto return (ret); 35248fe96085Stim szeto } 35258fe96085Stim szeto 35268fe96085Stim szeto 35278fe96085Stim szeto /* 35288fe96085Stim szeto * Purpose: access persistent config data for host groups and target groups 35298fe96085Stim szeto */ 35308fe96085Stim szeto static int 35318fe96085Stim szeto iLoadGroupMembersFromPs(stmfGroupName *groupName, 35328fe96085Stim szeto stmfGroupProperties **groupProp, int type) 35338fe96085Stim szeto { 35348fe96085Stim szeto int ret; 35358fe96085Stim szeto 35368fe96085Stim szeto if (groupName == NULL) { 35378fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 35388fe96085Stim szeto } 35398fe96085Stim szeto 35408fe96085Stim szeto if (type == HOST_GROUP) { 3541fcf3ce44SJohn Forte ret = psGetHostGroupMemberList((char *)groupName, groupProp); 35428fe96085Stim szeto } else if (type == TARGET_GROUP) { 35438fe96085Stim szeto ret = psGetTargetGroupMemberList((char *)groupName, groupProp); 35448fe96085Stim szeto } else { 35458fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 35468fe96085Stim szeto } 3547fcf3ce44SJohn Forte switch (ret) { 3548fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 3549fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 3550fcf3ce44SJohn Forte break; 3551fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 3552fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 3553fcf3ce44SJohn Forte break; 3554fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 3555fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3556fcf3ce44SJohn Forte break; 3557fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 3558fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 3559fcf3ce44SJohn Forte break; 3560fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 3561fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 3562fcf3ce44SJohn Forte break; 3563fcf3ce44SJohn Forte default: 3564fcf3ce44SJohn Forte syslog(LOG_DEBUG, 35658fe96085Stim szeto "iLoadGroupMembersFromPs:psGetHostGroupList:" 35668fe96085Stim szeto "error(%d)", ret); 3567fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3568fcf3ce44SJohn Forte break; 3569fcf3ce44SJohn Forte } 3570fcf3ce44SJohn Forte 3571fcf3ce44SJohn Forte return (ret); 3572fcf3ce44SJohn Forte } 3573fcf3ce44SJohn Forte 3574fcf3ce44SJohn Forte /* 35758fe96085Stim szeto * stmfGetHostGroupMembers 35768fe96085Stim szeto * 35778fe96085Stim szeto * Purpose: Retrieves the group properties for a host group 35788fe96085Stim szeto * 35798fe96085Stim szeto * groupName - name of group for which to retrieve host group members. 35808fe96085Stim szeto * groupProp - pointer to pointer to stmfGroupProperties structure 35818fe96085Stim szeto * on success, this contains the list of group members. 35828fe96085Stim szeto */ 35838fe96085Stim szeto int 35848fe96085Stim szeto stmfGetHostGroupMembers(stmfGroupName *groupName, 35858fe96085Stim szeto stmfGroupProperties **groupProp) 35868fe96085Stim szeto { 35878fe96085Stim szeto int ret; 35888fe96085Stim szeto 35898fe96085Stim szeto if (groupName == NULL || groupProp == NULL) { 35908fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 35918fe96085Stim szeto } 35928fe96085Stim szeto 35938fe96085Stim szeto ret = groupMemberListIoctl(groupName, groupProp, HOST_GROUP); 35948fe96085Stim szeto 35958fe96085Stim szeto return (ret); 35968fe96085Stim szeto } 35978fe96085Stim szeto 35988fe96085Stim szeto /* 3599fcf3ce44SJohn Forte * stmfGetProviderData 3600fcf3ce44SJohn Forte * 3601fcf3ce44SJohn Forte * Purpose: Get provider data list 3602fcf3ce44SJohn Forte * 3603fcf3ce44SJohn Forte * providerName - name of provider for which to retrieve the data 3604fcf3ce44SJohn Forte * nvl - pointer to nvlist_t pointer which will contain the nvlist data 3605fcf3ce44SJohn Forte * retrieved. 3606fcf3ce44SJohn Forte * providerType - type of provider for which to retrieve data. 3607fcf3ce44SJohn Forte * STMF_LU_PROVIDER_TYPE 3608fcf3ce44SJohn Forte * STMF_PORT_PROVIDER_TYPE 3609fcf3ce44SJohn Forte */ 3610fcf3ce44SJohn Forte int 3611fcf3ce44SJohn Forte stmfGetProviderData(char *providerName, nvlist_t **nvl, int providerType) 3612fcf3ce44SJohn Forte { 3613fcf3ce44SJohn Forte return (stmfGetProviderDataProt(providerName, nvl, providerType, 3614fcf3ce44SJohn Forte NULL)); 3615fcf3ce44SJohn Forte } 3616fcf3ce44SJohn Forte 3617fcf3ce44SJohn Forte /* 3618fcf3ce44SJohn Forte * stmfGetProviderDataProt 3619fcf3ce44SJohn Forte * 3620fcf3ce44SJohn Forte * Purpose: Get provider data list with token 3621fcf3ce44SJohn Forte * 3622fcf3ce44SJohn Forte * providerName - name of provider for which to retrieve the data 3623fcf3ce44SJohn Forte * nvl - pointer to nvlist_t pointer which will contain the nvlist data 3624fcf3ce44SJohn Forte * retrieved. 3625fcf3ce44SJohn Forte * providerType - type of provider for which to retrieve data. 3626fcf3ce44SJohn Forte * STMF_LU_PROVIDER_TYPE 3627fcf3ce44SJohn Forte * STMF_PORT_PROVIDER_TYPE 3628fcf3ce44SJohn Forte * setToken - Returns the stale data token 3629fcf3ce44SJohn Forte */ 3630fcf3ce44SJohn Forte int 3631fcf3ce44SJohn Forte stmfGetProviderDataProt(char *providerName, nvlist_t **nvl, int providerType, 3632fcf3ce44SJohn Forte uint64_t *setToken) 3633fcf3ce44SJohn Forte { 3634fcf3ce44SJohn Forte int ret; 3635fcf3ce44SJohn Forte 3636fcf3ce44SJohn Forte if (providerName == NULL || nvl == NULL) { 3637fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3638fcf3ce44SJohn Forte } 3639fcf3ce44SJohn Forte if (providerType != STMF_LU_PROVIDER_TYPE && 3640fcf3ce44SJohn Forte providerType != STMF_PORT_PROVIDER_TYPE) { 3641fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3642fcf3ce44SJohn Forte } 3643fcf3ce44SJohn Forte /* call init */ 3644fcf3ce44SJohn Forte ret = initializeConfig(); 3645fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 3646fcf3ce44SJohn Forte return (ret); 3647fcf3ce44SJohn Forte } 36488fe96085Stim szeto return (getProviderData(providerName, nvl, providerType, setToken)); 3649fcf3ce44SJohn Forte } 3650fcf3ce44SJohn Forte 3651fcf3ce44SJohn Forte /* 3652fcf3ce44SJohn Forte * stmfGetProviderDataList 3653fcf3ce44SJohn Forte * 3654fcf3ce44SJohn Forte * Purpose: Get the list of providers currently persisting data 3655fcf3ce44SJohn Forte * 3656fcf3ce44SJohn Forte * providerList - pointer to pointer to an stmfProviderList structure allocated 3657fcf3ce44SJohn Forte * by the caller. Will contain the list of providers on success. 3658fcf3ce44SJohn Forte */ 3659fcf3ce44SJohn Forte int 3660fcf3ce44SJohn Forte stmfGetProviderDataList(stmfProviderList **providerList) 3661fcf3ce44SJohn Forte { 3662fcf3ce44SJohn Forte int ret; 3663fcf3ce44SJohn Forte 3664fcf3ce44SJohn Forte ret = psGetProviderDataList(providerList); 3665fcf3ce44SJohn Forte switch (ret) { 3666fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 3667fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 3668fcf3ce44SJohn Forte break; 3669fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 3670fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3671fcf3ce44SJohn Forte break; 3672fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 3673fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 3674fcf3ce44SJohn Forte break; 3675fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 3676fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 3677fcf3ce44SJohn Forte break; 3678fcf3ce44SJohn Forte default: 3679fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3680fcf3ce44SJohn Forte "stmfGetProviderDataList:psGetProviderDataList" 3681fcf3ce44SJohn Forte ":error(%d)", ret); 3682fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3683fcf3ce44SJohn Forte break; 3684fcf3ce44SJohn Forte } 3685fcf3ce44SJohn Forte 3686fcf3ce44SJohn Forte return (ret); 3687fcf3ce44SJohn Forte } 3688fcf3ce44SJohn Forte 3689fcf3ce44SJohn Forte 3690fcf3ce44SJohn Forte /* 3691fcf3ce44SJohn Forte * stmfGetSessionList 3692fcf3ce44SJohn Forte * 3693fcf3ce44SJohn Forte * Purpose: Retrieves the session list for a target (devid) 3694fcf3ce44SJohn Forte * 3695fcf3ce44SJohn Forte * devid - devid of target for which to retrieve session information. 3696fcf3ce44SJohn Forte * sessionList - pointer to pointer to stmfSessionList structure 3697fcf3ce44SJohn Forte * on success, this contains the list of initiator sessions. 3698fcf3ce44SJohn Forte */ 3699fcf3ce44SJohn Forte int 3700fcf3ce44SJohn Forte stmfGetSessionList(stmfDevid *devid, stmfSessionList **sessionList) 3701fcf3ce44SJohn Forte { 3702fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 3703fcf3ce44SJohn Forte int fd; 3704fcf3ce44SJohn Forte int ioctlRet; 3705fcf3ce44SJohn Forte int cmd = STMF_IOCTL_SESSION_LIST; 3706fcf3ce44SJohn Forte int i; 3707fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 370856261083SCharles Ting slist_scsi_session_t *fSessionList, *fSessionListP = NULL; 3709fcf3ce44SJohn Forte uint8_t ident[260]; 3710fcf3ce44SJohn Forte uint32_t fSessionListSize; 3711fcf3ce44SJohn Forte 3712fcf3ce44SJohn Forte if (sessionList == NULL || devid == NULL) { 3713fcf3ce44SJohn Forte ret = STMF_ERROR_INVALID_ARG; 3714fcf3ce44SJohn Forte } 3715fcf3ce44SJohn Forte 3716fcf3ce44SJohn Forte /* call init */ 3717fcf3ce44SJohn Forte ret = initializeConfig(); 3718fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 3719fcf3ce44SJohn Forte return (ret); 3720fcf3ce44SJohn Forte } 3721fcf3ce44SJohn Forte 3722fcf3ce44SJohn Forte /* 3723fcf3ce44SJohn Forte * Open control node for stmf 3724fcf3ce44SJohn Forte */ 3725fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 3726fcf3ce44SJohn Forte return (ret); 3727fcf3ce44SJohn Forte 3728fcf3ce44SJohn Forte /* 3729fcf3ce44SJohn Forte * Allocate ioctl input buffer 3730fcf3ce44SJohn Forte */ 37318fe96085Stim szeto fSessionListSize = ALLOC_SESSION; 3732fcf3ce44SJohn Forte fSessionListSize = fSessionListSize * (sizeof (slist_scsi_session_t)); 3733fcf3ce44SJohn Forte fSessionList = (slist_scsi_session_t *)calloc(1, fSessionListSize); 373456261083SCharles Ting fSessionListP = fSessionList; 3735fcf3ce44SJohn Forte if (fSessionList == NULL) { 373656261083SCharles Ting ret = STMF_ERROR_NOMEM; 373756261083SCharles Ting goto done; 3738fcf3ce44SJohn Forte } 3739fcf3ce44SJohn Forte 3740fcf3ce44SJohn Forte ident[IDENT_LENGTH_BYTE] = devid->identLength; 3741fcf3ce44SJohn Forte bcopy(&(devid->ident), &ident[IDENT_LENGTH_BYTE + 1], 3742fcf3ce44SJohn Forte devid->identLength); 3743fcf3ce44SJohn Forte 3744fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 3745fcf3ce44SJohn Forte /* 3746fcf3ce44SJohn Forte * Issue ioctl to get the session list 3747fcf3ce44SJohn Forte */ 3748fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 3749fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ident; 3750fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (ident); 3751fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = fSessionListSize; 3752fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fSessionList; 3753fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 3754fcf3ce44SJohn Forte if (ioctlRet != 0) { 3755fcf3ce44SJohn Forte switch (errno) { 3756fcf3ce44SJohn Forte case EBUSY: 3757fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3758fcf3ce44SJohn Forte break; 37598fe96085Stim szeto case EPERM: 3760fcf3ce44SJohn Forte case EACCES: 3761fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 3762fcf3ce44SJohn Forte break; 3763fcf3ce44SJohn Forte default: 3764fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3765fcf3ce44SJohn Forte "stmfGetSessionList:ioctl errno(%d)", 3766fcf3ce44SJohn Forte errno); 3767fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3768fcf3ce44SJohn Forte break; 3769fcf3ce44SJohn Forte } 3770fcf3ce44SJohn Forte goto done; 3771fcf3ce44SJohn Forte } 3772fcf3ce44SJohn Forte /* 3773fcf3ce44SJohn Forte * Check whether input buffer was large enough 3774fcf3ce44SJohn Forte */ 37758fe96085Stim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_SESSION) { 3776fcf3ce44SJohn Forte fSessionListSize = stmfIoctl.stmf_obuf_max_nentries * 3777fcf3ce44SJohn Forte sizeof (slist_scsi_session_t); 3778fcf3ce44SJohn Forte fSessionList = realloc(fSessionList, fSessionListSize); 3779fcf3ce44SJohn Forte if (fSessionList == NULL) { 378056261083SCharles Ting ret = STMF_ERROR_NOMEM; 378156261083SCharles Ting goto done; 3782fcf3ce44SJohn Forte } 378356261083SCharles Ting fSessionListP = fSessionList; 3784fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = fSessionListSize; 3785fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fSessionList; 3786fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 3787fcf3ce44SJohn Forte if (ioctlRet != 0) { 3788fcf3ce44SJohn Forte switch (errno) { 3789fcf3ce44SJohn Forte case EBUSY: 3790fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3791fcf3ce44SJohn Forte break; 37928fe96085Stim szeto case EPERM: 3793fcf3ce44SJohn Forte case EACCES: 3794fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 3795fcf3ce44SJohn Forte break; 3796fcf3ce44SJohn Forte default: 3797fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3798fcf3ce44SJohn Forte "stmfGetSessionList:ioctl " 3799fcf3ce44SJohn Forte "errno(%d)", errno); 3800fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3801fcf3ce44SJohn Forte break; 3802fcf3ce44SJohn Forte } 3803fcf3ce44SJohn Forte goto done; 3804fcf3ce44SJohn Forte } 3805fcf3ce44SJohn Forte } 3806fcf3ce44SJohn Forte 3807fcf3ce44SJohn Forte /* 3808fcf3ce44SJohn Forte * allocate caller's buffer with the final size 3809fcf3ce44SJohn Forte */ 3810fcf3ce44SJohn Forte *sessionList = (stmfSessionList *)calloc(1, sizeof (stmfSessionList) + 3811fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_max_nentries * sizeof (stmfSession)); 3812fcf3ce44SJohn Forte if (*sessionList == NULL) { 3813fcf3ce44SJohn Forte ret = STMF_ERROR_NOMEM; 3814fcf3ce44SJohn Forte free(sessionList); 3815fcf3ce44SJohn Forte goto done; 3816fcf3ce44SJohn Forte } 3817fcf3ce44SJohn Forte 3818fcf3ce44SJohn Forte (*sessionList)->cnt = stmfIoctl.stmf_obuf_max_nentries; 3819fcf3ce44SJohn Forte 3820fcf3ce44SJohn Forte /* 3821fcf3ce44SJohn Forte * copy session info to caller's buffer 3822fcf3ce44SJohn Forte */ 3823fcf3ce44SJohn Forte for (i = 0; i < (*sessionList)->cnt; i++) { 3824fcf3ce44SJohn Forte (*sessionList)->session[i].initiator.identLength = 3825fcf3ce44SJohn Forte fSessionList->initiator[IDENT_LENGTH_BYTE]; 3826fcf3ce44SJohn Forte bcopy(&(fSessionList->initiator[IDENT_LENGTH_BYTE + 1]), 3827fcf3ce44SJohn Forte (*sessionList)->session[i].initiator.ident, 3828fcf3ce44SJohn Forte STMF_IDENT_LENGTH); 3829fcf3ce44SJohn Forte bcopy(&(fSessionList->alias), 3830fcf3ce44SJohn Forte &((*sessionList)->session[i].alias), 3831fcf3ce44SJohn Forte sizeof ((*sessionList)->session[i].alias)); 3832fcf3ce44SJohn Forte bcopy(&(fSessionList++->creation_time), 3833fcf3ce44SJohn Forte &((*sessionList)->session[i].creationTime), 3834fcf3ce44SJohn Forte sizeof (time_t)); 3835fcf3ce44SJohn Forte } 3836fcf3ce44SJohn Forte done: 3837fcf3ce44SJohn Forte (void) close(fd); 383856261083SCharles Ting free(fSessionListP); 3839fcf3ce44SJohn Forte return (ret); 3840fcf3ce44SJohn Forte } 3841fcf3ce44SJohn Forte 3842fcf3ce44SJohn Forte /* 3843fcf3ce44SJohn Forte * stmfGetTargetGroupList 3844fcf3ce44SJohn Forte * 3845fcf3ce44SJohn Forte * Purpose: Retrieves the list of target groups 3846fcf3ce44SJohn Forte * 3847fcf3ce44SJohn Forte * targetGroupList - pointer to a pointer to an stmfGroupList structure. On 3848fcf3ce44SJohn Forte * success, it contains the list of target groups. 3849fcf3ce44SJohn Forte */ 3850fcf3ce44SJohn Forte int 3851fcf3ce44SJohn Forte stmfGetTargetGroupList(stmfGroupList **targetGroupList) 3852fcf3ce44SJohn Forte { 3853fcf3ce44SJohn Forte int ret; 3854fcf3ce44SJohn Forte 3855fcf3ce44SJohn Forte if (targetGroupList == NULL) { 3856fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3857fcf3ce44SJohn Forte } 3858fcf3ce44SJohn Forte 38598fe96085Stim szeto ret = groupListIoctl(targetGroupList, TARGET_GROUP); 3860fcf3ce44SJohn Forte return (ret); 3861fcf3ce44SJohn Forte } 3862fcf3ce44SJohn Forte 3863fcf3ce44SJohn Forte /* 3864fcf3ce44SJohn Forte * stmfGetTargetGroupMembers 3865fcf3ce44SJohn Forte * 3866fcf3ce44SJohn Forte * Purpose: Retrieves the group members for a target group 3867fcf3ce44SJohn Forte * 3868fcf3ce44SJohn Forte * groupName - name of target group for which to retrieve members. 3869fcf3ce44SJohn Forte * groupProp - pointer to pointer to stmfGroupProperties structure 3870fcf3ce44SJohn Forte * on success, this contains the list of group members. 3871fcf3ce44SJohn Forte */ 3872fcf3ce44SJohn Forte int 3873fcf3ce44SJohn Forte stmfGetTargetGroupMembers(stmfGroupName *groupName, 3874fcf3ce44SJohn Forte stmfGroupProperties **groupProp) 3875fcf3ce44SJohn Forte { 3876fcf3ce44SJohn Forte int ret; 3877fcf3ce44SJohn Forte 3878fcf3ce44SJohn Forte if (groupName == NULL || groupProp == NULL) { 3879fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3880fcf3ce44SJohn Forte } 3881fcf3ce44SJohn Forte 38828fe96085Stim szeto ret = groupMemberListIoctl(groupName, groupProp, TARGET_GROUP); 3883fcf3ce44SJohn Forte 3884fcf3ce44SJohn Forte return (ret); 3885fcf3ce44SJohn Forte } 3886fcf3ce44SJohn Forte 3887fcf3ce44SJohn Forte /* 3888fcf3ce44SJohn Forte * stmfGetTargetList 3889fcf3ce44SJohn Forte * 3890fcf3ce44SJohn Forte * Purpose: Retrieves the list of target ports 3891fcf3ce44SJohn Forte * 3892fcf3ce44SJohn Forte * targetList - pointer to a pointer to an stmfDevidList structure. 3893fcf3ce44SJohn Forte * On success, it contains the list of local ports (target). 3894fcf3ce44SJohn Forte */ 3895fcf3ce44SJohn Forte int 3896fcf3ce44SJohn Forte stmfGetTargetList(stmfDevidList **targetList) 3897fcf3ce44SJohn Forte { 3898fcf3ce44SJohn Forte int ret; 3899fcf3ce44SJohn Forte int fd; 3900fcf3ce44SJohn Forte int ioctlRet; 3901fcf3ce44SJohn Forte int i; 3902fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 3903fcf3ce44SJohn Forte /* framework target port list */ 39048fe96085Stim szeto slist_target_port_t *fTargetList, *fTargetListP = NULL; 3905fcf3ce44SJohn Forte uint32_t fTargetListSize; 3906fcf3ce44SJohn Forte 3907fcf3ce44SJohn Forte if (targetList == NULL) { 3908fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 3909fcf3ce44SJohn Forte } 3910fcf3ce44SJohn Forte 3911fcf3ce44SJohn Forte /* call init */ 3912fcf3ce44SJohn Forte ret = initializeConfig(); 3913fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 3914fcf3ce44SJohn Forte return (ret); 3915fcf3ce44SJohn Forte } 3916fcf3ce44SJohn Forte 3917fcf3ce44SJohn Forte /* 3918fcf3ce44SJohn Forte * Open control node for stmf 3919fcf3ce44SJohn Forte */ 3920fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 3921fcf3ce44SJohn Forte return (ret); 3922fcf3ce44SJohn Forte 3923fcf3ce44SJohn Forte /* 3924fcf3ce44SJohn Forte * Allocate ioctl input buffer 3925fcf3ce44SJohn Forte */ 39268fe96085Stim szeto fTargetListSize = ALLOC_TARGET_PORT * sizeof (slist_target_port_t); 39273e7352aeSJohn Forte fTargetListP = fTargetList = 39283e7352aeSJohn Forte (slist_target_port_t *)calloc(1, fTargetListSize); 3929fcf3ce44SJohn Forte if (fTargetList == NULL) { 39308fe96085Stim szeto ret = STMF_ERROR_NOMEM; 3931fcf3ce44SJohn Forte goto done; 3932fcf3ce44SJohn Forte } 3933fcf3ce44SJohn Forte 3934fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 3935fcf3ce44SJohn Forte /* 39363e7352aeSJohn Forte * Issue ioctl to retrieve target list 3937fcf3ce44SJohn Forte */ 3938fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 3939fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = fTargetListSize; 3940fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fTargetList; 3941fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_TARGET_PORT_LIST, &stmfIoctl); 3942fcf3ce44SJohn Forte if (ioctlRet != 0) { 3943fcf3ce44SJohn Forte switch (errno) { 3944fcf3ce44SJohn Forte case EBUSY: 3945fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3946fcf3ce44SJohn Forte break; 39478fe96085Stim szeto case EPERM: 3948fcf3ce44SJohn Forte case EACCES: 3949fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 3950fcf3ce44SJohn Forte break; 3951fcf3ce44SJohn Forte default: 3952fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3953fcf3ce44SJohn Forte "stmfGetTargetList:ioctl errno(%d)", errno); 3954fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3955fcf3ce44SJohn Forte break; 3956fcf3ce44SJohn Forte } 3957fcf3ce44SJohn Forte goto done; 3958fcf3ce44SJohn Forte } 3959fcf3ce44SJohn Forte /* 3960fcf3ce44SJohn Forte * Check whether input buffer was large enough 3961fcf3ce44SJohn Forte */ 39628fe96085Stim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_TARGET_PORT) { 3963fcf3ce44SJohn Forte fTargetListSize = stmfIoctl.stmf_obuf_max_nentries * 396476602b8dSJohn Forte sizeof (slist_target_port_t); 39653e7352aeSJohn Forte fTargetListP = fTargetList = 39663e7352aeSJohn Forte realloc(fTargetList, fTargetListSize); 3967fcf3ce44SJohn Forte if (fTargetList == NULL) { 39688fe96085Stim szeto ret = STMF_ERROR_NOMEM; 39698fe96085Stim szeto goto done; 3970fcf3ce44SJohn Forte } 3971fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = fTargetListSize; 3972fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fTargetList; 3973fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_TARGET_PORT_LIST, 3974fcf3ce44SJohn Forte &stmfIoctl); 3975fcf3ce44SJohn Forte if (ioctlRet != 0) { 3976fcf3ce44SJohn Forte switch (errno) { 3977fcf3ce44SJohn Forte case EBUSY: 3978fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 3979fcf3ce44SJohn Forte break; 39808fe96085Stim szeto case EPERM: 3981fcf3ce44SJohn Forte case EACCES: 3982fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 3983fcf3ce44SJohn Forte break; 3984fcf3ce44SJohn Forte default: 3985fcf3ce44SJohn Forte syslog(LOG_DEBUG, 3986fcf3ce44SJohn Forte "stmfGetTargetList:ioctl errno(%d)", 3987fcf3ce44SJohn Forte errno); 3988fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 3989fcf3ce44SJohn Forte break; 3990fcf3ce44SJohn Forte } 3991fcf3ce44SJohn Forte goto done; 3992fcf3ce44SJohn Forte } 3993fcf3ce44SJohn Forte } 3994fcf3ce44SJohn Forte 3995fcf3ce44SJohn Forte *targetList = (stmfDevidList *)calloc(1, 3996fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_max_nentries * sizeof (stmfDevid) + 3997fcf3ce44SJohn Forte sizeof (stmfDevidList)); 39988fe96085Stim szeto if (*targetList == NULL) { 39998fe96085Stim szeto ret = STMF_ERROR_NOMEM; 40008fe96085Stim szeto goto done; 40018fe96085Stim szeto } 4002fcf3ce44SJohn Forte 4003fcf3ce44SJohn Forte (*targetList)->cnt = stmfIoctl.stmf_obuf_max_nentries; 4004fcf3ce44SJohn Forte for (i = 0; i < stmfIoctl.stmf_obuf_max_nentries; i++, fTargetList++) { 4005fcf3ce44SJohn Forte (*targetList)->devid[i].identLength = 4006fcf3ce44SJohn Forte fTargetList->target[IDENT_LENGTH_BYTE]; 4007fcf3ce44SJohn Forte bcopy(&fTargetList->target[IDENT_LENGTH_BYTE + 1], 4008fcf3ce44SJohn Forte &(*targetList)->devid[i].ident, 4009fcf3ce44SJohn Forte fTargetList->target[IDENT_LENGTH_BYTE]); 4010fcf3ce44SJohn Forte } 4011fcf3ce44SJohn Forte 4012fcf3ce44SJohn Forte done: 4013fcf3ce44SJohn Forte (void) close(fd); 40143e7352aeSJohn Forte free(fTargetListP); 4015fcf3ce44SJohn Forte return (ret); 4016fcf3ce44SJohn Forte } 4017fcf3ce44SJohn Forte 4018fcf3ce44SJohn Forte /* 4019fcf3ce44SJohn Forte * stmfGetTargetProperties 4020fcf3ce44SJohn Forte * 4021fcf3ce44SJohn Forte * Purpose: Retrieves the properties for a logical unit 4022fcf3ce44SJohn Forte * 4023fcf3ce44SJohn Forte * devid - devid of the target for which to retrieve properties 4024fcf3ce44SJohn Forte * targetProps - pointer to an stmfTargetProperties structure. 4025fcf3ce44SJohn Forte * On success, it contains the target properties for 4026fcf3ce44SJohn Forte * the specified devid. 4027fcf3ce44SJohn Forte */ 4028fcf3ce44SJohn Forte int 4029fcf3ce44SJohn Forte stmfGetTargetProperties(stmfDevid *devid, stmfTargetProperties *targetProps) 4030fcf3ce44SJohn Forte { 4031fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 4032fcf3ce44SJohn Forte int fd; 4033fcf3ce44SJohn Forte int ioctlRet; 4034fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 4035fcf3ce44SJohn Forte sioc_target_port_props_t targetProperties; 4036*45039663SJohn Forte scsi_devid_desc_t *scsiDevid; 4037fcf3ce44SJohn Forte 4038fcf3ce44SJohn Forte if (devid == NULL || targetProps == NULL) { 4039fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 4040fcf3ce44SJohn Forte } 4041fcf3ce44SJohn Forte 4042fcf3ce44SJohn Forte /* call init */ 4043fcf3ce44SJohn Forte ret = initializeConfig(); 4044fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4045fcf3ce44SJohn Forte return (ret); 4046fcf3ce44SJohn Forte } 4047fcf3ce44SJohn Forte 4048fcf3ce44SJohn Forte /* 4049fcf3ce44SJohn Forte * Open control node for stmf 4050fcf3ce44SJohn Forte */ 4051fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 4052fcf3ce44SJohn Forte return (ret); 4053fcf3ce44SJohn Forte 4054fcf3ce44SJohn Forte targetProperties.tgt_id[IDENT_LENGTH_BYTE] = devid->identLength; 4055fcf3ce44SJohn Forte bcopy(&(devid->ident), &targetProperties.tgt_id[IDENT_LENGTH_BYTE + 1], 4056fcf3ce44SJohn Forte devid->identLength); 4057fcf3ce44SJohn Forte 4058fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 4059fcf3ce44SJohn Forte /* 4060fcf3ce44SJohn Forte * Issue ioctl to add to the host group 4061fcf3ce44SJohn Forte */ 4062fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 4063fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (targetProperties.tgt_id); 4064fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&targetProperties.tgt_id; 4065fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&targetProperties; 4066fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = sizeof (targetProperties); 4067fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_GET_TARGET_PORT_PROPERTIES, 4068fcf3ce44SJohn Forte &stmfIoctl); 4069fcf3ce44SJohn Forte if (ioctlRet != 0) { 4070fcf3ce44SJohn Forte switch (errno) { 4071fcf3ce44SJohn Forte case EBUSY: 4072fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4073fcf3ce44SJohn Forte break; 40748fe96085Stim szeto case EPERM: 4075fcf3ce44SJohn Forte case EACCES: 4076fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 4077fcf3ce44SJohn Forte break; 4078fcf3ce44SJohn Forte case ENOENT: 4079fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4080fcf3ce44SJohn Forte break; 4081fcf3ce44SJohn Forte default: 4082fcf3ce44SJohn Forte syslog(LOG_DEBUG, 4083fcf3ce44SJohn Forte "stmfGetTargetProperties:ioctl errno(%d)", 4084fcf3ce44SJohn Forte errno); 4085fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4086fcf3ce44SJohn Forte break; 4087fcf3ce44SJohn Forte } 4088fcf3ce44SJohn Forte goto done; 4089fcf3ce44SJohn Forte } 4090fcf3ce44SJohn Forte 4091fcf3ce44SJohn Forte bcopy(targetProperties.tgt_provider_name, targetProps->providerName, 4092fcf3ce44SJohn Forte sizeof (targetProperties.tgt_provider_name)); 4093fcf3ce44SJohn Forte if (targetProperties.tgt_state == STMF_STATE_ONLINE) { 4094fcf3ce44SJohn Forte targetProps->status = STMF_TARGET_PORT_ONLINE; 4095fcf3ce44SJohn Forte } else if (targetProperties.tgt_state == STMF_STATE_OFFLINE) { 4096fcf3ce44SJohn Forte targetProps->status = STMF_TARGET_PORT_OFFLINE; 4097fcf3ce44SJohn Forte } else if (targetProperties.tgt_state == STMF_STATE_ONLINING) { 4098fcf3ce44SJohn Forte targetProps->status = STMF_TARGET_PORT_ONLINING; 4099fcf3ce44SJohn Forte } else if (targetProperties.tgt_state == STMF_STATE_OFFLINING) { 4100fcf3ce44SJohn Forte targetProps->status = STMF_TARGET_PORT_OFFLINING; 4101fcf3ce44SJohn Forte } 4102fcf3ce44SJohn Forte bcopy(targetProperties.tgt_alias, targetProps->alias, 4103fcf3ce44SJohn Forte sizeof (targetProps->alias)); 4104*45039663SJohn Forte 4105*45039663SJohn Forte scsiDevid = (scsi_devid_desc_t *)&targetProperties.tgt_id; 4106*45039663SJohn Forte targetProps->protocol = scsiDevid->protocol_id; 4107*45039663SJohn Forte 4108fcf3ce44SJohn Forte done: 4109fcf3ce44SJohn Forte (void) close(fd); 4110fcf3ce44SJohn Forte return (ret); 4111fcf3ce44SJohn Forte } 4112fcf3ce44SJohn Forte 4113fcf3ce44SJohn Forte /* 4114fcf3ce44SJohn Forte * stmfGetLogicalUnitList 4115fcf3ce44SJohn Forte * 4116fcf3ce44SJohn Forte * Purpose: Retrieves list of logical unit Object IDs 4117fcf3ce44SJohn Forte * 4118fcf3ce44SJohn Forte * luList - pointer to a pointer to a stmfGuidList structure. On success, 4119fcf3ce44SJohn Forte * it contains the list of logical unit guids. 4120fcf3ce44SJohn Forte * 4121fcf3ce44SJohn Forte */ 4122fcf3ce44SJohn Forte int 4123fcf3ce44SJohn Forte stmfGetLogicalUnitList(stmfGuidList **luList) 4124fcf3ce44SJohn Forte { 4125fcf3ce44SJohn Forte int ret; 4126fcf3ce44SJohn Forte int fd; 4127fcf3ce44SJohn Forte int ioctlRet; 4128fcf3ce44SJohn Forte int cmd = STMF_IOCTL_LU_LIST; 41298fe96085Stim szeto int i; 4130fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 4131fcf3ce44SJohn Forte slist_lu_t *fLuList; 4132fcf3ce44SJohn Forte uint32_t fLuListSize; 41338fe96085Stim szeto uint32_t listCnt; 4134fcf3ce44SJohn Forte 4135fcf3ce44SJohn Forte if (luList == NULL) { 4136fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 4137fcf3ce44SJohn Forte } 4138fcf3ce44SJohn Forte 4139fcf3ce44SJohn Forte /* call init */ 4140fcf3ce44SJohn Forte ret = initializeConfig(); 4141fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4142fcf3ce44SJohn Forte return (ret); 4143fcf3ce44SJohn Forte } 4144fcf3ce44SJohn Forte 4145fcf3ce44SJohn Forte /* 4146fcf3ce44SJohn Forte * Open control node for stmf 4147fcf3ce44SJohn Forte */ 4148fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 4149fcf3ce44SJohn Forte return (ret); 4150fcf3ce44SJohn Forte 4151fcf3ce44SJohn Forte /* 4152fcf3ce44SJohn Forte * Allocate ioctl input buffer 4153fcf3ce44SJohn Forte */ 41548fe96085Stim szeto fLuListSize = ALLOC_LU; 4155fcf3ce44SJohn Forte fLuListSize = fLuListSize * (sizeof (slist_lu_t)); 4156fcf3ce44SJohn Forte fLuList = (slist_lu_t *)calloc(1, fLuListSize); 4157fcf3ce44SJohn Forte if (fLuList == NULL) { 41588fe96085Stim szeto ret = STMF_ERROR_NOMEM; 41598fe96085Stim szeto goto done; 4160fcf3ce44SJohn Forte } 4161fcf3ce44SJohn Forte 4162fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 4163fcf3ce44SJohn Forte /* 4164fcf3ce44SJohn Forte * Issue ioctl to get the LU list 4165fcf3ce44SJohn Forte */ 4166fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 4167fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = fLuListSize; 4168fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fLuList; 4169fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 4170fcf3ce44SJohn Forte if (ioctlRet != 0) { 4171fcf3ce44SJohn Forte switch (errno) { 4172fcf3ce44SJohn Forte case EBUSY: 4173fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4174fcf3ce44SJohn Forte break; 41758fe96085Stim szeto case EPERM: 4176fcf3ce44SJohn Forte case EACCES: 4177fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 4178fcf3ce44SJohn Forte break; 4179fcf3ce44SJohn Forte default: 4180fcf3ce44SJohn Forte syslog(LOG_DEBUG, 4181fcf3ce44SJohn Forte "stmfGetLogicalUnitList:ioctl errno(%d)", 4182fcf3ce44SJohn Forte errno); 4183fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4184fcf3ce44SJohn Forte break; 4185fcf3ce44SJohn Forte } 4186fcf3ce44SJohn Forte goto done; 4187fcf3ce44SJohn Forte } 4188fcf3ce44SJohn Forte /* 4189fcf3ce44SJohn Forte * Check whether input buffer was large enough 4190fcf3ce44SJohn Forte */ 41918fe96085Stim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_LU) { 4192fcf3ce44SJohn Forte fLuListSize = stmfIoctl.stmf_obuf_max_nentries * 4193fcf3ce44SJohn Forte sizeof (slist_lu_t); 41948fe96085Stim szeto free(fLuList); 41958fe96085Stim szeto fLuList = (slist_lu_t *)calloc(1, fLuListSize); 4196fcf3ce44SJohn Forte if (fLuList == NULL) { 41978fe96085Stim szeto ret = STMF_ERROR_NOMEM; 41988fe96085Stim szeto goto done; 4199fcf3ce44SJohn Forte } 4200fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = fLuListSize; 4201fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fLuList; 4202fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 4203fcf3ce44SJohn Forte if (ioctlRet != 0) { 4204fcf3ce44SJohn Forte switch (errno) { 4205fcf3ce44SJohn Forte case EBUSY: 4206fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4207fcf3ce44SJohn Forte break; 42088fe96085Stim szeto case EPERM: 4209fcf3ce44SJohn Forte case EACCES: 4210fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 4211fcf3ce44SJohn Forte break; 4212fcf3ce44SJohn Forte default: 4213fcf3ce44SJohn Forte syslog(LOG_DEBUG, 4214fcf3ce44SJohn Forte "stmfGetLogicalUnitList:" 4215fcf3ce44SJohn Forte "ioctl errno(%d)", errno); 4216fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4217fcf3ce44SJohn Forte break; 4218fcf3ce44SJohn Forte } 4219fcf3ce44SJohn Forte goto done; 4220fcf3ce44SJohn Forte } 4221fcf3ce44SJohn Forte } 4222fcf3ce44SJohn Forte 4223fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4224fcf3ce44SJohn Forte goto done; 4225fcf3ce44SJohn Forte } 4226fcf3ce44SJohn Forte 42278fe96085Stim szeto listCnt = stmfIoctl.stmf_obuf_nentries; 4228fcf3ce44SJohn Forte 4229fcf3ce44SJohn Forte /* 4230fcf3ce44SJohn Forte * allocate caller's buffer with the final size 4231fcf3ce44SJohn Forte */ 4232fcf3ce44SJohn Forte *luList = (stmfGuidList *)calloc(1, sizeof (stmfGuidList) + 42338fe96085Stim szeto listCnt * sizeof (stmfGuid)); 4234fcf3ce44SJohn Forte if (*luList == NULL) { 4235fcf3ce44SJohn Forte ret = STMF_ERROR_NOMEM; 4236fcf3ce44SJohn Forte goto done; 4237fcf3ce44SJohn Forte } 4238fcf3ce44SJohn Forte 42398fe96085Stim szeto (*luList)->cnt = listCnt; 42408fe96085Stim szeto 42418fe96085Stim szeto /* copy to caller's buffer */ 42428fe96085Stim szeto for (i = 0; i < listCnt; i++) { 42438fe96085Stim szeto bcopy(&fLuList[i].lu_guid, (*luList)->guid[i].guid, 4244fcf3ce44SJohn Forte sizeof (stmfGuid)); 4245fcf3ce44SJohn Forte } 4246fcf3ce44SJohn Forte 42478fe96085Stim szeto /* 42488fe96085Stim szeto * sort the list. This gives a consistent view across gets 42498fe96085Stim szeto */ 42508fe96085Stim szeto qsort((void *)&((*luList)->guid[0]), (*luList)->cnt, 42518fe96085Stim szeto sizeof (stmfGuid), guidCompare); 4252fcf3ce44SJohn Forte 4253fcf3ce44SJohn Forte done: 4254fcf3ce44SJohn Forte (void) close(fd); 4255fcf3ce44SJohn Forte /* 4256fcf3ce44SJohn Forte * free internal buffers 4257fcf3ce44SJohn Forte */ 4258fcf3ce44SJohn Forte free(fLuList); 4259fcf3ce44SJohn Forte return (ret); 4260fcf3ce44SJohn Forte } 4261fcf3ce44SJohn Forte 4262fcf3ce44SJohn Forte /* 4263fcf3ce44SJohn Forte * stmfGetLogicalUnitProperties 4264fcf3ce44SJohn Forte * 4265fcf3ce44SJohn Forte * Purpose: Retrieves the properties for a logical unit 4266fcf3ce44SJohn Forte * 4267fcf3ce44SJohn Forte * lu - guid of the logical unit for which to retrieve properties 4268fcf3ce44SJohn Forte * stmfLuProps - pointer to an stmfLogicalUnitProperties structure. On success, 4269fcf3ce44SJohn Forte * it contains the logical unit properties for the specified guid. 4270fcf3ce44SJohn Forte */ 4271fcf3ce44SJohn Forte int 4272fcf3ce44SJohn Forte stmfGetLogicalUnitProperties(stmfGuid *lu, stmfLogicalUnitProperties *luProps) 4273fcf3ce44SJohn Forte { 4274fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 4275fcf3ce44SJohn Forte int stmfRet; 4276fcf3ce44SJohn Forte int fd; 4277fcf3ce44SJohn Forte int ioctlRet; 4278fcf3ce44SJohn Forte int cmd = STMF_IOCTL_GET_LU_PROPERTIES; 4279fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList = NULL; 4280fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 4281fcf3ce44SJohn Forte sioc_lu_props_t fLuProps; 4282fcf3ce44SJohn Forte 42838fe96085Stim szeto if (lu == NULL || luProps == NULL) { 42848fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 4285fcf3ce44SJohn Forte } 4286fcf3ce44SJohn Forte 4287fcf3ce44SJohn Forte bzero(luProps, sizeof (stmfLogicalUnitProperties)); 4288fcf3ce44SJohn Forte 4289fcf3ce44SJohn Forte /* call init */ 4290fcf3ce44SJohn Forte ret = initializeConfig(); 4291fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4292fcf3ce44SJohn Forte return (ret); 4293fcf3ce44SJohn Forte } 4294fcf3ce44SJohn Forte 4295fcf3ce44SJohn Forte /* 4296fcf3ce44SJohn Forte * Open control node for stmf 4297fcf3ce44SJohn Forte */ 4298fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 4299fcf3ce44SJohn Forte return (ret); 4300fcf3ce44SJohn Forte 4301fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 4302fcf3ce44SJohn Forte /* 4303fcf3ce44SJohn Forte * Issue ioctl to add to the host group 4304fcf3ce44SJohn Forte */ 4305fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 4306fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmfGuid); 4307fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)lu; 4308fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&fLuProps; 4309fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = sizeof (fLuProps); 4310fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 4311fcf3ce44SJohn Forte if (ioctlRet != 0) { 4312fcf3ce44SJohn Forte switch (errno) { 4313fcf3ce44SJohn Forte case EBUSY: 4314fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4315fcf3ce44SJohn Forte break; 43168fe96085Stim szeto case EPERM: 4317fcf3ce44SJohn Forte case EACCES: 4318fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 4319fcf3ce44SJohn Forte break; 4320fcf3ce44SJohn Forte case ENOENT: 4321fcf3ce44SJohn Forte stmfRet = stmfGetViewEntryList(lu, 4322fcf3ce44SJohn Forte &viewEntryList); 4323fcf3ce44SJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) { 4324fcf3ce44SJohn Forte luProps->status = 4325fcf3ce44SJohn Forte STMF_LOGICAL_UNIT_UNREGISTERED; 4326fcf3ce44SJohn Forte if (viewEntryList->cnt > 0) { 4327fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 4328fcf3ce44SJohn Forte } else { 4329fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4330fcf3ce44SJohn Forte } 4331fcf3ce44SJohn Forte } else { 4332fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4333fcf3ce44SJohn Forte } 4334fcf3ce44SJohn Forte stmfFreeMemory(viewEntryList); 4335fcf3ce44SJohn Forte break; 4336fcf3ce44SJohn Forte default: 4337fcf3ce44SJohn Forte syslog(LOG_DEBUG, 4338fcf3ce44SJohn Forte "stmfGetLogicalUnit:ioctl errno(%d)", 4339fcf3ce44SJohn Forte errno); 4340fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4341fcf3ce44SJohn Forte break; 4342fcf3ce44SJohn Forte } 4343fcf3ce44SJohn Forte goto done; 4344fcf3ce44SJohn Forte } 4345fcf3ce44SJohn Forte 4346fcf3ce44SJohn Forte bcopy(fLuProps.lu_provider_name, luProps->providerName, 4347fcf3ce44SJohn Forte sizeof (fLuProps.lu_provider_name)); 4348fcf3ce44SJohn Forte if (fLuProps.lu_state == STMF_STATE_ONLINE) { 4349fcf3ce44SJohn Forte luProps->status = STMF_LOGICAL_UNIT_ONLINE; 4350fcf3ce44SJohn Forte } else if (fLuProps.lu_state == STMF_STATE_OFFLINE) { 4351fcf3ce44SJohn Forte luProps->status = STMF_LOGICAL_UNIT_OFFLINE; 4352fcf3ce44SJohn Forte } else if (fLuProps.lu_state == STMF_STATE_ONLINING) { 4353fcf3ce44SJohn Forte luProps->status = STMF_LOGICAL_UNIT_ONLINING; 4354fcf3ce44SJohn Forte } else if (fLuProps.lu_state == STMF_STATE_OFFLINING) { 4355fcf3ce44SJohn Forte luProps->status = STMF_LOGICAL_UNIT_OFFLINING; 4356fcf3ce44SJohn Forte } 4357fcf3ce44SJohn Forte bcopy(fLuProps.lu_alias, luProps->alias, sizeof (luProps->alias)); 4358fcf3ce44SJohn Forte done: 4359fcf3ce44SJohn Forte (void) close(fd); 4360fcf3ce44SJohn Forte return (ret); 4361fcf3ce44SJohn Forte } 4362fcf3ce44SJohn Forte 4363fcf3ce44SJohn Forte /* 4364fcf3ce44SJohn Forte * stmfGetState 4365fcf3ce44SJohn Forte * 4366fcf3ce44SJohn Forte * Purpose: retrieve the current state of the stmf module 4367fcf3ce44SJohn Forte * 4368fcf3ce44SJohn Forte * state - pointer to stmfState structure allocated by the caller 4369fcf3ce44SJohn Forte * On success, contains the state of stmf 4370fcf3ce44SJohn Forte */ 4371fcf3ce44SJohn Forte int 4372fcf3ce44SJohn Forte stmfGetState(stmfState *state) 4373fcf3ce44SJohn Forte { 4374fcf3ce44SJohn Forte int ret; 4375fcf3ce44SJohn Forte stmf_state_desc_t iState; 4376fcf3ce44SJohn Forte 4377fcf3ce44SJohn Forte if (state == NULL) { 4378fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 4379fcf3ce44SJohn Forte } 4380fcf3ce44SJohn Forte 4381fcf3ce44SJohn Forte ret = getStmfState(&iState); 4382fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4383fcf3ce44SJohn Forte return (ret); 4384fcf3ce44SJohn Forte } 4385fcf3ce44SJohn Forte switch (iState.state) { 4386fcf3ce44SJohn Forte case STMF_STATE_ONLINE: 4387fcf3ce44SJohn Forte state->operationalState = 4388fcf3ce44SJohn Forte STMF_SERVICE_STATE_ONLINE; 4389fcf3ce44SJohn Forte break; 4390fcf3ce44SJohn Forte case STMF_STATE_OFFLINE: 4391fcf3ce44SJohn Forte state->operationalState = 4392fcf3ce44SJohn Forte STMF_SERVICE_STATE_OFFLINE; 4393fcf3ce44SJohn Forte break; 4394fcf3ce44SJohn Forte case STMF_STATE_ONLINING: 4395fcf3ce44SJohn Forte state->operationalState = 4396fcf3ce44SJohn Forte STMF_SERVICE_STATE_ONLINING; 4397fcf3ce44SJohn Forte break; 4398fcf3ce44SJohn Forte case STMF_STATE_OFFLINING: 4399fcf3ce44SJohn Forte state->operationalState = 4400fcf3ce44SJohn Forte STMF_SERVICE_STATE_OFFLINING; 4401fcf3ce44SJohn Forte break; 4402fcf3ce44SJohn Forte default: 4403fcf3ce44SJohn Forte state->operationalState = 4404fcf3ce44SJohn Forte STMF_SERVICE_STATE_UNKNOWN; 4405fcf3ce44SJohn Forte break; 4406fcf3ce44SJohn Forte } 4407fcf3ce44SJohn Forte switch (iState.config_state) { 4408fcf3ce44SJohn Forte case STMF_CONFIG_NONE: 4409fcf3ce44SJohn Forte state->configState = STMF_CONFIG_STATE_NONE; 4410fcf3ce44SJohn Forte break; 4411fcf3ce44SJohn Forte case STMF_CONFIG_INIT: 4412fcf3ce44SJohn Forte state->configState = STMF_CONFIG_STATE_INIT; 4413fcf3ce44SJohn Forte break; 4414fcf3ce44SJohn Forte case STMF_CONFIG_INIT_DONE: 4415fcf3ce44SJohn Forte state->configState = 4416fcf3ce44SJohn Forte STMF_CONFIG_STATE_INIT_DONE; 4417fcf3ce44SJohn Forte break; 4418fcf3ce44SJohn Forte default: 4419fcf3ce44SJohn Forte state->configState = 4420fcf3ce44SJohn Forte STMF_CONFIG_STATE_UNKNOWN; 4421fcf3ce44SJohn Forte break; 4422fcf3ce44SJohn Forte } 4423fcf3ce44SJohn Forte return (STMF_STATUS_SUCCESS); 4424fcf3ce44SJohn Forte } 4425fcf3ce44SJohn Forte 4426fcf3ce44SJohn Forte /* 4427fcf3ce44SJohn Forte * stmfGetViewEntryList 4428fcf3ce44SJohn Forte * 4429fcf3ce44SJohn Forte * Purpose: Retrieves the list of view entries for the specified 4430fcf3ce44SJohn Forte * logical unit. 4431fcf3ce44SJohn Forte * 4432fcf3ce44SJohn Forte * lu - the guid of the logical unit for which to retrieve the view entry list 4433fcf3ce44SJohn Forte * viewEntryList - a pointer to a pointer to a stmfViewEntryList structure. On 4434fcf3ce44SJohn Forte * success, contains the list of view entries. 4435fcf3ce44SJohn Forte */ 4436fcf3ce44SJohn Forte int 4437fcf3ce44SJohn Forte stmfGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList) 4438fcf3ce44SJohn Forte { 4439fcf3ce44SJohn Forte int ret; 44408fe96085Stim szeto int fd; 44418fe96085Stim szeto int ioctlRet; 44428fe96085Stim szeto int cmd = STMF_IOCTL_LU_VE_LIST; 44438fe96085Stim szeto int i; 44448fe96085Stim szeto stmf_iocdata_t stmfIoctl; 44458fe96085Stim szeto stmf_view_op_entry_t *fVeList; 44468fe96085Stim szeto uint32_t fVeListSize; 44478fe96085Stim szeto uint32_t listCnt; 4448fcf3ce44SJohn Forte 4449fcf3ce44SJohn Forte if (lu == NULL || viewEntryList == NULL) { 4450fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 4451fcf3ce44SJohn Forte } 4452fcf3ce44SJohn Forte 44538fe96085Stim szeto /* call init */ 44548fe96085Stim szeto ret = initializeConfig(); 44558fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 44568fe96085Stim szeto return (ret); 44578fe96085Stim szeto } 44588fe96085Stim szeto 44598fe96085Stim szeto /* 44608fe96085Stim szeto * Open control node for stmf 44618fe96085Stim szeto */ 44628fe96085Stim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 44638fe96085Stim szeto return (ret); 44648fe96085Stim szeto 44658fe96085Stim szeto /* 44668fe96085Stim szeto * Allocate ioctl input buffer 44678fe96085Stim szeto */ 44688fe96085Stim szeto fVeListSize = ALLOC_VE; 44698fe96085Stim szeto fVeListSize = fVeListSize * (sizeof (stmf_view_op_entry_t)); 44708fe96085Stim szeto fVeList = (stmf_view_op_entry_t *)calloc(1, fVeListSize); 44718fe96085Stim szeto if (fVeList == NULL) { 44728fe96085Stim szeto ret = STMF_ERROR_NOMEM; 44738fe96085Stim szeto goto done; 44748fe96085Stim szeto } 44758fe96085Stim szeto 44768fe96085Stim szeto bzero(&stmfIoctl, sizeof (stmfIoctl)); 44778fe96085Stim szeto /* 44788fe96085Stim szeto * Issue ioctl to get the LU list 44798fe96085Stim szeto */ 44808fe96085Stim szeto stmfIoctl.stmf_version = STMF_VERSION_1; 44818fe96085Stim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)lu; 44828fe96085Stim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmfGuid); 44838fe96085Stim szeto stmfIoctl.stmf_obuf_size = fVeListSize; 44848fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fVeList; 44858fe96085Stim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl); 44868fe96085Stim szeto if (ioctlRet != 0) { 44878fe96085Stim szeto switch (errno) { 44888fe96085Stim szeto case EBUSY: 4489fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4490fcf3ce44SJohn Forte break; 44918fe96085Stim szeto case EPERM: 44928fe96085Stim szeto case EACCES: 44938fe96085Stim szeto ret = STMF_ERROR_PERM; 4494fcf3ce44SJohn Forte break; 4495fcf3ce44SJohn Forte default: 4496fcf3ce44SJohn Forte syslog(LOG_DEBUG, 44978fe96085Stim szeto "stmfGetViewEntryList:ioctl errno(%d)", 44988fe96085Stim szeto errno); 4499fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4500fcf3ce44SJohn Forte break; 4501fcf3ce44SJohn Forte } 45028fe96085Stim szeto goto done; 45038fe96085Stim szeto } 45048fe96085Stim szeto /* 45058fe96085Stim szeto * Check whether input buffer was large enough 45068fe96085Stim szeto */ 45078fe96085Stim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_VE) { 45088fe96085Stim szeto bzero(&stmfIoctl, sizeof (stmfIoctl)); 45098fe96085Stim szeto fVeListSize = stmfIoctl.stmf_obuf_max_nentries * 45108fe96085Stim szeto sizeof (stmf_view_op_entry_t); 45118fe96085Stim szeto free(fVeList); 45128fe96085Stim szeto fVeList = (stmf_view_op_entry_t *)calloc(1, fVeListSize); 45138fe96085Stim szeto if (fVeList == NULL) { 45148fe96085Stim szeto return (STMF_ERROR_NOMEM); 45158fe96085Stim szeto } 45168fe96085Stim szeto stmfIoctl.stmf_obuf_size = fVeListSize; 45178fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fVeList; 45188fe96085Stim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl); 45198fe96085Stim szeto if (ioctlRet != 0) { 45208fe96085Stim szeto switch (errno) { 45218fe96085Stim szeto case EBUSY: 45228fe96085Stim szeto ret = STMF_ERROR_BUSY; 45238fe96085Stim szeto break; 45248fe96085Stim szeto case EPERM: 45258fe96085Stim szeto case EACCES: 45268fe96085Stim szeto ret = STMF_ERROR_PERM; 45278fe96085Stim szeto break; 45288fe96085Stim szeto default: 45298fe96085Stim szeto syslog(LOG_DEBUG, 45308fe96085Stim szeto "stmfGetLogicalUnitList:" 45318fe96085Stim szeto "ioctl errno(%d)", errno); 45328fe96085Stim szeto ret = STMF_STATUS_ERROR; 45338fe96085Stim szeto break; 45348fe96085Stim szeto } 45358fe96085Stim szeto goto done; 45368fe96085Stim szeto } 45378fe96085Stim szeto } 4538fcf3ce44SJohn Forte 45398fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) { 45408fe96085Stim szeto goto done; 45418fe96085Stim szeto } 45428fe96085Stim szeto 45438fe96085Stim szeto if (stmfIoctl.stmf_obuf_nentries == 0) { 45448fe96085Stim szeto ret = STMF_ERROR_NOT_FOUND; 45458fe96085Stim szeto goto done; 45468fe96085Stim szeto } 45478fe96085Stim szeto 45488fe96085Stim szeto listCnt = stmfIoctl.stmf_obuf_nentries; 45498fe96085Stim szeto 45508fe96085Stim szeto /* 45518fe96085Stim szeto * allocate caller's buffer with the final size 45528fe96085Stim szeto */ 45538fe96085Stim szeto *viewEntryList = (stmfViewEntryList *)calloc(1, 45548fe96085Stim szeto sizeof (stmfViewEntryList) + listCnt * sizeof (stmfViewEntry)); 45558fe96085Stim szeto if (*viewEntryList == NULL) { 45568fe96085Stim szeto ret = STMF_ERROR_NOMEM; 45578fe96085Stim szeto goto done; 45588fe96085Stim szeto } 45598fe96085Stim szeto 45608fe96085Stim szeto (*viewEntryList)->cnt = listCnt; 45618fe96085Stim szeto 45628fe96085Stim szeto /* copy to caller's buffer */ 45638fe96085Stim szeto for (i = 0; i < listCnt; i++) { 45648fe96085Stim szeto (*viewEntryList)->ve[i].veIndexValid = B_TRUE; 45658fe96085Stim szeto (*viewEntryList)->ve[i].veIndex = fVeList[i].ve_ndx; 45668fe96085Stim szeto if (fVeList[i].ve_all_hosts == 1) { 45678fe96085Stim szeto (*viewEntryList)->ve[i].allHosts = B_TRUE; 45688fe96085Stim szeto } else { 45698fe96085Stim szeto bcopy(fVeList[i].ve_host_group.name, 45708fe96085Stim szeto (*viewEntryList)->ve[i].hostGroup, 45718fe96085Stim szeto fVeList[i].ve_host_group.name_size); 45728fe96085Stim szeto } 45738fe96085Stim szeto if (fVeList[i].ve_all_targets == 1) { 45748fe96085Stim szeto (*viewEntryList)->ve[i].allTargets = B_TRUE; 45758fe96085Stim szeto } else { 45768fe96085Stim szeto bcopy(fVeList[i].ve_target_group.name, 45778fe96085Stim szeto (*viewEntryList)->ve[i].targetGroup, 45788fe96085Stim szeto fVeList[i].ve_target_group.name_size); 45798fe96085Stim szeto } 45808fe96085Stim szeto bcopy(fVeList[i].ve_lu_nbr, (*viewEntryList)->ve[i].luNbr, 45818fe96085Stim szeto sizeof ((*viewEntryList)->ve[i].luNbr)); 45828fe96085Stim szeto (*viewEntryList)->ve[i].luNbrValid = B_TRUE; 45838fe96085Stim szeto } 45848fe96085Stim szeto 45858fe96085Stim szeto /* 45868fe96085Stim szeto * sort the list. This gives a consistent view across gets 45878fe96085Stim szeto */ 45888fe96085Stim szeto qsort((void *)&((*viewEntryList)->ve[0]), (*viewEntryList)->cnt, 45898fe96085Stim szeto sizeof (stmfViewEntry), viewEntryCompare); 45908fe96085Stim szeto 45918fe96085Stim szeto done: 45928fe96085Stim szeto (void) close(fd); 45938fe96085Stim szeto /* 45948fe96085Stim szeto * free internal buffers 45958fe96085Stim szeto */ 45968fe96085Stim szeto free(fVeList); 4597fcf3ce44SJohn Forte return (ret); 4598fcf3ce44SJohn Forte } 4599fcf3ce44SJohn Forte 46008fe96085Stim szeto 4601fcf3ce44SJohn Forte /* 4602fcf3ce44SJohn Forte * loadHostGroups 4603fcf3ce44SJohn Forte * 4604fcf3ce44SJohn Forte * Purpose - issues the ioctl to load the host groups into stmf 4605fcf3ce44SJohn Forte * 4606fcf3ce44SJohn Forte * fd - file descriptor for the control node of stmf. 4607fcf3ce44SJohn Forte * groupList - populated host group list 4608fcf3ce44SJohn Forte */ 4609fcf3ce44SJohn Forte static int 4610fcf3ce44SJohn Forte loadHostGroups(int fd, stmfGroupList *groupList) 4611fcf3ce44SJohn Forte { 4612fcf3ce44SJohn Forte int i, j; 4613fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 4614fcf3ce44SJohn Forte stmfGroupProperties *groupProps = NULL; 4615fcf3ce44SJohn Forte 4616fcf3ce44SJohn Forte for (i = 0; i < groupList->cnt; i++) { 4617fcf3ce44SJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_HOST_GROUP, 4618fcf3ce44SJohn Forte &(groupList->name[i]))) != STMF_STATUS_SUCCESS) { 4619fcf3ce44SJohn Forte goto out; 4620fcf3ce44SJohn Forte } 46218fe96085Stim szeto ret = iLoadGroupMembersFromPs(&(groupList->name[i]), 46228fe96085Stim szeto &groupProps, HOST_GROUP); 4623fcf3ce44SJohn Forte for (j = 0; j < groupProps->cnt; j++) { 4624fcf3ce44SJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_HG_ENTRY, 4625fcf3ce44SJohn Forte &(groupList->name[i]), &(groupProps->name[j]))) 4626fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 4627fcf3ce44SJohn Forte goto out; 4628fcf3ce44SJohn Forte } 4629fcf3ce44SJohn Forte } 4630fcf3ce44SJohn Forte } 4631fcf3ce44SJohn Forte 4632fcf3ce44SJohn Forte 4633fcf3ce44SJohn Forte out: 4634fcf3ce44SJohn Forte stmfFreeMemory(groupProps); 4635fcf3ce44SJohn Forte return (ret); 4636fcf3ce44SJohn Forte } 4637fcf3ce44SJohn Forte 4638fcf3ce44SJohn Forte /* 4639fcf3ce44SJohn Forte * loadTargetGroups 4640fcf3ce44SJohn Forte * 4641fcf3ce44SJohn Forte * Purpose - issues the ioctl to load the target groups into stmf 4642fcf3ce44SJohn Forte * 4643fcf3ce44SJohn Forte * fd - file descriptor for the control node of stmf. 4644fcf3ce44SJohn Forte * groupList - populated target group list. 4645fcf3ce44SJohn Forte */ 4646fcf3ce44SJohn Forte static int 4647fcf3ce44SJohn Forte loadTargetGroups(int fd, stmfGroupList *groupList) 4648fcf3ce44SJohn Forte { 4649fcf3ce44SJohn Forte int i, j; 4650fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 4651fcf3ce44SJohn Forte stmfGroupProperties *groupProps = NULL; 4652fcf3ce44SJohn Forte 4653fcf3ce44SJohn Forte for (i = 0; i < groupList->cnt; i++) { 4654fcf3ce44SJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_TARGET_GROUP, 4655fcf3ce44SJohn Forte &(groupList->name[i]))) != STMF_STATUS_SUCCESS) { 4656fcf3ce44SJohn Forte goto out; 4657fcf3ce44SJohn Forte } 46588fe96085Stim szeto ret = iLoadGroupMembersFromPs(&(groupList->name[i]), 46598fe96085Stim szeto &groupProps, TARGET_GROUP); 4660fcf3ce44SJohn Forte for (j = 0; j < groupProps->cnt; j++) { 4661fcf3ce44SJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_TG_ENTRY, 4662fcf3ce44SJohn Forte &(groupList->name[i]), &(groupProps->name[j]))) 4663fcf3ce44SJohn Forte != STMF_STATUS_SUCCESS) { 4664fcf3ce44SJohn Forte goto out; 4665fcf3ce44SJohn Forte } 4666fcf3ce44SJohn Forte } 4667fcf3ce44SJohn Forte } 4668fcf3ce44SJohn Forte 4669fcf3ce44SJohn Forte 4670fcf3ce44SJohn Forte out: 4671fcf3ce44SJohn Forte stmfFreeMemory(groupProps); 4672fcf3ce44SJohn Forte return (ret); 4673fcf3ce44SJohn Forte } 4674fcf3ce44SJohn Forte 4675fcf3ce44SJohn Forte 4676fcf3ce44SJohn Forte /* 4677fcf3ce44SJohn Forte * loadStore 4678fcf3ce44SJohn Forte * 4679fcf3ce44SJohn Forte * Purpose: Load the configuration data from the store 4680fcf3ce44SJohn Forte * 4681fcf3ce44SJohn Forte * First load the host groups and target groups, then the view entries 4682fcf3ce44SJohn Forte * and finally the provider data 4683fcf3ce44SJohn Forte * 4684fcf3ce44SJohn Forte * fd - file descriptor of control node for stmf. 4685fcf3ce44SJohn Forte */ 4686fcf3ce44SJohn Forte static int 4687fcf3ce44SJohn Forte loadStore(int fd) 4688fcf3ce44SJohn Forte { 4689fcf3ce44SJohn Forte int ret; 4690fcf3ce44SJohn Forte int i, j; 4691fcf3ce44SJohn Forte stmfGroupList *groupList = NULL; 4692fcf3ce44SJohn Forte stmfGuidList *guidList = NULL; 4693fcf3ce44SJohn Forte stmfViewEntryList *viewEntryList = NULL; 4694fcf3ce44SJohn Forte stmfProviderList *providerList = NULL; 4695fcf3ce44SJohn Forte int providerType; 4696fcf3ce44SJohn Forte nvlist_t *nvl = NULL; 4697fcf3ce44SJohn Forte 4698fcf3ce44SJohn Forte 4699fcf3ce44SJohn Forte 4700fcf3ce44SJohn Forte /* load host groups */ 47018fe96085Stim szeto ret = iLoadGroupFromPs(&groupList, HOST_GROUP); 4702fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4703fcf3ce44SJohn Forte return (ret); 4704fcf3ce44SJohn Forte } 4705fcf3ce44SJohn Forte ret = loadHostGroups(fd, groupList); 4706fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4707fcf3ce44SJohn Forte goto out; 4708fcf3ce44SJohn Forte } 4709fcf3ce44SJohn Forte 4710fcf3ce44SJohn Forte stmfFreeMemory(groupList); 4711fcf3ce44SJohn Forte groupList = NULL; 4712fcf3ce44SJohn Forte 4713fcf3ce44SJohn Forte /* load target groups */ 47148fe96085Stim szeto ret = iLoadGroupFromPs(&groupList, TARGET_GROUP); 4715fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4716fcf3ce44SJohn Forte goto out; 4717fcf3ce44SJohn Forte } 4718fcf3ce44SJohn Forte ret = loadTargetGroups(fd, groupList); 4719fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4720fcf3ce44SJohn Forte goto out; 4721fcf3ce44SJohn Forte } 4722fcf3ce44SJohn Forte 4723fcf3ce44SJohn Forte stmfFreeMemory(groupList); 4724fcf3ce44SJohn Forte groupList = NULL; 4725fcf3ce44SJohn Forte 4726fcf3ce44SJohn Forte /* Get the guid list */ 4727fcf3ce44SJohn Forte ret = psGetLogicalUnitList(&guidList); 4728fcf3ce44SJohn Forte switch (ret) { 4729fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 4730fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 4731fcf3ce44SJohn Forte break; 4732fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 4733fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4734fcf3ce44SJohn Forte break; 4735fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 4736fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4737fcf3ce44SJohn Forte break; 4738fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 4739fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 4740fcf3ce44SJohn Forte break; 4741fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 4742fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 4743fcf3ce44SJohn Forte break; 4744fcf3ce44SJohn Forte default: 4745fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4746fcf3ce44SJohn Forte break; 4747fcf3ce44SJohn Forte } 4748fcf3ce44SJohn Forte 4749fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4750fcf3ce44SJohn Forte goto out; 4751fcf3ce44SJohn Forte } 4752fcf3ce44SJohn Forte 4753fcf3ce44SJohn Forte /* 4754fcf3ce44SJohn Forte * We have the guid list, now get the corresponding 4755fcf3ce44SJohn Forte * view entries for each guid 4756fcf3ce44SJohn Forte */ 4757fcf3ce44SJohn Forte for (i = 0; i < guidList->cnt; i++) { 4758fcf3ce44SJohn Forte ret = psGetViewEntryList(&guidList->guid[i], &viewEntryList); 4759fcf3ce44SJohn Forte switch (ret) { 4760fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 4761fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 4762fcf3ce44SJohn Forte break; 4763fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 4764fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4765fcf3ce44SJohn Forte break; 4766fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 4767fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4768fcf3ce44SJohn Forte break; 4769fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 4770fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 4771fcf3ce44SJohn Forte break; 4772fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 4773fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 4774fcf3ce44SJohn Forte break; 4775fcf3ce44SJohn Forte default: 4776fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4777fcf3ce44SJohn Forte break; 4778fcf3ce44SJohn Forte } 4779fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4780fcf3ce44SJohn Forte goto out; 4781fcf3ce44SJohn Forte } 4782fcf3ce44SJohn Forte for (j = 0; j < viewEntryList->cnt; j++) { 4783fcf3ce44SJohn Forte ret = addViewEntryIoctl(fd, &guidList->guid[i], 4784fcf3ce44SJohn Forte &viewEntryList->ve[j]); 4785fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4786fcf3ce44SJohn Forte goto out; 4787fcf3ce44SJohn Forte } 4788fcf3ce44SJohn Forte } 4789fcf3ce44SJohn Forte } 4790fcf3ce44SJohn Forte 4791fcf3ce44SJohn Forte /* get the list of providers that have data */ 4792fcf3ce44SJohn Forte ret = psGetProviderDataList(&providerList); 4793fcf3ce44SJohn Forte switch (ret) { 4794fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 4795fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 4796fcf3ce44SJohn Forte break; 4797fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 4798fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4799fcf3ce44SJohn Forte break; 4800fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 4801fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4802fcf3ce44SJohn Forte break; 4803fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 4804fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 4805fcf3ce44SJohn Forte break; 4806fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 4807fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 4808fcf3ce44SJohn Forte break; 4809fcf3ce44SJohn Forte default: 4810fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4811fcf3ce44SJohn Forte break; 4812fcf3ce44SJohn Forte } 4813fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4814fcf3ce44SJohn Forte goto out; 4815fcf3ce44SJohn Forte } 4816fcf3ce44SJohn Forte 4817fcf3ce44SJohn Forte for (i = 0; i < providerList->cnt; i++) { 4818fcf3ce44SJohn Forte providerType = providerList->provider[i].providerType; 4819fcf3ce44SJohn Forte ret = psGetProviderData(providerList->provider[i].name, 4820fcf3ce44SJohn Forte &nvl, providerType, NULL); 4821fcf3ce44SJohn Forte switch (ret) { 4822fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 4823fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 4824fcf3ce44SJohn Forte break; 4825fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 4826fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4827fcf3ce44SJohn Forte break; 4828fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 4829fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4830fcf3ce44SJohn Forte break; 4831fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 4832fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 4833fcf3ce44SJohn Forte break; 4834fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 4835fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 4836fcf3ce44SJohn Forte break; 4837fcf3ce44SJohn Forte default: 4838fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4839fcf3ce44SJohn Forte break; 4840fcf3ce44SJohn Forte } 4841fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4842fcf3ce44SJohn Forte goto out; 4843fcf3ce44SJohn Forte } 4844fcf3ce44SJohn Forte 4845fcf3ce44SJohn Forte /* call setProviderData */ 4846fcf3ce44SJohn Forte ret = setProviderData(fd, providerList->provider[i].name, nvl, 48478fe96085Stim szeto providerType, NULL); 4848fcf3ce44SJohn Forte switch (ret) { 4849fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 4850fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 4851fcf3ce44SJohn Forte break; 4852fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 4853fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 4854fcf3ce44SJohn Forte break; 4855fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 4856fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 4857fcf3ce44SJohn Forte break; 4858fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 4859fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 4860fcf3ce44SJohn Forte break; 4861fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 4862fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 4863fcf3ce44SJohn Forte break; 4864fcf3ce44SJohn Forte default: 4865fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 4866fcf3ce44SJohn Forte break; 4867fcf3ce44SJohn Forte } 4868fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 4869fcf3ce44SJohn Forte goto out; 4870fcf3ce44SJohn Forte } 4871fcf3ce44SJohn Forte 4872fcf3ce44SJohn Forte nvlist_free(nvl); 4873fcf3ce44SJohn Forte nvl = NULL; 4874fcf3ce44SJohn Forte } 4875fcf3ce44SJohn Forte out: 4876fcf3ce44SJohn Forte if (groupList != NULL) { 4877fcf3ce44SJohn Forte free(groupList); 4878fcf3ce44SJohn Forte } 4879fcf3ce44SJohn Forte if (guidList != NULL) { 4880fcf3ce44SJohn Forte free(guidList); 4881fcf3ce44SJohn Forte } 4882fcf3ce44SJohn Forte if (viewEntryList != NULL) { 4883fcf3ce44SJohn Forte free(viewEntryList); 4884fcf3ce44SJohn Forte } 4885fcf3ce44SJohn Forte if (nvl != NULL) { 4886fcf3ce44SJohn Forte nvlist_free(nvl); 4887fcf3ce44SJohn Forte } 4888fcf3ce44SJohn Forte return (ret); 4889fcf3ce44SJohn Forte } 4890fcf3ce44SJohn Forte 4891fcf3ce44SJohn Forte /* 4892*45039663SJohn Forte * stmfGetAluaState 4893*45039663SJohn Forte * 4894*45039663SJohn Forte * Purpose - Get the alua state 4895*45039663SJohn Forte * 4896*45039663SJohn Forte */ 4897*45039663SJohn Forte int 4898*45039663SJohn Forte stmfGetAluaState(boolean_t *enabled, uint32_t *node) 4899*45039663SJohn Forte { 4900*45039663SJohn Forte int ret = STMF_STATUS_SUCCESS; 4901*45039663SJohn Forte int fd; 4902*45039663SJohn Forte stmf_iocdata_t stmfIoctl = {0}; 4903*45039663SJohn Forte stmf_alua_state_desc_t alua_state = {0}; 4904*45039663SJohn Forte int ioctlRet; 4905*45039663SJohn Forte 4906*45039663SJohn Forte if (enabled == NULL || node == NULL) { 4907*45039663SJohn Forte return (STMF_ERROR_INVALID_ARG); 4908*45039663SJohn Forte } 4909*45039663SJohn Forte 4910*45039663SJohn Forte /* 4911*45039663SJohn Forte * Open control node for stmf 4912*45039663SJohn Forte */ 4913*45039663SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 4914*45039663SJohn Forte return (ret); 4915*45039663SJohn Forte 4916*45039663SJohn Forte /* 4917*45039663SJohn Forte * Issue ioctl to get the stmf state 4918*45039663SJohn Forte */ 4919*45039663SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 4920*45039663SJohn Forte stmfIoctl.stmf_obuf_size = sizeof (alua_state); 4921*45039663SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&alua_state; 4922*45039663SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_GET_ALUA_STATE, &stmfIoctl); 4923*45039663SJohn Forte 4924*45039663SJohn Forte (void) close(fd); 4925*45039663SJohn Forte 4926*45039663SJohn Forte if (ioctlRet != 0) { 4927*45039663SJohn Forte switch (errno) { 4928*45039663SJohn Forte case EBUSY: 4929*45039663SJohn Forte ret = STMF_ERROR_BUSY; 4930*45039663SJohn Forte break; 4931*45039663SJohn Forte case EPERM: 4932*45039663SJohn Forte case EACCES: 4933*45039663SJohn Forte ret = STMF_ERROR_PERM; 4934*45039663SJohn Forte break; 4935*45039663SJohn Forte default: 4936*45039663SJohn Forte syslog(LOG_DEBUG, 4937*45039663SJohn Forte "getStmfState:ioctl errno(%d)", errno); 4938*45039663SJohn Forte ret = STMF_STATUS_ERROR; 4939*45039663SJohn Forte break; 4940*45039663SJohn Forte } 4941*45039663SJohn Forte } else { 4942*45039663SJohn Forte if (alua_state.alua_state == 1) { 4943*45039663SJohn Forte *enabled = B_TRUE; 4944*45039663SJohn Forte } else { 4945*45039663SJohn Forte *enabled = B_FALSE; 4946*45039663SJohn Forte } 4947*45039663SJohn Forte *node = alua_state.alua_node; 4948*45039663SJohn Forte } 4949*45039663SJohn Forte 4950*45039663SJohn Forte return (ret); 4951*45039663SJohn Forte } 4952*45039663SJohn Forte 4953*45039663SJohn Forte /* 4954*45039663SJohn Forte * stmfSetAluaState 4955*45039663SJohn Forte * 4956*45039663SJohn Forte * Purpose - set the alua state to enabled/disabled 4957*45039663SJohn Forte * 4958*45039663SJohn Forte */ 4959*45039663SJohn Forte int 4960*45039663SJohn Forte stmfSetAluaState(boolean_t enabled, uint32_t node) 4961*45039663SJohn Forte { 4962*45039663SJohn Forte int ret = STMF_STATUS_SUCCESS; 4963*45039663SJohn Forte int fd; 4964*45039663SJohn Forte stmf_iocdata_t stmfIoctl = {0}; 4965*45039663SJohn Forte stmf_alua_state_desc_t alua_state = {0}; 4966*45039663SJohn Forte int ioctlRet; 4967*45039663SJohn Forte 4968*45039663SJohn Forte if ((enabled != B_TRUE && enabled != B_FALSE) || (node > 1)) { 4969*45039663SJohn Forte return (STMF_ERROR_INVALID_ARG); 4970*45039663SJohn Forte } 4971*45039663SJohn Forte 4972*45039663SJohn Forte if (enabled) { 4973*45039663SJohn Forte alua_state.alua_state = 1; 4974*45039663SJohn Forte } 4975*45039663SJohn Forte 4976*45039663SJohn Forte alua_state.alua_node = node; 4977*45039663SJohn Forte 4978*45039663SJohn Forte /* 4979*45039663SJohn Forte * Open control node for stmf 4980*45039663SJohn Forte */ 4981*45039663SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 4982*45039663SJohn Forte return (ret); 4983*45039663SJohn Forte 4984*45039663SJohn Forte /* 4985*45039663SJohn Forte * Issue ioctl to get the stmf state 4986*45039663SJohn Forte */ 4987*45039663SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 4988*45039663SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (alua_state); 4989*45039663SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&alua_state; 4990*45039663SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_SET_ALUA_STATE, &stmfIoctl); 4991*45039663SJohn Forte 4992*45039663SJohn Forte (void) close(fd); 4993*45039663SJohn Forte 4994*45039663SJohn Forte if (ioctlRet != 0) { 4995*45039663SJohn Forte switch (errno) { 4996*45039663SJohn Forte case EBUSY: 4997*45039663SJohn Forte ret = STMF_ERROR_BUSY; 4998*45039663SJohn Forte break; 4999*45039663SJohn Forte case EPERM: 5000*45039663SJohn Forte case EACCES: 5001*45039663SJohn Forte ret = STMF_ERROR_PERM; 5002*45039663SJohn Forte break; 5003*45039663SJohn Forte default: 5004*45039663SJohn Forte syslog(LOG_DEBUG, 5005*45039663SJohn Forte "getStmfState:ioctl errno(%d)", errno); 5006*45039663SJohn Forte ret = STMF_STATUS_ERROR; 5007*45039663SJohn Forte break; 5008*45039663SJohn Forte } 5009*45039663SJohn Forte } 5010*45039663SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 5011*45039663SJohn Forte deleteNonActiveLus(); 5012*45039663SJohn Forte } 5013*45039663SJohn Forte 5014*45039663SJohn Forte return (ret); 5015*45039663SJohn Forte } 5016*45039663SJohn Forte 5017*45039663SJohn Forte static void 5018*45039663SJohn Forte deleteNonActiveLus() 5019*45039663SJohn Forte { 5020*45039663SJohn Forte int stmfRet; 5021*45039663SJohn Forte int i; 5022*45039663SJohn Forte stmfGuidList *luList; 5023*45039663SJohn Forte luResource hdl = NULL; 5024*45039663SJohn Forte char propVal[10]; 5025*45039663SJohn Forte size_t propValSize = sizeof (propVal); 5026*45039663SJohn Forte 5027*45039663SJohn Forte stmfRet = stmfGetLogicalUnitList(&luList); 5028*45039663SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 5029*45039663SJohn Forte return; 5030*45039663SJohn Forte } 5031*45039663SJohn Forte 5032*45039663SJohn Forte for (i = 0; i < luList->cnt; i++) { 5033*45039663SJohn Forte stmfRet = stmfGetLuResource(&luList->guid[i], &hdl); 5034*45039663SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 5035*45039663SJohn Forte goto err; 5036*45039663SJohn Forte } 5037*45039663SJohn Forte stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_ACCESS_STATE, propVal, 5038*45039663SJohn Forte &propValSize); 5039*45039663SJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) { 5040*45039663SJohn Forte goto err; 5041*45039663SJohn Forte } 5042*45039663SJohn Forte if (propVal[0] == '0') { 5043*45039663SJohn Forte (void) stmfFreeLuResource(hdl); 5044*45039663SJohn Forte hdl = NULL; 5045*45039663SJohn Forte continue; 5046*45039663SJohn Forte } 5047*45039663SJohn Forte (void) stmfDeleteLu(&luList->guid[i]); 5048*45039663SJohn Forte (void) stmfFreeLuResource(hdl); 5049*45039663SJohn Forte hdl = NULL; 5050*45039663SJohn Forte } 5051*45039663SJohn Forte 5052*45039663SJohn Forte err: 5053*45039663SJohn Forte stmfFreeMemory(luList); 5054*45039663SJohn Forte (void) stmfFreeLuResource(hdl); 5055*45039663SJohn Forte } 5056*45039663SJohn Forte 5057*45039663SJohn Forte /* 5058fcf3ce44SJohn Forte * stmfLoadConfig 5059fcf3ce44SJohn Forte * 5060fcf3ce44SJohn Forte * Purpose - load the configuration data from smf into stmf 5061fcf3ce44SJohn Forte * 5062fcf3ce44SJohn Forte */ 5063fcf3ce44SJohn Forte int 5064fcf3ce44SJohn Forte stmfLoadConfig(void) 5065fcf3ce44SJohn Forte { 50668fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 5067fcf3ce44SJohn Forte int fd; 5068fcf3ce44SJohn Forte stmf_state_desc_t stmfStateSet; 5069fcf3ce44SJohn Forte stmfState state; 5070fcf3ce44SJohn Forte 50718fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 50728fe96085Stim szeto stmfStateSet.state = STMF_STATE_OFFLINE; 5073640428aeSSue Gleeson 50748fe96085Stim szeto if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) 50758fe96085Stim szeto != STMF_STATUS_SUCCESS) { 50768fe96085Stim szeto return (ret); 50778fe96085Stim szeto } 5078640428aeSSue Gleeson /* 5079640428aeSSue Gleeson * Configuration not stored persistently; nothing to 5080640428aeSSue Gleeson * initialize so do not set to STMF_CONFIG_INIT. 5081640428aeSSue Gleeson */ 50828fe96085Stim szeto stmfStateSet.config_state = STMF_CONFIG_INIT_DONE; 50838fe96085Stim szeto goto done; 50848fe96085Stim szeto } 5085fcf3ce44SJohn Forte 5086fcf3ce44SJohn Forte /* Check to ensure service exists */ 5087fcf3ce44SJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) { 5088fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND); 5089fcf3ce44SJohn Forte } 5090fcf3ce44SJohn Forte 5091fcf3ce44SJohn Forte ret = stmfGetState(&state); 5092fcf3ce44SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 5093fcf3ce44SJohn Forte if (state.operationalState != STMF_SERVICE_STATE_OFFLINE) { 5094fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_ONLINE); 5095fcf3ce44SJohn Forte } 5096fcf3ce44SJohn Forte } else { 5097fcf3ce44SJohn Forte return (STMF_STATUS_ERROR); 5098fcf3ce44SJohn Forte } 5099fcf3ce44SJohn Forte 5100fcf3ce44SJohn Forte 5101fcf3ce44SJohn Forte stmfStateSet.state = STMF_STATE_OFFLINE; 5102fcf3ce44SJohn Forte stmfStateSet.config_state = STMF_CONFIG_INIT; 5103fcf3ce44SJohn Forte 5104fcf3ce44SJohn Forte /* 5105fcf3ce44SJohn Forte * Open control node for stmf 5106fcf3ce44SJohn Forte */ 5107fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS) 5108fcf3ce44SJohn Forte return (ret); 5109fcf3ce44SJohn Forte 5110fcf3ce44SJohn Forte ret = setStmfState(fd, &stmfStateSet, STMF_SERVICE_TYPE); 5111fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 5112fcf3ce44SJohn Forte goto done; 5113fcf3ce44SJohn Forte } 5114fcf3ce44SJohn Forte 5115fcf3ce44SJohn Forte /* Load the persistent configuration data */ 5116fcf3ce44SJohn Forte ret = loadStore(fd); 5117fcf3ce44SJohn Forte if (ret != 0) { 5118fcf3ce44SJohn Forte goto done; 5119fcf3ce44SJohn Forte } 5120fcf3ce44SJohn Forte 5121fcf3ce44SJohn Forte stmfStateSet.state = STMF_STATE_OFFLINE; 5122fcf3ce44SJohn Forte stmfStateSet.config_state = STMF_CONFIG_INIT_DONE; 5123fcf3ce44SJohn Forte 5124fcf3ce44SJohn Forte done: 5125fcf3ce44SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 5126fcf3ce44SJohn Forte ret = setStmfState(fd, &stmfStateSet, STMF_SERVICE_TYPE); 5127fcf3ce44SJohn Forte } 5128fcf3ce44SJohn Forte (void) close(fd); 5129fcf3ce44SJohn Forte return (ret); 5130fcf3ce44SJohn Forte } 5131fcf3ce44SJohn Forte 51328fe96085Stim szeto 5133fcf3ce44SJohn Forte /* 5134fcf3ce44SJohn Forte * getStmfState 5135fcf3ce44SJohn Forte * 5136fcf3ce44SJohn Forte * stmfState - pointer to stmf_state_desc_t structure. Will contain the state 5137fcf3ce44SJohn Forte * information of the stmf service on success. 5138fcf3ce44SJohn Forte */ 5139fcf3ce44SJohn Forte static int 5140fcf3ce44SJohn Forte getStmfState(stmf_state_desc_t *stmfState) 5141fcf3ce44SJohn Forte { 5142fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5143fcf3ce44SJohn Forte int fd; 5144fcf3ce44SJohn Forte int ioctlRet; 5145fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 5146fcf3ce44SJohn Forte 5147fcf3ce44SJohn Forte /* 5148fcf3ce44SJohn Forte * Open control node for stmf 5149fcf3ce44SJohn Forte */ 5150fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 5151fcf3ce44SJohn Forte return (ret); 5152fcf3ce44SJohn Forte 5153fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 5154fcf3ce44SJohn Forte /* 5155fcf3ce44SJohn Forte * Issue ioctl to get the stmf state 5156fcf3ce44SJohn Forte */ 5157fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 5158fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmf_state_desc_t); 5159fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)stmfState; 5160fcf3ce44SJohn Forte stmfIoctl.stmf_obuf_size = sizeof (stmf_state_desc_t); 5161fcf3ce44SJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)stmfState; 5162fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_GET_STMF_STATE, &stmfIoctl); 5163fcf3ce44SJohn Forte 5164fcf3ce44SJohn Forte (void) close(fd); 5165fcf3ce44SJohn Forte 5166fcf3ce44SJohn Forte if (ioctlRet != 0) { 5167fcf3ce44SJohn Forte switch (errno) { 5168fcf3ce44SJohn Forte case EBUSY: 5169fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 5170fcf3ce44SJohn Forte break; 5171fcf3ce44SJohn Forte case EPERM: 5172fcf3ce44SJohn Forte case EACCES: 5173fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 5174fcf3ce44SJohn Forte break; 5175fcf3ce44SJohn Forte default: 5176fcf3ce44SJohn Forte syslog(LOG_DEBUG, 5177fcf3ce44SJohn Forte "getStmfState:ioctl errno(%d)", errno); 5178fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5179fcf3ce44SJohn Forte break; 5180fcf3ce44SJohn Forte } 5181fcf3ce44SJohn Forte } 5182fcf3ce44SJohn Forte return (ret); 5183fcf3ce44SJohn Forte } 5184fcf3ce44SJohn Forte 5185fcf3ce44SJohn Forte 5186fcf3ce44SJohn Forte /* 5187fcf3ce44SJohn Forte * setStmfState 5188fcf3ce44SJohn Forte * 5189fcf3ce44SJohn Forte * stmfState - pointer to caller set state structure 5190fcf3ce44SJohn Forte * objectType - one of: 5191fcf3ce44SJohn Forte * LOGICAL_UNIT_TYPE 5192fcf3ce44SJohn Forte * TARGET_TYPE 5193fcf3ce44SJohn Forte * STMF_SERVICE_TYPE 5194fcf3ce44SJohn Forte */ 5195fcf3ce44SJohn Forte static int 5196fcf3ce44SJohn Forte setStmfState(int fd, stmf_state_desc_t *stmfState, int objectType) 5197fcf3ce44SJohn Forte { 5198fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5199fcf3ce44SJohn Forte int ioctlRet; 5200fcf3ce44SJohn Forte int cmd; 5201fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 5202fcf3ce44SJohn Forte 5203fcf3ce44SJohn Forte switch (objectType) { 5204fcf3ce44SJohn Forte case LOGICAL_UNIT_TYPE: 5205fcf3ce44SJohn Forte cmd = STMF_IOCTL_SET_LU_STATE; 5206fcf3ce44SJohn Forte break; 5207fcf3ce44SJohn Forte case TARGET_TYPE: 5208fcf3ce44SJohn Forte cmd = STMF_IOCTL_SET_TARGET_PORT_STATE; 5209fcf3ce44SJohn Forte break; 5210fcf3ce44SJohn Forte case STMF_SERVICE_TYPE: 5211fcf3ce44SJohn Forte cmd = STMF_IOCTL_SET_STMF_STATE; 5212fcf3ce44SJohn Forte break; 5213fcf3ce44SJohn Forte default: 5214fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5215fcf3ce44SJohn Forte goto done; 5216fcf3ce44SJohn Forte } 5217fcf3ce44SJohn Forte 5218fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 5219fcf3ce44SJohn Forte /* 5220fcf3ce44SJohn Forte * Issue ioctl to set the stmf state 5221fcf3ce44SJohn Forte */ 5222fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 5223fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmf_state_desc_t); 5224fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)stmfState; 5225fcf3ce44SJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl); 5226fcf3ce44SJohn Forte if (ioctlRet != 0) { 5227fcf3ce44SJohn Forte switch (errno) { 5228fcf3ce44SJohn Forte case EBUSY: 5229fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 5230fcf3ce44SJohn Forte break; 52318fe96085Stim szeto case EPERM: 5232fcf3ce44SJohn Forte case EACCES: 5233fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 5234fcf3ce44SJohn Forte break; 5235fcf3ce44SJohn Forte case ENOENT: 5236fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 5237fcf3ce44SJohn Forte break; 5238fcf3ce44SJohn Forte default: 5239fcf3ce44SJohn Forte syslog(LOG_DEBUG, 5240fcf3ce44SJohn Forte "setStmfState:ioctl errno(%d)", errno); 5241fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5242fcf3ce44SJohn Forte break; 5243fcf3ce44SJohn Forte } 5244fcf3ce44SJohn Forte } 5245fcf3ce44SJohn Forte done: 5246fcf3ce44SJohn Forte return (ret); 5247fcf3ce44SJohn Forte } 5248fcf3ce44SJohn Forte 5249fcf3ce44SJohn Forte /* 5250fcf3ce44SJohn Forte * stmfOnline 5251fcf3ce44SJohn Forte * 5252fcf3ce44SJohn Forte * Purpose: Online stmf service 5253fcf3ce44SJohn Forte * 5254fcf3ce44SJohn Forte */ 5255fcf3ce44SJohn Forte int 5256fcf3ce44SJohn Forte stmfOnline(void) 5257fcf3ce44SJohn Forte { 5258fcf3ce44SJohn Forte int ret; 5259fcf3ce44SJohn Forte int fd; 5260fcf3ce44SJohn Forte stmfState state; 5261fcf3ce44SJohn Forte stmf_state_desc_t iState; 5262fcf3ce44SJohn Forte 5263fcf3ce44SJohn Forte ret = stmfGetState(&state); 5264fcf3ce44SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 5265fcf3ce44SJohn Forte if (state.operationalState == STMF_SERVICE_STATE_ONLINE) { 5266fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_ONLINE); 5267fcf3ce44SJohn Forte } 5268fcf3ce44SJohn Forte } else { 5269fcf3ce44SJohn Forte return (STMF_STATUS_ERROR); 5270fcf3ce44SJohn Forte } 5271fcf3ce44SJohn Forte iState.state = STMF_STATE_ONLINE; 5272fcf3ce44SJohn Forte iState.config_state = STMF_CONFIG_NONE; 5273fcf3ce44SJohn Forte /* 5274fcf3ce44SJohn Forte * Open control node for stmf 5275fcf3ce44SJohn Forte * to make call to setStmfState() 5276fcf3ce44SJohn Forte */ 5277fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS) 5278fcf3ce44SJohn Forte return (ret); 5279fcf3ce44SJohn Forte ret = setStmfState(fd, &iState, STMF_SERVICE_TYPE); 5280fcf3ce44SJohn Forte (void) close(fd); 5281fcf3ce44SJohn Forte return (ret); 5282fcf3ce44SJohn Forte } 5283fcf3ce44SJohn Forte 5284fcf3ce44SJohn Forte /* 5285fcf3ce44SJohn Forte * stmfOffline 5286fcf3ce44SJohn Forte * 5287fcf3ce44SJohn Forte * Purpose: Offline stmf service 5288fcf3ce44SJohn Forte * 5289fcf3ce44SJohn Forte */ 5290fcf3ce44SJohn Forte int 5291fcf3ce44SJohn Forte stmfOffline(void) 5292fcf3ce44SJohn Forte { 5293fcf3ce44SJohn Forte int ret; 5294fcf3ce44SJohn Forte int fd; 5295fcf3ce44SJohn Forte stmfState state; 5296fcf3ce44SJohn Forte stmf_state_desc_t iState; 5297fcf3ce44SJohn Forte 5298fcf3ce44SJohn Forte ret = stmfGetState(&state); 5299fcf3ce44SJohn Forte if (ret == STMF_STATUS_SUCCESS) { 5300fcf3ce44SJohn Forte if (state.operationalState == STMF_SERVICE_STATE_OFFLINE) { 5301fcf3ce44SJohn Forte return (STMF_ERROR_SERVICE_OFFLINE); 5302fcf3ce44SJohn Forte } 5303fcf3ce44SJohn Forte } else { 5304fcf3ce44SJohn Forte return (STMF_STATUS_ERROR); 5305fcf3ce44SJohn Forte } 5306fcf3ce44SJohn Forte iState.state = STMF_STATE_OFFLINE; 5307fcf3ce44SJohn Forte iState.config_state = STMF_CONFIG_NONE; 5308fcf3ce44SJohn Forte 5309fcf3ce44SJohn Forte /* 5310fcf3ce44SJohn Forte * Open control node for stmf 5311fcf3ce44SJohn Forte * to make call to setStmfState() 5312fcf3ce44SJohn Forte */ 5313fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS) 5314fcf3ce44SJohn Forte return (ret); 5315fcf3ce44SJohn Forte ret = setStmfState(fd, &iState, STMF_SERVICE_TYPE); 5316fcf3ce44SJohn Forte (void) close(fd); 5317fcf3ce44SJohn Forte return (ret); 5318fcf3ce44SJohn Forte } 5319fcf3ce44SJohn Forte 5320fcf3ce44SJohn Forte 5321fcf3ce44SJohn Forte /* 5322fcf3ce44SJohn Forte * stmfOfflineTarget 5323fcf3ce44SJohn Forte * 5324fcf3ce44SJohn Forte * Purpose: Change state of target to offline 5325fcf3ce44SJohn Forte * 5326fcf3ce44SJohn Forte * devid - devid of the target to offline 5327fcf3ce44SJohn Forte */ 5328fcf3ce44SJohn Forte int 5329fcf3ce44SJohn Forte stmfOfflineTarget(stmfDevid *devid) 5330fcf3ce44SJohn Forte { 5331fcf3ce44SJohn Forte stmf_state_desc_t targetState; 5332fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5333fcf3ce44SJohn Forte int fd; 5334fcf3ce44SJohn Forte 5335fcf3ce44SJohn Forte if (devid == NULL) { 5336fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5337fcf3ce44SJohn Forte } 5338fcf3ce44SJohn Forte bzero(&targetState, sizeof (targetState)); 5339fcf3ce44SJohn Forte 5340fcf3ce44SJohn Forte targetState.state = STMF_STATE_OFFLINE; 5341fcf3ce44SJohn Forte targetState.ident[IDENT_LENGTH_BYTE] = devid->identLength; 5342fcf3ce44SJohn Forte bcopy(&(devid->ident), &targetState.ident[IDENT_LENGTH_BYTE + 1], 5343fcf3ce44SJohn Forte devid->identLength); 5344fcf3ce44SJohn Forte /* 5345fcf3ce44SJohn Forte * Open control node for stmf 5346fcf3ce44SJohn Forte * to make call to setStmfState() 5347fcf3ce44SJohn Forte */ 5348fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS) 5349fcf3ce44SJohn Forte return (ret); 5350fcf3ce44SJohn Forte ret = setStmfState(fd, &targetState, TARGET_TYPE); 5351fcf3ce44SJohn Forte (void) close(fd); 5352fcf3ce44SJohn Forte return (ret); 5353fcf3ce44SJohn Forte } 5354fcf3ce44SJohn Forte 5355fcf3ce44SJohn Forte /* 5356fcf3ce44SJohn Forte * stmfOfflineLogicalUnit 5357fcf3ce44SJohn Forte * 5358fcf3ce44SJohn Forte * Purpose: Change state of logical unit to offline 5359fcf3ce44SJohn Forte * 5360fcf3ce44SJohn Forte * lu - guid of the logical unit to offline 5361fcf3ce44SJohn Forte */ 5362fcf3ce44SJohn Forte int 5363fcf3ce44SJohn Forte stmfOfflineLogicalUnit(stmfGuid *lu) 5364fcf3ce44SJohn Forte { 5365fcf3ce44SJohn Forte stmf_state_desc_t luState; 5366fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5367fcf3ce44SJohn Forte int fd; 5368fcf3ce44SJohn Forte 5369fcf3ce44SJohn Forte if (lu == NULL) { 5370fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5371fcf3ce44SJohn Forte } 5372fcf3ce44SJohn Forte 5373fcf3ce44SJohn Forte bzero(&luState, sizeof (luState)); 5374fcf3ce44SJohn Forte 5375fcf3ce44SJohn Forte luState.state = STMF_STATE_OFFLINE; 5376fcf3ce44SJohn Forte bcopy(lu, &luState.ident, sizeof (stmfGuid)); 5377fcf3ce44SJohn Forte /* 5378fcf3ce44SJohn Forte * Open control node for stmf 5379fcf3ce44SJohn Forte * to make call to setStmfState() 5380fcf3ce44SJohn Forte */ 5381fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS) 5382fcf3ce44SJohn Forte return (ret); 5383fcf3ce44SJohn Forte ret = setStmfState(fd, &luState, LOGICAL_UNIT_TYPE); 5384fcf3ce44SJohn Forte (void) close(fd); 5385fcf3ce44SJohn Forte return (ret); 5386fcf3ce44SJohn Forte } 5387fcf3ce44SJohn Forte 5388fcf3ce44SJohn Forte /* 5389fcf3ce44SJohn Forte * stmfOnlineTarget 5390fcf3ce44SJohn Forte * 5391fcf3ce44SJohn Forte * Purpose: Change state of target to online 5392fcf3ce44SJohn Forte * 5393fcf3ce44SJohn Forte * devid - devid of the target to online 5394fcf3ce44SJohn Forte */ 5395fcf3ce44SJohn Forte int 5396fcf3ce44SJohn Forte stmfOnlineTarget(stmfDevid *devid) 5397fcf3ce44SJohn Forte { 5398fcf3ce44SJohn Forte stmf_state_desc_t targetState; 5399fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5400fcf3ce44SJohn Forte int fd; 5401fcf3ce44SJohn Forte 5402fcf3ce44SJohn Forte if (devid == NULL) { 5403fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5404fcf3ce44SJohn Forte } 5405fcf3ce44SJohn Forte bzero(&targetState, sizeof (targetState)); 5406fcf3ce44SJohn Forte 5407fcf3ce44SJohn Forte targetState.state = STMF_STATE_ONLINE; 5408fcf3ce44SJohn Forte targetState.ident[IDENT_LENGTH_BYTE] = devid->identLength; 5409fcf3ce44SJohn Forte bcopy(&(devid->ident), &targetState.ident[IDENT_LENGTH_BYTE + 1], 5410fcf3ce44SJohn Forte devid->identLength); 5411fcf3ce44SJohn Forte /* 5412fcf3ce44SJohn Forte * Open control node for stmf 5413fcf3ce44SJohn Forte * to make call to setStmfState() 5414fcf3ce44SJohn Forte */ 5415fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS) 5416fcf3ce44SJohn Forte return (ret); 5417fcf3ce44SJohn Forte ret = setStmfState(fd, &targetState, TARGET_TYPE); 5418fcf3ce44SJohn Forte (void) close(fd); 5419fcf3ce44SJohn Forte return (ret); 5420fcf3ce44SJohn Forte } 5421fcf3ce44SJohn Forte 5422fcf3ce44SJohn Forte /* 5423fcf3ce44SJohn Forte * stmfOnlineLogicalUnit 5424fcf3ce44SJohn Forte * 5425fcf3ce44SJohn Forte * Purpose: Change state of logical unit to online 5426fcf3ce44SJohn Forte * 5427fcf3ce44SJohn Forte * lu - guid of the logical unit to online 5428fcf3ce44SJohn Forte */ 5429fcf3ce44SJohn Forte int 5430fcf3ce44SJohn Forte stmfOnlineLogicalUnit(stmfGuid *lu) 5431fcf3ce44SJohn Forte { 5432fcf3ce44SJohn Forte stmf_state_desc_t luState; 5433fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5434fcf3ce44SJohn Forte int fd; 5435fcf3ce44SJohn Forte 5436fcf3ce44SJohn Forte if (lu == NULL) { 5437fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5438fcf3ce44SJohn Forte } 5439fcf3ce44SJohn Forte 5440fcf3ce44SJohn Forte bzero(&luState, sizeof (luState)); 5441fcf3ce44SJohn Forte 5442fcf3ce44SJohn Forte luState.state = STMF_STATE_ONLINE; 5443fcf3ce44SJohn Forte bcopy(lu, &luState.ident, sizeof (stmfGuid)); 5444fcf3ce44SJohn Forte /* 5445fcf3ce44SJohn Forte * Open control node for stmf 5446fcf3ce44SJohn Forte * to make call to setStmfState() 5447fcf3ce44SJohn Forte */ 5448fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS) 5449fcf3ce44SJohn Forte return (ret); 5450fcf3ce44SJohn Forte ret = setStmfState(fd, &luState, LOGICAL_UNIT_TYPE); 5451fcf3ce44SJohn Forte (void) close(fd); 5452fcf3ce44SJohn Forte return (ret); 5453fcf3ce44SJohn Forte } 5454fcf3ce44SJohn Forte 5455fcf3ce44SJohn Forte /* 5456fcf3ce44SJohn Forte * stmfRemoveFromHostGroup 5457fcf3ce44SJohn Forte * 5458fcf3ce44SJohn Forte * Purpose: Removes an initiator from an initiator group 5459fcf3ce44SJohn Forte * 5460fcf3ce44SJohn Forte * hostGroupName - name of an initiator group 5461fcf3ce44SJohn Forte * hostName - name of host group member to remove 5462fcf3ce44SJohn Forte */ 5463fcf3ce44SJohn Forte int 5464fcf3ce44SJohn Forte stmfRemoveFromHostGroup(stmfGroupName *hostGroupName, stmfDevid *hostName) 5465fcf3ce44SJohn Forte { 5466fcf3ce44SJohn Forte int ret; 5467fcf3ce44SJohn Forte int fd; 5468fcf3ce44SJohn Forte 5469fcf3ce44SJohn Forte if (hostGroupName == NULL || 5470fcf3ce44SJohn Forte (strnlen((char *)hostGroupName, sizeof (stmfGroupName)) 5471fcf3ce44SJohn Forte == sizeof (stmfGroupName)) || hostName == NULL) { 5472fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5473fcf3ce44SJohn Forte } 5474fcf3ce44SJohn Forte 5475fcf3ce44SJohn Forte /* call init */ 5476fcf3ce44SJohn Forte ret = initializeConfig(); 5477fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 5478fcf3ce44SJohn Forte return (ret); 5479fcf3ce44SJohn Forte } 5480fcf3ce44SJohn Forte 5481fcf3ce44SJohn Forte /* 5482fcf3ce44SJohn Forte * Open control node for stmf 5483fcf3ce44SJohn Forte */ 5484fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 5485fcf3ce44SJohn Forte return (ret); 5486fcf3ce44SJohn Forte 5487fcf3ce44SJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_REMOVE_HG_ENTRY, 5488fcf3ce44SJohn Forte hostGroupName, hostName)) != STMF_STATUS_SUCCESS) { 5489fcf3ce44SJohn Forte goto done; 5490fcf3ce44SJohn Forte } 5491fcf3ce44SJohn Forte 54928fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 54938fe96085Stim szeto goto done; 54948fe96085Stim szeto } 54958fe96085Stim szeto 5496fcf3ce44SJohn Forte ret = psRemoveHostGroupMember((char *)hostGroupName, 5497fcf3ce44SJohn Forte (char *)hostName->ident); 5498fcf3ce44SJohn Forte switch (ret) { 5499fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 5500fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 5501fcf3ce44SJohn Forte break; 5502fcf3ce44SJohn Forte case STMF_PS_ERROR_MEMBER_NOT_FOUND: 5503fcf3ce44SJohn Forte ret = STMF_ERROR_MEMBER_NOT_FOUND; 5504fcf3ce44SJohn Forte break; 5505fcf3ce44SJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND: 5506fcf3ce44SJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND; 5507fcf3ce44SJohn Forte break; 5508fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 5509fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 5510fcf3ce44SJohn Forte break; 5511fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 5512fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 5513fcf3ce44SJohn Forte break; 5514fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 5515fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 5516fcf3ce44SJohn Forte break; 5517fcf3ce44SJohn Forte default: 5518fcf3ce44SJohn Forte syslog(LOG_DEBUG, 5519fcf3ce44SJohn Forte "stmfRemoveFromHostGroup" 5520fcf3ce44SJohn Forte "psRemoveHostGroupMember:error(%d)", ret); 5521fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5522fcf3ce44SJohn Forte break; 5523fcf3ce44SJohn Forte } 5524fcf3ce44SJohn Forte 5525fcf3ce44SJohn Forte done: 5526fcf3ce44SJohn Forte (void) close(fd); 5527fcf3ce44SJohn Forte return (ret); 5528fcf3ce44SJohn Forte } 5529fcf3ce44SJohn Forte 5530fcf3ce44SJohn Forte /* 5531fcf3ce44SJohn Forte * stmfRemoveFromTargetGroup 5532fcf3ce44SJohn Forte * 5533fcf3ce44SJohn Forte * Purpose: Removes a local port from a local port group 5534fcf3ce44SJohn Forte * 5535fcf3ce44SJohn Forte * targetGroupName - name of a target group 5536fcf3ce44SJohn Forte * targetName - name of target to remove 5537fcf3ce44SJohn Forte */ 5538fcf3ce44SJohn Forte int 5539fcf3ce44SJohn Forte stmfRemoveFromTargetGroup(stmfGroupName *targetGroupName, stmfDevid *targetName) 5540fcf3ce44SJohn Forte { 5541fcf3ce44SJohn Forte int ret; 5542fcf3ce44SJohn Forte int fd; 5543fcf3ce44SJohn Forte 5544fcf3ce44SJohn Forte if (targetGroupName == NULL || 5545fcf3ce44SJohn Forte (strnlen((char *)targetGroupName, sizeof (stmfGroupName)) 5546fcf3ce44SJohn Forte == sizeof (stmfGroupName)) || targetName == NULL) { 5547fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5548fcf3ce44SJohn Forte } 5549fcf3ce44SJohn Forte 5550fcf3ce44SJohn Forte /* call init */ 5551fcf3ce44SJohn Forte ret = initializeConfig(); 5552fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 5553fcf3ce44SJohn Forte return (ret); 5554fcf3ce44SJohn Forte } 5555fcf3ce44SJohn Forte 5556fcf3ce44SJohn Forte /* 5557fcf3ce44SJohn Forte * Open control node for stmf 5558fcf3ce44SJohn Forte */ 5559fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 5560fcf3ce44SJohn Forte return (ret); 5561fcf3ce44SJohn Forte 5562fcf3ce44SJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_REMOVE_TG_ENTRY, 5563fcf3ce44SJohn Forte targetGroupName, targetName)) != STMF_STATUS_SUCCESS) { 5564fcf3ce44SJohn Forte goto done; 5565fcf3ce44SJohn Forte } 5566fcf3ce44SJohn Forte 55678fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 55688fe96085Stim szeto goto done; 55698fe96085Stim szeto } 55708fe96085Stim szeto 5571fcf3ce44SJohn Forte ret = psRemoveTargetGroupMember((char *)targetGroupName, 5572fcf3ce44SJohn Forte (char *)targetName->ident); 5573fcf3ce44SJohn Forte switch (ret) { 5574fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 5575fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 5576fcf3ce44SJohn Forte break; 5577fcf3ce44SJohn Forte case STMF_PS_ERROR_MEMBER_NOT_FOUND: 5578fcf3ce44SJohn Forte ret = STMF_ERROR_MEMBER_NOT_FOUND; 5579fcf3ce44SJohn Forte break; 5580fcf3ce44SJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND: 5581fcf3ce44SJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND; 5582fcf3ce44SJohn Forte break; 5583fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 5584fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 5585fcf3ce44SJohn Forte break; 5586fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 5587fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 5588fcf3ce44SJohn Forte break; 5589fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 5590fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 5591fcf3ce44SJohn Forte break; 5592fcf3ce44SJohn Forte default: 5593fcf3ce44SJohn Forte syslog(LOG_DEBUG, 5594fcf3ce44SJohn Forte "stmfRemoveFromTargetGroup" 5595fcf3ce44SJohn Forte "psRemoveTargetGroupMember:error(%d)", ret); 5596fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5597fcf3ce44SJohn Forte break; 5598fcf3ce44SJohn Forte } 5599fcf3ce44SJohn Forte 5600fcf3ce44SJohn Forte done: 5601fcf3ce44SJohn Forte (void) close(fd); 5602fcf3ce44SJohn Forte return (ret); 5603fcf3ce44SJohn Forte } 5604fcf3ce44SJohn Forte 5605fcf3ce44SJohn Forte /* 5606fcf3ce44SJohn Forte * stmfRemoveViewEntry 5607fcf3ce44SJohn Forte * 5608fcf3ce44SJohn Forte * Purpose: Removes a view entry from a logical unit 5609fcf3ce44SJohn Forte * 5610fcf3ce44SJohn Forte * lu - guid of lu for which view entry is being removed 5611fcf3ce44SJohn Forte * viewEntryIndex - index of view entry to remove 5612fcf3ce44SJohn Forte * 5613fcf3ce44SJohn Forte */ 5614fcf3ce44SJohn Forte int 5615fcf3ce44SJohn Forte stmfRemoveViewEntry(stmfGuid *lu, uint32_t viewEntryIndex) 5616fcf3ce44SJohn Forte { 5617fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5618fcf3ce44SJohn Forte int fd; 5619fcf3ce44SJohn Forte int ioctlRet; 5620fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 5621fcf3ce44SJohn Forte stmf_view_op_entry_t ioctlViewEntry; 5622fcf3ce44SJohn Forte 5623fcf3ce44SJohn Forte if (lu == NULL) { 5624fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5625fcf3ce44SJohn Forte } 5626fcf3ce44SJohn Forte 5627fcf3ce44SJohn Forte /* call init */ 5628fcf3ce44SJohn Forte ret = initializeConfig(); 5629fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 5630fcf3ce44SJohn Forte return (ret); 5631fcf3ce44SJohn Forte } 5632fcf3ce44SJohn Forte 5633fcf3ce44SJohn Forte /* 5634fcf3ce44SJohn Forte * Open control node for stmf 5635fcf3ce44SJohn Forte */ 5636fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 5637fcf3ce44SJohn Forte return (ret); 5638fcf3ce44SJohn Forte 5639fcf3ce44SJohn Forte bzero(&ioctlViewEntry, sizeof (ioctlViewEntry)); 5640fcf3ce44SJohn Forte ioctlViewEntry.ve_ndx_valid = B_TRUE; 5641fcf3ce44SJohn Forte ioctlViewEntry.ve_ndx = viewEntryIndex; 5642fcf3ce44SJohn Forte bcopy(lu, &ioctlViewEntry.ve_guid, sizeof (stmfGuid)); 5643fcf3ce44SJohn Forte 5644fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 5645fcf3ce44SJohn Forte /* 5646fcf3ce44SJohn Forte * Issue ioctl to add to the view entry 5647fcf3ce44SJohn Forte */ 5648fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 5649fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (ioctlViewEntry); 5650fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ioctlViewEntry; 5651fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_REMOVE_VIEW_ENTRY, &stmfIoctl); 5652fcf3ce44SJohn Forte if (ioctlRet != 0) { 5653fcf3ce44SJohn Forte switch (errno) { 5654fcf3ce44SJohn Forte case EBUSY: 5655fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 5656fcf3ce44SJohn Forte break; 56578fe96085Stim szeto case EPERM: 56588fe96085Stim szeto ret = STMF_ERROR_PERM; 56598fe96085Stim szeto break; 5660fcf3ce44SJohn Forte case EACCES: 5661fcf3ce44SJohn Forte switch (stmfIoctl.stmf_error) { 5662fcf3ce44SJohn Forte case STMF_IOCERR_UPDATE_NEED_CFG_INIT: 5663fcf3ce44SJohn Forte ret = STMF_ERROR_CONFIG_NONE; 5664fcf3ce44SJohn Forte break; 5665fcf3ce44SJohn Forte default: 5666fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 5667fcf3ce44SJohn Forte break; 5668fcf3ce44SJohn Forte } 5669fcf3ce44SJohn Forte break; 5670fcf3ce44SJohn Forte case ENODEV: 5671fcf3ce44SJohn Forte case ENOENT: 5672fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 5673fcf3ce44SJohn Forte break; 5674fcf3ce44SJohn Forte default: 5675fcf3ce44SJohn Forte syslog(LOG_DEBUG, 5676fcf3ce44SJohn Forte "stmfRemoveViewEntry:ioctl errno(%d)", 5677fcf3ce44SJohn Forte errno); 5678fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5679fcf3ce44SJohn Forte break; 5680fcf3ce44SJohn Forte } 5681fcf3ce44SJohn Forte goto done; 5682fcf3ce44SJohn Forte } 5683fcf3ce44SJohn Forte 56848fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 56858fe96085Stim szeto goto done; 56868fe96085Stim szeto } 56878fe96085Stim szeto 5688fcf3ce44SJohn Forte ret = psRemoveViewEntry(lu, viewEntryIndex); 5689fcf3ce44SJohn Forte switch (ret) { 5690fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 5691fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 5692fcf3ce44SJohn Forte break; 5693fcf3ce44SJohn Forte case STMF_PS_ERROR_NOT_FOUND: 5694fcf3ce44SJohn Forte ret = STMF_ERROR_NOT_FOUND; 5695fcf3ce44SJohn Forte break; 5696fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 5697fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 5698fcf3ce44SJohn Forte break; 5699fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 5700fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 5701fcf3ce44SJohn Forte break; 5702fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 5703fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 5704fcf3ce44SJohn Forte break; 5705fcf3ce44SJohn Forte default: 5706fcf3ce44SJohn Forte syslog(LOG_DEBUG, 5707fcf3ce44SJohn Forte "stmfRemoveViewEntry" "psRemoveViewEntry:error(%d)", 5708fcf3ce44SJohn Forte ret); 5709fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5710fcf3ce44SJohn Forte break; 5711fcf3ce44SJohn Forte } 5712fcf3ce44SJohn Forte 5713fcf3ce44SJohn Forte done: 5714fcf3ce44SJohn Forte (void) close(fd); 5715fcf3ce44SJohn Forte return (ret); 5716fcf3ce44SJohn Forte } 5717fcf3ce44SJohn Forte 5718fcf3ce44SJohn Forte /* 5719fcf3ce44SJohn Forte * stmfSetProviderData 5720fcf3ce44SJohn Forte * 5721fcf3ce44SJohn Forte * Purpose: set the provider data 5722fcf3ce44SJohn Forte * 5723fcf3ce44SJohn Forte * providerName - unique name of provider 5724fcf3ce44SJohn Forte * nvl - nvlist to set 5725fcf3ce44SJohn Forte * providerType - type of provider for which to set data 5726fcf3ce44SJohn Forte * STMF_LU_PROVIDER_TYPE 5727fcf3ce44SJohn Forte * STMF_PORT_PROVIDER_TYPE 5728fcf3ce44SJohn Forte */ 5729fcf3ce44SJohn Forte int 5730fcf3ce44SJohn Forte stmfSetProviderData(char *providerName, nvlist_t *nvl, int providerType) 5731fcf3ce44SJohn Forte { 5732fcf3ce44SJohn Forte return (stmfSetProviderDataProt(providerName, nvl, providerType, 5733fcf3ce44SJohn Forte NULL)); 5734fcf3ce44SJohn Forte } 5735fcf3ce44SJohn Forte 5736fcf3ce44SJohn Forte /* 5737fcf3ce44SJohn Forte * stmfSetProviderDataProt 5738fcf3ce44SJohn Forte * 5739fcf3ce44SJohn Forte * Purpose: set the provider data 5740fcf3ce44SJohn Forte * 5741fcf3ce44SJohn Forte * providerName - unique name of provider 5742fcf3ce44SJohn Forte * nvl - nvlist to set 5743fcf3ce44SJohn Forte * providerType - type of provider for which to set data 5744fcf3ce44SJohn Forte * STMF_LU_PROVIDER_TYPE 5745fcf3ce44SJohn Forte * STMF_PORT_PROVIDER_TYPE 5746fcf3ce44SJohn Forte * setToken - Stale data token returned in the stmfGetProviderDataProt() 5747fcf3ce44SJohn Forte * call or NULL. 5748fcf3ce44SJohn Forte */ 5749fcf3ce44SJohn Forte int 5750fcf3ce44SJohn Forte stmfSetProviderDataProt(char *providerName, nvlist_t *nvl, int providerType, 5751fcf3ce44SJohn Forte uint64_t *setToken) 5752fcf3ce44SJohn Forte { 5753fcf3ce44SJohn Forte int ret; 5754fcf3ce44SJohn Forte int fd; 5755fcf3ce44SJohn Forte 5756fcf3ce44SJohn Forte if (providerName == NULL || nvl == NULL) { 5757fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5758fcf3ce44SJohn Forte } 5759fcf3ce44SJohn Forte 5760fcf3ce44SJohn Forte if (providerType != STMF_LU_PROVIDER_TYPE && 5761fcf3ce44SJohn Forte providerType != STMF_PORT_PROVIDER_TYPE) { 5762fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5763fcf3ce44SJohn Forte } 5764fcf3ce44SJohn Forte 5765fcf3ce44SJohn Forte /* call init */ 5766fcf3ce44SJohn Forte ret = initializeConfig(); 5767fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 5768fcf3ce44SJohn Forte return (ret); 5769fcf3ce44SJohn Forte } 5770fcf3ce44SJohn Forte 5771fcf3ce44SJohn Forte /* 5772fcf3ce44SJohn Forte * Open control node for stmf 5773fcf3ce44SJohn Forte */ 5774fcf3ce44SJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 5775fcf3ce44SJohn Forte return (ret); 5776fcf3ce44SJohn Forte 57778fe96085Stim szeto ret = setProviderData(fd, providerName, nvl, providerType, setToken); 5778fcf3ce44SJohn Forte 5779fcf3ce44SJohn Forte (void) close(fd); 5780fcf3ce44SJohn Forte 5781fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) { 5782fcf3ce44SJohn Forte goto done; 5783fcf3ce44SJohn Forte } 5784fcf3ce44SJohn Forte 57858fe96085Stim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) { 57868fe96085Stim szeto goto done; 57878fe96085Stim szeto } 57888fe96085Stim szeto 5789fcf3ce44SJohn Forte /* setting driver provider data successful. Now persist it */ 57908fe96085Stim szeto ret = psSetProviderData(providerName, nvl, providerType, NULL); 5791fcf3ce44SJohn Forte switch (ret) { 5792fcf3ce44SJohn Forte case STMF_PS_SUCCESS: 5793fcf3ce44SJohn Forte ret = STMF_STATUS_SUCCESS; 5794fcf3ce44SJohn Forte break; 5795fcf3ce44SJohn Forte case STMF_PS_ERROR_EXISTS: 5796fcf3ce44SJohn Forte ret = STMF_ERROR_EXISTS; 5797fcf3ce44SJohn Forte break; 5798fcf3ce44SJohn Forte case STMF_PS_ERROR_BUSY: 5799fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 5800fcf3ce44SJohn Forte break; 5801fcf3ce44SJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND: 5802fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND; 5803fcf3ce44SJohn Forte break; 5804fcf3ce44SJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH: 5805fcf3ce44SJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION; 5806fcf3ce44SJohn Forte break; 5807fcf3ce44SJohn Forte case STMF_PS_ERROR_PROV_DATA_STALE: 5808fcf3ce44SJohn Forte ret = STMF_ERROR_PROV_DATA_STALE; 5809fcf3ce44SJohn Forte break; 5810fcf3ce44SJohn Forte default: 5811fcf3ce44SJohn Forte syslog(LOG_DEBUG, 5812fcf3ce44SJohn Forte "stmfSetProviderData" 5813fcf3ce44SJohn Forte "psSetProviderData:error(%d)", ret); 5814fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 5815fcf3ce44SJohn Forte break; 5816fcf3ce44SJohn Forte } 5817fcf3ce44SJohn Forte 5818fcf3ce44SJohn Forte done: 5819fcf3ce44SJohn Forte return (ret); 5820fcf3ce44SJohn Forte } 5821fcf3ce44SJohn Forte 5822fcf3ce44SJohn Forte /* 58238fe96085Stim szeto * getProviderData 58248fe96085Stim szeto * 58258fe96085Stim szeto * Purpose: set the provider data from stmf 58268fe96085Stim szeto * 58278fe96085Stim szeto * providerName - unique name of provider 58288fe96085Stim szeto * nvl - nvlist to load/retrieve 58298fe96085Stim szeto * providerType - logical unit or port provider 58308fe96085Stim szeto * setToken - returned stale data token 58318fe96085Stim szeto */ 58328fe96085Stim szeto int 58338fe96085Stim szeto getProviderData(char *providerName, nvlist_t **nvl, int providerType, 58348fe96085Stim szeto uint64_t *setToken) 58358fe96085Stim szeto { 58368fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 58378fe96085Stim szeto int fd; 58388fe96085Stim szeto int ioctlRet; 58398fe96085Stim szeto size_t nvlistSize = ALLOC_PP_DATA_SIZE; 58408fe96085Stim szeto int retryCnt = 0; 58418fe96085Stim szeto int retryCntMax = MAX_PROVIDER_RETRY; 58428fe96085Stim szeto stmf_ppioctl_data_t ppi = {0}, *ppi_out = NULL; 58438fe96085Stim szeto boolean_t retry = B_TRUE; 58448fe96085Stim szeto stmf_iocdata_t stmfIoctl; 58458fe96085Stim szeto 58468fe96085Stim szeto if (providerName == NULL) { 58478fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 58488fe96085Stim szeto } 58498fe96085Stim szeto 58508fe96085Stim szeto /* 58518fe96085Stim szeto * Open control node for stmf 58528fe96085Stim szeto */ 58538fe96085Stim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 58548fe96085Stim szeto return (ret); 58558fe96085Stim szeto 58568fe96085Stim szeto /* set provider name and provider type */ 58578fe96085Stim szeto if (strlcpy(ppi.ppi_name, providerName, 58588fe96085Stim szeto sizeof (ppi.ppi_name)) >= 58598fe96085Stim szeto sizeof (ppi.ppi_name)) { 58608fe96085Stim szeto ret = STMF_ERROR_INVALID_ARG; 58618fe96085Stim szeto goto done; 58628fe96085Stim szeto } 58638fe96085Stim szeto switch (providerType) { 58648fe96085Stim szeto case STMF_LU_PROVIDER_TYPE: 58658fe96085Stim szeto ppi.ppi_lu_provider = 1; 58668fe96085Stim szeto break; 58678fe96085Stim szeto case STMF_PORT_PROVIDER_TYPE: 58688fe96085Stim szeto ppi.ppi_port_provider = 1; 58698fe96085Stim szeto break; 58708fe96085Stim szeto default: 58718fe96085Stim szeto ret = STMF_ERROR_INVALID_ARG; 58728fe96085Stim szeto goto done; 58738fe96085Stim szeto } 58748fe96085Stim szeto 58758fe96085Stim szeto do { 58768fe96085Stim szeto /* allocate memory for ioctl */ 58778fe96085Stim szeto ppi_out = (stmf_ppioctl_data_t *)calloc(1, nvlistSize + 58788fe96085Stim szeto sizeof (stmf_ppioctl_data_t)); 58798fe96085Stim szeto if (ppi_out == NULL) { 58808fe96085Stim szeto ret = STMF_ERROR_NOMEM; 58818fe96085Stim szeto goto done; 58828fe96085Stim szeto 58838fe96085Stim szeto } 58848fe96085Stim szeto 58858fe96085Stim szeto /* set the size of the ioctl data to allocated buffer */ 58868fe96085Stim szeto ppi.ppi_data_size = nvlistSize; 58878fe96085Stim szeto 58888fe96085Stim szeto bzero(&stmfIoctl, sizeof (stmfIoctl)); 58898fe96085Stim szeto 58908fe96085Stim szeto stmfIoctl.stmf_version = STMF_VERSION_1; 58918fe96085Stim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmf_ppioctl_data_t); 58928fe96085Stim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ppi; 58938fe96085Stim szeto stmfIoctl.stmf_obuf_size = sizeof (stmf_ppioctl_data_t) + 58948fe96085Stim szeto nvlistSize; 58958fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)ppi_out; 58968fe96085Stim szeto ioctlRet = ioctl(fd, STMF_IOCTL_GET_PP_DATA, &stmfIoctl); 58978fe96085Stim szeto if (ioctlRet != 0) { 58988fe96085Stim szeto switch (errno) { 58998fe96085Stim szeto case EBUSY: 59008fe96085Stim szeto ret = STMF_ERROR_BUSY; 59018fe96085Stim szeto break; 59028fe96085Stim szeto case EPERM: 59038fe96085Stim szeto case EACCES: 59048fe96085Stim szeto ret = STMF_ERROR_PERM; 59058fe96085Stim szeto break; 59068fe96085Stim szeto case EINVAL: 59078fe96085Stim szeto if (stmfIoctl.stmf_error == 59088fe96085Stim szeto STMF_IOCERR_INSUFFICIENT_BUF) { 59098fe96085Stim szeto nvlistSize = 59108fe96085Stim szeto ppi_out->ppi_data_size; 59118fe96085Stim szeto free(ppi_out); 59128fe96085Stim szeto ppi_out = NULL; 59138fe96085Stim szeto if (retryCnt++ > retryCntMax) { 59148fe96085Stim szeto retry = B_FALSE; 59158fe96085Stim szeto ret = STMF_ERROR_BUSY; 59168fe96085Stim szeto } else { 59178fe96085Stim szeto ret = 59188fe96085Stim szeto STMF_STATUS_SUCCESS; 59198fe96085Stim szeto } 59208fe96085Stim szeto } else { 59218fe96085Stim szeto syslog(LOG_DEBUG, 59228fe96085Stim szeto "getProviderData:ioctl" 59238fe96085Stim szeto "unable to retrieve " 59248fe96085Stim szeto "nvlist"); 59258fe96085Stim szeto ret = STMF_STATUS_ERROR; 59268fe96085Stim szeto } 59278fe96085Stim szeto break; 59288fe96085Stim szeto case ENOENT: 59298fe96085Stim szeto ret = STMF_ERROR_NOT_FOUND; 59308fe96085Stim szeto break; 59318fe96085Stim szeto default: 59328fe96085Stim szeto syslog(LOG_DEBUG, 59338fe96085Stim szeto "getProviderData:ioctl errno(%d)", 59348fe96085Stim szeto errno); 59358fe96085Stim szeto ret = STMF_STATUS_ERROR; 59368fe96085Stim szeto break; 59378fe96085Stim szeto } 59388fe96085Stim szeto if (ret != STMF_STATUS_SUCCESS) 59398fe96085Stim szeto goto done; 59408fe96085Stim szeto } 59418fe96085Stim szeto } while (retry && stmfIoctl.stmf_error == STMF_IOCERR_INSUFFICIENT_BUF); 59428fe96085Stim szeto 59438fe96085Stim szeto if ((ret = nvlist_unpack((char *)ppi_out->ppi_data, 59448fe96085Stim szeto ppi_out->ppi_data_size, nvl, 0)) != 0) { 59458fe96085Stim szeto ret = STMF_STATUS_ERROR; 59468fe96085Stim szeto goto done; 59478fe96085Stim szeto } 59488fe96085Stim szeto 59498fe96085Stim szeto /* caller has asked for new token */ 59508fe96085Stim szeto if (setToken) { 59518fe96085Stim szeto *setToken = ppi_out->ppi_token; 59528fe96085Stim szeto } 59538fe96085Stim szeto done: 59548fe96085Stim szeto free(ppi_out); 59558fe96085Stim szeto (void) close(fd); 59568fe96085Stim szeto return (ret); 59578fe96085Stim szeto } 59588fe96085Stim szeto 59598fe96085Stim szeto /* 5960fcf3ce44SJohn Forte * setProviderData 5961fcf3ce44SJohn Forte * 59628fe96085Stim szeto * Purpose: set the provider data in stmf 5963fcf3ce44SJohn Forte * 5964fcf3ce44SJohn Forte * providerName - unique name of provider 5965fcf3ce44SJohn Forte * nvl - nvlist to set 5966fcf3ce44SJohn Forte * providerType - logical unit or port provider 59678fe96085Stim szeto * setToken - stale data token to check if not NULL 5968fcf3ce44SJohn Forte */ 5969fcf3ce44SJohn Forte static int 59708fe96085Stim szeto setProviderData(int fd, char *providerName, nvlist_t *nvl, int providerType, 59718fe96085Stim szeto uint64_t *setToken) 5972fcf3ce44SJohn Forte { 5973fcf3ce44SJohn Forte int ret = STMF_STATUS_SUCCESS; 5974fcf3ce44SJohn Forte int ioctlRet; 5975fcf3ce44SJohn Forte size_t nvlistEncodedSize; 5976fcf3ce44SJohn Forte stmf_ppioctl_data_t *ppi = NULL; 59778fe96085Stim szeto uint64_t outToken; 5978fcf3ce44SJohn Forte char *allocatedNvBuffer; 5979fcf3ce44SJohn Forte stmf_iocdata_t stmfIoctl; 5980fcf3ce44SJohn Forte 5981fcf3ce44SJohn Forte if (providerName == NULL) { 5982fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 5983fcf3ce44SJohn Forte } 5984fcf3ce44SJohn Forte 5985fcf3ce44SJohn Forte /* get size of encoded nvlist */ 5986fcf3ce44SJohn Forte if (nvlist_size(nvl, &nvlistEncodedSize, NV_ENCODE_XDR) != 0) { 5987fcf3ce44SJohn Forte return (STMF_STATUS_ERROR); 5988fcf3ce44SJohn Forte } 5989fcf3ce44SJohn Forte 5990fcf3ce44SJohn Forte /* allocate memory for ioctl */ 5991fcf3ce44SJohn Forte ppi = (stmf_ppioctl_data_t *)calloc(1, nvlistEncodedSize + 5992fcf3ce44SJohn Forte sizeof (stmf_ppioctl_data_t)); 5993fcf3ce44SJohn Forte if (ppi == NULL) { 5994fcf3ce44SJohn Forte return (STMF_ERROR_NOMEM); 5995fcf3ce44SJohn Forte } 5996fcf3ce44SJohn Forte 59978fe96085Stim szeto if (setToken) { 59988fe96085Stim szeto ppi->ppi_token_valid = 1; 59998fe96085Stim szeto ppi->ppi_token = *setToken; 60008fe96085Stim szeto } 60018fe96085Stim szeto 6002fcf3ce44SJohn Forte allocatedNvBuffer = (char *)&ppi->ppi_data; 6003fcf3ce44SJohn Forte if (nvlist_pack(nvl, &allocatedNvBuffer, &nvlistEncodedSize, 6004fcf3ce44SJohn Forte NV_ENCODE_XDR, 0) != 0) { 6005fcf3ce44SJohn Forte return (STMF_STATUS_ERROR); 6006fcf3ce44SJohn Forte } 6007fcf3ce44SJohn Forte 6008fcf3ce44SJohn Forte /* set provider name and provider type */ 6009fcf3ce44SJohn Forte (void) strncpy(ppi->ppi_name, providerName, sizeof (ppi->ppi_name)); 6010fcf3ce44SJohn Forte switch (providerType) { 6011fcf3ce44SJohn Forte case STMF_LU_PROVIDER_TYPE: 6012fcf3ce44SJohn Forte ppi->ppi_lu_provider = 1; 6013fcf3ce44SJohn Forte break; 6014fcf3ce44SJohn Forte case STMF_PORT_PROVIDER_TYPE: 6015fcf3ce44SJohn Forte ppi->ppi_port_provider = 1; 6016fcf3ce44SJohn Forte break; 6017fcf3ce44SJohn Forte default: 6018fcf3ce44SJohn Forte return (STMF_ERROR_INVALID_ARG); 6019fcf3ce44SJohn Forte } 6020fcf3ce44SJohn Forte 6021fcf3ce44SJohn Forte /* set the size of the ioctl data to packed data size */ 6022fcf3ce44SJohn Forte ppi->ppi_data_size = nvlistEncodedSize; 6023fcf3ce44SJohn Forte 6024fcf3ce44SJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl)); 6025fcf3ce44SJohn Forte 6026fcf3ce44SJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1; 6027fcf3ce44SJohn Forte /* 6028fcf3ce44SJohn Forte * Subtracting 8 from the size as that is the size of the last member 6029fcf3ce44SJohn Forte * of the structure where the packed data resides 6030fcf3ce44SJohn Forte */ 6031fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf_size = nvlistEncodedSize + 6032fcf3ce44SJohn Forte sizeof (stmf_ppioctl_data_t) - 8; 6033fcf3ce44SJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)ppi; 60348fe96085Stim szeto stmfIoctl.stmf_obuf_size = sizeof (uint64_t); 60358fe96085Stim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&outToken; 6036fcf3ce44SJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_LOAD_PP_DATA, &stmfIoctl); 6037fcf3ce44SJohn Forte if (ioctlRet != 0) { 6038fcf3ce44SJohn Forte switch (errno) { 6039fcf3ce44SJohn Forte case EBUSY: 6040fcf3ce44SJohn Forte ret = STMF_ERROR_BUSY; 6041fcf3ce44SJohn Forte break; 60428fe96085Stim szeto case EPERM: 6043fcf3ce44SJohn Forte case EACCES: 6044fcf3ce44SJohn Forte ret = STMF_ERROR_PERM; 6045fcf3ce44SJohn Forte break; 60468fe96085Stim szeto case EINVAL: 60478fe96085Stim szeto if (stmfIoctl.stmf_error == 60488fe96085Stim szeto STMF_IOCERR_PPD_UPDATED) { 60498fe96085Stim szeto ret = STMF_ERROR_PROV_DATA_STALE; 60508fe96085Stim szeto } else { 60518fe96085Stim szeto ret = STMF_STATUS_ERROR; 60528fe96085Stim szeto } 60538fe96085Stim szeto break; 6054fcf3ce44SJohn Forte default: 6055fcf3ce44SJohn Forte syslog(LOG_DEBUG, 6056fcf3ce44SJohn Forte "setProviderData:ioctl errno(%d)", errno); 6057fcf3ce44SJohn Forte ret = STMF_STATUS_ERROR; 6058fcf3ce44SJohn Forte break; 6059fcf3ce44SJohn Forte } 6060fcf3ce44SJohn Forte if (ret != STMF_STATUS_SUCCESS) 6061fcf3ce44SJohn Forte goto done; 6062fcf3ce44SJohn Forte } 6063fcf3ce44SJohn Forte 60648fe96085Stim szeto /* caller has asked for new token */ 60658fe96085Stim szeto if (setToken) { 60668fe96085Stim szeto *setToken = outToken; 60678fe96085Stim szeto } 6068fcf3ce44SJohn Forte done: 6069fcf3ce44SJohn Forte free(ppi); 6070fcf3ce44SJohn Forte return (ret); 6071fcf3ce44SJohn Forte } 60728fe96085Stim szeto 60738fe96085Stim szeto /* 60748fe96085Stim szeto * set the persistence method in the library only or library and service 60758fe96085Stim szeto */ 60768fe96085Stim szeto int 60778fe96085Stim szeto stmfSetPersistMethod(uint8_t persistType, boolean_t serviceSet) 60788fe96085Stim szeto { 60798fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 60808fe96085Stim szeto int oldPersist; 60818fe96085Stim szeto 60828fe96085Stim szeto (void) pthread_mutex_lock(&persistenceTypeLock); 60838fe96085Stim szeto oldPersist = iPersistType; 60848fe96085Stim szeto if (persistType == STMF_PERSIST_NONE || 60858fe96085Stim szeto persistType == STMF_PERSIST_SMF) { 60868fe96085Stim szeto iLibSetPersist = B_TRUE; 60878fe96085Stim szeto iPersistType = persistType; 60888fe96085Stim szeto } else { 60898fe96085Stim szeto (void) pthread_mutex_unlock(&persistenceTypeLock); 60908fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 60918fe96085Stim szeto } 60928fe96085Stim szeto /* Is this for this library open or in SMF */ 60938fe96085Stim szeto if (serviceSet == B_TRUE) { 60948fe96085Stim szeto ret = psSetServicePersist(persistType); 60958fe96085Stim szeto if (ret != STMF_PS_SUCCESS) { 60968fe96085Stim szeto ret = STMF_ERROR_PERSIST_TYPE; 60978fe96085Stim szeto /* Set to old value */ 60988fe96085Stim szeto iPersistType = oldPersist; 60998fe96085Stim szeto } 61008fe96085Stim szeto } 61018fe96085Stim szeto (void) pthread_mutex_unlock(&persistenceTypeLock); 61028fe96085Stim szeto 61038fe96085Stim szeto return (ret); 61048fe96085Stim szeto } 61058fe96085Stim szeto 61068fe96085Stim szeto /* 61078fe96085Stim szeto * Only returns internal state for persist. If unset, goes to ps. If that 61088fe96085Stim szeto * fails, returns default setting 61098fe96085Stim szeto */ 61108fe96085Stim szeto static uint8_t 61118fe96085Stim szeto iGetPersistMethod() 61128fe96085Stim szeto { 61138fe96085Stim szeto 61148fe96085Stim szeto uint8_t persistType = 0; 61158fe96085Stim szeto 61168fe96085Stim szeto (void) pthread_mutex_lock(&persistenceTypeLock); 61178fe96085Stim szeto if (iLibSetPersist) { 61188fe96085Stim szeto persistType = iPersistType; 61198fe96085Stim szeto } else { 61208fe96085Stim szeto int ret; 61218fe96085Stim szeto ret = psGetServicePersist(&persistType); 61228fe96085Stim szeto if (ret != STMF_PS_SUCCESS) { 61238fe96085Stim szeto /* set to default */ 61248fe96085Stim szeto persistType = STMF_DEFAULT_PERSIST; 61258fe96085Stim szeto } 61268fe96085Stim szeto } 61278fe96085Stim szeto (void) pthread_mutex_unlock(&persistenceTypeLock); 61288fe96085Stim szeto return (persistType); 61298fe96085Stim szeto } 61308fe96085Stim szeto 61318fe96085Stim szeto /* 61328fe96085Stim szeto * Returns either library state or persistent config state depending on 61338fe96085Stim szeto * serviceState 61348fe96085Stim szeto */ 61358fe96085Stim szeto int 61368fe96085Stim szeto stmfGetPersistMethod(uint8_t *persistType, boolean_t serviceState) 61378fe96085Stim szeto { 61388fe96085Stim szeto int ret = STMF_STATUS_SUCCESS; 61398fe96085Stim szeto 61408fe96085Stim szeto if (persistType == NULL) { 61418fe96085Stim szeto return (STMF_ERROR_INVALID_ARG); 61428fe96085Stim szeto } 61438fe96085Stim szeto if (serviceState) { 61448fe96085Stim szeto ret = psGetServicePersist(persistType); 61458fe96085Stim szeto if (ret != STMF_PS_SUCCESS) { 61468fe96085Stim szeto ret = STMF_ERROR_PERSIST_TYPE; 61478fe96085Stim szeto } 61488fe96085Stim szeto } else { 61498fe96085Stim szeto (void) pthread_mutex_lock(&persistenceTypeLock); 61508fe96085Stim szeto if (iLibSetPersist) { 61518fe96085Stim szeto *persistType = iPersistType; 61528fe96085Stim szeto } else { 61538fe96085Stim szeto *persistType = STMF_DEFAULT_PERSIST; 61548fe96085Stim szeto } 61558fe96085Stim szeto (void) pthread_mutex_unlock(&persistenceTypeLock); 61568fe96085Stim szeto } 61578fe96085Stim szeto 61588fe96085Stim szeto return (ret); 61598fe96085Stim szeto } 616063ed874aStim szeto 616163ed874aStim szeto /* 6162*45039663SJohn Forte * stmfPostProxyMsg 6163*45039663SJohn Forte * 6164*45039663SJohn Forte * Purpose: Post a message to the proxy port provider 6165*45039663SJohn Forte * 6166*45039663SJohn Forte * buf - buffer containing message to post 6167*45039663SJohn Forte * buflen - buffer length 6168*45039663SJohn Forte */ 6169*45039663SJohn Forte int 6170*45039663SJohn Forte stmfPostProxyMsg(int hdl, void *buf, uint32_t buflen) 6171*45039663SJohn Forte { 6172*45039663SJohn Forte int ret = STMF_STATUS_SUCCESS; 6173*45039663SJohn Forte int ioctlRet; 6174*45039663SJohn Forte pppt_iocdata_t ppptIoctl = {0}; 6175*45039663SJohn Forte 6176*45039663SJohn Forte if (buf == NULL) { 6177*45039663SJohn Forte return (STMF_ERROR_INVALID_ARG); 6178*45039663SJohn Forte } 6179*45039663SJohn Forte 6180*45039663SJohn Forte /* 6181*45039663SJohn Forte * Issue ioctl to post the message 6182*45039663SJohn Forte */ 6183*45039663SJohn Forte ppptIoctl.pppt_version = PPPT_VERSION_1; 6184*45039663SJohn Forte ppptIoctl.pppt_buf_size = buflen; 6185*45039663SJohn Forte ppptIoctl.pppt_buf = (uint64_t)(unsigned long)buf; 6186*45039663SJohn Forte ioctlRet = ioctl(hdl, PPPT_MESSAGE, &ppptIoctl); 6187*45039663SJohn Forte if (ioctlRet != 0) { 6188*45039663SJohn Forte switch (errno) { 6189*45039663SJohn Forte case EPERM: 6190*45039663SJohn Forte case EACCES: 6191*45039663SJohn Forte ret = STMF_ERROR_PERM; 6192*45039663SJohn Forte break; 6193*45039663SJohn Forte default: 6194*45039663SJohn Forte ret = STMF_ERROR_POST_MSG_FAILED; 6195*45039663SJohn Forte break; 6196*45039663SJohn Forte } 6197*45039663SJohn Forte } 6198*45039663SJohn Forte 6199*45039663SJohn Forte return (ret); 6200*45039663SJohn Forte } 6201*45039663SJohn Forte 6202*45039663SJohn Forte /* 6203*45039663SJohn Forte * stmfInitProxyDoor 6204*45039663SJohn Forte * 6205*45039663SJohn Forte * Purpose: Install door in proxy 6206*45039663SJohn Forte * 6207*45039663SJohn Forte * hdl - pointer to returned handle 6208*45039663SJohn Forte * fd - door from door_create() 6209*45039663SJohn Forte */ 6210*45039663SJohn Forte int 6211*45039663SJohn Forte stmfInitProxyDoor(int *hdl, int door) 6212*45039663SJohn Forte { 6213*45039663SJohn Forte int ret = STMF_STATUS_SUCCESS; 6214*45039663SJohn Forte int ioctlRet; 6215*45039663SJohn Forte int fd; 6216*45039663SJohn Forte pppt_iocdata_t ppptIoctl = {0}; 6217*45039663SJohn Forte 6218*45039663SJohn Forte if (hdl == NULL) { 6219*45039663SJohn Forte return (STMF_ERROR_INVALID_ARG); 6220*45039663SJohn Forte } 6221*45039663SJohn Forte 6222*45039663SJohn Forte /* 6223*45039663SJohn Forte * Open control node for pppt 6224*45039663SJohn Forte */ 6225*45039663SJohn Forte if ((ret = openPppt(OPEN_PPPT, &fd)) != STMF_STATUS_SUCCESS) { 6226*45039663SJohn Forte return (ret); 6227*45039663SJohn Forte } 6228*45039663SJohn Forte 6229*45039663SJohn Forte /* 6230*45039663SJohn Forte * Issue ioctl to install the door 6231*45039663SJohn Forte */ 6232*45039663SJohn Forte ppptIoctl.pppt_version = PPPT_VERSION_1; 6233*45039663SJohn Forte ppptIoctl.pppt_door_fd = (uint32_t)door; 6234*45039663SJohn Forte ioctlRet = ioctl(fd, PPPT_INSTALL_DOOR, &ppptIoctl); 6235*45039663SJohn Forte if (ioctlRet != 0) { 6236*45039663SJohn Forte switch (errno) { 6237*45039663SJohn Forte case EPERM: 6238*45039663SJohn Forte case EACCES: 6239*45039663SJohn Forte ret = STMF_ERROR_PERM; 6240*45039663SJohn Forte break; 6241*45039663SJohn Forte case EINVAL: 6242*45039663SJohn Forte ret = STMF_ERROR_INVALID_ARG; 6243*45039663SJohn Forte break; 6244*45039663SJohn Forte case EBUSY: 6245*45039663SJohn Forte ret = STMF_ERROR_DOOR_INSTALLED; 6246*45039663SJohn Forte break; 6247*45039663SJohn Forte default: 6248*45039663SJohn Forte ret = STMF_STATUS_ERROR; 6249*45039663SJohn Forte break; 6250*45039663SJohn Forte } 6251*45039663SJohn Forte } 6252*45039663SJohn Forte 6253*45039663SJohn Forte /* return driver fd to caller */ 6254*45039663SJohn Forte *hdl = fd; 6255*45039663SJohn Forte return (ret); 6256*45039663SJohn Forte } 6257*45039663SJohn Forte 6258*45039663SJohn Forte void 6259*45039663SJohn Forte stmfDestroyProxyDoor(int hdl) 6260*45039663SJohn Forte { 6261*45039663SJohn Forte (void) close(hdl); 6262*45039663SJohn Forte } 6263*45039663SJohn Forte 6264*45039663SJohn Forte /* 626563ed874aStim szeto * validateLunNumIoctl 626663ed874aStim szeto * 626763ed874aStim szeto * Purpose: Issues ioctl to check and get available lun# in view entry 626863ed874aStim szeto * 626963ed874aStim szeto * viewEntry - view entry to use 627063ed874aStim szeto */ 627163ed874aStim szeto static int 627263ed874aStim szeto validateLunNumIoctl(int fd, stmfViewEntry *viewEntry) 627363ed874aStim szeto { 627463ed874aStim szeto int ret = STMF_STATUS_SUCCESS; 627563ed874aStim szeto int ioctlRet; 627663ed874aStim szeto stmf_iocdata_t stmfIoctl; 627763ed874aStim szeto stmf_view_op_entry_t ioctlViewEntry; 627863ed874aStim szeto 627963ed874aStim szeto bzero(&ioctlViewEntry, sizeof (ioctlViewEntry)); 628063ed874aStim szeto /* 628163ed874aStim szeto * don't set ve_ndx or ve_ndx_valid as ve_ndx_valid should be 628263ed874aStim szeto * false on input 628363ed874aStim szeto */ 628463ed874aStim szeto ioctlViewEntry.ve_lu_number_valid = viewEntry->luNbrValid; 628563ed874aStim szeto ioctlViewEntry.ve_all_hosts = viewEntry->allHosts; 628663ed874aStim szeto ioctlViewEntry.ve_all_targets = viewEntry->allTargets; 628763ed874aStim szeto 628863ed874aStim szeto if (viewEntry->allHosts == B_FALSE) { 628963ed874aStim szeto bcopy(viewEntry->hostGroup, &ioctlViewEntry.ve_host_group.name, 629063ed874aStim szeto sizeof (stmfGroupName)); 629163ed874aStim szeto ioctlViewEntry.ve_host_group.name_size = 629263ed874aStim szeto strlen((char *)viewEntry->hostGroup); 629363ed874aStim szeto } 629463ed874aStim szeto if (viewEntry->allTargets == B_FALSE) { 629563ed874aStim szeto bcopy(viewEntry->targetGroup, 629663ed874aStim szeto &ioctlViewEntry.ve_target_group.name, 629763ed874aStim szeto sizeof (stmfGroupName)); 629863ed874aStim szeto ioctlViewEntry.ve_target_group.name_size = 629963ed874aStim szeto strlen((char *)viewEntry->targetGroup); 630063ed874aStim szeto } 630163ed874aStim szeto /* Validating the lun number */ 630263ed874aStim szeto if (viewEntry->luNbrValid) { 630363ed874aStim szeto bcopy(viewEntry->luNbr, &ioctlViewEntry.ve_lu_nbr, 630463ed874aStim szeto sizeof (ioctlViewEntry.ve_lu_nbr)); 630563ed874aStim szeto } 630663ed874aStim szeto 630763ed874aStim szeto bzero(&stmfIoctl, sizeof (stmfIoctl)); 630863ed874aStim szeto /* 630963ed874aStim szeto * Issue ioctl to validate lun# in the view entry 631063ed874aStim szeto */ 631163ed874aStim szeto stmfIoctl.stmf_version = STMF_VERSION_1; 631263ed874aStim szeto stmfIoctl.stmf_ibuf_size = sizeof (ioctlViewEntry); 631363ed874aStim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ioctlViewEntry; 631463ed874aStim szeto stmfIoctl.stmf_obuf_size = sizeof (ioctlViewEntry); 631563ed874aStim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&ioctlViewEntry; 631663ed874aStim szeto ioctlRet = ioctl(fd, STMF_IOCTL_VALIDATE_VIEW, &stmfIoctl); 631763ed874aStim szeto 631863ed874aStim szeto /* save available lun number */ 631963ed874aStim szeto if (!viewEntry->luNbrValid) { 632063ed874aStim szeto bcopy(ioctlViewEntry.ve_lu_nbr, viewEntry->luNbr, 632163ed874aStim szeto sizeof (ioctlViewEntry.ve_lu_nbr)); 632263ed874aStim szeto } 632363ed874aStim szeto if (ioctlRet != 0) { 632463ed874aStim szeto switch (errno) { 632563ed874aStim szeto case EBUSY: 632663ed874aStim szeto ret = STMF_ERROR_BUSY; 632763ed874aStim szeto break; 632863ed874aStim szeto case EPERM: 632963ed874aStim szeto ret = STMF_ERROR_PERM; 633063ed874aStim szeto break; 633163ed874aStim szeto case EACCES: 633263ed874aStim szeto switch (stmfIoctl.stmf_error) { 633363ed874aStim szeto case STMF_IOCERR_UPDATE_NEED_CFG_INIT: 633463ed874aStim szeto ret = STMF_ERROR_CONFIG_NONE; 633563ed874aStim szeto break; 633663ed874aStim szeto default: 633763ed874aStim szeto ret = STMF_ERROR_PERM; 633863ed874aStim szeto break; 633963ed874aStim szeto } 634063ed874aStim szeto break; 634163ed874aStim szeto default: 634263ed874aStim szeto switch (stmfIoctl.stmf_error) { 634363ed874aStim szeto case STMF_IOCERR_LU_NUMBER_IN_USE: 634463ed874aStim szeto ret = STMF_ERROR_LUN_IN_USE; 634563ed874aStim szeto break; 634663ed874aStim szeto case STMF_IOCERR_VIEW_ENTRY_CONFLICT: 634763ed874aStim szeto ret = STMF_ERROR_VE_CONFLICT; 634863ed874aStim szeto break; 634963ed874aStim szeto case STMF_IOCERR_UPDATE_NEED_CFG_INIT: 635063ed874aStim szeto ret = STMF_ERROR_CONFIG_NONE; 635163ed874aStim szeto break; 635263ed874aStim szeto case STMF_IOCERR_INVALID_HG: 635363ed874aStim szeto ret = STMF_ERROR_INVALID_HG; 635463ed874aStim szeto break; 635563ed874aStim szeto case STMF_IOCERR_INVALID_TG: 635663ed874aStim szeto ret = STMF_ERROR_INVALID_TG; 635763ed874aStim szeto break; 635863ed874aStim szeto default: 635963ed874aStim szeto syslog(LOG_DEBUG, 636063ed874aStim szeto "addViewEntryIoctl" 636163ed874aStim szeto ":error(%d)", 636263ed874aStim szeto stmfIoctl.stmf_error); 636363ed874aStim szeto ret = STMF_STATUS_ERROR; 636463ed874aStim szeto break; 636563ed874aStim szeto } 636663ed874aStim szeto break; 636763ed874aStim szeto } 636863ed874aStim szeto } 636963ed874aStim szeto return (ret); 637063ed874aStim szeto } 637163ed874aStim szeto 637263ed874aStim szeto /* 637363ed874aStim szeto * stmfValidateView 637463ed874aStim szeto * 637563ed874aStim szeto * Purpose: Validate or get lun # base on TG, HG of view entry 637663ed874aStim szeto * 637763ed874aStim szeto * viewEntry - view entry structure to use 637863ed874aStim szeto */ 637963ed874aStim szeto int 638063ed874aStim szeto stmfValidateView(stmfViewEntry *viewEntry) 638163ed874aStim szeto { 638263ed874aStim szeto int ret; 638363ed874aStim szeto int fd; 638463ed874aStim szeto stmfViewEntry iViewEntry; 638563ed874aStim szeto 638663ed874aStim szeto if (viewEntry == NULL) { 638763ed874aStim szeto return (STMF_ERROR_INVALID_ARG); 638863ed874aStim szeto } 638963ed874aStim szeto 639063ed874aStim szeto /* initialize and set internal view entry */ 639163ed874aStim szeto bzero(&iViewEntry, sizeof (iViewEntry)); 639263ed874aStim szeto 639363ed874aStim szeto if (!viewEntry->allHosts) { 639463ed874aStim szeto bcopy(viewEntry->hostGroup, iViewEntry.hostGroup, 639563ed874aStim szeto sizeof (iViewEntry.hostGroup)); 639663ed874aStim szeto } else { 639763ed874aStim szeto iViewEntry.allHosts = B_TRUE; 639863ed874aStim szeto } 639963ed874aStim szeto 640063ed874aStim szeto if (!viewEntry->allTargets) { 640163ed874aStim szeto bcopy(viewEntry->targetGroup, iViewEntry.targetGroup, 640263ed874aStim szeto sizeof (iViewEntry.targetGroup)); 640363ed874aStim szeto } else { 640463ed874aStim szeto iViewEntry.allTargets = B_TRUE; 640563ed874aStim szeto } 640663ed874aStim szeto 640763ed874aStim szeto if (viewEntry->luNbrValid) { 640863ed874aStim szeto iViewEntry.luNbrValid = B_TRUE; 640963ed874aStim szeto bcopy(viewEntry->luNbr, iViewEntry.luNbr, 641063ed874aStim szeto sizeof (iViewEntry.luNbr)); 641163ed874aStim szeto } 641263ed874aStim szeto 641363ed874aStim szeto /* 641463ed874aStim szeto * set users return view entry index valid flag to false 641563ed874aStim szeto * in case of failure 641663ed874aStim szeto */ 641763ed874aStim szeto viewEntry->veIndexValid = B_FALSE; 641863ed874aStim szeto 641963ed874aStim szeto /* Check to ensure service exists */ 642063ed874aStim szeto if (psCheckService() != STMF_STATUS_SUCCESS) { 642163ed874aStim szeto return (STMF_ERROR_SERVICE_NOT_FOUND); 642263ed874aStim szeto } 642363ed874aStim szeto 642463ed874aStim szeto /* call init */ 642563ed874aStim szeto ret = initializeConfig(); 642663ed874aStim szeto if (ret != STMF_STATUS_SUCCESS) { 642763ed874aStim szeto return (ret); 642863ed874aStim szeto } 642963ed874aStim szeto 643063ed874aStim szeto /* 643163ed874aStim szeto * Open control node for stmf 643263ed874aStim szeto */ 643363ed874aStim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS) 643463ed874aStim szeto return (ret); 643563ed874aStim szeto 643663ed874aStim szeto /* 643763ed874aStim szeto * Validate lun# in the view entry from the driver 643863ed874aStim szeto */ 643963ed874aStim szeto ret = validateLunNumIoctl(fd, &iViewEntry); 644063ed874aStim szeto (void) close(fd); 644163ed874aStim szeto 644263ed874aStim szeto /* save available lun number */ 644363ed874aStim szeto if (!viewEntry->luNbrValid) { 644463ed874aStim szeto bcopy(iViewEntry.luNbr, viewEntry->luNbr, 644563ed874aStim szeto sizeof (iViewEntry.luNbr)); 644663ed874aStim szeto } 644763ed874aStim szeto 644863ed874aStim szeto return (ret); 644963ed874aStim szeto } 6450