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 #include <libdevinfo.h>
34
35
getOidList(di_node_t root_node,MP_OID_LIST * pOidList)36 static int getOidList(di_node_t root_node, MP_OID_LIST *pOidList)
37 {
38 int numNodes = 0;
39 int instNum = 0;
40 int majorNum = 0;
41
42 di_node_t vh_node = DI_NODE_NIL;
43 di_node_t ph_node = DI_NODE_NIL;
44
45 MP_UINT64 osn = 0;
46
47 int haveList = (NULL != pOidList);
48
49
50 log(LOG_INFO, "getOidList()", " - enter");
51
52 vh_node = di_vhci_first_node(root_node);
53
54 while (DI_NODE_NIL != vh_node) {
55 if ((di_driver_name(vh_node) != NULL) &&
56 (strncmp(di_driver_name(vh_node), "scsi_vhci", 9) == 0)) {
57 ph_node = di_phci_first_node(vh_node);
58 while (DI_NODE_NIL != ph_node) {
59 if (haveList) {
60
61 instNum = di_instance(ph_node);
62 majorNum = di_driver_major(ph_node);
63
64 log(LOG_INFO, "getOidList()",
65 "instNum = %d",
66 instNum);
67
68 log(LOG_INFO, "getOidList()",
69 "majorNum = %d",
70 majorNum);
71
72 if (numNodes < pOidList->oidCount) {
73
74 osn = 0;
75
76 osn =
77 MP_STORE_INST_TO_ID(instNum,
78 osn);
79
80 osn =
81 MP_STORE_MAJOR_TO_ID(majorNum,
82 osn);
83
84 pOidList->oids[numNodes]
85 .objectSequenceNumber =
86 osn;
87
88 pOidList->oids[numNodes].
89 objectType =
90 MP_OBJECT_TYPE_INITIATOR_PORT;
91
92 pOidList->oids[numNodes].
93 ownerId =
94 g_pluginOwnerID;
95 }
96 }
97
98 ++numNodes;
99 ph_node = di_phci_next_node(ph_node);
100 }
101
102 }
103 vh_node = di_vhci_next_node(vh_node);
104 }
105
106 log(LOG_INFO,
107 "getOidList()",
108 " - numNodes: %d",
109 numNodes);
110
111
112 log(LOG_INFO, "getOidList()", " - exit");
113
114 return (numNodes);
115 }
116
117
118
119 MP_STATUS
MP_GetInitiatorPortOidListPlugin(MP_OID_LIST ** ppList)120 MP_GetInitiatorPortOidListPlugin(MP_OID_LIST **ppList)
121 {
122 di_node_t root_node = DI_NODE_NIL;
123
124 int i = 0;
125 int numNodes = 0;
126
127
128
129 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()", " - enter");
130
131
132 root_node = di_init("/", DINFOCACHE);
133 if (DI_NODE_NIL == root_node) {
134 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
135 " - di_init() failed");
136
137 return (MP_STATUS_FAILED);
138 }
139
140 numNodes = getOidList(root_node, NULL);
141
142 if (numNodes < 1) {
143
144 *ppList = createOidList(1);
145
146 if (NULL == *ppList) {
147 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
148 "no memory for *ppList");
149 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
150 " - error exit");
151 return (MP_STATUS_INSUFFICIENT_MEMORY);
152 }
153
154 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
155 " - returning empty list.");
156
157 return (MP_STATUS_SUCCESS);
158 }
159
160 *ppList = createOidList(numNodes);
161 if (NULL == *ppList) {
162 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
163 "no memory for *ppList");
164 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
165 " - error exit");
166 return (MP_STATUS_INSUFFICIENT_MEMORY);
167 }
168
169 (*ppList)->oidCount = numNodes;
170
171 numNodes = getOidList(root_node, *ppList);
172
173 for (i = 0; i < (*ppList)->oidCount; i++) {
174
175 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
176 "(*ppList)->oids[%d].objectType = %d",
177 i, (*ppList)->oids[i].objectType);
178 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
179 "(*ppList)->oids[%d].ownerId = %d",
180 i, (*ppList)->oids[i].ownerId);
181 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
182 "(*ppList)->oids[%d].objectSequenceNumber = %llx",
183 i, (*ppList)->oids[i].objectSequenceNumber);
184 }
185
186
187 di_fini(root_node);
188
189
190 log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()", " - exit");
191
192 return (MP_STATUS_SUCCESS);
193 }
194