fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
33f5ff17089e3a43e6e730bf80384c233123dbd9Milan Jurik * Copyright 2012 Milan Jurik. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <wchar.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libintl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <assert.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libnvpair.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <pthread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <syslog.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <libstmf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/in.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <inttypes.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <store.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#include <math.h>
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#include <libstmf_impl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stmf_ioctl.h>
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#include <sys/stmf_sbd_ioctl.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/pppt_ioctl.h>
7beff157537d14493d525a42d33f0621b0b26217John Forte#include <macros.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STMF_PATH "/devices/pseudo/stmf@0:admin"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define SBD_PATH "/devices/pseudo/stmf_sbd@0:admin"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define PPPT_PATH "/devices/pseudo/pppt@0:pppt"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define EUI "eui."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WWN "wwn."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IQN "iqn."
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define LU_ASCII_GUID_SIZE 32
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define LU_GUID_SIZE 16
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define OUI_ASCII_SIZE 6
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte#define HOST_ID_ASCII_SIZE 8
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define OUI_SIZE 3
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte#define HOST_ID_SIZE 4
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IDENT_LENGTH_BYTE 3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/* various initial allocation values */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_LU 8192
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_TARGET_PORT 2048
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_PROVIDER 64
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_GROUP 2048
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_SESSION 2048
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_VE 256
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_PP_DATA_SIZE 128*1024
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define ALLOC_GRP_MEMBER 256
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_ISCSI_NAME 223
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define MAX_SERIAL_SIZE 252 + 1
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define MAX_LU_ALIAS_SIZE 256
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define MAX_SBD_PROPS MAXPATHLEN + MAX_SERIAL_SIZE + MAX_LU_ALIAS_SIZE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define OPEN_STMF 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define OPEN_EXCL_STMF O_EXCL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define OPEN_SBD 0
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define OPEN_EXCL_SBD O_EXCL
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define OPEN_PPPT 0
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define OPEN_EXCL_PPPT O_EXCL
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LOGICAL_UNIT_TYPE 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define TARGET_TYPE 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STMF_SERVICE_TYPE 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define HOST_GROUP 1
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define TARGET_GROUP 2
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/* set default persistence here */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define STMF_DEFAULT_PERSIST STMF_PERSIST_SMF
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define MAX_PROVIDER_RETRY 30
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int openStmf(int, int *fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int openSbd(int, int *fd);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int openPppt(int, int *fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int groupIoctl(int fd, int cmd, stmfGroupName *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int loadStore(int fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int groupMemberIoctl(int fd, int cmd, stmfGroupName *, stmfDevid *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int guidCompare(const void *, const void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int addViewEntryIoctl(int fd, stmfGuid *, stmfViewEntry *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int loadHostGroups(int fd, stmfGroupList *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int loadTargetGroups(int fd, stmfGroupList *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int getStmfState(stmf_state_desc_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int setStmfState(int fd, stmf_state_desc_t *, int);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int setProviderData(int fd, char *, nvlist_t *, int, uint64_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int createDiskResource(luResourceImpl *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int createDiskLu(diskResource *, stmfGuid *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int deleteDiskLu(stmfGuid *luGuid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int getDiskProp(luResourceImpl *, uint32_t, char *, size_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int getDiskAllProps(stmfGuid *luGuid, luResource *hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int loadDiskPropsFromDriver(luResourceImpl *, sbd_lu_props_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int removeGuidFromDiskStore(stmfGuid *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int addGuidToDiskStore(stmfGuid *, char *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int persistDiskGuid(stmfGuid *, char *, boolean_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int setDiskProp(luResourceImpl *, uint32_t, const char *);
7beff157537d14493d525a42d33f0621b0b26217John Fortestatic int getDiskGlobalProp(uint32_t prop, char *propVal, size_t *propLen);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int checkHexUpper(char *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int strToShift(const char *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int niceStrToNum(const char *, uint64_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic void diskError(uint32_t, int *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int importDiskLu(char *fname, stmfGuid *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int modifyDiskLu(diskResource *, stmfGuid *, const char *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int modifyDiskLuProp(stmfGuid *, const char *, uint32_t, const char *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int validateModifyDiskProp(uint32_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic uint8_t iGetPersistMethod();
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int groupListIoctl(stmfGroupList **, int);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int iLoadGroupFromPs(stmfGroupList **, int);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int groupMemberListIoctl(stmfGroupName *, stmfGroupProperties **, int);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int getProviderData(char *, nvlist_t **, int, uint64_t *);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int setDiskStandby(stmfGuid *luGuid);
7beff157537d14493d525a42d33f0621b0b26217John Fortestatic int setDiskGlobalProp(uint32_t, const char *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int viewEntryCompare(const void *, const void *);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void deleteNonActiveLus();
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallistatic int loadStmfProp(int fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic pthread_mutex_t persistenceTypeLock = PTHREAD_MUTEX_INITIALIZER;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int iPersistType = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/* when B_TRUE, no need to access SMF anymore. Just use iPersistType */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic boolean_t iLibSetPersist = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open for stmf module
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - open flag (OPEN_STMF, OPEN_EXCL_STMF)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fd - pointer to integer. On success, contains the stmf file descriptor
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteopenStmf(int flag, int *fd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*fd = open(STMF_PATH, O_NDELAY | O_RDONLY | flag)) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno == EBUSY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (errno == EACCES) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG, "openStmf:open failure:%s:errno(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_PATH, errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open for sbd module
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * flag - open flag (OPEN_SBD, OPEN_EXCL_SBD)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * fd - pointer to integer. On success, contains the stmf file descriptor
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoopenSbd(int flag, int *fd)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((*fd = open(SBD_PATH, O_NDELAY | O_RDONLY | flag)) != -1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (errno == EBUSY) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (errno == EACCES) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG, "openSbd:open failure:%s:errno(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto SBD_PATH, errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Open for pppt module
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * flag - open flag (OPEN_PPPT, OPEN_EXCL_PPPT)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * fd - pointer to integer. On success, contains the stmf file descriptor
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn ForteopenPppt(int flag, int *fd)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = STMF_STATUS_ERROR;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((*fd = open(PPPT_PATH, O_RDONLY | flag)) != -1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_STATUS_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (errno == EBUSY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_BUSY;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (errno == EACCES) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_PERM;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_STATUS_ERROR;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DEBUG, "openPppt:open failure:%s:errno(%d)",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte PPPT_PATH, errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initializeConfig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine should be called before any ioctl requiring initialization
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which is basically everything except stmfGetState(), setStmfState() and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfLoadConfig().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteinitializeConfig()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfState state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetState(&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if we've already initialized or in the process, return success */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state.configState == STMF_CONFIG_STATE_INIT_DONE ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.configState == STMF_CONFIG_STATE_INIT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfLoadConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "initializeConfig:stmfLoadConfig:error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetState(&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "initializeConfig:stmfGetState:error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state.configState != STMF_CONFIG_STATE_INIT_DONE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG, "initializeConfig:state.configState(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state.configState);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupIoctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: issue ioctl for create/delete on group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmd - valid STMF ioctl group cmd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupName - groupName to create or delete
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortegroupIoctl(int fd, int cmd, stmfGroupName *groupName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_group_name_t iGroupName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&iGroupName, sizeof (iGroupName));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(groupName, &iGroupName.name, strlen((char *)groupName));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iGroupName.name_size = strlen((char *)groupName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to create the host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (iGroupName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&iGroupName;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfIoctl.stmf_error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_TG_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_HG_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_TG_IN_USE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_HG_IN_USE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_GROUP_IN_USE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_HG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_TG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "groupIoctl:error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * groupMemberIoctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: issue ioctl for add/remove member on group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmd - valid STMF ioctl group member cmd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupName - groupName to add to or remove from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid - group member to add or remove
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortegroupMemberIoctl(int fd, int cmd, stmfGroupName *groupName, stmfDevid *devid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_group_op_data_t stmfGroupData;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfGroupData, sizeof (stmfGroupData));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(groupName, &stmfGroupData.group.name, strlen((char *)groupName));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGroupData.group.name_size = strlen((char *)groupName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGroupData.ident[IDENT_LENGTH_BYTE] = devid->identLength;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(devid->ident), &stmfGroupData.ident[IDENT_LENGTH_BYTE + 1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to add to the host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmfGroupData);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&stmfGroupData;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto switch (stmfIoctl.stmf_error) {
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto case STMF_IOCERR_TG_NEED_TG_OFFLINE:
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto ret = STMF_ERROR_TG_ONLINE;
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto break;
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto default:
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto ret = STMF_ERROR_BUSY;
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto break;
5c8cac22647b12e79982cf052e5df46dc7402bd5tim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfIoctl.stmf_error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_TG_ENTRY_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_HG_ENTRY_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_TG_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_HG_ENTRY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ERROR_MEMBER_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_TG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_HG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ERROR_GROUP_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "groupMemberIoctl:error"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * qsort function
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * sort on veIndex
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoviewEntryCompare(const void *p1, const void *p2)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfViewEntry *v1 = (stmfViewEntry *)p1, *v2 = (stmfViewEntry *)p2;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (v1->veIndex > v2->veIndex)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (v1->veIndex < v2->veIndex)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * guidCompare
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * qsort function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sort on guid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteguidCompare(const void *p1, const void *p2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGuid *g1 = (stmfGuid *)p1, *g2 = (stmfGuid *)p2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sizeof (stmfGuid); i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g1->guid[i] > g2->guid[i])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (g1->guid[i] < g2->guid[i])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfAddToHostGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Adds an initiator to an existing host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hostGroupName - name of an existing host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hostName - name of initiator to add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfAddToHostGroup(stmfGroupName *hostGroupName, stmfDevid *hostName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hostGroupName == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strnlen((char *)hostGroupName, sizeof (stmfGroupName))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == sizeof (stmfGroupName)) || hostName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_HG_ENTRY, hostGroupName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hostName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psAddHostGroupMember((char *)hostGroupName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)hostName->ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfAddToHostGroup:psAddHostGroupMember:error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfAddToTargetGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Adds a local port to an existing target group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetGroupName - name of an existing target group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetName - name of target to add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfAddToTargetGroup(stmfGroupName *targetGroupName, stmfDevid *targetName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (targetGroupName == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strnlen((char *)targetGroupName, sizeof (stmfGroupName))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == sizeof (stmfGroupName)) || targetName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_TG_ENTRY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetGroupName, targetName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psAddTargetGroupMember((char *)targetGroupName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)targetName->ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfAddToTargetGroup:psAddTargetGroupMember:"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * addViewEntryIoctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Issues ioctl to add a view entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lu - Logical Unit identifier to which the view entry is added
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * viewEntry - view entry to add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * init - When set to B_TRUE, we are in the init state, i.e. don't call open
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteaddViewEntryIoctl(int fd, stmfGuid *lu, stmfViewEntry *viewEntry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_op_entry_t ioctlViewEntry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ioctlViewEntry, sizeof (ioctlViewEntry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * don't set ve_ndx or ve_ndx_valid as ve_ndx_valid should be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * false on input
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlViewEntry.ve_lu_number_valid = viewEntry->luNbrValid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlViewEntry.ve_all_hosts = viewEntry->allHosts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlViewEntry.ve_all_targets = viewEntry->allTargets;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (viewEntry->allHosts == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(viewEntry->hostGroup, &ioctlViewEntry.ve_host_group.name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGroupName));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlViewEntry.ve_host_group.name_size =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen((char *)viewEntry->hostGroup);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (viewEntry->allTargets == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(viewEntry->targetGroup,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &ioctlViewEntry.ve_target_group.name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGroupName));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlViewEntry.ve_target_group.name_size =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen((char *)viewEntry->targetGroup);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (viewEntry->luNbrValid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(viewEntry->luNbr, &ioctlViewEntry.ve_lu_nbr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (ioctlViewEntry.ve_lu_nbr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(lu, &ioctlViewEntry.ve_guid, sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to add to the view entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (ioctlViewEntry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ioctlViewEntry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = sizeof (ioctlViewEntry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&ioctlViewEntry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_ADD_VIEW_ENTRY, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfIoctl.stmf_error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_UPDATE_NEED_CFG_INIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_CONFIG_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfIoctl.stmf_error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_LU_NUMBER_IN_USE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_LUN_IN_USE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_VIEW_ENTRY_CONFLICT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_VE_CONFLICT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_UPDATE_NEED_CFG_INIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_CONFIG_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_HG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_INVALID_HG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_INVALID_TG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_INVALID_TG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "addViewEntryIoctl"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ":error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_error);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy lu nbr back to caller's view entry on success */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte viewEntry->veIndex = ioctlViewEntry.ve_ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlViewEntry.ve_lu_number_valid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&ioctlViewEntry.ve_lu_nbr, viewEntry->luNbr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (ioctlViewEntry.ve_lu_nbr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte viewEntry->luNbrValid = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfAddViewEntry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Adds a view entry to a logical unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lu - guid of the logical unit to which the view entry is added
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * viewEntry - view entry structure to add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfAddViewEntry(stmfGuid *lu, stmfViewEntry *viewEntry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfViewEntry iViewEntry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu == NULL || viewEntry == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize and set internal view entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&iViewEntry, sizeof (iViewEntry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!viewEntry->allHosts) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(viewEntry->hostGroup, iViewEntry.hostGroup,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iViewEntry.hostGroup));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iViewEntry.allHosts = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!viewEntry->allTargets) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(viewEntry->targetGroup, iViewEntry.targetGroup,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iViewEntry.targetGroup));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iViewEntry.allTargets = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (viewEntry->luNbrValid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iViewEntry.luNbrValid = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(viewEntry->luNbr, iViewEntry.luNbr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iViewEntry.luNbr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set users return view entry index valid flag to false
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in case of failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte viewEntry->veIndexValid = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to ensure service exists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First add the view entry to the driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = addViewEntryIoctl(fd, lu, &iViewEntry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the add to driver was successful, add it to the persistent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psAddViewEntry(lu, &iViewEntry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfAddViewEntry:psAddViewEntry:error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set caller's view entry on success */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte viewEntry->veIndexValid = iViewEntry.veIndexValid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte viewEntry->veIndex = iViewEntry.veIndex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte viewEntry->luNbrValid = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(iViewEntry.luNbr, viewEntry->luNbr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iViewEntry.luNbr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfClearProviderData
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: delete all provider data for specified provider
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerName - name of provider for which data should be deleted
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfClearProviderData(char *providerName, int providerType)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int savedErrno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ppioctl_data_t ppi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (providerName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (providerType != STMF_LU_PROVIDER_TYPE &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte providerType != STMF_PORT_PROVIDER_TYPE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ppi, sizeof (ppi));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(ppi.ppi_name, providerName, sizeof (ppi.ppi_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (providerType) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_LU_PROVIDER_TYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi.ppi_lu_provider = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PORT_PROVIDER_TYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi.ppi_port_provider = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_INVALID_ARG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmf_ppioctl_data_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ppi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_CLEAR_PP_DATA, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte savedErrno = errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (savedErrno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfClearProviderData:ioctl error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (savedErrno != ENOENT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psClearProviderData(providerName, providerType);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfClearProviderData:psClearProviderData"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ":error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfCreateHostGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Create a new initiator group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hostGroupName - name of host group to create
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfCreateHostGroup(stmfGroupName *hostGroupName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hostGroupName == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strnlen((char *)hostGroupName, sizeof (stmfGroupName))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == sizeof (stmfGroupName))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to ensure service exists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_HOST_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hostGroupName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psCreateHostGroup((char *)hostGroupName);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfCreateHostGroup:psCreateHostGroup:error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfCreateLu
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Create a logical unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - handle to logical unit resource created via stmfCreateLuResource
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * luGuid - If non-NULL, on success, contains the guid of the created logical
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfCreateLu(luResource hdl, stmfGuid *luGuid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luResourceImpl *luPropsHdl = hdl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (hdl == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (luPropsHdl->type == STMF_DISK) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = createDiskLu((diskResource *)luPropsHdl->resource,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luGuid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfCreateLuResource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Create resource handle for a logical unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * dType - Type of logical unit resource to create
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Can be: STMF_DISK
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - pointer to luResource
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfCreateLuResource(uint16_t dType, luResource *hdl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (dType != STMF_DISK || hdl == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *hdl = calloc(1, sizeof (luResourceImpl));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*hdl == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = createDiskResource((luResourceImpl *)*hdl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(*hdl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_SUCCESS);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Creates a disk logical unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * disk - pointer to diskResource structure that represents the properties
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * for the disk logical unit to be created.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetocreateDiskLu(diskResource *disk, stmfGuid *createdGuid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int dataFileNameLen = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int metaFileNameLen = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int serialNumLen = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int luAliasLen = 0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan int luMgmtUrlLen = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int sluBufSize = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int bufOffset = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int savedErrno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfGuid guid;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t sbdIoctl = {0};
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_create_and_reg_lu_t *sbdLu = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for sbd
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* data file name must be specified */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luDataFileNameValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dataFileNameLen = strlen(disk->luDataFileName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_MISSING_PROP_VAL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sluBufSize += dataFileNameLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luMetaFileNameValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto metaFileNameLen = strlen(disk->luMetaFileName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sluBufSize += metaFileNameLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto serialNumLen = strlen(disk->serialNum);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sluBufSize += serialNumLen;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luAliasValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luAliasLen = strlen(disk->luAlias);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sluBufSize += luAliasLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (disk->luMgmtUrlValid) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan luMgmtUrlLen = strlen(disk->luMgmtUrl);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sluBufSize += luMgmtUrlLen + 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * 8 is the size of the buffer set aside for
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * concatenation of variable length fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu = (sbd_create_and_reg_lu_t *)calloc(1,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (sbd_create_and_reg_lu_t) + sluBufSize - 8);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdLu == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_struct_size = sizeof (sbd_create_and_reg_lu_t) +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sluBufSize - 8;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (metaFileNameLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_meta_fname_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_meta_fname_off = bufOffset;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->luMetaFileName, &(sbdLu->slu_buf[bufOffset]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto metaFileNameLen + 1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bufOffset += metaFileNameLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->luDataFileName, &(sbdLu->slu_buf[bufOffset]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dataFileNameLen + 1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_data_fname_off = bufOffset;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bufOffset += dataFileNameLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* currently, serial # is not passed null terminated to the driver */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->serialNumValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_serial_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_serial_off = bufOffset;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_serial_size = serialNumLen;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->serialNum, &(sbdLu->slu_buf[bufOffset]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto serialNumLen);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bufOffset += serialNumLen;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luAliasValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_alias_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_alias_off = bufOffset;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->luAlias, &(sbdLu->slu_buf[bufOffset]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luAliasLen + 1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bufOffset += luAliasLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (disk->luMgmtUrlValid) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sbdLu->slu_mgmt_url_valid = 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sbdLu->slu_mgmt_url_off = bufOffset;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bcopy(disk->luMgmtUrl, &(sbdLu->slu_buf[bufOffset]),
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan luMgmtUrlLen + 1);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bufOffset += luMgmtUrlLen + 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luSizeValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_lu_size_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_lu_size = disk->luSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luGuidValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_guid_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->luGuid, sbdLu->slu_guid, sizeof (disk->luGuid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->vidValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_vid_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->vid, sbdLu->slu_vid, sizeof (disk->vid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->pidValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_pid_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->pid, sbdLu->slu_pid, sizeof (disk->pid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->revValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_rev_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->rev, sbdLu->slu_rev, sizeof (disk->rev));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->companyIdValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_company_id_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_company_id = disk->companyId;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte if (disk->hostIdValid) {
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte sbdLu->slu_host_id_valid = 1;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte sbdLu->slu_host_id = disk->hostId;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte }
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->blkSizeValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_blksize_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_blksize = disk->blkSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writeProtectEnableValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writeProtectEnable) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_write_protected = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writebackCacheDisableValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_writeback_cache_disable_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writebackCacheDisable) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->slu_writeback_cache_disable = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf_size = sbdLu->slu_struct_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdLu;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_obuf_size = sbdLu->slu_struct_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdLu;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, SBD_IOCTL_CREATE_AND_REGISTER_LU, &sbdIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto savedErrno = errno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (savedErrno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskError(sbdIoctl.stmf_error, &ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret == STMF_STATUS_ERROR) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "createDiskLu:ioctl "
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "error(%d) (%d) (%d)", ioctlRet,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_error, savedErrno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * on success, copy the resulting guid into the caller's guid if not
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (createdGuid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdLu->slu_guid, createdGuid->guid,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (sbdLu->slu_guid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdLu->slu_guid, guid.guid, sizeof (sbdLu->slu_guid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luMetaFileNameValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = addGuidToDiskStore(&guid, disk->luMetaFileName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = addGuidToDiskStore(&guid, disk->luDataFileName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(sbdLu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfImportLu
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Import a previously created logical unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * dType - Type of logical unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Can be: STMF_DISK
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * luGuid - If non-NULL, on success, contains the guid of the imported logical
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * fname - A file name where the metadata resides
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfImportLu(uint16_t dType, char *fname, stmfGuid *luGuid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (dType == STMF_DISK) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = importDiskLu(fname, luGuid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * importDiskLu
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * filename - filename to import
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * createdGuid - if not NULL, on success contains the imported guid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoimportDiskLu(char *fname, stmfGuid *createdGuid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int savedErrno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int metaFileNameLen;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfGuid iGuid;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int iluBufSize = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_import_lu_t *sbdLu = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t sbdIoctl = {0};
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fname == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for sbd
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto metaFileNameLen = strlen(fname);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iluBufSize += metaFileNameLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * 8 is the size of the buffer set aside for
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * concatenation of variable length fields
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu = (sbd_import_lu_t *)calloc(1,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (sbd_import_lu_t) + iluBufSize - 8);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdLu == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Accept either a data file or meta data file.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * sbd will do the right thing here either way.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * i.e. if it's a data file, it assumes that the
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * meta data is shared with the data.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) strncpy(sbdLu->ilu_meta_fname, fname, metaFileNameLen);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->ilu_struct_size = sizeof (sbd_import_lu_t) + iluBufSize - 8;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf_size = sbdLu->ilu_struct_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdLu;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_obuf_size = sbdLu->ilu_struct_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdLu;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, SBD_IOCTL_IMPORT_LU, &sbdIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli if (createdGuid && sbdIoctl.stmf_error ==
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli SBD_RET_FILE_ALREADY_REGISTERED) {
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli bcopy(sbdLu->ilu_ret_guid, createdGuid->guid,
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli sizeof (sbdLu->ilu_ret_guid));
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli }
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto savedErrno = errno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (savedErrno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskError(sbdIoctl.stmf_error, &ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret == STMF_STATUS_ERROR) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "importDiskLu:ioctl "
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "error(%d) (%d) (%d)", ioctlRet,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_error, savedErrno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
a1837c6df940f4a4992df53cc52935596ced1b89srivijitha dugganapalli
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * on success, copy the resulting guid into the caller's guid if not
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * NULL and add it to the persistent store for sbd
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (createdGuid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdLu->ilu_ret_guid, createdGuid->guid,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (sbdLu->ilu_ret_guid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = addGuidToDiskStore(createdGuid, fname);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdLu->ilu_ret_guid, iGuid.guid,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (sbdLu->ilu_ret_guid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = addGuidToDiskStore(&iGuid, fname);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(sbdLu);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * diskError
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Translate sbd driver error
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic void
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodiskError(uint32_t stmfError, int *ret)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (stmfError) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_META_CREATION_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_ZFS_META_CREATE_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_META_CREATION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_INVALID_BLKSIZE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_INVALID_BLKSIZE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_FILE_ALREADY_REGISTERED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_FILE_IN_USE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_GUID_ALREADY_REGISTERED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_GUID_IN_USE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_META_PATH_NOT_ABSOLUTE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_META_FILE_LOOKUP_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_META_FILE_OPEN_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_META_FILE_GETATTR_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_NO_META:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_META_FILE_NAME;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_DATA_PATH_NOT_ABSOLUTE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_DATA_FILE_LOOKUP_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_DATA_FILE_OPEN_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_DATA_FILE_GETATTR_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_DATA_FILE_NAME;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_FILE_SIZE_ERROR:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_FILE_SIZE_INVALID;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_SIZE_OUT_OF_RANGE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_SIZE_OUT_OF_RANGE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_LU_BUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_LU_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SBD_RET_WRITE_CACHE_SET_FAILED:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_ERROR_WRITE_CACHE_SET;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case SBD_RET_ACCESS_STATE_FAILED:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *ret = STMF_ERROR_ACCESS_STATE_SET;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Creates a logical unit resource of type STMF_DISK.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * No defaults should be set here as all defaults are derived from the
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * driver's default settings.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetocreateDiskResource(luResourceImpl *hdl)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto hdl->type = STMF_DISK;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto hdl->resource = calloc(1, sizeof (diskResource));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (hdl->resource == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_SUCCESS);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfDeleteLu
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Delete a logical unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - handle to logical unit resource created via stmfCreateLuResource
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * luGuid - If non-NULL, on success, contains the guid of the created logical
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfDeleteLu(stmfGuid *luGuid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfLogicalUnitProperties luProps;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (luGuid == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check logical unit provider name to call correct dtype function */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strcmp(luProps.providerName, "sbd") == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = deleteDiskLu(luGuid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOT_FOUND);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodeleteDiskLu(stmfGuid *luGuid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int savedErrno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_delete_lu_t deleteLu = {0};
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t sbdIoctl = {0};
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for sbd
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = removeGuidFromDiskStore(luGuid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(luGuid, deleteLu.dlu_guid, sizeof (deleteLu.dlu_guid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto deleteLu.dlu_by_guid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf_size = sizeof (deleteLu);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)&deleteLu;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, SBD_IOCTL_DELETE_LU, &sbdIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto savedErrno = errno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (savedErrno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case ENOENT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "deleteDiskLu:ioctl error(%d) (%d) (%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet, sbdIoctl.stmf_error, savedErrno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * stmfLuStandby
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose: Sets access state to standby
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * luGuid - guid of registered logical unit
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortestmfLuStandby(stmfGuid *luGuid)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = STMF_STATUS_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfLogicalUnitProperties luProps;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (luGuid == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Check logical unit provider name to call correct dtype function */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps))
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (strcmp(luProps.providerName, "sbd") == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = setDiskStandby(luGuid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_NOT_FOUND);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortesetDiskStandby(stmfGuid *luGuid)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = STMF_STATUS_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_iocdata_t sbdIoctl = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbd_set_lu_standby_t sbdLu = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ioctlRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int savedErrno;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int fd = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Open control node for sbd
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte bcopy(luGuid, &sbdLu.stlu_guid, sizeof (stmfGuid));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbdIoctl.stmf_version = STMF_VERSION_1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbdIoctl.stmf_ibuf_size = sizeof (sbd_set_lu_standby_t);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)&sbdLu;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ioctlRet = ioctl(fd, SBD_IOCTL_SET_LU_STANDBY, &sbdIoctl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ioctlRet != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte savedErrno = errno;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (savedErrno) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EBUSY:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_BUSY;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EPERM:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EACCES:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_PERM;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte diskError(sbdIoctl.stmf_error, &ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ret == STMF_STATUS_ERROR) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DEBUG,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "setDiskStandby:ioctl "
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "error(%d) (%d) (%d)", ioctlRet,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbdIoctl.stmf_error, savedErrno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
5b0f0869cc90cee54c7aaef2233f2743c456a6c3John Forte (void) close(fd);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfModifyLu
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Modify properties of a logical unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * luGuid - guid of registered logical unit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * prop - property to modify
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * propVal - property value to set
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfModifyLu(stmfGuid *luGuid, uint32_t prop, const char *propVal)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfLogicalUnitProperties luProps;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (luGuid == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check logical unit provider name to call correct dtype function */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strcmp(luProps.providerName, "sbd") == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = modifyDiskLuProp(luGuid, NULL, prop, propVal);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOT_FOUND);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfModifyLuByFname
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Modify a device by filename. Device does not need to be registered.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * dType - type of device to modify
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * STMF_DISK
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * fname - filename or meta filename
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * prop - valid property identifier
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * propVal - property value
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfModifyLuByFname(uint16_t dType, const char *fname, uint32_t prop,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto const char *propVal)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fname == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (dType == STMF_DISK) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = modifyDiskLuProp(NULL, fname, prop, propVal);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetomodifyDiskLuProp(stmfGuid *luGuid, const char *fname, uint32_t prop,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto const char *propVal)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luResource hdl = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luResourceImpl *luPropsHdl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = stmfCreateLuResource(STMF_DISK, &hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = validateModifyDiskProp(prop);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) stmfFreeLuResource(hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = stmfSetLuProp(hdl, prop, propVal);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) stmfFreeLuResource(hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luPropsHdl = hdl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = modifyDiskLu((diskResource *)luPropsHdl->resource, luGuid, fname);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) stmfFreeLuResource(hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovalidateModifyDiskProp(uint32_t prop)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (prop) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_ALIAS:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_SIZE:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case STMF_LU_PROP_MGMT_URL:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_WRITE_PROTECT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_WRITE_CACHE_DISABLE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_SUCCESS);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetomodifyDiskLu(diskResource *disk, stmfGuid *luGuid, const char *fname)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int luAliasLen = 0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan int luMgmtUrlLen = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int mluBufSize = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int bufOffset = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int savedErrno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fnameSize = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t sbdIoctl = {0};
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_modify_lu_t *sbdLu = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (luGuid == NULL && fname == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fname) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fnameSize = strlen(fname) + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mluBufSize += fnameSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for sbd
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luAliasValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luAliasLen = strlen(disk->luAlias);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mluBufSize += luAliasLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (disk->luMgmtUrlValid) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan luMgmtUrlLen = strlen(disk->luMgmtUrl);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan mluBufSize += luMgmtUrlLen + 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * 8 is the size of the buffer set aside for
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * concatenation of variable length fields
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu = (sbd_modify_lu_t *)calloc(1,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (sbd_modify_lu_t) + mluBufSize - 8 + fnameSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdLu == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_struct_size = sizeof (sbd_modify_lu_t) +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mluBufSize - 8 + fnameSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luAliasValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_alias_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_alias_off = bufOffset;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(disk->luAlias, &(sbdLu->mlu_buf[bufOffset]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luAliasLen + 1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bufOffset += luAliasLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (disk->luMgmtUrlValid) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sbdLu->mlu_mgmt_url_valid = 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sbdLu->mlu_mgmt_url_off = bufOffset;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bcopy(disk->luMgmtUrl, &(sbdLu->mlu_buf[bufOffset]),
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan luMgmtUrlLen + 1);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bufOffset += luMgmtUrlLen + 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->luSizeValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_lu_size_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_lu_size = disk->luSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writeProtectEnableValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_write_protected_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writeProtectEnable) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_write_protected = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writebackCacheDisableValid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_writeback_cache_disable_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (disk->writebackCacheDisable) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_writeback_cache_disable = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (luGuid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(luGuid, sbdLu->mlu_input_guid, sizeof (stmfGuid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_by_guid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_fname_off = bufOffset;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(fname, &(sbdLu->mlu_buf[bufOffset]), fnameSize + 1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdLu->mlu_by_fname = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf_size = sbdLu->mlu_struct_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdLu;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, SBD_IOCTL_MODIFY_LU, &sbdIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto savedErrno = errno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (savedErrno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskError(sbdIoctl.stmf_error, &ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret == STMF_STATUS_ERROR) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "modifyDiskLu:ioctl "
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "error(%d) (%d) (%d)", ioctlRet,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_error, savedErrno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(sbdLu);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * removeGuidFromDiskStore
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: delete a logical unit from the sbd provider data
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoremoveGuidFromDiskStore(stmfGuid *guid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (persistDiskGuid(guid, NULL, B_FALSE));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * addGuidToDiskStore
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: add a logical unit to the sbd provider data
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoaddGuidToDiskStore(stmfGuid *guid, char *filename)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (persistDiskGuid(guid, filename, B_TRUE));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * persistDiskGuid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Persist or unpersist a guid for the sbd provider data
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetopersistDiskGuid(stmfGuid *guid, char *filename, boolean_t persist)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto char guidAsciiBuf[LU_ASCII_GUID_SIZE + 1] = {0};
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto nvlist_t *nvl = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint64_t setToken;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto boolean_t retryGetProviderData = B_FALSE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto boolean_t newData = B_FALSE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int retryCnt = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int stmfRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* if we're persisting a guid, there must be a filename */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (persist && !filename) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* guid is stored in lowercase ascii hex */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) snprintf(guidAsciiBuf, sizeof (guidAsciiBuf),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "%02x%02x%02x%02x%02x%02x",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto guid->guid[0], guid->guid[1], guid->guid[2], guid->guid[3],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto guid->guid[4], guid->guid[5], guid->guid[6], guid->guid[7],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto guid->guid[8], guid->guid[9], guid->guid[10], guid->guid[11],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto guid->guid[12], guid->guid[13], guid->guid[14], guid->guid[15]);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto do {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto retryGetProviderData = B_FALSE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfRet = stmfGetProviderDataProt("sbd", &nvl,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_LU_PROVIDER_TYPE, &setToken);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfRet != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (persist && stmfRet == STMF_ERROR_NOT_FOUND) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "unpersistGuid:nvlist_alloc(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto newData = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if we're persisting the data, it's
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * an error. Otherwise, just return
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (persist) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = stmfRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (persist) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = nvlist_add_string(nvl, guidAsciiBuf, filename);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = nvlist_remove(nvl, guidAsciiBuf,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto DATA_TYPE_STRING);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret == ENOENT) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (newData) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfRet = stmfSetProviderDataProt("sbd", nvl,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_LU_PROVIDER_TYPE, NULL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfRet = stmfSetProviderDataProt("sbd", nvl,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_LU_PROVIDER_TYPE, &setToken);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfRet != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfRet == STMF_ERROR_BUSY) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* get/set failed, try again */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto retryGetProviderData = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (retryCnt++ > MAX_PROVIDER_RETRY) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = stmfRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (stmfRet ==
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_ERROR_PROV_DATA_STALE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* update failed, try again */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto nvlist_free(nvl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto nvl = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto retryGetProviderData = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (retryCnt++ > MAX_PROVIDER_RETRY) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = stmfRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "unpersistGuid:error(%x)", stmfRet);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = stmfRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "unpersistGuid:error nvlist_add/remove(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } while (retryGetProviderData);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto nvlist_free(nvl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfGetLuProp
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Get current value for a resource property
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - luResource from a previous call to stmfCreateLuResource
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * resourceProp - a valid resource property type
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * propVal - void pointer to a pointer of the value to be retrieved
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfGetLuProp(luResource hdl, uint32_t prop, char *propVal, size_t *propLen)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luResourceImpl *luPropsHdl = hdl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (hdl == NULL || propLen == NULL || propVal == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (luPropsHdl->type == STMF_DISK) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = getDiskProp(luPropsHdl, prop, propVal, propLen);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfGetLuResource
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Get a logical unit resource handle for a given logical unit.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - pointer to luResource
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfGetLuResource(stmfGuid *luGuid, luResource *hdl)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfLogicalUnitProperties luProps;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
7b506e25917c371db526f76d85b9b1d17c8c5d39srivijitha dugganapalli if (hdl == NULL) {
7b506e25917c371db526f76d85b9b1d17c8c5d39srivijitha dugganapalli return (STMF_ERROR_INVALID_ARG);
7b506e25917c371db526f76d85b9b1d17c8c5d39srivijitha dugganapalli }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check logical unit provider name to call correct dtype function */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = stmfGetLogicalUnitProperties(luGuid, &luProps))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strcmp(luProps.providerName, "sbd") == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = getDiskAllProps(luGuid, hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (luProps.status == STMF_LOGICAL_UNIT_UNREGISTERED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOT_FOUND);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * getDiskAllProps
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: load all disk properties from sbd driver
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * luGuid - guid of disk device for which properties are to be retrieved
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - allocated luResource into which properties are to be copied
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetogetDiskAllProps(stmfGuid *luGuid, luResource *hdl)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_props_t *sbdProps;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int savedErrno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int sbdPropsSize = sizeof (*sbdProps) + MAX_SBD_PROPS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t sbdIoctl = {0};
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for sbd
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *hdl = calloc(1, sizeof (luResourceImpl));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*hdl == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdProps = calloc(1, sbdPropsSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(*hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = createDiskResource((luResourceImpl *)*hdl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(*hdl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte free(sbdProps);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdProps->slp_input_guid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(luGuid, sbdProps->slp_guid, sizeof (sbdProps->slp_guid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf_size = sbdPropsSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdProps;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_obuf_size = sbdPropsSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdProps;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, SBD_IOCTL_GET_LU_PROPS, &sbdIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto savedErrno = errno;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (savedErrno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case ENOENT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "getDiskAllProps:ioctl error(%d) (%d) (%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet, sbdIoctl.stmf_error, savedErrno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret == STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = loadDiskPropsFromDriver((luResourceImpl *)*hdl, sbdProps);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte free(sbdProps);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * loadDiskPropsFromDriver
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Retrieve all disk type properties from sbd driver
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - Allocated luResourceImpl
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * sbdProps - sbd_lu_props_t structure returned from sbd driver
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoloadDiskPropsFromDriver(luResourceImpl *hdl, sbd_lu_props_t *sbdProps)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskResource *diskLu = hdl->resource;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* copy guid */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuidValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdProps->slp_guid, diskLu->luGuid, sizeof (sbdProps->slp_guid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps->slp_separate_meta && sbdProps->slp_meta_fname_valid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luMetaFileNameValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strlcpy(diskLu->luMetaFileName,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (char *)&(sbdProps->slp_buf[sbdProps->slp_meta_fname_off]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luMetaFileName)) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luMetaFileName)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps->slp_data_fname_valid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luDataFileNameValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strlcpy(diskLu->luDataFileName,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (char *)&(sbdProps->slp_buf[sbdProps->slp_data_fname_off]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luDataFileName)) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luDataFileName)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps->slp_serial_valid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->serialNumValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(&(sbdProps->slp_buf[sbdProps->slp_serial_off]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->serialNum, sbdProps->slp_serial_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (sbdProps->slp_mgmt_url_valid) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan diskLu->luMgmtUrlValid = B_TRUE;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (strlcpy(diskLu->luMgmtUrl,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan (char *)&(sbdProps->slp_buf[sbdProps->slp_mgmt_url_off]),
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sizeof (diskLu->luMgmtUrl)) >=
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sizeof (diskLu->luMgmtUrl)) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan return (STMF_STATUS_ERROR);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps->slp_alias_valid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luAliasValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strlcpy(diskLu->luAlias,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (char *)&(sbdProps->slp_buf[sbdProps->slp_alias_off]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luAlias)) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luAlias)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else { /* set alias to data filename if not set */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps->slp_data_fname_valid) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luAliasValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strlcpy(diskLu->luAlias,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (char *)&(sbdProps->slp_buf[
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbdProps->slp_data_fname_off]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luAlias)) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luAlias)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->vidValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdProps->slp_vid, diskLu->vid, sizeof (diskLu->vid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->pidValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdProps->slp_pid, diskLu->pid, sizeof (diskLu->pid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->revValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbdProps->slp_rev, diskLu->rev, sizeof (diskLu->rev));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writeProtectEnableValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps->slp_write_protected) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writeProtectEnable = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writebackCacheDisableValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbdProps->slp_writeback_cache_disable_cur) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writebackCacheDisable = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->blkSizeValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->blkSize = sbdProps->slp_blksize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luSizeValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luSize = sbdProps->slp_lu_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte diskLu->accessState = sbdProps->slp_access_state;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
7beff157537d14493d525a42d33f0621b0b26217John Forte/*
7beff157537d14493d525a42d33f0621b0b26217John Forte * stmfGetGlobalLuProp
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte * Purpose: get a global property for a device type
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte */
7beff157537d14493d525a42d33f0621b0b26217John Forteint
7beff157537d14493d525a42d33f0621b0b26217John FortestmfGetGlobalLuProp(uint16_t dType, uint32_t prop, char *propVal,
7beff157537d14493d525a42d33f0621b0b26217John Forte size_t *propLen)
7beff157537d14493d525a42d33f0621b0b26217John Forte{
7beff157537d14493d525a42d33f0621b0b26217John Forte int ret = STMF_STATUS_SUCCESS;
7beff157537d14493d525a42d33f0621b0b26217John Forte if (dType != STMF_DISK || propVal == NULL) {
7beff157537d14493d525a42d33f0621b0b26217John Forte return (STMF_ERROR_INVALID_ARG);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = getDiskGlobalProp(prop, propVal, propLen);
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte return (ret);
7beff157537d14493d525a42d33f0621b0b26217John Forte}
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte/*
7beff157537d14493d525a42d33f0621b0b26217John Forte * getDiskGlobalProp
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte * Purpose: get global property from sbd driver
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte */
7beff157537d14493d525a42d33f0621b0b26217John Fortestatic int
7beff157537d14493d525a42d33f0621b0b26217John FortegetDiskGlobalProp(uint32_t prop, char *propVal, size_t *propLen)
7beff157537d14493d525a42d33f0621b0b26217John Forte{
7beff157537d14493d525a42d33f0621b0b26217John Forte int ret = STMF_STATUS_SUCCESS;
7beff157537d14493d525a42d33f0621b0b26217John Forte int fd;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbd_global_props_t *sbdProps;
7beff157537d14493d525a42d33f0621b0b26217John Forte void *sbd_realloc;
7beff157537d14493d525a42d33f0621b0b26217John Forte int retryCnt = 0;
7beff157537d14493d525a42d33f0621b0b26217John Forte boolean_t retry;
7beff157537d14493d525a42d33f0621b0b26217John Forte int ioctlRet;
7beff157537d14493d525a42d33f0621b0b26217John Forte int savedErrno;
7beff157537d14493d525a42d33f0621b0b26217John Forte int sbdPropsSize = sizeof (*sbdProps) + MAX_SBD_PROPS;
7beff157537d14493d525a42d33f0621b0b26217John Forte stmf_iocdata_t sbdIoctl = {0};
7beff157537d14493d525a42d33f0621b0b26217John Forte size_t reqLen;
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte switch (prop) {
7beff157537d14493d525a42d33f0621b0b26217John Forte case STMF_LU_PROP_MGMT_URL:
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte default:
7beff157537d14493d525a42d33f0621b0b26217John Forte return (STMF_ERROR_INVALID_PROP);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte /*
7beff157537d14493d525a42d33f0621b0b26217John Forte * Open control node for sbd
7beff157537d14493d525a42d33f0621b0b26217John Forte */
7beff157537d14493d525a42d33f0621b0b26217John Forte if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
7beff157537d14493d525a42d33f0621b0b26217John Forte return (ret);
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdProps = calloc(1, sbdPropsSize);
7beff157537d14493d525a42d33f0621b0b26217John Forte if (sbdProps == NULL) {
7beff157537d14493d525a42d33f0621b0b26217John Forte (void) close(fd);
7beff157537d14493d525a42d33f0621b0b26217John Forte return (STMF_ERROR_NOMEM);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte do {
7beff157537d14493d525a42d33f0621b0b26217John Forte retry = B_FALSE;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_version = STMF_VERSION_1;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_obuf_size = sbdPropsSize;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdProps;
7beff157537d14493d525a42d33f0621b0b26217John Forte ioctlRet = ioctl(fd, SBD_IOCTL_GET_GLOBAL_LU, &sbdIoctl);
7beff157537d14493d525a42d33f0621b0b26217John Forte if (ioctlRet != 0) {
7beff157537d14493d525a42d33f0621b0b26217John Forte savedErrno = errno;
7beff157537d14493d525a42d33f0621b0b26217John Forte switch (savedErrno) {
7beff157537d14493d525a42d33f0621b0b26217John Forte case EBUSY:
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_BUSY;
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte case EPERM:
7beff157537d14493d525a42d33f0621b0b26217John Forte case EACCES:
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_PERM;
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte case ENOMEM:
7beff157537d14493d525a42d33f0621b0b26217John Forte if (sbdIoctl.stmf_error ==
7beff157537d14493d525a42d33f0621b0b26217John Forte SBD_RET_INSUFFICIENT_BUF_SPACE &&
7beff157537d14493d525a42d33f0621b0b26217John Forte retryCnt++ < 3) {
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdPropsSize =
7beff157537d14493d525a42d33f0621b0b26217John Forte sizeof (*sbdProps) +
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdProps->
7beff157537d14493d525a42d33f0621b0b26217John Forte mlu_buf_size_needed;
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte sbd_realloc = sbdProps;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdProps = realloc(sbdProps,
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdPropsSize);
7beff157537d14493d525a42d33f0621b0b26217John Forte if (sbdProps == NULL) {
7beff157537d14493d525a42d33f0621b0b26217John Forte free(sbd_realloc);
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_NOMEM;
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte retry = B_TRUE;
7beff157537d14493d525a42d33f0621b0b26217John Forte } else {
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_NOMEM;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte default:
7beff157537d14493d525a42d33f0621b0b26217John Forte syslog(LOG_DEBUG,
7beff157537d14493d525a42d33f0621b0b26217John Forte "getDiskGlobalProp:ioctl error(%d)"
7beff157537d14493d525a42d33f0621b0b26217John Forte "(%d)(%d)", ioctlRet,
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_error, savedErrno);
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_STATUS_ERROR;
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte } while (retry);
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte if (ret != STMF_STATUS_SUCCESS) {
7beff157537d14493d525a42d33f0621b0b26217John Forte goto done;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte switch (prop) {
7beff157537d14493d525a42d33f0621b0b26217John Forte case STMF_LU_PROP_MGMT_URL:
7beff157537d14493d525a42d33f0621b0b26217John Forte if (sbdProps->mlu_mgmt_url_valid == 0) {
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_NO_PROP;
7beff157537d14493d525a42d33f0621b0b26217John Forte goto done;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte if ((reqLen = strlcpy(propVal, (char *)&(
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdProps->mlu_buf[sbdProps->mlu_mgmt_url_off]),
7beff157537d14493d525a42d33f0621b0b26217John Forte *propLen)) >= *propLen) {
7beff157537d14493d525a42d33f0621b0b26217John Forte *propLen = reqLen + 1;
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_INVALID_ARG;
7beff157537d14493d525a42d33f0621b0b26217John Forte goto done;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Fortedone:
7beff157537d14493d525a42d33f0621b0b26217John Forte free(sbdProps);
7beff157537d14493d525a42d33f0621b0b26217John Forte (void) close(fd);
7beff157537d14493d525a42d33f0621b0b26217John Forte return (ret);
7beff157537d14493d525a42d33f0621b0b26217John Forte}
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte/*
7beff157537d14493d525a42d33f0621b0b26217John Forte * stmfSetGlobalLuProp
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte * Purpose: set a global property for a device type
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte */
7beff157537d14493d525a42d33f0621b0b26217John Forteint
7beff157537d14493d525a42d33f0621b0b26217John FortestmfSetGlobalLuProp(uint16_t dType, uint32_t prop, const char *propVal)
7beff157537d14493d525a42d33f0621b0b26217John Forte{
7beff157537d14493d525a42d33f0621b0b26217John Forte int ret = STMF_STATUS_SUCCESS;
7beff157537d14493d525a42d33f0621b0b26217John Forte if (dType != STMF_DISK || propVal == NULL) {
7beff157537d14493d525a42d33f0621b0b26217John Forte return (STMF_ERROR_INVALID_ARG);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = setDiskGlobalProp(prop, propVal);
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte return (ret);
7beff157537d14493d525a42d33f0621b0b26217John Forte}
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte/*
7beff157537d14493d525a42d33f0621b0b26217John Forte * setDiskGlobalProp
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte * Purpose: set properties for resource of type disk
7beff157537d14493d525a42d33f0621b0b26217John Forte *
7beff157537d14493d525a42d33f0621b0b26217John Forte * resourceProp - valid resource identifier
7beff157537d14493d525a42d33f0621b0b26217John Forte * propVal - valid resource value
7beff157537d14493d525a42d33f0621b0b26217John Forte */
7beff157537d14493d525a42d33f0621b0b26217John Fortestatic int
7beff157537d14493d525a42d33f0621b0b26217John FortesetDiskGlobalProp(uint32_t resourceProp, const char *propVal)
7beff157537d14493d525a42d33f0621b0b26217John Forte{
7beff157537d14493d525a42d33f0621b0b26217John Forte int ret = STMF_STATUS_SUCCESS;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbd_global_props_t *sbdGlobalProps = NULL;
7beff157537d14493d525a42d33f0621b0b26217John Forte int sbdGlobalPropsSize = 0;
7beff157537d14493d525a42d33f0621b0b26217John Forte int propLen;
7beff157537d14493d525a42d33f0621b0b26217John Forte int mluBufSize = 0;
7beff157537d14493d525a42d33f0621b0b26217John Forte int fd;
7beff157537d14493d525a42d33f0621b0b26217John Forte int savedErrno;
7beff157537d14493d525a42d33f0621b0b26217John Forte int ioctlRet;
7beff157537d14493d525a42d33f0621b0b26217John Forte stmf_iocdata_t sbdIoctl = {0};
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte switch (resourceProp) {
7beff157537d14493d525a42d33f0621b0b26217John Forte case STMF_LU_PROP_MGMT_URL:
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte default:
7beff157537d14493d525a42d33f0621b0b26217John Forte return (STMF_ERROR_INVALID_PROP);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte /*
7beff157537d14493d525a42d33f0621b0b26217John Forte * Open control node for sbd
7beff157537d14493d525a42d33f0621b0b26217John Forte */
7beff157537d14493d525a42d33f0621b0b26217John Forte if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS)
7beff157537d14493d525a42d33f0621b0b26217John Forte return (ret);
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte propLen = strlen(propVal);
7beff157537d14493d525a42d33f0621b0b26217John Forte mluBufSize += propLen + 1;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdGlobalPropsSize += sizeof (sbd_global_props_t) - 8 +
7beff157537d14493d525a42d33f0621b0b26217John Forte max(8, mluBufSize);
7beff157537d14493d525a42d33f0621b0b26217John Forte /*
7beff157537d14493d525a42d33f0621b0b26217John Forte * 8 is the size of the buffer set aside for
7beff157537d14493d525a42d33f0621b0b26217John Forte * concatenation of variable length fields
7beff157537d14493d525a42d33f0621b0b26217John Forte */
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdGlobalProps = (sbd_global_props_t *)calloc(1, sbdGlobalPropsSize);
7beff157537d14493d525a42d33f0621b0b26217John Forte if (sbdGlobalProps == NULL) {
7beff157537d14493d525a42d33f0621b0b26217John Forte (void) close(fd);
7beff157537d14493d525a42d33f0621b0b26217John Forte return (STMF_ERROR_NOMEM);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdGlobalProps->mlu_struct_size = sbdGlobalPropsSize;
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte switch (resourceProp) {
7beff157537d14493d525a42d33f0621b0b26217John Forte case STMF_LU_PROP_MGMT_URL:
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdGlobalProps->mlu_mgmt_url_valid = 1;
7beff157537d14493d525a42d33f0621b0b26217John Forte bcopy(propVal, &(sbdGlobalProps->mlu_buf),
7beff157537d14493d525a42d33f0621b0b26217John Forte propLen + 1);
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte default:
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_NO_PROP;
7beff157537d14493d525a42d33f0621b0b26217John Forte goto done;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_version = STMF_VERSION_1;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_ibuf_size = sbdGlobalProps->mlu_struct_size;
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdGlobalProps;
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Forte ioctlRet = ioctl(fd, SBD_IOCTL_SET_GLOBAL_LU, &sbdIoctl);
7beff157537d14493d525a42d33f0621b0b26217John Forte if (ioctlRet != 0) {
7beff157537d14493d525a42d33f0621b0b26217John Forte savedErrno = errno;
7beff157537d14493d525a42d33f0621b0b26217John Forte switch (savedErrno) {
7beff157537d14493d525a42d33f0621b0b26217John Forte case EBUSY:
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_BUSY;
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte case EPERM:
7beff157537d14493d525a42d33f0621b0b26217John Forte case EACCES:
7beff157537d14493d525a42d33f0621b0b26217John Forte ret = STMF_ERROR_PERM;
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte default:
7beff157537d14493d525a42d33f0621b0b26217John Forte diskError(sbdIoctl.stmf_error, &ret);
7beff157537d14493d525a42d33f0621b0b26217John Forte if (ret == STMF_STATUS_ERROR) {
7beff157537d14493d525a42d33f0621b0b26217John Forte syslog(LOG_DEBUG,
7beff157537d14493d525a42d33f0621b0b26217John Forte "modifyDiskLu:ioctl "
7beff157537d14493d525a42d33f0621b0b26217John Forte "error(%d) (%d) (%d)", ioctlRet,
7beff157537d14493d525a42d33f0621b0b26217John Forte sbdIoctl.stmf_error, savedErrno);
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte break;
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte }
7beff157537d14493d525a42d33f0621b0b26217John Forte
7beff157537d14493d525a42d33f0621b0b26217John Fortedone:
7beff157537d14493d525a42d33f0621b0b26217John Forte free(sbdGlobalProps);
7beff157537d14493d525a42d33f0621b0b26217John Forte (void) close(fd);
7beff157537d14493d525a42d33f0621b0b26217John Forte return (ret);
7beff157537d14493d525a42d33f0621b0b26217John Forte}
7beff157537d14493d525a42d33f0621b0b26217John Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfSetLuProp
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: set a property on an luResource
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - allocated luResource
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * prop - property identifier
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * propVal - property value to be set
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfSetLuProp(luResource hdl, uint32_t prop, const char *propVal)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luResourceImpl *luPropsHdl = hdl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (hdl == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (luPropsHdl->type == STMF_DISK) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = setDiskProp(luPropsHdl, prop, propVal);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * getDiskProp
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: retrieve a given property from a logical unit resource of type disk
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - allocated luResourceImpl
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * prop - property identifier
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * propVal - pointer to character to contain the retrieved property value
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * propLen - On input this is the length of propVal. On failure, it contains the
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * number of bytes required for propVal
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetogetDiskProp(luResourceImpl *hdl, uint32_t prop, char *propVal, size_t *propLen)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskResource *diskLu = hdl->resource;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte char accessState[20];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto size_t reqLen;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (prop == STMF_LU_PROP_ACCESS_STATE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (diskLu->accessState == SBD_LU_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) strlcpy(accessState, STMF_ACCESS_ACTIVE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sizeof (accessState));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (diskLu->accessState == SBD_LU_TRANSITION_TO_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) strlcpy(accessState,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_ACCESS_STANDBY_TO_ACTIVE,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sizeof (accessState));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (diskLu->accessState == SBD_LU_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) strlcpy(accessState, STMF_ACCESS_STANDBY,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sizeof (accessState));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (diskLu->accessState ==
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte SBD_LU_TRANSITION_TO_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) strlcpy(accessState,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_ACCESS_ACTIVE_TO_STANDBY,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sizeof (accessState));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((reqLen = strlcpy(propVal, accessState,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *propLen)) >= *propLen) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *propLen = reqLen + 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (diskLu->accessState != SBD_LU_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_NO_PROP_STANDBY);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (prop) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_BLOCK_SIZE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->blkSizeValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto reqLen = snprintf(propVal, *propLen, "%llu",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (u_longlong_t)diskLu->blkSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (reqLen >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_FILENAME:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->luDataFileNameValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, diskLu->luDataFileName,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_META_FILENAME:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->luMetaFileNameValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, diskLu->luMetaFileName,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case STMF_LU_PROP_MGMT_URL:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (diskLu->luMgmtUrlValid == B_FALSE) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan return (STMF_ERROR_NO_PROP);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if ((reqLen = strlcpy(propVal, diskLu->luMgmtUrl,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan *propLen)) >= *propLen) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan *propLen = reqLen + 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan return (STMF_ERROR_INVALID_ARG);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_GUID:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->luGuidValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto reqLen = snprintf(propVal, *propLen,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "%02X%02X%02X%02X",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[0], diskLu->luGuid[1],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[2], diskLu->luGuid[3],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[4], diskLu->luGuid[5],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[6], diskLu->luGuid[7],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[8], diskLu->luGuid[9],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[10], diskLu->luGuid[11],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[12], diskLu->luGuid[13],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[14], diskLu->luGuid[15]);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (reqLen >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_SERIAL_NUM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->serialNumValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, diskLu->serialNum,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_SIZE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->luSizeValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) snprintf(propVal, *propLen, "%llu",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (u_longlong_t)diskLu->luSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_ALIAS:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->luAliasValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, diskLu->luAlias,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_VID:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->vidValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*propLen <= sizeof (diskLu->vid)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(diskLu->vid, propVal, sizeof (diskLu->vid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto propVal[sizeof (diskLu->vid)] = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_PID:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->pidValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*propLen <= sizeof (diskLu->pid)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(diskLu->pid, propVal, sizeof (diskLu->pid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto propVal[sizeof (diskLu->pid)] = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_WRITE_PROTECT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->writeProtectEnableValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->writeProtectEnable) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, "true",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, "false",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_WRITE_CACHE_DISABLE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->writebackCacheDisableValid == B_FALSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NO_PROP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (diskLu->writebackCacheDisable) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, "true",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((reqLen = strlcpy(propVal, "false",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen)) >= *propLen) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *propLen = reqLen + 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
7b506e25917c371db526f76d85b9b1d17c8c5d39srivijitha dugganapalli ret = STMF_ERROR_INVALID_PROP;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * setDiskProp
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: set properties for resource of type disk
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hdl - allocated luResourceImpl
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * resourceProp - valid resource identifier
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * propVal - valid resource value
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosetDiskProp(luResourceImpl *hdl, uint32_t resourceProp, const char *propVal)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskResource *diskLu = hdl->resource;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto unsigned long long numericProp = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto char guidProp[LU_ASCII_GUID_SIZE + 1];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto char ouiProp[OUI_ASCII_SIZE + 1];
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte char hostIdProp[HOST_ID_ASCII_SIZE + 1];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto unsigned int oui[OUI_SIZE];
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte unsigned int hostId[HOST_ID_SIZE];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto unsigned int guid[LU_GUID_SIZE];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int propSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (propVal == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (resourceProp) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_ALIAS:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strlcpy(diskLu->luAlias, propVal,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luAlias)) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luAlias)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luAliasValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli case STMF_LU_PROP_BLOCK_SIZE: {
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli const char *tmp = propVal;
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli while (*tmp) {
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli if (!isdigit(*tmp++)) {
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli return (STMF_ERROR_INVALID_ARG);
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli }
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) sscanf(propVal, "%llu", &numericProp);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (numericProp > UINT16_MAX) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->blkSize = numericProp;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->blkSizeValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
26717e15180d2ba9e65de91ddb82e00d97613be4srivijitha dugganapalli }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_COMPANY_ID:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((strlcpy(ouiProp, propVal, sizeof (ouiProp))) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (ouiProp)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (checkHexUpper(ouiProp) != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) sscanf(ouiProp, "%2X%2X%2X",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto &oui[0], &oui[1], &oui[2]);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->companyId = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->companyId += oui[0] << 16;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->companyId += oui[1] << 8;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->companyId += oui[2];
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte if (diskLu->companyId == 0) {
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte return (STMF_ERROR_INVALID_ARG);
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->companyIdValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte case STMF_LU_PROP_HOST_ID:
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte if ((strlcpy(hostIdProp, propVal,
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte sizeof (hostIdProp))) >= sizeof (hostIdProp)) {
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte return (STMF_ERROR_INVALID_ARG);
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte }
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte if (checkHexUpper(hostIdProp) != 0) {
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte return (STMF_ERROR_INVALID_ARG);
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte }
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte (void) sscanf(hostIdProp, "%2X%2X%2X%2X",
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte &hostId[0], &hostId[1], &hostId[2], &hostId[3]);
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte diskLu->hostId = 0;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte diskLu->hostId += hostId[0] << 24;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte diskLu->hostId += hostId[1] << 16;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte diskLu->hostId += hostId[2] << 8;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte diskLu->hostId += hostId[3];
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte if (diskLu->hostId == 0) {
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte return (STMF_ERROR_INVALID_ARG);
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte }
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte diskLu->hostIdValid = B_TRUE;
fdcc480a6215c1e81d58d8e7af8c84fd6f1faa50John Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_GUID:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strlen(propVal) != LU_ASCII_GUID_SIZE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((strlcpy(guidProp, propVal, sizeof (guidProp))) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (guidProp)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (checkHexUpper(guidProp) != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) sscanf(guidProp,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X%2X",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto &guid[0], &guid[1], &guid[2], &guid[3], &guid[4],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto &guid[5], &guid[6], &guid[7], &guid[8], &guid[9],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto &guid[10], &guid[11], &guid[12], &guid[13],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto &guid[14], &guid[15]);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < sizeof (diskLu->luGuid); i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuid[i] = guid[i];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luGuidValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_FILENAME:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((strlcpy(diskLu->luDataFileName, propVal,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luDataFileName))) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luDataFileName)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luDataFileNameValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_META_FILENAME:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((strlcpy(diskLu->luMetaFileName, propVal,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luMetaFileName))) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->luMetaFileName)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luMetaFileNameValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case STMF_LU_PROP_MGMT_URL:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if ((strlcpy(diskLu->luMgmtUrl, propVal,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sizeof (diskLu->luMgmtUrl))) >=
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sizeof (diskLu->luMgmtUrl)) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan return (STMF_ERROR_INVALID_PROPSIZE);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan diskLu->luMgmtUrlValid = B_TRUE;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_PID:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((propSize = strlen(propVal)) >
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->pid)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) strncpy(diskLu->pid, propVal, propSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->pidValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_SERIAL_NUM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((propSize = strlen(propVal)) >
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (sizeof (diskLu->serialNum) - 1)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) strncpy(diskLu->serialNum, propVal, propSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->serialNumValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_SIZE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((niceStrToNum(propVal, &diskLu->luSize) != 0)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->luSizeValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_VID:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((propSize = strlen(propVal)) >
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (diskLu->vid)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_PROPSIZE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) strncpy(diskLu->vid, propVal, propSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->vidValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_WRITE_PROTECT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strcasecmp(propVal, "TRUE") == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writeProtectEnable = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (strcasecmp(propVal, "FALSE") == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writeProtectEnable = B_FALSE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writeProtectEnableValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROP_WRITE_CACHE_DISABLE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strcasecmp(propVal, "TRUE") == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writebackCacheDisable = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (strcasecmp(propVal, "FALSE") == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writebackCacheDisable = B_FALSE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto diskLu->writebackCacheDisableValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case STMF_LU_PROP_ACCESS_STATE:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_INVALID_PROP;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
7b506e25917c371db526f76d85b9b1d17c8c5d39srivijitha dugganapalli ret = STMF_ERROR_INVALID_PROP;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetocheckHexUpper(char *buf)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < strlen(buf); i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (isxdigit(buf[i])) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto buf[i] = toupper(buf[i]);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Given a numeric suffix, convert the value into a number of bits that the
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * resulting value must be shifted.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Code lifted from libzfs_util.c
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostrToShift(const char *buf)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto const char *ends = "BKMGTPE";
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buf[0] == '\0')
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < strlen(ends); i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (toupper(buf[0]) == ends[i])
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (10*i);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfFreeLuResource(luResource hdl)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (hdl == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto luResourceImpl *hdlImpl = hdl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(hdlImpl->resource);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(hdlImpl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Convert a string of the form '100G' into a real number. Used when setting
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * the size of a logical unit.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Code lifted from libzfs_util.c
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoniceStrToNum(const char *value, uint64_t *num)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto char *end;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int shift;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *num = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check to see if this looks like a number. */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((value[0] < '0' || value[0] > '9') && value[0] != '.') {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Rely on stroull() to process the numeric portion. */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto errno = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *num = strtoull(value, &end, 10);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Check for ERANGE, which indicates that the value is too large to fit
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * in a 64-bit value.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (errno == ERANGE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * If we have a decimal value, then do the computation with floating
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * point arithmetic. Otherwise, use standard arithmetic.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*end == '.') {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto double fval = strtod(value, &end);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((shift = strToShift(end)) == -1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fval *= pow(2, shift);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fval > UINT64_MAX) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *num = (uint64_t)fval;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((shift = strToShift(end)) == -1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check for overflow */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (shift >= 64 || (*num << shift) >> shift != *num) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (-1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *num <<= shift;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfCreateTargetGroup
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Create a local port group
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * targetGroupName - name of local port group to create
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfCreateTargetGroup(stmfGroupName *targetGroupName)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (targetGroupName == NULL ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (strnlen((char *)targetGroupName, sizeof (stmfGroupName))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto == sizeof (stmfGroupName))) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check to ensure service exists */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (psCheckService() != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_SERVICE_NOT_FOUND);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* call init */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = initializeConfig();
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Add the group to the driver
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_TARGET_GROUP,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto targetGroupName)) != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * If the add to the driver was successful, add it to the persistent
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * store.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psCreateTargetGroup((char *)targetGroupName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (ret) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_SUCCESS:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_EXISTS:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_EXISTS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_BUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_SERVICE_NOT_FOUND:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_SERVICE_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_VERSION_MISMATCH:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_SERVICE_DATA_VERSION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "stmfCreateTargetGroup:psCreateTargetGroup"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ":error(%d)", ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfDeleteHostGroup
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Delete an initiator or local port group
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hostGroupName - group to delete
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfDeleteHostGroup(stmfGroupName *hostGroupName)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (hostGroupName == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check to ensure service exists */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (psCheckService() != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_SERVICE_NOT_FOUND);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* call init */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = initializeConfig();
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Remove the group from the driver
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = groupIoctl(fd, STMF_IOCTL_REMOVE_HOST_GROUP,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto hostGroupName)) != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * If the remove from the driver was successful, remove it from the
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * persistent store.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psDeleteHostGroup((char *)hostGroupName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (ret) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_SUCCESS:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_NOT_FOUND:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_BUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_SERVICE_NOT_FOUND:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_SERVICE_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_VERSION_MISMATCH:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_SERVICE_DATA_VERSION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "stmfDeleteHostGroup:psDeleteHostGroup:error(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfDeleteTargetGroup
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Delete an initiator or local port group
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * targetGroupName - group to delete
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfDeleteTargetGroup(stmfGroupName *targetGroupName)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (targetGroupName == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Check to ensure service exists */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (psCheckService() != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Remove the group from the driver
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = groupIoctl(fd, STMF_IOCTL_REMOVE_TARGET_GROUP,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto targetGroupName)) != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * If the remove from the driver was successful, remove it from the
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * persistent store.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psDeleteTargetGroup((char *)targetGroupName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (ret) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_SUCCESS:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_NOT_FOUND:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_BUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_SERVICE_NOT_FOUND:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_SERVICE_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PS_ERROR_VERSION_MISMATCH:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_SERVICE_DATA_VERSION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "stmfDeleteTargetGroup:psDeleteTargetGroup"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ":error(%d)", ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfDevidFromIscsiName
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: convert an iSCSI name to an stmf devid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * iscsiName - unicode nul terminated utf-8 encoded iSCSI name
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * devid - on success, contains the converted iscsi name
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfDevidFromIscsiName(char *iscsiName, stmfDevid *devid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (devid == NULL || iscsiName == NULL)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(devid, sizeof (stmfDevid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Validate size of target */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((devid->identLength = strlen(iscsiName)) > MAX_ISCSI_NAME ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto devid->identLength < strlen(EUI) ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto devid->identLength < strlen(IQN)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((strncmp(iscsiName, EUI, strlen(EUI)) != 0) &&
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto strncmp(iscsiName, IQN, strlen(IQN)) != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* copy UTF-8 bytes to ident */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(iscsiName, devid->ident, devid->identLength);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_SUCCESS);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfDevidFromWwn
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: convert a WWN to an stmf devid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * wwn - 8-byte wwn identifier
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * devid - on success, contains the converted wwn
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfDevidFromWwn(uchar_t *wwn, stmfDevid *devid)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (wwn == NULL || devid == NULL)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(devid, sizeof (stmfDevid));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Copy eui prefix */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) bcopy(WWN, devid->ident, strlen(WWN));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Convert to ASCII uppercase hexadecimal string */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) snprintf((char *)&devid->ident[strlen(WWN)],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (devid->ident), "%02X%02X%02X%02X%02X%02X%02X%02X",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto wwn[0], wwn[1], wwn[2], wwn[3], wwn[4], wwn[5], wwn[6], wwn[7]);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto devid->identLength = strlen((char *)devid->ident);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_SUCCESS);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfFreeMemory
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Free memory allocated by this library
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * memory - previously allocated pointer of memory managed by library
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfFreeMemory(void *memory)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(memory);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * get host group, target group list from stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * groupType - HOST_GROUP, TARGET_GROUP
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetogroupListIoctl(stmfGroupList **groupList, int groupType)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int cmd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t stmfIoctl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* framework group list */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_group_name_t *iGroupList = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t groupListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (groupList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (groupType == HOST_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd = STMF_IOCTL_GET_HG_LIST;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (groupType == TARGET_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd = STMF_IOCTL_GET_TG_LIST;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* call init */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = initializeConfig();
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Allocate ioctl input buffer
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto groupListSize = ALLOC_GROUP;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto groupListSize = groupListSize * (sizeof (stmf_group_name_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iGroupList = (stmf_group_name_t *)calloc(1, groupListSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGroupList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(&stmfIoctl, sizeof (stmfIoctl));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Issue ioctl to get the group list
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = groupListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupList;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "groupListIoctl:ioctl errno(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Check whether input buffer was large enough
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto groupListSize = stmfIoctl.stmf_obuf_max_nentries *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmf_group_name_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iGroupList = realloc(iGroupList, groupListSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGroupList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = groupListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupList;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "groupListIoctl:ioctl errno(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* allocate and copy to caller's buffer */
4f2997b292e45181ce3a682d44c3c14a815d97fdsrivijitha dugganapalli *groupList = (stmfGroupList *)calloc(1, sizeof (stmfGroupList) +
4f2997b292e45181ce3a682d44c3c14a815d97fdsrivijitha dugganapalli sizeof (stmfGroupName) * stmfIoctl.stmf_obuf_nentries);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*groupList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*groupList)->cnt = stmfIoctl.stmf_obuf_nentries;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < stmfIoctl.stmf_obuf_nentries; i++) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bcopy(iGroupList[i].name, (*groupList)->name[i],
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmfGroupName));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(iGroupList);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * get host group members, target group members from stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * groupProps - allocated on success
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * groupType - HOST_GROUP, TARGET_GROUP
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetogroupMemberListIoctl(stmfGroupName *groupName, stmfGroupProperties **groupProps,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int groupType)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int cmd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t stmfIoctl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* framework group list */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_group_name_t iGroupName;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_ge_ident_t *iGroupMembers;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t groupListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (groupName == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (groupType == HOST_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd = STMF_IOCTL_GET_HG_ENTRIES;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (groupType == TARGET_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd = STMF_IOCTL_GET_TG_ENTRIES;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* call init */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = initializeConfig();
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(&iGroupName, sizeof (iGroupName));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(groupName, &iGroupName.name, strlen((char *)groupName));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iGroupName.name_size = strlen((char *)groupName);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Allocate ioctl input buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto groupListSize = ALLOC_GRP_MEMBER;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto groupListSize = groupListSize * (sizeof (stmf_ge_ident_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iGroupMembers = (stmf_ge_ident_t *)calloc(1, groupListSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGroupMembers == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Issue ioctl to get the group list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&iGroupName;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmf_group_name_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = groupListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupMembers;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "groupListIoctl:ioctl errno(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Check whether input buffer was large enough
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_GRP_MEMBER) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto groupListSize = stmfIoctl.stmf_obuf_max_nentries *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmf_ge_ident_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iGroupMembers = realloc(iGroupMembers, groupListSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGroupMembers == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&iGroupName;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmf_group_name_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = groupListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)iGroupMembers;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "groupListIoctl:ioctl errno(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* allocate and copy to caller's buffer */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *groupProps = (stmfGroupProperties *)calloc(1,
4f2997b292e45181ce3a682d44c3c14a815d97fdsrivijitha dugganapalli sizeof (stmfGroupProperties) +
4f2997b292e45181ce3a682d44c3c14a815d97fdsrivijitha dugganapalli sizeof (stmfDevid) * stmfIoctl.stmf_obuf_nentries);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*groupProps == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*groupProps)->cnt = stmfIoctl.stmf_obuf_nentries;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < stmfIoctl.stmf_obuf_nentries; i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*groupProps)->name[i].identLength =
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan iGroupMembers[i].ident_size;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bcopy(iGroupMembers[i].ident, (*groupProps)->name[i].ident,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan iGroupMembers[i].ident_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(iGroupMembers);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: access persistent config data for host groups and target groups
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoiLoadGroupFromPs(stmfGroupList **groupList, int type)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (groupList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (type == HOST_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psGetHostGroupList(groupList);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (type == TARGET_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psGetTargetGroupList(groupList);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "stmfGetHostGroupList:psGetHostGroupList:error(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfGetHostGroupList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Retrieves the list of initiator group oids
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * hostGroupList - pointer to pointer to hostGroupList structure
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * on success, this contains the host group list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfGetHostGroupList(stmfGroupList **hostGroupList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (hostGroupList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = groupListIoctl(hostGroupList, HOST_GROUP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: access persistent config data for host groups and target groups
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoiLoadGroupMembersFromPs(stmfGroupName *groupName,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfGroupProperties **groupProp, int type)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (groupName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (type == HOST_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psGetHostGroupMemberList((char *)groupName, groupProp);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (type == TARGET_GROUP) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psGetTargetGroupMemberList((char *)groupName, groupProp);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "iLoadGroupMembersFromPs:psGetHostGroupList:"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetHostGroupMembers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the group properties for a host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupName - name of group for which to retrieve host group members.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupProp - pointer to pointer to stmfGroupProperties structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on success, this contains the list of group members.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetHostGroupMembers(stmfGroupName *groupName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGroupProperties **groupProp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (groupName == NULL || groupProp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = groupMemberListIoctl(groupName, groupProp, HOST_GROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetProviderData
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Get provider data list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerName - name of provider for which to retrieve the data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nvl - pointer to nvlist_t pointer which will contain the nvlist data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * retrieved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerType - type of provider for which to retrieve data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_LU_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_PORT_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetProviderData(char *providerName, nvlist_t **nvl, int providerType)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (stmfGetProviderDataProt(providerName, nvl, providerType,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetProviderDataProt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Get provider data list with token
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerName - name of provider for which to retrieve the data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nvl - pointer to nvlist_t pointer which will contain the nvlist data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * retrieved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerType - type of provider for which to retrieve data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_LU_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_PORT_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * setToken - Returns the stale data token
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetProviderDataProt(char *providerName, nvlist_t **nvl, int providerType,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t *setToken)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (providerName == NULL || nvl == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (providerType != STMF_LU_PROVIDER_TYPE &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte providerType != STMF_PORT_PROVIDER_TYPE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* call init */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = initializeConfig();
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (getProviderData(providerName, nvl, providerType, setToken));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetProviderDataList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Get the list of providers currently persisting data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerList - pointer to pointer to an stmfProviderList structure allocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by the caller. Will contain the list of providers on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetProviderDataList(stmfProviderList **providerList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetProviderDataList(providerList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetProviderDataList:psGetProviderDataList"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ":error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetSessionList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the session list for a target (devid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid - devid of target for which to retrieve session information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sessionList - pointer to pointer to stmfSessionList structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on success, this contains the list of initiator sessions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetSessionList(stmfDevid *devid, stmfSessionList **sessionList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cmd = STMF_IOCTL_SESSION_LIST;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting slist_scsi_session_t *fSessionList, *fSessionListP = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t ident[260];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t fSessionListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sessionList == NULL || devid == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_INVALID_ARG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate ioctl input buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fSessionListSize = ALLOC_SESSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionListSize = fSessionListSize * (sizeof (slist_scsi_session_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionList = (slist_scsi_session_t *)calloc(1, fSessionListSize);
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting fSessionListP = fSessionList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fSessionList == NULL) {
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting ret = STMF_ERROR_NOMEM;
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ident[IDENT_LENGTH_BYTE] = devid->identLength;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(devid->ident), &ident[IDENT_LENGTH_BYTE + 1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to get the session list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ident;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = fSessionListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fSessionList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetSessionList:ioctl errno(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check whether input buffer was large enough
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_SESSION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionListSize = stmfIoctl.stmf_obuf_max_nentries *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (slist_scsi_session_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionList = realloc(fSessionList, fSessionListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fSessionList == NULL) {
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting ret = STMF_ERROR_NOMEM;
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting fSessionListP = fSessionList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = fSessionListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fSessionList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetSessionList:ioctl "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "errno(%d)", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate caller's buffer with the final size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *sessionList = (stmfSessionList *)calloc(1, sizeof (stmfSessionList) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_max_nentries * sizeof (stmfSession));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*sessionList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(sessionList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*sessionList)->cnt = stmfIoctl.stmf_obuf_max_nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy session info to caller's buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < (*sessionList)->cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*sessionList)->session[i].initiator.identLength =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionList->initiator[IDENT_LENGTH_BYTE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(fSessionList->initiator[IDENT_LENGTH_BYTE + 1]),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*sessionList)->session[i].initiator.ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_IDENT_LENGTH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(fSessionList->alias),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &((*sessionList)->session[i].alias),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof ((*sessionList)->session[i].alias));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(fSessionList++->creation_time),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &((*sessionList)->session[i].creationTime),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (time_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
562610838fe0b8fdbe99a91a1dc13e77da2b6546Charles Ting free(fSessionListP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetTargetGroupList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the list of target groups
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetGroupList - pointer to a pointer to an stmfGroupList structure. On
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * success, it contains the list of target groups.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetTargetGroupList(stmfGroupList **targetGroupList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (targetGroupList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = groupListIoctl(targetGroupList, TARGET_GROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetTargetGroupMembers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the group members for a target group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupName - name of target group for which to retrieve members.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupProp - pointer to pointer to stmfGroupProperties structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on success, this contains the list of group members.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetTargetGroupMembers(stmfGroupName *groupName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGroupProperties **groupProp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (groupName == NULL || groupProp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = groupMemberListIoctl(groupName, groupProp, TARGET_GROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetTargetList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the list of target ports
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetList - pointer to a pointer to an stmfDevidList structure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On success, it contains the list of local ports (target).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetTargetList(stmfDevidList **targetList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* framework target port list */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto slist_target_port_t *fTargetList, *fTargetListP = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t fTargetListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (targetList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate ioctl input buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fTargetListSize = ALLOC_TARGET_PORT * sizeof (slist_target_port_t);
3e7352aecf183df6c5f819be775df62aadcdfd08John Forte fTargetListP = fTargetList =
3e7352aecf183df6c5f819be775df62aadcdfd08John Forte (slist_target_port_t *)calloc(1, fTargetListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fTargetList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
3e7352aecf183df6c5f819be775df62aadcdfd08John Forte * Issue ioctl to retrieve target list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = fTargetListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fTargetList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_TARGET_PORT_LIST, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetTargetList:ioctl errno(%d)", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check whether input buffer was large enough
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_TARGET_PORT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fTargetListSize = stmfIoctl.stmf_obuf_max_nentries *
76602b8d8c37ab03ff72d289b721cf827dbae7daJohn Forte sizeof (slist_target_port_t);
3e7352aecf183df6c5f819be775df62aadcdfd08John Forte fTargetListP = fTargetList =
3e7352aecf183df6c5f819be775df62aadcdfd08John Forte realloc(fTargetList, fTargetListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fTargetList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = fTargetListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fTargetList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_TARGET_PORT_LIST,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetTargetList:ioctl errno(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *targetList = (stmfDevidList *)calloc(1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_max_nentries * sizeof (stmfDevid) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfDevidList));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*targetList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*targetList)->cnt = stmfIoctl.stmf_obuf_max_nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < stmfIoctl.stmf_obuf_max_nentries; i++, fTargetList++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*targetList)->devid[i].identLength =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fTargetList->target[IDENT_LENGTH_BYTE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&fTargetList->target[IDENT_LENGTH_BYTE + 1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(*targetList)->devid[i].ident,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fTargetList->target[IDENT_LENGTH_BYTE]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
3e7352aecf183df6c5f819be775df62aadcdfd08John Forte free(fTargetListP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetTargetProperties
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the properties for a logical unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid - devid of the target for which to retrieve properties
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetProps - pointer to an stmfTargetProperties structure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On success, it contains the target properties for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the specified devid.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetTargetProperties(stmfDevid *devid, stmfTargetProperties *targetProps)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sioc_target_port_props_t targetProperties;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scsi_devid_desc_t *scsiDevid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devid == NULL || targetProps == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetProperties.tgt_id[IDENT_LENGTH_BYTE] = devid->identLength;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(devid->ident), &targetProperties.tgt_id[IDENT_LENGTH_BYTE + 1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to add to the host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (targetProperties.tgt_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&targetProperties.tgt_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&targetProperties;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = sizeof (targetProperties);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_GET_TARGET_PORT_PROPERTIES,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ENOENT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetTargetProperties:ioctl errno(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(targetProperties.tgt_provider_name, targetProps->providerName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (targetProperties.tgt_provider_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (targetProperties.tgt_state == STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetProps->status = STMF_TARGET_PORT_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (targetProperties.tgt_state == STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetProps->status = STMF_TARGET_PORT_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (targetProperties.tgt_state == STMF_STATE_ONLINING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetProps->status = STMF_TARGET_PORT_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (targetProperties.tgt_state == STMF_STATE_OFFLINING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetProps->status = STMF_TARGET_PORT_OFFLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(targetProperties.tgt_alias, targetProps->alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (targetProps->alias));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte scsiDevid = (scsi_devid_desc_t *)&targetProperties.tgt_id;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte targetProps->protocol = scsiDevid->protocol_id;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetLogicalUnitList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves list of logical unit Object IDs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * luList - pointer to a pointer to a stmfGuidList structure. On success,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it contains the list of logical unit guids.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetLogicalUnitList(stmfGuidList **luList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cmd = STMF_IOCTL_LU_LIST;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slist_lu_t *fLuList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t fLuListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t listCnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Allocate ioctl input buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fLuListSize = ALLOC_LU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuListSize = fLuListSize * (sizeof (slist_lu_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuList = (slist_lu_t *)calloc(1, fLuListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fLuList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to get the LU list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = fLuListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fLuList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetLogicalUnitList:ioctl errno(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check whether input buffer was large enough
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_LU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuListSize = stmfIoctl.stmf_obuf_max_nentries *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (slist_lu_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(fLuList);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fLuList = (slist_lu_t *)calloc(1, fLuListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fLuList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = fLuListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fLuList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetLogicalUnitList:"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "ioctl errno(%d)", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto listCnt = stmfIoctl.stmf_obuf_nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate caller's buffer with the final size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *luList = (stmfGuidList *)calloc(1, sizeof (stmfGuidList) +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto listCnt * sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*luList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*luList)->cnt = listCnt;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* copy to caller's buffer */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < listCnt; i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(&fLuList[i].lu_guid, (*luList)->guid[i].guid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * sort the list. This gives a consistent view across gets
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto qsort((void *)&((*luList)->guid[0]), (*luList)->cnt,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmfGuid), guidCompare);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free internal buffers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(fLuList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetLogicalUnitProperties
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the properties for a logical unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lu - guid of the logical unit for which to retrieve properties
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfLuProps - pointer to an stmfLogicalUnitProperties structure. On success,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it contains the logical unit properties for the specified guid.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetLogicalUnitProperties(stmfGuid *lu, stmfLogicalUnitProperties *luProps)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int stmfRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cmd = STMF_IOCTL_GET_LU_PROPERTIES;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfViewEntryList *viewEntryList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sioc_lu_props_t fLuProps;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (lu == NULL || luProps == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(luProps, sizeof (stmfLogicalUnitProperties));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to add to the host group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmfGuid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)lu;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&fLuProps;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = sizeof (fLuProps);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ENOENT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfRet = stmfGetViewEntryList(lu,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &viewEntryList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmfRet == STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luProps->status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_LOGICAL_UNIT_UNREGISTERED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (viewEntryList->cnt > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfFreeMemory(viewEntryList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetLogicalUnit:ioctl errno(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(fLuProps.lu_provider_name, luProps->providerName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (fLuProps.lu_provider_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fLuProps.lu_state == STMF_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luProps->status = STMF_LOGICAL_UNIT_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fLuProps.lu_state == STMF_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luProps->status = STMF_LOGICAL_UNIT_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fLuProps.lu_state == STMF_STATE_ONLINING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luProps->status = STMF_LOGICAL_UNIT_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (fLuProps.lu_state == STMF_STATE_OFFLINING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luProps->status = STMF_LOGICAL_UNIT_OFFLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(fLuProps.lu_alias, luProps->alias, sizeof (luProps->alias));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetState
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: retrieve the current state of the stmf module
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * state - pointer to stmfState structure allocated by the caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On success, contains the state of stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetState(stmfState *state)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t iState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = getStmfState(&iState);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (iState.state) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_STATE_ONLINE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->operationalState =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SERVICE_STATE_ONLINE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_STATE_OFFLINE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->operationalState =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SERVICE_STATE_OFFLINE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_STATE_ONLINING:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->operationalState =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SERVICE_STATE_ONLINING;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_STATE_OFFLINING:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->operationalState =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SERVICE_STATE_OFFLINING;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->operationalState =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SERVICE_STATE_UNKNOWN;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (iState.config_state) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_CONFIG_NONE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->configState = STMF_CONFIG_STATE_NONE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_CONFIG_INIT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->configState = STMF_CONFIG_STATE_INIT;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_CONFIG_INIT_DONE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->configState =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_CONFIG_STATE_INIT_DONE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto state->configState =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_CONFIG_STATE_UNKNOWN;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_STATUS_SUCCESS);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * stmfGetViewEntryList
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: Retrieves the list of view entries for the specified
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * logical unit.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * lu - the guid of the logical unit for which to retrieve the view entry list
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * viewEntryList - a pointer to a pointer to a stmfViewEntryList structure. On
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * success, contains the list of view entries.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int cmd = STMF_IOCTL_LU_VE_LIST;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t stmfIoctl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_view_op_entry_t *fVeList;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t fVeListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t listCnt;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (lu == NULL || viewEntryList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* call init */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = initializeConfig();
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Allocate ioctl input buffer
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fVeListSize = ALLOC_VE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fVeListSize = fVeListSize * (sizeof (stmf_view_op_entry_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fVeList = (stmf_view_op_entry_t *)calloc(1, fVeListSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fVeList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(&stmfIoctl, sizeof (stmfIoctl));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Issue ioctl to get the LU list
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)lu;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmfGuid);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = fVeListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fVeList;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "stmfGetViewEntryList:ioctl errno(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Check whether input buffer was large enough
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_obuf_max_nentries > ALLOC_VE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(&stmfIoctl, sizeof (stmfIoctl));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fVeListSize = stmfIoctl.stmf_obuf_max_nentries *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmf_view_op_entry_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(fVeList);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fVeList = (stmf_view_op_entry_t *)calloc(1, fVeListSize);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fVeList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_NOMEM);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = fVeListSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)fVeList;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, cmd, &stmfIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "stmfGetLogicalUnitList:"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "ioctl errno(%d)", errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto listCnt = stmfIoctl.stmf_obuf_nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * allocate caller's buffer with the final size
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *viewEntryList = (stmfViewEntryList *)calloc(1,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmfViewEntryList) + listCnt * sizeof (stmfViewEntry));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (*viewEntryList == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->cnt = listCnt;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* copy to caller's buffer */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 0; i < listCnt; i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->ve[i].veIndexValid = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->ve[i].veIndex = fVeList[i].ve_ndx;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fVeList[i].ve_all_hosts == 1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->ve[i].allHosts = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(fVeList[i].ve_host_group.name,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->ve[i].hostGroup,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fVeList[i].ve_host_group.name_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fVeList[i].ve_all_targets == 1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->ve[i].allTargets = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(fVeList[i].ve_target_group.name,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->ve[i].targetGroup,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto fVeList[i].ve_target_group.name_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(fVeList[i].ve_lu_nbr, (*viewEntryList)->ve[i].luNbr,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof ((*viewEntryList)->ve[i].luNbr));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (*viewEntryList)->ve[i].luNbrValid = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * sort the list. This gives a consistent view across gets
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto qsort((void *)&((*viewEntryList)->ve[0]), (*viewEntryList)->cnt,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmfViewEntry), viewEntryCompare);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * free internal buffers
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(fVeList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * loadHostGroups
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose - issues the ioctl to load the host groups into stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fd - file descriptor for the control node of stmf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupList - populated host group list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteloadHostGroups(int fd, stmfGroupList *groupList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGroupProperties *groupProps = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < groupList->cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_HOST_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(groupList->name[i]))) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = iLoadGroupMembersFromPs(&(groupList->name[i]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto &groupProps, HOST_GROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < groupProps->cnt; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_HG_ENTRY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(groupList->name[i]), &(groupProps->name[j])))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfFreeMemory(groupProps);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * loadTargetGroups
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose - issues the ioctl to load the target groups into stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fd - file descriptor for the control node of stmf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupList - populated target group list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteloadTargetGroups(int fd, stmfGroupList *groupList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGroupProperties *groupProps = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < groupList->cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_TARGET_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(groupList->name[i]))) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = iLoadGroupMembersFromPs(&(groupList->name[i]),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto &groupProps, TARGET_GROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < groupProps->cnt; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_ADD_TG_ENTRY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(groupList->name[i]), &(groupProps->name[j])))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfFreeMemory(groupProps);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * loadStore
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Load the configuration data from the store
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First load the host groups and target groups, then the view entries
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and finally the provider data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fd - file descriptor of control node for stmf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteloadStore(int fd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGroupList *groupList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGuidList *guidList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfViewEntryList *viewEntryList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfProviderList *providerList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int providerType;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nvlist_t *nvl = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* load host groups */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = iLoadGroupFromPs(&groupList, HOST_GROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = loadHostGroups(fd, groupList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfFreeMemory(groupList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte groupList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* load target groups */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = iLoadGroupFromPs(&groupList, TARGET_GROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = loadTargetGroups(fd, groupList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfFreeMemory(groupList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte groupList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the guid list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetLogicalUnitList(&guidList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We have the guid list, now get the corresponding
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * view entries for each guid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < guidList->cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetViewEntryList(&guidList->guid[i], &viewEntryList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < viewEntryList->cnt; j++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = addViewEntryIoctl(fd, &guidList->guid[i],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &viewEntryList->ve[j]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get the list of providers that have data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetProviderDataList(&providerList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < providerList->cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte providerType = providerList->provider[i].providerType;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetProviderData(providerList->provider[i].name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &nvl, providerType, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call setProviderData */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setProviderData(fd, providerList->provider[i].name, nvl,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto providerType, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nvlist_free(nvl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nvl = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (groupList != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(groupList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (guidList != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(guidList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (viewEntryList != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(viewEntryList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nvl != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nvlist_free(nvl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * stmfGetAluaState
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose - Get the alua state
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortestmfGetAluaState(boolean_t *enabled, uint32_t *node)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = STMF_STATUS_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int fd;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_iocdata_t stmfIoctl = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_alua_state_desc_t alua_state = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ioctlRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (enabled == NULL || node == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Open control node for stmf
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Issue ioctl to get the stmf state
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfIoctl.stmf_obuf_size = sizeof (alua_state);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&alua_state;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_GET_ALUA_STATE, &stmfIoctl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) close(fd);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ioctlRet != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (errno) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EBUSY:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_BUSY;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EPERM:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EACCES:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_PERM;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DEBUG,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "getStmfState:ioctl errno(%d)", errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_STATUS_ERROR;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (alua_state.alua_state == 1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *enabled = B_TRUE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *enabled = B_FALSE;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *node = alua_state.alua_node;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * stmfSetAluaState
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose - set the alua state to enabled/disabled
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortestmfSetAluaState(boolean_t enabled, uint32_t node)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = STMF_STATUS_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int fd;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_iocdata_t stmfIoctl = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_alua_state_desc_t alua_state = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ioctlRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((enabled != B_TRUE && enabled != B_FALSE) || (node > 1)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (enabled) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte alua_state.alua_state = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte alua_state.alua_node = node;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Open control node for stmf
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Issue ioctl to get the stmf state
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (alua_state);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&alua_state;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_SET_ALUA_STATE, &stmfIoctl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) close(fd);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ioctlRet != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (errno) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EBUSY:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_BUSY;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EPERM:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EACCES:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_PERM;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DEBUG,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "getStmfState:ioctl errno(%d)", errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_STATUS_ERROR;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
cd36db67f9470c74ed7f5bbd57ec6eeb84f71fcdJohn Forte if (!enabled && ret == STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte deleteNonActiveLus();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortedeleteNonActiveLus()
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int stmfRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int i;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfGuidList *luList;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte luResource hdl = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte char propVal[10];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte size_t propValSize = sizeof (propVal);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfRet = stmfGetLogicalUnitList(&luList);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (i = 0; i < luList->cnt; i++) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfRet = stmfGetLuResource(&luList->guid[i], &hdl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte goto err;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfRet = stmfGetLuProp(hdl, STMF_LU_PROP_ACCESS_STATE, propVal,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte &propValSize);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmfRet != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte goto err;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (propVal[0] == '0') {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmfFreeLuResource(hdl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte hdl = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte continue;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmfDeleteLu(&luList->guid[i]);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmfFreeLuResource(hdl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte hdl = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteerr:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmfFreeMemory(luList);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) stmfFreeLuResource(hdl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfLoadConfig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose - load the configuration data from smf into stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfLoadConfig(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t stmfStateSet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfState state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfStateSet.state = STMF_STATE_OFFLINE;
640428ae0ffb68033a9bf38dcc271e17d13933cbSue Gleeson
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openStmf(OPEN_EXCL_STMF, &fd))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto != STMF_STATUS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
640428ae0ffb68033a9bf38dcc271e17d13933cbSue Gleeson /*
640428ae0ffb68033a9bf38dcc271e17d13933cbSue Gleeson * Configuration not stored persistently; nothing to
640428ae0ffb68033a9bf38dcc271e17d13933cbSue Gleeson * initialize so do not set to STMF_CONFIG_INIT.
640428ae0ffb68033a9bf38dcc271e17d13933cbSue Gleeson */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfStateSet.config_state = STMF_CONFIG_INIT_DONE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to ensure service exists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (psCheckService() != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_SERVICE_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetState(&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state.operationalState != STMF_SERVICE_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_SERVICE_ONLINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfStateSet.state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfStateSet.config_state = STMF_CONFIG_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &stmfStateSet, STMF_SERVICE_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Load the persistent configuration data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = loadStore(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfStateSet.state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfStateSet.config_state = STMF_CONFIG_INIT_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &stmfStateSet, STMF_SERVICE_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * getStmfState
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfState - pointer to stmf_state_desc_t structure. Will contain the state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information of the stmf service on success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortegetStmfState(stmf_state_desc_t *stmfState)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to get the stmf state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmf_state_desc_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)stmfState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf_size = sizeof (stmf_state_desc_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)stmfState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_GET_STMF_STATE, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "getStmfState:ioctl errno(%d)", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * setStmfState
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfState - pointer to caller set state structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * objectType - one of:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LOGICAL_UNIT_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * TARGET_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_SERVICE_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortesetStmfState(int fd, stmf_state_desc_t *stmfState, int objectType)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (objectType) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case LOGICAL_UNIT_TYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd = STMF_IOCTL_SET_LU_STATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case TARGET_TYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd = STMF_IOCTL_SET_TARGET_PORT_STATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_SERVICE_TYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd = STMF_IOCTL_SET_STMF_STATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to set the stmf state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (stmf_state_desc_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)stmfState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, cmd, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ENOENT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "setStmfState:ioctl errno(%d)", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalliint
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallistmfSetStmfProp(uint8_t propType, char *propVal)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli{
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli int ret = STMF_STATUS_SUCCESS;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli switch (propType) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_DEFAULT_LU_STATE:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_DEFAULT_TARGET_PORT_STATE:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli default:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (STMF_ERROR_INVALID_ARG);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = psSetStmfProp(propType, propVal);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli switch (ret) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_SUCCESS:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_STATUS_SUCCESS;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_ERROR_BUSY:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_BUSY;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli default:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli syslog(LOG_DEBUG,
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli "stmfSetStmfProp:psSetStmfProp:error(%d)",
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_STATUS_ERROR;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli}
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalliint
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallistmfGetStmfProp(uint8_t propType, char *propVal, size_t *propLen)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli{
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli int ret = STMF_STATUS_SUCCESS;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli char prop[MAXNAMELEN] = {0};
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli size_t reqLen;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (propVal == NULL || propLen == NULL) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (STMF_ERROR_INVALID_ARG);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli switch (propType) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_DEFAULT_LU_STATE:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_DEFAULT_TARGET_PORT_STATE:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli default:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (STMF_ERROR_INVALID_ARG);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = psGetStmfProp(propType, prop);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((reqLen = strlcpy(propVal, prop, *propLen)) >= *propLen) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli *propLen = reqLen + 1;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (STMF_ERROR_INVALID_ARG);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli switch (ret) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_SUCCESS:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_STATUS_SUCCESS;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_ERROR_BUSY:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_BUSY;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_ERROR_NOT_FOUND:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_NOT_FOUND;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli default:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli syslog(LOG_DEBUG,
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli "stmfGetStmfProp:psGetStmfProp:error(%d)",
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_STATUS_ERROR;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli}
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallistatic int
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallisetStmfProp(stmf_set_props_t *stmf_set_props)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli{
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli char propVal[MAXNAMELEN] = {0};
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli int ret;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((ret = psGetStmfProp(STMF_DEFAULT_LU_STATE, propVal)) ==
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_PS_SUCCESS) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (strncmp(propVal, "offline", strlen(propVal)) == 0) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props->default_lu_state_value =
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_OFFLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli } else {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props->default_lu_state_value =
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_ONLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli } else {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli syslog(LOG_DEBUG,
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli "DefaultLuState:psSetStmfProp:error(%d)", ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli goto done;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((ret = psGetStmfProp(STMF_DEFAULT_TARGET_PORT_STATE, propVal)) ==
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_PS_SUCCESS) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (strncmp(propVal, "offline", strlen(propVal)) == 0) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props->default_target_state_value =
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_OFFLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli } else {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props->default_target_state_value =
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli STMF_STATE_ONLINE;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli } else {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli syslog(LOG_DEBUG,
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli "DefaultTargetPortState:psSetStmfProp:error(%d)", ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli goto done;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallidone:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli switch (ret) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_SUCCESS:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_STATUS_SUCCESS;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_ERROR_NOT_FOUND:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_NOT_FOUND;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case STMF_PS_ERROR_BUSY:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_BUSY;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli default:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_STATUS_ERROR;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli}
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallistatic int
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalliloadStmfProp(int fd)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli{
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli int ret = STMF_STATUS_SUCCESS;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli int ioctlRet;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_iocdata_t stmfIoctl = {0};
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props_t *stmf_set_props = NULL;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmf_set_props = (stmf_set_props_t *)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli calloc(1, (sizeof (stmf_set_props_t)));
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_set_props == NULL) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_NOMEM;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli goto done;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli /* Loading the default property values from smf */
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((ret = setStmfProp(stmf_set_props)) != STMF_STATUS_SUCCESS)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli goto done;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmfIoctl.stmf_version = STMF_VERSION_1;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmfIoctl.stmf_ibuf_size = sizeof (stmf_set_props_t);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli stmfIoctl.stmf_ibuf =
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (uint64_t)(unsigned long)stmf_set_props;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ioctlRet = ioctl(fd, STMF_IOCTL_SET_STMF_PROPS,
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli &stmfIoctl);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (ioctlRet != 0) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli switch (errno) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case EBUSY:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_BUSY;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case EPERM:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case EACCES:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_PERM;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli case ENOENT:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_ERROR_NOT_FOUND;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli default:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli syslog(LOG_DEBUG,
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli "setDefaultStmfState:"
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli "ioctl errno(%d)", errno);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = STMF_STATUS_ERROR;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli break;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallidone:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (stmf_set_props != NULL) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli free(stmf_set_props);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli}
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalliint
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallistmfLoadStmfProps(void)
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli{
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli int ret = STMF_STATUS_SUCCESS;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli int fd;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli /* open control node for stmf */
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if ((ret = openStmf(OPEN_EXCL_STMF, &fd))
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli != STMF_STATUS_SUCCESS) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli goto done;
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli ret = loadStmfProp(fd);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli (void) close(fd);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapallidone:
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli if (ret != STMF_STATUS_SUCCESS) {
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli syslog(LOG_DEBUG,
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli "stmfLoadStmfProps:Failed");
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli }
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli return (ret);
4b31676f89e318c11400fc0c4defc802da29222fsrivijitha dugganapalli}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfOnline
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Online stmf service
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfOnline(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfState state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t iState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetState(&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state.operationalState == STMF_SERVICE_STATE_ONLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_SERVICE_ONLINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iState.state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iState.config_state = STMF_CONFIG_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to make call to setStmfState()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &iState, STMF_SERVICE_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfOffline
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Offline stmf service
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfOffline(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfState state;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t iState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetState(&state);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (state.operationalState == STMF_SERVICE_STATE_OFFLINE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_SERVICE_OFFLINE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iState.state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iState.config_state = STMF_CONFIG_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to make call to setStmfState()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &iState, STMF_SERVICE_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfOfflineTarget
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Change state of target to offline
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid - devid of the target to offline
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfOfflineTarget(stmfDevid *devid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t targetState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devid == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&targetState, sizeof (targetState));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetState.state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetState.ident[IDENT_LENGTH_BYTE] = devid->identLength;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(devid->ident), &targetState.ident[IDENT_LENGTH_BYTE + 1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to make call to setStmfState()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &targetState, TARGET_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfOfflineLogicalUnit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Change state of logical unit to offline
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lu - guid of the logical unit to offline
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfOfflineLogicalUnit(stmfGuid *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t luState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&luState, sizeof (luState));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luState.state = STMF_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(lu, &luState.ident, sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to make call to setStmfState()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &luState, LOGICAL_UNIT_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfOnlineTarget
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Change state of target to online
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid - devid of the target to online
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfOnlineTarget(stmfDevid *devid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t targetState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devid == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&targetState, sizeof (targetState));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetState.state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetState.ident[IDENT_LENGTH_BYTE] = devid->identLength;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(devid->ident), &targetState.ident[IDENT_LENGTH_BYTE + 1],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to make call to setStmfState()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &targetState, TARGET_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfOnlineLogicalUnit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Change state of logical unit to online
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lu - guid of the logical unit to online
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfOnlineLogicalUnit(stmfGuid *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t luState;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&luState, sizeof (luState));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte luState.state = STMF_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(lu, &luState.ident, sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to make call to setStmfState()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_EXCL_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setStmfState(fd, &luState, LOGICAL_UNIT_TYPE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfRemoveFromHostGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Removes an initiator from an initiator group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hostGroupName - name of an initiator group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hostName - name of host group member to remove
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfRemoveFromHostGroup(stmfGroupName *hostGroupName, stmfDevid *hostName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hostGroupName == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strnlen((char *)hostGroupName, sizeof (stmfGroupName))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == sizeof (stmfGroupName)) || hostName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_REMOVE_HG_ENTRY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hostGroupName, hostName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psRemoveHostGroupMember((char *)hostGroupName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)hostName->ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_MEMBER_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_MEMBER_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfRemoveFromHostGroup"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "psRemoveHostGroupMember:error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfRemoveFromTargetGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Removes a local port from a local port group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetGroupName - name of a target group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetName - name of target to remove
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfRemoveFromTargetGroup(stmfGroupName *targetGroupName, stmfDevid *targetName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (targetGroupName == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strnlen((char *)targetGroupName, sizeof (stmfGroupName))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == sizeof (stmfGroupName)) || targetName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupMemberIoctl(fd, STMF_IOCTL_REMOVE_TG_ENTRY,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetGroupName, targetName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psRemoveTargetGroupMember((char *)targetGroupName,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)targetName->ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_MEMBER_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_MEMBER_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_GROUP_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_GROUP_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfRemoveFromTargetGroup"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "psRemoveTargetGroupMember:error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfRemoveViewEntry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Removes a view entry from a logical unit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lu - guid of lu for which view entry is being removed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * viewEntryIndex - index of view entry to remove
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfRemoveViewEntry(stmfGuid *lu, uint32_t viewEntryIndex)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_view_op_entry_t ioctlViewEntry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&ioctlViewEntry, sizeof (ioctlViewEntry));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlViewEntry.ve_ndx_valid = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlViewEntry.ve_ndx = viewEntryIndex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(lu, &ioctlViewEntry.ve_guid, sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Issue ioctl to add to the view entry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = sizeof (ioctlViewEntry);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ioctlViewEntry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_REMOVE_VIEW_ENTRY, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (stmfIoctl.stmf_error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_IOCERR_UPDATE_NEED_CFG_INIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_CONFIG_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ENODEV:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ENOENT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfRemoveViewEntry:ioctl errno(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psRemoveViewEntry(lu, viewEntryIndex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfRemoveViewEntry" "psRemoveViewEntry:error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfSetProviderData
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: set the provider data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerName - unique name of provider
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nvl - nvlist to set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerType - type of provider for which to set data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_LU_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_PORT_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfSetProviderData(char *providerName, nvlist_t *nvl, int providerType)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (stmfSetProviderDataProt(providerName, nvl, providerType,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfSetProviderDataProt
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: set the provider data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerName - unique name of provider
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nvl - nvlist to set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerType - type of provider for which to set data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_LU_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * STMF_PORT_PROVIDER_TYPE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * setToken - Stale data token returned in the stmfGetProviderDataProt()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * call or NULL.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfSetProviderDataProt(char *providerName, nvlist_t *nvl, int providerType,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t *setToken)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (providerName == NULL || nvl == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (providerType != STMF_LU_PROVIDER_TYPE &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte providerType != STMF_PORT_PROVIDER_TYPE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* call init */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = initializeConfig();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open control node for stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = setProviderData(fd, providerName, nvl, providerType, setToken);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iGetPersistMethod() == STMF_PERSIST_NONE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setting driver provider data successful. Now persist it */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psSetProviderData(providerName, nvl, providerType, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ret) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_SUCCESS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_EXISTS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_EXISTS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_BUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_SERVICE_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_NOT_FOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_VERSION_MISMATCH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_SERVICE_DATA_VERSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PS_ERROR_PROV_DATA_STALE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PROV_DATA_STALE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfSetProviderData"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "psSetProviderData:error(%d)", ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * getProviderData
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: set the provider data from stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * providerName - unique name of provider
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * nvl - nvlist to load/retrieve
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * providerType - logical unit or port provider
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * setToken - returned stale data token
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetogetProviderData(char *providerName, nvlist_t **nvl, int providerType,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint64_t *setToken)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int fd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ioctlRet;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto size_t nvlistSize = ALLOC_PP_DATA_SIZE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int retryCnt = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int retryCntMax = MAX_PROVIDER_RETRY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_ppioctl_data_t ppi = {0}, *ppi_out = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto boolean_t retry = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_iocdata_t stmfIoctl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (providerName == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Open control node for stmf
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* set provider name and provider type */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (strlcpy(ppi.ppi_name, providerName,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (ppi.ppi_name)) >=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (ppi.ppi_name)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_INVALID_ARG;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (providerType) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_LU_PROVIDER_TYPE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi.ppi_lu_provider = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case STMF_PORT_PROVIDER_TYPE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi.ppi_port_provider = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_INVALID_ARG;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto do {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* allocate memory for ioctl */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_out = (stmf_ppioctl_data_t *)calloc(1, nvlistSize +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sizeof (stmf_ppioctl_data_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ppi_out == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOMEM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* set the size of the ioctl data to allocated buffer */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi.ppi_data_size = nvlistSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(&stmfIoctl, sizeof (stmfIoctl));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_version = STMF_VERSION_1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf_size = sizeof (stmf_ppioctl_data_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ppi;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = sizeof (stmf_ppioctl_data_t) +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto nvlistSize;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)ppi_out;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ioctlRet = ioctl(fd, STMF_IOCTL_GET_PP_DATA, &stmfIoctl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ioctlRet != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (errno) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EBUSY:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EACCES:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERM;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EINVAL:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_error ==
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_IOCERR_INSUFFICIENT_BUF) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto nvlistSize =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_out->ppi_data_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(ppi_out);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_out = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (retryCnt++ > retryCntMax) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto retry = B_FALSE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_BUSY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "getProviderData:ioctl"
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "unable to retrieve "
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "nvlist");
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case ENOENT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_NOT_FOUND;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto syslog(LOG_DEBUG,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto "getProviderData:ioctl errno(%d)",
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto errno);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_STATUS_SUCCESS)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } while (retry && stmfIoctl.stmf_error == STMF_IOCERR_INSUFFICIENT_BUF);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret = nvlist_unpack((char *)ppi_out->ppi_data,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi_out->ppi_data_size, nvl, 0)) != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto done;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* caller has asked for new token */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (setToken) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *setToken = ppi_out->ppi_token;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetodone:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto free(ppi_out);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) close(fd);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * setProviderData
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Purpose: set the provider data in stmf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerName - unique name of provider
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nvl - nvlist to set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * providerType - logical unit or port provider
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * setToken - stale data token to check if not NULL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosetProviderData(int fd, char *providerName, nvlist_t *nvl, int providerType,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint64_t *setToken)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ioctlRet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t nvlistEncodedSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_ppioctl_data_t *ppi = NULL;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint64_t outToken;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *allocatedNvBuffer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (providerName == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get size of encoded nvlist */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nvlist_size(nvl, &nvlistEncodedSize, NV_ENCODE_XDR) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate memory for ioctl */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi = (stmf_ppioctl_data_t *)calloc(1, nvlistEncodedSize +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmf_ppioctl_data_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ppi == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_NOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (setToken) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi->ppi_token_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ppi->ppi_token = *setToken;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte allocatedNvBuffer = (char *)&ppi->ppi_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nvlist_pack(nvl, &allocatedNvBuffer, &nvlistEncodedSize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NV_ENCODE_XDR, 0) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set provider name and provider type */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(ppi->ppi_name, providerName, sizeof (ppi->ppi_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (providerType) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_LU_PROVIDER_TYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi->ppi_lu_provider = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_PORT_PROVIDER_TYPE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi->ppi_port_provider = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set the size of the ioctl data to packed data size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ppi->ppi_data_size = nvlistEncodedSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&stmfIoctl, sizeof (stmfIoctl));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_version = STMF_VERSION_1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Subtracting 8 from the size as that is the size of the last member
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of the structure where the packed data resides
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf_size = nvlistEncodedSize +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmf_ppioctl_data_t) - 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)ppi;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf_size = sizeof (uint64_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&outToken;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ioctlRet = ioctl(fd, STMF_IOCTL_LOAD_PP_DATA, &stmfIoctl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctlRet != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (errno) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EBUSY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EPERM:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case EINVAL:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (stmfIoctl.stmf_error ==
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_IOCERR_PPD_UPDATED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PROV_DATA_STALE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_STATUS_ERROR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "setProviderData:ioctl errno(%d)", errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_STATUS_ERROR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* caller has asked for new token */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (setToken) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *setToken = outToken;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ppi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * set the persistence method in the library only or library and service
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfSetPersistMethod(uint8_t persistType, boolean_t serviceSet)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int oldPersist;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) pthread_mutex_lock(&persistenceTypeLock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto oldPersist = iPersistType;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (persistType == STMF_PERSIST_NONE ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto persistType == STMF_PERSIST_SMF) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iLibSetPersist = B_TRUE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iPersistType = persistType;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) pthread_mutex_unlock(&persistenceTypeLock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Is this for this library open or in SMF */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (serviceSet == B_TRUE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psSetServicePersist(persistType);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_PS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERSIST_TYPE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Set to old value */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto iPersistType = oldPersist;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) pthread_mutex_unlock(&persistenceTypeLock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Only returns internal state for persist. If unset, goes to ps. If that
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * fails, returns default setting
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic uint8_t
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoiGetPersistMethod()
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t persistType = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) pthread_mutex_lock(&persistenceTypeLock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iLibSetPersist) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto persistType = iPersistType;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psGetServicePersist(&persistType);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_PS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* set to default */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto persistType = STMF_DEFAULT_PERSIST;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) pthread_mutex_unlock(&persistenceTypeLock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (persistType);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Returns either library state or persistent config state depending on
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * serviceState
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoint
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostmfGetPersistMethod(uint8_t *persistType, boolean_t serviceState)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret = STMF_STATUS_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (persistType == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (STMF_ERROR_INVALID_ARG);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (serviceState) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = psGetServicePersist(persistType);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ret != STMF_PS_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = STMF_ERROR_PERSIST_TYPE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) pthread_mutex_lock(&persistenceTypeLock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (iLibSetPersist) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *persistType = iPersistType;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *persistType = STMF_DEFAULT_PERSIST;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (void) pthread_mutex_unlock(&persistenceTypeLock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (ret);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * stmfPostProxyMsg
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose: Post a message to the proxy port provider
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * buf - buffer containing message to post
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * buflen - buffer length
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortestmfPostProxyMsg(int hdl, void *buf, uint32_t buflen)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = STMF_STATUS_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ioctlRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_iocdata_t ppptIoctl = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (buf == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Issue ioctl to post the message
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ppptIoctl.pppt_version = PPPT_VERSION_1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ppptIoctl.pppt_buf_size = buflen;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ppptIoctl.pppt_buf = (uint64_t)(unsigned long)buf;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ioctlRet = ioctl(hdl, PPPT_MESSAGE, &ppptIoctl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ioctlRet != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (errno) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EPERM:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EACCES:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_PERM;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_POST_MSG_FAILED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * stmfInitProxyDoor
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Purpose: Install door in proxy
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * hdl - pointer to returned handle
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * fd - door from door_create()
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortestmfInitProxyDoor(int *hdl, int door)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = STMF_STATUS_SUCCESS;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ioctlRet;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int fd;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_iocdata_t ppptIoctl = {0};
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (hdl == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (STMF_ERROR_INVALID_ARG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Open control node for pppt
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((ret = openPppt(OPEN_PPPT, &fd)) != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Issue ioctl to install the door
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ppptIoctl.pppt_version = PPPT_VERSION_1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ppptIoctl.pppt_door_fd = (uint32_t)door;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ioctlRet = ioctl(fd, PPPT_INSTALL_DOOR, &ppptIoctl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ioctlRet != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (errno) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EPERM:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EACCES:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_PERM;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EINVAL:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_INVALID_ARG;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case EBUSY:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_ERROR_DOOR_INSTALLED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = STMF_STATUS_ERROR;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* return driver fd to caller */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *hdl = fd;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortestmfDestroyProxyDoor(int hdl)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) close(hdl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto/*
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * validateLunNumIoctl
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto *
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * Purpose: Issues ioctl to check and get available lun# in view entry
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto *
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * viewEntry - view entry to use
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetostatic int
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetovalidateLunNumIoctl(int fd, stmfViewEntry *viewEntry)
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto{
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto int ret = STMF_STATUS_SUCCESS;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto int ioctlRet;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_iocdata_t stmfIoctl;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmf_view_op_entry_t ioctlViewEntry;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bzero(&ioctlViewEntry, sizeof (ioctlViewEntry));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /*
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * don't set ve_ndx or ve_ndx_valid as ve_ndx_valid should be
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * false on input
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ioctlViewEntry.ve_lu_number_valid = viewEntry->luNbrValid;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ioctlViewEntry.ve_all_hosts = viewEntry->allHosts;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ioctlViewEntry.ve_all_targets = viewEntry->allTargets;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (viewEntry->allHosts == B_FALSE) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(viewEntry->hostGroup, &ioctlViewEntry.ve_host_group.name,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (stmfGroupName));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ioctlViewEntry.ve_host_group.name_size =
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto strlen((char *)viewEntry->hostGroup);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (viewEntry->allTargets == B_FALSE) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(viewEntry->targetGroup,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto &ioctlViewEntry.ve_target_group.name,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (stmfGroupName));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ioctlViewEntry.ve_target_group.name_size =
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto strlen((char *)viewEntry->targetGroup);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* Validating the lun number */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (viewEntry->luNbrValid) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(viewEntry->luNbr, &ioctlViewEntry.ve_lu_nbr,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (ioctlViewEntry.ve_lu_nbr));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bzero(&stmfIoctl, sizeof (stmfIoctl));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /*
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * Issue ioctl to validate lun# in the view entry
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmfIoctl.stmf_version = STMF_VERSION_1;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmfIoctl.stmf_ibuf_size = sizeof (ioctlViewEntry);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmfIoctl.stmf_ibuf = (uint64_t)(unsigned long)&ioctlViewEntry;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmfIoctl.stmf_obuf_size = sizeof (ioctlViewEntry);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmfIoctl.stmf_obuf = (uint64_t)(unsigned long)&ioctlViewEntry;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ioctlRet = ioctl(fd, STMF_IOCTL_VALIDATE_VIEW, &stmfIoctl);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* save available lun number */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (!viewEntry->luNbrValid) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(ioctlViewEntry.ve_lu_nbr, viewEntry->luNbr,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (ioctlViewEntry.ve_lu_nbr));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (ioctlRet != 0) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto switch (errno) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case EBUSY:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_BUSY;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case EPERM:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_PERM;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case EACCES:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto switch (stmfIoctl.stmf_error) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case STMF_IOCERR_UPDATE_NEED_CFG_INIT:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_CONFIG_NONE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto default:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_PERM;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto default:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto switch (stmfIoctl.stmf_error) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case STMF_IOCERR_LU_NUMBER_IN_USE:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_LUN_IN_USE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case STMF_IOCERR_VIEW_ENTRY_CONFLICT:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_VE_CONFLICT;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case STMF_IOCERR_UPDATE_NEED_CFG_INIT:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_CONFIG_NONE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case STMF_IOCERR_INVALID_HG:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_INVALID_HG;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto case STMF_IOCERR_INVALID_TG:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_ERROR_INVALID_TG;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto default:
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto syslog(LOG_DEBUG,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto "addViewEntryIoctl"
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ":error(%d)",
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmfIoctl.stmf_error);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = STMF_STATUS_ERROR;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto break;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (ret);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto}
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto/*
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * stmfValidateView
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto *
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * Purpose: Validate or get lun # base on TG, HG of view entry
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto *
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * viewEntry - view entry structure to use
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetoint
63ed874a56e20df7e4ec98ba42582352d87386c5tim szetostmfValidateView(stmfViewEntry *viewEntry)
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto{
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto int ret;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto int fd;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto stmfViewEntry iViewEntry;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (viewEntry == NULL) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (STMF_ERROR_INVALID_ARG);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* initialize and set internal view entry */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bzero(&iViewEntry, sizeof (iViewEntry));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (!viewEntry->allHosts) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(viewEntry->hostGroup, iViewEntry.hostGroup,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (iViewEntry.hostGroup));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto } else {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto iViewEntry.allHosts = B_TRUE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (!viewEntry->allTargets) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(viewEntry->targetGroup, iViewEntry.targetGroup,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (iViewEntry.targetGroup));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto } else {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto iViewEntry.allTargets = B_TRUE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (viewEntry->luNbrValid) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto iViewEntry.luNbrValid = B_TRUE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(viewEntry->luNbr, iViewEntry.luNbr,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (iViewEntry.luNbr));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /*
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * set users return view entry index valid flag to false
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * in case of failure
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto viewEntry->veIndexValid = B_FALSE;
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* Check to ensure service exists */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (psCheckService() != STMF_STATUS_SUCCESS) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (STMF_ERROR_SERVICE_NOT_FOUND);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* call init */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = initializeConfig();
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (ret != STMF_STATUS_SUCCESS) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (ret);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /*
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * Open control node for stmf
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if ((ret = openStmf(OPEN_STMF, &fd)) != STMF_STATUS_SUCCESS)
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (ret);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /*
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto * Validate lun# in the view entry from the driver
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto ret = validateLunNumIoctl(fd, &iViewEntry);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto (void) close(fd);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto /* save available lun number */
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto if (!viewEntry->luNbrValid) {
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto bcopy(iViewEntry.luNbr, viewEntry->luNbr,
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto sizeof (iViewEntry.luNbr));
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto }
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto return (ret);
63ed874a56e20df7e4ec98ba42582352d87386c5tim szeto}