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
|
/* $OpenBSD: mpath_sym.c,v 1.18 2013/09/03 06:39:04 dlg Exp $ */
/*
* Copyright (c) 2010 David Gwynne <dlg@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <sys/proc.h>
#include <sys/conf.h>
#include <sys/queue.h>
#include <sys/rwlock.h>
#include <sys/pool.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/selinfo.h>
#include <scsi/scsi_all.h>
#include <scsi/scsiconf.h>
#include <scsi/mpathvar.h>
struct sym_softc {
struct device sc_dev;
struct mpath_path sc_path;
};
#define DEVNAME(_s) ((_s)->sc_dev.dv_xname)
int sym_match(struct device *, void *, void *);
void sym_attach(struct device *, struct device *, void *);
int sym_detach(struct device *, int);
int sym_activate(struct device *, int);
struct cfattach sym_ca = {
sizeof(struct sym_softc),
sym_match,
sym_attach,
sym_detach,
sym_activate
};
struct cfdriver sym_cd = {
NULL,
"sym",
DV_DULL
};
void sym_mpath_start(struct scsi_xfer *);
int sym_mpath_checksense(struct scsi_xfer *);
void sym_mpath_status(struct scsi_link *);
const struct mpath_ops sym_mpath_sym_ops = {
"sym",
sym_mpath_checksense,
sym_mpath_status
};
const struct mpath_ops sym_mpath_asym_ops = {
"sym",
sym_mpath_checksense,
sym_mpath_status
};
struct sym_device {
char *vendor;
char *product;
};
struct sym_device sym_devices[] = {
/* " vendor " " device " */
/* "01234567" "0123456789012345" */
{ "TOSHIBA ", "MBF" },
{ "SEAGATE ", "ST" },
{ "FUJITSU ", "MBD" },
{ "FUJITSU ", "MA" }
};
struct sym_device asym_devices[] = {
/* " vendor " " device " */
/* "01234567" "0123456789012345" */
{ "DELL ", "MD1220 " },
{ "DELL ", "MD3060e " },
{ "SUN ", "StorEdge 3510F D" },
{ "Transtec", "PROVIGO1100" },
{ "NetBSD", "NetBSD iSCSI" }
};
int
sym_match(struct device *parent, void *match, void *aux)
{
struct scsi_attach_args *sa = aux;
struct scsi_inquiry_data *inq = sa->sa_inqbuf;
struct sym_device *s;
int i;
if (mpath_path_probe(sa->sa_sc_link) != 0)
return (0);
for (i = 0; i < nitems(sym_devices); i++) {
s = &sym_devices[i];
if (bcmp(s->vendor, inq->vendor, strlen(s->vendor)) == 0 &&
bcmp(s->product, inq->product, strlen(s->product)) == 0)
return (8);
}
for (i = 0; i < nitems(asym_devices); i++) {
s = &asym_devices[i];
if (bcmp(s->vendor, inq->vendor, strlen(s->vendor)) == 0 &&
bcmp(s->product, inq->product, strlen(s->product)) == 0)
return (8);
}
return (0);
}
void
sym_attach(struct device *parent, struct device *self, void *aux)
{
struct sym_softc *sc = (struct sym_softc *)self;
struct scsi_attach_args *sa = aux;
struct scsi_link *link = sa->sa_sc_link;
struct scsi_inquiry_data *inq = sa->sa_inqbuf;
const struct mpath_ops *ops = &sym_mpath_sym_ops;
struct sym_device *s;
u_int id = 0;
int i;
printf("\n");
/* check if we're an assymetric access device */
for (i = 0; i < nitems(asym_devices); i++) {
s = &asym_devices[i];
if (bcmp(s->vendor, inq->vendor, strlen(s->vendor)) == 0 &&
bcmp(s->product, inq->product, strlen(s->product)) == 0) {
ops = &sym_mpath_asym_ops;
id = sc->sc_dev.dv_unit;
break;
}
}
/* init link */
link->device_softc = sc;
/* init path */
scsi_xsh_set(&sc->sc_path.p_xsh, link, sym_mpath_start);
sc->sc_path.p_link = link;
if (mpath_path_attach(&sc->sc_path, id, ops) != 0)
printf("%s: unable to attach path\n", DEVNAME(sc));
}
int
sym_detach(struct device *self, int flags)
{
return (0);
}
int
sym_activate(struct device *self, int act)
{
struct sym_softc *sc = (struct sym_softc *)self;
int rv = 0;
switch (act) {
case DVACT_SUSPEND:
case DVACT_RESUME:
break;
case DVACT_DEACTIVATE:
if (sc->sc_path.p_group != NULL)
mpath_path_detach(&sc->sc_path);
break;
}
return (rv);
}
void
sym_mpath_start(struct scsi_xfer *xs)
{
struct sym_softc *sc = xs->sc_link->device_softc;
mpath_start(&sc->sc_path, xs);
}
int
sym_mpath_checksense(struct scsi_xfer *xs)
{
return (MPATH_SENSE_DECLINED);
}
void
sym_mpath_status(struct scsi_link *link)
{
struct sym_softc *sc = link->device_softc;
mpath_path_status(&sc->sc_path, MPATH_S_ACTIVE);
}
|