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
|
#!/bin/sh
# Copyright (c) 2019 Axcient
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
. $(atf_get_srcdir)/conf.sh
atf_test_case add cleanup
add_head()
{
atf_set "descr" "Add a new path"
atf_set "require.user" "root"
}
add_body()
{
load_gmultipath
load_dtrace
md0=$(alloc_md)
md1=$(alloc_md)
md2=$(alloc_md)
name=$(mkname)
atf_check -s exit:0 gmultipath create "$name" ${md0} ${md1}
check_multipath_state ${md0} "OPTIMAL" "ACTIVE" "PASSIVE"
# Add a new path
atf_check -s exit:0 gmultipath add "$name" ${md2}
check_multipath_state ${md0} "OPTIMAL" "ACTIVE" "PASSIVE" "PASSIVE"
}
add_cleanup()
{
common_cleanup
}
atf_test_case create_A cleanup
create_A_head()
{
atf_set "descr" "Create an Active/Active multipath device"
atf_set "require.user" "root"
}
create_A_body()
{
load_gmultipath
load_dtrace
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
atf_check -s exit:0 gmultipath create -A "$name" ${md0} ${md1}
check_multipath_state "${md1} ${md0}" "OPTIMAL" "ACTIVE" "ACTIVE"
}
create_A_cleanup()
{
common_cleanup
}
atf_test_case create_R cleanup
create_R_head()
{
atf_set "descr" "Create an Active/Read multipath device"
atf_set "require.user" "root"
}
create_R_body()
{
load_gmultipath
load_dtrace
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
atf_check -s exit:0 gmultipath create -R "$name" ${md0} ${md1}
check_multipath_state ${md0} "OPTIMAL" "ACTIVE" "READ"
}
create_R_cleanup()
{
common_cleanup
}
atf_test_case depart_and_arrive cleanup
depart_and_arrive_head()
{
atf_set "descr" "gmultipath should remove devices that disappear, and automatically reattach labeled providers that reappear"
atf_set "require.user" "root"
}
depart_and_arrive_body()
{
load_gnop
load_gmultipath
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
# We need a non-zero offset to gmultipath won't see the label when it
# tastes the md device. We only want the label to be visible on the
# gnop device.
offset=131072
atf_check gnop create -o $offset /dev/${md0}
atf_check gnop create -o $offset /dev/${md1}
atf_check -s exit:0 gmultipath label "$name" ${md0}.nop
# gmultipath is too smart to let us create a gmultipath device by label
# when the two providers aren't actually related. So we create a
# device by label with one provider, and then manually add the second.
atf_check -s exit:0 gmultipath add "$name" ${md1}.nop
NDEVS=`gmultipath list "$name" | grep -c 'md[0-9]*\.nop'`
atf_check_equal 2 $NDEVS
# Now fail the labeled provider
atf_check -s exit:0 gnop destroy -f ${md0}.nop
# It should be automatically removed from the multipath device
NDEVS=`gmultipath list "$name" | grep -c 'md[0-9]*\.nop'`
atf_check_equal 1 $NDEVS
# Now return the labeled provider
atf_check gnop create -o $offset /dev/${md0}
# It should be automatically restored to the multipath device. We
# don't really care which path is active.
NDEVS=`gmultipath list "$name" | grep -c 'md[0-9]*\.nop'`
atf_check_equal 2 $NDEVS
STATE=`gmultipath list "$name" | awk '/^State:/ {print $2}'`
atf_check_equal "OPTIMAL" $STATE
}
depart_and_arrive_cleanup()
{
common_cleanup
}
atf_test_case fail cleanup
fail_head()
{
atf_set "descr" "Manually fail a path"
atf_set "require.user" "root"
}
fail_body()
{
load_gmultipath
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
atf_check -s exit:0 gmultipath create "$name" ${md0} ${md1}
check_multipath_state ${md0} "OPTIMAL" "ACTIVE" "PASSIVE"
# Manually fail the active path
atf_check -s exit:0 gmultipath fail "$name" ${md0}
check_multipath_state ${md1} "DEGRADED" "FAIL" "ACTIVE"
}
fail_cleanup()
{
common_cleanup
}
atf_test_case fail_on_error cleanup
fail_on_error_head()
{
atf_set "descr" "An error in the provider will cause gmultipath to mark it as FAIL"
atf_set "require.user" "root"
}
fail_on_error_body()
{
load_gnop
load_gmultipath
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
atf_check gnop create /dev/${md0}
atf_check gnop create /dev/${md1}
atf_check -s exit:0 gmultipath create "$name" ${md0}.nop ${md1}.nop
# The first I/O to the first path should fail, causing gmultipath to
# fail over to the second path.
atf_check gnop configure -r 100 -w 100 ${md0}.nop
atf_check -s exit:0 -o ignore -e ignore dd if=/dev/zero of=/dev/multipath/"$name" bs=4096 count=1
check_multipath_state ${md1}.nop "DEGRADED" "FAIL" "ACTIVE"
}
fail_on_error_cleanup()
{
common_cleanup
}
atf_test_case physpath cleanup
physpath_head()
{
atf_set "descr" "gmultipath should append /mp to the underlying providers' physical path"
atf_set "require.user" "root"
}
physpath_body()
{
load_gnop
load_gmultipath
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
physpath="some/physical/path"
# Create two providers with the same physical paths, mimicing how
# multipathed SAS drives appear. This is the normal way to use
# gmultipath. If the underlying providers' physical paths differ,
# then you're probably using gmultipath wrong.
atf_check gnop create -z $physpath /dev/${md0}
atf_check gnop create -z $physpath /dev/${md1}
atf_check -s exit:0 gmultipath create "$name" ${md0}.nop ${md1}.nop
gmultipath_physpath=$(diskinfo -p multipath/"$name")
atf_check_equal "$physpath/mp" "$gmultipath_physpath"
}
physpath_cleanup()
{
common_cleanup
}
atf_test_case prefer cleanup
prefer_head()
{
atf_set "descr" "Manually select the preferred path"
atf_set "require.user" "root"
}
prefer_body()
{
load_gmultipath
load_dtrace
md0=$(alloc_md)
md1=$(alloc_md)
md2=$(alloc_md)
name=$(mkname)
atf_check -s exit:0 gmultipath create "$name" ${md0} ${md1} ${md2}
check_multipath_state ${md0} "OPTIMAL" "ACTIVE" "PASSIVE" "PASSIVE"
# Explicitly prefer the final path
atf_check -s exit:0 gmultipath prefer "$name" ${md2}
check_multipath_state ${md2} "OPTIMAL" "PASSIVE" "PASSIVE" "ACTIVE"
}
prefer_cleanup()
{
common_cleanup
}
atf_test_case restore cleanup
restore_head()
{
atf_set "descr" "Manually restore a failed path"
atf_set "require.user" "root"
}
restore_body()
{
load_gmultipath
load_dtrace
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
atf_check -s exit:0 gmultipath create "$name" ${md0} ${md1}
# Explicitly fail the first path
atf_check -s exit:0 gmultipath fail "$name" ${md0}
check_multipath_state ${md1} "DEGRADED" "FAIL" "ACTIVE"
# Explicitly restore it
atf_check -s exit:0 gmultipath restore "$name" ${md0}
check_multipath_state ${md1} "OPTIMAL" "PASSIVE" "ACTIVE"
}
restore_cleanup()
{
common_cleanup
}
atf_test_case restore_on_error cleanup
restore_on_error_head()
{
atf_set "descr" "A failed path should be restored if an I/O error is encountered on all other active paths"
atf_set "require.user" "root"
}
restore_on_error_body()
{
load_gnop
load_gmultipath
load_dtrace
md0=$(alloc_md)
md1=$(alloc_md)
name=$(mkname)
atf_check gnop create /dev/${md0}
atf_check gnop create /dev/${md1}
atf_check -s exit:0 gmultipath create "$name" ${md0}.nop ${md1}.nop
# Explicitly fail the first path
atf_check -s exit:0 gmultipath fail "$name" ${md0}.nop
# Setup the second path to fail on the next I/O
atf_check gnop configure -r 100 -w 100 ${md1}.nop
atf_check -s exit:0 -o ignore -e ignore \
dd if=/dev/zero of=/dev/multipath/"$name" bs=4096 count=1
# Now the first path should be active, and the second should be failed
check_multipath_state ${md0}.nop "DEGRADED" "ACTIVE" "FAIL"
}
restore_on_error_cleanup()
{
common_cleanup
}
atf_test_case rotate cleanup
rotate_head()
{
atf_set "descr" "Manually rotate the active path"
atf_set "require.user" "root"
}
rotate_body()
{
load_gmultipath
load_dtrace
md0=$(alloc_md)
md1=$(alloc_md)
md2=$(alloc_md)
name=$(mkname)
atf_check -s exit:0 gmultipath create "$name" ${md0} ${md1} ${md2}
check_multipath_state ${md0} "OPTIMAL" "ACTIVE" "PASSIVE" "PASSIVE"
# Explicitly rotate the paths
atf_check -s exit:0 gmultipath rotate "$name"
check_multipath_state ${md2} "OPTIMAL" "PASSIVE" "PASSIVE" "ACTIVE"
# Again
atf_check -s exit:0 gmultipath rotate "$name"
check_multipath_state ${md1} "OPTIMAL" "PASSIVE" "ACTIVE" "PASSIVE"
# Final rotation should restore original configuration
atf_check -s exit:0 gmultipath rotate "$name"
check_multipath_state ${md0} "OPTIMAL" "ACTIVE" "PASSIVE" "PASSIVE"
}
rotate_cleanup()
{
common_cleanup
}
atf_init_test_cases()
{
atf_add_test_case add
atf_add_test_case create_A
atf_add_test_case create_R
atf_add_test_case depart_and_arrive
atf_add_test_case fail
atf_add_test_case fail_on_error
atf_add_test_case physpath
atf_add_test_case prefer
atf_add_test_case restore
atf_add_test_case restore_on_error
atf_add_test_case rotate
}
|