1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#include "mp_utils.h"
#include <sys/sunddi.h>
#ifndef OIDLIST
#define OIDLIST "oid"
#endif
/* Remove these 5 when this source can compile with sunddi.h */
#ifndef EC_DDI
#define EC_DDI "EC_ddi"
#endif
#ifndef ESC_DDI_INITIATOR_REGISTER
#define ESC_DDI_INITIATOR_REGISTER "ESC_ddi_initiator_register"
#endif
#ifndef ESC_DDI_INITIATOR_UNREGISTER
#define ESC_DDI_INITIATOR_UNREGISTER "ESC_ddi_initiator_unregister"
#endif
#ifndef DDI_DRIVER_MAJOR
#define DDI_DRIVER_MAJOR "ddi.major"
#endif
#ifndef DDI_INSTANCE
#define DDI_INSTANCE "ddi.instance"
#endif
#define VISA_CHANGE 1
#define PROP_CHANGE 2
MP_STATUS
getStatus4ErrorCode(int driverError)
{
MP_STATUS mpStatus = MP_STATUS_FAILED;
log(LOG_INFO, "getStatus4ErrorCode()", "- enter");
switch (driverError) {
case MP_DRVR_INVALID_ID:
log(LOG_INFO, "getStatus4ErrorCode()",
" received mp_errno=MP_DRVR_INVALID_ID"
" from driver call.");
log(LOG_INFO, "getStatus4ErrorCode()",
" returning MP_STATUS_OBJECT_NOT_FOUND"
" to caller.");
mpStatus = MP_STATUS_OBJECT_NOT_FOUND;
break;
case MP_DRVR_ID_OBSOLETE:
log(LOG_INFO, "getStatus4ErrorCode()",
" received mp_errno=MP_DRVR_ID_OBSOLETE"
" from driver call.");
log(LOG_INFO, "getStatus4ErrorCode()",
" returning MP_STATUS_OBJECT_NOT_FOUND"
" to caller.");
mpStatus = MP_STATUS_OBJECT_NOT_FOUND;
break;
case MP_DRVR_ACCESS_SYMMETRIC:
log(LOG_INFO, "getStatus4ErrorCode()",
" received mp_errno=MP_DRVR_ACCESS_SYMMETRIC"
" from driver call.");
log(LOG_INFO, "getStatus4ErrorCode()",
" returning MP_STATUS_INVALID_PARAMETER"
" to caller.");
mpStatus = MP_STATUS_INVALID_PARAMETER;
break;
case MP_DRVR_PATH_UNAVAILABLE:
log(LOG_INFO, "getStatus4ErrorCode()",
" received mp_errno=MP_DRVR_PATH_UNAVAILABLE"
" from driver call.");
log(LOG_INFO, "getStatus4ErrorCode()",
" returning MP_STATUS_PATH_NONOPERATIONAL"
" to caller.");
mpStatus = MP_STATUS_PATH_NONOPERATIONAL;
break;
case MP_DRVR_IDS_NOT_ASSOCIATED:
log(LOG_INFO, "getStatus4ErrorCode()",
" received mp_errno=MP_DRVR_IDS_NOT_ASSOCIATED"
" from driver call.");
log(LOG_INFO, "getStatus4ErrorCode()",
" returning MP_STATUS_INVALID_PARAMETER"
" to caller.");
mpStatus = MP_STATUS_INVALID_PARAMETER;
break;
case MP_DRVR_ILLEGAL_ACCESS_STATE_REQUEST:
log(LOG_INFO, "getStatus4ErrorCode()",
" received mp_errno="
"MP_DRVR_ILLEGAL_ACCESS_STATE_REQUEST"
" from driver call.");
log(LOG_INFO, "getStatus4ErrorCode()",
" returning MP_STATUS_INVALID_PARAMETER"
" to caller.");
mpStatus = MP_STATUS_ACCESS_STATE_INVALID;
break;
default:
log(LOG_INFO, "getStatus4ErrorCode()",
" - received (unsupported) mp_errno=%d from"
" driver call.", driverError);
log(LOG_INFO, "getStatus4ErrorCode()",
" - returning MP_STATUS_FAILED to caller.");
mpStatus = MP_STATUS_FAILED;
}
log(LOG_INFO, "getStatus4ErrorCode()", "- exit");
return (mpStatus);
}
MP_OID_LIST
*createOidList(int size) {
MP_OID_LIST *pOidList = NULL;
log(LOG_INFO, "createOidList()", "- enter");
if (size < 1) {
log(LOG_INFO, "createOidList()",
"requested size is less than 1");
log(LOG_INFO, "createOidList()",
" - error exit");
return (NULL);
} else {
pOidList = (MP_OID_LIST*)calloc(1,
sizeof (MP_OID_LIST) +
((size - 1) *
sizeof (MP_OID)));
if (NULL == pOidList) {
log(LOG_INFO, "createOidList()",
"no memory for pOidList");
log(LOG_INFO, "createOidList()",
" - error exit");
return (NULL);
}
log(LOG_INFO,
"createOidList()",
"- exit(%d)",
size);
return (pOidList);
}
}
/* Calls the client callback function, if one is registered */
static void
notifyClient(sysevent_t *ev)
{
nvlist_t *attr_list = NULL;
uint64_t *val = NULL;
int32_t *instance = NULL;
int32_t *major = NULL;
int valAllocated = 0;
uint_t nelem = 0;
int i = 0;
int eventType = 0;
int index = -1;
void *pCallerData = NULL;
char subClassName[256];
MP_BOOL becomingVisible = MP_FALSE;
MP_OID_LIST *oidList = NULL;
log(LOG_INFO, "notifyClient()", "- enter");
(void) strncpy(subClassName, sysevent_get_subclass_name(ev), 256);
if (strstr(subClassName, "change")) {
eventType = PROP_CHANGE;
log(LOG_INFO, "notifyClient()", "- got a change event");
log(LOG_INFO, "notifyClient()", ": [%s]",
subClassName);
if (strncmp(subClassName, ESC_SUN_MP_PLUGIN_CHANGE, 255)
== 0) {
index = MP_OBJECT_TYPE_PLUGIN;
} else if (strncmp(subClassName, ESC_SUN_MP_LU_CHANGE, 255)
== 0) {
index = MP_OBJECT_TYPE_MULTIPATH_LU;
} else if (strncmp(subClassName, ESC_SUN_MP_PATH_CHANGE, 255)
== 0) {
index = MP_OBJECT_TYPE_PATH_LU;
} else if (strncmp(subClassName, ESC_SUN_MP_INIT_PORT_CHANGE,
255) == 0) {
index = MP_OBJECT_TYPE_INITIATOR_PORT;
} else if (strncmp(subClassName, ESC_SUN_MP_TPG_CHANGE, 255)
== 0) {
index = MP_OBJECT_TYPE_TARGET_PORT_GROUP;
} else if (strncmp(subClassName, ESC_SUN_MP_TARGET_PORT_CHANGE,
255) == 0) {
index = MP_OBJECT_TYPE_TARGET_PORT;
} else if (strncmp(subClassName, ESC_SUN_MP_DEV_PROD_CHANGE,
255) == 0) {
index = MP_OBJECT_TYPE_DEVICE_PRODUCT;
}
} else if ((strstr(subClassName, "add")) ||
(strstr(subClassName, "initiator_register"))) {
eventType = VISA_CHANGE;
becomingVisible = MP_TRUE;
log(LOG_INFO, "notifyClient()", "- got a visibility"
" add event");
log(LOG_INFO, "notifyClient()", ": [%s]",
subClassName);
if (strncmp(subClassName, ESC_SUN_MP_LU_ADD, 255) == 0) {
index = MP_OBJECT_TYPE_MULTIPATH_LU;
} else if (strncmp(subClassName, ESC_SUN_MP_PATH_ADD, 255)
== 0) {
index = MP_OBJECT_TYPE_PATH_LU;
} else if (strncmp(subClassName, ESC_DDI_INITIATOR_REGISTER,
244) == 0) {
index = MP_OBJECT_TYPE_INITIATOR_PORT;
} else if (strncmp(subClassName, ESC_SUN_MP_TPG_ADD,
255) == 0) {
index = MP_OBJECT_TYPE_TARGET_PORT_GROUP;
} else if (strncmp(subClassName, ESC_SUN_MP_TARGET_PORT_ADD,
255) == 0) {
index = MP_OBJECT_TYPE_TARGET_PORT;
} else if (strncmp(subClassName, ESC_SUN_MP_DEV_PROD_ADD, 255)
== 0) {
index = MP_OBJECT_TYPE_DEVICE_PRODUCT;
}
} else if ((strstr(subClassName, "remove")) ||
(strstr(subClassName, "initiator_unregister"))) {
eventType = VISA_CHANGE;
becomingVisible = MP_FALSE;
log(LOG_INFO, "notifyClient()", "- got a visibility"
" remove event");
log(LOG_INFO, "notifyClient()", ": [%s]",
subClassName);
if (strncmp(subClassName, ESC_SUN_MP_LU_REMOVE, 255) == 0) {
index = MP_OBJECT_TYPE_MULTIPATH_LU;
} else if (strncmp(subClassName, ESC_SUN_MP_PATH_REMOVE, 255)
== 0) {
index = MP_OBJECT_TYPE_PATH_LU;
} else if (strncmp(subClassName, ESC_DDI_INITIATOR_UNREGISTER,
255) == 0) {
index = MP_OBJECT_TYPE_INITIATOR_PORT;
} else if (strncmp(subClassName, ESC_SUN_MP_TPG_REMOVE, 255)
== 0) {
index = MP_OBJECT_TYPE_TARGET_PORT_GROUP;
} else if (strncmp(subClassName, ESC_SUN_MP_TARGET_PORT_REMOVE,
255) == 0) {
index = MP_OBJECT_TYPE_TARGET_PORT;
} else if (strncmp(subClassName, ESC_SUN_MP_DEV_PROD_REMOVE,
255) == 0) {
index = MP_OBJECT_TYPE_DEVICE_PRODUCT;
}
} else {
log(LOG_INFO, "notifyClient()", "- got an unsupported event");
return;
}
if (index < 0) {
log(LOG_INFO, "notifyClient()", "- index is less than zero");
return;
}
if (eventType == VISA_CHANGE) {
(void) pthread_mutex_lock(&g_visa_mutex);
if (NULL == g_Visibility_Callback_List[index].pClientFn) {
log(LOG_INFO, "notifyClient()",
"- no visibility change callback to notify");
(void) pthread_mutex_unlock(&g_visa_mutex);
return;
}
(void) pthread_mutex_unlock(&g_visa_mutex);
}
if (eventType == PROP_CHANGE) {
(void) pthread_mutex_lock(&g_prop_mutex);
if (NULL == g_Property_Callback_List[index].pClientFn) {
log(LOG_INFO, "notifyClient()",
"- no property change callback to notify");
(void) pthread_mutex_unlock(&g_prop_mutex);
return;
}
(void) pthread_mutex_unlock(&g_prop_mutex);
}
(void) sysevent_get_attr_list(ev, &attr_list);
if (NULL != attr_list) {
if ((VISA_CHANGE == eventType) &&
(MP_OBJECT_TYPE_PLUGIN == index)) {
val = (uint64_t *)malloc(sizeof (uint64_t));
valAllocated = 1;
/*
* We have no well-defined way to determine our OSN.
* Currently the common library uses 0 as OSN for every
* plugin, so just use 0. If the OSN assigned by the
* common library changed, this code would have to be
* updated.
*/
*val = 0;
nelem = 1;
} else if ((VISA_CHANGE == eventType) &&
(MP_OBJECT_TYPE_INITIATOR_PORT == index)) {
(void) nvlist_lookup_int32_array(attr_list,
DDI_INSTANCE, &instance, &nelem);
log(LOG_INFO, "notifyClient()",
"- event (PHCI_INSTANCE) has [%d] elements",
nelem);
(void) nvlist_lookup_int32_array(attr_list,
DDI_DRIVER_MAJOR, &major, &nelem);
log(LOG_INFO, "notifyClient()",
"- event (PHCI_DRIVER_MAJOR) has [%d] elements",
nelem);
if ((NULL != instance) & (NULL != major)) {
val = (uint64_t *)malloc(sizeof (uint64_t));
valAllocated = 1;
*val = 0;
*val = MP_STORE_INST_TO_ID(*instance, *val);
*val = MP_STORE_MAJOR_TO_ID(*major, *val);
nelem = 1;
} else {
nelem = 0;
}
} else {
(void) nvlist_lookup_uint64_array(attr_list, OIDLIST,
&val, &nelem);
log(LOG_INFO, "notifyClient()",
"- event has [%d] elements",
nelem);
}
if (nelem > 0) {
for (i = 0; i < nelem; i++) {
log(LOG_INFO, "notifyClient()",
"- event [%d] = %llx",
i, val[i]);
}
oidList = createOidList(nelem);
if (NULL == oidList) {
log(LOG_INFO, "notifyClient()",
"- unable to create MP_OID_LIST");
log(LOG_INFO, "notifyClient()",
"- error exit");
nvlist_free(attr_list);
return;
}
oidList->oidCount = nelem;
for (i = 0; i < nelem; i++) {
oidList->oids[i].objectType = index;
oidList->oids[i].ownerId = g_pluginOwnerID;
oidList->oids[i].objectSequenceNumber = val[i];
}
if (valAllocated) {
free(val);
}
for (i = 0; i < oidList->oidCount; i++) {
log(LOG_INFO, "notifyClient()",
"oidList->oids[%d].objectType"
" = %d",
i, oidList->oids[i].objectType);
log(LOG_INFO, "notifyClient()",
"oidList->oids[%d].ownerId"
" = %d",
i, oidList->oids[i].ownerId);
log(LOG_INFO, "notifyClient()",
"oidList->oids[%d].objectSequenceNumber"
" = %llx",
i, oidList->oids[i].objectSequenceNumber);
}
if (eventType == PROP_CHANGE) {
(void) pthread_mutex_lock(&g_prop_mutex);
pCallerData = g_Property_Callback_List[index].
pCallerData;
(g_Property_Callback_List[index].pClientFn)
(oidList, pCallerData);
(void) pthread_mutex_unlock(&g_prop_mutex);
} else if (eventType == VISA_CHANGE) {
(void) pthread_mutex_lock(&g_visa_mutex);
pCallerData = g_Visibility_Callback_List[index].
pCallerData;
(g_Visibility_Callback_List[index].pClientFn)
(becomingVisible, oidList, pCallerData);
(void) pthread_mutex_unlock(&g_visa_mutex);
}
}
nvlist_free(attr_list);
}
log(LOG_INFO, "notifyClient()", "- exit");
}
/* Event handler called by system */
static void
sysevent_handler(sysevent_t *ev)
{
log(LOG_INFO, "sysevent_handler()", "- enter");
/* Is the event one of ours? */
if ((strncmp(EC_SUN_MP, sysevent_get_class_name(ev), 9) != 0) &&
(strncmp(EC_DDI, sysevent_get_class_name(ev), 6) != 0)) {
return;
}
/* Notify client if it cares */
notifyClient(ev);
log(LOG_INFO, "sysevent_handler()", "- exit");
}
/* Registers the plugin to the sysevent framework */
MP_STATUS
init_sysevents(void) {
const char *subclass_list[] = {
ESC_SUN_MP_PLUGIN_CHANGE,
ESC_SUN_MP_LU_CHANGE,
ESC_SUN_MP_LU_ADD,
ESC_SUN_MP_LU_REMOVE,
ESC_SUN_MP_PATH_CHANGE,
ESC_SUN_MP_PATH_ADD,
ESC_SUN_MP_PATH_REMOVE,
ESC_SUN_MP_INIT_PORT_CHANGE,
ESC_SUN_MP_TPG_CHANGE,
ESC_SUN_MP_TPG_ADD,
ESC_SUN_MP_TPG_REMOVE,
ESC_SUN_MP_TARGET_PORT_CHANGE,
ESC_SUN_MP_TARGET_PORT_ADD,
ESC_SUN_MP_TARGET_PORT_REMOVE,
ESC_SUN_MP_DEV_PROD_CHANGE,
ESC_SUN_MP_DEV_PROD_ADD,
ESC_SUN_MP_DEV_PROD_REMOVE
};
const char *init_port_subclass_list[] = {
ESC_DDI_INITIATOR_REGISTER,
ESC_DDI_INITIATOR_UNREGISTER
};
log(LOG_INFO, "init_sysevents()", "- enter");
g_SysEventHandle = sysevent_bind_handle(sysevent_handler);
if (g_SysEventHandle == NULL) {
log(LOG_INFO, "init_sysevents()",
"- sysevent_bind_handle() failed");
log(LOG_INFO, "init_sysevents()", "- error exit");
return (MP_STATUS_FAILED);
}
if (sysevent_subscribe_event(g_SysEventHandle, EC_SUN_MP,
subclass_list, sizeof (subclass_list) / sizeof (subclass_list[0]))
!= 0) {
log(LOG_INFO, "init_sysevents()",
"- sysevent_subscribe_event() failed for subclass_list");
log(LOG_INFO, "init_sysevents()", "- error exit");
sysevent_unbind_handle(g_SysEventHandle);
return (MP_STATUS_FAILED);
}
if (sysevent_subscribe_event(g_SysEventHandle, EC_DDI,
init_port_subclass_list, sizeof (init_port_subclass_list) /
sizeof (init_port_subclass_list[0])) != 0) {
log(LOG_INFO, "init_sysevents()",
"- sysevent_subscribe_event() failed "
"for init_port_subclass_list");
log(LOG_INFO, "init_sysevents()", "- error exit");
sysevent_unbind_handle(g_SysEventHandle);
return (MP_STATUS_FAILED);
}
log(LOG_INFO, "init_sysevents()", "- exit");
return (MP_STATUS_SUCCESS);
}
|