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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* NFS Version 4 state recovery code.
*/
#include <nfs/nfs4_clnt.h>
#include <nfs/nfs4.h>
#include <nfs/rnode4.h>
#include <sys/cmn_err.h>
#include <sys/cred.h>
#include <sys/systm.h>
#include <sys/flock.h>
#include <sys/dnlc.h>
#include <sys/ddi.h>
#include <sys/disp.h>
#include <sys/list.h>
#include <sys/sdt.h>
#include <sys/mount.h>
#include <sys/door.h>
#include <nfs/nfssys.h>
#include <nfs/nfsid_map.h>
#include <nfs/nfs4_idmap_impl.h>
extern r4hashq_t *rtable4;
/*
* Information that describes what needs to be done for recovery. It is
* passed to a client recovery thread as well as passed to various recovery
* routines. rc_mi, rc_vp1, and rc_vp2 refer to the filesystem and
* vnode(s) affected by recovery. rc_vp1 and rc_vp2 are references (use
* VN_HOLD) or NULL. rc_lost_rqst contains information about the lost
* lock or open/close request, and it holds reference counts for the
* various objects (vnode, etc.). The recovery thread also uses flags set
* in the mntinfo4_t or vnode_t to tell it what to do. rc_error is used
* to save the error that originally triggered the recovery event -- will
* later be used to set mi_error if recovery doesn't work. rc_bseqid_rqst
* contains information about the request that got NFS4ERR_BAD_SEQID, and
* it holds reference count for the various objects (vnode, open owner,
* open stream, lock owner).
*/
typedef struct {
mntinfo4_t *rc_mi;
vnode_t *rc_vp1;
vnode_t *rc_vp2;
nfs4_recov_t rc_action;
stateid4 rc_stateid;
bool_t rc_srv_reboot; /* server has rebooted */
nfs4_lost_rqst_t *rc_lost_rqst;
nfs4_error_t rc_orig_errors; /* original errors causing recovery */
int rc_error;
nfs4_bseqid_entry_t *rc_bseqid_rqst;
vnode_t *rc_moved_vp;
char *rc_moved_nm;
} recov_info_t;
/*
* How long to wait before trying again if there is an error doing
* recovery, in seconds.
*/
static int recov_err_delay = 1;
/*
* How long to wait when processing NFS4ERR_GRACE or NFS4ERR_DELAY
* errors. Expressed in seconds. Default is defined as
* NFS4ERR_DELAY_TIME and this variable is initialized in nfs4_subr_init()
*/
time_t nfs4err_delay_time = 0;
/*
* Tuneable to limit how many time "exempt" ops go OTW
* after a recovery error. Exempt op hints are OH_CLOSE,
* OH_LOCKU, OH_DELEGRETURN. These previously always went
* OTW even after rnode was "dead" due to recovery errors.
*
* The tuneable below limits the number of times a start_fop
* invocation will retry the exempt hints. After the limit
* is reached, nfs4_start_fop will return an error just like
* it would for non-exempt op hints.
*/
int nfs4_max_recov_error_retry = 3;
/*
* Number of seconds the recovery thread should pause before retry when the
* filesystem has been forcibly unmounted.
*/
int nfs4_unmount_delay = 1;
#ifdef DEBUG
/*
* How long to wait (in seconds) between recovery operations on a given
* file. Normally zero, but could be set longer for testing purposes.
*/
static int nfs4_recovdelay = 0;
/*
* Switch that controls whether to go into the debugger when recovery
* fails.
*/
static int nfs4_fail_recov_stop = 0;
/*
* Tuneables to debug client namespace interaction with server
* mount points:
*
* nfs4_srvmnt_fail_cnt:
* number of times EACCES returned because client
* attempted to cross server mountpoint
*
* nfs4_srvmnt_debug:
* trigger console printf whenever client attempts
* to cross server mountpoint
*/
int nfs4_srvmnt_fail_cnt = 0;
int nfs4_srvmnt_debug = 0;
#endif
extern zone_key_t nfs4clnt_zone_key;
/* forward references, in alphabetic order */
static void close_after_open_resend(vnode_t *, cred_t *, uint32_t,
nfs4_error_t *);
static void errs_to_action(recov_info_t *,
nfs4_server_t *, mntinfo4_t *, stateid4 *, nfs4_lost_rqst_t *, int,
nfs_opnum4, nfs4_bseqid_entry_t *);
static void flush_reinstate(nfs4_lost_rqst_t *);
static void free_milist(mntinfo4_t **, int);
static mntinfo4_t **make_milist(nfs4_server_t *, int *);
static int nfs4_check_recov_err(vnode_t *, nfs4_op_hint_t,
nfs4_recov_state_t *, int, char *);
static char *nfs4_getsrvnames(mntinfo4_t *, size_t *);
static void nfs4_recov_fh_fail(vnode_t *, int, nfsstat4);
static void nfs4_recov_thread(recov_info_t *);
static void nfs4_remove_lost_rqsts(mntinfo4_t *, nfs4_server_t *);
static void nfs4_resend_lost_rqsts(recov_info_t *, nfs4_server_t *);
static cred_t *pid_to_cr(pid_t);
static void reclaim_one_lock(vnode_t *, flock64_t *, nfs4_error_t *, int *);
static void recov_bad_seqid(recov_info_t *);
static void recov_badstate(recov_info_t *, vnode_t *, nfsstat4);
static void recov_clientid(recov_info_t *, nfs4_server_t *);
static void recov_done(mntinfo4_t *, recov_info_t *);
static void recov_filehandle(nfs4_recov_t, mntinfo4_t *, vnode_t *);
static void recov_newserver(recov_info_t *, nfs4_server_t **, bool_t *);
static void recov_openfiles(recov_info_t *, nfs4_server_t *);
static void recov_stale(mntinfo4_t *, vnode_t *);
static void nfs4_free_lost_rqst(nfs4_lost_rqst_t *, nfs4_server_t *);
static void recov_throttle(recov_info_t *, vnode_t *);
static void relock_skip_pid(vnode_t *, locklist_t *, pid_t);
static void resend_lock(nfs4_lost_rqst_t *, nfs4_error_t *);
static void resend_one_op(nfs4_lost_rqst_t *, nfs4_error_t *, mntinfo4_t *,
nfs4_server_t *);
static void save_bseqid_rqst(nfs4_bseqid_entry_t *, recov_info_t *);
static void start_recovery(recov_info_t *, mntinfo4_t *, vnode_t *, vnode_t *,
nfs4_server_t *, vnode_t *, char *);
static void start_recovery_action(nfs4_recov_t, bool_t, mntinfo4_t *, vnode_t *,
vnode_t *);
static int wait_for_recovery(mntinfo4_t *, nfs4_op_hint_t);
/*
* Return non-zero if the given errno, status, and rpc status codes
* in the nfs4_error_t indicate that client recovery is needed.
* "stateful" indicates whether the call that got the error establishes or
* removes state on the server (open, close, lock, unlock, delegreturn).
*/
int
nfs4_needs_recovery(nfs4_error_t *ep, bool_t stateful, vfs_t *vfsp)
{
int recov = 0;
mntinfo4_t *mi;
/*
* Try failover if the error values justify it and if
* it's a failover mount. Don't try if the mount is in
* progress, failures are handled explicitly by nfs4rootvp.
*/
if (nfs4_try_failover(ep)) {
mi = VFTOMI4(vfsp);
mutex_enter(&mi->mi_lock);
recov = FAILOVER_MOUNT4(mi) && !(mi->mi_flags & MI4_MOUNTING);
mutex_exit(&mi->mi_lock);
if (recov)
return (recov);
}
if (ep->error == EINTR || NFS4_FRC_UNMT_ERR(ep->error, vfsp)) {
/*
* The server may have gotten the request, so for stateful
* ops we need to resynchronize and possibly back out the
* op.
*/
return (stateful);
}
if (ep->error != 0)
return (0);
/* stat values are listed alphabetically */
/*
* There are two lists here: the errors for which we have code, and
* the errors for which we plan to have code before FCS. For the
* second list, print a warning message but don't attempt recovery.
*/
switch (ep->stat) {
case NFS4ERR_BADHANDLE:
case NFS4ERR_BAD_SEQID:
case NFS4ERR_BAD_STATEID:
case NFS4ERR_DELAY:
case NFS4ERR_EXPIRED:
case NFS4ERR_FHEXPIRED:
case NFS4ERR_GRACE:
case NFS4ERR_OLD_STATEID:
case NFS4ERR_RESOURCE:
case NFS4ERR_STALE_CLIENTID:
case NFS4ERR_STALE_STATEID:
case NFS4ERR_WRONGSEC:
case NFS4ERR_STALE:
recov = 1;
break;
#ifdef DEBUG
case NFS4ERR_LEASE_MOVED:
case NFS4ERR_MOVED:
zcmn_err(VFTOMI4(vfsp)->mi_zone->zone_id,
CE_WARN, "!Can't yet recover from NFS status %d",
ep->stat);
break;
#endif
}
return (recov);
}
/*
* Some operations such as DELEGRETURN want to avoid invoking
* recovery actions that will only mark the file dead. If
* better handlers are invoked for any of these errors, this
* routine should be modified.
*/
int
nfs4_recov_marks_dead(nfsstat4 status)
{
if (status == NFS4ERR_BAD_SEQID ||
status == NFS4ERR_EXPIRED ||
status == NFS4ERR_BAD_STATEID ||
status == NFS4ERR_OLD_STATEID)
return (1);
return (0);
}
/*
* Transfer the state recovery information in recovp to mi's resend queue,
* and mark mi as having a lost state request.
*/
static void
nfs4_enqueue_lost_rqst(recov_info_t *recovp, mntinfo4_t *mi)
{
nfs4_lost_rqst_t *lrp = recovp->rc_lost_rqst;
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
ASSERT(lrp != NULL && lrp->lr_op != 0);
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE,
"nfs4_enqueue_lost_rqst %p, op %d",
(void *)lrp, lrp->lr_op));
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_LOST_STATE;
if (lrp->lr_putfirst)
list_insert_head(&mi->mi_lost_state, lrp);
else
list_insert_tail(&mi->mi_lost_state, lrp);
recovp->rc_lost_rqst = NULL;
mutex_exit(&mi->mi_lock);
nfs4_queue_event(RE_LOST_STATE, mi, NULL, lrp->lr_op, lrp->lr_vp,
lrp->lr_dvp, 0, NULL, 0, TAG_NONE, TAG_NONE, 0, 0);
}
/*
* Transfer the bad seqid recovery information in recovp to mi's
* bad seqid queue, and mark mi as having a bad seqid request.
*/
void
enqueue_bseqid_rqst(recov_info_t *recovp, mntinfo4_t *mi)
{
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
ASSERT(recovp->rc_bseqid_rqst != NULL);
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_BAD_SEQID;
list_insert_tail(&mi->mi_bseqid_list, recovp->rc_bseqid_rqst);
recovp->rc_bseqid_rqst = NULL;
mutex_exit(&mi->mi_lock);
}
/*
* Initiate recovery.
*
* The nfs4_error_t contains the return codes that triggered a recovery
* attempt. mi, vp1, and vp2 refer to the filesystem and files that were
* being operated on. vp1 and vp2 may be NULL.
*
* Multiple calls are okay. If recovery is already underway, the call
* updates the information about what state needs recovery but does not
* start a new thread. The caller should hold mi->mi_recovlock as a reader
* for proper synchronization with any recovery thread.
*
* This will return TRUE if recovery was aborted, and FALSE otherwise.
*/
bool_t
nfs4_start_recovery(nfs4_error_t *ep, mntinfo4_t *mi, vnode_t *vp1,
vnode_t *vp2, stateid4 *sid, nfs4_lost_rqst_t *lost_rqstp, nfs_opnum4 op,
nfs4_bseqid_entry_t *bsep, vnode_t *moved_vp, char *moved_nm)
{
recov_info_t *recovp;
nfs4_server_t *sp;
bool_t abort = FALSE;
bool_t gone = FALSE;
ASSERT(nfs_zone() == mi->mi_zone);
mutex_enter(&mi->mi_lock);
/*
* If there is lost state, we need to kick off recovery even if the
* filesystem has been unmounted or the zone is shutting down.
*/
gone = FS_OR_ZONE_GONE4(mi->mi_vfsp);
if (gone) {
ASSERT(ep->error != EINTR || lost_rqstp != NULL);
if (ep->error == EIO && lost_rqstp == NULL) {
/* failed due to forced unmount, no new lost state */
abort = TRUE;
}
if ((ep->error == 0 || ep->error == ETIMEDOUT) &&
!(mi->mi_recovflags & MI4R_LOST_STATE)) {
/* some other failure, no existing lost state */
abort = TRUE;
}
if (abort) {
mutex_exit(&mi->mi_lock);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"nfs4_start_recovery: fs unmounted"));
return (TRUE);
}
}
mi->mi_in_recovery++;
mutex_exit(&mi->mi_lock);
recovp = kmem_alloc(sizeof (recov_info_t), KM_SLEEP);
recovp->rc_orig_errors = *ep;
sp = find_nfs4_server(mi);
errs_to_action(recovp, sp, mi, sid, lost_rqstp, gone, op, bsep);
if (sp != NULL)
mutex_exit(&sp->s_lock);
start_recovery(recovp, mi, vp1, vp2, sp, moved_vp, moved_nm);
if (sp != NULL)
nfs4_server_rele(sp);
return (FALSE);
}
/*
* Internal version of nfs4_start_recovery. The difference is that the
* caller specifies the recovery action, rather than the errors leading to
* recovery.
*/
static void
start_recovery_action(nfs4_recov_t what, bool_t reboot, mntinfo4_t *mi,
vnode_t *vp1, vnode_t *vp2)
{
recov_info_t *recovp;
ASSERT(nfs_zone() == mi->mi_zone);
mutex_enter(&mi->mi_lock);
mi->mi_in_recovery++;
mutex_exit(&mi->mi_lock);
recovp = kmem_zalloc(sizeof (recov_info_t), KM_SLEEP);
recovp->rc_action = what;
recovp->rc_srv_reboot = reboot;
recovp->rc_error = EIO;
start_recovery(recovp, mi, vp1, vp2, NULL, NULL, NULL);
}
static void
start_recovery(recov_info_t *recovp, mntinfo4_t *mi,
vnode_t *vp1, vnode_t *vp2, nfs4_server_t *sp,
vnode_t *moved_vp, char *moved_nm)
{
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"start_recovery: mi %p, what %s", (void*)mi,
nfs4_recov_action_to_str(recovp->rc_action)));
/*
* Bump the reference on the vfs so that we can pass it to the
* recovery thread.
*/
VFS_HOLD(mi->mi_vfsp);
MI4_HOLD(mi);
again:
switch (recovp->rc_action) {
case NR_FAILOVER:
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
if (mi->mi_servers->sv_next == NULL)
goto out_no_thread;
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_NEED_NEW_SERVER;
mutex_exit(&mi->mi_lock);
if (recovp->rc_lost_rqst != NULL)
nfs4_enqueue_lost_rqst(recovp, mi);
break;
case NR_CLIENTID:
/*
* If the filesystem has been unmounted, punt.
*/
if (sp == NULL)
goto out_no_thread;
/*
* If nobody else is working on the clientid, mark the
* clientid as being no longer set. Then mark the specific
* filesystem being worked on.
*/
if (!nfs4_server_in_recovery(sp)) {
mutex_enter(&sp->s_lock);
sp->s_flags &= ~N4S_CLIENTID_SET;
mutex_exit(&sp->s_lock);
}
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_NEED_CLIENTID;
if (recovp->rc_srv_reboot)
mi->mi_recovflags |= MI4R_SRV_REBOOT;
mutex_exit(&mi->mi_lock);
break;
case NR_OPENFILES:
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_REOPEN_FILES;
if (recovp->rc_srv_reboot)
mi->mi_recovflags |= MI4R_SRV_REBOOT;
mutex_exit(&mi->mi_lock);
break;
case NR_WRONGSEC:
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_NEED_SECINFO;
mutex_exit(&mi->mi_lock);
break;
case NR_EXPIRED:
if (vp1 != NULL)
recov_badstate(recovp, vp1, NFS4ERR_EXPIRED);
if (vp2 != NULL)
recov_badstate(recovp, vp2, NFS4ERR_EXPIRED);
goto out_no_thread; /* no further recovery possible */
case NR_BAD_STATEID:
if (vp1 != NULL)
recov_badstate(recovp, vp1, NFS4ERR_BAD_STATEID);
if (vp2 != NULL)
recov_badstate(recovp, vp2, NFS4ERR_BAD_STATEID);
goto out_no_thread; /* no further recovery possible */
case NR_FHEXPIRED:
case NR_BADHANDLE:
if (vp1 != NULL)
recov_throttle(recovp, vp1);
if (vp2 != NULL)
recov_throttle(recovp, vp2);
/*
* Recover the filehandle now, rather than using a
* separate thread. We can do this because filehandle
* recovery is independent of any other state, and because
* we know that we are not competing with the recovery
* thread at this time. recov_filehandle will deal with
* threads that are competing to recover this filehandle.
*/
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
if (vp1 != NULL)
recov_filehandle(recovp->rc_action, mi, vp1);
if (vp2 != NULL)
recov_filehandle(recovp->rc_action, mi, vp2);
goto out_no_thread; /* no further recovery needed */
case NR_STALE:
/*
* NFS4ERR_STALE handling
* recov_stale() could set MI4R_NEED_NEW_SERVER to
* indicate that we can and should failover.
*/
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_READER) ||
nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
if (vp1 != NULL)
recov_stale(mi, vp1);
if (vp2 != NULL)
recov_stale(mi, vp2);
mutex_enter(&mi->mi_lock);
if ((mi->mi_recovflags & MI4R_NEED_NEW_SERVER) == 0) {
mutex_exit(&mi->mi_lock);
goto out_no_thread;
}
mutex_exit(&mi->mi_lock);
recovp->rc_action = NR_FAILOVER;
goto again;
case NR_BAD_SEQID:
if (recovp->rc_bseqid_rqst) {
enqueue_bseqid_rqst(recovp, mi);
break;
}
if (vp1 != NULL)
recov_badstate(recovp, vp1, NFS4ERR_BAD_SEQID);
if (vp2 != NULL)
recov_badstate(recovp, vp2, NFS4ERR_BAD_SEQID);
goto out_no_thread; /* no further recovery possible */
case NR_OLDSTATEID:
if (vp1 != NULL)
recov_badstate(recovp, vp1, NFS4ERR_OLD_STATEID);
if (vp2 != NULL)
recov_badstate(recovp, vp2, NFS4ERR_OLD_STATEID);
goto out_no_thread; /* no further recovery possible */
case NR_GRACE:
nfs4_set_grace_wait(mi);
goto out_no_thread; /* no further action required for GRACE */
case NR_DELAY:
if (vp1)
nfs4_set_delay_wait(vp1);
goto out_no_thread; /* no further action required for DELAY */
case NR_LOST_STATE_RQST:
case NR_LOST_LOCK:
nfs4_enqueue_lost_rqst(recovp, mi);
break;
default:
nfs4_queue_event(RE_UNEXPECTED_ACTION, mi, NULL,
recovp->rc_action, NULL, NULL, 0, NULL, 0, TAG_NONE,
TAG_NONE, 0, 0);
goto out_no_thread;
}
/*
* If either file recently went through the same recovery, wait
* awhile. This is in case there is some sort of bug; we might not
* be able to recover properly, but at least we won't bombard the
* server with calls, and we won't tie up the client.
*/
if (vp1 != NULL)
recov_throttle(recovp, vp1);
if (vp2 != NULL)
recov_throttle(recovp, vp2);
/*
* If there's already a recovery thread, don't start another one.
*/
mutex_enter(&mi->mi_lock);
if (mi->mi_flags & MI4_RECOV_ACTIV) {
mutex_exit(&mi->mi_lock);
goto out_no_thread;
}
mi->mi_flags |= MI4_RECOV_ACTIV;
mutex_exit(&mi->mi_lock);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"start_recovery: starting new thread for mi %p", (void*)mi));
recovp->rc_mi = mi;
recovp->rc_vp1 = vp1;
if (vp1 != NULL) {
ASSERT(VTOMI4(vp1) == mi);
VN_HOLD(recovp->rc_vp1);
}
recovp->rc_vp2 = vp2;
if (vp2 != NULL) {
ASSERT(VTOMI4(vp2) == mi);
VN_HOLD(recovp->rc_vp2);
}
recovp->rc_moved_vp = moved_vp;
recovp->rc_moved_nm = moved_nm;
(void) zthread_create(NULL, 0, nfs4_recov_thread, recovp, 0,
minclsyspri);
return;
/* not reached by thread creating call */
out_no_thread:
mutex_enter(&mi->mi_lock);
mi->mi_in_recovery--;
if (mi->mi_in_recovery == 0)
cv_broadcast(&mi->mi_cv_in_recov);
mutex_exit(&mi->mi_lock);
VFS_RELE(mi->mi_vfsp);
MI4_RELE(mi);
/*
* Free up resources that were allocated for us.
*/
kmem_free(recovp, sizeof (recov_info_t));
}
static int
nfs4_check_recov_err(vnode_t *vp, nfs4_op_hint_t op,
nfs4_recov_state_t *rsp, int retry_err_cnt, char *str)
{
rnode4_t *rp;
int error = 0;
int exempt;
if (vp == NULL)
return (0);
exempt = (op == OH_CLOSE || op == OH_LOCKU || op == OH_DELEGRETURN);
rp = VTOR4(vp);
mutex_enter(&rp->r_statelock);
/*
* If there was a recovery error, then allow op hints "exempt" from
* recov errors to retry (currently 3 times). Either r_error or
* EIO is returned for non-exempt op hints.
*/
if (rp->r_flags & R4RECOVERR) {
if (exempt && rsp->rs_num_retry_despite_err <=
nfs4_max_recov_error_retry) {
/*
* Check to make sure that we haven't already inc'd
* rs_num_retry_despite_err for current nfs4_start_fop
* instance. We don't want to double inc (if we were
* called with vp2, then the vp1 call could have
* already incremented.
*/
if (retry_err_cnt == rsp->rs_num_retry_despite_err)
rsp->rs_num_retry_despite_err++;
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"nfs4_start_fop: %s %p DEAD, cnt=%d", str,
(void *)vp, rsp->rs_num_retry_despite_err));
} else {
error = (rp->r_error ? rp->r_error : EIO);
/*
* An ESTALE error on a non-regular file is not
* "sticky". Return the ESTALE error once, but
* clear the condition to allow future operations
* to go OTW. This will allow the client to
* recover if the server has merely unshared then
* re-shared the file system. For regular files,
* the unshare has destroyed the open state at the
* server and we aren't willing to do a reopen (yet).
*/
if (error == ESTALE && vp->v_type != VREG) {
rp->r_flags &=
~(R4RECOVERR|R4RECOVERRP|R4STALE);
rp->r_error = 0;
error = ESTALE;
}
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"nfs4_start_fop: %s %p DEAD, cnt=%d error=%d",
str, (void *)vp,
rsp->rs_num_retry_despite_err, error));
}
}
mutex_exit(&rp->r_statelock);
return (error);
}
/*
* Initial setup code that every operation should call if it might invoke
* client recovery. Can block waiting for recovery to finish on a
* filesystem. Either vnode ptr can be NULL.
*
* Returns 0 if there are no outstanding errors. Can return an
* errno value under various circumstances (e.g., failed recovery, or
* interrupted while waiting for recovery to finish).
*
* There must be a corresponding call to nfs4_end_op() to free up any locks
* or resources allocated by this call (assuming this call succeeded),
* using the same rsp that's passed in here.
*
* The open and lock seqid synchronization must be stopped before calling this
* function, as it could lead to deadlock when trying to reopen a file or
* reclaim a lock. The synchronization is obtained with calls to:
* nfs4_start_open_seqid_sync()
* nfs4_start_lock_seqid_sync()
*
* *startrecovp is set TRUE if the caller should not bother with the
* over-the-wire call, and just initiate recovery for the given request.
* This is typically used for state-releasing ops if the filesystem has
* been forcibly unmounted. startrecovp may be NULL for
* non-state-releasing ops.
*/
int
nfs4_start_fop(mntinfo4_t *mi, vnode_t *vp1, vnode_t *vp2, nfs4_op_hint_t op,
nfs4_recov_state_t *rsp, bool_t *startrecovp)
{
int error = 0, rerr_cnt;
nfs4_server_t *sp = NULL;
nfs4_server_t *tsp;
nfs4_error_t e = { 0, NFS4_OK, RPC_SUCCESS };
uint_t droplock_cnt;
#ifdef DEBUG
void *fop_caller;
#endif
ASSERT(vp1 == NULL || vp1->v_vfsp == mi->mi_vfsp);
ASSERT(vp2 == NULL || vp2->v_vfsp == mi->mi_vfsp);
#ifdef DEBUG
if ((fop_caller = tsd_get(nfs4_tsd_key)) != NULL) {
cmn_err(CE_PANIC, "Missing nfs4_end_fop: last caller %p",
fop_caller);
}
(void) tsd_set(nfs4_tsd_key, caller());
#endif
rsp->rs_sp = NULL;
rsp->rs_flags &= ~NFS4_RS_RENAME_HELD;
rerr_cnt = rsp->rs_num_retry_despite_err;
/*
* Process the items that may delay() based on server response
*/
error = nfs4_wait_for_grace(mi, rsp);
if (error)
goto out;
if (vp1 != NULL) {
error = nfs4_wait_for_delay(vp1, rsp);
if (error)
goto out;
}
/* Wait for a delegation recall to complete. */
error = wait_for_recall(vp1, vp2, op, rsp);
if (error)
goto out;
/*
* Wait for any current recovery actions to finish. Note that a
* recovery thread can still start up after wait_for_recovery()
* finishes. We don't block out recovery operations until we
* acquire s_recovlock and mi_recovlock.
*/
error = wait_for_recovery(mi, op);
if (error)
goto out;
/*
* Check to see if the rnode is already marked with a
* recovery error. If so, return it immediately. But
* always pass CLOSE, LOCKU, and DELEGRETURN so we can
* clean up state on the server.
*/
if (vp1 != NULL) {
if (error = nfs4_check_recov_err(vp1, op, rsp, rerr_cnt, "vp1"))
goto out;
nfs4_check_remap(mi, vp1, NFS4_REMAP_CKATTRS, &e);
}
if (vp2 != NULL) {
if (error = nfs4_check_recov_err(vp2, op, rsp, rerr_cnt, "vp2"))
goto out;
nfs4_check_remap(mi, vp2, NFS4_REMAP_CKATTRS, &e);
}
/*
* The lock order calls for us to acquire s_recovlock before
* mi_recovlock, but we have to hold mi_recovlock to look up sp (to
* prevent races with the failover/migration code). So acquire
* mi_recovlock, look up sp, drop mi_recovlock, acquire
* s_recovlock and mi_recovlock, then verify that sp is still the
* right object. XXX Can we find a simpler way to deal with this?
*/
if (nfs_rw_enter_sig(&mi->mi_recovlock, RW_READER,
mi->mi_flags & MI4_INT)) {
error = EINTR;
goto out;
}
get_sp:
sp = find_nfs4_server(mi);
if (sp != NULL) {
sp->s_otw_call_count++;
mutex_exit(&sp->s_lock);
droplock_cnt = mi->mi_srvset_cnt;
}
nfs_rw_exit(&mi->mi_recovlock);
if (sp != NULL) {
if (nfs_rw_enter_sig(&sp->s_recovlock, RW_READER,
mi->mi_flags & MI4_INT)) {
error = EINTR;
goto out;
}
}
if (nfs_rw_enter_sig(&mi->mi_recovlock, RW_READER,
mi->mi_flags & MI4_INT)) {
if (sp != NULL)
nfs_rw_exit(&sp->s_recovlock);
error = EINTR;
goto out;
}
/*
* If the mntinfo4_t hasn't changed nfs4_sever_ts then
* there's no point in double checking to make sure it
* has switched.
*/
if (sp == NULL || droplock_cnt != mi->mi_srvset_cnt) {
tsp = find_nfs4_server(mi);
if (tsp != sp) {
/* try again */
if (tsp != NULL) {
mutex_exit(&tsp->s_lock);
nfs4_server_rele(tsp);
tsp = NULL;
}
if (sp != NULL) {
nfs_rw_exit(&sp->s_recovlock);
mutex_enter(&sp->s_lock);
sp->s_otw_call_count--;
mutex_exit(&sp->s_lock);
nfs4_server_rele(sp);
sp = NULL;
}
goto get_sp;
} else {
if (tsp != NULL) {
mutex_exit(&tsp->s_lock);
nfs4_server_rele(tsp);
tsp = NULL;
}
}
}
if (sp != NULL) {
rsp->rs_sp = sp;
}
/*
* If the fileystem uses volatile filehandles, obtain a lock so
* that we synchronize with renames. Exception: mount operations
* can change mi_fh_expire_type, which could be a problem, since
* the end_op code needs to be consistent with the start_op code
* about mi_rename_lock. Since mounts don't compete with renames,
* it's simpler to just not acquire the rename lock for mounts.
*/
if (NFS4_VOLATILE_FH(mi) && op != OH_MOUNT) {
if (nfs_rw_enter_sig(&mi->mi_rename_lock,
op == OH_VFH_RENAME ? RW_WRITER : RW_READER,
mi->mi_flags & MI4_INT)) {
nfs_rw_exit(&mi->mi_recovlock);
if (sp != NULL)
nfs_rw_exit(&sp->s_recovlock);
error = EINTR;
goto out;
}
rsp->rs_flags |= NFS4_RS_RENAME_HELD;
}
if (OH_IS_STATE_RELE(op)) {
/*
* For forced unmount, letting the request proceed will
* almost always delay response to the user, so hand it off
* to the recovery thread. For exiting lwp's, we don't
* have a good way to tell if the request will hang. We
* generally want processes to handle their own requests so
* that they can be done in parallel, but if there is
* already a recovery thread, hand the request off to it.
* This will improve user response at no cost to overall
* system throughput. For zone shutdown, we'd prefer
* the recovery thread to handle this as well.
*/
ASSERT(startrecovp != NULL);
mutex_enter(&mi->mi_lock);
if (FS_OR_ZONE_GONE4(mi->mi_vfsp))
*startrecovp = TRUE;
else if ((curthread->t_proc_flag & TP_LWPEXIT) &&
(mi->mi_flags & MI4_RECOV_ACTIV))
*startrecovp = TRUE;
else
*startrecovp = FALSE;
mutex_exit(&mi->mi_lock);
} else
if (startrecovp != NULL)
*startrecovp = FALSE;
ASSERT(error == 0);
return (error);
out:
ASSERT(error != 0);
if (sp != NULL) {
mutex_enter(&sp->s_lock);
sp->s_otw_call_count--;
mutex_exit(&sp->s_lock);
nfs4_server_rele(sp);
rsp->rs_sp = NULL;
}
nfs4_end_op_recall(vp1, vp2, rsp);
#ifdef DEBUG
(void) tsd_set(nfs4_tsd_key, NULL);
#endif
return (error);
}
/*
* It is up to the caller to determine if rsp->rs_sp being NULL
* is detrimental or not.
*/
int
nfs4_start_op(mntinfo4_t *mi, vnode_t *vp1, vnode_t *vp2,
nfs4_recov_state_t *rsp)
{
ASSERT(rsp->rs_num_retry_despite_err == 0);
rsp->rs_num_retry_despite_err = 0;
return (nfs4_start_fop(mi, vp1, vp2, OH_OTHER, rsp, NULL));
}
/*
* Release any resources acquired by nfs4_start_op().
* 'sp' should be the nfs4_server pointer returned by nfs4_start_op().
*
* The operation hint is used to avoid a deadlock by bypassing delegation
* return logic for writes, which are done while returning a delegation.
*/
void
nfs4_end_fop(mntinfo4_t *mi, vnode_t *vp1, vnode_t *vp2, nfs4_op_hint_t op,
nfs4_recov_state_t *rsp, bool_t needs_recov)
{
nfs4_server_t *sp = rsp->rs_sp;
rnode4_t *rp = NULL;
#ifdef lint
/*
* The op hint isn't used any more, but might be in
* the future.
*/
op = op;
#endif
#ifdef DEBUG
ASSERT(tsd_get(nfs4_tsd_key) != NULL);
(void) tsd_set(nfs4_tsd_key, NULL);
#endif
nfs4_end_op_recall(vp1, vp2, rsp);
if (rsp->rs_flags & NFS4_RS_RENAME_HELD)
nfs_rw_exit(&mi->mi_rename_lock);
if (!needs_recov) {
if (rsp->rs_flags & NFS4_RS_DELAY_MSG) {
/* may need to clear the delay interval */
if (vp1 != NULL) {
rp = VTOR4(vp1);
mutex_enter(&rp->r_statelock);
rp->r_delay_interval = 0;
mutex_exit(&rp->r_statelock);
}
}
rsp->rs_flags &= ~(NFS4_RS_GRACE_MSG|NFS4_RS_DELAY_MSG);
}
/*
* If the corresponding nfs4_start_op() found a sp,
* then there must still be a sp.
*/
if (sp != NULL) {
nfs_rw_exit(&mi->mi_recovlock);
nfs_rw_exit(&sp->s_recovlock);
mutex_enter(&sp->s_lock);
sp->s_otw_call_count--;
cv_broadcast(&sp->s_cv_otw_count);
mutex_exit(&sp->s_lock);
nfs4_server_rele(sp);
} else {
nfs_rw_exit(&mi->mi_recovlock);
}
}
void
nfs4_end_op(mntinfo4_t *mi, vnode_t *vp1, vnode_t *vp2,
nfs4_recov_state_t *rsp, bool_t needrecov)
{
nfs4_end_fop(mi, vp1, vp2, OH_OTHER, rsp, needrecov);
}
/*
* If the filesystem is going through client recovery, block until
* finished.
* Exceptions:
* - state-releasing ops (CLOSE, LOCKU, DELEGRETURN) are allowed to proceed
* if the filesystem has been forcibly unmounted or the lwp is exiting.
*
* Return value:
* - 0 if no errors
* - EINTR if the call was interrupted
* - EIO if the filesystem has been forcibly unmounted (non-state-releasing
* op)
* - the errno value from the recovery thread, if recovery failed
*/
static int
wait_for_recovery(mntinfo4_t *mi, nfs4_op_hint_t op_hint)
{
int error = 0;
mutex_enter(&mi->mi_lock);
while (mi->mi_recovflags != 0) {
klwp_t *lwp = ttolwp(curthread);
if ((mi->mi_vfsp->vfs_flag & VFS_UNMOUNTED) ||
(mi->mi_flags & MI4_RECOV_FAIL))
break;
if (OH_IS_STATE_RELE(op_hint) &&
(curthread->t_proc_flag & TP_LWPEXIT))
break;
if (lwp != NULL)
lwp->lwp_nostop++;
/* XXX - use different cv? */
if (cv_wait_sig(&mi->mi_failover_cv, &mi->mi_lock) == 0) {
error = EINTR;
if (lwp != NULL)
lwp->lwp_nostop--;
break;
}
if (lwp != NULL)
lwp->lwp_nostop--;
}
if ((mi->mi_vfsp->vfs_flag & VFS_UNMOUNTED) &&
!OH_IS_STATE_RELE(op_hint)) {
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"wait_for_recovery: forced unmount"));
error = EIO;
} else if (mi->mi_flags & MI4_RECOV_FAIL) {
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"wait_for_recovery: fail since RECOV FAIL"));
error = mi->mi_error;
}
mutex_exit(&mi->mi_lock);
return (error);
}
/*
* If the client received NFS4ERR_GRACE for this particular mount,
* the client blocks here until it is time to try again.
*
* Return value:
* - 0 if wait was successful
* - EINTR if the call was interrupted
*/
int
nfs4_wait_for_grace(mntinfo4_t *mi, nfs4_recov_state_t *rsp)
{
int error = 0;
time_t curtime, time_to_wait;
/* do a unprotected check to reduce mi_lock contention */
if (mi->mi_grace_wait != 0) {
mutex_enter(&mi->mi_lock);
if (mi->mi_grace_wait != 0) {
if (!(rsp->rs_flags & NFS4_RS_GRACE_MSG))
rsp->rs_flags |= NFS4_RS_GRACE_MSG;
curtime = gethrestime_sec();
if (curtime < mi->mi_grace_wait) {
time_to_wait = mi->mi_grace_wait - curtime;
mutex_exit(&mi->mi_lock);
delay(SEC_TO_TICK(time_to_wait));
curtime = gethrestime_sec();
mutex_enter(&mi->mi_lock);
if (curtime >= mi->mi_grace_wait)
mi->mi_grace_wait = 0;
} else {
mi->mi_grace_wait = 0;
}
}
mutex_exit(&mi->mi_lock);
}
return (error);
}
/*
* If the client received NFS4ERR_DELAY for an operation on a vnode,
* the client blocks here until it is time to try again.
*
* Return value:
* - 0 if wait was successful
* - EINTR if the call was interrupted
*/
int
nfs4_wait_for_delay(vnode_t *vp, nfs4_recov_state_t *rsp)
{
int error = 0;
time_t curtime, time_to_wait;
rnode4_t *rp;
ASSERT(vp != NULL);
rp = VTOR4(vp);
/* do a unprotected check to reduce r_statelock contention */
if (rp->r_delay_wait != 0) {
mutex_enter(&rp->r_statelock);
if (rp->r_delay_wait != 0) {
if (!(rsp->rs_flags & NFS4_RS_DELAY_MSG)) {
rsp->rs_flags |= NFS4_RS_DELAY_MSG;
nfs4_mi_kstat_inc_delay(VTOMI4(vp));
}
curtime = gethrestime_sec();
if (curtime < rp->r_delay_wait) {
time_to_wait = rp->r_delay_wait - curtime;
mutex_exit(&rp->r_statelock);
delay(SEC_TO_TICK(time_to_wait));
curtime = gethrestime_sec();
mutex_enter(&rp->r_statelock);
if (curtime >= rp->r_delay_wait)
rp->r_delay_wait = 0;
} else {
rp->r_delay_wait = 0;
}
}
mutex_exit(&rp->r_statelock);
}
return (error);
}
/*
* The recovery thread.
*/
static void
nfs4_recov_thread(recov_info_t *recovp)
{
mntinfo4_t *mi = recovp->rc_mi;
nfs4_server_t *sp;
int done = 0, error = 0;
bool_t recov_fail = FALSE;
callb_cpr_t cpr_info;
kmutex_t cpr_lock;
nfs4_queue_event(RE_START, mi, NULL, mi->mi_recovflags,
recovp->rc_vp1, recovp->rc_vp2, 0, NULL, 0, TAG_NONE, TAG_NONE,
0, 0);
mutex_init(&cpr_lock, NULL, MUTEX_DEFAULT, NULL);
CALLB_CPR_INIT(&cpr_info, &cpr_lock, callb_generic_cpr, "nfsv4Recov");
mutex_enter(&mi->mi_lock);
mi->mi_recovthread = curthread;
mutex_exit(&mi->mi_lock);
/*
* We don't really need protection here against failover or
* migration, since the current thread is the one that would make
* any changes, but hold mi_recovlock anyway for completeness (and
* to satisfy any ASSERTs).
*/
(void) nfs_rw_enter_sig(&mi->mi_recovlock, RW_READER, 0);
sp = find_nfs4_server(mi);
if (sp != NULL)
mutex_exit(&sp->s_lock);
nfs_rw_exit(&mi->mi_recovlock);
/*
* Do any necessary recovery, based on the information in recovp
* and any recovery flags.
*/
do {
mutex_enter(&mi->mi_lock);
if (FS_OR_ZONE_GONE4(mi->mi_vfsp)) {
bool_t activesrv;
NFS4_DEBUG(nfs4_client_recov_debug &&
mi->mi_vfsp->vfs_flag & VFS_UNMOUNTED, (CE_NOTE,
"nfs4_recov_thread: file system has been "
"unmounted"));
NFS4_DEBUG(nfs4_client_recov_debug &&
zone_status_get(curproc->p_zone) >=
ZONE_IS_SHUTTING_DOWN, (CE_NOTE,
"nfs4_recov_thread: zone shutting down"));
/*
* If the server has lost its state for us and
* the filesystem is unmounted, then the filesystem
* can be tossed, even if there are lost lock or
* lost state calls in the recovery queue.
*/
if (mi->mi_recovflags &
(MI4R_NEED_CLIENTID | MI4R_REOPEN_FILES)) {
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"nfs4_recov_thread: bailing out"));
mi->mi_flags |= MI4_RECOV_FAIL;
mi->mi_error = recovp->rc_error;
recov_fail = TRUE;
}
/*
* We don't know if the server has any state for
* us, and the filesystem has been unmounted. If
* there are "lost state" recovery items, keep
* trying to process them until there are no more
* mounted filesystems for the server. Otherwise,
* bail out. The reason we don't mark the
* filesystem as failing recovery is in case we
* have to do "lost state" recovery later (e.g., a
* user process exits).
*/
if (!(mi->mi_recovflags & MI4R_LOST_STATE)) {
done = 1;
mutex_exit(&mi->mi_lock);
break;
}
mutex_exit(&mi->mi_lock);
if (sp == NULL)
activesrv = FALSE;
else {
mutex_enter(&sp->s_lock);
activesrv = nfs4_fs_active(sp);
}
if (!activesrv) {
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"no active fs for server %p",
(void *)sp));
mutex_enter(&mi->mi_lock);
mi->mi_flags |= MI4_RECOV_FAIL;
mi->mi_error = recovp->rc_error;
mutex_exit(&mi->mi_lock);
recov_fail = TRUE;
if (sp != NULL) {
/*
* Mark the server instance as
* dead, so that nobody will attach
* a new filesystem.
*/
nfs4_mark_srv_dead(sp);
}
}
if (sp != NULL)
mutex_exit(&sp->s_lock);
} else {
mutex_exit(&mi->mi_lock);
}
/*
* Check if we need to select a new server for a
* failover. Choosing a new server will force at
* least a check of the clientid.
*/
mutex_enter(&mi->mi_lock);
if (!recov_fail &&
(mi->mi_recovflags & MI4R_NEED_NEW_SERVER)) {
mutex_exit(&mi->mi_lock);
recov_newserver(recovp, &sp, &recov_fail);
} else
mutex_exit(&mi->mi_lock);
/*
* Check if we need to recover the clientid. This
* must be done before file and lock recovery, and it
* potentially affects the recovery threads for other
* filesystems, so it gets special treatment.
*/
if (sp != NULL && recov_fail == FALSE) {
mutex_enter(&sp->s_lock);
if (!(sp->s_flags & N4S_CLIENTID_SET)) {
mutex_exit(&sp->s_lock);
recov_clientid(recovp, sp);
} else {
/*
* Unset this flag in case another recovery
* thread successfully recovered the clientid
* for us already.
*/
mutex_enter(&mi->mi_lock);
mi->mi_recovflags &= ~MI4R_NEED_CLIENTID;
mutex_exit(&mi->mi_lock);
mutex_exit(&sp->s_lock);
}
}
/*
* Check if we need to get the security information.
*/
mutex_enter(&mi->mi_lock);
if ((mi->mi_recovflags & MI4R_NEED_SECINFO) &&
!(mi->mi_flags & MI4_RECOV_FAIL)) {
mutex_exit(&mi->mi_lock);
(void) nfs_rw_enter_sig(&mi->mi_recovlock,
RW_WRITER, 0);
error = nfs4_secinfo_recov(recovp->rc_mi,
recovp->rc_vp1, recovp->rc_vp2);
/*
* If error, nothing more can be done, stop
* the recovery.
*/
if (error) {
mutex_enter(&mi->mi_lock);
mi->mi_flags |= MI4_RECOV_FAIL;
mi->mi_error = recovp->rc_error;
mutex_exit(&mi->mi_lock);
nfs4_queue_event(RE_WRONGSEC, mi, NULL,
error, recovp->rc_vp1, recovp->rc_vp2,
0, NULL, 0, TAG_NONE, TAG_NONE, 0, 0);
}
nfs_rw_exit(&mi->mi_recovlock);
} else
mutex_exit(&mi->mi_lock);
/*
* Check if there's a bad seqid to recover.
*/
mutex_enter(&mi->mi_lock);
if ((mi->mi_recovflags & MI4R_BAD_SEQID) &&
!(mi->mi_flags & MI4_RECOV_FAIL)) {
mutex_exit(&mi->mi_lock);
(void) nfs_rw_enter_sig(&mi->mi_recovlock,
RW_WRITER, 0);
recov_bad_seqid(recovp);
nfs_rw_exit(&mi->mi_recovlock);
} else
mutex_exit(&mi->mi_lock);
/*
* Next check for recovery that affects the entire
* filesystem.
*/
if (sp != NULL) {
mutex_enter(&mi->mi_lock);
if ((mi->mi_recovflags & MI4R_REOPEN_FILES) &&
!(mi->mi_flags & MI4_RECOV_FAIL)) {
mutex_exit(&mi->mi_lock);
recov_openfiles(recovp, sp);
} else
mutex_exit(&mi->mi_lock);
}
/*
* Send any queued state recovery requests.
*/
mutex_enter(&mi->mi_lock);
if (sp != NULL &&
(mi->mi_recovflags & MI4R_LOST_STATE) &&
!(mi->mi_flags & MI4_RECOV_FAIL)) {
mutex_exit(&mi->mi_lock);
(void) nfs_rw_enter_sig(&mi->mi_recovlock,
RW_WRITER, 0);
nfs4_resend_lost_rqsts(recovp, sp);
if (list_head(&mi->mi_lost_state) == NULL) {
/* done */
mutex_enter(&mi->mi_lock);
mi->mi_recovflags &= ~MI4R_LOST_STATE;
mutex_exit(&mi->mi_lock);
}
nfs_rw_exit(&mi->mi_recovlock);
} else {
mutex_exit(&mi->mi_lock);
}
/*
* See if there is anything more to do. If not, announce
* that we are done and exit.
*
* Need mi_recovlock to keep 'sp' valid. Must grab
* mi_recovlock before mi_lock to preserve lock ordering.
*/
(void) nfs_rw_enter_sig(&mi->mi_recovlock, RW_READER, 0);
mutex_enter(&mi->mi_lock);
if ((mi->mi_recovflags & ~MI4R_SRV_REBOOT) == 0 ||
(mi->mi_flags & MI4_RECOV_FAIL)) {
list_t local_lost_state;
nfs4_lost_rqst_t *lrp;
/*
* We need to remove the lost requests before we
* unmark the mi as no longer doing recovery to
* avoid a race with a new thread putting new lost
* requests on the same mi (and the going away
* thread would remove the new lost requests).
*
* Move the lost requests to a local list since
* nfs4_remove_lost_rqst() drops mi_lock, and
* dropping the mi_lock would make our check to
* see if recovery is done no longer valid.
*/
list_create(&local_lost_state,
sizeof (nfs4_lost_rqst_t),
offsetof(nfs4_lost_rqst_t, lr_node));
list_move_tail(&local_lost_state, &mi->mi_lost_state);
done = 1;
mutex_exit(&mi->mi_lock);
/*
* Now officially free the "moved"
* lost requests.
*/
while ((lrp = list_head(&local_lost_state)) != NULL) {
list_remove(&local_lost_state, lrp);
nfs4_free_lost_rqst(lrp, sp);
}
list_destroy(&local_lost_state);
} else
mutex_exit(&mi->mi_lock);
nfs_rw_exit(&mi->mi_recovlock);
/*
* If the filesystem has been forcibly unmounted, there is
* probably no point in retrying immediately. Furthermore,
* there might be user processes waiting for a chance to
* queue up "lost state" requests, so that they can exit.
* So pause here for a moment. Same logic for zone shutdown.
*/
if (!done && FS_OR_ZONE_GONE4(mi->mi_vfsp)) {
mutex_enter(&mi->mi_lock);
cv_broadcast(&mi->mi_failover_cv);
mutex_exit(&mi->mi_lock);
delay(SEC_TO_TICK(nfs4_unmount_delay));
}
} while (!done);
if (sp != NULL)
nfs4_server_rele(sp);
/*
* Return all recalled delegations
*/
nfs4_dlistclean();
mutex_enter(&mi->mi_lock);
recov_done(mi, recovp);
mutex_exit(&mi->mi_lock);
/*
* Free up resources that were allocated for us.
*/
if (recovp->rc_vp1 != NULL)
VN_RELE(recovp->rc_vp1);
if (recovp->rc_vp2 != NULL)
VN_RELE(recovp->rc_vp2);
/* now we are done using the mi struct, signal the waiters */
mutex_enter(&mi->mi_lock);
mi->mi_in_recovery--;
if (mi->mi_in_recovery == 0)
cv_broadcast(&mi->mi_cv_in_recov);
mutex_exit(&mi->mi_lock);
VFS_RELE(mi->mi_vfsp);
MI4_RELE(mi);
kmem_free(recovp, sizeof (recov_info_t));
mutex_enter(&cpr_lock);
CALLB_CPR_EXIT(&cpr_info);
mutex_destroy(&cpr_lock);
zthread_exit();
}
/*
* Log the end of recovery and notify any waiting threads.
*/
static void
recov_done(mntinfo4_t *mi, recov_info_t *recovp)
{
ASSERT(MUTEX_HELD(&mi->mi_lock));
nfs4_queue_event(RE_END, mi, NULL, 0, recovp->rc_vp1,
recovp->rc_vp2, 0, NULL, 0, TAG_NONE, TAG_NONE, 0, 0);
mi->mi_recovthread = NULL;
mi->mi_flags &= ~MI4_RECOV_ACTIV;
mi->mi_recovflags &= ~MI4R_SRV_REBOOT;
cv_broadcast(&mi->mi_failover_cv);
}
/*
* State-specific recovery routines, by state.
*/
/*
* Failover.
*
* Replaces *spp with a reference to the new server, which must
* eventually be freed.
*/
static void
recov_newserver(recov_info_t *recovp, nfs4_server_t **spp, bool_t *recov_fail)
{
mntinfo4_t *mi = recovp->rc_mi;
servinfo4_t *svp = NULL;
nfs4_server_t *osp = *spp;
CLIENT *cl;
enum clnt_stat status;
struct timeval tv;
int error;
int oncethru = 0;
rnode4_t *rp;
int index;
nfs_fh4 fh;
char *snames;
size_t len;
(void) nfs_rw_enter_sig(&mi->mi_recovlock, RW_WRITER, 0);
tv.tv_sec = 2;
tv.tv_usec = 0;
#ifdef lint
/*
* Lint can't follow the logic, so thinks that snames and len
* can be used before being set. They can't, but lint can't
* figure it out. To address the lint warning, initialize
* snames and len for lint.
*/
snames = NULL;
len = 0;
#endif
/*
* Ping the null NFS procedure of every server in
* the list until one responds. We always start
* at the head of the list and always skip the one
* that is current, since it's caused us a problem.
*/
while (svp == NULL) {
for (svp = mi->mi_servers; svp; svp = svp->sv_next) {
mutex_enter(&mi->mi_lock);
if (FS_OR_ZONE_GONE4(mi->mi_vfsp)) {
mi->mi_flags |= MI4_RECOV_FAIL;
mutex_exit(&mi->mi_lock);
(void) nfs_rw_exit(&mi->mi_recovlock);
*recov_fail = TRUE;
if (oncethru)
kmem_free(snames, len);
return;
}
mutex_exit(&mi->mi_lock);
(void) nfs_rw_enter_sig(&svp->sv_lock, RW_READER, 0);
if (svp->sv_flags & SV4_NOTINUSE) {
nfs_rw_exit(&svp->sv_lock);
continue;
}
nfs_rw_exit(&svp->sv_lock);
if (!oncethru && svp == mi->mi_curr_serv)
continue;
error = clnt_tli_kcreate(svp->sv_knconf, &svp->sv_addr,
NFS_PROGRAM, NFS_V4, 0, 1, CRED(), &cl);
if (error)
continue;
if (!(mi->mi_flags & MI4_INT))
cl->cl_nosignal = TRUE;
status = CLNT_CALL(cl, RFS_NULL, xdr_void, NULL,
xdr_void, NULL, tv);
if (!(mi->mi_flags & MI4_INT))
cl->cl_nosignal = FALSE;
AUTH_DESTROY(cl->cl_auth);
CLNT_DESTROY(cl);
if (status == RPC_SUCCESS) {
nfs4_queue_event(RE_FAILOVER, mi,
svp == mi->mi_curr_serv ? NULL :
svp->sv_hostname, 0, NULL, NULL, 0,
NULL, 0, TAG_NONE, TAG_NONE, 0, 0);
break;
}
}
if (svp == NULL) {
if (!oncethru) {
snames = nfs4_getsrvnames(mi, &len);
nfs4_queue_fact(RF_SRVS_NOT_RESPOND, mi,
0, 0, 0, FALSE, snames, 0, NULL);
oncethru = 1;
}
delay(hz);
}
}
if (oncethru) {
nfs4_queue_fact(RF_SRVS_OK, mi, 0, 0, 0, FALSE, snames,
0, NULL);
kmem_free(snames, len);
}
#if DEBUG
(void) nfs_rw_enter_sig(&svp->sv_lock, RW_READER, 0);
ASSERT((svp->sv_flags & SV4_NOTINUSE) == 0);
nfs_rw_exit(&svp->sv_lock);
#endif
mutex_enter(&mi->mi_lock);
mi->mi_recovflags &= ~MI4R_NEED_NEW_SERVER;
if (svp != mi->mi_curr_serv) {
servinfo4_t *osvp = mi->mi_curr_serv;
mutex_exit(&mi->mi_lock);
/*
* Update server-dependent fields in the root vnode.
*/
index = rtable4hash(mi->mi_rootfh);
rw_enter(&rtable4[index].r_lock, RW_WRITER);
rp = r4find(&rtable4[index], mi->mi_rootfh, mi->mi_vfsp);
if (rp != NULL) {
NFS4_DEBUG(nfs4_client_failover_debug, (CE_NOTE,
"recov_newserver: remapping %s", rnode4info(rp)));
mutex_enter(&rp->r_statelock);
rp->r_server = svp;
PURGE_ATTRCACHE4_LOCKED(rp);
mutex_exit(&rp->r_statelock);
(void) nfs4_free_data_reclaim(rp);
nfs4_purge_rddir_cache(RTOV4(rp));
rw_exit(&rtable4[index].r_lock);
NFS4_DEBUG(nfs4_client_failover_debug, (CE_NOTE,
"recov_newserver: done with %s",
rnode4info(rp)));
VN_RELE(RTOV4(rp));
} else
rw_exit(&rtable4[index].r_lock);
(void) dnlc_purge_vfsp(mi->mi_vfsp, 0);
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_REOPEN_FILES | MI4R_REMAP_FILES;
if (recovp->rc_srv_reboot)
mi->mi_recovflags |= MI4R_SRV_REBOOT;
mi->mi_curr_serv = svp;
mi->mi_failover++;
mi->mi_flags &= ~MI4_BADOWNER_DEBUG;
mutex_exit(&mi->mi_lock);
(void) nfs_rw_enter_sig(&svp->sv_lock, RW_READER, 0);
fh.nfs_fh4_len = svp->sv_fhandle.fh_len;
fh.nfs_fh4_val = svp->sv_fhandle.fh_buf;
sfh4_update(mi->mi_rootfh, &fh);
fh.nfs_fh4_len = svp->sv_pfhandle.fh_len;
fh.nfs_fh4_val = svp->sv_pfhandle.fh_buf;
sfh4_update(mi->mi_srvparentfh, &fh);
nfs_rw_exit(&svp->sv_lock);
*spp = nfs4_move_mi(mi, osvp, svp);
if (osp != NULL)
nfs4_server_rele(osp);
} else
mutex_exit(&mi->mi_lock);
(void) nfs_rw_exit(&mi->mi_recovlock);
}
/*
* Clientid.
*/
static void
recov_clientid(recov_info_t *recovp, nfs4_server_t *sp)
{
mntinfo4_t *mi = recovp->rc_mi;
int error = 0;
int still_stale;
int need_new_s;
ASSERT(sp != NULL);
/*
* Acquire the recovery lock and then verify that the clientid
* still needs to be recovered. (Note that s_recovlock is supposed
* to be acquired before s_lock.) Since the thread holds the
* recovery lock, no other thread will recover the clientid.
*/
(void) nfs_rw_enter_sig(&sp->s_recovlock, RW_WRITER, 0);
(void) nfs_rw_enter_sig(&mi->mi_recovlock, RW_WRITER, 0);
mutex_enter(&sp->s_lock);
still_stale = ((sp->s_flags & N4S_CLIENTID_SET) == 0);
mutex_exit(&sp->s_lock);
if (still_stale) {
nfs4_error_t n4e;
nfs4_error_zinit(&n4e);
nfs4setclientid(mi, kcred, TRUE, &n4e);
error = n4e.error;
if (error != 0) {
/*
* nfs4setclientid may have set MI4R_NEED_NEW_SERVER,
* if so, just return and let recov_thread drive
* failover.
*/
mutex_enter(&mi->mi_lock);
need_new_s = mi->mi_recovflags & MI4R_NEED_NEW_SERVER;
mutex_exit(&mi->mi_lock);
if (need_new_s) {
nfs_rw_exit(&mi->mi_recovlock);
nfs_rw_exit(&sp->s_recovlock);
return;
}
nfs4_queue_event(RE_CLIENTID, mi, NULL, n4e.error, NULL,
NULL, n4e.stat, NULL, 0, TAG_NONE, TAG_NONE, 0, 0);
mutex_enter(&mi->mi_lock);
mi->mi_flags |= MI4_RECOV_FAIL;
mi->mi_error = recovp->rc_error;
mutex_exit(&mi->mi_lock);
/* don't destroy the nfs4_server, let umount do it */
}
}
if (error == 0) {
mutex_enter(&mi->mi_lock);
mi->mi_recovflags &= ~MI4R_NEED_CLIENTID;
/*
* If still_stale isn't true, then another thread already
* recovered the clientid. And that thread that set the
* clientid will have initiated reopening files on all the
* filesystems for the server, so we should not initiate
* reopening for this filesystem here.
*/
if (still_stale) {
mi->mi_recovflags |= MI4R_REOPEN_FILES;
if (recovp->rc_srv_reboot)
mi->mi_recovflags |= MI4R_SRV_REBOOT;
}
mutex_exit(&mi->mi_lock);
}
nfs_rw_exit(&mi->mi_recovlock);
if (error != 0) {
nfs_rw_exit(&sp->s_recovlock);
mutex_enter(&mi->mi_lock);
if ((mi->mi_flags & MI4_RECOV_FAIL) == 0)
delay(SEC_TO_TICK(recov_err_delay));
mutex_exit(&mi->mi_lock);
} else {
mntinfo4_t **milist;
mntinfo4_t *tmi;
int nummi, i;
/*
* Initiate recovery of open files for other filesystems.
* We create an array of filesystems, rather than just
* walking the filesystem list, to avoid deadlock issues
* with s_lock and mi_recovlock.
*/
milist = make_milist(sp, &nummi);
for (i = 0; i < nummi; i++) {
tmi = milist[i];
if (tmi != mi) {
(void) nfs_rw_enter_sig(&tmi->mi_recovlock,
RW_READER, 0);
start_recovery_action(NR_OPENFILES, TRUE, tmi,
NULL, NULL);
nfs_rw_exit(&tmi->mi_recovlock);
}
}
free_milist(milist, nummi);
nfs_rw_exit(&sp->s_recovlock);
}
}
/*
* Return an array of filesystems associated with the given server. The
* caller should call free_milist() to free the references and memory.
*/
static mntinfo4_t **
make_milist(nfs4_server_t *sp, int *nummip)
{
int nummi, i;
mntinfo4_t **milist;
mntinfo4_t *tmi;
mutex_enter(&sp->s_lock);
nummi = 0;
for (tmi = sp->mntinfo4_list; tmi != NULL; tmi = tmi->mi_clientid_next)
nummi++;
milist = kmem_alloc(nummi * sizeof (mntinfo4_t *), KM_SLEEP);
for (i = 0, tmi = sp->mntinfo4_list; tmi != NULL; i++,
tmi = tmi->mi_clientid_next) {
milist[i] = tmi;
VFS_HOLD(tmi->mi_vfsp);
}
mutex_exit(&sp->s_lock);
*nummip = nummi;
return (milist);
}
/*
* Free the filesystem list created by make_milist().
*/
static void
free_milist(mntinfo4_t **milist, int nummi)
{
mntinfo4_t *tmi;
int i;
for (i = 0; i < nummi; i++) {
tmi = milist[i];
VFS_RELE(tmi->mi_vfsp);
}
kmem_free(milist, nummi * sizeof (mntinfo4_t *));
}
/*
* Filehandle
*/
/*
* Lookup the filehandle for the given vnode and update the rnode if it has
* changed.
*
* Errors:
* - if the filehandle could not be updated because of an error that
* requires further recovery, initiate that recovery and return.
* - if the filehandle could not be updated because of a signal, pretend we
* succeeded and let someone else deal with it.
* - if the filehandle could not be updated and the filesystem has been
* forcibly unmounted, pretend we succeeded, and let the caller deal with
* the forced unmount (to retry or not to retry, that is the question).
* - if the filehandle could not be updated because of some other error,
* mark the rnode bad and return.
*/
static void
recov_filehandle(nfs4_recov_t action, mntinfo4_t *mi, vnode_t *vp)
{
rnode4_t *rp = VTOR4(vp);
nfs4_error_t e = { 0, NFS4_OK, RPC_SUCCESS };
bool_t needrecov;
mutex_enter(&rp->r_statelock);
if (rp->r_flags & R4RECOVERR) {
mutex_exit(&rp->r_statelock);
return;
}
/*
* If someone else is updating the filehandle, wait for them to
* finish and then let our caller retry.
*/
if (rp->r_flags & R4RECEXPFH) {
while (rp->r_flags & R4RECEXPFH) {
cv_wait(&rp->r_cv, &rp->r_statelock);
}
mutex_exit(&rp->r_statelock);
return;
}
rp->r_flags |= R4RECEXPFH;
mutex_exit(&rp->r_statelock);
if (action == NR_BADHANDLE) {
/* shouldn't happen */
nfs4_queue_event(RE_BADHANDLE, mi, NULL, 0,
vp, NULL, 0, NULL, 0, TAG_NONE, TAG_NONE, 0, 0);
}
nfs4_remap_file(mi, vp, 0, &e);
needrecov = nfs4_needs_recovery(&e, FALSE, mi->mi_vfsp);
/*
* If we get BADHANDLE, FHEXPIRED or STALE in their handler,
* something is broken. Don't try to recover, just mark the
* file dead.
*/
DTRACE_PROBE2(recov__filehandle, nfs4_error_t, &e, vnode_t, vp);
if (needrecov) {
if (e.error == 0) {
switch (e.stat) {
case NFS4ERR_BADHANDLE:
case NFS4ERR_FHEXPIRED:
case NFS4ERR_STALE:
goto norec; /* Unrecoverable errors */
default:
break;
}
}
(void) nfs4_start_recovery(&e, mi, vp, NULL,
NULL, NULL, OP_LOOKUP, NULL, NULL, NULL);
} else if (e.error != EINTR &&
!NFS4_FRC_UNMT_ERR(e.error, mi->mi_vfsp) &&
(e.error != 0 || e.stat != NFS4_OK)) {
nfs4_recov_fh_fail(vp, e.error, e.stat);
/*
* Don't set r_error to ESTALE. Higher-level code (e.g.,
* cstatat_getvp()) retries on ESTALE, which would cause
* an infinite loop.
*/
}
norec:
mutex_enter(&rp->r_statelock);
rp->r_flags &= ~R4RECEXPFH;
cv_broadcast(&rp->r_cv);
mutex_exit(&rp->r_statelock);
}
/*
* Stale Filehandle
*/
/*
* A stale filehandle can happen when an individual file has
* been removed, or when an entire filesystem has been taken
* offline. To distinguish these cases, we do this:
* - if a GETATTR with the current filehandle is okay, we do
* nothing (this can happen with two-filehandle ops)
* - if the GETATTR fails, but a GETATTR of the root filehandle
* succeeds, mark the rnode with R4STALE, which will stop use
* - if the GETATTR fails, and a GETATTR of the root filehandle
* also fails, we consider the problem filesystem-wide, so:
* - if we can failover, we should
* - if we can't failover, we should mark both the original
* vnode and the root bad
*/
static void
recov_stale(mntinfo4_t *mi, vnode_t *vp)
{
rnode4_t *rp = VTOR4(vp);
vnode_t *rootvp = NULL;
nfs4_error_t e = { 0, NFS4_OK, RPC_SUCCESS };
nfs4_ga_res_t gar;
char *fail_msg = "failed to recover from NFS4ERR_STALE";
bool_t needrecov;
mutex_enter(&rp->r_statelock);
if (rp->r_flags & R4RECOVERR) {
mutex_exit(&rp->r_statelock);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: already marked dead, rp %s",
rnode4info(rp)));
return;
}
if (rp->r_flags & R4STALE) {
mutex_exit(&rp->r_statelock);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: already marked stale, rp %s",
rnode4info(rp)));
return;
}
mutex_exit(&rp->r_statelock);
/* Try a GETATTR on this vnode */
nfs4_getattr_otw_norecovery(vp, &gar, &e, CRED(), 0);
/*
* Handle non-STALE recoverable errors
*/
needrecov = nfs4_needs_recovery(&e, FALSE, vp->v_vfsp);
if (needrecov) {
if (e.error == 0) {
switch (e.stat) {
case NFS4ERR_STALE:
case NFS4ERR_BADHANDLE:
goto norec; /* Unrecoverable */
default:
break;
}
}
(void) nfs4_start_recovery(&e, mi, vp, NULL,
NULL, NULL, OP_GETATTR, NULL, NULL, NULL);
goto out;
}
norec:
/* Are things OK for this vnode? */
if (!e.error && e.stat == NFS4_OK) {
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: file appears fine, rp %s",
rnode4info(rp)));
goto out;
}
/* Did we get an unrelated non-recoverable error? */
if (e.error || e.stat != NFS4ERR_STALE) {
nfs4_fail_recov(vp, fail_msg, e.error, e.stat);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: unrelated fatal error, rp %s",
rnode4info(rp)));
goto out;
}
/*
* If we don't appear to be dealing with the root node, find it.
*/
if ((vp->v_flag & VROOT) == 0) {
nfs4_error_zinit(&e);
e.error = VFS_ROOT(vp->v_vfsp, &rootvp);
if (e.error) {
nfs4_fail_recov(vp, fail_msg, 0, NFS4ERR_STALE);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: can't find root node for rp %s",
rnode4info(rp)));
goto out;
}
}
/* Try a GETATTR on the root vnode */
if (rootvp != NULL) {
nfs4_error_zinit(&e);
nfs4_getattr_otw_norecovery(rootvp, &gar, &e, CRED(), 0);
needrecov = nfs4_needs_recovery(&e, FALSE, vp->v_vfsp);
if (needrecov) {
if (e.error == 0) {
switch (e.stat) {
case NFS4ERR_STALE:
case NFS4ERR_BADHANDLE:
goto unrec; /* Unrecoverable */
default:
break;
}
}
(void) nfs4_start_recovery(&e, mi, rootvp, NULL,
NULL, NULL, OP_GETATTR, NULL, NULL, NULL);
}
unrec:
/*
* Check to see if a failover attempt is warranted
* NB: nfs4_try_failover doesn't check for STALE
* because recov_stale gets a shot first. Now that
* recov_stale has failed, go ahead and try failover.
*
* If the getattr on the root filehandle was successful,
* then mark recovery as failed for 'vp' and exit.
*/
if (nfs4_try_failover(&e) == 0 && e.stat != NFS4ERR_STALE) {
/*
* pass the original error to fail_recov, not
* the one from trying the root vnode.
*/
nfs4_fail_recov(vp, fail_msg, 0, NFS4ERR_STALE);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: root node OK, marking "
"dead rp %s", rnode4info(rp)));
goto out;
}
}
/*
* Here, we know that both the original file and the
* root filehandle (which may be the same) are stale.
* We want to fail over if we can, and if we can't, we
* want to mark everything in sight bad.
*/
if (FAILOVER_MOUNT4(mi)) {
mutex_enter(&mi->mi_lock);
mi->mi_recovflags |= MI4R_NEED_NEW_SERVER;
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: failing over due to rp %s",
rnode4info(rp)));
mutex_exit(&mi->mi_lock);
} else {
rnode4_t *rootrp;
servinfo4_t *svp;
/*
* Can't fail over, so mark things dead.
*
* If rootvp is set, we know we have a distinct
* non-root vnode which can be marked dead in
* the usual way.
*
* Then we want to mark the root vnode dead.
* Note that if rootvp wasn't set, our vp is
* actually the root vnode.
*/
if (rootvp != NULL) {
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_stale: can't fail over, marking dead rp %s",
rnode4info(rp)));
nfs4_fail_recov(vp, fail_msg, 0, NFS4ERR_STALE);
} else {
rootvp = vp;
VN_HOLD(rootvp);
}
/*
* Mark root dead, but quietly - since
* the root rnode is frequently recreated,
* we can encounter this at every access.
* Also mark recovery as failed on this VFS.
*/
rootrp = VTOR4(rootvp);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_CONT,
"recov_stale: marking dead root rp %s",
rnode4info(rootrp)));
mutex_enter(&rootrp->r_statelock);
rootrp->r_flags |= (R4RECOVERR | R4STALE);
rootrp->r_error = ESTALE;
mutex_exit(&rootrp->r_statelock);
mutex_enter(&mi->mi_lock);
mi->mi_error = ESTALE;
mutex_exit(&mi->mi_lock);
svp = mi->mi_curr_serv;
(void) nfs_rw_enter_sig(&svp->sv_lock, RW_WRITER, 0);
svp->sv_flags |= SV4_ROOT_STALE;
nfs_rw_exit(&svp->sv_lock);
}
out:
if (rootvp)
VN_RELE(rootvp);
}
/*
* Locks.
*/
/*
* Reclaim all the active (acquired) locks for the given file.
* If a process lost a lock, the process is sent a SIGLOST. This is not
* considered an error.
*
* Return values:
* Errors and status are returned via the nfs4_error_t parameter
* If an error indicates that recovery is needed, the caller is responsible
* for dealing with it.
*/
static void
relock_file(vnode_t *vp, mntinfo4_t *mi, nfs4_error_t *ep,
fattr4_change pre_change)
{
locklist_t *locks, *llp;
rnode4_t *rp;
ASSERT(ep != NULL);
nfs4_error_zinit(ep);
if (VTOMI4(vp)->mi_flags & MI4_LLOCK)
return;
nfs4_flush_lock_owners(VTOR4(vp));
/*
* If we get an error that requires recovery actions, just bail out
* and let the top-level recovery code handle it.
*
* If we get some other error, kill the process that owned the lock
* and mark its remaining locks (if any) as belonging to NOPID, so
* that we don't make any more reclaim requests for that process.
*/
rp = VTOR4(vp);
locks = flk_active_locks_for_vp(vp);
for (llp = locks; llp != NULL; llp = llp->ll_next) {
int did_reclaim = 1;
ASSERT(llp->ll_vp == vp);
if (llp->ll_flock.l_pid == NOPID)
continue;
reclaim_one_lock(vp, &llp->ll_flock, ep, &did_reclaim);
/*
* If we need to restart recovery, stop processing the
* list. Some errors would be recoverable under other
* circumstances, but if they happen here we just give up
* on the lock.
*/
if (nfs4_needs_recovery(ep, TRUE, vp->v_vfsp)) {
if (ep->error != 0)
break;
if (!nfs4_recov_marks_dead(ep->stat))
break;
}
/*
* In case the server isn't offering us a grace period, or
* if we missed it, we might have opened & locked from scratch,
* rather than reopened/reclaimed.
* We need to ensure that the object hadn't been otherwise
* changed during this time, by comparing the changeinfo.
* We get passed the changeinfo from before the reopen by our
* caller, in pre_change.
* The changeinfo from after the reopen is in rp->r_change,
* courtesy of the GETATTR in the reopen.
* If they're different, then the file has changed, and we
* have to SIGLOST the app.
*/
if (ep->error == 0 && ep->stat == NFS4_OK && !did_reclaim) {
mutex_enter(&rp->r_statelock);
if (pre_change != rp->r_change)
ep->stat = NFS4ERR_NO_GRACE;
mutex_exit(&rp->r_statelock);
}
if (ep->error != 0 || ep->stat != NFS4_OK) {
if (ep->error != 0)
nfs4_queue_event(RE_FAIL_RELOCK, mi,
NULL, ep->error, vp, NULL, 0, NULL,
llp->ll_flock.l_pid, TAG_NONE, TAG_NONE,
0, 0);
else
nfs4_queue_event(RE_FAIL_RELOCK, mi,
NULL, 0, vp, NULL, ep->stat, NULL,
llp->ll_flock.l_pid, TAG_NONE, TAG_NONE,
0, 0);
nfs4_send_siglost(llp->ll_flock.l_pid, mi, vp, TRUE,
ep->error, ep->stat);
relock_skip_pid(vp, llp, llp->ll_flock.l_pid);
/* Reinitialize the nfs4_error and continue */
nfs4_error_zinit(ep);
}
}
if (locks != NULL)
flk_free_locklist(locks);
}
/*
* Reclaim the given lock.
*
* Errors are returned via the nfs4_error_t parameter.
*/
static void
reclaim_one_lock(vnode_t *vp, flock64_t *flk, nfs4_error_t *ep,
int *did_reclaimp)
{
cred_t *cr;
rnode4_t *rp = VTOR4(vp);
cr = pid_to_cr(flk->l_pid);
if (cr == NULL) {
nfs4_error_init(ep, ESRCH);
return;
}
do {
mutex_enter(&rp->r_statelock);
if (rp->r_flags & R4RECOVERR) {
mutex_exit(&rp->r_statelock);
nfs4_error_init(ep, ESTALE);
break;
}
mutex_exit(&rp->r_statelock);
nfs4frlock(NFS4_LCK_CTYPE_RECLAIM, vp, F_SETLK, flk,
FREAD|FWRITE, 0, cr, ep, NULL, did_reclaimp);
if (ep->error == 0 && ep->stat == NFS4ERR_FHEXPIRED)
start_recovery_action(NR_FHEXPIRED, TRUE, VTOMI4(vp),
vp, NULL);
} while (ep->error == 0 && ep->stat == NFS4ERR_FHEXPIRED);
crfree(cr);
}
/*
* Open files.
*/
/*
* Verifies if the nfsstat4 is a valid error for marking this vnode dead.
* Returns 1 if the error is valid; 0 otherwise.
*/
static int
nfs4_valid_recov_err_for_vp(vnode_t *vp, nfsstat4 stat)
{
/*
* We should not be marking non-regular files as dead,
* except in very rare cases (eg: BADHANDLE or NFS4ERR_BADNAME).
*/
if (vp->v_type != VREG && stat != NFS4ERR_BADHANDLE &&
stat != NFS4ERR_BADNAME)
return (0);
return (1);
}
/*
* Failed attempting to recover a filehandle. If 'stat' is valid for 'vp',
* then mark the object dead. Since we've had to do a lookup for
* filehandle recovery, we will mark the object dead if we got NOENT.
*/
static void
nfs4_recov_fh_fail(vnode_t *vp, int error, nfsstat4 stat)
{
ASSERT(vp != NULL);
if ((error == 0) && (stat != NFS4ERR_NOENT) &&
(!nfs4_valid_recov_err_for_vp(vp, stat)))
return;
nfs4_fail_recov(vp, "can't recover filehandle", error, stat);
}
/*
* Recovery from a "shouldn't happen" error. In the long term, we'd like
* to mark only the data structure(s) that provided the bad value as being
* bad. But for now we'll just mark the entire file.
*/
static void
recov_badstate(recov_info_t *recovp, vnode_t *vp, nfsstat4 stat)
{
ASSERT(vp != NULL);
recov_throttle(recovp, vp);
if (!nfs4_valid_recov_err_for_vp(vp, stat))
return;
nfs4_fail_recov(vp, "", 0, stat);
}
/*
* Free up the information saved for a lost state request.
*/
static void
nfs4_free_lost_rqst(nfs4_lost_rqst_t *lrp, nfs4_server_t *sp)
{
component4 *filep;
nfs4_open_stream_t *osp;
int have_sync_lock;
NFS4_DEBUG(nfs4_lost_rqst_debug,
(CE_NOTE, "nfs4_free_lost_rqst:"));
switch (lrp->lr_op) {
case OP_OPEN:
filep = &lrp->lr_ofile;
if (filep->utf8string_val) {
kmem_free(filep->utf8string_val, filep->utf8string_len);
filep->utf8string_val = NULL;
}
break;
case OP_DELEGRETURN:
nfs4delegreturn_cleanup(VTOR4(lrp->lr_vp), sp);
break;
case OP_CLOSE:
osp = lrp->lr_osp;
ASSERT(osp != NULL);
mutex_enter(&osp->os_sync_lock);
have_sync_lock = 1;
if (osp->os_pending_close) {
/* clean up the open file state. */
osp->os_pending_close = 0;
nfs4close_notw(lrp->lr_vp, osp, &have_sync_lock);
}
if (have_sync_lock)
mutex_exit(&osp->os_sync_lock);
break;
}
lrp->lr_op = 0;
if (lrp->lr_oop != NULL) {
open_owner_rele(lrp->lr_oop);
lrp->lr_oop = NULL;
}
if (lrp->lr_osp != NULL) {
open_stream_rele(lrp->lr_osp, VTOR4(lrp->lr_vp));
lrp->lr_osp = NULL;
}
if (lrp->lr_lop != NULL) {
lock_owner_rele(lrp->lr_lop);
lrp->lr_lop = NULL;
}
if (lrp->lr_flk != NULL) {
kmem_free(lrp->lr_flk, sizeof (flock64_t));
lrp->lr_flk = NULL;
}
if (lrp->lr_vp != NULL) {
VN_RELE(lrp->lr_vp);
lrp->lr_vp = NULL;
}
if (lrp->lr_dvp != NULL) {
VN_RELE(lrp->lr_dvp);
lrp->lr_dvp = NULL;
}
if (lrp->lr_cr != NULL) {
crfree(lrp->lr_cr);
lrp->lr_cr = NULL;
}
kmem_free(lrp, sizeof (nfs4_lost_rqst_t));
}
/*
* Remove any lost state requests and free them.
*/
static void
nfs4_remove_lost_rqsts(mntinfo4_t *mi, nfs4_server_t *sp)
{
nfs4_lost_rqst_t *lrp;
mutex_enter(&mi->mi_lock);
while ((lrp = list_head(&mi->mi_lost_state)) != NULL) {
list_remove(&mi->mi_lost_state, lrp);
mutex_exit(&mi->mi_lock);
nfs4_free_lost_rqst(lrp, sp);
mutex_enter(&mi->mi_lock);
}
mutex_exit(&mi->mi_lock);
}
/*
* Reopen all the files for the given filesystem and reclaim any locks.
*/
static void
recov_openfiles(recov_info_t *recovp, nfs4_server_t *sp)
{
mntinfo4_t *mi = recovp->rc_mi;
nfs4_opinst_t *reopenlist = NULL, *rep;
nfs4_error_t e = { 0, NFS4_OK, RPC_SUCCESS };
open_claim_type4 claim;
int remap;
char *fail_msg = "No such file or directory on replica";
rnode4_t *rp;
fattr4_change pre_change;
ASSERT(sp != NULL);
/*
* This check is to allow a 10ms pause before we reopen files
* it should allow the server time to have received the CB_NULL
* reply and update its internal structures such that (if
* applicable) we are granted a delegation on reopened files.
*/
mutex_enter(&sp->s_lock);
if ((sp->s_flags & (N4S_CB_PINGED | N4S_CB_WAITER)) == 0) {
sp->s_flags |= N4S_CB_WAITER;
(void) cv_reltimedwait(&sp->wait_cb_null, &sp->s_lock,
drv_usectohz(N4S_CB_PAUSE_TIME), TR_CLOCK_TICK);
}
mutex_exit(&sp->s_lock);
(void) nfs_rw_enter_sig(&sp->s_recovlock, RW_READER, 0);
(void) nfs_rw_enter_sig(&mi->mi_recovlock, RW_WRITER, 0);
if (NFS4_VOLATILE_FH(mi)) {
nfs4_remap_root(mi, &e, 0);
if (nfs4_needs_recovery(&e, FALSE, mi->mi_vfsp)) {
(void) nfs4_start_recovery(&e, mi, NULL,
NULL, NULL, NULL, OP_LOOKUP, NULL, NULL, NULL);
}
}
mutex_enter(&mi->mi_lock);
if (recovp->rc_srv_reboot || (mi->mi_recovflags & MI4R_SRV_REBOOT))
claim = CLAIM_PREVIOUS;
else
claim = CLAIM_NULL;
mutex_exit(&mi->mi_lock);
if (e.error == 0 && e.stat == NFS4_OK) {
/*
* Get a snapshot of open files in the filesystem. Note
* that new opens will stall until the server's grace
* period is done.
*/
reopenlist = r4mkopenlist(mi);
mutex_enter(&mi->mi_lock);
remap = mi->mi_recovflags & MI4R_REMAP_FILES;
mutex_exit(&mi->mi_lock);
/*
* Since we are re-establishing state on the
* server, its ok to blow away the saved lost
* requests since we don't need to reissue it.
*/
nfs4_remove_lost_rqsts(mi, sp);
for (rep = reopenlist; rep; rep = rep->re_next) {
if (remap) {
nfs4_remap_file(mi, rep->re_vp,
NFS4_REMAP_CKATTRS, &e);
}
DTRACE_PROBE2(recov__openfiles, nfs4_error_t, &e,
vnode_t, rep->re_vp);
if (e.error == ENOENT || e.stat == NFS4ERR_NOENT) {
/*
* The current server does not have the file
* that is to be remapped. This is most
* likely due to an improperly maintained
* replica. The files that are missing from
* the server will be marked dead and logged
* in order to make sys admins aware of the
* problem.
*/
nfs4_fail_recov(rep->re_vp,
fail_msg, e.error, e.stat);
/*
* We've already handled the error so clear it.
*/
nfs4_error_zinit(&e);
continue;
} else if (e.error == 0 && e.stat == NFS4_OK) {
int j;
rp = VTOR4(rep->re_vp);
mutex_enter(&rp->r_statelock);
pre_change = rp->r_change;
mutex_exit(&rp->r_statelock);
for (j = 0; j < rep->re_numosp; j++) {
nfs4_reopen(rep->re_vp, rep->re_osp[j],
&e, claim, FALSE, TRUE);
if (e.error != 0 || e.stat != NFS4_OK)
break;
}
if (nfs4_needs_recovery(&e, TRUE,
mi->mi_vfsp)) {
(void) nfs4_start_recovery(&e, mi,
rep->re_vp, NULL, NULL, NULL,
OP_OPEN, NULL, NULL, NULL);
break;
}
}
#ifdef DEBUG
if (nfs4_recovdelay > 0)
delay(MSEC_TO_TICK(nfs4_recovdelay * 1000));
#endif
if (e.error == 0 && e.stat == NFS4_OK) {
relock_file(rep->re_vp, mi, &e, pre_change);
if (nfs4_needs_recovery(&e, TRUE, mi->mi_vfsp))
(void) nfs4_start_recovery(&e, mi,
rep->re_vp, NULL, NULL, NULL,
OP_LOCK, NULL, NULL, NULL);
}
if (e.error != 0 || e.stat != NFS4_OK)
break;
}
/*
* Check to see if we need to remap files passed in
* via the recovery arguments; this will have been
* done for open files. A failure here is not fatal.
*/
if (remap) {
nfs4_error_t ignore;
nfs4_check_remap(mi, recovp->rc_vp1, NFS4_REMAP_CKATTRS,
&ignore);
nfs4_check_remap(mi, recovp->rc_vp2, NFS4_REMAP_CKATTRS,
&ignore);
}
}
if (e.error == 0 && e.stat == NFS4_OK) {
mutex_enter(&mi->mi_lock);
mi->mi_recovflags &= ~(MI4R_REOPEN_FILES | MI4R_REMAP_FILES);
mutex_exit(&mi->mi_lock);
}
nfs_rw_exit(&mi->mi_recovlock);
nfs_rw_exit(&sp->s_recovlock);
if (reopenlist != NULL)
r4releopenlist(reopenlist);
}
/*
* Resend the queued state recovery requests in "rqsts".
*/
static void
nfs4_resend_lost_rqsts(recov_info_t *recovp, nfs4_server_t *sp)
{
nfs4_lost_rqst_t *lrp, *tlrp;
mntinfo4_t *mi = recovp->rc_mi;
nfs4_error_t n4e;
#ifdef NOTYET
uint32_t deny_bits = 0;
#endif
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE, "nfs4_resend_lost_rqsts"));
ASSERT(mi != NULL);
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
mutex_enter(&mi->mi_lock);
lrp = list_head(&mi->mi_lost_state);
mutex_exit(&mi->mi_lock);
while (lrp != NULL) {
nfs4_error_zinit(&n4e);
resend_one_op(lrp, &n4e, mi, sp);
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE,
"nfs4_resend_lost_rqsts: resend request: for vp %p got "
"error %d stat %d", (void *)lrp->lr_vp, n4e.error,
n4e.stat));
/*
* If we get a recovery error that we can actually
* recover from (such as ETIMEDOUT, FHEXPIRED), we
* return and let the recovery thread redrive the call.
* Don't requeue unless the zone is still healthy.
*/
if (zone_status_get(curproc->p_zone) < ZONE_IS_SHUTTING_DOWN &&
nfs4_needs_recovery(&n4e, TRUE, mi->mi_vfsp) &&
(nfs4_try_failover(&n4e) ||
NFS4_FRC_UNMT_ERR(n4e.error, mi->mi_vfsp) ||
(n4e.error == 0 && n4e.stat != NFS4ERR_BADHANDLE &&
!nfs4_recov_marks_dead(n4e.stat)))) {
/*
* For these three errors, we want to delay a bit
* instead of pounding the server into submission.
* We have to do this manually; the normal
* processing for these errors only works for
* non-recovery requests.
*/
if ((n4e.error == 0 && n4e.stat == NFS4ERR_DELAY) ||
(n4e.error == 0 && n4e.stat == NFS4ERR_GRACE) ||
(n4e.error == 0 && n4e.stat == NFS4ERR_RESOURCE) ||
NFS4_FRC_UNMT_ERR(n4e.error, mi->mi_vfsp)) {
delay(SEC_TO_TICK(nfs4err_delay_time));
} else {
(void) nfs4_start_recovery(&n4e,
mi, lrp->lr_dvp, lrp->lr_vp, NULL, NULL,
lrp->lr_op, NULL, NULL, NULL);
}
return;
}
mutex_enter(&mi->mi_lock);
list_remove(&mi->mi_lost_state, lrp);
tlrp = lrp;
lrp = list_head(&mi->mi_lost_state);
mutex_exit(&mi->mi_lock);
nfs4_free_lost_rqst(tlrp, sp);
}
}
/*
* Resend the given op, and issue any necessary undo call.
* errors are returned via the nfs4_error_t parameter.
*/
static void
resend_one_op(nfs4_lost_rqst_t *lrp, nfs4_error_t *ep,
mntinfo4_t *mi, nfs4_server_t *sp)
{
vnode_t *vp;
nfs4_open_stream_t *osp;
cred_t *cr;
uint32_t acc_bits;
vp = lrp->lr_vp;
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE, "resend_one_op: "
"have a lost open/close request for vp %p", (void *)vp));
switch (lrp->lr_op) {
case OP_OPEN:
nfs4_resend_open_otw(&vp, lrp, ep);
break;
case OP_OPEN_DOWNGRADE:
ASSERT(lrp->lr_oop != NULL);
ep->error = nfs4_start_open_seqid_sync(lrp->lr_oop, mi);
ASSERT(!ep->error); /* recov thread always succeeds */
ASSERT(lrp->lr_osp != NULL);
mutex_enter(&lrp->lr_osp->os_sync_lock);
nfs4_open_downgrade(lrp->lr_dg_acc, lrp->lr_dg_deny,
lrp->lr_oop, lrp->lr_osp, vp, lrp->lr_cr, lrp,
ep, NULL, NULL);
mutex_exit(&lrp->lr_osp->os_sync_lock);
nfs4_end_open_seqid_sync(lrp->lr_oop);
break;
case OP_CLOSE:
osp = lrp->lr_osp;
cr = lrp->lr_cr;
acc_bits = 0;
mutex_enter(&osp->os_sync_lock);
if (osp->os_share_acc_read)
acc_bits |= OPEN4_SHARE_ACCESS_READ;
if (osp->os_share_acc_write)
acc_bits |= OPEN4_SHARE_ACCESS_WRITE;
mutex_exit(&osp->os_sync_lock);
nfs4close_one(vp, osp, cr, acc_bits, lrp, ep,
CLOSE_RESEND, 0, 0, 0);
break;
case OP_LOCK:
case OP_LOCKU:
resend_lock(lrp, ep);
goto done;
case OP_DELEGRETURN:
nfs4_resend_delegreturn(lrp, ep, sp);
goto done;
default:
#ifdef DEBUG
cmn_err(CE_PANIC, "resend_one_op: unexpected op: %d",
lrp->lr_op);
#endif
nfs4_queue_event(RE_LOST_STATE_BAD_OP, mi, NULL,
lrp->lr_op, lrp->lr_vp, lrp->lr_dvp, NFS4_OK, NULL, 0,
TAG_NONE, TAG_NONE, 0, 0);
nfs4_error_init(ep, EINVAL);
return;
}
/*
* No need to retry nor send an "undo" CLOSE in the
* event the server rebooted.
*/
if (ep->error == 0 && (ep->stat == NFS4ERR_STALE_CLIENTID ||
ep->stat == NFS4ERR_STALE_STATEID || ep->stat == NFS4ERR_EXPIRED))
goto done;
/*
* If we resent a CLOSE or OPEN_DOWNGRADE, there's nothing
* to undo. Undoing locking operations was handled by
* resend_lock().
*/
if (lrp->lr_op == OP_OPEN_DOWNGRADE || lrp->lr_op == OP_CLOSE)
goto done;
/*
* If we get any other error for OPEN, then don't attempt
* to undo the resend of the open (since it was never
* successful!).
*/
ASSERT(lrp->lr_op == OP_OPEN);
if (ep->error || ep->stat != NFS4_OK)
goto done;
/*
* Now let's undo our OPEN.
*/
nfs4_error_zinit(ep);
close_after_open_resend(vp, lrp->lr_cr, lrp->lr_oacc, ep);
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE, "resend_one_op: "
"nfs4close_one: for vp %p got error %d stat %d",
(void *)vp, ep->error, ep->stat));
done:
if (vp != lrp->lr_vp)
VN_RELE(vp);
}
/*
* Close a file that was opened via a resent OPEN.
* Most errors are passed back to the caller (via the return value and
* *statp), except for FHEXPIRED, which is retried.
*
* It might be conceptually cleaner to push the CLOSE request onto the
* front of the resend queue, rather than sending it here. That would
* match the way we undo lost lock requests. On the other
* hand, we've already got something that works, and there's no reason to
* change it at this time.
*/
static void
close_after_open_resend(vnode_t *vp, cred_t *cr, uint32_t acc_bits,
nfs4_error_t *ep)
{
for (;;) {
nfs4close_one(vp, NULL, cr, acc_bits, NULL, ep,
CLOSE_AFTER_RESEND, 0, 0, 0);
if (ep->error == 0 && ep->stat == NFS4_OK)
break; /* success; done */
if (ep->error != 0 || ep->stat != NFS4ERR_FHEXPIRED)
break;
/* else retry FHEXPIRED */
}
}
/*
* Resend the given lost lock request. Return an errno value. If zero,
* *statp is set to the NFS status code for the call.
*
* Issue a SIGLOST and mark the rnode dead if we get a non-recovery error or
* a recovery error that we don't actually recover from yet (eg: BAD_SEQID).
* Let the recovery thread redrive the call if we get a recovery error that
* we can actually recover from.
*/
static void
resend_lock(nfs4_lost_rqst_t *lrp, nfs4_error_t *ep)
{
bool_t send_siglost = FALSE;
vnode_t *vp = lrp->lr_vp;
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE, "resend_lock:"));
ASSERT(lrp->lr_ctype == NFS4_LCK_CTYPE_REINSTATE ||
lrp->lr_ctype == NFS4_LCK_CTYPE_RESEND);
nfs4frlock(lrp->lr_ctype, vp, F_SETLK,
lrp->lr_flk, FREAD|FWRITE, 0, lrp->lr_cr, ep, lrp, NULL);
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE, "resend_lock: "
"nfs4frlock for vp %p returned error %d, stat %d",
(void *)vp, ep->error, ep->stat));
if (ep->error == 0 && ep->stat == 0)
goto done;
if (ep->error == 0 && ep->stat == NFS4ERR_DENIED &&
lrp->lr_ctype == NFS4_LCK_CTYPE_RESEND)
goto done;
/*
* If we failed with a non-recovery error, send SIGLOST and
* mark the file dead.
*/
if (!nfs4_needs_recovery(ep, TRUE, vp->v_vfsp))
send_siglost = TRUE;
else {
/*
* Done with recovering LOST LOCK in the event the
* server rebooted or we've lost the lease.
*/
if (ep->error == 0 && (ep->stat == NFS4ERR_STALE_CLIENTID ||
ep->stat == NFS4ERR_STALE_STATEID ||
ep->stat == NFS4ERR_EXPIRED)) {
goto done;
}
/*
* BAD_STATEID on an unlock indicates that the server has
* forgotten about the lock anyway, so act like the call
* was successful.
*/
if (ep->error == 0 && ep->stat == NFS4ERR_BAD_STATEID &&
lrp->lr_op == OP_LOCKU)
goto done;
/*
* If we got a recovery error that we don't actually
* recover from, send SIGLOST. If the filesystem was
* forcibly unmounted, we skip the SIGLOST because (a) it's
* unnecessary noise, and (b) there could be a new process
* with the same pid as the one that had generated the lost
* state request.
*/
if (ep->error == 0 && (ep->stat == NFS4ERR_BADHANDLE ||
nfs4_recov_marks_dead(ep->stat))) {
if (!(vp->v_vfsp->vfs_flag & VFS_UNMOUNTED))
send_siglost = TRUE;
goto done;
}
/*
* If the filesystem was forcibly unmounted, we
* still need to synchronize with the server and
* release state. Try again later.
*/
if (NFS4_FRC_UNMT_ERR(ep->error, vp->v_vfsp))
goto done;
/*
* If we get a recovery error that we can actually
* recover from (such as ETIMEDOUT, FHEXPIRED),
* return and let the recovery thread redrive the call.
*
* For the three errors below, we want to delay a bit
* instead of pounding the server into submission.
*/
if ((ep->error == 0 && ep->stat == NFS4ERR_DELAY) ||
(ep->error == 0 && ep->stat == NFS4ERR_GRACE) ||
(ep->error == 0 && ep->stat == NFS4ERR_RESOURCE))
delay(SEC_TO_TICK(recov_err_delay));
goto done;
}
done:
if (send_siglost) {
cred_t *sv_cred;
/*
* Must be root or the actual thread being issued the
* SIGLOST for this to work, so just become root.
*/
sv_cred = curthread->t_cred;
curthread->t_cred = kcred;
nfs4_send_siglost(lrp->lr_flk->l_pid, VTOMI4(vp), vp, FALSE,
ep->error, ep->stat);
curthread->t_cred = sv_cred;
/*
* Flush any additional reinstantiation requests for
* this operation. Sending multiple SIGLOSTs to the user
* process is unlikely to help and may cause trouble.
*/
if (lrp->lr_ctype == NFS4_LCK_CTYPE_REINSTATE)
flush_reinstate(lrp);
}
}
/*
* Remove any lock reinstantiation requests that correspond to the given
* lost request. We only remove items that follow lrp in the queue,
* assuming that lrp will be removed by the generic lost state code.
*/
static void
flush_reinstate(nfs4_lost_rqst_t *lrp)
{
vnode_t *vp;
pid_t pid;
mntinfo4_t *mi;
nfs4_lost_rqst_t *nlrp;
vp = lrp->lr_vp;
mi = VTOMI4(vp);
pid = lrp->lr_flk->l_pid;
/*
* If there are any more reinstantation requests to get rid of,
* they should all be clustered at the front of the lost state
* queue.
*/
mutex_enter(&mi->mi_lock);
for (lrp = list_next(&mi->mi_lost_state, lrp); lrp != NULL;
lrp = nlrp) {
nlrp = list_next(&mi->mi_lost_state, lrp);
if (lrp->lr_op != OP_LOCK && lrp->lr_op != OP_LOCKU)
break;
if (lrp->lr_ctype != NFS4_LCK_CTYPE_REINSTATE)
break;
ASSERT(lrp->lr_vp == vp);
ASSERT(lrp->lr_flk->l_pid == pid);
NFS4_DEBUG(nfs4_lost_rqst_debug, (CE_NOTE,
"remove reinstantiation %p", (void *)lrp));
list_remove(&mi->mi_lost_state, lrp);
nfs4_free_lost_rqst(lrp, NULL);
}
mutex_exit(&mi->mi_lock);
}
/*
* End of state-specific recovery routines.
*/
/*
* Allocate a lost request struct, initialize it from lost_rqstp (including
* bumping the reference counts for the referenced vnode, etc.), and hang
* it off of recovp.
*/
static void
nfs4_save_lost_rqst(nfs4_lost_rqst_t *lost_rqstp, recov_info_t *recovp,
nfs4_recov_t *action, mntinfo4_t *mi)
{
nfs4_lost_rqst_t *destp;
ASSERT(recovp->rc_lost_rqst == NULL);
destp = kmem_alloc(sizeof (nfs4_lost_rqst_t), KM_SLEEP);
recovp->rc_lost_rqst = destp;
if (lost_rqstp->lr_op == OP_LOCK ||
lost_rqstp->lr_op == OP_LOCKU) {
ASSERT(lost_rqstp->lr_lop);
*action = NR_LOST_LOCK;
destp->lr_ctype = lost_rqstp->lr_ctype;
destp->lr_locktype = lost_rqstp->lr_locktype;
} else if (lost_rqstp->lr_op == OP_OPEN) {
component4 *srcfp, *destfp;
destp->lr_oacc = lost_rqstp->lr_oacc;
destp->lr_odeny = lost_rqstp->lr_odeny;
destp->lr_oclaim = lost_rqstp->lr_oclaim;
if (lost_rqstp->lr_oclaim == CLAIM_DELEGATE_CUR)
destp->lr_ostateid = lost_rqstp->lr_ostateid;
srcfp = &lost_rqstp->lr_ofile;
destfp = &destp->lr_ofile;
/*
* Consume caller's utf8string
*/
destfp->utf8string_len = srcfp->utf8string_len;
destfp->utf8string_val = srcfp->utf8string_val;
srcfp->utf8string_len = 0;
srcfp->utf8string_val = NULL; /* make sure not reused */
*action = NR_LOST_STATE_RQST;
} else if (lost_rqstp->lr_op == OP_OPEN_DOWNGRADE) {
destp->lr_dg_acc = lost_rqstp->lr_dg_acc;
destp->lr_dg_deny = lost_rqstp->lr_dg_deny;
*action = NR_LOST_STATE_RQST;
} else if (lost_rqstp->lr_op == OP_CLOSE) {
ASSERT(lost_rqstp->lr_oop);
*action = NR_LOST_STATE_RQST;
} else if (lost_rqstp->lr_op == OP_DELEGRETURN) {
*action = NR_LOST_STATE_RQST;
} else {
#ifdef DEBUG
cmn_err(CE_PANIC, "nfs4_save_lost_rqst: bad op %d",
lost_rqstp->lr_op);
#endif
nfs4_queue_event(RE_LOST_STATE_BAD_OP, mi, NULL,
lost_rqstp->lr_op, lost_rqstp->lr_vp, lost_rqstp->lr_dvp,
NFS4_OK, NULL, curproc->p_pid, TAG_NONE, TAG_NONE, 0, 0);
*action = NR_UNUSED;
recovp->rc_lost_rqst = NULL;
kmem_free(destp, sizeof (nfs4_lost_rqst_t));
return;
}
destp->lr_op = lost_rqstp->lr_op;
destp->lr_vp = lost_rqstp->lr_vp;
if (destp->lr_vp)
VN_HOLD(destp->lr_vp);
destp->lr_dvp = lost_rqstp->lr_dvp;
if (destp->lr_dvp)
VN_HOLD(destp->lr_dvp);
destp->lr_oop = lost_rqstp->lr_oop;
if (destp->lr_oop)
open_owner_hold(destp->lr_oop);
destp->lr_osp = lost_rqstp->lr_osp;
if (destp->lr_osp)
open_stream_hold(destp->lr_osp);
destp->lr_lop = lost_rqstp->lr_lop;
if (destp->lr_lop)
lock_owner_hold(destp->lr_lop);
destp->lr_cr = lost_rqstp->lr_cr;
if (destp->lr_cr)
crhold(destp->lr_cr);
if (lost_rqstp->lr_flk == NULL)
destp->lr_flk = NULL;
else {
destp->lr_flk = kmem_alloc(sizeof (flock64_t), KM_SLEEP);
*destp->lr_flk = *lost_rqstp->lr_flk;
}
destp->lr_putfirst = lost_rqstp->lr_putfirst;
}
/*
* Map the given return values (errno and nfs4 status code) to a recovery
* action and fill in the following fields of recovp: rc_action,
* rc_srv_reboot, rc_stateid, rc_lost_rqst.
*/
void
errs_to_action(recov_info_t *recovp,
nfs4_server_t *sp, mntinfo4_t *mi, stateid4 *sidp,
nfs4_lost_rqst_t *lost_rqstp, int unmounted, nfs_opnum4 op,
nfs4_bseqid_entry_t *bsep)
{
nfs4_recov_t action = NR_UNUSED;
bool_t reboot = FALSE;
int try_f;
int error = recovp->rc_orig_errors.error;
nfsstat4 stat = recovp->rc_orig_errors.stat;
bzero(&recovp->rc_stateid, sizeof (stateid4));
recovp->rc_lost_rqst = NULL;
recovp->rc_bseqid_rqst = NULL;
try_f = nfs4_try_failover(&recovp->rc_orig_errors) &&
FAILOVER_MOUNT4(mi);
/*
* We start recovery for EINTR only in the lost lock
* or lost open/close case.
*/
if (try_f || error == EINTR || (error == EIO && unmounted)) {
recovp->rc_error = (error != 0 ? error : geterrno4(stat));
if (lost_rqstp) {
ASSERT(lost_rqstp->lr_op != 0);
nfs4_save_lost_rqst(lost_rqstp, recovp, &action, mi);
}
if (try_f)
action = NR_FAILOVER;
} else if (error != 0) {
recovp->rc_error = error;
nfs4_queue_event(RE_UNEXPECTED_ERRNO, mi, NULL, error, NULL,
NULL, 0, NULL, 0, TAG_NONE, TAG_NONE, 0, 0);
action = NR_CLIENTID;
} else {
recovp->rc_error = geterrno4(stat);
switch (stat) {
#ifdef notyet
case NFS4ERR_LEASE_MOVED:
action = xxx;
break;
#endif
case NFS4ERR_MOVED:
action = NR_MOVED;
break;
case NFS4ERR_BADHANDLE:
action = NR_BADHANDLE;
break;
case NFS4ERR_BAD_SEQID:
if (bsep)
save_bseqid_rqst(bsep, recovp);
action = NR_BAD_SEQID;
break;
case NFS4ERR_OLD_STATEID:
action = NR_OLDSTATEID;
break;
case NFS4ERR_WRONGSEC:
action = NR_WRONGSEC;
break;
case NFS4ERR_FHEXPIRED:
action = NR_FHEXPIRED;
break;
case NFS4ERR_BAD_STATEID:
if (sp == NULL || (sp != NULL && inlease(sp))) {
action = NR_BAD_STATEID;
if (sidp)
recovp->rc_stateid = *sidp;
} else
action = NR_CLIENTID;
break;
case NFS4ERR_EXPIRED:
/*
* The client's lease has expired, either due
* to a network partition or perhaps a client
* error. In either case, try an NR_CLIENTID
* style recovery. reboot remains false, since
* there is no evidence the server has rebooted.
* This will cause CLAIM_NULL opens and lock
* requests without the reclaim bit.
*/
action = NR_CLIENTID;
DTRACE_PROBE4(nfs4__expired,
nfs4_server_t *, sp,
mntinfo4_t *, mi,
stateid4 *, sidp, int, op);
break;
case NFS4ERR_STALE_CLIENTID:
case NFS4ERR_STALE_STATEID:
action = NR_CLIENTID;
reboot = TRUE;
break;
case NFS4ERR_RESOURCE:
/*
* If this had been a FAILOVER mount, then
* we'd have tried failover. Since it's not,
* just delay a while and retry.
*/
action = NR_DELAY;
break;
case NFS4ERR_GRACE:
action = NR_GRACE;
break;
case NFS4ERR_DELAY:
action = NR_DELAY;
break;
case NFS4ERR_STALE:
action = NR_STALE;
break;
default:
nfs4_queue_event(RE_UNEXPECTED_STATUS, mi, NULL, 0,
NULL, NULL, stat, NULL, 0, TAG_NONE, TAG_NONE,
0, 0);
action = NR_CLIENTID;
break;
}
}
/* make sure action got set */
ASSERT(action != NR_UNUSED);
recovp->rc_srv_reboot = reboot;
recovp->rc_action = action;
nfs4_queue_fact(RF_ERR, mi, stat, action, op, reboot, NULL, error,
NULL);
}
/*
* Return the (held) credential for the process with the given pid.
* May return NULL (e.g., process not found).
*/
static cred_t *
pid_to_cr(pid_t pid)
{
proc_t *p;
cred_t *cr;
mutex_enter(&pidlock);
if ((p = prfind(pid)) == NULL) {
mutex_exit(&pidlock);
return (NULL);
}
mutex_enter(&p->p_crlock);
crhold(cr = p->p_cred);
mutex_exit(&p->p_crlock);
mutex_exit(&pidlock);
return (cr);
}
/*
* Send SIGLOST to the given process and queue the event.
*
* The 'dump' boolean tells us whether this action should dump the
* in-kernel queue of recovery messages or not.
*/
void
nfs4_send_siglost(pid_t pid, mntinfo4_t *mi, vnode_t *vp, bool_t dump,
int error, nfsstat4 stat)
{
proc_t *p;
mutex_enter(&pidlock);
p = prfind(pid);
if (p)
psignal(p, SIGLOST);
mutex_exit(&pidlock);
nfs4_queue_event(dump ? RE_SIGLOST : RE_SIGLOST_NO_DUMP, mi,
NULL, error, vp, NULL, stat, NULL, pid, TAG_NONE, TAG_NONE, 0, 0);
}
/*
* Scan the lock list for entries that match the given pid. Unregister those
* locks that do and change their pid to NOPID.
*/
static void
relock_skip_pid(vnode_t *vp, locklist_t *llp, pid_t pid)
{
for (; llp != NULL; llp = llp->ll_next) {
if (llp->ll_flock.l_pid == pid) {
int r;
/*
* Unregister the lost lock.
*/
llp->ll_flock.l_type = F_UNLCK;
r = reclock(vp, &llp->ll_flock, SETFLCK, FREAD | FWRITE,
0, NULL);
/* The unlock cannot fail */
ASSERT(r == 0);
llp->ll_flock.l_pid = NOPID;
}
}
}
/*
* Mark a file as having failed recovery, after making a last-ditch effort
* to return any delegation.
*
* Sets r_error to EIO or ESTALE for the given vnode.
*/
void
nfs4_fail_recov(vnode_t *vp, char *why, int error, nfsstat4 stat)
{
rnode4_t *rp = VTOR4(vp);
#ifdef DEBUG
if (nfs4_fail_recov_stop)
debug_enter("nfs4_fail_recov");
#endif
mutex_enter(&rp->r_statelock);
if (rp->r_flags & (R4RECOVERR|R4RECOVERRP)) {
mutex_exit(&rp->r_statelock);
return;
}
/*
* Set R4RECOVERRP to indicate that a recovery error is in
* progress. This will shut down reads and writes at the top
* half. Don't set R4RECOVERR until after we've returned the
* delegation, otherwise it will fail.
*/
rp->r_flags |= R4RECOVERRP;
mutex_exit(&rp->r_statelock);
nfs4delegabandon(rp);
mutex_enter(&rp->r_statelock);
rp->r_flags |= (R4RECOVERR | R4STALE);
rp->r_error = (error == 0 && stat == NFS4ERR_STALE) ? ESTALE : EIO;
PURGE_ATTRCACHE4_LOCKED(rp);
if (!(vp->v_vfsp->vfs_flag & VFS_UNMOUNTED))
nfs4_queue_event(RE_DEAD_FILE, VTOMI4(vp), NULL, error,
vp, NULL, stat, why, 0, TAG_NONE, TAG_NONE, 0, 0);
mutex_exit(&rp->r_statelock);
dnlc_purge_vp(vp);
}
/*
* recov_throttle: if the file had the same recovery action within the
* throttle interval, wait for the throttle interval to finish before
* proceeding.
*
* Side effects: updates the rnode with the current recovery information.
*/
static void
recov_throttle(recov_info_t *recovp, vnode_t *vp)
{
time_t curtime, time_to_wait;
rnode4_t *rp = VTOR4(vp);
curtime = gethrestime_sec();
mutex_enter(&rp->r_statelock);
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_throttle: now: (%d, %ld), last: (%d, %ld)",
recovp->rc_action, curtime,
rp->r_recov_act, rp->r_last_recov));
if (recovp->rc_action == rp->r_recov_act &&
rp->r_last_recov + recov_err_delay > curtime) {
time_to_wait = rp->r_last_recov + recov_err_delay - curtime;
mutex_exit(&rp->r_statelock);
delay(SEC_TO_TICK(time_to_wait));
curtime = gethrestime_sec();
mutex_enter(&rp->r_statelock);
}
rp->r_last_recov = curtime;
rp->r_recov_act = recovp->rc_action;
mutex_exit(&rp->r_statelock);
}
/*
* React to NFS4ERR_GRACE by setting the time we'll permit
* the next call to this filesystem.
*/
void
nfs4_set_grace_wait(mntinfo4_t *mi)
{
mutex_enter(&mi->mi_lock);
/* Mark the time for the future */
mi->mi_grace_wait = gethrestime_sec() + nfs4err_delay_time;
mutex_exit(&mi->mi_lock);
}
/*
* React to MFS4ERR_DELAY by setting the time we'll permit
* the next call to this vnode.
*/
void
nfs4_set_delay_wait(vnode_t *vp)
{
rnode4_t *rp = VTOR4(vp);
mutex_enter(&rp->r_statelock);
/*
* Calculate amount we should delay, initial
* delay will be short and then we will back off.
*/
if (rp->r_delay_interval == 0)
rp->r_delay_interval = NFS4_INITIAL_DELAY_INTERVAL;
else
/* calculate next interval value */
rp->r_delay_interval =
MIN(NFS4_MAX_DELAY_INTERVAL, (rp->r_delay_interval << 1));
rp->r_delay_wait = gethrestime_sec() + rp->r_delay_interval;
mutex_exit(&rp->r_statelock);
}
/*
* The caller is responsible for freeing the returned string.
*/
static char *
nfs4_getsrvnames(mntinfo4_t *mi, size_t *len)
{
servinfo4_t *svp;
char *srvnames;
char *namep;
size_t length;
/*
* Calculate the length of the string required to hold all
* of the server names plus either a comma or a null
* character following each individual one.
*/
length = 0;
for (svp = mi->mi_servers; svp != NULL; svp = svp->sv_next) {
(void) nfs_rw_enter_sig(&svp->sv_lock, RW_READER, 0);
if (svp->sv_flags & SV4_NOTINUSE) {
nfs_rw_exit(&svp->sv_lock);
continue;
}
nfs_rw_exit(&svp->sv_lock);
length += svp->sv_hostnamelen;
}
srvnames = kmem_alloc(length, KM_SLEEP);
namep = srvnames;
for (svp = mi->mi_servers; svp != NULL; svp = svp->sv_next) {
(void) nfs_rw_enter_sig(&svp->sv_lock, RW_READER, 0);
if (svp->sv_flags & SV4_NOTINUSE) {
nfs_rw_exit(&svp->sv_lock);
continue;
}
nfs_rw_exit(&svp->sv_lock);
(void) strcpy(namep, svp->sv_hostname);
namep += svp->sv_hostnamelen - 1;
*namep++ = ',';
}
*--namep = '\0';
*len = length;
return (srvnames);
}
static void
save_bseqid_rqst(nfs4_bseqid_entry_t *bsep, recov_info_t *recovp)
{
nfs4_bseqid_entry_t *destp;
destp = kmem_alloc(sizeof (nfs4_bseqid_entry_t), KM_SLEEP);
recovp->rc_bseqid_rqst = destp;
if (bsep->bs_oop)
open_owner_hold(bsep->bs_oop);
destp->bs_oop = bsep->bs_oop;
if (bsep->bs_lop)
lock_owner_hold(bsep->bs_lop);
destp->bs_lop = bsep->bs_lop;
if (bsep->bs_vp)
VN_HOLD(bsep->bs_vp);
destp->bs_vp = bsep->bs_vp;
destp->bs_pid = bsep->bs_pid;
destp->bs_tag = bsep->bs_tag;
destp->bs_seqid = bsep->bs_seqid;
}
static void
free_bseqid_rqst(nfs4_bseqid_entry_t *bsep)
{
if (bsep->bs_oop)
open_owner_rele(bsep->bs_oop);
if (bsep->bs_lop)
lock_owner_rele(bsep->bs_lop);
if (bsep->bs_vp)
VN_RELE(bsep->bs_vp);
kmem_free(bsep, sizeof (nfs4_bseqid_entry_t));
}
/*
* We don't actually fully recover from NFS4ERR_BAD_SEQID. We
* simply mark the open owner and open stream (if provided) as "bad".
* Then future uses of these data structures will be limited to basically
* just cleaning up the internal client state (no going OTW).
*
* The result of this is to return errors back to the app/usr when
* we receive NFS4ERR_BAD_SEQID, but also allow future/new calls to
* succeed so progress can be made.
*/
void
recov_bad_seqid(recov_info_t *recovp)
{
mntinfo4_t *mi = recovp->rc_mi;
nfs4_open_owner_t *bad_oop;
nfs4_lock_owner_t *bad_lop;
vnode_t *vp;
rnode4_t *rp = NULL;
pid_t pid;
nfs4_bseqid_entry_t *bsep, *tbsep;
int error;
ASSERT(mi != NULL);
ASSERT(nfs_rw_lock_held(&mi->mi_recovlock, RW_WRITER));
mutex_enter(&mi->mi_lock);
bsep = list_head(&mi->mi_bseqid_list);
mutex_exit(&mi->mi_lock);
/*
* Handle all the bad seqid entries on mi's list.
*/
while (bsep != NULL) {
bad_oop = bsep->bs_oop;
bad_lop = bsep->bs_lop;
vp = bsep->bs_vp;
pid = bsep->bs_pid;
NFS4_DEBUG(nfs4_client_recov_debug, (CE_NOTE,
"recov_bad_seqid: mark oop %p lop %p as bad for "
"vp %p tag %s pid %d: last good seqid %d for tag %s",
(void *)bad_oop, (void *)bad_lop, (void *)vp,
nfs4_ctags[bsep->bs_tag].ct_str, pid,
bad_oop ? bad_oop->oo_last_good_seqid : 0,
bad_oop ? nfs4_ctags[bad_oop->oo_last_good_op].ct_str :
nfs4_ctags[TAG_NONE].ct_str));
nfs4_queue_event(RE_BAD_SEQID, mi, NULL,
0, vp, NULL, NFS4ERR_BAD_SEQID, NULL, pid, bsep->bs_tag,
bad_oop ? bad_oop->oo_last_good_op : TAG_NONE,
bsep->bs_seqid, bad_oop ? bad_oop->oo_last_good_seqid : 0);
if (bad_oop) {
/* essentially reset the open owner */
error = nfs4_start_open_seqid_sync(bad_oop, mi);
ASSERT(!error); /* recov thread always succeeds */
bad_oop->oo_name = nfs4_get_new_oo_name();
bad_oop->oo_seqid = 0;
nfs4_end_open_seqid_sync(bad_oop);
}
if (bad_lop) {
mutex_enter(&bad_lop->lo_lock);
bad_lop->lo_flags |= NFS4_BAD_SEQID_LOCK;
mutex_exit(&bad_lop->lo_lock);
ASSERT(vp != NULL);
rp = VTOR4(vp);
mutex_enter(&rp->r_statelock);
rp->r_flags |= R4LODANGLERS;
mutex_exit(&rp->r_statelock);
nfs4_send_siglost(pid, mi, vp, TRUE,
0, NFS4ERR_BAD_SEQID);
}
mutex_enter(&mi->mi_lock);
list_remove(&mi->mi_bseqid_list, bsep);
tbsep = bsep;
bsep = list_head(&mi->mi_bseqid_list);
mutex_exit(&mi->mi_lock);
free_bseqid_rqst(tbsep);
}
mutex_enter(&mi->mi_lock);
mi->mi_recovflags &= ~MI4R_BAD_SEQID;
mutex_exit(&mi->mi_lock);
}
|