2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#include <string.h>
2N/A#include <syslog.h>
2N/A#include <errno.h>
2N/A#include <unistd.h>
2N/A#include <stropts.h>
2N/A
2N/A
2N/A#include "mp_utils.h"
2N/A
2N/A
2N/A/*
2N/A * Called by the common layer to request the plugin to set the
2N/A * access state for a list of target port groups.
2N/A */
2N/A
2N/AMP_STATUS
2N/AMP_SetTPGAccess(MP_OID oid, MP_UINT32 count,
2N/A MP_TPG_STATE_PAIR *pTpgStateList)
2N/A{
2N/A
2N/A MP_TPG_STATE_PAIR *head = pTpgStateList;
2N/A
2N/A mp_iocdata_t mp_ioctl;
2N/A mp_set_tpg_state_req_t setTpgStateRequest;
2N/A
2N/A int r = 0;
2N/A
2N/A int ioctlStatus = 0;
2N/A
2N/A MP_STATUS mpStatus = MP_STATUS_SUCCESS;
2N/A
2N/A
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()", " - enter");
2N/A
2N/A
2N/A if (NULL == pTpgStateList) {
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "pTpgStateList is NULL");
2N/A
2N/A return (MP_STATUS_INVALID_PARAMETER);
2N/A }
2N/A
2N/A
2N/A if (g_scsi_vhci_fd < 0) {
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "invalid driver file handle");
2N/A log(LOG_INFO, "MP_SetTPGAccess()", " - error exit");
2N/A return (MP_STATUS_FAILED);
2N/A }
2N/A
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "oid.ownerId = %d",
2N/A oid.ownerId);
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "oid.objectType = %d",
2N/A oid.objectType);
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "oid.objectSequenceNumber = %llx",
2N/A oid.objectSequenceNumber);
2N/A
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "count = %d",
2N/A count);
2N/A
2N/A
2N/A for (r = 0; r < count; r++) {
2N/A
2N/A if (head->tpgOid.ownerId != g_pluginOwnerID) {
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "pTpgStateList->tpgOid.ownerId is not for"
2N/A " this plugin");
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "error exit");
2N/A
2N/A return (MP_STATUS_INVALID_PARAMETER);
2N/A }
2N/A
2N/A if (head->tpgOid.objectType !=
2N/A MP_OBJECT_TYPE_TARGET_PORT_GROUP) {
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "pTpgStateList->tpgOid.objectType is not"
2N/A " MP_OBJECT_TYPE_TARGET_PORT_GROUP");
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "error exit");
2N/A
2N/A return (MP_STATUS_INVALID_PARAMETER);
2N/A }
2N/A
2N/A
2N/A head++;
2N/A }
2N/A
2N/A
2N/A head = pTpgStateList;
2N/A
2N/A for (r = 0; r < count; r++) {
2N/A
2N/A (void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
2N/A (void) memset(&setTpgStateRequest, 0,
2N/A sizeof (mp_set_tpg_state_req_t));
2N/A
2N/A setTpgStateRequest.desiredState
2N/A = head->desiredState;
2N/A setTpgStateRequest.luTpgPair.luId
2N/A = oid.objectSequenceNumber;
2N/A setTpgStateRequest.luTpgPair.tpgId
2N/A = head->tpgOid.objectSequenceNumber;
2N/A
2N/A mp_ioctl.mp_cmd = MP_SET_TPG_ACCESS_STATE;
2N/A mp_ioctl.mp_ibuf = (caddr_t)&setTpgStateRequest;
2N/A mp_ioctl.mp_ilen = sizeof (mp_set_tpg_state_req_t);
2N/A mp_ioctl.mp_xfer = MP_XFER_WRITE;
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "mp_ioctl.mp_cmd (MP_SET_TPG_ACCESS_STATE) : %d",
2N/A mp_ioctl.mp_cmd);
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "setTpgStateRequest.luTpgPair.luId = %llx",
2N/A setTpgStateRequest.luTpgPair.luId);
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "setTpgStateRequest.luTpgPair.tpgId = %llx",
2N/A setTpgStateRequest.luTpgPair.tpgId);
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "setTpgStateRequest.desiredState = %d",
2N/A setTpgStateRequest.desiredState);
2N/A
2N/A ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A " IOCTL call returned: %d", ioctlStatus);
2N/A
2N/A if (ioctlStatus < 0) {
2N/A ioctlStatus = errno;
2N/A }
2N/A
2N/A if (ioctlStatus != 0) {
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "IOCTL call failed. IOCTL error is: %d",
2N/A ioctlStatus);
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "IOCTL call failed. IOCTL error is: %s",
2N/A strerror(ioctlStatus));
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A "IOCTL call failed. mp_ioctl.mp_errno: %x",
2N/A mp_ioctl.mp_errno);
2N/A
2N/A if (ENOTSUP == ioctlStatus) {
2N/A mpStatus = MP_STATUS_UNSUPPORTED;
2N/A } else if (0 == mp_ioctl.mp_errno) {
2N/A mpStatus = MP_STATUS_FAILED;
2N/A } else {
2N/A mpStatus =
2N/A getStatus4ErrorCode(mp_ioctl.mp_errno);
2N/A }
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()",
2N/A " - error exit");
2N/A
2N/A return (mpStatus);
2N/A }
2N/A
2N/A head++;
2N/A }
2N/A
2N/A
2N/A log(LOG_INFO, "MP_SetTPGAccess()", " - exit");
2N/A
2N/A return (MP_STATUS_SUCCESS);
2N/A}