xref: /illumos-gate/usr/src/lib/mpapi/libmpscsi_vhci/common/MP_AssignLogicalUnitToTPG.c (revision 628e3cbed6489fa1db545d8524a06cd6535af456)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <syslog.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <stropts.h>
30 
31 #include "mp_utils.h"
32 
33 
34 /*
35  *	Called by the common layer to request the plugin to assign
36  *	a logical unit to a TPG.  luOid is the logical unit to assign
37  *	to the TPG, tpgOid.
38  */
39 
40 MP_STATUS
41 MP_AssignLogicalUnitToTPG(MP_OID tpgOid, MP_OID luOid)
42 {
43 	mp_lu_tpg_pair_t	tpgPair;
44 	mp_iocdata_t		mp_ioctl;
45 
46 	int ioctlStatus = 0;
47 
48 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
49 
50 
51 
52 	log(LOG_INFO, "MP_AssignLogicalUnitToTPG()", " - enter");
53 
54 
55 	log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
56 		"tpgOid.objectSequenceNumber = %llx",
57 		tpgOid.objectSequenceNumber);
58 
59 	log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
60 		"luOid.objectSequenceNumber  = %llx",
61 		luOid.objectSequenceNumber);
62 
63 
64 	if (g_scsi_vhci_fd < 0) {
65 		log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
66 		    "invalid driver file handle");
67 		log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
68 			" - error exit");
69 		return (MP_STATUS_FAILED);
70 	}
71 
72 	(void) memset(&tpgPair, 0, sizeof (mp_lu_tpg_pair_t));
73 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
74 
75 	tpgPair.tpgId = tpgOid.objectSequenceNumber;
76 	tpgPair.luId = luOid.objectSequenceNumber;
77 
78 	mp_ioctl.mp_cmd  = MP_ASSIGN_LU_TO_TPG;
79 	mp_ioctl.mp_ibuf = (caddr_t)&tpgPair;
80 	mp_ioctl.mp_ilen = sizeof (mp_lu_tpg_pair_t);
81 	mp_ioctl.mp_xfer =  MP_XFER_WRITE;
82 
83 	log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
84 		"mp_ioctl.mp_cmd (MP_ASSIGN_LU_TO_TPG) : %d",
85 		mp_ioctl.mp_cmd);
86 
87 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
88 
89 	log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
90 		" IOCTL call returned: %d", ioctlStatus);
91 
92 	if (ioctlStatus < 0) {
93 		ioctlStatus = errno;
94 	}
95 
96 	if (ioctlStatus != 0) {
97 		log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
98 		    "IOCTL call failed.  IOCTL error is: %d",
99 			ioctlStatus);
100 		log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
101 		    "IOCTL call failed.  IOCTL error is: %s",
102 			strerror(ioctlStatus));
103 		log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
104 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
105 			mp_ioctl.mp_errno);
106 
107 		if (ENOTSUP == ioctlStatus) {
108 			mpStatus = MP_STATUS_UNSUPPORTED;
109 		} else if (0 == mp_ioctl.mp_errno) {
110 			mpStatus = MP_STATUS_FAILED;
111 		} else {
112 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
113 		}
114 
115 		log(LOG_INFO, "MP_AssignLogicalUnitToTPG()",
116 			" - error exit, returning %d to caller.", mpStatus);
117 
118 		return (mpStatus);
119 	}
120 
121 
122 	log(LOG_INFO, "MP_AssignLogicalUnitToTPG()", " - exit");
123 
124 	return (MP_STATUS_SUCCESS);
125 }
126