stmf.c revision 3e7352aecf183df6c5f819be775df62aadcdfd08
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/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
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>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stmf_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STMF_PATH "/devices/pseudo/stmf@0:admin"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define EUI "eui."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WWN "wwn."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IQN "iqn."
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define WWN_ASCII_SIZE 16
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define IDENT_LENGTH_BYTE 3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_LU 2<<16 - 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_TARGET_PORT 1024
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_PROVIDER 1024
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_GROUP 1024
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_SESSION 1024
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAX_ISCSI_NAME 223
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define OPEN_STMF 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define OPEN_EXCL_STMF O_EXCL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define LOGICAL_UNIT_TYPE 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define TARGET_TYPE 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define STMF_SERVICE_TYPE 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int openStmf(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);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int setProviderData(int fd, char *, nvlist_t *, int);
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;
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
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) {
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/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * groupIoctl
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:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_BUSY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
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
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
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 stmfState state;
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 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 /* 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
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;
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
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;
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
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
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/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfCreateTargetGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Create a local port group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetGroupName - name of local port group to create
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfCreateTargetGroup(stmfGroupName *targetGroupName)
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))) {
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 /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add the group to the driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_CREATE_TARGET_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetGroupName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the add to the driver was successful, add it to the persistent
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psCreateTargetGroup((char *)targetGroupName);
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 "stmfCreateTargetGroup:psCreateTargetGroup"
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 * stmfDeleteHostGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Delete an initiator or local port group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hostGroupName - group to delete
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfDeleteHostGroup(stmfGroupName *hostGroupName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hostGroupName == NULL) {
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 /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove the group from the driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_REMOVE_HOST_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hostGroupName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the remove from the driver was successful, remove it from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * persistent store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psDeleteHostGroup((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_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 "stmfDeleteHostGroup:psDeleteHostGroup: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 * stmfDeleteTargetGroup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Delete an initiator or local port group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * targetGroupName - group to delete
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfDeleteTargetGroup(stmfGroupName *targetGroupName)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = STMF_STATUS_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (targetGroupName == NULL) {
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 /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove the group from the driver
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ret = groupIoctl(fd, STMF_IOCTL_REMOVE_TARGET_GROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetGroupName)) != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the remove from the driver was successful, remove it from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * persistent store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psDeleteTargetGroup((char *)targetGroupName);
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 "stmfDeleteTargetGroup:psDeleteTargetGroup"
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 * stmfDevidFromIscsiName
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: convert an iSCSI name to an stmf devid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsiName - unicode nul terminated utf-8 encoded iSCSI name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid - on success, contains the converted iscsi name
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfDevidFromIscsiName(char *iscsiName, stmfDevid *devid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (devid == NULL || iscsiName == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(devid, sizeof (stmfDevid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Validate size of target */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((devid->identLength = strlen(iscsiName)) > MAX_ISCSI_NAME ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength < strlen(EUI) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength < strlen(IQN)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strncmp(iscsiName, EUI, strlen(EUI)) != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(iscsiName, IQN, strlen(IQN)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy UTF-8 bytes to ident */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(iscsiName, devid->ident, devid->identLength);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfDevidFromWwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: convert a WWN to an stmf devid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wwn - 8-byte wwn identifier
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * devid - on success, contains the converted wwn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfDevidFromWwn(uchar_t *wwn, stmfDevid *devid)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (wwn == NULL || devid == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(devid, sizeof (stmfDevid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy eui prefix */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) bcopy(WWN, devid->ident, strlen(WWN));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Convert to ASCII uppercase hexadecimal string */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) snprintf((char *)&devid->ident[strlen(WWN)],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (devid->ident), "%02X%02X%02X%02X%02X%02X%02X%02X",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wwn[0], wwn[1], wwn[2], wwn[3], wwn[4], wwn[5], wwn[6], wwn[7]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte devid->identLength = strlen((char *)devid->ident);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfFreeMemory
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Free memory allocated by this library
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * memory - previously allocated pointer of memory managed by library
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfFreeMemory(void *memory)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(memory);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetHostGroupList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the list of initiator group oids
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * hostGroupList - pointer to pointer to hostGroupList structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on success, this contains the host group list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetHostGroupList(stmfGroupList **hostGroupList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hostGroupList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetHostGroupList(hostGroupList);
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 "stmfGetHostGroupList:psGetHostGroupList:error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetHostGroupMemberList((char *)groupName, groupProp);
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 "stmfGetHostGroupMembers:psGetHostGroupMembers"
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 * 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
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 ret = psGetProviderData(providerName, nvl, providerType, setToken);
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_NOT_FOUND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOT_FOUND;
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 "stmfGetProviderData:psGetProviderData:error(%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 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 * 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;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slist_scsi_session_t *fSessionList;
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionListSize = MAX_SESSION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionListSize = fSessionListSize * (sizeof (slist_scsi_session_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fSessionList = (slist_scsi_session_t *)calloc(1, fSessionListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fSessionList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_NOMEM);
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;
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmfIoctl.stmf_obuf_max_nentries > MAX_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) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_NOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
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;
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);
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetTargetGroupList(targetGroupList);
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 "stmfGetTargetGroupList:psGetTargetGroupList:"
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 * 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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetTargetGroupMemberList((char *)groupName, groupProp);
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 "stmfGetTargetGroupMembers:psGetTargetGroupMembers:"
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 * 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 */
3e7352aecf183df6c5f819be775df62aadcdfd08John Forte slist_target_port_t *fTargetList, *fTargetListP;
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fTargetListSize = MAX_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) {
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;
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmfIoctl.stmf_obuf_max_nentries > MAX_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) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_NOMEM);
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;
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));
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;
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;
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));
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;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, k;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_iocdata_t stmfIoctl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* framework lu list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte slist_lu_t *fLuList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* persistent store lu list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfGuidList *sLuList = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int finalListSize = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int newAllocSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t fLuListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t endList;
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuListSize = MAX_LU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuListSize = fLuListSize * (sizeof (slist_lu_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuList = (slist_lu_t *)calloc(1, fLuListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fLuList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_NOMEM);
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;
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmfIoctl.stmf_obuf_max_nentries > MAX_LU) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuListSize = stmfIoctl.stmf_obuf_max_nentries *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (slist_lu_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fLuList = realloc(fLuList, fLuListSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fLuList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_NOMEM);
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;
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 ret = psGetLogicalUnitList(&sLuList);
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 "stmfGetLogicalUnitList:psGetLogicalUnitList"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ":error(%d)", ret);
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2 lists must be merged
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reallocate the store list to add the list from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * framework
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newAllocSize = sLuList->cnt * sizeof (stmfGuid) + sizeof (stmfGuidList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte + stmfIoctl.stmf_obuf_nentries * sizeof (stmfGuid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sLuList = realloc(sLuList, newAllocSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sLuList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add list from ioctl. Start from end of list retrieved from store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte endList = sLuList->cnt + stmfIoctl.stmf_obuf_nentries;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (k = 0, i = sLuList->cnt; i < endList; i++, k++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&fLuList[k].lu_guid, sLuList->guid[i].guid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sLuList->cnt = endList;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sort the list for merging
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte qsort((void *)&(sLuList->guid[0]), sLuList->cnt,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGuid), guidCompare);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get final list count
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < sLuList->cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((i + 1) <= sLuList->cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(sLuList->guid[i].guid, sLuList->guid[i+1].guid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGuid)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte finalListSize++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate caller's buffer with the final size
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *luList = (stmfGuidList *)calloc(1, sizeof (stmfGuidList) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte finalListSize * sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*luList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_NOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * copy guids to caller's buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (k = 0, i = 0; i < sLuList->cnt; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((i + 1) <= sLuList->cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(sLuList->guid[i].guid, sLuList->guid[i+1].guid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGuid)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&(sLuList->guid[i].guid), (*luList)->guid[k++].guid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (stmfGuid));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*luList)->cnt = finalListSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free internal buffers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(fLuList);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(sLuList);
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (luProps == NULL || luProps == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = 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;
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = getStmfState(&iState);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (iState.state) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_STATE_ONLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->operationalState =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SERVICE_STATE_ONLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_STATE_OFFLINE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->operationalState =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SERVICE_STATE_OFFLINE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_STATE_ONLINING:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->operationalState =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SERVICE_STATE_ONLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_STATE_OFFLINING:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->operationalState =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SERVICE_STATE_OFFLINING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->operationalState =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SERVICE_STATE_UNKNOWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (iState.config_state) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CONFIG_NONE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->configState = STMF_CONFIG_STATE_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CONFIG_INIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->configState = STMF_CONFIG_STATE_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CONFIG_INIT_DONE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->configState =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_CONFIG_STATE_INIT_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte state->configState =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_CONFIG_STATE_UNKNOWN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * stmfGetViewEntryList
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Purpose: Retrieves the list of view entries for the specified
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * logical unit.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lu - the guid of the logical unit for which to retrieve the view entry list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * viewEntryList - a pointer to a pointer to a stmfViewEntryList structure. On
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * success, contains the list of view entries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortestmfGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lu == NULL || viewEntryList == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ERROR_INVALID_ARG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psGetViewEntryList(lu, 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 syslog(LOG_DEBUG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "stmfGetViewEntryList: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 * 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 }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetHostGroupMembers(&(groupList->name[i]),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &groupProps);
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 }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetTargetGroupMembers(&(groupList->name[i]),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &groupProps);
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetHostGroupList(&groupList);
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = stmfGetTargetGroupList(&groupList);
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,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 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 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
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{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_state_desc_t stmfStateSet;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmfState state;
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 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
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;
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}
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
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
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;
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
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = setProviderData(fd, providerName, nvl, providerType);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret != STMF_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setting driver provider data successful. Now persist it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = psSetProviderData(providerName, nvl, providerType, setToken);
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * setProviderData
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 - logical unit or port provider
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn FortesetProviderData(int fd, char *providerName, nvlist_t *nvl, int providerType)
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;
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
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;
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;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case EACCES:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = STMF_ERROR_PERM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ppi);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}