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
|
/*
Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
This file is part of GlusterFS.
This file is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3 or
later), or the GNU General Public License, version 2 (GPLv2), in all
cases as published by the Free Software Foundation.
*/
#include "glusterfs.h"
#include "logging.h"
#include "dict.h"
#include "xlator.h"
#include "list.h"
#include "compat.h"
#include "compat-errno.h"
#include "common-utils.h"
#include "call-stub.h"
#include "statedump.h"
#include "defaults.h"
#include "write-behind-mem-types.h"
#include "write-behind-messages.h"
#define MAX_VECTOR_COUNT 8
#define WB_AGGREGATE_SIZE 131072 /* 128 KB */
#define WB_WINDOW_SIZE 1048576 /* 1MB */
typedef struct list_head list_head_t;
struct wb_conf;
struct wb_inode;
typedef struct wb_inode {
ssize_t window_conf;
ssize_t window_current;
ssize_t transit; /* size of data stack_wound, and yet
to be fulfilled (wb_fulfill_cbk).
used for trickling_writes
*/
list_head_t all; /* All requests, from enqueue() till destroy().
Used only for resetting generation
number when empty.
*/
list_head_t todo; /* Work to do (i.e, STACK_WIND to server).
Once we STACK_WIND, the entry is taken
off the list. If it is non-sync write,
then we continue to track it via @liability
or @temptation depending on the status
of its writeback.
*/
list_head_t liability; /* Non-sync writes which are lied
(STACK_UNWIND'ed to caller) but ack
from server not yet complete. This
is the "liability" which we hold, and
must guarantee that dependent operations
which arrive later (which overlap, etc.)
are issued only after their dependencies
in this list are "fulfilled".
Server acks for entries in this list
shrinks the window.
The sum total of all req->write_size
of entries in this list must be kept less
than the permitted window size.
*/
list_head_t temptation; /* Operations for which we are tempted
to 'lie' (write-behind), but temporarily
holding off (because of insufficient
window capacity, etc.)
This is the list to look at to grow
the window (in __wb_pick_unwinds()).
Entries typically get chosen from
write-behind from this list, and therefore
get "upgraded" to the "liability" list.
*/
list_head_t wip; /* List of write calls in progress, SYNC or non-SYNC
which are currently STACK_WIND'ed towards the server.
This is for guaranteeing that no two overlapping
writes are in progress at the same time. Modules
like eager-lock in AFR depend on this behavior.
*/
uint64_t gen; /* Liability generation number. Represents
the current 'state' of liability. Every
new addition to the liability list bumps
the generation number.
a newly arrived request is only required
to perform causal checks against the entries
in the liability list which were present
at the time of its addition. the generation
number at the time of its addition is stored
in the request and used during checks.
the liability list can grow while the request
waits in the todo list waiting for its
dependent operations to complete. however
it is not of the request's concern to depend
itself on those new entries which arrived
after it arrived (i.e, those that have a
liability generation higher than itself)
*/
size_t size; /* Size of the file to catch write after EOF. */
gf_lock_t lock;
xlator_t *this;
int dontsync; /* If positive, dont pick lies for
* winding. This is needed to break infinite
* recursion during invocation of
* wb_process_queue from
* wb_fulfill_cbk in case of an
* error during fulfill.
*/
} wb_inode_t;
typedef struct wb_request {
list_head_t all;
list_head_t todo;
list_head_t lie; /* either in @liability or @temptation */
list_head_t winds;
list_head_t unwinds;
list_head_t wip;
call_stub_t *stub;
ssize_t write_size; /* currently held size
(after collapsing) */
size_t orig_size; /* size which arrived with the request.
This is the size by which we grow
the window when unwinding the frame.
*/
size_t total_size; /* valid only in @head in wb_fulfill().
This is the size with which we perform
STACK_WIND to server and therefore the
amount by which we shrink the window.
*/
int op_ret;
int op_errno;
int32_t refcount;
wb_inode_t *wb_inode;
glusterfs_fop_t fop;
gf_lkowner_t lk_owner;
pid_t client_pid;
struct iobref *iobref;
uint64_t gen; /* inode liability state at the time of
request arrival */
fd_t *fd;
int wind_count; /* number of sync-attempts. Only
for debug purposes */
struct {
size_t size; /* 0 size == till infinity */
off_t off;
int append:1; /* offset is invalid. only one
outstanding append at a time */
int tempted:1; /* true only for non-sync writes */
int lied:1; /* sin committed */
int fulfilled:1; /* got server acknowledgement */
int go:1; /* enough aggregating, good to go */
} ordering;
/* for debug purposes. A request might outlive the fop it is
* representing. So, preserve essential info for logging.
*/
uint64_t unique;
uuid_t gfid;
} wb_request_t;
typedef struct wb_conf {
uint64_t aggregate_size;
uint64_t page_size;
uint64_t window_size;
gf_boolean_t flush_behind;
gf_boolean_t trickling_writes;
gf_boolean_t strict_write_ordering;
gf_boolean_t strict_O_DIRECT;
gf_boolean_t resync_after_fsync;
} wb_conf_t;
void
wb_process_queue (wb_inode_t *wb_inode);
wb_inode_t *
__wb_inode_ctx_get (xlator_t *this, inode_t *inode)
{
uint64_t value = 0;
wb_inode_t *wb_inode = NULL;
__inode_ctx_get (inode, this, &value);
wb_inode = (wb_inode_t *)(unsigned long) value;
return wb_inode;
}
wb_inode_t *
wb_inode_ctx_get (xlator_t *this, inode_t *inode)
{
wb_inode_t *wb_inode = NULL;
GF_VALIDATE_OR_GOTO ("write-behind", this, out);
GF_VALIDATE_OR_GOTO (this->name, inode, out);
LOCK (&inode->lock);
{
wb_inode = __wb_inode_ctx_get (this, inode);
}
UNLOCK (&inode->lock);
out:
return wb_inode;
}
/*
Below is a succinct explanation of the code deciding whether two regions
overlap, from Pavan <tcp@gluster.com>.
For any two ranges to be non-overlapping, either the end of the first
range is lesser than the start of the second, or vice versa. Example -
<---------> <-------------->
p q x y
( q < x ) or (y < p) = > No overlap.
To check for *overlap*, we can negate this (using de morgan's laws), and
it becomes -
(q >= x ) and (y >= p)
Either that, or you write the negation using -
if (! ((q < x) or (y < p)) ) {
"Overlap"
}
*/
gf_boolean_t
wb_requests_overlap (wb_request_t *req1, wb_request_t *req2)
{
uint64_t r1_start = 0;
uint64_t r1_end = 0;
uint64_t r2_start = 0;
uint64_t r2_end = 0;
gf_boolean_t do_overlap = _gf_false;
r1_start = req1->ordering.off;
if (req1->ordering.size)
r1_end = r1_start + req1->ordering.size - 1;
else
r1_end = ULLONG_MAX;
r2_start = req2->ordering.off;
if (req2->ordering.size)
r2_end = r2_start + req2->ordering.size - 1;
else
r2_end = ULLONG_MAX;
do_overlap = ((r1_end >= r2_start) && (r2_end >= r1_start));
return do_overlap;
}
gf_boolean_t
wb_requests_conflict (wb_request_t *lie, wb_request_t *req)
{
wb_conf_t *conf = NULL;
conf = req->wb_inode->this->private;
if (lie == req)
/* request cannot conflict with itself */
return _gf_false;
if (lie->gen >= req->gen)
/* this liability entry was behind
us in the todo list */
return _gf_false;
/* requests from different fd do not conflict with each other. */
if (req->fd && (req->fd != lie->fd))
return _gf_false;
if (lie->ordering.append)
/* all modifications wait for the completion
of outstanding append */
return _gf_true;
if (conf->strict_write_ordering)
/* We are sure (lie->gen < req->gen) by now. So
skip overlap check if strict write ordering is
requested and always return "conflict" against a
lower generation lie. */
return _gf_true;
return wb_requests_overlap (lie, req);
}
wb_request_t *
wb_liability_has_conflict (wb_inode_t *wb_inode, wb_request_t *req)
{
wb_request_t *each = NULL;
list_for_each_entry (each, &wb_inode->liability, lie) {
if (wb_requests_conflict (each, req)
&& (!each->ordering.fulfilled))
/* A fulfilled request shouldn't block another
* request (even a dependent one) from winding.
*/
return each;
}
return NULL;
}
wb_request_t *
wb_wip_has_conflict (wb_inode_t *wb_inode, wb_request_t *req)
{
wb_request_t *each = NULL;
if (req->stub->fop != GF_FOP_WRITE)
/* non-writes fundamentally never conflict with WIP requests */
return NULL;
list_for_each_entry (each, &wb_inode->wip, wip) {
if (each == req)
/* request never conflicts with itself,
though this condition should never occur.
*/
continue;
if (wb_requests_overlap (each, req))
return each;
}
return NULL;
}
static int
__wb_request_unref (wb_request_t *req)
{
int ret = -1;
wb_inode_t *wb_inode = NULL;
char gfid[64] = {0, };
wb_inode = req->wb_inode;
if (req->refcount <= 0) {
uuid_utoa_r (req->gfid, gfid);
gf_msg ("wb-request", GF_LOG_WARNING,
0, WRITE_BEHIND_MSG_RES_UNAVAILABLE,
"(unique=%"PRIu64", fop=%s, gfid=%s, gen=%"PRIu64"): "
"refcount(%d) is <= 0 ",
req->unique, gf_fop_list[req->fop], gfid, req->gen,
req->refcount);
goto out;
}
ret = --req->refcount;
if (req->refcount == 0) {
uuid_utoa_r (req->gfid, gfid);
gf_log_callingfn (wb_inode->this->name, GF_LOG_DEBUG,
"(unique = %"PRIu64", fop=%s, gfid=%s, "
"gen=%"PRIu64"): destroying request, "
"removing from all queues", req->unique,
gf_fop_list[req->fop], gfid, req->gen);
list_del_init (&req->todo);
list_del_init (&req->lie);
list_del_init (&req->wip);
list_del_init (&req->all);
if (list_empty (&wb_inode->all)) {
wb_inode->gen = 0;
/* in case of accounting errors? */
wb_inode->window_current = 0;
}
list_del_init (&req->winds);
list_del_init (&req->unwinds);
if (req->stub) {
call_stub_destroy (req->stub);
req->stub = NULL;
}
if (req->iobref)
iobref_unref (req->iobref);
if (req->fd)
fd_unref (req->fd);
GF_FREE (req);
}
out:
return ret;
}
static int
wb_request_unref (wb_request_t *req)
{
wb_inode_t *wb_inode = NULL;
int ret = -1;
GF_VALIDATE_OR_GOTO ("write-behind", req, out);
wb_inode = req->wb_inode;
LOCK (&wb_inode->lock);
{
ret = __wb_request_unref (req);
}
UNLOCK (&wb_inode->lock);
out:
return ret;
}
static wb_request_t *
__wb_request_ref (wb_request_t *req)
{
GF_VALIDATE_OR_GOTO ("write-behind", req, out);
if (req->refcount < 0) {
gf_msg ("wb-request", GF_LOG_WARNING, 0,
WRITE_BEHIND_MSG_RES_UNAVAILABLE,
"refcount(%d) is < 0", req->refcount);
req = NULL;
goto out;
}
req->refcount++;
out:
return req;
}
wb_request_t *
wb_request_ref (wb_request_t *req)
{
wb_inode_t *wb_inode = NULL;
GF_VALIDATE_OR_GOTO ("write-behind", req, out);
wb_inode = req->wb_inode;
LOCK (&wb_inode->lock);
{
req = __wb_request_ref (req);
}
UNLOCK (&wb_inode->lock);
out:
return req;
}
gf_boolean_t
wb_enqueue_common (wb_inode_t *wb_inode, call_stub_t *stub, int tempted)
{
wb_request_t *req = NULL;
inode_t *inode = NULL;
GF_VALIDATE_OR_GOTO ("write-behind", wb_inode, out);
GF_VALIDATE_OR_GOTO (wb_inode->this->name, stub, out);
req = GF_CALLOC (1, sizeof (*req), gf_wb_mt_wb_request_t);
if (!req)
goto out;
INIT_LIST_HEAD (&req->all);
INIT_LIST_HEAD (&req->todo);
INIT_LIST_HEAD (&req->lie);
INIT_LIST_HEAD (&req->winds);
INIT_LIST_HEAD (&req->unwinds);
INIT_LIST_HEAD (&req->wip);
req->stub = stub;
req->wb_inode = wb_inode;
req->fop = stub->fop;
req->ordering.tempted = tempted;
req->unique = stub->frame->root->unique;
inode = ((stub->args.fd != NULL) ? stub->args.fd->inode
: stub->args.loc.inode);
if (inode)
gf_uuid_copy (req->gfid, inode->gfid);
if (stub->fop == GF_FOP_WRITE) {
req->write_size = iov_length (stub->args.vector,
stub->args.count);
/* req->write_size can change as we collapse
small writes. But the window needs to grow
only by how much we acknowledge the app. so
copy the original size in orig_size for the
purpose of accounting.
*/
req->orig_size = req->write_size;
/* Let's be optimistic that we can
lie about it
*/
req->op_ret = req->write_size;
req->op_errno = 0;
if (stub->args.fd->flags & O_APPEND)
req->ordering.append = 1;
}
req->lk_owner = stub->frame->root->lk_owner;
req->client_pid = stub->frame->root->pid;
switch (stub->fop) {
case GF_FOP_WRITE:
LOCK (&wb_inode->lock);
{
if (wb_inode->size < stub->args.offset) {
req->ordering.off = wb_inode->size;
req->ordering.size = stub->args.offset
+ req->write_size
- wb_inode->size;
} else {
req->ordering.off = stub->args.offset;
req->ordering.size = req->write_size;
}
if (wb_inode->size < stub->args.offset + req->write_size)
wb_inode->size = stub->args.offset
+ req->write_size;
}
UNLOCK (&wb_inode->lock);
req->fd = fd_ref (stub->args.fd);
break;
case GF_FOP_READ:
req->ordering.off = stub->args.offset;
req->ordering.size = stub->args.size;
req->fd = fd_ref (stub->args.fd);
break;
case GF_FOP_TRUNCATE:
req->ordering.off = stub->args.offset;
req->ordering.size = 0; /* till infinity */
LOCK (&wb_inode->lock);
{
wb_inode->size = req->ordering.off;
}
UNLOCK (&wb_inode->lock);
break;
case GF_FOP_FTRUNCATE:
req->ordering.off = stub->args.offset;
req->ordering.size = 0; /* till infinity */
LOCK (&wb_inode->lock);
{
wb_inode->size = req->ordering.off;
}
UNLOCK (&wb_inode->lock);
req->fd = fd_ref (stub->args.fd);
break;
default:
if (stub && stub->args.fd)
req->fd = fd_ref (stub->args.fd);
break;
}
LOCK (&wb_inode->lock);
{
list_add_tail (&req->all, &wb_inode->all);
req->gen = wb_inode->gen;
list_add_tail (&req->todo, &wb_inode->todo);
__wb_request_ref (req); /* for wind */
if (req->ordering.tempted) {
list_add_tail (&req->lie, &wb_inode->temptation);
__wb_request_ref (req); /* for unwind */
}
}
UNLOCK (&wb_inode->lock);
out:
if (!req)
return _gf_false;
return _gf_true;
}
gf_boolean_t
wb_enqueue (wb_inode_t *wb_inode, call_stub_t *stub)
{
return wb_enqueue_common (wb_inode, stub, 0);
}
gf_boolean_t
wb_enqueue_tempted (wb_inode_t *wb_inode, call_stub_t *stub)
{
return wb_enqueue_common (wb_inode, stub, 1);
}
wb_inode_t *
__wb_inode_create (xlator_t *this, inode_t *inode)
{
wb_inode_t *wb_inode = NULL;
wb_conf_t *conf = NULL;
int ret = 0;
GF_VALIDATE_OR_GOTO (this->name, inode, out);
conf = this->private;
wb_inode = GF_CALLOC (1, sizeof (*wb_inode), gf_wb_mt_wb_inode_t);
if (!wb_inode)
goto out;
INIT_LIST_HEAD (&wb_inode->all);
INIT_LIST_HEAD (&wb_inode->todo);
INIT_LIST_HEAD (&wb_inode->liability);
INIT_LIST_HEAD (&wb_inode->temptation);
INIT_LIST_HEAD (&wb_inode->wip);
wb_inode->this = this;
wb_inode->window_conf = conf->window_size;
LOCK_INIT (&wb_inode->lock);
ret = __inode_ctx_put (inode, this, (uint64_t)(unsigned long)wb_inode);
if (ret) {
GF_FREE (wb_inode);
wb_inode = NULL;
}
out:
return wb_inode;
}
wb_inode_t *
wb_inode_create (xlator_t *this, inode_t *inode)
{
wb_inode_t *wb_inode = NULL;
GF_VALIDATE_OR_GOTO (this->name, inode, out);
LOCK (&inode->lock);
{
wb_inode = __wb_inode_ctx_get (this, inode);
if (!wb_inode)
wb_inode = __wb_inode_create (this, inode);
}
UNLOCK (&inode->lock);
out:
return wb_inode;
}
void
wb_inode_destroy (wb_inode_t *wb_inode)
{
GF_VALIDATE_OR_GOTO ("write-behind", wb_inode, out);
LOCK_DESTROY (&wb_inode->lock);
GF_FREE (wb_inode);
out:
return;
}
void
__wb_fulfill_request (wb_request_t *req)
{
wb_inode_t *wb_inode = NULL;
char gfid[64] = {0, };
wb_inode = req->wb_inode;
req->ordering.fulfilled = 1;
wb_inode->window_current -= req->total_size;
wb_inode->transit -= req->total_size;
uuid_utoa_r (req->gfid, gfid);
gf_log_callingfn (wb_inode->this->name, GF_LOG_DEBUG,
"(unique=%"PRIu64", fop=%s, gfid=%s, "
"gen=%"PRIu64"): request fulfilled. "
"removing the request from liability queue? = %s",
req->unique, gf_fop_list[req->fop], gfid, req->gen,
req->ordering.lied ? "yes" : "no");
if (req->ordering.lied) {
/* 1. If yes, request is in liability queue and hence can be
safely removed from list.
2. If no, request is in temptation queue and hence should be
left in the queue so that wb_pick_unwinds picks it up
*/
list_del_init (&req->lie);
} else {
/* TODO: fail the req->frame with error if
necessary
*/
}
__wb_request_unref (req);
}
/* get a flush/fsync waiting on req */
wb_request_t *
__wb_request_waiting_on (wb_request_t *req)
{
wb_inode_t *wb_inode = NULL;
wb_request_t *trav = NULL;
wb_inode = req->wb_inode;
list_for_each_entry (trav, &wb_inode->todo, todo) {
if ((trav->fd == req->fd)
&& ((trav->stub->fop == GF_FOP_FLUSH)
|| (trav->stub->fop == GF_FOP_FSYNC))
&& (trav->gen >= req->gen))
return trav;
}
return NULL;
}
void
__wb_add_request_for_retry (wb_request_t *req)
{
wb_inode_t *wb_inode = NULL;
if (!req)
goto out;
wb_inode = req->wb_inode;
/* response was unwound and no waiter waiting on this request, retry
till a flush or fsync (subject to conf->resync_after_fsync).
*/
wb_inode->transit -= req->total_size;
req->total_size = 0;
list_del_init (&req->winds);
list_del_init (&req->todo);
list_del_init (&req->wip);
/* sanitize ordering flags to retry */
req->ordering.go = 0;
/* Add back to todo list to retry */
list_add (&req->todo, &wb_inode->todo);
out:
return;
}
void
__wb_add_head_for_retry (wb_request_t *head)
{
wb_request_t *req = NULL, *tmp = NULL;
if (!head)
goto out;
list_for_each_entry_safe_reverse (req, tmp, &head->winds,
winds) {
__wb_add_request_for_retry (req);
}
__wb_add_request_for_retry (head);
out:
return;
}
void
wb_add_head_for_retry (wb_request_t *head)
{
if (!head)
goto out;
LOCK (&head->wb_inode->lock);
{
__wb_add_head_for_retry (head);
}
UNLOCK (&head->wb_inode->lock);
out:
return;
}
void
__wb_fulfill_request_err (wb_request_t *req, int32_t op_errno)
{
wb_inode_t *wb_inode = NULL;
wb_request_t *waiter = NULL;
wb_conf_t *conf = NULL;
wb_inode = req->wb_inode;
conf = wb_inode->this->private;
req->op_ret = -1;
req->op_errno = op_errno;
if (req->ordering.lied)
waiter = __wb_request_waiting_on (req);
if (!req->ordering.lied || waiter) {
if (!req->ordering.lied) {
/* response to app is still pending, send failure in
* response.
*/
} else {
/* response was sent, store the error in a
* waiter (either an fsync or flush).
*/
waiter->op_ret = -1;
waiter->op_errno = op_errno;
}
if (!req->ordering.lied
|| (waiter->stub->fop == GF_FOP_FLUSH)
|| ((waiter->stub->fop == GF_FOP_FSYNC)
&& !conf->resync_after_fsync)) {
/* No retry needed, forget the request */
__wb_fulfill_request (req);
return;
}
}
__wb_add_request_for_retry (req);
return;
}
void
wb_head_done (wb_request_t *head)
{
wb_request_t *req = NULL;
wb_request_t *tmp = NULL;
wb_inode_t *wb_inode = NULL;
wb_inode = head->wb_inode;
LOCK (&wb_inode->lock);
{
list_for_each_entry_safe (req, tmp, &head->winds, winds) {
__wb_fulfill_request (req);
}
__wb_fulfill_request (head);
}
UNLOCK (&wb_inode->lock);
}
void
__wb_fulfill_err (wb_request_t *head, int op_errno)
{
wb_request_t *req = NULL, *tmp = NULL;
if (!head)
goto out;
head->wb_inode->dontsync++;
list_for_each_entry_safe_reverse (req, tmp, &head->winds,
winds) {
__wb_fulfill_request_err (req, op_errno);
}
__wb_fulfill_request_err (head, op_errno);
out:
return;
}
void
wb_fulfill_err (wb_request_t *head, int op_errno)
{
wb_inode_t *wb_inode = NULL;
wb_inode = head->wb_inode;
LOCK (&wb_inode->lock);
{
__wb_fulfill_err (head, op_errno);
}
UNLOCK (&wb_inode->lock);
}
void
__wb_modify_write_request (wb_request_t *req, int synced_size)
{
struct iovec *vector = NULL;
int count = 0;
if (!req || synced_size == 0)
goto out;
req->write_size -= synced_size;
req->stub->args.offset += synced_size;
vector = req->stub->args.vector;
count = req->stub->args.count;
req->stub->args.count = iov_subset (vector, count, synced_size,
iov_length (vector, count), vector);
out:
return;
}
int
__wb_fulfill_short_write (wb_request_t *req, int size, gf_boolean_t *fulfilled)
{
int accounted_size = 0;
if (req == NULL)
goto out;
if (req->write_size <= size) {
accounted_size = req->write_size;
__wb_fulfill_request (req);
*fulfilled = 1;
} else {
accounted_size = size;
__wb_modify_write_request (req, size);
*fulfilled = 0;
}
out:
return accounted_size;
}
void
wb_fulfill_short_write (wb_request_t *head, int size)
{
wb_inode_t *wb_inode = NULL;
wb_request_t *req = NULL, *next = NULL;
int accounted_size = 0;
gf_boolean_t fulfilled = _gf_false;
if (!head)
goto out;
wb_inode = head->wb_inode;
req = head;
LOCK (&wb_inode->lock);
{
/* hold a reference to head so that __wb_fulfill_short_write
* won't free it. We need head for a cleaner list traversal as
* list_for_each_entry_safe doesn't iterate over "head" member.
* So, if we pass "next->winds" as head to list_for_each_entry,
* "next" is skipped. For a simpler logic we need to traverse
* the list in the order. So, we start traversal from
* "head->winds" and hence we want head to be alive.
*/
__wb_request_ref (head);
next = list_entry (head->winds.next, wb_request_t, winds);
accounted_size = __wb_fulfill_short_write (head, size,
&fulfilled);
size -= accounted_size;
if (size == 0) {
if (fulfilled && (next != head))
req = next;
goto done;
}
list_for_each_entry_safe (req, next, &head->winds, winds) {
accounted_size = __wb_fulfill_short_write (req, size,
&fulfilled);
size -= accounted_size;
if (size == 0) {
if (fulfilled && (next != head))
req = next;
break;
}
}
done:
__wb_request_unref (head);
}
UNLOCK (&wb_inode->lock);
wb_add_head_for_retry (req);
out:
return;
}
int
wb_fulfill_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
struct iatt *postbuf, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
wb_request_t *head = NULL;
head = frame->local;
frame->local = NULL;
wb_inode = head->wb_inode;
if (op_ret == -1) {
wb_fulfill_err (head, op_errno);
} else if (op_ret < head->total_size) {
wb_fulfill_short_write (head, op_ret);
} else {
wb_head_done (head);
}
wb_process_queue (wb_inode);
STACK_DESTROY (frame->root);
return 0;
}
#define WB_IOV_LOAD(vec, cnt, req, head) do { \
memcpy (&vec[cnt], req->stub->args.vector, \
(req->stub->args.count * sizeof(vec[0]))); \
cnt += req->stub->args.count; \
head->total_size += req->write_size; \
} while (0)
int
wb_fulfill_head (wb_inode_t *wb_inode, wb_request_t *head)
{
struct iovec vector[MAX_VECTOR_COUNT];
int count = 0;
wb_request_t *req = NULL;
call_frame_t *frame = NULL;
/* make sure head->total_size is updated before we run into any
* errors
*/
WB_IOV_LOAD (vector, count, head, head);
list_for_each_entry (req, &head->winds, winds) {
WB_IOV_LOAD (vector, count, req, head);
if (iobref_merge (head->stub->args.iobref,
req->stub->args.iobref))
goto err;
}
frame = create_frame (wb_inode->this, wb_inode->this->ctx->pool);
if (!frame)
goto err;
frame->root->lk_owner = head->lk_owner;
frame->root->pid = head->client_pid;
frame->local = head;
LOCK (&wb_inode->lock);
{
wb_inode->transit += head->total_size;
}
UNLOCK (&wb_inode->lock);
STACK_WIND (frame, wb_fulfill_cbk, FIRST_CHILD (frame->this),
FIRST_CHILD (frame->this)->fops->writev,
head->fd, vector, count,
head->stub->args.offset,
head->stub->args.flags,
head->stub->args.iobref, NULL);
return 0;
err:
/* frame creation failure */
wb_fulfill_err (head, ENOMEM);
return ENOMEM;
}
#define NEXT_HEAD(head, req) do { \
if (head) \
ret |= wb_fulfill_head (wb_inode, head); \
head = req; \
expected_offset = req->stub->args.offset + \
req->write_size; \
curr_aggregate = 0; \
vector_count = 0; \
} while (0)
int
wb_fulfill (wb_inode_t *wb_inode, list_head_t *liabilities)
{
wb_request_t *req = NULL;
wb_request_t *head = NULL;
wb_request_t *tmp = NULL;
wb_conf_t *conf = NULL;
off_t expected_offset = 0;
size_t curr_aggregate = 0;
size_t vector_count = 0;
int ret = 0;
conf = wb_inode->this->private;
list_for_each_entry_safe (req, tmp, liabilities, winds) {
list_del_init (&req->winds);
if (!head) {
NEXT_HEAD (head, req);
continue;
}
if (req->fd != head->fd) {
NEXT_HEAD (head, req);
continue;
}
if (!is_same_lkowner (&req->lk_owner, &head->lk_owner)) {
NEXT_HEAD (head, req);
continue;
}
if (expected_offset != req->stub->args.offset) {
NEXT_HEAD (head, req);
continue;
}
if ((curr_aggregate + req->write_size) > conf->aggregate_size) {
NEXT_HEAD (head, req);
continue;
}
if (vector_count + req->stub->args.count >
MAX_VECTOR_COUNT) {
NEXT_HEAD (head, req);
continue;
}
list_add_tail (&req->winds, &head->winds);
curr_aggregate += req->write_size;
vector_count += req->stub->args.count;
}
if (head)
ret |= wb_fulfill_head (wb_inode, head);
return ret;
}
void
wb_do_unwinds (wb_inode_t *wb_inode, list_head_t *lies)
{
wb_request_t *req = NULL;
wb_request_t *tmp = NULL;
call_frame_t *frame = NULL;
struct iatt buf = {0, };
list_for_each_entry_safe (req, tmp, lies, unwinds) {
frame = req->stub->frame;
STACK_UNWIND_STRICT (writev, frame, req->op_ret, req->op_errno,
&buf, &buf, NULL); /* :O */
req->stub->frame = NULL;
list_del_init (&req->unwinds);
wb_request_unref (req);
}
return;
}
void
__wb_pick_unwinds (wb_inode_t *wb_inode, list_head_t *lies)
{
wb_request_t *req = NULL;
wb_request_t *tmp = NULL;
char gfid[64] = {0,};
list_for_each_entry_safe (req, tmp, &wb_inode->temptation, lie) {
if (!req->ordering.fulfilled &&
wb_inode->window_current > wb_inode->window_conf)
continue;
list_del_init (&req->lie);
list_move_tail (&req->unwinds, lies);
wb_inode->window_current += req->orig_size;
if (!req->ordering.fulfilled) {
/* burden increased */
list_add_tail (&req->lie, &wb_inode->liability);
req->ordering.lied = 1;
wb_inode->gen++;
uuid_utoa_r (req->gfid, gfid);
gf_msg_debug (wb_inode->this->name, 0,
"(unique=%"PRIu64", fop=%s, gfid=%s, "
"gen=%"PRIu64"): added req to liability "
"queue. inode-generation-number=%"PRIu64,
req->stub->frame->root->unique,
gf_fop_list[req->fop], gfid, req->gen,
wb_inode->gen);
}
}
return;
}
int
__wb_collapse_small_writes (wb_conf_t *conf, wb_request_t *holder, wb_request_t *req)
{
char *ptr = NULL;
struct iobuf *iobuf = NULL;
struct iobref *iobref = NULL;
int ret = -1;
ssize_t required_size = 0;
size_t holder_len = 0;
size_t req_len = 0;
if (!holder->iobref) {
holder_len = iov_length (holder->stub->args.vector,
holder->stub->args.count);
req_len = iov_length (req->stub->args.vector,
req->stub->args.count);
required_size = max ((conf->page_size),
(holder_len + req_len));
iobuf = iobuf_get2 (req->wb_inode->this->ctx->iobuf_pool,
required_size);
if (iobuf == NULL) {
goto out;
}
iobref = iobref_new ();
if (iobref == NULL) {
iobuf_unref (iobuf);
goto out;
}
ret = iobref_add (iobref, iobuf);
if (ret != 0) {
gf_msg (req->wb_inode->this->name, GF_LOG_WARNING,
-ret, WRITE_BEHIND_MSG_INVALID_ARGUMENT,
"cannot add iobuf (%p) into iobref (%p)",
iobuf, iobref);
iobuf_unref (iobuf);
iobref_unref (iobref);
goto out;
}
iov_unload (iobuf->ptr, holder->stub->args.vector,
holder->stub->args.count);
holder->stub->args.vector[0].iov_base = iobuf->ptr;
holder->stub->args.count = 1;
iobref_unref (holder->stub->args.iobref);
holder->stub->args.iobref = iobref;
iobuf_unref (iobuf);
holder->iobref = iobref_ref (iobref);
}
ptr = holder->stub->args.vector[0].iov_base + holder->write_size;
iov_unload (ptr, req->stub->args.vector,
req->stub->args.count);
holder->stub->args.vector[0].iov_len += req->write_size;
holder->write_size += req->write_size;
holder->ordering.size += req->write_size;
ret = 0;
out:
return ret;
}
void
__wb_preprocess_winds (wb_inode_t *wb_inode)
{
off_t offset_expected = 0;
ssize_t space_left = 0;
wb_request_t *req = NULL;
wb_request_t *tmp = NULL;
wb_request_t *holder = NULL;
wb_conf_t *conf = NULL;
int ret = 0;
ssize_t page_size = 0;
char gfid[64] = {0, };
/* With asynchronous IO from a VM guest (as a file), there
can be two sequential writes happening in two regions
of the file. But individual (broken down) IO requests
can arrive interleaved.
TODO: cycle for each such sequence sifting
through the interleaved ops
*/
conf = wb_inode->this->private;
page_size = conf->page_size;
list_for_each_entry_safe (req, tmp, &wb_inode->todo, todo) {
if (wb_inode->dontsync && req->ordering.lied) {
/* sync has failed. Don't pick lies _again_ for winding
* as winding these lies again will trigger an infinite
* recursion of wb_process_queue being called from a
* failed fulfill. However, pick non-lied requests for
* winding so that application wont block indefinitely
* waiting for write result.
*/
uuid_utoa_r (req->gfid, gfid);
gf_msg_debug (wb_inode->this->name, 0,
"(unique=%"PRIu64", fop=%s, gfid=%s, "
"gen=%"PRIu64"): not setting ordering.go"
"as dontsync is set", req->unique,
gf_fop_list[req->fop], gfid, req->gen);
continue;
}
if (!req->ordering.tempted) {
if (holder) {
if (wb_requests_conflict (holder, req))
/* do not hold on write if a
dependent write is in queue */
holder->ordering.go = 1;
}
/* collapse only non-sync writes */
continue;
} else if (!holder) {
/* holder is always a non-sync write */
holder = req;
continue;
}
offset_expected = holder->stub->args.offset
+ holder->write_size;
if (req->stub->args.offset != offset_expected) {
holder->ordering.go = 1;
holder = req;
continue;
}
if (!is_same_lkowner (&req->lk_owner, &holder->lk_owner)) {
holder->ordering.go = 1;
holder = req;
continue;
}
if (req->fd != holder->fd) {
holder->ordering.go = 1;
holder = req;
continue;
}
space_left = page_size - holder->write_size;
if (space_left < req->write_size) {
holder->ordering.go = 1;
holder = req;
continue;
}
ret = __wb_collapse_small_writes (conf, holder, req);
if (ret)
continue;
/* collapsed request is as good as wound
(from its p.o.v)
*/
list_del_init (&req->todo);
__wb_fulfill_request (req);
/* Only the last @holder in queue which
- does not have any non-buffered-writes following it
- has not yet filled its capacity
does not get its 'go' set, in anticipation of the arrival
of consecutive smaller writes.
*/
}
/* but if trickling writes are enabled, then do not hold back
writes if there are no outstanding requests
*/
if (conf->trickling_writes && !wb_inode->transit && holder)
holder->ordering.go = 1;
if (wb_inode->dontsync > 0)
wb_inode->dontsync--;
return;
}
int
__wb_handle_failed_conflict (wb_request_t *req, wb_request_t *conflict,
list_head_t *tasks)
{
wb_conf_t *conf = NULL;
char gfid[64] = {0, };
conf = req->wb_inode->this->private;
uuid_utoa_r (req->gfid, gfid);
if ((req->stub->fop != GF_FOP_FLUSH)
&& ((req->stub->fop != GF_FOP_FSYNC) || conf->resync_after_fsync)) {
if (!req->ordering.lied && list_empty (&conflict->wip)) {
/* If request itself is in liability queue,
* 1. We cannot unwind as the response has already been
* sent.
* 2. We cannot wind till conflict clears up.
* 3. So, skip the request for now.
* 4. Otherwise, resume (unwind) it with error.
*/
req->op_ret = -1;
req->op_errno = conflict->op_errno;
list_del_init (&req->todo);
list_add_tail (&req->winds, tasks);
gf_msg_debug (req->wb_inode->this->name, 0,
"(unique=%"PRIu64", fop=%s, gfid=%s, "
"gen=%"PRIu64"): A conflicting write "
"request in liability queue has failed "
"to sync (error = \"%s\"), "
"unwinding this request as a failure",
req->unique, gf_fop_list[req->fop], gfid,
req->gen, strerror (req->op_errno));
if (req->ordering.tempted) {
/* make sure that it won't be unwound in
* wb_do_unwinds too. Otherwise there'll be
* a double wind.
*/
list_del_init (&req->lie);
gf_msg_debug (req->wb_inode->this->name, 0,
"(unique=%"PRIu64", fop=%s, "
"gfid=%s, gen=%"PRIu64"): "
"removed from liability queue",
req->unique,
gf_fop_list[req->fop], gfid,
req->gen);
__wb_fulfill_request (req);
}
}
} else {
gf_msg_debug (req->wb_inode->this->name, 0,
"(unique=%"PRIu64", fop=%s, gfid=%s, "
"gen=%"PRIu64"): A conflicting write request "
"in liability queue has failed to sync "
"(error = \"%s\"). This is an "
"FSYNC/FLUSH and we need to maintain ordering "
"guarantees with other writes in TODO queue. "
"Hence doing nothing now", req->unique,
gf_fop_list[req->fop], gfid, req->gen,
strerror (conflict->op_errno));
/* flush and fsync (without conf->resync_after_fsync) act as
barriers. We cannot unwind them out of
order, when there are earlier generation writes just because
there is a conflicting liability with an error. So, wait for
our turn till there are no conflicting liabilities.
This situation can arise when there liabilities spread across
multiple generations. For eg., consider two writes with
following characterstics:
1. they belong to different generations gen1, gen2 and
(gen1 > gen2).
2. they overlap.
3. both are liabilities.
4. gen1 write was attempted to sync, but the attempt failed.
5. there was no attempt to sync gen2 write yet.
6. A flush (as part of close) is issued and gets a gen no
gen3.
In the above scenario, if flush is unwound without waiting
for gen1 and gen2 writes either to be successfully synced or
purged, we end up with these two writes in wb_inode->todo
list forever as there will be no attempt to process the queue
as flush is the last operation.
*/
}
return 0;
}
int
__wb_pick_winds (wb_inode_t *wb_inode, list_head_t *tasks,
list_head_t *liabilities)
{
wb_request_t *req = NULL;
wb_request_t *tmp = NULL;
wb_request_t *conflict = NULL;
char req_gfid[64] = {0, }, conflict_gfid[64] = {0, };
list_for_each_entry_safe (req, tmp, &wb_inode->todo, todo) {
uuid_utoa_r (req->gfid, req_gfid);
conflict = wb_liability_has_conflict (wb_inode, req);
if (conflict) {
uuid_utoa_r (conflict->gfid, conflict_gfid);
gf_msg_debug (wb_inode->this->name, 0,
"Not winding request due to a "
"conflicting write in liability queue. "
"REQ: unique=%"PRIu64", fop=%s, "
"gen=%"PRIu64", gfid=%s. "
"CONFLICT: unique=%"PRIu64", fop=%s, "
"gen=%"PRIu64", gfid=%s, "
"conflicts-sync-failed?=%s, "
"conflicts-error=%s",
req->unique, gf_fop_list[req->fop],
req->gen, req_gfid,
conflict->unique,
gf_fop_list[conflict->fop], conflict->gen,
conflict_gfid,
(conflict->op_ret == 1) ? "yes" : "no",
strerror (conflict->op_errno));
if (conflict->op_ret == -1) {
/* There is a conflicting liability which failed
* to sync in previous attempts, resume the req
* and fail, unless its an fsync/flush.
*/
__wb_handle_failed_conflict (req, conflict,
tasks);
} else {
/* There is a conflicting liability which was
* not attempted to sync even once. Wait till
* atleast one attempt to sync is made.
*/
}
continue;
}
if (req->ordering.tempted && !req->ordering.go) {
/* wait some more */
gf_msg_debug (wb_inode->this->name, 0,
"(unique=%"PRIu64", fop=%s, gen=%"PRIu64
", gfid=%s): ordering.go is not set, "
"hence not winding", req->unique,
gf_fop_list[req->fop], req->gen,
req_gfid);
continue;
}
if (req->stub->fop == GF_FOP_WRITE) {
conflict = wb_wip_has_conflict (wb_inode, req);
if (conflict) {
uuid_utoa_r (conflict->gfid, conflict_gfid);
gf_msg_debug (wb_inode->this->name, 0,
"Not winding write request as "
"a conflicting write is being "
"synced to backend. "
"REQ: unique=%"PRIu64" fop=%s,"
" gen=%"PRIu64", gfid=%s. "
"CONFLICT: unique=%"PRIu64" "
"fop=%s, gen=%"PRIu64", "
"gfid=%s",
req->unique,
gf_fop_list[req->fop],
req->gen, req_gfid,
conflict->unique,
gf_fop_list[conflict->fop],
conflict->gen, conflict_gfid);
continue;
}
list_add_tail (&req->wip, &wb_inode->wip);
req->wind_count++;
if (!req->ordering.tempted)
/* unrefed in wb_writev_cbk */
req->stub->frame->local =
__wb_request_ref (req);
}
gf_msg_debug (wb_inode->this->name, 0,
"(unique=%"PRIu64", fop=%s, gfid=%s, "
"gen=%"PRIu64"): picking the request for "
"winding", req->unique, gf_fop_list[req->fop],
req_gfid, req->gen);
list_del_init (&req->todo);
if (req->ordering.tempted) {
list_add_tail (&req->winds, liabilities);
} else {
list_add_tail (&req->winds, tasks);
}
}
return 0;
}
void
wb_do_winds (wb_inode_t *wb_inode, list_head_t *tasks)
{
wb_request_t *req = NULL;
wb_request_t *tmp = NULL;
list_for_each_entry_safe (req, tmp, tasks, winds) {
list_del_init (&req->winds);
if (req->op_ret == -1) {
call_unwind_error_keep_stub (req->stub, req->op_ret,
req->op_errno);
} else {
call_resume_keep_stub (req->stub);
}
wb_request_unref (req);
}
}
void
wb_process_queue (wb_inode_t *wb_inode)
{
list_head_t tasks = {0, };
list_head_t lies = {0, };
list_head_t liabilities = {0, };
int wind_failure = 0;
INIT_LIST_HEAD (&tasks);
INIT_LIST_HEAD (&lies);
INIT_LIST_HEAD (&liabilities);
do {
gf_log_callingfn (wb_inode->this->name, GF_LOG_DEBUG,
"processing queues");
LOCK (&wb_inode->lock);
{
__wb_preprocess_winds (wb_inode);
__wb_pick_winds (wb_inode, &tasks, &liabilities);
__wb_pick_unwinds (wb_inode, &lies);
}
UNLOCK (&wb_inode->lock);
wb_do_unwinds (wb_inode, &lies);
wb_do_winds (wb_inode, &tasks);
/* If there is an error in wb_fulfill before winding write
* requests, we would miss invocation of wb_process_queue
* from wb_fulfill_cbk. So, retry processing again.
*/
wind_failure = wb_fulfill (wb_inode, &liabilities);
} while (wind_failure);
return;
}
void
wb_set_inode_size(wb_inode_t *wb_inode, struct iatt *postbuf)
{
GF_ASSERT (wb_inode);
GF_ASSERT (postbuf);
LOCK (&wb_inode->lock);
{
wb_inode->size = postbuf->ia_size;
}
UNLOCK (&wb_inode->lock);
}
int
wb_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata)
{
wb_request_t *req = NULL;
wb_inode_t *wb_inode;
req = frame->local;
frame->local = NULL;
wb_inode = req->wb_inode;
wb_request_unref (req);
/* requests could be pending while this was in progress */
wb_process_queue(wb_inode);
STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf,
xdata);
return 0;
}
int
wb_writev_helper (call_frame_t *frame, xlator_t *this, fd_t *fd,
struct iovec *vector, int32_t count, off_t offset,
uint32_t flags, struct iobref *iobref, dict_t *xdata)
{
STACK_WIND (frame, wb_writev_cbk,
FIRST_CHILD (this), FIRST_CHILD (this)->fops->writev,
fd, vector, count, offset, flags, iobref, xdata);
return 0;
}
int
wb_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector,
int32_t count, off_t offset, uint32_t flags, struct iobref *iobref,
dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
wb_conf_t *conf = NULL;
gf_boolean_t wb_disabled = 0;
call_stub_t *stub = NULL;
int ret = -1;
int32_t op_errno = EINVAL;
int o_direct = O_DIRECT;
conf = this->private;
wb_inode = wb_inode_create (this, fd->inode);
if (!wb_inode) {
op_errno = ENOMEM;
goto unwind;
}
if (!conf->strict_O_DIRECT)
o_direct = 0;
if (fd->flags & (O_SYNC|O_DSYNC|o_direct))
wb_disabled = 1;
if (flags & (O_SYNC|O_DSYNC|o_direct))
wb_disabled = 1;
if (wb_disabled)
stub = fop_writev_stub (frame, wb_writev_helper, fd, vector,
count, offset, flags, iobref, xdata);
else
stub = fop_writev_stub (frame, NULL, fd, vector, count, offset,
flags, iobref, xdata);
if (!stub) {
op_errno = ENOMEM;
goto unwind;
}
if (wb_disabled)
ret = wb_enqueue (wb_inode, stub);
else
ret = wb_enqueue_tempted (wb_inode, stub);
if (!ret) {
op_errno = ENOMEM;
goto unwind;
}
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
}
int
wb_readv_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
off_t offset, uint32_t flags, dict_t *xdata)
{
STACK_WIND (frame, default_readv_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->readv, fd, size, offset, flags,
xdata);
return 0;
}
int
wb_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
off_t offset, uint32_t flags, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_readv_stub (frame, wb_readv_helper, fd, size,
offset, flags, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (readv, frame, -1, ENOMEM, NULL, 0, NULL, NULL,
NULL);
return 0;
noqueue:
STACK_WIND (frame, default_readv_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->readv, fd, size, offset, flags,
xdata);
return 0;
}
int
wb_flush_bg_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
STACK_DESTROY (frame->root);
return 0;
}
int
wb_flush_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
wb_conf_t *conf = NULL;
wb_inode_t *wb_inode = NULL;
call_frame_t *bg_frame = NULL;
int32_t op_errno = 0;
int op_ret = 0;
conf = this->private;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode) {
op_ret = -1;
op_errno = EINVAL;
goto unwind;
}
if (conf->flush_behind)
goto flushbehind;
STACK_WIND (frame, default_flush_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->flush, fd, xdata);
return 0;
flushbehind:
bg_frame = copy_frame (frame);
if (!bg_frame) {
op_ret = -1;
op_errno = ENOMEM;
goto unwind;
}
STACK_WIND (bg_frame, wb_flush_bg_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->flush, fd, xdata);
/* fall through */
unwind:
STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno, NULL);
return 0;
}
int
wb_flush (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_flush_stub (frame, wb_flush_helper, fd, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (flush, frame, -1, ENOMEM, NULL);
return 0;
noqueue:
STACK_WIND (frame, default_flush_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->flush, fd, xdata);
return 0;
}
int
wb_fsync_helper (call_frame_t *frame, xlator_t *this, fd_t *fd,
int32_t datasync, dict_t *xdata)
{
STACK_WIND (frame, default_fsync_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fsync, fd, datasync, xdata);
return 0;
}
int
wb_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t datasync,
dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
int32_t op_errno = EINVAL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_fsync_stub (frame, wb_fsync_helper, fd, datasync, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (fsync, frame, -1, op_errno, NULL, NULL, NULL);
return 0;
noqueue:
STACK_WIND (frame, default_fsync_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fsync, fd, datasync, xdata);
return 0;
}
int
wb_stat_helper (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
STACK_WIND (frame, default_stat_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->stat, loc, xdata);
return 0;
}
int
wb_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, loc->inode);
if (!wb_inode)
goto noqueue;
stub = fop_stat_stub (frame, wb_stat_helper, loc, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (stat, frame, -1, ENOMEM, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
noqueue:
STACK_WIND (frame, default_stat_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->stat, loc, xdata);
return 0;
}
int
wb_fstat_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
STACK_WIND (frame, default_fstat_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fstat, fd, xdata);
return 0;
}
int
wb_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_fstat_stub (frame, wb_fstat_helper, fd, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (fstat, frame, -1, ENOMEM, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
noqueue:
STACK_WIND (frame, default_fstat_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fstat, fd, xdata);
return 0;
}
int32_t
wb_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
struct iatt *postbuf, dict_t *xdata)
{
GF_ASSERT (frame->local);
if (op_ret == 0)
wb_set_inode_size (frame->local, postbuf);
frame->local = NULL;
STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, prebuf,
postbuf, xdata);
return 0;
}
int
wb_truncate_helper (call_frame_t *frame, xlator_t *this, loc_t *loc,
off_t offset, dict_t *xdata)
{
STACK_WIND (frame, wb_truncate_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->truncate, loc, offset, xdata);
return 0;
}
int
wb_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_create (this, loc->inode);
if (!wb_inode)
goto unwind;
frame->local = wb_inode;
stub = fop_truncate_stub (frame, wb_truncate_helper, loc,
offset, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (truncate, frame, -1, ENOMEM, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
}
int32_t
wb_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
struct iatt *postbuf, dict_t *xdata)
{
GF_ASSERT (frame->local);
if (op_ret == 0)
wb_set_inode_size (frame->local, postbuf);
frame->local = NULL;
STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf,
postbuf, xdata);
return 0;
}
int
wb_ftruncate_helper (call_frame_t *frame, xlator_t *this, fd_t *fd,
off_t offset, dict_t *xdata)
{
STACK_WIND (frame, wb_ftruncate_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
return 0;
}
int
wb_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
int32_t op_errno = 0;
wb_inode = wb_inode_create (this, fd->inode);
if (!wb_inode) {
op_errno = ENOMEM;
goto unwind;
}
frame->local = wb_inode;
stub = fop_ftruncate_stub (frame, wb_ftruncate_helper, fd,
offset, xdata);
if (!stub) {
op_errno = ENOMEM;
goto unwind;
}
if (!wb_enqueue (wb_inode, stub)) {
op_errno = ENOMEM;
goto unwind;
}
wb_process_queue (wb_inode);
return 0;
unwind:
frame->local = NULL;
STACK_UNWIND_STRICT (ftruncate, frame, -1, op_errno, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
}
int
wb_setattr_helper (call_frame_t *frame, xlator_t *this, loc_t *loc,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
STACK_WIND (frame, default_setattr_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata);
return 0;
}
int
wb_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, loc->inode);
if (!wb_inode)
goto noqueue;
stub = fop_setattr_stub (frame, wb_setattr_helper, loc, stbuf,
valid, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (setattr, frame, -1, ENOMEM, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
noqueue:
STACK_WIND (frame, default_setattr_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->setattr, loc, stbuf, valid, xdata);
return 0;
}
int
wb_fsetattr_helper (call_frame_t *frame, xlator_t *this, fd_t *fd,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
STACK_WIND (frame, default_fsetattr_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid, xdata);
return 0;
}
int
wb_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
struct iatt *stbuf, int32_t valid, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_fsetattr_stub (frame, wb_fsetattr_helper, fd, stbuf,
valid, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (fsetattr, frame, -1, ENOMEM, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
noqueue:
STACK_WIND (frame, default_fsetattr_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fsetattr, fd, stbuf, valid, xdata);
return 0;
}
int32_t
wb_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
wb_inode = wb_inode_create (this, fd->inode);
if (!wb_inode)
goto unwind;
if (((flags & O_RDWR) || (flags & O_WRONLY)) && (flags & O_TRUNC))
wb_inode->size = 0;
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->create, loc, flags, mode,
umask, fd, xdata);
return 0;
unwind:
STACK_UNWIND_STRICT (create, frame, -1, ENOMEM, NULL, NULL, NULL, NULL,
NULL, NULL);
return 0;
}
int32_t
wb_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
fd_t *fd, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
wb_inode = wb_inode_create (this, fd->inode);
if (!wb_inode)
goto unwind;
if (((flags & O_RDWR) || (flags & O_WRONLY)) && (flags & O_TRUNC))
wb_inode->size = 0;
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
return 0;
unwind:
STACK_UNWIND_STRICT (open, frame, -1, ENOMEM, NULL, NULL);
return 0;
}
int32_t
wb_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, inode_t *inode,
struct iatt *buf, dict_t *xdata, struct iatt *postparent)
{
if (op_ret == 0) {
wb_inode_t *wb_inode = wb_inode_ctx_get (this, inode);
if (wb_inode)
wb_set_inode_size (wb_inode, buf);
}
STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf,
xdata, postparent);
return 0;
}
int
wb_lookup_helper (call_frame_t *frame, xlator_t *this, loc_t *loc,
dict_t *xdata)
{
STACK_WIND (frame, wb_lookup_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->lookup, loc, xdata);
return 0;
}
int32_t
wb_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc,
dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, loc->inode);
if (!wb_inode)
goto noqueue;
stub = fop_lookup_stub (frame, wb_lookup_helper, loc, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
if (stub)
call_stub_destroy (stub);
STACK_UNWIND_STRICT (lookup, frame, -1, ENOMEM, NULL, NULL, NULL, NULL);
return 0;
noqueue:
STACK_WIND (frame, wb_lookup_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->lookup, loc, xdata);
return 0;
}
int32_t
wb_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
gf_dirent_t *entry = NULL;
inode_t *inode = NULL;
if (op_ret <= 0)
goto unwind;
list_for_each_entry (entry, &entries->list, list) {
if (!entry->inode || !IA_ISREG (entry->d_stat.ia_type))
continue;
wb_inode = wb_inode_ctx_get (this, entry->inode);
if (!wb_inode)
continue;
LOCK (&wb_inode->lock);
{
if (!list_empty (&wb_inode->liability)) {
/* We cannot guarantee integrity of
entry->d_stat as there are cached writes.
The stat is most likely stale as it doesn't
account the cached writes. However, checking
for non-empty liability list here is not a
fool-proof solution as there can be races
like,
1. readdirp is successful on posix
2. sync of cached write is successful on
posix
3. write-behind received sync response and
removed the request from liability queue
4. readdirp response is processed at
write-behind
In the above scenario, stat for the file is
sent back in readdirp response but it is
stale.
For lack of better solutions I am sticking
with current solution.
*/
inode = entry->inode;
entry->inode = NULL;
memset (&entry->d_stat, 0,
sizeof (entry->d_stat));
inode_unref (inode);
}
}
UNLOCK (&wb_inode->lock);
}
unwind:
STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno,
entries, xdata);
return 0;
}
int32_t
wb_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
off_t off, dict_t *xdata)
{
STACK_WIND (frame, wb_readdirp_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->readdirp,
fd, size, off, xdata);
return 0;
}
int32_t
wb_link_helper (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
loc_t *newloc, dict_t *xdata)
{
STACK_WIND_TAIL (frame,
FIRST_CHILD(this), FIRST_CHILD(this)->fops->link,
oldloc, newloc, xdata);
return 0;
}
int32_t
wb_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,
dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, oldloc->inode);
if (!wb_inode)
goto noqueue;
stub = fop_link_stub (frame, wb_link_helper, oldloc, newloc, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (link, frame, -1, ENOMEM, NULL, NULL, NULL, NULL,
NULL);
if (stub)
call_stub_destroy (stub);
return 0;
noqueue:
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->link,
oldloc, newloc, xdata);
return 0;
}
int32_t
wb_fallocate_helper (call_frame_t *frame, xlator_t *this, fd_t *fd,
int32_t keep_size, off_t offset, size_t len, dict_t *xdata)
{
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fallocate, fd, keep_size,
offset, len, xdata);
return 0;
}
int32_t
wb_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,
int32_t keep_size, off_t offset, size_t len, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_fallocate_stub (frame, wb_fallocate_helper, fd, keep_size,
offset, len, xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (fallocate, frame, -1, ENOMEM, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
noqueue:
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fallocate, fd, keep_size,
offset, len, xdata);
return 0;
}
int32_t
wb_discard_helper (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
size_t len, dict_t *xdata)
{
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->discard,
fd, offset, len, xdata);
return 0;
}
int32_t
wb_discard (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
size_t len, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_discard_stub (frame, wb_discard_helper, fd, offset, len,
xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (discard, frame, -1, ENOMEM, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
return 0;
noqueue:
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->discard,
fd, offset, len, xdata);
return 0;
}
int32_t
wb_zerofill_helper (call_frame_t *frame, xlator_t *this, fd_t *fd,
off_t offset, off_t len, dict_t *xdata)
{
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->zerofill,
fd, offset, len, xdata);
return 0;
}
int32_t
wb_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd,
off_t offset, off_t len, dict_t *xdata)
{
wb_inode_t *wb_inode = NULL;
call_stub_t *stub = NULL;
wb_inode = wb_inode_ctx_get (this, fd->inode);
if (!wb_inode)
goto noqueue;
stub = fop_zerofill_stub (frame, wb_zerofill_helper, fd, offset, len,
xdata);
if (!stub)
goto unwind;
if (!wb_enqueue (wb_inode, stub))
goto unwind;
wb_process_queue (wb_inode);
return 0;
unwind:
STACK_UNWIND_STRICT (zerofill, frame, -1, ENOMEM, NULL, NULL, NULL);
if (stub)
call_stub_destroy (stub);
noqueue:
STACK_WIND_TAIL (frame, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->zerofill,
fd, offset, len, xdata);
return 0;
}
int
wb_forget (xlator_t *this, inode_t *inode)
{
uint64_t tmp = 0;
wb_inode_t *wb_inode = NULL;
inode_ctx_del (inode, this, &tmp);
wb_inode = (wb_inode_t *)(long)tmp;
if (!wb_inode)
return 0;
GF_ASSERT (list_empty (&wb_inode->todo));
GF_ASSERT (list_empty (&wb_inode->liability));
GF_ASSERT (list_empty (&wb_inode->temptation));
GF_FREE (wb_inode);
return 0;
}
int
wb_release (xlator_t *this, fd_t *fd)
{
uint64_t tmp = 0;
fd_ctx_del (fd, this, &tmp);
return 0;
}
int
wb_priv_dump (xlator_t *this)
{
wb_conf_t *conf = NULL;
char key_prefix[GF_DUMP_MAX_BUF_LEN] = {0, };
int ret = -1;
GF_VALIDATE_OR_GOTO ("write-behind", this, out);
conf = this->private;
GF_VALIDATE_OR_GOTO (this->name, conf, out);
gf_proc_dump_build_key (key_prefix, "xlator.performance.write-behind",
"priv");
gf_proc_dump_add_section (key_prefix);
gf_proc_dump_write ("aggregate_size", "%d", conf->aggregate_size);
gf_proc_dump_write ("window_size", "%d", conf->window_size);
gf_proc_dump_write ("flush_behind", "%d", conf->flush_behind);
gf_proc_dump_write ("trickling_writes", "%d", conf->trickling_writes);
ret = 0;
out:
return ret;
}
void
__wb_dump_requests (struct list_head *head, char *prefix)
{
char key[GF_DUMP_MAX_BUF_LEN] = {0, };
char key_prefix[GF_DUMP_MAX_BUF_LEN] = {0, }, flag = 0;
wb_request_t *req = NULL;
list_for_each_entry (req, head, all) {
gf_proc_dump_build_key (key_prefix, key, "%s",
(char *)gf_fop_list[req->fop]);
gf_proc_dump_add_section(key_prefix);
gf_proc_dump_write ("unique", "%"PRIu64, req->unique);
gf_proc_dump_write ("refcount", "%d", req->refcount);
if (list_empty (&req->todo))
gf_proc_dump_write ("wound", "yes");
else
gf_proc_dump_write ("wound", "no");
gf_proc_dump_write ("generation-number", "%d", req->gen);
gf_proc_dump_write ("req->op_ret", "%d", req->op_ret);
gf_proc_dump_write ("req->op_errno", "%d", req->op_errno);
gf_proc_dump_write ("sync-attempts", "%d", req->wind_count);
if (req->fop == GF_FOP_WRITE) {
if (list_empty (&req->wip))
gf_proc_dump_write ("sync-in-progress", "no");
else
gf_proc_dump_write ("sync-in-progress", "yes");
gf_proc_dump_write ("size", "%"GF_PRI_SIZET,
req->write_size);
if (req->stub)
gf_proc_dump_write ("offset", "%"PRId64,
req->stub->args.offset);
flag = req->ordering.lied;
gf_proc_dump_write ("lied", "%d", flag);
flag = req->ordering.append;
gf_proc_dump_write ("append", "%d", flag);
flag = req->ordering.fulfilled;
gf_proc_dump_write ("fulfilled", "%d", flag);
flag = req->ordering.go;
gf_proc_dump_write ("go", "%d", flag);
}
}
}
int
wb_inode_dump (xlator_t *this, inode_t *inode)
{
wb_inode_t *wb_inode = NULL;
int32_t ret = -1;
char *path = NULL;
char key_prefix[GF_DUMP_MAX_BUF_LEN] = {0, };
char uuid_str[64] = {0,};
if ((inode == NULL) || (this == NULL)) {
ret = 0;
goto out;
}
wb_inode = wb_inode_ctx_get (this, inode);
if (wb_inode == NULL) {
ret = 0;
goto out;
}
uuid_utoa_r (inode->gfid, uuid_str);
gf_proc_dump_build_key (key_prefix, "xlator.performance.write-behind",
"wb_inode");
gf_proc_dump_add_section (key_prefix);
__inode_path (inode, NULL, &path);
if (path != NULL) {
gf_proc_dump_write ("path", "%s", path);
GF_FREE (path);
}
gf_proc_dump_write ("inode", "%p", inode);
gf_proc_dump_write ("gfid", "%s", uuid_str);
gf_proc_dump_write ("window_conf", "%"GF_PRI_SIZET,
wb_inode->window_conf);
gf_proc_dump_write ("window_current", "%"GF_PRI_SIZET,
wb_inode->window_current);
gf_proc_dump_write ("transit-size", "%"GF_PRI_SIZET,
wb_inode->transit);
gf_proc_dump_write ("dontsync", "%d", wb_inode->dontsync);
ret = TRY_LOCK (&wb_inode->lock);
if (!ret)
{
if (!list_empty (&wb_inode->all)) {
__wb_dump_requests (&wb_inode->all, key_prefix);
}
UNLOCK (&wb_inode->lock);
}
if (ret && wb_inode)
gf_proc_dump_write ("Unable to dump the inode information",
"(Lock acquisition failed) %p (gfid: %s)",
wb_inode, uuid_str);
ret = 0;
out:
return ret;
}
int
mem_acct_init (xlator_t *this)
{
int ret = -1;
if (!this) {
goto out;
}
ret = xlator_mem_acct_init (this, gf_wb_mt_end + 1);
if (ret != 0) {
gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
WRITE_BEHIND_MSG_NO_MEMORY,
"Memory accounting init"
"failed");
}
out:
return ret;
}
int
reconfigure (xlator_t *this, dict_t *options)
{
wb_conf_t *conf = NULL;
int ret = -1;
conf = this->private;
GF_OPTION_RECONF ("cache-size", conf->window_size, options, size_uint64,
out);
GF_OPTION_RECONF ("flush-behind", conf->flush_behind, options, bool,
out);
GF_OPTION_RECONF ("trickling-writes", conf->trickling_writes, options,
bool, out);
GF_OPTION_RECONF ("strict-O_DIRECT", conf->strict_O_DIRECT, options,
bool, out);
GF_OPTION_RECONF ("strict-write-ordering", conf->strict_write_ordering,
options, bool, out);
GF_OPTION_RECONF ("resync-failed-syncs-after-fsync",
conf->resync_after_fsync, options, bool, out);
ret = 0;
out:
return ret;
}
int32_t
init (xlator_t *this)
{
wb_conf_t *conf = NULL;
int32_t ret = -1;
if ((this->children == NULL)
|| this->children->next) {
gf_msg (this->name, GF_LOG_ERROR, 0,
WRITE_BEHIND_MSG_INIT_FAILED,
"FATAL: write-behind (%s) not configured with exactly "
"one child", this->name);
goto out;
}
if (this->parents == NULL) {
gf_msg (this->name, GF_LOG_WARNING, 0,
WRITE_BEHIND_MSG_VOL_MISCONFIGURED,
"dangling volume. check volfilex");
}
conf = GF_CALLOC (1, sizeof (*conf), gf_wb_mt_wb_conf_t);
if (conf == NULL) {
goto out;
}
/* configure 'options aggregate-size <size>' */
GF_OPTION_INIT ("aggregate-size", conf->aggregate_size, size_uint64, out);
conf->page_size = conf->aggregate_size;
/* configure 'option window-size <size>' */
GF_OPTION_INIT ("cache-size", conf->window_size, size_uint64, out);
if (!conf->window_size && conf->aggregate_size) {
gf_msg (this->name, GF_LOG_WARNING, 0,
WRITE_BEHIND_MSG_SIZE_NOT_SET,
"setting window-size to be equal to "
"aggregate-size(%"PRIu64")",
conf->aggregate_size);
conf->window_size = conf->aggregate_size;
}
if (conf->window_size < conf->aggregate_size) {
gf_msg (this->name, GF_LOG_ERROR, 0,
WRITE_BEHIND_MSG_EXCEEDED_MAX_SIZE,
"aggregate-size(%"PRIu64") cannot be more than "
"window-size(%"PRIu64")", conf->aggregate_size,
conf->window_size);
goto out;
}
/* configure 'option flush-behind <on/off>' */
GF_OPTION_INIT ("flush-behind", conf->flush_behind, bool, out);
GF_OPTION_INIT ("trickling-writes", conf->trickling_writes, bool, out);
GF_OPTION_INIT ("strict-O_DIRECT", conf->strict_O_DIRECT, bool, out);
GF_OPTION_INIT ("strict-write-ordering", conf->strict_write_ordering,
bool, out);
GF_OPTION_INIT ("resync-failed-syncs-after-fsync",
conf->resync_after_fsync, bool, out);
this->private = conf;
ret = 0;
out:
if (ret) {
GF_FREE (conf);
}
return ret;
}
void
fini (xlator_t *this)
{
wb_conf_t *conf = NULL;
GF_VALIDATE_OR_GOTO ("write-behind", this, out);
conf = this->private;
if (!conf) {
goto out;
}
this->private = NULL;
GF_FREE (conf);
out:
return;
}
struct xlator_fops fops = {
.writev = wb_writev,
.readv = wb_readv,
.flush = wb_flush,
.fsync = wb_fsync,
.stat = wb_stat,
.fstat = wb_fstat,
.truncate = wb_truncate,
.ftruncate = wb_ftruncate,
.setattr = wb_setattr,
.fsetattr = wb_fsetattr,
.lookup = wb_lookup,
.readdirp = wb_readdirp,
.link = wb_link,
.fallocate = wb_fallocate,
.discard = wb_discard,
.zerofill = wb_zerofill,
};
struct xlator_cbks cbks = {
.forget = wb_forget,
.release = wb_release
};
struct xlator_dumpops dumpops = {
.priv = wb_priv_dump,
.inodectx = wb_inode_dump,
};
struct volume_options options[] = {
{ .key = {"flush-behind"},
.type = GF_OPTION_TYPE_BOOL,
.default_value = "on",
.op_version = {1},
.flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_CLIENT_OPT,
.tags = {"write-behind"},
.description = "If this option is set ON, instructs write-behind "
"translator to perform flush in background, by "
"returning success (or any errors, if any of "
"previous writes were failed) to application even "
"before flush FOP is sent to backend filesystem. "
},
{ .key = {"cache-size", "window-size"},
.type = GF_OPTION_TYPE_SIZET,
.min = 512 * GF_UNIT_KB,
.max = 1 * GF_UNIT_GB,
.default_value = "1MB",
.op_version = {1},
.flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_CLIENT_OPT,
.tags = {"write-behind"},
.description = "Size of the write-behind buffer for a single file "
"(inode)."
},
{ .key = {"trickling-writes"},
.type = GF_OPTION_TYPE_BOOL,
.op_version = {GD_OP_VERSION_3_13_1},
.flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_CLIENT_OPT,
.tags = {"write-behind"},
.default_value = "on",
},
{ .key = {"strict-O_DIRECT"},
.type = GF_OPTION_TYPE_BOOL,
.default_value = "off",
.op_version = {2},
.flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_CLIENT_OPT,
.tags = {"write-behind"},
.description = "This option when set to off, ignores the "
"O_DIRECT flag."
},
{ .key = {"strict-write-ordering"},
.type = GF_OPTION_TYPE_BOOL,
.default_value = "off",
.op_version = {2},
.flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_CLIENT_OPT,
.tags = {"write-behind"},
.description = "Do not let later writes overtake earlier writes even "
"if they do not overlap",
},
{ .key = {"resync-failed-syncs-after-fsync"},
.type = GF_OPTION_TYPE_BOOL,
.default_value = "off",
.op_version = {GD_OP_VERSION_3_7_7},
.flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_CLIENT_OPT,
.tags = {"write-behind"},
.description = "If sync of \"cached-writes issued before fsync\" "
"(to backend) fails, this option configures whether "
"to retry syncing them after fsync or forget them. "
"If set to on, cached-writes are retried "
"till a \"flush\" fop (or a successful sync) on sync "
"failures. "
"fsync itself is failed irrespective of the value of "
"this option. ",
},
{ .key = {"aggregate-size"},
.type = GF_OPTION_TYPE_SIZET,
.default_value = "128KB",
.op_version = {GD_OP_VERSION_4_1_0},
.flags = OPT_FLAG_SETTABLE | OPT_FLAG_DOC | OPT_FLAG_CLIENT_OPT,
.description = "Will aggregate writes until data of specified "
"size is fully filled for a single file provided "
"there are no dependent fops on cached writes. This "
"option just sets the aggregate size. Note that "
"aggregation won't happen if performance.write-behind-trickling-writes"
" is turned on. Hence turn off performance.write-behind.trickling-writes"
" so that writes are aggregated till a max of "
"\"aggregate-size\" bytes",
},
{ .key = {NULL} },
};
|