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
|
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sun_sas.h>
/*
* Discover an HBA node with matching path.
* The di_node_t argument should be the root of the device tree.
* This routine assumes the locks have been taken
*/
static int
find_matching_hba(di_node_t node, void *arg)
{
int *propData, rval;
walkarg_t *wa = (walkarg_t *)arg;
char *devpath, fulldevpath[MAXPATHLEN];
/* Skip stub(instance -1) nodes */
if (IS_STUB_NODE(node)) {
return (DI_WALK_CONTINUE);
}
rval = di_prop_lookup_ints(DDI_DEV_T_ANY, node,
"sm-hba-supported", &propData);
if (rval < 0) {
return (DI_WALK_CONTINUE);
} else {
if ((devpath = di_devfs_path(node)) == NULL) {
/* still continue to see if there is matching one. */
return (DI_WALK_CONTINUE);
}
(void) snprintf(fulldevpath, MAXPATHLEN, "%s%s", DEVICES_DIR,
devpath);
if ((strstr(fulldevpath, wa->devpath)) != NULL) {
*wa->flag = B_TRUE;
/* Found a node. No need to walk any more. */
di_devfs_path_free(devpath);
return (DI_WALK_TERMINATE);
}
di_devfs_path_free(devpath);
}
return (DI_WALK_CONTINUE);
}
/*
* Refreshes information about an HBA
*
* Note: This routine holds the locks in write mode
* during most of the processing, and as such, will cause
* all other threads to block on entry into the library
* until the refresh is complete. An optimization would be
* to put fine-grain locking in for the open_handle structures.
*/
void
Sun_sasRefreshAdapterConfiguration()
{
const char ROUTINE[] =
"Sun_sasRefreshAdapterConfiguration";
struct sun_sas_hba *hba_ptr;
di_node_t root;
hrtime_t start;
hrtime_t end;
double duration;
walkarg_t wa;
/*
* We're going to be tweaking a lot of global lists, so write
* lock them.
*/
lock(&all_hbas_lock);
lock(&open_handles_lock);
start = gethrtime();
/* Grab device tree */
if ((root = di_init("/", DINFOCACHE)) == DI_NODE_NIL) {
log(LOG_DEBUG, ROUTINE,
"Unable to load device tree for reason \"%s\"",
strerror(errno));
unlock(&open_handles_lock);
unlock(&all_hbas_lock);
return;
}
end = gethrtime();
duration = end - start;
duration /= HR_SECOND;
log(LOG_DEBUG, ROUTINE, "Device tree init took "
"%.6f seconds", duration);
for (hba_ptr = global_hba_head; hba_ptr != NULL;
hba_ptr = hba_ptr->next) {
wa.devpath = hba_ptr->device_path;
wa.flag = (boolean_t *)calloc(1, sizeof (boolean_t));
*wa.flag = B_FALSE;
if (di_walk_node(root, DI_WALK_SIBFIRST, &wa,
find_matching_hba) != 0) {
log(LOG_DEBUG, ROUTINE, "di_walk_node failed.");
unlock(&open_handles_lock);
unlock(&all_hbas_lock);
S_FREE(wa.flag);
di_fini(root);
return;
}
if (*wa.flag == B_FALSE) {
/*
* Keep the HBA as it is including open handles
* per the SM-HBA standards. Just mark it as invalid.
*/
log(LOG_DEBUG, ROUTINE, "No matching HBA found. %s",
hba_ptr->device_path);
hba_ptr->invalid = B_TRUE;
}
S_FREE(wa.flag);
}
/*
* Now we marked missing HBA(s). Redisoover hbas to refresh
* or add any new adapter to the hba list.
* Simply call devtree_get_all_hbas().
*/
if (devtree_get_all_hbas(root) != HBA_STATUS_OK) {
log(LOG_DEBUG, ROUTINE, "devtree_get_all_hbas failed.");
}
di_fini(root);
unlock(&open_handles_lock);
unlock(&all_hbas_lock);
}
|