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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
|
/*++
Copyright (C) 2004-2010 Microsoft Corporation
Module Name:
intrface.c
Abstract:
This driver is the Microsoft Device Specific Module (DSM)
devices that conform with SPC-3 specs.
It exports behaviors that mpio.sys will use to determine how to
multipath these devices.
This file contains DriverEntry and all the functions that are
exported to MPIO.
This DSM is targetted towards Windows 2008 and above.
Environment:
kernel mode only
--*/
#include "precomp.h"
#ifdef DEBUG_USE_WPP
#include "intrface.tmh"
#endif
#pragma warning (disable:4305)
//
// Flag to indicate whether to NT_ASSERT or ignore a particular condition.
//
BOOLEAN DoAssert = TRUE;
//
// OS Version Info
// MSDSM is targetted towards Windows Server 2008 and above.
//
BOOLEAN gServer2008AndAbove = FALSE;
//
// Global to cache MPIO's Control Object.
//
PDEVICE_OBJECT gMPIOControlObject = NULL;
//
// Flag to indicate if the MPIO control object was referenced.
//
BOOLEAN gMPIOControlObjectRefd = FALSE;
//
// Global to cache the Driver Object.
//
PDRIVER_OBJECT gDsmDriverObject = NULL;
#ifdef ALLOC_PRAGMA
#pragma alloc_text(INIT, DriverEntry)
#endif
//
// The code.
//
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
This routine is called when the driver is loaded.
Arguments:
DriverObject - Supplies the driver object.
RegistryPath - Supplies the registry path.
Return Value:
NTSTATUS
--*/
{
PDSM_CONTEXT dsmContext = NULL;
PFILE_OBJECT fileObject;
WCHAR dosDeviceName[64] = DSM_MPIO_CONTROL_OBJECT_SYMLINK;
UNICODE_STRING mpUnicodeName;
NTSTATUS status = STATUS_SUCCESS;
MPIO_VERSION_INFO versionInfo = {0};
DSM_TYPE dsmMode = DsmType3;
DSM_MPIO_CONTEXT mpctlContext;
IO_STATUS_BLOCK ioStatus;
//
// Must call this function before using pool allocation functions.
//
ExInitializeDriverRuntime(0);
//
// Initialize the tracing subsystem.
// Any failure is handled by ETW itself.
//
WPP_INIT_TRACING(DriverObject, RegistryPath);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Entering function.\n",
DriverObject));
gDsmDriverObject = DriverObject;
//
// Determine the OS version.
//
gServer2008AndAbove = RtlIsNtDdiVersionAvailable(NTDDI_VISTA);
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Server2008AndAbove is %!bool!.\n",
DriverObject,
gServer2008AndAbove));
//
// MSDSM is supported only on Server 2008 and above.
//
if (!gServer2008AndAbove) {
status = STATUS_NOT_SUPPORTED;
goto __Exit_DriverEntry;
}
//
// Build the mpio symbolic link name.
//
RtlInitUnicodeString(&mpUnicodeName, dosDeviceName);
//
// Get a pointer to mpio's deviceObject.
//
status = IoGetDeviceObjectPointer(&mpUnicodeName,
FILE_READ_ATTRIBUTES,
&fileObject,
&gMPIOControlObject);
if (!NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_FATAL,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Failed to communicate with MPIO control object. Status %x.\n",
DriverObject,
status));
goto __Exit_DriverEntry;
}
ObReferenceObject(gMPIOControlObject);
gMPIOControlObjectRefd = TRUE;
ObDereferenceObject(fileObject);
status = DsmGetVersion(&versionInfo, sizeof(MPIO_VERSION_INFO));
if (!NT_SUCCESS(status)) {
//
// If we can't get the version, that means we aren't using a compatible
// version of MPIO drivers and so should not continue.
//
TracePrint((TRACE_LEVEL_FATAL,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): MPIO version unknown - DSM exiting.\n",
DriverObject));
status = STATUS_UNSUCCESSFUL;
goto __Exit_DriverEntry;
}
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): MPIO version %d.%d.%d.%d.\n",
DriverObject,
versionInfo.MajorVersion,
versionInfo.MinorVersion,
versionInfo.ProductBuild,
versionInfo.QfeNumber));
RtlZeroMemory(&gDsmInitData, sizeof(DSM_INIT_DATA));
//
// Must be newer than 1.0.7.0 to support DSM type 2 upwards.
//
if ((versionInfo.MajorVersion > 1) ||
(versionInfo.MinorVersion >= 1) ||
(versionInfo.ProductBuild > 7) ||
(versionInfo.QfeNumber >= 1)) {
//
// Must be newer than 1.18 to support DSM's versioning
//
if (versionInfo.MajorVersion > 1 ||
versionInfo.MinorVersion > 17) {
dsmMode = DsmType6;
{
RTL_OSVERSIONINFOW osVersion = {0};
osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
RtlGetVersion(&osVersion);
gDsmInitData.DsmVersion.MajorVersion = osVersion.dwMajorVersion;
gDsmInitData.DsmVersion.MinorVersion = osVersion.dwMinorVersion;
gDsmInitData.DsmVersion.ProductBuild = osVersion.dwBuildNumber;
gDsmInitData.DsmVersion.QfeNumber = 0;
}
}
} else {
//
// We cannot use this DSM with older versions of the MPIO drivers.
//
TracePrint((TRACE_LEVEL_FATAL,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): MPIO version not supported - DSM exiting.\n",
DriverObject));
status = STATUS_UNSUCCESSFUL;
goto __Exit_DriverEntry;
}
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Setting DSM type to %d.\n",
DriverObject,
dsmMode));
//
// Build the init data structure.
//
dsmContext = DsmpAllocatePool(NonPagedPoolNx,
sizeof(DSM_CONTEXT),
DSM_TAG_DSM_CONTEXT);
if (!dsmContext) {
TracePrint((TRACE_LEVEL_FATAL,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Failed to allocate memory for DSM Context.\n",
DriverObject));
status = STATUS_INSUFFICIENT_RESOURCES;
goto __Exit_DriverEntry;
}
//
// Set-up the init data
//
gDsmInitData.DsmContext = (PVOID) dsmContext;
gDsmInitData.InitDataSize = sizeof(DSM_INIT_DATA);
gDsmInitData.DsmInquireDriver = DsmInquire;
gDsmInitData.DsmCompareDevices = DsmCompareDevices;
gDsmInitData.DsmGetControllerInfo = DsmGetControllerInfo;
gDsmInitData.DsmSetDeviceInfo = DsmSetDeviceInfo;
gDsmInitData.DsmIsPathActive = DsmIsPathActive;
gDsmInitData.DsmPathVerify = DsmPathVerify;
gDsmInitData.DsmInvalidatePath = DsmInvalidatePath;
gDsmInitData.DsmMoveDevice = DsmMoveDevice;
gDsmInitData.DsmRemovePending = DsmRemovePending;
gDsmInitData.DsmRemoveDevice = DsmRemoveDevice;
gDsmInitData.DsmRemovePath = DsmRemovePath;
gDsmInitData.DsmSrbDeviceControl = DsmSrbDeviceControl;
gDsmInitData.DsmLBGetPath = DsmLBGetPath;
gDsmInitData.DsmInterpretErrorEx = DsmInterpretError;
gDsmInitData.DsmUnload = DsmUnload;
gDsmInitData.DsmSetCompletion = DsmSetCompletion;
gDsmInitData.DsmCategorizeRequest = DsmCategorizeRequest;
gDsmInitData.DsmBroadcastSrb = DsmBroadcastRequest;
gDsmInitData.DsmIsAddressTypeSupported = DsmIsAddressTypeSupported;
gDsmInitData.DsmDeviceNotUsed = DsmDeviceNotUsed;
//
// Since MSDSM is for SPC-3 compliant devices, MPIO should be able to build
// a serial number for the device.
//
gDsmInitData.DsmDeviceSerialNumber = NULL;
//
// Notifies MPIO of the appropriate Type support
//
gDsmInitData.DsmType = dsmMode;
gDsmInitData.DriverObject = DriverObject;
//
// Set-up the WMI Info.
//
DsmpWmiInitialize(&gDsmInitData.DsmWmiInfo, RegistryPath);
DsmpDsmWmiInitialize(&gDsmInitData.DsmWmiGlobalInfo, RegistryPath);
RtlInitUnicodeString(&gDsmInitData.DisplayName, DSM_FRIENDLY_NAME);
//
// Initialize some of the fields in DSM Context structure.
//
KeInitializeSpinLock(&dsmContext->SupportedDevicesListLock);
InitializeListHead(&dsmContext->GroupList);
InitializeListHead(&dsmContext->DeviceList);
InitializeListHead(&dsmContext->FailGroupList);
InitializeListHead(&dsmContext->ControllerList);
InitializeListHead(&dsmContext->StaleFailGroupList);
//
// Build the list context structures used for completion processing.
//
ExInitializeNPagedLookasideList(&dsmContext->CompletionContextList,
NULL,
NULL,
POOL_NX_ALLOCATION,
sizeof(DSM_COMPLETION_CONTEXT),
DSM_TAG_GENERIC,
0);
RtlZeroMemory(&mpctlContext, sizeof(DSM_MPIO_CONTEXT));
//
// Send the IOCTL to mpio.sys to register ourselves.
//
DsmSendDeviceIoControlSynchronous(IOCTL_MPDSM_REGISTER,
gMPIOControlObject,
&gDsmInitData,
&mpctlContext,
sizeof(DSM_INIT_DATA),
sizeof(DSM_MPIO_CONTEXT),
TRUE,
&ioStatus);
status = ioStatus.Status;
if (NT_SUCCESS(status)) {
dsmContext->MPIOContext = mpctlContext.MPIOContext;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Registered with MPIO.\n",
DriverObject));
DriverObject->DriverUnload = DsmDriverUnload;
//
// Query the registry for disabling/enabling statistics gathering
//
if (STATUS_OBJECT_NAME_NOT_FOUND == DsmpGetStatsGatheringChoice(dsmContext, (PULONG)&dsmContext->DisableStatsGathering)) {
//
// If the value does not exist, write the default to registry.
//
DsmpSetStatsGatheringChoice(dsmContext, (ULONG)dsmContext->DisableStatsGathering);
}
}
__Exit_DriverEntry:
if (NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Exiting function successfully.\n",
DriverObject));
} else {
//
// Since the DSM is going to be unloaded but without DriverUnload being
// called, we need to perform cleanup here.
//
if (dsmContext != NULL) {
DsmpFreeDSMResources(dsmContext);
dsmContext = NULL;
}
if (gMPIOControlObjectRefd) {
//
// Drop the reference on MPIO's control object.
//
ObDereferenceObject(gMPIOControlObject);
gMPIOControlObjectRefd = FALSE;
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_INIT,
"DriverEntry (DrvObj %p): Exiting function with status %x.\n",
DriverObject,
status));
//
// Stop the tracing subsystem.
// NOTE: once we unregister ETW, no more TracePrint can be done, so we
// must ensure that ETW unregister is the last thing that happens.
//
WPP_CLEANUP(gDsmDriverObject);
}
return status;
}
VOID
DsmDriverUnload(
_In_ IN PDRIVER_OBJECT DriverObject
)
/*++
Routine Description:
This routine is called when the driver is unloaded.
Arguments:
DriverObject - Supplies the driver object.
Return Value:
Nothing
--*/
{
DSM_DEREGISTER_DATA deregisterData;
IO_STATUS_BLOCK ioStatus;
deregisterData.DeregisterDataSize = sizeof(DSM_DEREGISTER_DATA);
deregisterData.DriverObject = DriverObject;
deregisterData.DsmContext = gDsmInitData.DsmContext;
deregisterData.MpioContext = ((PDSM_CONTEXT)(gDsmInitData.DsmContext))->MPIOContext;
//
// Send the IOCTL to mpio.sys to de-register ourselves.
//
DsmSendDeviceIoControlSynchronous(IOCTL_MPDSM_DEREGISTER,
gMPIOControlObject,
&deregisterData,
NULL,
sizeof(DSM_DEREGISTER_DATA),
0,
TRUE,
&ioStatus);
NT_ASSERT(NT_SUCCESS(ioStatus.Status));
return;
}
NTSTATUS
DsmInquire(
_In_ IN PVOID DsmContext,
_In_ IN PDEVICE_OBJECT TargetDevice,
_In_ IN PDEVICE_OBJECT PortObject,
_In_ IN PSTORAGE_DEVICE_DESCRIPTOR Descriptor,
_In_ IN PSTORAGE_DEVICE_ID_DESCRIPTOR DeviceIdList,
_Out_ OUT PVOID *DsmIdentifier
)
/*++
Routine Description:
This routine is used to determine if TargetDevice belongs to
the DSM. If this is a supported device DsmIdentifier will be
updated with 'deviceInfo'.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
TargetDevice - DeviceObject for the child device.
PortObject - The Port driver FDO on which TargetDevice resides.
Descriptor - Pointer to the device descriptor corresponding to TargetDevice.
Rehash of inquiry data, plus serial number information
(if applicable).
DeviceIdList - VPD Page 0x83 information.
DsmIdentifier - Pointer to be filled in by the DSM on success.
Return Value:
STATUS_NOT_SUPPORTED - if not on the SupportList.
STATUS_INSUFFICIENT_RESOURCES - No mem.
STATUS_SUCCESS
--*/
{
PDSM_CONTEXT dsmContext = DsmContext;
PDSM_DEVICE_INFO deviceInfo = NULL;
PDSM_GROUP_ENTRY group;
BOOLEAN newGroup;
PDSM_TARGET_PORT_GROUP_ENTRY targetPortGroupEntry = NULL;
PDSM_TARGET_PORT_LIST_ENTRY targetPortEntry = NULL;
PSTR serialNumber = NULL;
SIZE_T serialNumberLength = 0;
NTSTATUS status;
ULONG allocationLength;
BOOLEAN serialNumberAllocated = FALSE;
KIRQL irql = PASSIVE_LEVEL; // Initialize variable to prevent C4701 error
BOOLEAN supported = FALSE;
BOOLEAN spinlockHeld = FALSE;
UCHAR vendorId[9] = {0};
UCHAR productId[17] = {0};
INQUIRYDATA inquiryData;
UCHAR alua = DSM_DEVINFO_ALUA_NOT_SUPPORTED;
ULONG index;
PDSM_IDS controllerObjects = NULL;
PDEVICE_OBJECT controllerDeviceObject;
PLIST_ENTRY entry = NULL;
PSTORAGE_DESCRIPTOR_HEADER controllerIdHeader = NULL;
PULONG relativeTargetPortId = NULL;
PUSHORT targetPortGroupId = NULL;
PUCHAR targetPortGroupsInfo = NULL;
ULONG targetPortGroupsInfoLength = 0;
PSTR controllerSerialNumber;
BOOLEAN match = FALSE;
BOOLEAN doneUpdating = FALSE;
PDSM_CONTROLLER_LIST_ENTRY controllerEntry = NULL;
PDSM_TARGET_PORT_DEVICELIST_ENTRY tp_device = NULL;
PWSTR hardwareId = NULL;
PWCHAR deviceName = NULL;
ULONG tempResult = 0;
ULONG maxPRRetryTimeDuringStateTransition = DSM_MAX_PR_UNIT_ATTENTION_RETRY_TIME;
BOOLEAN useCacheForLeastBlocks = FALSE;
ULONGLONG cacheSizeForLeastBlocks = 0;
BOOLEAN fakeControllerEntryExists = FALSE;
STORAGE_IDENTIFIER_CODE_SET serialNumberCodeSet = StorageIdCodeSetReserved;
#if DBG
BOOLEAN multiport;
#endif
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Entering function.\n",
TargetDevice));
//
// 1. Get standard inquiry for the device. Check if SPC-3 compliant.
// If not compliant, check SupportedDeviceList.
// 2. Create device serial number.
// 3. Create a partially populated deviceInfo.
// DeviceDescriptor.
// SCSI address.
// Save off serial number.
// ALUA, port FDO, etc.
// 4. Create device name.
// 5. If ALUA support, send down Report Target Port Groups.
// 6. Find the group. If none, build one.
// 7. If new group, build target port groups and target ports info.
// Else, update target port groups and target ports info.
// 8. If both implicit as well as explicit transitions allowed, disable implicit.
// 9. Get list of controllers objects and get VPD 0x83 for each (only if no
// match for existing ones).
// Match returned ids of type 0x5 with what was returned in Report Target Port Groups.
// If no type 0x5 identifier, use SCSI address.
// Create controller list (delete stale entries).
//
//
// Query the registry to find out what devices are being supported
// on this machine.
//
DsmpGetDeviceList(dsmContext);
status = DsmpGetStandardInquiryData(TargetDevice, &inquiryData);
if (NT_SUCCESS(status)) {
supported = DsmpCheckScsiCompliance(TargetDevice,
&inquiryData,
Descriptor,
DeviceIdList);
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to get inquiry data with status %x.\n",
TargetDevice,
status));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// Since the device isn't SPC-3 compliant, check if the device is on the
// SupportedDeviceList.
//
if (!supported) {
if (!supported) {
//
// Get the inquiry data embedded in the device descriptor.
//
RtlStringCchCopyA((LPSTR)vendorId,
sizeof(vendorId) / sizeof(vendorId[0]),
(LPCSTR)(&inquiryData.VendorId));
RtlStringCchCopyA((LPSTR)productId,
sizeof(productId) / sizeof(productId[0]),
(LPCSTR)(&inquiryData.ProductId));
supported = DsmpDeviceSupported(dsmContext,
(PCSZ)vendorId,
(PCSZ)productId);
}
if (!supported) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Unsupported Device.\n",
TargetDevice));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
}
//
// Find out if device can be accessed via mulitple ports. This info is
// important since it will determine whether or not to send down a
// ReportTargetPortGroups command.
//
#if DBG
multiport = (inquiryData.MultiPort & 0x10) ? TRUE : FALSE;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Is %ws multiported.\n",
TargetDevice,
multiport ? L"" : L"not"));
#endif
//
// Query the assymmetric states transition method
//
switch ((inquiryData.Reserved >> 0x4) & 0x3) {
case 1: alua = DSM_DEVINFO_ALUA_IMPLICIT;
break;
case 2: alua = DSM_DEVINFO_ALUA_EXPLICIT;
break;
case 3: alua = DSM_DEVINFO_ALUA_IMPLICIT | DSM_DEVINFO_ALUA_EXPLICIT;
break;
default: alua = DSM_DEVINFO_ALUA_NOT_SUPPORTED;
break;
}
//
// Get some information about this device. The preferred info is
// from the Device ID Page.
//
if (DeviceIdList) {
//
// This will parse out the 'best' identifier and return
// a NULL-terminated ascii string.
//
serialNumber = (PSTR)DsmpParseDeviceID(DeviceIdList,
DSM_DEVID_SERIAL_NUMBER,
NULL,
&serialNumberCodeSet,
FALSE);
if (!serialNumber) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): NULL serial number.\n",
TargetDevice));
//
// Either an allocation failed, or the DeviceIdList is malformed.
//
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// Indicate that the serialnumber buffer is allocated.
//
serialNumberAllocated = TRUE;
serialNumberLength = strlen((const char*)serialNumber);
} else {
//
// Get the serial number of this device. Use the serial number
// page (0x80). Ensure that the device's serial number is
// present. If not, can't claim support for this drive.
//
if (!Descriptor ||
(Descriptor->SerialNumberOffset == MAXULONG) ||
(Descriptor->SerialNumberOffset == 0)) {
//
// The port driver currently doesn't get the VPD page 0x80,
// if the device doesn't support GET_SUPPORTED_PAGES. Check to
// see whether there actually is a serial number.
//
serialNumber = DsmpGetSerialNumber(TargetDevice);
if (!serialNumber) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): serialNumber = NULL.\n",
TargetDevice));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
} else {
serialNumberAllocated = TRUE;
serialNumberLength = strlen((const char*)serialNumber);
}
}
}
//
// Allocate for the device. This is also used as DsmId.
//
allocationLength = sizeof(DSM_DEVICE_INFO);
//
// As DSM_DEVICE_INFO has storage for the descriptor, add only
// the additional stuff that's at the end.
//
if (Descriptor) {
status = RtlULongSub(Descriptor->Size, sizeof(STORAGE_DEVICE_DESCRIPTOR), &tempResult);
if (!NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Arithmetic underflow - status %x.\n",
TargetDevice,
status));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
}
status = RtlULongAdd(allocationLength, tempResult, &allocationLength);
if (!NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Arithmetic overflow - status %x.\n",
TargetDevice,
status));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
deviceInfo = DsmpAllocatePool(NonPagedPoolNx,
allocationLength,
DSM_TAG_DEV_INFO);
if (!deviceInfo) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to allocate Device Info.\n",
TargetDevice));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
deviceInfo->State = deviceInfo->PreviousState = deviceInfo->TempPreviousStateForLB = deviceInfo->ALUAState = deviceInfo->LastKnownGoodState = DSM_DEV_NOT_USED_STATE;
deviceInfo->DesiredState = DSM_DEV_UNDETERMINED;
//
// Copy over the StorageDescriptor.
//
if (Descriptor) {
RtlCopyMemory(&deviceInfo->Descriptor,
Descriptor,
Descriptor->Size);
}
//
// Get the scsi address for this device. Note that on success, DsmGetScsiAddress()
// will allocate memory which we are responsible for freeing.
//
status = DsmGetScsiAddress(TargetDevice,
&deviceInfo->ScsiAddress);
if (!NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Error %x while getting scsi address.\n",
TargetDevice,
status));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// Capture the serial number allocated flag.
//
deviceInfo->SerialNumberAllocated = serialNumberAllocated;
//
// Set the serial number.
//
if (!serialNumberAllocated) {
PSTORAGE_DEVICE_DESCRIPTOR descriptor;
//
// serialNumber is not pointing to the buffer passed by MPIO. Update
// it to point to the Device Descriptor allocated by the DSM.
//
descriptor = &(deviceInfo->Descriptor);
NT_ASSERT(descriptor->SerialNumberOffset != 0 && descriptor->SerialNumberOffset != MAXULONG);
serialNumber = (PCHAR)descriptor + descriptor->SerialNumberOffset;
serialNumberLength = strlen((const char*)serialNumber);
}
if (alua == (DSM_DEVINFO_ALUA_IMPLICIT | DSM_DEVINFO_ALUA_EXPLICIT)) {
BOOLEAN disableImplicit = FALSE;
status = DsmpDisableImplicitStateTransition(TargetDevice, &disableImplicit);
if (NT_SUCCESS(status)) {
if (disableImplicit) {
alua &= ~DSM_DEVINFO_ALUA_IMPLICIT;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Disabled implicit ALUA state transition.\n",
TargetDevice));
//
// Record that the storage actually supported implicit also, but we
// turned it OFF.
//
deviceInfo->ImplicitDisabled = TRUE;
} else {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Storage support both transitions but does NOT allow disabling Implicit.\n",
TargetDevice));
}
} else {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to disable implicit ALUA state transitions - status %x.\n",
TargetDevice,
status));
}
}
deviceInfo->SerialNumber = serialNumber;
//
// Save the Physical Device Object (PDO) of the device.
// Used to verify that no two devices have the same PDO.
//
deviceInfo->PortPdo = TargetDevice;
//
// Save the FDO of the adapter. Used for handling reserve\release
//
deviceInfo->PortFdo = PortObject;
//
// Set the signature.
//
deviceInfo->DeviceSig = DSM_DEVICE_SIG;
deviceInfo->DsmContext = DsmContext;
deviceInfo->ALUASupport = alua;
//
// Build the name (using serialnumber) that will be used as registry key
// to store Load Balance settings for this device.
//
deviceName = DsmpBuildDeviceName(deviceInfo, serialNumber, serialNumberLength);
if (!deviceName) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to allocate device name for %p.\n",
TargetDevice,
deviceInfo));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// Send down ReportTargetPortGroups command and keep the info handy.
//
if (alua != DSM_DEVINFO_ALUA_NOT_SUPPORTED) {
status = DsmpReportTargetPortGroups(TargetDevice,
&targetPortGroupsInfo,
&targetPortGroupsInfoLength);
if (!NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to report target port groups for %p. Status %x.\n",
TargetDevice,
deviceInfo,
status));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// We've just sent down an RTPG (relatively expensive operation), and it
// succeeded, so sending down one more as part part of the initialization
// in PathVerify() since it is going to be called almost immediately.
//
deviceInfo->IgnorePathVerify = TRUE;
}
//
// Query the registry for max time to retry failed PR requests
//
DsmpGetMaxPRRetryTime(DsmContext, &maxPRRetryTimeDuringStateTransition);
//
// Query the registry to see if the user has overridden the default
// Least Blocks settings.
//
status = DsmpQueryCacheInformationFromRegistry(DsmContext,
&useCacheForLeastBlocks,
&cacheSizeForLeastBlocks);
if (!NT_SUCCESS(status)) {
//
// Couldn't get the settings from the registry so fall back on the
// default for Least Blocks.
//
useCacheForLeastBlocks = TRUE;
cacheSizeForLeastBlocks = DSM_LEAST_BLOCKS_DEFAULT_THRESHOLD;
}
//
// Build LUN's hardware id. Needs to be called at PASSIVE_LEVEL, so
// do it before grabbing the lock. The hardware id of the group is
// later set under the protection of the lock.
//
hardwareId = DsmpBuildHardwareId(deviceInfo);
irql = ExAcquireSpinLockExclusive(&(((PDSM_CONTEXT)DsmContext)->DsmContextLock));
spinlockHeld = TRUE;
status = STATUS_SUCCESS;
//
// See if there is an existing Multi-path group to which this belongs.
// (same serial number).
//
group = DsmpFindDevice(DsmContext, deviceInfo, FALSE);
if (!group) {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): First device %p in the group.\n",
TargetDevice,
deviceInfo));
newGroup = TRUE;
//
// This device doesn't belong to any group yet. So Build a multi-path
// group entry. This'll represents all paths to a particular device.
//
group = DsmpBuildGroupEntry(DsmContext, deviceInfo);
if (group) {
//
// Set the registry key name for the new group
//
group->RegistryKeyName = deviceName;
deviceName = NULL;
//
// Cache the LUN's hardware id
//
if (!hardwareId) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to build a hardwareId for %p.\n",
TargetDevice,
deviceInfo));
}
group->HardwareId = hardwareId;
hardwareId = NULL;
group->UseCacheForLeastBlocks = useCacheForLeastBlocks;
group->CacheSizeForLeastBlocks = cacheSizeForLeastBlocks;
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to allocate Group Entry for %p.\n",
TargetDevice,
deviceInfo));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
} else {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Found group %p for device %p.\n",
TargetDevice,
group,
deviceInfo));
newGroup = FALSE;
if (!group->HardwareId) {
//
// If we weren't successful in previously building the hardware id for this LUN,
// retry doing it again now.
//
hardwareId = DsmpBuildHardwareId(deviceInfo);
if (!hardwareId) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to build a hardwareId for %p.\n",
TargetDevice,
deviceInfo));
}
group->HardwareId = hardwareId;
hardwareId = NULL;
}
//
// Sanity check that we haven't been presented with device instances
// with different ALUA support. So compare with the first device instance.
//
for (index = 0; index < DSM_MAX_PATHS; index++) {
if (group->DeviceList[index]) {
break;
}
}
if (index < DSM_MAX_PATHS) {
//
// Only acceptable conditions are:
// 1. both have same support,
// 2. one has explicit, while other has both explicit-and-implicit (this
// is a potential valid case because DsmpDisableImplicitStateTransition
// may have failed).
//
if (!((deviceInfo->ALUASupport == group->DeviceList[index]->ALUASupport) ||
((deviceInfo->ALUASupport == DSM_DEVINFO_ALUA_EXPLICIT && deviceInfo->ImplicitDisabled) &&
(group->DeviceList[index]->ALUASupport == (DSM_DEVINFO_ALUA_IMPLICIT | DSM_DEVINFO_ALUA_EXPLICIT))) ||
((group->DeviceList[index]->ALUASupport == DSM_DEVINFO_ALUA_EXPLICIT && group->DeviceList[index]->ImplicitDisabled) &&
(deviceInfo->ALUASupport == (DSM_DEVINFO_ALUA_IMPLICIT | DSM_DEVINFO_ALUA_EXPLICIT))))) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Mismatch in device instances' ALUA support %d vs %d.\n",
TargetDevice,
deviceInfo->ALUASupport,
group->DeviceList[index]->ALUASupport));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
}
}
if (NT_SUCCESS(status)) {
NT_ASSERT(group);
group->MaxPRRetryTimeDuringStateTransition = maxPRRetryTimeDuringStateTransition;
if (alua == DSM_DEVINFO_ALUA_NOT_SUPPORTED) {
//
// Since the device doesn't support ALUA, it is automatically
// symmetric LU access.
//
group->Symmetric = TRUE;
if (newGroup) {
//
// This is the first in the group, so make it the active device.
// The actual active/passive devices will be set-up when
// LB policies are set by the user.
//
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_ACTIVE_OPTIMIZED;
} else {
//
// Already something active, this will be the fail-over device
// until the load-balance groups are set-up.
//
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_STANDBY;
}
} else {
if (DeviceIdList == NULL) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): No Device ID List.\n",
TargetDevice));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
if (alua == DSM_DEVINFO_ALUA_IMPLICIT) {
//
// Assume that the LU access is symmetric. When parsing the TPG
// info, if we find that not all TPGs are in the same LU access
// state, then we know that this the access is asymmetric.
//
group->Symmetric = TRUE;
}
//
// Build TPG and TP info
//
status = DsmpParseTargetPortGroupsInformation(DsmContext,
group,
targetPortGroupsInfo,
targetPortGroupsInfoLength);
if (!NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to build TPG information - status %x.\n",
TargetDevice,
status));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
for (index = 0; index < DSM_MAX_PATHS; index++) {
PDSM_TARGET_PORT_GROUP_ENTRY targetPortGroup;
targetPortGroup = group->TargetPortGroupList[index];
if (targetPortGroup) {
DsmpUpdateTargetPortGroupDevicesStates(targetPortGroup, targetPortGroup->AsymmetricAccessState);
}
}
//
// Find the target port through which this devInfo was exposed.
//
relativeTargetPortId = (PULONG)DsmpParseDeviceID(DeviceIdList,
DSM_DEVID_RELATIVE_TARGET_PORT,
NULL,
NULL,
FALSE);
NT_ASSERT(relativeTargetPortId);
if (!relativeTargetPortId) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Couldn't retrieve relative TP id.\n",
TargetDevice));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// Find the target port group
//
targetPortGroupId = (PUSHORT)DsmpParseDeviceID(DeviceIdList,
DSM_DEVID_TARGET_PORT_GROUP,
NULL,
NULL,
FALSE);
NT_ASSERT(targetPortGroupId);
if (targetPortGroupId) {
//
// Find the target port group entry
//
targetPortGroupEntry = DsmpFindTargetPortGroup(DsmContext,
group,
targetPortGroupId);
NT_ASSERT(targetPortGroupEntry);
if (targetPortGroupEntry) {
//
// Look through the target port group to find the target port
//
targetPortEntry = DsmpFindTargetPort(DsmContext,
targetPortGroupEntry,
relativeTargetPortId);
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Couldn't find TPG Id %x's entry.\n",
TargetDevice,
*targetPortGroupId));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
NT_ASSERT(targetPortEntry);
if (!targetPortEntry) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Couldn't find relative TP %x's entry.\n",
TargetDevice,
*relativeTargetPortId));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// Update the devInfo with the target port and target port group
// info
//
deviceInfo->TargetPortGroup = targetPortGroupEntry;
deviceInfo->TargetPort = targetPortEntry;
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = deviceInfo->ALUAState = deviceInfo->TargetPortGroup->AsymmetricAccessState;
tp_device = DsmpAllocatePool(NonPagedPoolNx,
sizeof(DSM_TARGET_PORT_DEVICELIST_ENTRY),
DSM_TAG_TP_DEVICE_LIST_ENTRY);
if (!tp_device) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Insufficient resources allocating TP device list entry.\n",
TargetDevice));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
//
// Add the device to the list of devices that are exposed via this target port.
//
tp_device->DeviceInfo = deviceInfo;
InterlockedIncrement((LONG volatile*)&targetPortEntry->Count);
InsertTailList(&targetPortEntry->TP_DeviceList, &tp_device->ListEntry);
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to retrieve TPG Id.\n",
TargetDevice));
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
}
if (NT_SUCCESS(status)) {
//
// Add the deviceInfo to the list. DO NOT modify the status
// variable if this function returns SUCCESS.
//
status = DsmpAddDeviceEntry(DsmContext,
group,
deviceInfo);
if (NT_SUCCESS(status)) {
*DsmIdentifier = deviceInfo;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Added device %p to group %p.\n",
TargetDevice,
*DsmIdentifier,
group));
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to add device %p to group %p - status %x.\n",
TargetDevice,
deviceInfo,
group,
status));
//
// We weren't able to add this deviceInfo to the list so we must
// remove its entry on the target port list before the deviceInfo
// is freed.
//
DsmpRemoveDeviceFromTargetPortList(deviceInfo);
if (newGroup) {
DsmpRemoveGroupEntry(DsmContext, group, FALSE);
DsmpFreePool(group);
group = NULL;
}
status = STATUS_NOT_SUPPORTED;
goto __Exit_DsmInquire;
}
}
}
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
spinlockHeld = FALSE;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Device %p added. State %d, Desired State %d\n",
TargetDevice,
deviceInfo,
deviceInfo->State,
deviceInfo->DesiredState));
//
// Update the global list of controller objects
//
controllerObjects = DsmGetAssociatedDevice(dsmContext->MPIOContext,
PortObject,
0x0C);
if (controllerObjects) {
//
// This loop needs its own status variable so that it does not
// inadvertently overwrite a STATUS_SUCCESS from the code above.
//
NTSTATUS matchStatus = STATUS_SUCCESS;
PSCSI_ADDRESS controllerScsiAddress = NULL;
//
// Walk through the list and get VPD 0x83 data and associate the devInfo
// with the controller object.
//
for (index = 0; index < controllerObjects->Count; index++) {
STORAGE_IDENTIFIER_CODE_SET codeSet = StorageIdCodeSetReserved;
//
// Free the previously allocated SCSI address, if any.
//
if (controllerScsiAddress) {
DsmpFreePool(controllerScsiAddress);
controllerScsiAddress = NULL;
}
controllerDeviceObject = (PDEVICE_OBJECT)controllerObjects->IdList[index];
NT_ASSERT(controllerDeviceObject);
if (!controllerDeviceObject) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Controller list %p's index %x is NULL.\n",
TargetDevice,
controllerObjects,
index));
continue;
}
matchStatus = DsmpGetDeviceIdList(controllerDeviceObject, &controllerIdHeader);
NT_ASSERT(NT_SUCCESS(matchStatus));
if (!NT_SUCCESS(matchStatus)) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to get DeviceId list for controller %p - status %x.\n",
TargetDevice,
controllerDeviceObject,
matchStatus));
continue;
}
controllerSerialNumber = DsmpParseDeviceID((PSTORAGE_DEVICE_ID_DESCRIPTOR)controllerIdHeader,
DSM_DEVID_SERIAL_NUMBER,
NULL,
&codeSet,
FALSE);
NT_ASSERT(controllerSerialNumber);
DsmpFreePool(controllerIdHeader);
if (!controllerSerialNumber) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to parse serial number for controller %p.\n",
TargetDevice,
controllerDeviceObject));
continue;
}
//
// Note that on success, DsmGetScsiAddress() will allocate memory
// which we are responsible for freeing.
//
matchStatus = DsmGetScsiAddress(controllerDeviceObject, &controllerScsiAddress);
NT_ASSERT(NT_SUCCESS(matchStatus));
if (!NT_SUCCESS(matchStatus)) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to get controller %p's scsi address - status %x.\n",
TargetDevice,
controllerDeviceObject,
matchStatus));
continue;
}
controllerEntry = DsmpFindControllerEntry(DsmContext,
PortObject,
controllerScsiAddress,
controllerSerialNumber,
strlen(controllerSerialNumber),
codeSet,
TRUE);
if (!controllerEntry) {
controllerEntry = DsmpBuildControllerEntry(DsmContext,
controllerDeviceObject,
PortObject,
controllerScsiAddress,
controllerSerialNumber,
codeSet,
TRUE);
if (!controllerEntry) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to build an entry for controller %p.\n",
TargetDevice,
controllerDeviceObject));
continue;
}
InsertHeadList(&dsmContext->ControllerList, &controllerEntry->ListEntry);
InterlockedIncrement((LONG volatile*)&dsmContext->NumberControllers);
}
controllerEntry->DeviceObject = controllerDeviceObject;
//
// Parse the DeviceIdList for all the 0x5 type identifiers
// and for each, compare the target port groups and target ports to match
// the device to its controller.
//
if (!match) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Failed to match devInfo %p with controller %p's Ids.\n",
TargetDevice,
deviceInfo,
controllerDeviceObject));
match = DsmpIsDeviceBelongsToController(DsmContext,
deviceInfo,
controllerEntry);
}
if (match && !doneUpdating) {
InterlockedIncrement((LONG volatile*)&(controllerEntry->RefCount));
deviceInfo->Controller = controllerEntry;
doneUpdating = TRUE;
}
}
//
// Free the last SCSI address allocated in the loop, if any.
//
if (controllerScsiAddress) {
DsmpFreePool(controllerScsiAddress);
controllerScsiAddress = NULL;
}
}
//
// If there was no controller to associate this device with, use a fake one.
// Note that we only really care about matching on the Port and Target
// portions of the SCSI address.
//
if (!deviceInfo->Controller) {
for (entry = dsmContext->ControllerList.Flink;
entry != &dsmContext->ControllerList;
entry = entry->Flink) {
controllerEntry = CONTAINING_RECORD(entry, DSM_CONTROLLER_LIST_ENTRY, ListEntry);
if ((controllerEntry->IsFakeController) &&
(controllerEntry->ScsiAddress->PortNumber == deviceInfo->ScsiAddress->PortNumber) &&
(controllerEntry->ScsiAddress->TargetId == deviceInfo->ScsiAddress->TargetId)) {
fakeControllerEntryExists = TRUE;
break;
}
}
//
// If no fake one exists as yet for this port FDO, create one now.
//
if (!fakeControllerEntryExists) {
CHAR fakeControllerSerialNumber[] = "FakeController";
SCSI_ADDRESS fakeControllerScsiAddress = {0};
fakeControllerScsiAddress.PortNumber = deviceInfo->ScsiAddress->PortNumber;
fakeControllerScsiAddress.TargetId = deviceInfo->ScsiAddress->TargetId;
controllerEntry = DsmpBuildControllerEntry(DsmContext,
NULL,
PortObject,
&fakeControllerScsiAddress,
fakeControllerSerialNumber,
StorageIdCodeSetBinary,
TRUE);
if (controllerEntry) {
InsertHeadList(&dsmContext->ControllerList, &controllerEntry->ListEntry);
InterlockedIncrement((LONG volatile*)&dsmContext->NumberControllers);
controllerEntry->IsFakeController = TRUE;
}
}
if (controllerEntry) {
InterlockedIncrement((LONG volatile*)&(controllerEntry->RefCount));
}
deviceInfo->Controller = controllerEntry;
}
__Exit_DsmInquire:
if (spinlockHeld) {
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
}
if (NT_SUCCESS(status)) {
NT_ASSERT(*DsmIdentifier);
} else {
//
// If there was any sort of ERROR, the deviceInfo will NOT be put on
// MSDSM's internal list that is accessible to other threads. Thus,
// we are safe to free the memory below and we do not require any
// synchronization mechanism to do so.
//
//
// Check to see whether the serial number buffer was allocated, or just
// an offset into the Descriptor.
//
if (serialNumberAllocated) {
//
// Need to free this before returning.
//
DsmpFreePool(serialNumber);
}
if (deviceInfo) {
if (deviceInfo->ScsiAddress) {
DsmpFreePool(deviceInfo->ScsiAddress);
}
DsmpFreePool(deviceInfo);
}
}
//
// If deviceName is not NULL then it hasn't been assigned to any GROUP.
// Free the allocated memory.
//
if (deviceName) {
DsmpFreePool(deviceName);
}
//
// If hardwareId is not NULL then it hasn't been assigned to any GROUP.
// Free the allocated memory.
//
if (hardwareId) {
DsmpFreePool(hardwareId);
}
if (targetPortGroupsInfo) {
DsmpFreePool(targetPortGroupsInfo);
}
if (relativeTargetPortId) {
DsmpFreePool(relativeTargetPortId);
}
if (targetPortGroupId) {
DsmpFreePool(targetPortGroupId);
}
if (controllerObjects) {
DsmpFreePool(controllerObjects);
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmInquire (DevObj %p): Exiting function with status %x.\n",
TargetDevice,
status));
return status;
}
BOOLEAN
DsmCompareDevices(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId1,
_In_ IN PVOID DsmId2
)
/*++
Routine Description:
This routine is called to determine if the device ids represent
the same underlying physical device.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
DsmId1/2 - Identifers returned from DMS_INQUIRE_DRIVER.
Return Value:
TRUE if DsmIds correspond to the same underlying device.
--*/
{
PDSM_DEVICE_INFO deviceInfo0 = DsmId1;
PDSM_DEVICE_INFO deviceInfo1 = DsmId2;
PSTR serialNumber0;
PSTR serialNumber1;
SIZE_T length;
BOOLEAN match = FALSE;
UNREFERENCED_PARAMETER(DsmContext);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmCompareDevices (DevInfo %p): Entering function - comparing with %p.\n",
deviceInfo0,
deviceInfo1));
//
// Get the two serial numbers. They were either embedded in
// the STORAGE_DEVICE_DESCRIPTOR or built by directly issuing
// the VPD request.
//
serialNumber0 = deviceInfo0->SerialNumber;
serialNumber1 = deviceInfo1->SerialNumber;
if (serialNumber0 && serialNumber1) {
//
// Get the length of the base-device Serial Number.
//
length = strlen((const char*)serialNumber0);
//
// If the lengths match, compare the contents.
//
if (length == strlen((const char*)serialNumber1)) {
if (RtlEqualMemory(serialNumber0, serialNumber1, length)) {
match = TRUE;
}
}
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmCompareDevices (DevInfo %p): Serialnumber not assigned for %p and\\or %p.\n",
DsmId1,
deviceInfo0,
deviceInfo1));
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmCompareDevices (DevInfo %p): Exiting function with match = %!bool!.\n",
DsmId1,
match));
return match;
}
NTSTATUS
DsmGetControllerInfo(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId,
_In_ IN ULONG Flags,
_Inout_ IN OUT PCONTROLLER_INFO *ControllerInfo
)
/*++
Routine Description:
This routine is used to get information about the controller that
the device corresponding to DsmId in on. Currently this DSM controls
hardware that doesn't expose controllers directly. Therefore State
is always NO_CNTRL. This information is used mainly by whatever
WMI admin utilities want it.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
DsmId - Value returned from DMSInquireDriver.
Flags - Bitfield of modifiers. If ALLOCATE is not set, ControllerInfo
will have a valid buffer for the DSM to operate on.
ControllerInfo - Pointer for the DSM to place the allocated controller
info pertaining to DsmId
Return Value:
STATUS_INSUFFICIENT_RESOURCES if memory allocation fails.
STATUS_SUCCESS on success
--*/
{
PDSM_DEVICE_INFO deviceInfo = DsmId;
PDSM_CONTROLLER_LIST_ENTRY controllerEntry = deviceInfo->Controller;
PCONTROLLER_INFO controllerInfo = NULL;
LARGE_INTEGER time;
ULONG controllerId = 0;
NTSTATUS status = STATUS_SUCCESS;
UNREFERENCED_PARAMETER(DsmContext);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmGetControllerInfo (DevInfo %p): Entering function.\n",
DsmId));
//
// Check to see whether a controller id has already been made-up.
//
if (!controllerEntry) {
//
// Since this device is in an enclosure that doesn't have controllers,
// e.g. JBOD, make one up.
//
KeQuerySystemTime(&time);
//
// Use only the lower 32-bits.
//
controllerId = time.LowPart;
}
//
// Check the Flags
//
if (Flags & DSM_CNTRL_FLAGS_ALLOCATE) {
//
// This is the first call. Need to allocate the controller structure.
//
controllerInfo = DsmpAllocatePool(NonPagedPoolNx,
sizeof(CONTROLLER_INFO),
DSM_TAG_CTRL_INFO);
if (!controllerInfo) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmGetControllerInfo (DevInfo %p): Failed to allocate memory for Controller Info\n",
DsmId));
status = STATUS_INSUFFICIENT_RESOURCES;
goto __Exit_DsmGetControllerInfo;
}
if (!controllerEntry) {
//
// Indicate that there are no specific controllers.
//
controllerInfo->State = DSM_CONTROLLER_NO_CNTRL;
//
// Set the identifier to the value generated earlier.
// Indicate that it's Binary, not ASCII.
//
controllerInfo->Identifier.Type = StorageIdCodeSetBinary;
controllerInfo->Identifier.Length = 8;
RtlCopyMemory(controllerInfo->Identifier.SerialNumber,
&controllerId,
sizeof(controllerId));
} else {
//
// If either implicit or explicit ALUA state transition is supported,
// every controller is active. Else, if the devInfo's is in Active
// state, the controller is obviously in the active state.
//
if ((deviceInfo->ALUASupport != DSM_DEVINFO_ALUA_NOT_SUPPORTED) ||
(DsmpIsDeviceStateActive(deviceInfo->State))) {
controllerInfo->State = DSM_CONTROLLER_ACTIVE;
} else {
controllerInfo->State = DSM_CONTROLLER_STANDBY;
}
controllerInfo->Identifier.Type = controllerEntry->IdCodeSet;
controllerInfo->Identifier.Length = controllerEntry->IdLength;
if (controllerInfo->Identifier.Length > 32) {
controllerInfo->Identifier.Length = 32;
}
RtlCopyMemory(controllerInfo->Identifier.SerialNumber,
controllerEntry->Identifier,
controllerInfo->Identifier.Length);
controllerInfo->DeviceObject = controllerEntry->DeviceObject;
}
*ControllerInfo = controllerInfo;
} else if (Flags & DSM_CNTRL_FLAGS_CHECK_STATE) {
//
// Get the passed in struct.
//
controllerInfo = *ControllerInfo;
//
// If the enclosures supported by this DSM actually had controllers,
// there would be a list of them and a search based on
// ControllerIdentifier would be made.
//
controllerEntry = deviceInfo->Controller;
if (!controllerEntry) {
controllerInfo->State = DSM_CONTROLLER_NO_CNTRL;
} else {
//
// If either implicit or explicit ALUA state transition is supported,
// every controller is active. Else, if the devInfo's is in Active
// state, the controller is obviously in the active state.
//
if ((deviceInfo->ALUASupport != DSM_DEVINFO_ALUA_NOT_SUPPORTED) ||
(DsmpIsDeviceStateActive(deviceInfo->State))) {
controllerInfo->State = DSM_CONTROLLER_ACTIVE;
} else {
controllerInfo->State = DSM_CONTROLLER_STANDBY;
}
}
}
__Exit_DsmGetControllerInfo:
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmGetControllerInfo (DevInfo %p): Exiting function with status %x.\n",
DsmId,
status));
return status;
}
NTSTATUS
DsmSetDeviceInfo(
_In_ IN PVOID DsmContext,
_In_ IN PDEVICE_OBJECT TargetObject,
_In_ IN PVOID DsmId,
_Inout_ IN OUT PVOID *PathId
)
/*++
Routine Description:
This routine associates the DsmId to the controlling MPDisk PDO,
the targetObject for DSM-initiated requests, and to a Path
(given by PathId).
This routine will update the PathId in a way that better explains
the topology to MPIO.
Additionally, if we are in failover LB policy, failback if this
path is preferred path.
Also, if PR is being used, send registration down this path.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
TargetObject - The D.O. to which DSM-initiated requests should be sent.
DsmId - Value returned from DMSInquireDriver.
PathId - Id that represents the path. The value passed in may be used
as is, or the DSM optionally can update it if it requires
additional state info to be kept.
Return Value:
INSUFFICENT_RESOURCES for no-mem conditions.
STATUS_SUCCESS
--*/
{
PDSM_DEVICE_INFO deviceInfo = DsmId;
PDSM_GROUP_ENTRY group = deviceInfo->Group;
PDSM_FAILOVER_GROUP failGroup;
PDSM_CONTEXT dsmContext;
PSCSI_ADDRESS scsiAddress;
ULONG primaryPath = 0;
ULONG optimizedPath = 0;
ULONG pathWeight = 0;
ULONG pathId;
NTSTATUS status = STATUS_SUCCESS;
WCHAR registryKeyName[256] = {0};
BOOLEAN newFOGroup = FALSE;
BOOLEAN registryKeyExists = FALSE;
KIRQL irql;
PVOID tempPathId = *PathId;
DSM_LOAD_BALANCE_TYPE loadBalanceType;
ULONGLONG preferredPath = (ULONGLONG)((ULONG_PTR)MAXULONG);
UCHAR explicitlySet = FALSE;
BOOLEAN vidpidPolicySet = FALSE;
BOOLEAN overallPolicySet = FALSE;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): Entering function.\n",
DsmId));
//
// 1. Set default LB policy.
// 2. Query LB policy from registry and update if necessary.
// 3. Set default value for primaryPath and optimizedPath based on device's
// access state
// 4. Map deviceInfo to real LUN by saving off the target for I/O
// 5. Build pathId from SCSI address
// 6. Find FOG for device. If none found, build one.
// Add deviceInfo to FOG.
// 7. Query registry for pathWeight, primaryPath and optimizedPath
// Update deviceInfo with results of query.
// 8. Compare deviceInfo access state with persistent value (based on
// primaryPath and optimizedPath) and update its DesiredState.
//
if (!TargetObject) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): No target object.\n",
deviceInfo));
//
// This deviceInfo will have no path or targetObject associated with it.
// Mark it in a failed state so it won't be used to handle any requests.
//
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_UNDETERMINED;
goto __Exit_DsmSetDeviceInfo;
}
//
// Default LB type is Round Robin.
//
loadBalanceType = DSM_LB_ROUND_ROBIN;
//
// Override the default with whatever is the overall policy that needs to be
// applied for all LUNs controlled by MSDSM.
//
// Override that policy if one has been set for this device's VID/PID.
//
// Override that policy with whatever has been explicitly set for this particular
// device.
//
// In order to perform the above, first query the policy for this particular device.
// If it has not been explicity set, use MSDSM's overall policy or VID/PID policy.
//
status = DsmpQueryDeviceLBPolicyFromRegistry(deviceInfo,
group->RegistryKeyName,
&loadBalanceType,
&preferredPath,
&explicitlySet);
if (!NT_SUCCESS(status)) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): Failed to query LB policy from registry. Status %x.\n",
deviceInfo,
status));
NT_ASSERT(NT_SUCCESS(status));
//
// This deviceInfo will have no path or targetObject associated with it.
// Mark it in a failed state so it won't be used to handle any requests.
//
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_UNDETERMINED;
goto __Exit_DsmSetDeviceInfo;
}
//
// If this device's policy was not explicitly set, check to see if a policy
// was set for this device's VID/PID and use that.
// If VID/PID policy is not set, query the overall default policy
// that needs to be applied to all devices controlled by this DSM.
// If this setting hasn't been set, we'll fall back to using the default that was
// determined based on the storage's ALUA capabilities.
//
if (!explicitlySet) {
status = DsmpQueryTargetLBPolicyFromRegistry(deviceInfo,
&loadBalanceType,
&preferredPath);
if (NT_SUCCESS(status)) {
group->LBPolicySelection = DSM_DEFAULT_LB_POLICY_VID_PID;
vidpidPolicySet = TRUE;
} else if (status == STATUS_OBJECT_NAME_NOT_FOUND) {
//
// Since the policy hasn't been set for this VID/PID, check if
// overall MSDSM-wide policy has been set.
//
status = DsmpQueryDsmLBPolicyFromRegistry(&loadBalanceType,
&preferredPath);
if (NT_SUCCESS(status)) {
group->LBPolicySelection = DSM_DEFAULT_LB_POLICY_DSM_WIDE;
overallPolicySet = TRUE;
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): Failed to query Dsm overall LB policy from registry. Status %x.\n",
deviceInfo,
status));
NT_ASSERT(status == STATUS_OBJECT_NAME_NOT_FOUND);
status = STATUS_SUCCESS;
}
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): Failed to query VID/PID LB policy from registry. Status %x.\n",
deviceInfo,
status));
NT_ASSERT(status == STATUS_OBJECT_NAME_NOT_FOUND);
status = STATUS_SUCCESS;
}
} else {
group->LBPolicySelection = DSM_DEFAULT_LB_POLICY_LUN_EXPLICIT;
}
if (!explicitlySet && !vidpidPolicySet && !overallPolicySet) {
group->LBPolicySelection = DSM_DEFAULT_LB_POLICY_ALUA_CAPABILITY;
}
//
// If ALUA is enabled and the load balance policy is set to Round Robin,
// we need to set it to Round Robin with Subset instead.
//
if (!DsmpIsSymmetricAccess(deviceInfo) && loadBalanceType == DSM_LB_ROUND_ROBIN) {
loadBalanceType = DSM_LB_ROUND_ROBIN_WITH_SUBSET;
}
group->LoadBalanceType = loadBalanceType;
group->PreferredPath = preferredPath;
dsmContext = (PDSM_CONTEXT) DsmContext;
irql = ExAcquireSpinLockExclusive(&(dsmContext->DsmContextLock));
//
// Save the registry key name under which Load balance policies
// are stored. This will be used to query the LB policy later.
//
if (group->RegistryKeyName) {
registryKeyExists = TRUE;
if (!NT_SUCCESS(RtlStringCchCopyNW(registryKeyName,
sizeof(registryKeyName) / sizeof(registryKeyName[0]),
group->RegistryKeyName,
((sizeof(registryKeyName) / sizeof(registryKeyName[0])) - sizeof(WCHAR))))) {
registryKeyName[(sizeof(registryKeyName) / sizeof(registryKeyName[0])) - 1] = L'\0';
}
}
//
// TargetObject is the destination for any requests created by this driver.
// Save this for future reference.
//
deviceInfo->TargetObject = TargetObject;
//
// Set the PathId - All devices on the same PathId will
// failover together. Currently the pathId is constructed
// from Port Number, Bus Number, and Target Id of the device.
//
scsiAddress = deviceInfo->ScsiAddress;
NT_ASSERT(scsiAddress);
pathId = 0x77;
pathId <<= 8;
pathId |= scsiAddress->PortNumber;
pathId <<= 8;
pathId |= scsiAddress->PathId;
pathId <<= 8;
pathId |= scsiAddress->TargetId;
*PathId = ((PVOID)((ULONG_PTR)(pathId)));
//
// PathId indicates the path on which this device resides. Meaning
// that when a Fail-Over occurs all device's on the same path fail
// together. Search for a matching F.O. Group
//
failGroup = DsmpFindFOGroup(DsmContext, *PathId);
//
// If not found, create a new failover group
//
if (!failGroup) {
failGroup = DsmpBuildFOGroup(DsmContext, deviceInfo, PathId);
if (failGroup) {
newFOGroup = TRUE;
failGroup->MPIOPath = tempPathId;
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): Failed to build FO Group.\n",
DsmId));
status = STATUS_INSUFFICIENT_RESOURCES;
}
}
if (NT_SUCCESS(status)) {
//
// If this path is in the midst of failover processing, mark it as "good"
// again.
//
failGroup->State = DSM_FG_NORMAL;
//
// add this deviceInfo to the f.o. group.
//
status = DsmpUpdateFOGroup(DsmContext, failGroup, deviceInfo);
NT_ASSERT(NT_SUCCESS(status));
}
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
if (NT_SUCCESS(status)) {
if (registryKeyExists) {
NTSTATUS queryStatus = STATUS_INVALID_PARAMETER;
ULONGLONG pathId64;
//
// If the overall default policy or a target-level policy has been set and
// this device's policy has not been explicitly set, there's no use querying
// its individual path (desired) states.
//
if ((!overallPolicySet && !vidpidPolicySet) || (explicitlySet)) {
//
// Created a new failover group. Query the LB policy
// for this device from registry.
//
pathId64 = (ULONGLONG)((ULONG_PTR)*PathId);
queryStatus = DsmpQueryLBPolicyForDevice(registryKeyName,
pathId64,
loadBalanceType,
&primaryPath,
&optimizedPath,
&pathWeight);
}
irql = ExAcquireSpinLockExclusive(&(dsmContext->DsmContextLock));
if (NT_SUCCESS(queryStatus)) {
deviceInfo->PathWeight = pathWeight;
//
// If device doesn't support ALUA, update the device state
// based on the primary path info in the registry.
//
if (DsmpIsSymmetricAccess(deviceInfo)) {
if (primaryPath) {
deviceInfo->DesiredState = DSM_DEV_ACTIVE_OPTIMIZED;
} else {
deviceInfo->DesiredState = DSM_DEV_STANDBY;
}
} else {
DSM_DEVICE_STATE devState;
if (primaryPath) {
devState = optimizedPath ? DSM_DEV_ACTIVE_OPTIMIZED : DSM_DEV_ACTIVE_UNOPTIMIZED;
} else {
devState = optimizedPath ? DSM_DEV_STANDBY : DSM_DEV_UNAVAILABLE;
}
//
// For ALUA, desired state makes sense for FOO.
// For RRWS, we assume desired state was explicitly selected
// by Admin if the ALUA state is different from the path
// state. Only under such cases would the path state have
// been saved in registry.
// In all other policies, state must just match the TPG state.
//
if (group->LoadBalanceType == DSM_LB_FAILOVER ||
group->LoadBalanceType == DSM_LB_ROUND_ROBIN_WITH_SUBSET) {
deviceInfo->DesiredState = devState;
} else {
deviceInfo->DesiredState = DSM_DEV_UNDETERMINED;
}
}
} else if (queryStatus == STATUS_OBJECT_NAME_NOT_FOUND) {
deviceInfo->PathWeight = pathWeight;
deviceInfo->DesiredState = DSM_DEV_UNDETERMINED;
} else {
deviceInfo->PathWeight = 0;
deviceInfo->DesiredState = DSM_DEV_UNDETERMINED;
}
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
}
}
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): PathWeight %x, DesiredState %x, State %x, PrevState %x.\n",
deviceInfo,
deviceInfo->PathWeight,
deviceInfo->DesiredState,
deviceInfo->State,
deviceInfo->PreviousState));
if (NT_SUCCESS(status)) {
deviceInfo->Initialized = TRUE;
} else if (!NT_SUCCESS(status) && newFOGroup) {
//
// This deviceInfo will have no path associated with it.
// Mark it in a failed state so it won't be used to handle any requests.
//
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_UNDETERMINED;
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): No path associated with instance. Changing state from %u to %u.\n",
deviceInfo,
deviceInfo->PreviousState,
deviceInfo->State));
DsmpRemoveDeviceFailGroup(DsmContext, failGroup, deviceInfo, TRUE);
if (failGroup->Count == 0) {
//
// Yank it from the list.
//
RemoveEntryList(&failGroup->ListEntry);
InterlockedDecrement((LONG volatile*)&dsmContext->NumberFOGroups);
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): Removing FOGroup %p with path %p. Count of FOGroups %d.\n",
DsmId,
failGroup,
failGroup->PathId,
dsmContext->NumberFOGroups));
//
// Free the zombie group list and then the failover group.
//
DsmpFreeZombieGroupList(failGroup);
DsmpFreePool(failGroup);
}
}
__Exit_DsmSetDeviceInfo:
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmSetDeviceInfo (DevInfo %p): Exiting function with status %x.\n",
DsmId,
status));
return status;
}
BOOLEAN
DsmIsPathActive(
_In_ IN PVOID DsmContext,
_In_ IN PVOID PathId,
_In_ IN PVOID DsmId
)
/*++
Routine Description:
This routine is used to determine whether the path to DsmId is usable
(ie. able to handle requests without a failover).
Also, after a failover, the path validity will be queried.
If the path error was transitory and the DSM feels that the path is good,
then this request will be re-issued to determine whether it is usable.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
PathId - Value set in SetPathId.
DsmId - DSM Id returned during DsmInquire.
Return Value:
TRUE if the path is active. FALSE otherwise.
--*/
{
PDSM_FAILOVER_GROUP foGroup;
PDSM_DEVICE_INFO deviceInfo = DsmId;
PDSM_GROUP_ENTRY group = deviceInfo->Group;
PDSM_CONTEXT dsmContext = (PDSM_CONTEXT) DsmContext;
KIRQL irql;
BOOLEAN retVal;
ULONG SpecialHandlingFlag = 0;
//
// 1. If PR and reserved by this node, register the PR keys.
// 2. Find the FOG for the passed in PathId
// 3. Depending on the LB policy, set the appropriate devInfo states
// If FailOver, and DesiredState is AO, change the active
// devInfos to non-active state and make this one AO.
// If ALUA supported, send down SetTPG to make this change,
// else directly make the change.
// If RR/LWP/LQD, make this DevInfo ActiveOptimized.
// If RRS, and DesiredState is AO, change the active devInfos to
// their desired states and then make this one AO.
// If DesiredState is not AO, find a devInfo in AO state. If
// one is found, make this devInfo's state its desired state,
// else if one isn't found, make this one AO.
// 3. If this is preferredPath, and LB policy is failover-only, change the
// access state of deviceInfo to AO.
// If there is another devInfo currently in AO, change its state too.
// If ALUA supported, send down SetTPG to make these changes.
// 4. Get the appropriate AO DeviceInfo and mark the group's PTBU to its
// pathId.
//
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): Entering function.\n",
DsmId));
//
// Initialize this instance to be usable so that during the possible processing
// of PR register, this device can be a candidate for certain kind of requests.
//
deviceInfo->Usable = TRUE;
//
// New path arriving. If this Node owns the reservation register this path.
//
if (group->PRKeyValid) {
NTSTATUS prRegStatus;
ULONG i;
PDSM_DEVICE_INFO devInfo;
ULONG ordinal;
prRegStatus = DsmpRegisterPersistentReservationKeys(deviceInfo, TRUE);
deviceInfo->RegisterServiced = TRUE;
if (NT_SUCCESS(prRegStatus)) {
deviceInfo->PRKeyRegistered = TRUE;
} else {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): Failed (status %x) to register PR key\n",
deviceInfo,
prRegStatus));
}
for (i = 0; i < group->NumberDevices; i++) {
devInfo = group->DeviceList[i];
if (devInfo && devInfo == deviceInfo) {
ordinal = (1 << i);
group->ReservationList |= ordinal;
break;
}
}
}
irql = ExAcquireSpinLockExclusive(&(dsmContext->DsmContextLock));
//
// Get the F.O. Group information.
//
foGroup = DsmpFindFOGroup(DsmContext, PathId);
//
// If there are any devices on this path, and it's not in a failed state
// it's capable of handling requests. So it's active.
//
if ((foGroup) &&
(foGroup->Count) &&
(foGroup->State == DSM_FG_NORMAL)) {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): Path %p is usable.\n",
DsmId,
PathId));
retVal = TRUE;
//
// Update the next path to be used for the group if it not set already.
//
deviceInfo = (PDSM_DEVICE_INFO)DsmId;
group = deviceInfo->Group;
DSM_ASSERT(group != NULL);
DSM_ASSERT(group->GroupSig == DSM_GROUP_SIG);
//
// If an invalidated path came back online before PnP removes came in,
// then MPIO's path recovery thread would have sent down a PathVerify
// just moments before by which we changed the state of the FOG to
// normal. Now it is time to change the deviceInfo's state to a "good"
// state.
//
if (deviceInfo->State >= DSM_DEV_FAILED) {
DSM_ASSERT(deviceInfo->State == DSM_DEV_INVALIDATED);
if (DsmpIsSymmetricAccess(deviceInfo)) {
//
// Mark it as AO. The SetLBForPathArrival will update the state
// appropriately.
//
deviceInfo->State = DSM_DEV_ACTIVE_OPTIMIZED;
} else {
//
// Set it to the state that was reported during the last RTPG
// call that was made.
//
deviceInfo->State = deviceInfo->ALUAState;
}
}
if (DsmpIsSymmetricAccess(deviceInfo)) {
DsmpSetLBForPathArrival(DsmContext, deviceInfo, SpecialHandlingFlag);
} else {
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
DsmpSetLBForPathArrivalALUA(DsmContext, deviceInfo, SpecialHandlingFlag);
irql = ExAcquireSpinLockExclusive(&(dsmContext->DsmContextLock));
}
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): State set to %d\n",
deviceInfo,
deviceInfo->State));
if (group->PathToBeUsed == NULL) {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): Will set PathToBeUsed for %p\n",
deviceInfo,
group));
deviceInfo = DsmpGetActivePathToBeUsed(group,
DsmpIsSymmetricAccess(deviceInfo),
SpecialHandlingFlag);
if (deviceInfo != NULL) {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): FOG %p set for PathToBeUsed for %p\n",
deviceInfo,
deviceInfo->FailGroup,
group));
InterlockedExchangePointer(&(group->PathToBeUsed), deviceInfo->FailGroup);
} else {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): No active/alternative path available for group %p\n",
DsmId,
group));
InterlockedExchangePointer(&(group->PathToBeUsed), NULL);
}
}
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): Path %p is NOT usable.\n",
DsmId,
PathId));
retVal = FALSE;
}
((PDSM_DEVICE_INFO)DsmId)->Usable = retVal;
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmIsPathActive (DevInfo %p): Exiting function with retVal = %!bool!.\n",
DsmId,
retVal));
return retVal;
}
NTSTATUS
DsmPathVerify(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId,
_In_ IN PVOID PathId
)
/*++
Routine Description:
This routine ensures that the path to the device indicated by DsmId
is healthy. It's called periodically by the bus driver, and also
after a fail-over condition has been dealt with to ensure that
the path is able to handle requests.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
DsmId - Value returned from DMSInquire.
PathId - Value set in SetPathId.
Return Value:
NTSTATUS
--*/
{
PDSM_CONTEXT dsmCtxt = (PDSM_CONTEXT) DsmContext;
PDSM_DEVICE_INFO deviceInfo = DsmId;
PDSM_FAILOVER_GROUP foGroup;
NTSTATUS status = STATUS_UNSUCCESSFUL;
BOOLEAN found = FALSE;
KIRQL irql;
PLIST_ENTRY entry;
PDSM_FOG_DEVICELIST_ENTRY fogDeviceListEntry = NULL;
PDSM_GROUP_ENTRY group = deviceInfo->Group;
ULONG SpecialHandlingFlag = 0;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmPathVerify (DevInfo %p): Entering function.\n",
DsmId));
if (DsmpIsDeviceInitialized(deviceInfo)) {
irql = ExAcquireSpinLockExclusive(&(dsmCtxt->DsmContextLock));
//
// Get the failover group
//
foGroup = DsmpFindFOGroup(DsmContext, PathId);
if (foGroup) {
//
// Find the device.
//
for (entry = foGroup->FOG_DeviceList.Flink;
entry != &foGroup->FOG_DeviceList;
entry = entry->Flink) {
fogDeviceListEntry = CONTAINING_RECORD(entry, DSM_FOG_DEVICELIST_ENTRY, ListEntry);
if (fogDeviceListEntry && fogDeviceListEntry->DeviceInfo == deviceInfo) {
status = STATUS_SUCCESS;
found = TRUE;
break;
}
}
} else {
//
// This is not a good thing. It indicates that either we
// returned a bogus path to the bus-driver on a fail-over,
// or that the path evaporated between polls and PnP hasn't
// torn stuff down.
//
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmPathVerify (DevInfo %p): Failed to find failover group for path %p.\n",
DsmId,
PathId));
status = STATUS_DEVICE_NOT_CONNECTED;
}
ExReleaseSpinLockExclusive(&(dsmCtxt->DsmContextLock), irql);
if (NT_SUCCESS(status)) {
if (found) {
//
// Send down TUR if ALUA is not supported.
// Else, send down ReportTargetPortGroups (sending TUR down non-A/O path will
// always result in a check condition).
//
if (deviceInfo->ALUASupport == DSM_DEVINFO_ALUA_NOT_SUPPORTED) {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmPathVerify (DevInfo %p): Sending TUR using %p to verify path %p.\n",
DsmId,
deviceInfo,
deviceInfo->FailGroup->PathId));
status = DsmSendTUR(deviceInfo->TargetObject);
} else {
//
// Check for whether we should ignore sending down an RTPG:
// Flag set indicates that this PathVerify() is happening in response to device
// arrival and can be skipped since Inquire() has just already sent down an RTPG.
// All that needs to be done is to clear the flag so that subsequent PathVerify()
// sent in response to InitiateFO will send RTPG as a ping.
// This is an optimization with the idea of helping speed up boot time, which is
// is adversely impacted, especially if there are many LUNs, each with many paths.
//
if (deviceInfo->IgnorePathVerify) {
deviceInfo->IgnorePathVerify = FALSE;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmPathVerify (DevInfo %p): Returning success immediately since RTPG was already just sent.\n",
DsmId));
status = STATUS_SUCCESS;
} else {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmPathVerify (DevInfo %p): Sending RTPG using %p to verify path %p.\n",
DsmId,
deviceInfo,
deviceInfo->FailGroup->PathId));
status = DsmpGetDeviceALUAState(dsmCtxt, deviceInfo, NULL);
//
// Since this RTPG may have resulted in us losing a UA, adjust
// the states if needed.
//
if (NT_SUCCESS(status)) {
DsmpAdjustDeviceStatesALUA(group, NULL, SpecialHandlingFlag);
}
}
}
}
if (NT_SUCCESS(status)) {
if (deviceInfo->State >= DSM_DEV_FAILED) {
foGroup->State = DSM_FG_NORMAL;
deviceInfo->State = deviceInfo->LastKnownGoodState;
}
}
}
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmPathVerify (DevInfo %p): Exiting function with status %x.\n",
DsmId,
status));
return status;
}
NTSTATUS
DsmInvalidatePath(
_In_ IN PVOID DsmContext,
_In_ IN ULONG ErrorMask,
_In_ IN PVOID PathId,
_Inout_ IN OUT PVOID *NewPathId
)
/*++
Routine Description:
This routine will mark up devices as failed on PathId, and find
an appropriate path to return to MPIO.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
ErrorMask - Value returned from InterpretError.
PathId - The failing path.
NewPathId - Pointer to the new path.
Return Value:
NTSTATUS of the operation.
--*/
{
PDSM_CONTEXT context = DsmContext;
PDSM_FAILOVER_GROUP failGroup;
PDSM_FAILOVER_GROUP newPath = NULL;
PDSM_FAILOVER_GROUP pathId;
PDSM_DEVICE_INFO deviceInfo;
LIST_ENTRY reservedDeviceList;
NTSTATUS status = STATUS_SUCCESS;
KIRQL irql;
PLIST_ENTRY entry;
PDSM_FOG_DEVICELIST_ENTRY fogDeviceListEntry = NULL;
BOOLEAN lockHeld = FALSE;
UNREFERENCED_PARAMETER(ErrorMask);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmInvalidatePath (PathId %p): Entering function.\n",
PathId));
DSM_ASSERT(ErrorMask & DSM_FATAL_ERROR);
*NewPathId = NULL;
InitializeListHead(&reservedDeviceList);
irql = ExAcquireSpinLockExclusive(&(context->DsmContextLock));
lockHeld = TRUE;
//
// Get the fail-over group corresponding to the PathId.
//
failGroup = DsmpFindFOGroup(DsmContext, PathId);
if (!failGroup || failGroup->State == DSM_FG_FAILED) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInvalidatePath (PathId %p): Failed to find FailOver group.\n",
PathId));
status = STATUS_NO_SUCH_DEVICE;
goto __Exit_DsmInvalidatePath;
}
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_RW,
"DsmInvalidatePath (PathId %p): Context %p, FOG %p failing.\n",
PathId,
DsmContext,
failGroup));
//
// Mark the path as failed.
//
failGroup->State = DSM_FG_FAILED;
//
// Check to see whether the port driver and PnP removed the devices
// BEFORE the fail-over indication actually occurred. Work-around
// of several Fibre miniports.
//
if (failGroup->Count == 0) {
//
// There are no longer any devices in this fail-over group, which means
// in order to get a back-pointer to the groups using this fail-over
// group, we need to go through the "zombie" group list. This should
// allow us to find a new path ID to return.
//Then go through failGroup->ZombieGroupList to do failover for each group.
//
PDSM_ZOMBIEGROUP_ENTRY group;
PDSM_GROUP_ENTRY groupEntry;
//
// Initialize all the entries to indicate that they haven't been processed.
//
for (entry = failGroup->ZombieGroupList.Flink; entry != &(failGroup->ZombieGroupList); entry = entry->Flink) {
group = CONTAINING_RECORD(entry, DSM_ZOMBIEGROUP_ENTRY, ListEntry);
group->Processed = FALSE;
}
//
// Since we need to drop the spin lock while processing an entry, it is possible
// that a removal in parallel frees up this entry during that time, thus making it
// impossible for us to move to the next entry in the list.
// In order to safely access each of the entries, we mark an entry as being processed
// just before dropping the spinlock, and always start processing from the beginning
// of the list, skipping over the already processed ones.
//
entry = failGroup->ZombieGroupList.Flink;
while (entry != &(failGroup->ZombieGroupList)) {
group = CONTAINING_RECORD(entry, DSM_ZOMBIEGROUP_ENTRY, ListEntry);
entry = entry->Flink;
if (!group || !group->Group || group->Processed) {
continue;
}
group->Processed = TRUE;
groupEntry = group->Group;
ExReleaseSpinLockExclusive(&context->DsmContextLock, irql);
lockHeld = FALSE;
pathId = DsmpSetNewPathUsingGroup((PDSM_CONTEXT)DsmContext, groupEntry);
if (!newPath) {
newPath = pathId; // Save off first good alternative path that we find
}
if (!lockHeld) {
irql = ExAcquireSpinLockExclusive(&(context->DsmContextLock));
lockHeld = TRUE;
entry = failGroup->ZombieGroupList.Flink;
}
}
if (!newPath) {
//
// This indicates that all of the devices have already been removed.
// If there were reservations outstanding, the RemoveDevice code
// should have updated them.
//
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInvalidatePath (PathId %p): Failed to find new path using zombie group list.\n",
PathId));
}
} else {
//
// Process each device in the fail-over group
//
for (entry = failGroup->FOG_DeviceList.Flink;
entry != &failGroup->FOG_DeviceList;
entry = entry->Flink) {
fogDeviceListEntry = CONTAINING_RECORD(entry, DSM_FOG_DEVICELIST_ENTRY, ListEntry);
if (!fogDeviceListEntry) {
continue;
}
//
// Get the deviceInfo.
//
deviceInfo = fogDeviceListEntry->DeviceInfo;
if (!(DsmpIsDeviceFailedState(deviceInfo->State))) {
deviceInfo->LastKnownGoodState = deviceInfo->State;
}
//
// Set the state of the Failing Device
//
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_INVALIDATED;
InterlockedIncrement(&deviceInfo->BlockRemove);
ExReleaseSpinLockExclusive(&(context->DsmContextLock), irql);
lockHeld = FALSE;
pathId = DsmpSetNewPath(DsmContext, deviceInfo);
if (!newPath) {
newPath = pathId; // Save off first good alternative path that we find
}
if (!lockHeld) {
irql = ExAcquireSpinLockExclusive(&(context->DsmContextLock));
lockHeld = TRUE;
}
InterlockedDecrement(&deviceInfo->BlockRemove);
}
}
if (!newPath) {
//
// This indicates that no acceptable paths
// were found. Return the error to mpctl.
//
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInvalidatePath (PathId %p): No valid path found.\n",
PathId));
status = STATUS_NO_SUCH_DEVICE;
} else {
//
// return the new path.
//
*NewPathId = newPath->PathId;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_RW,
"DsmInvalidatePath (PathId %p): Returning %p as newPath.\n",
PathId,
newPath->PathId));
}
__Exit_DsmInvalidatePath:
if (lockHeld) {
ExReleaseSpinLockExclusive(&(context->DsmContextLock), irql);
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmInvalidatePath (PathId %p): Exiting function with status %x.\n",
PathId,
status));
return status;
}
NTSTATUS
DsmMoveDevice(
_In_ IN PVOID DsmContext,
_In_ IN PDSM_IDS DsmIds,
_In_ IN PVOID MPIOPath,
_In_ IN PVOID SuggestedPath,
_In_ IN ULONG Flags
)
/*++
Routine Description:
This routine is invoked in response to an administrative request.
The device that's associated with SuggestedPath will be made active, and the
current active device, moved to stand-by.
Arguments:
DsmContext - Context value given to the multipath driver during registration.
DsmIds - The collection of DSM IDs that pertain to the MPDisk.
MPIOPath - The original path value passed to SetDeviceInfo.
SuggestedPath - The path which should become the active path.
Flags - Bitmask indicating the intent of the move.
Return Value:
NTSTATUS - STATUS_SUCCESS, unless SuggestedPath is somehow invalid.
STATUS_INVALID_PARAMETER is ADMIN is set and the path is invalid.
--*/
{
PDSM_CONTEXT context = DsmContext;
PDSM_DEVICE_INFO deviceInfo;
PDSM_FAILOVER_GROUP failGroup;
ULONG i;
NTSTATUS status;
KIRQL irql;
BOOLEAN adminRequest = FALSE;
PDSM_GROUP_ENTRY group = NULL;
ULONG SpecialHandlingFlag = 0;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_WMI,
"DsmMoveDevice (DsmIds %p): Entering function - DsmContext %p MPIOPath (%p) SuggestedPath %p.\n",
DsmIds,
DsmContext,
MPIOPath,
SuggestedPath));
//
// Capture the value of the ADMIN flag bit.
// Currently, permanent assignment of the device to "preferred path" isn't supported.
// This driver doesn't care about the pending remove flag (currently).
//
adminRequest = (BOOLEAN)(Flags & DSM_MOVE_ADMIN_REQUEST);
irql = ExAcquireSpinLockExclusive(&(context->DsmContextLock));
group = ((PDSM_DEVICE_INFO)(DsmIds->IdList[0]))->Group;
//
// Find the first active device.
//
deviceInfo = DsmpGetActivePathToBeUsed(group,
DsmpIsSymmetricAccess((PDSM_DEVICE_INFO)DsmIds->IdList[0]),
SpecialHandlingFlag);
if (!deviceInfo) {
//
// Didn't find an active device. Should LOG.
// Use the first one to piggy-back the request.
//
deviceInfo = DsmIds->IdList[0];
}
//
// Get the fail-over group associated with the Path.
//
failGroup = DsmpFindFOGroup(DsmContext,
SuggestedPath);
if (!failGroup) {
//
// The caller has made a terrible mistake.
// If it's an ADMIN request, blow it off.
//
if (adminRequest) {
status = STATUS_INVALID_PARAMETER;
} else {
//
// Try to set another path.
//
// Note that failGroup will be NULL going into
// SetNewPath. This is OK.
//
status = STATUS_SUCCESS;
}
} else {
status = STATUS_SUCCESS;
}
if (status == STATUS_SUCCESS) {
//
// Set the new path, using SuggestedPath.
//
InterlockedIncrement(&deviceInfo->BlockRemove);
ExReleaseSpinLockExclusive(&context->DsmContextLock, irql);
failGroup = DsmpSetNewPath(context,
deviceInfo);
irql = ExAcquireSpinLockExclusive(&(context->DsmContextLock));
InterlockedDecrement(&deviceInfo->BlockRemove);
//
// If we were able to make the suggested path active, that should be used.
//
for (i = 0, status = STATUS_UNSUCCESSFUL; i < DsmIds->Count && !NT_SUCCESS(status); i++) {
deviceInfo = DsmIds->IdList[i];
if (deviceInfo->FailGroup == failGroup) {
if (deviceInfo->State == DSM_DEV_ACTIVE_OPTIMIZED) {
InterlockedExchangePointer(&(group->PathToBeUsed), (PVOID)failGroup);
status = STATUS_SUCCESS;
}
}
}
}
ExReleaseSpinLockExclusive(&(context->DsmContextLock), irql);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_WMI,
"DsmMoveDevice (DsmIds %p): Exiting function with status %x.\n",
DsmIds,
status));
return status;
}
NTSTATUS
DsmRemovePending(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId
)
/*++
Routine Description:
This routine indicates that the device represented by DsmId will be
removed, so the deviceInfo is marked up to indicate the pending removal,
so that it won't be used.
Arguments:
DsmContext - Context value given to the multipath driver
during registration.
DsmId - Value referring to the failed device.
Return Value:
STATUS_SUCCESS
--*/
{
PDSM_CONTEXT dsmContext = DsmContext;
PDSM_DEVICE_INFO deviceInfo = DsmId;
KIRQL irql;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmRemovePending (DevInfo %p): Entering function.\n",
DsmId));
//
// DsmpSetNewPath then finds the next available device. This is basically a
// fail-over for just this device.
//
InterlockedIncrement(&deviceInfo->BlockRemove);
DsmpSetNewPath(DsmContext, deviceInfo);
irql = ExAcquireSpinLockExclusive(&(dsmContext->DsmContextLock));
InterlockedDecrement(&deviceInfo->BlockRemove);
if (!(DsmpIsDeviceFailedState(deviceInfo->State))) {
deviceInfo->LastKnownGoodState = deviceInfo->State;
}
//
// Mark the device as being unavailable since remove will be sent shortly.
//
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_REMOVE_PENDING;
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmRemovePending (DevInfo %p): Exiting function.\n",
DsmId));
return STATUS_SUCCESS;
}
NTSTATUS
DsmRemoveDevice(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId,
_In_ IN PVOID PathId
)
/*++
Routine Description:
The device is gone and the port pdo has been removed. This routine will
update the internal structures and free any allocations.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
DsmId - Value referring to the failed device.
PathId - The path on which the Device lives.
Return Value:
STATUS_SUCCESS
--*/
{
PDSM_CONTEXT dsmContext = DsmContext;
PDSM_DEVICE_INFO deviceInfo = DsmId;
KIRQL irql;
PDSM_FAILOVER_GROUP failGroup = deviceInfo->FailGroup;
PDSM_GROUP_ENTRY group = deviceInfo->Group;
LONG block;
UNREFERENCED_PARAMETER(PathId);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmRemoveDevice (DevInfo %p): Entering function.\n",
DsmId));
do {
irql = ExAcquireSpinLockExclusive(&(dsmContext->DsmContextLock));
block = deviceInfo->BlockRemove;
NT_ASSERT(block >= 0);
if (block) {
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
KeStallExecutionProcessor(10000);
}
} while (block);
if (!(DsmpIsDeviceFailedState(deviceInfo->State))) {
deviceInfo->LastKnownGoodState = deviceInfo->State;
}
deviceInfo->PreviousState = deviceInfo->State;
deviceInfo->State = DSM_DEV_REMOVED;
//
// Decrement the reference count for this device's controller entry and
// delete the entry if its reference count is now zero.
//
if (deviceInfo->Controller) {
if (InterlockedDecrement((LONG volatile*)&(deviceInfo->Controller->RefCount)) == 0) {
RemoveEntryList(&(deviceInfo->Controller->ListEntry));
DsmpFreeControllerEntry(dsmContext, deviceInfo->Controller);
deviceInfo->Controller = NULL;
InterlockedDecrement((LONG volatile*)&(dsmContext->NumberControllers));
}
}
//
// Ensure that the device has been fully initialized before trying to
// remove it from the FOG. If SetDeviceInfo has yet to be invoked, there
// will yet to be an association set.
//
if (failGroup) {
//
// Remove its entry from the Fail-Over Group.
//
DsmpRemoveDeviceFailGroup(DsmContext, failGroup, deviceInfo, FALSE);
}
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
//
// Remove it from it's multi-path group. This has the side-effect
// of cleaning up the Group if the number of devices goes to zero.
//
DsmpRemoveDeviceEntry(DsmContext, group, deviceInfo);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmRemoveDevice (DevInfo %p): Exiting function.\n",
DsmId));
return STATUS_SUCCESS;
}
NTSTATUS
DsmRemovePath(
_In_ IN PDSM_CONTEXT DsmContext,
_In_ IN PVOID PathId
)
/*++
Routine Description:
This routine indicates that the path is no longer valid, and that it should
be removed. Internal counts will be updated and any allocations associated
with this path freed.
Arguments:
DsmContext - Context value given to the multipath driver during registration.
PathId - The path to remove.
Return Value:
NTSTATUS of the operation.
--*/
{
PDSM_FAILOVER_GROUP failGroup;
KIRQL irql;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmRemovePath (PathId %p): Entering function.\n",
PathId));
irql = ExAcquireSpinLockExclusive(&(DsmContext->DsmContextLock));
failGroup = DsmpFindFOGroup(DsmContext, PathId);
if (failGroup) {
//
// The claim is that a path won't be removed, until all
// the devices on it are.
//
if (failGroup->Count == 0) {
//
// Yank it from the list.
//
RemoveEntryList(&failGroup->ListEntry);
InterlockedDecrement((LONG volatile*)&DsmContext->NumberFOGroups);
//
// Move this over to the stale FOG list if there are inflight requests.
// Otherwise free the allocation.
//
if (InterlockedCompareExchange(&failGroup->NumberOfRequestsInFlight, 0, 0) > 0) {
failGroup->State = DSM_FG_PENDING_REMOVE;
InsertTailList(&DsmContext->StaleFailGroupList, &failGroup->ListEntry);
InterlockedIncrement((LONG volatile*)&DsmContext->NumberStaleFOGroups);
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmRemovePath (PathId %p): Outstanding requests %d. Moving FOGroup %p with path %p to stale path list.\n",
PathId,
failGroup->NumberOfRequestsInFlight,
failGroup,
failGroup->PathId));
} else {
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmRemovePath (PathId %p): Removing FOGroup %p with path %p. Count of FOGroups %d.\n",
PathId,
failGroup,
failGroup->PathId,
DsmContext->NumberFOGroups));
//
// Free the zombie group list and then the failover group.
//
DsmpFreeZombieGroupList(failGroup);
DsmpFreePool(failGroup);
}
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmRemovePath (PathId %p): Count %d. Not removing FOGroup %p.\n",
PathId,
failGroup->Count,
failGroup));
//
// Should never be here.
//
NT_ASSERT(failGroup->Count == 0);
}
} else {
//
// It's already been removed.
//
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_PNP,
"DsmRemovePath (PathId %p): Did not find the FO group.\n",
PathId));
NT_ASSERT(failGroup);
}
ExReleaseSpinLockExclusive(&(DsmContext->DsmContextLock), irql);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_PNP,
"DsmRemovePath (PathId %p): Exiting function.\n",
PathId));
return STATUS_SUCCESS;
}
PVOID
DsmLBGetPath(
_In_ IN PVOID DsmContext,
_In_ IN PSCSI_REQUEST_BLOCK Srb,
_In_ IN PDSM_IDS DsmList,
_In_ IN PVOID CurrentPath,
_Out_ OUT NTSTATUS *Status
)
/*++
Routine Description:
This routine is used by mpio to handle load-balancing.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
Srb - The current read/write Srb.
DsmList - List of our DSM IDs.
CurrentPath - The last path that was returned for this multi-path group.
Status - Storage to place NTSTATUS of the call.
Return Value:
The path ID to which the request should be sent.
--*/
{
PDSM_CONTEXT dsmContext = DsmContext;
PDSM_DEVICE_INFO deviceInfo;
PDSM_GROUP_ENTRY group;
PDSM_FAILOVER_GROUP failGroup = NULL;
PVOID newPath = NULL;
PDSM_FAILOVER_GROUP oldFailGroup = NULL;
PDSM_FAIL_PATH_PROCESSING_LIST_ENTRY failPathDevInfoEntry = NULL;
PCDB cdb = NULL;
UCHAR opCode = 0xFF;
BOOLEAN lockInExclusiveMode = FALSE;
ULONG SpecialHandlingFlag = 0;
if (Srb) {
cdb = SrbGetCdb(Srb);
if (cdb) {
opCode = cdb->AsByte[0];
}
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmLBGetPath (DsmIds %p): Entering function.\n",
DsmList));
//
// Up-front checking to minimally validate the list of
// DsmId's being passed in.
//
NT_ASSERT(DsmList->Count && DsmList->IdList[0]);
if (!(DsmList->Count && DsmList->IdList[0])) {
*Status = STATUS_NO_SUCH_DEVICE;
goto __Exit_DsmLBGetPath;
}
deviceInfo = DsmList->IdList[0];
group = deviceInfo->Group;
failGroup = DsmpGetPath(dsmContext, DsmList, Srb, SpecialHandlingFlag);
//
// If there wasn't a single active/optimized path found, check to see if
// there is an STPG in progress that may be making a path A/O.
//
if (!failGroup) {
//
// Take the last path used.
//
oldFailGroup = DsmpFindFOGroup(dsmContext, CurrentPath);
//
// Find the devInfo corresponding to this path.
//
deviceInfo = DsmpFindDevInfoFromGroupAndFOGroup(dsmContext,
group,
oldFailGroup);
if (deviceInfo) {
//
// Check if there is an alternate devInfo to be used temporarily
// for this deviceInfo
//
failPathDevInfoEntry = DsmpFindFailPathDevInfoEntry(dsmContext,
group,
deviceInfo);
if (failPathDevInfoEntry) {
//
// Use the alternate devInfo for now temporarily while the STPG
// that was previously sent (asynchronously) works on making the
// appropriate path active/optimized.
//
failGroup = (failPathDevInfoEntry->TempDeviceInfo)->FailGroup;
}
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_RW,
"DsmLBGetPath (DsmIds %p): Couldn't find FOG but FO in progress, so returning devInfo %p (FOG %p path %p).\n",
DsmList,
deviceInfo,
deviceInfo->FailGroup,
deviceInfo->FailGroup->PathId));
} else {
//
// Check if there is an RTPG in progress, if yes, return some path
// for the IO to be sent down.
//
if (InterlockedCompareExchange((LONG volatile*)&group->InFlightRTPG, 0, 0)) {
BOOLEAN sendTPG = FALSE;
deviceInfo = DsmpFindStandbyPathToActivateALUA(group, &sendTPG, SpecialHandlingFlag);
if (deviceInfo) {
failGroup = deviceInfo->FailGroup;
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_RW,
"DsmLBGetPath (DsmIds %p): Couldn't find FOG but RTPG inflight, so returning devInfo %p (FOG %p path %p).\n",
DsmList,
deviceInfo,
deviceInfo->FailGroup,
deviceInfo->FailGroup->PathId));
} else {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_RW,
"DsmLBGetPath (DsmIds %p): Couldn't find FOG but RTPG inflight, even then couldn't find alternative devInfo.\n",
DsmList));
}
}
}
}
if (failGroup) {
newPath = failGroup->PathId;
*Status = STATUS_SUCCESS;
//
// If this is a retried request, our SetCompletion would have been bypassed,
// and our completion routine won't yet get called, so update the old and
// the new paths' stats.
//
if (Srb && DsmIsReadWrite(opCode)) {
PDSM_FAILOVER_GROUP oldPath;
PIRP irp = (PIRP)SrbGetOriginalRequest(Srb);
PIO_STACK_LOCATION irpStack;
//
// This indicates that the request is being retried. So we need to:
// 1. Update old path's and new path's request count
// 2. If the old path was supposed to be removed, check if there are
// no more requests are outstanding, and if yes, remove the path
//
irpStack = IoGetCurrentIrpStackLocation(irp);
oldPath = irpStack->Parameters.Others.Argument3;
if (oldPath) {
NT_ASSERT(oldPath->FailOverSig == DSM_FOG_SIG);
if (DsmpDecrementCounters(oldPath, Srb)) {
//
// If there are no requests on a path that is supposed to be removed,
// remove it now.
//
if (oldPath->State == DSM_FG_PENDING_REMOVE) {
KIRQL irql;
NT_ASSERT(oldPath->Count == 0);
//
// We need to acquire the DsmContextLock in Exclusive mode since
// we are removing a path from the Failover Group list.
//
irql = ExAcquireSpinLockExclusive(&(dsmContext->DsmContextLock));
lockInExclusiveMode = TRUE;
RemoveEntryList(&oldPath->ListEntry);
InterlockedDecrement((LONG volatile*)&dsmContext->NumberStaleFOGroups);
ExReleaseSpinLockExclusive(&(dsmContext->DsmContextLock), irql);
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_PNP,
"DsmLBGetPath (DsmIds %p): Removing FOGroup %p with path %p.\n",
DsmList,
oldPath,
oldPath->PathId));
DsmpFreePool(oldPath);
}
}
irpStack->Parameters.Others.Argument3 = failGroup;
DsmpIncrementCounters(failGroup, Srb);
}
}
} else {
*Status = STATUS_NO_SUCH_DEVICE;
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmLBGetPath (DsmIds %p): Failed to get FO group in LBGetPath.\n",
DsmList));
}
__Exit_DsmLBGetPath:
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmLBGetPath (DsmIds %p): Exiting function returning path %p for request %p.\n",
DsmList,
newPath,
Srb));
return newPath;
}
_Success_(return == DSM_PATH_SET)
ULONG
DsmCategorizeRequest(
_In_ IN PVOID DsmContext,
_In_ IN PDSM_IDS DsmIds,
_In_ IN PIRP Irp,
_In_ IN PSCSI_REQUEST_BLOCK Srb,
_In_ IN PVOID CurrentPath,
_Outptr_result_maybenull_ OUT PVOID *PathId,
_Out_ OUT NTSTATUS *Status
)
/*++
Routine Description:
This routine is called when a request is received other than a read/write.
It will determine the best path to which the request is to be sent.
In order to support clusters, reserve and release need to be handled
via SrbControl.
Arguments:
DsmContext - Context value given to the multipath driver during
registration.
DsmIds - List of our DSM IDs.
Irp - The Irp containing Srb.
Srb - The current non-read/write Srb.
CurrentPath - The last path that was returned for this multi-path group.
PathId - Placeholder for the PathID
Status - Storage to place NTSTATUS of the call.
Return Value:
DSM_PATH_SET - Indicates PathID is valid.
DSM_ERROR - Couldn't get a path.
--*/
{
ULONG dsmStatus;
NTSTATUS status = STATUS_UNSUCCESSFUL;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_IOCTL,
"DsmCategorizeRequest (DsmIds %p): Entering function.\n",
DsmIds));
//
// Determine whether this is a special-case request.
//
if (DsmpReservationCommand(Irp, Srb)) {
dsmStatus = DSM_WILL_HANDLE;
goto __Exit_DsmCategorizeRequest;
}
//
// If this is a mpio pass through or a mpio pass through direct request,
// pick the path that corresponds to the pathId specified.
//
if (DsmpMpioPassThroughPathCommand(Irp)) {
*PathId = DsmpGetPathIdFromPassThroughPath(DsmContext,
DsmIds,
Irp,
&status);
} else {
//
// For requests other than reservation-handling and pass through, punt
// it back to the bus-driver. Need to get a path for the request first,
// so call the Load-Balance function.
//
*PathId = DsmLBGetPath(DsmContext,
Srb,
DsmIds,
CurrentPath,
&status);
}
if (NT_SUCCESS(status)) {
if (!*PathId) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_IOCTL,
"DsmCategorizeRequest (DsmIds %p): DSM_PATH_SET didn't return a path.\n",
DsmIds));
}
//
// Indicate that the path is updated, and mpctl should handle the request.
//
dsmStatus = DSM_PATH_SET;
} else {
//
// Indicate the error back to mpctl.
//
dsmStatus = DSM_ERROR;
//
// Mark-up the Srb to show that a failure has occurred.
// This value is really only for this DSM to know what to do
// in the InterpretError routine - Fatal Error.
// It could be something more meaningful.
//
if (Srb) {
Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
}
*PathId = NULL;
}
//
// Pass back status info to mpctl.
//
*Status = status;
__Exit_DsmCategorizeRequest:
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_IOCTL,
"DsmCategorizeRequest (DsmIds %p): Exiting function with categorization %x.\n",
DsmIds,
dsmStatus));
return dsmStatus;
}
NTSTATUS
DsmBroadcastRequest(
_In_ IN PVOID DsmContext,
_In_ IN PDSM_IDS DsmIds,
_In_ IN PIRP Irp,
_In_ IN PSCSI_REQUEST_BLOCK Srb,
_In_ IN PKEVENT Event
)
/*++
Routine Description:
This routine is called when the DSM has indicated that Srb should be
sent to the device down all paths. The DSM will update IoStatus
information and status, but not complete the request.
Currently MSDSM doesn't have a need for this.
Arguments:
DsmIds - The collection of DSM IDs that pertain to the MPDisk.
Irp - Irp containing SRB.
Srb - Scsi request block
Event - DSM sets this once all sub-requests have completed and
the original request's IoStatus has been setup.
Return Value:
NTSTATUS of the operation.
--*/
{
NTSTATUS status = STATUS_INVALID_DEVICE_REQUEST;
UNREFERENCED_PARAMETER(DsmContext);
UNREFERENCED_PARAMETER(Srb);
UNREFERENCED_PARAMETER(Irp);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_IOCTL,
"DsmBroadcastRequest (DsmIds %p): Entering function.\n",
DsmIds));
//
// Currently nothing is handled via Broadcast. Just set the event to
// free up the request handling in the bus-driver.
//
NT_ASSERT(NT_SUCCESS(status));
KeSetEvent(Event, 0, FALSE);
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_IOCTL,
"DsmBroadcastReqeust (DsmIds %p): Exiting function with status %x.\n",
DsmIds,
status));
return status;
}
NTSTATUS
DsmSrbDeviceControl(
_In_ IN PVOID DsmContext,
_In_ IN PDSM_IDS DsmIds,
_In_ IN PIRP Irp,
_In_ IN PSCSI_REQUEST_BLOCK Srb,
_In_ IN PKEVENT Event
)
/*++
Routine Description:
This routine is called when the DSM has indicated that it wants to handle
it internally (via returning DSM_WILL_HANDLE in CategorizeRequest).
It should set IoStatus (Status and Information) and the Event, but not
complete the request.
Arguments:
DsmContext - The DSM's context
DsmIds - The collection of DSM IDs that pertain to the MPDISK.
Irp - Irp containing SRB.
Srb - Scsi request block
Event - Event to be set when the DSM is finished if DsmHandled is TRUE
Return Value:
NTSTATUS of the request.
--*/
{
PDSM_CONTEXT dsmContext = DsmContext;
PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS status;
UCHAR opCode = 0;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_IOCTL,
"DsmSrbDeviceControl (DsmIds %p): Entering function.\n",
DsmIds));
if (!DsmIds || !DsmIds->Count) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_IOCTL,
"DsmSrbDeviceControl (DsmIds %p): No DsmIds passed in.\n",
DsmIds));
status = STATUS_NO_SUCH_DEVICE;
goto __Exit_DsmSrbDeviceControl;
}
if (irpStack->MajorFunction == IRP_MJ_SCSI) {
//
// Determine the operation.
//
PCDB cdb = SrbGetCdb(Srb);
if (cdb) {
opCode = cdb->AsByte[0];
}
if (opCode == SCSIOP_PERSISTENT_RESERVE_OUT) {
status = DsmpPersistentReserveOut(dsmContext,
DsmIds,
Irp,
Srb,
Event);
} else if (opCode == SCSIOP_PERSISTENT_RESERVE_IN) {
status = DsmpPersistentReserveIn(dsmContext,
DsmIds,
Irp,
Srb,
Event);
} else {
//
// Should never be here.
//
DSM_ASSERT(FALSE);
status = STATUS_INVALID_DEVICE_REQUEST;
}
} else {
//
// Should never be here.
//
DSM_ASSERT(irpStack->MajorFunction == IRP_MJ_SCSI);
status = STATUS_INVALID_DEVICE_REQUEST;
}
__Exit_DsmSrbDeviceControl:
if (status != STATUS_PENDING) {
//
// Set-up the Irp status for mpio's completion of the request.
// If it was IRP_MJ_SCSI, one of the helper routines set Srb->SrbStatus
// already.
//
if ((irpStack->MajorFunction == IRP_MJ_SCSI) &&
(Srb != NULL) &&
(Srb->SrbStatus == SRB_STATUS_PENDING)) {
Srb->SrbStatus = SRB_STATUS_ERROR;
}
Irp->IoStatus.Status = status;
//
// Set the event to free up the request handling in the bus-driver.
//
KeSetEvent(Event, 0, FALSE);
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_IOCTL,
"DsmSrbDeviceControl (DsmIds %p): Exiting function with status %x.\n",
DsmIds,
status));
return status;
}
VOID
DsmSetCompletion(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId,
_In_ IN PIRP Irp,
_In_ IN PSCSI_REQUEST_BLOCK Srb,
_Inout_ IN OUT PDSM_COMPLETION_INFO DsmCompletion
)
/*++
Routine Description:
This routine is called before the actual submission of a request,
but after the categorisation of the I/O. This will be called only
for those requests not handled by the DSM directly:
Read/Write
Other requests not handled by SrbControl or Broadcast
Arguments:
DsmContext - The DSM's context.
DsmId - Identifer that was indicated when the request was
categorized (or be LBGetPath)
Irp - Irp containing Srb.
Srb - The request
DsmCompletion - Completion info structure to be filled out by DSM.
Return Value:
None
--*/
{
PDSM_CONTEXT dsmContext = DsmContext;
PDSM_DEVICE_INFO deviceInfo = DsmId;
PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
PDSM_FAILOVER_GROUP failGroup = deviceInfo->FailGroup;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmSetCompletion (DevInfo %p): Entering function.\n",
DsmId));
//
// Save off the path that was selected to service this request in Argument3.
//
irpStack->Parameters.Others.Argument3 = failGroup;
DsmpIncrementCounters(failGroup, Srb);
if (!dsmContext->DisableStatsGathering) {
//
// Indicate one more request on this device down this path.
//
InterlockedIncrement(&deviceInfo->NumberOfRequestsInProgress);
}
//
// Update the passed-in struct with our routine and context values.
//
DsmCompletion->DsmCompletionRoutine = DsmpRequestComplete;
DsmCompletion->DsmContext = DsmContext;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmSetCompletion (DevInfo %p): Exiting function.\n",
DsmId));
return;
}
ULONG
DsmInterpretError(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId,
_In_ IN PSCSI_REQUEST_BLOCK Srb,
_Inout_ IN OUT NTSTATUS *Status,
_Out_ OUT PBOOLEAN Retry,
_Out_ OUT PLONG RetryInterval,
...
)
/*++
Routine Description:
This routine is invoked by MPIO if Status is other than SUCCESS.
A few NTSTATUS and SRB_STATUS values indicate a fatal error.
Also checked are unit attentions, for which a retry is requested.
Arguments:
DsmContext - The DSM's context.
DsmId - Identifers returned from DMS_INQUIRE_DRIVER.
Srb - The Srb with an error.
Status - NTSTATUS of the operation. Can be updated.
Retry - Allows the DSM to indicate whether to retry the IO.
RetryInterval - Lets DSM specify (in seconds) when this specific I/O
should be retried. Use MAXLONG to use the default
retry interval. Use zero to retry immediately.
Return Value:
DSM_FATAL_ERROR indicates a fatal error.
--*/
{
//
// The requests that will be encountered can be divided into four categories:
// 1. The request that has failed.
// 2. Subsequent requests that were sent down the failing path that will
// complete with failure.
// 3. Requests that were already submitted to LBGetPath() just before InterpretError()
// was called for the failed request (but have yet to have the LB policy
// algo run).
// 4. Requests that come into the Dispatch() routine after the failed request
// has been processed by InterpretError().
//
// For the failed request:
// =======================
// 1. Find a standby path to make active/optimized.
// 2. Send STPG asynchronously as a scsi pass through via IRP_MJ_SCSI (this
// way it can be sent at DISPATCH_IRQL) after setting a completion routine.
// 3. Save the devInfo corresponding to the standby path for the failing devInfo.
// 4. Return FATAL to MPIO so that new IO are queued.
// 5. In the completion routine, update the new states for the devInfos. Then
// clear the saved (previously) standby devInfo for the failing devInfo.
//
// For the subsequent request that will fail (since it was sent on the failing path):
// ==================================================================================
// 1. If a standby devInfo has been saved off, it indicates that an STPG was
// already sent, so no need to send another one.
// 2. Return FATAL to MPIO so that this request gets queued.
//
// For the requests that were already submitted to LBGetPath() during this time:
// =============================================================================
// 1. If there is no active path, check if a standby devInfo has been saved
// away. If it has, return this path. Such requests will fail with check
// condition saying path used is in standby.
// 2. In InterpretError() retry (since the error indicates that request
// completed before STPG completed) without decrementing the remaining
// retries count.
//
// For new requests that come into Dispatch() after above processing:
// ==================================================================
// We don't need to worry about such requests, since MPIO will queue them
// automatically.
//
PDSM_DEVICE_INFO deviceInfo = DsmId;
ULONG errorMask = 0;
PVOID senseData = SrbGetSenseInfoBuffer(Srb);
UCHAR senseDataLength = SrbGetSenseInfoBufferLength(Srb);
BOOLEAN failover = FALSE;
BOOLEAN retry = FALSE;
BOOLEAN handled = FALSE;
BOOLEAN sendTPG = FALSE;
BOOLEAN tpgException = FALSE;
BOOLEAN devInfoException = FALSE;
PCDB cdb = SrbGetCdb(Srb);
UCHAR opCode = 0;
UCHAR scsiStatus = SrbGetScsiStatus(Srb);
BOOLEAN validSense = FALSE;
UCHAR senseKey = 0;
UCHAR addSenseCode = 0;
UCHAR addSenseCodeQualifier = 0;
if (cdb) {
opCode = cdb->AsByte[0];
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Entering function.\n",
DsmId));
*RetryInterval = MAXLONG;
if ((scsiStatus == SCSISTAT_RESERVATION_CONFLICT) ||
(*Status == STATUS_DEVICE_BUSY)) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Srb %p. Either busy or res. conflict (%x %x).\n",
DsmId,
Srb,
scsiStatus,
*Status));
}
//
// Go ahead and get the sense data if it's valid.
//
if (Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID) {
NT_ASSERT(senseData != NULL);
validSense = ScsiGetSenseKeyAndCodes(senseData,
senseDataLength,
SCSI_SENSE_OPTIONS_FIXED_FORMAT_IF_UNKNOWN_FORMAT_INDICATED,
&senseKey,
&addSenseCode,
&addSenseCodeQualifier);
}
//
// Sense data relating to logical block provisioning should be failed
// immediately back to the class layer for handling.
//
if (validSense) {
if (senseKey == SCSI_SENSE_NOT_READY &&
addSenseCode == SCSI_ADSENSE_LUN_NOT_READY &&
addSenseCodeQualifier == SCSI_SENSEQ_SPACE_ALLOC_IN_PROGRESS) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Temporary resource exhaustion. Fail Srb %p.\n",
DsmId,
Srb));
handled = TRUE;
} else if (senseKey == SCSI_SENSE_DATA_PROTECT &&
addSenseCode == SCSI_ADSENSE_WRITE_PROTECT &&
addSenseCodeQualifier == SCSI_SENSEQ_SPACE_ALLOC_FAILED_WRITE_PROTECT) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Permanent resource exhaustion. Fail Srb %p.\n",
DsmId,
Srb));
handled = TRUE;
} else if (senseKey == SCSI_SENSE_UNIT_ATTENTION &&
addSenseCode == SCSI_ADSENSE_LB_PROVISIONING &&
addSenseCodeQualifier == SCSI_SENSEQ_SOFT_THRESHOLD_REACHED) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Soft threshold reached. Fail Srb %p.\n",
DsmId,
Srb));
handled = TRUE;
} else if (senseKey == SCSI_SENSE_UNIT_ATTENTION &&
addSenseCode == SCSI_ADSENSE_OPERATING_CONDITIONS_CHANGED &&
addSenseCodeQualifier == SCSI_SENSEQ_INQUIRY_DATA_CHANGED) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Inquiry data changed. Fail Srb %p.\n",
DsmId,
Srb));
handled = TRUE;
} else if (senseKey == SCSI_SENSE_UNIT_ATTENTION &&
addSenseCode == SCSI_ADSENSE_PARAMETERS_CHANGED &&
addSenseCodeQualifier == SCSI_SENSEQ_CAPACITY_DATA_CHANGED) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Capacity data changed. Fail Srb %p.\n",
DsmId,
Srb));
handled = TRUE;
}
}
if (handled) {
return errorMask;
}
//
// Check the NT Status first.
// Several are clearly failover conditions.
//
switch (*Status) {
case STATUS_DEVICE_NOT_CONNECTED:
case STATUS_DEVICE_DOES_NOT_EXIST:
case STATUS_NO_SUCH_DEVICE:
case STATUS_DELETE_PENDING: {
//
// The port pdo has either been removed or is
// very broken. A fail-over is necessary.
//
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Will initiate fail over. Status %x. Opcode %x.\n",
DsmId,
*Status,
opCode));
handled = TRUE;
failover = TRUE;
break;
}
case STATUS_IO_DEVICE_ERROR: {
if (Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID) {
if (validSense) {
//
// See if it's a unit attention.
//
if (senseKey == SCSI_SENSE_UNIT_ATTENTION) {
switch (addSenseCode) {
case SCSI_ADSENSE_PARAMETERS_CHANGED: {
switch (addSenseCodeQualifier) {
case SPC3_SCSI_SENSEQ_ASYMMETRIC_ACCESS_STATE_CHANGED:
case SPC3_SCSI_SENSEQ_IMPLICIT_ASYMMETRIC_ACCESS_STATE_TRANSITION_FAILED: {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): TPG states have changed. Requesting retry on Srb %p. Will send asyn RTPG.\n",
DsmId,
Srb));
//
// Retry but after sending RTPG, which will update the path states.
//
sendTPG = TRUE;
retry = TRUE;
handled = TRUE;
errorMask = DSM_RETRY_DONT_DECREMENT;
if (addSenseCodeQualifier == SPC3_SCSI_SENSEQ_ASYMMETRIC_ACCESS_STATE_CHANGED) {
//
// Worth retrying on the same path.
//
devInfoException = TRUE;
NT_ASSERT(!tpgException);
}
break;
}
case SPC3_SCSI_SENSEQ_RESERVATIONS_RELEASED: {
//
// This request needs to be immediately retried down the same path.
//
retry = TRUE;
*RetryInterval = 0;
handled = TRUE;
InterlockedExchangePointer(&(deviceInfo->Group->PathToBeUsed), deviceInfo->FailGroup);
break;
}
case SPC3_SCSI_SENSEQ_MODE_PARAMETERS_CHANGED:
case SPC3_SCSI_SENSEQ_RESERVATIONS_PREEMPTED:
case SPC3_SCSI_SENSEQ_REGISTRATIONS_PREEMPTED:
case SPC3_SCSI_SENSEQ_CAPACITY_DATA_HAS_CHANGED: {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Failing request. STATUS_IO_DEVICE_ERROR (params changed). SrbStatus (%x) Scsi (%x) AddQual (%u).\n",
DsmId,
Srb->SrbStatus,
scsiStatus,
addSenseCodeQualifier));
//
// Just fail these back.
//
handled = TRUE;
break;
}
default: {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): UNIT_ATTENTION for params changed. ASCQ %x. Asking for retry on Srb %p.\n",
DsmId,
addSenseCodeQualifier,
Srb));
//
// Indicate that a retry is necessary.
//
retry = TRUE;
handled = TRUE;
break;
}
}
break;
}
case SPC3_SCSI_ADSENSE_COMMANDS_CLEARED_BY_ANOTHER_INITIATOR: {
if (addSenseCodeQualifier == 0x00) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): UNIT_ATTENTION (commands cleared by another initiator). Fail back to upper level. Srb %p.\n",
DsmId,
Srb));
//
// Commands cleared by another Initiator
//
handled = TRUE;
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): UNIT_ATTENTION (commands cleared by another initiator). ASCQ %x. Asking for retry on Srb %p.\n",
DsmId,
addSenseCodeQualifier,
Srb));
//
// Indicate that a retry is necessary.
//
retry = TRUE;
handled = TRUE;
}
break;
}
case SCSI_ADSENSE_OPERATING_CONDITIONS_CHANGED: {
if (addSenseCodeQualifier == SCSI_SENSEQ_VOLUME_SET_MODIFIED ||
addSenseCodeQualifier == SCSI_SENSEQ_REPORTED_LUNS_DATA_CHANGED) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): VolumeSet/LunsData changed. Fail Srb %p.\n",
DsmId,
Srb));
//
// Fail back to upper layers.
//
handled = TRUE;
break;
} else {
//
// Fall through to default case (ie. retry the request)
//
}
}
default: {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): UNIT_ATTENTION. ASC %x, ASCQ %x. Asking for retry on Srb %p.\n",
DsmId,
addSenseCode,
addSenseCodeQualifier,
Srb));
//
// Indicate that a retry is necessary.
//
retry = TRUE;
handled = TRUE;
break;
}
}
} else if (senseKey == SCSI_SENSE_NOT_READY) {
if (addSenseCode == SCSI_ADSENSE_LUN_NOT_READY) {
if (scsiStatus == SCSISTAT_CHECK_CONDITION) {
switch (addSenseCodeQualifier) {
//
// See if failure is due to device's current TPG state.
//
// If the failure is PORT_IN_STANDBY_STATE, we leave DSM_RETRY_DONT_DECREMENT unset if no active path exists,
// because otherwise MPIO will not be able to find a better path, and it will get into an infinite loop
// of trying and failing the command on a Standby path. See WCxeTfs:89150
//
case SPC3_SCSI_SENSEQ_ASYMMETRIC_ACCESS_STATE_TRANSITION:
case SPC3_SCSI_SENSEQ_TARGET_PORT_IN_UNAVAILABLE_STATE:
errorMask = DSM_RETRY_DONT_DECREMENT;
case SPC3_SCSI_SENSEQ_TARGET_PORT_IN_STANDBY_STATE:
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): TPG-transition/TPG-SB/TPG-UA. ASCQ %x. Will send down async RTPG. Asking for retry on Srb %p.\n",
DsmId,
addSenseCodeQualifier,
Srb));
//
// Indicate that a retry is necessary but without decrementing the remaining
// retries count. However, we may need to send down an STPG/RTPG also.
// And we must set PTBU to a path that is in a different TPG.
//
sendTPG = TRUE;
tpgException = TRUE;
NT_ASSERT(!devInfoException);
retry = TRUE;
handled = TRUE;
if ((addSenseCodeQualifier == SPC3_SCSI_SENSEQ_TARGET_PORT_IN_STANDBY_STATE) &&
DsmIsReadWrite(opCode)) {
PDSM_CONTEXT context = (PDSM_CONTEXT) deviceInfo->DsmContext;
KIRQL oldIrql = ExAcquireSpinLockExclusive(&(context->DsmContextLock));
BOOLEAN activePathExists = ( NULL != DsmpGetAnyActivePath(deviceInfo->Group, FALSE, NULL, 0) );
ExReleaseSpinLockExclusive(&(context->DsmContextLock), oldIrql);
if (activePathExists) {
errorMask = DSM_RETRY_DONT_DECREMENT;
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Not decrementing error counter, as an active path exists in group %p and opcode %x is r/w\n",
DsmId,
deviceInfo->Group,
opCode));
}
}
break;
case SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED:
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Manual intervention required. Asking for retry on Srb %p.\n",
DsmId,
Srb));
//
// This may be caused by NDU of controller firmware. It does not
// necessarily indicate that the device won't be ready via other path(s).
// Worth retrying instead of immediately failing back.
//
retry = TRUE;
handled = TRUE;
break;
}
}
}
}
}
} else if (Srb->SrbStatus == SRB_STATUS_BUS_RESET) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): BUS_RESET. Failing back Srb %p.\n",
DsmId,
Srb));
//
// Upper layers will retry in this case. If we retry here it will
// have a multiplicative effect which may result in a very long
// IO completion time if the device persistently times out.
//
retry = FALSE;
handled = TRUE;
} else {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Failing request. STATUS_IO_DEVICE_ERROR. SrbStatus (%x) ScsiStatus (%x).\n",
DsmId,
Srb->SrbStatus,
scsiStatus));
}
break;
}
case STATUS_BUFFER_OVERFLOW: {
if (DsmIsReadWrite(opCode)) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): BUFFER_OVERFLOW: Retry.\n",
DsmId));
//
// Retry these, as this condition might indicate a torn write.
//
retry = TRUE;
handled = TRUE;
}
break;
}
case STATUS_DEVICE_BUSY: {
//
// See if it's a check condition for TPG states in transition.
//
if (Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID &&
scsiStatus == SCSISTAT_CHECK_CONDITION) {
if (validSense) {
if (senseKey == SCSI_SENSE_NOT_READY &&
addSenseCode == SCSI_ADSENSE_LUN_NOT_READY &&
addSenseCodeQualifier == SPC3_SCSI_SENSEQ_ASYMMETRIC_ACCESS_STATE_TRANSITION) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): TPG transition. Will send down async RTPG. Asking for retry on Srb %p.\n",
DsmId,
Srb));
//
// Indicate that a retry is necessary but without decrementing the remaining
// retries count. However, we may need to send down an STPG/RTPG also.
// And we must set PTBU to a path that is in a different TPG.
//
sendTPG = TRUE;
tpgException = TRUE;
NT_ASSERT(!devInfoException);
retry = TRUE;
handled = TRUE;
errorMask = DSM_RETRY_DONT_DECREMENT;
}
}
}
break;
}
case STATUS_DEVICE_NOT_READY: {
if (Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID &&
scsiStatus == SCSISTAT_CHECK_CONDITION) {
if (validSense) {
if (senseKey == SCSI_SENSE_NOT_READY &&
addSenseCode == SCSI_ADSENSE_LUN_NOT_READY) {
switch (addSenseCodeQualifier) {
case SCSI_SENSEQ_MANUAL_INTERVENTION_REQUIRED: {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Manual intervention required. Asking for retry on Srb %p.\n",
DsmId,
Srb));
//
// This may be caused by NDU of controller firmware. It does not
// necessarily indicate that the device won't be ready via other path(s).
// Worth retrying instead of immediately failing back.
//
retry = TRUE;
handled = TRUE;
break;
}
case SCSI_SENSEQ_SPACE_ALLOC_IN_PROGRESS: {
//
// This indicates a logical block provisioning temporary resource exhaustion
// condition and therefore we must allow the class layer to handle it.
//
retry = FALSE;
handled = TRUE;
break;
}
default: {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Unhandled AddQual %x.\n",
DsmId,
addSenseCodeQualifier));
break;
}
}
}
}
}
}
default: {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Unhandled status code %x.\n",
DsmId,
*Status));
break;
}
}
if (!handled) {
//
// The NTSTATUS didn't indicate a fail-over condition, but
// check various srb status for failover-class error.
//
switch (Srb->SrbStatus) {
case SRB_STATUS_SELECTION_TIMEOUT:
case SRB_STATUS_INVALID_LUN:
case SRB_STATUS_INVALID_TARGET_ID:
case SRB_STATUS_NO_DEVICE:
case SRB_STATUS_NO_HBA:
case SRB_STATUS_INVALID_PATH_ID: {
//
// All of these are fatal.
//
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): SrbStatus 0x%x. Will initiate fail over.\n",
DsmId,
Srb->SrbStatus));
failover = TRUE;
break;
}
default: {
if ((scsiStatus == SCSISTAT_CHECK_CONDITION) &&
(Srb->SrbStatus & SRB_STATUS_AUTOSENSE_VALID)) {
if (validSense) {
switch (senseKey) {
case SCSI_SENSE_NO_SENSE: {
if (addSenseCode == SCSI_ADSENSE_NO_SENSE &&
addSenseCodeQualifier == SCSI_SENSEQ_CAUSE_NOT_REPORTABLE) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): CheckCondition with no sense info. Will initiate fail over.\n",
DsmId));
//
// This could be a transient error generated
// in response to potentially a hardware fault.
// Worth trying another path.
//
failover = TRUE;
handled = TRUE;
}
break;
}
case SCSI_SENSE_ILLEGAL_REQUEST: {
if (addSenseCode == SCSI_ADSENSE_INVALID_LUN) {
if (addSenseCodeQualifier == 0x00) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Invalid LUN. Will initiate fail over.\n",
DsmId));
//
// LUN may still exist on other path(s).
// Worth a failover.
//
failover = TRUE;
handled = TRUE;
}
}
break;
}
case SCSI_SENSE_HARDWARE_ERROR: {
if (addSenseCode == SPC3_SCSI_ADSENSE_LOGICAL_UNIT_COMMAND_FAILED) {
if (addSenseCodeQualifier == SPC3_SCSI_SENSEQ_SET_TARGET_PORT_GROUPS_FAILED) {
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): STPG failed. Will initiate fail over.\n",
DsmId));
//
// If an STPG failed, treat as FATAL and get another
// path set to A/O via another STPG.
//
failover = TRUE;
handled = TRUE;
}
} else if ((addSenseCode == SCSI_ADSENSE_LOGICAL_UNIT_ERROR && addSenseCodeQualifier == SCSI_SENSEQ_TIMEOUT_ON_LOGICAL_UNIT) ||
(addSenseCode == SCSI_ADSENSE_DATA_TRANSFER_ERROR && addSenseCodeQualifier == SCSI_SENSEQ_INITIATOR_RESPONSE_TIMEOUT)) {
//
// Could potentially indicate a dropped FC packet. Retry (along another
// path, based on the LB policy).
//
retry = TRUE;
handled = TRUE;
}
break;
}
default: {
break;
}
}
}
}
if (!handled) {
TracePrint((TRACE_LEVEL_WARNING,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Unhandled SRB Status 0x%x. Sense data %x|%x|%x.\n",
DsmId,
Srb->SrbStatus,
validSense ? senseKey : 0xFF,
validSense ? addSenseCode : 0xFF,
validSense ? addSenseCodeQualifier : 0xFF));
}
break;
}
}
}
if (failover) {
ULONG SpecialHandlingFlag = 0;
//
// If ALUA is supported, then it is possible that we may need to send
// down an STPG so build an IRP and fill in the SRB for STPG and send it down.
//
if (!DsmpIsSymmetricAccess(deviceInfo)) {
DsmpSetLBForPathFailingALUA(DsmContext, deviceInfo, TRUE, SpecialHandlingFlag);
} else {
//
// If device doesn't support ALUA, we just need to update
// states without sending down any commands (STPG)
//
DsmpSetLBForPathFailing(DsmContext, deviceInfo, TRUE, SpecialHandlingFlag);
}
errorMask = DSM_FATAL_ERROR;
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_RW,
"DsmInterpretError(DevInfo %p): Device changed to state %d\n",
deviceInfo,
deviceInfo->State));
#if DBG
{
ULONG inx;
PDSM_GROUP_ENTRY group = deviceInfo->Group;
PDSM_DEVICE_INFO tempDevInfo;
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Device %p in group %p being marked as failed. NTStatus 0x%x.\n",
DsmId,
deviceInfo,
group,
*Status));
for (inx = 0; inx < group->NumberDevices; inx++) {
tempDevInfo = group->DeviceList[inx];
TracePrint((TRACE_LEVEL_ERROR,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Device %p at %d. State %d.\n",
DsmId,
tempDevInfo,
inx,
tempDevInfo->State));
}
}
#endif // DBG
}
if (retry) {
if (sendTPG) {
//
// If ALUA is supported, send down STPG/RTPG as appropriate.
//
if (!DsmpIsSymmetricAccess(deviceInfo)) {
DsmpSetPathForIoRetryALUA(DsmContext, deviceInfo, tpgException, devInfoException);
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_RW,
"DsmInterpretError(DevInfo %p): SRB request %p will be retried. PTBU set to %p.\n",
deviceInfo,
Srb,
deviceInfo->Group->PathToBeUsed));
}
}
}
*Retry = retry;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_RW,
"DsmInterpretError (DevInfo %p): Exiting function returning errorMask %x.\n",
DsmId,
errorMask));
return errorMask;
}
BOOLEAN
DsmIsAddressTypeSupported(
_In_ IN PVOID DsmContext,
_In_ IN ULONG AddressType
)
/*++
Routine Description:
This routine is called when MPIO wants to know if the DSM supports a
particular storage address type.
This routine must be provided for DSMs of DsmType6 or higher.
Arguments:
DsmContext - Context value passed to DsmInitialize()
AddressType - The storage address type being queried.
Return Value:
TRUE - If the DSM supports the given storage address type.
FALSE - If the DSM does not support the given storage address type.
--*/
{
UNREFERENCED_PARAMETER(DsmContext);
if (AddressType == STORAGE_ADDRESS_TYPE_BTL8)
{
return TRUE;
}
return FALSE;
}
NTSTATUS
DsmDeviceNotUsed(
_In_ IN PVOID DsmContext,
_In_ IN PVOID DsmId
)
/*++
Routine Description:
This routine indicates that the device represented by DsmId will not be
initialized completely by MPIO.
The DSM_ID list passed to other functions will no longer contain DsmId,
so internal structures should be updated accordingly.
This routine must be provided for DSMs of DsmType6 or higher.
Arguments:
DsmContext - Context value given to the multipath driver during registration.
DsmId - Value referring to the uninitialized device.
Return Value:
NTSTATUS of the operation.
--*/
{
PDSM_DEVICE_INFO deviceInfo = (PDSM_DEVICE_INFO)DsmId;
DSM_ASSERT(deviceInfo->Group != NULL);
DSM_ASSERT(deviceInfo->Group->GroupSig == DSM_GROUP_SIG);
//
// Undo anything we did to build up the device in DsmInquire().
//
DsmRemoveDevice((PDSM_CONTEXT)DsmContext, DsmId, deviceInfo->FailGroup);
return STATUS_SUCCESS;
}
NTSTATUS
DsmUnload(
_In_ IN PVOID DsmContext
)
/*++
Routine Description:
This routine is called when the main module requires the DSM to be unloaded
(ie. prior to the main module unload).
Arguments:
DsmContext - Context value passed to DsmInitialize()
Return Value:
STATUS_SUCCESS;
--*/
{
PVOID tempAddress = DsmContext;
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_INIT,
"DsmUnload (DsmCtxt %p): Entering function.\n",
DsmContext));
DsmpFreeDSMResources((PDSM_CONTEXT) DsmContext);
if (gMPIOControlObjectRefd) {
ObDereferenceObject(gMPIOControlObject);
gMPIOControlObjectRefd = FALSE;
}
TracePrint((TRACE_LEVEL_VERBOSE,
TRACE_FLAG_INIT,
"DsmUnload (DsmCtxt %p): Exiting function.\n",
tempAddress));
//
// Stop the tracing subsystem.
//
WPP_CLEANUP(gDsmDriverObject);
return STATUS_SUCCESS;
}
|