summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-rpc-ops.c
blob: 0fef7da8b7d6a87483b713b546f891a0ebc2ee2f (plain)
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
/*
  Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/


#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include "cli.h"
#include "compat-errno.h"
#include "cli-cmd.h"
#include <sys/uio.h>

#include "cli1-xdr.h"
#include "cli1.h"
#include "protocol-common.h"
#include "cli-mem-types.h"
#include "compat.h"

#include "glusterfs3.h"
#include "portmap.h"

extern rpc_clnt_prog_t *cli_rpc_prog;
extern int              cli_op_ret;

char *cli_volume_type[] = {"Distribute",
                           "Stripe",
                           "Replicate",
                           "Distributed-Stripe",
                           "Distributed-Replicate",
};


char *cli_volume_status[] = {"Created",
                             "Started",
                             "Stopped"
};

int32_t
gf_cli3_1_get_volume (call_frame_t *frame, xlator_t *this,
                      void *data);


rpc_clnt_prog_t cli_handshake_prog = {
        .progname  = "cli handshake",
        .prognum   = GLUSTER_HNDSK_PROGRAM,
        .progver   = GLUSTER_HNDSK_VERSION,
};

rpc_clnt_prog_t cli_pmap_prog = {
        .progname   = "cli portmap",
        .prognum    = GLUSTER_PMAP_PROGRAM,
        .progver    = GLUSTER_PMAP_VERSION,
};


int
gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
                        int count, void *myframe)
{
        gf1_cli_probe_rsp    rsp   = {0,};
        int                   ret   = 0;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_probe_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                //rsp.op_ret   = -1;
                //rsp.op_errno = EINVAL;
                goto out;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe");
	 if (!rsp.op_ret) {
	 	switch (rsp.op_errno) {
		 	case GF_PROBE_SUCCESS:
		      		cli_out ("Probe successful");
		      		break;
	 	 	case GF_PROBE_LOCALHOST:
		      		cli_out ("Probe on localhost not needed");
		      		break;
			case GF_PROBE_FRIEND:
				cli_out ("Probe on host %s port %d already"
					 " in peer list", rsp.hostname, rsp.port);
				break;
		 	default:
		      		cli_out ("Probe returned with unknown errno %d",
					rsp.op_errno);
		      		break;
	 	}
	 }

        if (rsp.op_ret) {
                switch (rsp.op_errno) {
                        case GF_PROBE_ANOTHER_CLUSTER:
                                cli_out ("%s is already part of "
                                         "another cluster", rsp.hostname);
                                break;
                        case GF_PROBE_VOLUME_CONFLICT:
                                cli_out ("Atleast one volume on %s conflicts "
                                         "with existing volumes in the "
                                         "cluster", rsp.hostname);
                                break;
                        case GF_PROBE_UNKNOWN_PEER:
                                cli_out ("%s responded with 'unknown peer' error, "
                                         "this could happen if %s doesn't have"
                                         " localhost in its peer database",
                                         rsp.hostname, rsp.hostname);
                                break;
                        case GF_PROBE_ADD_FAILED:
                                cli_out ("Failed to add peer information "
                                         "on %s" , rsp.hostname);
                                break;

                        default:
                                cli_out ("Probe unsuccessful\nProbe returned "
                                         "with unknown errno %d", rsp.op_errno);
                                break;
                }
                gf_log ("glusterd",GF_LOG_ERROR,"Probe failed with op_ret %d"
                        " and op_errno %d", rsp.op_ret, rsp.op_errno);
        }
        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_deprobe_cbk (struct rpc_req *req, struct iovec *iov,
                       int count, void *myframe)
{
        gf1_cli_deprobe_rsp    rsp   = {0,};
        int                   ret   = 0;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_deprobe_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                //rsp.op_ret   = -1;
                //rsp.op_errno = EINVAL;
                goto out;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to deprobe");
        if (rsp.op_ret) {
                switch (rsp.op_errno) {
                        case GF_DEPROBE_LOCALHOST:
                                cli_out ("%s is localhost",
                                         rsp.hostname);
                                break;
                        case GF_DEPROBE_NOT_FRIEND:
                                cli_out ("%s is not part of cluster",
                                         rsp.hostname);
                                break;
                        case GF_DEPROBE_BRICK_EXIST:
                                cli_out ("Brick(s) with the peer %s exist in "
                                         "cluster", rsp.hostname);
                                break;
                        default:
                                cli_out ("Detach unsuccessful\nDetach returned "
                                         "with unknown errno %d",
                                         rsp.op_errno);
                                break;
                }
                gf_log ("glusterd",GF_LOG_ERROR,"Detach failed with op_ret %d"
                        " and op_errno %d", rsp.op_ret, rsp.op_errno);
        } else {
                cli_out ("Detach successful");
        }


        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_peer_list_rsp      rsp   = {0,};
        int                        ret   = 0;
        dict_t                     *dict = NULL;
        char                       *uuid_buf = NULL;
        char                       *hostname_buf = NULL;
        int32_t                    i = 1;
        char                       key[256] = {0,};
        char                       *state = NULL;
        int32_t                    port = 0;
        int32_t                    connected = 0;
        char                       *connected_str = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_peer_list_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                //rsp.op_ret   = -1;
                //rsp.op_errno = EINVAL;
                goto out;
        }


        gf_log ("cli", GF_LOG_NORMAL, "Received resp to list: %d",
                rsp.op_ret);

        ret = rsp.op_ret;

        if (!rsp.op_ret) {

                if (!rsp.friends.friends_len) {
                        cli_out ("No peers present");
                        ret = 0;
                        goto out;
                }

                dict = dict_new ();

                if (!dict) {
                        ret = -1;
                        goto out;
                }

                ret = dict_unserialize (rsp.friends.friends_val,
                                        rsp.friends.friends_len,
                                        &dict);

                if (ret) {
                        gf_log ("", GF_LOG_ERROR,
                                        "Unable to allocate memory");
                        goto out;
                }

                ret = dict_get_int32 (dict, "count", &count);

                if (ret) {
                        goto out;
                }

                cli_out ("Number of Peers: %d", count);

                while ( i <= count) {
                        snprintf (key, 256, "friend%d.uuid", i);
                        ret = dict_get_str (dict, key, &uuid_buf);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "friend%d.hostname", i);
                        ret = dict_get_str (dict, key, &hostname_buf);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "friend%d.connected", i);
                        ret = dict_get_int32 (dict, key, &connected);
                        if (ret)
                                goto out;
                        if (connected)
                                connected_str = "Connected";
                        else
                                connected_str = "Disconnected";

                        snprintf (key, 256, "friend%d.port", i);
                        ret = dict_get_int32 (dict, key, &port);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "friend%d.state", i);
                        ret = dict_get_str (dict, key, &state);
                        if (ret)
                                goto out;

                        if (!port) {
                                cli_out ("\nHostname: %s\nUuid: %s\nState: %s "
                                         "(%s)",
                                         hostname_buf, uuid_buf, state,
                                         connected_str);
                        } else {
                                cli_out ("\nHostname: %s\nPort: %d\nUuid: %s\n"
                                         "State: %s (%s)", hostname_buf, port,
                                         uuid_buf, state, connected_str);
                        }
                        i++;
                }
        } else {
                ret = -1;
                goto out;
        }


        ret = 0;

out:
        cli_cmd_broadcast_response (ret);
        if (ret)
                cli_out ("Peer status unsuccessful");

        if (dict)
                dict_destroy (dict);

        return ret;
}

void
cli_out_options ( char *substr, char *optstr, char *valstr)
{
        char                    *ptr1 = NULL;
        char                    *ptr2 = NULL;

        ptr1 = substr;
        ptr2 = optstr;

        while (ptr1)
        {
                if (*ptr1 != *ptr2)
                        break;
                ptr1++;
                ptr2++;
                if (!ptr1)
                        return;
                if (!ptr2)
                        return;
        }

        if (*ptr2 == '\0')
                return;
        cli_out ("%s: %s",ptr2 , valstr);
}


int
gf_cli3_1_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_get_vol_rsp        rsp   = {0,};
        int                        ret   = 0;
        dict_t                     *dict = NULL;
        char                       *volname = NULL;
        int32_t                    i = 0;
        char                       key[1024] = {0,};
        int32_t                    status = 0;
        int32_t                    type = 0;
        int32_t                    brick_count = 0;
        int32_t                    sub_count = 0;
        int32_t                    vol_type = 0;
        char                       *brick = NULL;
        int32_t                    j = 1;
        cli_local_t                *local = NULL;
        int32_t                    transport = 0;
        data_pair_t                *pairs = NULL;
        char                       *ptr = NULL;
        data_t                     *value = NULL;
        int                        opt_count = 0;
        int                        k = 0;
        char                       err_str[2048] = {0};

        snprintf (err_str, sizeof (err_str), "Volume info unsuccessful");
        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_get_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                //rsp.op_ret   = -1;
                //rsp.op_errno = EINVAL;
                goto out;
        }


        gf_log ("cli", GF_LOG_NORMAL, "Received resp to get vol: %d",
                rsp.op_ret);

        if (!rsp.op_ret) {

                if (!rsp.volumes.volumes_len) {
                        cli_out ("No volumes present");
                        ret = 0;
                        goto out;
                }

                dict = dict_new ();

                if (!dict) {
                        ret = -1;
                        goto out;
                }

                ret = dict_unserialize (rsp.volumes.volumes_val,
                                        rsp.volumes.volumes_len,
                                        &dict);

                if (ret) {
                        gf_log ("", GF_LOG_ERROR,
                                        "Unable to allocate memory");
                        goto out;
                }

                ret = dict_get_int32 (dict, "count", &count);

                if (ret) {
                        goto out;
                }

                local = ((call_frame_t *)myframe)->local;
                //cli_out ("Number of Volumes: %d", count);

                if (!count && (local->u.get_vol.flags ==
                                        GF_CLI_GET_NEXT_VOLUME)) {
                        local->u.get_vol.volname = NULL;
                        ret = 0;
                        goto out;
                } else if (!count && (local->u.get_vol.flags ==
                                        GF_CLI_GET_VOLUME)) {
                        snprintf (err_str, sizeof (err_str),
                                  "Volume %s does not exist",
                                  local->u.get_vol.volname);
                        ret = -1;
                        goto out;
                }

                while ( i < count) {
                        cli_out ("");
                        snprintf (key, 256, "volume%d.name", i);
                        ret = dict_get_str (dict, key, &volname);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "volume%d.type", i);
                        ret = dict_get_int32 (dict, key, &type);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "volume%d.status", i);
                        ret = dict_get_int32 (dict, key, &status);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "volume%d.brick_count", i);
                        ret = dict_get_int32 (dict, key, &brick_count);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "volume%d.sub_count", i);
                        ret = dict_get_int32 (dict, key, &sub_count);
                        if (ret)
                                goto out;

                        snprintf (key, 256, "volume%d.transport", i);
                        ret = dict_get_int32 (dict, key, &transport);
                        if (ret)
                                goto out;

                        vol_type = type;

                        // Stripe
                        if ((type == 1) && (sub_count < brick_count))
                                vol_type = 3;

                        // Replicate
                        if ((type == 2) && (sub_count < brick_count))
                                vol_type = 4;

                        cli_out ("Volume Name: %s", volname);
                        cli_out ("Type: %s", cli_volume_type[vol_type]);
                        cli_out ("Status: %s", cli_volume_status[status], brick_count);
                        if ((sub_count > 1) && (brick_count > sub_count))
                                cli_out ("Number of Bricks: %d x %d = %d",
                                         brick_count / sub_count, sub_count,
                                         brick_count);
                        else
                                cli_out ("Number of Bricks: %d", brick_count);

                        cli_out ("Transport-type: %s",
                                 ((transport == 0)?"tcp":
                                   (transport == 1)?"rdma":
                                  "tcp,rdma"));
                        j = 1;


                        GF_FREE (local->u.get_vol.volname);
                        local->u.get_vol.volname = gf_strdup (volname);

                        if (brick_count)
                                cli_out ("Bricks:");

                        while ( j <= brick_count) {
                                snprintf (key, 1024, "volume%d.brick%d",
                                          i, j);
                                ret = dict_get_str (dict, key, &brick);
                                if (ret)
                                        goto out;
                                cli_out ("Brick%d: %s", j, brick);
                                j++;
                        }
                        pairs = dict->members_list;
                        if (!pairs) {
                                ret = -1;
                                goto out;
                        }

                        snprintf (key, 256, "volume%d.opt_count",i);
                        ret = dict_get_int32 (dict, key, &opt_count);
                        if (ret)
                            goto out;

                        if (!opt_count)
                            goto out;

                        cli_out ("Options Reconfigured:");
                        k = 0;
                        while ( k < opt_count) {

                                snprintf (key, 256, "volume%d.option.",i);
                                while (pairs) {
                                        ptr = strstr (pairs->key, "option.");
                                        if (ptr) {
                                                value = pairs->value;
                                                if (!value) {
                                                        ret = -1;
                                                        goto out;
                                                }
                                                cli_out_options (key, pairs->key,
                                                                 value->data);
                                        }
                                        pairs = pairs->next;
                                }
                                k++;
                       }

                       i++;
                }


        } else {
                ret = -1;
                goto out;
        }


        ret = 0;

out:
        cli_cmd_broadcast_response (ret);
        if (ret)
                cli_out (err_str);

        if (dict)
                dict_destroy (dict);

        gf_log ("", GF_LOG_NORMAL, "Returning: %d", ret);
        return ret;
}

int
gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_create_vol_rsp  rsp   = {0,};
        int                     ret   = 0;
        cli_local_t             *local = NULL;
        char                    *volname = NULL;
        dict_t                  *dict = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        local = ((call_frame_t *) (myframe))->local;
        ((call_frame_t *) (myframe))->local = NULL;

        ret = gf_xdr_to_cli_create_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        dict = local->u.create_vol.dict;

        ret = dict_get_str (dict, "volname", &volname);

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to create volume");
	if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
	        cli_out ("%s", rsp.op_errstr);
        else
                cli_out ("Creation of volume %s has been %s", volname,
                                (rsp.op_ret) ? "unsuccessful":
                                "successful. Please start the volume to "
                                "access data.");
        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        if (dict)
                dict_unref (dict);
        if (local)
                cli_local_wipe (local);
        if (rsp.volname)
                free (rsp.volname);
        if (rsp.op_errstr)
                free (rsp.op_errstr);
        return ret;
}

int
gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_delete_vol_rsp  rsp   = {0,};
        int                     ret   = 0;
        cli_local_t             *local = NULL;
        char                    *volname = NULL;
        call_frame_t            *frame = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_delete_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        frame = myframe;
        local = frame->local;
        frame->local = NULL;

        if (local)
                volname = local->u.delete_vol.volname;


        gf_log ("cli", GF_LOG_NORMAL, "Received resp to delete volume");

        if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
                cli_out (rsp.op_errstr);
        else
                cli_out ("Deleting volume %s has been %s", volname,
                         (rsp.op_ret) ? "unsuccessful": "successful");
        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        cli_local_wipe (local);
        if (rsp.volname)
                free (rsp.volname);
        gf_log ("", GF_LOG_NORMAL, "Returning with %d", ret);
        return ret;
}

int
gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_start_vol_rsp   rsp   = {0,};
        int                     ret   = 0;
        cli_local_t             *local = NULL;
        char                    *volname = NULL;
        call_frame_t            *frame = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_start_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        frame = myframe;

        if (frame) {
                local = frame->local;
                frame->local = NULL;
        }

        if (local)
                volname = local->u.start_vol.volname;

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to start volume");

        if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
                cli_out ("%s", rsp.op_errstr);
        else
                cli_out ("Starting volume %s has been %s", volname,
                        (rsp.op_ret) ? "unsuccessful": "successful");

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        if (local)
                cli_local_wipe (local);
        if (rsp.volname)
                free (rsp.volname);
        if (rsp.op_errstr)
                free (rsp.op_errstr);
        return ret;
}

int
gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_stop_vol_rsp  rsp   = {0,};
        int                   ret   = 0;
        cli_local_t           *local = NULL;
        char                  *volname = NULL;
        call_frame_t          *frame = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_stop_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        frame = myframe;

        if (frame)
                local = frame->local;

        if (local)
                volname = local->u.start_vol.volname;

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to stop volume");

        if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
                cli_out (rsp.op_errstr);
        else
                cli_out ("Stopping volume %s has been %s", volname,
                        (rsp.op_ret) ? "unsuccessful": "successful");
        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        if (rsp.op_errstr)
                free (rsp.op_errstr);
        if (rsp.volname)
                free (rsp.volname);
        return ret;
}

int
gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf2_cli_defrag_vol_rsp  rsp     = {0,};
        cli_local_t             *local   = NULL;
        char                    *volname = NULL;
        call_frame_t            *frame   = NULL;
        int                      cmd     = 0;
        int                      ret     = 0;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_defrag_vol_rsp_v2 (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        frame = myframe;

        if (frame)
                local = frame->local;

        if (local) {
                volname = local->u.defrag_vol.volname;
                cmd = local->u.defrag_vol.cmd;
        }
        if ((cmd == GF_DEFRAG_CMD_START) ||
            (cmd == GF_DEFRAG_CMD_START_LAYOUT_FIX) ||
            (cmd == GF_DEFRAG_CMD_START_MIGRATE_DATA)) {
                if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
                        cli_out (rsp.op_errstr);
                else
                        cli_out ("starting rebalance on volume %s has been %s",
                                 volname, (rsp.op_ret) ? "unsuccessful":
                                 "successful");
        }
        if (cmd == GF_DEFRAG_CMD_STOP) {
                if (rsp.op_ret == -1) {
                        if (strcmp (rsp.op_errstr, ""))
                                cli_out (rsp.op_errstr);
                        else
                                cli_out ("rebalance volume %s stop failed",
                                         volname);
                } else {
                        cli_out ("stopped rebalance process of volume %s \n"
                                 "(after rebalancing %"PRId64" files totaling "
                                 "%"PRId64" bytes)", volname, rsp.files, rsp.size);
                }
        }
        if (cmd == GF_DEFRAG_CMD_STATUS) {
                if (rsp.op_ret == -1) {
                        if (strcmp (rsp.op_errstr, ""))
                                cli_out (rsp.op_errstr);
                        else
                                cli_out ("failed to get the status of "
                                         "rebalance process");
                } else {
                        char *status = "unknown";
                        if (rsp.op_errno == 0)
                                status = "not started";
                        if (rsp.op_errno == 1)
                                status = "step 1: layout fix in progress";
                        if (rsp.op_errno == 2)
                                status = "step 2: data migration in progress";
                        if (rsp.op_errno == 3)
                                status = "stopped";
                        if (rsp.op_errno == 4)
                                status = "completed";
                        if (rsp.op_errno == 5)
                                status = "failed";
                        if (rsp.op_errno == 6)
                                status = "step 1: layout fix complete";
                        if (rsp.op_errno == 7)
                                status = "step 2: data migration complete";

                        if (rsp.files && (rsp.op_errno == 1)) {
                                cli_out ("rebalance %s: fixed layout %"PRId64,
                                         status, rsp.files);
                                goto done;
                        }
                        if (rsp.files && (rsp.op_errno == 6)) {
                                cli_out ("rebalance %s: fixed layout %"PRId64,
                                         status, rsp.files);
                                goto done;
                        }
                        if (rsp.files) {
                                cli_out ("rebalance %s: rebalanced %"PRId64
                                         " files of size %"PRId64" (total files"
                                         " scanned %"PRId64")", status,
                                         rsp.files, rsp.size, rsp.lookedup_files);
                                goto done;
                        }

                        cli_out ("rebalance %s", status);
                }
        }

done:
        if (volname)
                GF_FREE (volname);

        ret = rsp.op_ret;

out:
        if (rsp.op_errstr)
                free (rsp.op_errstr); //malloced by xdr
        if (rsp.volname)
                free (rsp.volname); //malloced by xdr
        cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_rename_vol_rsp  rsp   = {0,};
        int                     ret   = 0;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_rename_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }


        gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe");
        cli_out ("Rename volume %s", (rsp.op_ret) ? "unsuccessful":
                                        "successful");

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_reset_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_reset_vol_rsp  rsp   = {0,};
        int                  ret   = 0;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_reset_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to reset");

        if (rsp.op_ret &&  strcmp (rsp.op_errstr, ""))
                cli_out ("%s", rsp.op_errstr);
        else
                cli_out ("reset volume %s", (rsp.op_ret) ? "unsuccessful":
                                "successful");

        ret = rsp.op_ret;

out:
                cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_set_vol_rsp  rsp   = {0,};
        int                  ret   = 0;
        dict_t               *dict = NULL;
        char                 *help_str = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_set_vol_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to set");

        if (rsp.op_ret &&  strcmp (rsp.op_errstr, ""))
                cli_out ("%s", rsp.op_errstr);

        dict = dict_new ();

        if (!dict) {
                ret = -1;
                goto out;
        }

        ret = dict_unserialize (rsp.dict.dict_val, rsp.dict.dict_len, &dict);

        if (ret)
                goto out;

        if (dict_get_str (dict, "help-str", &help_str))
                cli_out ("Set volume %s", (rsp.op_ret) ? "unsuccessful":
                                                         "successful");
        else
                cli_out ("%s", help_str);

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_add_brick_rsp       rsp   = {0,};
        int                         ret   = 0;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_add_brick_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }


        gf_log ("cli", GF_LOG_NORMAL, "Received resp to add brick");

        if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
                cli_out ("%s", rsp.op_errstr);
        else
                cli_out ("Add Brick %s", (rsp.op_ret) ? "unsuccessful":
                                                        "successful");
        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        if (rsp.volname)
                free (rsp.volname);
        if (rsp.op_errstr)
                free (rsp.op_errstr);
        return ret;
}


int
gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_remove_brick_rsp        rsp   = {0,};
        int                             ret   = 0;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_remove_brick_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to remove brick");

        if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
                cli_out ("%s", rsp.op_errstr);
        else
                cli_out ("Remove Brick %s", (rsp.op_ret) ? "unsuccessful":
                                                           "successful");

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        if (rsp.volname)
                free (rsp.volname);
        if (rsp.op_errstr)
                free (rsp.op_errstr);
        return ret;
}



int
gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,
                             int count, void *myframe)
{
        gf1_cli_replace_brick_rsp        rsp              = {0,};
        int                              ret              = 0;
        cli_local_t                     *local            = NULL;
        call_frame_t                    *frame            = NULL;
        dict_t                          *dict             = NULL;
        char                            *src_brick        = NULL;
        char                            *dst_brick        = NULL;
        char                            *status_reply     = NULL;
        gf1_cli_replace_op               replace_op       = 0;
        char                            *rb_operation_str = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        frame = (call_frame_t *) myframe;

        ret = gf_xdr_to_cli_replace_brick_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        local = frame->local;
        GF_ASSERT (local);
        dict = local->u.replace_brick.dict;

        ret = dict_get_int32 (dict, "operation", (int32_t *)&replace_op);
        if (ret) {
                gf_log ("", GF_LOG_DEBUG,
                        "dict_get on operation failed");
                goto out;
        }

        switch (replace_op) {
        case GF_REPLACE_OP_START:
                if (rsp.op_ret)
                        rb_operation_str = "replace-brick failed to start";
                else
                        rb_operation_str = "replace-brick started successfully";
                break;

        case GF_REPLACE_OP_STATUS:

                status_reply = rsp.status;
                if (rsp.op_ret || ret)
                        rb_operation_str = "replace-brick status unknown";
                else
                        rb_operation_str = status_reply;

                break;

        case GF_REPLACE_OP_PAUSE:
                if (rsp.op_ret)
                        rb_operation_str = "replace-brick pause failed";
                else
                        rb_operation_str = "replace-brick paused successfully";
                break;

        case GF_REPLACE_OP_ABORT:
                if (rsp.op_ret)
                        rb_operation_str = "replace-brick abort failed";
                else
                        rb_operation_str = "replace-brick aborted successfully";
                break;

        case GF_REPLACE_OP_COMMIT:
        case GF_REPLACE_OP_COMMIT_FORCE:
                ret = dict_get_str (dict, "src-brick", &src_brick);
                if (ret) {
                        gf_log ("", GF_LOG_DEBUG,
                                "dict_get on src-brick failed");
                        goto out;
                }

                ret = dict_get_str (dict, "dst-brick", &dst_brick);
                if (ret) {
                        gf_log ("", GF_LOG_DEBUG,
                                "dict_get on dst-brick failed");
                        goto out;
                }


                if (rsp.op_ret || ret)
                        rb_operation_str = "replace-brick commit failed";
                else
                        rb_operation_str = "replace-brick commit successful";

                break;

        default:
                gf_log ("", GF_LOG_DEBUG,
                        "Unknown operation");
                break;
        }

        if (rsp.op_ret && (strcmp (rsp.op_errstr, ""))) {
                rb_operation_str = rsp.op_errstr;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to replace brick");
        cli_out ("%s",
                 rb_operation_str ? rb_operation_str : "Unknown operation");

        ret = rsp.op_ret;

out:
        if (local) {
                dict_unref (local->u.replace_brick.dict);
                GF_FREE (local->u.replace_brick.volname);
                cli_local_wipe (local);
        }

        cli_cmd_broadcast_response (ret);
        return ret;
}

static int
gf_cli3_1_log_filename_cbk (struct rpc_req *req, struct iovec *iov,
                            int count, void *myframe)
{
        gf1_cli_log_filename_rsp        rsp   = {0,};
        int                             ret   = -1;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_log_filename_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_DEBUG, "Received resp to log filename");

        if (rsp.op_ret && strcmp (rsp.errstr, ""))
                cli_out (rsp.errstr);
        else
                cli_out ("log filename : %s",
                         (rsp.op_ret) ? "unsuccessful": "successful");

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

static int
gf_cli3_1_log_locate_cbk (struct rpc_req *req, struct iovec *iov,
                          int count, void *myframe)
{
        gf1_cli_log_locate_rsp rsp   = {0,};
        int                    ret   = -1;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_log_locate_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_DEBUG, "Received resp to log locate");
        cli_out ("log file location: %s", rsp.path);

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

static int
gf_cli3_1_log_rotate_cbk (struct rpc_req *req, struct iovec *iov,
                          int count, void *myframe)
{
        gf1_cli_log_rotate_rsp rsp   = {0,};
        int                    ret   = -1;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_log_rotate_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_DEBUG, "Received resp to log rotate");

        if (rsp.op_ret && strcmp (rsp.errstr, ""))
                cli_out (rsp.errstr);
        else
                cli_out ("log rotate %s", (rsp.op_ret) ? "unsuccessful":
                                                         "successful");

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

static int
gf_cli3_1_sync_volume_cbk (struct rpc_req *req, struct iovec *iov,
                           int count, void *myframe)
{
        gf1_cli_sync_volume_rsp        rsp   = {0,};
        int                            ret   = -1;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_sync_volume_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_DEBUG, "Received resp to sync");

        if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
                cli_out (rsp.op_errstr);
        else
                cli_out ("volume sync: %s",
                         (rsp.op_ret) ? "unsuccessful": "successful");
        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_getspec_cbk (struct rpc_req *req, struct iovec *iov,
                       int count, void *myframe)
{
        gf_getspec_rsp          rsp   = {0,};
        int                     ret   = 0;
        char                   *spec  = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = xdr_to_getspec_rsp (*iov, &rsp);
        if (ret < 0 || rsp.op_ret == -1) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to getspec");

        spec = GF_MALLOC (rsp.op_ret + 1, cli_mt_char);
        if (!spec) {
                gf_log("", GF_LOG_ERROR, "out of memory");
                goto out;
        }
        memcpy (spec, rsp.spec, rsp.op_ret);
        spec[rsp.op_ret] = '\0';
        cli_out ("%s", spec);
        GF_FREE (spec);

        ret = 0;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

int
gf_cli3_1_pmap_b2p_cbk (struct rpc_req *req, struct iovec *iov,
                        int count, void *myframe)
{
        pmap_port_by_brick_rsp rsp = {0,};
        int                     ret   = 0;
        char                   *spec  = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = xdr_to_pmap_port_by_brick_rsp (*iov, &rsp);
        if (ret < 0 || rsp.op_ret == -1) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        gf_log ("cli", GF_LOG_NORMAL, "Received resp to pmap b2p");

        cli_out ("%d", rsp.port);
        GF_FREE (spec);

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}


int32_t
gf_cli3_1_probe (call_frame_t *frame, xlator_t *this,
                 void *data)
{
        gf1_cli_probe_req  req      = {0,};
        int                ret      = 0;
        dict_t            *dict     = NULL;
        char              *hostname = NULL;
        int                port     = 0;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;
        ret = dict_get_str (dict, "hostname", &hostname);
        if (ret)
                goto out;

        ret = dict_get_int32 (dict, "port", &port);
        if (ret)
                port = CLI_GLUSTERD_PORT;

        req.hostname = hostname;
        req.port     = port;

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_PROBE, NULL, gf_xdr_from_cli_probe_req,
                              this, gf_cli3_1_probe_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

int32_t
gf_cli3_1_deprobe (call_frame_t *frame, xlator_t *this,
                   void *data)
{
        gf1_cli_deprobe_req  req      = {0,};
        int                  ret      = 0;
        dict_t              *dict     = NULL;
        char                *hostname = NULL;
        int                  port     = 0;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;
        ret = dict_get_str (dict, "hostname", &hostname);
        if (ret)
                goto out;

        ret = dict_get_int32 (dict, "port", &port);
        if (ret)
                port = CLI_GLUSTERD_PORT;

        req.hostname = hostname;
        req.port     = port;

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_DEPROBE, NULL,
                              gf_xdr_from_cli_deprobe_req,
                              this, gf_cli3_1_deprobe_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

int32_t
gf_cli3_1_list_friends (call_frame_t *frame, xlator_t *this,
                        void *data)
{
        gf1_cli_peer_list_req   req = {0,};
        int                     ret = 0;

        if (!frame || !this) {
                ret = -1;
                goto out;
        }

        req.flags = GF_CLI_LIST_ALL;

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_LIST_FRIENDS, NULL,
                              gf_xdr_from_cli_peer_list_req,
                              this, gf_cli3_1_list_friends_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

int32_t
gf_cli3_1_get_next_volume (call_frame_t *frame, xlator_t *this,
                           void *data)
{

        int                             ret = 0;
        cli_cmd_volume_get_ctx_t        *ctx = NULL;
        cli_local_t                     *local = NULL;

        if (!frame || !this || !data) {
                ret = -1;
                goto out;
        }

        ctx = data;

        ret = gf_cli3_1_get_volume (frame, this, data);

        local = frame->local;

        if (!local || !local->u.get_vol.volname) {
                cli_out ("No volumes present");
                goto out;
        }

        ctx->volname = local->u.get_vol.volname;

        while (ctx->volname) {
                ret = gf_cli3_1_get_volume (frame, this, ctx);
                if (ret)
                        goto out;
                ctx->volname = local->u.get_vol.volname;
        }

out:
        return ret;
}

int32_t
gf_cli3_1_get_volume (call_frame_t *frame, xlator_t *this,
                      void *data)
{
        gf1_cli_get_vol_req             req = {0,};
        int                             ret = 0;
        cli_cmd_volume_get_ctx_t        *ctx = NULL;
        dict_t                          *dict = NULL;

        if (!frame || !this || !data) {
                ret = -1;
                goto out;
        }

        ctx = data;
        req.flags = ctx->flags;

        dict = dict_new ();
        if (!dict)
                goto out;

        if (ctx->volname) {
                ret = dict_set_str (dict, "volname", ctx->volname);
                if (ret)
                        goto out;
        }

        ret = dict_allocate_and_serialize (dict,
                                           &req.dict.dict_val,
                                           (size_t *)&req.dict.dict_len);

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_GET_VOLUME, NULL,
                              gf_xdr_from_cli_get_vol_req,
                              this, gf_cli3_1_get_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}


int32_t
gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_create_vol_req  req = {0,};
        int                     ret = 0;
        dict_t                  *dict = NULL;
        cli_local_t             *local = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = dict_ref ((dict_t *)data);

        ret = dict_get_str (dict, "volname", &req.volname);

        if (ret)
                goto out;

        ret = dict_get_int32 (dict, "type", (int32_t *)&req.type);

        if (ret)
                goto out;

        ret = dict_get_int32 (dict, "count", &req.count);
        if (ret)
                goto out;

        ret = dict_allocate_and_serialize (dict,
                                           &req.bricks.bricks_val,
                                           (size_t *)&req.bricks.bricks_len);
        if (ret < 0) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "failed to get serialized length of dict");
                goto out;
        }

        local = cli_local_get ();

        if (local) {
                local->u.create_vol.dict = dict_ref (dict);
                frame->local = local;
        }

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_CREATE_VOLUME, NULL,
                              gf_xdr_from_cli_create_vol_req,
                              this, gf_cli3_1_create_volume_cbk);



out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        if (dict)
                dict_unref (dict);

        if (req.bricks.bricks_val) {
                GF_FREE (req.bricks.bricks_val);
        }

        return ret;
}

int32_t
gf_cli3_1_delete_volume (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_delete_vol_req  req = {0,};
        int                     ret = 0;
        cli_local_t             *local = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        local = cli_local_get ();

        if (local) {
                local->u.delete_vol.volname = data;
                frame->local = local;
        }

        req.volname = data;

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_DELETE_VOLUME, NULL,
                              gf_xdr_from_cli_delete_vol_req,
                              this, gf_cli3_1_delete_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_start_volume (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_start_vol_req   *req = NULL;
        int                     ret = 0;
        cli_local_t             *local = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        req = data;
        local = cli_local_get ();

        if (local) {
                local->u.start_vol.volname = req->volname;
                local->u.start_vol.flags = req->flags;
                frame->local = local;
        }

        ret = cli_cmd_submit (req, frame, cli_rpc_prog,
                              GLUSTER_CLI_START_VOLUME, NULL,
                              gf_xdr_from_cli_start_vol_req,
                              this, gf_cli3_1_start_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_stop_vol_req   req = {0,};
        int                    ret = 0;
        cli_local_t            *local = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        req = *((gf1_cli_stop_vol_req*)data);
        local = cli_local_get ();

        if (local) {
                local->u.stop_vol.volname = req.volname;
                local->u.stop_vol.flags = req.flags;
                frame->local = local;
        }

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_STOP_VOLUME, NULL,
                              gf_xdr_from_cli_stop_vol_req,
                              this, gf_cli3_1_stop_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_defrag_vol_req  req     = {0,};
        int                     ret     = 0;
        cli_local_t            *local   = NULL;
        char                   *volname = NULL;
        char                   *cmd_str = NULL;
        dict_t                 *dict    = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &volname);
        if (ret)
                gf_log ("", GF_LOG_DEBUG, "error");

        ret = dict_get_str (dict, "command", &cmd_str);
        if (ret) {
                gf_log ("", GF_LOG_DEBUG, "error");
                goto out;
        }

        if (strcmp (cmd_str, "start") == 0) {
                req.cmd = GF_DEFRAG_CMD_START;
                ret = dict_get_str (dict, "start-type", &cmd_str);
                if (!ret) {
                        if (strcmp (cmd_str, "fix-layout") == 0) {
                                req.cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX;
                        }
                        if (strcmp (cmd_str, "migrate-data") == 0) {
                                req.cmd = GF_DEFRAG_CMD_START_MIGRATE_DATA;
                        }
                }
                goto done;
        }
        if (strcmp (cmd_str, "stop") == 0) {
                req.cmd = GF_DEFRAG_CMD_STOP;
                goto done;
        }
        if (strcmp (cmd_str, "status") == 0) {
                req.cmd = GF_DEFRAG_CMD_STATUS;
        }

done:
        local = cli_local_get ();

        if (local) {
                local->u.defrag_vol.volname = gf_strdup (volname);
                local->u.defrag_vol.cmd = req.cmd;
                frame->local = local;
        }

        req.volname = volname;

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_DEFRAG_VOLUME, NULL,
                              gf_xdr_from_cli_defrag_vol_req,
                              this, gf_cli3_1_defrag_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_rename_volume (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_rename_vol_req  req = {0,};
        int                     ret = 0;
        dict_t                  *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "old-volname", &req.old_volname);

        if (ret)
                goto out;

        ret = dict_get_str (dict, "new-volname", &req.new_volname);

        if (ret)
                goto out;

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_RENAME_VOLUME, NULL,
                              gf_xdr_from_cli_rename_vol_req,
                              this, gf_cli3_1_rename_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_reset_volume (call_frame_t *frame, xlator_t *this, 
                        void *data)
{
        gf1_cli_reset_vol_req     req = {0,};
        int                     ret = 0;
        dict_t                  *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &req.volname);

        if (ret)
                goto out;

        ret = dict_allocate_and_serialize (dict,
                                           &req.dict.dict_val,
                                           (size_t *)&req.dict.dict_len);
        if (ret < 0) {
                gf_log (this->name, GF_LOG_ERROR,
                        "failed to get serialized length of dict");
                goto out;
        }


        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                               GLUSTER_CLI_RESET_VOLUME, NULL,
                               gf_xdr_from_cli_reset_vol_req,
                               this, gf_cli3_1_reset_volume_cbk);

out:
                gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_set_vol_req     req = {0,};
        int                     ret = 0;
        dict_t                  *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &req.volname);

        if (ret)
                goto out;

        ret = dict_allocate_and_serialize (dict,
                                           &req.dict.dict_val,
                                           (size_t *)&req.dict.dict_len);
        if (ret < 0) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "failed to get serialized length of dict");
                goto out;
        }


        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_SET_VOLUME, NULL,
                              gf_xdr_from_cli_set_vol_req,
                              this, gf_cli3_1_set_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_add_brick_req  req = {0,};
        int                     ret = 0;
        dict_t                  *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &req.volname);

        if (ret)
                goto out;

        ret = dict_get_int32 (dict, "count", &req.count);
        if (ret)
                goto out;


        ret = dict_allocate_and_serialize (dict,
                                           &req.bricks.bricks_val,
                                           (size_t *)&req.bricks.bricks_len);
        if (ret < 0) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "failed to get serialized length of dict");
                goto out;
        }

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_ADD_BRICK, NULL,
                              gf_xdr_from_cli_add_brick_req,
                              this, gf_cli3_1_add_brick_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        if (req.bricks.bricks_val) {
                GF_FREE (req.bricks.bricks_val);
        }

        return ret;
}

int32_t
gf_cli3_1_remove_brick (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_remove_brick_req  req = {0,};
        int                       ret = 0;
        dict_t                    *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &req.volname);

        if (ret)
                goto out;

        ret = dict_get_int32 (dict, "count", &req.count);

        if (ret)
                goto out;

        ret = dict_allocate_and_serialize (dict,
                                           &req.bricks.bricks_val,
                                           (size_t *)&req.bricks.bricks_len);
        if (ret < 0) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "failed to get serialized length of dict");
                goto out;
        }

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_REMOVE_BRICK, NULL,
                              gf_xdr_from_cli_remove_brick_req,
                              this, gf_cli3_1_remove_brick_cbk);


out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        if (req.bricks.bricks_val) {
                GF_FREE (req.bricks.bricks_val);
        }

        return ret;
}

int32_t
gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf1_cli_replace_brick_req   req        = {0,};
        int                         ret        = 0;
        cli_local_t                *local      = NULL;
        dict_t                     *dict       = NULL;
        char                       *src_brick  = NULL;
        char                       *dst_brick  = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

	dict = data;

        local = cli_local_get ();
        if (!local) {
                ret = -1;
                gf_log (this->name, GF_LOG_ERROR,
                        "Out of memory");
                goto out;
        }

        local->u.replace_brick.dict = dict_ref (dict);
        frame->local                = local;

        ret = dict_get_int32 (dict, "operation", (int32_t *)&req.op);
        if (ret) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "dict_get on operation failed");
                goto out;
        }
        ret = dict_get_str (dict, "volname", &req.volname);
        if (ret) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "dict_get on volname failed");
                goto out;
        }

        local->u.replace_brick.volname = gf_strdup (req.volname);
        if (!local->u.replace_brick.volname) {
                gf_log (this->name, GF_LOG_ERROR,
                        "Out of memory");
                ret = -1;
                goto out;
        }

        ret = dict_get_str (dict, "src-brick", &src_brick);
        if (ret) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "dict_get on src-brick failed");
                goto out;
        }

        ret = dict_get_str (dict, "dst-brick", &dst_brick);
        if (ret) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "dict_get on dst-brick failed");
                goto out;
        }

        gf_log (this->name, GF_LOG_DEBUG,
                "Recevied command replace-brick %s with "
                "%s with operation=%d", src_brick,
                dst_brick, req.op);


        ret = dict_allocate_and_serialize (dict,
                                           &req.bricks.bricks_val,
                                           (size_t *)&req.bricks.bricks_len);
        if (ret < 0) {
                gf_log (this->name, GF_LOG_DEBUG,
                        "failed to get serialized length of dict");
                goto out;
        }

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_REPLACE_BRICK, NULL,
                              gf_xdr_from_cli_replace_brick_req,
                              this, gf_cli3_1_replace_brick_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        if (req.bricks.bricks_val) {
                GF_FREE (req.bricks.bricks_val);
        }

        return ret;
}

int32_t
gf_cli3_1_log_filename (call_frame_t *frame, xlator_t *this,
                        void *data)
{
        gf1_cli_log_filename_req  req = {0,};
        int                       ret = 0;
        dict_t                   *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &req.volname);
        if (ret)
                goto out;

        ret = dict_get_str (dict, "brick", &req.brick);
        if (ret)
                req.brick = "";

        ret = dict_get_str (dict, "path", &req.path);
        if (ret)
                goto out;

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_LOG_FILENAME, NULL,
                              gf_xdr_from_cli_log_filename_req,
                              this, gf_cli3_1_log_filename_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}


int32_t
gf_cli3_1_log_locate (call_frame_t *frame, xlator_t *this,
                      void *data)
{
        gf1_cli_log_locate_req  req = {0,};
        int                     ret = 0;
        dict_t                 *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &req.volname);
        if (ret)
                goto out;

        ret = dict_get_str (dict, "brick", &req.brick);
        if (ret)
                req.brick = "";

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_LOG_LOCATE, NULL,
                              gf_xdr_from_cli_log_locate_req,
                              this, gf_cli3_1_log_locate_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_log_rotate (call_frame_t *frame, xlator_t *this,
                      void *data)
{
        gf1_cli_log_locate_req  req = {0,};
        int                       ret = 0;
        dict_t                   *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volname", &req.volname);
        if (ret)
                goto out;

        ret = dict_get_str (dict, "brick", &req.brick);
        if (ret)
                req.brick = "";

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_LOG_ROTATE, NULL,
                              gf_xdr_from_cli_log_rotate_req,
                              this, gf_cli3_1_log_rotate_cbk);


out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_sync_volume (call_frame_t *frame, xlator_t *this,
                       void *data)
{
        int               ret = 0;

        if (!frame || !this || !data) {
                ret = -1;
                goto out;
        }

        ret = cli_cmd_submit ((gf1_cli_sync_volume_req*)data, frame,
                              cli_rpc_prog, GLUSTER_CLI_SYNC_VOLUME,
                              NULL, gf_xdr_from_cli_sync_volume_req,
                              this, gf_cli3_1_sync_volume_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_getspec (call_frame_t *frame, xlator_t *this,
                         void *data)
{
        gf_getspec_req          req = {0,};
        int                     ret = 0;
        dict_t                  *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "volid", &req.key);
        if (ret)
                goto out;

        ret = cli_cmd_submit (&req, frame, &cli_handshake_prog,
                              GF_HNDSK_GETSPEC, NULL,
                              xdr_from_getspec_req,
                              this, gf_cli3_1_getspec_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int32_t
gf_cli3_1_pmap_b2p (call_frame_t *frame, xlator_t *this, void *data)
{
        pmap_port_by_brick_req  req = {0,};
        int                     ret = 0;
        dict_t                  *dict = NULL;

        if (!frame || !this ||  !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_get_str (dict, "brick", &req.brick);
        if (ret)
                goto out;

        ret = cli_cmd_submit (&req, frame, &cli_pmap_prog,
                              GF_PMAP_PORTBYBRICK, NULL,
                              xdr_from_pmap_port_by_brick_req,
                              this, gf_cli3_1_pmap_b2p_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

static int
gf_cli3_1_fsm_log_cbk (struct rpc_req *req, struct iovec *iov,
                       int count, void *myframe)
{
        gf1_cli_fsm_log_rsp        rsp   = {0,};
        int                        ret   = -1;
        dict_t                     *dict = NULL;
        int                        tr_count = 0;
        char                       key[256] = {0};
        int                        i = 0;
        char                       *old_state = NULL;
        char                       *new_state = NULL;
        char                       *event = NULL;
        char                       *time = NULL;

        if (-1 == req->rpc_status) {
                goto out;
        }

        ret = gf_xdr_to_cli_fsm_log_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR, "error");
                goto out;
        }

        if (rsp.op_ret) {
                if (strcmp (rsp.op_errstr, "")) {
                        cli_out (rsp.op_errstr);
                } else if (rsp.op_ret) {
                        cli_out ("fsm log unsuccessful");
                }
                ret = rsp.op_ret;
                goto out;
        }

        dict = dict_new ();
        if (!dict) {
                ret = -1;
                goto out;
        }

        ret = dict_unserialize (rsp.fsm_log.fsm_log_val,
                                rsp.fsm_log.fsm_log_len,
                                &dict);

        if (ret) {
                cli_out ("bad response");
                goto out;
        }

        ret = dict_get_int32 (dict, "count", &tr_count);
        if (tr_count)
                cli_out("number of transitions: %d", tr_count);
        else
                cli_out("No transitions");
        for (i = 0; i < tr_count; i++) {
                memset (key, 0, sizeof (key));
                snprintf (key, sizeof (key), "log%d-old-state", i);
                ret = dict_get_str (dict, key, &old_state);
                if (ret)
                        goto out;

                memset (key, 0, sizeof (key));
                snprintf (key, sizeof (key), "log%d-event", i);
                ret = dict_get_str (dict, key, &event);
                if (ret)
                        goto out;

                memset (key, 0, sizeof (key));
                snprintf (key, sizeof (key), "log%d-new-state", i);
                ret = dict_get_str (dict, key, &new_state);
                if (ret)
                        goto out;

                memset (key, 0, sizeof (key));
                snprintf (key, sizeof (key), "log%d-time", i);
                ret = dict_get_str (dict, key, &time);
                if (ret)
                        goto out;
                cli_out ("Old State: [%s]\n"
                         "New State: [%s]\n"
                         "Event    : [%s]\n"
                         "timestamp: [%s]\n", old_state, new_state, event, time);
        }

        ret = rsp.op_ret;

out:
        cli_cmd_broadcast_response (ret);
        return ret;
}

int32_t
gf_cli3_1_fsm_log (call_frame_t *frame, xlator_t *this, void *data)
{
        int                        ret = -1;
        gf1_cli_fsm_log_req        req = {0,};

        GF_ASSERT (frame);
        GF_ASSERT (this);
        GF_ASSERT (data);

        if (!frame || !this || !data)
                goto out;
        req.name = data;
        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_FSM_LOG, NULL,
                              gf_xdr_from_cli_fsm_log_req,
                              this, gf_cli3_1_fsm_log_cbk);

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}

int
gf_cli3_1_gsync_get_command (gf1_cli_gsync_set_rsp rsp)
{
        char  cmd[1024] = {0,};

        if (rsp.op_ret < 0)
                return 0;

        if (!rsp.gsync_prefix || !rsp.master || !rsp.slave)
                return -1;

        if (rsp.config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET) {
                if (!rsp.op_name)
                        return -1;

                snprintf (cmd, 1024, "%s/gsyncd %s %s --config-get %s ",
                          rsp.gsync_prefix, rsp.master, rsp.slave,
                          rsp.op_name);
                system (cmd);
                goto out;
        }
        if (rsp.config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL) {
                snprintf (cmd, 1024, "%s/gsyncd %s %s --config-get-all ",
                          rsp.gsync_prefix, rsp.master, rsp.slave);

                system (cmd);

                goto out;
        }
out:
        return 0;
}

int
gf_cli3_1_gsync_get_pid_file (char *pidfile, char *master, char *slave)
{
        int     ret      = -1;
        int     i        = 0;
        char    str[256] = {0, };

        GF_VALIDATE_OR_GOTO ("gsync", pidfile, out);
        GF_VALIDATE_OR_GOTO ("gsync", master, out);
        GF_VALIDATE_OR_GOTO ("gsync", slave, out);

        i = 0;
        //change '/' to '-'
        while (slave[i]) {
                (slave[i] == '/') ? (str[i] = '-') : (str[i] = slave[i]);
                i++;
        }

        ret = snprintf (pidfile, 1024, "/etc/glusterd/gsync/%s/%s.pid",
                        master, str);
        if (ret <= 0) {
                ret = -1;
                goto out;
        }

        ret = 0;
out:
        return ret;
}

/* status: 0 when gsync is running
 * -1 when not running
 */
int
gf_cli3_1_gsync_status (char *master, char *slave,
                        char *pidfile, int *status)
{
        int     ret             = -1;
        FILE    *file           = NULL;

        GF_VALIDATE_OR_GOTO ("gsync", master, out);
        GF_VALIDATE_OR_GOTO ("gsync", slave, out);
        GF_VALIDATE_OR_GOTO ("gsync", pidfile, out);
        GF_VALIDATE_OR_GOTO ("gsync", status, out);

        file = fopen (pidfile, "r+");
        if (file) {
                ret = lockf (fileno (file), F_TEST, 0);
                if (ret == 0) {
                        *status = -1;
                }
                else
                *status = 0;
        } else
                *status = -1;
        ret = 0;
out:
        return ret;
}

int
gf_cli3_1_start_gsync (char *master, char *slave)
{
        int32_t         ret     = -1;
        int32_t         status  = 0;
        char            cmd[1024] = {0,};
        char            pidfile[1024] = {0,};

        ret = gf_cli3_1_gsync_get_pid_file (pidfile, master, slave);
        if (ret == -1) {
                ret = -1;
                gf_log ("", GF_LOG_WARNING, "failed to construct the "
                        "pidfile string");
                goto out;
        }

        ret = gf_cli3_1_gsync_status (master, slave, pidfile, &status);
        if ((ret == 0 && status == 0)) {
                gf_log ("", GF_LOG_WARNING, "gsync %s:%s"
                        "already started", master, slave);

                cli_out ("gsyncd is already running");

                ret = -1;
                goto out;
        }

        unlink (pidfile);

        ret = snprintf (cmd, 1024, "mkdir -p /etc/glusterd/gsync/%s",
                        master);
        if (ret <= 0) {
                ret = -1;
                gf_log ("", GF_LOG_WARNING, "failed to construct the "
                        "pid path");
                goto out;
        }

        ret = system (cmd);
        if (ret == -1) {
                gf_log ("", GF_LOG_WARNING, "failed to create the "
                        "pid path for %s %s", master, slave);
                goto out;
        }

        memset (cmd, 0, sizeof (cmd));
        ret = snprintf (cmd, 1024, GSYNCD_PREFIX "/gsyncd %s %s "
                        "--config-set pid-file %s", master, slave, pidfile);
        if (ret <= 0) {
                ret = -1;
                gf_log ("", GF_LOG_WARNING, "failed to construct the  "
                        "config set command for %s %s", master, slave);
                goto out;
        }

        ret = system (cmd);
        if (ret == -1) {
                gf_log ("", GF_LOG_WARNING, "failed to set the pid "
                        "option for %s %s", master, slave);
                goto out;
        }

        memset (cmd, 0, sizeof (cmd));
        ret = snprintf (cmd, 1024, GSYNCD_PREFIX "/gsyncd "
                        "%s %s", master, slave);
        if (ret <= 0) {
                ret = -1;
                goto out;
        }

        ret = system (cmd);
        if (ret == -1)
                goto out;

        cli_out ("gsync started");
        ret = 0;

out:

        return ret;
}

int
gf_cli3_1_gsync_set_cbk (struct rpc_req *req, struct iovec *iov,
                         int count, void *myframe)
{
        int                     ret     = 0;
        gf1_cli_gsync_set_rsp   rsp     = {0, };

        if (req->rpc_status == -1) {
                ret = -1;
                goto out;
        }

        ret = gf_xdr_to_cli_gsync_set_rsp (*iov, &rsp);
        if (ret < 0) {
                gf_log ("", GF_LOG_ERROR,
                        "Unable to get response structure");
                goto out;
        }

        if (rsp.op_ret) {
                cli_out ("%s", rsp.op_errstr ? rsp.op_errstr :
                         "command unsuccessful");
                goto out;
        }
        else {
                if (rsp.type == GF_GSYNC_OPTION_TYPE_START)
                        ret = gf_cli3_1_start_gsync (rsp.master, rsp.slave);
                else if (rsp.config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL)
                        ret = gf_cli3_1_gsync_get_command (rsp);
                else
                        cli_out ("command executed successfully");
        }
out:
        ret = rsp.op_ret;

        cli_cmd_broadcast_response (ret);

        return ret;
}

int32_t
gf_cli3_1_gsync_set (call_frame_t *frame, xlator_t *this,
                     void *data)
{
        int                      ret    = 0;
        dict_t                  *dict   = NULL;
        gf1_cli_gsync_set_req    req;

        if (!frame || !this || !data) {
                ret = -1;
                goto out;
        }

        dict = data;

        ret = dict_allocate_and_serialize (dict,
                                           &req.dict.dict_val,
                                           (size_t *) &req.dict.dict_len);
        if (ret < 0) {
                gf_log (this->name, GF_LOG_ERROR,
                        "failed to serialize the data");

                goto out;
        }

        ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
                              GLUSTER_CLI_GSYNC_SET, NULL,
                              gf_xdr_from_cli_gsync_set_req,
                              this, gf_cli3_1_gsync_set_cbk);

out:
        return ret;
}


struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = {
        [GLUSTER_CLI_NULL]             = {"NULL", NULL },
        [GLUSTER_CLI_PROBE]            = {"PROBE_QUERY", gf_cli3_1_probe},
        [GLUSTER_CLI_DEPROBE]          = {"DEPROBE_QUERY", gf_cli3_1_deprobe},
        [GLUSTER_CLI_LIST_FRIENDS]     = {"LIST_FRIENDS", gf_cli3_1_list_friends},
        [GLUSTER_CLI_CREATE_VOLUME]    = {"CREATE_VOLUME", gf_cli3_1_create_volume},
        [GLUSTER_CLI_DELETE_VOLUME]    = {"DELETE_VOLUME", gf_cli3_1_delete_volume},
        [GLUSTER_CLI_START_VOLUME]     = {"START_VOLUME", gf_cli3_1_start_volume},
        [GLUSTER_CLI_STOP_VOLUME]      = {"STOP_VOLUME", gf_cli3_1_stop_volume},
        [GLUSTER_CLI_RENAME_VOLUME]    = {"RENAME_VOLUME", gf_cli3_1_rename_volume},
        [GLUSTER_CLI_DEFRAG_VOLUME]    = {"DEFRAG_VOLUME", gf_cli3_1_defrag_volume},
        [GLUSTER_CLI_GET_VOLUME]       = {"GET_VOLUME", gf_cli3_1_get_volume},
        [GLUSTER_CLI_GET_NEXT_VOLUME]  = {"GET_NEXT_VOLUME", gf_cli3_1_get_next_volume},
        [GLUSTER_CLI_SET_VOLUME]       = {"SET_VOLUME", gf_cli3_1_set_volume},
        [GLUSTER_CLI_ADD_BRICK]        = {"ADD_BRICK", gf_cli3_1_add_brick},
        [GLUSTER_CLI_REMOVE_BRICK]     = {"REMOVE_BRICK", gf_cli3_1_remove_brick},
        [GLUSTER_CLI_REPLACE_BRICK]    = {"REPLACE_BRICK", gf_cli3_1_replace_brick},
        [GLUSTER_CLI_LOG_FILENAME]     = {"LOG FILENAME", gf_cli3_1_log_filename},
        [GLUSTER_CLI_LOG_LOCATE]       = {"LOG LOCATE", gf_cli3_1_log_locate},
        [GLUSTER_CLI_LOG_ROTATE]       = {"LOG ROTATE", gf_cli3_1_log_rotate},
        [GLUSTER_CLI_GETSPEC]          = {"GETSPEC", gf_cli3_1_getspec},
        [GLUSTER_CLI_PMAP_PORTBYBRICK] = {"PMAP PORTBYBRICK", gf_cli3_1_pmap_b2p},
        [GLUSTER_CLI_SYNC_VOLUME]      = {"SYNC_VOLUME", gf_cli3_1_sync_volume},
        [GLUSTER_CLI_RESET_VOLUME]     = {"RESET_VOLUME", gf_cli3_1_reset_volume},
        [GLUSTER_CLI_FSM_LOG]          = {"FSM_LOG", gf_cli3_1_fsm_log},
        [GLUSTER_CLI_GSYNC_SET]        = {"GSYNC_SET", gf_cli3_1_gsync_set},
};

struct rpc_clnt_program cli_prog = {
        .progname  = "Gluster CLI",
        .prognum   = GLUSTER_CLI_PROGRAM,
        .progver   = GLUSTER_CLI_VERSION,
        .numproc   = GLUSTER_CLI_PROCCNT,
        .proctable = gluster_cli_actors,
};
eec6b6b53a0b'>xlators/protocol/client/src/saved-frames.h74
-rw-r--r--xlators/protocol/server/Makefile.am3
-rw-r--r--xlators/protocol/server/src/Makefile.am18
-rw-r--r--xlators/protocol/server/src/server-dentry.c413
-rw-r--r--xlators/protocol/server/src/server-helpers.c586
-rw-r--r--xlators/protocol/server/src/server-helpers.h77
-rw-r--r--xlators/protocol/server/src/server-protocol.c7984
-rw-r--r--xlators/protocol/server/src/server-protocol.h143
-rw-r--r--xlators/storage/Makefile.am3
-rw-r--r--xlators/storage/bdb/Makefile.am3
-rw-r--r--xlators/storage/bdb/src/Makefile.am18
-rw-r--r--xlators/storage/bdb/src/bctx.c394
-rw-r--r--xlators/storage/bdb/src/bdb-ll.c1455
-rw-r--r--xlators/storage/bdb/src/bdb.c3371
-rw-r--r--xlators/storage/bdb/src/bdb.h439
-rw-r--r--xlators/storage/posix/Makefile.am3
-rw-r--r--xlators/storage/posix/src/Makefile.am17
-rw-r--r--xlators/storage/posix/src/posix.c3715
-rw-r--r--xlators/storage/posix/src/posix.h110
-rw-r--r--xlators/storage/posix/src/xattr-cache.c521
-rw-r--r--xlators/storage/posix/src/xattr-cache.h65
420 files changed, 164055 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 000000000..d9abdcd07
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,3 @@
+CORE TEAM:
+* Please visit http://www.gluster.org/core-team.php for complete list
+ of contributors.
diff --git a/COPYING b/COPYING
new file mode 100644
index 000000000..94a9ed024
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 000000000..800cdf327
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1 @@
+ChangeLog is maintained by "tla changelog".
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 000000000..88e28999d
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,32 @@
+Installation Instructions
+*************************
+
+Run ./configure after untaring the package.
+
+ bash# ./configure
+ GlusterFS configure summary
+ ===========================
+ FUSE client : yes
+ Infiniband verbs : yes
+ epoll IO multiplex : yes
+ Berkeley-DB : yes
+ libglusterfsclient : yes
+ mod_glusterfs : yes
+ argp-standalone : no
+
+The configure summary will tell you what all components will be built with
+GlusterFS. Other than 'argp-standalone' if something else says 'no', that
+feature in GlusterFS will not be built. 'argp-standalone' package will only
+be used if the system doesn't have a proper argp package installed.
+
+Now just run 'make' and later run 'make install' to install the package.
+
+ bash# make
+ bash# make install
+
+Installation complete :-)
+
+ bash# glusterfs --version
+
+Make sure your version is the latest from the release, and the one you
+just installed :-)
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 000000000..6c7988a1c
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,15 @@
+EXTRA_DIST = autogen.sh COPYING INSTALL README AUTHORS THANKS NEWS glusterfs.spec
+
+SUBDIRS = argp-standalone libglusterfs $(LIBGLUSTERFSCLIENT_SUBDIR) xlators scheduler transport auth glusterfsd $(MOD_GLUSTERFS_SUBDIR) $(GF_BOOSTER_SUBDIR) doc extras
+
+CLEANFILES =
+
+tlaclean: distclean
+ find . -name Makefile.in -exec rm -f {} \;
+ find . -name Makefile -exec rm -f {} \;
+ find . -name mount.glusterfs -exec rm -f {} \;
+ rm -fr autom4te.cache
+ rm -f missing aclocal.m4 config.h.in config.guess config.sub ltmain.sh install-sh configure depcomp
+ rm -fr argp-standalone/autom4te.cache
+ rm -f argp-standalone/aclocal.m4 argp-standalone/config.h.in argp-standalone/configure argp-standalone/depcomp argp-standalone/install-sh argp-standalone/missing
+ rm -fr mod_glusterfs/apache-1.3/src/.deps transport/ib-verbs/src/.deps
diff --git a/NEWS b/NEWS
new file mode 100644
index 000000000..39a37cd93
--- /dev/null
+++ b/NEWS
@@ -0,0 +1 @@
+Please visit http://www.gluster.org/news.php for news updates.
diff --git a/README b/README
new file mode 100644
index 000000000..8c6cb42ce
--- /dev/null
+++ b/README
@@ -0,0 +1,9 @@
+GlusterFS is a powerful network/cluster filesystem. Posix compliant. You
+can keep scaling your storage beyond peta bytes as your demand increases.
+
+GlusterFS natively supports Infiniband verbs calls to do RDMA between remote
+machine to get the maximum I/O throughput.
+
+It has on the fly replication and striping as inbuilt options.
+
+Please visit http://www.gluster.org/glusterfs.php for more info.
diff --git a/THANKS b/THANKS
new file mode 100644
index 000000000..5e86b41a7
--- /dev/null
+++ b/THANKS
@@ -0,0 +1,3 @@
+
+* http://www.gluster.org/glusterfs-thanks.php
+
diff --git a/argp-standalone/Makefile.am b/argp-standalone/Makefile.am
new file mode 100644
index 000000000..4775d4876
--- /dev/null
+++ b/argp-standalone/Makefile.am
@@ -0,0 +1,38 @@
+# From glibc
+
+# Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public
+# License along with the GNU C Library; see the file COPYING.LIB. If
+# not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+AUTOMAKE_OPTIONS = foreign
+SUBDIRS = .
+
+LIBOBJS = @LIBOBJS@
+
+noinst_LIBRARIES = libargp.a
+
+noinst_HEADERS = argp.h argp-fmtstream.h argp-namefrob.h
+
+EXTRA_DIST = mempcpy.c strchrnul.c strndup.c strcasecmp.c vsnprintf.c autogen.sh
+
+# Leaves out argp-fs-xinl.c and argp-xinl.c
+libargp_a_SOURCES = argp-ba.c argp-eexst.c argp-fmtstream.c \
+ argp-help.c argp-parse.c argp-pv.c \
+ argp-pvh.c
+
+libargp_a_LIBADD = $(LIBOBJS)
+
+
diff --git a/argp-standalone/acinclude.m4 b/argp-standalone/acinclude.m4
new file mode 100644
index 000000000..fb61e957d
--- /dev/null
+++ b/argp-standalone/acinclude.m4
@@ -0,0 +1,1084 @@
+dnl Try to detect the type of the third arg to getsockname() et al
+AC_DEFUN([LSH_TYPE_SOCKLEN_T],
+[AH_TEMPLATE([socklen_t], [Length type used by getsockopt])
+AC_CACHE_CHECK([for socklen_t in sys/socket.h], ac_cv_type_socklen_t,
+[AC_EGREP_HEADER(socklen_t, sys/socket.h,
+ [ac_cv_type_socklen_t=yes], [ac_cv_type_socklen_t=no])])
+if test $ac_cv_type_socklen_t = no; then
+ AC_MSG_CHECKING(for AIX)
+ AC_EGREP_CPP(yes, [
+#ifdef _AIX
+ yes
+#endif
+],[
+AC_MSG_RESULT(yes)
+AC_DEFINE(socklen_t, size_t)
+],[
+AC_MSG_RESULT(no)
+AC_DEFINE(socklen_t, int)
+])
+fi
+])
+
+dnl Choose cc flags for compiling position independent code
+AC_DEFUN([LSH_CCPIC],
+[AC_MSG_CHECKING(CCPIC)
+AC_CACHE_VAL(lsh_cv_sys_ccpic,[
+ if test -z "$CCPIC" ; then
+ if test "$GCC" = yes ; then
+ case `uname -sr` in
+ BSD/OS*)
+ case `uname -r` in
+ 4.*) CCPIC="-fPIC";;
+ *) CCPIC="";;
+ esac
+ ;;
+ Darwin*)
+ CCPIC="-fPIC"
+ ;;
+ SunOS\ 5.*)
+ # Could also use -fPIC, if there are a large number of symbol reference
+ CCPIC="-fPIC"
+ ;;
+ CYGWIN*)
+ CCPIC=""
+ ;;
+ *)
+ CCPIC="-fpic"
+ ;;
+ esac
+ else
+ case `uname -sr` in
+ Darwin*)
+ CCPIC="-fPIC"
+ ;;
+ IRIX*)
+ CCPIC="-share"
+ ;;
+ hp*|HP*) CCPIC="+z"; ;;
+ FreeBSD*) CCPIC="-fpic";;
+ SCO_SV*) CCPIC="-KPIC -dy -Bdynamic";;
+ UnixWare*|OpenUNIX*) CCPIC="-KPIC -dy -Bdynamic";;
+ Solaris*) CCPIC="-KPIC -Bdynamic";;
+ Windows_NT*) CCPIC="-shared" ;;
+ esac
+ fi
+ fi
+ OLD_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $CCPIC"
+ AC_TRY_COMPILE([], [exit(0);],
+ lsh_cv_sys_ccpic="$CCPIC", lsh_cv_sys_ccpic='')
+ CFLAGS="$OLD_CFLAGS"
+])
+CCPIC="$lsh_cv_sys_ccpic"
+AC_MSG_RESULT($CCPIC)
+AC_SUBST([CCPIC])])
+
+dnl LSH_PATH_ADD(path-id, directory)
+AC_DEFUN([LSH_PATH_ADD],
+[AC_MSG_CHECKING($2)
+ac_exists=no
+if test -d "$2/." ; then
+ ac_real_dir=`cd $2 && pwd`
+ if test -n "$ac_real_dir" ; then
+ ac_exists=yes
+ for old in $1_REAL_DIRS ; do
+ ac_found=no
+ if test x$ac_real_dir = x$old ; then
+ ac_found=yes;
+ break;
+ fi
+ done
+ if test $ac_found = yes ; then
+ AC_MSG_RESULT(already added)
+ else
+ AC_MSG_RESULT(added)
+ # LDFLAGS="$LDFLAGS -L $2"
+ $1_REAL_DIRS="$ac_real_dir [$]$1_REAL_DIRS"
+ $1_DIRS="$2 [$]$1_DIRS"
+ fi
+ fi
+fi
+if test $ac_exists = no ; then
+ AC_MSG_RESULT(not found)
+fi
+])
+
+dnl LSH_RPATH_ADD(dir)
+AC_DEFUN([LSH_RPATH_ADD], [LSH_PATH_ADD(RPATH_CANDIDATE, $1)])
+
+dnl LSH_RPATH_INIT(candidates)
+AC_DEFUN([LSH_RPATH_INIT],
+[AC_MSG_CHECKING([for -R flag])
+RPATHFLAG=''
+case `uname -sr` in
+ OSF1\ V4.*)
+ RPATHFLAG="-rpath "
+ ;;
+ IRIX\ 6.*)
+ RPATHFLAG="-rpath "
+ ;;
+ IRIX\ 5.*)
+ RPATHFLAG="-rpath "
+ ;;
+ SunOS\ 5.*)
+ if test "$TCC" = "yes"; then
+ # tcc doesn't know about -R
+ RPATHFLAG="-Wl,-R,"
+ else
+ RPATHFLAG=-R
+ fi
+ ;;
+ Linux\ 2.*)
+ RPATHFLAG="-Wl,-rpath,"
+ ;;
+ *)
+ :
+ ;;
+esac
+
+if test x$RPATHFLAG = x ; then
+ AC_MSG_RESULT(none)
+else
+ AC_MSG_RESULT([using $RPATHFLAG])
+fi
+
+RPATH_CANDIDATE_REAL_DIRS=''
+RPATH_CANDIDATE_DIRS=''
+
+AC_MSG_RESULT([Searching for libraries])
+
+for d in $1 ; do
+ LSH_RPATH_ADD($d)
+done
+])
+
+dnl Try to execute a main program, and if it fails, try adding some
+dnl -R flag.
+dnl LSH_RPATH_FIX
+AC_DEFUN([LSH_RPATH_FIX],
+[if test $cross_compiling = no -a "x$RPATHFLAG" != x ; then
+ ac_success=no
+ AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
+ ac_success=yes, ac_success=no, :)
+
+ if test $ac_success = no ; then
+ AC_MSG_CHECKING([Running simple test program failed. Trying -R flags])
+dnl echo RPATH_CANDIDATE_DIRS = $RPATH_CANDIDATE_DIRS
+ ac_remaining_dirs=''
+ ac_rpath_save_LDFLAGS="$LDFLAGS"
+ for d in $RPATH_CANDIDATE_DIRS ; do
+ if test $ac_success = yes ; then
+ ac_remaining_dirs="$ac_remaining_dirs $d"
+ else
+ LDFLAGS="$RPATHFLAG$d $LDFLAGS"
+dnl echo LDFLAGS = $LDFLAGS
+ AC_TRY_RUN([int main(int argc, char **argv) { return 0; }],
+ [ac_success=yes
+ ac_rpath_save_LDFLAGS="$LDFLAGS"
+ AC_MSG_RESULT([adding $RPATHFLAG$d])
+ ],
+ [ac_remaining_dirs="$ac_remaining_dirs $d"], :)
+ LDFLAGS="$ac_rpath_save_LDFLAGS"
+ fi
+ done
+ RPATH_CANDIDATE_DIRS=$ac_remaining_dirs
+ fi
+ if test $ac_success = no ; then
+ AC_MSG_RESULT(failed)
+ fi
+fi
+])
+
+dnl Like AC_CHECK_LIB, but uses $KRB_LIBS rather than $LIBS.
+dnl LSH_CHECK_KRB_LIB(LIBRARY, FUNCTION, [, ACTION-IF-FOUND [,
+dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
+
+AC_DEFUN([LSH_CHECK_KRB_LIB],
+[AC_CHECK_LIB([$1], [$2],
+ ifelse([$3], ,
+ [[ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
+ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
+ AC_DEFINE_UNQUOTED($ac_tr_lib)
+ KRB_LIBS="-l$1 $KRB_LIBS"
+ ]], [$3]),
+ ifelse([$4], , , [$4
+])dnl
+, [$5 $KRB_LIBS])
+])
+
+dnl LSH_LIB_ARGP(ACTION-IF-OK, ACTION-IF-BAD)
+AC_DEFUN([LSH_LIB_ARGP],
+[ ac_argp_save_LIBS="$LIBS"
+ ac_argp_save_LDFLAGS="$LDFLAGS"
+ ac_argp_ok=no
+ # First check if we can link with argp.
+ AC_SEARCH_LIBS(argp_parse, argp,
+ [ LSH_RPATH_FIX
+ AC_CACHE_CHECK([for working argp],
+ lsh_cv_lib_argp_works,
+ [ AC_TRY_RUN(
+[#include <argp.h>
+#include <stdlib.h>
+
+static const struct argp_option
+options[] =
+{
+ { NULL, 0, NULL, 0, NULL, 0 }
+};
+
+struct child_state
+{
+ int n;
+};
+
+static error_t
+child_parser(int key, char *arg, struct argp_state *state)
+{
+ struct child_state *input = (struct child_state *) state->input;
+
+ switch(key)
+ {
+ default:
+ return ARGP_ERR_UNKNOWN;
+ case ARGP_KEY_END:
+ if (!input->n)
+ input->n = 1;
+ break;
+ }
+ return 0;
+}
+
+const struct argp child_argp =
+{
+ options,
+ child_parser,
+ NULL, NULL, NULL, NULL, NULL
+};
+
+struct main_state
+{
+ struct child_state child;
+ int m;
+};
+
+static error_t
+main_parser(int key, char *arg, struct argp_state *state)
+{
+ struct main_state *input = (struct main_state *) state->input;
+
+ switch(key)
+ {
+ default:
+ return ARGP_ERR_UNKNOWN;
+ case ARGP_KEY_INIT:
+ state->child_inputs[0] = &input->child;
+ break;
+ case ARGP_KEY_END:
+ if (!input->m)
+ input->m = input->child.n;
+
+ break;
+ }
+ return 0;
+}
+
+static const struct argp_child
+main_children[] =
+{
+ { &child_argp, 0, "", 0 },
+ { NULL, 0, NULL, 0}
+};
+
+static const struct argp
+main_argp =
+{ options, main_parser,
+ NULL,
+ NULL,
+ main_children,
+ NULL, NULL
+};
+
+int main(int argc, char **argv)
+{
+ struct main_state input = { { 0 }, 0 };
+ char *v[2] = { "foo", NULL };
+
+ argp_parse(&main_argp, 1, v, 0, NULL, &input);
+
+ if ( (input.m == 1) && (input.child.n == 1) )
+ return 0;
+ else
+ return 1;
+}
+], lsh_cv_lib_argp_works=yes,
+ lsh_cv_lib_argp_works=no,
+ lsh_cv_lib_argp_works=no)])
+
+ if test x$lsh_cv_lib_argp_works = xyes ; then
+ ac_argp_ok=yes
+ else
+ # Reset link flags
+ LIBS="$ac_argp_save_LIBS"
+ LDFLAGS="$ac_argp_save_LDFLAGS"
+ fi])
+
+ if test x$ac_argp_ok = xyes ; then
+ ifelse([$1],, true, [$1])
+ else
+ ifelse([$2],, true, [$2])
+ fi
+])
+
+dnl LSH_GCC_ATTRIBUTES
+dnl Check for gcc's __attribute__ construction
+
+AC_DEFUN([LSH_GCC_ATTRIBUTES],
+[AC_CACHE_CHECK(for __attribute__,
+ lsh_cv_c_attribute,
+[ AC_TRY_COMPILE([
+#include <stdlib.h>
+],
+[
+static void foo(void) __attribute__ ((noreturn));
+
+static void __attribute__ ((noreturn))
+foo(void)
+{
+ exit(1);
+}
+],
+lsh_cv_c_attribute=yes,
+lsh_cv_c_attribute=no)])
+
+AH_TEMPLATE([HAVE_GCC_ATTRIBUTE], [Define if the compiler understands __attribute__])
+if test "x$lsh_cv_c_attribute" = "xyes"; then
+ AC_DEFINE(HAVE_GCC_ATTRIBUTE)
+fi
+
+AH_BOTTOM(
+[#if __GNUC__ || HAVE_GCC_ATTRIBUTE
+# define NORETURN __attribute__ ((__noreturn__))
+# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a)))
+# define UNUSED __attribute__ ((__unused__))
+#else
+# define NORETURN
+# define PRINTF_STYLE(f, a)
+# define UNUSED
+#endif
+])])
+
+AC_DEFUN([LSH_GCC_FUNCTION_NAME],
+[# Check for gcc's __FUNCTION__ variable
+AH_TEMPLATE([HAVE_GCC_FUNCTION],
+ [Define if the compiler understands __FUNCTION__])
+AH_BOTTOM(
+[#if HAVE_GCC_FUNCTION
+# define FUNCTION_NAME __FUNCTION__
+#else
+# define FUNCTION_NAME "Unknown"
+#endif
+])
+
+AC_CACHE_CHECK(for __FUNCTION__,
+ lsh_cv_c_FUNCTION,
+ [ AC_TRY_COMPILE(,
+ [ #if __GNUC__ == 3
+ # error __FUNCTION__ is broken in gcc-3
+ #endif
+ void foo(void) { char c = __FUNCTION__[0]; } ],
+ lsh_cv_c_FUNCTION=yes,
+ lsh_cv_c_FUNCTION=no)])
+
+if test "x$lsh_cv_c_FUNCTION" = "xyes"; then
+ AC_DEFINE(HAVE_GCC_FUNCTION)
+fi
+])
+
+# Check for alloca, and include the standard blurb in config.h
+AC_DEFUN([LSH_FUNC_ALLOCA],
+[AC_FUNC_ALLOCA
+AC_CHECK_HEADERS([malloc.h])
+AH_BOTTOM(
+[/* AIX requires this to be the first thing in the file. */
+#ifndef __GNUC__
+# if HAVE_ALLOCA_H
+# include <alloca.h>
+# else
+# ifdef _AIX
+ #pragma alloca
+# else
+# ifndef alloca /* predefined by HP cc +Olibcalls */
+char *alloca ();
+# endif
+# endif
+# endif
+#else /* defined __GNUC__ */
+# if HAVE_ALLOCA_H
+# include <alloca.h>
+# endif
+#endif
+/* Needed for alloca on windows */
+#if HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+])])
+
+AC_DEFUN([LSH_FUNC_STRERROR],
+[AC_CHECK_FUNCS(strerror)
+AH_BOTTOM(
+[#if HAVE_STRERROR
+#define STRERROR strerror
+#else
+#define STRERROR(x) (sys_errlist[x])
+#endif
+])])
+
+AC_DEFUN([LSH_FUNC_STRSIGNAL],
+[AC_CHECK_FUNCS(strsignal)
+AC_CHECK_DECLS([sys_siglist, _sys_siglist])
+AH_BOTTOM(
+[#if HAVE_STRSIGNAL
+# define STRSIGNAL strsignal
+#else /* !HAVE_STRSIGNAL */
+# if HAVE_DECL_SYS_SIGLIST
+# define STRSIGNAL(x) (sys_siglist[x])
+# else
+# if HAVE_DECL__SYS_SIGLIST
+# define STRSIGNAL(x) (_sys_siglist[x])
+# else
+# define STRSIGNAL(x) "Unknown signal"
+# if __GNUC__
+# warning Using dummy STRSIGNAL
+# endif
+# endif
+# endif
+#endif /* !HAVE_STRSIGNAL */
+])])
+
+dnl LSH_MAKE_CONDITIONAL(symbol, test)
+AC_DEFUN([LSH_MAKE_CONDITIONAL],
+[if $2 ; then
+ IF_$1=''
+ UNLESS_$1='# '
+else
+ IF_$1='# '
+ UNLESS_$1=''
+fi
+AC_SUBST(IF_$1)
+AC_SUBST(UNLESS_$1)])
+
+dnl LSH_DEPENDENCY_TRACKING
+
+dnl Defines compiler flags DEP_FLAGS to generate dependency
+dnl information, and DEP_PROCESS that is any shell commands needed for
+dnl massaging the dependency information further. Dependencies are
+dnl generated as a side effect of compilation. Dependency files
+dnl themselves are not treated as targets.
+
+AC_DEFUN([LSH_DEPENDENCY_TRACKING],
+[AC_ARG_ENABLE(dependency_tracking,
+ AC_HELP_STRING([--disable-dependency-tracking],
+ [Disable dependency tracking. Dependency tracking doesn't work with BSD make]),,
+ [enable_dependency_tracking=yes])
+
+DEP_FLAGS=''
+DEP_PROCESS='true'
+if test x$enable_dependency_tracking = xyes ; then
+ if test x$GCC = xyes ; then
+ gcc_version=`gcc --version | head -1`
+ case "$gcc_version" in
+ 2.*|*[[!0-9.]]2.*)
+ enable_dependency_tracking=no
+ AC_MSG_WARN([Dependency tracking disabled, gcc-3.x is needed])
+ ;;
+ *)
+ DEP_FLAGS='-MT $[]@ -MD -MP -MF $[]@.d'
+ DEP_PROCESS='true'
+ ;;
+ esac
+ else
+ enable_dependency_tracking=no
+ AC_MSG_WARN([Dependency tracking disabled])
+ fi
+fi
+
+if test x$enable_dependency_tracking = xyes ; then
+ DEP_INCLUDE='include '
+else
+ DEP_INCLUDE='# '
+fi
+
+AC_SUBST([DEP_INCLUDE])
+AC_SUBST([DEP_FLAGS])
+AC_SUBST([DEP_PROCESS])])
+
+dnl @synopsis AX_CREATE_STDINT_H [( HEADER-TO-GENERATE [, HEADERS-TO-CHECK])]
+dnl
+dnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires the
+dnl existence of an include file <stdint.h> that defines a set of
+dnl typedefs, especially uint8_t,int32_t,uintptr_t.
+dnl Many older installations will not provide this file, but some will
+dnl have the very same definitions in <inttypes.h>. In other enviroments
+dnl we can use the inet-types in <sys/types.h> which would define the
+dnl typedefs int8_t and u_int8_t respectivly.
+dnl
+dnl This macros will create a local "_stdint.h" or the headerfile given as
+dnl an argument. In many cases that file will just "#include <stdint.h>"
+dnl or "#include <inttypes.h>", while in other environments it will provide
+dnl the set of basic 'stdint's definitions/typedefs:
+dnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t
+dnl int_least32_t.. int_fast32_t.. intmax_t
+dnl which may or may not rely on the definitions of other files,
+dnl or using the AC_CHECK_SIZEOF macro to determine the actual
+dnl sizeof each type.
+dnl
+dnl if your header files require the stdint-types you will want to create an
+dnl installable file mylib-int.h that all your other installable header
+dnl may include. So if you have a library package named "mylib", just use
+dnl AX_CREATE_STDINT_H(mylib-int.h)
+dnl in configure.ac and go to install that very header file in Makefile.am
+dnl along with the other headers (mylib.h) - and the mylib-specific headers
+dnl can simply use "#include <mylib-int.h>" to obtain the stdint-types.
+dnl
+dnl Remember, if the system already had a valid <stdint.h>, the generated
+dnl file will include it directly. No need for fuzzy HAVE_STDINT_H things...
+dnl
+dnl @, (status: used on new platforms) (see http://ac-archive.sf.net/gstdint/)
+dnl @version $Id: acinclude.m4,v 1.27 2004/11/23 21:27:35 nisse Exp $
+dnl @author Guido Draheim <guidod@gmx.de>
+
+AC_DEFUN([AX_CREATE_STDINT_H],
+[# ------ AX CREATE STDINT H -------------------------------------
+AC_MSG_CHECKING([for stdint types])
+ac_stdint_h=`echo ifelse($1, , _stdint.h, $1)`
+# try to shortcircuit - if the default include path of the compiler
+# can find a "stdint.h" header then we assume that all compilers can.
+AC_CACHE_VAL([ac_cv_header_stdint_t],[
+old_CXXFLAGS="$CXXFLAGS" ; CXXFLAGS=""
+old_CPPFLAGS="$CPPFLAGS" ; CPPFLAGS=""
+old_CFLAGS="$CFLAGS" ; CFLAGS=""
+AC_TRY_COMPILE([#include <stdint.h>],[int_least32_t v = 0;],
+[ac_cv_stdint_result="(assuming C99 compatible system)"
+ ac_cv_header_stdint_t="stdint.h"; ],
+[ac_cv_header_stdint_t=""])
+CXXFLAGS="$old_CXXFLAGS"
+CPPFLAGS="$old_CPPFLAGS"
+CFLAGS="$old_CFLAGS" ])
+
+v="... $ac_cv_header_stdint_h"
+if test "$ac_stdint_h" = "stdint.h" ; then
+ AC_MSG_RESULT([(are you sure you want them in ./stdint.h?)])
+elif test "$ac_stdint_h" = "inttypes.h" ; then
+ AC_MSG_RESULT([(are you sure you want them in ./inttypes.h?)])
+elif test "_$ac_cv_header_stdint_t" = "_" ; then
+ AC_MSG_RESULT([(putting them into $ac_stdint_h)$v])
+else
+ ac_cv_header_stdint="$ac_cv_header_stdint_t"
+ AC_MSG_RESULT([$ac_cv_header_stdint (shortcircuit)])
+fi
+
+if test "_$ac_cv_header_stdint_t" = "_" ; then # can not shortcircuit..
+
+dnl .....intro message done, now do a few system checks.....
+dnl btw, all CHECK_TYPE macros do automatically "DEFINE" a type, therefore
+dnl we use the autoconf implementation detail _AC CHECK_TYPE_NEW instead
+
+inttype_headers=`echo $2 | sed -e 's/,/ /g'`
+
+ac_cv_stdint_result="(no helpful system typedefs seen)"
+AC_CACHE_CHECK([for stdint uintptr_t], [ac_cv_header_stdint_x],[
+ ac_cv_header_stdint_x="" # the 1997 typedefs (inttypes.h)
+ AC_MSG_RESULT([(..)])
+ for i in stdint.h inttypes.h sys/inttypes.h $inttype_headers ; do
+ unset ac_cv_type_uintptr_t
+ unset ac_cv_type_uint64_t
+ _AC_CHECK_TYPE_NEW(uintptr_t,[ac_cv_header_stdint_x=$i],dnl
+ continue,[#include <$i>])
+ AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
+ ac_cv_stdint_result="(seen uintptr_t$and64 in $i)"
+ break;
+ done
+ AC_MSG_CHECKING([for stdint uintptr_t])
+ ])
+
+if test "_$ac_cv_header_stdint_x" = "_" ; then
+AC_CACHE_CHECK([for stdint uint32_t], [ac_cv_header_stdint_o],[
+ ac_cv_header_stdint_o="" # the 1995 typedefs (sys/inttypes.h)
+ AC_MSG_RESULT([(..)])
+ for i in inttypes.h sys/inttypes.h stdint.h $inttype_headers ; do
+ unset ac_cv_type_uint32_t
+ unset ac_cv_type_uint64_t
+ AC_CHECK_TYPE(uint32_t,[ac_cv_header_stdint_o=$i],dnl
+ continue,[#include <$i>])
+ AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
+ ac_cv_stdint_result="(seen uint32_t$and64 in $i)"
+ break;
+ done
+ AC_MSG_CHECKING([for stdint uint32_t])
+ ])
+fi
+
+if test "_$ac_cv_header_stdint_x" = "_" ; then
+if test "_$ac_cv_header_stdint_o" = "_" ; then
+AC_CACHE_CHECK([for stdint u_int32_t], [ac_cv_header_stdint_u],[
+ ac_cv_header_stdint_u="" # the BSD typedefs (sys/types.h)
+ AC_MSG_RESULT([(..)])
+ for i in sys/types.h inttypes.h sys/inttypes.h $inttype_headers ; do
+ unset ac_cv_type_u_int32_t
+ unset ac_cv_type_u_int64_t
+ AC_CHECK_TYPE(u_int32_t,[ac_cv_header_stdint_u=$i],dnl
+ continue,[#include <$i>])
+ AC_CHECK_TYPE(u_int64_t,[and64="/u_int64_t"],[and64=""],[#include<$i>])
+ ac_cv_stdint_result="(seen u_int32_t$and64 in $i)"
+ break;
+ done
+ AC_MSG_CHECKING([for stdint u_int32_t])
+ ])
+fi fi
+
+dnl if there was no good C99 header file, do some typedef checks...
+if test "_$ac_cv_header_stdint_x" = "_" ; then
+ AC_MSG_CHECKING([for stdint datatype model])
+ AC_MSG_RESULT([(..)])
+ AC_CHECK_SIZEOF(char)
+ AC_CHECK_SIZEOF(short)
+ AC_CHECK_SIZEOF(int)
+ AC_CHECK_SIZEOF(long)
+ AC_CHECK_SIZEOF(void*)
+ ac_cv_stdint_char_model=""
+ ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_char"
+ ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_short"
+ ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_int"
+ ac_cv_stdint_long_model=""
+ ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_int"
+ ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_long"
+ ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_voidp"
+ name="$ac_cv_stdint_long_model"
+ case "$ac_cv_stdint_char_model/$ac_cv_stdint_long_model" in
+ 122/242) name="$name, IP16 (standard 16bit machine)" ;;
+ 122/244) name="$name, LP32 (standard 32bit mac/win)" ;;
+ 122/*) name="$name (unusual int16 model)" ;;
+ 124/444) name="$name, ILP32 (standard 32bit unixish)" ;;
+ 124/488) name="$name, LP64 (standard 64bit unixish)" ;;
+ 124/448) name="$name, LLP64 (unusual 64bit unixish)" ;;
+ 124/*) name="$name (unusual int32 model)" ;;
+ 128/888) name="$name, ILP64 (unusual 64bit numeric)" ;;
+ 128/*) name="$name (unusual int64 model)" ;;
+ 222/*|444/*) name="$name (unusual dsptype)" ;;
+ *) name="$name (very unusal model)" ;;
+ esac
+ AC_MSG_RESULT([combined for stdint datatype model... $name])
+fi
+
+if test "_$ac_cv_header_stdint_x" != "_" ; then
+ ac_cv_header_stdint="$ac_cv_header_stdint_x"
+elif test "_$ac_cv_header_stdint_o" != "_" ; then
+ ac_cv_header_stdint="$ac_cv_header_stdint_o"
+elif test "_$ac_cv_header_stdint_u" != "_" ; then
+ ac_cv_header_stdint="$ac_cv_header_stdint_u"
+else
+ ac_cv_header_stdint="stddef.h"
+fi
+
+AC_MSG_CHECKING([for extra inttypes in chosen header])
+AC_MSG_RESULT([($ac_cv_header_stdint)])
+dnl see if int_least and int_fast types are present in _this_ header.
+unset ac_cv_type_int_least32_t
+unset ac_cv_type_int_fast32_t
+AC_CHECK_TYPE(int_least32_t,,,[#include <$ac_cv_header_stdint>])
+AC_CHECK_TYPE(int_fast32_t,,,[#include<$ac_cv_header_stdint>])
+AC_CHECK_TYPE(intmax_t,,,[#include <$ac_cv_header_stdint>])
+
+fi # shortcircut to system "stdint.h"
+# ------------------ PREPARE VARIABLES ------------------------------
+if test "$GCC" = "yes" ; then
+ac_cv_stdint_message="using gnu compiler "`$CC --version | head -1`
+else
+ac_cv_stdint_message="using $CC"
+fi
+
+AC_MSG_RESULT([make use of $ac_cv_header_stdint in $ac_stdint_h dnl
+$ac_cv_stdint_result])
+
+# ----------------- DONE inttypes.h checks START header -------------
+AC_CONFIG_COMMANDS([$ac_stdint_h],[
+AC_MSG_NOTICE(creating $ac_stdint_h : $_ac_stdint_h)
+ac_stdint=$tmp/_stdint.h
+
+echo "#ifndef" $_ac_stdint_h >$ac_stdint
+echo "#define" $_ac_stdint_h "1" >>$ac_stdint
+echo "#ifndef" _GENERATED_STDINT_H >>$ac_stdint
+echo "#define" _GENERATED_STDINT_H '"'$PACKAGE $VERSION'"' >>$ac_stdint
+echo "/* generated $ac_cv_stdint_message */" >>$ac_stdint
+if test "_$ac_cv_header_stdint_t" != "_" ; then
+echo "#define _STDINT_HAVE_STDINT_H" "1" >>$ac_stdint
+fi
+
+cat >>$ac_stdint <<STDINT_EOF
+
+/* ................... shortcircuit part ........................... */
+
+#if defined HAVE_STDINT_H || defined _STDINT_HAVE_STDINT_H
+#include <stdint.h>
+#else
+#include <stddef.h>
+
+/* .................... configured part ............................ */
+
+STDINT_EOF
+
+echo "/* whether we have a C99 compatible stdint header file */" >>$ac_stdint
+if test "_$ac_cv_header_stdint_x" != "_" ; then
+ ac_header="$ac_cv_header_stdint_x"
+ echo "#define _STDINT_HEADER_INTPTR" '"'"$ac_header"'"' >>$ac_stdint
+else
+ echo "/* #undef _STDINT_HEADER_INTPTR */" >>$ac_stdint
+fi
+
+echo "/* whether we have a C96 compatible inttypes header file */" >>$ac_stdint
+if test "_$ac_cv_header_stdint_o" != "_" ; then
+ ac_header="$ac_cv_header_stdint_o"
+ echo "#define _STDINT_HEADER_UINT32" '"'"$ac_header"'"' >>$ac_stdint
+else
+ echo "/* #undef _STDINT_HEADER_UINT32 */" >>$ac_stdint
+fi
+
+echo "/* whether we have a BSD compatible inet types header */" >>$ac_stdint
+if test "_$ac_cv_header_stdint_u" != "_" ; then
+ ac_header="$ac_cv_header_stdint_u"
+ echo "#define _STDINT_HEADER_U_INT32" '"'"$ac_header"'"' >>$ac_stdint
+else
+ echo "/* #undef _STDINT_HEADER_U_INT32 */" >>$ac_stdint
+fi
+
+echo "" >>$ac_stdint
+
+if test "_$ac_header" != "_" ; then if test "$ac_header" != "stddef.h" ; then
+ echo "#include <$ac_header>" >>$ac_stdint
+ echo "" >>$ac_stdint
+fi fi
+
+echo "/* which 64bit typedef has been found */" >>$ac_stdint
+if test "$ac_cv_type_uint64_t" = "yes" ; then
+echo "#define _STDINT_HAVE_UINT64_T" "1" >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_UINT64_T */" >>$ac_stdint
+fi
+if test "$ac_cv_type_u_int64_t" = "yes" ; then
+echo "#define _STDINT_HAVE_U_INT64_T" "1" >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_U_INT64_T */" >>$ac_stdint
+fi
+echo "" >>$ac_stdint
+
+echo "/* which type model has been detected */" >>$ac_stdint
+if test "_$ac_cv_stdint_char_model" != "_" ; then
+echo "#define _STDINT_CHAR_MODEL" "$ac_cv_stdint_char_model" >>$ac_stdint
+echo "#define _STDINT_LONG_MODEL" "$ac_cv_stdint_long_model" >>$ac_stdint
+else
+echo "/* #undef _STDINT_CHAR_MODEL // skipped */" >>$ac_stdint
+echo "/* #undef _STDINT_LONG_MODEL // skipped */" >>$ac_stdint
+fi
+echo "" >>$ac_stdint
+
+echo "/* whether int_least types were detected */" >>$ac_stdint
+if test "$ac_cv_type_int_least32_t" = "yes"; then
+echo "#define _STDINT_HAVE_INT_LEAST32_T" "1" >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_INT_LEAST32_T */" >>$ac_stdint
+fi
+echo "/* whether int_fast types were detected */" >>$ac_stdint
+if test "$ac_cv_type_int_fast32_t" = "yes"; then
+echo "#define _STDINT_HAVE_INT_FAST32_T" "1" >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_INT_FAST32_T */" >>$ac_stdint
+fi
+echo "/* whether intmax_t type was detected */" >>$ac_stdint
+if test "$ac_cv_type_intmax_t" = "yes"; then
+echo "#define _STDINT_HAVE_INTMAX_T" "1" >>$ac_stdint
+else
+echo "/* #undef _STDINT_HAVE_INTMAX_T */" >>$ac_stdint
+fi
+echo "" >>$ac_stdint
+
+ cat >>$ac_stdint <<STDINT_EOF
+/* .................... detections part ............................ */
+
+/* whether we need to define bitspecific types from compiler base types */
+#ifndef _STDINT_HEADER_INTPTR
+#ifndef _STDINT_HEADER_UINT32
+#ifndef _STDINT_HEADER_U_INT32
+#define _STDINT_NEED_INT_MODEL_T
+#else
+#define _STDINT_HAVE_U_INT_TYPES
+#endif
+#endif
+#endif
+
+#ifdef _STDINT_HAVE_U_INT_TYPES
+#undef _STDINT_NEED_INT_MODEL_T
+#endif
+
+#ifdef _STDINT_CHAR_MODEL
+#if _STDINT_CHAR_MODEL+0 == 122 || _STDINT_CHAR_MODEL+0 == 124
+#ifndef _STDINT_BYTE_MODEL
+#define _STDINT_BYTE_MODEL 12
+#endif
+#endif
+#endif
+
+#ifndef _STDINT_HAVE_INT_LEAST32_T
+#define _STDINT_NEED_INT_LEAST_T
+#endif
+
+#ifndef _STDINT_HAVE_INT_FAST32_T
+#define _STDINT_NEED_INT_FAST_T
+#endif
+
+#ifndef _STDINT_HEADER_INTPTR
+#define _STDINT_NEED_INTPTR_T
+#ifndef _STDINT_HAVE_INTMAX_T
+#define _STDINT_NEED_INTMAX_T
+#endif
+#endif
+
+
+/* .................... definition part ............................ */
+
+/* some system headers have good uint64_t */
+#ifndef _HAVE_UINT64_T
+#if defined _STDINT_HAVE_UINT64_T || defined HAVE_UINT64_T
+#define _HAVE_UINT64_T
+#elif defined _STDINT_HAVE_U_INT64_T || defined HAVE_U_INT64_T
+#define _HAVE_UINT64_T
+typedef u_int64_t uint64_t;
+#endif
+#endif
+
+#ifndef _HAVE_UINT64_T
+/* .. here are some common heuristics using compiler runtime specifics */
+#if defined __STDC_VERSION__ && defined __STDC_VERSION__ >= 199901L
+#define _HAVE_UINT64_T
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+
+#elif !defined __STRICT_ANSI__
+#if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
+#define _HAVE_UINT64_T
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+
+#elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
+/* note: all ELF-systems seem to have loff-support which needs 64-bit */
+#if !defined _NO_LONGLONG
+#define _HAVE_UINT64_T
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+#endif
+
+#elif defined __alpha || (defined __mips && defined _ABIN32)
+#if !defined _NO_LONGLONG
+typedef long int64_t;
+typedef unsigned long uint64_t;
+#endif
+ /* compiler/cpu type to define int64_t */
+#endif
+#endif
+#endif
+
+#if defined _STDINT_HAVE_U_INT_TYPES
+/* int8_t int16_t int32_t defined by inet code, redeclare the u_intXX types */
+typedef u_int8_t uint8_t;
+typedef u_int16_t uint16_t;
+typedef u_int32_t uint32_t;
+
+/* glibc compatibility */
+#ifndef __int8_t_defined
+#define __int8_t_defined
+#endif
+#endif
+
+#ifdef _STDINT_NEED_INT_MODEL_T
+/* we must guess all the basic types. Apart from byte-adressable system, */
+/* there a few 32-bit-only dsp-systems that we guard with BYTE_MODEL 8-} */
+/* (btw, those nibble-addressable systems are way off, or so we assume) */
+
+dnl /* have a look at "64bit and data size neutrality" at */
+dnl /* http://unix.org/version2/whatsnew/login_64bit.html */
+dnl /* (the shorthand "ILP" types always have a "P" part) */
+
+#if defined _STDINT_BYTE_MODEL
+#if _STDINT_LONG_MODEL+0 == 242
+/* 2:4:2 = IP16 = a normal 16-bit system */
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned long uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef char int8_t;
+typedef short int16_t;
+typedef long int32_t;
+#endif
+#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL == 444
+/* 2:4:4 = LP32 = a 32-bit system derived from a 16-bit */
+/* 4:4:4 = ILP32 = a normal 32-bit system */
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+#endif
+#elif _STDINT_LONG_MODEL+0 == 484 || _STDINT_LONG_MODEL+0 == 488
+/* 4:8:4 = IP32 = a 32-bit system prepared for 64-bit */
+/* 4:8:8 = LP64 = a normal 64-bit system */
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+#endif
+/* this system has a "long" of 64bit */
+#ifndef _HAVE_UINT64_T
+#define _HAVE_UINT64_T
+typedef unsigned long uint64_t;
+typedef long int64_t;
+#endif
+#elif _STDINT_LONG_MODEL+0 == 448
+/* LLP64 a 64-bit system derived from a 32-bit system */
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+#ifndef __int8_t_defined
+#define __int8_t_defined
+typedef char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+#endif
+/* assuming the system has a "long long" */
+#ifndef _HAVE_UINT64_T
+#define _HAVE_UINT64_T
+typedef unsigned long long uint64_t;
+typedef long long int64_t;
+#endif
+#else
+#define _STDINT_NO_INT32_T
+#endif
+#else
+#define _STDINT_NO_INT8_T
+#define _STDINT_NO_INT32_T
+#endif
+#endif
+
+/*
+ * quote from SunOS-5.8 sys/inttypes.h:
+ * Use at your own risk. As of February 1996, the committee is squarely
+ * behind the fixed sized types; the "least" and "fast" types are still being
+ * discussed. The probability that the "fast" types may be removed before
+ * the standard is finalized is high enough that they are not currently
+ * implemented.
+ */
+
+#if defined _STDINT_NEED_INT_LEAST_T
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+#ifdef _HAVE_UINT64_T
+typedef int64_t int_least64_t;
+#endif
+
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+#ifdef _HAVE_UINT64_T
+typedef uint64_t uint_least64_t;
+#endif
+ /* least types */
+#endif
+
+#if defined _STDINT_NEED_INT_FAST_T
+typedef int8_t int_fast8_t;
+typedef int int_fast16_t;
+typedef int32_t int_fast32_t;
+#ifdef _HAVE_UINT64_T
+typedef int64_t int_fast64_t;
+#endif
+
+typedef uint8_t uint_fast8_t;
+typedef unsigned uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+#ifdef _HAVE_UINT64_T
+typedef uint64_t uint_fast64_t;
+#endif
+ /* fast types */
+#endif
+
+#ifdef _STDINT_NEED_INTMAX_T
+#ifdef _HAVE_UINT64_T
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+#else
+typedef long intmax_t;
+typedef unsigned long uintmax_t;
+#endif
+#endif
+
+#ifdef _STDINT_NEED_INTPTR_T
+#ifndef __intptr_t_defined
+#define __intptr_t_defined
+/* we encourage using "long" to store pointer values, never use "int" ! */
+#if _STDINT_LONG_MODEL+0 == 242 || _STDINT_LONG_MODEL+0 == 484
+typedef unsinged int uintptr_t;
+typedef int intptr_t;
+#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL+0 == 444
+typedef unsigned long uintptr_t;
+typedef long intptr_t;
+#elif _STDINT_LONG_MODEL+0 == 448 && defined _HAVE_UINT64_T
+typedef uint64_t uintptr_t;
+typedef int64_t intptr_t;
+#else /* matches typical system types ILP32 and LP64 - but not IP16 or LLP64 */
+typedef unsigned long uintptr_t;
+typedef long intptr_t;
+#endif
+#endif
+#endif
+
+ /* shortcircuit*/
+#endif
+ /* once */
+#endif
+#endif
+STDINT_EOF
+ if cmp -s $ac_stdint_h $ac_stdint 2>/dev/null; then
+ AC_MSG_NOTICE([$ac_stdint_h is unchanged])
+ else
+ ac_dir=`AS_DIRNAME(["$ac_stdint_h"])`
+ AS_MKDIR_P(["$ac_dir"])
+ rm -f $ac_stdint_h
+ mv $ac_stdint $ac_stdint_h
+ fi
+],[# variables for create stdint.h replacement
+PACKAGE="$PACKAGE"
+VERSION="$VERSION"
+ac_stdint_h="$ac_stdint_h"
+_ac_stdint_h=AS_TR_CPP(_$PACKAGE-$ac_stdint_h)
+ac_cv_stdint_message="$ac_cv_stdint_message"
+ac_cv_header_stdint_t="$ac_cv_header_stdint_t"
+ac_cv_header_stdint_x="$ac_cv_header_stdint_x"
+ac_cv_header_stdint_o="$ac_cv_header_stdint_o"
+ac_cv_header_stdint_u="$ac_cv_header_stdint_u"
+ac_cv_type_uint64_t="$ac_cv_type_uint64_t"
+ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
+ac_cv_stdint_char_model="$ac_cv_stdint_char_model"
+ac_cv_stdint_long_model="$ac_cv_stdint_long_model"
+ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
+ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
+ac_cv_type_intmax_t="$ac_cv_type_intmax_t"
+])
+])
diff --git a/argp-standalone/argp-ba.c b/argp-standalone/argp-ba.c
new file mode 100644
index 000000000..0d3958c11
--- /dev/null
+++ b/argp-standalone/argp-ba.c
@@ -0,0 +1,26 @@
+/* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
+ Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* If set by the user program, it should point to string that is the
+ bug-reporting address for the program. It will be printed by argp_help if
+ the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help
+ messages), embedded in a sentence that says something like `Report bugs to
+ ADDR.'. */
+const char *argp_program_bug_address = 0;
diff --git a/argp-standalone/argp-eexst.c b/argp-standalone/argp-eexst.c
new file mode 100644
index 000000000..46b27847a
--- /dev/null
+++ b/argp-standalone/argp-eexst.c
@@ -0,0 +1,36 @@
+/* Default definition for ARGP_ERR_EXIT_STATUS
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_SYSEXITS_H
+# include <sysexits.h>
+#else
+# define EX_USAGE 64
+#endif
+
+#include "argp.h"
+
+/* The exit status that argp will use when exiting due to a parsing error.
+ If not defined or set by the user program, this defaults to EX_USAGE from
+ <sysexits.h>. */
+error_t argp_err_exit_status = EX_USAGE;
diff --git a/argp-standalone/argp-fmtstream.c b/argp-standalone/argp-fmtstream.c
new file mode 100644
index 000000000..7f792854f
--- /dev/null
+++ b/argp-standalone/argp-fmtstream.c
@@ -0,0 +1,475 @@
+/* Word-wrapping and line-truncating streams
+ Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This package emulates glibc `line_wrap_stream' semantics for systems that
+ don't have that. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <ctype.h>
+
+#include "argp-fmtstream.h"
+#include "argp-namefrob.h"
+
+#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
+
+#ifndef isblank
+#define isblank(ch) ((ch)==' ' || (ch)=='\t')
+#endif
+
+#if defined _LIBC && defined USE_IN_LIBIO
+# include <libio/libioP.h>
+# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
+#endif
+
+#define INIT_BUF_SIZE 200
+#define PRINTF_SIZE_GUESS 150
+
+/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
+ written on it with LMARGIN spaces and limits them to RMARGIN columns
+ total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
+ replacing the whitespace before them with a newline and WMARGIN spaces.
+ Otherwise, chars beyond RMARGIN are simply dropped until a newline.
+ Returns NULL if there was an error. */
+argp_fmtstream_t
+__argp_make_fmtstream (FILE *stream,
+ size_t lmargin, size_t rmargin, ssize_t wmargin)
+{
+ argp_fmtstream_t fs = malloc (sizeof (struct argp_fmtstream));
+ if (fs)
+ {
+ fs->stream = stream;
+
+ fs->lmargin = lmargin;
+ fs->rmargin = rmargin;
+ fs->wmargin = wmargin;
+ fs->point_col = 0;
+ fs->point_offs = 0;
+
+ fs->buf = malloc (INIT_BUF_SIZE);
+ if (! fs->buf)
+ {
+ free (fs);
+ fs = 0;
+ }
+ else
+ {
+ fs->p = fs->buf;
+ fs->end = fs->buf + INIT_BUF_SIZE;
+ }
+ }
+
+ return fs;
+}
+#ifdef weak_alias
+weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
+#endif
+
+/* Flush FS to its stream, and free it (but don't close the stream). */
+void
+__argp_fmtstream_free (argp_fmtstream_t fs)
+{
+ __argp_fmtstream_update (fs);
+ if (fs->p > fs->buf)
+ FWRITE_UNLOCKED (fs->buf, 1, fs->p - fs->buf, fs->stream);
+ free (fs->buf);
+ free (fs);
+}
+#ifdef weak_alias
+weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
+#endif
+
+/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
+ end of its buffer. This code is mostly from glibc stdio/linewrap.c. */
+void
+__argp_fmtstream_update (argp_fmtstream_t fs)
+{
+ char *buf, *nl;
+ size_t len;
+
+ /* Scan the buffer for newlines. */
+ buf = fs->buf + fs->point_offs;
+ while (buf < fs->p)
+ {
+ size_t r;
+
+ if (fs->point_col == 0 && fs->lmargin != 0)
+ {
+ /* We are starting a new line. Print spaces to the left margin. */
+ const size_t pad = fs->lmargin;
+ if (fs->p + pad < fs->end)
+ {
+ /* We can fit in them in the buffer by moving the
+ buffer text up and filling in the beginning. */
+ memmove (buf + pad, buf, fs->p - buf);
+ fs->p += pad; /* Compensate for bigger buffer. */
+ memset (buf, ' ', pad); /* Fill in the spaces. */
+ buf += pad; /* Don't bother searching them. */
+ }
+ else
+ {
+ /* No buffer space for spaces. Must flush. */
+ size_t i;
+ for (i = 0; i < pad; i++)
+ PUTC_UNLOCKED (' ', fs->stream);
+ }
+ fs->point_col = pad;
+ }
+
+ len = fs->p - buf;
+ nl = memchr (buf, '\n', len);
+
+ if (fs->point_col < 0)
+ fs->point_col = 0;
+
+ if (!nl)
+ {
+ /* The buffer ends in a partial line. */
+
+ if (fs->point_col + len < fs->rmargin)
+ {
+ /* The remaining buffer text is a partial line and fits
+ within the maximum line width. Advance point for the
+ characters to be written and stop scanning. */
+ fs->point_col += len;
+ break;
+ }
+ else
+ /* Set the end-of-line pointer for the code below to
+ the end of the buffer. */
+ nl = fs->p;
+ }
+ else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
+ {
+ /* The buffer contains a full line that fits within the maximum
+ line width. Reset point and scan the next line. */
+ fs->point_col = 0;
+ buf = nl + 1;
+ continue;
+ }
+
+ /* This line is too long. */
+ r = fs->rmargin - 1;
+
+ if (fs->wmargin < 0)
+ {
+ /* Truncate the line by overwriting the excess with the
+ newline and anything after it in the buffer. */
+ if (nl < fs->p)
+ {
+ memmove (buf + (r - fs->point_col), nl, fs->p - nl);
+ fs->p -= buf + (r - fs->point_col) - nl;
+ /* Reset point for the next line and start scanning it. */
+ fs->point_col = 0;
+ buf += r + 1; /* Skip full line plus \n. */
+ }
+ else
+ {
+ /* The buffer ends with a partial line that is beyond the
+ maximum line width. Advance point for the characters
+ written, and discard those past the max from the buffer. */
+ fs->point_col += len;
+ fs->p -= fs->point_col - r;
+ break;
+ }
+ }
+ else
+ {
+ /* Do word wrap. Go to the column just past the maximum line
+ width and scan back for the beginning of the word there.
+ Then insert a line break. */
+
+ char *p, *nextline;
+ int i;
+
+ p = buf + (r + 1 - fs->point_col);
+ while (p >= buf && !isblank (*p))
+ --p;
+ nextline = p + 1; /* This will begin the next line. */
+
+ if (nextline > buf)
+ {
+ /* Swallow separating blanks. */
+ if (p >= buf)
+ do
+ --p;
+ while (p >= buf && isblank (*p));
+ nl = p + 1; /* The newline will replace the first blank. */
+ }
+ else
+ {
+ /* A single word that is greater than the maximum line width.
+ Oh well. Put it on an overlong line by itself. */
+ p = buf + (r + 1 - fs->point_col);
+ /* Find the end of the long word. */
+ do
+ ++p;
+ while (p < nl && !isblank (*p));
+ if (p == nl)
+ {
+ /* It already ends a line. No fussing required. */
+ fs->point_col = 0;
+ buf = nl + 1;
+ continue;
+ }
+ /* We will move the newline to replace the first blank. */
+ nl = p;
+ /* Swallow separating blanks. */
+ do
+ ++p;
+ while (isblank (*p));
+ /* The next line will start here. */
+ nextline = p;
+ }
+
+ /* Note: There are a bunch of tests below for
+ NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
+ at the end of the buffer, and NEXTLINE is in fact empty (and so
+ we need not be careful to maintain its contents). */
+
+ if (nextline == buf + len + 1
+ ? fs->end - nl < fs->wmargin + 1
+ : nextline - (nl + 1) < fs->wmargin)
+ {
+ /* The margin needs more blanks than we removed. */
+ if (fs->end - fs->p > fs->wmargin + 1)
+ /* Make some space for them. */
+ {
+ size_t mv = fs->p - nextline;
+ memmove (nl + 1 + fs->wmargin, nextline, mv);
+ nextline = nl + 1 + fs->wmargin;
+ len = nextline + mv - buf;
+ *nl++ = '\n';
+ }
+ else
+ /* Output the first line so we can use the space. */
+ {
+ if (nl > fs->buf)
+ FWRITE_UNLOCKED (fs->buf, 1, nl - fs->buf, fs->stream);
+ PUTC_UNLOCKED ('\n', fs->stream);
+ len += buf - fs->buf;
+ nl = buf = fs->buf;
+ }
+ }
+ else
+ /* We can fit the newline and blanks in before
+ the next word. */
+ *nl++ = '\n';
+
+ if (nextline - nl >= fs->wmargin
+ || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
+ /* Add blanks up to the wrap margin column. */
+ for (i = 0; i < fs->wmargin; ++i)
+ *nl++ = ' ';
+ else
+ for (i = 0; i < fs->wmargin; ++i)
+ PUTC_UNLOCKED (' ', fs->stream);
+
+ /* Copy the tail of the original buffer into the current buffer
+ position. */
+ if (nl < nextline)
+ memmove (nl, nextline, buf + len - nextline);
+ len -= nextline - buf;
+
+ /* Continue the scan on the remaining lines in the buffer. */
+ buf = nl;
+
+ /* Restore bufp to include all the remaining text. */
+ fs->p = nl + len;
+
+ /* Reset the counter of what has been output this line. If wmargin
+ is 0, we want to avoid the lmargin getting added, so we set
+ point_col to a magic value of -1 in that case. */
+ fs->point_col = fs->wmargin ? fs->wmargin : -1;
+ }
+ }
+
+ /* Remember that we've scanned as far as the end of the buffer. */
+ fs->point_offs = fs->p - fs->buf;
+}
+
+/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
+ growing the buffer, or by flushing it. True is returned iff we succeed. */
+int
+__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
+{
+ if ((size_t) (fs->end - fs->p) < amount)
+ {
+ ssize_t wrote;
+
+ /* Flush FS's buffer. */
+ __argp_fmtstream_update (fs);
+
+ wrote = FWRITE_UNLOCKED (fs->buf, 1, fs->p - fs->buf, fs->stream);
+ if (wrote == fs->p - fs->buf)
+ {
+ fs->p = fs->buf;
+ fs->point_offs = 0;
+ }
+ else
+ {
+ fs->p -= wrote;
+ fs->point_offs -= wrote;
+ memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
+ return 0;
+ }
+
+ if ((size_t) (fs->end - fs->buf) < amount)
+ /* Gotta grow the buffer. */
+ {
+ size_t new_size = fs->end - fs->buf + amount;
+ char *new_buf = realloc (fs->buf, new_size);
+
+ if (! new_buf)
+ {
+ __set_errno (ENOMEM);
+ return 0;
+ }
+
+ fs->buf = new_buf;
+ fs->end = new_buf + new_size;
+ fs->p = fs->buf;
+ }
+ }
+
+ return 1;
+}
+
+ssize_t
+__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
+{
+ size_t out;
+ size_t avail;
+ size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
+
+ do
+ {
+ va_list args;
+
+ if (! __argp_fmtstream_ensure (fs, size_guess))
+ return -1;
+
+ va_start (args, fmt);
+ avail = fs->end - fs->p;
+ out = __vsnprintf (fs->p, avail, fmt, args);
+ va_end (args);
+ if (out >= avail)
+ size_guess = out + 1;
+ }
+ while (out >= avail);
+
+ fs->p += out;
+
+ return out;
+}
+#ifdef weak_alias
+weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
+#endif
+
+/* Duplicate the inline definitions in argp-fmtstream.h, for compilers
+ * that don't do inlining. */
+size_t
+__argp_fmtstream_write (argp_fmtstream_t __fs,
+ __const char *__str, size_t __len)
+{
+ if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
+ {
+ memcpy (__fs->p, __str, __len);
+ __fs->p += __len;
+ return __len;
+ }
+ else
+ return 0;
+}
+
+int
+__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str)
+{
+ size_t __len = strlen (__str);
+ if (__len)
+ {
+ size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
+ return __wrote == __len ? 0 : -1;
+ }
+ else
+ return 0;
+}
+
+int
+__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
+{
+ if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
+ return *__fs->p++ = __ch;
+ else
+ return EOF;
+}
+
+/* Set __FS's left margin to __LMARGIN and return the old value. */
+size_t
+__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
+{
+ size_t __old;
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ __old = __fs->lmargin;
+ __fs->lmargin = __lmargin;
+ return __old;
+}
+
+/* Set __FS's right margin to __RMARGIN and return the old value. */
+size_t
+__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
+{
+ size_t __old;
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ __old = __fs->rmargin;
+ __fs->rmargin = __rmargin;
+ return __old;
+}
+
+/* Set FS's wrap margin to __WMARGIN and return the old value. */
+size_t
+__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
+{
+ size_t __old;
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ __old = __fs->wmargin;
+ __fs->wmargin = __wmargin;
+ return __old;
+}
+
+/* Return the column number of the current output point in __FS. */
+size_t
+__argp_fmtstream_point (argp_fmtstream_t __fs)
+{
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ return __fs->point_col >= 0 ? __fs->point_col : 0;
+}
+
+#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
diff --git a/argp-standalone/argp-fmtstream.h b/argp-standalone/argp-fmtstream.h
new file mode 100644
index 000000000..e797b119e
--- /dev/null
+++ b/argp-standalone/argp-fmtstream.h
@@ -0,0 +1,319 @@
+/* Word-wrapping and line-truncating streams.
+ Copyright (C) 1997, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This package emulates glibc `line_wrap_stream' semantics for systems that
+ don't have that. If the system does have it, it is just a wrapper for
+ that. This header file is only used internally while compiling argp, and
+ shouldn't be installed. */
+
+#ifndef _ARGP_FMTSTREAM_H
+#define _ARGP_FMTSTREAM_H
+
+#include <stdio.h>
+#include <string.h>
+
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#else
+/* This is a kludge to make the code compile on windows. Perhaps it
+ would be better to just replace ssize_t with int through out the
+ code. */
+# define ssize_t int
+#endif
+
+#if _LIBC || (defined (HAVE_FLOCKFILE) && defined(HAVE_PUTC_UNLOCKED) \
+ && defined (HAVE_FPUTS_UNLOCKED) && defined (HAVE_FWRITE_UNLOCKED) )
+/* Use locking funxtions */
+# define FLOCKFILE(f) flockfile(f)
+# define FUNLOCKFILE(f) funlockfile(f)
+# define PUTC_UNLOCKED(c, f) putc_unlocked((c), (f))
+# define FPUTS_UNLOCKED(s, f) fputs_unlocked((s), (f))
+# define FWRITE_UNLOCKED(b, s, n, f) fwrite_unlocked((b), (s), (n), (f))
+#else
+/* Disable stdio locking */
+# define FLOCKFILE(f)
+# define FUNLOCKFILE(f)
+# define PUTC_UNLOCKED(c, f) putc((c), (f))
+# define FPUTS_UNLOCKED(s, f) fputs((s), (f))
+# define FWRITE_UNLOCKED(b, s, n, f) fwrite((b), (s), (n), (f))
+#endif /* No thread safe i/o */
+
+#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
+ || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
+/* line_wrap_stream is available, so use that. */
+#define ARGP_FMTSTREAM_USE_LINEWRAP
+#endif
+
+#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
+/* Just be a simple wrapper for line_wrap_stream; the semantics are
+ *slightly* different, as line_wrap_stream doesn't actually make a new
+ object, it just modifies the given stream (reversibly) to do
+ line-wrapping. Since we control who uses this code, it doesn't matter. */
+
+#include <linewrap.h>
+
+typedef FILE *argp_fmtstream_t;
+
+#define argp_make_fmtstream line_wrap_stream
+#define __argp_make_fmtstream line_wrap_stream
+#define argp_fmtstream_free line_unwrap_stream
+#define __argp_fmtstream_free line_unwrap_stream
+
+#define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
+#define argp_fmtstream_putc(fs,ch) putc(ch,fs)
+#define __argp_fmtstream_puts(fs,str) fputs(str,fs)
+#define argp_fmtstream_puts(fs,str) fputs(str,fs)
+#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
+#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
+#define __argp_fmtstream_printf fprintf
+#define argp_fmtstream_printf fprintf
+
+#define __argp_fmtstream_lmargin line_wrap_lmargin
+#define argp_fmtstream_lmargin line_wrap_lmargin
+#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
+#define argp_fmtstream_set_lmargin line_wrap_set_lmargin
+#define __argp_fmtstream_rmargin line_wrap_rmargin
+#define argp_fmtstream_rmargin line_wrap_rmargin
+#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
+#define argp_fmtstream_set_rmargin line_wrap_set_rmargin
+#define __argp_fmtstream_wmargin line_wrap_wmargin
+#define argp_fmtstream_wmargin line_wrap_wmargin
+#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
+#define argp_fmtstream_set_wmargin line_wrap_set_wmargin
+#define __argp_fmtstream_point line_wrap_point
+#define argp_fmtstream_point line_wrap_point
+
+#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
+/* Guess we have to define our own version. */
+
+#ifndef __const
+#define __const const
+#endif
+
+
+struct argp_fmtstream
+{
+ FILE *stream; /* The stream we're outputting to. */
+
+ size_t lmargin, rmargin; /* Left and right margins. */
+ ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */
+
+ /* Point in buffer to which we've processed for wrapping, but not output. */
+ size_t point_offs;
+ /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
+ ssize_t point_col;
+
+ char *buf; /* Output buffer. */
+ char *p; /* Current end of text in BUF. */
+ char *end; /* Absolute end of BUF. */
+};
+
+typedef struct argp_fmtstream *argp_fmtstream_t;
+
+/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
+ written on it with LMARGIN spaces and limits them to RMARGIN columns
+ total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
+ replacing the whitespace before them with a newline and WMARGIN spaces.
+ Otherwise, chars beyond RMARGIN are simply dropped until a newline.
+ Returns NULL if there was an error. */
+extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
+ size_t __lmargin,
+ size_t __rmargin,
+ ssize_t __wmargin);
+extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
+ size_t __lmargin,
+ size_t __rmargin,
+ ssize_t __wmargin);
+
+/* Flush __FS to its stream, and free it (but don't close the stream). */
+extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
+extern void argp_fmtstream_free (argp_fmtstream_t __fs);
+
+extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
+ __const char *__fmt, ...)
+ PRINTF_STYLE(2,3);
+extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
+ __const char *__fmt, ...)
+ PRINTF_STYLE(2,3);
+
+extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
+extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
+
+extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str);
+extern int argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str);
+
+extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
+ __const char *__str, size_t __len);
+extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
+ __const char *__str, size_t __len);
+
+/* Access macros for various bits of state. */
+#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
+#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
+#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
+#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
+#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
+#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
+
+/* Set __FS's left margin to LMARGIN and return the old value. */
+extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
+ size_t __lmargin);
+extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
+ size_t __lmargin);
+
+/* Set __FS's right margin to __RMARGIN and return the old value. */
+extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
+ size_t __rmargin);
+extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
+ size_t __rmargin);
+
+/* Set __FS's wrap margin to __WMARGIN and return the old value. */
+extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
+ size_t __wmargin);
+extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
+ size_t __wmargin);
+
+/* Return the column number of the current output point in __FS. */
+extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
+extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
+
+/* Internal routines. */
+extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
+extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
+extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
+extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
+
+#ifdef __OPTIMIZE__
+/* Inline versions of above routines. */
+
+#if !_LIBC
+#define __argp_fmtstream_putc argp_fmtstream_putc
+#define __argp_fmtstream_puts argp_fmtstream_puts
+#define __argp_fmtstream_write argp_fmtstream_write
+#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
+#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
+#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
+#define __argp_fmtstream_point argp_fmtstream_point
+#define __argp_fmtstream_update _argp_fmtstream_update
+#define __argp_fmtstream_ensure _argp_fmtstream_ensure
+#endif
+
+#ifndef ARGP_FS_EI
+#define ARGP_FS_EI extern inline
+#endif
+
+ARGP_FS_EI size_t
+__argp_fmtstream_write (argp_fmtstream_t __fs,
+ __const char *__str, size_t __len)
+{
+ if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
+ {
+ memcpy (__fs->p, __str, __len);
+ __fs->p += __len;
+ return __len;
+ }
+ else
+ return 0;
+}
+
+ARGP_FS_EI int
+__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str)
+{
+ size_t __len = strlen (__str);
+ if (__len)
+ {
+ size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
+ return __wrote == __len ? 0 : -1;
+ }
+ else
+ return 0;
+}
+
+ARGP_FS_EI int
+__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
+{
+ if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
+ return *__fs->p++ = __ch;
+ else
+ return EOF;
+}
+
+/* Set __FS's left margin to __LMARGIN and return the old value. */
+ARGP_FS_EI size_t
+__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
+{
+ size_t __old;
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ __old = __fs->lmargin;
+ __fs->lmargin = __lmargin;
+ return __old;
+}
+
+/* Set __FS's right margin to __RMARGIN and return the old value. */
+ARGP_FS_EI size_t
+__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
+{
+ size_t __old;
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ __old = __fs->rmargin;
+ __fs->rmargin = __rmargin;
+ return __old;
+}
+
+/* Set FS's wrap margin to __WMARGIN and return the old value. */
+ARGP_FS_EI size_t
+__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
+{
+ size_t __old;
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ __old = __fs->wmargin;
+ __fs->wmargin = __wmargin;
+ return __old;
+}
+
+/* Return the column number of the current output point in __FS. */
+ARGP_FS_EI size_t
+__argp_fmtstream_point (argp_fmtstream_t __fs)
+{
+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
+ __argp_fmtstream_update (__fs);
+ return __fs->point_col >= 0 ? __fs->point_col : 0;
+}
+
+#if !_LIBC
+#undef __argp_fmtstream_putc
+#undef __argp_fmtstream_puts
+#undef __argp_fmtstream_write
+#undef __argp_fmtstream_set_lmargin
+#undef __argp_fmtstream_set_rmargin
+#undef __argp_fmtstream_set_wmargin
+#undef __argp_fmtstream_point
+#undef __argp_fmtstream_update
+#undef __argp_fmtstream_ensure
+#endif
+
+#endif /* __OPTIMIZE__ */
+
+#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
+
+#endif /* argp-fmtstream.h */
diff --git a/argp-standalone/argp-help.c b/argp-standalone/argp-help.c
new file mode 100644
index 000000000..ced78c4cb
--- /dev/null
+++ b/argp-standalone/argp-help.c
@@ -0,0 +1,1849 @@
+/* Hierarchial argument parsing help output
+ Copyright (C) 1995,96,97,98,99,2000, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <ctype.h>
+#if HAVE_MALLOC_H
+/* Needed, for alloca on windows */
+# include <malloc.h>
+#endif
+
+#ifndef _
+/* This is for other GNU distributions with internationalized messages. */
+# if defined HAVE_LIBINTL_H || defined _LIBC
+# include <libintl.h>
+# ifdef _LIBC
+# undef dgettext
+# define dgettext(domain, msgid) __dcgettext (domain, msgid, LC_MESSAGES)
+# endif
+# else
+# define dgettext(domain, msgid) (msgid)
+# endif
+#endif
+
+#include "argp.h"
+#include "argp-fmtstream.h"
+#include "argp-namefrob.h"
+
+
+#ifndef _LIBC
+# ifndef __strchrnul
+# define __strchrnul strchrnul
+# endif
+# ifndef __mempcpy
+# define __mempcpy mempcpy
+# endif
+/* We need to use a different name, as __strndup is likely a macro. */
+# define STRNDUP strndup
+# if HAVE_STRERROR
+# define STRERROR strerror
+# else
+# define STRERROR(x) (sys_errlist[x])
+# endif
+#else /* _LIBC */
+# define FLOCKFILE __flockfile
+# define FUNLOCKFILE __funlockfile
+# define STRNDUP __strndup
+# define STRERROR strerror
+#endif
+
+#if !_LIBC
+# if !HAVE_STRNDUP
+char *strndup (const char *s, size_t size);
+# endif /* !HAVE_STRNDUP */
+
+# if !HAVE_MEMPCPY
+void *mempcpy (void *to, const void *from, size_t size);
+# endif /* !HAVE_MEMPCPY */
+
+# if !HAVE_STRCHRNUL
+char *strchrnul(const char *s, int c);
+# endif /* !HAVE_STRCHRNUL */
+
+# if !HAVE_STRCASECMP
+int strcasecmp(const char *s1, const char *s2);
+#endif
+
+#endif /* !_LIBC */
+
+
+/* User-selectable (using an environment variable) formatting parameters.
+
+ These may be specified in an environment variable called `ARGP_HELP_FMT',
+ with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2
+ Where VALn must be a positive integer. The list of variables is in the
+ UPARAM_NAMES vector, below. */
+
+/* Default parameters. */
+#define DUP_ARGS 0 /* True if option argument can be duplicated. */
+#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */
+#define SHORT_OPT_COL 2 /* column in which short options start */
+#define LONG_OPT_COL 6 /* column in which long options start */
+#define DOC_OPT_COL 2 /* column in which doc options start */
+#define OPT_DOC_COL 29 /* column in which option text starts */
+#define HEADER_COL 1 /* column in which group headers are printed */
+#define USAGE_INDENT 12 /* indentation of wrapped usage lines */
+#define RMARGIN 79 /* right margin used for wrapping */
+
+/* User-selectable (using an environment variable) formatting parameters.
+ They must all be of type `int' for the parsing code to work. */
+struct uparams
+{
+ /* If true, arguments for an option are shown with both short and long
+ options, even when a given option has both, e.g. `-x ARG, --longx=ARG'.
+ If false, then if an option has both, the argument is only shown with
+ the long one, e.g., `-x, --longx=ARG', and a message indicating that
+ this really means both is printed below the options. */
+ int dup_args;
+
+ /* This is true if when DUP_ARGS is false, and some duplicate arguments have
+ been suppressed, an explanatory message should be printed. */
+ int dup_args_note;
+
+ /* Various output columns. */
+ int short_opt_col;
+ int long_opt_col;
+ int doc_opt_col;
+ int opt_doc_col;
+ int header_col;
+ int usage_indent;
+ int rmargin;
+
+ int valid; /* True when the values in here are valid. */
+};
+
+/* This is a global variable, as user options are only ever read once. */
+static struct uparams uparams = {
+ DUP_ARGS, DUP_ARGS_NOTE,
+ SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL,
+ USAGE_INDENT, RMARGIN,
+ 0
+};
+
+/* A particular uparam, and what the user name is. */
+struct uparam_name
+{
+ const char *name; /* User name. */
+ int is_bool; /* Whether it's `boolean'. */
+ size_t uparams_offs; /* Location of the (int) field in UPARAMS. */
+};
+
+/* The name-field mappings we know about. */
+static const struct uparam_name uparam_names[] =
+{
+ { "dup-args", 1, offsetof (struct uparams, dup_args) },
+ { "dup-args-note", 1, offsetof (struct uparams, dup_args_note) },
+ { "short-opt-col", 0, offsetof (struct uparams, short_opt_col) },
+ { "long-opt-col", 0, offsetof (struct uparams, long_opt_col) },
+ { "doc-opt-col", 0, offsetof (struct uparams, doc_opt_col) },
+ { "opt-doc-col", 0, offsetof (struct uparams, opt_doc_col) },
+ { "header-col", 0, offsetof (struct uparams, header_col) },
+ { "usage-indent", 0, offsetof (struct uparams, usage_indent) },
+ { "rmargin", 0, offsetof (struct uparams, rmargin) },
+ { 0, 0, 0 }
+};
+
+/* Read user options from the environment, and fill in UPARAMS appropiately. */
+static void
+fill_in_uparams (const struct argp_state *state)
+{
+
+ const char *var = getenv ("ARGP_HELP_FMT");
+
+#define SKIPWS(p) do { while (isspace (*p)) p++; } while (0);
+
+ if (var)
+ /* Parse var. */
+ while (*var)
+ {
+ SKIPWS (var);
+
+ if (isalpha (*var))
+ {
+ size_t var_len;
+ const struct uparam_name *un;
+ int unspec = 0, val = 0;
+ const char *arg = var;
+
+ while (isalnum (*arg) || *arg == '-' || *arg == '_')
+ arg++;
+ var_len = arg - var;
+
+ SKIPWS (arg);
+
+ if (*arg == '\0' || *arg == ',')
+ unspec = 1;
+ else if (*arg == '=')
+ {
+ arg++;
+ SKIPWS (arg);
+ }
+
+ if (unspec)
+ {
+ if (var[0] == 'n' && var[1] == 'o' && var[2] == '-')
+ {
+ val = 0;
+ var += 3;
+ var_len -= 3;
+ }
+ else
+ val = 1;
+ }
+ else if (isdigit (*arg))
+ {
+ val = atoi (arg);
+ while (isdigit (*arg))
+ arg++;
+ SKIPWS (arg);
+ }
+
+ for (un = uparam_names; un->name; un++)
+ if (strlen (un->name) == var_len
+ && strncmp (var, un->name, var_len) == 0)
+ {
+ if (unspec && !un->is_bool)
+ __argp_failure (state, 0, 0,
+ dgettext (state->root_argp->argp_domain, "\
+%.*s: ARGP_HELP_FMT parameter requires a value"),
+ (int) var_len, var);
+ else
+ *(int *)((char *)&uparams + un->uparams_offs) = val;
+ break;
+ }
+ if (! un->name)
+ __argp_failure (state, 0, 0,
+ dgettext (state->root_argp->argp_domain, "\
+%.*s: Unknown ARGP_HELP_FMT parameter"),
+ (int) var_len, var);
+
+ var = arg;
+ if (*var == ',')
+ var++;
+ }
+ else if (*var)
+ {
+ __argp_failure (state, 0, 0,
+ dgettext (state->root_argp->argp_domain,
+ "Garbage in ARGP_HELP_FMT: %s"), var);
+ break;
+ }
+ }
+}
+
+/* Returns true if OPT hasn't been marked invisible. Visibility only affects
+ whether OPT is displayed or used in sorting, not option shadowing. */
+#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN))
+
+/* Returns true if OPT is an alias for an earlier option. */
+#define oalias(opt) ((opt)->flags & OPTION_ALIAS)
+
+/* Returns true if OPT is an documentation-only entry. */
+#define odoc(opt) ((opt)->flags & OPTION_DOC)
+
+/* Returns true if OPT is the end-of-list marker for a list of options. */
+#define oend(opt) __option_is_end (opt)
+
+/* Returns true if OPT has a short option. */
+#define oshort(opt) __option_is_short (opt)
+
+/*
+ The help format for a particular option is like:
+
+ -xARG, -yARG, --long1=ARG, --long2=ARG Documentation...
+
+ Where ARG will be omitted if there's no argument, for this option, or
+ will be surrounded by "[" and "]" appropiately if the argument is
+ optional. The documentation string is word-wrapped appropiately, and if
+ the list of options is long enough, it will be started on a separate line.
+ If there are no short options for a given option, the first long option is
+ indented slighly in a way that's supposed to make most long options appear
+ to be in a separate column.
+
+ For example, the following output (from ps):
+
+ -p PID, --pid=PID List the process PID
+ --pgrp=PGRP List processes in the process group PGRP
+ -P, -x, --no-parent Include processes without parents
+ -Q, --all-fields Don't elide unusable fields (normally if there's
+ some reason ps can't print a field for any
+ process, it's removed from the output entirely)
+ -r, --reverse, --gratuitously-long-reverse-option
+ Reverse the order of any sort
+ --session[=SID] Add the processes from the session SID (which
+ defaults to the sid of the current process)
+
+ Here are some more options:
+ -f ZOT, --foonly=ZOT Glork a foonly
+ -z, --zaza Snit a zar
+
+ -?, --help Give this help list
+ --usage Give a short usage message
+ -V, --version Print program version
+
+ The struct argp_option array for the above could look like:
+
+ {
+ {"pid", 'p', "PID", 0, "List the process PID"},
+ {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"},
+ {"no-parent", 'P', 0, 0, "Include processes without parents"},
+ {0, 'x', 0, OPTION_ALIAS},
+ {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally"
+ " if there's some reason ps can't"
+ " print a field for any process, it's"
+ " removed from the output entirely)" },
+ {"reverse", 'r', 0, 0, "Reverse the order of any sort"},
+ {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
+ {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL,
+ "Add the processes from the session"
+ " SID (which defaults to the sid of"
+ " the current process)" },
+
+ {0,0,0,0, "Here are some more options:"},
+ {"foonly", 'f', "ZOT", 0, "Glork a foonly"},
+ {"zaza", 'z', 0, 0, "Snit a zar"},
+
+ {0}
+ }
+
+ Note that the last three options are automatically supplied by argp_parse,
+ unless you tell it not to with ARGP_NO_HELP.
+
+*/
+
+/* Returns true if CH occurs between BEG and END. */
+static int
+find_char (char ch, char *beg, char *end)
+{
+ while (beg < end)
+ if (*beg == ch)
+ return 1;
+ else
+ beg++;
+ return 0;
+}
+
+struct hol_cluster; /* fwd decl */
+
+struct hol_entry
+{
+ /* First option. */
+ const struct argp_option *opt;
+ /* Number of options (including aliases). */
+ unsigned num;
+
+ /* A pointers into the HOL's short_options field, to the first short option
+ letter for this entry. The order of the characters following this point
+ corresponds to the order of options pointed to by OPT, and there are at
+ most NUM. A short option recorded in a option following OPT is only
+ valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's
+ probably been shadowed by some other entry). */
+ char *short_options;
+
+ /* Entries are sorted by their group first, in the order:
+ 1, 2, ..., n, 0, -m, ..., -2, -1
+ and then alphabetically within each group. The default is 0. */
+ int group;
+
+ /* The cluster of options this entry belongs to, or 0 if none. */
+ struct hol_cluster *cluster;
+
+ /* The argp from which this option came. */
+ const struct argp *argp;
+};
+
+/* A cluster of entries to reflect the argp tree structure. */
+struct hol_cluster
+{
+ /* A descriptive header printed before options in this cluster. */
+ const char *header;
+
+ /* Used to order clusters within the same group with the same parent,
+ according to the order in which they occurred in the parent argp's child
+ list. */
+ int index;
+
+ /* How to sort this cluster with respect to options and other clusters at the
+ same depth (clusters always follow options in the same group). */
+ int group;
+
+ /* The cluster to which this cluster belongs, or 0 if it's at the base
+ level. */
+ struct hol_cluster *parent;
+
+ /* The argp from which this cluster is (eventually) derived. */
+ const struct argp *argp;
+
+ /* The distance this cluster is from the root. */
+ int depth;
+
+ /* Clusters in a given hol are kept in a linked list, to make freeing them
+ possible. */
+ struct hol_cluster *next;
+};
+
+/* A list of options for help. */
+struct hol
+{
+ /* An array of hol_entry's. */
+ struct hol_entry *entries;
+ /* The number of entries in this hol. If this field is zero, the others
+ are undefined. */
+ unsigned num_entries;
+
+ /* A string containing all short options in this HOL. Each entry contains
+ pointers into this string, so the order can't be messed with blindly. */
+ char *short_options;
+
+ /* Clusters of entries in this hol. */
+ struct hol_cluster *clusters;
+};
+
+/* Create a struct hol from the options in ARGP. CLUSTER is the
+ hol_cluster in which these entries occur, or 0, if at the root. */
+static struct hol *
+make_hol (const struct argp *argp, struct hol_cluster *cluster)
+{
+ char *so;
+ const struct argp_option *o;
+ const struct argp_option *opts = argp->options;
+ struct hol_entry *entry;
+ unsigned num_short_options = 0;
+ struct hol *hol = malloc (sizeof (struct hol));
+
+ assert (hol);
+
+ hol->num_entries = 0;
+ hol->clusters = 0;
+
+ if (opts)
+ {
+ int cur_group = 0;
+
+ /* The first option must not be an alias. */
+ assert (! oalias (opts));
+
+ /* Calculate the space needed. */
+ for (o = opts; ! oend (o); o++)
+ {
+ if (! oalias (o))
+ hol->num_entries++;
+ if (oshort (o))
+ num_short_options++; /* This is an upper bound. */
+ }
+
+ hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries);
+ hol->short_options = malloc (num_short_options + 1);
+
+ assert (hol->entries && hol->short_options);
+
+ /* Fill in the entries. */
+ so = hol->short_options;
+ for (o = opts, entry = hol->entries; ! oend (o); entry++)
+ {
+ entry->opt = o;
+ entry->num = 0;
+ entry->short_options = so;
+ entry->group = cur_group =
+ o->group
+ ? o->group
+ : ((!o->name && !o->key)
+ ? cur_group + 1
+ : cur_group);
+ entry->cluster = cluster;
+ entry->argp = argp;
+
+ do
+ {
+ entry->num++;
+ if (oshort (o) && ! find_char (o->key, hol->short_options, so))
+ /* O has a valid short option which hasn't already been used.*/
+ *so++ = o->key;
+ o++;
+ }
+ while (! oend (o) && oalias (o));
+ }
+ *so = '\0'; /* null terminated so we can find the length */
+ }
+
+ return hol;
+}
+
+/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the
+ associated argp child list entry), INDEX, and PARENT, and return a pointer
+ to it. ARGP is the argp that this cluster results from. */
+static struct hol_cluster *
+hol_add_cluster (struct hol *hol, int group, const char *header, int index,
+ struct hol_cluster *parent, const struct argp *argp)
+{
+ struct hol_cluster *cl = malloc (sizeof (struct hol_cluster));
+ if (cl)
+ {
+ cl->group = group;
+ cl->header = header;
+
+ cl->index = index;
+ cl->parent = parent;
+ cl->argp = argp;
+ cl->depth = parent ? parent->depth + 1 : 0;
+
+ cl->next = hol->clusters;
+ hol->clusters = cl;
+ }
+ return cl;
+}
+
+/* Free HOL and any resources it uses. */
+static void
+hol_free (struct hol *hol)
+{
+ struct hol_cluster *cl = hol->clusters;
+
+ while (cl)
+ {
+ struct hol_cluster *next = cl->next;
+ free (cl);
+ cl = next;
+ }
+
+ if (hol->num_entries > 0)
+ {
+ free (hol->entries);
+ free (hol->short_options);
+ }
+
+ free (hol);
+}
+
+static inline int
+hol_entry_short_iterate (const struct hol_entry *entry,
+ int (*func)(const struct argp_option *opt,
+ const struct argp_option *real,
+ const char *domain, void *cookie),
+ const char *domain, void *cookie)
+{
+ unsigned nopts;
+ int val = 0;
+ const struct argp_option *opt, *real = entry->opt;
+ char *so = entry->short_options;
+
+ for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
+ if (oshort (opt) && *so == opt->key)
+ {
+ if (!oalias (opt))
+ real = opt;
+ if (ovisible (opt))
+ val = (*func)(opt, real, domain, cookie);
+ so++;
+ }
+
+ return val;
+}
+
+static inline int
+hol_entry_long_iterate (const struct hol_entry *entry,
+ int (*func)(const struct argp_option *opt,
+ const struct argp_option *real,
+ const char *domain, void *cookie),
+ const char *domain, void *cookie)
+{
+ unsigned nopts;
+ int val = 0;
+ const struct argp_option *opt, *real = entry->opt;
+
+ for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
+ if (opt->name)
+ {
+ if (!oalias (opt))
+ real = opt;
+ if (ovisible (opt))
+ val = (*func)(opt, real, domain, cookie);
+ }
+
+ return val;
+}
+
+/* Iterator that returns true for the first short option. */
+static inline int
+until_short (const struct argp_option *opt, const struct argp_option *real UNUSED,
+ const char *domain UNUSED, void *cookie UNUSED)
+{
+ return oshort (opt) ? opt->key : 0;
+}
+
+/* Returns the first valid short option in ENTRY, or 0 if there is none. */
+static char
+hol_entry_first_short (const struct hol_entry *entry)
+{
+ return hol_entry_short_iterate (entry, until_short,
+ entry->argp->argp_domain, 0);
+}
+
+/* Returns the first valid long option in ENTRY, or 0 if there is none. */
+static const char *
+hol_entry_first_long (const struct hol_entry *entry)
+{
+ const struct argp_option *opt;
+ unsigned num;
+ for (opt = entry->opt, num = entry->num; num > 0; opt++, num--)
+ if (opt->name && ovisible (opt))
+ return opt->name;
+ return 0;
+}
+
+/* Returns the entry in HOL with the long option name NAME, or 0 if there is
+ none. */
+static struct hol_entry *
+hol_find_entry (struct hol *hol, const char *name)
+{
+ struct hol_entry *entry = hol->entries;
+ unsigned num_entries = hol->num_entries;
+
+ while (num_entries-- > 0)
+ {
+ const struct argp_option *opt = entry->opt;
+ unsigned num_opts = entry->num;
+
+ while (num_opts-- > 0)
+ if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0)
+ return entry;
+ else
+ opt++;
+
+ entry++;
+ }
+
+ return 0;
+}
+
+/* If an entry with the long option NAME occurs in HOL, set it's special
+ sort position to GROUP. */
+static void
+hol_set_group (struct hol *hol, const char *name, int group)
+{
+ struct hol_entry *entry = hol_find_entry (hol, name);
+ if (entry)
+ entry->group = group;
+}
+
+/* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1.
+ EQ is what to return if GROUP1 and GROUP2 are the same. */
+static int
+group_cmp (int group1, int group2, int eq)
+{
+ if (group1 == group2)
+ return eq;
+ else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0))
+ return group1 - group2;
+ else
+ return group2 - group1;
+}
+
+/* Compare clusters CL1 & CL2 by the order that they should appear in
+ output. */
+static int
+hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2)
+{
+ /* If one cluster is deeper than the other, use its ancestor at the same
+ level, so that finding the common ancestor is straightforward. */
+ while (cl1->depth < cl2->depth)
+ cl1 = cl1->parent;
+ while (cl2->depth < cl1->depth)
+ cl2 = cl2->parent;
+
+ /* Now reduce both clusters to their ancestors at the point where both have
+ a common parent; these can be directly compared. */
+ while (cl1->parent != cl2->parent)
+ cl1 = cl1->parent, cl2 = cl2->parent;
+
+ return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index);
+}
+
+/* Return the ancestor of CL that's just below the root (i.e., has a parent
+ of 0). */
+static struct hol_cluster *
+hol_cluster_base (struct hol_cluster *cl)
+{
+ while (cl->parent)
+ cl = cl->parent;
+ return cl;
+}
+
+/* Return true if CL1 is a child of CL2. */
+static int
+hol_cluster_is_child (const struct hol_cluster *cl1,
+ const struct hol_cluster *cl2)
+{
+ while (cl1 && cl1 != cl2)
+ cl1 = cl1->parent;
+ return cl1 == cl2;
+}
+
+/* Given the name of a OPTION_DOC option, modifies NAME to start at the tail
+ that should be used for comparisons, and returns true iff it should be
+ treated as a non-option. */
+
+/* FIXME: Can we use unsigned char * for the argument? */
+static int
+canon_doc_option (const char **name)
+{
+ int non_opt;
+ /* Skip initial whitespace. */
+ while (isspace ( (unsigned char) **name))
+ (*name)++;
+ /* Decide whether this looks like an option (leading `-') or not. */
+ non_opt = (**name != '-');
+ /* Skip until part of name used for sorting. */
+ while (**name && !isalnum ( (unsigned char) **name))
+ (*name)++;
+ return non_opt;
+}
+
+/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help
+ listing. */
+static int
+hol_entry_cmp (const struct hol_entry *entry1,
+ const struct hol_entry *entry2)
+{
+ /* The group numbers by which the entries should be ordered; if either is
+ in a cluster, then this is just the group within the cluster. */
+ int group1 = entry1->group, group2 = entry2->group;
+
+ if (entry1->cluster != entry2->cluster)
+ {
+ /* The entries are not within the same cluster, so we can't compare them
+ directly, we have to use the appropiate clustering level too. */
+ if (! entry1->cluster)
+ /* ENTRY1 is at the `base level', not in a cluster, so we have to
+ compare it's group number with that of the base cluster in which
+ ENTRY2 resides. Note that if they're in the same group, the
+ clustered option always comes laster. */
+ return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1);
+ else if (! entry2->cluster)
+ /* Likewise, but ENTRY2's not in a cluster. */
+ return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1);
+ else
+ /* Both entries are in clusters, we can just compare the clusters. */
+ return hol_cluster_cmp (entry1->cluster, entry2->cluster);
+ }
+ else if (group1 == group2)
+ /* The entries are both in the same cluster and group, so compare them
+ alphabetically. */
+ {
+ int short1 = hol_entry_first_short (entry1);
+ int short2 = hol_entry_first_short (entry2);
+ int doc1 = odoc (entry1->opt);
+ int doc2 = odoc (entry2->opt);
+ /* FIXME: Can we use unsigned char * instead? */
+ const char *long1 = hol_entry_first_long (entry1);
+ const char *long2 = hol_entry_first_long (entry2);
+
+ if (doc1)
+ doc1 = canon_doc_option (&long1);
+ if (doc2)
+ doc2 = canon_doc_option (&long2);
+
+ if (doc1 != doc2)
+ /* `documentation' options always follow normal options (or
+ documentation options that *look* like normal options). */
+ return doc1 - doc2;
+ else if (!short1 && !short2 && long1 && long2)
+ /* Only long options. */
+ return __strcasecmp (long1, long2);
+ else
+ /* Compare short/short, long/short, short/long, using the first
+ character of long options. Entries without *any* valid
+ options (such as options with OPTION_HIDDEN set) will be put
+ first, but as they're not displayed, it doesn't matter where
+ they are. */
+ {
+ unsigned char first1 = short1 ? short1 : long1 ? *long1 : 0;
+ unsigned char first2 = short2 ? short2 : long2 ? *long2 : 0;
+#ifdef _tolower
+ int lower_cmp = _tolower (first1) - _tolower (first2);
+#else
+ int lower_cmp = tolower (first1) - tolower (first2);
+#endif
+ /* Compare ignoring case, except when the options are both the
+ same letter, in which case lower-case always comes first. */
+ /* NOTE: The subtraction below does the right thing
+ even with eight-bit chars: first1 and first2 are
+ converted to int *before* the subtraction. */
+ return lower_cmp ? lower_cmp : first2 - first1;
+ }
+ }
+ else
+ /* Within the same cluster, but not the same group, so just compare
+ groups. */
+ return group_cmp (group1, group2, 0);
+}
+
+/* Version of hol_entry_cmp with correct signature for qsort. */
+static int
+hol_entry_qcmp (const void *entry1_v, const void *entry2_v)
+{
+ return hol_entry_cmp (entry1_v, entry2_v);
+}
+
+/* Sort HOL by group and alphabetically by option name (with short options
+ taking precedence over long). Since the sorting is for display purposes
+ only, the shadowing of options isn't effected. */
+static void
+hol_sort (struct hol *hol)
+{
+ if (hol->num_entries > 0)
+ qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry),
+ hol_entry_qcmp);
+}
+
+/* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow
+ any in MORE with the same name. */
+static void
+hol_append (struct hol *hol, struct hol *more)
+{
+ struct hol_cluster **cl_end = &hol->clusters;
+
+ /* Steal MORE's cluster list, and add it to the end of HOL's. */
+ while (*cl_end)
+ cl_end = &(*cl_end)->next;
+ *cl_end = more->clusters;
+ more->clusters = 0;
+
+ /* Merge entries. */
+ if (more->num_entries > 0)
+ {
+ if (hol->num_entries == 0)
+ {
+ hol->num_entries = more->num_entries;
+ hol->entries = more->entries;
+ hol->short_options = more->short_options;
+ more->num_entries = 0; /* Mark MORE's fields as invalid. */
+ }
+ else
+ /* Append the entries in MORE to those in HOL, taking care to only add
+ non-shadowed SHORT_OPTIONS values. */
+ {
+ unsigned left;
+ char *so, *more_so;
+ struct hol_entry *e;
+ unsigned num_entries = hol->num_entries + more->num_entries;
+ struct hol_entry *entries =
+ malloc (num_entries * sizeof (struct hol_entry));
+ unsigned hol_so_len = strlen (hol->short_options);
+ char *short_options =
+ malloc (hol_so_len + strlen (more->short_options) + 1);
+
+ __mempcpy (__mempcpy (entries, hol->entries,
+ hol->num_entries * sizeof (struct hol_entry)),
+ more->entries,
+ more->num_entries * sizeof (struct hol_entry));
+
+ __mempcpy (short_options, hol->short_options, hol_so_len);
+
+ /* Fix up the short options pointers from HOL. */
+ for (e = entries, left = hol->num_entries; left > 0; e++, left--)
+ e->short_options += (short_options - hol->short_options);
+
+ /* Now add the short options from MORE, fixing up its entries
+ too. */
+ so = short_options + hol_so_len;
+ more_so = more->short_options;
+ for (left = more->num_entries; left > 0; e++, left--)
+ {
+ int opts_left;
+ const struct argp_option *opt;
+
+ e->short_options = so;
+
+ for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
+ {
+ int ch = *more_so;
+ if (oshort (opt) && ch == opt->key)
+ /* The next short option in MORE_SO, CH, is from OPT. */
+ {
+ if (! find_char (ch, short_options,
+ short_options + hol_so_len))
+ /* The short option CH isn't shadowed by HOL's options,
+ so add it to the sum. */
+ *so++ = ch;
+ more_so++;
+ }
+ }
+ }
+
+ *so = '\0';
+
+ free (hol->entries);
+ free (hol->short_options);
+
+ hol->entries = entries;
+ hol->num_entries = num_entries;
+ hol->short_options = short_options;
+ }
+ }
+
+ hol_free (more);
+}
+
+/* Inserts enough spaces to make sure STREAM is at column COL. */
+static void
+indent_to (argp_fmtstream_t stream, unsigned col)
+{
+ int needed = col - __argp_fmtstream_point (stream);
+ while (needed-- > 0)
+ __argp_fmtstream_putc (stream, ' ');
+}
+
+/* Output to STREAM either a space, or a newline if there isn't room for at
+ least ENSURE characters before the right margin. */
+static void
+space (argp_fmtstream_t stream, size_t ensure)
+{
+ if (__argp_fmtstream_point (stream) + ensure
+ >= __argp_fmtstream_rmargin (stream))
+ __argp_fmtstream_putc (stream, '\n');
+ else
+ __argp_fmtstream_putc (stream, ' ');
+}
+
+/* If the option REAL has an argument, we print it in using the printf
+ format REQ_FMT or OPT_FMT depending on whether it's a required or
+ optional argument. */
+static void
+arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt,
+ const char *domain UNUSED, argp_fmtstream_t stream)
+{
+ if (real->arg)
+ {
+ if (real->flags & OPTION_ARG_OPTIONAL)
+ __argp_fmtstream_printf (stream, opt_fmt,
+ dgettext (domain, real->arg));
+ else
+ __argp_fmtstream_printf (stream, req_fmt,
+ dgettext (domain, real->arg));
+ }
+}
+
+/* Helper functions for hol_entry_help. */
+
+/* State used during the execution of hol_help. */
+struct hol_help_state
+{
+ /* PREV_ENTRY should contain the previous entry printed, or 0. */
+ struct hol_entry *prev_entry;
+
+ /* If an entry is in a different group from the previous one, and SEP_GROUPS
+ is true, then a blank line will be printed before any output. */
+ int sep_groups;
+
+ /* True if a duplicate option argument was suppressed (only ever set if
+ UPARAMS.dup_args is false). */
+ int suppressed_dup_arg;
+};
+
+/* Some state used while printing a help entry (used to communicate with
+ helper functions). See the doc for hol_entry_help for more info, as most
+ of the fields are copied from its arguments. */
+struct pentry_state
+{
+ const struct hol_entry *entry;
+ argp_fmtstream_t stream;
+ struct hol_help_state *hhstate;
+
+ /* True if nothing's been printed so far. */
+ int first;
+
+ /* If non-zero, the state that was used to print this help. */
+ const struct argp_state *state;
+};
+
+/* If a user doc filter should be applied to DOC, do so. */
+static const char *
+filter_doc (const char *doc, int key, const struct argp *argp,
+ const struct argp_state *state)
+{
+ if (argp->help_filter)
+ /* We must apply a user filter to this output. */
+ {
+ void *input = __argp_input (argp, state);
+ return (*argp->help_filter) (key, doc, input);
+ }
+ else
+ /* No filter. */
+ return doc;
+}
+
+/* Prints STR as a header line, with the margin lines set appropiately, and
+ notes the fact that groups should be separated with a blank line. ARGP is
+ the argp that should dictate any user doc filtering to take place. Note
+ that the previous wrap margin isn't restored, but the left margin is reset
+ to 0. */
+static void
+print_header (const char *str, const struct argp *argp,
+ struct pentry_state *pest)
+{
+ const char *tstr = dgettext (argp->argp_domain, str);
+ const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state);
+
+ if (fstr)
+ {
+ if (*fstr)
+ {
+ if (pest->hhstate->prev_entry)
+ /* Precede with a blank line. */
+ __argp_fmtstream_putc (pest->stream, '\n');
+ indent_to (pest->stream, uparams.header_col);
+ __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col);
+ __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col);
+ __argp_fmtstream_puts (pest->stream, fstr);
+ __argp_fmtstream_set_lmargin (pest->stream, 0);
+ __argp_fmtstream_putc (pest->stream, '\n');
+ }
+
+ pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */
+ }
+
+ if (fstr != tstr)
+ free ((char *) fstr);
+}
+
+/* Inserts a comma if this isn't the first item on the line, and then makes
+ sure we're at least to column COL. If this *is* the first item on a line,
+ prints any pending whitespace/headers that should precede this line. Also
+ clears FIRST. */
+static void
+comma (unsigned col, struct pentry_state *pest)
+{
+ if (pest->first)
+ {
+ const struct hol_entry *pe = pest->hhstate->prev_entry;
+ const struct hol_cluster *cl = pest->entry->cluster;
+
+ if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group)
+ __argp_fmtstream_putc (pest->stream, '\n');
+
+ if (cl && cl->header && *cl->header
+ && (!pe
+ || (pe->cluster != cl
+ && !hol_cluster_is_child (pe->cluster, cl))))
+ /* If we're changing clusters, then this must be the start of the
+ ENTRY's cluster unless that is an ancestor of the previous one
+ (in which case we had just popped into a sub-cluster for a bit).
+ If so, then print the cluster's header line. */
+ {
+ int old_wm = __argp_fmtstream_wmargin (pest->stream);
+ print_header (cl->header, cl->argp, pest);
+ __argp_fmtstream_set_wmargin (pest->stream, old_wm);
+ }
+
+ pest->first = 0;
+ }
+ else
+ __argp_fmtstream_puts (pest->stream, ", ");
+
+ indent_to (pest->stream, col);
+}
+
+/* Print help for ENTRY to STREAM. */
+static void
+hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
+ argp_fmtstream_t stream, struct hol_help_state *hhstate)
+{
+ unsigned num;
+ const struct argp_option *real = entry->opt, *opt;
+ char *so = entry->short_options;
+ int have_long_opt = 0; /* We have any long options. */
+ /* Saved margins. */
+ int old_lm = __argp_fmtstream_set_lmargin (stream, 0);
+ int old_wm = __argp_fmtstream_wmargin (stream);
+ /* PEST is a state block holding some of our variables that we'd like to
+ share with helper functions. */
+
+ /* Decent initializers are a GNU extension, so don't use it here. */
+ struct pentry_state pest;
+ pest.entry = entry;
+ pest.stream = stream;
+ pest.hhstate = hhstate;
+ pest.first = 1;
+ pest.state = state;
+
+ if (! odoc (real))
+ for (opt = real, num = entry->num; num > 0; opt++, num--)
+ if (opt->name && ovisible (opt))
+ {
+ have_long_opt = 1;
+ break;
+ }
+
+ /* First emit short options. */
+ __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */
+ for (opt = real, num = entry->num; num > 0; opt++, num--)
+ if (oshort (opt) && opt->key == *so)
+ /* OPT has a valid (non shadowed) short option. */
+ {
+ if (ovisible (opt))
+ {
+ comma (uparams.short_opt_col, &pest);
+ __argp_fmtstream_putc (stream, '-');
+ __argp_fmtstream_putc (stream, *so);
+ if (!have_long_opt || uparams.dup_args)
+ arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream);
+ else if (real->arg)
+ hhstate->suppressed_dup_arg = 1;
+ }
+ so++;
+ }
+
+ /* Now, long options. */
+ if (odoc (real))
+ /* A `documentation' option. */
+ {
+ __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col);
+ for (opt = real, num = entry->num; num > 0; opt++, num--)
+ if (opt->name && ovisible (opt))
+ {
+ comma (uparams.doc_opt_col, &pest);
+ /* Calling gettext here isn't quite right, since sorting will
+ have been done on the original; but documentation options
+ should be pretty rare anyway... */
+ __argp_fmtstream_puts (stream,
+ dgettext (state->root_argp->argp_domain,
+ opt->name));
+ }
+ }
+ else
+ /* A real long option. */
+ {
+ int first_long_opt = 1;
+
+ __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col);
+ for (opt = real, num = entry->num; num > 0; opt++, num--)
+ if (opt->name && ovisible (opt))
+ {
+ comma (uparams.long_opt_col, &pest);
+ __argp_fmtstream_printf (stream, "--%s", opt->name);
+ if (first_long_opt || uparams.dup_args)
+ arg (real, "=%s", "[=%s]", state->root_argp->argp_domain,
+ stream);
+ else if (real->arg)
+ hhstate->suppressed_dup_arg = 1;
+ }
+ }
+
+ /* Next, documentation strings. */
+ __argp_fmtstream_set_lmargin (stream, 0);
+
+ if (pest.first)
+ {
+ /* Didn't print any switches, what's up? */
+ if (!oshort (real) && !real->name)
+ /* This is a group header, print it nicely. */
+ print_header (real->doc, entry->argp, &pest);
+ else
+ /* Just a totally shadowed option or null header; print nothing. */
+ goto cleanup; /* Just return, after cleaning up. */
+ }
+ else
+ {
+ const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain,
+ real->doc) : 0;
+ const char *fstr = filter_doc (tstr, real->key, entry->argp, state);
+ if (fstr && *fstr)
+ {
+ unsigned int col = __argp_fmtstream_point (stream);
+
+ __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col);
+ __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col);
+
+ if (col > (unsigned int) (uparams.opt_doc_col + 3))
+ __argp_fmtstream_putc (stream, '\n');
+ else if (col >= (unsigned int) uparams.opt_doc_col)
+ __argp_fmtstream_puts (stream, " ");
+ else
+ indent_to (stream, uparams.opt_doc_col);
+
+ __argp_fmtstream_puts (stream, fstr);
+ }
+ if (fstr && fstr != tstr)
+ free ((char *) fstr);
+
+ /* Reset the left margin. */
+ __argp_fmtstream_set_lmargin (stream, 0);
+ __argp_fmtstream_putc (stream, '\n');
+ }
+
+ hhstate->prev_entry = entry;
+
+cleanup:
+ __argp_fmtstream_set_lmargin (stream, old_lm);
+ __argp_fmtstream_set_wmargin (stream, old_wm);
+}
+
+/* Output a long help message about the options in HOL to STREAM. */
+static void
+hol_help (struct hol *hol, const struct argp_state *state,
+ argp_fmtstream_t stream)
+{
+ unsigned num;
+ struct hol_entry *entry;
+ struct hol_help_state hhstate = { 0, 0, 0 };
+
+ for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--)
+ hol_entry_help (entry, state, stream, &hhstate);
+
+ if (hhstate.suppressed_dup_arg && uparams.dup_args_note)
+ {
+ const char *tstr = dgettext (state->root_argp->argp_domain, "\
+Mandatory or optional arguments to long options are also mandatory or \
+optional for any corresponding short options.");
+ const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE,
+ state ? state->root_argp : 0, state);
+ if (fstr && *fstr)
+ {
+ __argp_fmtstream_putc (stream, '\n');
+ __argp_fmtstream_puts (stream, fstr);
+ __argp_fmtstream_putc (stream, '\n');
+ }
+ if (fstr && fstr != tstr)
+ free ((char *) fstr);
+ }
+}
+
+/* Helper functions for hol_usage. */
+
+/* If OPT is a short option without an arg, append its key to the string
+ pointer pointer to by COOKIE, and advance the pointer. */
+static int
+add_argless_short_opt (const struct argp_option *opt,
+ const struct argp_option *real,
+ const char *domain UNUSED, void *cookie)
+{
+ char **snao_end = cookie;
+ if (!(opt->arg || real->arg)
+ && !((opt->flags | real->flags) & OPTION_NO_USAGE))
+ *(*snao_end)++ = opt->key;
+ return 0;
+}
+
+/* If OPT is a short option with an arg, output a usage entry for it to the
+ stream pointed at by COOKIE. */
+static int
+usage_argful_short_opt (const struct argp_option *opt,
+ const struct argp_option *real,
+ const char *domain UNUSED, void *cookie)
+{
+ argp_fmtstream_t stream = cookie;
+ const char *arg = opt->arg;
+ int flags = opt->flags | real->flags;
+
+ if (! arg)
+ arg = real->arg;
+
+ if (arg && !(flags & OPTION_NO_USAGE))
+ {
+ arg = dgettext (domain, arg);
+
+ if (flags & OPTION_ARG_OPTIONAL)
+ __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg);
+ else
+ {
+ /* Manually do line wrapping so that it (probably) won't
+ get wrapped at the embedded space. */
+ space (stream, 6 + strlen (arg));
+ __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg);
+ }
+ }
+
+ return 0;
+}
+
+/* Output a usage entry for the long option opt to the stream pointed at by
+ COOKIE. */
+static int
+usage_long_opt (const struct argp_option *opt,
+ const struct argp_option *real,
+ const char *domain UNUSED, void *cookie)
+{
+ argp_fmtstream_t stream = cookie;
+ const char *arg = opt->arg;
+ int flags = opt->flags | real->flags;
+
+ if (! arg)
+ arg = real->arg;
+
+ if (! (flags & OPTION_NO_USAGE))
+ {
+ if (arg)
+ {
+ arg = dgettext (domain, arg);
+ if (flags & OPTION_ARG_OPTIONAL)
+ __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg);
+ else
+ __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg);
+ }
+ else
+ __argp_fmtstream_printf (stream, " [--%s]", opt->name);
+ }
+
+ return 0;
+}
+
+/* Print a short usage description for the arguments in HOL to STREAM. */
+static void
+hol_usage (struct hol *hol, argp_fmtstream_t stream)
+{
+ if (hol->num_entries > 0)
+ {
+ unsigned nentries;
+ struct hol_entry *entry;
+ char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1);
+ char *snao_end = short_no_arg_opts;
+
+ /* First we put a list of short options without arguments. */
+ for (entry = hol->entries, nentries = hol->num_entries
+ ; nentries > 0
+ ; entry++, nentries--)
+ hol_entry_short_iterate (entry, add_argless_short_opt,
+ entry->argp->argp_domain, &snao_end);
+ if (snao_end > short_no_arg_opts)
+ {
+ *snao_end++ = 0;
+ __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts);
+ }
+
+ /* Now a list of short options *with* arguments. */
+ for (entry = hol->entries, nentries = hol->num_entries
+ ; nentries > 0
+ ; entry++, nentries--)
+ hol_entry_short_iterate (entry, usage_argful_short_opt,
+ entry->argp->argp_domain, stream);
+
+ /* Finally, a list of long options (whew!). */
+ for (entry = hol->entries, nentries = hol->num_entries
+ ; nentries > 0
+ ; entry++, nentries--)
+ hol_entry_long_iterate (entry, usage_long_opt,
+ entry->argp->argp_domain, stream);
+ }
+}
+
+/* Make a HOL containing all levels of options in ARGP. CLUSTER is the
+ cluster in which ARGP's entries should be clustered, or 0. */
+static struct hol *
+argp_hol (const struct argp *argp, struct hol_cluster *cluster)
+{
+ const struct argp_child *child = argp->children;
+ struct hol *hol = make_hol (argp, cluster);
+ if (child)
+ while (child->argp)
+ {
+ struct hol_cluster *child_cluster =
+ ((child->group || child->header)
+ /* Put CHILD->argp within its own cluster. */
+ ? hol_add_cluster (hol, child->group, child->header,
+ child - argp->children, cluster, argp)
+ /* Just merge it into the parent's cluster. */
+ : cluster);
+ hol_append (hol, argp_hol (child->argp, child_cluster)) ;
+ child++;
+ }
+ return hol;
+}
+
+/* Calculate how many different levels with alternative args strings exist in
+ ARGP. */
+static size_t
+argp_args_levels (const struct argp *argp)
+{
+ size_t levels = 0;
+ const struct argp_child *child = argp->children;
+
+ if (argp->args_doc && strchr (argp->args_doc, '\n'))
+ levels++;
+
+ if (child)
+ while (child->argp)
+ levels += argp_args_levels ((child++)->argp);
+
+ return levels;
+}
+
+/* Print all the non-option args documented in ARGP to STREAM. Any output is
+ preceded by a space. LEVELS is a pointer to a byte vector the length
+ returned by argp_args_levels; it should be initialized to zero, and
+ updated by this routine for the next call if ADVANCE is true. True is
+ returned as long as there are more patterns to output. */
+static int
+argp_args_usage (const struct argp *argp, const struct argp_state *state,
+ char **levels, int advance, argp_fmtstream_t stream)
+{
+ char *our_level = *levels;
+ int multiple = 0;
+ const struct argp_child *child = argp->children;
+ const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
+ const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
+
+ if (fdoc)
+ {
+ const char *cp = fdoc;
+ nl = __strchrnul (cp, '\n');
+ if (*nl != '\0')
+ /* This is a `multi-level' args doc; advance to the correct position
+ as determined by our state in LEVELS, and update LEVELS. */
+ {
+ int i;
+ multiple = 1;
+ for (i = 0; i < *our_level; i++)
+ cp = nl + 1, nl = __strchrnul (cp, '\n');
+ (*levels)++;
+ }
+
+ /* Manually do line wrapping so that it (probably) won't get wrapped at
+ any embedded spaces. */
+ space (stream, 1 + nl - cp);
+
+ __argp_fmtstream_write (stream, cp, nl - cp);
+ }
+ if (fdoc && fdoc != tdoc)
+ free ((char *)fdoc); /* Free user's modified doc string. */
+
+ if (child)
+ while (child->argp)
+ advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);
+
+ if (advance && multiple)
+ {
+ /* Need to increment our level. */
+ if (*nl)
+ /* There's more we can do here. */
+ {
+ (*our_level)++;
+ advance = 0; /* Our parent shouldn't advance also. */
+ }
+ else if (*our_level > 0)
+ /* We had multiple levels, but used them up; reset to zero. */
+ *our_level = 0;
+ }
+
+ return !advance;
+}
+
+/* Print the documentation for ARGP to STREAM; if POST is false, then
+ everything preceeding a `\v' character in the documentation strings (or
+ the whole string, for those with none) is printed, otherwise, everything
+ following the `\v' character (nothing for strings without). Each separate
+ bit of documentation is separated a blank line, and if PRE_BLANK is true,
+ then the first is as well. If FIRST_ONLY is true, only the first
+ occurrence is output. Returns true if anything was output. */
+static int
+argp_doc (const struct argp *argp, const struct argp_state *state,
+ int post, int pre_blank, int first_only,
+ argp_fmtstream_t stream)
+{
+ const char *text;
+ const char *inp_text;
+ void *input = 0;
+ int anything = 0;
+ size_t inp_text_limit = 0;
+ const char *doc = dgettext (argp->argp_domain, argp->doc);
+ const struct argp_child *child = argp->children;
+
+ if (doc)
+ {
+ char *vt = strchr (doc, '\v');
+ inp_text = post ? (vt ? vt + 1 : 0) : doc;
+ inp_text_limit = (!post && vt) ? (vt - doc) : 0;
+ }
+ else
+ inp_text = 0;
+
+ if (argp->help_filter)
+ /* We have to filter the doc strings. */
+ {
+ if (inp_text_limit)
+ /* Copy INP_TEXT so that it's nul-terminated. */
+ inp_text = STRNDUP (inp_text, inp_text_limit);
+ input = __argp_input (argp, state);
+ text =
+ (*argp->help_filter) (post
+ ? ARGP_KEY_HELP_POST_DOC
+ : ARGP_KEY_HELP_PRE_DOC,
+ inp_text, input);
+ }
+ else
+ text = (const char *) inp_text;
+
+ if (text)
+ {
+ if (pre_blank)
+ __argp_fmtstream_putc (stream, '\n');
+
+ if (text == inp_text && inp_text_limit)
+ __argp_fmtstream_write (stream, inp_text, inp_text_limit);
+ else
+ __argp_fmtstream_puts (stream, text);
+
+ if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream))
+ __argp_fmtstream_putc (stream, '\n');
+
+ anything = 1;
+ }
+
+ if (text && text != inp_text)
+ free ((char *) text); /* Free TEXT returned from the help filter. */
+ if (inp_text && inp_text_limit && argp->help_filter)
+ free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */
+
+ if (post && argp->help_filter)
+ /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text. */
+ {
+ text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input);
+ if (text)
+ {
+ if (anything || pre_blank)
+ __argp_fmtstream_putc (stream, '\n');
+ __argp_fmtstream_puts (stream, text);
+ free ((char *) text);
+ if (__argp_fmtstream_point (stream)
+ > __argp_fmtstream_lmargin (stream))
+ __argp_fmtstream_putc (stream, '\n');
+ anything = 1;
+ }
+ }
+
+ if (child)
+ while (child->argp && !(first_only && anything))
+ anything |=
+ argp_doc ((child++)->argp, state,
+ post, anything || pre_blank, first_only,
+ stream);
+
+ return anything;
+}
+
+/* Output a usage message for ARGP to STREAM. If called from
+ argp_state_help, STATE is the relevent parsing state. FLAGS are from the
+ set ARGP_HELP_*. NAME is what to use wherever a `program name' is
+ needed. */
+
+static void
+_help (const struct argp *argp, const struct argp_state *state, FILE *stream,
+ unsigned flags, const char *name)
+{
+ int anything = 0; /* Whether we've output anything. */
+ struct hol *hol = 0;
+ argp_fmtstream_t fs;
+
+ if (! stream)
+ return;
+
+ FLOCKFILE (stream);
+
+ if (! uparams.valid)
+ fill_in_uparams (state);
+
+ fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
+ if (! fs)
+ {
+ FUNLOCKFILE (stream);
+ return;
+ }
+
+ if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG))
+ {
+ hol = argp_hol (argp, 0);
+
+ /* If present, these options always come last. */
+ hol_set_group (hol, "help", -1);
+ hol_set_group (hol, "version", -1);
+
+ hol_sort (hol);
+ }
+
+ if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE))
+ /* Print a short `Usage:' message. */
+ {
+ int first_pattern = 1, more_patterns;
+ size_t num_pattern_levels = argp_args_levels (argp);
+ char *pattern_levels = alloca (num_pattern_levels);
+
+ memset (pattern_levels, 0, num_pattern_levels);
+
+ do
+ {
+ int old_lm;
+ int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent);
+ char *levels = pattern_levels;
+
+ if (first_pattern)
+ __argp_fmtstream_printf (fs, "%s %s",
+ dgettext (argp->argp_domain, "Usage:"),
+ name);
+ else
+ __argp_fmtstream_printf (fs, "%s %s",
+ dgettext (argp->argp_domain, " or: "),
+ name);
+
+ /* We set the lmargin as well as the wmargin, because hol_usage
+ manually wraps options with newline to avoid annoying breaks. */
+ old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent);
+
+ if (flags & ARGP_HELP_SHORT_USAGE)
+ /* Just show where the options go. */
+ {
+ if (hol->num_entries > 0)
+ __argp_fmtstream_puts (fs, dgettext (argp->argp_domain,
+ " [OPTION...]"));
+ }
+ else
+ /* Actually print the options. */
+ {
+ hol_usage (hol, fs);
+ flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */
+ }
+
+ more_patterns = argp_args_usage (argp, state, &levels, 1, fs);
+
+ __argp_fmtstream_set_wmargin (fs, old_wm);
+ __argp_fmtstream_set_lmargin (fs, old_lm);
+
+ __argp_fmtstream_putc (fs, '\n');
+ anything = 1;
+
+ first_pattern = 0;
+ }
+ while (more_patterns);
+ }
+
+ if (flags & ARGP_HELP_PRE_DOC)
+ anything |= argp_doc (argp, state, 0, 0, 1, fs);
+
+ if (flags & ARGP_HELP_SEE)
+ {
+ __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\
+Try `%s --help' or `%s --usage' for more information.\n"),
+ name, name);
+ anything = 1;
+ }
+
+ if (flags & ARGP_HELP_LONG)
+ /* Print a long, detailed help message. */
+ {
+ /* Print info about all the options. */
+ if (hol->num_entries > 0)
+ {
+ if (anything)
+ __argp_fmtstream_putc (fs, '\n');
+ hol_help (hol, state, fs);
+ anything = 1;
+ }
+ }
+
+ if (flags & ARGP_HELP_POST_DOC)
+ /* Print any documentation strings at the end. */
+ anything |= argp_doc (argp, state, 1, anything, 0, fs);
+
+ if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address)
+ {
+ if (anything)
+ __argp_fmtstream_putc (fs, '\n');
+ __argp_fmtstream_printf (fs, dgettext (argp->argp_domain,
+ "Report bugs to %s.\n"),
+ argp_program_bug_address);
+ anything = 1;
+ }
+
+ FUNLOCKFILE (stream);
+
+ if (hol)
+ hol_free (hol);
+
+ __argp_fmtstream_free (fs);
+}
+
+/* Output a usage message for ARGP to STREAM. FLAGS are from the set
+ ARGP_HELP_*. NAME is what to use wherever a `program name' is needed. */
+void __argp_help (const struct argp *argp, FILE *stream,
+ unsigned flags, char *name)
+{
+ _help (argp, 0, stream, flags, name);
+}
+#ifdef weak_alias
+weak_alias (__argp_help, argp_help)
+#endif
+
+char *__argp_basename(char *name)
+{
+ char *short_name = strrchr(name, '/');
+ return short_name ? short_name + 1 : name;
+}
+
+char *
+__argp_short_program_name(const struct argp_state *state)
+{
+ if (state)
+ return state->name;
+#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+ return program_invocation_short_name;
+#elif HAVE_DECL_PROGRAM_INVOCATION_NAME
+ return __argp_basename(program_invocation_name);
+#else /* !HAVE_DECL_PROGRAM_INVOCATION_NAME */
+ /* FIXME: What now? Miles suggests that it is better to use NULL,
+ but currently the value is passed on directly to fputs_unlocked,
+ so that requires more changes. */
+# if __GNUC__
+ return "";
+# endif /* __GNUC__ */
+#endif /* !HAVE_DECL_PROGRAM_INVOCATION_NAME */
+}
+
+/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
+ from the set ARGP_HELP_*. */
+void
+__argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags)
+{
+ if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream)
+ {
+ if (state && (state->flags & ARGP_LONG_ONLY))
+ flags |= ARGP_HELP_LONG_ONLY;
+
+ _help (state ? state->root_argp : 0, state, stream, flags,
+ __argp_short_program_name(state));
+
+ if (!state || ! (state->flags & ARGP_NO_EXIT))
+ {
+ if (flags & ARGP_HELP_EXIT_ERR)
+ exit (argp_err_exit_status);
+ if (flags & ARGP_HELP_EXIT_OK)
+ exit (0);
+ }
+ }
+}
+#ifdef weak_alias
+weak_alias (__argp_state_help, argp_state_help)
+#endif
+
+/* If appropriate, print the printf string FMT and following args, preceded
+ by the program name and `:', to stderr, and followed by a `Try ... --help'
+ message, then exit (1). */
+void
+__argp_error (const struct argp_state *state, const char *fmt, ...)
+{
+ if (!state || !(state->flags & ARGP_NO_ERRS))
+ {
+ FILE *stream = state ? state->err_stream : stderr;
+
+ if (stream)
+ {
+ va_list ap;
+
+ FLOCKFILE (stream);
+
+ FPUTS_UNLOCKED (__argp_short_program_name(state),
+ stream);
+ PUTC_UNLOCKED (':', stream);
+ PUTC_UNLOCKED (' ', stream);
+
+ va_start (ap, fmt);
+ vfprintf (stream, fmt, ap);
+ va_end (ap);
+
+ PUTC_UNLOCKED ('\n', stream);
+
+ __argp_state_help (state, stream, ARGP_HELP_STD_ERR);
+
+ FUNLOCKFILE (stream);
+ }
+ }
+}
+#ifdef weak_alias
+weak_alias (__argp_error, argp_error)
+#endif
+
+/* Similar to the standard gnu error-reporting function error(), but will
+ respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
+ to STATE->err_stream. This is useful for argument parsing code that is
+ shared between program startup (when exiting is desired) and runtime
+ option parsing (when typically an error code is returned instead). The
+ difference between this function and argp_error is that the latter is for
+ *parsing errors*, and the former is for other problems that occur during
+ parsing but don't reflect a (syntactic) problem with the input. */
+void
+__argp_failure (const struct argp_state *state, int status, int errnum,
+ const char *fmt, ...)
+{
+ if (!state || !(state->flags & ARGP_NO_ERRS))
+ {
+ FILE *stream = state ? state->err_stream : stderr;
+
+ if (stream)
+ {
+ FLOCKFILE (stream);
+
+ FPUTS_UNLOCKED (__argp_short_program_name(state),
+ stream);
+
+ if (fmt)
+ {
+ va_list ap;
+
+ PUTC_UNLOCKED (':', stream);
+ PUTC_UNLOCKED (' ', stream);
+
+ va_start (ap, fmt);
+ vfprintf (stream, fmt, ap);
+ va_end (ap);
+ }
+
+ if (errnum)
+ {
+ PUTC_UNLOCKED (':', stream);
+ PUTC_UNLOCKED (' ', stream);
+ fputs (STRERROR (errnum), stream);
+ }
+
+ PUTC_UNLOCKED ('\n', stream);
+
+ FUNLOCKFILE (stream);
+
+ if (status && (!state || !(state->flags & ARGP_NO_EXIT)))
+ exit (status);
+ }
+ }
+}
+#ifdef weak_alias
+weak_alias (__argp_failure, argp_failure)
+#endif
diff --git a/argp-standalone/argp-namefrob.h b/argp-standalone/argp-namefrob.h
new file mode 100644
index 000000000..0ce11481a
--- /dev/null
+++ b/argp-standalone/argp-namefrob.h
@@ -0,0 +1,96 @@
+/* Name frobnication for compiling argp outside of glibc
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#if !_LIBC
+/* This code is written for inclusion in gnu-libc, and uses names in the
+ namespace reserved for libc. If we're not compiling in libc, define those
+ names to be the normal ones instead. */
+
+/* argp-parse functions */
+#undef __argp_parse
+#define __argp_parse argp_parse
+#undef __option_is_end
+#define __option_is_end _option_is_end
+#undef __option_is_short
+#define __option_is_short _option_is_short
+#undef __argp_input
+#define __argp_input _argp_input
+
+/* argp-help functions */
+#undef __argp_help
+#define __argp_help argp_help
+#undef __argp_error
+#define __argp_error argp_error
+#undef __argp_failure
+#define __argp_failure argp_failure
+#undef __argp_state_help
+#define __argp_state_help argp_state_help
+#undef __argp_usage
+#define __argp_usage argp_usage
+#undef __argp_basename
+#define __argp_basename _argp_basename
+#undef __argp_short_program_name
+#define __argp_short_program_name _argp_short_program_name
+
+/* argp-fmtstream functions */
+#undef __argp_make_fmtstream
+#define __argp_make_fmtstream argp_make_fmtstream
+#undef __argp_fmtstream_free
+#define __argp_fmtstream_free argp_fmtstream_free
+#undef __argp_fmtstream_putc
+#define __argp_fmtstream_putc argp_fmtstream_putc
+#undef __argp_fmtstream_puts
+#define __argp_fmtstream_puts argp_fmtstream_puts
+#undef __argp_fmtstream_write
+#define __argp_fmtstream_write argp_fmtstream_write
+#undef __argp_fmtstream_printf
+#define __argp_fmtstream_printf argp_fmtstream_printf
+#undef __argp_fmtstream_set_lmargin
+#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
+#undef __argp_fmtstream_set_rmargin
+#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
+#undef __argp_fmtstream_set_wmargin
+#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
+#undef __argp_fmtstream_point
+#define __argp_fmtstream_point argp_fmtstream_point
+#undef __argp_fmtstream_update
+#define __argp_fmtstream_update _argp_fmtstream_update
+#undef __argp_fmtstream_ensure
+#define __argp_fmtstream_ensure _argp_fmtstream_ensure
+#undef __argp_fmtstream_lmargin
+#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
+#undef __argp_fmtstream_rmargin
+#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
+#undef __argp_fmtstream_wmargin
+#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
+
+/* normal libc functions we call */
+#undef __sleep
+#define __sleep sleep
+#undef __strcasecmp
+#define __strcasecmp strcasecmp
+#undef __vsnprintf
+#define __vsnprintf vsnprintf
+
+#endif /* !_LIBC */
+
+#ifndef __set_errno
+#define __set_errno(e) (errno = (e))
+#endif
diff --git a/argp-standalone/argp-parse.c b/argp-standalone/argp-parse.c
new file mode 100644
index 000000000..78f7bf139
--- /dev/null
+++ b/argp-standalone/argp-parse.c
@@ -0,0 +1,1305 @@
+/* Hierarchial argument parsing
+ Copyright (C) 1995, 96, 97, 98, 99, 2000,2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <limits.h>
+#include <assert.h>
+
+#if HAVE_MALLOC_H
+/* Needed, for alloca on windows */
+# include <malloc.h>
+#endif
+
+#ifndef _
+/* This is for other GNU distributions with internationalized messages.
+ When compiling libc, the _ macro is predefined. */
+# if defined HAVE_LIBINTL_H || defined _LIBC
+# include <libintl.h>
+# ifdef _LIBC
+# undef dgettext
+# define dgettext(domain, msgid) __dcgettext (domain, msgid, LC_MESSAGES)
+# endif
+# else
+# define dgettext(domain, msgid) (msgid)
+# define gettext(msgid) (msgid)
+# endif
+#endif
+#ifndef N_
+# define N_(msgid) (msgid)
+#endif
+
+#if _LIBC - 0
+#include <bits/libc-lock.h>
+#else
+#ifdef HAVE_CTHREADS_H
+#include <cthreads.h>
+#endif
+#endif /* _LIBC */
+
+#include "argp.h"
+#include "argp-namefrob.h"
+
+
+/* The meta-argument used to prevent any further arguments being interpreted
+ as options. */
+#define QUOTE "--"
+
+/* EZ alias for ARGP_ERR_UNKNOWN. */
+#define EBADKEY ARGP_ERR_UNKNOWN
+
+
+/* Default options. */
+
+/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep
+ for one second intervals, decrementing _ARGP_HANG until it's zero. Thus
+ you can force the program to continue by attaching a debugger and setting
+ it to 0 yourself. */
+volatile int _argp_hang;
+
+#define OPT_PROGNAME -2
+#define OPT_USAGE -3
+#if HAVE_SLEEP && HAVE_GETPID
+#define OPT_HANG -4
+#endif
+
+static const struct argp_option argp_default_options[] =
+{
+ {"help", '?', 0, 0, N_("Give this help list"), -1},
+ {"usage", OPT_USAGE, 0, 0, N_("Give a short usage message"), 0 },
+ {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN,
+ N_("Set the program name"), 0},
+#if OPT_HANG
+ {"HANG", OPT_HANG, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
+ N_("Hang for SECS seconds (default 3600)"), 0 },
+#endif
+ {0, 0, 0, 0, 0, 0}
+};
+
+static error_t
+argp_default_parser (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ case '?':
+ __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
+ break;
+ case OPT_USAGE:
+ __argp_state_help (state, state->out_stream,
+ ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
+ break;
+
+ case OPT_PROGNAME: /* Set the program name. */
+#if HAVE_DECL_PROGRAM_INVOCATION_NAME
+ program_invocation_name = arg;
+#endif
+ /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
+ __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
+ to be that, so we have to be a bit careful here.] */
+
+ /* Update what we use for messages. */
+
+ state->name = __argp_basename(arg);
+
+#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+ program_invocation_short_name = state->name;
+#endif
+
+ if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
+ == ARGP_PARSE_ARGV0)
+ /* Update what getopt uses too. */
+ state->argv[0] = arg;
+
+ break;
+
+#if OPT_HANG
+ case OPT_HANG:
+ _argp_hang = atoi (arg ? arg : "3600");
+ fprintf(state->err_stream, "%s: pid = %ld\n",
+ state->name, (long) getpid());
+ while (_argp_hang-- > 0)
+ __sleep (1);
+ break;
+#endif
+
+ default:
+ return EBADKEY;
+ }
+ return 0;
+}
+
+static const struct argp argp_default_argp =
+ {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"};
+
+
+static const struct argp_option argp_version_options[] =
+{
+ {"version", 'V', 0, 0, N_("Print program version"), -1},
+ {0, 0, 0, 0, 0, 0 }
+};
+
+static error_t
+argp_version_parser (int key, char *arg UNUSED, struct argp_state *state)
+{
+ switch (key)
+ {
+ case 'V':
+ if (argp_program_version_hook)
+ (*argp_program_version_hook) (state->out_stream, state);
+ else if (argp_program_version)
+ fprintf (state->out_stream, "%s\n", argp_program_version);
+ else
+ __argp_error (state, dgettext (state->root_argp->argp_domain,
+ "(PROGRAM ERROR) No version known!?"));
+ if (! (state->flags & ARGP_NO_EXIT))
+ exit (0);
+ break;
+ default:
+ return EBADKEY;
+ }
+ return 0;
+}
+
+static const struct argp argp_version_argp =
+ {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"};
+
+
+
+/* The state of a `group' during parsing. Each group corresponds to a
+ particular argp structure from the tree of such descending from the top
+ level argp passed to argp_parse. */
+struct group
+{
+ /* This group's parsing function. */
+ argp_parser_t parser;
+
+ /* Which argp this group is from. */
+ const struct argp *argp;
+
+ /* The number of non-option args sucessfully handled by this parser. */
+ unsigned args_processed;
+
+ /* This group's parser's parent's group. */
+ struct group *parent;
+ unsigned parent_index; /* And the our position in the parent. */
+
+ /* These fields are swapped into and out of the state structure when
+ calling this group's parser. */
+ void *input, **child_inputs;
+ void *hook;
+};
+
+/* Call GROUP's parser with KEY and ARG, swapping any group-specific info
+ from STATE before calling, and back into state afterwards. If GROUP has
+ no parser, EBADKEY is returned. */
+static error_t
+group_parse (struct group *group, struct argp_state *state, int key, char *arg)
+{
+ if (group->parser)
+ {
+ error_t err;
+ state->hook = group->hook;
+ state->input = group->input;
+ state->child_inputs = group->child_inputs;
+ state->arg_num = group->args_processed;
+ err = (*group->parser)(key, arg, state);
+ group->hook = state->hook;
+ return err;
+ }
+ else
+ return EBADKEY;
+}
+
+struct parser
+{
+ const struct argp *argp;
+
+ const char *posixly_correct;
+
+ /* True if there are only no-option arguments left, which are just
+ passed verbatim with ARGP_KEY_ARG. This is set if we encounter a
+ quote, or the end of the proper options, but may be cleared again
+ if the user moves the next argument pointer backwards. */
+ int args_only;
+
+ /* Describe how to deal with options that follow non-option ARGV-elements.
+
+ If the caller did not specify anything, the default is
+ REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is
+ defined, PERMUTE otherwise.
+
+ REQUIRE_ORDER means don't recognize them as options; stop option
+ processing when the first non-option is seen. This is what Unix
+ does. This mode of operation is selected by either setting the
+ environment variable POSIXLY_CORRECT, or using `+' as the first
+ character of the list of option characters.
+
+ PERMUTE is the default. We permute the contents of ARGV as we
+ scan, so that eventually all the non-options are at the end. This
+ allows options to be given in any order, even with programs that
+ were not written to expect this.
+
+ RETURN_IN_ORDER is an option available to programs that were
+ written to expect options and other ARGV-elements in any order
+ and that care about the ordering of the two. We describe each
+ non-option ARGV-element as if it were the argument of an option
+ with character code 1. Using `-' as the first character of the
+ list of option characters selects this mode of operation.
+
+ */
+ enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering;
+
+ /* A segment of non-option arguments that have been skipped for
+ later processing, after all options. `first_nonopt' is the index
+ in ARGV of the first of them; `last_nonopt' is the index after
+ the last of them.
+
+ If quoted or args_only is non-zero, this segment should be empty. */
+
+ /* FIXME: I'd prefer to use unsigned, but it's more consistent to
+ use the same type as for state.next. */
+ int first_nonopt;
+ int last_nonopt;
+
+ /* String of all recognized short options. Needed for ARGP_LONG_ONLY. */
+ /* FIXME: Perhaps change to a pointer to a suitable bitmap instead? */
+ char *short_opts;
+
+ /* For parsing combined short options. */
+ char *nextchar;
+
+ /* States of the various parsing groups. */
+ struct group *groups;
+ /* The end of the GROUPS array. */
+ struct group *egroup;
+ /* An vector containing storage for the CHILD_INPUTS field in all groups. */
+ void **child_inputs;
+
+ /* State block supplied to parsing routines. */
+ struct argp_state state;
+
+ /* Memory used by this parser. */
+ void *storage;
+};
+
+/* Search for a group defining a short option. */
+static const struct argp_option *
+find_short_option(struct parser *parser, int key, struct group **p)
+{
+ struct group *group;
+
+ assert(key >= 0);
+ assert(isascii(key));
+
+ for (group = parser->groups; group < parser->egroup; group++)
+ {
+ const struct argp_option *opts;
+
+ for (opts = group->argp->options; !__option_is_end(opts); opts++)
+ if (opts->key == key)
+ {
+ *p = group;
+ return opts;
+ }
+ }
+ return NULL;
+}
+
+enum match_result { MATCH_EXACT, MATCH_PARTIAL, MATCH_NO };
+
+/* If defined, allow complete.el-like abbreviations of long options. */
+#ifndef ARGP_COMPLETE
+#define ARGP_COMPLETE 0
+#endif
+
+/* Matches an encountern long-option argument ARG against an option NAME.
+ * ARG is terminated by NUL or '='. */
+static enum match_result
+match_option(const char *arg, const char *name)
+{
+ unsigned i, j;
+ for (i = j = 0;; i++, j++)
+ {
+ switch(arg[i])
+ {
+ case '\0':
+ case '=':
+ return name[j] ? MATCH_PARTIAL : MATCH_EXACT;
+#if ARGP_COMPLETE
+ case '-':
+ while (name[j] != '-')
+ if (!name[j++])
+ return MATCH_NO;
+ break;
+#endif
+ default:
+ if (arg[i] != name[j])
+ return MATCH_NO;
+ }
+ }
+}
+
+static const struct argp_option *
+find_long_option(struct parser *parser,
+ const char *arg,
+ struct group **p)
+{
+ struct group *group;
+
+ /* Partial match found so far. */
+ struct group *matched_group = NULL;
+ const struct argp_option *matched_option = NULL;
+
+ /* Number of partial matches. */
+ int num_partial = 0;
+
+ for (group = parser->groups; group < parser->egroup; group++)
+ {
+ const struct argp_option *opts;
+
+ for (opts = group->argp->options; !__option_is_end(opts); opts++)
+ {
+ if (!opts->name)
+ continue;
+ switch (match_option(arg, opts->name))
+ {
+ case MATCH_NO:
+ break;
+ case MATCH_PARTIAL:
+ num_partial++;
+
+ matched_group = group;
+ matched_option = opts;
+
+ break;
+ case MATCH_EXACT:
+ /* Exact match. */
+ *p = group;
+ return opts;
+ }
+ }
+ }
+ if (num_partial == 1)
+ {
+ *p = matched_group;
+ return matched_option;
+ }
+
+ return NULL;
+}
+
+
+/* The next usable entries in the various parser tables being filled in by
+ convert_options. */
+struct parser_convert_state
+{
+ struct parser *parser;
+ char *short_end;
+ void **child_inputs_end;
+};
+
+/* Initialize GROUP from ARGP. If CVT->SHORT_END is non-NULL, short
+ options are recorded in the short options string. Returns the next
+ unused group entry. CVT holds state used during the conversion. */
+static struct group *
+convert_options (const struct argp *argp,
+ struct group *parent, unsigned parent_index,
+ struct group *group, struct parser_convert_state *cvt)
+{
+ const struct argp_option *opt = argp->options;
+ const struct argp_child *children = argp->children;
+
+ if (opt || argp->parser)
+ {
+ /* This parser needs a group. */
+ if (cvt->short_end)
+ {
+ /* Record any short options. */
+ for ( ; !__option_is_end (opt); opt++)
+ if (__option_is_short(opt))
+ *cvt->short_end++ = opt->key;
+ }
+
+ group->parser = argp->parser;
+ group->argp = argp;
+ group->args_processed = 0;
+ group->parent = parent;
+ group->parent_index = parent_index;
+ group->input = 0;
+ group->hook = 0;
+ group->child_inputs = 0;
+
+ if (children)
+ /* Assign GROUP's CHILD_INPUTS field some space from
+ CVT->child_inputs_end.*/
+ {
+ unsigned num_children = 0;
+ while (children[num_children].argp)
+ num_children++;
+ group->child_inputs = cvt->child_inputs_end;
+ cvt->child_inputs_end += num_children;
+ }
+ parent = group++;
+ }
+ else
+ parent = 0;
+
+ if (children)
+ {
+ unsigned index = 0;
+ while (children->argp)
+ group =
+ convert_options (children++->argp, parent, index++, group, cvt);
+ }
+
+ return group;
+}
+/* Allocate and initialize the group structures, so that they are
+ ordered as if by traversing the corresponding argp parser tree in
+ pre-order. Also build the list of short options, if that is needed. */
+static void
+parser_convert (struct parser *parser, const struct argp *argp)
+{
+ struct parser_convert_state cvt;
+
+ cvt.parser = parser;
+ cvt.short_end = parser->short_opts;
+ cvt.child_inputs_end = parser->child_inputs;
+
+ parser->argp = argp;
+
+ if (argp)
+ parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt);
+ else
+ parser->egroup = parser->groups; /* No parsers at all! */
+
+ if (parser->short_opts)
+ *cvt.short_end ='\0';
+}
+
+/* Lengths of various parser fields which we will allocated. */
+struct parser_sizes
+{
+ /* Needed only ARGP_LONG_ONLY */
+ size_t short_len; /* Number of short options. */
+
+ size_t num_groups; /* Group structures we allocate. */
+ size_t num_child_inputs; /* Child input slots. */
+};
+
+/* For ARGP, increments the NUM_GROUPS field in SZS by the total
+ number of argp structures descended from it, and the SHORT_LEN by
+ the total number of short options. */
+static void
+calc_sizes (const struct argp *argp, struct parser_sizes *szs)
+{
+ const struct argp_child *child = argp->children;
+ const struct argp_option *opt = argp->options;
+
+ if (opt || argp->parser)
+ {
+ /* This parser needs a group. */
+ szs->num_groups++;
+ if (opt)
+ {
+ while (__option_is_short (opt++))
+ szs->short_len++;
+ }
+ }
+
+ if (child)
+ while (child->argp)
+ {
+ calc_sizes ((child++)->argp, szs);
+ szs->num_child_inputs++;
+ }
+}
+
+/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */
+static error_t
+parser_init (struct parser *parser, const struct argp *argp,
+ int argc, char **argv, int flags, void *input)
+{
+ error_t err = 0;
+ struct group *group;
+ struct parser_sizes szs;
+
+ parser->posixly_correct = getenv ("POSIXLY_CORRECT");
+
+ if (flags & ARGP_IN_ORDER)
+ parser->ordering = RETURN_IN_ORDER;
+ else if (flags & ARGP_NO_ARGS)
+ parser->ordering = REQUIRE_ORDER;
+ else if (parser->posixly_correct)
+ parser->ordering = REQUIRE_ORDER;
+ else
+ parser->ordering = PERMUTE;
+
+ szs.short_len = 0;
+ szs.num_groups = 0;
+ szs.num_child_inputs = 0;
+
+ if (argp)
+ calc_sizes (argp, &szs);
+
+ if (!(flags & ARGP_LONG_ONLY))
+ /* We have no use for the short option array. */
+ szs.short_len = 0;
+
+ /* Lengths of the various bits of storage used by PARSER. */
+#define GLEN (szs.num_groups + 1) * sizeof (struct group)
+#define CLEN (szs.num_child_inputs * sizeof (void *))
+#define SLEN (szs.short_len + 1)
+#define STORAGE(offset) ((void *) (((char *) parser->storage) + (offset)))
+
+ parser->storage = malloc (GLEN + CLEN + SLEN);
+ if (! parser->storage)
+ return ENOMEM;
+
+ parser->groups = parser->storage;
+
+ parser->child_inputs = STORAGE(GLEN);
+ memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *));
+
+ if (flags & ARGP_LONG_ONLY)
+ parser->short_opts = STORAGE(GLEN + CLEN);
+ else
+ parser->short_opts = NULL;
+
+ parser_convert (parser, argp);
+
+ memset (&parser->state, 0, sizeof (struct argp_state));
+
+ parser->state.root_argp = parser->argp;
+ parser->state.argc = argc;
+ parser->state.argv = argv;
+ parser->state.flags = flags;
+ parser->state.err_stream = stderr;
+ parser->state.out_stream = stdout;
+ parser->state.pstate = parser;
+
+ parser->args_only = 0;
+ parser->nextchar = NULL;
+ parser->first_nonopt = parser->last_nonopt = 0;
+
+ /* Call each parser for the first time, giving it a chance to propagate
+ values to child parsers. */
+ if (parser->groups < parser->egroup)
+ parser->groups->input = input;
+ for (group = parser->groups;
+ group < parser->egroup && (!err || err == EBADKEY);
+ group++)
+ {
+ if (group->parent)
+ /* If a child parser, get the initial input value from the parent. */
+ group->input = group->parent->child_inputs[group->parent_index];
+
+ if (!group->parser
+ && group->argp->children && group->argp->children->argp)
+ /* For the special case where no parsing function is supplied for an
+ argp, propagate its input to its first child, if any (this just
+ makes very simple wrapper argps more convenient). */
+ group->child_inputs[0] = group->input;
+
+ err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0);
+ }
+ if (err == EBADKEY)
+ err = 0; /* Some parser didn't understand. */
+
+ if (err)
+ return err;
+
+ if (argv[0] && !(parser->state.flags & ARGP_PARSE_ARGV0))
+ /* There's an argv[0]; use it for messages. */
+ {
+ parser->state.name = __argp_basename(argv[0]);
+
+ /* Don't parse it as an argument. */
+ parser->state.next = 1;
+ }
+ else
+ parser->state.name = __argp_short_program_name(NULL);
+
+ return 0;
+}
+
+/* Free any storage consumed by PARSER (but not PARSER itself). */
+static error_t
+parser_finalize (struct parser *parser,
+ error_t err, int arg_ebadkey, int *end_index)
+{
+ struct group *group;
+
+ if (err == EBADKEY && arg_ebadkey)
+ /* Suppress errors generated by unparsed arguments. */
+ err = 0;
+
+ if (! err)
+ {
+ if (parser->state.next == parser->state.argc)
+ /* We successfully parsed all arguments! Call all the parsers again,
+ just a few more times... */
+ {
+ for (group = parser->groups;
+ group < parser->egroup && (!err || err==EBADKEY);
+ group++)
+ if (group->args_processed == 0)
+ err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
+ for (group = parser->egroup - 1;
+ group >= parser->groups && (!err || err==EBADKEY);
+ group--)
+ err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
+
+ if (err == EBADKEY)
+ err = 0; /* Some parser didn't understand. */
+
+ /* Tell the user that all arguments are parsed. */
+ if (end_index)
+ *end_index = parser->state.next;
+ }
+ else if (end_index)
+ /* Return any remaining arguments to the user. */
+ *end_index = parser->state.next;
+ else
+ /* No way to return the remaining arguments, they must be bogus. */
+ {
+ if (!(parser->state.flags & ARGP_NO_ERRS)
+ && parser->state.err_stream)
+ fprintf (parser->state.err_stream,
+ dgettext (parser->argp->argp_domain,
+ "%s: Too many arguments\n"),
+ parser->state.name);
+ err = EBADKEY;
+ }
+ }
+
+ /* Okay, we're all done, with either an error or success; call the parsers
+ to indicate which one. */
+
+ if (err)
+ {
+ /* Maybe print an error message. */
+ if (err == EBADKEY)
+ /* An appropriate message describing what the error was should have
+ been printed earlier. */
+ __argp_state_help (&parser->state, parser->state.err_stream,
+ ARGP_HELP_STD_ERR);
+
+ /* Since we didn't exit, give each parser an error indication. */
+ for (group = parser->groups; group < parser->egroup; group++)
+ group_parse (group, &parser->state, ARGP_KEY_ERROR, 0);
+ }
+ else
+ /* Notify parsers of success, and propagate back values from parsers. */
+ {
+ /* We pass over the groups in reverse order so that child groups are
+ given a chance to do there processing before passing back a value to
+ the parent. */
+ for (group = parser->egroup - 1
+ ; group >= parser->groups && (!err || err == EBADKEY)
+ ; group--)
+ err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0);
+ if (err == EBADKEY)
+ err = 0; /* Some parser didn't understand. */
+ }
+
+ /* Call parsers once more, to do any final cleanup. Errors are ignored. */
+ for (group = parser->egroup - 1; group >= parser->groups; group--)
+ group_parse (group, &parser->state, ARGP_KEY_FINI, 0);
+
+ if (err == EBADKEY)
+ err = EINVAL;
+
+ free (parser->storage);
+
+ return err;
+}
+
+/* Call the user parsers to parse the non-option argument VAL, at the
+ current position, returning any error. The state NEXT pointer
+ should point to the argument; this function will adjust it
+ correctly to reflect however many args actually end up being
+ consumed. */
+static error_t
+parser_parse_arg (struct parser *parser, char *val)
+{
+ /* Save the starting value of NEXT */
+ int index = parser->state.next;
+ error_t err = EBADKEY;
+ struct group *group;
+ int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */
+
+ /* Try to parse the argument in each parser. */
+ for (group = parser->groups
+ ; group < parser->egroup && err == EBADKEY
+ ; group++)
+ {
+ parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */
+ key = ARGP_KEY_ARG;
+ err = group_parse (group, &parser->state, key, val);
+
+ if (err == EBADKEY)
+ /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */
+ {
+ parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */
+ key = ARGP_KEY_ARGS;
+ err = group_parse (group, &parser->state, key, 0);
+ }
+ }
+
+ if (! err)
+ {
+ if (key == ARGP_KEY_ARGS)
+ /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't
+ changed by the user, *all* arguments should be considered
+ consumed. */
+ parser->state.next = parser->state.argc;
+
+ if (parser->state.next > index)
+ /* Remember that we successfully processed a non-option
+ argument -- but only if the user hasn't gotten tricky and set
+ the clock back. */
+ (--group)->args_processed += (parser->state.next - index);
+ else
+ /* The user wants to reparse some args, so try looking for options again. */
+ parser->args_only = 0;
+ }
+
+ return err;
+}
+
+/* Exchange two adjacent subsequences of ARGV.
+ One subsequence is elements [first_nonopt,last_nonopt)
+ which contains all the non-options that have been skipped so far.
+ The other is elements [last_nonopt,next), which contains all
+ the options processed since those non-options were skipped.
+
+ `first_nonopt' and `last_nonopt' are relocated so that they describe
+ the new indices of the non-options in ARGV after they are moved. */
+
+static void
+exchange (struct parser *parser)
+{
+ int bottom = parser->first_nonopt;
+ int middle = parser->last_nonopt;
+ int top = parser->state.next;
+ char **argv = parser->state.argv;
+
+ char *tem;
+
+ /* Exchange the shorter segment with the far end of the longer segment.
+ That puts the shorter segment into the right place.
+ It leaves the longer segment in the right place overall,
+ but it consists of two parts that need to be swapped next. */
+
+ while (top > middle && middle > bottom)
+ {
+ if (top - middle > middle - bottom)
+ {
+ /* Bottom segment is the short one. */
+ int len = middle - bottom;
+ register int i;
+
+ /* Swap it with the top part of the top segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[top - (middle - bottom) + i];
+ argv[top - (middle - bottom) + i] = tem;
+ }
+ /* Exclude the moved bottom segment from further swapping. */
+ top -= len;
+ }
+ else
+ {
+ /* Top segment is the short one. */
+ int len = top - middle;
+ register int i;
+
+ /* Swap it with the bottom part of the bottom segment. */
+ for (i = 0; i < len; i++)
+ {
+ tem = argv[bottom + i];
+ argv[bottom + i] = argv[middle + i];
+ argv[middle + i] = tem;
+ }
+ /* Exclude the moved top segment from further swapping. */
+ bottom += len;
+ }
+ }
+
+ /* Update records for the slots the non-options now occupy. */
+
+ parser->first_nonopt += (parser->state.next - parser->last_nonopt);
+ parser->last_nonopt = parser->state.next;
+}
+
+
+
+enum arg_type { ARG_ARG, ARG_SHORT_OPTION,
+ ARG_LONG_OPTION, ARG_LONG_ONLY_OPTION,
+ ARG_QUOTE };
+
+static enum arg_type
+classify_arg(struct parser *parser, char *arg, char **opt)
+{
+ if (arg[0] == '-')
+ /* Looks like an option... */
+ switch (arg[1])
+ {
+ case '\0':
+ /* "-" is not an option. */
+ return ARG_ARG;
+ case '-':
+ /* Long option, or quote. */
+ if (!arg[2])
+ return ARG_QUOTE;
+
+ /* A long option. */
+ if (opt)
+ *opt = arg + 2;
+ return ARG_LONG_OPTION;
+
+ default:
+ /* Short option. But if ARGP_LONG_ONLY, it can also be a long option. */
+
+ if (opt)
+ *opt = arg + 1;
+
+ if (parser->state.flags & ARGP_LONG_ONLY)
+ {
+ /* Rules from getopt.c:
+
+ If long_only and the ARGV-element has the form "-f",
+ where f is a valid short option, don't consider it an
+ abbreviated form of a long option that starts with f.
+ Otherwise there would be no way to give the -f short
+ option.
+
+ On the other hand, if there's a long option "fubar" and
+ the ARGV-element is "-fu", do consider that an
+ abbreviation of the long option, just like "--fu", and
+ not "-f" with arg "u".
+
+ This distinction seems to be the most useful approach. */
+
+ assert(parser->short_opts);
+
+ if (arg[2] || !strchr(parser->short_opts, arg[1]))
+ return ARG_LONG_ONLY_OPTION;
+ }
+
+ return ARG_SHORT_OPTION;
+ }
+
+ else
+ return ARG_ARG;
+}
+
+/* Parse the next argument in PARSER (as indicated by PARSER->state.next).
+ Any error from the parsers is returned, and *ARGP_EBADKEY indicates
+ whether a value of EBADKEY is due to an unrecognized argument (which is
+ generally not fatal). */
+static error_t
+parser_parse_next (struct parser *parser, int *arg_ebadkey)
+{
+ if (parser->state.quoted && parser->state.next < parser->state.quoted)
+ /* The next argument pointer has been moved to before the quoted
+ region, so pretend we never saw the quoting `--', and start
+ looking for options again. If the `--' is still there we'll just
+ process it one more time. */
+ parser->state.quoted = parser->args_only = 0;
+
+ /* Give FIRST_NONOPT & LAST_NONOPT rational values if NEXT has been
+ moved back by the user (who may also have changed the arguments). */
+ if (parser->last_nonopt > parser->state.next)
+ parser->last_nonopt = parser->state.next;
+ if (parser->first_nonopt > parser->state.next)
+ parser->first_nonopt = parser->state.next;
+
+ if (parser->nextchar)
+ /* Deal with short options. */
+ {
+ struct group *group;
+ char c;
+ const struct argp_option *option;
+ char *value = NULL;;
+
+ assert(!parser->args_only);
+
+ c = *parser->nextchar++;
+
+ option = find_short_option(parser, c, &group);
+ if (!option)
+ {
+ if (parser->posixly_correct)
+ /* 1003.2 specifies the format of this message. */
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: illegal option -- %c\n"),
+ parser->state.name, c);
+ else
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: invalid option -- %c\n"),
+ parser->state.name, c);
+
+ *arg_ebadkey = 0;
+ return EBADKEY;
+ }
+
+ if (!*parser->nextchar)
+ parser->nextchar = NULL;
+
+ if (option->arg)
+ {
+ value = parser->nextchar;
+ parser->nextchar = NULL;
+
+ if (!value
+ && !(option->flags & OPTION_ARG_OPTIONAL))
+ /* We need an mandatory argument. */
+ {
+ if (parser->state.next == parser->state.argc)
+ /* Missing argument */
+ {
+ /* 1003.2 specifies the format of this message. */
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: option requires an argument -- %c\n"),
+ parser->state.name, c);
+
+ *arg_ebadkey = 0;
+ return EBADKEY;
+ }
+ value = parser->state.argv[parser->state.next++];
+ }
+ }
+ return group_parse(group, &parser->state,
+ option->key, value);
+ }
+ else
+ /* Advance to the next ARGV-element. */
+ {
+ if (parser->args_only)
+ {
+ *arg_ebadkey = 1;
+ if (parser->state.next >= parser->state.argc)
+ /* We're done. */
+ return EBADKEY;
+ else
+ return parser_parse_arg(parser,
+ parser->state.argv[parser->state.next]);
+ }
+
+ if (parser->state.next >= parser->state.argc)
+ /* Almost done. If there are non-options that we skipped
+ previously, we should process them now. */
+ {
+ *arg_ebadkey = 1;
+ if (parser->first_nonopt != parser->last_nonopt)
+ {
+ exchange(parser);
+
+ /* Start processing the arguments we skipped previously. */
+ parser->state.next = parser->first_nonopt;
+
+ parser->first_nonopt = parser->last_nonopt = 0;
+
+ parser->args_only = 1;
+ return 0;
+ }
+ else
+ /* Indicate that we're really done. */
+ return EBADKEY;
+ }
+ else
+ /* Look for options. */
+ {
+ char *arg = parser->state.argv[parser->state.next];
+
+ char *optstart;
+ enum arg_type token = classify_arg(parser, arg, &optstart);
+
+ switch (token)
+ {
+ case ARG_ARG:
+ switch (parser->ordering)
+ {
+ case PERMUTE:
+ if (parser->first_nonopt == parser->last_nonopt)
+ /* Skipped sequence is empty; start a new one. */
+ parser->first_nonopt = parser->last_nonopt = parser->state.next;
+
+ else if (parser->last_nonopt != parser->state.next)
+ /* We have a non-empty skipped sequence, and
+ we're not at the end-point, so move it. */
+ exchange(parser);
+
+ assert(parser->last_nonopt == parser->state.next);
+
+ /* Skip this argument for now. */
+ parser->state.next++;
+ parser->last_nonopt = parser->state.next;
+
+ return 0;
+
+ case REQUIRE_ORDER:
+ /* Implicit quote before the first argument. */
+ parser->args_only = 1;
+ return 0;
+
+ case RETURN_IN_ORDER:
+ *arg_ebadkey = 1;
+ return parser_parse_arg(parser, arg);
+
+ default:
+ abort();
+ }
+ case ARG_QUOTE:
+ /* Skip it, then exchange with any previous non-options. */
+ parser->state.next++;
+ assert (parser->last_nonopt != parser->state.next);
+
+ if (parser->first_nonopt != parser->last_nonopt)
+ {
+ exchange(parser);
+
+ /* Start processing the skipped and the quoted
+ arguments. */
+
+ parser->state.quoted = parser->state.next = parser->first_nonopt;
+
+ /* Also empty the skipped-list, to avoid confusion
+ if the user resets the next pointer. */
+ parser->first_nonopt = parser->last_nonopt = 0;
+ }
+ else
+ parser->state.quoted = parser->state.next;
+
+ parser->args_only = 1;
+ return 0;
+
+ case ARG_LONG_ONLY_OPTION:
+ case ARG_LONG_OPTION:
+ {
+ struct group *group;
+ const struct argp_option *option;
+ char *value;
+
+ parser->state.next++;
+ option = find_long_option(parser, optstart, &group);
+
+ if (!option)
+ {
+ /* NOTE: This includes any "=something" in the output. */
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: unrecognized option `%s'\n"),
+ parser->state.name, arg);
+ *arg_ebadkey = 0;
+ return EBADKEY;
+ }
+
+ value = strchr(optstart, '=');
+ if (value)
+ value++;
+
+ if (value && !option->arg)
+ /* Unexpected argument. */
+ {
+ if (token == ARG_LONG_OPTION)
+ /* --option */
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: option `--%s' doesn't allow an argument\n"),
+ parser->state.name, option->name);
+ else
+ /* +option or -option */
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: option `%c%s' doesn't allow an argument\n"),
+ parser->state.name, arg[0], option->name);
+
+ *arg_ebadkey = 0;
+ return EBADKEY;
+ }
+
+ if (option->arg && !value
+ && !(option->flags & OPTION_ARG_OPTIONAL))
+ /* We need an mandatory argument. */
+ {
+ if (parser->state.next == parser->state.argc)
+ /* Missing argument */
+ {
+ if (token == ARG_LONG_OPTION)
+ /* --option */
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: option `--%s' requires an argument\n"),
+ parser->state.name, option->name);
+ else
+ /* +option or -option */
+ fprintf (parser->state.err_stream,
+ dgettext(parser->state.root_argp->argp_domain,
+ "%s: option `%c%s' requires an argument\n"),
+ parser->state.name, arg[0], option->name);
+
+ *arg_ebadkey = 0;
+ return EBADKEY;
+ }
+
+ value = parser->state.argv[parser->state.next++];
+ }
+ *arg_ebadkey = 0;
+ return group_parse(group, &parser->state,
+ option->key, value);
+ }
+ case ARG_SHORT_OPTION:
+ parser->state.next++;
+ parser->nextchar = optstart;
+ return 0;
+
+ default:
+ abort();
+ }
+ }
+ }
+}
+
+/* Parse the options strings in ARGC & ARGV according to the argp in ARGP.
+ FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the
+ index in ARGV of the first unparsed option is returned in it. If an
+ unknown option is present, EINVAL is returned; if some parser routine
+ returned a non-zero value, it is returned; otherwise 0 is returned. */
+error_t
+__argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
+ int *end_index, void *input)
+{
+ error_t err;
+ struct parser parser;
+
+ /* If true, then err == EBADKEY is a result of a non-option argument failing
+ to be parsed (which in some cases isn't actually an error). */
+ int arg_ebadkey = 0;
+
+ if (! (flags & ARGP_NO_HELP))
+ /* Add our own options. */
+ {
+ struct argp_child *child = alloca (4 * sizeof (struct argp_child));
+ struct argp *top_argp = alloca (sizeof (struct argp));
+
+ /* TOP_ARGP has no options, it just serves to group the user & default
+ argps. */
+ memset (top_argp, 0, sizeof (*top_argp));
+ top_argp->children = child;
+
+ memset (child, 0, 4 * sizeof (struct argp_child));
+
+ if (argp)
+ (child++)->argp = argp;
+ (child++)->argp = &argp_default_argp;
+ if (argp_program_version || argp_program_version_hook)
+ (child++)->argp = &argp_version_argp;
+ child->argp = 0;
+
+ argp = top_argp;
+ }
+
+ /* Construct a parser for these arguments. */
+ err = parser_init (&parser, argp, argc, argv, flags, input);
+
+ if (! err)
+ /* Parse! */
+ {
+ while (! err)
+ err = parser_parse_next (&parser, &arg_ebadkey);
+ err = parser_finalize (&parser, err, arg_ebadkey, end_index);
+ }
+
+ return err;
+}
+#ifdef weak_alias
+weak_alias (__argp_parse, argp_parse)
+#endif
+
+/* Return the input field for ARGP in the parser corresponding to STATE; used
+ by the help routines. */
+void *
+__argp_input (const struct argp *argp, const struct argp_state *state)
+{
+ if (state)
+ {
+ struct group *group;
+ struct parser *parser = state->pstate;
+
+ for (group = parser->groups; group < parser->egroup; group++)
+ if (group->argp == argp)
+ return group->input;
+ }
+
+ return 0;
+}
+#ifdef weak_alias
+weak_alias (__argp_input, _argp_input)
+#endif
+
+/* Defined here, in case a user is not inlining the definitions in
+ * argp.h */
+void
+__argp_usage (__const struct argp_state *__state)
+{
+ __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
+}
+
+int
+__option_is_short (__const struct argp_option *__opt)
+{
+ if (__opt->flags & OPTION_DOC)
+ return 0;
+ else
+ {
+ int __key = __opt->key;
+ /* FIXME: whether or not a particular key implies a short option
+ * ought not to be locale dependent. */
+ return __key > 0 && isprint (__key);
+ }
+}
+
+int
+__option_is_end (__const struct argp_option *__opt)
+{
+ return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
+}
diff --git a/argp-standalone/argp-pv.c b/argp-standalone/argp-pv.c
new file mode 100644
index 000000000..d7d374a66
--- /dev/null
+++ b/argp-standalone/argp-pv.c
@@ -0,0 +1,25 @@
+/* Default definition for ARGP_PROGRAM_VERSION.
+ Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* If set by the user program to a non-zero value, then a default option
+ --version is added (unless the ARGP_NO_HELP flag is used), which will
+ print this this string followed by a newline and exit (unless the
+ ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
+const char *argp_program_version = 0;
diff --git a/argp-standalone/argp-pvh.c b/argp-standalone/argp-pvh.c
new file mode 100644
index 000000000..829a1cda8
--- /dev/null
+++ b/argp-standalone/argp-pvh.c
@@ -0,0 +1,32 @@
+/* Default definition for ARGP_PROGRAM_VERSION_HOOK.
+ Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "argp.h"
+
+/* If set by the user program to a non-zero value, then a default option
+ --version is added (unless the ARGP_NO_HELP flag is used), which calls
+ this function with a stream to print the version to and a pointer to the
+ current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
+ used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
+void (*argp_program_version_hook) (FILE *stream, struct argp_state *state) = 0;
diff --git a/argp-standalone/argp.h b/argp-standalone/argp.h
new file mode 100644
index 000000000..29d3dfe97
--- /dev/null
+++ b/argp-standalone/argp.h
@@ -0,0 +1,602 @@
+/* Hierarchial argument parsing.
+ Copyright (C) 1995, 96, 97, 98, 99, 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef _ARGP_H
+#define _ARGP_H
+
+#include <stdio.h>
+#include <ctype.h>
+
+#define __need_error_t
+#include <errno.h>
+
+#ifndef __THROW
+# define __THROW
+#endif
+
+#ifndef __const
+# define __const const
+#endif
+
+#ifndef __error_t_defined
+typedef int error_t;
+# define __error_t_defined
+#endif
+
+/* FIXME: What's the right way to check for __restrict? Sun's cc seems
+ not to have it. Perhaps it's easiest to just delete the use of
+ __restrict from the prototypes. */
+#ifndef __restrict
+# ifndef __GNUC___
+# define __restrict
+# endif
+#endif
+
+/* NOTE: We can't use the autoconf tests, since this is supposed to be
+ an installed header file and argp's config.h is of course not
+ installed. */
+#ifndef PRINTF_STYLE
+# if __GNUC__ >= 2
+# define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a)))
+# else
+# define PRINTF_STYLE(f, a)
+# endif
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* A description of a particular option. A pointer to an array of
+ these is passed in the OPTIONS field of an argp structure. Each option
+ entry can correspond to one long option and/or one short option; more
+ names for the same option can be added by following an entry in an option
+ array with options having the OPTION_ALIAS flag set. */
+struct argp_option
+{
+ /* The long option name. For more than one name for the same option, you
+ can use following options with the OPTION_ALIAS flag set. */
+ __const char *name;
+
+ /* What key is returned for this option. If > 0 and printable, then it's
+ also accepted as a short option. */
+ int key;
+
+ /* If non-NULL, this is the name of the argument associated with this
+ option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */
+ __const char *arg;
+
+ /* OPTION_ flags. */
+ int flags;
+
+ /* The doc string for this option. If both NAME and KEY are 0, This string
+ will be printed outdented from the normal option column, making it
+ useful as a group header (it will be the first thing printed in its
+ group); in this usage, it's conventional to end the string with a `:'. */
+ __const char *doc;
+
+ /* The group this option is in. In a long help message, options are sorted
+ alphabetically within each group, and the groups presented in the order
+ 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with
+ if this field 0 will inherit the group number of the previous entry, or
+ zero if it's the first one, unless its a group header (NAME and KEY both
+ 0), in which case, the previous entry + 1 is the default. Automagic
+ options such as --help are put into group -1. */
+ int group;
+};
+
+/* The argument associated with this option is optional. */
+#define OPTION_ARG_OPTIONAL 0x1
+
+/* This option isn't displayed in any help messages. */
+#define OPTION_HIDDEN 0x2
+
+/* This option is an alias for the closest previous non-alias option. This
+ means that it will be displayed in the same help entry, and will inherit
+ fields other than NAME and KEY from the aliased option. */
+#define OPTION_ALIAS 0x4
+
+/* This option isn't actually an option (and so should be ignored by the
+ actual option parser), but rather an arbitrary piece of documentation that
+ should be displayed in much the same manner as the options. If this flag
+ is set, then the option NAME field is displayed unmodified (e.g., no `--'
+ prefix is added) at the left-margin (where a *short* option would normally
+ be displayed), and the documentation string in the normal place. For
+ purposes of sorting, any leading whitespace and puncuation is ignored,
+ except that if the first non-whitespace character is not `-', this entry
+ is displayed after all options (and OPTION_DOC entries with a leading `-')
+ in the same group. */
+#define OPTION_DOC 0x8
+
+/* This option shouldn't be included in `long' usage messages (but is still
+ included in help messages). This is mainly intended for options that are
+ completely documented in an argp's ARGS_DOC field, in which case including
+ the option in the generic usage list would be redundant. For instance,
+ if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to
+ distinguish these two cases, -x should probably be marked
+ OPTION_NO_USAGE. */
+#define OPTION_NO_USAGE 0x10
+
+struct argp; /* fwd declare this type */
+struct argp_state; /* " */
+struct argp_child; /* " */
+
+/* The type of a pointer to an argp parsing function. */
+typedef error_t (*argp_parser_t) (int key, char *arg,
+ struct argp_state *state);
+
+/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such
+ returns will simply be ignored. For user keys, this error will be turned
+ into EINVAL (if the call to argp_parse is such that errors are propagated
+ back to the user instead of exiting); returning EINVAL itself would result
+ in an immediate stop to parsing in *all* cases. */
+#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */
+
+/* Special values for the KEY argument to an argument parsing function.
+ ARGP_ERR_UNKNOWN should be returned if they aren't understood.
+
+ The sequence of keys to a parsing function is either (where each
+ uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key):
+
+ INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all
+ or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed
+ or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized
+
+ The third case is where every parser returned ARGP_KEY_UNKNOWN for an
+ argument, in which case parsing stops at that argument (returning the
+ unparsed arguments to the caller of argp_parse if requested, or stopping
+ with an error message if not).
+
+ If an error occurs (either detected by argp, or because the parsing
+ function returned an error value), then the parser is called with
+ ARGP_KEY_ERROR, and no further calls are made. */
+
+/* This is not an option at all, but rather a command line argument. If a
+ parser receiving this key returns success, the fact is recorded, and the
+ ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the
+ argument, a parser function decrements the NEXT field of the state it's
+ passed, the option won't be considered processed; this is to allow you to
+ actually modify the argument (perhaps into an option), and have it
+ processed again. */
+#define ARGP_KEY_ARG 0
+/* There are remaining arguments not parsed by any parser, which may be found
+ starting at (STATE->argv + STATE->next). If success is returned, but
+ STATE->next left untouched, it's assumed that all arguments were consume,
+ otherwise, the parser should adjust STATE->next to reflect any arguments
+ consumed. */
+#define ARGP_KEY_ARGS 0x1000006
+/* There are no more command line arguments at all. */
+#define ARGP_KEY_END 0x1000001
+/* Because it's common to want to do some special processing if there aren't
+ any non-option args, user parsers are called with this key if they didn't
+ successfully process any non-option arguments. Called just before
+ ARGP_KEY_END (where more general validity checks on previously parsed
+ arguments can take place). */
+#define ARGP_KEY_NO_ARGS 0x1000002
+/* Passed in before any parsing is done. Afterwards, the values of each
+ element of the CHILD_INPUT field, if any, in the state structure is
+ copied to each child's state to be the initial value of the INPUT field. */
+#define ARGP_KEY_INIT 0x1000003
+/* Use after all other keys, including SUCCESS & END. */
+#define ARGP_KEY_FINI 0x1000007
+/* Passed in when parsing has successfully been completed (even if there are
+ still arguments remaining). */
+#define ARGP_KEY_SUCCESS 0x1000004
+/* Passed in if an error occurs. */
+#define ARGP_KEY_ERROR 0x1000005
+
+/* An argp structure contains a set of options declarations, a function to
+ deal with parsing one, documentation string, a possible vector of child
+ argp's, and perhaps a function to filter help output. When actually
+ parsing options, getopt is called with the union of all the argp
+ structures chained together through their CHILD pointers, with conflicts
+ being resolved in favor of the first occurrence in the chain. */
+struct argp
+{
+ /* An array of argp_option structures, terminated by an entry with both
+ NAME and KEY having a value of 0. */
+ __const struct argp_option *options;
+
+ /* What to do with an option from this structure. KEY is the key
+ associated with the option, and ARG is any associated argument (NULL if
+ none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be
+ returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then
+ parsing is stopped immediately, and that value is returned from
+ argp_parse(). For special (non-user-supplied) values of KEY, see the
+ ARGP_KEY_ definitions below. */
+ argp_parser_t parser;
+
+ /* A string describing what other arguments are wanted by this program. It
+ is only used by argp_usage to print the `Usage:' message. If it
+ contains newlines, the strings separated by them are considered
+ alternative usage patterns, and printed on separate lines (lines after
+ the first are prefix by ` or: ' instead of `Usage:'). */
+ __const char *args_doc;
+
+ /* If non-NULL, a string containing extra text to be printed before and
+ after the options in a long help message (separated by a vertical tab
+ `\v' character). */
+ __const char *doc;
+
+ /* A vector of argp_children structures, terminated by a member with a 0
+ argp field, pointing to child argps should be parsed with this one. Any
+ conflicts are resolved in favor of this argp, or early argps in the
+ CHILDREN list. This field is useful if you use libraries that supply
+ their own argp structure, which you want to use in conjunction with your
+ own. */
+ __const struct argp_child *children;
+
+ /* If non-zero, this should be a function to filter the output of help
+ messages. KEY is either a key from an option, in which case TEXT is
+ that option's help text, or a special key from the ARGP_KEY_HELP_
+ defines, below, describing which other help text TEXT is. The function
+ should return either TEXT, if it should be used as-is, a replacement
+ string, which should be malloced, and will be freed by argp, or NULL,
+ meaning `print nothing'. The value for TEXT is *after* any translation
+ has been done, so if any of the replacement text also needs translation,
+ that should be done by the filter function. INPUT is either the input
+ supplied to argp_parse, or NULL, if argp_help was called directly. */
+ char *(*help_filter) (int __key, __const char *__text, void *__input);
+
+ /* If non-zero the strings used in the argp library are translated using
+ the domain described by this string. Otherwise the currently installed
+ default domain is used. */
+ const char *argp_domain;
+};
+
+/* Possible KEY arguments to a help filter function. */
+#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */
+#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */
+#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */
+#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation;
+ TEXT is NULL for this key. */
+/* Explanatory note emitted when duplicate option arguments have been
+ suppressed. */
+#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005
+#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */
+
+/* When an argp has a non-zero CHILDREN field, it should point to a vector of
+ argp_child structures, each of which describes a subsidiary argp. */
+struct argp_child
+{
+ /* The child parser. */
+ __const struct argp *argp;
+
+ /* Flags for this child. */
+ int flags;
+
+ /* If non-zero, an optional header to be printed in help output before the
+ child options. As a side-effect, a non-zero value forces the child
+ options to be grouped together; to achieve this effect without actually
+ printing a header string, use a value of "". */
+ __const char *header;
+
+ /* Where to group the child options relative to the other (`consolidated')
+ options in the parent argp; the values are the same as the GROUP field
+ in argp_option structs, but all child-groupings follow parent options at
+ a particular group level. If both this field and HEADER are zero, then
+ they aren't grouped at all, but rather merged with the parent options
+ (merging the child's grouping levels with the parents). */
+ int group;
+};
+
+/* Parsing state. This is provided to parsing functions called by argp,
+ which may examine and, as noted, modify fields. */
+struct argp_state
+{
+ /* The top level ARGP being parsed. */
+ __const struct argp *root_argp;
+
+ /* The argument vector being parsed. May be modified. */
+ int argc;
+ char **argv;
+
+ /* The index in ARGV of the next arg that to be parsed. May be modified. */
+ int next;
+
+ /* The flags supplied to argp_parse. May be modified. */
+ unsigned flags;
+
+ /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the
+ number of the current arg, starting at zero, and incremented after each
+ such call returns. At all other times, this is the number of such
+ arguments that have been processed. */
+ unsigned arg_num;
+
+ /* If non-zero, the index in ARGV of the first argument following a special
+ `--' argument (which prevents anything following being interpreted as an
+ option). Only set once argument parsing has proceeded past this point. */
+ int quoted;
+
+ /* An arbitrary pointer passed in from the user. */
+ void *input;
+ /* Values to pass to child parsers. This vector will be the same length as
+ the number of children for the current parser. */
+ void **child_inputs;
+
+ /* For the parser's use. Initialized to 0. */
+ void *hook;
+
+ /* The name used when printing messages. This is initialized to ARGV[0],
+ or PROGRAM_INVOCATION_NAME if that is unavailable. */
+ char *name;
+
+ /* Streams used when argp prints something. */
+ FILE *err_stream; /* For errors; initialized to stderr. */
+ FILE *out_stream; /* For information; initialized to stdout. */
+
+ void *pstate; /* Private, for use by argp. */
+};
+
+/* Flags for argp_parse (note that the defaults are those that are
+ convenient for program command line parsing): */
+
+/* Don't ignore the first element of ARGV. Normally (and always unless
+ ARGP_NO_ERRS is set) the first element of the argument vector is
+ skipped for option parsing purposes, as it corresponds to the program name
+ in a command line. */
+#define ARGP_PARSE_ARGV0 0x01
+
+/* Don't print error messages for unknown options to stderr; unless this flag
+ is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program
+ name in the error messages. This flag implies ARGP_NO_EXIT (on the
+ assumption that silent exiting upon errors is bad behaviour). */
+#define ARGP_NO_ERRS 0x02
+
+/* Don't parse any non-option args. Normally non-option args are parsed by
+ calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg
+ as the value. Since it's impossible to know which parse function wants to
+ handle it, each one is called in turn, until one returns 0 or an error
+ other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the
+ argp_parse returns prematurely (but with a return value of 0). If all
+ args have been parsed without error, all parsing functions are called one
+ last time with a key of ARGP_KEY_END. This flag needn't normally be set,
+ as the normal behavior is to stop parsing as soon as some argument can't
+ be handled. */
+#define ARGP_NO_ARGS 0x04
+
+/* Parse options and arguments in the same order they occur on the command
+ line -- normally they're rearranged so that all options come first. */
+#define ARGP_IN_ORDER 0x08
+
+/* Don't provide the standard long option --help, which causes usage and
+ option help information to be output to stdout, and exit (0) called. */
+#define ARGP_NO_HELP 0x10
+
+/* Don't exit on errors (they may still result in error messages). */
+#define ARGP_NO_EXIT 0x20
+
+/* Use the gnu getopt `long-only' rules for parsing arguments. */
+#define ARGP_LONG_ONLY 0x40
+
+/* Turns off any message-printing/exiting options. */
+#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)
+
+/* Parse the options strings in ARGC & ARGV according to the options in ARGP.
+ FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the
+ index in ARGV of the first unparsed option is returned in it. If an
+ unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser
+ routine returned a non-zero value, it is returned; otherwise 0 is
+ returned. This function may also call exit unless the ARGP_NO_HELP flag
+ is set. INPUT is a pointer to a value to be passed in to the parser. */
+extern error_t argp_parse (__const struct argp *__restrict argp,
+ int argc, char **__restrict argv,
+ unsigned flags, int *__restrict arg_index,
+ void *__restrict input) __THROW;
+extern error_t __argp_parse (__const struct argp *__restrict argp,
+ int argc, char **__restrict argv,
+ unsigned flags, int *__restrict arg_index,
+ void *__restrict input) __THROW;
+
+/* Global variables. */
+
+/* If defined or set by the user program to a non-zero value, then a default
+ option --version is added (unless the ARGP_NO_HELP flag is used), which
+ will print this string followed by a newline and exit (unless the
+ ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
+extern __const char *argp_program_version;
+
+/* If defined or set by the user program to a non-zero value, then a default
+ option --version is added (unless the ARGP_NO_HELP flag is used), which
+ calls this function with a stream to print the version to and a pointer to
+ the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
+ used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
+extern void (*argp_program_version_hook) (FILE *__restrict __stream,
+ struct argp_state *__restrict
+ __state);
+
+/* If defined or set by the user program, it should point to string that is
+ the bug-reporting address for the program. It will be printed by
+ argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
+ standard help messages), embedded in a sentence that says something like
+ `Report bugs to ADDR.'. */
+extern __const char *argp_program_bug_address;
+
+/* The exit status that argp will use when exiting due to a parsing error.
+ If not defined or set by the user program, this defaults to EX_USAGE from
+ <sysexits.h>. */
+extern error_t argp_err_exit_status;
+
+/* Flags for argp_help. */
+#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */
+#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */
+#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */
+#define ARGP_HELP_LONG 0x08 /* a long help message. */
+#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */
+#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */
+#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)
+#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */
+#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to
+ reflect ARGP_LONG_ONLY mode. */
+
+/* These ARGP_HELP flags are only understood by argp_state_help. */
+#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */
+#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */
+
+/* The standard thing to do after a program command line parsing error, if an
+ error message has already been printed. */
+#define ARGP_HELP_STD_ERR \
+ (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
+/* The standard thing to do after a program command line parsing error, if no
+ more specific error message has been printed. */
+#define ARGP_HELP_STD_USAGE \
+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
+/* The standard thing to do in response to a --help option. */
+#define ARGP_HELP_STD_HELP \
+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
+ | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)
+
+/* Output a usage message for ARGP to STREAM. FLAGS are from the set
+ ARGP_HELP_*. */
+extern void argp_help (__const struct argp *__restrict __argp,
+ FILE *__restrict __stream,
+ unsigned __flags, char *__restrict __name) __THROW;
+extern void __argp_help (__const struct argp *__restrict __argp,
+ FILE *__restrict __stream, unsigned __flags,
+ char *__name) __THROW;
+
+/* The following routines are intended to be called from within an argp
+ parsing routine (thus taking an argp_state structure as the first
+ argument). They may or may not print an error message and exit, depending
+ on the flags in STATE -- in any case, the caller should be prepared for
+ them *not* to exit, and should return an appropiate error after calling
+ them. [argp_usage & argp_error should probably be called argp_state_...,
+ but they're used often enough that they should be short] */
+
+/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
+ from the set ARGP_HELP_*. */
+extern void argp_state_help (__const struct argp_state *__restrict __state,
+ FILE *__restrict __stream,
+ unsigned int __flags) __THROW;
+extern void __argp_state_help (__const struct argp_state *__restrict __state,
+ FILE *__restrict __stream,
+ unsigned int __flags) __THROW;
+
+/* Possibly output the standard usage message for ARGP to stderr and exit. */
+extern void argp_usage (__const struct argp_state *__state) __THROW;
+extern void __argp_usage (__const struct argp_state *__state) __THROW;
+
+/* If appropriate, print the printf string FMT and following args, preceded
+ by the program name and `:', to stderr, and followed by a `Try ... --help'
+ message, then exit (1). */
+extern void argp_error (__const struct argp_state *__restrict __state,
+ __const char *__restrict __fmt, ...) __THROW
+ PRINTF_STYLE(2,3);
+extern void __argp_error (__const struct argp_state *__restrict __state,
+ __const char *__restrict __fmt, ...) __THROW
+ PRINTF_STYLE(2,3);
+
+/* Similar to the standard gnu error-reporting function error(), but will
+ respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
+ to STATE->err_stream. This is useful for argument parsing code that is
+ shared between program startup (when exiting is desired) and runtime
+ option parsing (when typically an error code is returned instead). The
+ difference between this function and argp_error is that the latter is for
+ *parsing errors*, and the former is for other problems that occur during
+ parsing but don't reflect a (syntactic) problem with the input. */
+extern void argp_failure (__const struct argp_state *__restrict __state,
+ int __status, int __errnum,
+ __const char *__restrict __fmt, ...) __THROW
+ PRINTF_STYLE(4,5);
+extern void __argp_failure (__const struct argp_state *__restrict __state,
+ int __status, int __errnum,
+ __const char *__restrict __fmt, ...) __THROW
+ PRINTF_STYLE(4,5);
+
+/* Returns true if the option OPT is a valid short option. */
+extern int _option_is_short (__const struct argp_option *__opt) __THROW;
+extern int __option_is_short (__const struct argp_option *__opt) __THROW;
+
+/* Returns true if the option OPT is in fact the last (unused) entry in an
+ options array. */
+extern int _option_is_end (__const struct argp_option *__opt) __THROW;
+extern int __option_is_end (__const struct argp_option *__opt) __THROW;
+
+/* Return the input field for ARGP in the parser corresponding to STATE; used
+ by the help routines. */
+extern void *_argp_input (__const struct argp *__restrict __argp,
+ __const struct argp_state *__restrict __state)
+ __THROW;
+extern void *__argp_input (__const struct argp *__restrict __argp,
+ __const struct argp_state *__restrict __state)
+ __THROW;
+
+/* Used for extracting the program name from argv[0] */
+extern char *_argp_basename(char *name) __THROW;
+extern char *__argp_basename(char *name) __THROW;
+
+/* Getting the program name given an argp state */
+extern char *
+_argp_short_program_name(const struct argp_state *state) __THROW;
+extern char *
+__argp_short_program_name(const struct argp_state *state) __THROW;
+
+
+#ifdef __USE_EXTERN_INLINES
+
+# if !_LIBC
+# define __argp_usage argp_usage
+# define __argp_state_help argp_state_help
+# define __option_is_short _option_is_short
+# define __option_is_end _option_is_end
+# endif
+
+# ifndef ARGP_EI
+# define ARGP_EI extern __inline__
+# endif
+
+ARGP_EI void
+__argp_usage (__const struct argp_state *__state)
+{
+ __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
+}
+
+ARGP_EI int
+__option_is_short (__const struct argp_option *__opt)
+{
+ if (__opt->flags & OPTION_DOC)
+ return 0;
+ else
+ {
+ int __key = __opt->key;
+ return __key > 0 && isprint (__key);
+ }
+}
+
+ARGP_EI int
+__option_is_end (__const struct argp_option *__opt)
+{
+ return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
+}
+
+# if !_LIBC
+# undef __argp_usage
+# undef __argp_state_help
+# undef __option_is_short
+# undef __option_is_end
+# endif
+#endif /* Use extern inlines. */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* argp.h */
diff --git a/argp-standalone/autogen.sh b/argp-standalone/autogen.sh
new file mode 100755
index 000000000..8337353b5
--- /dev/null
+++ b/argp-standalone/autogen.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+aclocal -I .
+autoheader
+autoconf
+automake --add-missing --copy --foreign
diff --git a/argp-standalone/configure.ac b/argp-standalone/configure.ac
new file mode 100644
index 000000000..fe54d5ac9
--- /dev/null
+++ b/argp-standalone/configure.ac
@@ -0,0 +1,100 @@
+dnl Process this file with autoconf to produce a configure script.
+
+dnl This configure.ac is only for building a standalone argp library.
+AC_INIT([argp], [standalone-1.3])
+AC_PREREQ(2.54)
+AC_CONFIG_SRCDIR([argp-ba.c])
+# Needed to stop autoconf from looking for files in parent directories.
+AC_CONFIG_AUX_DIR([.])
+
+AM_INIT_AUTOMAKE
+AM_CONFIG_HEADER(config.h)
+
+# GNU libc defaults to supplying the ISO C library functions only. The
+# _GNU_SOURCE define enables these extensions, in particular we want
+# errno.h to declare program_invocation_name. Enable it on all
+# systems; no problems have been reported with it so far.
+AC_GNU_SOURCE
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_MAKE_SET
+AC_PROG_RANLIB
+AM_PROG_CC_STDC
+
+if test "x$am_cv_prog_cc_stdc" = xno ; then
+ AC_ERROR([the C compiler doesn't handle ANSI-C])
+fi
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS(limits.h malloc.h unistd.h sysexits.h stdarg.h)
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_C_INLINE
+AC_TYPE_SIZE_T
+
+LSH_GCC_ATTRIBUTES
+
+# Checks for library functions.
+AC_FUNC_ALLOCA
+AC_FUNC_VPRINTF
+AC_CHECK_FUNCS(strerror sleep getpid snprintf)
+
+AC_REPLACE_FUNCS(mempcpy strndup strchrnul strcasecmp vsnprintf)
+
+dnl ARGP_CHECK_FUNC(includes, function-call [, if-found [, if-not-found]])
+AC_DEFUN([ARGP_CHECK_FUNC],
+ [AS_VAR_PUSHDEF([ac_func], m4_substr([$2], 0, m4_index([$2], [(])))
+ AS_VAR_PUSHDEF([ac_var], [ac_cv_func_call_]ac_func)
+ AH_TEMPLATE(AS_TR_CPP(HAVE_[]ac_func),
+ [Define to 1 if you have the `]ac_func[' function.])
+ AC_CACHE_CHECK([for $2], ac_var,
+ [AC_TRY_LINK([$1], [$2],
+ [AS_VAR_SET(ac_var, yes)],
+ [AS_VAR_SET(ac_var, no)])])
+ if test AS_VAR_GET(ac_var) = yes ; then
+ ifelse([$3],,
+ [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]ac_func))],
+ [$3
+])
+ else
+ ifelse([$4],, true, [$4])
+ fi
+ AS_VAR_POPDEF([ac_var])
+ AS_VAR_POPDEF([ac_func])
+ ])
+
+# At least on freebsd, putc_unlocked is a macro, so the standard
+# AC_CHECK_FUNCS doesn't work well.
+ARGP_CHECK_FUNC([#include <stdio.h>], [putc_unlocked('x', stdout)])
+
+AC_CHECK_FUNCS(flockfile)
+AC_CHECK_FUNCS(fputs_unlocked fwrite_unlocked)
+
+# Used only by argp-test.c, so don't use AC_REPLACE_FUNCS.
+AC_CHECK_FUNCS(strdup asprintf)
+
+AC_CHECK_DECLS([program_invocation_name, program_invocation_short_name],
+ [], [], [[#include <errno.h>]])
+
+# Set these flags *last*, or else the test programs won't compile
+if test x$GCC = xyes ; then
+ # Using -ggdb3 makes (some versions of) Redhat's gcc-2.96 dump core
+ if "$CC" --version | grep '^2\.96$' 1>/dev/null 2>&1; then
+ true
+ else
+ CFLAGS="$CFLAGS -ggdb3"
+ fi
+ CFLAGS="$CFLAGS -Wall -W \
+ -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \
+ -Waggregate-return \
+ -Wpointer-arith -Wbad-function-cast -Wnested-externs"
+fi
+
+CPPFLAGS="$CPPFLAGS -I$srcdir"
+
+AC_OUTPUT(Makefile)
diff --git a/argp-standalone/mempcpy.c b/argp-standalone/mempcpy.c
new file mode 100644
index 000000000..21d8bd2ed
--- /dev/null
+++ b/argp-standalone/mempcpy.c
@@ -0,0 +1,21 @@
+/* strndup.c
+ *
+ */
+
+/* Written by Niels Möller <nisse@lysator.liu.se>
+ *
+ * This file is hereby placed in the public domain.
+ */
+
+#include <string.h>
+
+void *
+mempcpy (void *, const void *, size_t) ;
+
+void *
+mempcpy (void *to, const void *from, size_t size)
+{
+ memcpy(to, from, size);
+ return (char *) to + size;
+}
+
diff --git a/argp-standalone/strcasecmp.c b/argp-standalone/strcasecmp.c
new file mode 100644
index 000000000..bcad7a226
--- /dev/null
+++ b/argp-standalone/strcasecmp.c
@@ -0,0 +1,28 @@
+/* strcasecmp.c
+ *
+ */
+
+/* Written by Niels Möller <nisse@lysator.liu.se>
+ *
+ * This file is hereby placed in the public domain.
+ */
+
+#include <ctype.h>
+
+int strcasecmp(const char *s1, const char *s2)
+{
+ unsigned i;
+
+ for (i = 0; s1[i] && s2[i]; i++)
+ {
+ unsigned char c1 = tolower( (unsigned char) s1[i]);
+ unsigned char c2 = tolower( (unsigned char) s2[i]);
+
+ if (c1 < c2)
+ return -1;
+ else if (c1 > c2)
+ return 1;
+ }
+
+ return !s2[i] - !s1[i];
+}
diff --git a/argp-standalone/strchrnul.c b/argp-standalone/strchrnul.c
new file mode 100644
index 000000000..ee4145e4e
--- /dev/null
+++ b/argp-standalone/strchrnul.c
@@ -0,0 +1,23 @@
+/* strchrnul.c
+ *
+ */
+
+/* Written by Niels Möller <nisse@lysator.liu.se>
+ *
+ * This file is hereby placed in the public domain.
+ */
+
+/* FIXME: What is this function supposed to do? My guess is that it is
+ * like strchr, but returns a pointer to the NUL character, not a NULL
+ * pointer, if the character isn't found. */
+
+char *strchrnul(const char *, int );
+
+char *strchrnul(const char *s, int c)
+{
+ const char *p = s;
+ while (*p && (*p != c))
+ p++;
+
+ return (char *) p;
+}
diff --git a/argp-standalone/strndup.c b/argp-standalone/strndup.c
new file mode 100644
index 000000000..4147b7a20
--- /dev/null
+++ b/argp-standalone/strndup.c
@@ -0,0 +1,34 @@
+/* strndup.c
+ *
+ */
+
+/* Written by Niels Möller <nisse@lysator.liu.se>
+ *
+ * This file is hereby placed in the public domain.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+char *
+strndup (const char *, size_t);
+
+char *
+strndup (const char *s, size_t size)
+{
+ char *r;
+ char *end = memchr(s, 0, size);
+
+ if (end)
+ /* Length + 1 */
+ size = end - s + 1;
+
+ r = malloc(size);
+
+ if (size)
+ {
+ memcpy(r, s, size-1);
+ r[size-1] = '\0';
+ }
+ return r;
+}
diff --git a/argp-standalone/vsnprintf.c b/argp-standalone/vsnprintf.c
new file mode 100644
index 000000000..e9b5f192b
--- /dev/null
+++ b/argp-standalone/vsnprintf.c
@@ -0,0 +1,839 @@
+/* Copied from http://www.fiction.net/blong/programs/snprintf.c */
+
+/*
+ * Copyright Patrick Powell 1995
+ * This code is based on code written by Patrick Powell (papowell@astart.com)
+ * It may be used for any purpose as long as this notice remains intact
+ * on all source code distributions
+ */
+
+/**************************************************************
+ * Original:
+ * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
+ * A bombproof version of doprnt (dopr) included.
+ * Sigh. This sort of thing is always nasty do deal with. Note that
+ * the version here does not include floating point...
+ *
+ * snprintf() is used instead of sprintf() as it does limit checks
+ * for string length. This covers a nasty loophole.
+ *
+ * The other functions are there to prevent NULL pointers from
+ * causing nast effects.
+ *
+ * More Recently:
+ * Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
+ * This was ugly. It is still ugly. I opted out of floating point
+ * numbers, but the formatter understands just about everything
+ * from the normal C string format, at least as far as I can tell from
+ * the Solaris 2.5 printf(3S) man page.
+ *
+ * Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
+ * Ok, added some minimal floating point support, which means this
+ * probably requires libm on most operating systems. Don't yet
+ * support the exponent (e,E) and sigfig (g,G). Also, fmtint()
+ * was pretty badly broken, it just wasn't being exercised in ways
+ * which showed it, so that's been fixed. Also, formated the code
+ * to mutt conventions, and removed dead code left over from the
+ * original. Also, there is now a builtin-test, just compile with:
+ * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
+ * and run snprintf for results.
+ *
+ * Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
+ * The PGP code was using unsigned hexadecimal formats.
+ * Unfortunately, unsigned formats simply didn't work.
+ *
+ * Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
+ * The original code assumed that both snprintf() and vsnprintf() were
+ * missing. Some systems only have snprintf() but not vsnprintf(), so
+ * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
+ *
+ * Andrew Tridgell (tridge@samba.org) Oct 1998
+ * fixed handling of %.0f
+ * added test for HAVE_LONG_DOUBLE
+ *
+ * Russ Allbery <rra@stanford.edu> 2000-08-26
+ * fixed return value to comply with C99
+ * fixed handling of snprintf(NULL, ...)
+ *
+ * Niels Möller <nisse@lysator.liu.se> 2004-03-05
+ * fixed calls to isdigit to use unsigned char.
+ * fixed calls to va_arg; short arguments are always passed as int.
+ *
+ **************************************************************/
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
+
+#include <string.h>
+#include <ctype.h>
+#include <sys/types.h>
+
+/* Define this as a fall through, HAVE_STDARG_H is probably already set */
+
+#define HAVE_VARARGS_H
+
+
+/* varargs declarations: */
+
+#if defined(HAVE_STDARG_H)
+# include <stdarg.h>
+# define HAVE_STDARGS /* let's hope that works everywhere (mj) */
+# define VA_LOCAL_DECL va_list ap
+# define VA_START(f) va_start(ap, f)
+# define VA_SHIFT(v,t) ; /* no-op for ANSI */
+# define VA_END va_end(ap)
+#else
+# if defined(HAVE_VARARGS_H)
+# include <varargs.h>
+# undef HAVE_STDARGS
+# define VA_LOCAL_DECL va_list ap
+# define VA_START(f) va_start(ap) /* f is ignored! */
+# define VA_SHIFT(v,t) v = va_arg(ap,t)
+# define VA_END va_end(ap)
+# else
+/*XX ** NO VARARGS ** XX*/
+# endif
+#endif
+
+#ifdef HAVE_LONG_DOUBLE
+#define LDOUBLE long double
+#else
+#define LDOUBLE double
+#endif
+
+int snprintf (char *str, size_t count, const char *fmt, ...);
+int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
+
+static int dopr (char *buffer, size_t maxlen, const char *format,
+ va_list args);
+static int fmtstr (char *buffer, size_t *currlen, size_t maxlen,
+ char *value, int flags, int min, int max);
+static int fmtint (char *buffer, size_t *currlen, size_t maxlen,
+ long value, int base, int min, int max, int flags);
+static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
+ LDOUBLE fvalue, int min, int max, int flags);
+static int dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
+
+/*
+ * dopr(): poor man's version of doprintf
+ */
+
+/* format read states */
+#define DP_S_DEFAULT 0
+#define DP_S_FLAGS 1
+#define DP_S_MIN 2
+#define DP_S_DOT 3
+#define DP_S_MAX 4
+#define DP_S_MOD 5
+#define DP_S_CONV 6
+#define DP_S_DONE 7
+
+/* format flags - Bits */
+#define DP_F_MINUS (1 << 0)
+#define DP_F_PLUS (1 << 1)
+#define DP_F_SPACE (1 << 2)
+#define DP_F_NUM (1 << 3)
+#define DP_F_ZERO (1 << 4)
+#define DP_F_UP (1 << 5)
+#define DP_F_UNSIGNED (1 << 6)
+
+/* Conversion Flags */
+#define DP_C_SHORT 1
+#define DP_C_LONG 2
+#define DP_C_LDOUBLE 3
+
+#define char_to_int(p) (p - '0')
+#define MAX(p,q) ((p >= q) ? p : q)
+#define MIN(p,q) ((p <= q) ? p : q)
+
+static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
+{
+ unsigned char ch;
+ long value;
+ LDOUBLE fvalue;
+ char *strvalue;
+ int min;
+ int max;
+ int state;
+ int flags;
+ int cflags;
+ int total;
+ size_t currlen;
+
+ state = DP_S_DEFAULT;
+ currlen = flags = cflags = min = 0;
+ max = -1;
+ ch = *format++;
+ total = 0;
+
+ while (state != DP_S_DONE)
+ {
+ if (ch == '\0')
+ state = DP_S_DONE;
+
+ switch(state)
+ {
+ case DP_S_DEFAULT:
+ if (ch == '%')
+ state = DP_S_FLAGS;
+ else
+ total += dopr_outch (buffer, &currlen, maxlen, ch);
+ ch = *format++;
+ break;
+ case DP_S_FLAGS:
+ switch (ch)
+ {
+ case '-':
+ flags |= DP_F_MINUS;
+ ch = *format++;
+ break;
+ case '+':
+ flags |= DP_F_PLUS;
+ ch = *format++;
+ break;
+ case ' ':
+ flags |= DP_F_SPACE;
+ ch = *format++;
+ break;
+ case '#':
+ flags |= DP_F_NUM;
+ ch = *format++;
+ break;
+ case '0':
+ flags |= DP_F_ZERO;
+ ch = *format++;
+ break;
+ default:
+ state = DP_S_MIN;
+ break;
+ }
+ break;
+ case DP_S_MIN:
+ if (isdigit(ch))
+ {
+ min = 10*min + char_to_int (ch);
+ ch = *format++;
+ }
+ else if (ch == '*')
+ {
+ min = va_arg (args, int);
+ ch = *format++;
+ state = DP_S_DOT;
+ }
+ else
+ state = DP_S_DOT;
+ break;
+ case DP_S_DOT:
+ if (ch == '.')
+ {
+ state = DP_S_MAX;
+ ch = *format++;
+ }
+ else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MAX:
+ if (isdigit(ch))
+ {
+ if (max < 0)
+ max = 0;
+ max = 10*max + char_to_int (ch);
+ ch = *format++;
+ }
+ else if (ch == '*')
+ {
+ max = va_arg (args, int);
+ ch = *format++;
+ state = DP_S_MOD;
+ }
+ else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MOD:
+ /* Currently, we don't support Long Long, bummer */
+ switch (ch)
+ {
+ case 'h':
+ cflags = DP_C_SHORT;
+ ch = *format++;
+ break;
+ case 'l':
+ cflags = DP_C_LONG;
+ ch = *format++;
+ break;
+ case 'L':
+ cflags = DP_C_LDOUBLE;
+ ch = *format++;
+ break;
+ default:
+ break;
+ }
+ state = DP_S_CONV;
+ break;
+ case DP_S_CONV:
+ switch (ch)
+ {
+ case 'd':
+ case 'i':
+ if (cflags == DP_C_SHORT)
+ value = (short) va_arg (args, int);
+ else if (cflags == DP_C_LONG)
+ value = va_arg (args, long int);
+ else
+ value = va_arg (args, int);
+ total += fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
+ break;
+ case 'o':
+ flags |= DP_F_UNSIGNED;
+ if (cflags == DP_C_SHORT)
+ value = (unsigned short) va_arg (args, unsigned);
+ else if (cflags == DP_C_LONG)
+ value = va_arg (args, unsigned long int);
+ else
+ value = va_arg (args, unsigned int);
+ total += fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
+ break;
+ case 'u':
+ flags |= DP_F_UNSIGNED;
+ if (cflags == DP_C_SHORT)
+ value = (unsigned short) va_arg (args, unsigned);
+ else if (cflags == DP_C_LONG)
+ value = va_arg (args, unsigned long int);
+ else
+ value = va_arg (args, unsigned int);
+ total += fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
+ break;
+ case 'X':
+ flags |= DP_F_UP;
+ case 'x':
+ flags |= DP_F_UNSIGNED;
+ if (cflags == DP_C_SHORT)
+ value = (unsigned short) va_arg (args, unsigned);
+ else if (cflags == DP_C_LONG)
+ value = va_arg (args, unsigned long int);
+ else
+ value = va_arg (args, unsigned int);
+ total += fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
+ break;
+ case 'f':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg (args, LDOUBLE);
+ else
+ fvalue = va_arg (args, double);
+ /* um, floating point? */
+ total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
+ break;
+ case 'E':
+ flags |= DP_F_UP;
+ case 'e':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg (args, LDOUBLE);
+ else
+ fvalue = va_arg (args, double);
+ break;
+ case 'G':
+ flags |= DP_F_UP;
+ case 'g':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg (args, LDOUBLE);
+ else
+ fvalue = va_arg (args, double);
+ break;
+ case 'c':
+ total += dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
+ break;
+ case 's':
+ strvalue = va_arg (args, char *);
+ total += fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
+ break;
+ case 'p':
+ strvalue = va_arg (args, void *);
+ total += fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min,
+ max, flags);
+ break;
+ case 'n':
+ if (cflags == DP_C_SHORT)
+ {
+ short int *num;
+ num = va_arg (args, short int *);
+ *num = currlen;
+ }
+ else if (cflags == DP_C_LONG)
+ {
+ long int *num;
+ num = va_arg (args, long int *);
+ *num = currlen;
+ }
+ else
+ {
+ int *num;
+ num = va_arg (args, int *);
+ *num = currlen;
+ }
+ break;
+ case '%':
+ total += dopr_outch (buffer, &currlen, maxlen, ch);
+ break;
+ case 'w':
+ /* not supported yet, treat as next char */
+ ch = *format++;
+ break;
+ default:
+ /* Unknown, skip */
+ break;
+ }
+ ch = *format++;
+ state = DP_S_DEFAULT;
+ flags = cflags = min = 0;
+ max = -1;
+ break;
+ case DP_S_DONE:
+ break;
+ default:
+ /* hmm? */
+ break; /* some picky compilers need this */
+ }
+ }
+ if (buffer != NULL)
+ {
+ if (currlen < maxlen - 1)
+ buffer[currlen] = '\0';
+ else
+ buffer[maxlen - 1] = '\0';
+ }
+ return total;
+}
+
+static int fmtstr (char *buffer, size_t *currlen, size_t maxlen,
+ char *value, int flags, int min, int max)
+{
+ int padlen, strln; /* amount to pad */
+ int cnt = 0;
+ int total = 0;
+
+ if (value == 0)
+ {
+ value = "<NULL>";
+ }
+
+ for (strln = 0; value[strln]; ++strln); /* strlen */
+ if (max >= 0 && max < strln)
+ strln = max;
+ padlen = min - strln;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen; /* Left Justify */
+
+ while (padlen > 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, ' ');
+ --padlen;
+ }
+ while (*value && ((max < 0) || (cnt < max)))
+ {
+ total += dopr_outch (buffer, currlen, maxlen, *value++);
+ ++cnt;
+ }
+ while (padlen < 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, ' ');
+ ++padlen;
+ }
+ return total;
+}
+
+/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
+
+static int fmtint (char *buffer, size_t *currlen, size_t maxlen,
+ long value, int base, int min, int max, int flags)
+{
+ int signvalue = 0;
+ unsigned long uvalue;
+ char convert[20];
+ int place = 0;
+ int spadlen = 0; /* amount to space pad */
+ int zpadlen = 0; /* amount to zero pad */
+ int caps = 0;
+ int total = 0;
+
+ if (max < 0)
+ max = 0;
+
+ uvalue = value;
+
+ if(!(flags & DP_F_UNSIGNED))
+ {
+ if( value < 0 ) {
+ signvalue = '-';
+ uvalue = -value;
+ }
+ else
+ if (flags & DP_F_PLUS) /* Do a sign (+/i) */
+ signvalue = '+';
+ else
+ if (flags & DP_F_SPACE)
+ signvalue = ' ';
+ }
+
+ if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
+
+ do {
+ convert[place++] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")
+ [uvalue % (unsigned)base ];
+ uvalue = (uvalue / (unsigned)base );
+ } while(uvalue && (place < 20));
+ if (place == 20) place--;
+ convert[place] = 0;
+
+ zpadlen = max - place;
+ spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
+ if (zpadlen < 0) zpadlen = 0;
+ if (spadlen < 0) spadlen = 0;
+ if (flags & DP_F_ZERO)
+ {
+ zpadlen = MAX(zpadlen, spadlen);
+ spadlen = 0;
+ }
+ if (flags & DP_F_MINUS)
+ spadlen = -spadlen; /* Left Justifty */
+
+#ifdef DEBUG_SNPRINTF
+ dprint (1, (debugfile, "zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
+ zpadlen, spadlen, min, max, place));
+#endif
+
+ /* Spaces */
+ while (spadlen > 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, ' ');
+ --spadlen;
+ }
+
+ /* Sign */
+ if (signvalue)
+ total += dopr_outch (buffer, currlen, maxlen, signvalue);
+
+ /* Zeros */
+ if (zpadlen > 0)
+ {
+ while (zpadlen > 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+ }
+
+ /* Digits */
+ while (place > 0)
+ total += dopr_outch (buffer, currlen, maxlen, convert[--place]);
+
+ /* Left Justified spaces */
+ while (spadlen < 0) {
+ total += dopr_outch (buffer, currlen, maxlen, ' ');
+ ++spadlen;
+ }
+
+ return total;
+}
+
+static LDOUBLE abs_val (LDOUBLE value)
+{
+ LDOUBLE result = value;
+
+ if (value < 0)
+ result = -value;
+
+ return result;
+}
+
+static LDOUBLE pow10 (int exp)
+{
+ LDOUBLE result = 1;
+
+ while (exp)
+ {
+ result *= 10;
+ exp--;
+ }
+
+ return result;
+}
+
+static long round (LDOUBLE value)
+{
+ long intpart;
+
+ intpart = value;
+ value = value - intpart;
+ if (value >= 0.5)
+ intpart++;
+
+ return intpart;
+}
+
+static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
+ LDOUBLE fvalue, int min, int max, int flags)
+{
+ int signvalue = 0;
+ LDOUBLE ufvalue;
+ char iconvert[20];
+ char fconvert[20];
+ int iplace = 0;
+ int fplace = 0;
+ int padlen = 0; /* amount to pad */
+ int zpadlen = 0;
+ int caps = 0;
+ int total = 0;
+ long intpart;
+ long fracpart;
+
+ /*
+ * AIX manpage says the default is 0, but Solaris says the default
+ * is 6, and sprintf on AIX defaults to 6
+ */
+ if (max < 0)
+ max = 6;
+
+ ufvalue = abs_val (fvalue);
+
+ if (fvalue < 0)
+ signvalue = '-';
+ else
+ if (flags & DP_F_PLUS) /* Do a sign (+/i) */
+ signvalue = '+';
+ else
+ if (flags & DP_F_SPACE)
+ signvalue = ' ';
+
+#if 0
+ if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
+#endif
+
+ intpart = ufvalue;
+
+ /*
+ * Sorry, we only support 9 digits past the decimal because of our
+ * conversion method
+ */
+ if (max > 9)
+ max = 9;
+
+ /* We "cheat" by converting the fractional part to integer by
+ * multiplying by a factor of 10
+ */
+ fracpart = round ((pow10 (max)) * (ufvalue - intpart));
+
+ if (fracpart >= pow10 (max))
+ {
+ intpart++;
+ fracpart -= pow10 (max);
+ }
+
+#ifdef DEBUG_SNPRINTF
+ dprint (1, (debugfile, "fmtfp: %f =? %d.%d\n", fvalue, intpart, fracpart));
+#endif
+
+ /* Convert integer part */
+ do {
+ iconvert[iplace++] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")[intpart % 10];
+ intpart = (intpart / 10);
+ } while(intpart && (iplace < 20));
+ if (iplace == 20) iplace--;
+ iconvert[iplace] = 0;
+
+ /* Convert fractional part */
+ do {
+ fconvert[fplace++] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10];
+ fracpart = (fracpart / 10);
+ } while(fracpart && (fplace < 20));
+ if (fplace == 20) fplace--;
+ fconvert[fplace] = 0;
+
+ /* -1 for decimal point, another -1 if we are printing a sign */
+ padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
+ zpadlen = max - fplace;
+ if (zpadlen < 0)
+ zpadlen = 0;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen; /* Left Justifty */
+
+ if ((flags & DP_F_ZERO) && (padlen > 0))
+ {
+ if (signvalue)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, signvalue);
+ --padlen;
+ signvalue = 0;
+ }
+ while (padlen > 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, '0');
+ --padlen;
+ }
+ }
+ while (padlen > 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, ' ');
+ --padlen;
+ }
+ if (signvalue)
+ total += dopr_outch (buffer, currlen, maxlen, signvalue);
+
+ while (iplace > 0)
+ total += dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
+
+ /*
+ * Decimal point. This should probably use locale to find the correct
+ * char to print out.
+ */
+ if (max > 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, '.');
+
+ while (fplace > 0)
+ total += dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
+ }
+
+ while (zpadlen > 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+
+ while (padlen < 0)
+ {
+ total += dopr_outch (buffer, currlen, maxlen, ' ');
+ ++padlen;
+ }
+
+ return total;
+}
+
+static int dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
+{
+ if (*currlen + 1 < maxlen)
+ buffer[(*currlen)++] = c;
+ return 1;
+}
+
+#ifndef HAVE_VSNPRINTF
+int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
+{
+ if (str != NULL)
+ str[0] = 0;
+ return dopr(str, count, fmt, args);
+}
+#endif /* !HAVE_VSNPRINTF */
+
+#ifndef HAVE_SNPRINTF
+/* VARARGS3 */
+#ifdef HAVE_STDARGS
+int snprintf (char *str,size_t count,const char *fmt,...)
+#else
+int snprintf (va_alist) va_dcl
+#endif
+{
+#ifndef HAVE_STDARGS
+ char *str;
+ size_t count;
+ char *fmt;
+#endif
+ VA_LOCAL_DECL;
+ int total;
+
+ VA_START (fmt);
+ VA_SHIFT (str, char *);
+ VA_SHIFT (count, size_t );
+ VA_SHIFT (fmt, char *);
+ total = vsnprintf(str, count, fmt, ap);
+ VA_END;
+ return total;
+}
+#endif /* !HAVE_SNPRINTF */
+
+#ifdef TEST_SNPRINTF
+#ifndef LONG_STRING
+#define LONG_STRING 1024
+#endif
+int main (void)
+{
+ char buf1[LONG_STRING];
+ char buf2[LONG_STRING];
+ char *fp_fmt[] = {
+ "%-1.5f",
+ "%1.5f",
+ "%123.9f",
+ "%10.5f",
+ "% 10.5f",
+ "%+22.9f",
+ "%+4.9f",
+ "%01.3f",
+ "%4f",
+ "%3.1f",
+ "%3.2f",
+ "%.0f",
+ "%.1f",
+ NULL
+ };
+ double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
+ 0.9996, 1.996, 4.136, 0};
+ char *int_fmt[] = {
+ "%-1.5d",
+ "%1.5d",
+ "%123.9d",
+ "%5.5d",
+ "%10.5d",
+ "% 10.5d",
+ "%+22.33d",
+ "%01.3d",
+ "%4d",
+ NULL
+ };
+ long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
+ int x, y;
+ int fail = 0;
+ int num = 0;
+
+ printf ("Testing snprintf format codes against system sprintf...\n");
+
+ for (x = 0; fp_fmt[x] != NULL ; x++)
+ for (y = 0; fp_nums[y] != 0 ; y++)
+ {
+ snprintf (buf1, sizeof (buf1), fp_fmt[x], fp_nums[y]);
+ sprintf (buf2, fp_fmt[x], fp_nums[y]);
+ if (strcmp (buf1, buf2))
+ {
+ printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
+ fp_fmt[x], buf1, buf2);
+ fail++;
+ }
+ num++;
+ }
+
+ for (x = 0; int_fmt[x] != NULL ; x++)
+ for (y = 0; int_nums[y] != 0 ; y++)
+ {
+ snprintf (buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
+ sprintf (buf2, int_fmt[x], int_nums[y]);
+ if (strcmp (buf1, buf2))
+ {
+ printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
+ int_fmt[x], buf1, buf2);
+ fail++;
+ }
+ num++;
+ }
+ printf ("%d tests failed out of %d.\n", fail, num);
+}
+#endif /* SNPRINTF_TEST */
+
+#endif /* !HAVE_SNPRINTF */
diff --git a/auth/Makefile.am b/auth/Makefile.am
new file mode 100644
index 000000000..6bd54eee3
--- /dev/null
+++ b/auth/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = addr login
+
+CLEANFILES =
diff --git a/auth/addr/Makefile.am b/auth/addr/Makefile.am
new file mode 100644
index 000000000..d471a3f92
--- /dev/null
+++ b/auth/addr/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = src
+
+CLEANFILES =
diff --git a/auth/addr/src/Makefile.am b/auth/addr/src/Makefile.am
new file mode 100644
index 000000000..cca406151
--- /dev/null
+++ b/auth/addr/src/Makefile.am
@@ -0,0 +1,12 @@
+auth_LTLIBRARIES = addr.la
+authdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/auth
+
+addr_la_LDFLAGS = -module -avoidversion
+
+addr_la_SOURCES = addr.c
+addr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
+
+AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\
+ -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)
+
+CLEANFILES =
diff --git a/auth/addr/src/addr.c b/auth/addr/src/addr.c
new file mode 100644
index 000000000..0b248b4c6
--- /dev/null
+++ b/auth/addr/src/addr.c
@@ -0,0 +1,208 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include <fnmatch.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include "authenticate.h"
+#include "dict.h"
+
+#define ADDR_DELIMITER " ,"
+#define PRIVILAGED_PORT_CIELING 1024
+
+#ifndef AF_INET_SDP
+#define AF_INET_SDP 27
+#endif
+
+auth_result_t
+gf_auth (dict_t *input_params, dict_t *config_params)
+{
+ char *name = NULL;
+ char *searchstr = NULL;
+ char peer_addr[UNIX_PATH_MAX];
+ data_t *peer_info_data = NULL;
+ peer_info_t *peer_info = NULL;
+ data_t *allow_addr = NULL, *reject_addr = NULL;
+ char is_inet_sdp = 0;
+
+ name = data_to_str (dict_get (input_params, "remote-subvolume"));
+ if (!name) {
+ gf_log ("authenticate/addr",
+ GF_LOG_ERROR,
+ "remote-subvolume not specified");
+ return AUTH_DONT_CARE;
+ }
+
+ asprintf (&searchstr, "auth.addr.%s.allow", name);
+ allow_addr = dict_get (config_params,
+ searchstr);
+ free (searchstr);
+
+ asprintf (&searchstr, "auth.addr.%s.reject", name);
+ reject_addr = dict_get (config_params,
+ searchstr);
+ free (searchstr);
+
+ if (!allow_addr) {
+ /* TODO: backword compatibility */
+ asprintf (&searchstr, "auth.ip.%s.allow", name);
+ allow_addr = dict_get (config_params, searchstr);
+ free (searchstr);
+ }
+
+ if (!(allow_addr || reject_addr)) {
+ gf_log ("auth/addr", GF_LOG_DEBUG,
+ "none of the options auth.addr.%s.allow or "
+ "auth.addr.%s.reject specified, returning auth_dont_care",
+ name, name);
+ return AUTH_DONT_CARE;
+ }
+
+ peer_info_data = dict_get (input_params, "peer-info");
+ if (!peer_info_data) {
+ gf_log ("authenticate/addr",
+ GF_LOG_ERROR,
+ "peer-info not present");
+ return AUTH_DONT_CARE;
+ }
+
+ peer_info = data_to_ptr (peer_info_data);
+
+ switch (((struct sockaddr *) &peer_info->sockaddr)->sa_family)
+ {
+ case AF_INET_SDP:
+ is_inet_sdp = 1;
+ ((struct sockaddr *) &peer_info->sockaddr)->sa_family = AF_INET;
+
+ case AF_INET:
+ case AF_INET6:
+ {
+ char *service;
+ uint16_t peer_port;
+ strcpy (peer_addr, peer_info->identifier);
+ service = strrchr (peer_addr, ':');
+ *service = '\0';
+ service ++;
+
+ if (is_inet_sdp) {
+ ((struct sockaddr *) &peer_info->sockaddr)->sa_family = AF_INET_SDP;
+ }
+
+ peer_port = atoi (service);
+ if (peer_port >= PRIVILAGED_PORT_CIELING) {
+ gf_log ("auth/addr", GF_LOG_ERROR,
+ "client is bound to port %d which is not privilaged",
+ peer_port);
+ return AUTH_DONT_CARE;
+ }
+ break;
+
+ case AF_UNIX:
+ strcpy (peer_addr, peer_info->identifier);
+ break;
+
+ default:
+ gf_log ("authenticate/addr", GF_LOG_ERROR,
+ "unknown address family %d",
+ ((struct sockaddr *) &peer_info->sockaddr)->sa_family);
+ return AUTH_DONT_CARE;
+ }
+ }
+
+ if (reject_addr) {
+ char *addr_str = NULL;
+ char *tmp;
+ char *addr_cpy = strdup (reject_addr->data);
+
+ addr_str = strtok_r (addr_cpy, ADDR_DELIMITER, &tmp);
+
+ while (addr_str) {
+ char negate = 0, match =0;
+ gf_log (name, GF_LOG_DEBUG,
+ "rejected = \"%s\", received addr = \"%s\"",
+ addr_str, peer_addr);
+ if (addr_str[0] == '!') {
+ negate = 1;
+ addr_str++;
+ }
+
+ match = fnmatch (addr_str,
+ peer_addr,
+ 0);
+ if (negate ? match : !match) {
+ free (addr_cpy);
+ return AUTH_REJECT;
+ }
+ addr_str = strtok_r (NULL, ADDR_DELIMITER, &tmp);
+ }
+ free (addr_cpy);
+ }
+
+ if (allow_addr) {
+ char *addr_str = NULL;
+ char *tmp;
+ char *addr_cpy = strdup (allow_addr->data);
+
+ addr_str = strtok_r (addr_cpy, ADDR_DELIMITER, &tmp);
+
+ while (addr_str) {
+ char negate = 0, match = 0;
+ gf_log (name, GF_LOG_DEBUG,
+ "allowed = \"%s\", received addr = \"%s\"",
+ addr_str, peer_addr);
+ if (addr_str[0] == '!') {
+ negate = 1;
+ addr_str++;
+ }
+
+ match = fnmatch (addr_str,
+ peer_addr,
+ 0);
+
+ if (negate ? match : !match) {
+ free (addr_cpy);
+ return AUTH_ACCEPT;
+ }
+ addr_str = strtok_r (NULL, ADDR_DELIMITER, &tmp);
+ }
+ free (addr_cpy);
+ }
+
+ return AUTH_DONT_CARE;
+}
+
+struct volume_options options[] = {
+ { .key = {"auth.addr.*.allow"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ { .key = {"auth.addr.*.reject"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ /* Backword compatibility */
+ { .key = {"auth.ip.*.allow"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ { .key = {NULL} }
+};
diff --git a/auth/login/Makefile.am b/auth/login/Makefile.am
new file mode 100644
index 000000000..d471a3f92
--- /dev/null
+++ b/auth/login/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = src
+
+CLEANFILES =
diff --git a/auth/login/src/Makefile.am b/auth/login/src/Makefile.am
new file mode 100644
index 000000000..eb7b990c2
--- /dev/null
+++ b/auth/login/src/Makefile.am
@@ -0,0 +1,13 @@
+auth_LTLIBRARIES = login.la
+authdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/auth
+
+login_la_LDFLAGS = -module -avoidversion
+
+login_la_SOURCES = login.c
+login_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
+
+
+AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\
+ -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)
+
+CLEANFILES =
diff --git a/auth/login/src/login.c b/auth/login/src/login.c
new file mode 100644
index 000000000..88c9f8206
--- /dev/null
+++ b/auth/login/src/login.c
@@ -0,0 +1,100 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include <fnmatch.h>
+#include "authenticate.h"
+
+auth_result_t gf_auth (dict_t *input_params, dict_t *config_params)
+{
+ char *username = NULL, *password = NULL;
+ data_t *allow_user = NULL, *username_data = NULL, *password_data = NULL;
+ int32_t result = AUTH_DONT_CARE;
+ char *brick_name = NULL, *searchstr = NULL;
+
+ username_data = dict_get (input_params, "username");
+ if (!username_data)
+ return AUTH_DONT_CARE;
+
+ username = data_to_str (username_data);
+
+ password_data = dict_get (input_params, "password");
+ if (!password_data)
+ return AUTH_DONT_CARE;
+
+ password = data_to_str (password_data);
+
+ brick_name = data_to_str (dict_get (input_params, "remote-subvolume"));
+ if (!brick_name) {
+ gf_log ("auth/login",
+ GF_LOG_ERROR,
+ "remote-subvolume not specified");
+ return AUTH_REJECT;
+ }
+
+ asprintf (&searchstr, "auth.login.%s.allow", brick_name);
+ allow_user = dict_get (config_params,
+ searchstr);
+ free (searchstr);
+
+ if (allow_user) {
+ char *username_str = NULL;
+ char *tmp;
+ char *username_cpy = strdup (allow_user->data);
+
+ username_str = strtok_r (username_cpy, " ,", &tmp);
+
+ while (username_str) {
+ data_t *passwd_data = NULL;
+ if (!fnmatch (username_str,
+ username,
+ 0)) {
+ asprintf (&searchstr, "auth.login.%s.password", username);
+ passwd_data = dict_get (config_params, searchstr);
+ if (!passwd_data) {
+ gf_log ("auth/login",
+ GF_LOG_DEBUG,
+ "wrong username/password combination");
+ result = AUTH_REJECT;
+ }
+ else
+ result = !strcmp (data_to_str (passwd_data), password) ? AUTH_ACCEPT : AUTH_REJECT;
+ break;
+ }
+ username_str = strtok_r (NULL, " ,", &tmp);
+ }
+ free (username_cpy);
+ }
+
+ return result;
+}
+
+struct volume_options options[] = {
+ { .key = {"auth.login.*.allow"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ { .key = {"auth.login.*.password"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ { .key = {NULL} }
+};
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 000000000..e20408bf2
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+aclocal
+autoheader
+(libtoolize --automake --copy --force || glibtoolize --automake --copy --force)
+autoconf
+automake --add-missing --copy --foreign
+cd argp-standalone;./autogen.sh
diff --git a/booster/Makefile.am b/booster/Makefile.am
new file mode 100644
index 000000000..e1c45f305
--- /dev/null
+++ b/booster/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS=src \ No newline at end of file
diff --git a/booster/src/Makefile.am b/booster/src/Makefile.am
new file mode 100644
index 000000000..9b6e77f95
--- /dev/null
+++ b/booster/src/Makefile.am
@@ -0,0 +1,17 @@
+xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/performance
+
+ldpreload_PROGRAMS = glusterfs-booster.so
+ldpreloaddir = $(libdir)/glusterfs/
+glusterfs_booster_so_SOURCES = booster.c
+glusterfs_booster_so_CFLAGS = -I$(top_srcdir)/libglusterfsclient/src/ -D_GNU_SOURCE -D$(GF_HOST_OS) -fPIC -Wall \
+ -pthread $(GF_BOOSTER_CFLAGS)
+glusterfs_booster_so_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE \
+ -I$(top_srcdir)/libglusterfsclient/src \
+ -I$(top_srcdir)/libglusterfs/src -DDATADIR=\"$(localstatedir)\" \
+ -DCONFDIR=\"$(sysconfdir)/glusterfs\"
+glusterfs_booster_so_LDFLAGS = -shared -nostartfiles
+glusterfs_booster_so_LDADD = -L$(top_builddir)/libglusterfs/src -lglusterfs \
+ -L$(top_builddir)/libglusterfsclient/src -lglusterfsclient
+
+CLEANFILES =
+
diff --git a/booster/src/booster.c b/booster/src/booster.c
new file mode 100644
index 000000000..cf5f7883c
--- /dev/null
+++ b/booster/src/booster.c
@@ -0,0 +1,920 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <libglusterfsclient.h>
+#include <list.h>
+#include <pthread.h>
+#include <fcntl.h>
+#include <sys/xattr.h>
+#include <string.h>
+#include <assert.h>
+
+#ifndef GF_UNIT_KB
+#define GF_UNIT_KB 1024
+#endif
+
+#ifndef UNIX_PATH_MAX
+#define UNIX_PATH_MAX 108
+#endif
+
+struct _inode;
+struct _dict;
+struct _fd {
+ pid_t pid;
+ struct list_head inode_list;
+ struct _inode *inode;
+ struct _dict *ctx;
+ int32_t refcount;
+};
+
+typedef struct _fdtable fdtable_t;
+typedef struct _fd fd_t;
+
+
+inline void
+gf_fd_put (struct _fdtable *fdtable, int64_t fd);
+
+struct _fd *
+gf_fd_fdptr_get (struct _fdtable *fdtable, int64_t fd);
+
+struct _fdtable *
+gf_fd_fdtable_alloc (void);
+
+void
+gf_fd_fdtable_destroy (struct _fdtable *);
+
+int32_t
+gf_fd_unused_get (struct _fdtable *fdtable, struct _fd *fdptr);
+
+int32_t
+gf_fd_unused_get2 (struct _fdtable *fdtable, struct _fd *fdptr, int64_t fd);
+
+void
+fd_unref (struct _fd *fd);
+
+fd_t *
+fd_ref (struct _fd *fd);
+
+pid_t
+getpid (void);
+
+ssize_t
+write (int fd, const void *buf, size_t count);
+
+/* open, open64, creat */
+static int (*real_open) (const char *pathname, int flags, ...);
+static int (*real_open64) (const char *pathname, int flags, ...);
+static int (*real_creat) (const char *pathname, mode_t mode);
+
+/* read, readv, pread, pread64 */
+static ssize_t (*real_read) (int fd, void *buf, size_t count);
+static ssize_t (*real_readv) (int fd, const struct iovec *vector, int count);
+static ssize_t (*real_pread) (int fd, void *buf, size_t count, unsigned long offset);
+static ssize_t (*real_pread64) (int fd, void *buf, size_t count, uint64_t offset);
+
+/* write, writev, pwrite, pwrite64 */
+static ssize_t (*real_write) (int fd, const void *buf, size_t count);
+static ssize_t (*real_writev) (int fd, const struct iovec *vector, int count);
+static ssize_t (*real_pwrite) (int fd, const void *buf, size_t count, unsigned long offset);
+static ssize_t (*real_pwrite64) (int fd, const void *buf, size_t count, uint64_t offset);
+
+/* lseek, llseek, lseek64 */
+static off_t (*real_lseek) (int fildes, unsigned long offset, int whence);
+static off_t (*real_lseek64) (int fildes, uint64_t offset, int whence);
+
+/* close */
+static int (*real_close) (int fd);
+
+/* dup dup2 */
+static int (*real_dup) (int fd);
+static int (*real_dup2) (int oldfd, int newfd);
+
+static pid_t (*real_fork) (void);
+
+#define RESOLVE(sym) do { \
+ if (!real_##sym) \
+ real_##sym = dlsym (RTLD_NEXT, #sym); \
+ } while (0)
+
+/*TODO: set proper value */
+#define MOUNT_HASH_SIZE 256
+
+struct booster_mount {
+ dev_t st_dev;
+ libglusterfs_handle_t handle;
+ struct list_head device_list;
+};
+typedef struct booster_mount booster_mount_t;
+
+struct booster_mount_table {
+ pthread_mutex_t lock;
+ struct list_head *mounts;
+ int32_t hash_size;
+};
+typedef struct booster_mount_table booster_mount_table_t;
+
+static fdtable_t *booster_glfs_fdtable = NULL;
+static booster_mount_table_t *booster_mount_table = NULL;
+
+static int32_t
+booster_put_handle (booster_mount_table_t *table,
+ dev_t st_dev,
+ libglusterfs_handle_t handle)
+{
+ int32_t hash = 0;
+ booster_mount_t *mount = NULL, *tmp = NULL;
+ int32_t ret = 0;
+
+ mount = calloc (1, sizeof (*mount));
+ if (!mount) {
+ return -1;
+ }
+
+ // ERR_ABORT (mount);
+ INIT_LIST_HEAD (&mount->device_list);
+ mount->st_dev = st_dev;
+ mount->handle = handle;
+
+ hash = st_dev % table->hash_size;
+
+ pthread_mutex_lock (&table->lock);
+ {
+ list_for_each_entry (tmp, &table->mounts[hash], device_list) {
+ if (tmp->st_dev == st_dev) {
+ ret = -1;
+ errno = EEXIST;
+ goto unlock;
+ }
+ }
+
+ list_add (&mount->device_list, &table->mounts[hash]);
+ }
+unlock:
+ pthread_mutex_unlock (&table->lock);
+
+ return ret;
+}
+
+
+static inline long
+booster_get_glfs_fd (fdtable_t *fdtable, int fd)
+{
+ fd_t *glfs_fd = NULL;
+
+ glfs_fd = gf_fd_fdptr_get (fdtable, fd);
+ return (long) glfs_fd;
+}
+
+
+static inline void
+booster_put_glfs_fd (long glfs_fd)
+{
+ fd_unref ((fd_t *)glfs_fd);
+}
+
+
+static inline int32_t
+booster_get_unused_fd (fdtable_t *fdtable, long glfs_fd, int fd)
+{
+ int32_t ret = -1;
+ ret = gf_fd_unused_get2 (fdtable, (fd_t *)glfs_fd, fd);
+ return ret;
+}
+
+
+static inline void
+booster_put_fd (fdtable_t *fdtable, int fd)
+{
+ gf_fd_put (fdtable, fd);
+}
+
+
+static libglusterfs_handle_t
+booster_get_handle (booster_mount_table_t *table, dev_t st_dev)
+{
+ int32_t hash = 0;
+ booster_mount_t *mount = NULL;
+ libglusterfs_handle_t handle = NULL;
+
+ hash = st_dev % table->hash_size;
+
+ pthread_mutex_lock (&table->lock);
+ {
+ list_for_each_entry (mount, &table->mounts[hash], device_list) {
+ if (mount->st_dev == st_dev) {
+ handle = mount->handle;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock (&table->lock);
+
+ return handle;
+}
+
+
+void
+do_open (int fd, int flags, mode_t mode)
+{
+ char *specfile = NULL;
+ libglusterfs_handle_t handle;
+ int32_t file_size;
+ struct stat st = {0,};
+ int32_t ret = -1;
+
+ ret = fstat (fd, &st);
+ if (ret == -1) {
+ return;
+ }
+
+ if (!booster_mount_table) {
+ return;
+ }
+
+ handle = booster_get_handle (booster_mount_table, st.st_dev);
+ if (!handle) {
+ FILE *specfp = NULL;
+
+ glusterfs_init_ctx_t ctx = {
+ .loglevel = "critical",
+ .lookup_timeout = 600,
+ .stat_timeout = 600,
+ };
+
+ file_size = fgetxattr (fd, "user.glusterfs-booster-volfile", NULL, 0);
+ if (file_size == -1) {
+ return;
+ }
+
+ specfile = calloc (1, file_size);
+ if (!specfile) {
+ fprintf (stderr, "cannot allocate memory: %s\n", strerror (errno));
+ return;
+ }
+
+ ret = fgetxattr (fd, "user.glusterfs-booster-volfile", specfile, file_size);
+ if (ret == -1) {
+ free (specfile);
+ return ;
+ }
+
+ specfp = tmpfile ();
+ if (!specfp) {
+ free (specfile);
+ return;
+ }
+
+ ret = fwrite (specfile, file_size, 1, specfp);
+ if (ret != 1) {
+ fclose (specfp);
+ free (specfile);
+ }
+
+ fseek (specfp, 0L, SEEK_SET);
+
+ ctx.logfile = getenv ("GLFS_BOOSTER_LOGFILE");
+ ctx.specfp = specfp;
+
+ handle = glusterfs_init (&ctx);
+
+ free (specfile);
+ fclose (specfp);
+
+ if (!handle) {
+ return;
+ }
+
+ ret = booster_put_handle (booster_mount_table, st.st_dev, handle);
+ if (ret == -1) {
+ glusterfs_fini (handle);
+ if (errno != EEXIST) {
+ return;
+ }
+ }
+ }
+
+ if (handle) {
+ long glfs_fd;
+ char path [UNIX_PATH_MAX];
+ ret = fgetxattr (fd, "user.glusterfs-booster-path", path, UNIX_PATH_MAX);
+ if (ret == -1) {
+ return;
+ }
+
+ glfs_fd = glusterfs_open (handle, path, flags, mode);
+ if (glfs_fd) {
+ ret = booster_get_unused_fd (booster_glfs_fdtable, glfs_fd, fd);
+ if (ret == -1) {
+ glusterfs_close (glfs_fd);
+ return;
+ }
+ }
+ }
+
+ return;
+}
+
+#ifndef __USE_FILE_OFFSET64
+int
+open (const char *pathname, int flags, ...)
+{
+ int ret;
+ mode_t mode = 0;
+ va_list ap;
+
+ if (flags & O_CREAT) {
+ va_start (ap, flags);
+ mode = va_arg (ap, mode_t);
+ va_end (ap);
+
+ ret = real_open (pathname, flags, mode);
+ } else {
+ ret = real_open (pathname, flags);
+ }
+
+ if (ret != -1) {
+ flags &= ~ O_CREAT;
+ do_open (ret, flags, mode);
+ }
+
+ return ret;
+}
+#endif
+
+#if defined (__USE_LARGEFILE64) || !defined (__USE_FILE_OFFSET64)
+int
+open64 (const char *pathname, int flags, ...)
+{
+ int ret;
+ mode_t mode = 0;
+ va_list ap;
+
+ if (flags & O_CREAT) {
+ va_start (ap, flags);
+ mode = va_arg (ap, mode_t);
+ va_end (ap);
+
+ ret = real_open64 (pathname, flags, mode);
+ } else {
+ ret = real_open64 (pathname, flags);
+ }
+
+ if (ret != -1) {
+ flags &= ~O_CREAT;
+ do_open (ret, flags, mode);
+ }
+
+ return ret;
+}
+#endif
+
+int
+creat (const char *pathname, mode_t mode)
+{
+ int ret;
+
+ ret = real_creat (pathname, mode);
+
+ if (ret != -1) {
+ do_open (ret, O_WRONLY | O_TRUNC, mode);
+ }
+
+ return ret;
+}
+
+
+/* pread */
+
+ssize_t
+pread (int fd, void *buf, size_t count, unsigned long offset)
+{
+ ssize_t ret;
+ long glfs_fd = 0;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+ if (!glfs_fd) {
+ ret = real_pread (fd, buf, count, offset);
+ } else {
+ ret = glusterfs_pread (glfs_fd, buf, count, offset);
+ if (ret == -1) {
+ ret = real_pread (fd, buf, count, offset);
+ }
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+
+
+ssize_t
+pread64 (int fd, void *buf, size_t count, uint64_t offset)
+{
+ ssize_t ret;
+ long glfs_fd = 0;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+ if (!glfs_fd) {
+ ret = real_pread (fd, buf, count, offset);
+ } else {
+ ret = glusterfs_pread (glfs_fd, buf, count, offset);
+ if (ret == -1) {
+ ret = real_pread (fd, buf, count, offset);
+ }
+ }
+
+ return ret;
+}
+
+
+ssize_t
+read (int fd, void *buf, size_t count)
+{
+ int ret;
+ long glfs_fd;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+ if (!glfs_fd) {
+ ret = real_read (fd, buf, count);
+ } else {
+ uint64_t offset = 0;
+ offset = real_lseek64 (fd, 0L, SEEK_CUR);
+ if ((int64_t)offset != -1) {
+ ret = glusterfs_lseek (glfs_fd, offset, SEEK_SET);
+ if (ret != -1) {
+ ret = glusterfs_read (glfs_fd, buf, count);
+ }
+ } else {
+ ret = -1;
+ }
+
+ if (ret == -1) {
+ ret = real_read (fd, buf, count);
+ }
+
+ if (ret > 0 && ((int64_t) offset) >= 0) {
+ real_lseek64 (fd, ret + offset, SEEK_SET);
+ }
+
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+
+
+ssize_t
+readv (int fd, const struct iovec *vector, int count)
+{
+ int ret;
+ long glfs_fd = 0;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+ if (!glfs_fd) {
+ ret = real_readv (fd, vector, count);
+ } else {
+ uint64_t offset = 0;
+ offset = real_lseek64 (fd, 0L, SEEK_CUR);
+ if ((int64_t)offset != -1) {
+ ret = glusterfs_lseek (glfs_fd, offset, SEEK_SET);
+ if (ret != -1) {
+ ret = glusterfs_readv (glfs_fd, vector, count);
+ }
+ } else {
+ ret = -1;
+ }
+
+ ret = glusterfs_readv (glfs_fd, vector, count);
+ if (ret > 0) {
+ real_lseek64 (fd, offset + ret, SEEK_SET);
+ }
+
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+
+
+ssize_t
+write (int fd, const void *buf, size_t count)
+{
+ int ret;
+ long glfs_fd = 0;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+
+ if (!glfs_fd) {
+ ret = real_write (fd, buf, count);
+ } else {
+ uint64_t offset = 0;
+ offset = real_lseek64 (fd, 0L, SEEK_CUR);
+ if (((int64_t) offset) != -1) {
+ ret = glusterfs_lseek (glfs_fd, offset, SEEK_SET);
+ if (ret != -1) {
+ ret = glusterfs_write (glfs_fd, buf, count);
+ }
+ } else {
+ ret = -1;
+ }
+
+ if (ret == -1) {
+ ret = real_write (fd, buf, count);
+ }
+
+ if (ret > 0 && ((int64_t) offset) >= 0) {
+ real_lseek64 (fd, offset + ret, SEEK_SET);
+ }
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+
+ssize_t
+writev (int fd, const struct iovec *vector, int count)
+{
+ int ret = 0;
+ long glfs_fd = 0;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+
+ if (!glfs_fd) {
+ ret = real_writev (fd, vector, count);
+ } else {
+ uint64_t offset = 0;
+ offset = real_lseek64 (fd, 0L, SEEK_CUR);
+
+ if (((int64_t) offset) != -1) {
+ ret = glusterfs_lseek (glfs_fd, offset, SEEK_SET);
+ if (ret != -1) {
+ ret = glusterfs_writev (glfs_fd, vector, count);
+ }
+ } else {
+ ret = -1;
+ }
+
+/* ret = glusterfs_writev (glfs_fd, vector, count); */
+ if (ret == -1) {
+ ret = real_writev (fd, vector, count);
+ }
+
+ if (ret > 0 && ((int64_t)offset) >= 0) {
+ real_lseek64 (fd, offset + ret, SEEK_SET);
+ }
+
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+
+
+ssize_t
+pwrite (int fd, const void *buf, size_t count, unsigned long offset)
+{
+ int ret;
+ long glfs_fd = 0;
+
+ assert (real_pwrite != NULL);
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+
+ if (!glfs_fd) {
+ ret = real_pwrite (fd, buf, count, offset);
+ } else {
+ ret = glusterfs_pwrite (glfs_fd, buf, count, offset);
+ if (ret == -1) {
+ ret = real_pwrite (fd, buf, count, offset);
+ }
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+
+
+ssize_t
+pwrite64 (int fd, const void *buf, size_t count, uint64_t offset)
+{
+ int ret;
+ long glfs_fd = 0;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+
+ if (!glfs_fd) {
+ ret = real_pwrite64 (fd, buf, count, offset);
+ } else {
+ ret = glusterfs_pwrite (glfs_fd, buf, count, offset);
+ if (ret == -1) {
+ ret = real_pwrite64 (fd, buf, count, offset);
+ }
+ }
+
+ return ret;
+}
+
+
+int
+close (int fd)
+{
+ int ret = -1;
+ long glfs_fd = 0;
+/* struct stat st = {0,}; */
+
+/* ret = fstat (fd, &st);
+ if (ret != -1) {
+ libglusterfs_handle_t handle = 0;
+ handle = booster_get_handle (booster_mount_table, st.st_dev);
+ if (handle) { */
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd);
+
+ if (glfs_fd) {
+ booster_put_fd (booster_glfs_fdtable, fd);
+ ret = glusterfs_close (glfs_fd);
+ booster_put_glfs_fd (glfs_fd);
+ }
+/*}
+ }*/
+
+ ret = real_close (fd);
+
+ return ret;
+}
+
+#ifndef _LSEEK_DECLARED
+#define _LSEEK_DECLARED
+off_t
+lseek (int filedes, unsigned long offset, int whence)
+{
+ int ret;
+ long glfs_fd = 0;
+
+ ret = real_lseek (filedes, offset, whence);
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, filedes);
+ if (glfs_fd) {
+ ret = glusterfs_lseek (glfs_fd, offset, whence);
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+#endif
+
+off_t
+lseek64 (int filedes, uint64_t offset, int whence)
+{
+ int ret;
+ long glfs_fd = 0;
+
+ ret = real_lseek64 (filedes, offset, whence);
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, filedes);
+ if (glfs_fd) {
+ ret = glusterfs_lseek (glfs_fd, offset, whence);
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return ret;
+}
+
+int
+dup (int oldfd)
+{
+ int ret = -1, new_fd = -1;
+ long glfs_fd = 0;
+
+ glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, oldfd);
+ new_fd = real_dup (oldfd);
+
+ if (new_fd >=0 && glfs_fd) {
+ ret = booster_get_unused_fd (booster_glfs_fdtable, glfs_fd, new_fd);
+ fd_ref ((fd_t *)glfs_fd);
+ if (ret == -1) {
+ real_close (new_fd);
+ }
+ }
+
+ if (glfs_fd) {
+ booster_put_glfs_fd (glfs_fd);
+ }
+
+ return new_fd;
+}
+
+
+int
+dup2 (int oldfd, int newfd)
+{
+ int ret = -1;
+ long old_glfs_fd = 0, new_glfs_fd = 0;
+
+ if (oldfd == newfd) {
+ return newfd;
+ }
+
+ old_glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, oldfd);
+ new_glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, newfd);
+
+ ret = real_dup2 (oldfd, newfd);
+ if (ret >= 0) {
+ if (new_glfs_fd) {
+ glusterfs_close (new_glfs_fd);
+ booster_put_glfs_fd (new_glfs_fd);
+ booster_put_fd (booster_glfs_fdtable, newfd);
+ new_glfs_fd = 0;
+ }
+
+ if (old_glfs_fd) {
+ ret = booster_get_unused_fd (booster_glfs_fdtable, old_glfs_fd, newfd);
+ fd_ref ((fd_t *)old_glfs_fd);
+ if (ret == -1) {
+ real_close (newfd);
+ }
+ }
+ }
+
+ if (old_glfs_fd) {
+ booster_put_glfs_fd (old_glfs_fd);
+ }
+
+ if (new_glfs_fd) {
+ booster_put_glfs_fd (new_glfs_fd);
+ }
+
+ return ret;
+}
+
+
+#define MOUNT_TABLE_HASH_SIZE 256
+
+
+static int
+booster_init (void)
+{
+ int i = 0;
+ booster_glfs_fdtable = gf_fd_fdtable_alloc ();
+ if (!booster_glfs_fdtable) {
+ fprintf (stderr, "cannot allocate fdtable: %s\n", strerror (errno));
+ goto err;
+ }
+
+ booster_mount_table = calloc (1, sizeof (*booster_mount_table));
+ if (!booster_mount_table) {
+ fprintf (stderr, "cannot allocate memory: %s\n", strerror (errno));
+ goto err;
+ }
+
+ pthread_mutex_init (&booster_mount_table->lock, NULL);
+ booster_mount_table->hash_size = MOUNT_TABLE_HASH_SIZE;
+ booster_mount_table->mounts = calloc (booster_mount_table->hash_size, sizeof (*booster_mount_table->mounts));
+ if (!booster_mount_table->mounts) {
+ fprintf (stderr, "cannot allocate memory: %s\n", strerror (errno));
+ goto err;
+ }
+
+ for (i = 0; i < booster_mount_table->hash_size; i++)
+ {
+ INIT_LIST_HEAD (&booster_mount_table->mounts[i]);
+ }
+
+ return 0;
+
+err:
+ if (booster_glfs_fdtable) {
+ gf_fd_fdtable_destroy (booster_glfs_fdtable);
+ booster_glfs_fdtable = NULL;
+ }
+
+ if (booster_mount_table) {
+ if (booster_mount_table->mounts) {
+ free (booster_mount_table->mounts);
+ }
+
+ free (booster_mount_table);
+ booster_mount_table = NULL;
+ }
+ return -1;
+}
+
+
+static void
+booster_cleanup (void)
+{
+ int i;
+ booster_mount_t *mount = NULL, *tmp = NULL;
+
+ /* gf_fd_fdtable_destroy (booster_glfs_fdtable);*/
+ /*for (i=0; i < booster_glfs_fdtable->max_fds; i++) {
+ if (booster_glfs_fdtable->fds[i]) {
+ fd_t *fd = booster_glfs_fdtable->fds[i];
+ free (fd);
+ }
+ }*/
+
+ free (booster_glfs_fdtable);
+ booster_glfs_fdtable = NULL;
+
+ pthread_mutex_lock (&booster_mount_table->lock);
+ {
+ for (i = 0; i < booster_mount_table->hash_size; i++)
+ {
+ list_for_each_entry_safe (mount, tmp,
+ &booster_mount_table->mounts[i], device_list) {
+ list_del (&mount->device_list);
+ glusterfs_fini (mount->handle);
+ free (mount);
+ }
+ }
+ free (booster_mount_table->mounts);
+ }
+ pthread_mutex_unlock (&booster_mount_table->lock);
+
+ glusterfs_reset ();
+ free (booster_mount_table);
+ booster_mount_table = NULL;
+}
+
+
+
+pid_t
+fork (void)
+{
+ pid_t pid = 0;
+ char child = 0;
+
+ glusterfs_log_lock ();
+ {
+ pid = real_fork ();
+ }
+ glusterfs_log_unlock ();
+
+ child = (pid == 0);
+ if (child) {
+ booster_cleanup ();
+ booster_init ();
+ }
+
+ return pid;
+}
+
+
+void
+_init (void)
+{
+ booster_init ();
+
+ RESOLVE (open);
+ RESOLVE (open64);
+ RESOLVE (creat);
+
+ RESOLVE (read);
+ RESOLVE (readv);
+ RESOLVE (pread);
+ RESOLVE (pread64);
+
+ RESOLVE (write);
+ RESOLVE (writev);
+ RESOLVE (pwrite);
+ RESOLVE (pwrite64);
+
+ RESOLVE (lseek);
+ RESOLVE (lseek64);
+
+ RESOLVE (close);
+
+ RESOLVE (dup);
+ RESOLVE (dup2);
+
+ RESOLVE (fork);
+}
+
diff --git a/commit.sh b/commit.sh
new file mode 100755
index 000000000..26318959d
--- /dev/null
+++ b/commit.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+export EDITOR="emacs"
+#TLA_REVISION=$(expr 1 + $(cat ./libglusterfs/src/revision.h | cut -f 8 -d '-' | sed -e 's/"//'))
+#sed -i "s/AC_INIT.*/AC_INIT([glusterfs],[2.0.0tla${TLA_REVISION}],[gluster-users@gluster.org])/g" ./configure.ac
+tla commit --write-revision ./libglusterfs/src/revision.h:'#define GLUSTERFS_REPOSITORY_REVISION "%s"' "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 000000000..6fb7838df
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,554 @@
+dnl Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+dnl This file is part of GlusterFS.
+dnl
+dnl GlusterFS is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 3 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl GlusterFS is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+AC_INIT([glusterfs],[2.0.0tla],[gluster-users@gluster.org])
+
+AM_INIT_AUTOMAKE
+
+AM_CONFIG_HEADER([config.h])
+
+AC_CONFIG_FILES([Makefile
+ libglusterfs/Makefile
+ libglusterfs/src/Makefile
+ libglusterfsclient/Makefile
+ libglusterfsclient/src/Makefile
+ mod_glusterfs/Makefile
+ mod_glusterfs/apache/Makefile
+ mod_glusterfs/apache/1.3/Makefile
+ mod_glusterfs/apache/1.3/src/Makefile
+ mod_glusterfs/apache/2.2/Makefile
+ mod_glusterfs/apache/2.2/src/Makefile
+ mod_glusterfs/lighttpd/Makefile
+ mod_glusterfs/lighttpd/1.4/Makefile
+ mod_glusterfs/lighttpd/1.5/Makefile
+ glusterfsd/Makefile
+ glusterfsd/src/Makefile
+ booster/Makefile
+ booster/src/Makefile
+ xlators/Makefile
+ xlators/mount/Makefile
+ xlators/mount/fuse/Makefile
+ xlators/mount/fuse/src/Makefile
+ xlators/mount/fuse/utils/mount.glusterfs
+ xlators/mount/fuse/utils/mount_glusterfs
+ xlators/mount/fuse/utils/Makefile
+ xlators/storage/Makefile
+ xlators/storage/posix/Makefile
+ xlators/storage/posix/src/Makefile
+ xlators/storage/bdb/Makefile
+ xlators/storage/bdb/src/Makefile
+ xlators/cluster/Makefile
+ xlators/cluster/unify/Makefile
+ xlators/cluster/unify/src/Makefile
+ xlators/cluster/afr/Makefile
+ xlators/cluster/afr/src/Makefile
+ xlators/cluster/stripe/Makefile
+ xlators/cluster/stripe/src/Makefile
+ xlators/cluster/dht/Makefile
+ xlators/cluster/dht/src/Makefile
+ xlators/cluster/ha/Makefile
+ xlators/cluster/ha/src/Makefile
+ xlators/cluster/map/Makefile
+ xlators/cluster/map/src/Makefile
+ xlators/performance/Makefile
+ xlators/performance/write-behind/Makefile
+ xlators/performance/write-behind/src/Makefile
+ xlators/performance/read-ahead/Makefile
+ xlators/performance/read-ahead/src/Makefile
+ xlators/performance/io-threads/Makefile
+ xlators/performance/io-threads/src/Makefile
+ xlators/performance/io-cache/Makefile
+ xlators/performance/io-cache/src/Makefile
+ xlators/performance/symlink-cache/Makefile
+ xlators/performance/symlink-cache/src/Makefile
+ xlators/debug/Makefile
+ xlators/debug/trace/Makefile
+ xlators/debug/trace/src/Makefile
+ xlators/debug/error-gen/Makefile
+ xlators/debug/error-gen/src/Makefile
+ xlators/protocol/Makefile
+ xlators/protocol/client/Makefile
+ xlators/protocol/client/src/Makefile
+ xlators/protocol/server/Makefile
+ xlators/protocol/server/src/Makefile
+ xlators/features/Makefile
+ xlators/features/locks/Makefile
+ xlators/features/locks/src/Makefile
+ xlators/features/path-convertor/Makefile
+ xlators/features/path-convertor/src/Makefile
+ xlators/features/trash/Makefile
+ xlators/features/trash/src/Makefile
+ xlators/features/filter/Makefile
+ xlators/features/filter/src/Makefile
+ xlators/features/quota/Makefile
+ xlators/features/quota/src/Makefile
+ xlators/encryption/Makefile
+ xlators/encryption/rot-13/Makefile
+ xlators/encryption/rot-13/src/Makefile
+ scheduler/Makefile
+ scheduler/alu/Makefile
+ scheduler/alu/src/Makefile
+ scheduler/random/Makefile
+ scheduler/random/src/Makefile
+ scheduler/nufa/Makefile
+ scheduler/nufa/src/Makefile
+ scheduler/rr/Makefile
+ scheduler/rr/src/Makefile
+ scheduler/switch/Makefile
+ scheduler/switch/src/Makefile
+ transport/Makefile
+ transport/socket/Makefile
+ transport/socket/src/Makefile
+ transport/ib-verbs/Makefile
+ transport/ib-verbs/src/Makefile
+ auth/Makefile
+ auth/addr/Makefile
+ auth/addr/src/Makefile
+ auth/login/Makefile
+ auth/login/src/Makefile
+ doc/Makefile
+ doc/examples/Makefile
+ doc/hacker-guide/Makefile
+ doc/user-guide/Makefile
+ extras/Makefile
+ extras/init.d/Makefile
+ extras/init.d/glusterfs-server.plist
+ extras/benchmarking/Makefile
+ extras/test/Makefile
+ glusterfs.spec])
+
+AC_CANONICAL_HOST
+
+AC_PROG_CC
+AC_PROG_LIBTOOL
+
+# LEX needs a check
+AC_PROG_LEX
+if test "x${LEX}" != "xflex" -a "x${FLEX}" != "xlex"; then
+ AC_MSG_ERROR([Flex or lex required to build glusterfs.])
+fi
+
+# YACC needs a check
+AC_PROG_YACC
+if test "x${YACC}" = "xbyacc" -o "x${YACC}" = "xyacc" -o "x${YACC}" = "x"; then
+ AC_MSG_ERROR([GNU Bison required to build glusterfs.])
+fi
+
+AC_CHECK_TOOL([LD],[ld])
+
+AC_CHECK_LIB([pthread], [pthread_mutex_init], , AC_MSG_ERROR([Posix threads library is required to build glusterfs]))
+
+AC_CHECK_FUNC([dlopen], [has_dlopen=yes], AC_CHECK_LIB([dl], [dlopen], , AC_MSG_ERROR([Dynamic linking library required to build glusterfs])))
+
+
+AC_CHECK_HEADERS([sys/xattr.h])
+
+AC_CHECK_HEADERS([sys/extattr.h])
+
+dnl Mac OS X does not have spinlocks
+AC_CHECK_FUNC([pthread_spin_init], [have_spinlock=yes])
+if test "x${have_spinlock}" = "xyes"; then
+ AC_DEFINE(HAVE_SPINLOCK, 1, [define if found spinlock])
+fi
+AC_SUBST(HAVE_SPINLOCK)
+
+dnl some os may not have GNU defined strnlen function
+AC_CHECK_FUNC([strnlen], [have_strnlen=yes])
+if test "x${have_strnlen}" = "xyes"; then
+ AC_DEFINE(HAVE_STRNLEN, 1, [define if found strnlen])
+fi
+AC_SUBST(HAVE_STRNLEN)
+
+
+AC_CHECK_FUNC([setfsuid], [have_setfsuid=yes])
+AC_CHECK_FUNC([setfsgid], [have_setfsgid=yes])
+
+if test "x${have_setfsuid}" = "xyes" -a "x${have_setfsgid}" = "xyes"; then
+ AC_DEFINE(HAVE_SET_FSID, 1, [define if found setfsuid setfsgid])
+fi
+
+
+# LIBGLUSTERFSCLIENT section
+AC_ARG_ENABLE([libglusterfsclient],
+ AC_HELP_STRING([--disable-libglusterfsclient],
+ [Do not build libglusterfsclient]))
+
+BUILD_LIBGLUSTERFSCLIENT="no"
+
+if test "x$enable_libglusterfsclient" != "xno"; then
+ LIBGLUSTERFSCLIENT_SUBDIR="libglusterfsclient"
+ BUILD_LIBGLUSTERFSCLIENT="yes"
+fi
+
+AC_SUBST(LIBGLUSTERFSCLIENT_SUBDIR)
+# end LIBGLUSTERFSCLIENT section
+
+
+# MOD_GLUSTERFS section
+AC_ARG_ENABLE([mod_glusterfs],
+ AC_HELP_STRING([--disable-mod_glusterfs],
+ [Do not build glusterfs module for webserver. Currently supported module is for apache/1.3.x]))
+
+if test "x$enable_mod_glusterfs" != "xno"; then
+ AC_ARG_WITH([apxs],
+ AC_HELP_STRING([--with-apxs],
+ [directory containing apxs binary]))
+ if test "x$with_apxs" != "x"; then
+ APXS_BIN=$with_apxs
+ else
+ APXS_BIN="$PATH"
+ fi
+ AC_CHECK_TOOL([APXS],[apxs], ["no"], [$APXS_BIN])
+ if test "X$APXS" = "Xno"; then
+ HAVE_APXS="no";
+ else
+ if test "x$with_apxs" != "x"; then
+ APXS="$with_apxs/apxs";
+ fi
+ HAVE_APXS="yes";
+ fi
+
+ HAVE_LIBGLUSTERFSCLIENT="no";
+ if test "x$BUILD_LIBGLUSTERFSCLIENT" = "xyes"; then
+ HAVE_LIBGLUSTERFSCLIENT="yes";
+ fi
+
+ AC_ARG_WITH([apxspath],
+ AC_HELP_STRING([--with-apxspath],
+ [Path to apxs binary]))
+
+ AC_ARG_WITH([apachepath],
+ AC_HELP_STRING([--with-apachepath],
+ [Path to apache binary]))
+fi
+
+if test "x$enable_mod_glusterfs" = "xyes" -a "x$HAVE_APXS" = "xno"; then
+ echo "apxs is required to build mod_glusterfs. Use --with-apxs to specify path to apxs. If mod_glusterfs is not required, do not pass --enable-mod_glusterfs option to configure "
+ exit 1
+fi
+
+if test "x$enable_mod_glusterfs" = "xyes" -a "x$HAVE_LIBGLUSTERFSCLIENT" = "xno"; then
+ echo "libglusterfsclient is required to build mod_glusterfs. Do not specify --disable-libglusterfsclient to configure script. If mod_glusterfs is not required, do not pass --enable-mod_glusterfs option to configure "
+ exit 1
+fi
+
+BUILD_MOD_GLUSTERFS=no
+MOD_GLUSTERFS_HTTPD_VERSION=""
+
+if test "x$enable_mod_glusterfs" != "xno" -a "x$HAVE_APXS" = "xyes" -a "x$HAVE_LIBGLUSTERFSCLIENT" = "xyes"; then
+ BUILD_MOD_GLUSTERFS="yes";
+ MOD_GLUSTERFS_SUBDIR="mod_glusterfs";
+fi
+
+if test "x$BUILD_MOD_GLUSTERFS" = "xyes"; then
+ HTTPD_BIN_DIR=`$APXS -q SBINDIR`
+ MOD_GLUSTERFS_HTTPD_VERSION=`$HTTPD_BIN_DIR/httpd -V | head -1 | awk "{print $3}" | sed 's/[[^0-9.]]//g' | sed 's/\(.*\..*\)\..*/\1/'`
+fi
+
+if test "x$with_apxspath" != "x"; then
+ APXS_MANUAL=$with_apxspath
+fi
+
+if test "x$with_apachepath" != "x"; then
+ HTTPD_MANUAL=$with_apachepath
+fi
+
+if test "x$enable_mod_glusterfs" != "xno" -a "x$with_apxspath" != "x" -a "x$with_apachepath" != "x"; then
+ BUILD_MOD_GLUSTERFS="yes";
+ MOD_GLUSTERFS_SUBDIR="mod_glusterfs";
+ APACHE_MANUAL=yes
+fi
+
+if test "x$APACHE_MANUAL" = "xyes"; then
+ HTTPD_BIN_DIR=`$APXS_MANUAL -q SBINDIR`
+ MOD_GLUSTERFS_HTTPD_VERSION=`$HTTPD_MANUAL -V | head -1 | awk "{print $3}" | sed 's/[[^0-9.]]//g' | sed 's/\(.*\..*\)\..*/\1/'`
+ APXS=$APXS_MANUAL
+fi
+
+AC_SUBST(MOD_GLUSTERFS_SUBDIR)
+AC_SUBST(APXS)
+AC_SUBST(MOD_GLUSTERFS_HTTPD_VERSION)
+# end MOD_GLUSTERFS section
+
+
+# FUSE section
+# TODO: make a clean version check of libfuse
+AC_ARG_ENABLE([fuse-client],
+ AC_HELP_STRING([--disable-fuse-client],
+ [Do not build the fuse client. NOTE: you cannot mount glusterfs without the client]))
+
+if test "x$enable_fuse_client" != "xno"; then
+ AC_CHECK_LIB([fuse],
+ [fuse_req_interrupt_func],
+ [HAVE_LIBFUSE="yes"],
+ [HAVE_LIBFUSE="no"])
+fi
+
+if test "x$enable_fuse_client" = "xyes" -a "x$HAVE_LIBFUSE" = "xno"; then
+ echo "FUSE requested but not found."
+ exit 1
+fi
+
+BUILD_FUSE_CLIENT=no
+if test "x$enable_fuse_client" != "xno" -a "x$HAVE_LIBFUSE" = "xyes"; then
+ FUSE_CLIENT_SUBDIR=fuse
+ BUILD_FUSE_CLIENT="yes"
+fi
+
+AC_SUBST(FUSE_CLIENT_SUBDIR)
+# end FUSE section
+
+
+# EPOLL section
+AC_ARG_ENABLE([epoll],
+ AC_HELP_STRING([--disable-epoll],
+ [Use poll instead of epoll.]))
+
+BUILD_EPOLL=no
+if test "x$enable_epoll" != "xno"; then
+ AC_CHECK_HEADERS([sys/epoll.h],
+ [BUILD_EPOLL=yes],
+ [BUILD_EPOLL=no])
+fi
+# end EPOLL section
+
+
+# IBVERBS section
+AC_ARG_ENABLE([ibverbs],
+ AC_HELP_STRING([--disable-ibverbs],
+ [Do not build the ibverbs transport]))
+
+if test "x$enable_ibverbs" != "xno"; then
+ AC_CHECK_LIB([ibverbs],
+ [ibv_get_device_list],
+ [HAVE_LIBIBVERBS="yes"],
+ [HAVE_LIBIBVERBS="no"])
+fi
+
+if test "x$enable_ibverbs" = "xyes" -a "x$HAVE_LIBIBVERBS" = "xno"; then
+ echo "ibverbs requested but not found."
+ exit 1
+fi
+
+
+BUILD_IBVERBS=no
+if test "x$enable_ibverbs" != "xno" -a "x$HAVE_LIBIBVERBS" = "xyes"; then
+ IBVERBS_SUBDIR=ib-verbs
+ BUILD_IBVERBS=yes
+fi
+
+AC_SUBST(IBVERBS_SUBDIR)
+# end IBVERBS section
+
+
+# Berkely-DB section
+# storage/bdb requires Berkeley-DB version 4.6.21 or higher
+_GLFS_DB_VERSION_MAJOR=4
+_GLFS_DB_VERSION_MINOR=6
+_GLFS_DB_VERSION_PATCH=21
+AC_ARG_ENABLE([db],
+ AC_HELP_STRING([--disable-bdb],
+ [Do not build the Berkeley-DB translator]))
+
+if test "x$enable_bdb" != "xno"; then
+ AC_CHECK_HEADERS([db.h],
+ [HAVE_BDB="yes"],
+ [HAVE_BDB="no"])
+ if test "x$HAVE_BDB" = "xyes"; then
+ AC_CHECK_LIB([db],
+ [db_create],
+ [HAVE_BDB="yes"],
+ [HAVE_BDB="no"])
+ fi
+
+ if test "x$HAVE_BDB" = "xyes"; then
+ AC_TRY_COMPILE([#include <db.h>],
+ #if (DB_VERSION_MAJOR < $_GLFS_DB_VERSION_MAJOR) ||\
+ (DB_VERSION_MAJOR == $_GLFS_DB_VERSION_MAJOR && \
+ DB_VERSION_MINOR < $_GLFS_DB_VERSION_MINOR) || \
+ (DB_VERSION_MAJOR == $_GLFS_DB_VERSION_MAJOR && \
+ DB_VERSION_MINOR == $_GLFS_DB_VERSION_MINOR && \
+ DB_VERSION_PATCH < $_GLFS_DB_VERSION_PATCH)
+ #error "bdb older than required"
+ #endif
+ ,
+ [HAVE_BDB_VERSION="yes"],
+ [HAVE_BDB_VERSION="no"])
+
+ dnl check for DB->stat having 4 arguments.
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <db.h>]],
+ [[DB *bdb; bdb->stat (NULL, NULL, NULL, 0);]])],
+ [HAVE_BDB_VERSION=yes], [HAVE_BDB_VERSION=no])
+
+ dnl check for DBC->c_get presence.
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <db.h>]],
+ [[DBC *cursor; cursor->get (NULL, NULL, NULL, 0);]])],
+ [HAVE_BDB_CURSOR_GET=yes], [HAVE_BDB_CURSOR_GET=no])
+
+ fi
+fi
+
+if test "x$HAVE_BDB_CURSOR_GET" = "xyes" -a "x$HAVE_BDB_VERSION" = "xyes"; then
+ AC_DEFINE(HAVE_BDB_CURSOR_GET, 1, [Berkeley-DB version has cursor->get()])
+fi
+
+if test "x$enable_bdb" = "xyes" -a "x$HAVE_BDB" = "xno" -a "x$HAVE_BDB_VERSION" = "xno" -a "x$HAVE_BDB_CURSOR_GET" = "xno"; then
+ echo "Berkeley-DB requested but not found. glusterfs bdb feature requires db version 4.6.21 or higher"
+ exit 1
+fi
+
+
+BUILD_BDB=no
+if test "x$enable_bdb" != "xno" -a "x$HAVE_BDB" = "xyes"; then
+ BDB_SUBDIR=bdb
+ BUILD_BDB=yes
+fi
+
+
+
+AC_SUBST(BDB_SUBDIR)
+# end BDB section
+
+dnl FreeBSD > 5 has execinfo as a Ported library for giving a workaround
+dnl solution to GCC backtrace functionality
+
+AC_CHECK_HEADERS([execinfo.h], [have_backtrace=yes],
+ AC_CHECK_LIB([execinfo], [backtrace], [have_backtrace=yes]))
+dnl AC_MSG_ERROR([libexecinfo not found libexecinfo required.])))
+
+if test "x${have_backtrace}" = "xyes"; then
+ AC_DEFINE(HAVE_BACKTRACE, 1, [define if found backtrace])
+fi
+AC_SUBST(HAVE_BACKTRACE)
+
+dnl glusterfs prints memory usage to stderr by sending it SIGUSR1
+AC_CHECK_FUNC([malloc_stats], [have_malloc_stats=yes])
+if test "x${have_malloc_stats}" = "xyes"; then
+ AC_DEFINE(HAVE_MALLOC_STATS, 1, [define if found malloc_stats])
+fi
+AC_SUBST(HAVE_MALLOC_STATS)
+
+dnl Linux, Solaris, Cygwin
+AC_CHECK_MEMBERS([struct stat.st_atim.tv_nsec])
+dnl FreeBSD, NetBSD
+AC_CHECK_MEMBERS([struct stat.st_atimespec.tv_nsec])
+
+dnl Check for argp
+AC_CHECK_HEADER([argp.h], AC_DEFINE(HAVE_ARGP, 1, [have argp]))
+AC_CONFIG_SUBDIRS(argp-standalone)
+BUILD_ARGP_STANDALONE=no
+if test "x${ac_cv_header_argp_h}" = "xno"; then
+ BUILD_ARGP_STANDALONE=yes
+ ARGP_STANDALONE_CPPFLAGS='-I${top_srcdir}/argp-standalone'
+ ARGP_STANDALONE_LDADD='${top_builddir}/argp-standalone/libargp.a'
+fi
+
+AC_SUBST(ARGP_STANDALONE_CPPFLAGS)
+AC_SUBST(ARGP_STANDALONE_LDADD)
+
+AC_CHECK_HEADER([malloc.h], AC_DEFINE(HAVE_MALLOC_H, 1, [have malloc.h]))
+
+AC_CHECK_FUNC([llistxattr], [have_llistxattr=yes])
+if test "x${have_llistxattr}" = "xyes"; then
+ AC_DEFINE(HAVE_LLISTXATTR, 1, [define if llistxattr exists])
+fi
+
+AC_CHECK_FUNC([fdatasync], [have_fdatasync=yes])
+if test "x${have_fdatasync}" = "xyes"; then
+ AC_DEFINE(HAVE_FDATASYNC, 1, [define if fdatasync exists])
+fi
+
+GF_HOST_OS=""
+GF_LDFLAGS="-rdynamic"
+
+if test "x$HAVE_LIBGLUSTERFSCLIENT" = "xyes"; then
+ GF_BOOSTER_SUBDIR="booster"
+fi
+
+GF_FUSE_LDADD="-lfuse"
+case $host_os in
+ linux*)
+ dnl GF_LINUX_HOST_OS=1
+ GF_HOST_OS="GF_LINUX_HOST_OS"
+ GF_CFLAGS="${ARGP_STANDALONE_CPPFLAGS}"
+ GF_GLUSTERFS_CFLAGS="${GF_CFLAGS}"
+ GF_LDADD="${ARGP_STANDALONE_LDADD}"
+ ;;
+ solaris*)
+ GF_HOST_OS="GF_SOLARIS_HOST_OS"
+ GF_CFLAGS="${ARGP_STANDALONE_CPPFLAGS} -D_REENTRANT"
+ GF_LDFLAGS=""
+ GF_GLUSTERFS_CFLAGS="${GF_CFLAGS}"
+ GF_LDADD="${ARGP_STANDALONE_LDADD}"
+ GF_GLUSTERFS_LDFLAGS="-lnsl -lresolv -lsocket"
+ GF_BOOSTER_SUBDIR=""
+ ;;
+ *bsd*)
+ GF_HOST_OS="GF_BSD_HOST_OS"
+ GF_CFLAGS="${ARGP_STANDALONE_CPPFLAGS}"
+ GF_GLUSTERFS_CFLAGS="${GF_CFLAGS}"
+ GF_LDADD="${ARGP_STANDALONE_LDADD}"
+ if test "x$ac_cv_header_execinfo_h" = "xyes"; then
+ GF_GLUSTERFS_LDFLAGS="-lexecinfo"
+ fi
+ GF_FUSE_LDADD="-liconv -lfuse"
+ BUILD_MOD_GLUSTERFS=no
+ MOD_GLUSTERFS_SUBDIR=""
+ BUILD_LIBGLUSTERFSCLIENT=no
+ LIBGLUSTERFSCLIENT_SUBDIR=""
+ GF_BOOSTER_SUBDIR=""
+ ;;
+ darwin*)
+ GF_HOST_OS="GF_DARWIN_HOST_OS"
+ LIBTOOL=glibtool
+ GF_CFLAGS="${ARGP_STANDALONE_CPPFLAGS} -D__DARWIN_64_BIT_INO_T -bundle -undefined suppress -flat_namespace"
+ GF_GLUSTERFS_CFLAGS="${ARGP_STANDALONE_CPPFLAGS} -D__DARWIN_64_BIT_INO_T -undefined suppress -flat_namespace"
+ GF_LDADD="${ARGP_STANDALONE_LDADD}"
+ GF_FUSE_LDADD="-liconv -lfuse_ino64"
+ BUILD_MOD_GLUSTERFS=no
+ MOD_GLUSTERFS_SUBDIR=""
+ BUILD_LIBGLUSTERFSCLIENT=no
+ LIBGLUSTERFSCLIENT_SUBDIR=""
+ GF_BOOSTER_SUBDIR=""
+ ;;
+esac
+
+AC_SUBST(GF_HOST_OS)
+AC_SUBST(GF_GLUSTERFS_LDFLAGS)
+AC_SUBST(GF_GLUSTERFS_CFLAGS)
+AC_SUBST(GF_CFLAGS)
+AC_SUBST(GF_LDFLAGS)
+AC_SUBST(GF_LDADD)
+AC_SUBST(GF_FUSE_LDADD)
+AC_SUBST(GF_BOOSTER_SUBDIR)
+
+AM_CONDITIONAL([GF_DARWIN_HOST_OS], test "${GF_HOST_OS}" = "GF_DARWIN_HOST_OS")
+
+AC_OUTPUT
+
+exec >&2
+
+echo
+echo "GlusterFS configure summary"
+echo "==========================="
+echo "FUSE client : $BUILD_FUSE_CLIENT"
+echo "Infiniband verbs : $BUILD_IBVERBS"
+echo "epoll IO multiplex : $BUILD_EPOLL"
+echo "Berkeley-DB : $BUILD_BDB"
+echo "libglusterfsclient : $BUILD_LIBGLUSTERFSCLIENT"
+echo "mod_glusterfs : $BUILD_MOD_GLUSTERFS ($MOD_GLUSTERFS_HTTPD_VERSION)"
+echo "argp-standalone : $BUILD_ARGP_STANDALONE"
+echo
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 000000000..83f88320c
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,11 @@
+EXTRA_DIST = glusterfs.vol.sample glusterfsd.vol.sample glusterfs.8 \
+ porting_guide.txt authentication.txt coding-standard.pdf get_put_api_using_xattr.txt \
+ translator-options.txt mac-related-xattrs.txt replicate.pdf
+SUBDIRS = examples hacker-guide user-guide
+
+voldir = $(sysconfdir)/glusterfs
+vol_DATA = glusterfs.vol.sample glusterfsd.vol.sample
+
+man8_MANS = glusterfs.8
+
+CLEANFILES =
diff --git a/doc/authentication.txt b/doc/authentication.txt
new file mode 100644
index 000000000..70aafd933
--- /dev/null
+++ b/doc/authentication.txt
@@ -0,0 +1,112 @@
+
+* Authentication is provided by two modules addr and login. Login based authentication uses username/password from client for authentication. Each module returns either ACCEPT, REJCET or DONT_CARE. DONT_CARE is returned if the input authentication information to the module is not concerned to its working. The theory behind authentication is that "none of the auth modules should return REJECT and atleast one of them should return ACCEPT"
+
+* Currently all the authentication related information is passed un-encrypted over the network from client to server.
+
+----------------------------------------------------------------------------------------------------
+* options provided in protocol/client:
+ * for username/password based authentication:
+ option username <username>
+ option password <password>
+ * client can have only one set of username/password
+ * for addr based authentication:
+ * no options required in protocol/client. Client has to bind to privileged port (port < 1024 ) which means the process in which protocol/client is loaded has to be run as root.
+
+----------------------------------------------------------------------------------------------------
+* options provided in protocol/server:
+ * for username/password based authentication:
+ option auth.login.<brick>.allow [comma seperated list of usernames using which clients can connect to volume <brick>]
+ option auth.login.<username>.password <password> #specify password <password> for username <username>
+ * for addr based authentication:
+ option auth.addr.<brick>.allow [comma seperated list of ip-addresses/unix-paths from which clients are allowed to connect to volume <brick>]
+ option auth.addr.<brick>.reject [comma seperated list of ip-addresses/unix-paths from which clients are not allowed to connect to volume <brick>]
+ * negation operator '!' is used to invert the sense of matching.
+ Eg., option auth.addr.brick.allow !a.b.c.d #do not allow client from a.b.c.d to connect to volume brick
+ option auth.addr.brick.reject !w.x.y.z #allow client from w.x.y.z to connect to volume brick
+ * wildcard '*' can be used to match any ip-address/unix-path
+
+----------------------------------------------------------------------------------------------------
+
+* Usecases:
+
+* username/password based authentication only
+ protocol/client:
+ option username foo
+ option password foo-password
+ option remote-subvolume foo-brick
+
+ protocol/server:
+ option auth.login.foo-brick.allow foo,who #,other users allowed to connect to foo-brick
+ option auth.login.foo.password foo-password
+ option auth.login.who.password who-password
+
+ * in protocol/server, dont specify ip from which client is connecting in auth.addr.foo-brick.reject list
+
+****************************************************************************************************
+
+* ip based authentication only
+ protocol/client:
+ option remote-subvolume foo-brick
+ * Client is connecting from a.b.c.d
+
+ protocol/server:
+ option auth.addr.foo-brick.allow a.b.c.d,e.f.g.h,i.j.k.l #, other ip addresses from which clients are allowed to connect to foo-brick
+
+****************************************************************************************************
+* ip and username/password based authentication
+ * allow only "user foo from a.b.c.d"
+ protocol/client:
+ option username foo
+ option password foo-password
+ option remote-subvolume foo-brick
+
+ protocol/server:
+ option auth.login.foo-brick.allow foo
+ option auth.login.foo.password foo-password
+ option auth.addr.foo-brick.reject !a.b.c.d
+
+ * allow only "user foo" from a.b.c.d i.e., only user foo is allowed from a.b.c.d, but anyone is allowed from ip addresses other than a.b.c.d
+ protocol/client:
+ option username foo
+ option password foo-password
+ option remote-subvolume foo-brick
+
+ protocol/server:
+ option auth.login.foo-brick.allow foo
+ option auth.login.foo.password foo-password
+ option auth.addr.foo-brick.allow !a.b.c.d
+
+ * reject only "user shoo from a.b.c.d"
+ protcol/client:
+ option remote-subvolume shoo-brick
+
+ protocol/server:
+ # observe that no "option auth.login.shoo-brick.allow shoo" given
+ # Also other users from a.b.c.d have to be explicitly allowed using auth.login.shoo-brick.allow ...
+ option auth.addr.shoo-brick.allow !a.b.c.d
+
+ * reject only "user shoo" from a.b.c.d i.e., user shoo from a.b.c.d has to be rejected.
+ * same as reject only "user shoo from a.b.c.d" above, but rules have to be added whether to allow ip addresses (and users from those ips) other than a.b.c.d
+
+****************************************************************************************************
+
+* ip or username/password based authentication
+
+ * allow user foo or clients from a.b.c.d
+ protocol/client:
+ option remote-subvolume foo-brick
+
+ protocol/server:
+ option auth.login.foo-brick.allow foo
+ option auth.login.foo.password foo-password
+ option auth.addr.foo-brick.allow a.b.c.d
+
+ * reject user shoo or clients from a.b.c.d
+ protocol/client:
+ option remote-subvolume shoo-brick
+
+ protocol/server:
+ option auth.login.shoo-brick.allow <usernames other than shoo>
+ #for each username mentioned in the above <usernames other than shoo> list, specify password as below
+ option auth.login.<username other than shoo>.password password
+ option auth.addr.shoo-brick.reject a.b.c.d
diff --git a/doc/booster.txt b/doc/booster.txt
new file mode 100644
index 000000000..684ac8965
--- /dev/null
+++ b/doc/booster.txt
@@ -0,0 +1,54 @@
+Introduction
+============
+* booster is a LD_PRELOADable library which boosts read/write performance by bypassing fuse for
+ read() and write() calls.
+
+Requirements
+============
+* fetch volfile from glusterfs.
+* identify whether multiple files are from the same mount point. If so, use only one context.
+
+Design
+======
+* for a getxattr, along with other attributes, fuse returns following attributes.
+ * contents of client volume-file.
+ * mount point.
+
+* LD_PRELOADed booster.so maintains an hash table storing mount-points and libglusterfsclient handles
+ so that handles are reused for files from same mount point.
+
+* it also maintains a fdtable. fdtable maps the fd (integer) returned to application to fd (pointer to fd struct)
+ used by libglusterfsclient. application is returned the same fd as the one returned from libc apis.
+
+* During fork, these tables are overwritten to enable creation of fresh glusterfs context in child.
+
+Working
+=======
+* application willing to use booster LD_PRELOADs booster.so which is a wrapper library implementing
+ open, read and write.
+
+* application should specify the path to logfile through the environment variable GLFS_BOOSTER_LOGFILE. If
+ not specified, logging is done to /dev/stderr.
+
+* open call does,
+ * real_open on the file.
+ * fgetxattr(fd).
+ * store the volume-file content got in the dictionary to a temparory file.
+ * look in the hashtable for the mount-point, if already present get the libglusterfsclient handle from the
+ hashtable. Otherwise get a new handle from libglusterfsclient (be careful about mount point not present in
+ the hashtable and multiple glusterfs_inits running simultaneously for the same mount-point there by using
+ multiple handles for the same mount point).
+ * real_close (fd).
+ * delete temporary volume-volfile.
+ * glusterfs_open (handle, path, mode).
+ * store the fd returned by glusterfs_open in the fdtable at the same index as the fd returned by real_open.
+ * return the index as fd.
+
+* read/write calls do,
+ * get the libglusterfsclient fd from fdtable.
+ * if found use glusterfs_read/glusterfs_write, else use real_read/real_write.
+
+* close call does,
+ * remove the fd from the fdtable.
+
+* other calls use real_calls.
diff --git a/doc/coding-standard.pdf b/doc/coding-standard.pdf
new file mode 100644
index 000000000..bc9cb5620
--- /dev/null
+++ b/doc/coding-standard.pdf
Binary files differ
diff --git a/doc/coding-standard.tex b/doc/coding-standard.tex
new file mode 100644
index 000000000..ed9d920ec
--- /dev/null
+++ b/doc/coding-standard.tex
@@ -0,0 +1,361 @@
+\documentclass{article}[12pt]
+\usepackage{color}
+
+\begin{document}
+
+
+\hrule
+\begin{center}\textbf{\Large{GlusterFS Coding Standards}}\end{center}
+\begin{center}\textbf{\large{\textcolor{red}{Z} Research}}\end{center}
+\begin{center}{July 14, 2008}\end{center}
+\hrule
+
+\vspace{8ex}
+
+\section*{$\bullet$ Structure definitions should have a comment per member}
+
+Every member in a structure definition must have a comment about its
+purpose. The comment should be descriptive without being overly verbose.
+
+\vspace{2ex}
+\textsl{Bad}:
+
+\begin{verbatim}
+ gf_lock_t lock; /* lock */
+\end{verbatim}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ DBTYPE access_mode; /* access mode for accessing
+ * the databases, can be
+ * DB_HASH, DB_BTREE
+ * (option access-mode <mode>)
+ */
+\end{verbatim}
+
+\section*{$\bullet$ Declare all variables at the beginning of the function}
+All local variables in a function must be declared immediately after the
+opening brace. This makes it easy to keep track of memory that needs to be freed
+during exit. It also helps debugging, since gdb cannot handle variables
+declared inside loops or other such blocks.
+
+\section*{$\bullet$ Always initialize local variables}
+Every local variable should be initialized to a sensible default value
+at the point of its declaration. All pointers should be initialized to NULL,
+and all integers should be zero or (if it makes sense) an error value.
+
+\vspace{2ex}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ int ret = 0;
+ char *databuf = NULL;
+ int _fd = -1;
+\end{verbatim}
+
+\section*{$\bullet$ Initialization should always be done with a constant value}
+Never use a non-constant expression as the initialization value for a variable.
+
+\vspace{2ex}
+
+\textsl{Bad}:
+
+\begin{verbatim}
+ pid_t pid = frame->root->pid;
+ char *databuf = malloc (1024);
+\end{verbatim}
+
+\section*{$\bullet$ Validate all arguments to a function}
+All pointer arguments to a function must be checked for \texttt{NULL}.
+A macro named \texttt{VALIDATE} (in \texttt{common-utils.h})
+takes one argument, and if it is \texttt{NULL}, writes a log message and
+jumps to a label called \texttt{err} after setting op\_ret and op\_errno
+appropriately. It is recommended to use this template.
+
+\vspace{2ex}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ VALIDATE(frame);
+ VALIDATE(this);
+ VALIDATE(inode);
+\end{verbatim}
+
+\section*{$\bullet$ Never rely on precedence of operators}
+Never write code that relies on the precedence of operators to execute
+correctly. Such code can be hard to read and someone else might not
+know the precedence of operators as accurately as you do.
+\vspace{2ex}
+
+\textsl{Bad}:
+
+\begin{verbatim}
+ if (op_ret == -1 && errno != ENOENT)
+\end{verbatim}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ if ((op_ret == -1) && (errno != ENOENT))
+\end{verbatim}
+
+\section*{$\bullet$ Use exactly matching types}
+Use a variable of the exact type declared in the manual to hold the
+return value of a function. Do not use an ``equivalent'' type.
+
+\vspace{2ex}
+
+\textsl{Bad}:
+
+\begin{verbatim}
+ int len = strlen (path);
+\end{verbatim}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ size_t len = strlen (path);
+\end{verbatim}
+
+\section*{$\bullet$ Never write code such as \texttt{foo->bar->baz}; check every pointer}
+Do not write code that blindly follows a chain of pointer
+references. Any pointer in the chain may be \texttt{NULL} and thus
+cause a crash. Verify that each pointer is non-null before following
+it.
+
+\section*{$\bullet$ Check return value of all functions and system calls}
+The return value of all system calls and API functions must be checked
+for success or failure.
+
+\vspace{2ex}
+\textsl{Bad}:
+
+\begin{verbatim}
+ close (fd);
+\end{verbatim}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ op_ret = close (_fd);
+ if (op_ret == -1) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "close on file %s failed (%s)", real_path,
+ strerror (errno));
+ op_errno = errno;
+ goto out;
+ }
+\end{verbatim}
+
+
+\section*{$\bullet$ Gracefully handle failure of malloc}
+GlusterFS should never crash or exit due to lack of memory. If a
+memory allocation fails, the call should be unwound and an error
+returned to the user.
+
+\section*{$\bullet$ Use result args and reserve the return value to indicate success or failure}
+The return value of every functions must indicate success or failure (unless
+it is impossible for the function to fail --- e.g., boolean functions). If
+the function needs to return additional data, it must be returned using a
+result (pointer) argument.
+
+\vspace{2ex}
+\textsl{Bad}:
+
+\begin{verbatim}
+ int32_t dict_get_int32 (dict_t *this, char *key);
+\end{verbatim}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ int dict_get_int32 (dict_t *this, char *key, int32_t *val);
+\end{verbatim}
+
+\section*{$\bullet$ Always use the `n' versions of string functions}
+Unless impossible, use the length-limited versions of the string functions.
+
+\vspace{2ex}
+\textsl{Bad}:
+
+\begin{verbatim}
+ strcpy (entry_path, real_path);
+\end{verbatim}
+
+\textsl{Good}:
+
+\begin{verbatim}
+ strncpy (entry_path, real_path, entry_path_len);
+\end{verbatim}
+
+\section*{$\bullet$ No dead or commented code}
+There must be no dead code (code to which control can never be passed) or
+commented out code in the codebase.
+
+\section*{$\bullet$ Only one unwind and return per function}
+There must be only one exit out of a function. \texttt{UNWIND} and return
+should happen at only point in the function.
+
+\section*{$\bullet$ Keep functions small}
+Try to keep functions small. Two to three screenfulls (80 lines per screen) is
+considered a reasonable limit. If a function is very long, try splitting it
+into many little helper functions.
+
+\vspace{2ex}
+\textsl{Example for a helper function}:
+\begin{verbatim}
+ static int
+ same_owner (posix_lock_t *l1, posix_lock_t *l2)
+ {
+ return ((l1->client_pid == l2->client_pid) &&
+ (l1->transport == l2->transport));
+ }
+\end{verbatim}
+
+\section*{Style issues}
+
+\subsection*{Brace placement}
+Use K\&R/Linux style of brace placement for blocks.
+
+\textsl{Example}:
+\begin{verbatim}
+ int some_function (...)
+ {
+ if (...) {
+ /* ... */
+ } else if (...) {
+ /* ... */
+ } else {
+ /* ... */
+ }
+
+ do {
+ /* ... */
+ } while (cond);
+ }
+\end{verbatim}
+
+\subsection*{Indentation}
+Use \textbf{eight} spaces for indenting blocks. Ensure that your
+file contains only spaces and not tab characters. You can do this
+in Emacs by selecting the entire file (\texttt{C-x h}) and
+running \texttt{M-x untabify}.
+
+To make Emacs indent lines automatically by eight spaces, add this
+line to your \texttt{.emacs}:
+
+\begin{verbatim}
+ (add-hook 'c-mode-hook (lambda () (c-set-style "linux")))
+\end{verbatim}
+
+\subsection*{Comments}
+Write a comment before every function describing its purpose (one-line),
+its arguments, and its return value. Mention whether it is an internal
+function or an exported function.
+
+Write a comment before every structure describing its purpose, and
+write comments about each of its members.
+
+Follow the style shown below for comments, since such comments
+can then be automatically extracted by doxygen to generate
+documentation.
+
+\textsl{Example}:
+\begin{verbatim}
+/**
+ * hash_name -hash function for filenames
+ * @par: parent inode number
+ * @name: basename of inode
+ * @mod: number of buckets in the hashtable
+ *
+ * @return: success: bucket number
+ * failure: -1
+ *
+ * Not for external use.
+ */
+\end{verbatim}
+
+\subsection*{Indicating critical sections}
+To clearly show regions of code which execute with locks held, use
+the following format:
+
+\begin{verbatim}
+ pthread_mutex_lock (&mutex);
+ {
+ /* code */
+ }
+ pthread_mutex_unlock (&mutex);
+\end{verbatim}
+
+\section*{A skeleton fop function}
+This is the recommended template for any fop. In the beginning come
+the initializations. After that, the `success' control flow should be
+linear. Any error conditions should cause a \texttt{goto} to a single
+point, \texttt{out}. At that point, the code should detect the error
+that has occured and do appropriate cleanup.
+
+\begin{verbatim}
+int32_t
+sample_fop (call_frame_t *frame,
+ xlator_t *this,
+ ...)
+{
+ char * var1 = NULL;
+ int32_t op_ret = -1;
+ int32_t op_errno = 0;
+ DIR * dir = NULL;
+ struct posix_fd * pfd = NULL;
+
+ VALIDATE_OR_GOTO (frame, out);
+ VALIDATE_OR_GOTO (this, out);
+
+ /* other validations */
+
+ dir = opendir (...);
+
+ if (dir == NULL) {
+ op_errno = errno;
+ gf_log (this->name, GF_LOG_ERROR,
+ "opendir failed on %s (%s)", loc->path,
+ strerror (op_errno));
+ goto out;
+ }
+
+ /* another system call */
+ if (...) {
+ op_errno = ENOMEM;
+ gf_log (this->name, GF_LOG_ERROR,
+ "out of memory :(");
+ goto out;
+ }
+
+ /* ... */
+
+ out:
+ if (op_ret == -1) {
+
+ /* check for all the cleanup that needs to be
+ done */
+
+ if (dir) {
+ closedir (dir);
+ dir = NULL;
+ }
+
+ if (pfd) {
+ if (pfd->path)
+ FREE (pfd->path);
+ FREE (pfd);
+ pfd = NULL;
+ }
+ }
+
+ STACK_UNWIND (frame, op_ret, op_errno, fd);
+ return 0;
+}
+\end{verbatim}
+
+\end{document}
diff --git a/doc/errno.list.bsd.txt b/doc/errno.list.bsd.txt
new file mode 100644
index 000000000..350af25e4
--- /dev/null
+++ b/doc/errno.list.bsd.txt
@@ -0,0 +1,376 @@
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)errno.h 8.5 (Berkeley) 1/21/94
+ * $FreeBSD: src/sys/sys/errno.h,v 1.28 2005/04/02 12:33:28 das Exp $
+ */
+
+#ifndef _SYS_ERRNO_H_
+#define _SYS_ERRNO_H_
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+__BEGIN_DECLS
+int * __error(void);
+__END_DECLS
+#define errno (* __error())
+#endif
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* Input/output error */
+#define ENXIO 6 /* Device not configured */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file descriptor */
+#define ECHILD 10 /* No child processes */
+#define EDEADLK 11 /* Resource deadlock avoided */
+ /* 11 was EAGAIN */
+#define ENOMEM 12 /* Cannot allocate memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#ifndef _POSIX_SOURCE
+#define ENOTBLK 15 /* Block device required */
+#endif
+#define EBUSY 16 /* Device busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* Operation not supported by device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* Too many open files in system */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+#ifndef _POSIX_SOURCE
+#define ETXTBSY 26 /* Text file busy */
+#endif
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only filesystem */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+
+/* math software */
+#define EDOM 33 /* Numerical argument out of domain */
+#define ERANGE 34 /* Result too large */
+
+/* non-blocking and interrupt i/o */
+#define EAGAIN 35 /* Resource temporarily unavailable */
+#ifndef _POSIX_SOURCE
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define EINPROGRESS 36 /* Operation now in progress */
+#define EALREADY 37 /* Operation already in progress */
+
+/* ipc/network software -- argument errors */
+#define ENOTSOCK 38 /* Socket operation on non-socket */
+#define EDESTADDRREQ 39 /* Destination address required */
+#define EMSGSIZE 40 /* Message too long */
+#define EPROTOTYPE 41 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 42 /* Protocol not available */
+#define EPROTONOSUPPORT 43 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
+#define EOPNOTSUPP 45 /* Operation not supported */
+#define ENOTSUP EOPNOTSUPP /* Operation not supported */
+#define EPFNOSUPPORT 46 /* Protocol family not supported */
+#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
+#define EADDRINUSE 48 /* Address already in use */
+#define EADDRNOTAVAIL 49 /* Can't assign requested address */
+
+/* ipc/network software -- operational errors */
+#define ENETDOWN 50 /* Network is down */
+#define ENETUNREACH 51 /* Network is unreachable */
+#define ENETRESET 52 /* Network dropped connection on reset */
+#define ECONNABORTED 53 /* Software caused connection abort */
+#define ECONNRESET 54 /* Connection reset by peer */
+#define ENOBUFS 55 /* No buffer space available */
+#define EISCONN 56 /* Socket is already connected */
+#define ENOTCONN 57 /* Socket is not connected */
+#define ESHUTDOWN 58 /* Can't send after socket shutdown */
+#define ETOOMANYREFS 59 /* Too many references: can't splice */
+#define ETIMEDOUT 60 /* Operation timed out */
+#define ECONNREFUSED 61 /* Connection refused */
+
+#define ELOOP 62 /* Too many levels of symbolic links */
+#endif /* _POSIX_SOURCE */
+#define ENAMETOOLONG 63 /* File name too long */
+
+/* should be rearranged */
+#ifndef _POSIX_SOURCE
+#define EHOSTDOWN 64 /* Host is down */
+#define EHOSTUNREACH 65 /* No route to host */
+#endif /* _POSIX_SOURCE */
+#define ENOTEMPTY 66 /* Directory not empty */
+
+/* quotas & mush */
+#ifndef _POSIX_SOURCE
+#define EPROCLIM 67 /* Too many processes */
+#define EUSERS 68 /* Too many users */
+#define EDQUOT 69 /* Disc quota exceeded */
+
+/* Network File System */
+#define ESTALE 70 /* Stale NFS file handle */
+#define EREMOTE 71 /* Too many levels of remote in path */
+#define EBADRPC 72 /* RPC struct is bad */
+#define ERPCMISMATCH 73 /* RPC version wrong */
+#define EPROGUNAVAIL 74 /* RPC prog. not avail */
+#define EPROGMISMATCH 75 /* Program version wrong */
+#define EPROCUNAVAIL 76 /* Bad procedure for program */
+#endif /* _POSIX_SOURCE */
+
+#define ENOLCK 77 /* No locks available */
+#define ENOSYS 78 /* Function not implemented */
+
+#ifndef _POSIX_SOURCE
+#define EFTYPE 79 /* Inappropriate file type or format */
+#define EAUTH 80 /* Authentication error */
+#define ENEEDAUTH 81 /* Need authenticator */
+#define EIDRM 82 /* Identifier removed */
+#define ENOMSG 83 /* No message of desired type */
+#define EOVERFLOW 84 /* Value too large to be stored in data type */
+#define ECANCELED 85 /* Operation canceled */
+#define EILSEQ 86 /* Illegal byte sequence */
+#define ENOATTR 87 /* Attribute not found */
+
+#define EDOOFUS 88 /* Programming error */
+#endif /* _POSIX_SOURCE */
+
+#define EBADMSG 89 /* Bad message */
+#define EMULTIHOP 90 /* Multihop attempted */
+#define ENOLINK 91 /* Link has been severed */
+#define EPROTO 92 /* Protocol error */
+
+#ifndef _POSIX_SOURCE
+#define ELAST 92 /* Must be equal largest errno */
+#endif /* _POSIX_SOURCE */
+
+#ifdef _KERNEL
+/* pseudo-errors returned inside kernel to modify return to process */
+#define ERESTART (-1) /* restart syscall */
+#define EJUSTRETURN (-2) /* don't modify regs, just return */
+#define ENOIOCTL (-3) /* ioctl not handled by this layer */
+#define EDIRIOCTL (-4) /* do direct ioctl in GEOM */
+#endif
+
+#endif
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)errno.h 8.5 (Berkeley) 1/21/94
+ * $FreeBSD: src/sys/sys/errno.h,v 1.28 2005/04/02 12:33:28 das Exp $
+ */
+
+#ifndef _SYS_ERRNO_H_
+#define _SYS_ERRNO_H_
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+__BEGIN_DECLS
+int * __error(void);
+__END_DECLS
+#define errno (* __error())
+#endif
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* Input/output error */
+#define ENXIO 6 /* Device not configured */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file descriptor */
+#define ECHILD 10 /* No child processes */
+#define EDEADLK 11 /* Resource deadlock avoided */
+ /* 11 was EAGAIN */
+#define ENOMEM 12 /* Cannot allocate memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#ifndef _POSIX_SOURCE
+#define ENOTBLK 15 /* Block device required */
+#endif
+#define EBUSY 16 /* Device busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* Operation not supported by device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* Too many open files in system */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+#ifndef _POSIX_SOURCE
+#define ETXTBSY 26 /* Text file busy */
+#endif
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only filesystem */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+
+/* math software */
+#define EDOM 33 /* Numerical argument out of domain */
+#define ERANGE 34 /* Result too large */
+
+/* non-blocking and interrupt i/o */
+#define EAGAIN 35 /* Resource temporarily unavailable */
+#ifndef _POSIX_SOURCE
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define EINPROGRESS 36 /* Operation now in progress */
+#define EALREADY 37 /* Operation already in progress */
+
+/* ipc/network software -- argument errors */
+#define ENOTSOCK 38 /* Socket operation on non-socket */
+#define EDESTADDRREQ 39 /* Destination address required */
+#define EMSGSIZE 40 /* Message too long */
+#define EPROTOTYPE 41 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 42 /* Protocol not available */
+#define EPROTONOSUPPORT 43 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
+#define EOPNOTSUPP 45 /* Operation not supported */
+#define ENOTSUP EOPNOTSUPP /* Operation not supported */
+#define EPFNOSUPPORT 46 /* Protocol family not supported */
+#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
+#define EADDRINUSE 48 /* Address already in use */
+#define EADDRNOTAVAIL 49 /* Can't assign requested address */
+
+/* ipc/network software -- operational errors */
+#define ENETDOWN 50 /* Network is down */
+#define ENETUNREACH 51 /* Network is unreachable */
+#define ENETRESET 52 /* Network dropped connection on reset */
+#define ECONNABORTED 53 /* Software caused connection abort */
+#define ECONNRESET 54 /* Connection reset by peer */
+#define ENOBUFS 55 /* No buffer space available */
+#define EISCONN 56 /* Socket is already connected */
+#define ENOTCONN 57 /* Socket is not connected */
+#define ESHUTDOWN 58 /* Can't send after socket shutdown */
+#define ETOOMANYREFS 59 /* Too many references: can't splice */
+#define ETIMEDOUT 60 /* Operation timed out */
+#define ECONNREFUSED 61 /* Connection refused */
+
+#define ELOOP 62 /* Too many levels of symbolic links */
+#endif /* _POSIX_SOURCE */
+#define ENAMETOOLONG 63 /* File name too long */
+
+/* should be rearranged */
+#ifndef _POSIX_SOURCE
+#define EHOSTDOWN 64 /* Host is down */
+#define EHOSTUNREACH 65 /* No route to host */
+#endif /* _POSIX_SOURCE */
+#define ENOTEMPTY 66 /* Directory not empty */
+
+/* quotas & mush */
+#ifndef _POSIX_SOURCE
+#define EPROCLIM 67 /* Too many processes */
+#define EUSERS 68 /* Too many users */
+#define EDQUOT 69 /* Disc quota exceeded */
+
+/* Network File System */
+#define ESTALE 70 /* Stale NFS file handle */
+#define EREMOTE 71 /* Too many levels of remote in path */
+#define EBADRPC 72 /* RPC struct is bad */
+#define ERPCMISMATCH 73 /* RPC version wrong */
+#define EPROGUNAVAIL 74 /* RPC prog. not avail */
+#define EPROGMISMATCH 75 /* Program version wrong */
+#define EPROCUNAVAIL 76 /* Bad procedure for program */
+#endif /* _POSIX_SOURCE */
+
+#define ENOLCK 77 /* No locks available */
+#define ENOSYS 78 /* Function not implemented */
+
+#ifndef _POSIX_SOURCE
+#define EFTYPE 79 /* Inappropriate file type or format */
+#define EAUTH 80 /* Authentication error */
+#define ENEEDAUTH 81 /* Need authenticator */
+#define EIDRM 82 /* Identifier removed */
+#define ENOMSG 83 /* No message of desired type */
+#define EOVERFLOW 84 /* Value too large to be stored in data type */
+#define ECANCELED 85 /* Operation canceled */
+#define EILSEQ 86 /* Illegal byte sequence */
+#define ENOATTR 87 /* Attribute not found */
+
+#define EDOOFUS 88 /* Programming error */
+#endif /* _POSIX_SOURCE */
+
+#define EBADMSG 89 /* Bad message */
+#define EMULTIHOP 90 /* Multihop attempted */
+#define ENOLINK 91 /* Link has been severed */
+#define EPROTO 92 /* Protocol error */
+
+#ifndef _POSIX_SOURCE
+#define ELAST 92 /* Must be equal largest errno */
+#endif /* _POSIX_SOURCE */
+
+#ifdef _KERNEL
+/* pseudo-errors returned inside kernel to modify return to process */
+#define ERESTART (-1) /* restart syscall */
+#define EJUSTRETURN (-2) /* don't modify regs, just return */
+#define ENOIOCTL (-3) /* ioctl not handled by this layer */
+#define EDIRIOCTL (-4) /* do direct ioctl in GEOM */
+#endif
+
+#endif
diff --git a/doc/errno.list.linux.txt b/doc/errno.list.linux.txt
new file mode 100644
index 000000000..baa50792d
--- /dev/null
+++ b/doc/errno.list.linux.txt
@@ -0,0 +1,1586 @@
+#define ICONV_SUPPORTS_ERRNO 1
+#include <errno.h>
+/* Error constants. Linux specific version.
+ Copyright (C) 1996, 1997, 1998, 1999, 2005 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifdef _ERRNO_H
+
+# undef EDOM
+# undef EILSEQ
+# undef ERANGE
+# include <linux/errno.h>
+
+/* Linux has no ENOTSUP error code. */
+# define ENOTSUP EOPNOTSUPP
+
+/* Older Linux versions also had no ECANCELED error code. */
+# ifndef ECANCELED
+# define ECANCELED 125
+# endif
+
+/* Support for error codes to support robust mutexes was added later, too. */
+# ifndef EOWNERDEAD
+# define EOWNERDEAD 130
+# define ENOTRECOVERABLE 131
+# endif
+
+# ifndef __ASSEMBLER__
+/* Function to get address of global `errno' variable. */
+extern int *__errno_location (void) __THROW __attribute__ ((__const__));
+
+# if !defined _LIBC || defined _LIBC_REENTRANT
+/* When using threads, errno is a per-thread value. */
+# define errno (*__errno_location ())
+# endif
+# endif /* !__ASSEMBLER__ */
+#endif /* _ERRNO_H */
+
+#if !defined _ERRNO_H && defined __need_Emath
+/* This is ugly but the kernel header is not clean enough. We must
+ define only the values EDOM, EILSEQ and ERANGE in case __need_Emath is
+ defined. */
+# define EDOM 33 /* Math argument out of domain of function. */
+# define EILSEQ 84 /* Illegal byte sequence. */
+# define ERANGE 34 /* Math result not representable. */
+#endif /* !_ERRNO_H && __need_Emath */
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APR_ERRNO_H
+#define APR_ERRNO_H
+
+/**
+ * @file apr_errno.h
+ * @brief APR Error Codes
+ */
+
+#include "apr.h"
+
+#if APR_HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup apr_errno Error Codes
+ * @ingroup APR
+ * @{
+ */
+
+/**
+ * Type for specifying an error or status code.
+ */
+typedef int apr_status_t;
+
+/**
+ * Return a human readable string describing the specified error.
+ * @param statcode The error code the get a string for.
+ * @param buf A buffer to hold the error string.
+ * @param bufsize Size of the buffer to hold the string.
+ */
+APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
+ apr_size_t bufsize);
+
+#if defined(DOXYGEN)
+/**
+ * @def APR_FROM_OS_ERROR(os_err_type syserr)
+ * Fold a platform specific error into an apr_status_t code.
+ * @return apr_status_t
+ * @param e The platform os error code.
+ * @warning macro implementation; the syserr argument may be evaluated
+ * multiple times.
+ */
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+
+/**
+ * @def APR_TO_OS_ERROR(apr_status_t statcode)
+ * @return os_err_type
+ * Fold an apr_status_t code back to the native platform defined error.
+ * @param e The apr_status_t folded platform os error code.
+ * @warning macro implementation; the statcode argument may be evaluated
+ * multiple times. If the statcode was not created by apr_get_os_error
+ * or APR_FROM_OS_ERROR, the results are undefined.
+ */
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+/** @def apr_get_os_error()
+ * @return apr_status_t the last platform error, folded into apr_status_t, on most platforms
+ * @remark This retrieves errno, or calls a GetLastError() style function, and
+ * folds it with APR_FROM_OS_ERROR. Some platforms (such as OS2) have no
+ * such mechanism, so this call may be unsupported. Do NOT use this
+ * call for socket errors from socket, send, recv etc!
+ */
+
+/** @def apr_set_os_error(e)
+ * Reset the last platform error, unfolded from an apr_status_t, on some platforms
+ * @param e The OS error folded in a prior call to APR_FROM_OS_ERROR()
+ * @warning This is a macro implementation; the statcode argument may be evaluated
+ * multiple times. If the statcode was not created by apr_get_os_error
+ * or APR_FROM_OS_ERROR, the results are undefined. This macro sets
+ * errno, or calls a SetLastError() style function, unfolding statcode
+ * with APR_TO_OS_ERROR. Some platforms (such as OS2) have no such
+ * mechanism, so this call may be unsupported.
+ */
+
+/** @def apr_get_netos_error()
+ * Return the last socket error, folded into apr_status_t, on all platforms
+ * @remark This retrieves errno or calls a GetLastSocketError() style function,
+ * and folds it with APR_FROM_OS_ERROR.
+ */
+
+/** @def apr_set_netos_error(e)
+ * Reset the last socket error, unfolded from an apr_status_t
+ * @param e The socket error folded in a prior call to APR_FROM_OS_ERROR()
+ * @warning This is a macro implementation; the statcode argument may be evaluated
+ * multiple times. If the statcode was not created by apr_get_os_error
+ * or APR_FROM_OS_ERROR, the results are undefined. This macro sets
+ * errno, or calls a WSASetLastError() style function, unfolding
+ * socketcode with APR_TO_OS_ERROR.
+ */
+
+#endif /* defined(DOXYGEN) */
+
+/**
+ * APR_OS_START_ERROR is where the APR specific error values start.
+ */
+#define APR_OS_START_ERROR 20000
+/**
+ * APR_OS_ERRSPACE_SIZE is the maximum number of errors you can fit
+ * into one of the error/status ranges below -- except for
+ * APR_OS_START_USERERR, which see.
+ */
+#define APR_OS_ERRSPACE_SIZE 50000
+/**
+ * APR_OS_START_STATUS is where the APR specific status codes start.
+ */
+#define APR_OS_START_STATUS (APR_OS_START_ERROR + APR_OS_ERRSPACE_SIZE)
+/**
+ * APR_OS_START_USERERR are reserved for applications that use APR that
+ * layer their own error codes along with APR's. Note that the
+ * error immediately following this one is set ten times farther
+ * away than usual, so that users of apr have a lot of room in
+ * which to declare custom error codes.
+ */
+#define APR_OS_START_USERERR (APR_OS_START_STATUS + APR_OS_ERRSPACE_SIZE)
+/**
+ * APR_OS_START_USEERR is obsolete, defined for compatibility only.
+ * Use APR_OS_START_USERERR instead.
+ */
+#define APR_OS_START_USEERR APR_OS_START_USERERR
+/**
+ * APR_OS_START_CANONERR is where APR versions of errno values are defined
+ * on systems which don't have the corresponding errno.
+ */
+#define APR_OS_START_CANONERR (APR_OS_START_USERERR \
+ + (APR_OS_ERRSPACE_SIZE * 10))
+/**
+ * APR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into
+ * apr_status_t values.
+ */
+#define APR_OS_START_EAIERR (APR_OS_START_CANONERR + APR_OS_ERRSPACE_SIZE)
+/**
+ * APR_OS_START_SYSERR folds platform-specific system error values into
+ * apr_status_t values.
+ */
+#define APR_OS_START_SYSERR (APR_OS_START_EAIERR + APR_OS_ERRSPACE_SIZE)
+
+/** no error. */
+#define APR_SUCCESS 0
+
+/**
+ * @defgroup APR_Error APR Error Values
+ * <PRE>
+ * <b>APR ERROR VALUES</b>
+ * APR_ENOSTAT APR was unable to perform a stat on the file
+ * APR_ENOPOOL APR was not provided a pool with which to allocate memory
+ * APR_EBADDATE APR was given an invalid date
+ * APR_EINVALSOCK APR was given an invalid socket
+ * APR_ENOPROC APR was not given a process structure
+ * APR_ENOTIME APR was not given a time structure
+ * APR_ENODIR APR was not given a directory structure
+ * APR_ENOLOCK APR was not given a lock structure
+ * APR_ENOPOLL APR was not given a poll structure
+ * APR_ENOSOCKET APR was not given a socket
+ * APR_ENOTHREAD APR was not given a thread structure
+ * APR_ENOTHDKEY APR was not given a thread key structure
+ * APR_ENOSHMAVAIL There is no more shared memory available
+ * APR_EDSOOPEN APR was unable to open the dso object. For more
+ * information call apr_dso_error().
+ * APR_EGENERAL General failure (specific information not available)
+ * APR_EBADIP The specified IP address is invalid
+ * APR_EBADMASK The specified netmask is invalid
+ * APR_ESYMNOTFOUND Could not find the requested symbol
+ * </PRE>
+ *
+ * <PRE>
+ * <b>APR STATUS VALUES</b>
+ * APR_INCHILD Program is currently executing in the child
+ * APR_INPARENT Program is currently executing in the parent
+ * APR_DETACH The thread is detached
+ * APR_NOTDETACH The thread is not detached
+ * APR_CHILD_DONE The child has finished executing
+ * APR_CHILD_NOTDONE The child has not finished executing
+ * APR_TIMEUP The operation did not finish before the timeout
+ * APR_INCOMPLETE The operation was incomplete although some processing
+ * was performed and the results are partially valid
+ * APR_BADCH Getopt found an option not in the option string
+ * APR_BADARG Getopt found an option that is missing an argument
+ * and an argument was specified in the option string
+ * APR_EOF APR has encountered the end of the file
+ * APR_NOTFOUND APR was unable to find the socket in the poll structure
+ * APR_ANONYMOUS APR is using anonymous shared memory
+ * APR_FILEBASED APR is using a file name as the key to the shared memory
+ * APR_KEYBASED APR is using a shared key as the key to the shared memory
+ * APR_EINIT Ininitalizer value. If no option has been found, but
+ * the status variable requires a value, this should be used
+ * APR_ENOTIMPL The APR function has not been implemented on this
+ * platform, either because nobody has gotten to it yet,
+ * or the function is impossible on this platform.
+ * APR_EMISMATCH Two passwords do not match.
+ * APR_EABSOLUTE The given path was absolute.
+ * APR_ERELATIVE The given path was relative.
+ * APR_EINCOMPLETE The given path was neither relative nor absolute.
+ * APR_EABOVEROOT The given path was above the root path.
+ * APR_EBUSY The given lock was busy.
+ * APR_EPROC_UNKNOWN The given process wasn't recognized by APR
+ * </PRE>
+ * @{
+ */
+/** @see APR_STATUS_IS_ENOSTAT */
+#define APR_ENOSTAT (APR_OS_START_ERROR + 1)
+/** @see APR_STATUS_IS_ENOPOOL */
+#define APR_ENOPOOL (APR_OS_START_ERROR + 2)
+/* empty slot: +3 */
+/** @see APR_STATUS_IS_EBADDATE */
+#define APR_EBADDATE (APR_OS_START_ERROR + 4)
+/** @see APR_STATUS_IS_EINVALSOCK */
+#define APR_EINVALSOCK (APR_OS_START_ERROR + 5)
+/** @see APR_STATUS_IS_ENOPROC */
+#define APR_ENOPROC (APR_OS_START_ERROR + 6)
+/** @see APR_STATUS_IS_ENOTIME */
+#define APR_ENOTIME (APR_OS_START_ERROR + 7)
+/** @see APR_STATUS_IS_ENODIR */
+#define APR_ENODIR (APR_OS_START_ERROR + 8)
+/** @see APR_STATUS_IS_ENOLOCK */
+#define APR_ENOLOCK (APR_OS_START_ERROR + 9)
+/** @see APR_STATUS_IS_ENOPOLL */
+#define APR_ENOPOLL (APR_OS_START_ERROR + 10)
+/** @see APR_STATUS_IS_ENOSOCKET */
+#define APR_ENOSOCKET (APR_OS_START_ERROR + 11)
+/** @see APR_STATUS_IS_ENOTHREAD */
+#define APR_ENOTHREAD (APR_OS_START_ERROR + 12)
+/** @see APR_STATUS_IS_ENOTHDKEY */
+#define APR_ENOTHDKEY (APR_OS_START_ERROR + 13)
+/** @see APR_STATUS_IS_EGENERAL */
+#define APR_EGENERAL (APR_OS_START_ERROR + 14)
+/** @see APR_STATUS_IS_ENOSHMAVAIL */
+#define APR_ENOSHMAVAIL (APR_OS_START_ERROR + 15)
+/** @see APR_STATUS_IS_EBADIP */
+#define APR_EBADIP (APR_OS_START_ERROR + 16)
+/** @see APR_STATUS_IS_EBADMASK */
+#define APR_EBADMASK (APR_OS_START_ERROR + 17)
+/* empty slot: +18 */
+/** @see APR_STATUS_IS_EDSOPEN */
+#define APR_EDSOOPEN (APR_OS_START_ERROR + 19)
+/** @see APR_STATUS_IS_EABSOLUTE */
+#define APR_EABSOLUTE (APR_OS_START_ERROR + 20)
+/** @see APR_STATUS_IS_ERELATIVE */
+#define APR_ERELATIVE (APR_OS_START_ERROR + 21)
+/** @see APR_STATUS_IS_EINCOMPLETE */
+#define APR_EINCOMPLETE (APR_OS_START_ERROR + 22)
+/** @see APR_STATUS_IS_EABOVEROOT */
+#define APR_EABOVEROOT (APR_OS_START_ERROR + 23)
+/** @see APR_STATUS_IS_EBADPATH */
+#define APR_EBADPATH (APR_OS_START_ERROR + 24)
+/** @see APR_STATUS_IS_EPATHWILD */
+#define APR_EPATHWILD (APR_OS_START_ERROR + 25)
+/** @see APR_STATUS_IS_ESYMNOTFOUND */
+#define APR_ESYMNOTFOUND (APR_OS_START_ERROR + 26)
+/** @see APR_STATUS_IS_EPROC_UNKNOWN */
+#define APR_EPROC_UNKNOWN (APR_OS_START_ERROR + 27)
+/** @see APR_STATUS_IS_ENOTENOUGHENTROPY */
+#define APR_ENOTENOUGHENTROPY (APR_OS_START_ERROR + 28)
+/** @} */
+
+/**
+ * @defgroup APR_STATUS_IS Status Value Tests
+ * @warning For any particular error condition, more than one of these tests
+ * may match. This is because platform-specific error codes may not
+ * always match the semantics of the POSIX codes these tests (and the
+ * corresponding APR error codes) are named after. A notable example
+ * are the APR_STATUS_IS_ENOENT and APR_STATUS_IS_ENOTDIR tests on
+ * Win32 platforms. The programmer should always be aware of this and
+ * adjust the order of the tests accordingly.
+ * @{
+ */
+/**
+ * APR was unable to perform a stat on the file
+ * @warning always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ENOSTAT(s) ((s) == APR_ENOSTAT)
+/**
+ * APR was not provided a pool with which to allocate memory
+ * @warning always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ENOPOOL(s) ((s) == APR_ENOPOOL)
+/** APR was given an invalid date */
+#define APR_STATUS_IS_EBADDATE(s) ((s) == APR_EBADDATE)
+/** APR was given an invalid socket */
+#define APR_STATUS_IS_EINVALSOCK(s) ((s) == APR_EINVALSOCK)
+/** APR was not given a process structure */
+#define APR_STATUS_IS_ENOPROC(s) ((s) == APR_ENOPROC)
+/** APR was not given a time structure */
+#define APR_STATUS_IS_ENOTIME(s) ((s) == APR_ENOTIME)
+/** APR was not given a directory structure */
+#define APR_STATUS_IS_ENODIR(s) ((s) == APR_ENODIR)
+/** APR was not given a lock structure */
+#define APR_STATUS_IS_ENOLOCK(s) ((s) == APR_ENOLOCK)
+/** APR was not given a poll structure */
+#define APR_STATUS_IS_ENOPOLL(s) ((s) == APR_ENOPOLL)
+/** APR was not given a socket */
+#define APR_STATUS_IS_ENOSOCKET(s) ((s) == APR_ENOSOCKET)
+/** APR was not given a thread structure */
+#define APR_STATUS_IS_ENOTHREAD(s) ((s) == APR_ENOTHREAD)
+/** APR was not given a thread key structure */
+#define APR_STATUS_IS_ENOTHDKEY(s) ((s) == APR_ENOTHDKEY)
+/** Generic Error which can not be put into another spot */
+#define APR_STATUS_IS_EGENERAL(s) ((s) == APR_EGENERAL)
+/** There is no more shared memory available */
+#define APR_STATUS_IS_ENOSHMAVAIL(s) ((s) == APR_ENOSHMAVAIL)
+/** The specified IP address is invalid */
+#define APR_STATUS_IS_EBADIP(s) ((s) == APR_EBADIP)
+/** The specified netmask is invalid */
+#define APR_STATUS_IS_EBADMASK(s) ((s) == APR_EBADMASK)
+/* empty slot: +18 */
+/**
+ * APR was unable to open the dso object.
+ * For more information call apr_dso_error().
+ */
+#if defined(WIN32)
+#define APR_STATUS_IS_EDSOOPEN(s) ((s) == APR_EDSOOPEN \
+ || APR_TO_OS_ERROR(s) == ERROR_MOD_NOT_FOUND)
+#else
+#define APR_STATUS_IS_EDSOOPEN(s) ((s) == APR_EDSOOPEN)
+#endif
+/** The given path was absolute. */
+#define APR_STATUS_IS_EABSOLUTE(s) ((s) == APR_EABSOLUTE)
+/** The given path was relative. */
+#define APR_STATUS_IS_ERELATIVE(s) ((s) == APR_ERELATIVE)
+/** The given path was neither relative nor absolute. */
+#define APR_STATUS_IS_EINCOMPLETE(s) ((s) == APR_EINCOMPLETE)
+/** The given path was above the root path. */
+#define APR_STATUS_IS_EABOVEROOT(s) ((s) == APR_EABOVEROOT)
+/** The given path was bad. */
+#define APR_STATUS_IS_EBADPATH(s) ((s) == APR_EBADPATH)
+/** The given path contained wildcards. */
+#define APR_STATUS_IS_EPATHWILD(s) ((s) == APR_EPATHWILD)
+/** Could not find the requested symbol.
+ * For more information call apr_dso_error().
+ */
+#if defined(WIN32)
+#define APR_STATUS_IS_ESYMNOTFOUND(s) ((s) == APR_ESYMNOTFOUND \
+ || APR_TO_OS_ERROR(s) == ERROR_PROC_NOT_FOUND)
+#else
+#define APR_STATUS_IS_ESYMNOTFOUND(s) ((s) == APR_ESYMNOTFOUND)
+#endif
+/** The given process was not recognized by APR. */
+#define APR_STATUS_IS_EPROC_UNKNOWN(s) ((s) == APR_EPROC_UNKNOWN)
+
+/** APR could not gather enough entropy to continue. */
+#define APR_STATUS_IS_ENOTENOUGHENTROPY(s) ((s) == APR_ENOTENOUGHENTROPY)
+
+/** @} */
+
+/**
+ * @addtogroup APR_Error
+ * @{
+ */
+/** @see APR_STATUS_IS_INCHILD */
+#define APR_INCHILD (APR_OS_START_STATUS + 1)
+/** @see APR_STATUS_IS_INPARENT */
+#define APR_INPARENT (APR_OS_START_STATUS + 2)
+/** @see APR_STATUS_IS_DETACH */
+#define APR_DETACH (APR_OS_START_STATUS + 3)
+/** @see APR_STATUS_IS_NOTDETACH */
+#define APR_NOTDETACH (APR_OS_START_STATUS + 4)
+/** @see APR_STATUS_IS_CHILD_DONE */
+#define APR_CHILD_DONE (APR_OS_START_STATUS + 5)
+/** @see APR_STATUS_IS_CHILD_NOTDONE */
+#define APR_CHILD_NOTDONE (APR_OS_START_STATUS + 6)
+/** @see APR_STATUS_IS_TIMEUP */
+#define APR_TIMEUP (APR_OS_START_STATUS + 7)
+/** @see APR_STATUS_IS_INCOMPLETE */
+#define APR_INCOMPLETE (APR_OS_START_STATUS + 8)
+/* empty slot: +9 */
+/* empty slot: +10 */
+/* empty slot: +11 */
+/** @see APR_STATUS_IS_BADCH */
+#define APR_BADCH (APR_OS_START_STATUS + 12)
+/** @see APR_STATUS_IS_BADARG */
+#define APR_BADARG (APR_OS_START_STATUS + 13)
+/** @see APR_STATUS_IS_EOF */
+#define APR_EOF (APR_OS_START_STATUS + 14)
+/** @see APR_STATUS_IS_NOTFOUND */
+#define APR_NOTFOUND (APR_OS_START_STATUS + 15)
+/* empty slot: +16 */
+/* empty slot: +17 */
+/* empty slot: +18 */
+/** @see APR_STATUS_IS_ANONYMOUS */
+#define APR_ANONYMOUS (APR_OS_START_STATUS + 19)
+/** @see APR_STATUS_IS_FILEBASED */
+#define APR_FILEBASED (APR_OS_START_STATUS + 20)
+/** @see APR_STATUS_IS_KEYBASED */
+#define APR_KEYBASED (APR_OS_START_STATUS + 21)
+/** @see APR_STATUS_IS_EINIT */
+#define APR_EINIT (APR_OS_START_STATUS + 22)
+/** @see APR_STATUS_IS_ENOTIMPL */
+#define APR_ENOTIMPL (APR_OS_START_STATUS + 23)
+/** @see APR_STATUS_IS_EMISMATCH */
+#define APR_EMISMATCH (APR_OS_START_STATUS + 24)
+/** @see APR_STATUS_IS_EBUSY */
+#define APR_EBUSY (APR_OS_START_STATUS + 25)
+/** @} */
+
+/**
+ * @addtogroup APR_STATUS_IS
+ * @{
+ */
+/**
+ * Program is currently executing in the child
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code */
+#define APR_STATUS_IS_INCHILD(s) ((s) == APR_INCHILD)
+/**
+ * Program is currently executing in the parent
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_INPARENT(s) ((s) == APR_INPARENT)
+/**
+ * The thread is detached
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_DETACH(s) ((s) == APR_DETACH)
+/**
+ * The thread is not detached
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_NOTDETACH(s) ((s) == APR_NOTDETACH)
+/**
+ * The child has finished executing
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_CHILD_DONE(s) ((s) == APR_CHILD_DONE)
+/**
+ * The child has not finished executing
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_CHILD_NOTDONE(s) ((s) == APR_CHILD_NOTDONE)
+/**
+ * The operation did not finish before the timeout
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP)
+/**
+ * The operation was incomplete although some processing was performed
+ * and the results are partially valid.
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_INCOMPLETE(s) ((s) == APR_INCOMPLETE)
+/* empty slot: +9 */
+/* empty slot: +10 */
+/* empty slot: +11 */
+/**
+ * Getopt found an option not in the option string
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_BADCH(s) ((s) == APR_BADCH)
+/**
+ * Getopt found an option not in the option string and an argument was
+ * specified in the option string
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_BADARG(s) ((s) == APR_BADARG)
+/**
+ * APR has encountered the end of the file
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EOF(s) ((s) == APR_EOF)
+/**
+ * APR was unable to find the socket in the poll structure
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_NOTFOUND(s) ((s) == APR_NOTFOUND)
+/* empty slot: +16 */
+/* empty slot: +17 */
+/* empty slot: +18 */
+/**
+ * APR is using anonymous shared memory
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ANONYMOUS(s) ((s) == APR_ANONYMOUS)
+/**
+ * APR is using a file name as the key to the shared memory
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_FILEBASED(s) ((s) == APR_FILEBASED)
+/**
+ * APR is using a shared key as the key to the shared memory
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_KEYBASED(s) ((s) == APR_KEYBASED)
+/**
+ * Ininitalizer value. If no option has been found, but
+ * the status variable requires a value, this should be used
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EINIT(s) ((s) == APR_EINIT)
+/**
+ * The APR function has not been implemented on this
+ * platform, either because nobody has gotten to it yet,
+ * or the function is impossible on this platform.
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ENOTIMPL(s) ((s) == APR_ENOTIMPL)
+/**
+ * Two passwords do not match.
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EMISMATCH(s) ((s) == APR_EMISMATCH)
+/**
+ * The given lock was busy
+ * @warning always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EBUSY(s) ((s) == APR_EBUSY)
+
+/** @} */
+
+/**
+ * @addtogroup APR_Error APR Error Values
+ * @{
+ */
+/* APR CANONICAL ERROR VALUES */
+/** @see APR_STATUS_IS_EACCES */
+#ifdef EACCES
+#define APR_EACCES EACCES
+#else
+#define APR_EACCES (APR_OS_START_CANONERR + 1)
+#endif
+
+/** @see APR_STATUS_IS_EXIST */
+#ifdef EEXIST
+#define APR_EEXIST EEXIST
+#else
+#define APR_EEXIST (APR_OS_START_CANONERR + 2)
+#endif
+
+/** @see APR_STATUS_IS_ENAMETOOLONG */
+#ifdef ENAMETOOLONG
+#define APR_ENAMETOOLONG ENAMETOOLONG
+#else
+#define APR_ENAMETOOLONG (APR_OS_START_CANONERR + 3)
+#endif
+
+/** @see APR_STATUS_IS_ENOENT */
+#ifdef ENOENT
+#define APR_ENOENT ENOENT
+#else
+#define APR_ENOENT (APR_OS_START_CANONERR + 4)
+#endif
+
+/** @see APR_STATUS_IS_ENOTDIR */
+#ifdef ENOTDIR
+#define APR_ENOTDIR ENOTDIR
+#else
+#define APR_ENOTDIR (APR_OS_START_CANONERR + 5)
+#endif
+
+/** @see APR_STATUS_IS_ENOSPC */
+#ifdef ENOSPC
+#define APR_ENOSPC ENOSPC
+#else
+#define APR_ENOSPC (APR_OS_START_CANONERR + 6)
+#endif
+
+/** @see APR_STATUS_IS_ENOMEM */
+#ifdef ENOMEM
+#define APR_ENOMEM ENOMEM
+#else
+#define APR_ENOMEM (APR_OS_START_CANONERR + 7)
+#endif
+
+/** @see APR_STATUS_IS_EMFILE */
+#ifdef EMFILE
+#define APR_EMFILE EMFILE
+#else
+#define APR_EMFILE (APR_OS_START_CANONERR + 8)
+#endif
+
+/** @see APR_STATUS_IS_ENFILE */
+#ifdef ENFILE
+#define APR_ENFILE ENFILE
+#else
+#define APR_ENFILE (APR_OS_START_CANONERR + 9)
+#endif
+
+/** @see APR_STATUS_IS_EBADF */
+#ifdef EBADF
+#define APR_EBADF EBADF
+#else
+#define APR_EBADF (APR_OS_START_CANONERR + 10)
+#endif
+
+/** @see APR_STATUS_IS_EINVAL */
+#ifdef EINVAL
+#define APR_EINVAL EINVAL
+#else
+#define APR_EINVAL (APR_OS_START_CANONERR + 11)
+#endif
+
+/** @see APR_STATUS_IS_ESPIPE */
+#ifdef ESPIPE
+#define APR_ESPIPE ESPIPE
+#else
+#define APR_ESPIPE (APR_OS_START_CANONERR + 12)
+#endif
+
+/**
+ * @see APR_STATUS_IS_EAGAIN
+ * @warning use APR_STATUS_IS_EAGAIN instead of just testing this value
+ */
+#ifdef EAGAIN
+#define APR_EAGAIN EAGAIN
+#elif defined(EWOULDBLOCK)
+#define APR_EAGAIN EWOULDBLOCK
+#else
+#define APR_EAGAIN (APR_OS_START_CANONERR + 13)
+#endif
+
+/** @see APR_STATUS_IS_EINTR */
+#ifdef EINTR
+#define APR_EINTR EINTR
+#else
+#define APR_EINTR (APR_OS_START_CANONERR + 14)
+#endif
+
+/** @see APR_STATUS_IS_ENOTSOCK */
+#ifdef ENOTSOCK
+#define APR_ENOTSOCK ENOTSOCK
+#else
+#define APR_ENOTSOCK (APR_OS_START_CANONERR + 15)
+#endif
+
+/** @see APR_STATUS_IS_ECONNREFUSED */
+#ifdef ECONNREFUSED
+#define APR_ECONNREFUSED ECONNREFUSED
+#else
+#define APR_ECONNREFUSED (APR_OS_START_CANONERR + 16)
+#endif
+
+/** @see APR_STATUS_IS_EINPROGRESS */
+#ifdef EINPROGRESS
+#define APR_EINPROGRESS EINPROGRESS
+#else
+#define APR_EINPROGRESS (APR_OS_START_CANONERR + 17)
+#endif
+
+/**
+ * @see APR_STATUS_IS_ECONNABORTED
+ * @warning use APR_STATUS_IS_ECONNABORTED instead of just testing this value
+ */
+
+#ifdef ECONNABORTED
+#define APR_ECONNABORTED ECONNABORTED
+#else
+#define APR_ECONNABORTED (APR_OS_START_CANONERR + 18)
+#endif
+
+/** @see APR_STATUS_IS_ECONNRESET */
+#ifdef ECONNRESET
+#define APR_ECONNRESET ECONNRESET
+#else
+#define APR_ECONNRESET (APR_OS_START_CANONERR + 19)
+#endif
+
+/** @see APR_STATUS_IS_ETIMEDOUT
+ * @deprecated */
+#ifdef ETIMEDOUT
+#define APR_ETIMEDOUT ETIMEDOUT
+#else
+#define APR_ETIMEDOUT (APR_OS_START_CANONERR + 20)
+#endif
+
+/** @see APR_STATUS_IS_EHOSTUNREACH */
+#ifdef EHOSTUNREACH
+#define APR_EHOSTUNREACH EHOSTUNREACH
+#else
+#define APR_EHOSTUNREACH (APR_OS_START_CANONERR + 21)
+#endif
+
+/** @see APR_STATUS_IS_ENETUNREACH */
+#ifdef ENETUNREACH
+#define APR_ENETUNREACH ENETUNREACH
+#else
+#define APR_ENETUNREACH (APR_OS_START_CANONERR + 22)
+#endif
+
+/** @see APR_STATUS_IS_EFTYPE */
+#ifdef EFTYPE
+#define APR_EFTYPE EFTYPE
+#else
+#define APR_EFTYPE (APR_OS_START_CANONERR + 23)
+#endif
+
+/** @see APR_STATUS_IS_EPIPE */
+#ifdef EPIPE
+#define APR_EPIPE EPIPE
+#else
+#define APR_EPIPE (APR_OS_START_CANONERR + 24)
+#endif
+
+/** @see APR_STATUS_IS_EXDEV */
+#ifdef EXDEV
+#define APR_EXDEV EXDEV
+#else
+#define APR_EXDEV (APR_OS_START_CANONERR + 25)
+#endif
+
+/** @see APR_STATUS_IS_ENOTEMPTY */
+#ifdef ENOTEMPTY
+#define APR_ENOTEMPTY ENOTEMPTY
+#else
+#define APR_ENOTEMPTY (APR_OS_START_CANONERR + 26)
+#endif
+
+/** @} */
+
+#if defined(OS2) && !defined(DOXYGEN)
+
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+#define INCL_DOSERRORS
+#define INCL_DOS
+
+/* Leave these undefined.
+ * OS2 doesn't rely on the errno concept.
+ * The API calls always return a result codes which
+ * should be filtered through APR_FROM_OS_ERROR().
+ *
+ * #define apr_get_os_error() (APR_FROM_OS_ERROR(GetLastError()))
+ * #define apr_set_os_error(e) (SetLastError(APR_TO_OS_ERROR(e)))
+ */
+
+/* A special case, only socket calls require this;
+ */
+#define apr_get_netos_error() (APR_FROM_OS_ERROR(errno))
+#define apr_set_netos_error(e) (errno = APR_TO_OS_ERROR(e))
+
+/* And this needs to be greped away for good:
+ */
+#define APR_OS2_STATUS(e) (APR_FROM_OS_ERROR(e))
+
+/* These can't sit in a private header, so in spite of the extra size,
+ * they need to be made available here.
+ */
+#define SOCBASEERR 10000
+#define SOCEPERM (SOCBASEERR+1) /* Not owner */
+#define SOCESRCH (SOCBASEERR+3) /* No such process */
+#define SOCEINTR (SOCBASEERR+4) /* Interrupted system call */
+#define SOCENXIO (SOCBASEERR+6) /* No such device or address */
+#define SOCEBADF (SOCBASEERR+9) /* Bad file number */
+#define SOCEACCES (SOCBASEERR+13) /* Permission denied */
+#define SOCEFAULT (SOCBASEERR+14) /* Bad address */
+#define SOCEINVAL (SOCBASEERR+22) /* Invalid argument */
+#define SOCEMFILE (SOCBASEERR+24) /* Too many open files */
+#define SOCEPIPE (SOCBASEERR+32) /* Broken pipe */
+#define SOCEOS2ERR (SOCBASEERR+100) /* OS/2 Error */
+#define SOCEWOULDBLOCK (SOCBASEERR+35) /* Operation would block */
+#define SOCEINPROGRESS (SOCBASEERR+36) /* Operation now in progress */
+#define SOCEALREADY (SOCBASEERR+37) /* Operation already in progress */
+#define SOCENOTSOCK (SOCBASEERR+38) /* Socket operation on non-socket */
+#define SOCEDESTADDRREQ (SOCBASEERR+39) /* Destination address required */
+#define SOCEMSGSIZE (SOCBASEERR+40) /* Message too long */
+#define SOCEPROTOTYPE (SOCBASEERR+41) /* Protocol wrong type for socket */
+#define SOCENOPROTOOPT (SOCBASEERR+42) /* Protocol not available */
+#define SOCEPROTONOSUPPORT (SOCBASEERR+43) /* Protocol not supported */
+#define SOCESOCKTNOSUPPORT (SOCBASEERR+44) /* Socket type not supported */
+#define SOCEOPNOTSUPP (SOCBASEERR+45) /* Operation not supported on socket */
+#define SOCEPFNOSUPPORT (SOCBASEERR+46) /* Protocol family not supported */
+#define SOCEAFNOSUPPORT (SOCBASEERR+47) /* Address family not supported by protocol family */
+#define SOCEADDRINUSE (SOCBASEERR+48) /* Address already in use */
+#define SOCEADDRNOTAVAIL (SOCBASEERR+49) /* Can't assign requested address */
+#define SOCENETDOWN (SOCBASEERR+50) /* Network is down */
+#define SOCENETUNREACH (SOCBASEERR+51) /* Network is unreachable */
+#define SOCENETRESET (SOCBASEERR+52) /* Network dropped connection on reset */
+#define SOCECONNABORTED (SOCBASEERR+53) /* Software caused connection abort */
+#define SOCECONNRESET (SOCBASEERR+54) /* Connection reset by peer */
+#define SOCENOBUFS (SOCBASEERR+55) /* No buffer space available */
+#define SOCEISCONN (SOCBASEERR+56) /* Socket is already connected */
+#define SOCENOTCONN (SOCBASEERR+57) /* Socket is not connected */
+#define SOCESHUTDOWN (SOCBASEERR+58) /* Can't send after socket shutdown */
+#define SOCETOOMANYREFS (SOCBASEERR+59) /* Too many references: can't splice */
+#define SOCETIMEDOUT (SOCBASEERR+60) /* Connection timed out */
+#define SOCECONNREFUSED (SOCBASEERR+61) /* Connection refused */
+#define SOCELOOP (SOCBASEERR+62) /* Too many levels of symbolic links */
+#define SOCENAMETOOLONG (SOCBASEERR+63) /* File name too long */
+#define SOCEHOSTDOWN (SOCBASEERR+64) /* Host is down */
+#define SOCEHOSTUNREACH (SOCBASEERR+65) /* No route to host */
+#define SOCENOTEMPTY (SOCBASEERR+66) /* Directory not empty */
+
+/* APR CANONICAL ERROR TESTS */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED \
+ || (s) == APR_OS_START_SYSERR + ERROR_SHARING_VIOLATION)
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST \
+ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_EXISTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_ALREADY_EXISTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED)
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILENAME_EXCED_RANGE \
+ || (s) == APR_OS_START_SYSERR + SOCENAMETOOLONG)
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_MORE_FILES \
+ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED)
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR)
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \
+ || (s) == APR_OS_START_SYSERR + ERROR_DISK_FULL)
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM)
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE \
+ || (s) == APR_OS_START_SYSERR + ERROR_TOO_MANY_OPEN_FILES)
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE)
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_PARAMETER \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_FUNCTION)
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA \
+ || (s) == APR_OS_START_SYSERR + SOCEWOULDBLOCK \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION)
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \
+ || (s) == APR_OS_START_SYSERR + SOCEINTR)
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \
+ || (s) == APR_OS_START_SYSERR + SOCENOTSOCK)
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \
+ || (s) == APR_OS_START_SYSERR + SOCECONNREFUSED)
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \
+ || (s) == APR_OS_START_SYSERR + SOCEINPROGRESS)
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == APR_OS_START_SYSERR + SOCECONNABORTED)
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \
+ || (s) == APR_OS_START_SYSERR + SOCECONNRESET)
+/* XXX deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + SOCETIMEDOUT)
+#undef APR_STATUS_IS_TIMEUP
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \
+ || (s) == APR_OS_START_SYSERR + SOCETIMEDOUT)
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \
+ || (s) == APR_OS_START_SYSERR + SOCEHOSTUNREACH)
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \
+ || (s) == APR_OS_START_SYSERR + SOCENETUNREACH)
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE)
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_BROKEN_PIPE \
+ || (s) == APR_OS_START_SYSERR + SOCEPIPE)
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_SAME_DEVICE)
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY \
+ || (s) == APR_OS_START_SYSERR + ERROR_DIR_NOT_EMPTY \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED)
+
+/*
+ Sorry, too tired to wrap this up for OS2... feel free to
+ fit the following into their best matches.
+
+ { ERROR_NO_SIGNAL_SENT, ESRCH },
+ { SOCEALREADY, EALREADY },
+ { SOCEDESTADDRREQ, EDESTADDRREQ },
+ { SOCEMSGSIZE, EMSGSIZE },
+ { SOCEPROTOTYPE, EPROTOTYPE },
+ { SOCENOPROTOOPT, ENOPROTOOPT },
+ { SOCEPROTONOSUPPORT, EPROTONOSUPPORT },
+ { SOCESOCKTNOSUPPORT, ESOCKTNOSUPPORT },
+ { SOCEOPNOTSUPP, EOPNOTSUPP },
+ { SOCEPFNOSUPPORT, EPFNOSUPPORT },
+ { SOCEAFNOSUPPORT, EAFNOSUPPORT },
+ { SOCEADDRINUSE, EADDRINUSE },
+ { SOCEADDRNOTAVAIL, EADDRNOTAVAIL },
+ { SOCENETDOWN, ENETDOWN },
+ { SOCENETRESET, ENETRESET },
+ { SOCENOBUFS, ENOBUFS },
+ { SOCEISCONN, EISCONN },
+ { SOCENOTCONN, ENOTCONN },
+ { SOCESHUTDOWN, ESHUTDOWN },
+ { SOCETOOMANYREFS, ETOOMANYREFS },
+ { SOCELOOP, ELOOP },
+ { SOCEHOSTDOWN, EHOSTDOWN },
+ { SOCENOTEMPTY, ENOTEMPTY },
+ { SOCEPIPE, EPIPE }
+*/
+
+#elif defined(WIN32) && !defined(DOXYGEN) /* !defined(OS2) */
+
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+#define apr_get_os_error() (APR_FROM_OS_ERROR(GetLastError()))
+#define apr_set_os_error(e) (SetLastError(APR_TO_OS_ERROR(e)))
+
+/* A special case, only socket calls require this:
+ */
+#define apr_get_netos_error() (APR_FROM_OS_ERROR(WSAGetLastError()))
+#define apr_set_netos_error(e) (WSASetLastError(APR_TO_OS_ERROR(e)))
+
+/* APR CANONICAL ERROR TESTS */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED \
+ || (s) == APR_OS_START_SYSERR + ERROR_CANNOT_MAKE \
+ || (s) == APR_OS_START_SYSERR + ERROR_CURRENT_DIRECTORY \
+ || (s) == APR_OS_START_SYSERR + ERROR_DRIVE_LOCKED \
+ || (s) == APR_OS_START_SYSERR + ERROR_FAIL_I24 \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_FAILED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_LOCKED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NETWORK_ACCESS_DENIED \
+ || (s) == APR_OS_START_SYSERR + ERROR_SHARING_VIOLATION)
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_EXISTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_ALREADY_EXISTS)
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILENAME_EXCED_RANGE \
+ || (s) == APR_OS_START_SYSERR + WSAENAMETOOLONG)
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_MORE_FILES)
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR \
+ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_NETPATH \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_NET_NAME \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_PATHNAME \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DRIVE)
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \
+ || (s) == APR_OS_START_SYSERR + ERROR_DISK_FULL)
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM \
+ || (s) == APR_OS_START_SYSERR + ERROR_ARENA_TRASHED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_ENOUGH_MEMORY \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_BLOCK \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_ENOUGH_QUOTA \
+ || (s) == APR_OS_START_SYSERR + ERROR_OUTOFMEMORY)
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE \
+ || (s) == APR_OS_START_SYSERR + ERROR_TOO_MANY_OPEN_FILES)
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_TARGET_HANDLE)
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_ACCESS \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DATA \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_FUNCTION \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_PARAMETER \
+ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK)
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_SEEK_ON_DEVICE \
+ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_PROC_SLOTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_NESTING_NOT_ALLOWED \
+ || (s) == APR_OS_START_SYSERR + ERROR_MAX_THRDS_REACHED \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION \
+ || (s) == APR_OS_START_SYSERR + WSAEWOULDBLOCK)
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \
+ || (s) == APR_OS_START_SYSERR + WSAEINTR)
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \
+ || (s) == APR_OS_START_SYSERR + WSAENOTSOCK)
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNREFUSED)
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \
+ || (s) == APR_OS_START_SYSERR + WSAEINPROGRESS)
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNABORTED)
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \
+ || (s) == APR_OS_START_SYSERR + ERROR_NETNAME_DELETED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNRESET)
+/* XXX deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#undef APR_STATUS_IS_TIMEUP
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAEHOSTUNREACH)
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAENETUNREACH)
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_EXE_MACHINE_TYPE_MISMATCH \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DLL \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_MODULETYPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_EXE_FORMAT \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_EXE_SIGNATURE \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_CORRUPT \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_FORMAT)
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_BROKEN_PIPE)
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_SAME_DEVICE)
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY \
+ || (s) == APR_OS_START_SYSERR + ERROR_DIR_NOT_EMPTY)
+
+#elif defined(NETWARE) && defined(USE_WINSOCK) && !defined(DOXYGEN) /* !defined(OS2) && !defined(WIN32) */
+
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+#define apr_get_os_error() (errno)
+#define apr_set_os_error(e) (errno = (e))
+
+/* A special case, only socket calls require this: */
+#define apr_get_netos_error() (APR_FROM_OS_ERROR(WSAGetLastError()))
+#define apr_set_netos_error(e) (WSASetLastError(APR_TO_OS_ERROR(e)))
+
+/* APR CANONICAL ERROR TESTS */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES)
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST)
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG)
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT)
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR)
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC)
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM)
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE)
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF)
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL)
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE)
+
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == EWOULDBLOCK \
+ || (s) == APR_OS_START_SYSERR + WSAEWOULDBLOCK)
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \
+ || (s) == APR_OS_START_SYSERR + WSAEINTR)
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \
+ || (s) == APR_OS_START_SYSERR + WSAENOTSOCK)
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNREFUSED)
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \
+ || (s) == APR_OS_START_SYSERR + WSAEINPROGRESS)
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNABORTED)
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \
+ || (s) == APR_OS_START_SYSERR + WSAECONNRESET)
+/* XXX deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#undef APR_STATUS_IS_TIMEUP
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAEHOSTUNREACH)
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAENETUNREACH)
+#define APR_STATUS_IS_ENETDOWN(s) ((s) == APR_OS_START_SYSERR + WSAENETDOWN)
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE)
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE)
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV)
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY)
+
+#else /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */
+
+/*
+ * os error codes are clib error codes
+ */
+#define APR_FROM_OS_ERROR(e) (e)
+#define APR_TO_OS_ERROR(e) (e)
+
+#define apr_get_os_error() (errno)
+#define apr_set_os_error(e) (errno = (e))
+
+/* A special case, only socket calls require this:
+ */
+#define apr_get_netos_error() (errno)
+#define apr_set_netos_error(e) (errno = (e))
+
+/**
+ * @addtogroup APR_STATUS_IS
+ * @{
+ */
+
+/** permission denied */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES)
+/** file exists */
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST)
+/** path name is too long */
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG)
+/**
+ * no such file or directory
+ * @remark
+ * EMVSCATLG can be returned by the automounter on z/OS for
+ * paths which do not exist.
+ */
+#ifdef EMVSCATLG
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \
+ || (s) == EMVSCATLG)
+#else
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT)
+#endif
+/** not a directory */
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR)
+/** no space left on device */
+#ifdef EDQUOT
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \
+ || (s) == EDQUOT)
+#else
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC)
+#endif
+/** not enough memory */
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM)
+/** too many open files */
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE)
+/** file table overflow */
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+/** bad file # */
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF)
+/** invalid argument */
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL)
+/** illegal seek */
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE)
+
+/** operation would block */
+#if !defined(EWOULDBLOCK) || !defined(EAGAIN)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN)
+#elif (EWOULDBLOCK == EAGAIN)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN)
+#else
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == EWOULDBLOCK)
+#endif
+
+/** interrupted system call */
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR)
+/** socket operation on a non-socket */
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK)
+/** Connection Refused */
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED)
+/** operation now in progress */
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS)
+
+/**
+ * Software caused connection abort
+ * @remark
+ * EPROTO on certain older kernels really means ECONNABORTED, so we need to
+ * ignore it for them. See discussion in new-httpd archives nh.9701 & nh.9603
+ *
+ * There is potentially a bug in Solaris 2.x x<6, and other boxes that
+ * implement tcp sockets in userland (i.e. on top of STREAMS). On these
+ * systems, EPROTO can actually result in a fatal loop. See PR#981 for
+ * example. It's hard to handle both uses of EPROTO.
+ */
+#ifdef EPROTO
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == EPROTO)
+#else
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED)
+#endif
+
+/** Connection Reset by peer */
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET)
+/** Operation timed out
+ * @deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT)
+/** no route to host */
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH)
+/** network is unreachable */
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH)
+/** inappropiate file type or format */
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE)
+/** broken pipe */
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE)
+/** cross device link */
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV)
+/** Directory Not Empty */
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY || \
+ (s) == APR_EEXIST)
+/** @} */
+
+#endif /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! APR_ERRNO_H */
+#ifndef _LINUX_ERRNO_H
+#define _LINUX_ERRNO_H
+
+#include <asm/errno.h>
+
+#ifdef __KERNEL__
+
+/* Should never be seen by user programs */
+#define ERESTARTSYS 512
+#define ERESTARTNOINTR 513
+#define ERESTARTNOHAND 514 /* restart if no handler.. */
+#define ENOIOCTLCMD 515 /* No ioctl command */
+#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
+
+/* Defined for the NFSv3 protocol */
+#define EBADHANDLE 521 /* Illegal NFS file handle */
+#define ENOTSYNC 522 /* Update synchronization mismatch */
+#define EBADCOOKIE 523 /* Cookie is stale */
+#define ENOTSUPP 524 /* Operation is not supported */
+#define ETOOSMALL 525 /* Buffer or request is too small */
+#define ESERVERFAULT 526 /* An untranslatable error occurred */
+#define EBADTYPE 527 /* Type not supported by server */
+#define EJUKEBOX 528 /* Request initiated, but will not complete before timeout */
+#define EIOCBQUEUED 529 /* iocb queued, will get completion event */
+#define EIOCBRETRY 530 /* iocb queued, will trigger a retry */
+
+#endif
+
+#endif
+// Copyright (c) 1994 James Clark
+// See the file COPYING for copying permission.
+
+#ifndef ErrnoMessageArg_INCLUDED
+#define ErrnoMessageArg_INCLUDED 1
+
+#include "MessageArg.h"
+#include "rtti.h"
+
+#ifdef SP_NAMESPACE
+namespace SP_NAMESPACE {
+#endif
+
+class SP_API ErrnoMessageArg : public OtherMessageArg {
+ RTTI_CLASS
+public:
+ ErrnoMessageArg(int errnum) : errno_(errnum) { }
+ MessageArg *copy() const;
+ // errno might be a macro so we must use a different name
+ int errnum() const;
+private:
+ int errno_;
+};
+
+inline
+int ErrnoMessageArg::errnum() const
+{
+ return errno_;
+}
+
+#ifdef SP_NAMESPACE
+}
+#endif
+
+#endif /* not ErrnoMessageArg_INCLUDED */
+/* Copyright (C) 1991,92,93,94,95,96,97,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/*
+ * ISO C99 Standard: 7.5 Errors <errno.h>
+ */
+
+#ifndef _ERRNO_H
+
+/* The includer defined __need_Emath if he wants only the definitions
+ of EDOM and ERANGE, and not everything else. */
+#ifndef __need_Emath
+# define _ERRNO_H 1
+# include <features.h>
+#endif
+
+__BEGIN_DECLS
+
+/* Get the error number constants from the system-specific file.
+ This file will test __need_Emath and _ERRNO_H. */
+#include <bits/errno.h>
+#undef __need_Emath
+
+#ifdef _ERRNO_H
+
+/* Declare the `errno' variable, unless it's defined as a macro by
+ bits/errno.h. This is the case in GNU, where it is a per-thread
+ variable. This redeclaration using the macro still works, but it
+ will be a function declaration without a prototype and may trigger
+ a -Wstrict-prototypes warning. */
+#ifndef errno
+extern int errno;
+#endif
+
+#ifdef __USE_GNU
+
+/* The full and simple forms of the name with which the program was
+ invoked. These variables are set up automatically at startup based on
+ the value of ARGV[0] (this works only if you use GNU ld). */
+extern char *program_invocation_name, *program_invocation_short_name;
+#endif /* __USE_GNU */
+#endif /* _ERRNO_H */
+
+__END_DECLS
+
+#endif /* _ERRNO_H */
+
+/* The Hurd <bits/errno.h> defines `error_t' as an enumerated type so
+ that printing `error_t' values in the debugger shows the names. We
+ might need this definition sometimes even if this file was included
+ before. */
+#if defined __USE_GNU || defined __need_error_t
+# ifndef __error_t_defined
+typedef int error_t;
+# define __error_t_defined 1
+# endif
+# undef __need_error_t
+#endif
+#ifndef _I386_ERRNO_H
+#define _I386_ERRNO_H
+
+#include <asm-generic/errno.h>
+
+#endif
+#ifndef _ASM_GENERIC_ERRNO_BASE_H
+#define _ASM_GENERIC_ERRNO_BASE_H
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* I/O error */
+#define ENXIO 6 /* No such device or address */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file number */
+#define ECHILD 10 /* No child processes */
+#define EAGAIN 11 /* Try again */
+#define ENOMEM 12 /* Out of memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#define ENOTBLK 15 /* Block device required */
+#define EBUSY 16 /* Device or resource busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* No such device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* File table overflow */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Not a typewriter */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+#define EDOM 33 /* Math argument out of domain of func */
+#define ERANGE 34 /* Math result not representable */
+
+#endif
+#ifndef _ASM_GENERIC_ERRNO_H
+#define _ASM_GENERIC_ERRNO_H
+
+#include <asm-generic/errno-base.h>
+
+#define EDEADLK 35 /* Resource deadlock would occur */
+#define ENAMETOOLONG 36 /* File name too long */
+#define ENOLCK 37 /* No record locks available */
+#define ENOSYS 38 /* Function not implemented */
+#define ENOTEMPTY 39 /* Directory not empty */
+#define ELOOP 40 /* Too many symbolic links encountered */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define ENOMSG 42 /* No message of desired type */
+#define EIDRM 43 /* Identifier removed */
+#define ECHRNG 44 /* Channel number out of range */
+#define EL2NSYNC 45 /* Level 2 not synchronized */
+#define EL3HLT 46 /* Level 3 halted */
+#define EL3RST 47 /* Level 3 reset */
+#define ELNRNG 48 /* Link number out of range */
+#define EUNATCH 49 /* Protocol driver not attached */
+#define ENOCSI 50 /* No CSI structure available */
+#define EL2HLT 51 /* Level 2 halted */
+#define EBADE 52 /* Invalid exchange */
+#define EBADR 53 /* Invalid request descriptor */
+#define EXFULL 54 /* Exchange full */
+#define ENOANO 55 /* No anode */
+#define EBADRQC 56 /* Invalid request code */
+#define EBADSLT 57 /* Invalid slot */
+
+#define EDEADLOCK EDEADLK
+
+#define EBFONT 59 /* Bad font file format */
+#define ENOSTR 60 /* Device not a stream */
+#define ENODATA 61 /* No data available */
+#define ETIME 62 /* Timer expired */
+#define ENOSR 63 /* Out of streams resources */
+#define ENONET 64 /* Machine is not on the network */
+#define ENOPKG 65 /* Package not installed */
+#define EREMOTE 66 /* Object is remote */
+#define ENOLINK 67 /* Link has been severed */
+#define EADV 68 /* Advertise error */
+#define ESRMNT 69 /* Srmount error */
+#define ECOMM 70 /* Communication error on send */
+#define EPROTO 71 /* Protocol error */
+#define EMULTIHOP 72 /* Multihop attempted */
+#define EDOTDOT 73 /* RFS specific error */
+#define EBADMSG 74 /* Not a data message */
+#define EOVERFLOW 75 /* Value too large for defined data type */
+#define ENOTUNIQ 76 /* Name not unique on network */
+#define EBADFD 77 /* File descriptor in bad state */
+#define EREMCHG 78 /* Remote address changed */
+#define ELIBACC 79 /* Can not access a needed shared library */
+#define ELIBBAD 80 /* Accessing a corrupted shared library */
+#define ELIBSCN 81 /* .lib section in a.out corrupted */
+#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
+#define ELIBEXEC 83 /* Cannot exec a shared library directly */
+#define EILSEQ 84 /* Illegal byte sequence */
+#define ERESTART 85 /* Interrupted system call should be restarted */
+#define ESTRPIPE 86 /* Streams pipe error */
+#define EUSERS 87 /* Too many users */
+#define ENOTSOCK 88 /* Socket operation on non-socket */
+#define EDESTADDRREQ 89 /* Destination address required */
+#define EMSGSIZE 90 /* Message too long */
+#define EPROTOTYPE 91 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 92 /* Protocol not available */
+#define EPROTONOSUPPORT 93 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
+#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
+#define EPFNOSUPPORT 96 /* Protocol family not supported */
+#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
+#define EADDRINUSE 98 /* Address already in use */
+#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
+#define ENETDOWN 100 /* Network is down */
+#define ENETUNREACH 101 /* Network is unreachable */
+#define ENETRESET 102 /* Network dropped connection because of reset */
+#define ECONNABORTED 103 /* Software caused connection abort */
+#define ECONNRESET 104 /* Connection reset by peer */
+#define ENOBUFS 105 /* No buffer space available */
+#define EISCONN 106 /* Transport endpoint is already connected */
+#define ENOTCONN 107 /* Transport endpoint is not connected */
+#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
+#define ETOOMANYREFS 109 /* Too many references: cannot splice */
+#define ETIMEDOUT 110 /* Connection timed out */
+#define ECONNREFUSED 111 /* Connection refused */
+#define EHOSTDOWN 112 /* Host is down */
+#define EHOSTUNREACH 113 /* No route to host */
+#define EALREADY 114 /* Operation already in progress */
+#define EINPROGRESS 115 /* Operation now in progress */
+#define ESTALE 116 /* Stale NFS file handle */
+#define EUCLEAN 117 /* Structure needs cleaning */
+#define ENOTNAM 118 /* Not a XENIX named type file */
+#define ENAVAIL 119 /* No XENIX semaphores available */
+#define EISNAM 120 /* Is a named type file */
+#define EREMOTEIO 121 /* Remote I/O error */
+#define EDQUOT 122 /* Quota exceeded */
+
+#define ENOMEDIUM 123 /* No medium found */
+#define EMEDIUMTYPE 124 /* Wrong medium type */
+#define ECANCELED 125 /* Operation Canceled */
+#define ENOKEY 126 /* Required key not available */
+#define EKEYEXPIRED 127 /* Key has expired */
+#define EKEYREVOKED 128 /* Key has been revoked */
+#define EKEYREJECTED 129 /* Key was rejected by service */
+
+/* for robust mutexes */
+#define EOWNERDEAD 130 /* Owner died */
+#define ENOTRECOVERABLE 131 /* State not recoverable */
+
+#endif
diff --git a/doc/errno.list.macosx.txt b/doc/errno.list.macosx.txt
new file mode 100644
index 000000000..728753ac7
--- /dev/null
+++ b/doc/errno.list.macosx.txt
@@ -0,0 +1,1513 @@
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef APR_ERRNO_H
+#define APR_ERRNO_H
+
+/**
+ * @file apr_errno.h
+ * @brief APR Error Codes
+ */
+
+#include "apr.h"
+
+#if APR_HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup apr_errno Error Codes
+ * @ingroup APR
+ * @{
+ */
+
+/**
+ * Type for specifying an error or status code.
+ */
+typedef int apr_status_t;
+
+/**
+ * Return a human readable string describing the specified error.
+ * @param statcode The error code the get a string for.
+ * @param buf A buffer to hold the error string.
+ * @param bufsize Size of the buffer to hold the string.
+ */
+APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf,
+ apr_size_t bufsize);
+
+#if defined(DOXYGEN)
+/**
+ * @def APR_FROM_OS_ERROR(os_err_type syserr)
+ * Fold a platform specific error into an apr_status_t code.
+ * @return apr_status_t
+ * @param e The platform os error code.
+ * @warning macro implementation; the syserr argument may be evaluated
+ * multiple times.
+ */
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+
+/**
+ * @def APR_TO_OS_ERROR(apr_status_t statcode)
+ * @return os_err_type
+ * Fold an apr_status_t code back to the native platform defined error.
+ * @param e The apr_status_t folded platform os error code.
+ * @warning macro implementation; the statcode argument may be evaluated
+ * multiple times. If the statcode was not created by apr_get_os_error
+ * or APR_FROM_OS_ERROR, the results are undefined.
+ */
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+/** @def apr_get_os_error()
+ * @return apr_status_t the last platform error, folded into apr_status_t, on most platforms
+ * @remark This retrieves errno, or calls a GetLastError() style function, and
+ * folds it with APR_FROM_OS_ERROR. Some platforms (such as OS2) have no
+ * such mechanism, so this call may be unsupported. Do NOT use this
+ * call for socket errors from socket, send, recv etc!
+ */
+
+/** @def apr_set_os_error(e)
+ * Reset the last platform error, unfolded from an apr_status_t, on some platforms
+ * @param e The OS error folded in a prior call to APR_FROM_OS_ERROR()
+ * @warning This is a macro implementation; the statcode argument may be evaluated
+ * multiple times. If the statcode was not created by apr_get_os_error
+ * or APR_FROM_OS_ERROR, the results are undefined. This macro sets
+ * errno, or calls a SetLastError() style function, unfolding statcode
+ * with APR_TO_OS_ERROR. Some platforms (such as OS2) have no such
+ * mechanism, so this call may be unsupported.
+ */
+
+/** @def apr_get_netos_error()
+ * Return the last socket error, folded into apr_status_t, on all platforms
+ * @remark This retrieves errno or calls a GetLastSocketError() style function,
+ * and folds it with APR_FROM_OS_ERROR.
+ */
+
+/** @def apr_set_netos_error(e)
+ * Reset the last socket error, unfolded from an apr_status_t
+ * @param e The socket error folded in a prior call to APR_FROM_OS_ERROR()
+ * @warning This is a macro implementation; the statcode argument may be evaluated
+ * multiple times. If the statcode was not created by apr_get_os_error
+ * or APR_FROM_OS_ERROR, the results are undefined. This macro sets
+ * errno, or calls a WSASetLastError() style function, unfolding
+ * socketcode with APR_TO_OS_ERROR.
+ */
+
+#endif /* defined(DOXYGEN) */
+
+/**
+ * APR_OS_START_ERROR is where the APR specific error values start.
+ */
+#define APR_OS_START_ERROR 20000
+/**
+ * APR_OS_ERRSPACE_SIZE is the maximum number of errors you can fit
+ * into one of the error/status ranges below -- except for
+ * APR_OS_START_USERERR, which see.
+ */
+#define APR_OS_ERRSPACE_SIZE 50000
+/**
+ * APR_OS_START_STATUS is where the APR specific status codes start.
+ */
+#define APR_OS_START_STATUS (APR_OS_START_ERROR + APR_OS_ERRSPACE_SIZE)
+/**
+ * APR_OS_START_USERERR are reserved for applications that use APR that
+ * layer their own error codes along with APR's. Note that the
+ * error immediately following this one is set ten times farther
+ * away than usual, so that users of apr have a lot of room in
+ * which to declare custom error codes.
+ */
+#define APR_OS_START_USERERR (APR_OS_START_STATUS + APR_OS_ERRSPACE_SIZE)
+/**
+ * APR_OS_START_USEERR is obsolete, defined for compatibility only.
+ * Use APR_OS_START_USERERR instead.
+ */
+#define APR_OS_START_USEERR APR_OS_START_USERERR
+/**
+ * APR_OS_START_CANONERR is where APR versions of errno values are defined
+ * on systems which don't have the corresponding errno.
+ */
+#define APR_OS_START_CANONERR (APR_OS_START_USERERR \
+ + (APR_OS_ERRSPACE_SIZE * 10))
+/**
+ * APR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into
+ * apr_status_t values.
+ */
+#define APR_OS_START_EAIERR (APR_OS_START_CANONERR + APR_OS_ERRSPACE_SIZE)
+/**
+ * APR_OS_START_SYSERR folds platform-specific system error values into
+ * apr_status_t values.
+ */
+#define APR_OS_START_SYSERR (APR_OS_START_EAIERR + APR_OS_ERRSPACE_SIZE)
+
+/** no error. */
+#define APR_SUCCESS 0
+
+/**
+ * @defgroup APR_Error APR Error Values
+ * <PRE>
+ * <b>APR ERROR VALUES</b>
+ * APR_ENOSTAT APR was unable to perform a stat on the file
+ * APR_ENOPOOL APR was not provided a pool with which to allocate memory
+ * APR_EBADDATE APR was given an invalid date
+ * APR_EINVALSOCK APR was given an invalid socket
+ * APR_ENOPROC APR was not given a process structure
+ * APR_ENOTIME APR was not given a time structure
+ * APR_ENODIR APR was not given a directory structure
+ * APR_ENOLOCK APR was not given a lock structure
+ * APR_ENOPOLL APR was not given a poll structure
+ * APR_ENOSOCKET APR was not given a socket
+ * APR_ENOTHREAD APR was not given a thread structure
+ * APR_ENOTHDKEY APR was not given a thread key structure
+ * APR_ENOSHMAVAIL There is no more shared memory available
+ * APR_EDSOOPEN APR was unable to open the dso object. For more
+ * information call apr_dso_error().
+ * APR_EGENERAL General failure (specific information not available)
+ * APR_EBADIP The specified IP address is invalid
+ * APR_EBADMASK The specified netmask is invalid
+ * APR_ESYMNOTFOUND Could not find the requested symbol
+ * </PRE>
+ *
+ * <PRE>
+ * <b>APR STATUS VALUES</b>
+ * APR_INCHILD Program is currently executing in the child
+ * APR_INPARENT Program is currently executing in the parent
+ * APR_DETACH The thread is detached
+ * APR_NOTDETACH The thread is not detached
+ * APR_CHILD_DONE The child has finished executing
+ * APR_CHILD_NOTDONE The child has not finished executing
+ * APR_TIMEUP The operation did not finish before the timeout
+ * APR_INCOMPLETE The operation was incomplete although some processing
+ * was performed and the results are partially valid
+ * APR_BADCH Getopt found an option not in the option string
+ * APR_BADARG Getopt found an option that is missing an argument
+ * and an argument was specified in the option string
+ * APR_EOF APR has encountered the end of the file
+ * APR_NOTFOUND APR was unable to find the socket in the poll structure
+ * APR_ANONYMOUS APR is using anonymous shared memory
+ * APR_FILEBASED APR is using a file name as the key to the shared memory
+ * APR_KEYBASED APR is using a shared key as the key to the shared memory
+ * APR_EINIT Ininitalizer value. If no option has been found, but
+ * the status variable requires a value, this should be used
+ * APR_ENOTIMPL The APR function has not been implemented on this
+ * platform, either because nobody has gotten to it yet,
+ * or the function is impossible on this platform.
+ * APR_EMISMATCH Two passwords do not match.
+ * APR_EABSOLUTE The given path was absolute.
+ * APR_ERELATIVE The given path was relative.
+ * APR_EINCOMPLETE The given path was neither relative nor absolute.
+ * APR_EABOVEROOT The given path was above the root path.
+ * APR_EBUSY The given lock was busy.
+ * APR_EPROC_UNKNOWN The given process wasn't recognized by APR
+ * </PRE>
+ * @{
+ */
+/** @see APR_STATUS_IS_ENOSTAT */
+#define APR_ENOSTAT (APR_OS_START_ERROR + 1)
+/** @see APR_STATUS_IS_ENOPOOL */
+#define APR_ENOPOOL (APR_OS_START_ERROR + 2)
+/* empty slot: +3 */
+/** @see APR_STATUS_IS_EBADDATE */
+#define APR_EBADDATE (APR_OS_START_ERROR + 4)
+/** @see APR_STATUS_IS_EINVALSOCK */
+#define APR_EINVALSOCK (APR_OS_START_ERROR + 5)
+/** @see APR_STATUS_IS_ENOPROC */
+#define APR_ENOPROC (APR_OS_START_ERROR + 6)
+/** @see APR_STATUS_IS_ENOTIME */
+#define APR_ENOTIME (APR_OS_START_ERROR + 7)
+/** @see APR_STATUS_IS_ENODIR */
+#define APR_ENODIR (APR_OS_START_ERROR + 8)
+/** @see APR_STATUS_IS_ENOLOCK */
+#define APR_ENOLOCK (APR_OS_START_ERROR + 9)
+/** @see APR_STATUS_IS_ENOPOLL */
+#define APR_ENOPOLL (APR_OS_START_ERROR + 10)
+/** @see APR_STATUS_IS_ENOSOCKET */
+#define APR_ENOSOCKET (APR_OS_START_ERROR + 11)
+/** @see APR_STATUS_IS_ENOTHREAD */
+#define APR_ENOTHREAD (APR_OS_START_ERROR + 12)
+/** @see APR_STATUS_IS_ENOTHDKEY */
+#define APR_ENOTHDKEY (APR_OS_START_ERROR + 13)
+/** @see APR_STATUS_IS_EGENERAL */
+#define APR_EGENERAL (APR_OS_START_ERROR + 14)
+/** @see APR_STATUS_IS_ENOSHMAVAIL */
+#define APR_ENOSHMAVAIL (APR_OS_START_ERROR + 15)
+/** @see APR_STATUS_IS_EBADIP */
+#define APR_EBADIP (APR_OS_START_ERROR + 16)
+/** @see APR_STATUS_IS_EBADMASK */
+#define APR_EBADMASK (APR_OS_START_ERROR + 17)
+/* empty slot: +18 */
+/** @see APR_STATUS_IS_EDSOPEN */
+#define APR_EDSOOPEN (APR_OS_START_ERROR + 19)
+/** @see APR_STATUS_IS_EABSOLUTE */
+#define APR_EABSOLUTE (APR_OS_START_ERROR + 20)
+/** @see APR_STATUS_IS_ERELATIVE */
+#define APR_ERELATIVE (APR_OS_START_ERROR + 21)
+/** @see APR_STATUS_IS_EINCOMPLETE */
+#define APR_EINCOMPLETE (APR_OS_START_ERROR + 22)
+/** @see APR_STATUS_IS_EABOVEROOT */
+#define APR_EABOVEROOT (APR_OS_START_ERROR + 23)
+/** @see APR_STATUS_IS_EBADPATH */
+#define APR_EBADPATH (APR_OS_START_ERROR + 24)
+/** @see APR_STATUS_IS_EPATHWILD */
+#define APR_EPATHWILD (APR_OS_START_ERROR + 25)
+/** @see APR_STATUS_IS_ESYMNOTFOUND */
+#define APR_ESYMNOTFOUND (APR_OS_START_ERROR + 26)
+/** @see APR_STATUS_IS_EPROC_UNKNOWN */
+#define APR_EPROC_UNKNOWN (APR_OS_START_ERROR + 27)
+/** @see APR_STATUS_IS_ENOTENOUGHENTROPY */
+#define APR_ENOTENOUGHENTROPY (APR_OS_START_ERROR + 28)
+/** @} */
+
+/**
+ * @defgroup APR_STATUS_IS Status Value Tests
+ * @warning For any particular error condition, more than one of these tests
+ * may match. This is because platform-specific error codes may not
+ * always match the semantics of the POSIX codes these tests (and the
+ * corresponding APR error codes) are named after. A notable example
+ * are the APR_STATUS_IS_ENOENT and APR_STATUS_IS_ENOTDIR tests on
+ * Win32 platforms. The programmer should always be aware of this and
+ * adjust the order of the tests accordingly.
+ * @{
+ */
+/**
+ * APR was unable to perform a stat on the file
+ * @warning always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ENOSTAT(s) ((s) == APR_ENOSTAT)
+/**
+ * APR was not provided a pool with which to allocate memory
+ * @warning always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ENOPOOL(s) ((s) == APR_ENOPOOL)
+/** APR was given an invalid date */
+#define APR_STATUS_IS_EBADDATE(s) ((s) == APR_EBADDATE)
+/** APR was given an invalid socket */
+#define APR_STATUS_IS_EINVALSOCK(s) ((s) == APR_EINVALSOCK)
+/** APR was not given a process structure */
+#define APR_STATUS_IS_ENOPROC(s) ((s) == APR_ENOPROC)
+/** APR was not given a time structure */
+#define APR_STATUS_IS_ENOTIME(s) ((s) == APR_ENOTIME)
+/** APR was not given a directory structure */
+#define APR_STATUS_IS_ENODIR(s) ((s) == APR_ENODIR)
+/** APR was not given a lock structure */
+#define APR_STATUS_IS_ENOLOCK(s) ((s) == APR_ENOLOCK)
+/** APR was not given a poll structure */
+#define APR_STATUS_IS_ENOPOLL(s) ((s) == APR_ENOPOLL)
+/** APR was not given a socket */
+#define APR_STATUS_IS_ENOSOCKET(s) ((s) == APR_ENOSOCKET)
+/** APR was not given a thread structure */
+#define APR_STATUS_IS_ENOTHREAD(s) ((s) == APR_ENOTHREAD)
+/** APR was not given a thread key structure */
+#define APR_STATUS_IS_ENOTHDKEY(s) ((s) == APR_ENOTHDKEY)
+/** Generic Error which can not be put into another spot */
+#define APR_STATUS_IS_EGENERAL(s) ((s) == APR_EGENERAL)
+/** There is no more shared memory available */
+#define APR_STATUS_IS_ENOSHMAVAIL(s) ((s) == APR_ENOSHMAVAIL)
+/** The specified IP address is invalid */
+#define APR_STATUS_IS_EBADIP(s) ((s) == APR_EBADIP)
+/** The specified netmask is invalid */
+#define APR_STATUS_IS_EBADMASK(s) ((s) == APR_EBADMASK)
+/* empty slot: +18 */
+/**
+ * APR was unable to open the dso object.
+ * For more information call apr_dso_error().
+ */
+#if defined(WIN32)
+#define APR_STATUS_IS_EDSOOPEN(s) ((s) == APR_EDSOOPEN \
+ || APR_TO_OS_ERROR(s) == ERROR_MOD_NOT_FOUND)
+#else
+#define APR_STATUS_IS_EDSOOPEN(s) ((s) == APR_EDSOOPEN)
+#endif
+/** The given path was absolute. */
+#define APR_STATUS_IS_EABSOLUTE(s) ((s) == APR_EABSOLUTE)
+/** The given path was relative. */
+#define APR_STATUS_IS_ERELATIVE(s) ((s) == APR_ERELATIVE)
+/** The given path was neither relative nor absolute. */
+#define APR_STATUS_IS_EINCOMPLETE(s) ((s) == APR_EINCOMPLETE)
+/** The given path was above the root path. */
+#define APR_STATUS_IS_EABOVEROOT(s) ((s) == APR_EABOVEROOT)
+/** The given path was bad. */
+#define APR_STATUS_IS_EBADPATH(s) ((s) == APR_EBADPATH)
+/** The given path contained wildcards. */
+#define APR_STATUS_IS_EPATHWILD(s) ((s) == APR_EPATHWILD)
+/** Could not find the requested symbol.
+ * For more information call apr_dso_error().
+ */
+#if defined(WIN32)
+#define APR_STATUS_IS_ESYMNOTFOUND(s) ((s) == APR_ESYMNOTFOUND \
+ || APR_TO_OS_ERROR(s) == ERROR_PROC_NOT_FOUND)
+#else
+#define APR_STATUS_IS_ESYMNOTFOUND(s) ((s) == APR_ESYMNOTFOUND)
+#endif
+/** The given process was not recognized by APR. */
+#define APR_STATUS_IS_EPROC_UNKNOWN(s) ((s) == APR_EPROC_UNKNOWN)
+
+/** APR could not gather enough entropy to continue. */
+#define APR_STATUS_IS_ENOTENOUGHENTROPY(s) ((s) == APR_ENOTENOUGHENTROPY)
+
+/** @} */
+
+/**
+ * @addtogroup APR_Error
+ * @{
+ */
+/** @see APR_STATUS_IS_INCHILD */
+#define APR_INCHILD (APR_OS_START_STATUS + 1)
+/** @see APR_STATUS_IS_INPARENT */
+#define APR_INPARENT (APR_OS_START_STATUS + 2)
+/** @see APR_STATUS_IS_DETACH */
+#define APR_DETACH (APR_OS_START_STATUS + 3)
+/** @see APR_STATUS_IS_NOTDETACH */
+#define APR_NOTDETACH (APR_OS_START_STATUS + 4)
+/** @see APR_STATUS_IS_CHILD_DONE */
+#define APR_CHILD_DONE (APR_OS_START_STATUS + 5)
+/** @see APR_STATUS_IS_CHILD_NOTDONE */
+#define APR_CHILD_NOTDONE (APR_OS_START_STATUS + 6)
+/** @see APR_STATUS_IS_TIMEUP */
+#define APR_TIMEUP (APR_OS_START_STATUS + 7)
+/** @see APR_STATUS_IS_INCOMPLETE */
+#define APR_INCOMPLETE (APR_OS_START_STATUS + 8)
+/* empty slot: +9 */
+/* empty slot: +10 */
+/* empty slot: +11 */
+/** @see APR_STATUS_IS_BADCH */
+#define APR_BADCH (APR_OS_START_STATUS + 12)
+/** @see APR_STATUS_IS_BADARG */
+#define APR_BADARG (APR_OS_START_STATUS + 13)
+/** @see APR_STATUS_IS_EOF */
+#define APR_EOF (APR_OS_START_STATUS + 14)
+/** @see APR_STATUS_IS_NOTFOUND */
+#define APR_NOTFOUND (APR_OS_START_STATUS + 15)
+/* empty slot: +16 */
+/* empty slot: +17 */
+/* empty slot: +18 */
+/** @see APR_STATUS_IS_ANONYMOUS */
+#define APR_ANONYMOUS (APR_OS_START_STATUS + 19)
+/** @see APR_STATUS_IS_FILEBASED */
+#define APR_FILEBASED (APR_OS_START_STATUS + 20)
+/** @see APR_STATUS_IS_KEYBASED */
+#define APR_KEYBASED (APR_OS_START_STATUS + 21)
+/** @see APR_STATUS_IS_EINIT */
+#define APR_EINIT (APR_OS_START_STATUS + 22)
+/** @see APR_STATUS_IS_ENOTIMPL */
+#define APR_ENOTIMPL (APR_OS_START_STATUS + 23)
+/** @see APR_STATUS_IS_EMISMATCH */
+#define APR_EMISMATCH (APR_OS_START_STATUS + 24)
+/** @see APR_STATUS_IS_EBUSY */
+#define APR_EBUSY (APR_OS_START_STATUS + 25)
+/** @} */
+
+/**
+ * @addtogroup APR_STATUS_IS
+ * @{
+ */
+/**
+ * Program is currently executing in the child
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code */
+#define APR_STATUS_IS_INCHILD(s) ((s) == APR_INCHILD)
+/**
+ * Program is currently executing in the parent
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_INPARENT(s) ((s) == APR_INPARENT)
+/**
+ * The thread is detached
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_DETACH(s) ((s) == APR_DETACH)
+/**
+ * The thread is not detached
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_NOTDETACH(s) ((s) == APR_NOTDETACH)
+/**
+ * The child has finished executing
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_CHILD_DONE(s) ((s) == APR_CHILD_DONE)
+/**
+ * The child has not finished executing
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_CHILD_NOTDONE(s) ((s) == APR_CHILD_NOTDONE)
+/**
+ * The operation did not finish before the timeout
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP)
+/**
+ * The operation was incomplete although some processing was performed
+ * and the results are partially valid.
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_INCOMPLETE(s) ((s) == APR_INCOMPLETE)
+/* empty slot: +9 */
+/* empty slot: +10 */
+/* empty slot: +11 */
+/**
+ * Getopt found an option not in the option string
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_BADCH(s) ((s) == APR_BADCH)
+/**
+ * Getopt found an option not in the option string and an argument was
+ * specified in the option string
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_BADARG(s) ((s) == APR_BADARG)
+/**
+ * APR has encountered the end of the file
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EOF(s) ((s) == APR_EOF)
+/**
+ * APR was unable to find the socket in the poll structure
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_NOTFOUND(s) ((s) == APR_NOTFOUND)
+/* empty slot: +16 */
+/* empty slot: +17 */
+/* empty slot: +18 */
+/**
+ * APR is using anonymous shared memory
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ANONYMOUS(s) ((s) == APR_ANONYMOUS)
+/**
+ * APR is using a file name as the key to the shared memory
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_FILEBASED(s) ((s) == APR_FILEBASED)
+/**
+ * APR is using a shared key as the key to the shared memory
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_KEYBASED(s) ((s) == APR_KEYBASED)
+/**
+ * Ininitalizer value. If no option has been found, but
+ * the status variable requires a value, this should be used
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EINIT(s) ((s) == APR_EINIT)
+/**
+ * The APR function has not been implemented on this
+ * platform, either because nobody has gotten to it yet,
+ * or the function is impossible on this platform.
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_ENOTIMPL(s) ((s) == APR_ENOTIMPL)
+/**
+ * Two passwords do not match.
+ * @warning
+ * always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EMISMATCH(s) ((s) == APR_EMISMATCH)
+/**
+ * The given lock was busy
+ * @warning always use this test, as platform-specific variances may meet this
+ * more than one error code
+ */
+#define APR_STATUS_IS_EBUSY(s) ((s) == APR_EBUSY)
+
+/** @} */
+
+/**
+ * @addtogroup APR_Error APR Error Values
+ * @{
+ */
+/* APR CANONICAL ERROR VALUES */
+/** @see APR_STATUS_IS_EACCES */
+#ifdef EACCES
+#define APR_EACCES EACCES
+#else
+#define APR_EACCES (APR_OS_START_CANONERR + 1)
+#endif
+
+/** @see APR_STATUS_IS_EXIST */
+#ifdef EEXIST
+#define APR_EEXIST EEXIST
+#else
+#define APR_EEXIST (APR_OS_START_CANONERR + 2)
+#endif
+
+/** @see APR_STATUS_IS_ENAMETOOLONG */
+#ifdef ENAMETOOLONG
+#define APR_ENAMETOOLONG ENAMETOOLONG
+#else
+#define APR_ENAMETOOLONG (APR_OS_START_CANONERR + 3)
+#endif
+
+/** @see APR_STATUS_IS_ENOENT */
+#ifdef ENOENT
+#define APR_ENOENT ENOENT
+#else
+#define APR_ENOENT (APR_OS_START_CANONERR + 4)
+#endif
+
+/** @see APR_STATUS_IS_ENOTDIR */
+#ifdef ENOTDIR
+#define APR_ENOTDIR ENOTDIR
+#else
+#define APR_ENOTDIR (APR_OS_START_CANONERR + 5)
+#endif
+
+/** @see APR_STATUS_IS_ENOSPC */
+#ifdef ENOSPC
+#define APR_ENOSPC ENOSPC
+#else
+#define APR_ENOSPC (APR_OS_START_CANONERR + 6)
+#endif
+
+/** @see APR_STATUS_IS_ENOMEM */
+#ifdef ENOMEM
+#define APR_ENOMEM ENOMEM
+#else
+#define APR_ENOMEM (APR_OS_START_CANONERR + 7)
+#endif
+
+/** @see APR_STATUS_IS_EMFILE */
+#ifdef EMFILE
+#define APR_EMFILE EMFILE
+#else
+#define APR_EMFILE (APR_OS_START_CANONERR + 8)
+#endif
+
+/** @see APR_STATUS_IS_ENFILE */
+#ifdef ENFILE
+#define APR_ENFILE ENFILE
+#else
+#define APR_ENFILE (APR_OS_START_CANONERR + 9)
+#endif
+
+/** @see APR_STATUS_IS_EBADF */
+#ifdef EBADF
+#define APR_EBADF EBADF
+#else
+#define APR_EBADF (APR_OS_START_CANONERR + 10)
+#endif
+
+/** @see APR_STATUS_IS_EINVAL */
+#ifdef EINVAL
+#define APR_EINVAL EINVAL
+#else
+#define APR_EINVAL (APR_OS_START_CANONERR + 11)
+#endif
+
+/** @see APR_STATUS_IS_ESPIPE */
+#ifdef ESPIPE
+#define APR_ESPIPE ESPIPE
+#else
+#define APR_ESPIPE (APR_OS_START_CANONERR + 12)
+#endif
+
+/**
+ * @see APR_STATUS_IS_EAGAIN
+ * @warning use APR_STATUS_IS_EAGAIN instead of just testing this value
+ */
+#ifdef EAGAIN
+#define APR_EAGAIN EAGAIN
+#elif defined(EWOULDBLOCK)
+#define APR_EAGAIN EWOULDBLOCK
+#else
+#define APR_EAGAIN (APR_OS_START_CANONERR + 13)
+#endif
+
+/** @see APR_STATUS_IS_EINTR */
+#ifdef EINTR
+#define APR_EINTR EINTR
+#else
+#define APR_EINTR (APR_OS_START_CANONERR + 14)
+#endif
+
+/** @see APR_STATUS_IS_ENOTSOCK */
+#ifdef ENOTSOCK
+#define APR_ENOTSOCK ENOTSOCK
+#else
+#define APR_ENOTSOCK (APR_OS_START_CANONERR + 15)
+#endif
+
+/** @see APR_STATUS_IS_ECONNREFUSED */
+#ifdef ECONNREFUSED
+#define APR_ECONNREFUSED ECONNREFUSED
+#else
+#define APR_ECONNREFUSED (APR_OS_START_CANONERR + 16)
+#endif
+
+/** @see APR_STATUS_IS_EINPROGRESS */
+#ifdef EINPROGRESS
+#define APR_EINPROGRESS EINPROGRESS
+#else
+#define APR_EINPROGRESS (APR_OS_START_CANONERR + 17)
+#endif
+
+/**
+ * @see APR_STATUS_IS_ECONNABORTED
+ * @warning use APR_STATUS_IS_ECONNABORTED instead of just testing this value
+ */
+
+#ifdef ECONNABORTED
+#define APR_ECONNABORTED ECONNABORTED
+#else
+#define APR_ECONNABORTED (APR_OS_START_CANONERR + 18)
+#endif
+
+/** @see APR_STATUS_IS_ECONNRESET */
+#ifdef ECONNRESET
+#define APR_ECONNRESET ECONNRESET
+#else
+#define APR_ECONNRESET (APR_OS_START_CANONERR + 19)
+#endif
+
+/** @see APR_STATUS_IS_ETIMEDOUT
+ * @deprecated */
+#ifdef ETIMEDOUT
+#define APR_ETIMEDOUT ETIMEDOUT
+#else
+#define APR_ETIMEDOUT (APR_OS_START_CANONERR + 20)
+#endif
+
+/** @see APR_STATUS_IS_EHOSTUNREACH */
+#ifdef EHOSTUNREACH
+#define APR_EHOSTUNREACH EHOSTUNREACH
+#else
+#define APR_EHOSTUNREACH (APR_OS_START_CANONERR + 21)
+#endif
+
+/** @see APR_STATUS_IS_ENETUNREACH */
+#ifdef ENETUNREACH
+#define APR_ENETUNREACH ENETUNREACH
+#else
+#define APR_ENETUNREACH (APR_OS_START_CANONERR + 22)
+#endif
+
+/** @see APR_STATUS_IS_EFTYPE */
+#ifdef EFTYPE
+#define APR_EFTYPE EFTYPE
+#else
+#define APR_EFTYPE (APR_OS_START_CANONERR + 23)
+#endif
+
+/** @see APR_STATUS_IS_EPIPE */
+#ifdef EPIPE
+#define APR_EPIPE EPIPE
+#else
+#define APR_EPIPE (APR_OS_START_CANONERR + 24)
+#endif
+
+/** @see APR_STATUS_IS_EXDEV */
+#ifdef EXDEV
+#define APR_EXDEV EXDEV
+#else
+#define APR_EXDEV (APR_OS_START_CANONERR + 25)
+#endif
+
+/** @see APR_STATUS_IS_ENOTEMPTY */
+#ifdef ENOTEMPTY
+#define APR_ENOTEMPTY ENOTEMPTY
+#else
+#define APR_ENOTEMPTY (APR_OS_START_CANONERR + 26)
+#endif
+
+/** @} */
+
+#if defined(OS2) && !defined(DOXYGEN)
+
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+#define INCL_DOSERRORS
+#define INCL_DOS
+
+/* Leave these undefined.
+ * OS2 doesn't rely on the errno concept.
+ * The API calls always return a result codes which
+ * should be filtered through APR_FROM_OS_ERROR().
+ *
+ * #define apr_get_os_error() (APR_FROM_OS_ERROR(GetLastError()))
+ * #define apr_set_os_error(e) (SetLastError(APR_TO_OS_ERROR(e)))
+ */
+
+/* A special case, only socket calls require this;
+ */
+#define apr_get_netos_error() (APR_FROM_OS_ERROR(errno))
+#define apr_set_netos_error(e) (errno = APR_TO_OS_ERROR(e))
+
+/* And this needs to be greped away for good:
+ */
+#define APR_OS2_STATUS(e) (APR_FROM_OS_ERROR(e))
+
+/* These can't sit in a private header, so in spite of the extra size,
+ * they need to be made available here.
+ */
+#define SOCBASEERR 10000
+#define SOCEPERM (SOCBASEERR+1) /* Not owner */
+#define SOCESRCH (SOCBASEERR+3) /* No such process */
+#define SOCEINTR (SOCBASEERR+4) /* Interrupted system call */
+#define SOCENXIO (SOCBASEERR+6) /* No such device or address */
+#define SOCEBADF (SOCBASEERR+9) /* Bad file number */
+#define SOCEACCES (SOCBASEERR+13) /* Permission denied */
+#define SOCEFAULT (SOCBASEERR+14) /* Bad address */
+#define SOCEINVAL (SOCBASEERR+22) /* Invalid argument */
+#define SOCEMFILE (SOCBASEERR+24) /* Too many open files */
+#define SOCEPIPE (SOCBASEERR+32) /* Broken pipe */
+#define SOCEOS2ERR (SOCBASEERR+100) /* OS/2 Error */
+#define SOCEWOULDBLOCK (SOCBASEERR+35) /* Operation would block */
+#define SOCEINPROGRESS (SOCBASEERR+36) /* Operation now in progress */
+#define SOCEALREADY (SOCBASEERR+37) /* Operation already in progress */
+#define SOCENOTSOCK (SOCBASEERR+38) /* Socket operation on non-socket */
+#define SOCEDESTADDRREQ (SOCBASEERR+39) /* Destination address required */
+#define SOCEMSGSIZE (SOCBASEERR+40) /* Message too long */
+#define SOCEPROTOTYPE (SOCBASEERR+41) /* Protocol wrong type for socket */
+#define SOCENOPROTOOPT (SOCBASEERR+42) /* Protocol not available */
+#define SOCEPROTONOSUPPORT (SOCBASEERR+43) /* Protocol not supported */
+#define SOCESOCKTNOSUPPORT (SOCBASEERR+44) /* Socket type not supported */
+#define SOCEOPNOTSUPP (SOCBASEERR+45) /* Operation not supported on socket */
+#define SOCEPFNOSUPPORT (SOCBASEERR+46) /* Protocol family not supported */
+#define SOCEAFNOSUPPORT (SOCBASEERR+47) /* Address family not supported by protocol family */
+#define SOCEADDRINUSE (SOCBASEERR+48) /* Address already in use */
+#define SOCEADDRNOTAVAIL (SOCBASEERR+49) /* Can't assign requested address */
+#define SOCENETDOWN (SOCBASEERR+50) /* Network is down */
+#define SOCENETUNREACH (SOCBASEERR+51) /* Network is unreachable */
+#define SOCENETRESET (SOCBASEERR+52) /* Network dropped connection on reset */
+#define SOCECONNABORTED (SOCBASEERR+53) /* Software caused connection abort */
+#define SOCECONNRESET (SOCBASEERR+54) /* Connection reset by peer */
+#define SOCENOBUFS (SOCBASEERR+55) /* No buffer space available */
+#define SOCEISCONN (SOCBASEERR+56) /* Socket is already connected */
+#define SOCENOTCONN (SOCBASEERR+57) /* Socket is not connected */
+#define SOCESHUTDOWN (SOCBASEERR+58) /* Can't send after socket shutdown */
+#define SOCETOOMANYREFS (SOCBASEERR+59) /* Too many references: can't splice */
+#define SOCETIMEDOUT (SOCBASEERR+60) /* Connection timed out */
+#define SOCECONNREFUSED (SOCBASEERR+61) /* Connection refused */
+#define SOCELOOP (SOCBASEERR+62) /* Too many levels of symbolic links */
+#define SOCENAMETOOLONG (SOCBASEERR+63) /* File name too long */
+#define SOCEHOSTDOWN (SOCBASEERR+64) /* Host is down */
+#define SOCEHOSTUNREACH (SOCBASEERR+65) /* No route to host */
+#define SOCENOTEMPTY (SOCBASEERR+66) /* Directory not empty */
+
+/* APR CANONICAL ERROR TESTS */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED \
+ || (s) == APR_OS_START_SYSERR + ERROR_SHARING_VIOLATION)
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST \
+ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_EXISTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_ALREADY_EXISTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED)
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILENAME_EXCED_RANGE \
+ || (s) == APR_OS_START_SYSERR + SOCENAMETOOLONG)
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_MORE_FILES \
+ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED)
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR)
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \
+ || (s) == APR_OS_START_SYSERR + ERROR_DISK_FULL)
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM)
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE \
+ || (s) == APR_OS_START_SYSERR + ERROR_TOO_MANY_OPEN_FILES)
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE)
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_PARAMETER \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_FUNCTION)
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA \
+ || (s) == APR_OS_START_SYSERR + SOCEWOULDBLOCK \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION)
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \
+ || (s) == APR_OS_START_SYSERR + SOCEINTR)
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \
+ || (s) == APR_OS_START_SYSERR + SOCENOTSOCK)
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \
+ || (s) == APR_OS_START_SYSERR + SOCECONNREFUSED)
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \
+ || (s) == APR_OS_START_SYSERR + SOCEINPROGRESS)
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == APR_OS_START_SYSERR + SOCECONNABORTED)
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \
+ || (s) == APR_OS_START_SYSERR + SOCECONNRESET)
+/* XXX deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + SOCETIMEDOUT)
+#undef APR_STATUS_IS_TIMEUP
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \
+ || (s) == APR_OS_START_SYSERR + SOCETIMEDOUT)
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \
+ || (s) == APR_OS_START_SYSERR + SOCEHOSTUNREACH)
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \
+ || (s) == APR_OS_START_SYSERR + SOCENETUNREACH)
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE)
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_BROKEN_PIPE \
+ || (s) == APR_OS_START_SYSERR + SOCEPIPE)
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_SAME_DEVICE)
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY \
+ || (s) == APR_OS_START_SYSERR + ERROR_DIR_NOT_EMPTY \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED)
+
+/*
+ Sorry, too tired to wrap this up for OS2... feel free to
+ fit the following into their best matches.
+
+ { ERROR_NO_SIGNAL_SENT, ESRCH },
+ { SOCEALREADY, EALREADY },
+ { SOCEDESTADDRREQ, EDESTADDRREQ },
+ { SOCEMSGSIZE, EMSGSIZE },
+ { SOCEPROTOTYPE, EPROTOTYPE },
+ { SOCENOPROTOOPT, ENOPROTOOPT },
+ { SOCEPROTONOSUPPORT, EPROTONOSUPPORT },
+ { SOCESOCKTNOSUPPORT, ESOCKTNOSUPPORT },
+ { SOCEOPNOTSUPP, EOPNOTSUPP },
+ { SOCEPFNOSUPPORT, EPFNOSUPPORT },
+ { SOCEAFNOSUPPORT, EAFNOSUPPORT },
+ { SOCEADDRINUSE, EADDRINUSE },
+ { SOCEADDRNOTAVAIL, EADDRNOTAVAIL },
+ { SOCENETDOWN, ENETDOWN },
+ { SOCENETRESET, ENETRESET },
+ { SOCENOBUFS, ENOBUFS },
+ { SOCEISCONN, EISCONN },
+ { SOCENOTCONN, ENOTCONN },
+ { SOCESHUTDOWN, ESHUTDOWN },
+ { SOCETOOMANYREFS, ETOOMANYREFS },
+ { SOCELOOP, ELOOP },
+ { SOCEHOSTDOWN, EHOSTDOWN },
+ { SOCENOTEMPTY, ENOTEMPTY },
+ { SOCEPIPE, EPIPE }
+*/
+
+#elif defined(WIN32) && !defined(DOXYGEN) /* !defined(OS2) */
+
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+#define apr_get_os_error() (APR_FROM_OS_ERROR(GetLastError()))
+#define apr_set_os_error(e) (SetLastError(APR_TO_OS_ERROR(e)))
+
+/* A special case, only socket calls require this:
+ */
+#define apr_get_netos_error() (APR_FROM_OS_ERROR(WSAGetLastError()))
+#define apr_set_netos_error(e) (WSASetLastError(APR_TO_OS_ERROR(e)))
+
+/* APR CANONICAL ERROR TESTS */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES \
+ || (s) == APR_OS_START_SYSERR + ERROR_ACCESS_DENIED \
+ || (s) == APR_OS_START_SYSERR + ERROR_CANNOT_MAKE \
+ || (s) == APR_OS_START_SYSERR + ERROR_CURRENT_DIRECTORY \
+ || (s) == APR_OS_START_SYSERR + ERROR_DRIVE_LOCKED \
+ || (s) == APR_OS_START_SYSERR + ERROR_FAIL_I24 \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_FAILED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_LOCKED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NETWORK_ACCESS_DENIED \
+ || (s) == APR_OS_START_SYSERR + ERROR_SHARING_VIOLATION)
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_EXISTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_ALREADY_EXISTS)
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILENAME_EXCED_RANGE \
+ || (s) == APR_OS_START_SYSERR + WSAENAMETOOLONG)
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_OPEN_FAILED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_MORE_FILES)
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR \
+ || (s) == APR_OS_START_SYSERR + ERROR_PATH_NOT_FOUND \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_NETPATH \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_NET_NAME \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_PATHNAME \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DRIVE)
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \
+ || (s) == APR_OS_START_SYSERR + ERROR_DISK_FULL)
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM \
+ || (s) == APR_OS_START_SYSERR + ERROR_ARENA_TRASHED \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_ENOUGH_MEMORY \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_BLOCK \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_ENOUGH_QUOTA \
+ || (s) == APR_OS_START_SYSERR + ERROR_OUTOFMEMORY)
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE \
+ || (s) == APR_OS_START_SYSERR + ERROR_TOO_MANY_OPEN_FILES)
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_TARGET_HANDLE)
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_ACCESS \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DATA \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_FUNCTION \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_HANDLE \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_PARAMETER \
+ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK)
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_SEEK_ON_DEVICE \
+ || (s) == APR_OS_START_SYSERR + ERROR_NEGATIVE_SEEK)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_DATA \
+ || (s) == APR_OS_START_SYSERR + ERROR_NO_PROC_SLOTS \
+ || (s) == APR_OS_START_SYSERR + ERROR_NESTING_NOT_ALLOWED \
+ || (s) == APR_OS_START_SYSERR + ERROR_MAX_THRDS_REACHED \
+ || (s) == APR_OS_START_SYSERR + ERROR_LOCK_VIOLATION \
+ || (s) == APR_OS_START_SYSERR + WSAEWOULDBLOCK)
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \
+ || (s) == APR_OS_START_SYSERR + WSAEINTR)
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \
+ || (s) == APR_OS_START_SYSERR + WSAENOTSOCK)
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNREFUSED)
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \
+ || (s) == APR_OS_START_SYSERR + WSAEINPROGRESS)
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNABORTED)
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \
+ || (s) == APR_OS_START_SYSERR + ERROR_NETNAME_DELETED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNRESET)
+/* XXX deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#undef APR_STATUS_IS_TIMEUP
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAEHOSTUNREACH)
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAENETUNREACH)
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_EXE_MACHINE_TYPE_MISMATCH \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_DLL \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_MODULETYPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_EXE_FORMAT \
+ || (s) == APR_OS_START_SYSERR + ERROR_INVALID_EXE_SIGNATURE \
+ || (s) == APR_OS_START_SYSERR + ERROR_FILE_CORRUPT \
+ || (s) == APR_OS_START_SYSERR + ERROR_BAD_FORMAT)
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE \
+ || (s) == APR_OS_START_SYSERR + ERROR_BROKEN_PIPE)
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV \
+ || (s) == APR_OS_START_SYSERR + ERROR_NOT_SAME_DEVICE)
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY \
+ || (s) == APR_OS_START_SYSERR + ERROR_DIR_NOT_EMPTY)
+
+#elif defined(NETWARE) && defined(USE_WINSOCK) && !defined(DOXYGEN) /* !defined(OS2) && !defined(WIN32) */
+
+#define APR_FROM_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
+#define APR_TO_OS_ERROR(e) (e == 0 ? APR_SUCCESS : e - APR_OS_START_SYSERR)
+
+#define apr_get_os_error() (errno)
+#define apr_set_os_error(e) (errno = (e))
+
+/* A special case, only socket calls require this: */
+#define apr_get_netos_error() (APR_FROM_OS_ERROR(WSAGetLastError()))
+#define apr_set_netos_error(e) (WSASetLastError(APR_TO_OS_ERROR(e)))
+
+/* APR CANONICAL ERROR TESTS */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES)
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST)
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG)
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT)
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR)
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC)
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM)
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE)
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF)
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL)
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE)
+
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == EWOULDBLOCK \
+ || (s) == APR_OS_START_SYSERR + WSAEWOULDBLOCK)
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR \
+ || (s) == APR_OS_START_SYSERR + WSAEINTR)
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK \
+ || (s) == APR_OS_START_SYSERR + WSAENOTSOCK)
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNREFUSED)
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS \
+ || (s) == APR_OS_START_SYSERR + WSAEINPROGRESS)
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == APR_OS_START_SYSERR + WSAECONNABORTED)
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET \
+ || (s) == APR_OS_START_SYSERR + WSAECONNRESET)
+/* XXX deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#undef APR_STATUS_IS_TIMEUP
+#define APR_STATUS_IS_TIMEUP(s) ((s) == APR_TIMEUP \
+ || (s) == APR_OS_START_SYSERR + WSAETIMEDOUT \
+ || (s) == APR_OS_START_SYSERR + WAIT_TIMEOUT)
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAEHOSTUNREACH)
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH \
+ || (s) == APR_OS_START_SYSERR + WSAENETUNREACH)
+#define APR_STATUS_IS_ENETDOWN(s) ((s) == APR_OS_START_SYSERR + WSAENETDOWN)
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE)
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE)
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV)
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY)
+
+#else /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */
+
+/*
+ * os error codes are clib error codes
+ */
+#define APR_FROM_OS_ERROR(e) (e)
+#define APR_TO_OS_ERROR(e) (e)
+
+#define apr_get_os_error() (errno)
+#define apr_set_os_error(e) (errno = (e))
+
+/* A special case, only socket calls require this:
+ */
+#define apr_get_netos_error() (errno)
+#define apr_set_netos_error(e) (errno = (e))
+
+/**
+ * @addtogroup APR_STATUS_IS
+ * @{
+ */
+
+/** permission denied */
+#define APR_STATUS_IS_EACCES(s) ((s) == APR_EACCES)
+/** file exists */
+#define APR_STATUS_IS_EEXIST(s) ((s) == APR_EEXIST)
+/** path name is too long */
+#define APR_STATUS_IS_ENAMETOOLONG(s) ((s) == APR_ENAMETOOLONG)
+/**
+ * no such file or directory
+ * @remark
+ * EMVSCATLG can be returned by the automounter on z/OS for
+ * paths which do not exist.
+ */
+#ifdef EMVSCATLG
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT \
+ || (s) == EMVSCATLG)
+#else
+#define APR_STATUS_IS_ENOENT(s) ((s) == APR_ENOENT)
+#endif
+/** not a directory */
+#define APR_STATUS_IS_ENOTDIR(s) ((s) == APR_ENOTDIR)
+/** no space left on device */
+#ifdef EDQUOT
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC \
+ || (s) == EDQUOT)
+#else
+#define APR_STATUS_IS_ENOSPC(s) ((s) == APR_ENOSPC)
+#endif
+/** not enough memory */
+#define APR_STATUS_IS_ENOMEM(s) ((s) == APR_ENOMEM)
+/** too many open files */
+#define APR_STATUS_IS_EMFILE(s) ((s) == APR_EMFILE)
+/** file table overflow */
+#define APR_STATUS_IS_ENFILE(s) ((s) == APR_ENFILE)
+/** bad file # */
+#define APR_STATUS_IS_EBADF(s) ((s) == APR_EBADF)
+/** invalid argument */
+#define APR_STATUS_IS_EINVAL(s) ((s) == APR_EINVAL)
+/** illegal seek */
+#define APR_STATUS_IS_ESPIPE(s) ((s) == APR_ESPIPE)
+
+/** operation would block */
+#if !defined(EWOULDBLOCK) || !defined(EAGAIN)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN)
+#elif (EWOULDBLOCK == EAGAIN)
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN)
+#else
+#define APR_STATUS_IS_EAGAIN(s) ((s) == APR_EAGAIN \
+ || (s) == EWOULDBLOCK)
+#endif
+
+/** interrupted system call */
+#define APR_STATUS_IS_EINTR(s) ((s) == APR_EINTR)
+/** socket operation on a non-socket */
+#define APR_STATUS_IS_ENOTSOCK(s) ((s) == APR_ENOTSOCK)
+/** Connection Refused */
+#define APR_STATUS_IS_ECONNREFUSED(s) ((s) == APR_ECONNREFUSED)
+/** operation now in progress */
+#define APR_STATUS_IS_EINPROGRESS(s) ((s) == APR_EINPROGRESS)
+
+/**
+ * Software caused connection abort
+ * @remark
+ * EPROTO on certain older kernels really means ECONNABORTED, so we need to
+ * ignore it for them. See discussion in new-httpd archives nh.9701 & nh.9603
+ *
+ * There is potentially a bug in Solaris 2.x x<6, and other boxes that
+ * implement tcp sockets in userland (i.e. on top of STREAMS). On these
+ * systems, EPROTO can actually result in a fatal loop. See PR#981 for
+ * example. It's hard to handle both uses of EPROTO.
+ */
+#ifdef EPROTO
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED \
+ || (s) == EPROTO)
+#else
+#define APR_STATUS_IS_ECONNABORTED(s) ((s) == APR_ECONNABORTED)
+#endif
+
+/** Connection Reset by peer */
+#define APR_STATUS_IS_ECONNRESET(s) ((s) == APR_ECONNRESET)
+/** Operation timed out
+ * @deprecated */
+#define APR_STATUS_IS_ETIMEDOUT(s) ((s) == APR_ETIMEDOUT)
+/** no route to host */
+#define APR_STATUS_IS_EHOSTUNREACH(s) ((s) == APR_EHOSTUNREACH)
+/** network is unreachable */
+#define APR_STATUS_IS_ENETUNREACH(s) ((s) == APR_ENETUNREACH)
+/** inappropiate file type or format */
+#define APR_STATUS_IS_EFTYPE(s) ((s) == APR_EFTYPE)
+/** broken pipe */
+#define APR_STATUS_IS_EPIPE(s) ((s) == APR_EPIPE)
+/** cross device link */
+#define APR_STATUS_IS_EXDEV(s) ((s) == APR_EXDEV)
+/** Directory Not Empty */
+#define APR_STATUS_IS_ENOTEMPTY(s) ((s) == APR_ENOTEMPTY || \
+ (s) == APR_EEXIST)
+/** @} */
+
+#endif /* !defined(NETWARE) && !defined(OS2) && !defined(WIN32) */
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ! APR_ERRNO_H */
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include <sys/errno.h>
+
+
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ *
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ */
+/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)errno.h 8.5 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_ERRNO_H_
+#define _SYS_ERRNO_H_
+
+#include <sys/cdefs.h>
+__BEGIN_DECLS
+extern int * __error(void);
+#define errno (*__error())
+__END_DECLS
+
+/*
+ * Error codes
+ */
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* Input/output error */
+#define ENXIO 6 /* Device not configured */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file descriptor */
+#define ECHILD 10 /* No child processes */
+#define EDEADLK 11 /* Resource deadlock avoided */
+ /* 11 was EAGAIN */
+#define ENOMEM 12 /* Cannot allocate memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define ENOTBLK 15 /* Block device required */
+#endif
+#define EBUSY 16 /* Device / Resource busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* Operation not supported by device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* Too many open files in system */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+
+/* math software */
+#define EDOM 33 /* Numerical argument out of domain */
+#define ERANGE 34 /* Result too large */
+
+/* non-blocking and interrupt i/o */
+#define EAGAIN 35 /* Resource temporarily unavailable */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define EINPROGRESS 36 /* Operation now in progress */
+#define EALREADY 37 /* Operation already in progress */
+
+/* ipc/network software -- argument errors */
+#define ENOTSOCK 38 /* Socket operation on non-socket */
+#define EDESTADDRREQ 39 /* Destination address required */
+#define EMSGSIZE 40 /* Message too long */
+#define EPROTOTYPE 41 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 42 /* Protocol not available */
+#define EPROTONOSUPPORT 43 /* Protocol not supported */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
+#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
+#define ENOTSUP 45 /* Operation not supported */
+#if !__DARWIN_UNIX03 && !defined(KERNEL)
+/*
+ * This is the same for binary and source copmpatability, unless compiling
+ * the kernel itself, or compiling __DARWIN_UNIX03; if compiling for the
+ * kernel, the correct value will be returned. If compiling non-POSIX
+ * source, the kernel return value will be converted by a stub in libc, and
+ * if compiling source with __DARWIN_UNIX03, the conversion in libc is not
+ * done, and the caller gets the expected (discrete) value.
+ */
+#define EOPNOTSUPP ENOTSUP /* Operation not supported on socket */
+#endif /* !__DARWIN_UNIX03 && !KERNEL */
+
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define EPFNOSUPPORT 46 /* Protocol family not supported */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
+#define EADDRINUSE 48 /* Address already in use */
+#define EADDRNOTAVAIL 49 /* Can't assign requested address */
+
+/* ipc/network software -- operational errors */
+#define ENETDOWN 50 /* Network is down */
+#define ENETUNREACH 51 /* Network is unreachable */
+#define ENETRESET 52 /* Network dropped connection on reset */
+#define ECONNABORTED 53 /* Software caused connection abort */
+#define ECONNRESET 54 /* Connection reset by peer */
+#define ENOBUFS 55 /* No buffer space available */
+#define EISCONN 56 /* Socket is already connected */
+#define ENOTCONN 57 /* Socket is not connected */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define ESHUTDOWN 58 /* Can't send after socket shutdown */
+#define ETOOMANYREFS 59 /* Too many references: can't splice */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+#define ETIMEDOUT 60 /* Operation timed out */
+#define ECONNREFUSED 61 /* Connection refused */
+
+#define ELOOP 62 /* Too many levels of symbolic links */
+#define ENAMETOOLONG 63 /* File name too long */
+
+/* should be rearranged */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define EHOSTDOWN 64 /* Host is down */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+#define EHOSTUNREACH 65 /* No route to host */
+#define ENOTEMPTY 66 /* Directory not empty */
+
+/* quotas & mush */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define EPROCLIM 67 /* Too many processes */
+#define EUSERS 68 /* Too many users */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+#define EDQUOT 69 /* Disc quota exceeded */
+
+/* Network File System */
+#define ESTALE 70 /* Stale NFS file handle */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define EREMOTE 71 /* Too many levels of remote in path */
+#define EBADRPC 72 /* RPC struct is bad */
+#define ERPCMISMATCH 73 /* RPC version wrong */
+#define EPROGUNAVAIL 74 /* RPC prog. not avail */
+#define EPROGMISMATCH 75 /* Program version wrong */
+#define EPROCUNAVAIL 76 /* Bad procedure for program */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+
+#define ENOLCK 77 /* No locks available */
+#define ENOSYS 78 /* Function not implemented */
+
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define EFTYPE 79 /* Inappropriate file type or format */
+#define EAUTH 80 /* Authentication error */
+#define ENEEDAUTH 81 /* Need authenticator */
+
+/* Intelligent device errors */
+#define EPWROFF 82 /* Device power is off */
+#define EDEVERR 83 /* Device error, e.g. paper out */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+
+#define EOVERFLOW 84 /* Value too large to be stored in data type */
+
+/* Program loading errors */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define EBADEXEC 85 /* Bad executable */
+#define EBADARCH 86 /* Bad CPU type in executable */
+#define ESHLIBVERS 87 /* Shared library version mismatch */
+#define EBADMACHO 88 /* Malformed Macho file */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+
+#define ECANCELED 89 /* Operation canceled */
+
+#define EIDRM 90 /* Identifier removed */
+#define ENOMSG 91 /* No message of desired type */
+#define EILSEQ 92 /* Illegal byte sequence */
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define ENOATTR 93 /* Attribute not found */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+
+#define EBADMSG 94 /* Bad message */
+#define EMULTIHOP 95 /* Reserved */
+#define ENODATA 96 /* No message available on STREAM */
+#define ENOLINK 97 /* Reserved */
+#define ENOSR 98 /* No STREAM resources */
+#define ENOSTR 99 /* Not a STREAM */
+#define EPROTO 100 /* Protocol error */
+#define ETIME 101 /* STREAM ioctl timeout */
+
+#if __DARWIN_UNIX03 || defined(KERNEL)
+/* This value is only discrete when compiling __DARWIN_UNIX03, or KERNEL */
+#define EOPNOTSUPP 102 /* Operation not supported on socket */
+#endif /* __DARWIN_UNIX03 || KERNEL */
+
+#define ENOPOLICY 103 /* No such policy registered */
+
+#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
+#define ELAST 103 /* Must be equal largest errno */
+#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
+
+#endif /* _SYS_ERRNO_H_ */
diff --git a/doc/errno.list.solaris.txt b/doc/errno.list.solaris.txt
new file mode 100644
index 000000000..23601e9d3
--- /dev/null
+++ b/doc/errno.list.solaris.txt
@@ -0,0 +1,206 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (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 2000 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#ifndef _SYS_ERRNO_H
+#define _SYS_ERRNO_H
+
+#pragma ident "@(#)errno.h 1.22 05/06/08 SMI"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Error codes
+ */
+
+#define EPERM 1 /* Not super-user */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* interrupted system call */
+#define EIO 5 /* I/O error */
+#define ENXIO 6 /* No such device or address */
+#define E2BIG 7 /* Arg list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file number */
+#define ECHILD 10 /* No children */
+#define EAGAIN 11 /* Resource temporarily unavailable */
+#define ENOMEM 12 /* Not enough core */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#define ENOTBLK 15 /* Block device required */
+#define EBUSY 16 /* Mount device busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* No such device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* File table overflow */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+#define EDOM 33 /* Math arg out of domain of func */
+#define ERANGE 34 /* Math result not representable */
+#define ENOMSG 35 /* No message of desired type */
+#define EIDRM 36 /* Identifier removed */
+#define ECHRNG 37 /* Channel number out of range */
+#define EL2NSYNC 38 /* Level 2 not synchronized */
+#define EL3HLT 39 /* Level 3 halted */
+#define EL3RST 40 /* Level 3 reset */
+#define ELNRNG 41 /* Link number out of range */
+#define EUNATCH 42 /* Protocol driver not attached */
+#define ENOCSI 43 /* No CSI structure available */
+#define EL2HLT 44 /* Level 2 halted */
+#define EDEADLK 45 /* Deadlock condition. */
+#define ENOLCK 46 /* No record locks available. */
+#define ECANCELED 47 /* Operation canceled */
+#define ENOTSUP 48 /* Operation not supported */
+
+/* Filesystem Quotas */
+#define EDQUOT 49 /* Disc quota exceeded */
+
+/* Convergent Error Returns */
+#define EBADE 50 /* invalid exchange */
+#define EBADR 51 /* invalid request descriptor */
+#define EXFULL 52 /* exchange full */
+#define ENOANO 53 /* no anode */
+#define EBADRQC 54 /* invalid request code */
+#define EBADSLT 55 /* invalid slot */
+#define EDEADLOCK 56 /* file locking deadlock error */
+
+#define EBFONT 57 /* bad font file fmt */
+
+/* Interprocess Robust Locks */
+#define EOWNERDEAD 58 /* process died with the lock */
+#define ENOTRECOVERABLE 59 /* lock is not recoverable */
+
+/* stream problems */
+#define ENOSTR 60 /* Device not a stream */
+#define ENODATA 61 /* no data (for no delay io) */
+#define ETIME 62 /* timer expired */
+#define ENOSR 63 /* out of streams resources */
+
+#define ENONET 64 /* Machine is not on the network */
+#define ENOPKG 65 /* Package not installed */
+#define EREMOTE 66 /* The object is remote */
+#define ENOLINK 67 /* the link has been severed */
+#define EADV 68 /* advertise error */
+#define ESRMNT 69 /* srmount error */
+
+#define ECOMM 70 /* Communication error on send */
+#define EPROTO 71 /* Protocol error */
+
+/* Interprocess Robust Locks */
+#define ELOCKUNMAPPED 72 /* locked lock was unmapped */
+
+#define ENOTACTIVE 73 /* Facility is not active */
+#define EMULTIHOP 74 /* multihop attempted */
+#define EBADMSG 77 /* trying to read unreadable message */
+#define ENAMETOOLONG 78 /* path name is too long */
+#define EOVERFLOW 79 /* value too large to be stored in data type */
+#define ENOTUNIQ 80 /* given log. name not unique */
+#define EBADFD 81 /* f.d. invalid for this operation */
+#define EREMCHG 82 /* Remote address changed */
+
+/* shared library problems */
+#define ELIBACC 83 /* Can't access a needed shared lib. */
+#define ELIBBAD 84 /* Accessing a corrupted shared lib. */
+#define ELIBSCN 85 /* .lib section in a.out corrupted. */
+#define ELIBMAX 86 /* Attempting to link in too many libs. */
+#define ELIBEXEC 87 /* Attempting to exec a shared library. */
+#define EILSEQ 88 /* Illegal byte sequence. */
+#define ENOSYS 89 /* Unsupported file system operation */
+#define ELOOP 90 /* Symbolic link loop */
+#define ERESTART 91 /* Restartable system call */
+#define ESTRPIPE 92 /* if pipe/FIFO, don't sleep in stream head */
+#define ENOTEMPTY 93 /* directory not empty */
+#define EUSERS 94 /* Too many users (for UFS) */
+
+/* BSD Networking Software */
+ /* argument errors */
+#define ENOTSOCK 95 /* Socket operation on non-socket */
+#define EDESTADDRREQ 96 /* Destination address required */
+#define EMSGSIZE 97 /* Message too long */
+#define EPROTOTYPE 98 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 99 /* Protocol not available */
+#define EPROTONOSUPPORT 120 /* Protocol not supported */
+#define ESOCKTNOSUPPORT 121 /* Socket type not supported */
+#define EOPNOTSUPP 122 /* Operation not supported on socket */
+#define EPFNOSUPPORT 123 /* Protocol family not supported */
+#define EAFNOSUPPORT 124 /* Address family not supported by */
+ /* protocol family */
+#define EADDRINUSE 125 /* Address already in use */
+#define EADDRNOTAVAIL 126 /* Can't assign requested address */
+ /* operational errors */
+#define ENETDOWN 127 /* Network is down */
+#define ENETUNREACH 128 /* Network is unreachable */
+#define ENETRESET 129 /* Network dropped connection because */
+ /* of reset */
+#define ECONNABORTED 130 /* Software caused connection abort */
+#define ECONNRESET 131 /* Connection reset by peer */
+#define ENOBUFS 132 /* No buffer space available */
+#define EISCONN 133 /* Socket is already connected */
+#define ENOTCONN 134 /* Socket is not connected */
+/* XENIX has 135 - 142 */
+#define ESHUTDOWN 143 /* Can't send after socket shutdown */
+#define ETOOMANYREFS 144 /* Too many references: can't splice */
+#define ETIMEDOUT 145 /* Connection timed out */
+#define ECONNREFUSED 146 /* Connection refused */
+#define EHOSTDOWN 147 /* Host is down */
+#define EHOSTUNREACH 148 /* No route to host */
+#define EWOULDBLOCK EAGAIN
+#define EALREADY 149 /* operation already in progress */
+#define EINPROGRESS 150 /* operation now in progress */
+
+/* SUN Network File System */
+#define ESTALE 151 /* Stale NFS file handle */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_ERRNO_H */
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
new file mode 100644
index 000000000..b4c93f4c9
--- /dev/null
+++ b/doc/examples/Makefile.am
@@ -0,0 +1,8 @@
+EXTRA = README unify.vol replicate.vol stripe.vol protocol-client.vol protocol-server.vol posix-locks.vol trash.vol write-behind.vol io-threads.vol io-cache.vol read-ahead.vol filter.vol trace.vol
+EXTRA_DIST = $(EXTRA)
+
+docdir = $(datadir)/doc/$(PACKAGE_NAME)
+Examplesdir = $(docdir)/examples
+Examples_DATA = $(EXTRA)
+
+CLEANFILES =
diff --git a/doc/examples/README b/doc/examples/README
new file mode 100644
index 000000000..4d472ac08
--- /dev/null
+++ b/doc/examples/README
@@ -0,0 +1,13 @@
+GlusterFS's translator feature is very flexible and there are quite a lot of ways one
+can configure their filesystem to behave like.
+
+Volume Specification is a way in which GlusterFS understands how it has to work, based
+on what is written there.
+
+Going through the following URLs may give you more idea about all these.
+
+* http://www.gluster.org/docs/index.php/GlusterFS
+* http://www.gluster.org/docs/index.php/GlusterFS_Volume_Specification
+* http://www.gluster.org/docs/index.php/GlusterFS_Translators
+
+Mail us any doubts, suggestions on 'gluster-devel(at)nongnu.org'
diff --git a/doc/examples/filter.vol b/doc/examples/filter.vol
new file mode 100644
index 000000000..ca5c59837
--- /dev/null
+++ b/doc/examples/filter.vol
@@ -0,0 +1,23 @@
+volume client
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 192.168.1.10 # IP address of the remote brick
+ option remote-subvolume brick # name of the remote volume
+end-volume
+
+## In normal clustered storage type, any of the cluster translators can come here.
+#
+# Definition of other clients
+#
+# Definition of cluster translator (may be unify, afr, or unify over afr)
+#
+
+### 'Filter' translator is used on client side (or server side according to needs). This traslator makes all the below translators, (or say volumes) as read-only. Hence if one wants a 'read-only' filesystem, using filter as the top most volume will make it really fast as the fops are returned from this level itself.
+
+volume filter-ro
+ type features/filter
+ option root-squashing enable
+# option completely-read-only yes
+# translate-uid 1-99=0
+ subvolumes client
+end-volume \ No newline at end of file
diff --git a/doc/examples/io-cache.vol b/doc/examples/io-cache.vol
new file mode 100644
index 000000000..5f3eca4c5
--- /dev/null
+++ b/doc/examples/io-cache.vol
@@ -0,0 +1,25 @@
+volume client
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 192.168.1.10 # IP address of the remote brick
+ option remote-subvolume brick # name of the remote volume
+end-volume
+
+## In normal clustered storage type, any of the cluster translators can come here.
+#
+# Definition of other clients
+#
+# Definition of cluster translator (may be unify, replicate, or unify over replicate)
+#
+
+### 'IO-Cache' translator is best used on client side when a filesystem has file which are not modified frequently but read several times. For example, while compiling a kernel, *.h files are read while compiling every *.c file, in these case, io-cache translator comes very handy, as it keeps the whole file content in the cache, and serves from the cache.
+# One can provide the priority of the cache too.
+
+volume ioc
+ type performance/io-cache
+ subvolumes client # In this example it is 'client' you may have to change it according to your spec file.
+ option page-size 1MB # 128KB is default
+ option cache-size 64MB # 32MB is default
+ option force-revalidate-timeout 5 # 1second is default
+ option priority *.html:2,*:1 # default is *:0
+end-volume
diff --git a/doc/examples/io-threads.vol b/doc/examples/io-threads.vol
new file mode 100644
index 000000000..9954724e1
--- /dev/null
+++ b/doc/examples/io-threads.vol
@@ -0,0 +1,21 @@
+
+volume brick
+ type storage/posix # POSIX FS translator
+ option directory /home/export # Export this directory
+end-volume
+
+### 'IO-threads' translator gives a threading behaviour to File I/O calls. All other normal fops are having default behaviour. Loading this on server side helps to reduce the contension of network. (Which is assumed as a GlusterFS hang).
+# One can load it in client side to reduce the latency involved in case of a slow network, when loaded below write-behind.
+volume iot
+ type performance/io-threads
+ subvolumes brick
+ option thread-count 4 # default value is 1
+end-volume
+
+volume server
+ type protocol/server
+ subvolumes iot brick
+ option transport-type tcp # For TCP/IP transport
+ option auth.addr.brick.allow 192.168.* # Allow access to "brick" volume
+ option auth.addr.iot.allow 192.168.* # Allow access to "p-locks" volume
+end-volume
diff --git a/doc/examples/posix-locks.vol b/doc/examples/posix-locks.vol
new file mode 100644
index 000000000..b9c9e7a64
--- /dev/null
+++ b/doc/examples/posix-locks.vol
@@ -0,0 +1,20 @@
+
+volume brick
+ type storage/posix # POSIX FS translator
+ option directory /home/export # Export this directory
+end-volume
+
+### 'Posix-locks' feature should be added on the server side (as posix volume as subvolume) because it contains the actual file.
+volume p-locks
+ type features/posix-locks
+ subvolumes brick
+ option mandatory on
+end-volume
+
+volume server
+ type protocol/server
+ subvolumes p-locks brick
+ option transport-type tcp
+ option auth.addr.brick.allow 192.168.* # Allow access to "brick" volume
+ option auth.addr.p-locks.allow 192.168.* # Allow access to "p-locks" volume
+end-volume
diff --git a/doc/examples/protocol-client.vol b/doc/examples/protocol-client.vol
new file mode 100644
index 000000000..43108f2c2
--- /dev/null
+++ b/doc/examples/protocol-client.vol
@@ -0,0 +1,17 @@
+volume client
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+ option remote-host 192.168.1.10 # IP address of the remote brick
+# option transport.socket.remote-port 6996 # default server port is 6996
+
+# option transport-type ib-verbs # for Infiniband verbs transport
+# option transport.ib-verbs.work-request-send-size 1048576
+# option transport.ib-verbs.work-request-send-count 16
+# option transport.ib-verbs.work-request-recv-size 1048576
+# option transport.ib-verbs.work-request-recv-count 16
+# option transport.ib-verbs.remote-port 6996 # default server port is 6996
+
+ option remote-subvolume brick # name of the remote volume
+# option transport-timeout 30 # default value is 120seconds
+end-volume
diff --git a/doc/examples/protocol-server.vol b/doc/examples/protocol-server.vol
new file mode 100644
index 000000000..88477511f
--- /dev/null
+++ b/doc/examples/protocol-server.vol
@@ -0,0 +1,25 @@
+
+### Export volume "brick" with the contents of "/home/export" directory.
+volume brick
+ type storage/posix # POSIX FS translator
+ option directory /home/export # Export this directory
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+# option transport.socket.listen-port 6996 # Default is 6996
+
+# option transport-type ib-verbs # For Infiniband Verbs transport
+# option transport.ib-verbs.work-request-send-size 131072
+# option transport.ib-verbs.work-request-send-count 64
+# option transport.ib-verbs.work-request-recv-size 131072
+# option transport.ib-verbs.work-request-recv-count 64
+# option transport.ib-verbs.listen-port 6996 # Default is 6996
+
+# option bind-address 192.168.1.10 # Default is to listen on all interfaces
+# option client-volume-filename /etc/glusterfs/glusterfs-client.vol
+ subvolumes brick
+ option auth.addr.brick.allow 192.168.* # Allow access to "brick" volume
+end-volume
diff --git a/doc/examples/read-ahead.vol b/doc/examples/read-ahead.vol
new file mode 100644
index 000000000..3ce0d95ac
--- /dev/null
+++ b/doc/examples/read-ahead.vol
@@ -0,0 +1,22 @@
+volume client
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 192.168.1.10 # IP address of the remote brick
+ option remote-subvolume brick # name of the remote volume
+end-volume
+
+## In normal clustered storage type, any of the cluster translators can come here.
+#
+# Definition of other clients
+#
+# Definition of cluster translator (may be unify, replicate, or unify over replicate)
+#
+
+### 'Read-Ahead' translator is best utilized on client side, as it prefetches the file contents when the first read() call is issued.
+volume ra
+ type performance/read-ahead
+ subvolumes client # In this example it is 'client' you may have to change it according to your spec file.
+ option page-size 1MB # default is 256KB
+ option page-count 4 # default is 2
+ option force-atime-update no # defalut is 'no'
+end-volume
diff --git a/doc/examples/replicate.vol b/doc/examples/replicate.vol
new file mode 100644
index 000000000..8c9541444
--- /dev/null
+++ b/doc/examples/replicate.vol
@@ -0,0 +1,119 @@
+### 'NOTE'
+# This file has both server spec and client spec to get an understanding of stripe's spec file. Hence can't be used as it is, as a GlusterFS spec file.
+# One need to seperate out server spec and client spec to get it working.
+
+#=========================================================================
+
+# **** server1 spec file ****
+
+### Export volume "brick" with the contents of "/home/export" directory.
+volume posix1
+ type storage/posix # POSIX FS translator
+ option directory /home/export1 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick1
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix1
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6996 # Default is 6996
+# option client-volume-filename /etc/glusterfs/glusterfs-client.vol
+ subvolumes brick1
+ option auth.addr.brick1.allow * # access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** server2 spec file ****
+volume posix2
+ type storage/posix # POSIX FS translator
+ option directory /home/export2 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick2
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix2
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6997 # Default is 6996
+ subvolumes brick2
+ option auth.addr.brick2.allow * # Allow access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** server3 spec file ****
+
+volume posix3
+ type storage/posix # POSIX FS translator
+ option directory /home/export3 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick3
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix3
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6998 # Default is 6996
+ subvolumes brick3
+ option auth.addr.brick3.allow * # access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** Clustered Client config file ****
+
+### Add client feature and attach to remote subvolume of server1
+volume client1
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6996 # default server port is 6996
+ option remote-subvolume brick1 # name of the remote volume
+end-volume
+
+### Add client feature and attach to remote subvolume of server2
+volume client2
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6997 # default server port is 6996
+ option remote-subvolume brick2 # name of the remote volume
+end-volume
+
+volume client3
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6998 # default server port is 6996
+ option remote-subvolume brick3 # name of the remote volume
+end-volume
+
+## Add replicate feature.
+volume replicate
+ type cluster/replicate
+ subvolumes client1 client2 client3
+end-volume
+
diff --git a/doc/examples/stripe.vol b/doc/examples/stripe.vol
new file mode 100644
index 000000000..ea24cf860
--- /dev/null
+++ b/doc/examples/stripe.vol
@@ -0,0 +1,121 @@
+
+### 'NOTE'
+# This file has both server spec and client spec to get an understanding of stripe's spec file. Hence can't be used as it is, as a GlusterFS spec file.
+# One need to seperate out server spec and client spec to get it working.
+
+#=========================================================================
+
+# **** server1 spec file ****
+
+### Export volume "brick" with the contents of "/home/export" directory.
+volume posix1
+ type storage/posix # POSIX FS translator
+ option directory /home/export1 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick1
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix1
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6996 # Default is 6996
+# option client-volume-filename /etc/glusterfs/glusterfs-client.vol
+ subvolumes brick1
+ option auth.addr.brick1.allow * # access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** server2 spec file ****
+volume posix2
+ type storage/posix # POSIX FS translator
+ option directory /home/export2 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick2
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix2
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6997 # Default is 6996
+ subvolumes brick2
+ option auth.addr.brick2.allow * # Allow access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** server3 spec file ****
+
+volume posix3
+ type storage/posix # POSIX FS translator
+ option directory /home/export3 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick3
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix3
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6998 # Default is 6996
+ subvolumes brick3
+ option auth.addr.brick3.allow * # access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** Clustered Client config file ****
+
+### Add client feature and attach to remote subvolume of server1
+volume client1
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6996 # default server port is 6996
+ option remote-subvolume brick1 # name of the remote volume
+end-volume
+
+### Add client feature and attach to remote subvolume of server2
+volume client2
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6997 # default server port is 6996
+ option remote-subvolume brick2 # name of the remote volume
+end-volume
+
+volume client3
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6998 # default server port is 6996
+ option remote-subvolume brick3 # name of the remote volume
+end-volume
+
+## Add Stripe Feature.
+volume stripe
+ type cluster/stripe
+ subvolumes client1 client2 client3
+ option block-size 1MB
+end-volume
+
diff --git a/doc/examples/trace.vol b/doc/examples/trace.vol
new file mode 100644
index 000000000..3f4864db4
--- /dev/null
+++ b/doc/examples/trace.vol
@@ -0,0 +1,16 @@
+volume client
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 192.168.1.10 # IP address of the remote brick
+ option remote-subvolume brick # name of the remote volume
+end-volume
+
+### 'Trace' translator is a very handy debug tool for GlusterFS, as it can be loaded between any of the two volumes without changing the behaviour of the filesystem.
+# On client side it can be the top most volume in spec (like now) to understand what calls are made on FUSE filesystem, when a mounted filesystem is accessed.
+
+volume trace
+ type debug/trace
+ subvolumes client
+end-volume
+
+# 'NOTE:' By loading 'debug/trace' translator, filesystem will be very slow as it logs each and every calls to the log file.
diff --git a/doc/examples/trash.vol b/doc/examples/trash.vol
new file mode 100644
index 000000000..16e71be32
--- /dev/null
+++ b/doc/examples/trash.vol
@@ -0,0 +1,20 @@
+
+volume brick
+ type storage/posix # POSIX FS translator
+ option directory /home/export # Export this directory
+end-volume
+
+### 'Trash' translator is best used on server side as it just renames the deleted file inside 'trash-dir', and it makes 4 seperate fops for one unlink call.
+volume trashcan
+ type features/trash
+ subvolumes brick
+ option trash-dir /.trashcan
+end-volume
+
+volume server
+ type protocol/server
+ subvolumes trashcan brick
+ option transport-type tcp # For TCP/IP transport
+ option auth.addr.brick.allow 192.168.* # Allow access to "brick" volume
+ option auth.addr.trashcan.allow 192.168.* # Allow access to "p-locks" volume
+end-volume
diff --git a/doc/examples/unify.vol b/doc/examples/unify.vol
new file mode 100644
index 000000000..4f7415a23
--- /dev/null
+++ b/doc/examples/unify.vol
@@ -0,0 +1,178 @@
+### 'NOTE'
+# This file has both server spec and client spec to get an understanding of stripe's spec file. Hence can't be used as it is, as a GlusterFS spec file.
+# One need to seperate out server spec and client spec to get it working.
+
+
+#=========================================================================
+
+# **** server1 spec file ****
+
+### Export volume "brick" with the contents of "/home/export" directory.
+volume posix1
+ type storage/posix # POSIX FS translator
+ option directory /home/export1 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick1
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix1
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6996 # Default is 6996
+# option client-volume-filename /etc/glusterfs/glusterfs-client.vol
+ subvolumes brick1
+ option auth.addr.brick1.allow * # access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** server2 spec file ****
+volume posix2
+ type storage/posix # POSIX FS translator
+ option directory /home/export2 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick2
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix2
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6997 # Default is 6996
+ subvolumes brick2
+ option auth.addr.brick2.allow * # Allow access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** server3 spec file ****
+
+volume posix3
+ type storage/posix # POSIX FS translator
+ option directory /home/export3 # Export this directory
+end-volume
+
+### Add POSIX record locking support to the storage brick
+volume brick3
+ type features/posix-locks
+ option mandatory on # enables mandatory locking on all files
+ subvolumes posix3
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6998 # Default is 6996
+ subvolumes brick3
+ option auth.addr.brick3.allow * # access to "brick" volume
+end-volume
+
+#=========================================================================
+
+# *** server for namespace ***
+### Export volume "brick" with the contents of "/home/export" directory.
+volume brick-ns
+ type storage/posix # POSIX FS translator
+ option directory /home/export-ns # Export this directory
+end-volume
+
+volume server
+ type protocol/server
+ option transport-type tcp # For TCP/IP transport
+ option transport.socket.listen-port 6999 # Default is 6996
+ subvolumes brick-ns
+ option auth.addr.brick-ns.allow * # access to "brick" volume
+end-volume
+
+
+#=========================================================================
+
+# **** Clustered Client config file ****
+
+### Add client feature and attach to remote subvolume of server1
+volume client1
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6996 # default server port is 6996
+ option remote-subvolume brick1 # name of the remote volume
+end-volume
+
+### Add client feature and attach to remote subvolume of server2
+volume client2
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6997 # default server port is 6996
+ option remote-subvolume brick2 # name of the remote volume
+end-volume
+
+volume client3
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6998 # default server port is 6996
+ option remote-subvolume brick3 # name of the remote volume
+end-volume
+
+
+volume client-ns
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+ option remote-host 127.0.0.1 # IP address of the remote brick
+ option transport.socket.remote-port 6999 # default server port is 6996
+ option remote-subvolume brick-ns # name of the remote volume
+end-volume
+
+### Add unify feature to cluster the servers. Associate an
+### appropriate scheduler that matches your I/O demand.
+volume bricks
+ type cluster/unify
+ option namespace client-ns # this will not be storage child of unify.
+ subvolumes client1 client2 client3
+### ** ALU Scheduler Option **
+ option self-heal background # foreground off # default is foreground
+ option scheduler alu
+ option alu.limits.min-free-disk 5% #%
+ option alu.limits.max-open-files 10000
+ option alu.order disk-usage:read-usage:write-usage:open-files-usage:disk-speed-usage
+ option alu.disk-usage.entry-threshold 2GB
+ option alu.disk-usage.exit-threshold 128MB
+ option alu.open-files-usage.entry-threshold 1024
+ option alu.open-files-usage.exit-threshold 32
+ option alu.read-usage.entry-threshold 20 #%
+ option alu.read-usage.exit-threshold 4 #%
+ option alu.write-usage.entry-threshold 20 #%
+ option alu.write-usage.exit-threshold 4 #%
+ option alu.disk-speed-usage.entry-threshold 0 # DO NOT SET IT. SPEED IS CONSTANT!!!.
+ option alu.disk-speed-usage.exit-threshold 0 # DO NOT SET IT. SPEED IS CONSTANT!!!.
+ option alu.stat-refresh.interval 10sec
+ option alu.stat-refresh.num-file-create 10
+### ** Random Scheduler **
+# option scheduler random
+### ** NUFA Scheduler **
+# option scheduler nufa
+# option nufa.local-volume-name posix1
+### ** Round Robin (RR) Scheduler **
+# option scheduler rr
+# option rr.limits.min-free-disk 5% #%
+end-volume
+
diff --git a/doc/examples/write-behind.vol b/doc/examples/write-behind.vol
new file mode 100644
index 000000000..9c6bae11c
--- /dev/null
+++ b/doc/examples/write-behind.vol
@@ -0,0 +1,26 @@
+volume client
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+ option remote-host 192.168.1.10 # IP address of the remote brick
+ option remote-subvolume brick # name of the remote volume
+end-volume
+
+## In normal clustered storage type, any of the cluster translators can come here.
+#
+# Definition of other clients
+#
+# Definition of cluster translator (may be unify, replicate, or unify over replicate)
+#
+
+
+### 'Write-behind' translator is a performance booster for write operation. Best used on client side, as its main intension is to reduce the network latency caused for each write operation.
+
+volume wb
+ type performance/write-behind
+ subvolumes client # In this example it is 'client' you may have to change it according to your spec file.
+ option flush-behind on # default value is 'off'
+ option window-size 2MB
+ option aggregate-size 1MB # default value is 0
+ option enable_O_SYNC no # default is no
+ option disable-for-first-nbytes 128KB #default is 1
+end-volume
diff --git a/doc/get_put_api_using_xattr.txt b/doc/get_put_api_using_xattr.txt
new file mode 100644
index 000000000..58951f5bf
--- /dev/null
+++ b/doc/get_put_api_using_xattr.txt
@@ -0,0 +1,22 @@
+GlusterFS get/put API interface provided through extended attributes:
+
+API usage:
+ int put(dirpath/filename, data): setfattr -n glusterfs.file.<filename> -v <data> <dirpath>
+ void *get(dirpath/filename): getfattr -n glusterfs.file.<filename> <dirpath>
+
+
+internals:
+* unify handling setxattr/getxattr
+ - setxattr
+ unify's setxattr forwards setxattr call to all the child nodes with XATTR_REPLACE flag, except namespace. setxattr will succeeds only on the child node on which the file already exists. if the setxattr operation fails on all child nodes, it indicates that the file does not already exist on any of the child nodes. unify follows the same rules as it follows for create, but using setxattr call itself with XATTR_CREATE flag. unify sends a setxattr to namespace first, with zero length data. if namespace setxattr succeeds, unify schedules setxattr to one of the child nodes.
+
+ - getxattr
+ unify's getxattr forwards getxattr call to all the child nodes. wait for completion of operation on all the child nodes, and returns success if getxattr succeeded one child node.
+
+* posix handling setxattr/getxattr
+ - setxattr
+ posix setxattr does a open with O_CREAT|O_TRUNC on the <path>/<name>, writes value of the setxattr as data into the file and closes the file. when data is null, posix setxattr avoids doing write. file is closed after write.
+
+ - getxattr
+ posix getxattr does open with O_RDONLY on the <path>/<name>, reads the complete content of the file. file is closed after read.
+
diff --git a/doc/glusterfs.8 b/doc/glusterfs.8
new file mode 100644
index 000000000..46c596a5b
--- /dev/null
+++ b/doc/glusterfs.8
@@ -0,0 +1,139 @@
+.\" Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+.\" This file is part of GlusterFS.
+.\"
+.\" GlusterFS is free software; you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published
+.\" by the Free Software Foundation; either version 3 of the License,
+.\" or (at your option) any later version.
+.\"
+.\" GlusterFS is distributed in the hope that it will be useful, but
+.\" WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+.\" General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" long with this program. If not, see
+.\" <http://www.gnu.org/licenses/>.
+.\"
+.\" :O
+.\"
+.TH GlusterFS 8 ":O Cluster Filesystem" "07 December 2008" "Z Research Inc."
+.SH NAME
+GlusterFS \- Clustered Filesystem.
+.SH SYNOPSYS
+.B glusterfs
+.I [options] [mountpoint]
+.PP
+.SH DESCRIPTION
+GlusterFS is a clustered file-system capable of scaling to several peta-bytes. It aggregates various storage bricks over Infiniband RDMA or TCP/IP interconnect into one large parallel network file system. Storage bricks can be made of any commodity hardware such as x86-64 server with SATA-II RAID and Infiniband HBA.
+GlusterFS is fully POSIX compliant FileSystem. On client side, it has dependency on FUSE package, on server side, it works seemlessly on different OSes. (Currently supported on GNU/Linux, Mac OSX, FreeBSD, OpenSolaris).
+.SH OPTIONS
+.PP
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+.SS "Basic options"
+.PP
+.TP
+
+\fB\-f, \fB\-\-volfile=VOLUME-FILE\fR
+File to use as VOLUME-FILE [default:/etc/glusterfs/glusterfs.vol]
+.TP
+\fB\-l, \fB\-\-log\-file=LOGFILE\fR
+File to use for logging [default:/var/log/glusterfs/glusterfs.log]
+.TP
+\fB\-L, \fB\-\-log\-level=LOGLEVEL\fR
+Logging severity. Valid options are DEBUG, WARNING, ERROR, CRITICAL
+and NONE [default: WARNING]
+.TP
+\fB\-s, \fB\-\-volfile\-server=SERVER\fR
+Server to get the volume from. This option overrides \fB\-\-volfile option
+
+.SS "Advanced options"
+.PP
+.TP
+
+\fB\-\-debug\fR
+Run in debug mode. This option sets \fB\-\-no\-daemon\fR, \fB\-\-log\-level\fR to DEBUG
+and \fB\-\-log\-file\fR to console
+.TP
+\fB\-N, \fB\-\-no\-daemon\fR
+Run in foreground
+.TP
+\fB\-p, \fB\-\-pid\-file=PIDFILE\fR
+File to use as pid file
+.TP
+\fB\-\-volfile\-id=KEY\fR
+KEY of the volume file to be fetched from server
+.TP
+\fB\-\-volfile\-server\-port=PORT\fR
+Port number of volfile server
+.TP
+\fB\-\-volfile\-server\-transport=TRANSPORT\fR
+Transport type to get volume file from server [default: socket]
+.TP
+\fB\-\-volume\-name=VOLUME\-NAME\fR
+Volume name to be used for MOUNT-POINT [default: top most volume in
+VOLUME-FILE]
+.TP
+\fB\-\-xlator\-option=VOLUME\-NAME.OPTION=VALUE\fR
+Add/override a translator option for a volume with the specified value
+
+
+.SS "Fuse options"
+.PP
+.TP
+
+\fB\-\-attribute\-timeout=SECONDS\fR
+Set attribute timeout to SECONDS for inodes in fuse kernel module [default: 1]
+.TP
+\fB\-\-entry\-timeout=SECONDS\fR
+Set entry timeout to SECONDS in fuse kernel module [default: 1]
+.TP
+\fB\-\-disable\-direct\-io\-mode\fR
+Disable direct I/O mode in fuse kernel module
+.TP
+
+.SS "Miscellaneous Options"
+.PP
+.TP
+
+\fB\-?, \fB\-\-help\fR
+Give this help list
+.TP
+\fB\-\-usage\fR
+Give a short usage message
+.TP
+\fB\-V, \fB\-\-version\fR
+Print program version
+
+.PP
+.SH FILES
+/etc/glusterfs/*.vol
+
+.SH SEE ALSO
+.nf
+The full documentation for \fBGlusterFS\fR is maintained as a Texinfo manual.
+If the \fBinfo\fR and \fBglusterfs\fR are properly installed on your site, the command
+ \fBinfo glusterfs\fR
+should give you access to complete documentation.
+
+.nf
+\fBbison\fR(1) \fBflex\fR(1) \fBfusermount\fR(1)
+\fBhttp://www.glusterfs.org/ <URL:http://www.glusterfs.org/>
+\fR
+.fi
+.SH SUPPORT
+.nf
+\fBhttp://support.gluster.com/ <URL:http://support.gluster.com/>
+\fR
+.fi
+.SH AUTHORS
+.nf
+\fBhttp://www.gluster.org/core-team.php <URL:http://www.gluster.org/core-team.php>
+\fR
+.fi
+.SH COPYRIGHT
+.nf
+\fBCopyright(c)2006,2007,2008,2009 Z RESEARCH, Inc. <http://www.zresearch.com>
+\fR
+.fi
diff --git a/doc/glusterfs.vol.sample b/doc/glusterfs.vol.sample
new file mode 100644
index 000000000..e126f66b3
--- /dev/null
+++ b/doc/glusterfs.vol.sample
@@ -0,0 +1,61 @@
+### file: client-volume.vol.sample
+
+#####################################
+### GlusterFS Client Volume File ##
+#####################################
+
+#### CONFIG FILE RULES:
+### "#" is comment character.
+### - Config file is case sensitive
+### - Options within a volume block can be in any order.
+### - Spaces or tabs are used as delimitter within a line.
+### - Each option should end within a line.
+### - Missing or commented fields will assume default values.
+### - Blank/commented lines are allowed.
+### - Sub-volumes should already be defined above before referring.
+
+### Add client feature and attach to remote subvolume
+volume client
+ type protocol/client
+ option transport-type tcp
+# option transport-type unix
+# option transport-type ib-sdp
+ option remote-host 127.0.0.1 # IP address of the remote brick
+# option transport.socket.remote-port 6996 # default server port is 6996
+
+# option transport-type ib-verbs
+# option transport.ib-verbs.remote-port 6996 # default server port is 6996
+# option transport.ib-verbs.work-request-send-size 1048576
+# option transport.ib-verbs.work-request-send-count 16
+# option transport.ib-verbs.work-request-recv-size 1048576
+# option transport.ib-verbs.work-request-recv-count 16
+
+# option transport-timeout 30 # seconds to wait for a reply
+ # from server for each request
+ option remote-subvolume brick # name of the remote volume
+end-volume
+
+### Add readahead feature
+#volume readahead
+# type performance/read-ahead
+# option page-size 1MB # unit in bytes
+# option page-count 2 # cache per file = (page-count x page-size)
+# subvolumes client
+#end-volume
+
+### Add IO-Cache feature
+#volume iocache
+# type performance/io-cache
+# option page-size 256KB
+# option page-count 2
+# subvolumes readahead
+#end-volume
+
+### Add writeback feature
+#volume writeback
+# type performance/write-behind
+# option aggregate-size 1MB
+# option window-size 2MB
+# option flush-behind off
+# subvolumes iocache
+#end-volume
diff --git a/doc/glusterfsd.vol.sample b/doc/glusterfsd.vol.sample
new file mode 100644
index 000000000..b6d8a1580
--- /dev/null
+++ b/doc/glusterfsd.vol.sample
@@ -0,0 +1,47 @@
+### file: server-volume.vol.sample
+
+#####################################
+### GlusterFS Server Volume File ##
+#####################################
+
+#### CONFIG FILE RULES:
+### "#" is comment character.
+### - Config file is case sensitive
+### - Options within a volume block can be in any order.
+### - Spaces or tabs are used as delimitter within a line.
+### - Multiple values to options will be : delimitted.
+### - Each option should end within a line.
+### - Missing or commented fields will assume default values.
+### - Blank/commented lines are allowed.
+### - Sub-volumes should already be defined above before referring.
+
+### Export volume "brick" with the contents of "/home/export" directory.
+volume brick
+ type storage/posix # POSIX FS translator
+ option directory /home/export # Export this directory
+end-volume
+
+### Add network serving capability to above brick.
+volume server
+ type protocol/server
+ option transport-type tcp
+# option transport-type unix
+# option transport-type ib-sdp
+# option transport.socket.bind-address 192.168.1.10 # Default is to listen on all interfaces
+# option transport.socket.listen-port 6996 # Default is 6996
+
+# option transport-type ib-verbs
+# option transport.ib-verbs.bind-address 192.168.1.10 # Default is to listen on all interfaces
+# option transport.ib-verbs.listen-port 6996 # Default is 6996
+# option transport.ib-verbs.work-request-send-size 131072
+# option transport.ib-verbs.work-request-send-count 64
+# option transport.ib-verbs.work-request-recv-size 131072
+# option transport.ib-verbs.work-request-recv-count 64
+
+# option client-volume-filename /etc/glusterfs/glusterfs-client.vol
+ subvolumes brick
+# NOTE: Access to any volume through protocol/server is denied by
+# default. You need to explicitly grant access through # "auth"
+# option.
+ option auth.addr.brick.allow * # Allow access to "brick" volume
+end-volume
diff --git a/doc/hacker-guide/Makefile.am b/doc/hacker-guide/Makefile.am
new file mode 100644
index 000000000..65c92ac23
--- /dev/null
+++ b/doc/hacker-guide/Makefile.am
@@ -0,0 +1,8 @@
+EXTRA_DIST = replicate.txt bdb.txt posix.txt call-stub.txt write-behind.txt
+
+#EXTRA_DIST = hacker-guide.tex afr.txt bdb.txt posix.txt call-stub.txt write-behind.txt
+#hacker_guidedir = $(docdir)
+#hacker_guide_DATA = hacker-guide.pdf
+
+#hacker-guide.pdf: $(EXTRA_DIST)
+# pdflatex $(srcdir)/hacker-guide.tex
diff --git a/doc/hacker-guide/adding-fops.txt b/doc/hacker-guide/adding-fops.txt
new file mode 100644
index 000000000..293de2637
--- /dev/null
+++ b/doc/hacker-guide/adding-fops.txt
@@ -0,0 +1,33 @@
+ HOW TO ADD A NEW FOP TO GlusterFS
+ =================================
+
+Steps to be followed when adding a new FOP to GlusterFS:
+
+1. Edit glusterfs.h and add a GF_FOP_* constant.
+
+2. Edit xlator.[ch] and:
+ 2a. add the new prototype for fop and callback.
+ 2b. edit xlator_fops structure.
+
+3. Edit xlator.c and add to fill_defaults.
+
+4. Edit protocol.h and add struct necessary for the new FOP.
+
+5. Edit defaults.[ch] and provide default implementation.
+
+6. Edit call-stub.[ch] and provide stub implementation.
+
+7. Edit common-utils.c and add to gf_global_variable_init().
+
+8. Edit client-protocol and add your FOP.
+
+9. Edit server-protocol and add your FOP.
+
+10. Implement your FOP in any translator for which the default implementation
+ is not sufficient.
+
+==========================================
+Last updated: Mon Oct 27 21:35:49 IST 2008
+
+Author: Vikas Gorur <vikas@zresearch.com>
+==========================================
diff --git a/doc/hacker-guide/bdb.txt b/doc/hacker-guide/bdb.txt
new file mode 100644
index 000000000..fd0bd3652
--- /dev/null
+++ b/doc/hacker-guide/bdb.txt
@@ -0,0 +1,70 @@
+
+* How does file translates to key/value pair?
+---------------------------------------------
+
+ in bdb a file is identified by key (obtained by taking basename() of the path of
+the file) and file contents are stored as value corresponding to the key in database
+file (defaults to glusterfs_storage.db under dirname() directory).
+
+* symlinks, directories
+-----------------------
+
+ symlinks and directories are stored as is.
+
+* db (database) files
+---------------------
+
+ every directory, including root directory, contains a database file called
+glusterfs_storage.db. all the regular files contained in the directory are stored
+as key/value pair inside the glusterfs_storage.db.
+
+* internal data cache
+---------------------
+
+ db does not provide a way to find out the size of the value corresponding to a key.
+so, bdb makes DB->get() call for key and takes the length of the value returned.
+since DB->get() also returns file contents for key, bdb maintains an internal cache and
+stores the file contents in the cache.
+ every directory maintains a seperate cache.
+
+* inode number transformation
+-----------------------------
+
+ bdb allocates a inode number to each file and directory on its own. bdb maintains a
+global counter and increments it after allocating inode number for each file
+(regular, symlink or directory). NOTE: bdb does not guarantee persistent inode numbers.
+
+* checkpoint thread
+-------------------
+
+ bdb creates a checkpoint thread at the time of init(). checkpoint thread does a
+periodic checkpoint on the DB_ENV. checkpoint is the mechanism, provided by db, to
+forcefully commit the logged transactions to the storage.
+
+NOTES ABOUT FOPS:
+-----------------
+
+lookup() -
+ 1> do lstat() on the path, if lstat fails, we assume that the file being looked up
+ is either a regular file or doesn't exist.
+ 2> lookup in the DB of parent directory for key corresponding to path. if key exists,
+ return key, with.
+ NOTE: 'struct stat' stat()ed from DB file is used as a container for 'struct stat'
+ of the regular file. st_ino, st_size, st_blocks are updated with file's values.
+
+readv() -
+ 1> do a lookup in bctx cache. if successful, return the requested data from cache.
+ 2> if cache missed, do a DB->get() the entire file content and insert to cache.
+
+writev():
+ 1> flush any cached content of this file.
+ 2> do a DB->put(), with DB_DBT_PARTIAL flag.
+ NOTE: DB_DBT_PARTIAL is used to do partial update of a value in DB.
+
+readdir():
+ 1> regular readdir() in a loop, and vomit all DB_ENV log files and DB files that
+ we encounter.
+ 2> if the readdir() buffer still has space, open a DB cursor and do a sequential
+ DBC->get() to fill the reaadir buffer.
+
+
diff --git a/doc/hacker-guide/call-stub.txt b/doc/hacker-guide/call-stub.txt
new file mode 100644
index 000000000..bca1579b2
--- /dev/null
+++ b/doc/hacker-guide/call-stub.txt
@@ -0,0 +1,1033 @@
+creating a call stub and pausing a call
+---------------------------------------
+libglusterfs provides seperate API to pause each of the fop. parameters to each API is
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+ NOTE: @fn should exactly take the same type and number of parameters that
+ the corresponding regular fop takes.
+rest will be the regular parameters to corresponding fop.
+
+NOTE: @frame can never be NULL. fop_<operation>_stub() fails with errno
+ set to EINVAL, if @frame is NULL. also wherever @loc is applicable,
+ @loc cannot be NULL.
+
+refer to individual stub creation API to know about call-stub creation's behaviour with
+specific parameters.
+
+here is the list of stub creation APIs for xlator fops.
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@need_xattr - flag to specify if xattr should be returned or not.
+call_stub_t *
+fop_lookup_stub (call_frame_t *frame,
+ fop_lookup_t fn,
+ loc_t *loc,
+ int32_t need_xattr);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+call_stub_t *
+fop_stat_stub (call_frame_t *frame,
+ fop_stat_t fn,
+ loc_t *loc);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+call_stub_t *
+fop_fstat_stub (call_frame_t *frame,
+ fop_fstat_t fn,
+ fd_t *fd);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to @loc->inode and
+ @loc->parent, if not NULL. also @loc->path will be copied to a different location.
+@mode - mode parameter to chmod.
+call_stub_t *
+fop_chmod_stub (call_frame_t *frame,
+ fop_chmod_t fn,
+ loc_t *loc,
+ mode_t mode);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+@mode - mode parameter for fchmod fop.
+call_stub_t *
+fop_fchmod_stub (call_frame_t *frame,
+ fop_fchmod_t fn,
+ fd_t *fd,
+ mode_t mode);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to @loc->inode and
+ @loc->parent, if not NULL. also @loc->path will be copied to a different location.
+@uid - uid parameter to chown.
+@gid - gid parameter to chown.
+call_stub_t *
+fop_chown_stub (call_frame_t *frame,
+ fop_chown_t fn,
+ loc_t *loc,
+ uid_t uid,
+ gid_t gid);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+@uid - uid parameter to fchown.
+@gid - gid parameter to fchown.
+call_stub_t *
+fop_fchown_stub (call_frame_t *frame,
+ fop_fchown_t fn,
+ fd_t *fd,
+ uid_t uid,
+ gid_t gid);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location, if not NULL.
+@off - offset parameter to truncate fop.
+call_stub_t *
+fop_truncate_stub (call_frame_t *frame,
+ fop_truncate_t fn,
+ loc_t *loc,
+ off_t off);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+@off - offset parameter to ftruncate fop.
+call_stub_t *
+fop_ftruncate_stub (call_frame_t *frame,
+ fop_ftruncate_t fn,
+ fd_t *fd,
+ off_t off);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@tv - tv parameter to utimens fop.
+call_stub_t *
+fop_utimens_stub (call_frame_t *frame,
+ fop_utimens_t fn,
+ loc_t *loc,
+ struct timespec tv[2]);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@mask - mask parameter for access fop.
+call_stub_t *
+fop_access_stub (call_frame_t *frame,
+ fop_access_t fn,
+ loc_t *loc,
+ int32_t mask);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@size - size parameter to readlink fop.
+call_stub_t *
+fop_readlink_stub (call_frame_t *frame,
+ fop_readlink_t fn,
+ loc_t *loc,
+ size_t size);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@mode - mode parameter to mknod fop.
+@rdev - rdev parameter to mknod fop.
+call_stub_t *
+fop_mknod_stub (call_frame_t *frame,
+ fop_mknod_t fn,
+ loc_t *loc,
+ mode_t mode,
+ dev_t rdev);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@mode - mode parameter to mkdir fop.
+call_stub_t *
+fop_mkdir_stub (call_frame_t *frame,
+ fop_mkdir_t fn,
+ loc_t *loc,
+ mode_t mode);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+call_stub_t *
+fop_unlink_stub (call_frame_t *frame,
+ fop_unlink_t fn,
+ loc_t *loc);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+call_stub_t *
+fop_rmdir_stub (call_frame_t *frame,
+ fop_rmdir_t fn,
+ loc_t *loc);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@linkname - linkname parameter to symlink fop.
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+call_stub_t *
+fop_symlink_stub (call_frame_t *frame,
+ fop_symlink_t fn,
+ const char *linkname,
+ loc_t *loc);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@oldloc - pointer to location structure.
+ NOTE: @oldloc will be copied to a different location, with inode_ref() to
+ @oldloc->inode and @oldloc->parent, if not NULL. also @oldloc->path will
+ be copied to a different location, if not NULL.
+@newloc - pointer to location structure.
+ NOTE: @newloc will be copied to a different location, with inode_ref() to
+ @newloc->inode and @newloc->parent, if not NULL. also @newloc->path will
+ be copied to a different location, if not NULL.
+call_stub_t *
+fop_rename_stub (call_frame_t *frame,
+ fop_rename_t fn,
+ loc_t *oldloc,
+ loc_t *newloc);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@newpath - newpath parameter to link fop.
+call_stub_t *
+fop_link_stub (call_frame_t *frame,
+ fop_link_t fn,
+ loc_t *oldloc,
+ const char *newpath);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@flags - flags parameter to create fop.
+@mode - mode parameter to create fop.
+@fd - file descriptor parameter to create fop.
+ NOTE: @fd is stored with a fd_ref().
+call_stub_t *
+fop_create_stub (call_frame_t *frame,
+ fop_create_t fn,
+ loc_t *loc,
+ int32_t flags,
+ mode_t mode, fd_t *fd);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@flags - flags parameter to open fop.
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+call_stub_t *
+fop_open_stub (call_frame_t *frame,
+ fop_open_t fn,
+ loc_t *loc,
+ int32_t flags,
+ fd_t *fd);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+@size - size parameter to readv fop.
+@off - offset parameter to readv fop.
+call_stub_t *
+fop_readv_stub (call_frame_t *frame,
+ fop_readv_t fn,
+ fd_t *fd,
+ size_t size,
+ off_t off);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+@vector - vector parameter to writev fop.
+ NOTE: @vector is iov_dup()ed while creating stub. and frame->root->req_refs
+ dictionary is dict_ref()ed.
+@count - count parameter to writev fop.
+@off - off parameter to writev fop.
+call_stub_t *
+fop_writev_stub (call_frame_t *frame,
+ fop_writev_t fn,
+ fd_t *fd,
+ struct iovec *vector,
+ int32_t count,
+ off_t off);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to flush fop.
+ NOTE: @fd is stored with a fd_ref().
+call_stub_t *
+fop_flush_stub (call_frame_t *frame,
+ fop_flush_t fn,
+ fd_t *fd);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+@datasync - datasync parameter to fsync fop.
+call_stub_t *
+fop_fsync_stub (call_frame_t *frame,
+ fop_fsync_t fn,
+ fd_t *fd,
+ int32_t datasync);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to @loc->inode and
+ @loc->parent, if not NULL. also @loc->path will be copied to a different location.
+@fd - file descriptor parameter to opendir fop.
+ NOTE: @fd is stored with a fd_ref().
+call_stub_t *
+fop_opendir_stub (call_frame_t *frame,
+ fop_opendir_t fn,
+ loc_t *loc,
+ fd_t *fd);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to getdents fop.
+ NOTE: @fd is stored with a fd_ref().
+@size - size parameter to getdents fop.
+@off - off parameter to getdents fop.
+@flags - flags parameter to getdents fop.
+call_stub_t *
+fop_getdents_stub (call_frame_t *frame,
+ fop_getdents_t fn,
+ fd_t *fd,
+ size_t size,
+ off_t off,
+ int32_t flag);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to setdents fop.
+ NOTE: @fd is stored with a fd_ref().
+@flags - flags parameter to setdents fop.
+@entries - entries parameter to setdents fop.
+call_stub_t *
+fop_setdents_stub (call_frame_t *frame,
+ fop_setdents_t fn,
+ fd_t *fd,
+ int32_t flags,
+ dir_entry_t *entries,
+ int32_t count);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to setdents fop.
+ NOTE: @fd is stored with a fd_ref().
+@datasync - datasync parameter to fsyncdir fop.
+call_stub_t *
+fop_fsyncdir_stub (call_frame_t *frame,
+ fop_fsyncdir_t fn,
+ fd_t *fd,
+ int32_t datasync);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+call_stub_t *
+fop_statfs_stub (call_frame_t *frame,
+ fop_statfs_t fn,
+ loc_t *loc);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@dict - dict parameter to setxattr fop.
+ NOTE: stub creation procedure stores @dict pointer with dict_ref() to it.
+call_stub_t *
+fop_setxattr_stub (call_frame_t *frame,
+ fop_setxattr_t fn,
+ loc_t *loc,
+ dict_t *dict,
+ int32_t flags);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@name - name parameter to getxattr fop.
+call_stub_t *
+fop_getxattr_stub (call_frame_t *frame,
+ fop_getxattr_t fn,
+ loc_t *loc,
+ const char *name);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@name - name parameter to removexattr fop.
+ NOTE: name string will be copied to a different location while creating stub.
+call_stub_t *
+fop_removexattr_stub (call_frame_t *frame,
+ fop_removexattr_t fn,
+ loc_t *loc,
+ const char *name);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to lk fop.
+ NOTE: @fd is stored with a fd_ref().
+@cmd - command parameter to lk fop.
+@lock - lock parameter to lk fop.
+ NOTE: lock will be copied to a different location while creating stub.
+call_stub_t *
+fop_lk_stub (call_frame_t *frame,
+ fop_lk_t fn,
+ fd_t *fd,
+ int32_t cmd,
+ struct flock *lock);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - fd parameter to gf_lk fop.
+ NOTE: @fd is fd_ref()ed while creating stub, if not NULL.
+@cmd - cmd parameter to gf_lk fop.
+@lock - lock paramater to gf_lk fop.
+ NOTE: @lock is copied to a different memory location while creating
+ stub.
+call_stub_t *
+fop_gf_lk_stub (call_frame_t *frame,
+ fop_gf_lk_t fn,
+ fd_t *fd,
+ int32_t cmd,
+ struct flock *lock);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@fd - file descriptor parameter to readdir fop.
+ NOTE: @fd is stored with a fd_ref().
+@size - size parameter to readdir fop.
+@off - offset parameter to readdir fop.
+call_stub_t *
+fop_readdir_stub (call_frame_t *frame,
+ fop_readdir_t fn,
+ fd_t *fd,
+ size_t size,
+ off_t off);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@loc - pointer to location structure.
+ NOTE: @loc will be copied to a different location, with inode_ref() to
+ @loc->inode and @loc->parent, if not NULL. also @loc->path will be
+ copied to a different location.
+@flags - flags parameter to checksum fop.
+call_stub_t *
+fop_checksum_stub (call_frame_t *frame,
+ fop_checksum_t fn,
+ loc_t *loc,
+ int32_t flags);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@inode - inode parameter to @fn.
+ NOTE: @inode pointer is stored with a inode_ref().
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+@dict - dict parameter to @fn.
+ NOTE: @dict pointer is stored with dict_ref().
+call_stub_t *
+fop_lookup_cbk_stub (call_frame_t *frame,
+ fop_lookup_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf,
+ dict_t *dict);
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_stat_cbk_stub (call_frame_t *frame,
+ fop_stat_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_fstat_cbk_stub (call_frame_t *frame,
+ fop_fstat_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_chmod_cbk_stub (call_frame_t *frame,
+ fop_chmod_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_fchmod_cbk_stub (call_frame_t *frame,
+ fop_fchmod_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_chown_cbk_stub (call_frame_t *frame,
+ fop_chown_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_fchown_cbk_stub (call_frame_t *frame,
+ fop_fchown_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_truncate_cbk_stub (call_frame_t *frame,
+ fop_truncate_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_ftruncate_cbk_stub (call_frame_t *frame,
+ fop_ftruncate_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_utimens_cbk_stub (call_frame_t *frame,
+ fop_utimens_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_access_cbk_stub (call_frame_t *frame,
+ fop_access_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@path - path parameter to @fn.
+ NOTE: @path is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_readlink_cbk_stub (call_frame_t *frame,
+ fop_readlink_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ const char *path);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@inode - inode parameter to @fn.
+ NOTE: @inode pointer is stored with a inode_ref().
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_mknod_cbk_stub (call_frame_t *frame,
+ fop_mknod_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@inode - inode parameter to @fn.
+ NOTE: @inode pointer is stored with a inode_ref().
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_mkdir_cbk_stub (call_frame_t *frame,
+ fop_mkdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_unlink_cbk_stub (call_frame_t *frame,
+ fop_unlink_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_rmdir_cbk_stub (call_frame_t *frame,
+ fop_rmdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@inode - inode parameter to @fn.
+ NOTE: @inode pointer is stored with a inode_ref().
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_symlink_cbk_stub (call_frame_t *frame,
+ fop_symlink_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_rename_cbk_stub (call_frame_t *frame,
+ fop_rename_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@inode - inode parameter to @fn.
+ NOTE: @inode pointer is stored with a inode_ref().
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_link_cbk_stub (call_frame_t *frame,
+ fop_link_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@fd - fd parameter to @fn.
+ NOTE: @fd pointer is stored with a fd_ref().
+@inode - inode parameter to @fn.
+ NOTE: @inode pointer is stored with a inode_ref().
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_create_cbk_stub (call_frame_t *frame,
+ fop_create_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd,
+ inode_t *inode,
+ struct stat *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@fd - fd parameter to @fn.
+ NOTE: @fd pointer is stored with a fd_ref().
+call_stub_t *
+fop_open_cbk_stub (call_frame_t *frame,
+ fop_open_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@vector - vector parameter to @fn.
+ NOTE: @vector is copied to a different memory location, if not NULL. also
+ frame->root->rsp_refs is dict_ref()ed.
+@stbuf - stbuf parameter to @fn.
+ NOTE: @stbuf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_readv_cbk_stub (call_frame_t *frame,
+ fop_readv_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct iovec *vector,
+ int32_t count,
+ struct stat *stbuf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@stbuf - stbuf parameter to @fn.
+ NOTE: @stbuf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_writev_cbk_stub (call_frame_t *frame,
+ fop_writev_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *stbuf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_flush_cbk_stub (call_frame_t *frame,
+ fop_flush_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_fsync_cbk_stub (call_frame_t *frame,
+ fop_fsync_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@fd - fd parameter to @fn.
+ NOTE: @fd pointer is stored with a fd_ref().
+call_stub_t *
+fop_opendir_cbk_stub (call_frame_t *frame,
+ fop_opendir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@entries - entries parameter to @fn.
+@count - count parameter to @fn.
+call_stub_t *
+fop_getdents_cbk_stub (call_frame_t *frame,
+ fop_getdents_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ dir_entry_t *entries,
+ int32_t count);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_setdents_cbk_stub (call_frame_t *frame,
+ fop_setdents_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_fsyncdir_cbk_stub (call_frame_t *frame,
+ fop_fsyncdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@buf - buf parameter to @fn.
+ NOTE: @buf is copied to a different memory location, if not NULL.
+call_stub_t *
+fop_statfs_cbk_stub (call_frame_t *frame,
+ fop_statfs_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct statvfs *buf);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_setxattr_cbk_stub (call_frame_t *frame,
+ fop_setxattr_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@value - value dictionary parameter to @fn.
+ NOTE: @value pointer is stored with a dict_ref().
+call_stub_t *
+fop_getxattr_cbk_stub (call_frame_t *frame,
+ fop_getxattr_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ dict_t *value);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+call_stub_t *
+fop_removexattr_cbk_stub (call_frame_t *frame,
+ fop_removexattr_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@lock - lock parameter to @fn.
+ NOTE: @lock is copied to a different memory location while creating
+ stub.
+call_stub_t *
+fop_lk_cbk_stub (call_frame_t *frame,
+ fop_lk_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct flock *lock);
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@lock - lock parameter to @fn.
+ NOTE: @lock is copied to a different memory location while creating
+ stub.
+call_stub_t *
+fop_gf_lk_cbk_stub (call_frame_t *frame,
+ fop_gf_lk_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct flock *lock);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@entries - entries parameter to @fn.
+call_stub_t *
+fop_readdir_cbk_stub (call_frame_t *frame,
+ fop_readdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ gf_dirent_t *entries);
+
+
+@frame - call frame which has to be used to resume the call at call_resume().
+@fn - procedure to call during call_resume().
+@op_ret - op_ret parameter to @fn.
+@op_errno - op_errno parameter to @fn.
+@file_checksum - file_checksum parameter to @fn.
+ NOTE: file_checksum will be copied to a different memory location
+ while creating stub.
+@dir_checksum - dir_checksum parameter to @fn.
+ NOTE: file_checksum will be copied to a different memory location
+ while creating stub.
+call_stub_t *
+fop_checksum_cbk_stub (call_frame_t *frame,
+ fop_checksum_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ uint8_t *file_checksum,
+ uint8_t *dir_checksum);
+
+resuming a call:
+---------------
+ call can be resumed using call stub through call_resume API.
+
+ void call_resume (call_stub_t *stub);
+
+ stub - call stub created during pausing a call.
+
+ NOTE: call_resume() will decrease reference count of any fd_t, dict_t and inode_t that it finds
+ in stub->args.<operation>.<fd_t-or-inode_t-or-dict_t>. so, if any fd_t, dict_t or
+ inode_t pointers are assigned at stub->args.<operation>.<fd_t-or-inode_t-or-dict_t> after
+ fop_<operation>_stub() call, they must be <fd_t-or-inode_t-or-dict_t>_ref()ed.
+
+ call_resume does not STACK_DESTROY() for any fop.
+
+ if stub->fn is NULL, call_resume does STACK_WIND() or STACK_UNWIND() using the stub->frame.
+
+ return - call resume fails only if stub is NULL. call resume fails with errno set to EINVAL.
diff --git a/doc/hacker-guide/hacker-guide.tex b/doc/hacker-guide/hacker-guide.tex
new file mode 100644
index 000000000..72c44df1a
--- /dev/null
+++ b/doc/hacker-guide/hacker-guide.tex
@@ -0,0 +1,312 @@
+\documentclass{book}[12pt]
+\usepackage{graphicx}
+% \usepackage{fancyhdr}
+
+% \pagestyle{fancy}
+\begin{document}
+
+% \headheight 117pt
+% \rhead{\includegraphics{zr-logo.eps}}
+
+\author{Z Research}
+\title{GlusterFS 1.3 Hacker's Guide}
+\date{June 1, 2007}
+
+\maketitle
+\frontmatter
+\tableofcontents
+
+\mainmatter
+\chapter{Introduction}
+
+\section{Coding guidelines}
+GlusterFS uses GNU Arch for version control. To get the latest source do:
+\begin{verbatim}
+ $ tla register-archive http://arch.sv.gnu.org/archives/gluster
+ $ tla -A gluster@sv.gnu.org get glusterfs--mainline--2.4
+\end{verbatim}
+\noindent
+GlusterFS follows the GNU coding
+standards\footnote{http://www.gnu.org/prep/standards\_toc.html} for the
+most part.
+
+\chapter{Major components}
+\section{libglusterfs}
+\texttt{libglusterfs} contains supporting code used by all the other components.
+The important files here are:
+
+\texttt{dict.c}: This is an implementation of a serializable dictionary type. It is
+used by the protocol code to send requests and replies. It is also used to pass options
+to translators.
+
+\texttt{logging.c}: This is a thread-safe logging library. The log messages go to a
+file (default \texttt{/usr/local/var/log/glusterfs/*}).
+
+\texttt{protocol.c}: This file implements the GlusterFS on-the-wire
+protocol. The protocol itself is a simple ASCII protocol, designed to
+be easy to parse and be human readable.
+
+A sample GlusterFS protocol block looks like this:
+\begin{verbatim}
+ Block Start header
+ 0000000000000023 callid
+ 00000001 type
+ 00000016 op
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx human-readable name
+ 00000000000000000000000000000ac3 block size
+ <...> block
+ Block End
+\end{verbatim}
+
+\texttt{stack.h}: This file defines the \texttt{STACK\_WIND} and
+\texttt{STACK\_UNWIND} macros which are used to implement the parallel
+stack that is maintained for inter-xlator calls. See the \textsl{Taking control
+of the stack} section below for more details.
+
+\texttt{spec.y}: This contains the Yacc grammar for the GlusterFS
+specification file, and the parsing code.
+
+
+Draw diagrams of trees
+Two rules:
+(1) directory structure is same
+(2) file can exist only on one node
+
+\section{glusterfs-fuse}
+\section{glusterfsd}
+\section{transport}
+\section{scheduler}
+\section{xlator}
+
+\chapter{xlators}
+\section{Taking control of the stack}
+One can think of STACK\_WIND/UNWIND as a very specific RPC mechanism.
+
+% \includegraphics{stack.eps}
+
+\section{Overview of xlators}
+
+\flushleft{\LARGE\texttt{cluster/}}
+\vskip 2ex
+\flushleft{\Large\texttt{afr}}
+\vskip 2ex
+\flushleft{\Large\texttt{stripe}}
+\vskip 2ex
+\flushleft{\Large\texttt{unify}}
+
+\vskip 4ex
+\flushleft{\LARGE\texttt{debug/}}
+\vskip 2ex
+\flushleft{\Large\texttt{trace}}
+\vskip 2ex
+The trace xlator simply logs all fops and mops, and passes them through to its child.
+
+\vskip 4ex
+\flushleft{\LARGE\texttt{features/}}
+\flushleft{\Large\texttt{posix-locks}}
+\vskip 2ex
+This xlator implements \textsc{posix} record locking semantics over
+any kind of storage.
+
+\vskip 4ex
+\flushleft{\LARGE\texttt{performance/}}
+
+\flushleft{\Large\texttt{io-threads}}
+\vskip 2ex
+\flushleft{\Large\texttt{read-ahead}}
+\vskip 2ex
+\flushleft{\Large\texttt{stat-prefetch}}
+\vskip 2ex
+\flushleft{\Large\texttt{write-behind}}
+\vskip 2ex
+
+\vskip 4ex
+\flushleft{\LARGE\texttt{protocol/}}
+\vskip 2ex
+
+\flushleft{\Large\texttt{client}}
+\vskip 2ex
+
+\flushleft{\Large\texttt{server}}
+\vskip 2ex
+
+\vskip 4ex
+\flushleft{\LARGE\texttt{storage/}}
+\flushleft{\Large\texttt{posix}}
+\vskip 2ex
+The \texttt{posix} xlator is the one which actually makes calls to the
+on-disk filesystem. Currently this is the only storage xlator available. However,
+plans to develop other storage xlators, such as one for Amazon's S3 service, are
+on the roadmap.
+
+\chapter{Writing a simple xlator}
+\noindent
+In this section we're going to write a rot13 xlator. ``Rot13'' is a
+simple substitution cipher which obscures a text by replacing each
+letter with the letter thirteen places down the alphabet. So `a' (0)
+would become `n' (12), `b' would be 'm', and so on. Rot13 applied to
+a piece of ciphertext yields the plaintext again, because rot13 is its
+own inverse, since:
+
+\[
+x_c = x + 13\; (mod\; 26)
+\]
+\[
+x_c + 13\; (mod\; 26) = x + 13 + 13\; (mod\; 26) = x
+\]
+
+First we include the requisite headers.
+
+\begin{verbatim}
+#include <ctype.h>
+#include <sys/uio.h>
+
+#include "glusterfs.h"
+#include "xlator.h"
+#include "logging.h"
+
+/*
+ * This is a rot13 ``encryption'' xlator. It rot13's data when
+ * writing to disk and rot13's it back when reading it.
+ * This xlator is meant as an example, not for production
+ * use ;) (hence no error-checking)
+ */
+
+\end{verbatim}
+
+Then we write the rot13 function itself. For simplicity, we only transform lower case
+letters. Any other byte is passed through as it is.
+
+\begin{verbatim}
+/* We only handle lower case letters for simplicity */
+static void
+rot13 (char *buf, int len)
+{
+ int i;
+ for (i = 0; i < len; i++) {
+ if (isalpha (buf[i]))
+ buf[i] = (buf[i] - 'a' + 13) % 26;
+ else if (buf[i] <= 26)
+ buf[i] = (buf[i] + 13) % 26 + 'a';
+ }
+}
+\end{verbatim}
+
+Next comes a utility function whose purpose will be clear after looking at the code
+below.
+
+\begin{verbatim}
+static void
+rot13_iovec (struct iovec *vector, int count)
+{
+ int i;
+ for (i = 0; i < count; i++) {
+ rot13 (vector[i].iov_base, vector[i].iov_len);
+ }
+}
+\end{verbatim}
+
+\begin{verbatim}
+static int32_t
+rot13_readv_cbk (call_frame_t *frame,
+ call_frame_t *prev_frame,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct iovec *vector,
+ int32_t count)
+{
+ rot13_iovec (vector, count);
+
+ STACK_UNWIND (frame, op_ret, op_errno, vector, count);
+ return 0;
+}
+
+static int32_t
+rot13_readv (call_frame_t *frame,
+ xlator_t *this,
+ dict_t *ctx,
+ size_t size,
+ off_t offset)
+{
+ STACK_WIND (frame,
+ rot13_readv_cbk,
+ FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->readv,
+ ctx, size, offset);
+ return 0;
+}
+
+static int32_t
+rot13_writev_cbk (call_frame_t *frame,
+ call_frame_t *prev_frame,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ STACK_UNWIND (frame, op_ret, op_errno);
+ return 0;
+}
+
+static int32_t
+rot13_writev (call_frame_t *frame,
+ xlator_t *this,
+ dict_t *ctx,
+ struct iovec *vector,
+ int32_t count,
+ off_t offset)
+{
+ rot13_iovec (vector, count);
+
+ STACK_WIND (frame,
+ rot13_writev_cbk,
+ FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->writev,
+ ctx, vector, count, offset);
+ return 0;
+}
+
+\end{verbatim}
+
+Every xlator must define two functions and two external symbols. The functions are
+\texttt{init} and \texttt{fini}, and the symbols are \texttt{fops} and \texttt{mops}.
+The \texttt{init} function is called when the xlator is loaded by GlusterFS, and
+contains code for the xlator to initialize itself. Note that if an xlator is present
+multiple times in the spec tree, the \texttt{init} function will be called each time
+the xlator is loaded.
+
+\begin{verbatim}
+int32_t
+init (xlator_t *this)
+{
+ if (!this->children) {
+ gf_log ("rot13", GF_LOG_ERROR,
+ "FATAL: rot13 should have exactly one child");
+ return -1;
+ }
+
+ gf_log ("rot13", GF_LOG_DEBUG, "rot13 xlator loaded");
+ return 0;
+}
+\end{verbatim}
+
+\begin{verbatim}
+
+void
+fini (xlator_t *this)
+{
+ return;
+}
+
+struct xlator_fops fops = {
+ .readv = rot13_readv,
+ .writev = rot13_writev
+};
+
+struct xlator_mops mops = {
+};
+
+\end{verbatim}
+
+\end{document}
+
diff --git a/doc/hacker-guide/posix.txt b/doc/hacker-guide/posix.txt
new file mode 100644
index 000000000..d0132abfe
--- /dev/null
+++ b/doc/hacker-guide/posix.txt
@@ -0,0 +1,59 @@
+---------------
+* storage/posix
+---------------
+
+- SET_FS_ID
+
+ This is so that all filesystem checks are done with the user's
+ uid/gid and not GlusterFS's uid/gid.
+
+- MAKE_REAL_PATH
+
+ This macro concatenates the base directory of the posix volume
+ ('option directory') with the given path.
+
+- need_xattr in lookup
+
+ If this flag is passed, lookup returns a xattr dictionary that contains
+ the file's create time, the file's contents, and the version number
+ of the file.
+
+ This is a hack to increase small file performance. If an application
+ wants to read a small file, it can finish its job with just a lookup
+ call instead of a lookup followed by read.
+
+- getdents/setdents
+
+ These are used by unify to set and get directory entries.
+
+- ALIGN_BUF
+
+ Macro to align an address to a page boundary (4K).
+
+- priv->export_statfs
+
+ In some cases, two exported volumes may reside on the same
+ partition on the server. Sending statvfs info for both
+ the volumes will lead to erroneous df output at the client,
+ since free space on the partition will be counted twice.
+
+ In such cases, user can disable exporting statvfs info
+ on one of the volumes by setting this option.
+
+- xattrop
+
+ This fop is used by replicate to set version numbers on files.
+
+- getxattr/setxattr hack to read/write files
+
+ A key, GLUSTERFS_FILE_CONTENT_STRING, is handled in a special way by
+ getxattr/setxattr. A getxattr with the key will return the entire
+ content of the file as the value. A setxattr with the key will write
+ the value as the entire content of the file.
+
+- posix_checksum
+
+ This calculates a simple XOR checksum on all entry names in a
+ directory that is used by unify to compare directory contents.
+
+
diff --git a/doc/hacker-guide/replicate.txt b/doc/hacker-guide/replicate.txt
new file mode 100644
index 000000000..284f373fb
--- /dev/null
+++ b/doc/hacker-guide/replicate.txt
@@ -0,0 +1,206 @@
+---------------
+* cluster/replicate
+---------------
+
+Before understanding replicate, one must understand two internal FOPs:
+
+GF_FILE_LK:
+ This is exactly like fcntl(2) locking, except the locks are in a
+ separate domain from locks held by applications.
+
+GF_DIR_LK (loc_t *loc, char *basename):
+ This allows one to lock a name under a directory. For example,
+ to lock /mnt/glusterfs/foo, one would use the call:
+
+ GF_DIR_LK ({loc_t for "/mnt/glusterfs"}, "foo")
+
+ If one wishes to lock *all* the names under a particular directory,
+ supply the basename argument as NULL.
+
+ The locks can either be read locks or write locks; consult the
+ function prototype for more details.
+
+Both these operations are implemented by the features/locks (earlier
+known as posix-locks) translator.
+
+--------------
+* Basic design
+--------------
+
+All FOPs can be classified into four major groups:
+
+ - inode-read
+ Operations that read an inode's data (file contents) or metadata (perms, etc.).
+
+ access, getxattr, fstat, readlink, readv, stat.
+
+ - inode-write
+ Operations that modify an inode's data or metadata.
+
+ chmod, chown, truncate, writev, utimens.
+
+ - dir-read
+ Operations that read a directory's contents or metadata.
+
+ readdir, getdents, checksum.
+
+ - dir-write
+ Operations that modify a directory's contents or metadata.
+
+ create, link, mkdir, mknod, rename, rmdir, symlink, unlink.
+
+ Some of these make a subgroup in that they modify *two* different entries:
+ link, rename, symlink.
+
+ - Others
+ Other operations.
+
+ flush, lookup, open, opendir, statfs.
+
+------------
+* Algorithms
+------------
+
+Each of the four major groups has its own algorithm:
+
+ ----------------------
+ - inode-read, dir-read
+ ----------------------
+
+ = Send a request to the first child that is up:
+ - if it fails:
+ try the next available child
+ - if we have exhausted all children:
+ return failure
+
+ -------------
+ - inode-write
+ -------------
+
+ All operations are done in parallel unless specified otherwise.
+
+ (1) Send a GF_FILE_LK request on all children for a write lock on
+ the appropriate region
+ (for metadata operations: entire file (0, 0)
+ for writev: (offset, offset+size of buffer))
+
+ - If a lock request fails on a child:
+ unlock all children
+ try to acquire a blocking lock (F_SETLKW) on each child, serially.
+
+ If this fails (due to ENOTCONN or EINVAL):
+ Consider this child as dead for rest of transaction.
+
+ (2) Mark all children as "pending" on all (alive) children
+ (see below for meaning of "pending").
+
+ - If it fails on any child:
+ mark it as dead (in transaction local state).
+
+ (3) Perform operation on all (alive) children.
+
+ - If it fails on any child:
+ mark it as dead (in transaction local state).
+
+ (4) Unmark all successful children as not "pending" on all nodes.
+
+ (5) Unlock region on all (alive) children.
+
+ -----------
+ - dir-write
+ -----------
+
+ The algorithm for dir-write is same as above except instead of holding
+ GF_FILE_LK locks we hold a GF_DIR_LK lock on the name being operated upon.
+ In case of link-type calls, we hold locks on both the operand names.
+
+-----------
+* "pending"
+-----------
+
+ The "pending" number is like a journal entry. A pending entry is an
+ array of 32-bit integers stored in network byte-order as the extended
+ attribute of an inode (which can be a directory as well).
+
+ There are three keys corresponding to three types of pending operations:
+
+ - AFR_METADATA_PENDING
+ There are some metadata operations pending on this inode (perms, ctime/mtime,
+ xattr, etc.).
+
+ - AFR_DATA_PENDING
+ There is some data pending on this inode (writev).
+
+ - AFR_ENTRY_PENDING
+ There are some directory operations pending on this directory
+ (create, unlink, etc.).
+
+-----------
+* Self heal
+-----------
+
+ - On lookup, gather extended attribute data:
+ - If entry is a regular file:
+ - If an entry is present on one child and not on others:
+ - create entry on others.
+ - If entries exist but have different metadata (perms, etc.):
+ - consider the entry with the highest AFR_METADATA_PENDING number as
+ definitive and replicate its attributes on children.
+
+ - If entry is a directory:
+ - Consider the entry with the higest AFR_ENTRY_PENDING number as
+ definitive and replicate its contents on all children.
+
+ - If any two entries have non-matching types (i.e., one is file and
+ other is directory):
+ - Announce to the user via log that a split-brain situation has been
+ detected, and do nothing.
+
+ - On open, gather extended attribute data:
+ - Consider the file with the highest AFR_DATA_PENDING number as
+ the definitive one and replicate its contents on all other
+ children.
+
+ During all self heal operations, appropriate locks must be held on all
+ regions/entries being affected.
+
+---------------
+* Inode scaling
+---------------
+
+Inode scaling is necessary because if a situation arises where:
+ - An inode number is returned for a directory (by lookup) which was
+ previously the inode number of a file (as per FUSE's table), then
+ FUSE gets horribly confused (consult a FUSE expert for more details).
+
+To avoid such a situation, we distribute the 64-bit inode space equally
+among all children of replicate.
+
+To illustrate:
+
+If c1, c2, c3 are children of replicate, they each get 1/3 of the available
+inode space:
+
+Child: c1 c2 c3 c1 c2 c3 c1 c2 c3 c1 c2 ...
+Inode number: 1 2 3 4 5 6 7 8 9 10 11 ...
+
+Thus, if lookup on c1 returns an inode number "2", it is scaled to "4"
+(which is the second inode number in c1's space).
+
+This way we ensure that there is never a collision of inode numbers from
+two different children.
+
+This reduction of inode space doesn't really reduce the usability of
+replicate since even if we assume replicate has 1024 children (which would be a
+highly unusual scenario), each child still has a 54-bit inode space.
+
+2^54 ~ 1.8 * 10^16
+
+which is much larger than any real world requirement.
+
+
+==============================================
+$ Last updated: Sun Oct 12 23:17:01 IST 2008 $
+$ Author: Vikas Gorur <vikas@zresearch.com> $
+==============================================
+
diff --git a/doc/hacker-guide/write-behind.txt b/doc/hacker-guide/write-behind.txt
new file mode 100644
index 000000000..498e95480
--- /dev/null
+++ b/doc/hacker-guide/write-behind.txt
@@ -0,0 +1,45 @@
+basic working
+--------------
+
+ write behind is basically a translator to lie to the application that the write-requests are finished, even before it is actually finished.
+
+ on a regular translator tree without write-behind, control flow is like this:
+
+ 1. application makes a write() system call.
+ 2. VFS ==> FUSE ==> /dev/fuse.
+ 3. fuse-bridge initiates a glusterfs writev() call.
+ 4. writev() is STACK_WIND()ed upto client-protocol or storage translator.
+ 5. client-protocol, on recieving reply from server, starts STACK_UNWIND() towards the fuse-bridge.
+
+ on a translator tree with write-behind, control flow is like this:
+
+ 1. application makes a write() system call.
+ 2. VFS ==> FUSE ==> /dev/fuse.
+ 3. fuse-bridge initiates a glusterfs writev() call.
+ 4. writev() is STACK_WIND()ed upto write-behind translator.
+ 5. write-behind adds the write buffer to its internal queue and does a STACK_UNWIND() towards the fuse-bridge.
+
+ write call is completed in application's percepective. after STACK_UNWIND()ing towards the fuse-bridge, write-behind initiates a fresh writev() call to its child translator, whose replies will be consumed by write-behind itself. write-behind _doesn't_ cache the write buffer, unless 'option flush-behind on' is specified in volume specification file.
+
+windowing
+---------
+
+ write respect to write-behind, each write-buffer has three flags: 'stack_wound', 'write_behind' and 'got_reply'.
+
+ stack_wound: if set, indicates that write-behind has initiated STACK_WIND() towards child translator.
+
+ write_behind: if set, indicates that write-behind has done STACK_UNWIND() towards fuse-bridge.
+
+ got_reply: if set, indicates that write-behind has recieved reply from child translator for a writev() STACK_WIND(). a request will be destroyed by write-behind only if this flag is set.
+
+ currently pending write requests = aggregate size of requests with write_behind = 1 and got_reply = 0.
+
+ window size limits the aggregate size of currently pending write requests. once the pending requests' size has reached the window size, write-behind blocks writev() calls from fuse-bridge.
+ blocking is only from application's perspective. write-behind does STACK_WIND() to child translator straight-away, but hold behind the STACK_UNWIND() towards fuse-bridge. STACK_UNWIND() is done only once write-behind gets enough replies to accomodate for currently blocked request.
+
+flush behind
+------------
+
+ if 'option flush-behind on' is specified in volume specification file, then write-behind sends aggregate write requests to child translator, instead of regular per request STACK_WIND()s.
+
+
diff --git a/doc/handling-options.txt b/doc/handling-options.txt
new file mode 100644
index 000000000..cac1fe939
--- /dev/null
+++ b/doc/handling-options.txt
@@ -0,0 +1,13 @@
+
+How to add a new option to a given volume ?
+===========================================
+
+* Add a entry in 'struct volume_options options[]' with your key, what is
+ the type of the 'key', etc.
+
+* The 'key' and corresponding 'value' given for the same by user are validated
+ before calling init() of the translator/transport/scheduler/auth-module.
+
+* Once the complete init() is successful, user will get a warning if he has
+ given a 'key' which is not defined in these modules.
+
diff --git a/doc/mac-related-xattrs.txt b/doc/mac-related-xattrs.txt
new file mode 100644
index 000000000..805658334
--- /dev/null
+++ b/doc/mac-related-xattrs.txt
@@ -0,0 +1,21 @@
+
+This document is intended to briefly explain how the Extended Attributes on
+Darwin 10.5.x releases works
+----
+
+On Darwin other than all the normal filesystem operations, 'Finder' (like
+Explorer in Windows but a little more) keeps its information in two extended
+attributes named 'com.apple.FinderInfo' and 'com.apple.ResourceFork'. If these
+xattrs are not implemented the filesystem won't be shown on Finder, and if they
+are not implemented properly there may be issues when some of the file operations
+are done through GUI of Finder. But when a filesystem is used over mountpoint in a
+terminal, everything is fine and these xattrs are not required.
+
+Currently the way these xattrs are implemented is simple. All the xattr calls
+(getxattr, setxattr, listxattr, removexattr) are passed down to underlaying filesystem,
+most of the cases when exported FS is on MacOS X itself, these keys are supported, hence
+the fops succeed. But in the case of using exports of different OS on Darwin the issue is
+extended attribute prefix like 'com.apple.' may not be supported, hence the problem with
+Finder. To solve this issue, GlusterFS returns virtual default values to these keys, which
+works fine on most of the cases.
+
diff --git a/doc/porting_guide.txt b/doc/porting_guide.txt
new file mode 100644
index 000000000..905bb4228
--- /dev/null
+++ b/doc/porting_guide.txt
@@ -0,0 +1,45 @@
+ GlusterFS Porting Guide
+ -----------------------
+
+* General setup
+
+The configure script will detect the target platform for the build.
+All platform-specific CFLAGS, macro definitions should be done
+in configure.ac
+
+Platform-specific code can be written like this:
+
+#ifdef GF_DARWIN_HOST_OS
+ /* some code specific to Darwin */
+#endif
+
+* Coding guidelines
+
+In general, avoid glibc extensions. For example, nested functions don't work
+on Mac OS X. It is best to stick to C99.
+
+When using library calls and system calls, pay attention to the
+portability notes. As far as possible stick to POSIX-specified behavior.
+Do not use anything expressly permitted by the specification. For example,
+some fields in structures may be present only on certain platforms. Avoid
+use of such things.
+
+Do not pass values of constants such as F_*, O_*, errno values, etc. across
+platforms.
+
+Please refer compat-errno.h for more details about errno handling inside
+glusterfs for cross platform.
+
+* Specific issues
+
+- The argp library is available only on Linux through glibc, but for other
+ platforms glusterfs has already included argp-standalone library which will
+ statically linked during the glusterfs build.
+
+- Extended attribute calls (setxattr, listxattr, etc.) have differing prototypes
+ on different platforms. See compat.h for macro definitions to resolve this, also
+ read out the specific extended attribute documentation for your platforms.
+
+------------------------------------------
+Last revised: Thu Feb 28 13:58:07 IST 2008
+------------------------------------------
diff --git a/doc/qa/qa-client.vol b/doc/qa/qa-client.vol
new file mode 100644
index 000000000..176dda589
--- /dev/null
+++ b/doc/qa/qa-client.vol
@@ -0,0 +1,170 @@
+# This spec file should be used for testing before any release
+#
+
+# 1st client
+volume client1
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+# option transport.ib-verbs.work-request-send-size 131072
+# option transport.ib-verbs.work-request-send-count 64
+# option transport.ib-verbs.work-request-recv-size 131072
+# option transport.ib-verbs.work-request-recv-count 64
+ option remote-host 127.0.0.1
+ option remote-subvolume ra1
+end-volume
+
+# 2nd client
+volume client2
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+ option remote-host 127.0.0.1
+ option remote-subvolume ra2
+end-volume
+
+# 3rd client
+volume client3
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+ option remote-host 127.0.0.1
+ option remote-subvolume ra3
+end-volume
+
+# 4th client
+volume client4
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+ option remote-host 127.0.0.1
+ option remote-subvolume ra4
+end-volume
+
+# 5th client
+volume client5
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+ option remote-host 127.0.0.1
+ option remote-subvolume ra5
+end-volume
+
+# 6th client
+volume client6
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+ option remote-host 127.0.0.1
+ option remote-subvolume ra6
+end-volume
+
+# 7th client
+volume client7
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+ option remote-host 127.0.0.1
+ option remote-subvolume ra7
+end-volume
+
+# 8th client
+volume client8
+ type protocol/client
+ option transport-type tcp # for TCP/IP transport
+# option transport-type ib-sdp # for Infiniband transport
+# option transport-type ib-verbs # for ib-verbs transport
+ option remote-host 127.0.0.1
+ option remote-subvolume ra8
+end-volume
+
+# 1st Stripe (client1 client2)
+volume stripe1
+ type cluster/stripe
+ subvolumes client1 client2
+ option block-size 128KB # all striped in 128kB block
+end-volume
+
+# 2st Stripe (client3 client4)
+volume stripe2
+ type cluster/stripe
+ subvolumes client3 client4
+ option block-size 128KB # all striped in 128kB block
+end-volume
+
+# 3st Stripe (client5 client6)
+volume stripe3
+ type cluster/stripe
+ subvolumes client5 client6
+ option block-size 128KB # all striped in 128kB block
+end-volume
+
+# 4st Stripe (client7 client8)
+volume stripe4
+ type cluster/stripe
+ subvolumes client7 client8
+ option block-size 128KB # all striped in 128kB block
+end-volume
+
+
+# 1st replicate
+volume replicate1
+ type cluster/replicate
+ subvolumes stripe1 stripe2
+end-volume
+
+# 2nd replicate
+volume replicate2
+ type cluster/replicate
+ subvolumes stripe3 stripe4
+end-volume
+
+volume ns
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option remote-subvolume brick-ns
+end-volume
+
+# Unify
+volume unify0
+ type cluster/unify
+ subvolumes replicate1 replicate2
+# subvolumes stripe1 stripe3
+ option namespace ns
+ option scheduler rr # random # alu # nufa
+ option rr.limits.min-free-disk 1GB
+# option alu.order x
+# option alu.x.entry-threshold
+# option alu.x.exit-threshold
+end-volume
+
+
+# ==== Performance Translators ====
+# The default options for performance translators should be the best for 90+% of the cases
+volume iot
+ type performance/io-threads
+ subvolumes unify0
+end-volume
+
+volume wb
+ type performance/write-behind
+ subvolumes iot
+end-volume
+
+volume ioc
+ type performance/io-cache
+ subvolumes wb
+end-volume
+
+volume ra
+ type performance/read-ahead
+ subvolumes ioc
+end-volume
diff --git a/doc/qa/qa-high-avail-client.vol b/doc/qa/qa-high-avail-client.vol
new file mode 100644
index 000000000..69cb8dd30
--- /dev/null
+++ b/doc/qa/qa-high-avail-client.vol
@@ -0,0 +1,17 @@
+volume client
+ type protocol/client
+ option transport-type tcp
+ option remote-host localhost
+ option transport.socket.remote-port 7001
+ option remote-subvolume server1-iot
+end-volume
+
+volume ra
+ type performance/read-ahead
+ subvolumes client
+end-volume
+
+volume wb
+ type performance/write-behind
+ subvolumes ra
+end-volume
diff --git a/doc/qa/qa-high-avail-server.vol b/doc/qa/qa-high-avail-server.vol
new file mode 100644
index 000000000..09d91c4c4
--- /dev/null
+++ b/doc/qa/qa-high-avail-server.vol
@@ -0,0 +1,346 @@
+
+# -- server 1 --
+volume server1-posix1
+ type storage/posix
+ option directory /tmp/ha-export1/
+end-volume
+
+volume server1-ns1
+ type storage/posix
+ option directory /tmp/ha-export-ns1/
+end-volume
+
+volume server1-client2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7002
+ option remote-subvolume server2-posix2
+end-volume
+
+volume server1-ns2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7002
+ option remote-subvolume server2-ns2
+end-volume
+
+volume server1-client3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7003
+ option remote-subvolume server3-posix3
+end-volume
+
+volume server1-ns3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7003
+ option remote-subvolume server3-ns3
+end-volume
+
+volume server1-io1
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server1-posix1
+end-volume
+
+
+volume server1-io2
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server1-client2
+end-volume
+
+volume server1-io3
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server1-client3
+end-volume
+
+volume server1-ns-io1
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server1-ns1
+end-volume
+
+volume server1-ns-io2
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server1-ns2
+end-volume
+
+volume server1-ns-io3
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server1-ns3
+end-volume
+
+volume server1-ns-replicate
+ type cluster/replicate
+ subvolumes server1-ns-io1 server1-ns-io2 server1-ns-io3
+end-volume
+
+volume server1-storage-replicate
+ type cluster/replicate
+ subvolumes server1-io1 server1-io2 server1-io3
+end-volume
+
+volume server1-unify
+ type cluster/unify
+ #option self-heal off
+ subvolumes server1-storage-replicate
+ option namespace server1-ns-replicate
+ option scheduler rr
+end-volume
+
+volume server1-iot
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server1-unify
+end-volume
+
+volume server1
+ type protocol/server
+ option transport-type tcp
+ subvolumes server1-iot
+ option transport.socket.listen-port 7001
+ option auth.addr.server1-posix1.allow *
+ option auth.addr.server1-ns1.allow *
+ option auth.addr.server1-iot.allow *
+end-volume
+
+
+# == Server2 ==
+volume server2-client1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7001
+ option remote-subvolume server1-posix1
+end-volume
+
+volume server2-ns1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7001
+ option remote-subvolume server1-ns1
+end-volume
+
+volume server2-posix2
+ type storage/posix
+ option directory /tmp/ha-export2/
+end-volume
+
+volume server2-ns2
+ type storage/posix
+ option directory /tmp/ha-export-ns2/
+end-volume
+
+volume server2-client3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7003
+ option remote-subvolume server3-posix3
+end-volume
+
+volume server2-ns3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7003
+ option remote-subvolume server3-ns3
+end-volume
+
+volume server2-io1
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server2-client1
+end-volume
+
+
+volume server2-io2
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server2-posix2
+end-volume
+
+volume server2-io3
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server2-client3
+end-volume
+
+volume server2-ns-io1
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server2-ns1
+end-volume
+
+volume server2-ns-io2
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server2-ns2
+end-volume
+
+volume server2-ns-io3
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server2-ns3
+end-volume
+
+volume server2-ns-replicate
+ type cluster/replicate
+ subvolumes server2-ns-io1 server2-ns-io2 server2-ns-io3
+end-volume
+
+volume server2-storage-replicate
+ type cluster/replicate
+ subvolumes server2-io2 server2-io3 server2-io1
+end-volume
+
+volume server2-unify
+ type cluster/unify
+ option self-heal off
+ subvolumes server2-storage-replicate
+ option namespace server2-ns-replicate
+ option scheduler rr
+end-volume
+
+volume server2-iot
+ type performance/io-threads
+ option thread-count 8
+ option cache-size 64MB
+ subvolumes server2-unify
+end-volume
+
+volume server2
+ type protocol/server
+ option transport-type tcp
+ subvolumes server2-iot
+ option transport.socket.listen-port 7002
+ option auth.addr.server2-posix2.allow *
+ option auth.addr.server2-ns2.allow *
+ option auth.addr.server2-iot.allow *
+end-volume
+
+# == server 3 ==
+volume server3-client1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7001
+ option remote-subvolume server1-posix1
+end-volume
+
+volume server3-ns1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7001
+ option remote-subvolume server1-ns1
+end-volume
+
+volume server3-client2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7002
+ option remote-subvolume server2-posix2
+end-volume
+
+volume server3-ns2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 127.0.0.1
+ option transport.socket.remote-port 7002
+ option remote-subvolume server2-ns2
+end-volume
+
+volume server3-posix3
+ type storage/posix
+ option directory /tmp/ha-export3/
+end-volume
+
+volume server3-ns3
+ type storage/posix
+ option directory /tmp/ha-export-ns3/
+end-volume
+
+volume server3-io1
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server3-client1
+end-volume
+
+
+volume server3-io2
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server3-client2
+end-volume
+
+volume server3-io3
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server3-posix3
+end-volume
+
+volume server3-ns-io1
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server3-ns1
+end-volume
+
+volume server3-ns-io2
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server3-ns2
+end-volume
+
+volume server3-ns-io3
+ type performance/io-threads
+ option thread-count 8
+ subvolumes server3-ns3
+end-volume
+
+volume server3-ns-replicate
+ type cluster/replicate
+ subvolumes server3-ns-io1 server3-ns-io2 server3-ns-io3
+end-volume
+
+volume server3-storage-replicate
+ type cluster/replicate
+ subvolumes server3-io3 server3-io2 server3-io1
+end-volume
+
+volume server3-unify
+ type cluster/unify
+ option self-heal off
+ subvolumes server3-storage-replicate
+ option namespace server3-ns-replicate
+ option scheduler rr
+end-volume
+
+volume server3-iot
+ type performance/io-threads
+ option thread-count 8
+ option cache-size 64MB
+ subvolumes server3-unify
+end-volume
+
+volume server3
+ type protocol/server
+ option transport-type tcp
+ subvolumes server3-iot
+ option transport.socket.listen-port 7003
+ option auth.addr.server3-posix3.allow *
+ option auth.addr.server3-ns3.allow *
+ option auth.addr.server3-iot.allow *
+end-volume
+
diff --git a/doc/qa/qa-server.vol b/doc/qa/qa-server.vol
new file mode 100644
index 000000000..1c245c324
--- /dev/null
+++ b/doc/qa/qa-server.vol
@@ -0,0 +1,284 @@
+# This spec file should be used for testing before any release
+#
+
+# Namespace posix
+volume brick-ns
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export-ns # Export this directory
+end-volume
+
+# 1st server
+
+volume brick1
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export1 # Export this directory
+end-volume
+
+# == Posix-Locks ==
+ volume plocks1
+ type features/posix-locks
+# option mandatory on
+ subvolumes brick1
+ end-volume
+
+volume iot1
+ type performance/io-threads
+ subvolumes plocks1 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb1
+ type performance/write-behind
+ subvolumes iot1
+# option <key> <value>
+end-volume
+
+volume ra1
+ type performance/read-ahead
+ subvolumes wb1
+# option <key> <value>
+end-volume
+
+volume brick2
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export2 # Export this directory
+end-volume
+
+# == TrashCan Translator ==
+# volume trash2
+# type features/trash
+# option trash-dir /.trashcan
+# subvolumes brick2
+# end-volume
+
+# == Posix-Locks ==
+volume plocks2
+ type features/posix-locks
+# option <something> <something>
+ subvolumes brick2
+end-volume
+
+volume iot2
+ type performance/io-threads
+ subvolumes plocks2 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb2
+ type performance/write-behind
+ subvolumes iot2
+# option <key> <value>
+end-volume
+
+volume ra2
+ type performance/read-ahead
+ subvolumes wb2
+# option <key> <value>
+end-volume
+
+volume brick3
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export3 # Export this directory
+end-volume
+
+# == TrashCan Translator ==
+# volume trash3
+# type features/trash
+# option trash-dir /.trashcan
+# subvolumes brick3
+# end-volume
+
+# == Posix-Locks ==
+volume plocks3
+ type features/posix-locks
+# option <something> <something>
+ subvolumes brick3
+end-volume
+
+volume iot3
+ type performance/io-threads
+ subvolumes plocks3 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb3
+ type performance/write-behind
+ subvolumes iot3
+# option <key> <value>
+end-volume
+
+volume ra3
+ type performance/read-ahead
+ subvolumes wb3
+# option <key> <value>
+end-volume
+
+volume brick4
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export4 # Export this directory
+end-volume
+
+# == Posix-Locks ==
+volume plocks4
+ type features/posix-locks
+# option <something> <something>
+ subvolumes brick4
+end-volume
+
+volume iot4
+ type performance/io-threads
+ subvolumes plocks4 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb4
+ type performance/write-behind
+ subvolumes iot4
+# option <key> <value>
+end-volume
+
+volume ra4
+ type performance/read-ahead
+ subvolumes wb4
+# option <key> <value>
+end-volume
+
+volume brick5
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export5 # Export this directory
+end-volume
+
+
+# == Posix-Locks ==
+volume plocks5
+ type features/posix-locks
+# option <something> <something>
+ subvolumes brick5
+end-volume
+
+volume iot5
+ type performance/io-threads
+ subvolumes plocks5 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb5
+ type performance/write-behind
+ subvolumes iot5
+# option <key> <value>
+end-volume
+
+volume ra5
+ type performance/read-ahead
+ subvolumes wb5
+# option <key> <value>
+end-volume
+
+volume brick6
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export6 # Export this directory
+end-volume
+
+# == Posix-Locks ==
+volume plocks6
+ type features/posix-locks
+# option <something> <something>
+ subvolumes brick6
+end-volume
+
+volume iot6
+ type performance/io-threads
+ subvolumes plocks6 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb6
+ type performance/write-behind
+ subvolumes iot6
+# option <key> <value>
+end-volume
+
+volume ra6
+ type performance/read-ahead
+ subvolumes wb6
+# option <key> <value>
+end-volume
+
+volume brick7
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export7 # Export this directory
+end-volume
+
+# == Posix-Locks ==
+volume plocks7
+ type features/posix-locks
+# option <something> <something>
+ subvolumes brick7
+end-volume
+
+volume iot7
+ type performance/io-threads
+ subvolumes plocks7 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb7
+ type performance/write-behind
+ subvolumes iot7
+# option <key> <value>
+end-volume
+
+volume ra7
+ type performance/read-ahead
+ subvolumes wb7
+# option <key> <value>
+end-volume
+
+volume brick8
+ type storage/posix # POSIX FS translator
+ option directory /tmp/export8 # Export this directory
+end-volume
+
+# == Posix-Locks ==
+volume plocks8
+ type features/posix-locks
+# option <something> <something>
+ subvolumes brick8
+end-volume
+
+volume iot8
+ type performance/io-threads
+ subvolumes plocks8 # change properly if above commented volumes needs to be included
+# option <key> <value>
+end-volume
+
+volume wb8
+ type performance/write-behind
+ subvolumes iot8
+# option <key> <value>
+end-volume
+
+volume ra8
+ type performance/read-ahead
+ subvolumes wb8
+# option <key> <value>
+end-volume
+
+volume server8
+ type protocol/server
+ subvolumes ra8 ra1 ra2 ra3 ra4 ra5 ra6 ra7 brick-ns
+ option transport-type tcp # For TCP/IP transport
+# option transport-type ib-sdp # For Infiniband transport
+# option transport-type ib-verbs # For ib-verbs transport
+ option client-volume-filename /examples/qa-client.vol
+ option auth.addr.ra1.allow * # Allow access to "stat8" volume
+ option auth.addr.ra2.allow * # Allow access to "stat8" volume
+ option auth.addr.ra3.allow * # Allow access to "stat8" volume
+ option auth.addr.ra4.allow * # Allow access to "stat8" volume
+ option auth.addr.ra5.allow * # Allow access to "stat8" volume
+ option auth.addr.ra6.allow * # Allow access to "stat8" volume
+ option auth.addr.ra7.allow * # Allow access to "stat8" volume
+ option auth.addr.ra8.allow * # Allow access to "stat8" volume
+ option auth.addr.brick-ns.allow * # Allow access to "stat8" volume
+end-volume
+
diff --git a/doc/replicate.lyx b/doc/replicate.lyx
new file mode 100644
index 000000000..2bbcb652a
--- /dev/null
+++ b/doc/replicate.lyx
@@ -0,0 +1,797 @@
+#LyX 1.4.2 created this file. For more info see http://www.lyx.org/
+\lyxformat 245
+\begin_document
+\begin_header
+\textclass article
+\language english
+\inputencoding auto
+\fontscheme default
+\graphics default
+\paperfontsize default
+\spacing single
+\papersize default
+\use_geometry false
+\use_amsmath 1
+\cite_engine basic
+\use_bibtopic false
+\paperorientation portrait
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation skip
+\defskip medskip
+\quotes_language english
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+\tracking_changes false
+\output_changes false
+\end_header
+
+\begin_body
+
+\begin_layout Title
+
+\size larger
+Automatic File Replication (replicate) in GlusterFS
+\end_layout
+
+\begin_layout Author
+Vikas Gorur
+\family typewriter
+\size larger
+<vikas@zresearch.com>
+\end_layout
+
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Standard
+
+
+\backslash
+hrule
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Section*
+Overview
+\end_layout
+
+\begin_layout Standard
+This document describes the design and usage of the replicate translator in GlusterFS.
+ This document is valid for the 1.4.x releases, and not earlier ones.
+\end_layout
+
+\begin_layout Standard
+The replicate translator of GlusterFS aims to keep identical copies of a file
+ on all its subvolumes, as far as possible.
+ It tries to do this by performing all filesystem mutation operations (writing
+ data, creating files, changing ownership, etc.) on all its subvolumes in
+ such a way that if an operation succeeds on atleast one subvolume, all
+ other subvolumes can later be brought up to date.
+\end_layout
+
+\begin_layout Standard
+In the rest of the document the terms
+\begin_inset Quotes eld
+\end_inset
+
+subvolume
+\begin_inset Quotes erd
+\end_inset
+
+ and
+\begin_inset Quotes eld
+\end_inset
+
+server
+\begin_inset Quotes erd
+\end_inset
+
+ are used interchangeably, trusting that it will cause no confusion to the
+ reader.
+\end_layout
+
+\begin_layout Section*
+Usage
+\end_layout
+
+\begin_layout Standard
+A sample volume declaration for replicate looks like this:
+\end_layout
+
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Standard
+
+
+\backslash
+begin{verbatim}
+\end_layout
+
+\begin_layout Standard
+
+volume replicate
+\end_layout
+
+\begin_layout Standard
+
+ type cluster/replicate
+\end_layout
+
+\begin_layout Standard
+
+ # options, see below for description
+\end_layout
+
+\begin_layout Standard
+
+ subvolumes brick1 brick2
+\end_layout
+
+\begin_layout Standard
+
+end-volume
+\end_layout
+
+\begin_layout Standard
+
+
+\backslash
+end{verbatim}
+\end_layout
+
+\begin_layout Standard
+
+\end_layout
+
+\begin_layout Standard
+
+\end_layout
+
+\begin_layout Standard
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+This defines an replicate volume with two subvolumes, brick1, and brick2.
+ For replicate to work properly, it is essential that its subvolumes support
+\series bold
+extended attributes
+\series default
+.
+ This means that you should choose a backend filesystem that supports extended
+ attributes, like XFS, ReiserFS, or Ext3.
+\end_layout
+
+\begin_layout Standard
+The storage volumes used as backend for replicate
+\emph on
+must
+\emph default
+ have a posix-locks volume loaded above them.
+\end_layout
+
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Standard
+
+
+\backslash
+begin{verbatim}
+\end_layout
+
+\begin_layout Standard
+
+volume brick1
+\end_layout
+
+\begin_layout Standard
+
+ type features/posix-locks
+\end_layout
+
+\begin_layout Standard
+
+ subvolumes brick1-ds
+\end_layout
+
+\begin_layout Standard
+
+end-volume
+\end_layout
+
+\begin_layout Standard
+
+
+\backslash
+end{verbatim}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Section*
+Design
+\end_layout
+
+\begin_layout Subsection*
+Read algorithm
+\end_layout
+
+\begin_layout Standard
+All operations that do not modify the file or directory are sent to all
+ the subvolumes and the first successful reply is returned to the application.
+\end_layout
+
+\begin_layout Standard
+The read() system call (reading data from a file) is an exception.
+ For read() calls, replicate tries to do load balancing by sending all reads from
+ a particular file to a particular server.
+\end_layout
+
+\begin_layout Standard
+The read algorithm is also affected by the option read-subvolume; see below
+ for details.
+\end_layout
+
+\begin_layout Subsection*
+Classes of file operations
+\end_layout
+
+\begin_layout Standard
+replicate divides all filesystem write operations into three classes:
+\end_layout
+
+\begin_layout Itemize
+
+\series bold
+data:
+\series default
+Operations that modify the contents of a file (write, truncate).
+\end_layout
+
+\begin_layout Itemize
+
+\series bold
+metadata:
+\series default
+Operations that modify attributes of a file or directory (permissions, ownership
+, etc.).
+\end_layout
+
+\begin_layout Itemize
+
+\series bold
+entry:
+\series default
+Operations that create or delete directory entries (mkdir, create, rename,
+ rmdir, unlink, etc.).
+\end_layout
+
+\begin_layout Subsection*
+Locking and Change Log
+\end_layout
+
+\begin_layout Standard
+To ensure consistency across subvolumes, replicate holds a lock whenever a modificatio
+n is being made to a file or directory.
+ By default, replicate considers the first subvolume as the sole lock server.
+ However, the number of lock servers can be increased upto the total number
+ of subvolumes.
+\end_layout
+
+\begin_layout Standard
+The change log is a set of extended attributes associated with files and
+ directories that replicate maintains.
+ The change log keeps track of the changes made to files and directories
+ (data, metadata, entry) so that the self-heal algorithm knows which copy
+ of a file or directory is the most recent one.
+\end_layout
+
+\begin_layout Subsection*
+Write algorithm
+\end_layout
+
+\begin_layout Standard
+The algorithm for all write operations (data, metadata, entry) is:
+\end_layout
+
+\begin_layout Enumerate
+Lock the file (or directory) on all of the lock servers (see options below).
+\end_layout
+
+\begin_layout Enumerate
+Write change log entries on all servers.
+\end_layout
+
+\begin_layout Enumerate
+Perform the operation.
+\end_layout
+
+\begin_layout Enumerate
+Erase change log entries.
+\end_layout
+
+\begin_layout Enumerate
+Unlock the file (or directory) on all of the lock servers.
+\end_layout
+
+\begin_layout Standard
+The above algorithm is a simplified version intended for general users.
+ Please refer to the source code for the full details.
+\end_layout
+
+\begin_layout Subsection*
+Self-Heal
+\end_layout
+
+\begin_layout Standard
+replicate automatically tries to fix any inconsistencies it detects among different
+ copies of a file.
+ It uses information in the change log to determine which copy is the
+\begin_inset Quotes eld
+\end_inset
+
+correct
+\begin_inset Quotes erd
+\end_inset
+
+ version.
+\end_layout
+
+\begin_layout Standard
+Self-heal is triggered when a file or directory is first
+\begin_inset Quotes eld
+\end_inset
+
+accessed
+\begin_inset Quotes erd
+\end_inset
+
+, that is, the first time any operation is attempted on it.
+ The self-heal algorithm does the following things:
+\end_layout
+
+\begin_layout Standard
+If the entry being accessed is a directory:
+\end_layout
+
+\begin_layout Itemize
+The contents of the
+\begin_inset Quotes eld
+\end_inset
+
+correct
+\begin_inset Quotes erd
+\end_inset
+
+ version is replicated on all subvolumes, by deleting entries and creating
+ entries as necessary.
+\end_layout
+
+\begin_layout Standard
+If the entry being accessed is a file:
+\end_layout
+
+\begin_layout Itemize
+If the file does not exist on some subvolumes, it is created.
+\end_layout
+
+\begin_layout Itemize
+If there is a mismatch in the size of the file, or ownership, or permission,
+ it is fixed.
+\end_layout
+
+\begin_layout Itemize
+If the change log indicates that some copies need updating, they are updated.
+\end_layout
+
+\begin_layout Subsection*
+Split-brain
+\end_layout
+
+\begin_layout Standard
+It may happen that one replicate client can access only some of the servers in
+ a cluster and another replicate client can access the remaining servers.
+ Or it may happen that in a cluster of two servers, one server goes down
+ and comes back up, but the other goes down immediately.
+ Both these scenarios result in a
+\begin_inset Quotes eld
+\end_inset
+
+split-brain
+\begin_inset Quotes erd
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+In a split-brain situation, there will be two or more copies of a file,
+ all of which are
+\begin_inset Quotes eld
+\end_inset
+
+correct
+\begin_inset Quotes erd
+\end_inset
+
+ in some sense.
+ replicate without manual intervention has no way of knowing what to do, since
+ it cannot consider any single copy as definitive, nor does it know of any
+ meaningful way to merge the copies.
+\end_layout
+
+\begin_layout Standard
+If replicate detects that a split-brain has happened on a file, it disallows opening
+ of that file.
+ You will have to manually resolve the conflict by deleting all but one
+ copy of the file.
+ Alternatively you can set an automatic split-brain resolution policy by
+ using the `favorite-child' option (see below).
+\end_layout
+
+\begin_layout Section*
+Translator Options
+\end_layout
+
+\begin_layout Standard
+replicate accepts the following options:
+\end_layout
+
+\begin_layout Subsection*
+read-subvolume (default: none)
+\end_layout
+
+\begin_layout Standard
+The value of this option must be the name of a subvolume.
+ If given, all read operations are sent to only the specified subvolume,
+ instead of being balanced across all subvolumes.
+\end_layout
+
+\begin_layout Subsection*
+favorite-child (default: none)
+\end_layout
+
+\begin_layout Standard
+The value of this option must be the name of a subvolume.
+ If given, the specified subvolume will be preferentially used in resolving
+ conflicts (
+\begin_inset Quotes eld
+\end_inset
+
+split-brain
+\begin_inset Quotes erd
+\end_inset
+
+).
+ This means if a discrepancy is noticed in the attributes or content of
+ a file, the copy on the `favorite-child' will be considered the definitive
+ version and its contents will
+\emph on
+overwrite
+\emph default
+the contents of all other copies.
+ Use this option with caution! It is possible to
+\emph on
+lose data
+\emph default
+ with this option.
+ If you are in doubt, do not specify this option.
+\end_layout
+
+\begin_layout Subsection*
+Self-heal options
+\end_layout
+
+\begin_layout Standard
+Setting any of these options to
+\begin_inset Quotes eld
+\end_inset
+
+off
+\begin_inset Quotes erd
+\end_inset
+
+ prevents that kind of self-heal from being done on a file or directory.
+ For example, if metadata self-heal is turned off, permissions and ownership
+ are no longer fixed automatically.
+\end_layout
+
+\begin_layout Subsubsection*
+data-self-heal (default: on)
+\end_layout
+
+\begin_layout Standard
+Enable/disable self-healing of file contents.
+\end_layout
+
+\begin_layout Subsubsection*
+metadata-self-heal (default: off)
+\end_layout
+
+\begin_layout Standard
+Enable/disable self-healing of metadata (permissions, ownership, modification
+ times).
+\end_layout
+
+\begin_layout Subsubsection*
+entry-self-heal (default: on)
+\end_layout
+
+\begin_layout Standard
+Enable/disable self-healing of directory entries.
+\end_layout
+
+\begin_layout Subsection*
+Change Log options
+\end_layout
+
+\begin_layout Standard
+If any of these options is turned off, it disables writing of change log
+ entries for that class of file operations.
+ That is, steps 2 and 4 of the write algorithm (see above) are not done.
+ Note that if the change log is not written, the self-heal algorithm cannot
+ determine the
+\begin_inset Quotes eld
+\end_inset
+
+correct
+\begin_inset Quotes erd
+\end_inset
+
+ version of a file and hence self-heal will only be able to fix
+\begin_inset Quotes eld
+\end_inset
+
+obviously
+\begin_inset Quotes erd
+\end_inset
+
+ wrong things (such as a file existing on only one node).
+\end_layout
+
+\begin_layout Subsubsection*
+data-change-log (default: on)
+\end_layout
+
+\begin_layout Standard
+Enable/disable writing of change log for data operations.
+\end_layout
+
+\begin_layout Subsubsection*
+metadata-change-log (default: on)
+\end_layout
+
+\begin_layout Standard
+Enable/disable writing of change log for metadata operations.
+\end_layout
+
+\begin_layout Subsubsection*
+entry-change-log (default: on)
+\end_layout
+
+\begin_layout Standard
+Enable/disable writing of change log for entry operations.
+\end_layout
+
+\begin_layout Subsection*
+Locking options
+\end_layout
+
+\begin_layout Standard
+These options let you specify the number of lock servers to use for each
+ class of file operations.
+ The default values are satisfactory in most cases.
+ If you are extra paranoid, you may want to increase the values.
+ However, be very cautious if you set the data- or entry- lock server counts
+ to zero, since this can result in
+\emph on
+lost data.
+
+\emph default
+ For example, if you set the data-lock-server-count to zero, and two application
+s write to the same region of a file, there is a possibility that none of
+ your servers will have all the data.
+ In other words, the copies will be
+\emph on
+inconsistent
+\emph default
+, and
+\emph on
+incomplete
+\emph default
+.
+ Do not set data- and entry- lock server counts to zero unless you absolutely
+ know what you are doing and agree to not hold GlusterFS responsible for
+ any lost data.
+\end_layout
+
+\begin_layout Subsubsection*
+data-lock-server-count (default: 1)
+\end_layout
+
+\begin_layout Standard
+Number of lock servers to use for data operations.
+\end_layout
+
+\begin_layout Subsubsection*
+metadata-lock-server-count (default: 0)
+\end_layout
+
+\begin_layout Standard
+Number of lock servers to use for metadata operations.
+\end_layout
+
+\begin_layout Subsubsection*
+entry-lock-server-count (default: 1)
+\end_layout
+
+\begin_layout Standard
+Number of lock servers to use for entry operations.
+\end_layout
+
+\begin_layout Section*
+Known Issues
+\end_layout
+
+\begin_layout Subsection*
+Self-heal of file with more than one link (hard links):
+\end_layout
+
+\begin_layout Standard
+Consider two servers, A and B.
+ Assume A is down, and the user creates a file `new' as a hard link to a
+ file `old'.
+ When A comes back up, replicate will see that the file `new' does not exist on
+ A, and self-heal will create the file and copy the contents from B.
+ However, now on server A the file `new' is not a link to the file `old'
+ but an entirely different file.
+\end_layout
+
+\begin_layout Standard
+We know of no easy way to fix this problem, but we will try to fix it in
+ forthcoming releases.
+\end_layout
+
+\begin_layout Subsection*
+File re-opening after a server comes back up:
+\end_layout
+
+\begin_layout Standard
+If a server A goes down and comes back up, any files which were opened while
+ A was down and are still open will not have their writes replicated on
+ A.
+ In other words, data replication only happens on those servers which were
+ alive when the file was opened.
+\end_layout
+
+\begin_layout Standard
+This is a rather tricky issue but we hope to fix it very soon.
+\end_layout
+
+\begin_layout Section*
+Frequently Asked Questions
+\end_layout
+
+\begin_layout Subsection*
+1.
+ How can I force self-heal to happen?
+\end_layout
+
+\begin_layout Standard
+You can force self-heal to happen on your cluster by running a script or
+ a command that accesses every file.
+ A simple way to do it would be:
+\end_layout
+
+\begin_layout Standard
+\begin_inset ERT
+status open
+
+\begin_layout Standard
+
+\end_layout
+
+\begin_layout Standard
+
+
+\backslash
+begin{verbatim}
+\end_layout
+
+\begin_layout Standard
+
+$ ls -lR
+\end_layout
+
+\begin_layout Standard
+
+
+\backslash
+end{verbatim}
+\end_layout
+
+\begin_layout Standard
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+Run the command in all directories which you want to forcibly self-heal.
+\end_layout
+
+\begin_layout Subsection*
+2.
+ Which backend filesystem should I use for replicate?
+\end_layout
+
+\begin_layout Standard
+You can use any backend filesystem that supports extended attributes.
+ We know of users successfully using XFR, ReiserFS, and Ext3.
+\end_layout
+
+\begin_layout Subsection*
+3.
+ What can I do to improve replicate performance?
+\end_layout
+
+\begin_layout Standard
+Try loading performance translators such as io-threads, write-behind, io-cache,
+ and read-ahead depending on your workload.
+ If you are willing to sacrifice correctness in corner cases, you can experiment
+ with the lock-server-count and the change-log options (see above).
+ As warned earlier, be very careful!
+\end_layout
+
+\begin_layout Subsection*
+4.
+ How can I selectively replicate files?
+\end_layout
+
+\begin_layout Standard
+There is no support for selective replication in replicate itself.
+ You can achieve selective replication by loading the unify translator over
+ replicate, and using the switch scheduler.
+ Configure unify with two subvolumes, one of them being replicate.
+ Using the switch scheduler, schedule all files for which you need replication
+ to the replicate subvolume.
+ Consult unify and switch documentation for more details.
+\end_layout
+
+\begin_layout Section*
+Contact
+\end_layout
+
+\begin_layout Standard
+If you need more assistance on replicate, contact us on the mailing list <gluster-user
+s@gluster.org> (visit gluster.org for details on how to subscribe).
+\end_layout
+
+\begin_layout Standard
+Send you comments and suggestions about this document to <vikas@zresearch.com>.
+\end_layout
+
+\end_body
+\end_document
diff --git a/doc/replicate.pdf b/doc/replicate.pdf
new file mode 100644
index 000000000..b7212af2b
--- /dev/null
+++ b/doc/replicate.pdf
Binary files differ
diff --git a/doc/solaris-related-xattrs.txt b/doc/solaris-related-xattrs.txt
new file mode 100644
index 000000000..e26efa5d1
--- /dev/null
+++ b/doc/solaris-related-xattrs.txt
@@ -0,0 +1,44 @@
+ Solaris Extended Attributes
+
+In solaris extended attributes are logically supported as files
+within the filesystem. The file system is therefore augmented
+with an orthogonal namespace of file attributes. Attribute values
+are accessed by file descriptors obtained through a special attribute
+interface. This type of logical view of "attributes as files" allows
+the leveraging of existing file system interface functionality to
+support the construction, deletion and manipulation of attributes.
+
+But as we have tested through this functionality provided by Solaris
+we have come accross two major issues as written below.
+
+1. Symlink XATTR_NOFOLLOW not present for creating extended attributes
+ directly on the symlinks like other platforms Linux,MAC-OSX,BSD etc.
+ An implementation is present for O_NOFOLLOW for "openat()" call sets
+ up errno ELOOP whenever encountered with a symlink and also another
+ implementation AT_SYMLINK_NOFOLLOW which is not present for calls like
+ "attropen(), openat()"
+
+ a snippet of test code which helped us understand this behaviour
+ --------------------------------------
+ attrfd = attropen (path, key,
+ flags|AT_SYMLINK_NOFOLLOW|O_CREAT|O_WRONLY|O_NOFOLLOW, 0777);
+ if (attrfd >= 0) {
+ ftruncate (attrfd, 0);
+ ret = write (attrfd, value, size);
+ close (attrfd);
+ } else {
+ fprintf (stderr, "Couldn't set extended attribute for %s (%d)\n",
+ path, errno);
+ }
+ --------------------------------------
+
+2. Extended attribute support for special files like device files, fifo files
+ is not supported under solaris.
+
+Apart from these glitches almost everything regarding porting functionality
+for extended attribute calls has been properly implemented in compat.c
+with writing wrapper around functions over
+"attropen()", "openat()", "unlinkat()"
+
+
+
diff --git a/doc/translator-options.txt b/doc/translator-options.txt
new file mode 100644
index 000000000..3d8402be5
--- /dev/null
+++ b/doc/translator-options.txt
@@ -0,0 +1,221 @@
+mount/fuse:
+ * direct-io-mode GF_OPTION_TYPE_BOOL on|off|yes|no
+ * macfuse-local GF_OPTION_TYPE_BOOL on|off|yes|no
+ * mount-point (mountpoint) GF_OPTION_TYPE_PATH <any-posix-valid-path>
+ * attribute-timeout GF_OPTION_TYPE_TIME 0-3600
+ * entry-timeout GF_OPTION_TYPE_TIME 0-3600
+
+protocol/server:
+ * transport-type GF_OPTION_TYPE_STR tcp|socket|ib-verbs|unix|ib-sdp|
+ tcp/client|ib-verbs/client
+ * volume-filename.* GF_OPTION_TYPE_PATH
+ * inode-lru-limit GF_OPTION_TYPE_INT 0-(1 * GF_UNIT_MB)
+ * client-volume-filename GF_OPTION_TYPE_PATH
+
+protocol/client:
+ * username GF_OPTION_TYPE_ANY
+ * password GF_OPTION_TYPE_ANY
+ * transport-type GF_OPTION_TYPE_STR tcp|socket|ib-verbs|unix|ib-sdp|
+ tcp/client|ib-verbs/client
+ * remote-host GF_OPTION_TYPE_ANY
+ * remote-subvolume GF_OPTION_TYPE_ANY
+ * transport-timeout GF_OPTION_TYPE_TIME 5-1013
+
+cluster/replicate:
+ * read-subvolume GF_OPTION_TYPE_XLATOR
+ * favorite-child GF_OPTION_TYPE_XLATOR
+ * data-self-heal GF_OPTION_TYPE_BOOL
+ * metadata-self-heal GF_OPTION_TYPE_BOOL
+ * entry-self-heal GF_OPTION_TYPE_BOOL
+ * data-change-log GF_OPTION_TYPE_BOOL
+ * metadata-change-log GF_OPTION_TYPE_BOOL
+ * entry-change-log GF_OPTION_TYPE_BOOL
+ * data-lock-server-count GF_OPTION_TYPE_INT 0
+ * metadata-lock-server-count GF_OPTION_TYPE_INT 0
+ * entry-lock-server-count GF_OPTION_TYPE_INT 0
+
+cluster/distribute:
+ * lookup-unhashed GF_OPTION_TYPE_BOOL
+
+cluster/unify:
+ * namespace GF_OPTION_TYPE_XLATOR
+ * scheduler GF_OPTION_TYPE_STR alu|rr|random|nufa|switch
+ * self-heal GF_OPTION_TYPE_STR foreground|background|off
+ * optimist GF_OPTION_TYPE_BOOL
+
+cluster/nufa:
+ local-volume-name GF_OPTION_TYPE_XLATOR
+
+cluster/stripe:
+ * block-size GF_OPTION_TYPE_ANY
+ * use-xattr GF_OPTION_TYPE_BOOL
+
+debug/trace:
+ * include-ops (include) GF_OPTION_TYPE_STR
+ * exclude-ops (exclude) GF_OPTION_TYPE_STR
+
+encryption/rot-13:
+ * encrypt-write GF_OPTION_TYPE_BOOL
+ * decrypt-read GF_OPTION_TYPE_BOOL
+
+features/path-convertor:
+ * start-offset GF_OPTION_TYPE_INT 0-4095
+ * end-offset GF_OPTION_TYPE_INT 1-4096
+ * replace-with GF_OPTION_TYPE_ANY
+
+features/trash:
+ * trash-dir GF_OPTION_TYPE_PATH
+
+features/locks:
+ * mandatory-locks (mandatory) GF_OPTION_TYPE_BOOL
+
+features/filter:
+ * root-squashing GF_OPTION_TYPE_BOOL
+ * read-only GF_OPTION_TYPE_BOOL
+ * fixed-uid GF_OPTION_TYPE_INT
+ * fixed-gid GF_OPTION_TYPE_INT
+ * translate-uid GF_OPTION_TYPE_ANY
+ * translate-gid GF_OPTION_TYPE_ANY
+ * filter-uid GF_OPTION_TYPE_ANY
+ * filter-gid GF_OPTION_TYPE_ANY
+
+features/quota:
+ * min-free-disk-limit GF_OPTION_TYPE_PERCENT
+ * refresh-interval GF_OPTION_TYPE_TIME
+ * disk-usage-limit GF_OPTION_TYPE_SIZET
+
+storage/posix:
+ * o-direct GF_OPTION_TYPE_BOOL
+ * directory GF_OPTION_TYPE_PATH
+ * export-statfs-size GF_OPTION_TYPE_BOOL
+ * mandate-attribute GF_OPTION_TYPE_BOOL
+
+storage/bdb:
+ * directory GF_OPTION_TYPE_PATH
+ * logdir GF_OPTION_TYPE_PATH
+ * errfile GF_OPTION_TYPE_PATH
+ * dir-mode GF_OPTION_TYPE_ANY
+ * file-mode GF_OPTION_TYPE_ANY
+ * page-size GF_OPTION_TYPE_SIZET
+ * lru-limit GF_OPTION_TYPE_INT
+ * lock-timeout GF_OPTION_TYPE_TIME
+ * checkpoint-timeout GF_OPTION_TYPE_TIME
+ * transaction-timeout GF_OPTION_TYPE_TIME
+ * mode GF_OPTION_TYPE_BOOL
+ * access-mode GF_OPTION_TYPE_STR
+
+performance/read-ahead:
+ * force-atime-update GF_OPTION_TYPE_BOOL
+ * page-size GF_OPTION_TYPE_SIZET (64 * GF_UNIT_KB)-(2 * GF_UNIT_MB)
+ * page-count GF_OPTION_TYPE_INT 1-16
+
+performance/write-behind:
+ * flush-behind GF_OPTION_TYPE_BOOL
+ * aggregate-size GF_OPTION_TYPE_SIZET (128 * GF_UNIT_KB)-(4 * GF_UNIT_MB)
+ * window-size GF_OPTION_TYPE_SIZET (512 * GF_UNIT_KB)-(1 * GF_UNIT_GB)
+ * enable-O_SYNC GF_OPTION_TYPE_BOOL
+ * disable-for-first-nbytes GF_OPTION_TYPE_SIZET 1 - (1 * GF_UNIT_MB)
+
+performance/symlink-cache:
+
+performance/io-threads:
+ * thread-count GF_OPTION_TYPE_INT 1-32
+
+performance/io-cache:
+ * priority GF_OPTION_TYPE_ANY
+ * cache-timeout (force-revalidate-timeout) GF_OPTION_TYPE_INT 0-60
+ * page-size GF_OPTION_TYPE_SIZET (16 * GF_UNIT_KB)-(4 * GF_UNIT_MB)
+ * cache-size GF_OPTION_TYPE_SIZET (4 * GF_UNIT_MB)-(6 * GF_UNIT_GB)
+
+auth:
+- addr:
+ * auth.addr.*.allow GF_OPTION_TYPE_ANY
+ * auth.addr.*.reject GF_OPTION_TYPE_ANY
+
+- login:
+ * auth.login.*.allow GF_OPTION_TYPE_ANY
+ * auth.login.*.password GF_OPTION_TYPE_ANY
+
+scheduler/alu:
+ * scheduler.alu.order (alu.order)
+ GF_OPTION_TYPE_ANY
+ * scheduler.alu.disk-usage.entry-threshold (alu.disk-usage.entry-threshold)
+ GF_OPTION_TYPE_SIZET
+ * scheduler.alu.disk-usage.exit-threshold (alu.disk-usage.exit-threshold)
+ GF_OPTION_TYPE_SIZET
+ * scheduler.alu.write-usage.entry-threshold (alu.write-usage.entry-threshold)
+ GF_OPTION_TYPE_SIZET
+ * scheduler.alu.write-usage.exit-threshold (alu.write-usage.exit-threshold)
+ GF_OPTION_TYPE_SIZET
+ * scheduler.alu.read-usage.entry-threshold (alu.read-usage.entry-threshold)
+ GF_OPTION_TYPE_SIZET
+ * scheduler.alu.read-usage.exit-threshold (alu.read-usage.exit-threshold)
+ GF_OPTION_TYPE_SIZET
+ * scheduler.alu.open-files-usage.entry-threshold (alu.open-files-usage.entry-threshold)
+ GF_OPTION_TYPE_INT
+ * scheduler.alu.open-files-usage.exit-threshold (alu.open-files-usage.exit-threshold)
+ GF_OPTION_TYPE_INT
+ * scheduler.read-only-subvolumes (alu.read-only-subvolumes)
+ GF_OPTION_TYPE_ANY
+ * scheduler.refresh-interval (alu.refresh-interval)
+ GF_OPTION_TYPE_TIME
+ * scheduler.limits.min-free-disk (alu.limits.min-free-disk)
+ GF_OPTION_TYPE_PERCENT
+ * scheduler.alu.stat-refresh.num-file-create (alu.stat-refresh.num-file-create)
+ GF_OPTION_TYPE_INT
+
+scheduler/nufa:
+ * scheduler.refresh-interval (nufa.refresh-interval)
+ GF_OPTION_TYPE_TIME
+ * scheduler.limits.min-free-disk (nufa.limits.min-free-disk)
+ GF_OPTION_TYPE_PERCENT
+ * scheduler.local-volume-name (nufa.local-volume-name)
+ GF_OPTION_TYPE_XLATOR
+
+scheduler/random:
+ * scheduler.refresh-interval (random.refresh-interval) GF_OPTION_TYPE_TIME
+ * scheduler.limits.min-free-disk (random.limits.min-free-disk) GF_OPTION_TYPE_PERCENT
+
+scheduler/rr:
+ * scheduler.refresh-interval (rr.refresh-interval) GF_OPTION_TYPE_TIME
+ * scheduler.limits.min-free-disk (rr.limits.min-free-disk) GF_OPTION_TYPE_PERCENT
+ * scheduler.read-only-subvolumes (rr.read-only-subvolumes) GF_OPTION_TYPE_ANY
+
+scheduler/switch:
+ * scheduler.read-only-subvolumes (switch.read-only-subvolumes) GF_OPTION_TYPE_ANY
+ * scheduler.local-volume-name (switch.nufa.local-volume-name) GF_OPTION_TYPE_XLATOR
+ * scheduler.switch.case (switch.case) GF_OPTION_TYPE_ANY
+
+transport/ib-verbs:
+ * transport.ib-verbs.port (ib-verbs-port) GF_OPTION_TYPE_INT 1-4
+ check the option by 'ibv_devinfo'
+ * transport.ib-verbs.mtu (ib-verbs-mtu) GF_OPTION_TYPE_INT
+ * transport.ib-verbs.device-name (ib-verbs-device-name) GF_OPTION_TYPE_ANY,
+ check by 'ibv_devinfo'
+ * transport.ib-verbs.work-request-send-size (ib-verbs-work-request-send-size)
+ GF_OPTION_TYPE_INT,
+ * transport.ib-verbs.work-request-recv-size (ib-verbs-work-request-recv-size)
+ GF_OPTION_TYPE_INT
+ * transport.ib-verbs.work-request-send-count (ib-verbs-work-request-send-count)
+ GF_OPTION_TYPE_INT
+ * transport.ib-verbs.work-request-recv-count (ib-verbs-work-request-recv-count)
+ GF_OPTION_TYPE_INT
+ * remote-port (transport.remote-port,transport.ib-verbs.remote-port)
+ GF_OPTION_TYPE_INT
+ * transport.ib-verbs.listen-port GF_OPTION_TYPE_INT
+ * transport.ib-verbs.connect-path (connect-path) GF_OPTION_TYPE_ANY
+ * transport.ib-verbs.bind-path (bind-path) GF_OPTION_TYPE_ANY
+ * transport.ib-verbs.listen-path (listen-path) GF_OPTION_TYPE_ANY
+ * transport.address-family (address-family) GF_OPTION_TYPE_STR inet|inet6|inet/inet6|
+ inet6/inet|unix|inet-sdp
+
+transport/socket:
+ * transport.remote-port (remote-port,transport.socket.remote-port) GF_OPTION_TYPE_INT
+ * transport.socket.listen-port (listen-port) GF_OPTION_TYPE_INT
+ * transport.socket.bind-address (bind-address) GF_OPTION_TYPE_ANY
+ * transport.socket.connect-path (connect-path) GF_OPTION_TYPE_ANY
+ * transport.socket.bind-path (bind-path) GF_OPTION_TYPE_ANY
+ * transport.socket.listen-path (listen-path) GF_OPTION_TYPE_ANY
+ * transport.address-family (address-family) GF_OPTION_TYPE_STR inet|inet6|
+ inet/inet6|inet6/inet|
+ unix|inet-sdp
diff --git a/doc/user-guide/Makefile.am b/doc/user-guide/Makefile.am
new file mode 100644
index 000000000..8d7068f14
--- /dev/null
+++ b/doc/user-guide/Makefile.am
@@ -0,0 +1 @@
+info_TEXINFOS = user-guide.texi
diff --git a/doc/user-guide/advanced-stripe.odg b/doc/user-guide/advanced-stripe.odg
new file mode 100644
index 000000000..7686d7091
--- /dev/null
+++ b/doc/user-guide/advanced-stripe.odg
Binary files differ
diff --git a/doc/user-guide/advanced-stripe.pdf b/doc/user-guide/advanced-stripe.pdf
new file mode 100644
index 000000000..ec8b03dcf
--- /dev/null
+++ b/doc/user-guide/advanced-stripe.pdf
Binary files differ
diff --git a/doc/user-guide/colonO-icon.jpg b/doc/user-guide/colonO-icon.jpg
new file mode 100644
index 000000000..3e66f7a27
--- /dev/null
+++ b/doc/user-guide/colonO-icon.jpg
Binary files differ
diff --git a/doc/user-guide/fdl.texi b/doc/user-guide/fdl.texi
new file mode 100644
index 000000000..e33c687cd
--- /dev/null
+++ b/doc/user-guide/fdl.texi
@@ -0,0 +1,454 @@
+
+@c @node GNU Free Documentation License
+@c @appendixsec GNU Free Documentation License
+
+@cindex FDL, GNU Free Documentation License
+@center Version 1.2, November 2002
+
+@display
+Copyright @copyright{} 2000,2001,2002 Free Software Foundation, Inc.
+59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+@end display
+
+@enumerate 0
+@item
+PREAMBLE
+
+The purpose of this License is to make a manual, textbook, or other
+functional and useful document @dfn{free} in the sense of freedom: to
+assure everyone the effective freedom to copy and redistribute it,
+with or without modifying it, either commercially or noncommercially.
+Secondarily, this License preserves for the author and publisher a way
+to get credit for their work, while not being considered responsible
+for modifications made by others.
+
+This License is a kind of ``copyleft'', which means that derivative
+works of the document must themselves be free in the same sense. It
+complements the GNU General Public License, which is a copyleft
+license designed for free software.
+
+We have designed this License in order to use it for manuals for free
+software, because free software needs free documentation: a free
+program should come with manuals providing the same freedoms that the
+software does. But this License is not limited to software manuals;
+it can be used for any textual work, regardless of subject matter or
+whether it is published as a printed book. We recommend this License
+principally for works whose purpose is instruction or reference.
+
+@item
+APPLICABILITY AND DEFINITIONS
+
+This License applies to any manual or other work, in any medium, that
+contains a notice placed by the copyright holder saying it can be
+distributed under the terms of this License. Such a notice grants a
+world-wide, royalty-free license, unlimited in duration, to use that
+work under the conditions stated herein. The ``Document'', below,
+refers to any such manual or work. Any member of the public is a
+licensee, and is addressed as ``you''. You accept the license if you
+copy, modify or distribute the work in a way requiring permission
+under copyright law.
+
+A ``Modified Version'' of the Document means any work containing the
+Document or a portion of it, either copied verbatim, or with
+modifications and/or translated into another language.
+
+A ``Secondary Section'' is a named appendix or a front-matter section
+of the Document that deals exclusively with the relationship of the
+publishers or authors of the Document to the Document's overall
+subject (or to related matters) and contains nothing that could fall
+directly within that overall subject. (Thus, if the Document is in
+part a textbook of mathematics, a Secondary Section may not explain
+any mathematics.) The relationship could be a matter of historical
+connection with the subject or with related matters, or of legal,
+commercial, philosophical, ethical or political position regarding
+them.
+
+The ``Invariant Sections'' are certain Secondary Sections whose titles
+are designated, as being those of Invariant Sections, in the notice
+that says that the Document is released under this License. If a
+section does not fit the above definition of Secondary then it is not
+allowed to be designated as Invariant. The Document may contain zero
+Invariant Sections. If the Document does not identify any Invariant
+Sections then there are none.
+
+The ``Cover Texts'' are certain short passages of text that are listed,
+as Front-Cover Texts or Back-Cover Texts, in the notice that says that
+the Document is released under this License. A Front-Cover Text may
+be at most 5 words, and a Back-Cover Text may be at most 25 words.
+
+A ``Transparent'' copy of the Document means a machine-readable copy,
+represented in a format whose specification is available to the
+general public, that is suitable for revising the document
+straightforwardly with generic text editors or (for images composed of
+pixels) generic paint programs or (for drawings) some widely available
+drawing editor, and that is suitable for input to text formatters or
+for automatic translation to a variety of formats suitable for input
+to text formatters. A copy made in an otherwise Transparent file
+format whose markup, or absence of markup, has been arranged to thwart
+or discourage subsequent modification by readers is not Transparent.
+An image format is not Transparent if used for any substantial amount
+of text. A copy that is not ``Transparent'' is called ``Opaque''.
+
+Examples of suitable formats for Transparent copies include plain
+@sc{ascii} without markup, Texinfo input format, La@TeX{} input
+format, @acronym{SGML} or @acronym{XML} using a publicly available
+@acronym{DTD}, and standard-conforming simple @acronym{HTML},
+PostScript or @acronym{PDF} designed for human modification. Examples
+of transparent image formats include @acronym{PNG}, @acronym{XCF} and
+@acronym{JPG}. Opaque formats include proprietary formats that can be
+read and edited only by proprietary word processors, @acronym{SGML} or
+@acronym{XML} for which the @acronym{DTD} and/or processing tools are
+not generally available, and the machine-generated @acronym{HTML},
+PostScript or @acronym{PDF} produced by some word processors for
+output purposes only.
+
+The ``Title Page'' means, for a printed book, the title page itself,
+plus such following pages as are needed to hold, legibly, the material
+this License requires to appear in the title page. For works in
+formats which do not have any title page as such, ``Title Page'' means
+the text near the most prominent appearance of the work's title,
+preceding the beginning of the body of the text.
+
+A section ``Entitled XYZ'' means a named subunit of the Document whose
+title either is precisely XYZ or contains XYZ in parentheses following
+text that translates XYZ in another language. (Here XYZ stands for a
+specific section name mentioned below, such as ``Acknowledgements'',
+``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title''
+of such a section when you modify the Document means that it remains a
+section ``Entitled XYZ'' according to this definition.
+
+The Document may include Warranty Disclaimers next to the notice which
+states that this License applies to the Document. These Warranty
+Disclaimers are considered to be included by reference in this
+License, but only as regards disclaiming warranties: any other
+implication that these Warranty Disclaimers may have is void and has
+no effect on the meaning of this License.
+
+@item
+VERBATIM COPYING
+
+You may copy and distribute the Document in any medium, either
+commercially or noncommercially, provided that this License, the
+copyright notices, and the license notice saying this License applies
+to the Document are reproduced in all copies, and that you add no other
+conditions whatsoever to those of this License. You may not use
+technical measures to obstruct or control the reading or further
+copying of the copies you make or distribute. However, you may accept
+compensation in exchange for copies. If you distribute a large enough
+number of copies you must also follow the conditions in section 3.
+
+You may also lend copies, under the same conditions stated above, and
+you may publicly display copies.
+
+@item
+COPYING IN QUANTITY
+
+If you publish printed copies (or copies in media that commonly have
+printed covers) of the Document, numbering more than 100, and the
+Document's license notice requires Cover Texts, you must enclose the
+copies in covers that carry, clearly and legibly, all these Cover
+Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
+the back cover. Both covers must also clearly and legibly identify
+you as the publisher of these copies. The front cover must present
+the full title with all words of the title equally prominent and
+visible. You may add other material on the covers in addition.
+Copying with changes limited to the covers, as long as they preserve
+the title of the Document and satisfy these conditions, can be treated
+as verbatim copying in other respects.
+
+If the required texts for either cover are too voluminous to fit
+legibly, you should put the first ones listed (as many as fit
+reasonably) on the actual cover, and continue the rest onto adjacent
+pages.
+
+If you publish or distribute Opaque copies of the Document numbering
+more than 100, you must either include a machine-readable Transparent
+copy along with each Opaque copy, or state in or with each Opaque copy
+a computer-network location from which the general network-using
+public has access to download using public-standard network protocols
+a complete Transparent copy of the Document, free of added material.
+If you use the latter option, you must take reasonably prudent steps,
+when you begin distribution of Opaque copies in quantity, to ensure
+that this Transparent copy will remain thus accessible at the stated
+location until at least one year after the last time you distribute an
+Opaque copy (directly or through your agents or retailers) of that
+edition to the public.
+
+It is requested, but not required, that you contact the authors of the
+Document well before redistributing any large number of copies, to give
+them a chance to provide you with an updated version of the Document.
+
+@item
+MODIFICATIONS
+
+You may copy and distribute a Modified Version of the Document under
+the conditions of sections 2 and 3 above, provided that you release
+the Modified Version under precisely this License, with the Modified
+Version filling the role of the Document, thus licensing distribution
+and modification of the Modified Version to whoever possesses a copy
+of it. In addition, you must do these things in the Modified Version:
+
+@enumerate A
+@item
+Use in the Title Page (and on the covers, if any) a title distinct
+from that of the Document, and from those of previous versions
+(which should, if there were any, be listed in the History section
+of the Document). You may use the same title as a previous version
+if the original publisher of that version gives permission.
+
+@item
+List on the Title Page, as authors, one or more persons or entities
+responsible for authorship of the modifications in the Modified
+Version, together with at least five of the principal authors of the
+Document (all of its principal authors, if it has fewer than five),
+unless they release you from this requirement.
+
+@item
+State on the Title page the name of the publisher of the
+Modified Version, as the publisher.
+
+@item
+Preserve all the copyright notices of the Document.
+
+@item
+Add an appropriate copyright notice for your modifications
+adjacent to the other copyright notices.
+
+@item
+Include, immediately after the copyright notices, a license notice
+giving the public permission to use the Modified Version under the
+terms of this License, in the form shown in the Addendum below.
+
+@item
+Preserve in that license notice the full lists of Invariant Sections
+and required Cover Texts given in the Document's license notice.
+
+@item
+Include an unaltered copy of this License.
+
+@item
+Preserve the section Entitled ``History'', Preserve its Title, and add
+to it an item stating at least the title, year, new authors, and
+publisher of the Modified Version as given on the Title Page. If
+there is no section Entitled ``History'' in the Document, create one
+stating the title, year, authors, and publisher of the Document as
+given on its Title Page, then add an item describing the Modified
+Version as stated in the previous sentence.
+
+@item
+Preserve the network location, if any, given in the Document for
+public access to a Transparent copy of the Document, and likewise
+the network locations given in the Document for previous versions
+it was based on. These may be placed in the ``History'' section.
+You may omit a network location for a work that was published at
+least four years before the Document itself, or if the original
+publisher of the version it refers to gives permission.
+
+@item
+For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
+the Title of the section, and preserve in the section all the
+substance and tone of each of the contributor acknowledgements and/or
+dedications given therein.
+
+@item
+Preserve all the Invariant Sections of the Document,
+unaltered in their text and in their titles. Section numbers
+or the equivalent are not considered part of the section titles.
+
+@item
+Delete any section Entitled ``Endorsements''. Such a section
+may not be included in the Modified Version.
+
+@item
+Do not retitle any existing section to be Entitled ``Endorsements'' or
+to conflict in title with any Invariant Section.
+
+@item
+Preserve any Warranty Disclaimers.
+@end enumerate
+
+If the Modified Version includes new front-matter sections or
+appendices that qualify as Secondary Sections and contain no material
+copied from the Document, you may at your option designate some or all
+of these sections as invariant. To do this, add their titles to the
+list of Invariant Sections in the Modified Version's license notice.
+These titles must be distinct from any other section titles.
+
+You may add a section Entitled ``Endorsements'', provided it contains
+nothing but endorsements of your Modified Version by various
+parties---for example, statements of peer review or that the text has
+been approved by an organization as the authoritative definition of a
+standard.
+
+You may add a passage of up to five words as a Front-Cover Text, and a
+passage of up to 25 words as a Back-Cover Text, to the end of the list
+of Cover Texts in the Modified Version. Only one passage of
+Front-Cover Text and one of Back-Cover Text may be added by (or
+through arrangements made by) any one entity. If the Document already
+includes a cover text for the same cover, previously added by you or
+by arrangement made by the same entity you are acting on behalf of,
+you may not add another; but you may replace the old one, on explicit
+permission from the previous publisher that added the old one.
+
+The author(s) and publisher(s) of the Document do not by this License
+give permission to use their names for publicity for or to assert or
+imply endorsement of any Modified Version.
+
+@item
+COMBINING DOCUMENTS
+
+You may combine the Document with other documents released under this
+License, under the terms defined in section 4 above for modified
+versions, provided that you include in the combination all of the
+Invariant Sections of all of the original documents, unmodified, and
+list them all as Invariant Sections of your combined work in its
+license notice, and that you preserve all their Warranty Disclaimers.
+
+The combined work need only contain one copy of this License, and
+multiple identical Invariant Sections may be replaced with a single
+copy. If there are multiple Invariant Sections with the same name but
+different contents, make the title of each such section unique by
+adding at the end of it, in parentheses, the name of the original
+author or publisher of that section if known, or else a unique number.
+Make the same adjustment to the section titles in the list of
+Invariant Sections in the license notice of the combined work.
+
+In the combination, you must combine any sections Entitled ``History''
+in the various original documents, forming one section Entitled
+``History''; likewise combine any sections Entitled ``Acknowledgements'',
+and any sections Entitled ``Dedications''. You must delete all
+sections Entitled ``Endorsements.''
+
+@item
+COLLECTIONS OF DOCUMENTS
+
+You may make a collection consisting of the Document and other documents
+released under this License, and replace the individual copies of this
+License in the various documents with a single copy that is included in
+the collection, provided that you follow the rules of this License for
+verbatim copying of each of the documents in all other respects.
+
+You may extract a single document from such a collection, and distribute
+it individually under this License, provided you insert a copy of this
+License into the extracted document, and follow this License in all
+other respects regarding verbatim copying of that document.
+
+@item
+AGGREGATION WITH INDEPENDENT WORKS
+
+A compilation of the Document or its derivatives with other separate
+and independent documents or works, in or on a volume of a storage or
+distribution medium, is called an ``aggregate'' if the copyright
+resulting from the compilation is not used to limit the legal rights
+of the compilation's users beyond what the individual works permit.
+When the Document is included in an aggregate, this License does not
+apply to the other works in the aggregate which are not themselves
+derivative works of the Document.
+
+If the Cover Text requirement of section 3 is applicable to these
+copies of the Document, then if the Document is less than one half of
+the entire aggregate, the Document's Cover Texts may be placed on
+covers that bracket the Document within the aggregate, or the
+electronic equivalent of covers if the Document is in electronic form.
+Otherwise they must appear on printed covers that bracket the whole
+aggregate.
+
+@item
+TRANSLATION
+
+Translation is considered a kind of modification, so you may
+distribute translations of the Document under the terms of section 4.
+Replacing Invariant Sections with translations requires special
+permission from their copyright holders, but you may include
+translations of some or all Invariant Sections in addition to the
+original versions of these Invariant Sections. You may include a
+translation of this License, and all the license notices in the
+Document, and any Warranty Disclaimers, provided that you also include
+the original English version of this License and the original versions
+of those notices and disclaimers. In case of a disagreement between
+the translation and the original version of this License or a notice
+or disclaimer, the original version will prevail.
+
+If a section in the Document is Entitled ``Acknowledgements'',
+``Dedications'', or ``History'', the requirement (section 4) to Preserve
+its Title (section 1) will typically require changing the actual
+title.
+
+@item
+TERMINATION
+
+You may not copy, modify, sublicense, or distribute the Document except
+as expressly provided for under this License. Any other attempt to
+copy, modify, sublicense or distribute the Document is void, and will
+automatically terminate your rights under this License. However,
+parties who have received copies, or rights, from you under this
+License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+@item
+FUTURE REVISIONS OF THIS LICENSE
+
+The Free Software Foundation may publish new, revised versions
+of the GNU Free Documentation License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns. See
+@uref{http://www.gnu.org/copyleft/}.
+
+Each version of the License is given a distinguishing version number.
+If the Document specifies that a particular numbered version of this
+License ``or any later version'' applies to it, you have the option of
+following the terms and conditions either of that specified version or
+of any later version that has been published (not as a draft) by the
+Free Software Foundation. If the Document does not specify a version
+number of this License, you may choose any version ever published (not
+as a draft) by the Free Software Foundation.
+@end enumerate
+
+@page
+@c @appendixsubsec ADDENDUM: How to use this License for your
+@c documents
+@subsection ADDENDUM: How to use this License for your documents
+
+To use this License in a document you have written, include a copy of
+the License in the document and put the following copyright and
+license notices just after the title page:
+
+@smallexample
+@group
+ Copyright (C) @var{year} @var{your name}.
+ Permission is granted to copy, distribute and/or modify this document
+ under the terms of the GNU Free Documentation License, Version 1.2
+ or any later version published by the Free Software Foundation;
+ with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
+ Texts. A copy of the license is included in the section entitled ``GNU
+ Free Documentation License''.
+@end group
+@end smallexample
+
+If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
+replace the ``with...Texts.'' line with this:
+
+@smallexample
+@group
+ with the Invariant Sections being @var{list their titles}, with
+ the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
+ being @var{list}.
+@end group
+@end smallexample
+
+If you have Invariant Sections without Cover Texts, or some other
+combination of the three, merge those two alternatives to suit the
+situation.
+
+If your document contains nontrivial examples of program code, we
+recommend releasing these examples in parallel under your choice of
+free software license, such as the GNU General Public License,
+to permit their use in free software.
+
+@c Local Variables:
+@c ispell-local-pdict: "ispell-dict"
+@c End:
+
diff --git a/doc/user-guide/fuse.odg b/doc/user-guide/fuse.odg
new file mode 100644
index 000000000..61bd103c7
--- /dev/null
+++ b/doc/user-guide/fuse.odg
Binary files differ
diff --git a/doc/user-guide/fuse.pdf b/doc/user-guide/fuse.pdf
new file mode 100644
index 000000000..a7d13faff
--- /dev/null
+++ b/doc/user-guide/fuse.pdf
Binary files differ
diff --git a/doc/user-guide/ha.odg b/doc/user-guide/ha.odg
new file mode 100644
index 000000000..e4b8b72d0
--- /dev/null
+++ b/doc/user-guide/ha.odg
Binary files differ
diff --git a/doc/user-guide/ha.pdf b/doc/user-guide/ha.pdf
new file mode 100644
index 000000000..e372c0ab0
--- /dev/null
+++ b/doc/user-guide/ha.pdf
Binary files differ
diff --git a/doc/user-guide/stripe.odg b/doc/user-guide/stripe.odg
new file mode 100644
index 000000000..79441bf14
--- /dev/null
+++ b/doc/user-guide/stripe.odg
Binary files differ
diff --git a/doc/user-guide/stripe.pdf b/doc/user-guide/stripe.pdf
new file mode 100644
index 000000000..b94446feb
--- /dev/null
+++ b/doc/user-guide/stripe.pdf
Binary files differ
diff --git a/doc/user-guide/unify.odg b/doc/user-guide/unify.odg
new file mode 100644
index 000000000..ccaa9bf16
--- /dev/null
+++ b/doc/user-guide/unify.odg
Binary files differ
diff --git a/doc/user-guide/unify.pdf b/doc/user-guide/unify.pdf
new file mode 100644
index 000000000..c22027f66
--- /dev/null
+++ b/doc/user-guide/unify.pdf
Binary files differ
diff --git a/doc/user-guide/user-guide.info b/doc/user-guide/user-guide.info
new file mode 100644
index 000000000..078d62ade
--- /dev/null
+++ b/doc/user-guide/user-guide.info
@@ -0,0 +1,2698 @@
+This is ../../../doc/user-guide/user-guide.info, produced by makeinfo
+version 4.9 from ../../../doc/user-guide/user-guide.texi.
+
+START-INFO-DIR-ENTRY
+* GlusterFS: (user-guide). GlusterFS distributed filesystem user guide
+END-INFO-DIR-ENTRY
+
+ This is the user manual for GlusterFS 2.0.
+
+ Copyright (C) 2008,2007 <Z> Research, Inc. Permission is granted to
+copy, distribute and/or modify this document under the terms of the GNU
+Free Documentation License, Version 1.2 or any later version published
+by the Free Software Foundation; with no Invariant Sections, no
+Front-Cover Texts, and no Back-Cover Texts. A copy of the license is
+included in the chapter entitled "GNU Free Documentation License".
+
+
+File: user-guide.info, Node: Top, Next: Acknowledgements, Up: (dir)
+
+GlusterFS 2.0 User Guide
+************************
+
+This is the user manual for GlusterFS 2.0.
+
+ Copyright (C) 2008,2007 <Z> Research, Inc. Permission is granted to
+copy, distribute and/or modify this document under the terms of the GNU
+Free Documentation License, Version 1.2 or any later version published
+by the Free Software Foundation; with no Invariant Sections, no
+Front-Cover Texts, and no Back-Cover Texts. A copy of the license is
+included in the chapter entitled "GNU Free Documentation License".
+
+* Menu:
+
+* Acknowledgements::
+* Introduction::
+* Installation and Invocation::
+* Concepts::
+* Translators::
+* Usage Scenarios::
+* Troubleshooting::
+* GNU Free Documentation Licence::
+* Index::
+
+ --- The Detailed Node Listing ---
+
+Installation and Invocation
+
+* Pre requisites::
+* Getting GlusterFS::
+* Building::
+* Running GlusterFS::
+* A Tutorial Introduction::
+
+Running GlusterFS
+
+* Server::
+* Client::
+
+Concepts
+
+* Filesystems in Userspace::
+* Translator::
+* Volume specification file::
+
+Translators
+
+* Storage Translators::
+* Client and Server Translators::
+* Clustering Translators::
+* Performance Translators::
+* Features Translators::
+
+Storage Translators
+
+* POSIX::
+
+Client and Server Translators
+
+* Transport modules::
+* Client protocol::
+* Server protocol::
+
+Clustering Translators
+
+* Unify::
+* Replicate::
+* Stripe::
+
+Performance Translators
+
+* Read Ahead::
+* Write Behind::
+* IO Threads::
+* IO Cache::
+
+Features Translators
+
+* POSIX Locks::
+* Fixed ID::
+
+Miscellaneous Translators
+
+* ROT-13::
+* Trace::
+
+
+File: user-guide.info, Node: Acknowledgements, Next: Introduction, Prev: Top, Up: Top
+
+Acknowledgements
+****************
+
+GlusterFS continues to be a wonderful and enriching experience for all
+of us involved.
+
+ GlusterFS development would not have been possible at this pace if
+not for our enthusiastic users. People from around the world have
+helped us with bug reports, performance numbers, and feature
+suggestions. A huge thanks to them all.
+
+ Matthew Paine - for RPMs & general enthu
+
+ Leonardo Rodrigues de Mello - for DEBs
+
+ Julian Perez & Adam D'Auria - for multi-server tutorial
+
+ Paul England - for HA spec
+
+ Brent Nelson - for many bug reports
+
+ Jacques Mattheij - for Europe mirror.
+
+ Patrick Negri - for TCP non-blocking connect.
+ http://gluster.org/core-team.php (<list-hacking@zresearch.com>)
+ <Z> Research
+
+
+File: user-guide.info, Node: Introduction, Next: Installation and Invocation, Prev: Acknowledgements, Up: Top
+
+1 Introduction
+**************
+
+GlusterFS is a distributed filesystem. It works at the file level, not
+block level.
+
+ A network filesystem is one which allows us to access remote files. A
+distributed filesystem is one that stores data on multiple machines and
+makes them all appear to be a part of the same filesystem.
+
+ Need for distributed filesystems
+
+ * Scalability: A distributed filesystem allows us to store more data
+ than what can be stored on a single machine.
+
+ * Redundancy: We might want to replicate crucial data on to several
+ machines.
+
+ * Uniform access: One can mount a remote volume (for example your
+ home directory) from any machine and access the same data.
+
+1.1 Contacting us
+=================
+
+You can reach us through the mailing list *gluster-devel*
+(<gluster-devel@nongnu.org>).
+
+ You can also find many of the developers on IRC, on the `#gluster'
+channel on Freenode (<irc.freenode.net>).
+
+ The GlusterFS documentation wiki is also useful:
+<http://gluster.org/docs/index.php/GlusterFS>
+
+ For commercial support, you can contact <Z> Research at:
+
+ 3194 Winding Vista Common
+ Fremont, CA 94539
+ USA.
+
+ Phone: +1 (510) 354 6801
+ Toll free: +1 (888) 813 6309
+ Fax: +1 (510) 372 0604
+
+ You can also email us at <support@zresearch.com>.
+
+
+File: user-guide.info, Node: Installation and Invocation, Next: Concepts, Prev: Introduction, Up: Top
+
+2 Installation and Invocation
+*****************************
+
+* Menu:
+
+* Pre requisites::
+* Getting GlusterFS::
+* Building::
+* Running GlusterFS::
+* A Tutorial Introduction::
+
+
+File: user-guide.info, Node: Pre requisites, Next: Getting GlusterFS, Up: Installation and Invocation
+
+2.1 Pre requisites
+==================
+
+Before installing GlusterFS make sure you have the following components
+installed.
+
+2.1.1 FUSE
+----------
+
+You'll need FUSE version 2.6.0 or higher to use GlusterFS. You can omit
+installing FUSE if you want to build _only_ the server. Note that you
+won't be able to mount a GlusterFS filesystem on a machine that does
+not have FUSE installed.
+
+ FUSE can be downloaded from: <http://fuse.sourceforge.net/>
+
+ To get the best performance from GlusterFS, however, it is
+recommended that you use our patched version of FUSE. See Patched FUSE
+for details.
+
+2.1.2 Patched FUSE
+------------------
+
+The GlusterFS project maintains a patched version of FUSE meant to be
+used with GlusterFS. The patches increase GlusterFS performance. It is
+recommended that all users use the patched FUSE.
+
+ The patched FUSE tarball can be downloaded from:
+
+ <ftp://ftp.zresearch.com/pub/gluster/glusterfs/fuse/>
+
+ The specific changes made to FUSE are:
+
+ * The communication channel size between FUSE kernel module and
+ GlusterFS has been increased to 1MB, permitting large reads and
+ writes to be sent in bigger chunks.
+
+ * The kernel's read-ahead boundry has been extended upto 1MB.
+
+ * Block size returned in the `stat()'/`fstat()' calls tuned to 1MB,
+ to make cp and similar commands perform I/O using that block size.
+
+ * `flock()' locking support has been added (although some rework in
+ GlusterFS is needed for perfect compliance).
+
+2.1.3 libibverbs (optional)
+---------------------------
+
+This is only needed if you want GlusterFS to use InfiniBand as the
+interconnect mechanism between server and client. You can get it from:
+
+ <http://www.openfabrics.org/downloads.htm>.
+
+2.1.4 Bison and Flex
+--------------------
+
+These should be already installed on most Linux systems. If not, use
+your distribution's normal software installation procedures to install
+them. Make sure you install the relevant developer packages also.
+
+
+File: user-guide.info, Node: Getting GlusterFS, Next: Building, Prev: Pre requisites, Up: Installation and Invocation
+
+2.2 Getting GlusterFS
+=====================
+
+There are many ways to get hold of GlusterFS. For a production
+deployment, the recommended method is to download the latest release
+tarball. Release tarballs are available at:
+<http://gluster.org/download.php>.
+
+ If you want the bleeding edge development source, you can get them
+from the GNU Arch(1) repository. First you must install GNU Arch
+itself. Then register the GlusterFS archive by doing:
+
+ $ tla register-archive http://arch.sv.gnu.org/archives/gluster
+
+ Now you can check out the source itself:
+
+ $ tla get -A gluster@sv.gnu.org glusterfs--mainline--3.0
+
+ ---------- Footnotes ----------
+
+ (1) <http://www.gnu.org/software/gnu-arch/>
+
+
+File: user-guide.info, Node: Building, Next: Running GlusterFS, Prev: Getting GlusterFS, Up: Installation and Invocation
+
+2.3 Building
+============
+
+You can skip this section if you're installing from RPMs or DEBs.
+
+ GlusterFS uses the Autotools mechanism to build. As such, the
+procedure is straight-forward. First, change into the GlusterFS source
+directory.
+
+ $ cd glusterfs-<version>
+
+ If you checked out the source from the Arch repository, you'll need
+to run `./autogen.sh' first. Note that you'll need to have Autoconf and
+Automake installed for this.
+
+ Run `configure'.
+
+ $ ./configure
+
+ The configure script accepts the following options:
+
+`--disable-ibverbs'
+ Disable the InfiniBand transport mechanism.
+
+`--disable-fuse-client'
+ Disable the FUSE client.
+
+`--disable-server'
+ Disable building of the GlusterFS server.
+
+`--disable-bdb'
+ Disable building of Berkeley DB based storage translator.
+
+`--disable-mod_glusterfs'
+ Disable building of Apache/lighttpd glusterfs plugins.
+
+`--disable-epoll'
+ Use poll instead of epoll.
+
+`--disable-libglusterfsclient'
+ Disable building of libglusterfsclient
+
+
+ Build and install GlusterFS.
+
+ # make install
+
+ The binaries (`glusterfsd' and `glusterfs') will be by default
+installed in `/usr/local/sbin/'. Translator, scheduler, and transport
+shared libraries will be installed in
+`/usr/local/lib/glusterfs/<version>/'. Sample volume specification
+files will be in `/usr/local/etc/glusterfs/'. This document itself can
+be found in `/usr/local/share/doc/glusterfs/'. If you passed the
+`--prefix' argument to the configure script, then replace `/usr/local'
+in the preceding paths with the prefix.
+
+
+File: user-guide.info, Node: Running GlusterFS, Next: A Tutorial Introduction, Prev: Building, Up: Installation and Invocation
+
+2.4 Running GlusterFS
+=====================
+
+* Menu:
+
+* Server::
+* Client::
+
+
+File: user-guide.info, Node: Server, Next: Client, Up: Running GlusterFS
+
+2.4.1 Server
+------------
+
+The GlusterFS server is necessary to export storage volumes to remote
+clients (See *Note Server protocol:: for more info). This section
+documents the invocation of the GlusterFS server program and all the
+command-line options accepted by it.
+
+ Basic Options
+
+`-f, --volfile=<path>'
+ Use the volume file as the volume specification.
+
+`-s, --volfile-server=<hostname>'
+ Server to get volume file from. This option overrides -volfile
+ option.
+
+`-l, --log-file=<path>'
+ Specify the path for the log file.
+
+`-L, --log-level=<level>'
+ Set the log level for the server. Log level should be one of DEBUG,
+ WARNING, ERROR, CRITICAL, or NONE.
+
+ Advanced Options
+
+`--debug'
+ Run in debug mode. This option sets -no-daemon, -log-level to
+ DEBUG and -log-file to console.
+
+`-N, --no-daemon'
+ Run glusterfsd as a foreground process.
+
+`-p, --pid-file=<path>'
+ Path for the PID file.
+
+`--volfile-id=<key>'
+ 'key' of the volfile to be fetched from server.
+
+`--volfile-server-port=<port-number>'
+ Listening port number of volfile server.
+
+`--volfile-server-transport=[socket|ib-verbs]'
+ Transport type to get volfile from server. [default: `socket']
+
+`--xlator-options=<volume-name.option=value>'
+ Add/override a translator option for a volume with specified value.
+
+ Miscellaneous Options
+
+`-?, --help'
+ Show this help text.
+
+`--usage'
+ Display a short usage message.
+
+`-V, --version'
+ Show version information.
+
+
+File: user-guide.info, Node: Client, Prev: Server, Up: Running GlusterFS
+
+2.4.2 Client
+------------
+
+The GlusterFS client process is necessary to access remote storage
+volumes and mount them locally using FUSE. This section documents the
+invocation of the client process and all its command-line arguments.
+
+ # glusterfs [options] <mountpoint>
+
+ The `mountpoint' is the directory where you want the GlusterFS
+filesystem to appear. Example:
+
+ # glusterfs -f /usr/local/etc/glusterfs-client.vol /mnt
+
+ The command-line options are detailed below.
+
+ Basic Options
+
+`-f, --volfile=<path>'
+ Use the volume file as the volume specification.
+
+`-s, --volfile-server=<hostname>'
+ Server to get volume file from. This option overrides -volfile
+ option.
+
+`-l, --log-file=<path>'
+ Specify the path for the log file.
+
+`-L, --log-level=<level>'
+ Set the log level for the server. Log level should be one of DEBUG,
+ WARNING, ERROR, CRITICAL, or NONE.
+
+ Advanced Options
+
+`--debug'
+ Run in debug mode. This option sets -no-daemon, -log-level to
+ DEBUG and -log-file to console.
+
+`-N, --no-daemon'
+ Run `glusterfs' as a foreground process.
+
+`-p, --pid-file=<path>'
+ Path for the PID file.
+
+`--volfile-id=<key>'
+ 'key' of the volfile to be fetched from server.
+
+`--volfile-server-port=<port-number>'
+ Listening port number of volfile server.
+
+`--volfile-server-transport=[socket|ib-verbs]'
+ Transport type to get volfile from server. [default: `socket']
+
+`--xlator-options=<volume-name.option=value>'
+ Add/override a translator option for a volume with specified value.
+
+`--volume-name=<volume name>'
+ Volume name in client spec to use. Defaults to the root volume.
+
+ FUSE Options
+
+`--attribute-timeout=<n>'
+ Attribute timeout for inodes in the kernel, in seconds. Defaults
+ to 1 second.
+
+`--disable-direct-io-mode'
+ Disable direct I/O mode in FUSE kernel module.
+
+`-e, --entry-timeout=<n>'
+ Entry timeout for directory entries in the kernel, in seconds.
+ Defaults to 1 second.
+
+ Missellaneous Options
+
+`-?, --help'
+ Show this help information.
+
+`-V, --version'
+ Show version information.
+
+
+File: user-guide.info, Node: A Tutorial Introduction, Prev: Running GlusterFS, Up: Installation and Invocation
+
+2.5 A Tutorial Introduction
+===========================
+
+This section will show you how to quickly get GlusterFS up and running.
+We'll configure GlusterFS as a simple network filesystem, with one
+server and one client. In this mode of usage, GlusterFS can serve as a
+replacement for NFS.
+
+ We'll make use of two machines; call them _server_ and _client_ (If
+you don't want to setup two machines, just run everything that follows
+on the same machine). In the examples that follow, the shell prompts
+will use these names to clarify the machine on which the command is
+being run. For example, a command that should be run on the server will
+be shown with the prompt:
+
+ [root@server]#
+
+ Our goal is to make a directory on the _server_ (say, `/export')
+accessible to the _client_.
+
+ First of all, get GlusterFS installed on both the machines, as
+described in the previous sections. Make sure you have the FUSE kernel
+module loaded. You can ensure this by running:
+
+ [root@server]# modprobe fuse
+
+ Before we can run the GlusterFS client or server programs, we need
+to write two files called _volume specifications_ (equivalently refered
+to as _volfiles_). The volfile describes the _translator tree_ on a
+node. The next chapter will explain the concepts of `translator' and
+`volume specification' in detail. For now, just assume that the volfile
+is like an NFS `/etc/export' file.
+
+ On the server, create a text file somewhere (we'll assume the path
+`/tmp/glusterfsd.vol') with the following contents.
+
+ volume colon-o
+ type storage/posix
+ option directory /export
+ end-volume
+
+ volume server
+ type protocol/server
+ subvolumes colon-o
+ option transport-type tcp
+ option auth.addr.colon-o.allow *
+ end-volume
+
+ A brief explanation of the file's contents. The first section
+defines a storage volume, named "colon-o" (the volume names are
+arbitrary), which exports the `/export' directory. The second section
+defines options for the translator which will make the storage volume
+accessible remotely. It specifies `colon-o' as a subvolume. This
+defines the _translator tree_, about which more will be said in the
+next chapter. The two options specify that the TCP protocol is to be
+used (as opposed to InfiniBand, for example), and that access to the
+storage volume is to be provided to clients with any IP address at all.
+If you wanted to restrict access to this server to only your subnet for
+example, you'd specify something like `192.168.1.*' in the second
+option line.
+
+ On the client machine, create the following text file (again, we'll
+assume the path to be `/tmp/glusterfs-client.vol'). Replace
+_server-ip-address_ with the IP address of your server machine. If you
+are doing all this on a single machine, use `127.0.0.1'.
+
+ volume client
+ type protocol/client
+ option transport-type tcp
+ option remote-host _server-ip-address_
+ option remote-subvolume colon-o
+ end-volume
+
+ Now we need to start both the server and client programs. To start
+the server:
+
+ [root@server]# glusterfsd -f /tmp/glusterfs-server.vol
+
+ To start the client:
+
+ [root@client]# glusterfs -f /tmp/glusterfs-client.vol /mnt/glusterfs
+
+ You should now be able to see the files under the server's `/export'
+directory in the `/mnt/glusterfs' directory on the client. That's it;
+GlusterFS is now working as a network file system.
+
+
+File: user-guide.info, Node: Concepts, Next: Translators, Prev: Installation and Invocation, Up: Top
+
+3 Concepts
+**********
+
+* Menu:
+
+* Filesystems in Userspace::
+* Translator::
+* Volume specification file::
+
+
+File: user-guide.info, Node: Filesystems in Userspace, Next: Translator, Up: Concepts
+
+3.1 Filesystems in Userspace
+============================
+
+A filesystem is usually implemented in kernel space. Kernel space
+development is much harder than userspace development. FUSE is a kernel
+module/library that allows us to write a filesystem completely in
+userspace.
+
+ FUSE consists of a kernel module which interacts with the userspace
+implementation using a device file `/dev/fuse'. When a process makes a
+syscall on a FUSE filesystem, VFS hands the request to the FUSE module,
+which writes the request to `/dev/fuse'. The userspace implementation
+polls `/dev/fuse', and when a request arrives, processes it and writes
+the result back to `/dev/fuse'. The kernel then reads from the device
+file and returns the result to the user process.
+
+ In case of GlusterFS, the userspace program is the GlusterFS client.
+The control flow is shown in the diagram below. The GlusterFS client
+services the request by sending it to the server, which in turn hands
+it to the local POSIX filesystem.
+
+
+ Fig 1. Control flow in GlusterFS
+
+
+File: user-guide.info, Node: Translator, Next: Volume specification file, Prev: Filesystems in Userspace, Up: Concepts
+
+3.2 Translator
+==============
+
+The _translator_ is the most important concept in GlusterFS. In fact,
+GlusterFS is nothing but a collection of translators working together,
+forming a translator _tree_.
+
+ The idea of a translator is perhaps best understood using an
+analogy. Consider the VFS in the Linux kernel. The VFS abstracts the
+various filesystem implementations (such as EXT3, ReiserFS, XFS, etc.)
+supported by the kernel. When an application calls the kernel to
+perform an operation on a file, the kernel passes the request on to the
+appropriate filesystem implementation.
+
+ For example, let's say there are two partitions on a Linux machine:
+`/', which is an EXT3 partition, and `/usr', which is a ReiserFS
+partition. Now if an application wants to open a file called, say,
+`/etc/fstab', then the kernel will internally pass the request to the
+EXT3 implementation. If on the other hand, an application wants to
+read a file called `/usr/src/linux/CREDITS', then the kernel will call
+upon the ReiserFS implementation to do the job.
+
+ The "filesystem implementation" objects are analogous to GlusterFS
+translators. A GlusterFS translator implements all the filesystem
+operations. Whereas in VFS there is a two-level tree (with the kernel
+at the root and all the filesystem implementation as its children), in
+GlusterFS there exists a more elaborate tree structure.
+
+ We can now define translators more precisely. A GlusterFS translator
+is a shared object (`.so') that implements every filesystem call.
+GlusterFS translators can be arranged in an arbitrary tree structure
+(subject to constraints imposed by the translators). When GlusterFS
+receives a filesystem call, it passes it on to the translator at the
+root of the translator tree. The root translator may in turn pass it on
+to any or all of its children, and so on, until the leaf nodes are
+reached. The result of a filesystem call is communicated in the reverse
+fashion, from the leaf nodes up to the root node, and then on to the
+application.
+
+ So what might a translator tree look like?
+
+
+ Fig 2. A sample translator tree
+
+ The diagram depicts three servers and one GlusterFS client. It is
+important to note that conceptually, the translator tree spans machine
+boundaries. Thus, the client machine in the diagram, `10.0.0.1', can
+access the aggregated storage of the filesystems on the server machines
+`10.0.0.2', `10.0.0.3', and `10.0.0.4'. The translator diagram will
+make more sense once you've read the next chapter and understood the
+functions of the various translators.
+
+
+File: user-guide.info, Node: Volume specification file, Prev: Translator, Up: Concepts
+
+3.3 Volume specification file
+=============================
+
+The volume specification file describes the translator tree for both the
+server and client programs.
+
+ A volume specification file is a sequence of volume definitions.
+The syntax of a volume definition is explained below:
+
+ *volume* _volume-name_
+ *type* _translator-name_
+ *option* _option-name_ _option-value_
+ ...
+ *subvolumes* _subvolume1_ _subvolume2_ ...
+ *end-volume*
+
+ ...
+
+_volume-name_
+ An identifier for the volume. This is just a human-readable name,
+ and can contain any alphanumeric character. For instance,
+ "storage-1", "colon-o", or "forty-two".
+
+_translator-name_
+ Name of one of the available translators. Example:
+ `protocol/client', `cluster/unify'.
+
+_option-name_
+ Name of a valid option for the translator.
+
+_option-value_
+ Value for the option. Everything following the "option" keyword to
+ the end of the line is considered the value; it is up to the
+ translator to parse it.
+
+_subvolume1_, _subvolume2_, ...
+ Volume names of sub-volumes. The sub-volumes must already have
+ been defined earlier in the file.
+
+ There are a few rules you must follow when writing a volume
+specification file:
+
+ * Everything following a ``#'' is considered a comment and is
+ ignored. Blank lines are also ignored.
+
+ * All names and keywords are case-sensitive.
+
+ * The order of options inside a volume definition does not matter.
+
+ * An option value may not span multiple lines.
+
+ * If an option is not specified, it will assume its default value.
+
+ * A sub-volume must have already been defined before it can be
+ referenced. This means you have to write the specification file
+ "bottom-up", starting from the leaf nodes of the translator tree
+ and moving up to the root.
+
+ A simple example volume specification file is shown below:
+
+ # This is a comment line
+ volume client
+ type protocol/client
+ option transport-type tcp
+ option remote-host localhost # Also a comment
+ option remote-subvolume brick
+ # The subvolumes line may be absent
+ end-volume
+
+ volume iot
+ type performance/io-threads
+ option thread-count 4
+ subvolumes client
+ end-volume
+
+ volume wb
+ type performance/write-behind
+ subvolumes iot
+ end-volume
+
+
+File: user-guide.info, Node: Translators, Next: Usage Scenarios, Prev: Concepts, Up: Top
+
+4 Translators
+*************
+
+* Menu:
+
+* Storage Translators::
+* Client and Server Translators::
+* Clustering Translators::
+* Performance Translators::
+* Features Translators::
+* Miscellaneous Translators::
+
+ This chapter documents all the available GlusterFS translators in
+detail. Each translator section will show its name (for example,
+`cluster/unify'), briefly describe its purpose and workings, and list
+every option accepted by that translator and their meaning.
+
+
+File: user-guide.info, Node: Storage Translators, Next: Client and Server Translators, Up: Translators
+
+4.1 Storage Translators
+=======================
+
+The storage translators form the "backend" for GlusterFS. Currently,
+the only available storage translator is the POSIX translator, which
+stores files on a normal POSIX filesystem. A pleasant consequence of
+this is that your data will still be accessible if GlusterFS crashes or
+cannot be started.
+
+ Other storage backends are planned for the future. One of the
+possibilities is an Amazon S3 translator. Amazon S3 is an unlimited
+online storage service accessible through a web services API. The S3
+translator will allow you to access the storage as a normal POSIX
+filesystem. (1)
+
+* Menu:
+
+* POSIX::
+* BDB::
+
+ ---------- Footnotes ----------
+
+ (1) Some more discussion about this can be found at:
+
+http://developer.amazonwebservices.com/connect/message.jspa?messageID=52873
+
+
+File: user-guide.info, Node: POSIX, Next: BDB, Up: Storage Translators
+
+4.1.1 POSIX
+-----------
+
+ type storage/posix
+
+ The `posix' translator uses a normal POSIX filesystem as its
+"backend" to actually store files and directories. This can be any
+filesystem that supports extended attributes (EXT3, ReiserFS, XFS,
+...). Extended attributes are used by some translators to store
+metadata, for example, by the replicate and stripe translators. See
+*Note Replicate:: and *Note Stripe::, respectively for details.
+
+`directory <path>'
+ The directory on the local filesystem which is to be used for
+ storage.
+
+
+File: user-guide.info, Node: BDB, Prev: POSIX, Up: Storage Translators
+
+4.1.2 BDB
+---------
+
+ type storage/bdb
+
+ The `BDB' translator uses a Berkeley DB database as its "backend" to
+actually store files as key-value pair in the database and directories
+as regular POSIX directories. Note that BDB does not provide extended
+attribute support for regular files. Do not use BDB as storage
+translator while using any translator that demands extended attributes
+on "backend".
+
+`directory <path>'
+ The directory on the local filesystem which is to be used for
+ storage.
+
+`mode [cache|persistent] (cache)'
+ When BDB is run in `cache' mode, recovery of back-end is not
+ completely guaranteed. `persistent' guarantees that BDB can
+ recover back-end from Berkeley DB even if GlusterFS crashes.
+
+`errfile <path>'
+ The path of the file to be used as `errfile' for Berkeley DB to
+ report detailed error messages, if any. Note that all the contents
+ of this file will be written by Berkeley DB, not GlusterFS.
+
+`logdir <path>'
+
+
+File: user-guide.info, Node: Client and Server Translators, Next: Clustering Translators, Prev: Storage Translators, Up: Translators
+
+4.2 Client and Server Translators
+=================================
+
+The client and server translator enable GlusterFS to export a
+translator tree over the network or access a remote GlusterFS server.
+These two translators implement GlusterFS's network protocol.
+
+* Menu:
+
+* Transport modules::
+* Client protocol::
+* Server protocol::
+
+
+File: user-guide.info, Node: Transport modules, Next: Client protocol, Up: Client and Server Translators
+
+4.2.1 Transport modules
+-----------------------
+
+The client and server translators are capable of using any of the
+pluggable transport modules. Currently available transport modules are
+`tcp', which uses a TCP connection between client and server to
+communicate; `ib-sdp', which uses a TCP connection over InfiniBand, and
+`ibverbs', which uses high-speed InfiniBand connections.
+
+ Each transport module comes in two different versions, one to be
+used on the server side and the other on the client side.
+
+4.2.1.1 TCP
+...........
+
+The TCP transport module uses a TCP/IP connection between the server
+and the client.
+
+ option transport-type tcp
+
+ The TCP client module accepts the following options:
+
+`non-blocking-connect [no|off|on|yes] (on)'
+ Whether to make the connection attempt asynchronous.
+
+`remote-port <n> (6996)'
+ Server port to connect to.
+
+`remote-host <hostname> *'
+ Hostname or IP address of the server. If the host name resolves to
+ multiple IP addresses, all of them will be tried in a round-robin
+ fashion. This feature can be used to implement fail-over.
+
+ The TCP server module accepts the following options:
+
+`bind-address <address> (0.0.0.0)'
+ The local interface on which the server should listen to requests.
+ Default is to listen on all interfaces.
+
+`listen-port <n> (6996)'
+ The local port to listen on.
+
+4.2.1.2 IB-SDP
+..............
+
+ option transport-type ib-sdp
+
+ kernel implements socket interface for ib hardware. SDP is over
+ib-verbs. This module accepts the same options as `tcp'
+
+4.2.1.3 ibverbs
+...............
+
+ option transport-type tcp
+
+ InfiniBand is a scalable switched fabric interconnect mechanism
+primarily used in high-performance computing. InfiniBand can deliver
+data throughput of the order of 10 Gbit/s, with latencies of 4-5 ms.
+
+ The `ib-verbs' transport accesses the InfiniBand hardware through
+the "verbs" API, which is the lowest level of software access possible
+and which gives the highest performance. On InfiniBand hardware, it is
+always best to use `ib-verbs'. Use `ib-sdp' only if you cannot get
+`ib-verbs' working for some reason.
+
+ The `ib-verbs' client module accepts the following options:
+
+`non-blocking-connect [no|off|on|yes] (on)'
+ Whether to make the connection attempt asynchronous.
+
+`remote-port <n> (6996)'
+ Server port to connect to.
+
+`remote-host <hostname> *'
+ Hostname or IP address of the server. If the host name resolves to
+ multiple IP addresses, all of them will be tried in a round-robin
+ fashion. This feature can be used to implement fail-over.
+
+ The `ib-verbs' server module accepts the following options:
+
+`bind-address <address> (0.0.0.0)'
+ The local interface on which the server should listen to requests.
+ Default is to listen on all interfaces.
+
+`listen-port <n> (6996)'
+ The local port to listen on.
+
+ The following options are common to both the client and server
+modules:
+
+ If you are familiar with InfiniBand jargon, the mode is used by
+GlusterFS is "reliable connection-oriented channel transfer".
+
+`ib-verbs-work-request-send-count <n> (64)'
+ Length of the send queue in datagrams. [Reason to
+ increase/decrease?]
+
+`ib-verbs-work-request-recv-count <n> (64)'
+ Length of the receive queue in datagrams. [Reason to
+ increase/decrease?]
+
+`ib-verbs-work-request-send-size <size> (128KB)'
+ Size of each datagram that is sent. [Reason to increase/decrease?]
+
+`ib-verbs-work-request-recv-size <size> (128KB)'
+ Size of each datagram that is received. [Reason to
+ increase/decrease?]
+
+`ib-verbs-port <n> (1)'
+ Port number for ib-verbs.
+
+`ib-verbs-mtu [256|512|1024|2048|4096] (2048)'
+ The Maximum Transmission Unit [Reason to increase/decrease?]
+
+`ib-verbs-device-name <device-name> (first device in the list)'
+ InfiniBand device to be used.
+
+ For maximum performance, you should ensure that the send/receive
+counts on both the client and server are the same.
+
+ ib-verbs is preferred over ib-sdp.
+
+
+File: user-guide.info, Node: Client protocol, Next: Server protocol, Prev: Transport modules, Up: Client and Server Translators
+
+4.2.2 Client
+------------
+
+ type procotol/client
+
+ The client translator enables the GlusterFS client to access a
+remote server's translator tree.
+
+`transport-type [tcp,ib-sdp,ib-verbs] (tcp)'
+ The transport type to use. You should use the client versions of
+ all the transport modules (`tcp', `ib-sdp', `ib-verbs').
+
+`remote-subvolume <volume_name> *'
+ The name of the volume on the remote host to attach to. Note that
+ this is _not_ the name of the `protocol/server' volume on the
+ server. It should be any volume under the server.
+
+`transport-timeout <n> (120- seconds)'
+ Inactivity timeout. If a reply is expected and no activity takes
+ place on the connection within this time, the transport connection
+ will be broken, and a new connection will be attempted.
+
+
+File: user-guide.info, Node: Server protocol, Prev: Client protocol, Up: Client and Server Translators
+
+4.2.3 Server
+------------
+
+ type protocol/server
+
+ The server translator exports a translator tree and makes it
+accessible to remote GlusterFS clients.
+
+`client-volume-filename <path> (<CONFDIR>/glusterfs-client.vol)'
+ The volume specification file to use for the client. This is the
+ file the client will receive when it is invoked with the
+ `--server' option (*Note Client::).
+
+`transport-type [tcp,ib-verbs,ib-sdp] (tcp)'
+ The transport to use. You should use the server versions of all
+ the transport modules (`tcp', `ib-sdp', `ib-verbs').
+
+`auth.addr.<volume name>.allow <IP address wildcard pattern>'
+ IP addresses of the clients that are allowed to attach to the
+ specified volume. This can be a wildcard. For example, a wildcard
+ of the form `192.168.*.*' allows any host in the `192.168.x.x'
+ subnet to connect to the server.
+
+
+
+File: user-guide.info, Node: Clustering Translators, Next: Performance Translators, Prev: Client and Server Translators, Up: Translators
+
+4.3 Clustering Translators
+==========================
+
+The clustering translators are the most important GlusterFS
+translators, since it is these that make GlusterFS a cluster
+filesystem. These translators together enable GlusterFS to access an
+arbitrarily large amount of storage, and provide RAID-like redundancy
+and distribution over the entire cluster.
+
+ There are three clustering translators: *unify*, *replicate*, and
+*stripe*. The unify translator aggregates storage from many server
+nodes. The replicate translator provides file replication. The stripe
+translator allows a file to be spread across many server nodes. The
+following sections look at each of these translators in detail.
+
+* Menu:
+
+* Unify::
+* Replicate::
+* Stripe::
+
+
+File: user-guide.info, Node: Unify, Next: Replicate, Up: Clustering Translators
+
+4.3.1 Unify
+-----------
+
+ type cluster/unify
+
+ The unify translator presents a `unified' view of all its
+sub-volumes. That is, it makes the union of all its sub-volumes appear
+as a single volume. It is the unify translator that gives GlusterFS the
+ability to access an arbitrarily large amount of storage.
+
+ For unify to work correctly, certain invariants need to be
+maintained across the entire network. These are:
+
+ * The directory structure of all the sub-volumes must be identical.
+
+ * A particular file can exist on only one of the sub-volumes.
+ Phrasing it in another way, a pathname such as
+ `/home/calvin/homework.txt') is unique across the entire cluster.
+
+
+
+Looking at the second requirement, you might wonder how one can
+accomplish storing redundant copies of a file, if no file can exist
+multiple times. To answer, we must remember that these invariants are
+from _unify's perspective_. A translator such as replicate at a lower
+level in the translator tree than unify may subvert this picture.
+
+ The first invariant might seem quite tedious to ensure. We shall see
+later that this is not so, since unify's _self-heal_ mechanism takes
+care of maintaining it.
+
+ The second invariant implies that unify needs some way to decide
+which file goes where. Unify makes use of _scheduler_ modules for this
+purpose.
+
+ When a file needs to be created, unify's scheduler decides upon the
+sub-volume to be used to store the file. There are many schedulers
+available, each using a different algorithm and suitable for different
+purposes.
+
+ The various schedulers are described in detail in the sections that
+follow.
+
+4.3.1.1 ALU
+...........
+
+ option scheduler alu
+
+ ALU stands for "Adaptive Least Usage". It is the most advanced
+scheduler available in GlusterFS. It balances the load across volumes
+taking several factors in account. It adapts itself to changing I/O
+patterns according to its configuration. When properly configured, it
+can eliminate the need for regular tuning of the filesystem to keep
+volume load nicely balanced.
+
+ The ALU scheduler is composed of multiple least-usage
+sub-schedulers. Each sub-scheduler keeps track of a certain type of
+load, for each of the sub-volumes, getting statistics from the
+sub-volumes themselves. The sub-schedulers are these:
+
+ * disk-usage: The used and free disk space on the volume.
+
+ * read-usage: The amount of reading done from this volume.
+
+ * write-usage: The amount of writing done to this volume.
+
+ * open-files-usage: The number of files currently open from this
+ volume.
+
+ * disk-speed-usage: The speed at which the disks are spinning. This
+ is a constant value and therefore not very useful.
+
+ The ALU scheduler needs to know which of these sub-schedulers to use,
+and in which order to evaluate them. This is done through the `option
+alu.order' configuration directive.
+
+ Each sub-scheduler needs to know two things: when to kick in (the
+entry-threshold), and how long to stay in control (the exit-threshold).
+For example: when unifying three disks of 100GB, keeping an exact
+balance of disk-usage is not necesary. Instead, there could be a 1GB
+margin, which can be used to nicely balance other factors, such as
+read-usage. The disk-usage scheduler can be told to kick in only when a
+certain threshold of discrepancy is passed, such as 1GB. When it
+assumes control under this condition, it will write all subsequent data
+to the least-used volume. If it is doing so, it is unwise to stop right
+after the values are below the entry-threshold again, since that would
+make it very likely that the situation will occur again very soon. Such
+a situation would cause the ALU to spend most of its time disk-usage
+scheduling, which is unfair to the other sub-schedulers. The
+exit-threshold therefore defines the amount of data that needs to be
+written to the least-used disk, before control is relinquished again.
+
+ In addition to the sub-schedulers, the ALU scheduler also has
+"limits" options. These can stop the creation of new files on a volume
+once values drop below a certain threshold. For example, setting
+`option alu.limits.min-free-disk 5GB' will stop the scheduling of files
+to volumes that have less than 5GB of free disk space, leaving the
+files on that disk some room to grow.
+
+ The actual values you assign to the thresholds for sub-schedulers and
+limits depend on your situation. If you have fast-growing files, you'll
+want to stop file-creation on a disk much earlier than when hardly any
+of your files are growing. If you care less about disk-usage balance
+than about read-usage balance, you'll want a bigger disk-usage
+scheduler entry-threshold and a smaller read-usage scheduler
+entry-threshold.
+
+ For thresholds defining a size, values specifying "KB", "MB" and "GB"
+are allowed. For example: `option alu.limits.min-free-disk 5GB'.
+
+`alu.order <order> * ("disk-usage:write-usage:read-usage:open-files-usage:disk-speed")'
+
+`alu.disk-usage.entry-threshold <size> (1GB)'
+
+`alu.disk-usage.exit-threshold <size> (512MB)'
+
+`alu.write-usage.entry-threshold <%> (25)'
+
+`alu.write-usage.exit-threshold <%> (5)'
+
+`alu.read-usage.entry-threshold <%> (25)'
+
+`alu.read-usage.exit-threshold <%> (5)'
+
+`alu.open-files-usage.entry-threshold <n> (1000)'
+
+`alu.open-files-usage.exit-threshold <n> (100)'
+
+`alu.limits.min-free-disk <%>'
+
+`alu.limits.max-open-files <n>'
+
+4.3.1.2 Round Robin (RR)
+........................
+
+ option scheduler rr
+
+ Round-Robin (RR) scheduler creates files in a round-robin fashion.
+Each client will have its own round-robin loop. When your files are
+mostly similar in size and I/O access pattern, this scheduler is a good
+choice. RR scheduler checks for free disk space on the server before
+scheduling, so you can know when to add another server node. The
+default value of min-free-disk is 5% and is checked on file creation
+calls, with atleast 10 seconds (by default) elapsing between two checks.
+
+ Options:
+`rr.limits.min-free-disk <%> (5)'
+ Minimum free disk space a node must have for RR to schedule a file
+ to it.
+
+`rr.refresh-interval <t> (10 seconds)'
+ Time between two successive free disk space checks.
+
+4.3.1.3 Random
+..............
+
+ option scheduler random
+
+ The random scheduler schedules file creation randomly among its
+child nodes. Like the round-robin scheduler, it also checks for a
+minimum amount of free disk space before scheduling a file to a node.
+
+`random.limits.min-free-disk <%> (5)'
+ Minimum free disk space a node must have for random to schedule a
+ file to it.
+
+`random.refresh-interval <t> (10 seconds)'
+ Time between two successive free disk space checks.
+
+4.3.1.4 NUFA
+............
+
+ option scheduler nufa
+
+ It is common in many GlusterFS computing environments for all
+deployed machines to act as both servers and clients. For example, a
+research lab may have 40 workstations each with its own storage. All of
+these workstations might act as servers exporting a volume as well as
+clients accessing the entire cluster's storage. In such a situation,
+it makes sense to store locally created files on the local workstation
+itself (assuming files are accessed most by the workstation that
+created them). The Non-Uniform File Allocation (NUFA) scheduler
+accomplishes that.
+
+ NUFA gives the local system first priority for file creation over
+other nodes. If the local volume does not have more free disk space
+than a specified amount (5% by default) then NUFA schedules files among
+the other child volumes in a round-robin fashion.
+
+ NUFA is named after the similar strategy used for memory access,
+NUMA(1).
+
+`nufa.limits.min-free-disk <%> (5)'
+ Minimum disk space that must be free (local or remote) for NUFA to
+ schedule a file to it.
+
+`nufa.refresh-interval <t> (10 seconds)'
+ Time between two successive free disk space checks.
+
+`nufa.local-volume-name <volume>'
+ The name of the volume corresponding to the local system. This
+ volume must be one of the children of the unify volume. This
+ option is mandatory.
+
+4.3.1.5 Namespace
+.................
+
+Namespace volume needed because: - persistent inode numbers. - file
+exists even when node is down.
+
+ namespace files are simply touched. on every lookup it is checked.
+
+`namespace <volume> *'
+ Name of the namespace volume (which should be one of the unify
+ volume's children).
+
+`self-heal [on|off] (on)'
+ Enable/disable self-heal. Unless you know what you are doing, do
+ not disable self-heal.
+
+4.3.1.6 Self Heal
+.................
+
+* When a 'lookup()/stat()' call is made on directory for the first
+time, a self-heal call is made, which checks for the consistancy of its
+child nodes. If an entry is present in storage node, but not in
+namespace, that entry is created in namespace, and vica-versa. There is
+an writedir() API introduced which is used for the same. It also checks
+for permissions, and uid/gid consistencies.
+
+ * This check is also done when an server goes down and comes up.
+
+ * If one starts with an empty namespace export, but has data in
+storage nodes, a 'find .>/dev/null' or 'ls -lR >/dev/null' should help
+to build namespace in one shot. Even otherwise, namespace is built on
+demand when a file is looked up for the first time.
+
+ NOTE: There are some issues (Kernel 'Oops' msgs) seen with
+fuse-2.6.3, when someone deletes namespace in backend, when glusterfs is
+running. But with fuse-2.6.5, this issue is not there.
+
+ ---------- Footnotes ----------
+
+ (1) Non-Uniform Memory Access:
+<http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access>
+
+
+File: user-guide.info, Node: Replicate, Next: Stripe, Prev: Unify, Up: Clustering Translators
+
+4.3.2 Replicate (formerly AFR)
+------------------------------
+
+ type cluster/replicate
+
+ Replicate provides RAID-1 like functionality for GlusterFS.
+Replicate replicates files and directories across the subvolumes. Hence
+if Replicate has four subvolumes, there will be four copies of all
+files and directories. Replicate provides high-availability, i.e., in
+case one of the subvolumes go down (e. g. server crash, network
+disconnection) Replicate will still service the requests using the
+redundant copies.
+
+ Replicate also provides self-heal functionality, i.e., in case the
+crashed servers come up, the outdated files and directories will be
+updated with the latest versions. Replicate uses extended attributes of
+the backend file system to track the versioning of files and
+directories and provide the self-heal feature.
+
+ volume replicate-example
+ type cluster/replicate
+ subvolumes brick1 brick2 brick3
+ end-volume
+
+ This sample configuration will replicate all directories and files on
+brick1, brick2 and brick3.
+
+ All the read operations happen from the first alive child. If all the
+three sub-volumes are up, reads will be done from brick1; if brick1 is
+down read will be done from brick2. In case read() was being done on
+brick1 and it goes down, replicate transparently falls back to brick2.
+
+ The next release of GlusterFS will add the following features:
+ * Ability to specify the sub-volume from which read operations are
+ to be done (this will help users who have one of the sub-volumes
+ as a local storage volume).
+
+ * Allow scheduling of read operations amongst the sub-volumes in a
+ round-robin fashion.
+
+ The order of the subvolumes list should be same across all the
+'replicate's as they will be used for locking purposes.
+
+4.3.2.1 Self Heal
+.................
+
+Replicate has self-heal feature, which updates the outdated file and
+directory copies by the most recent versions. For example consider the
+following config:
+
+ volume replicate-example
+ type cluster/replicate
+ subvolumes brick1 brick2
+ end-volume
+
+4.3.2.2 File self-heal
+......................
+
+Now if we create a file foo.txt on replicate-example, the file will be
+created on brick1 and brick2. The file will have two extended
+attributes associated with it in the backend filesystem. One is
+trusted.afr.createtime and the other is trusted.afr.version. The
+trusted.afr.createtime xattr has the create time (in terms of seconds
+since epoch) and trusted.afr.version is a number that is incremented
+each time a file is modified. This increment happens during close
+(incase any write was done before close).
+
+ If brick1 goes down, we edit foo.txt the version gets incremented.
+Now the brick1 comes back up, when we open() on foo.txt replicate will
+check if their versions are same. If they are not same, the outdated
+copy is replaced by the latest copy and its version is updated. After
+the sync the open() proceeds in the usual manner and the application
+calling open() can continue on its access to the file.
+
+ If brick1 goes down, we delete foo.txt and create a file with the
+same name again i.e foo.txt. Now brick1 comes back up, clearly there is
+a chance that the version on brick1 being more than the version on
+brick2, this is where createtime extended attribute helps in deciding
+which the outdated copy is. Hence we need to consider both createtime
+and version to decide on the latest copy.
+
+ The version attribute is incremented during the close() call. Version
+will not be incremented in case there was no write() done. In case the
+fd that the close() gets was got by create() call, we also create the
+createtime extended attribute.
+
+4.3.2.3 Directory self-heal
+...........................
+
+Suppose brick1 goes down, we delete foo.txt, brick1 comes back up, now
+we should not create foo.txt on brick2 but we should delete foo.txt on
+brick1. We handle this situation by having the createtime and version
+attribute on the directory similar to the file. when lookup() is done
+on the directory, we compare the createtime/version attributes of the
+copies and see which files needs to be deleted and delete those files
+and update the extended attributes of the outdated directory copy.
+Each time a directory is modified (a file or a subdirectory is created
+or deleted inside the directory) and one of the subvols is down, we
+increment the directory's version.
+
+ lookup() is a call initiated by the kernel on a file or directory
+just before any access to that file or directory. In glusterfs, by
+default, lookup() will not be called in case it was called in the past
+one second on that particular file or directory.
+
+ The extended attributes can be seen in the backend filesystem using
+the `getfattr' command. (`getfattr -n trusted.afr.version <file>')
+
+`debug [on|off] (off)'
+
+`self-heal [on|off] (on)'
+
+`replicate <pattern> (*:1)'
+
+`lock-node <child_volume> (first child is used by default)'
+
+
+File: user-guide.info, Node: Stripe, Prev: Replicate, Up: Clustering Translators
+
+4.3.3 Stripe
+------------
+
+ type cluster/stripe
+
+ The stripe translator distributes the contents of a file over its
+sub-volumes. It does this by creating a file equal in size to the
+total size of the file on each of its sub-volumes. It then writes only
+a part of the file to each sub-volume, leaving the rest of it empty.
+These empty regions are called `holes' in Unix terminology. The holes
+do not consume any disk space.
+
+ The diagram below makes this clear.
+
+
+
+You can configure stripe so that only filenames matching a pattern are
+striped. You can also configure the size of the data to be stored on
+each sub-volume.
+
+`block-size <pattern>:<size> (*:0 no striping)'
+ Distribute files matching `<pattern>' over the sub-volumes,
+ storing at least `<size>' on each sub-volume. For example,
+
+ option block-size *.mpg:1M
+
+ distributes all files ending in `.mpg', storing at least 1 MB on
+ each sub-volume.
+
+ Any number of `block-size' option lines may be present, specifying
+ different sizes for different file name patterns.
+
+
+File: user-guide.info, Node: Performance Translators, Next: Features Translators, Prev: Clustering Translators, Up: Translators
+
+4.4 Performance Translators
+===========================
+
+* Menu:
+
+* Read Ahead::
+* Write Behind::
+* IO Threads::
+* IO Cache::
+* Booster::
+
+
+File: user-guide.info, Node: Read Ahead, Next: Write Behind, Up: Performance Translators
+
+4.4.1 Read Ahead
+----------------
+
+ type performance/read-ahead
+
+ The read-ahead translator pre-fetches data in advance on every read.
+This benefits applications that mostly process files in sequential
+order, since the next block of data will already be available by the
+time the application is done with the current one.
+
+ Additionally, the read-ahead translator also behaves as a
+read-aggregator. Many small read operations are combined and issued as
+fewer, larger read requests to the server.
+
+ Read-ahead deals in "pages" as the unit of data fetched. The page
+size is configurable, as is the "page count", which is the number of
+pages that are pre-fetched.
+
+ Read-ahead is best used with InfiniBand (using the ib-verbs
+transport). On FastEthernet and Gigabit Ethernet networks, GlusterFS
+can achieve the link-maximum throughput even without read-ahead, making
+it quite superflous.
+
+ Note that read-ahead only happens if the reads are perfectly
+sequential. If your application accesses data in a random fashion,
+using read-ahead might actually lead to a performance loss, since
+read-ahead will pointlessly fetch pages which won't be used by the
+application.
+
+ Options:
+`page-size <n> (256KB)'
+ The unit of data that is pre-fetched.
+
+`page-count <n> (2)'
+ The number of pages that are pre-fetched.
+
+`force-atime-update [on|off|yes|no] (off|no)'
+ Whether to force an access time (atime) update on the file on
+ every read. Without this, the atime will be slightly imprecise, as
+ it will reflect the time when the read-ahead translator read the
+ data, not when the application actually read it.
+
+
+File: user-guide.info, Node: Write Behind, Next: IO Threads, Prev: Read Ahead, Up: Performance Translators
+
+4.4.2 Write Behind
+------------------
+
+ type performance/write-behind
+
+ The write-behind translator improves the latency of a write
+operation. It does this by relegating the write operation to the
+background and returning to the application even as the write is in
+progress. Using the write-behind translator, successive write requests
+can be pipelined. This mode of write-behind operation is best used on
+the client side, to enable decreased write latency for the application.
+
+ The write-behind translator can also aggregate write requests. If the
+`aggregate-size' option is specified, then successive writes upto that
+size are accumulated and written in a single operation. This mode of
+operation is best used on the server side, as this will decrease the
+disk's head movement when multiple files are being written to in
+parallel.
+
+ The `aggregate-size' option has a default value of 128KB. Although
+this works well for most users, you should always experiment with
+different values to determine the one that will deliver maximum
+performance. This is because the performance of write-behind depends on
+your interconnect, size of RAM, and the work load.
+
+`aggregate-size <n> (128KB)'
+ Amount of data to accumulate before doing a write
+
+`flush-behind [on|yes|off|no] (off|no)'
+
+
+File: user-guide.info, Node: IO Threads, Next: IO Cache, Prev: Write Behind, Up: Performance Translators
+
+4.4.3 IO Threads
+----------------
+
+ type performance/io-threads
+
+ The IO threads translator is intended to increase the responsiveness
+of the server to metadata operations by doing file I/O (read, write) in
+a background thread. Since the GlusterFS server is single-threaded,
+using the IO threads translator can significantly improve performance.
+This translator is best used on the server side, loaded just below the
+server protocol translator.
+
+ IO threads operates by handing out read and write requests to a
+separate thread. The total number of threads in existence at a time is
+constant, and configurable.
+
+`thread-count <n> (1)'
+ Number of threads to use.
+
+
+File: user-guide.info, Node: IO Cache, Next: Booster, Prev: IO Threads, Up: Performance Translators
+
+4.4.4 IO Cache
+--------------
+
+ type performance/io-cache
+
+ The IO cache translator caches data that has been read. This is
+useful if many applications read the same data multiple times, and if
+reads are much more frequent than writes (for example, IO caching may be
+useful in a web hosting environment, where most clients will simply
+read some files and only a few will write to them).
+
+ The IO cache translator reads data from its child in `page-size'
+chunks. It caches data upto `cache-size' bytes. The cache is
+maintained as a prioritized least-recently-used (LRU) list, with
+priorities determined by user-specified patterns to match filenames.
+
+ When the IO cache translator detects a write operation, the cache
+for that file is flushed.
+
+ The IO cache translator periodically verifies the consistency of
+cached data, using the modification times on the files. The
+verification timeout is configurable.
+
+`page-size <n> (128KB)'
+ Size of a page.
+
+`cache-size (n) (32MB)'
+ Total amount of data to be cached.
+
+`force-revalidate-timeout <n> (1)'
+ Timeout to force a cache consistency verification, in seconds.
+
+`priority <pattern> (*:0)'
+ Filename patterns listed in order of priority.
+
+
+File: user-guide.info, Node: Booster, Prev: IO Cache, Up: Performance Translators
+
+4.4.5 Booster
+-------------
+
+ type performance/booster
+
+ The booster translator gives applications a faster path to
+communicate read and write requests to GlusterFS. Normally, all
+requests to GlusterFS from applications go through FUSE, as indicated
+in *Note Filesystems in Userspace::. Using the booster translator in
+conjunction with the GlusterFS booster shared library, an application
+can bypass the FUSE path and send read/write requests directly to the
+GlusterFS client process.
+
+ The booster mechanism consists of two parts: the booster translator,
+and the booster shared library. The booster translator is meant to be
+loaded on the client side, usually at the root of the translator tree.
+The booster shared library should be `LD_PRELOAD'ed with the
+application.
+
+ The booster translator when loaded opens a Unix domain socket and
+listens for read/write requests on it. The booster shared library
+intercepts read and write system calls and sends the requests to the
+GlusterFS process directly using the Unix domain socket, bypassing FUSE.
+This leads to superior performance.
+
+ Once you've loaded the booster translator in your volume
+specification file, you can start your application as:
+
+ $ LD_PRELOAD=/usr/local/bin/glusterfs-booster.so your_app
+
+ The booster translator accepts no options.
+
+
+File: user-guide.info, Node: Features Translators, Next: Miscellaneous Translators, Prev: Performance Translators, Up: Translators
+
+4.5 Features Translators
+========================
+
+* Menu:
+
+* POSIX Locks::
+* Fixed ID::
+
+
+File: user-guide.info, Node: POSIX Locks, Next: Fixed ID, Up: Features Translators
+
+4.5.1 POSIX Locks
+-----------------
+
+ type features/posix-locks
+
+ This translator provides storage independent POSIX record locking
+support (`fcntl' locking). Typically you'll want to load this on the
+server side, just above the POSIX storage translator. Using this
+translator you can get both advisory locking and mandatory locking
+support. It also handles `flock()' locks properly.
+
+ Caveat: Consider a file that does not have its mandatory locking bits
+(+setgid, -group execution) turned on. Assume that this file is now
+opened by a process on a client that has the write-behind xlator
+loaded. The write-behind xlator does not cache anything for files which
+have mandatory locking enabled, to avoid incoherence. Let's say that
+mandatory locking is now enabled on this file through another client.
+The former client will not know about this change, and write-behind may
+erroneously report a write as being successful when in fact it would
+fail due to the region it is writing to being locked.
+
+ There seems to be no easy way to fix this. To work around this
+problem, it is recommended that you never enable the mandatory bits on
+a file while it is open.
+
+`mandatory [on|off] (on)'
+ Turns mandatory locking on.
+
+
+File: user-guide.info, Node: Fixed ID, Prev: POSIX Locks, Up: Features Translators
+
+4.5.2 Fixed ID
+--------------
+
+ type features/fixed-id
+
+ The fixed ID translator makes all filesystem requests from the client
+to appear to be coming from a fixed, specified UID/GID, regardless of
+which user actually initiated the request.
+
+`fixed-uid <n> [if not set, not used]'
+ The UID to send to the server
+
+`fixed-gid <n> [if not set, not used]'
+ The GID to send to the server
+
+
+File: user-guide.info, Node: Miscellaneous Translators, Prev: Features Translators, Up: Translators
+
+4.6 Miscellaneous Translators
+=============================
+
+* Menu:
+
+* ROT-13::
+* Trace::
+
+
+File: user-guide.info, Node: ROT-13, Next: Trace, Up: Miscellaneous Translators
+
+4.6.1 ROT-13
+------------
+
+ type encryption/rot-13
+
+ ROT-13 is a toy translator that can "encrypt" and "decrypt" file
+contents using the ROT-13 algorithm. ROT-13 is a trivial algorithm that
+rotates each alphabet by thirteen places. Thus, 'A' becomes 'N', 'B'
+becomes 'O', and 'Z' becomes 'M'.
+
+ It goes without saying that you shouldn't use this translator if you
+need _real_ encryption (a future release of GlusterFS will have real
+encryption translators).
+
+`encrypt-write [on|off] (on)'
+ Whether to encrypt on write
+
+`decrypt-read [on|off] (on)'
+ Whether to decrypt on read
+
+
+File: user-guide.info, Node: Trace, Prev: ROT-13, Up: Miscellaneous Translators
+
+4.6.2 Trace
+-----------
+
+ type debug/trace
+
+ The trace translator is intended for debugging purposes. When
+loaded, it logs all the system calls received by the server or client
+(wherever trace is loaded), their arguments, and the results. You must
+use a GlusterFS log level of DEBUG (See *Note Running GlusterFS::) for
+trace to work.
+
+ Sample trace output (lines have been wrapped for readability):
+ 2007-10-30 00:08:58 D [trace.c:1579:trace_opendir] trace: callid: 68
+ (*this=0x8059e40, loc=0x8091984 {path=/iozone3_283, inode=0x8091f00},
+ fd=0x8091d50)
+
+ 2007-10-30 00:08:58 D [trace.c:630:trace_opendir_cbk] trace:
+ (*this=0x8059e40, op_ret=4, op_errno=1, fd=0x8091d50)
+
+ 2007-10-30 00:08:58 D [trace.c:1602:trace_readdir] trace: callid: 69
+ (*this=0x8059e40, size=4096, offset=0 fd=0x8091d50)
+
+ 2007-10-30 00:08:58 D [trace.c:215:trace_readdir_cbk] trace:
+ (*this=0x8059e40, op_ret=0, op_errno=0, count=4)
+
+ 2007-10-30 00:08:58 D [trace.c:1624:trace_closedir] trace: callid: 71
+ (*this=0x8059e40, *fd=0x8091d50)
+
+ 2007-10-30 00:08:58 D [trace.c:809:trace_closedir_cbk] trace:
+ (*this=0x8059e40, op_ret=0, op_errno=1)
+
+
+File: user-guide.info, Node: Usage Scenarios, Next: Troubleshooting, Prev: Translators, Up: Top
+
+5 Usage Scenarios
+*****************
+
+5.1 Advanced Striping
+=====================
+
+This section is based on the Advanced Striping tutorial written by
+Anand Avati on the GlusterFS wiki (1).
+
+5.1.1 Mixed Storage Requirements
+--------------------------------
+
+There are two ways of scheduling the I/O. One at file level (using
+unify translator) and other at block level (using stripe translator).
+Striped I/O is good for files that are potentially large and require
+high parallel throughput (for example, a single file of 400GB being
+accessed by 100s and 1000s of systems simultaneously and randomly). For
+most of the cases, file level scheduling works best.
+
+ In the real world, it is desirable to mix file level and block level
+scheduling on a single storage volume. Alternatively users can choose
+to have two separate volumes and hence two mount points, but the
+applications may demand a single storage system to host both.
+
+ This document explains how to mix file level scheduling with stripe.
+
+5.1.2 Configuration Brief
+-------------------------
+
+This setup demonstrates how users can configure unify translator with
+appropriate I/O scheduler for file level scheduling and strip for only
+matching patterns. This way, GlusterFS chooses appropriate I/O profile
+and knows how to efficiently handle both the types of data.
+
+ A simple technique to achieve this effect is to create a stripe set
+of unify and stripe blocks, where unify is the first sub-volume. Files
+that do not match the stripe policy passed on to first unify sub-volume
+and inturn scheduled arcoss the cluster using its file level I/O
+scheduler.
+
+ 5.1.3 Preparing GlusterFS Envoronment
+-------------------------------------
+
+Create the directories /export/namespace, /export/unify and
+/export/stripe on all the storage bricks.
+
+ Place the following server and client volume spec file under
+/etc/glusterfs (or appropriate installed path) and replace the IP
+addresses / access control fields to match your environment.
+
+ ## file: /etc/glusterfs/glusterfsd.vol
+ volume posix-unify
+ type storage/posix
+ option directory /export/for-unify
+ end-volume
+
+ volume posix-stripe
+ type storage/posix
+ option directory /export/for-stripe
+ end-volume
+
+ volume posix-namespace
+ type storage/posix
+ option directory /export/for-namespace
+ end-volume
+
+ volume server
+ type protocol/server
+ option transport-type tcp
+ option auth.addr.posix-unify.allow 192.168.1.*
+ option auth.addr.posix-stripe.allow 192.168.1.*
+ option auth.addr.posix-namespace.allow 192.168.1.*
+ subvolumes posix-unify posix-stripe posix-namespace
+ end-volume
+
+ ## file: /etc/glusterfs/glusterfs.vol
+ volume client-namespace
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.1
+ option remote-subvolume posix-namespace
+ end-volume
+
+ volume client-unify-1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.1
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-unify-2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.2
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-unify-3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.3
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-unify-4
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.4
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-stripe-1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.1
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume client-stripe-2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.2
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume client-stripe-3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.3
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume client-stripe-4
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.4
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume unify
+ type cluster/unify
+ option scheduler rr
+ subvolumes cluster-unify-1 cluster-unify-2 cluster-unify-3 cluster-unify-4
+ end-volume
+
+ volume stripe
+ type cluster/stripe
+ option block-size *.img:2MB # All files ending with .img are striped with 2MB stripe block size.
+ subvolumes unify cluster-stripe-1 cluster-stripe-2 cluster-stripe-3 cluster-stripe-4
+ end-volume
+
+ Bring up the Storage
+
+ Starting GlusterFS Server: If you have installed through binary
+package, you can start the service through init.d startup script. If
+not:
+
+ [root@server]# glusterfsd
+
+ Mounting GlusterFS Volumes:
+
+ [root@client]# glusterfs -s [BRICK-IP-ADDRESS] /mnt/cluster
+
+ Improving upon this Setup
+
+ Infiniband Verbs RDMA transport is much faster than TCP/IP GigE
+transport.
+
+ Use of performance translators such as read-ahead, write-behind,
+io-cache, io-threads, booster is recommended.
+
+ Replace round-robin (rr) scheduler with ALU to handle more dynamic
+storage environments.
+
+ ---------- Footnotes ----------
+
+ (1)
+http://gluster.org/docs/index.php/Mixing_Striped_and_Regular_Files
+
+
+File: user-guide.info, Node: Troubleshooting, Next: GNU Free Documentation Licence, Prev: Usage Scenarios, Up: Top
+
+6 Troubleshooting
+*****************
+
+This chapter is a general troubleshooting guide to GlusterFS. It lists
+common GlusterFS server and client error messages, debugging hints, and
+concludes with the suggested procedure to report bugs in GlusterFS.
+
+6.1 GlusterFS error messages
+============================
+
+6.1.1 Server errors
+-------------------
+
+ glusterfsd: FATAL: could not open specfile:
+ '/etc/glusterfs/glusterfsd.vol'
+
+ The GlusterFS server expects the volume specification file to be at
+`/etc/glusterfs/glusterfsd.vol'. The example specification file will be
+installed as `/etc/glusterfs/glusterfsd.vol.sample'. You need to edit
+it and rename it, or provide a different specification file using the
+`--spec-file' command line option (See *Note Server::).
+
+ gf_log_init: failed to open logfile "/usr/var/log/glusterfs/glusterfsd.log"
+ (Permission denied)
+
+ You don't have permission to create files in the
+`/usr/var/log/glusterfs' directory. Make sure you are running GlusterFS
+as root. Alternatively, specify a different path for the log file using
+the `--log-file' option (See *Note Server::).
+
+6.1.2 Client errors
+-------------------
+
+ fusermount: failed to access mountpoint /mnt:
+ Transport endpoint is not connected
+
+ A previous failed (or hung) mount of GlusterFS is preventing it from
+being mounted again in the same location. The fix is to do:
+
+ # umount /mnt
+
+ and try mounting again.
+
+ *"Transport endpoint is not connected".*
+
+ If you get this error when you try a command such as `ls' or `cat',
+it means the GlusterFS mount did not succeed. Try running GlusterFS in
+`DEBUG' logging level and study the log messages to discover the cause.
+
+ *"Connect to server failed", "SERVER-ADDRESS: Connection refused".*
+
+ GluserFS Server is not running or dead. Check your network
+connections and firewall settings. To check if the server is reachable,
+try:
+
+ telnet IP-ADDRESS 6996
+
+ If the server is accessible, your `telnet' command should connect and
+block. If not you will see an error message such as `telnet: Unable to
+connect to remote host: Connection refused'. 6996 is the default
+GlusterFS port. If you have changed it, then use the corresponding port
+instead.
+
+ gf_log_init: failed to open logfile "/usr/var/log/glusterfs/glusterfs.log"
+ (Permission denied)
+
+ You don't have permission to create files in the
+`/usr/var/log/glusterfs' directory. Make sure you are running GlusterFS
+as root. Alternatively, specify a different path for the log file using
+the `--log-file' option (See *Note Client::).
+
+6.2 FUSE error messages
+=======================
+
+`modprobe fuse' fails with: "Unknown symbol in module, or unknown
+parameter".
+
+ If you are using fuse-2.6.x on Redhat Enterprise Linux Work Station 4
+and Advanced Server 4 with 2.6.9-42.ELlargesmp, 2.6.9-42.ELsmp,
+2.6.9-42.EL kernels and get this error while loading FUSE kernel
+module, you need to apply the following patch.
+
+ For fuse-2.6.2:
+
+<http://ftp.zresearch.com/pub/gluster/glusterfs/fuse/fuse-2.6.2-rhel-build.patch>
+
+ For fuse-2.6.3:
+
+<http://ftp.zresearch.com/pub/gluster/glusterfs/fuse/fuse-2.6.3-rhel-build.patch>
+
+6.3 AppArmour and GlusterFS
+===========================
+
+Under OpenSuSE GNU/Linux, the AppArmour security feature does not allow
+GlusterFS to create temporary files or network socket connections even
+while running as root. You will see error messages like `Unable to open
+log file: Operation not permitted' or `Connection refused'. Disabling
+AppArmour using YaST or properly configuring AppArmour to recognize
+`glusterfsd' or `glusterfs'/`fusermount' should solve the problem.
+
+6.4 Reporting a bug
+===================
+
+If you encounter a bug in GlusterFS, please follow the below guidelines
+when you report it to the mailing list. Be sure to report it! User
+feedback is crucial to the health of the project and we value it highly.
+
+6.4.1 General instructions
+--------------------------
+
+When running GlusterFS in a non-production environment, be sure to
+build it with the following command:
+
+ $ make CFLAGS='-g -O0 -DDEBUG'
+
+ This includes debugging information which will be helpful in getting
+backtraces (see below) and also disable optimization. Enabling
+optimization can result in incorrect line numbers being reported to gdb.
+
+6.4.2 Volume specification files
+--------------------------------
+
+Attach all relevant server and client spec files you were using when
+you encountered the bug. Also tell us details of your setup, i.e., how
+many clients and how many servers.
+
+6.4.3 Log files
+---------------
+
+Set the loglevel of your client and server programs to DEBUG (by
+passing the -L DEBUG option) and attach the log files with your bug
+report. Obviously, if only the client is failing (for example), you
+only need to send us the client log file.
+
+6.4.4 Backtrace
+---------------
+
+If GlusterFS has encountered a segmentation fault or has crashed for
+some other reason, include the backtrace with the bug report. You can
+get the backtrace using the following procedure.
+
+ Run the GlusterFS client or server inside gdb.
+
+ $ gdb ./glusterfs
+ (gdb) set args -f client.spec -N -l/path/to/log/file -LDEBUG /mnt/point
+ (gdb) run
+
+ Now when the process segfaults, you can get the backtrace by typing:
+
+ (gdb) bt
+
+ If the GlusterFS process has crashed and dumped a core file (you can
+find this in / if running as a daemon and in the current directory
+otherwise), you can do:
+
+ $ gdb /path/to/glusterfs /path/to/core.<pid>
+
+ and then get the backtrace.
+
+ If the GlusterFS server or client seems to be hung, then you can get
+the backtrace by attaching gdb to the process. First get the `PID' of
+the process (using ps), and then do:
+
+ $ gdb ./glusterfs <pid>
+
+ Press Ctrl-C to interrupt the process and then generate the
+backtrace.
+
+6.4.5 Reproducing the bug
+-------------------------
+
+If the bug is reproducible, please include the steps necessary to do
+so. If the bug is not reproducible, send us the bug report anyway.
+
+6.4.6 Other information
+-----------------------
+
+If you think it is relevant, send us also the version of FUSE you're
+using, the kernel version, platform.
+
+
+File: user-guide.info, Node: GNU Free Documentation Licence, Next: Index, Prev: Troubleshooting, Up: Top
+
+Appendix A GNU Free Documentation Licence
+*****************************************
+
+ Version 1.2, November 2002
+
+ Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ 0. PREAMBLE
+
+ The purpose of this License is to make a manual, textbook, or other
+ functional and useful document "free" in the sense of freedom: to
+ assure everyone the effective freedom to copy and redistribute it,
+ with or without modifying it, either commercially or
+ noncommercially. Secondarily, this License preserves for the
+ author and publisher a way to get credit for their work, while not
+ being considered responsible for modifications made by others.
+
+ This License is a kind of "copyleft", which means that derivative
+ works of the document must themselves be free in the same sense.
+ It complements the GNU General Public License, which is a copyleft
+ license designed for free software.
+
+ We have designed this License in order to use it for manuals for
+ free software, because free software needs free documentation: a
+ free program should come with manuals providing the same freedoms
+ that the software does. But this License is not limited to
+ software manuals; it can be used for any textual work, regardless
+ of subject matter or whether it is published as a printed book.
+ We recommend this License principally for works whose purpose is
+ instruction or reference.
+
+ 1. APPLICABILITY AND DEFINITIONS
+
+ This License applies to any manual or other work, in any medium,
+ that contains a notice placed by the copyright holder saying it
+ can be distributed under the terms of this License. Such a notice
+ grants a world-wide, royalty-free license, unlimited in duration,
+ to use that work under the conditions stated herein. The
+ "Document", below, refers to any such manual or work. Any member
+ of the public is a licensee, and is addressed as "you". You
+ accept the license if you copy, modify or distribute the work in a
+ way requiring permission under copyright law.
+
+ A "Modified Version" of the Document means any work containing the
+ Document or a portion of it, either copied verbatim, or with
+ modifications and/or translated into another language.
+
+ A "Secondary Section" is a named appendix or a front-matter section
+ of the Document that deals exclusively with the relationship of the
+ publishers or authors of the Document to the Document's overall
+ subject (or to related matters) and contains nothing that could
+ fall directly within that overall subject. (Thus, if the Document
+ is in part a textbook of mathematics, a Secondary Section may not
+ explain any mathematics.) The relationship could be a matter of
+ historical connection with the subject or with related matters, or
+ of legal, commercial, philosophical, ethical or political position
+ regarding them.
+
+ The "Invariant Sections" are certain Secondary Sections whose
+ titles are designated, as being those of Invariant Sections, in
+ the notice that says that the Document is released under this
+ License. If a section does not fit the above definition of
+ Secondary then it is not allowed to be designated as Invariant.
+ The Document may contain zero Invariant Sections. If the Document
+ does not identify any Invariant Sections then there are none.
+
+ The "Cover Texts" are certain short passages of text that are
+ listed, as Front-Cover Texts or Back-Cover Texts, in the notice
+ that says that the Document is released under this License. A
+ Front-Cover Text may be at most 5 words, and a Back-Cover Text may
+ be at most 25 words.
+
+ A "Transparent" copy of the Document means a machine-readable copy,
+ represented in a format whose specification is available to the
+ general public, that is suitable for revising the document
+ straightforwardly with generic text editors or (for images
+ composed of pixels) generic paint programs or (for drawings) some
+ widely available drawing editor, and that is suitable for input to
+ text formatters or for automatic translation to a variety of
+ formats suitable for input to text formatters. A copy made in an
+ otherwise Transparent file format whose markup, or absence of
+ markup, has been arranged to thwart or discourage subsequent
+ modification by readers is not Transparent. An image format is
+ not Transparent if used for any substantial amount of text. A
+ copy that is not "Transparent" is called "Opaque".
+
+ Examples of suitable formats for Transparent copies include plain
+ ASCII without markup, Texinfo input format, LaTeX input format,
+ SGML or XML using a publicly available DTD, and
+ standard-conforming simple HTML, PostScript or PDF designed for
+ human modification. Examples of transparent image formats include
+ PNG, XCF and JPG. Opaque formats include proprietary formats that
+ can be read and edited only by proprietary word processors, SGML or
+ XML for which the DTD and/or processing tools are not generally
+ available, and the machine-generated HTML, PostScript or PDF
+ produced by some word processors for output purposes only.
+
+ The "Title Page" means, for a printed book, the title page itself,
+ plus such following pages as are needed to hold, legibly, the
+ material this License requires to appear in the title page. For
+ works in formats which do not have any title page as such, "Title
+ Page" means the text near the most prominent appearance of the
+ work's title, preceding the beginning of the body of the text.
+
+ A section "Entitled XYZ" means a named subunit of the Document
+ whose title either is precisely XYZ or contains XYZ in parentheses
+ following text that translates XYZ in another language. (Here XYZ
+ stands for a specific section name mentioned below, such as
+ "Acknowledgements", "Dedications", "Endorsements", or "History".)
+ To "Preserve the Title" of such a section when you modify the
+ Document means that it remains a section "Entitled XYZ" according
+ to this definition.
+
+ The Document may include Warranty Disclaimers next to the notice
+ which states that this License applies to the Document. These
+ Warranty Disclaimers are considered to be included by reference in
+ this License, but only as regards disclaiming warranties: any other
+ implication that these Warranty Disclaimers may have is void and
+ has no effect on the meaning of this License.
+
+ 2. VERBATIM COPYING
+
+ You may copy and distribute the Document in any medium, either
+ commercially or noncommercially, provided that this License, the
+ copyright notices, and the license notice saying this License
+ applies to the Document are reproduced in all copies, and that you
+ add no other conditions whatsoever to those of this License. You
+ may not use technical measures to obstruct or control the reading
+ or further copying of the copies you make or distribute. However,
+ you may accept compensation in exchange for copies. If you
+ distribute a large enough number of copies you must also follow
+ the conditions in section 3.
+
+ You may also lend copies, under the same conditions stated above,
+ and you may publicly display copies.
+
+ 3. COPYING IN QUANTITY
+
+ If you publish printed copies (or copies in media that commonly
+ have printed covers) of the Document, numbering more than 100, and
+ the Document's license notice requires Cover Texts, you must
+ enclose the copies in covers that carry, clearly and legibly, all
+ these Cover Texts: Front-Cover Texts on the front cover, and
+ Back-Cover Texts on the back cover. Both covers must also clearly
+ and legibly identify you as the publisher of these copies. The
+ front cover must present the full title with all words of the
+ title equally prominent and visible. You may add other material
+ on the covers in addition. Copying with changes limited to the
+ covers, as long as they preserve the title of the Document and
+ satisfy these conditions, can be treated as verbatim copying in
+ other respects.
+
+ If the required texts for either cover are too voluminous to fit
+ legibly, you should put the first ones listed (as many as fit
+ reasonably) on the actual cover, and continue the rest onto
+ adjacent pages.
+
+ If you publish or distribute Opaque copies of the Document
+ numbering more than 100, you must either include a
+ machine-readable Transparent copy along with each Opaque copy, or
+ state in or with each Opaque copy a computer-network location from
+ which the general network-using public has access to download
+ using public-standard network protocols a complete Transparent
+ copy of the Document, free of added material. If you use the
+ latter option, you must take reasonably prudent steps, when you
+ begin distribution of Opaque copies in quantity, to ensure that
+ this Transparent copy will remain thus accessible at the stated
+ location until at least one year after the last time you
+ distribute an Opaque copy (directly or through your agents or
+ retailers) of that edition to the public.
+
+ It is requested, but not required, that you contact the authors of
+ the Document well before redistributing any large number of
+ copies, to give them a chance to provide you with an updated
+ version of the Document.
+
+ 4. MODIFICATIONS
+
+ You may copy and distribute a Modified Version of the Document
+ under the conditions of sections 2 and 3 above, provided that you
+ release the Modified Version under precisely this License, with
+ the Modified Version filling the role of the Document, thus
+ licensing distribution and modification of the Modified Version to
+ whoever possesses a copy of it. In addition, you must do these
+ things in the Modified Version:
+
+ A. Use in the Title Page (and on the covers, if any) a title
+ distinct from that of the Document, and from those of
+ previous versions (which should, if there were any, be listed
+ in the History section of the Document). You may use the
+ same title as a previous version if the original publisher of
+ that version gives permission.
+
+ B. List on the Title Page, as authors, one or more persons or
+ entities responsible for authorship of the modifications in
+ the Modified Version, together with at least five of the
+ principal authors of the Document (all of its principal
+ authors, if it has fewer than five), unless they release you
+ from this requirement.
+
+ C. State on the Title page the name of the publisher of the
+ Modified Version, as the publisher.
+
+ D. Preserve all the copyright notices of the Document.
+
+ E. Add an appropriate copyright notice for your modifications
+ adjacent to the other copyright notices.
+
+ F. Include, immediately after the copyright notices, a license
+ notice giving the public permission to use the Modified
+ Version under the terms of this License, in the form shown in
+ the Addendum below.
+
+ G. Preserve in that license notice the full lists of Invariant
+ Sections and required Cover Texts given in the Document's
+ license notice.
+
+ H. Include an unaltered copy of this License.
+
+ I. Preserve the section Entitled "History", Preserve its Title,
+ and add to it an item stating at least the title, year, new
+ authors, and publisher of the Modified Version as given on
+ the Title Page. If there is no section Entitled "History" in
+ the Document, create one stating the title, year, authors,
+ and publisher of the Document as given on its Title Page,
+ then add an item describing the Modified Version as stated in
+ the previous sentence.
+
+ J. Preserve the network location, if any, given in the Document
+ for public access to a Transparent copy of the Document, and
+ likewise the network locations given in the Document for
+ previous versions it was based on. These may be placed in
+ the "History" section. You may omit a network location for a
+ work that was published at least four years before the
+ Document itself, or if the original publisher of the version
+ it refers to gives permission.
+
+ K. For any section Entitled "Acknowledgements" or "Dedications",
+ Preserve the Title of the section, and preserve in the
+ section all the substance and tone of each of the contributor
+ acknowledgements and/or dedications given therein.
+
+ L. Preserve all the Invariant Sections of the Document,
+ unaltered in their text and in their titles. Section numbers
+ or the equivalent are not considered part of the section
+ titles.
+
+ M. Delete any section Entitled "Endorsements". Such a section
+ may not be included in the Modified Version.
+
+ N. Do not retitle any existing section to be Entitled
+ "Endorsements" or to conflict in title with any Invariant
+ Section.
+
+ O. Preserve any Warranty Disclaimers.
+
+ If the Modified Version includes new front-matter sections or
+ appendices that qualify as Secondary Sections and contain no
+ material copied from the Document, you may at your option
+ designate some or all of these sections as invariant. To do this,
+ add their titles to the list of Invariant Sections in the Modified
+ Version's license notice. These titles must be distinct from any
+ other section titles.
+
+ You may add a section Entitled "Endorsements", provided it contains
+ nothing but endorsements of your Modified Version by various
+ parties--for example, statements of peer review or that the text
+ has been approved by an organization as the authoritative
+ definition of a standard.
+
+ You may add a passage of up to five words as a Front-Cover Text,
+ and a passage of up to 25 words as a Back-Cover Text, to the end
+ of the list of Cover Texts in the Modified Version. Only one
+ passage of Front-Cover Text and one of Back-Cover Text may be
+ added by (or through arrangements made by) any one entity. If the
+ Document already includes a cover text for the same cover,
+ previously added by you or by arrangement made by the same entity
+ you are acting on behalf of, you may not add another; but you may
+ replace the old one, on explicit permission from the previous
+ publisher that added the old one.
+
+ The author(s) and publisher(s) of the Document do not by this
+ License give permission to use their names for publicity for or to
+ assert or imply endorsement of any Modified Version.
+
+ 5. COMBINING DOCUMENTS
+
+ You may combine the Document with other documents released under
+ this License, under the terms defined in section 4 above for
+ modified versions, provided that you include in the combination
+ all of the Invariant Sections of all of the original documents,
+ unmodified, and list them all as Invariant Sections of your
+ combined work in its license notice, and that you preserve all
+ their Warranty Disclaimers.
+
+ The combined work need only contain one copy of this License, and
+ multiple identical Invariant Sections may be replaced with a single
+ copy. If there are multiple Invariant Sections with the same name
+ but different contents, make the title of each such section unique
+ by adding at the end of it, in parentheses, the name of the
+ original author or publisher of that section if known, or else a
+ unique number. Make the same adjustment to the section titles in
+ the list of Invariant Sections in the license notice of the
+ combined work.
+
+ In the combination, you must combine any sections Entitled
+ "History" in the various original documents, forming one section
+ Entitled "History"; likewise combine any sections Entitled
+ "Acknowledgements", and any sections Entitled "Dedications". You
+ must delete all sections Entitled "Endorsements."
+
+ 6. COLLECTIONS OF DOCUMENTS
+
+ You may make a collection consisting of the Document and other
+ documents released under this License, and replace the individual
+ copies of this License in the various documents with a single copy
+ that is included in the collection, provided that you follow the
+ rules of this License for verbatim copying of each of the
+ documents in all other respects.
+
+ You may extract a single document from such a collection, and
+ distribute it individually under this License, provided you insert
+ a copy of this License into the extracted document, and follow
+ this License in all other respects regarding verbatim copying of
+ that document.
+
+ 7. AGGREGATION WITH INDEPENDENT WORKS
+
+ A compilation of the Document or its derivatives with other
+ separate and independent documents or works, in or on a volume of
+ a storage or distribution medium, is called an "aggregate" if the
+ copyright resulting from the compilation is not used to limit the
+ legal rights of the compilation's users beyond what the individual
+ works permit. When the Document is included in an aggregate, this
+ License does not apply to the other works in the aggregate which
+ are not themselves derivative works of the Document.
+
+ If the Cover Text requirement of section 3 is applicable to these
+ copies of the Document, then if the Document is less than one half
+ of the entire aggregate, the Document's Cover Texts may be placed
+ on covers that bracket the Document within the aggregate, or the
+ electronic equivalent of covers if the Document is in electronic
+ form. Otherwise they must appear on printed covers that bracket
+ the whole aggregate.
+
+ 8. TRANSLATION
+
+ Translation is considered a kind of modification, so you may
+ distribute translations of the Document under the terms of section
+ 4. Replacing Invariant Sections with translations requires special
+ permission from their copyright holders, but you may include
+ translations of some or all Invariant Sections in addition to the
+ original versions of these Invariant Sections. You may include a
+ translation of this License, and all the license notices in the
+ Document, and any Warranty Disclaimers, provided that you also
+ include the original English version of this License and the
+ original versions of those notices and disclaimers. In case of a
+ disagreement between the translation and the original version of
+ this License or a notice or disclaimer, the original version will
+ prevail.
+
+ If a section in the Document is Entitled "Acknowledgements",
+ "Dedications", or "History", the requirement (section 4) to
+ Preserve its Title (section 1) will typically require changing the
+ actual title.
+
+ 9. TERMINATION
+
+ You may not copy, modify, sublicense, or distribute the Document
+ except as expressly provided for under this License. Any other
+ attempt to copy, modify, sublicense or distribute the Document is
+ void, and will automatically terminate your rights under this
+ License. However, parties who have received copies, or rights,
+ from you under this License will not have their licenses
+ terminated so long as such parties remain in full compliance.
+
+ 10. FUTURE REVISIONS OF THIS LICENSE
+
+ The Free Software Foundation may publish new, revised versions of
+ the GNU Free Documentation License from time to time. Such new
+ versions will be similar in spirit to the present version, but may
+ differ in detail to address new problems or concerns. See
+ `http://www.gnu.org/copyleft/'.
+
+ Each version of the License is given a distinguishing version
+ number. If the Document specifies that a particular numbered
+ version of this License "or any later version" applies to it, you
+ have the option of following the terms and conditions either of
+ that specified version or of any later version that has been
+ published (not as a draft) by the Free Software Foundation. If
+ the Document does not specify a version number of this License,
+ you may choose any version ever published (not as a draft) by the
+ Free Software Foundation.
+
+A.0.1 ADDENDUM: How to use this License for your documents
+----------------------------------------------------------
+
+To use this License in a document you have written, include a copy of
+the License in the document and put the following copyright and license
+notices just after the title page:
+
+ Copyright (C) YEAR YOUR NAME.
+ Permission is granted to copy, distribute and/or modify this document
+ under the terms of the GNU Free Documentation License, Version 1.2
+ or any later version published by the Free Software Foundation;
+ with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
+ Texts. A copy of the license is included in the section entitled ``GNU
+ Free Documentation License''.
+
+ If you have Invariant Sections, Front-Cover Texts and Back-Cover
+Texts, replace the "with...Texts." line with this:
+
+ with the Invariant Sections being LIST THEIR TITLES, with
+ the Front-Cover Texts being LIST, and with the Back-Cover Texts
+ being LIST.
+
+ If you have Invariant Sections without Cover Texts, or some other
+combination of the three, merge those two alternatives to suit the
+situation.
+
+ If your document contains nontrivial examples of program code, we
+recommend releasing these examples in parallel under your choice of
+free software license, such as the GNU General Public License, to
+permit their use in free software.
+
+
+File: user-guide.info, Node: Index, Prev: GNU Free Documentation Licence, Up: Top
+
+Index
+*****
+
+
+* Menu:
+
+* alu (scheduler): Unify. (line 49)
+* AppArmour: Troubleshooting. (line 96)
+* arch: Getting GlusterFS. (line 6)
+* booster: Booster. (line 6)
+* commercial support: Introduction. (line 36)
+* DNS round robin: Transport modules. (line 29)
+* fcntl: POSIX Locks. (line 6)
+* FDL, GNU Free Documentation License: GNU Free Documentation Licence.
+ (line 6)
+* fixed-id (translator): Fixed ID. (line 6)
+* GlusterFS client: Client. (line 6)
+* GlusterFS mailing list: Introduction. (line 28)
+* GlusterFS server: Server. (line 6)
+* infiniband transport: Transport modules. (line 58)
+* InfiniBand, installation: Pre requisites. (line 51)
+* io-cache (translator): IO Cache. (line 6)
+* io-threads (translator): IO Threads. (line 6)
+* IRC channel, #gluster: Introduction. (line 31)
+* libibverbs: Pre requisites. (line 51)
+* namespace: Unify. (line 207)
+* nufa (scheduler): Unify. (line 175)
+* OpenSuSE: Troubleshooting. (line 96)
+* posix-locks (translator): POSIX Locks. (line 6)
+* random (scheduler): Unify. (line 159)
+* read-ahead (translator): Read Ahead. (line 6)
+* record locking: POSIX Locks. (line 6)
+* Redhat Enterprise Linux: Troubleshooting. (line 78)
+* Replicate: Replicate. (line 6)
+* rot-13 (translator): ROT-13. (line 6)
+* rr (scheduler): Unify. (line 138)
+* scheduler (unify): Unify. (line 6)
+* self heal (replicate): Replicate. (line 46)
+* self heal (unify): Unify. (line 223)
+* stripe (translator): Stripe. (line 6)
+* trace (translator): Trace. (line 6)
+* unify (translator): Unify. (line 6)
+* unify invariants: Unify. (line 16)
+* write-behind (translator): Write Behind. (line 6)
+* Z Research, Inc.: Introduction. (line 36)
+
+
+
+Tag Table:
+Node: Top703
+Node: Acknowledgements2303
+Node: Introduction3213
+Node: Installation and Invocation4648
+Node: Pre requisites4932
+Node: Getting GlusterFS7022
+Ref: Getting GlusterFS-Footnote-17808
+Node: Building7856
+Node: Running GlusterFS9558
+Node: Server9769
+Node: Client11357
+Node: A Tutorial Introduction13563
+Node: Concepts17100
+Node: Filesystems in Userspace17315
+Node: Translator18456
+Node: Volume specification file21159
+Node: Translators23631
+Node: Storage Translators24200
+Ref: Storage Translators-Footnote-125007
+Node: POSIX25141
+Node: BDB25764
+Node: Client and Server Translators26821
+Node: Transport modules27297
+Node: Client protocol31444
+Node: Server protocol32383
+Node: Clustering Translators33372
+Node: Unify34259
+Ref: Unify-Footnote-143858
+Node: Replicate43950
+Node: Stripe49005
+Node: Performance Translators50163
+Node: Read Ahead50437
+Node: Write Behind52169
+Node: IO Threads53578
+Node: IO Cache54366
+Node: Booster55690
+Node: Features Translators57104
+Node: POSIX Locks57332
+Node: Fixed ID58649
+Node: Miscellaneous Translators59135
+Node: ROT-1359333
+Node: Trace60012
+Node: Usage Scenarios61281
+Ref: Usage Scenarios-Footnote-167214
+Node: Troubleshooting67289
+Node: GNU Free Documentation Licence73637
+Node: Index96086
+
+End Tag Table
diff --git a/doc/user-guide/user-guide.pdf b/doc/user-guide/user-guide.pdf
new file mode 100644
index 000000000..ed7bd2a99
--- /dev/null
+++ b/doc/user-guide/user-guide.pdf
Binary files differ
diff --git a/doc/user-guide/user-guide.texi b/doc/user-guide/user-guide.texi
new file mode 100644
index 000000000..8365419a6
--- /dev/null
+++ b/doc/user-guide/user-guide.texi
@@ -0,0 +1,2226 @@
+\input texinfo
+@setfilename user-guide.info
+@settitle GlusterFS 2.0 User Guide
+@afourpaper
+
+@direntry
+* GlusterFS: (user-guide). GlusterFS distributed filesystem user guide
+@end direntry
+
+@copying
+This is the user manual for GlusterFS 2.0.
+
+Copyright @copyright{} 2008,2007 @email{@b{Z}} Research, Inc. Permission is granted to
+copy, distribute and/or modify this document under the terms of the
+@acronym{GNU} Free Documentation License, Version 1.2 or any later
+version published by the Free Software Foundation; with no Invariant
+Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the
+license is included in the chapter entitled ``@acronym{GNU} Free
+Documentation License''.
+@end copying
+
+@titlepage
+@title GlusterFS 2.0 User Guide [DRAFT]
+@subtitle January 15, 2008
+@author http://gluster.org/core-team.php
+@author @email{@b{Z}} @b{Research}
+
+@page
+@vskip 0pt plus 1filll
+@insertcopying
+@end titlepage
+
+@c Info stuff
+@ifnottex
+@node Top
+@top GlusterFS 2.0 User Guide
+
+@insertcopying
+@menu
+* Acknowledgements::
+* Introduction::
+* Installation and Invocation::
+* Concepts::
+* Translators::
+* Usage Scenarios::
+* Troubleshooting::
+* GNU Free Documentation Licence::
+* Index::
+
+@detailmenu
+ --- The Detailed Node Listing ---
+
+Installation and Invocation
+
+* Pre requisites::
+* Getting GlusterFS::
+* Building::
+* Running GlusterFS::
+* A Tutorial Introduction::
+
+Running GlusterFS
+
+* Server::
+* Client::
+
+Concepts
+
+* Filesystems in Userspace::
+* Translator::
+* Volume specification file::
+
+Translators
+
+* Storage Translators::
+* Client and Server Translators::
+* Clustering Translators::
+* Performance Translators::
+* Features Translators::
+
+Storage Translators
+
+* POSIX::
+
+Client and Server Translators
+
+* Transport modules::
+* Client protocol::
+* Server protocol::
+
+Clustering Translators
+
+* Unify::
+* Replicate::
+* Stripe::
+
+Performance Translators
+
+* Read Ahead::
+* Write Behind::
+* IO Threads::
+* IO Cache::
+
+Features Translators
+
+* POSIX Locks::
+* Fixed ID::
+
+Miscellaneous Translators
+
+* ROT-13::
+* Trace::
+
+@end detailmenu
+@end menu
+
+@end ifnottex
+@c Info stuff end
+
+@contents
+
+@node Acknowledgements
+@unnumbered Acknowledgements
+GlusterFS continues to be a wonderful and enriching experience for all
+of us involved.
+
+GlusterFS development would not have been possible at this pace if
+not for our enthusiastic users. People from around the world have
+helped us with bug reports, performance numbers, and feature suggestions.
+A huge thanks to them all.
+
+Matthew Paine - for RPMs & general enthu
+
+Leonardo Rodrigues de Mello - for DEBs
+
+Julian Perez & Adam D'Auria - for multi-server tutorial
+
+Paul England - for HA spec
+
+Brent Nelson - for many bug reports
+
+Jacques Mattheij - for Europe mirror.
+
+Patrick Negri - for TCP non-blocking connect.
+@flushright
+http://gluster.org/core-team.php (@email{list-hacking@@zresearch.com})
+@email{@b{Z}} Research
+@end flushright
+
+@node Introduction
+@chapter Introduction
+
+GlusterFS is a distributed filesystem. It works at the file level,
+not block level.
+
+A network filesystem is one which allows us to access remote files. A
+distributed filesystem is one that stores data on multiple machines
+and makes them all appear to be a part of the same filesystem.
+
+Need for distributed filesystems
+
+@itemize @bullet
+@item Scalability: A distributed filesystem allows us to store more data than what can be stored on a single machine.
+
+@item Redundancy: We might want to replicate crucial data on to several machines.
+
+@item Uniform access: One can mount a remote volume (for example your home directory) from any machine and access the same data.
+@end itemize
+
+@section Contacting us
+You can reach us through the mailing list @strong{gluster-devel}
+(@email{gluster-devel@@nongnu.org}).
+@cindex GlusterFS mailing list
+
+You can also find many of the developers on @acronym{IRC}, on the @code{#gluster}
+channel on Freenode (@indicateurl{irc.freenode.net}).
+@cindex IRC channel, #gluster
+
+The GlusterFS documentation wiki is also useful: @*
+@indicateurl{http://gluster.org/docs/index.php/GlusterFS}
+
+For commercial support, you can contact @email{@b{Z}} Research at:
+@cindex commercial support
+@cindex Z Research, Inc.
+
+@display
+3194 Winding Vista Common
+Fremont, CA 94539
+USA.
+
+Phone: +1 (510) 354 6801
+Toll free: +1 (888) 813 6309
+Fax: +1 (510) 372 0604
+@end display
+
+You can also email us at @email{support@@zresearch.com}.
+
+@node Installation and Invocation
+@chapter Installation and Invocation
+
+@menu
+* Pre requisites::
+* Getting GlusterFS::
+* Building::
+* Running GlusterFS::
+* A Tutorial Introduction::
+@end menu
+
+@node Pre requisites
+@section Pre requisites
+
+Before installing GlusterFS make sure you have the
+following components installed.
+
+@subsection @acronym{FUSE}
+You'll need @acronym{FUSE} version 2.6.0 or higher to
+use GlusterFS. You can omit installing @acronym{FUSE} if you want to
+build @emph{only} the server. Note that you won't be able to mount
+a GlusterFS filesystem on a machine that does not have @acronym{FUSE}
+installed.
+
+@acronym{FUSE} can be downloaded from: @indicateurl{http://fuse.sourceforge.net/}
+
+To get the best performance from GlusterFS, however, it is recommended that you use
+our patched version of @acronym{FUSE}. See Patched FUSE for details.
+
+@subsection Patched FUSE
+
+The GlusterFS project maintains a patched version of @acronym{FUSE} meant to be used
+with GlusterFS. The patches increase GlusterFS performance. It is recommended that
+all users use the patched @acronym{FUSE}.
+
+The patched @acronym{FUSE} tarball can be downloaded from:
+
+@indicateurl{ftp://ftp.zresearch.com/pub/gluster/glusterfs/fuse/}
+
+The specific changes made to @acronym{FUSE} are:
+
+@itemize
+@item The communication channel size between @acronym{FUSE} kernel module and GlusterFS has been increased to 1MB, permitting large reads and writes to be sent in bigger chunks.
+
+@item The kernel's read-ahead boundry has been extended upto 1MB.
+
+@item Block size returned in the @command{stat()}/@command{fstat()} calls tuned to 1MB, to make cp and similar commands perform I/O using that block size.
+
+@item @command{flock()} locking support has been added (although some rework in GlusterFS is needed for perfect compliance).
+@end itemize
+
+@subsection libibverbs (optional)
+@cindex InfiniBand, installation
+@cindex libibverbs
+This is only needed if you want GlusterFS to use InfiniBand as the
+interconnect mechanism between server and client. You can get it from:
+
+@indicateurl{http://www.openfabrics.org/downloads.htm}.
+
+@subsection Bison and Flex
+These should be already installed on most Linux systems. If not, use your distribution's
+normal software installation procedures to install them. Make sure you install the
+relevant developer packages also.
+
+@node Getting GlusterFS
+@section Getting GlusterFS
+@cindex arch
+There are many ways to get hold of GlusterFS. For a production deployment,
+the recommended method is to download the latest release tarball.
+Release tarballs are available at: @indicateurl{http://gluster.org/download.php}.
+
+If you want the bleeding edge development source, you can get them
+from the @acronym{GNU}
+Arch@footnote{@indicateurl{http://www.gnu.org/software/gnu-arch/}}
+repository. First you must install @acronym{GNU} Arch itself. Then
+register the GlusterFS archive by doing:
+
+@example
+$ tla register-archive http://arch.sv.gnu.org/archives/gluster
+@end example
+
+Now you can check out the source itself:
+
+@example
+$ tla get -A gluster@@sv.gnu.org glusterfs--mainline--3.0
+@end example
+
+@node Building
+@section Building
+You can skip this section if you're installing from @acronym{RPM}s
+or @acronym{DEB}s.
+
+GlusterFS uses the Autotools mechanism to build. As such, the procedure
+is straight-forward. First, change into the GlusterFS source directory.
+
+@example
+$ cd glusterfs-<version>
+@end example
+
+If you checked out the source from the Arch repository, you'll need
+to run @command{./autogen.sh} first. Note that you'll need to have
+Autoconf and Automake installed for this.
+
+Run @command{configure}.
+
+@example
+$ ./configure
+@end example
+
+The configure script accepts the following options:
+
+@cartouche
+@table @code
+
+@item --disable-ibverbs
+Disable the InfiniBand transport mechanism.
+
+@item --disable-fuse-client
+Disable the @acronym{FUSE} client.
+
+@item --disable-server
+Disable building of the GlusterFS server.
+
+@item --disable-bdb
+Disable building of Berkeley DB based storage translator.
+
+@item --disable-mod_glusterfs
+Disable building of Apache/lighttpd glusterfs plugins.
+
+@item --disable-epoll
+Use poll instead of epoll.
+
+@item --disable-libglusterfsclient
+Disable building of libglusterfsclient
+
+@end table
+@end cartouche
+
+Build and install GlusterFS.
+
+@example
+# make install
+@end example
+
+The binaries (@command{glusterfsd} and @command{glusterfs}) will be by
+default installed in @command{/usr/local/sbin/}. Translator,
+scheduler, and transport shared libraries will be installed in
+@command{/usr/local/lib/glusterfs/<version>/}. Sample volume
+specification files will be in @command{/usr/local/etc/glusterfs/}.
+This document itself can be found in
+@command{/usr/local/share/doc/glusterfs/}. If you passed the @command{--prefix}
+argument to the configure script, then replace @command{/usr/local} in the preceding
+paths with the prefix.
+
+@node Running GlusterFS
+@section Running GlusterFS
+
+@menu
+* Server::
+* Client::
+@end menu
+
+@node Server
+@subsection Server
+@cindex GlusterFS server
+
+The GlusterFS server is necessary to export storage volumes to remote clients
+(See @ref{Server protocol} for more info). This section documents the invocation
+of the GlusterFS server program and all the command-line options accepted by it.
+
+@cartouche
+@table @code
+Basic Options
+@item -f, --volfile=<path>
+ Use the volume file as the volume specification.
+
+@item -s, --volfile-server=<hostname>
+ Server to get volume file from. This option overrides --volfile option.
+
+@item -l, --log-file=<path>
+ Specify the path for the log file.
+
+@item -L, --log-level=<level>
+ Set the log level for the server. Log level should be one of @acronym{DEBUG},
+@acronym{WARNING}, @acronym{ERROR}, @acronym{CRITICAL}, or @acronym{NONE}.
+
+Advanced Options
+@item --debug
+ Run in debug mode. This option sets --no-daemon, --log-level to DEBUG and
+ --log-file to console.
+
+@item -N, --no-daemon
+ Run glusterfsd as a foreground process.
+
+@item -p, --pid-file=<path>
+ Path for the @acronym{PID} file.
+
+@item --volfile-id=<key>
+ 'key' of the volfile to be fetched from server.
+
+@item --volfile-server-port=<port-number>
+ Listening port number of volfile server.
+
+@item --volfile-server-transport=[socket|ib-verbs]
+ Transport type to get volfile from server. [default: @command{socket}]
+
+@item --xlator-options=<volume-name.option=value>
+ Add/override a translator option for a volume with specified value.
+
+Miscellaneous Options
+@item -?, --help
+ Show this help text.
+
+@item --usage
+ Display a short usage message.
+
+@item -V, --version
+ Show version information.
+@end table
+@end cartouche
+
+@node Client
+@subsection Client
+@cindex GlusterFS client
+
+The GlusterFS client process is necessary to access remote storage volumes and
+mount them locally using @acronym{FUSE}. This section documents the invocation of the
+client process and all its command-line arguments.
+
+@example
+ # glusterfs [options] <mountpoint>
+@end example
+
+The @command{mountpoint} is the directory where you want the GlusterFS
+filesystem to appear. Example:
+
+@example
+ # glusterfs -f /usr/local/etc/glusterfs-client.vol /mnt
+@end example
+
+The command-line options are detailed below.
+
+@tex
+\vfill
+@end tex
+@page
+
+@cartouche
+@table @code
+
+Basic Options
+@item -f, --volfile=<path>
+ Use the volume file as the volume specification.
+
+@item -s, --volfile-server=<hostname>
+ Server to get volume file from. This option overrides --volfile option.
+
+@item -l, --log-file=<path>
+ Specify the path for the log file.
+
+@item -L, --log-level=<level>
+ Set the log level for the server. Log level should be one of @acronym{DEBUG},
+@acronym{WARNING}, @acronym{ERROR}, @acronym{CRITICAL}, or @acronym{NONE}.
+
+Advanced Options
+@item --debug
+ Run in debug mode. This option sets --no-daemon, --log-level to DEBUG and
+ --log-file to console.
+
+@item -N, --no-daemon
+ Run @command{glusterfs} as a foreground process.
+
+@item -p, --pid-file=<path>
+ Path for the @acronym{PID} file.
+
+@item --volfile-id=<key>
+ 'key' of the volfile to be fetched from server.
+
+@item --volfile-server-port=<port-number>
+ Listening port number of volfile server.
+
+@item --volfile-server-transport=[socket|ib-verbs]
+ Transport type to get volfile from server. [default: @command{socket}]
+
+@item --xlator-options=<volume-name.option=value>
+ Add/override a translator option for a volume with specified value.
+
+@item --volume-name=<volume name>
+ Volume name in client spec to use. Defaults to the root volume.
+
+@acronym{FUSE} Options
+@item --attribute-timeout=<n>
+ Attribute timeout for inodes in the kernel, in seconds. Defaults to 1 second.
+
+@item --disable-direct-io-mode
+ Disable direct @acronym{I/O} mode in @acronym{FUSE} kernel module.
+
+@item -e, --entry-timeout=<n>
+ Entry timeout for directory entries in the kernel, in seconds.
+ Defaults to 1 second.
+
+Missellaneous Options
+@item -?, --help
+ Show this help information.
+
+@item -V, --version
+ Show version information.
+@end table
+@end cartouche
+
+@node A Tutorial Introduction
+@section A Tutorial Introduction
+
+This section will show you how to quickly get GlusterFS up and running. We'll
+configure GlusterFS as a simple network filesystem, with one server and one client.
+In this mode of usage, GlusterFS can serve as a replacement for NFS.
+
+We'll make use of two machines; call them @emph{server} and
+@emph{client} (If you don't want to setup two machines, just run
+everything that follows on the same machine). In the examples that
+follow, the shell prompts will use these names to clarify the machine
+on which the command is being run. For example, a command that should
+be run on the server will be shown with the prompt:
+
+@example
+[root@@server]#
+@end example
+
+Our goal is to make a directory on the @emph{server} (say, @command{/export})
+accessible to the @emph{client}.
+
+First of all, get GlusterFS installed on both the machines, as described in the
+previous sections. Make sure you have the @acronym{FUSE} kernel module loaded. You
+can ensure this by running:
+
+@example
+[root@@server]# modprobe fuse
+@end example
+
+Before we can run the GlusterFS client or server programs, we need to write
+two files called @emph{volume specifications} (equivalently refered to as @emph{volfiles}).
+The volfile describes the @emph{translator tree} on a node. The next chapter will
+explain the concepts of `translator' and `volume specification' in detail. For now,
+just assume that the volfile is like an NFS @command{/etc/export} file.
+
+On the server, create a text file somewhere (we'll assume the path
+@command{/tmp/glusterfsd.vol}) with the following contents.
+
+@cartouche
+@example
+volume colon-o
+ type storage/posix
+ option directory /export
+end-volume
+
+volume server
+ type protocol/server
+ subvolumes colon-o
+ option transport-type tcp
+ option auth.addr.colon-o.allow *
+end-volume
+@end example
+@end cartouche
+
+A brief explanation of the file's contents. The first section defines a storage
+volume, named ``colon-o'' (the volume names are arbitrary), which exports the
+@command{/export} directory. The second section defines options for the translator
+which will make the storage volume accessible remotely. It specifies @command{colon-o} as
+a subvolume. This defines the @emph{translator tree}, about which more will be said
+in the next chapter. The two options specify that the @acronym{TCP} protocol is to be
+used (as opposed to InfiniBand, for example), and that access to the storage volume
+is to be provided to clients with any @acronym{IP} address at all. If you wanted to
+restrict access to this server to only your subnet for example, you'd specify
+something like @command{192.168.1.*} in the second option line.
+
+On the client machine, create the following text file (again, we'll assume
+the path to be @command{/tmp/glusterfs-client.vol}). Replace
+@emph{server-ip-address} with the @acronym{IP} address of your server machine. If you
+are doing all this on a single machine, use @command{127.0.0.1}.
+
+@cartouche
+@example
+volume client
+ type protocol/client
+ option transport-type tcp
+ option remote-host @emph{server-ip-address}
+ option remote-subvolume colon-o
+end-volume
+@end example
+@end cartouche
+
+Now we need to start both the server and client programs. To start the server:
+
+@example
+[root@@server]# glusterfsd -f /tmp/glusterfs-server.vol
+@end example
+
+To start the client:
+
+@example
+[root@@client]# glusterfs -f /tmp/glusterfs-client.vol /mnt/glusterfs
+@end example
+
+You should now be able to see the files under the server's @command{/export} directory
+in the @command{/mnt/glusterfs} directory on the client. That's it; GlusterFS is now
+working as a network file system.
+
+@node Concepts
+@chapter Concepts
+
+@menu
+* Filesystems in Userspace::
+* Translator::
+* Volume specification file::
+@end menu
+
+@node Filesystems in Userspace
+@section Filesystems in Userspace
+
+A filesystem is usually implemented in kernel space. Kernel space
+development is much harder than userspace development. @acronym{FUSE}
+is a kernel module/library that allows us to write a filesystem
+completely in userspace.
+
+@acronym{FUSE} consists of a kernel module which interacts with the userspace
+implementation using a device file @code{/dev/fuse}. When a process
+makes a syscall on a @acronym{FUSE} filesystem, @acronym{VFS} hands the request to the
+@acronym{FUSE} module, which writes the request to @code{/dev/fuse}. The
+userspace implementation polls @code{/dev/fuse}, and when a request arrives,
+processes it and writes the result back to @code{/dev/fuse}. The kernel then
+reads from the device file and returns the result to the user process.
+
+In case of GlusterFS, the userspace program is the GlusterFS client.
+The control flow is shown in the diagram below. The GlusterFS client
+services the request by sending it to the server, which in turn
+hands it to the local @acronym{POSIX} filesystem.
+
+@center @image{fuse,44pc,,,.pdf}
+@center Fig 1. Control flow in GlusterFS
+
+@node Translator
+@section Translator
+
+The @emph{translator} is the most important concept in GlusterFS. In
+fact, GlusterFS is nothing but a collection of translators working
+together, forming a translator @emph{tree}.
+
+The idea of a translator is perhaps best understood using an
+analogy. Consider the @acronym{VFS} in the Linux kernel. The
+@acronym{VFS} abstracts the various filesystem implementations (such
+as @acronym{EXT3}, ReiserFS, @acronym{XFS}, etc.) supported by the
+kernel. When an application calls the kernel to perform an operation
+on a file, the kernel passes the request on to the appropriate
+filesystem implementation.
+
+For example, let's say there are two partitions on a Linux machine:
+@command{/}, which is an @acronym{EXT3} partition, and @command{/usr},
+which is a ReiserFS partition. Now if an application wants to open a
+file called, say, @command{/etc/fstab}, then the kernel will
+internally pass the request to the @acronym{EXT3} implementation. If
+on the other hand, an application wants to read a file called
+@command{/usr/src/linux/CREDITS}, then the kernel will call upon the
+ReiserFS implementation to do the job.
+
+The ``filesystem implementation'' objects are analogous to GlusterFS
+translators. A GlusterFS translator implements all the filesystem
+operations. Whereas in @acronym{VFS} there is a two-level tree (with
+the kernel at the root and all the filesystem implementation as its
+children), in GlusterFS there exists a more elaborate tree structure.
+
+We can now define translators more precisely. A GlusterFS translator
+is a shared object (@command{.so}) that implements every filesystem
+call. GlusterFS translators can be arranged in an arbitrary tree
+structure (subject to constraints imposed by the translators). When
+GlusterFS receives a filesystem call, it passes it on to the
+translator at the root of the translator tree. The root translator may
+in turn pass it on to any or all of its children, and so on, until the
+leaf nodes are reached. The result of a filesystem call is
+communicated in the reverse fashion, from the leaf nodes up to the
+root node, and then on to the application.
+
+So what might a translator tree look like?
+
+@tex
+\vfill
+@end tex
+@page
+
+@center @image{xlator,44pc,,,.pdf}
+@center Fig 2. A sample translator tree
+
+The diagram depicts three servers and one GlusterFS client. It is important
+to note that conceptually, the translator tree spans machine boundaries.
+Thus, the client machine in the diagram, @command{10.0.0.1}, can access
+the aggregated storage of the filesystems on the server machines @command{10.0.0.2},
+@command{10.0.0.3}, and @command{10.0.0.4}. The translator diagram will make more
+sense once you've read the next chapter and understood the functions of the
+various translators.
+
+@node Volume specification file
+@section Volume specification file
+The volume specification file describes the translator tree for both the
+server and client programs.
+
+A volume specification file is a sequence of volume definitions.
+The syntax of a volume definition is explained below:
+
+@cartouche
+@example
+@strong{volume} @emph{volume-name}
+ @strong{type} @emph{translator-name}
+ @strong{option} @emph{option-name} @emph{option-value}
+ @dots{}
+ @strong{subvolumes} @emph{subvolume1} @emph{subvolume2} @dots{}
+@strong{end-volume}
+@end example
+
+@dots{}
+@end cartouche
+
+@table @asis
+@item @emph{volume-name}
+ An identifier for the volume. This is just a human-readable name,
+and can contain any alphanumeric character. For instance, ``storage-1'', ``colon-o'',
+or ``forty-two''.
+
+@item @emph{translator-name}
+ Name of one of the available translators. Example: @command{protocol/client},
+@command{cluster/unify}.
+
+@item @emph{option-name}
+ Name of a valid option for the translator.
+
+@item @emph{option-value}
+ Value for the option. Everything following the ``option'' keyword to the end of the
+line is considered the value; it is up to the translator to parse it.
+
+@item @emph{subvolume1}, @emph{subvolume2}, @dots{}
+ Volume names of sub-volumes. The sub-volumes must already have been defined earlier
+in the file.
+@end table
+
+There are a few rules you must follow when writing a volume specification file:
+
+@itemize
+@item Everything following a `@command{#}' is considered a comment and is ignored. Blank lines are also ignored.
+@item All names and keywords are case-sensitive.
+@item The order of options inside a volume definition does not matter.
+@item An option value may not span multiple lines.
+@item If an option is not specified, it will assume its default value.
+@item A sub-volume must have already been defined before it can be referenced. This means you have to write the specification file ``bottom-up'', starting from the leaf nodes of the translator tree and moving up to the root.
+@end itemize
+
+A simple example volume specification file is shown below:
+
+@cartouche
+@example
+# This is a comment line
+volume client
+ type protocol/client
+ option transport-type tcp
+ option remote-host localhost # Also a comment
+ option remote-subvolume brick
+# The subvolumes line may be absent
+end-volume
+
+volume iot
+ type performance/io-threads
+ option thread-count 4
+ subvolumes client
+end-volume
+
+volume wb
+ type performance/write-behind
+ subvolumes iot
+end-volume
+@end example
+@end cartouche
+
+@node Translators
+@chapter Translators
+
+@menu
+* Storage Translators::
+* Client and Server Translators::
+* Clustering Translators::
+* Performance Translators::
+* Features Translators::
+* Miscellaneous Translators::
+@end menu
+
+This chapter documents all the available GlusterFS translators in detail.
+Each translator section will show its name (for example, @command{cluster/unify}),
+briefly describe its purpose and workings, and list every option accepted by
+that translator and their meaning.
+
+@node Storage Translators
+@section Storage Translators
+
+The storage translators form the ``backend'' for GlusterFS. Currently,
+the only available storage translator is the @acronym{POSIX}
+translator, which stores files on a normal @acronym{POSIX}
+filesystem. A pleasant consequence of this is that your data will
+still be accessible if GlusterFS crashes or cannot be started.
+
+Other storage backends are planned for the future. One of the possibilities is an
+Amazon S3 translator. Amazon S3 is an unlimited online storage service accessible
+through a web services @acronym{API}. The S3 translator will allow you to access
+the storage as a normal @acronym{POSIX} filesystem.
+@footnote{Some more discussion about this can be found at:
+
+http://developer.amazonwebservices.com/connect/message.jspa?messageID=52873}
+
+@menu
+* POSIX::
+* BDB::
+@end menu
+
+@node POSIX
+@subsection POSIX
+@example
+type storage/posix
+@end example
+
+The @command{posix} translator uses a normal @acronym{POSIX}
+filesystem as its ``backend'' to actually store files and
+directories. This can be any filesystem that supports extended
+attributes (@acronym{EXT3}, ReiserFS, @acronym{XFS}, ...). Extended
+attributes are used by some translators to store metadata, for
+example, by the replicate and stripe translators. See
+@ref{Replicate} and @ref{Stripe}, respectively for details.
+
+@cartouche
+@table @code
+@item directory <path>
+The directory on the local filesystem which is to be used for storage.
+@end table
+@end cartouche
+
+@node BDB
+@subsection BDB
+@example
+type storage/bdb
+@end example
+
+The @command{BDB} translator uses a @acronym{Berkeley DB} database as its
+``backend'' to actually store files as key-value pair in the database and
+directories as regular @acronym{POSIX} directories. Note that @acronym{BDB}
+does not provide extended attribute support for regular files. Do not use
+@acronym{BDB} as storage translator while using any translator that demands
+extended attributes on ``backend''.
+
+@cartouche
+@table @code
+@item directory <path>
+The directory on the local filesystem which is to be used for storage.
+@item mode [cache|persistent] (cache)
+When @acronym{BDB} is run in @command{cache} mode, recovery of back-end is not completely
+guaranteed. @command{persistent} guarantees that @acronym{BDB} can recover back-end from
+@acronym{Berkeley DB} even if GlusterFS crashes.
+@item errfile <path>
+The path of the file to be used as @command{errfile} for @acronym{Berkeley DB} to report
+detailed error messages, if any. Note that all the contents of this file will be written
+by @acronym{Berkeley DB}, not GlusterFS.
+@item logdir <path>
+
+
+@end table
+@end cartouche
+
+@node Client and Server Translators, Clustering Translators, Storage Translators, Translators
+@section Client and Server Translators
+
+The client and server translator enable GlusterFS to export a
+translator tree over the network or access a remote GlusterFS
+server. These two translators implement GlusterFS's network protocol.
+
+@menu
+* Transport modules::
+* Client protocol::
+* Server protocol::
+@end menu
+
+@node Transport modules
+@subsection Transport modules
+The client and server translators are capable of using any of the
+pluggable transport modules. Currently available transport modules are
+@command{tcp}, which uses a @acronym{TCP} connection between client
+and server to communicate; @command{ib-sdp}, which uses a
+@acronym{TCP} connection over InfiniBand, and @command{ibverbs}, which
+uses high-speed InfiniBand connections.
+
+Each transport module comes in two different versions, one to be used on
+the server side and the other on the client side.
+
+@subsubsection TCP
+
+The @acronym{TCP} transport module uses a @acronym{TCP/IP} connection between
+the server and the client.
+
+@example
+ option transport-type tcp
+@end example
+
+The @acronym{TCP} client module accepts the following options:
+
+@cartouche
+@table @code
+@item non-blocking-connect [no|off|on|yes] (on)
+Whether to make the connection attempt asynchronous.
+@item remote-port <n> (6996)
+Server port to connect to.
+@cindex DNS round robin
+@item remote-host <hostname> *
+Hostname or @acronym{IP} address of the server. If the host name resolves to
+multiple IP addresses, all of them will be tried in a round-robin fashion. This
+feature can be used to implement fail-over.
+@end table
+@end cartouche
+
+The @acronym{TCP} server module accepts the following options:
+
+@cartouche
+@table @code
+@item bind-address <address> (0.0.0.0)
+The local interface on which the server should listen to requests. Default is to
+listen on all interfaces.
+@item listen-port <n> (6996)
+The local port to listen on.
+@end table
+@end cartouche
+
+@subsubsection IB-SDP
+@example
+ option transport-type ib-sdp
+@end example
+
+kernel implements socket interface for ib hardware. SDP is over ib-verbs.
+This module accepts the same options as @command{tcp}
+
+@subsubsection ibverbs
+
+@example
+ option transport-type tcp
+@end example
+
+@cindex infiniband transport
+
+InfiniBand is a scalable switched fabric interconnect mechanism
+primarily used in high-performance computing. InfiniBand can deliver
+data throughput of the order of 10 Gbit/s, with latencies of 4-5 ms.
+
+The @command{ib-verbs} transport accesses the InfiniBand hardware through
+the ``verbs'' @acronym{API}, which is the lowest level of software access possible
+and which gives the highest performance. On InfiniBand hardware, it is always
+best to use @command{ib-verbs}. Use @command{ib-sdp} only if you cannot get
+@command{ib-verbs} working for some reason.
+
+The @command{ib-verbs} client module accepts the following options:
+
+@cartouche
+@table @code
+@item non-blocking-connect [no|off|on|yes] (on)
+Whether to make the connection attempt asynchronous.
+@item remote-port <n> (6996)
+Server port to connect to.
+@cindex DNS round robin
+@item remote-host <hostname> *
+Hostname or @acronym{IP} address of the server. If the host name resolves to
+multiple IP addresses, all of them will be tried in a round-robin fashion. This
+feature can be used to implement fail-over.
+@end table
+@end cartouche
+
+The @command{ib-verbs} server module accepts the following options:
+
+@cartouche
+@table @code
+@item bind-address <address> (0.0.0.0)
+The local interface on which the server should listen to requests. Default is to
+listen on all interfaces.
+@item listen-port <n> (6996)
+The local port to listen on.
+@end table
+@end cartouche
+
+The following options are common to both the client and server modules:
+
+If you are familiar with InfiniBand jargon,
+the mode is used by GlusterFS is ``reliable connection-oriented channel transfer''.
+
+@cartouche
+@table @code
+@item ib-verbs-work-request-send-count <n> (64)
+Length of the send queue in datagrams. [Reason to increase/decrease?]
+
+@item ib-verbs-work-request-recv-count <n> (64)
+Length of the receive queue in datagrams. [Reason to increase/decrease?]
+
+@item ib-verbs-work-request-send-size <size> (128KB)
+Size of each datagram that is sent. [Reason to increase/decrease?]
+
+@item ib-verbs-work-request-recv-size <size> (128KB)
+Size of each datagram that is received. [Reason to increase/decrease?]
+
+@item ib-verbs-port <n> (1)
+Port number for ib-verbs.
+
+@item ib-verbs-mtu [256|512|1024|2048|4096] (2048)
+The Maximum Transmission Unit [Reason to increase/decrease?]
+
+@item ib-verbs-device-name <device-name> (first device in the list)
+InfiniBand device to be used.
+@end table
+@end cartouche
+
+For maximum performance, you should ensure that the send/receive counts on both
+the client and server are the same.
+
+ib-verbs is preferred over ib-sdp.
+
+@node Client protocol
+@subsection Client
+@example
+type procotol/client
+@end example
+
+The client translator enables the GlusterFS client to access a remote server's
+translator tree.
+
+@cartouche
+@table @code
+
+@item transport-type [tcp,ib-sdp,ib-verbs] (tcp)
+The transport type to use. You should use the client versions of all the
+transport modules (@command{tcp}, @command{ib-sdp},
+@command{ib-verbs}).
+@item remote-subvolume <volume_name> *
+The name of the volume on the remote host to attach to. Note that
+this is @emph{not} the name of the @command{protocol/server} volume on the
+server. It should be any volume under the server.
+@item transport-timeout <n> (120- seconds)
+Inactivity timeout. If a reply is expected and no activity takes place
+on the connection within this time, the transport connection will be
+broken, and a new connection will be attempted.
+@end table
+@end cartouche
+
+@node Server protocol
+@subsection Server
+@example
+type protocol/server
+@end example
+
+The server translator exports a translator tree and makes it accessible to
+remote GlusterFS clients.
+
+@cartouche
+@table @code
+@item client-volume-filename <path> (<CONFDIR>/glusterfs-client.vol)
+The volume specification file to use for the client. This is the file the
+client will receive when it is invoked with the @command{--server} option
+(@ref{Client}).
+
+@item transport-type [tcp,ib-verbs,ib-sdp] (tcp)
+The transport to use. You should use the server versions of all the transport
+modules (@command{tcp}, @command{ib-sdp}, @command{ib-verbs}).
+
+@item auth.addr.<volume name>.allow <IP address wildcard pattern>
+IP addresses of the clients that are allowed to attach to the specified volume.
+This can be a wildcard. For example, a wildcard of the form @command{192.168.*.*}
+allows any host in the @command{192.168.x.x} subnet to connect to the server.
+
+@end table
+@end cartouche
+
+@node Clustering Translators
+@section Clustering Translators
+
+The clustering translators are the most important GlusterFS
+translators, since it is these that make GlusterFS a cluster
+filesystem. These translators together enable GlusterFS to access an
+arbitrarily large amount of storage, and provide @acronym{RAID}-like
+redundancy and distribution over the entire cluster.
+
+There are three clustering translators: @strong{unify}, @strong{replicate},
+and @strong{stripe}. The unify translator aggregates storage from
+many server nodes. The replicate translator provides file replication. The stripe
+translator allows a file to be spread across many server nodes. The following sections
+look at each of these translators in detail.
+
+@menu
+* Unify::
+* Replicate::
+* Stripe::
+@end menu
+
+@node Unify
+@subsection Unify
+@cindex unify (translator)
+@cindex scheduler (unify)
+@example
+type cluster/unify
+@end example
+
+The unify translator presents a `unified' view of all its sub-volumes. That is,
+it makes the union of all its sub-volumes appear as a single volume. It is the
+unify translator that gives GlusterFS the ability to access an arbitrarily
+large amount of storage.
+
+For unify to work correctly, certain invariants need to be maintained across
+the entire network. These are:
+
+@cindex unify invariants
+@itemize
+@item The directory structure of all the sub-volumes must be identical.
+@item A particular file can exist on only one of the sub-volumes. Phrasing it in another way, a pathname such as @command{/home/calvin/homework.txt}) is unique across the entire cluster.
+@end itemize
+
+@tex
+\vfill
+@end tex
+@page
+
+@center @image{unify,44pc,,,.pdf}
+
+Looking at the second requirement, you might wonder how one can
+accomplish storing redundant copies of a file, if no file can exist
+multiple times. To answer, we must remember that these invariants are
+from @emph{unify's perspective}. A translator such as replicate at a lower
+level in the translator tree than unify may subvert this picture.
+
+The first invariant might seem quite tedious to ensure. We shall see
+later that this is not so, since unify's @emph{self-heal} mechanism
+takes care of maintaining it.
+
+The second invariant implies that unify needs some way to decide which file goes where.
+Unify makes use of @emph{scheduler} modules for this purpose.
+
+When a file needs to be created, unify's scheduler decides upon the
+sub-volume to be used to store the file. There are many schedulers
+available, each using a different algorithm and suitable for different
+purposes.
+
+The various schedulers are described in detail in the sections that follow.
+
+@subsubsection ALU
+@cindex alu (scheduler)
+
+@example
+ option scheduler alu
+@end example
+
+ALU stands for "Adaptive Least Usage". It is the most advanced
+scheduler available in GlusterFS. It balances the load across volumes
+taking several factors in account. It adapts itself to changing I/O
+patterns according to its configuration. When properly configured, it
+can eliminate the need for regular tuning of the filesystem to keep
+volume load nicely balanced.
+
+The ALU scheduler is composed of multiple least-usage
+sub-schedulers. Each sub-scheduler keeps track of a certain type of
+load, for each of the sub-volumes, getting statistics from
+the sub-volumes themselves. The sub-schedulers are these:
+
+@itemize
+@item disk-usage: The used and free disk space on the volume.
+
+@item read-usage: The amount of reading done from this volume.
+
+@item write-usage: The amount of writing done to this volume.
+
+@item open-files-usage: The number of files currently open from this volume.
+
+@item disk-speed-usage: The speed at which the disks are spinning. This is a constant value and therefore not very useful.
+@end itemize
+
+The ALU scheduler needs to know which of these sub-schedulers to use,
+and in which order to evaluate them. This is done through the
+@command{option alu.order} configuration directive.
+
+Each sub-scheduler needs to know two things: when to kick in (the
+entry-threshold), and how long to stay in control (the
+exit-threshold). For example: when unifying three disks of 100GB,
+keeping an exact balance of disk-usage is not necesary. Instead, there
+could be a 1GB margin, which can be used to nicely balance other
+factors, such as read-usage. The disk-usage scheduler can be told to
+kick in only when a certain threshold of discrepancy is passed, such
+as 1GB. When it assumes control under this condition, it will write
+all subsequent data to the least-used volume. If it is doing so, it is
+unwise to stop right after the values are below the entry-threshold
+again, since that would make it very likely that the situation will
+occur again very soon. Such a situation would cause the ALU to spend
+most of its time disk-usage scheduling, which is unfair to the other
+sub-schedulers. The exit-threshold therefore defines the amount of
+data that needs to be written to the least-used disk, before control
+is relinquished again.
+
+In addition to the sub-schedulers, the ALU scheduler also has "limits"
+options. These can stop the creation of new files on a volume once
+values drop below a certain threshold. For example, setting
+@command{option alu.limits.min-free-disk 5GB} will stop the scheduling
+of files to volumes that have less than 5GB of free disk space,
+leaving the files on that disk some room to grow.
+
+The actual values you assign to the thresholds for sub-schedulers and
+limits depend on your situation. If you have fast-growing files,
+you'll want to stop file-creation on a disk much earlier than when
+hardly any of your files are growing. If you care less about
+disk-usage balance than about read-usage balance, you'll want a bigger
+disk-usage scheduler entry-threshold and a smaller read-usage
+scheduler entry-threshold.
+
+For thresholds defining a size, values specifying "KB", "MB" and "GB"
+are allowed. For example: @command{option alu.limits.min-free-disk 5GB}.
+
+@cartouche
+@table @code
+@item alu.order <order> * ("disk-usage:write-usage:read-usage:open-files-usage:disk-speed")
+@item alu.disk-usage.entry-threshold <size> (1GB)
+@item alu.disk-usage.exit-threshold <size> (512MB)
+@item alu.write-usage.entry-threshold <%> (25)
+@item alu.write-usage.exit-threshold <%> (5)
+@item alu.read-usage.entry-threshold <%> (25)
+@item alu.read-usage.exit-threshold <%> (5)
+@item alu.open-files-usage.entry-threshold <n> (1000)
+@item alu.open-files-usage.exit-threshold <n> (100)
+@item alu.limits.min-free-disk <%>
+@item alu.limits.max-open-files <n>
+@end table
+@end cartouche
+
+@subsubsection Round Robin (RR)
+@cindex rr (scheduler)
+
+@example
+ option scheduler rr
+@end example
+
+Round-Robin (RR) scheduler creates files in a round-robin
+fashion. Each client will have its own round-robin loop. When your
+files are mostly similar in size and I/O access pattern, this
+scheduler is a good choice. RR scheduler checks for free disk space
+on the server before scheduling, so you can know when to add
+another server node. The default value of min-free-disk is 5% and is
+checked on file creation calls, with atleast 10 seconds (by default)
+elapsing between two checks.
+
+Options:
+@cartouche
+@table @code
+@item rr.limits.min-free-disk <%> (5)
+Minimum free disk space a node must have for RR to schedule a file to it.
+@item rr.refresh-interval <t> (10 seconds)
+Time between two successive free disk space checks.
+@end table
+@end cartouche
+
+@subsubsection Random
+@cindex random (scheduler)
+
+@example
+ option scheduler random
+@end example
+
+The random scheduler schedules file creation randomly among its child nodes.
+Like the round-robin scheduler, it also checks for a minimum amount of free disk
+space before scheduling a file to a node.
+
+@cartouche
+@table @code
+@item random.limits.min-free-disk <%> (5)
+Minimum free disk space a node must have for random to schedule a file to it.
+@item random.refresh-interval <t> (10 seconds)
+Time between two successive free disk space checks.
+@end table
+@end cartouche
+
+@subsubsection NUFA
+@cindex nufa (scheduler)
+
+@example
+ option scheduler nufa
+@end example
+
+It is common in many GlusterFS computing environments for all deployed
+machines to act as both servers and clients. For example, a
+research lab may have 40 workstations each with its own storage. All
+of these workstations might act as servers exporting a volume as well
+as clients accessing the entire cluster's storage. In such a
+situation, it makes sense to store locally created files on the local
+workstation itself (assuming files are accessed most by the
+workstation that created them). The Non-Uniform File Allocation (@acronym{NUFA})
+scheduler accomplishes that.
+
+@acronym{NUFA} gives the local system first priority for file creation
+over other nodes. If the local volume does not have more free disk space
+than a specified amount (5% by default) then @acronym{NUFA} schedules files
+among the other child volumes in a round-robin fashion.
+
+@acronym{NUFA} is named after the similar strategy used for memory access,
+@acronym{NUMA}@footnote{Non-Uniform Memory Access:
+@indicateurl{http://en.wikipedia.org/wiki/Non-Uniform_Memory_Access}}.
+
+@cartouche
+@table @code
+@item nufa.limits.min-free-disk <%> (5)
+Minimum disk space that must be free (local or remote) for @acronym{NUFA} to schedule a
+file to it.
+@item nufa.refresh-interval <t> (10 seconds)
+Time between two successive free disk space checks.
+@item nufa.local-volume-name <volume>
+The name of the volume corresponding to the local system. This volume must be
+one of the children of the unify volume. This option is mandatory.
+@end table
+@end cartouche
+
+@cindex namespace
+@subsubsection Namespace
+Namespace volume needed because:
+ - persistent inode numbers.
+ - file exists even when node is down.
+
+namespace files are simply touched. on every lookup it is checked.
+
+@cartouche
+@table @code
+@item namespace <volume> *
+Name of the namespace volume (which should be one of the unify volume's children).
+@item self-heal [on|off] (on)
+Enable/disable self-heal. Unless you know what you are doing, do not disable self-heal.
+@end table
+@end cartouche
+
+@cindex self heal (unify)
+@subsubsection Self Heal
+ * When a 'lookup()/stat()' call is made on directory for the first
+time, a self-heal call is made, which checks for the consistancy of
+its child nodes. If an entry is present in storage node, but not in
+namespace, that entry is created in namespace, and vica-versa. There
+is an writedir() API introduced which is used for the same. It also
+checks for permissions, and uid/gid consistencies.
+
+ * This check is also done when an server goes down and comes up.
+
+ * If one starts with an empty namespace export, but has data in
+storage nodes, a 'find .>/dev/null' or 'ls -lR >/dev/null' should help
+to build namespace in one shot. Even otherwise, namespace is built on
+demand when a file is looked up for the first time.
+
+NOTE: There are some issues (Kernel 'Oops' msgs) seen with fuse-2.6.3,
+when someone deletes namespace in backend, when glusterfs is
+running. But with fuse-2.6.5, this issue is not there.
+
+@node Replicate
+@subsection Replicate (formerly AFR)
+@cindex Replicate
+@example
+type cluster/replicate
+@end example
+
+Replicate provides @acronym{RAID}-1 like functionality for
+GlusterFS. Replicate replicates files and directories across the
+subvolumes. Hence if Replicate has four subvolumes, there will be
+four copies of all files and directories. Replicate provides
+high-availability, i.e., in case one of the subvolumes go down
+(e. g. server crash, network disconnection) Replicate will still
+service the requests using the redundant copies.
+
+Replicate also provides self-heal functionality, i.e., in case the
+crashed servers come up, the outdated files and directories will be
+updated with the latest versions. Replicate uses extended
+attributes of the backend file system to track the versioning of files
+and directories and provide the self-heal feature.
+
+@example
+volume replicate-example
+ type cluster/replicate
+ subvolumes brick1 brick2 brick3
+end-volume
+@end example
+
+This sample configuration will replicate all directories and files on
+brick1, brick2 and brick3.
+
+All the read operations happen from the first alive child. If all the
+three sub-volumes are up, reads will be done from brick1; if brick1 is
+down read will be done from brick2. In case read() was being done on
+brick1 and it goes down, replicate transparently falls back to
+brick2.
+
+The next release of GlusterFS will add the following features:
+@itemize
+@item Ability to specify the sub-volume from which read operations are to be done (this will help users who have one of the sub-volumes as a local storage volume).
+@item Allow scheduling of read operations amongst the sub-volumes in a round-robin fashion.
+@end itemize
+
+The order of the subvolumes list should be same across all the 'replicate's as
+they will be used for locking purposes.
+
+@cindex self heal (replicate)
+@subsubsection Self Heal
+Replicate has self-heal feature, which updates the outdated file and
+directory copies by the most recent versions. For example consider the
+following config:
+
+@example
+volume replicate-example
+ type cluster/replicate
+ subvolumes brick1 brick2
+end-volume
+@end example
+
+@subsubsection File self-heal
+
+Now if we create a file foo.txt on replicate-example, the file will be created
+on brick1 and brick2. The file will have two extended attributes associated
+with it in the backend filesystem. One is trusted.afr.createtime and the
+other is trusted.afr.version. The trusted.afr.createtime xattr has the
+create time (in terms of seconds since epoch) and trusted.afr.version
+is a number that is incremented each time a file is modified. This increment
+happens during close (incase any write was done before close).
+
+If brick1 goes down, we edit foo.txt the version gets incremented. Now
+the brick1 comes back up, when we open() on foo.txt replicate will check if
+their versions are same. If they are not same, the outdated copy is
+replaced by the latest copy and its version is updated. After the sync
+the open() proceeds in the usual manner and the application calling open()
+can continue on its access to the file.
+
+If brick1 goes down, we delete foo.txt and create a file with the same
+name again i.e foo.txt. Now brick1 comes back up, clearly there is a
+chance that the version on brick1 being more than the version on brick2,
+this is where createtime extended attribute helps in deciding which
+the outdated copy is. Hence we need to consider both createtime and
+version to decide on the latest copy.
+
+The version attribute is incremented during the close() call. Version
+will not be incremented in case there was no write() done. In case the
+fd that the close() gets was got by create() call, we also create
+the createtime extended attribute.
+
+@subsubsection Directory self-heal
+
+Suppose brick1 goes down, we delete foo.txt, brick1 comes back up, now
+we should not create foo.txt on brick2 but we should delete foo.txt
+on brick1. We handle this situation by having the createtime and version
+attribute on the directory similar to the file. when lookup() is done
+on the directory, we compare the createtime/version attributes of the
+copies and see which files needs to be deleted and delete those files
+and update the extended attributes of the outdated directory copy.
+Each time a directory is modified (a file or a subdirectory is created
+or deleted inside the directory) and one of the subvols is down, we
+increment the directory's version.
+
+lookup() is a call initiated by the kernel on a file or directory
+just before any access to that file or directory. In glusterfs, by
+default, lookup() will not be called in case it was called in the
+past one second on that particular file or directory.
+
+The extended attributes can be seen in the backend filesystem using
+the @command{getfattr} command. (@command{getfattr -n trusted.afr.version <file>})
+
+@cartouche
+@table @code
+@item debug [on|off] (off)
+@item self-heal [on|off] (on)
+@item replicate <pattern> (*:1)
+@item lock-node <child_volume> (first child is used by default)
+@end table
+@end cartouche
+
+@node Stripe
+@subsection Stripe
+@cindex stripe (translator)
+@example
+type cluster/stripe
+@end example
+
+The stripe translator distributes the contents of a file over its
+sub-volumes. It does this by creating a file equal in size to the
+total size of the file on each of its sub-volumes. It then writes only
+a part of the file to each sub-volume, leaving the rest of it empty.
+These empty regions are called `holes' in Unix terminology. The holes
+do not consume any disk space.
+
+The diagram below makes this clear.
+
+@center @image{stripe,44pc,,,.pdf}
+
+You can configure stripe so that only filenames matching a pattern
+are striped. You can also configure the size of the data to be stored
+on each sub-volume.
+
+@cartouche
+@table @code
+@item block-size <pattern>:<size> (*:0 no striping)
+Distribute files matching @command{<pattern>} over the sub-volumes,
+storing at least @command{<size>} on each sub-volume. For example,
+
+@example
+ option block-size *.mpg:1M
+@end example
+
+distributes all files ending in @command{.mpg}, storing at least 1 MB on
+each sub-volume.
+
+Any number of @command{block-size} option lines may be present, specifying
+different sizes for different file name patterns.
+@end table
+@end cartouche
+
+@node Performance Translators
+@section Performance Translators
+
+@menu
+* Read Ahead::
+* Write Behind::
+* IO Threads::
+* IO Cache::
+* Booster::
+@end menu
+
+@node Read Ahead
+@subsection Read Ahead
+@cindex read-ahead (translator)
+@example
+type performance/read-ahead
+@end example
+
+The read-ahead translator pre-fetches data in advance on every read.
+This benefits applications that mostly process files in sequential order,
+since the next block of data will already be available by the time the
+application is done with the current one.
+
+Additionally, the read-ahead translator also behaves as a read-aggregator.
+Many small read operations are combined and issued as fewer, larger read
+requests to the server.
+
+Read-ahead deals in ``pages'' as the unit of data fetched. The page size
+is configurable, as is the ``page count'', which is the number of pages
+that are pre-fetched.
+
+Read-ahead is best used with InfiniBand (using the ib-verbs transport).
+On FastEthernet and Gigabit Ethernet networks,
+GlusterFS can achieve the link-maximum throughput even without
+read-ahead, making it quite superflous.
+
+Note that read-ahead only happens if the reads are perfectly
+sequential. If your application accesses data in a random fashion,
+using read-ahead might actually lead to a performance loss, since
+read-ahead will pointlessly fetch pages which won't be used by the
+application.
+
+@cartouche
+Options:
+@table @code
+@item page-size <n> (256KB)
+The unit of data that is pre-fetched.
+@item page-count <n> (2)
+The number of pages that are pre-fetched.
+@item force-atime-update [on|off|yes|no] (off|no)
+Whether to force an access time (atime) update on the file on every read. Without
+this, the atime will be slightly imprecise, as it will reflect the time when
+the read-ahead translator read the data, not when the application actually read it.
+@end table
+@end cartouche
+
+@node Write Behind
+@subsection Write Behind
+@cindex write-behind (translator)
+@example
+type performance/write-behind
+@end example
+
+The write-behind translator improves the latency of a write operation.
+It does this by relegating the write operation to the background and
+returning to the application even as the write is in progress. Using the
+write-behind translator, successive write requests can be pipelined.
+This mode of write-behind operation is best used on the client side, to
+enable decreased write latency for the application.
+
+The write-behind translator can also aggregate write requests. If the
+@command{aggregate-size} option is specified, then successive writes upto that
+size are accumulated and written in a single operation. This mode of operation
+is best used on the server side, as this will decrease the disk's head movement
+when multiple files are being written to in parallel.
+
+The @command{aggregate-size} option has a default value of 128KB. Although
+this works well for most users, you should always experiment with different values
+to determine the one that will deliver maximum performance. This is because the
+performance of write-behind depends on your interconnect, size of RAM, and the
+work load.
+
+@cartouche
+@table @code
+@item aggregate-size <n> (128KB)
+Amount of data to accumulate before doing a write
+@item flush-behind [on|yes|off|no] (off|no)
+
+@end table
+@end cartouche
+
+@node IO Threads
+@subsection IO Threads
+@cindex io-threads (translator)
+@example
+type performance/io-threads
+@end example
+
+The IO threads translator is intended to increase the responsiveness
+of the server to metadata operations by doing file I/O (read, write)
+in a background thread. Since the GlusterFS server is
+single-threaded, using the IO threads translator can significantly
+improve performance. This translator is best used on the server side,
+loaded just below the server protocol translator.
+
+IO threads operates by handing out read and write requests to a separate thread.
+The total number of threads in existence at a time is constant, and configurable.
+
+@cartouche
+@table @code
+@item thread-count <n> (1)
+Number of threads to use.
+@end table
+@end cartouche
+
+@node IO Cache
+@subsection IO Cache
+@cindex io-cache (translator)
+@example
+type performance/io-cache
+@end example
+
+The IO cache translator caches data that has been read. This is useful
+if many applications read the same data multiple times, and if reads
+are much more frequent than writes (for example, IO caching may be
+useful in a web hosting environment, where most clients will simply
+read some files and only a few will write to them).
+
+The IO cache translator reads data from its child in @command{page-size} chunks.
+It caches data upto @command{cache-size} bytes. The cache is maintained as
+a prioritized least-recently-used (@acronym{LRU}) list, with priorities determined
+by user-specified patterns to match filenames.
+
+When the IO cache translator detects a write operation, the
+cache for that file is flushed.
+
+The IO cache translator periodically verifies the consistency of
+cached data, using the modification times on the files. The verification timeout
+is configurable.
+
+@cartouche
+@table @code
+@item page-size <n> (128KB)
+Size of a page.
+@item cache-size (n) (32MB)
+Total amount of data to be cached.
+@item force-revalidate-timeout <n> (1)
+Timeout to force a cache consistency verification, in seconds.
+@item priority <pattern> (*:0)
+Filename patterns listed in order of priority.
+@end table
+@end cartouche
+
+@node Booster
+@subsection Booster
+@cindex booster
+@example
+ type performance/booster
+@end example
+
+The booster translator gives applications a faster path to communicate
+read and write requests to GlusterFS. Normally, all requests to GlusterFS from
+applications go through FUSE, as indicated in @ref{Filesystems in Userspace}.
+Using the booster translator in conjunction with the GlusterFS booster shared
+library, an application can bypass the FUSE path and send read/write requests
+directly to the GlusterFS client process.
+
+The booster mechanism consists of two parts: the booster translator,
+and the booster shared library. The booster translator is meant to be
+loaded on the client side, usually at the root of the translator tree.
+The booster shared library should be @command{LD_PRELOAD}ed with the
+application.
+
+The booster translator when loaded opens a Unix domain socket and
+listens for read/write requests on it. The booster shared library
+intercepts read and write system calls and sends the requests to the
+GlusterFS process directly using the Unix domain socket, bypassing FUSE.
+This leads to superior performance.
+
+Once you've loaded the booster translator in your volume specification file, you
+can start your application as:
+
+@example
+ $ LD_PRELOAD=/usr/local/bin/glusterfs-booster.so your_app
+@end example
+
+The booster translator accepts no options.
+
+@node Features Translators
+@section Features Translators
+
+@menu
+* POSIX Locks::
+* Fixed ID::
+@end menu
+
+@node POSIX Locks
+@subsection POSIX Locks
+@cindex record locking
+@cindex fcntl
+@cindex posix-locks (translator)
+@example
+type features/posix-locks
+@end example
+
+This translator provides storage independent POSIX record locking
+support (@command{fcntl} locking). Typically you'll want to load this on the
+server side, just above the @acronym{POSIX} storage translator. Using this
+translator you can get both advisory locking and mandatory locking
+support. It also handles @command{flock()} locks properly.
+
+Caveat: Consider a file that does not have its mandatory locking bits
+(+setgid, -group execution) turned on. Assume that this file is now
+opened by a process on a client that has the write-behind xlator
+loaded. The write-behind xlator does not cache anything for files
+which have mandatory locking enabled, to avoid incoherence. Let's say
+that mandatory locking is now enabled on this file through another
+client. The former client will not know about this change, and
+write-behind may erroneously report a write as being successful when
+in fact it would fail due to the region it is writing to being locked.
+
+There seems to be no easy way to fix this. To work around this
+problem, it is recommended that you never enable the mandatory bits on
+a file while it is open.
+
+@cartouche
+@table @code
+@item mandatory [on|off] (on)
+Turns mandatory locking on.
+@end table
+@end cartouche
+
+@node Fixed ID
+@subsection Fixed ID
+@cindex fixed-id (translator)
+@example
+type features/fixed-id
+@end example
+
+The fixed ID translator makes all filesystem requests from the client
+to appear to be coming from a fixed, specified
+@acronym{UID}/@acronym{GID}, regardless of which user actually
+initiated the request.
+
+@cartouche
+@table @code
+@item fixed-uid <n> [if not set, not used]
+The @acronym{UID} to send to the server
+@item fixed-gid <n> [if not set, not used]
+The @acronym{GID} to send to the server
+@end table
+@end cartouche
+
+@node Miscellaneous Translators
+@section Miscellaneous Translators
+
+@menu
+* ROT-13::
+* Trace::
+@end menu
+
+@node ROT-13
+@subsection ROT-13
+@cindex rot-13 (translator)
+@example
+type encryption/rot-13
+@end example
+
+@acronym{ROT-13} is a toy translator that can ``encrypt'' and ``decrypt'' file
+contents using the @acronym{ROT-13} algorithm. @acronym{ROT-13} is a trivial
+algorithm that rotates each alphabet by thirteen places. Thus, 'A' becomes 'N',
+'B' becomes 'O', and 'Z' becomes 'M'.
+
+It goes without saying that you shouldn't use this translator if you need
+@emph{real} encryption (a future release of GlusterFS will have real encryption
+translators).
+
+@cartouche
+@table @code
+@item encrypt-write [on|off] (on)
+Whether to encrypt on write
+@item decrypt-read [on|off] (on)
+Whether to decrypt on read
+@end table
+@end cartouche
+
+@node Trace
+@subsection Trace
+@cindex trace (translator)
+@example
+type debug/trace
+@end example
+
+The trace translator is intended for debugging purposes. When loaded, it
+logs all the system calls received by the server or client (wherever
+trace is loaded), their arguments, and the results. You must use a GlusterFS log
+level of DEBUG (See @ref{Running GlusterFS}) for trace to work.
+
+Sample trace output (lines have been wrapped for readability):
+@cartouche
+@example
+2007-10-30 00:08:58 D [trace.c:1579:trace_opendir] trace: callid: 68
+(*this=0x8059e40, loc=0x8091984 @{path=/iozone3_283, inode=0x8091f00@},
+ fd=0x8091d50)
+
+2007-10-30 00:08:58 D [trace.c:630:trace_opendir_cbk] trace:
+(*this=0x8059e40, op_ret=4, op_errno=1, fd=0x8091d50)
+
+2007-10-30 00:08:58 D [trace.c:1602:trace_readdir] trace: callid: 69
+(*this=0x8059e40, size=4096, offset=0 fd=0x8091d50)
+
+2007-10-30 00:08:58 D [trace.c:215:trace_readdir_cbk] trace:
+(*this=0x8059e40, op_ret=0, op_errno=0, count=4)
+
+2007-10-30 00:08:58 D [trace.c:1624:trace_closedir] trace: callid: 71
+(*this=0x8059e40, *fd=0x8091d50)
+
+2007-10-30 00:08:58 D [trace.c:809:trace_closedir_cbk] trace:
+(*this=0x8059e40, op_ret=0, op_errno=1)
+@end example
+@end cartouche
+
+@node Usage Scenarios
+@chapter Usage Scenarios
+
+@section Advanced Striping
+
+This section is based on the Advanced Striping tutorial written by
+Anand Avati on the GlusterFS wiki
+@footnote{http://gluster.org/docs/index.php/Mixing_Striped_and_Regular_Files}.
+
+@subsection Mixed Storage Requirements
+
+There are two ways of scheduling the I/O. One at file level (using
+unify translator) and other at block level (using stripe
+translator). Striped I/O is good for files that are potentially large
+and require high parallel throughput (for example, a single file of
+400GB being accessed by 100s and 1000s of systems simultaneously and
+randomly). For most of the cases, file level scheduling works best.
+
+In the real world, it is desirable to mix file level and block level
+scheduling on a single storage volume. Alternatively users can choose
+to have two separate volumes and hence two mount points, but the
+applications may demand a single storage system to host both.
+
+This document explains how to mix file level scheduling with stripe.
+
+@subsection Configuration Brief
+
+This setup demonstrates how users can configure unify translator with
+appropriate I/O scheduler for file level scheduling and strip for only
+matching patterns. This way, GlusterFS chooses appropriate I/O profile
+and knows how to efficiently handle both the types of data.
+
+A simple technique to achieve this effect is to create a stripe set of
+unify and stripe blocks, where unify is the first sub-volume. Files
+that do not match the stripe policy passed on to first unify
+sub-volume and inturn scheduled arcoss the cluster using its file
+level I/O scheduler.
+
+@image{advanced-stripe,44pc,,,.pdf}
+
+@subsection Preparing GlusterFS Envoronment
+
+Create the directories /export/namespace, /export/unify and
+/export/stripe on all the storage bricks.
+
+ Place the following server and client volume spec file under
+/etc/glusterfs (or appropriate installed path) and replace the IP
+addresses / access control fields to match your environment.
+
+@cartouche
+@example
+ ## file: /etc/glusterfs/glusterfsd.vol
+ volume posix-unify
+ type storage/posix
+ option directory /export/for-unify
+ end-volume
+
+ volume posix-stripe
+ type storage/posix
+ option directory /export/for-stripe
+ end-volume
+
+ volume posix-namespace
+ type storage/posix
+ option directory /export/for-namespace
+ end-volume
+
+ volume server
+ type protocol/server
+ option transport-type tcp
+ option auth.addr.posix-unify.allow 192.168.1.*
+ option auth.addr.posix-stripe.allow 192.168.1.*
+ option auth.addr.posix-namespace.allow 192.168.1.*
+ subvolumes posix-unify posix-stripe posix-namespace
+ end-volume
+@end example
+@end cartouche
+
+@cartouche
+@example
+ ## file: /etc/glusterfs/glusterfs.vol
+ volume client-namespace
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.1
+ option remote-subvolume posix-namespace
+ end-volume
+
+ volume client-unify-1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.1
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-unify-2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.2
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-unify-3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.3
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-unify-4
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.4
+ option remote-subvolume posix-unify
+ end-volume
+
+ volume client-stripe-1
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.1
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume client-stripe-2
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.2
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume client-stripe-3
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.3
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume client-stripe-4
+ type protocol/client
+ option transport-type tcp
+ option remote-host 192.168.1.4
+ option remote-subvolume posix-stripe
+ end-volume
+
+ volume unify
+ type cluster/unify
+ option scheduler rr
+ subvolumes cluster-unify-1 cluster-unify-2 cluster-unify-3 cluster-unify-4
+ end-volume
+
+ volume stripe
+ type cluster/stripe
+ option block-size *.img:2MB # All files ending with .img are striped with 2MB stripe block size.
+ subvolumes unify cluster-stripe-1 cluster-stripe-2 cluster-stripe-3 cluster-stripe-4
+ end-volume
+@end example
+@end cartouche
+
+
+Bring up the Storage
+
+Starting GlusterFS Server: If you have installed through binary
+package, you can start the service through init.d startup script. If
+not:
+
+@example
+[root@@server]# glusterfsd
+@end example
+
+Mounting GlusterFS Volumes:
+
+@example
+[root@@client]# glusterfs -s [BRICK-IP-ADDRESS] /mnt/cluster
+@end example
+
+Improving upon this Setup
+
+Infiniband Verbs RDMA transport is much faster than TCP/IP GigE
+transport.
+
+Use of performance translators such as read-ahead, write-behind,
+io-cache, io-threads, booster is recommended.
+
+Replace round-robin (rr) scheduler with ALU to handle more dynamic
+storage environments.
+
+@node Troubleshooting
+@chapter Troubleshooting
+
+This chapter is a general troubleshooting guide to GlusterFS. It lists
+common GlusterFS server and client error messages, debugging hints, and
+concludes with the suggested procedure to report bugs in GlusterFS.
+
+@section GlusterFS error messages
+
+@subsection Server errors
+
+@example
+glusterfsd: FATAL: could not open specfile:
+'/etc/glusterfs/glusterfsd.vol'
+@end example
+
+The GlusterFS server expects the volume specification file to be
+at @command{/etc/glusterfs/glusterfsd.vol}. The example
+specification file will be installed as
+@command{/etc/glusterfs/glusterfsd.vol.sample}. You need to edit
+it and rename it, or provide a different specification file using
+the @command{--spec-file} command line option (See @ref{Server}).
+
+@vskip 4ex
+
+@example
+gf_log_init: failed to open logfile "/usr/var/log/glusterfs/glusterfsd.log"
+ (Permission denied)
+@end example
+
+You don't have permission to create files in the
+@command{/usr/var/log/glusterfs} directory. Make sure you are running
+GlusterFS as root. Alternatively, specify a different path for the log
+file using the @command{--log-file} option (See @ref{Server}).
+
+@subsection Client errors
+
+@example
+fusermount: failed to access mountpoint /mnt:
+ Transport endpoint is not connected
+@end example
+
+A previous failed (or hung) mount of GlusterFS is preventing it from being
+mounted again in the same location. The fix is to do:
+
+@example
+# umount /mnt
+@end example
+
+and try mounting again.
+
+@vskip 4ex
+
+@strong{``Transport endpoint is not connected''.}
+
+If you get this error when you try a command such as @command{ls} or @command{cat},
+it means the GlusterFS mount did not succeed. Try running GlusterFS in @command{DEBUG}
+logging level and study the log messages to discover the cause.
+
+@vskip 4ex
+
+@strong{``Connect to server failed'', ``SERVER-ADDRESS: Connection refused''.}
+
+GluserFS Server is not running or dead. Check your network
+connections and firewall settings. To check if the server is reachable,
+try:
+
+@example
+telnet IP-ADDRESS 6996
+@end example
+
+If the server is accessible, your `telnet' command should connect and
+block. If not you will see an error message such as @command{telnet: Unable to
+connect to remote host: Connection refused}. 6996 is the default
+GlusterFS port. If you have changed it, then use the corresponding
+port instead.
+
+@vskip 4ex
+
+@example
+gf_log_init: failed to open logfile "/usr/var/log/glusterfs/glusterfs.log"
+ (Permission denied)
+@end example
+
+You don't have permission to create files in the
+@command{/usr/var/log/glusterfs} directory. Make sure you are running
+GlusterFS as root. Alternatively, specify a different path for the log
+file using the @command{--log-file} option (See @ref{Client}).
+
+@section FUSE error messages
+@command{modprobe fuse} fails with: ``Unknown symbol in module, or unknown parameter''.
+@cindex Redhat Enterprise Linux
+
+If you are using fuse-2.6.x on Redhat Enterprise Linux Work Station 4
+and Advanced Server 4 with 2.6.9-42.ELlargesmp, 2.6.9-42.ELsmp,
+2.6.9-42.EL kernels and get this error while loading @acronym{FUSE} kernel
+module, you need to apply the following patch.
+
+For fuse-2.6.2:
+
+@indicateurl{http://ftp.zresearch.com/pub/gluster/glusterfs/fuse/fuse-2.6.2-rhel-build.patch}
+
+For fuse-2.6.3:
+
+@indicateurl{http://ftp.zresearch.com/pub/gluster/glusterfs/fuse/fuse-2.6.3-rhel-build.patch}
+
+@section AppArmour and GlusterFS
+@cindex AppArmour
+@cindex OpenSuSE
+Under OpenSuSE GNU/Linux, the AppArmour security feature does not
+allow GlusterFS to create temporary files or network socket
+connections even while running as root. You will see error messages
+like `Unable to open log file: Operation not permitted' or `Connection
+refused'. Disabling AppArmour using YaST or properly configuring
+AppArmour to recognize @command{glusterfsd} or @command{glusterfs}/@command{fusermount}
+should solve the problem.
+
+@section Reporting a bug
+
+If you encounter a bug in GlusterFS, please follow the below
+guidelines when you report it to the mailing list. Be sure to report
+it! User feedback is crucial to the health of the project and we value
+it highly.
+
+@subsection General instructions
+
+When running GlusterFS in a non-production environment, be sure to
+build it with the following command:
+
+@example
+ $ make CFLAGS='-g -O0 -DDEBUG'
+@end example
+
+This includes debugging information which will be helpful in getting
+backtraces (see below) and also disable optimization. Enabling
+optimization can result in incorrect line numbers being reported to
+gdb.
+
+@subsection Volume specification files
+
+Attach all relevant server and client spec files you were using when
+you encountered the bug. Also tell us details of your setup, i.e., how
+many clients and how many servers.
+
+@subsection Log files
+
+Set the loglevel of your client and server programs to @acronym{DEBUG} (by
+passing the -L @acronym{DEBUG} option) and attach the log files with your bug
+report. Obviously, if only the client is failing (for example), you
+only need to send us the client log file.
+
+@subsection Backtrace
+
+If GlusterFS has encountered a segmentation fault or has crashed for
+some other reason, include the backtrace with the bug report. You can
+get the backtrace using the following procedure.
+
+Run the GlusterFS client or server inside gdb.
+
+@example
+ $ gdb ./glusterfs
+ (gdb) set args -f client.spec -N -l/path/to/log/file -LDEBUG /mnt/point
+ (gdb) run
+@end example
+
+Now when the process segfaults, you can get the backtrace by typing:
+
+@example
+ (gdb) bt
+@end example
+
+If the GlusterFS process has crashed and dumped a core file (you can
+find this in / if running as a daemon and in the current directory
+otherwise), you can do:
+
+@example
+ $ gdb /path/to/glusterfs /path/to/core.<pid>
+@end example
+
+and then get the backtrace.
+
+If the GlusterFS server or client seems to be hung, then you can get
+the backtrace by attaching gdb to the process. First get the @command{PID} of
+the process (using ps), and then do:
+
+@example
+ $ gdb ./glusterfs <pid>
+@end example
+
+Press Ctrl-C to interrupt the process and then generate the backtrace.
+
+@subsection Reproducing the bug
+
+If the bug is reproducible, please include the steps necessary to do
+so. If the bug is not reproducible, send us the bug report anyway.
+
+@subsection Other information
+
+If you think it is relevant, send us also the version of @acronym{FUSE} you're
+using, the kernel version, platform.
+
+@node GNU Free Documentation Licence
+@appendix GNU Free Documentation Licence
+@include fdl.texi
+
+@node Index
+@unnumbered Index
+@printindex cp
+
+@bye
diff --git a/doc/user-guide/xlator.odg b/doc/user-guide/xlator.odg
new file mode 100644
index 000000000..179a65f6e
--- /dev/null
+++ b/doc/user-guide/xlator.odg
Binary files differ
diff --git a/doc/user-guide/xlator.pdf b/doc/user-guide/xlator.pdf
new file mode 100644
index 000000000..a07e14d67
--- /dev/null
+++ b/doc/user-guide/xlator.pdf
Binary files differ
diff --git a/extras/Makefile.am b/extras/Makefile.am
new file mode 100644
index 000000000..f243a0da5
--- /dev/null
+++ b/extras/Makefile.am
@@ -0,0 +1,13 @@
+
+docdir = $(datadir)/doc/glusterfs/
+EmacsModedir = $(docdir)/
+EmacsMode_DATA = glusterfs-mode.el
+
+SUBDIRS = init.d benchmarking
+
+EXTRA_DIST = specgen.scm glusterfs.vim glusterfs-mode.el Portfile \
+ test/Makefile.am test/Makefile.in test/rdd.c \
+ benchmarking/Makefile.am benchmarking/Makefile.in
+
+CLEANFILES =
+
diff --git a/extras/Portfile b/extras/Portfile
new file mode 100644
index 000000000..4732c38ee
--- /dev/null
+++ b/extras/Portfile
@@ -0,0 +1,26 @@
+# $Id$
+
+PortSystem 1.0
+
+name glusterfs
+version 2.0.0rc1
+categories fuse
+maintainers amar@zresearch.com
+description GlusterFS
+long_description GlusterFS is a cluster file system, flexible to tune it for your needs.
+homepage http://www.gluster.org/
+platforms darwin
+master_sites http://ftp.zresearch.com/pub/gluster/glusterfs/2.0/2.0.0
+
+configure.args --disable-bdb
+checksums md5 33c2d02344d4fab422e80cfb637e0b48
+
+post-destroot {
+ file mkdir ${destroot}/Library/LaunchDaemons/
+ file copy ${worksrcpath}/extras/glusterfs-server.plist \
+ ${destroot}/Library/LaunchDaemons/com.zresearch.glusterfs.plist
+
+ file mkdir ${destroot}/sbin/
+ file copy ${worksrcpath}/xlators/mount/fuse/utils/mount_glusterfs \
+ ${destroot}/sbin/
+} \ No newline at end of file
diff --git a/extras/benchmarking/Makefile.am b/extras/benchmarking/Makefile.am
new file mode 100644
index 000000000..16f73cbaa
--- /dev/null
+++ b/extras/benchmarking/Makefile.am
@@ -0,0 +1,7 @@
+
+docdir = $(datadir)/doc/$(PACKAGE_NAME)/benchmarking
+
+EXTRA_DIST = glfs-bm.c README launch-script.sh local-script.sh
+
+CLEANFILES =
+
diff --git a/extras/benchmarking/README b/extras/benchmarking/README
new file mode 100644
index 000000000..e83dd8822
--- /dev/null
+++ b/extras/benchmarking/README
@@ -0,0 +1,18 @@
+
+--------------
+Parallel DD performance:
+
+* Copy the local-script.sh in ${mountpoint}/benchmark/ directory
+* Edit it so the blocksize and count are as per the requirements
+
+* Edit the launch-script.sh script to make sure paths, mountpoints etc are alright.
+
+* run 'lauch-script.sh'
+
+* after the run, you can get the aggregated result by adding all the 3rd entry in output.$(hostname) entries in 'output/' directory.
+
+--------------
+
+iozone:
+
+bash# iozone - +m iozone_cluster.config - t 62 - r ${block_size} - s ${file_size} - +n - i 0 - i 1 \ No newline at end of file
diff --git a/extras/benchmarking/glfs-bm.c b/extras/benchmarking/glfs-bm.c
new file mode 100644
index 000000000..f5e63ae80
--- /dev/null
+++ b/extras/benchmarking/glfs-bm.c
@@ -0,0 +1,619 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#define _GNU_SOURCE
+#define __USE_FILE_OFFSET64
+#define _FILE_OFFSET_BITS 64
+
+#include <stdio.h>
+#include <argp.h>
+#include <libglusterfsclient.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/xattr.h>
+#include <string.h>
+#include <libgen.h>
+#include <errno.h>
+#include <sys/time.h>
+
+struct state {
+ char need_op_write:1;
+ char need_op_read:1;
+
+ char need_iface_fileio:1;
+ char need_iface_xattr:1;
+
+ char need_mode_posix:1;
+ char need_mode_libglusterfsclient:1;
+
+ char prefix[512];
+ long int count;
+
+ size_t block_size;
+
+ char *specfile;
+ void *libglusterfsclient_context;
+
+ long int io_size;
+};
+
+
+#define MEASURE(func, arg) measure (func, #func, arg)
+
+
+void
+tv_difference (struct timeval *tv_stop,
+ struct timeval *tv_start,
+ struct timeval *tv_diff)
+{
+ if (tv_stop->tv_usec < tv_start->tv_usec) {
+ tv_diff->tv_usec = (tv_stop->tv_usec + 1000000) - tv_start->tv_usec;
+ tv_diff->tv_sec = (tv_stop->tv_sec - 1 - tv_start->tv_sec);
+ } else {
+ tv_diff->tv_usec = tv_stop->tv_usec - tv_start->tv_usec;
+ tv_diff->tv_sec = tv_stop->tv_sec - tv_start->tv_sec;
+ }
+}
+
+
+void
+measure (int (*func)(struct state *state),
+ char *func_name, struct state *state)
+{
+ struct timeval tv_start, tv_stop, tv_diff;
+ state->io_size = 0;
+ long int count;
+
+ gettimeofday (&tv_start, NULL);
+ count = func (state);
+ gettimeofday (&tv_stop, NULL);
+
+ tv_difference (&tv_stop, &tv_start, &tv_diff);
+
+ fprintf (stdout, "%s: count=%ld, size=%ld, time=%ld:%ld\n",
+ func_name, count, state->io_size,
+ tv_diff.tv_sec, tv_diff.tv_usec);
+}
+
+
+static error_t
+parse_opts (int key, char *arg,
+ struct argp_state *_state)
+{
+ struct state *state = _state->input;
+
+ switch (key)
+ {
+ case 'o':
+ if (strcasecmp (arg, "read") == 0) {
+ state->need_op_write = 0;
+ state->need_op_read = 1;
+ } else if (strcasecmp (arg, "write") == 0) {
+ state->need_op_write = 1;
+ state->need_op_read = 0;
+ } else if (strcasecmp (arg, "both") == 0) {
+ state->need_op_write = 1;
+ state->need_op_read = 1;
+ } else {
+ fprintf (stderr, "unknown op: %s\n", arg);
+ return -1;
+ }
+ break;
+ case 'i':
+ if (strcasecmp (arg, "fileio") == 0) {
+ state->need_iface_fileio = 1;
+ state->need_iface_xattr = 0;
+ } else if (strcasecmp (arg, "xattr") == 0) {
+ state->need_iface_fileio = 0;
+ state->need_iface_xattr = 1;
+ } else if (strcasecmp (arg, "both") == 0) {
+ state->need_iface_fileio = 1;
+ state->need_iface_xattr = 1;
+ } else {
+ fprintf (stderr, "unknown interface: %s\n", arg);
+ return -1;
+ }
+ break;
+ case 'm':
+ if (strcasecmp (arg, "posix") == 0) {
+ state->need_mode_posix = 1;
+ state->need_mode_libglusterfsclient = 0;
+ } else if (strcasecmp (arg, "libglusterfsclient") == 0) {
+ state->need_mode_posix = 0;
+ state->need_mode_libglusterfsclient = 1;
+ } else if (strcasecmp (arg, "both") == 0) {
+ state->need_mode_posix = 1;
+ state->need_mode_libglusterfsclient = 1;
+ } else {
+ fprintf (stderr, "unknown mode: %s\n", arg);
+ return -1;
+ }
+ break;
+ case 'b':
+ {
+ size_t block_size = atoi (arg);
+ if (!block_size) {
+ fprintf (stderr, "incorrect size: %s\n", arg);
+ return -1;
+ }
+ state->block_size = block_size;
+ }
+ break;
+ case 's':
+ state->specfile = strdup (arg);
+ break;
+ case 'p':
+ fprintf (stderr, "using prefix: %s\n", arg);
+ strncpy (state->prefix, arg, 512);
+ break;
+ case 'c':
+ {
+ long count = atol (arg);
+ if (!count) {
+ fprintf (stderr, "incorrect count: %s\n", arg);
+ return -1;
+ }
+ state->count = count;
+ }
+ break;
+ case ARGP_KEY_NO_ARGS:
+ break;
+ case ARGP_KEY_ARG:
+ break;
+ }
+
+ return 0;
+}
+
+int
+do_mode_posix_iface_fileio_write (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+
+ for (i=0; i<state->count; i++) {
+ int fd = -1;
+ char filename[512];
+
+ sprintf (filename, "%s.%06ld", state->prefix, i);
+
+ fd = open (filename, O_CREAT|O_WRONLY, 00600);
+ if (fd == -1) {
+ fprintf (stderr, "open(%s) => %s\n", filename, strerror (errno));
+ break;
+ }
+ ret = write (fd, block, state->block_size);
+ if (ret != state->block_size) {
+ fprintf (stderr, "write (%s) => %d/%s\n", filename, ret,
+ strerror (errno));
+ close (fd);
+ break;
+ }
+ close (fd);
+ state->io_size += ret;
+ }
+
+ return i;
+}
+
+
+int
+do_mode_posix_iface_fileio_read (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+
+ for (i=0; i<state->count; i++) {
+ int fd = -1;
+ char filename[512];
+
+ sprintf (filename, "%s.%06ld", state->prefix, i);
+
+ fd = open (filename, O_RDONLY);
+ if (fd == -1) {
+ fprintf (stderr, "open(%s) => %s\n", filename, strerror (errno));
+ break;
+ }
+ ret = read (fd, block, state->block_size);
+ if (ret == -1) {
+ fprintf (stderr, "read(%s) => %d/%s\n", filename, ret, strerror (errno));
+ close (fd);
+ break;
+ }
+ close (fd);
+ state->io_size += ret;
+ }
+
+ return i;
+}
+
+
+int
+do_mode_posix_iface_fileio (struct state *state)
+{
+ if (state->need_op_write)
+ MEASURE (do_mode_posix_iface_fileio_write, state);
+
+ if (state->need_op_read)
+ MEASURE (do_mode_posix_iface_fileio_read, state);
+
+ return 0;
+}
+
+
+int
+do_mode_posix_iface_xattr_write (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+ char *dname = NULL, *dirc = NULL;
+ char *bname = NULL, *basec = NULL;
+
+ dirc = strdup (state->prefix);
+ basec = strdup (state->prefix);
+ dname = dirname (dirc);
+ bname = basename (basec);
+
+ for (i=0; i<state->count; i++) {
+ char key[512];
+
+ sprintf (key, "glusterfs.file.%s.%06ld", bname, i);
+
+ ret = lsetxattr (dname, key, block, state->block_size, 0);
+
+ if (ret != 0) {
+ fprintf (stderr, "lsetxattr (%s, %s, %p) => %s\n",
+ dname, key, block, strerror (errno));
+ break;
+ }
+ state->io_size += state->block_size;
+ }
+
+ free (dirc);
+ free (basec);
+
+ return i;
+}
+
+
+int
+do_mode_posix_iface_xattr_read (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+ char *dname = NULL, *dirc = NULL;
+ char *bname = NULL, *basec = NULL;
+
+ dirc = strdup (state->prefix);
+ basec = strdup (state->prefix);
+ dname = dirname (dirc);
+ bname = basename (basec);
+
+ for (i=0; i<state->count; i++) {
+ char key[512];
+
+ sprintf (key, "glusterfs.file.%s.%06ld", bname, i);
+
+ ret = lgetxattr (dname, key, block, state->block_size);
+
+ if (ret < 0) {
+ fprintf (stderr, "lgetxattr (%s, %s, %p) => %s\n",
+ dname, key, block, strerror (errno));
+ break;
+ }
+ state->io_size += ret;
+ }
+
+ return i;
+}
+
+
+int
+do_mode_posix_iface_xattr (struct state *state)
+{
+ if (state->need_op_write)
+ MEASURE (do_mode_posix_iface_xattr_write, state);
+
+ if (state->need_op_read)
+ MEASURE (do_mode_posix_iface_xattr_read, state);
+
+ return 0;
+}
+
+
+int
+do_mode_libglusterfsclient_iface_fileio_write (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+
+ for (i=0; i<state->count; i++) {
+ long fd = 0;
+ char filename[512];
+
+ sprintf (filename, "/%s.%06ld", state->prefix, i);
+
+ fd = glusterfs_open (state->libglusterfsclient_context,
+ filename, O_CREAT|O_WRONLY, 0);
+
+ if (fd == 0) {
+ fprintf (stderr, "open(%s) => %s\n", filename, strerror (errno));
+ break;
+ }
+ ret = glusterfs_write (fd, block, state->block_size);
+ if (ret == -1) {
+ fprintf (stderr, "glusterfs_write(%s) => %s\n", filename, strerror (errno));
+ glusterfs_close (fd);
+ break;
+ }
+ glusterfs_close (fd);
+ state->io_size += ret;
+ }
+
+ return i;
+}
+
+
+int
+do_mode_libglusterfsclient_iface_fileio_read (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+
+ for (i=0; i<state->count; i++) {
+ long fd = 0;
+ char filename[512];
+
+ sprintf (filename, "/%s.%06ld", state->prefix, i);
+
+ fd = glusterfs_open (state->libglusterfsclient_context,
+ filename, O_RDONLY, 0);
+
+ if (fd == 0) {
+ fprintf (stderr, "glusterfs_open(%s) => %s\n", filename, strerror (errno));
+ break;
+ }
+ ret = glusterfs_read (fd, block, state->block_size);
+ if (ret == -1) {
+ fprintf (stderr, "glusterfs_read(%s) => %s\n", filename, strerror (errno));
+ glusterfs_close (fd);
+ break;
+ }
+ glusterfs_close (fd);
+ state->io_size += ret;
+ }
+
+ return i;
+}
+
+
+int
+do_mode_libglusterfsclient_iface_fileio (struct state *state)
+{
+ if (state->need_op_write)
+ MEASURE (do_mode_libglusterfsclient_iface_fileio_write, state);
+
+ if (state->need_op_read)
+ MEASURE (do_mode_libglusterfsclient_iface_fileio_read, state);
+
+ return 0;
+}
+
+
+int
+do_mode_libglusterfsclient_iface_xattr_write (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+ char *dname = NULL, *dirc = NULL;
+ char *bname = NULL, *basec = NULL;
+
+ asprintf (&dirc, "/%s", state->prefix);
+ asprintf (&basec, "/%s", state->prefix);
+ dname = dirname (dirc);
+ bname = basename (basec);
+
+ for (i=0; i<state->count; i++) {
+ char key[512];
+
+ sprintf (key, "glusterfs.file.%s.%06ld", bname, i);
+
+ ret = glusterfs_setxattr (state->libglusterfsclient_context,
+ dname, key, block, state->block_size, 0);
+
+ if (ret < 0) {
+ fprintf (stderr, "glusterfs_setxattr (%s, %s, %p) => %s\n",
+ dname, key, block, strerror (errno));
+ break;
+ }
+ state->io_size += state->block_size;
+ }
+
+ return i;
+
+}
+
+
+int
+do_mode_libglusterfsclient_iface_xattr_read (struct state *state)
+{
+ long int i;
+ int ret = -1;
+ char block[state->block_size];
+ char *dname = NULL, *dirc = NULL;
+ char *bname = NULL, *basec = NULL;
+
+ dirc = strdup (state->prefix);
+ basec = strdup (state->prefix);
+ dname = dirname (dirc);
+ bname = basename (basec);
+
+ for (i=0; i<state->count; i++) {
+ char key[512];
+
+ sprintf (key, "glusterfs.file.%s.%06ld", bname, i);
+
+ ret = glusterfs_getxattr (state->libglusterfsclient_context,
+ dname, key, block, state->block_size);
+
+ if (ret < 0) {
+ fprintf (stderr, "glusterfs_getxattr (%s, %s, %p) => %s\n",
+ dname, key, block, strerror (errno));
+ break;
+ }
+ state->io_size += ret;
+ }
+
+ return i;
+}
+
+
+int
+do_mode_libglusterfsclient_iface_xattr (struct state *state)
+{
+ if (state->need_op_write)
+ MEASURE (do_mode_libglusterfsclient_iface_xattr_write, state);
+
+ if (state->need_op_read)
+ MEASURE (do_mode_libglusterfsclient_iface_xattr_read, state);
+
+ return 0;
+}
+
+
+int
+do_mode_posix (struct state *state)
+{
+ if (state->need_iface_fileio)
+ do_mode_posix_iface_fileio (state);
+
+ if (state->need_iface_xattr)
+ do_mode_posix_iface_xattr (state);
+
+ return 0;
+}
+
+
+int
+do_mode_libglusterfsclient (struct state *state)
+{
+ glusterfs_init_ctx_t ctx = {
+ .logfile = "/dev/stderr",
+ .loglevel = "error",
+ .lookup_timeout = 60,
+ .stat_timeout = 60,
+ };
+
+ ctx.specfile = state->specfile;
+ if (state->specfile) {
+ state->libglusterfsclient_context = glusterfs_init (&ctx);
+
+ if (!state->libglusterfsclient_context) {
+ fprintf (stdout, "Unable to initialize glusterfs context, skipping libglusterfsclient mode\n");
+ return -1;
+ }
+ } else {
+ fprintf (stdout, "glusterfs volume specification file not provided, skipping libglusterfsclient mode\n");
+ return -1;
+ }
+
+ if (state->need_iface_fileio)
+ do_mode_libglusterfsclient_iface_fileio (state);
+
+ if (state->need_iface_xattr)
+ do_mode_libglusterfsclient_iface_xattr (state);
+
+ return 0;
+}
+
+
+int
+do_actions (struct state *state)
+{
+ if (state->need_mode_libglusterfsclient)
+ do_mode_libglusterfsclient (state);
+
+ if (state->need_mode_posix)
+ do_mode_posix (state);
+
+ return 0;
+}
+
+static struct argp_option options[] = {
+ {"op", 'o', "OPERATIONS", 0,
+ "WRITE|READ|BOTH - defaults to BOTH"},
+ {"iface", 'i', "INTERFACE", 0,
+ "FILEIO|XATTR|BOTH - defaults to FILEIO"},
+ {"mode", 'm', "MODE", 0,
+ "POSIX|LIBGLUSTERFSCLIENT|BOTH - defaults to POSIX"},
+ {"block", 'b', "BLOCKSIZE", 0,
+ "<NUM> - defaults to 4096"},
+ {"specfile", 's', "SPECFILE", 0,
+ "absolute path to specfile"},
+ {"prefix", 'p', "PREFIX", 0,
+ "filename prefix"},
+ {"count", 'c', "COUNT", 0,
+ "number of files"},
+ {0, 0, 0, 0, 0}
+};
+
+static struct argp argp = {
+ options,
+ parse_opts,
+ "tool",
+ "tool to benchmark small file performance"
+};
+
+int
+main (int argc, char *argv[])
+{
+ struct state state = {0, };
+
+ state.need_op_write = 1;
+ state.need_op_read = 1;
+
+ state.need_iface_fileio = 1;
+ state.need_iface_xattr = 0;
+
+ state.need_mode_posix = 1;
+ state.need_mode_libglusterfsclient = 0;
+
+ state.block_size = 4096;
+
+ strcpy (state.prefix, "tmpfile");
+ state.count = 1048576;
+
+ if (argp_parse (&argp, argc, argv, 0, 0, &state) != 0) {
+ fprintf (stderr, "argp_parse() failed\n");
+ return 1;
+ }
+
+ do_actions (&state);
+
+ return 0;
+}
diff --git a/extras/benchmarking/launch-script.sh b/extras/benchmarking/launch-script.sh
new file mode 100755
index 000000000..5d5050d41
--- /dev/null
+++ b/extras/benchmarking/launch-script.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+# This script is to launch the script in parallel across all the nodes.
+
+mount_point="/mnt/glusterfs"
+path_to_script="$mount_point}/benchmark/local-script.sh"
+
+num_hosts=8
+
+for i in $(seq 1 $num_hosts); do
+ ssh node$i path_to_script &
+done
+
+sleep 3;
+
+touch ${mount_point}/benchmark/start-test
+
+
diff --git a/extras/benchmarking/local-script.sh b/extras/benchmarking/local-script.sh
new file mode 100755
index 000000000..80a7fafe8
--- /dev/null
+++ b/extras/benchmarking/local-script.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# This script needs to be present on glusterfs mount, (ie, on every node which wants to run benchmark)
+
+ifilename="/dev/zero"
+ofilename="testdir/testfile.$(hostname)"
+result="output/output.$(hostname)"
+blocksize=128k
+count=8
+
+mkdir -p testdir;
+mkdir -p output;
+echo > ${result}
+while [ ! -e start-test ]; do
+ sleep 1;
+done;
+
+
+for i in $(seq 1 5); do
+ # write
+ dd if=${ifilename} of=${ofilename} bs=${blocksize} count=${count} 2>&1 | tail -n 1 | cut -f 8,9 -d ' ' >> ${result} ;
+ # read
+ #dd if=${ofilename} of=/dev/null bs=${blocksize} count=${count} 2>&1 | tail -n 1 | cut -f 8,9 -d ' ' >> ${result} ;
+done
+
+rm -f start-test
diff --git a/extras/glusterfs-mode.el b/extras/glusterfs-mode.el
new file mode 100644
index 000000000..e65fbf460
--- /dev/null
+++ b/extras/glusterfs-mode.el
@@ -0,0 +1,112 @@
+;;; Copyright (C) 2007, 2008 Z RESEARCH Inc. <http://www.zresearch.com>
+;;;
+;;; This program is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 2 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program; if not, write to the Free Software
+;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+;;;
+
+(defvar glusterfs-mode-hook nil)
+
+;; (defvar glusterfs-mode-map
+;; (let ((glusterfs-mode-map (make-keymap)))
+;; (define-key glusterfs-mode-map "\C-j" 'newline-and-indent)
+;; glusterfs-mode-map)
+;; "Keymap for WPDL major mode")
+
+(add-to-list 'auto-mode-alist '("\\.vol\\'" . glusterfs-mode))
+
+(defconst glusterfs-font-lock-keywords-1
+ (list
+ ; "cluster/{unify,afr,stripe}"
+ ; "performance/{io-cache,io-threads,write-behind,read-ahead,stat-prefetch}"
+ ; "protocol/{client/server}"
+ ; "features/{trash,posix-locks,fixed-id,filter}"
+ ; "stroage/posix"
+ ; "encryption/rot-13"
+ ; "debug/trace"
+ '("\\<\\(cluster/\\(unify\\|afr\\|replicate\\|stripe\\|ha\\|dht\\|distribute\\)\\|\\performance/\\(io-\\(cache\\|threads\\)\\|write-behind\\|read-ahead\\|symlink-cache\\)\\|protocol/\\(server\\|client\\)\\|features/\\(trash\\|posix-locks\\|locks\\|path-converter\\|filter\\)\\|storage/\\(posix\\|bdb\\)\\|encryption/rot-13\\|debug/trace\\)\\>" . font-lock-keyword-face))
+"Additional Keywords to highlight in GlusterFS mode.")
+
+(defconst glusterfs-font-lock-keywords-2
+ (append glusterfs-font-lock-keywords-1
+ (list
+ ; "replicate" "namespace" "scheduler" "remote-subvolume" "remote-host"
+ ; "auth.addr" "block-size" "remote-port" "listen-port" "transport-type"
+ ; "limits.min-free-disk" "directory"
+ ; TODO: add all the keys here.
+ '("\\<\\(inode-lru-limit\\|replicate\\|namespace\\|scheduler\\|username\\|password\\|allow\\|reject\\|block-size\\|listen-port\\|transport-type\\|transport-timeout\\|directory\\|page-size\\|page-count\\|aggregate-size\\|non-blocking-io\\|client-volume-filename\\|bind-address\\|self-heal\\|read-only-subvolumes\\|read-subvolume\\|thread-count\\|cache-size\\|window-size\\|force-revalidate-timeout\\|priority\\|include\\|exclude\\|remote-\\(host\\|subvolume\\|port\\)\\|auth.\\(addr\\|login\\)\\|limits.\\(min-disk-free\\|transaction-size\\|ib-verbs-\\(work-request-\\(send-\\|recv-\\(count\\|size\\)\\)\\|port\\|mtu\\|device-name\\)\\)\\)\ \\>" . font-lock-constant-face)))
+ "option keys in GlusterFS mode.")
+
+(defconst glusterfs-font-lock-keywords-3
+ (append glusterfs-font-lock-keywords-2
+ (list
+ ; "option" "volume" "end-volume" "subvolumes" "type"
+ '("\\<\\(option\ \\|volume\ \\|subvolumes\ \\|type\ \\|end-volume\\)\\>" . font-lock-builtin-face)))
+ ;'((regexp-opt (" option " "^volume " "^end-volume" "subvolumes " " type ") t) . font-lock-builtin-face))
+ "Minimal highlighting expressions for GlusterFS mode.")
+
+
+(defvar glusterfs-font-lock-keywords glusterfs-font-lock-keywords-3
+ "Default highlighting expressions for GlusterFS mode.")
+
+(defvar glusterfs-mode-syntax-table
+ (let ((glusterfs-mode-syntax-table (make-syntax-table)))
+ (modify-syntax-entry ?\# "<" glusterfs-mode-syntax-table)
+ (modify-syntax-entry ?* ". 23" glusterfs-mode-syntax-table)
+ (modify-syntax-entry ?\n ">#" glusterfs-mode-syntax-table)
+ glusterfs-mode-syntax-table)
+ "Syntax table for glusterfs-mode")
+
+;; TODO: add an indentation table
+
+(defun glusterfs-indent-line ()
+ "Indent current line as GlusterFS code"
+ (interactive)
+ (beginning-of-line)
+ (if (bobp)
+ (indent-line-to 0) ; First line is always non-indented
+ (let ((not-indented t) cur-indent)
+ (if (looking-at "^[ \t]*volume\ ")
+ (progn
+ (save-excursion
+ (forward-line -1)
+ (setq not-indented nil)
+ (setq cur-indent 0))))
+ (if (looking-at "^[ \t]*end-volume")
+ (progn
+ (save-excursion
+ (forward-line -1)
+ (setq cur-indent 0))
+ (if (< cur-indent 0) ; We can't indent past the left margin
+ (setq cur-indent 0)))
+ (save-excursion
+ (while not-indented ; Iterate backwards until we find an indentation hint
+ (progn
+ (setq cur-indent 2) ; Do the actual indenting
+ (setq not-indented nil)))))
+ (if cur-indent
+ (indent-line-to cur-indent)
+ (indent-line-to 0)))))
+
+(defun glusterfs-mode ()
+ (interactive)
+ (kill-all-local-variables)
+ ;; (use-local-map glusterfs-mode-map)
+ (set-syntax-table glusterfs-mode-syntax-table)
+ (set (make-local-variable 'indent-line-function) 'glusterfs-indent-line)
+ (set (make-local-variable 'font-lock-defaults) '(glusterfs-font-lock-keywords))
+ (setq major-mode 'glusterfs-mode)
+ (setq mode-name "GlusterFS")
+ (run-hooks 'glusterfs-mode-hook))
+
+(provide 'glusterfs-mode)
diff --git a/extras/glusterfs.vim b/extras/glusterfs.vim
new file mode 100644
index 000000000..0de6b5b2f
--- /dev/null
+++ b/extras/glusterfs.vim
@@ -0,0 +1,211 @@
+" glusterfs.vim: GNU Vim Syntax file for GlusterFS .vol specification
+" Copyright (C) 2007 Z RESEARCH, Inc. <http://www.zresearch.com>
+" This file is part of GlusterFS.
+"
+" GlusterFS is free software; you can redistribute it and/or modify
+" it under the terms of the GNU General Public License as published
+" by the Free Software Foundation; either version 3 of the License,
+" or (at your option) any later version.
+"
+" GlusterFS is distributed in the hope that it will be useful, but
+" WITHOUT ANY WARRANTY; without even the implied warranty of
+" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+" General Public License for more details.
+"
+" You should have received a copy of the GNU General Public License
+" along with this program. If not, see
+" <http://www.gnu.org/licenses/>.
+"
+" Last Modified: Wed Aug 1 00:47:10 IST 2007
+" Version: 0.8
+
+syntax clear
+syntax case match
+
+setlocal iskeyword+=-
+setlocal iskeyword+=%
+setlocal iskeyword+=.
+setlocal iskeyword+=*
+setlocal iskeyword+=:
+setlocal iskeyword+=,
+
+
+"************************************************************************
+" Initially, consider everything an error. Then start eliminating one
+" field after the other. Whatever is not eliminated (due to defined
+" properties) is an error - Multiples Values for a key
+"************************************************************************
+syn match glusterfsError /[^ ]\+/ skipwhite
+syn match glusterfsComment "#.*" contains=glusterfsTodo
+
+syn keyword glusterfsTodo contained TODO FIXME NOTE
+
+"------------------------------------------------------------------------
+" 'Type' Begin
+"------------------------------------------------------------------------
+" Handle all the 'Type' keys and values. Here, a '/' is used to separate
+" the key-value pair, they are clubbed together for convenience
+syn match glusterfsType "^\s*type\s\+" skipwhite nextgroup=glusterfsTypeKeyVal
+
+syn match glusterfsTypeKeyVal contained "\<protocol/\(client\|server\)\>"
+syn match glusterfsTypeKeyVal contained "\<cluster/\(unify\|afr\|stripe\)\>"
+syn match glusterfsTypeKeyVal contained "\<debug/\(trace\)\>"
+syn match glusterfsTypeKeyVal contained "\<encryption/\(rot-13\)\>"
+syn match glusterfsTypeKeyVal contained "\<storage/\(posix\)\>"
+"syn match glusterfsTypeKeyVal contained "\<features/\(trash\)\>"
+syn match glusterfsTypeKeyVal contained "\<features/\(trash\|posix-locks\|fixed-id\|filter\)\>"
+syn match glusterfsTypeKeyVal contained "\<performance/\(io-threads\|write-behind\|io-cache\|read-ahead\)\>"
+"------------------------------------------------------------------------
+" 'Type' End
+"------------------------------------------------------------------------
+
+
+"************************************************************************
+
+"------------------------------------------------------------------------
+" 'Volume' Begin
+"------------------------------------------------------------------------
+" NOTE 1: Only one volume name allowed after 'volume' keyword
+" NOTE 2: Multiple volumes allowed after 'subvolumes'
+" NOTE 3: Some other options (like remote-subvolume, namespace etc) use
+" volume name (single)
+syn match glusterfsVol "^\s*volume\s\+" nextgroup=glusterfsVolName
+syn match glusterfsVolName "\<\k\+" contained
+
+syn match glusterfsVol "^\s*subvolumes\s\+" skipwhite nextgroup=glusterfsSubVolName
+syn match glusterfsSubVolName "\<\k\+\>" skipwhite contained nextgroup=glusterfsSubVolName
+
+syn match glusterfsVol "^\s*end-volume\>"
+"------------------------------------------------------------------------
+" 'Volume' End
+"------------------------------------------------------------------------
+
+
+
+
+
+"------------------------------------------------------------------------
+" 'Options' Begin
+"------------------------------------------------------------------------
+syn match glusterfsOpt "^\s*option\s\+" nextgroup=glusterfsOptKey
+
+
+syn keyword glusterfsOptKey contained transport-type skipwhite nextgroup=glusterfsOptValTransportType
+syn match glusterfsOptValTransportType contained "\<\(tcp\|ib\-verbs\|ib-sdp\)/\(client\|server\)\>"
+
+syn keyword glusterfsOptKey contained remote-subvolume skipwhite nextgroup=glusterfsVolName
+
+syn keyword glusterfsOptKey contained auth.addr.ra8.allow auth.addr.ra7.allow auth.addr.ra6.allow auth.addr.ra5.allow auth.addr.ra4.allow auth.addr.ra3.allow auth.addr.ra2.allow auth.addr.ra1.allow auth.addr.brick-ns.allow skipwhite nextgroup=glusterfsOptVal
+
+syn keyword glusterfsOptKey contained client-volume-filename directory trash-dir skipwhite nextgroup=glusterfsOpt_Path
+syn match glusterfsOpt_Path contained "\s\+\f\+\>"
+
+syn keyword glusterfsOptKey contained debug self-heal encrypt-write decrypt-read mandatory nextgroup=glusterfsOpt_OnOff
+syn match glusterfsOpt_OnOff contained "\s\+\(on\|off\)\>"
+
+syn keyword glusterfsOptKey contained flush-behind non-blocking-connect nextgroup=glusterfsOpt_OnOffNoYes
+syn keyword glusterfsOpt_OnOffNoYes contained on off no yes
+
+syn keyword glusterfsOptKey contained page-size cache-size nextgroup=glusterfsOpt_Size
+
+syn keyword glusterfsOptKey contained fixed-gid fixed-uid cache-seconds page-count thread-count aggregate-size listen-port remote-port transport-timeout inode-lru-limit nextgroup=glusterfsOpt_Number
+
+syn keyword glusterfsOptKey contained alu.disk-usage.entry-threshold alu.disk-usage.exit-threshold nextgroup=glusterfsOpt_Size
+
+syn keyword glusterfsOptKey contained alu.order skipwhite nextgroup=glusterfsOptValAluOrder
+syn match glusterfsOptValAluOrder contained "\s\+\(\(disk-usage\|write-usage\|read-usage\|open-files-usage\|disk-speed\):\)*\(disk-usage\|write-usage\|read-usage\|open-files-usage\|disk-speed\)\>"
+
+syn keyword glusterfsOptKey contained alu.open-files-usage.entry-threshold alu.open-files-usage.exit-threshold alu.limits.max-open-files rr.refresh-interval random.refresh-interval nufa.refresh-interval nextgroup=glusterfsOpt_Number
+
+syn keyword glusterfsOptKey contained nufa.local-volume-name skipwhite nextgroup=glusterfsVolName
+
+syn keyword glusterfsOptKey contained ib-verbs-work-request-send-size ib-verbs-work-request-recv-size nextgroup=glusterfsOpt_Size
+syn match glusterfsOpt_Size contained "\s\+\d\+\([gGmMkK][bB]\)\=\>"
+
+syn keyword glusterfsOptKey contained ib-verbs-work-request-send-count ib-verbs-work-request-recv-count ib-verbs-port nextgroup=glusterfsOpt_Number
+
+syn keyword glusterfsOptKey contained ib-verbs-mtu nextgroup=glusterfsOptValIBVerbsMtu
+syn match glusterfsOptValIBVerbsMtu "\s\+\(256\|512\|1024\|2048\|4096\)\>" contained
+
+syn keyword glusterfsOptKey contained ib-verbs-device-name nextgroup=glusterfsOptVal
+
+syn match glusterfsOpt_Number contained "\s\+\d\+\>"
+
+syn keyword glusterfsOptKey contained scheduler skipwhite nextgroup=glusterfsOptValScheduler
+syn keyword glusterfsOptValScheduler contained rr alu random nufa
+
+syn keyword glusterfsOptKey contained namespace skipwhite nextgroup=glusterfsVolName
+
+syn keyword glusterfsOptKey contained lock-node skipwhite nextgroup=glusterfsVolName
+
+
+
+syn keyword glusterfsOptKey contained alu.write-usage.entry-threshold alu.write-usage.exit-threshold alu.read-usage.entry-threshold alu.read-usage.exit-threshold alu.limits.min-free-disk nextgroup=glusterfsOpt_Percentage
+
+syn keyword glusterfsOptKey contained random.limits.min-free-disk nextgroup=glusterfsOpt_Percentage
+syn keyword glusterfsOptKey contained rr.limits.min-disk-free nextgroup=glusterfsOpt_Size
+
+syn keyword glusterfsOptKey contained nufa.limits.min-free-disk nextgroup=glusterfsOpt_Percentage
+
+syn match glusterfsOpt_Percentage contained "\s\+\d\+%\=\>"
+
+
+
+
+
+
+
+
+
+syn keyword glusterfsOptKey contained remote-host bind-address nextgroup=glusterfsOpt_IP,glusterfsOpt_Domain
+syn match glusterfsOpt_IP contained "\s\+\d\d\=\d\=\.\d\d\=\d\=\.\d\d\=\d\=\.\d\d\=\d\=\>"
+syn match glusterfsOpt_Domain contained "\s\+\a[a-zA-Z0-9_-]*\(\.\a\+\)*\>"
+
+syn match glusterfsVolNames "\s*\<\S\+\>" contained skipwhite nextgroup=glusterfsVolNames
+
+syn keyword glusterfsOptKey contained block-size replicate skipwhite nextgroup=glusterfsOpt_Pattern
+
+syn match glusterfsOpt_Pattern contained "\s\+\k\+\>"
+syn match glusterfsOptVal contained "\s\+\S\+\>"
+
+
+
+
+
+hi link glusterfsError Error
+hi link glusterfsComment Comment
+
+hi link glusterfsVol keyword
+
+hi link glusterfsVolName function
+hi link glusterfsSubVolName function
+
+hi link glusterfsType Keyword
+hi link glusterfsTypeKeyVal String
+
+hi link glusterfsOpt Keyword
+
+hi link glusterfsOptKey Special
+hi link glusterfsOptVal Normal
+
+hi link glusterfsOptValTransportType String
+hi link glusterfsOptValScheduler String
+hi link glusterfsOptValAluOrder String
+hi link glusterfsOptValIBVerbsMtu String
+
+hi link glusterfsOpt_OnOff String
+hi link glusterfsOpt_OnOffNoYes String
+
+
+" Options that require
+hi link glusterfsOpt_Size PreProc
+hi link glusterfsOpt_Domain PreProc
+hi link glusterfsOpt_Percentage PreProc
+hi link glusterfsOpt_IP PreProc
+hi link glusterfsOpt_Pattern PreProc
+hi link glusterfsOpt_Number Preproc
+hi link glusterfsOpt_Path Preproc
+
+
+
+let b:current_syntax = "glusterfs"
diff --git a/extras/init.d/Makefile.am b/extras/init.d/Makefile.am
new file mode 100644
index 000000000..608b5bb2d
--- /dev/null
+++ b/extras/init.d/Makefile.am
@@ -0,0 +1,9 @@
+
+EXTRA_DIST = glusterfsd glusterfs-server glusterfs-server.plist
+
+CLEANFILES =
+
+install-data-am:
+if GF_DARWIN_HOST_OS
+ cp glusterfs-server.plist /Library/LaunchDaemons/com.zresearch.glusterfs.plist
+endif
diff --git a/extras/init.d/glusterfs-server b/extras/init.d/glusterfs-server
new file mode 100755
index 000000000..975283982
--- /dev/null
+++ b/extras/init.d/glusterfs-server
@@ -0,0 +1,100 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: glusterfsd
+# Required-Start: $local_fs $network
+# Required-Stop: $local_fs $network
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: gluster server
+# Description: This file starts / stops the gluster server
+### END INIT INFO
+
+# Author: Chris AtLee <chris@atlee.ca>
+# Patched by: Matthias Albert < matthias@linux4experts.de>
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+NAME=glusterfsd
+SCRIPTNAME=/etc/init.d/$NAME
+DAEMON=/usr/sbin/$NAME
+PIDFILE=/var/run/$NAME.pid
+CONFIGFILE=/etc/glusterfs/server.vol
+GLUSTERFS_OPTS="-f $CONFIGFILE"
+PID=`test -f $PIDFILE && cat $PIDFILE`
+
+
+# Gracefully exit if the package has been removed.
+test -x $DAEMON || exit 0
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+. /lib/lsb/init-functions
+
+check_config()
+{
+ if [ ! -f "$CONFIGFILE" ]; then
+ echo "Config file $CONFIGFILE is missing...exiting!"
+ exit 0
+ fi
+}
+
+do_start()
+{
+ check_config;
+ pidofproc -p $PIDFILE $DAEMON >/dev/null
+ status=$?
+ if [ $status -eq 0 ]; then
+ log_success_msg "glusterfs server is already running with pid $PID"
+ else
+ log_daemon_msg "Starting glusterfs server" "glusterfsd"
+ start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $GLUSTERFS_OPTS
+ log_end_msg $?
+ start_daemon -p $PIDFILE $DAEMON -f $CONFIGFILE
+ return $?
+ fi
+}
+
+do_stop()
+{
+ log_daemon_msg "Stopping glusterfs server" "glusterfsd"
+ start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
+ log_end_msg $?
+ rm -f $PIDFILE
+ killproc -p $PIDFILE $DAEMON
+ return $?
+}
+
+do_status()
+{
+ pidofproc -p $PIDFILE $DAEMON >/dev/null
+ status=$?
+ if [ $status -eq 0 ]; then
+ log_success_msg "glusterfs server is running with pid $PID"
+ else
+ log_failure_msg "glusterfs server is not running."
+ fi
+ exit $status
+}
+
+case "$1" in
+ start)
+ do_start
+ ;;
+ stop)
+ do_stop
+ ;;
+ status)
+ do_status;
+ ;;
+ restart|force-reload)
+ do_stop
+ sleep 2
+ do_start
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
diff --git a/extras/init.d/glusterfs-server.plist.in b/extras/init.d/glusterfs-server.plist.in
new file mode 100644
index 000000000..4d2287c57
--- /dev/null
+++ b/extras/init.d/glusterfs-server.plist.in
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Label</key>
+ <string>com.zresearch.glusterfs</string>
+ <key>ProgramArguments</key>
+ <array>
+ <string>@prefix@/sbin/glusterfsd</string>
+ <string>-N</string>
+ <string>-f</string>
+ <string>@prefix@/etc/glusterfs/server.vol</string>
+ </array>
+</dict>
+</plist>
diff --git a/extras/init.d/glusterfsd b/extras/init.d/glusterfsd
new file mode 100755
index 000000000..866a0010e
--- /dev/null
+++ b/extras/init.d/glusterfsd
@@ -0,0 +1,110 @@
+#!/bin/bash
+#
+# chkconfig: 35 90 12
+# description: Glusterfsd server
+#
+
+# Get function from functions library
+# . /etc/rc.d/init.d/functions
+
+BASE=glusterfsd
+GSERVER="/sbin/$BASE -f /etc/glusterfs/glusterfs-server.vol"
+
+# A function to stop gluster
+killgluster()
+{
+ killlevel="-9"
+ # Find pid.
+ pid=
+ if [ -f /var/run/$BASE.pid ]; then
+ local line p
+ read line < /var/run/$BASE.pid
+ for p in $line ; do
+ [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid
+$p"
+ done
+ fi
+ if [ -z "$pid" ]; then
+ pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \
+ pidof -o $$ -o $PPID -o %PPID -x $BASE`
+ fi
+ # Kill it.
+ kill $killlevel $pid
+ if [ "$?" = 0 ]
+ then
+ echo "Gluster process $pid has been killed"
+ initlog -n "Kill gluster" -e 1
+ else
+ echo "Failed: Gluster process $pid has not been killed"
+ initlog -n "Kill gluster" -e 2
+ fi
+
+ # Remove pid and lock file if any.
+ if [ -f /var/run/$BASE.pid ]
+ then
+ rm -f /var/run/$BASE.pid && initlog -n "Remove $BASE.pid:" -e
+1
+ else echo "$BASE.pid not found" && initlog -n "Remove
+$BASE.pid:" -e 2
+ fi
+
+ if [ -f /var/lock/subsys/$BASE ]
+ then
+ rm -f /var/lock/subsys/$BASE && initlog -n "Remove $BASE lock
+file:" -e 1
+ else echo "$BASE lock file not found" && initlog -n "Remove
+$BASE lock file:" -e 2
+ fi
+}
+
+# Start the service $BASE
+start()
+{
+ initlog -c "echo -n Starting $BASE:"
+ $GSERVER
+ if [ $? = 0 ]
+ then
+ touch /var/lock/subsys/$BASE
+ initlog -n "Starting $BASE" -e 1
+ echo " [OK]"
+ else
+ echo "$BASE start failed."
+ initlog -n "$BASE start" -e 2
+ fi
+}
+
+# Stop the service $BASE
+stop()
+{
+ echo "Stopping $BASE:"
+ killgluster
+}
+status()
+{
+ if test "`lsof |grep -c /sbin/$BASE`" = "0"
+ then echo "$BASE is stopped."
+ else echo "$BASE is running..."
+ fi
+}
+
+### service arguments ###
+case $1 in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ status)
+ status
+ ;;
+ restart|reload|condrestart)
+ stop
+ start
+ ;;
+ *)
+ echo $.Usage: $0 {start|stop|restart|reload|status}.
+ exit 1
+esac
+
+exit 0
diff --git a/extras/specgen.scm b/extras/specgen.scm
new file mode 100755
index 000000000..279afe896
--- /dev/null
+++ b/extras/specgen.scm
@@ -0,0 +1,98 @@
+#!/usr/bin/guile -s
+!#
+
+;;; Copyright (C) 2007 Z RESEARCH Inc. <http://www.zresearch.com>
+;;;
+;;; This program is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 2 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program; if not, write to the Free Software
+;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+;;;
+
+;;; This script lets you specify the xlator graph as a Scheme list
+;;; and provides a function to generate the spec file for the graph.
+
+
+(define (volume args)
+ (apply
+ (lambda (name type options)
+ (lambda args
+ (display "volume ") (display name) (newline)
+ (display " type ") (display type) (newline)
+ (map (lambda (key-value-cons)
+ (let ((key (car key-value-cons))
+ (value (cdr key-value-cons)))
+ (display " option ") (display key) (display " ")
+ (display value) (newline)))
+ options)
+ (if (> (length args) 0)
+ (begin
+ (display " subvolumes ")
+ (map (lambda (subvol)
+ (display subvol) (display " "))
+ args)
+ (newline)))
+ (display "end-volume") (newline) (newline)
+ name))
+ args))
+
+;; define volumes with names/type/options and bind to a symbol
+;; relate them seperately (see below)
+;; more convinient to seperate volume definition and relation
+
+(define wb (volume '(wb0
+ performance/write-behind
+ ((aggregate-size . 0)
+ (flush-behind . off)
+ ))))
+
+(define ra (volume '(ra0
+ performance/read-ahead
+ ((page-size . 128KB)
+ (page-count . 1)
+ ))))
+
+(define ioc (volume '(ioc0
+ performance/io-cache
+ ((page-size . 128KB)
+ (cache-size . 64MB)
+ ))))
+
+(define iot (volume '(iot0
+ performance/io-threads
+ ()
+ )))
+
+(define client1 (volume '(client1
+ protocol/client
+ ((transport-type . tcp/client)
+ (remote-host . localhost)
+ (remote-subvolume . brick1)
+ ))))
+
+(define client2 (volume '(client2
+ protocol/client
+ ((transport-type . tcp/client)
+ (remote-host . localhost)
+ (remote-subvolume . brick2)
+ ))))
+
+(define unify (volume '(unify0
+ cluster/unify
+ ((scheduler . rr)
+ ))))
+
+;; relate the symbols to output a spec file
+;; note: relating with symbols lets you change volume name in one place
+
+(wb (ra (ioc (iot (unify (client1)
+ (client2))))))
diff --git a/extras/stripe-merge.c b/extras/stripe-merge.c
new file mode 100644
index 000000000..3f8e4b124
--- /dev/null
+++ b/extras/stripe-merge.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+int
+main (int argc, char *argv[])
+{
+ int fds[argc-1];
+ char buf[argc-1][4096];
+ int i;
+ int max_ret, ret;
+
+ if (argc < 2) {
+ printf ("Usage: %s file1 file2 ... >file\n", argv[0]);
+ return 1;
+ }
+
+ for (i=0; i<argc-1; i++) {
+ fds[i] = open (argv[i+1], O_RDONLY);
+ if (fds[i] == -1) {
+ perror (argv[i+1]);
+ return 1;
+ }
+ }
+
+ max_ret = 0;
+ do {
+ char newbuf[4096] = {0, };
+ int j;
+
+ max_ret = 0;
+ for (i=0; i<argc-1; i++) {
+ memset (buf[i], 0, 4096);
+ ret = read (fds[i], buf[i], 4096);
+ if (ret > max_ret)
+ max_ret = ret;
+ }
+ for (i=0; i<max_ret;i++)
+ for (j=0; j<argc-1; j++)
+ newbuf[i] |= buf[j][i];
+ write (1, newbuf, max_ret);
+ } while (max_ret);
+
+ return 0;
+}
+
diff --git a/extras/test/Makefile.am b/extras/test/Makefile.am
new file mode 100644
index 000000000..e68770549
--- /dev/null
+++ b/extras/test/Makefile.am
@@ -0,0 +1,3 @@
+bin_PROGRAMS = rdd
+rdd_SOURCES = rdd.c
+AM_CFLAGS = -pthread
diff --git a/extras/test/rdd.c b/extras/test/rdd.c
new file mode 100644
index 000000000..3636c636d
--- /dev/null
+++ b/extras/test/rdd.c
@@ -0,0 +1,457 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <argp.h>
+
+#define TWO_POWER(power) (2UL << (power))
+
+#define RDD_INTEGER_VALUE ((TWO_POWER ((sizeof (int) * 8))) - 1)
+
+#ifndef UNIX_PATH_MAX
+#define UNIX_PATH_MAX 108
+#endif
+
+struct rdd_file {
+ char path[UNIX_PATH_MAX];
+ struct stat st;
+ int fd;
+};
+
+struct rdd_config {
+ long iters;
+ long max_ops_per_seq;
+ size_t max_bs;
+ size_t min_bs;
+ int thread_count;
+ pthread_t *threads;
+ pthread_barrier_t barrier;
+ pthread_mutex_t lock;
+ struct rdd_file in_file;
+ struct rdd_file out_file;
+};
+static struct rdd_config rdd_config;
+
+enum rdd_keys {
+ RDD_MIN_BS_KEY = 1,
+ RDD_MAX_BS_KEY,
+};
+
+static error_t
+rdd_parse_opts (int key, char *arg,
+ struct argp_state *_state)
+{
+ switch (key) {
+ case 'o':
+ {
+ int len = 0;
+ len = strlen (arg);
+ if (len > UNIX_PATH_MAX) {
+ fprintf (stderr, "output file name too long (%s)\n", arg);
+ return -1;
+ }
+
+ strncpy (rdd_config.out_file.path, arg, len);
+ }
+ break;
+
+ case 'i':
+ {
+ int len = 0;
+ len = strlen (arg);
+ if (len > UNIX_PATH_MAX) {
+ fprintf (stderr, "input file name too long (%s)\n", arg);
+ return -1;
+ }
+
+ strncpy (rdd_config.in_file.path, arg, len);
+ }
+ break;
+
+ case RDD_MIN_BS_KEY:
+ {
+ char *tmp = NULL;
+ long bs = 0;
+ bs = strtol (arg, &tmp, 10);
+ if ((bs == LONG_MAX) || (bs == LONG_MIN) || (tmp && *tmp)) {
+ fprintf (stderr, "invalid argument for minimum block size (%s)\n", arg);
+ return -1;
+ }
+
+ rdd_config.min_bs = bs;
+ }
+ break;
+
+ case RDD_MAX_BS_KEY:
+ {
+ char *tmp = NULL;
+ long bs = 0;
+ bs = strtol (arg, &tmp, 10);
+ if ((bs == LONG_MAX) || (bs == LONG_MIN) || (tmp && *tmp)) {
+ fprintf (stderr, "invalid argument for maximum block size (%s)\n", arg);
+ return -1;
+ }
+
+ rdd_config.max_bs = bs;
+ }
+ break;
+
+ case 'r':
+ {
+ char *tmp = NULL;
+ long iters = 0;
+ iters = strtol (arg, &tmp, 10);
+ if ((iters == LONG_MAX) || (iters == LONG_MIN) || (tmp && *tmp)) {
+ fprintf (stderr, "invalid argument for iterations (%s)\n", arg);
+ return -1;
+ }
+
+ rdd_config.iters = iters;
+ }
+ break;
+
+ case 'm':
+ {
+ char *tmp = NULL;
+ long max_ops = 0;
+ max_ops = strtol (arg, &tmp, 10);
+ if ((max_ops == LONG_MAX) || (max_ops == LONG_MIN) || (tmp && *tmp)) {
+ fprintf (stderr, "invalid argument for max-ops (%s)\n", arg);
+ return -1;
+ }
+
+ rdd_config.max_ops_per_seq = max_ops;
+ }
+ break;
+
+ case 't':
+ {
+ char *tmp = NULL;
+ long threads = 0;
+ threads = strtol (arg, &tmp, 10);
+ if ((threads == LONG_MAX) || (threads == LONG_MIN) || (tmp && *tmp)) {
+ fprintf (stderr, "invalid argument for thread count (%s)\n", arg);
+ return -1;
+ }
+
+ rdd_config.thread_count = threads;
+ }
+ break;
+
+ case ARGP_KEY_NO_ARGS:
+ break;
+ case ARGP_KEY_ARG:
+ break;
+ case ARGP_KEY_END:
+ if (_state->argc == 1) {
+ argp_usage (_state);
+ }
+
+ }
+
+ return 0;
+}
+
+static struct argp_option rdd_options[] = {
+ {"if", 'i', "INPUT_FILE", 0, "input-file"},
+ {"of", 'o', "OUTPUT_FILE", 0, "output-file"},
+ {"threads", 't', "COUNT", 0, "number of threads to spawn (defaults to 2)"},
+ {"min-bs", RDD_MIN_BS_KEY, "MIN_BLOCK_SIZE", 0,
+ "Minimum block size in bytes (defaults to 1024)"},
+ {"max-bs", RDD_MAX_BS_KEY, "MAX_BLOCK_SIZE", 0,
+ "Maximum block size in bytes (defaults to 4096)"},
+ {"iters", 'r', "ITERS", 0,
+ "Number of read-write sequences (defaults to 1000000)"},
+ {"max-ops", 'm', "MAXOPS", 0,
+ "maximum number of read-writes to be performed in a sequence (defaults to 1)"},
+ {0, 0, 0, 0, 0}
+};
+
+static struct argp argp = {
+ rdd_options,
+ rdd_parse_opts,
+ "",
+ "random dd - tool to do a sequence of random block-sized continuous read writes starting at a random offset"
+};
+
+
+static void
+rdd_default_config (void)
+{
+ rdd_config.thread_count = 2;
+ rdd_config.iters = 1000000;
+ rdd_config.max_bs = 4096;
+ rdd_config.min_bs = 1024;
+ rdd_config.in_file.fd = rdd_config.out_file.fd = -1;
+ rdd_config.max_ops_per_seq = 1;
+
+ return;
+}
+
+
+static char
+rdd_valid_config (void)
+{
+ char ret = 1;
+ int fd = -1;
+
+ fd = open (rdd_config.in_file.path, O_RDONLY);
+ if (fd == -1) {
+ ret = 0;
+ goto out;
+ }
+ close (fd);
+
+ if (rdd_config.min_bs > rdd_config.max_bs) {
+ ret = 0;
+ goto out;
+ }
+
+ if (strlen (rdd_config.out_file.path) == 0) {
+ sprintf (rdd_config.out_file.path, "%s.rddout", rdd_config.in_file.path);
+ }
+
+out:
+ return ret;
+}
+
+
+static void *
+rdd_read_write (void *arg)
+{
+ int i = 0, ret = 0;
+ size_t bs = 0;
+ off_t offset = 0;
+ long rand = 0;
+ long max_ops = 0;
+ char *buf = NULL;
+
+ buf = CALLOC (1, rdd_config.max_bs);
+ if (!buf) {
+ fprintf (stderr, "calloc failed (%s)\n", strerror (errno));
+ ret = -1;
+ goto out;
+ }
+
+ for (i = 0; i < rdd_config.iters; i++)
+ {
+ pthread_mutex_lock (&rdd_config.lock);
+ {
+ int bytes = 0;
+ rand = random ();
+
+ if (rdd_config.min_bs == rdd_config.max_bs) {
+ bs = rdd_config.max_bs;
+ } else {
+ bs = rdd_config.min_bs + (rand % (rdd_config.max_bs - rdd_config.min_bs));
+ }
+
+ offset = rand % rdd_config.in_file.st.st_size;
+ max_ops = rand % rdd_config.max_ops_per_seq;
+ if (!max_ops) {
+ max_ops ++;
+ }
+
+ ret = lseek (rdd_config.in_file.fd, offset, SEEK_SET);
+ if (ret != offset) {
+ fprintf (stderr, "lseek failed (%s)\n", strerror (errno));
+ ret = -1;
+ goto unlock;
+ }
+
+ ret = lseek (rdd_config.out_file.fd, offset, SEEK_SET);
+ if (ret != offset) {
+ fprintf (stderr, "lseek failed (%s)\n", strerror (errno));
+ ret = -1;
+ goto unlock;
+ }
+
+ while (max_ops--)
+ {
+ bytes = read (rdd_config.in_file.fd, buf, bs);
+ if (!bytes) {
+ break;
+ }
+
+ if (bytes == -1) {
+ fprintf (stderr, "read failed (%s)\n", strerror (errno));
+ ret = -1;
+ goto unlock;
+ }
+
+ if (write (rdd_config.out_file.fd, buf, bytes) != bytes) {
+ fprintf (stderr, "write failed (%s)\n", strerror (errno));
+ ret = -1;
+ goto unlock;
+ }
+ }
+ }
+ unlock:
+ pthread_mutex_unlock (&rdd_config.lock);
+ if (ret == -1) {
+ goto out;
+ }
+ ret = 0;
+ }
+out:
+ free (buf);
+ pthread_barrier_wait (&rdd_config.barrier);
+
+ return NULL;
+}
+
+
+static int
+rdd_spawn_threads (void)
+{
+ int i = 0, ret = -1, fd = -1;
+ char buf[4096];
+
+ fd = open (rdd_config.in_file.path, O_RDONLY);
+ if (fd < 0) {
+ fprintf (stderr, "cannot open %s (%s)\n", rdd_config.in_file.path, strerror (errno));
+ ret = -1;
+ goto out;
+ }
+ ret = fstat (fd, &rdd_config.in_file.st);
+ if (ret != 0) {
+ close (fd);
+ fprintf (stderr, "cannot stat %s (%s)\n", rdd_config.in_file.path, strerror (errno));
+ ret = -1;
+ goto out;
+ }
+ rdd_config.in_file.fd = fd;
+
+ fd = open (rdd_config.out_file.path, O_WRONLY | O_CREAT, S_IRWXU | S_IROTH);
+ if (fd < 0) {
+ close (rdd_config.in_file.fd);
+ rdd_config.in_file.fd = -1;
+ fprintf (stderr, "cannot open %s (%s)\n", rdd_config.out_file.path, strerror (errno));
+ ret = -1;
+ goto out;
+ }
+ rdd_config.out_file.fd = fd;
+
+ while ((ret = read (rdd_config.in_file.fd, buf, 4096)) > 0) {
+ if (write (rdd_config.out_file.fd, buf, ret) != ret) {
+ fprintf (stderr, "write failed (%s)\n", strerror (errno));
+ close (rdd_config.in_file.fd);
+ close (rdd_config.out_file.fd);
+ rdd_config.in_file.fd = rdd_config.out_file.fd = -1;
+ ret = -1;
+ goto out;
+ }
+ }
+
+ rdd_config.threads = CALLOC (rdd_config.thread_count, sizeof (pthread_t));
+ if (rdd_config.threads == NULL) {
+ fprintf (stderr, "calloc() failed (%s)\n", strerror (errno));
+
+ ret = -1;
+ close (rdd_config.in_file.fd);
+ close (rdd_config.out_file.fd);
+ rdd_config.in_file.fd = rdd_config.out_file.fd = -1;
+ goto out;
+ }
+
+ ret = pthread_barrier_init (&rdd_config.barrier, NULL, rdd_config.thread_count + 1);
+ if (ret != 0) {
+ fprintf (stderr, "pthread_barrier_init() failed (%s)\n", strerror (ret));
+
+ free (rdd_config.threads);
+ close (rdd_config.in_file.fd);
+ close (rdd_config.out_file.fd);
+ rdd_config.in_file.fd = rdd_config.out_file.fd = -1;
+ ret = -1;
+ goto out;
+ }
+
+ ret = pthread_mutex_init (&rdd_config.lock, NULL);
+ if (ret != 0) {
+ fprintf (stderr, "pthread_mutex_init() failed (%s)\n", strerror (ret));
+
+ free (rdd_config.threads);
+ pthread_barrier_destroy (&rdd_config.barrier);
+ close (rdd_config.in_file.fd);
+ close (rdd_config.out_file.fd);
+ rdd_config.in_file.fd = rdd_config.out_file.fd = -1;
+ ret = -1;
+ goto out;
+ }
+
+ for (i = 0; i < rdd_config.thread_count; i++)
+ {
+ ret = pthread_create (&rdd_config.threads[i], NULL, rdd_read_write, NULL);
+ if (ret != 0) {
+ fprintf (stderr, "pthread_create failed (%s)\n", strerror (errno));
+ exit (1);
+ }
+ }
+
+out:
+ return ret;
+}
+
+
+static void
+rdd_wait_for_completion (void)
+{
+ pthread_barrier_wait (&rdd_config.barrier);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ int ret = -1;
+
+ rdd_default_config ();
+
+ ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
+ if (ret != 0) {
+ ret = -1;
+ fprintf (stderr, "%s: argp_parse() failed\n", argv[0]);
+ goto err;
+ }
+
+ if (!rdd_valid_config ()) {
+ ret = -1;
+ fprintf (stderr, "%s: configuration validation failed\n", argv[0]);
+ goto err;
+ }
+
+ ret = rdd_spawn_threads ();
+ if (ret != 0) {
+ fprintf (stderr, "%s: spawning threads failed\n", argv[0]);
+ goto err;
+ }
+
+ rdd_wait_for_completion ();
+
+err:
+ return ret;
+}
diff --git a/glusterfs-guts/Makefile.am b/glusterfs-guts/Makefile.am
new file mode 100644
index 000000000..f963effea
--- /dev/null
+++ b/glusterfs-guts/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = src \ No newline at end of file
diff --git a/glusterfs-guts/src/Makefile.am b/glusterfs-guts/src/Makefile.am
new file mode 100644
index 000000000..bb8c7b176
--- /dev/null
+++ b/glusterfs-guts/src/Makefile.am
@@ -0,0 +1,17 @@
+sbin_PROGRAMS = glusterfs-guts
+
+glusterfs_guts_SOURCES = glusterfs-guts.c fuse-bridge.c guts-replay.c guts-trace.c \
+ fuse-extra.c guts-extra.c guts-parse.c guts-tables.c
+
+noinst_HEADERS = fuse_kernel.h fuse-extra.h glusterfs-guts.h glusterfs-fuse.h guts-lowlevel.h \
+ guts-parse.h guts-replay.h guts-tables.h guts-trace.h
+
+glusterfs_guts_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la -lfuse
+
+AM_CFLAGS = -fPIC -Wall -pthread
+
+AM_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -DFUSE_USE_VERSION=26 \
+ -I$(top_srcdir)/libglusterfs/src -DDATADIR=\"$(localstatedir)\" \
+ -DCONFDIR=\"$(sysconfdir)/glusterfs\"
+
+CLEANFILES =
diff --git a/glusterfs-guts/src/fuse-bridge.c b/glusterfs-guts/src/fuse-bridge.c
new file mode 100644
index 000000000..0972563c6
--- /dev/null
+++ b/glusterfs-guts/src/fuse-bridge.c
@@ -0,0 +1,2724 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <stdint.h>
+#include <signal.h>
+#include <pthread.h>
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif /* _CONFIG_H */
+
+#include "glusterfs.h"
+#include "logging.h"
+#include "xlator.h"
+#include "glusterfs.h"
+#include "transport.h"
+#include "defaults.h"
+#include "common-utils.h"
+
+#include <fuse/fuse_lowlevel.h>
+
+#include "fuse-extra.h"
+#include "list.h"
+
+#include "guts-lowlevel.h"
+
+#define BIG_FUSE_CHANNEL_SIZE 1048576
+
+struct fuse_private {
+ int fd;
+ struct fuse *fuse;
+ struct fuse_session *se;
+ struct fuse_chan *ch;
+ char *mountpoint;
+};
+
+char glusterfs_fuse_direct_io_mode = 1;
+float glusterfs_fuse_entry_timeout = 1.0;
+float glusterfs_fuse_attr_timeout = 1.0;
+
+#define FI_TO_FD(fi) ((fd_t *)((long)fi->fh))
+
+#define FUSE_FOP(state, ret, op, args ...) \
+do { \
+ call_frame_t *frame = get_call_frame_for_req (state, 1); \
+ xlator_t *xl = frame->this->children ? \
+ frame->this->children->xlator : NULL; \
+ dict_t *refs = frame->root->req_refs; \
+ frame->root->state = state; \
+ STACK_WIND (frame, ret, xl, xl->fops->op, args); \
+ dict_unref (refs); \
+} while (0)
+
+#define FUSE_FOP_NOREPLY(state, op, args ...) \
+do { \
+ call_frame_t *_frame = get_call_frame_for_req (state, 0); \
+ xlator_t *xl = _frame->this->children->xlator; \
+ _frame->root->req_refs = NULL; \
+ STACK_WIND (_frame, fuse_nop_cbk, xl, xl->fops->op, args); \
+} while (0)
+
+typedef struct {
+ loc_t loc;
+ inode_t *parent;
+ inode_t *inode;
+ char *name;
+} fuse_loc_t;
+
+typedef struct {
+ void *pool;
+ xlator_t *this;
+ inode_table_t *itable;
+ fuse_loc_t fuse_loc;
+ fuse_loc_t fuse_loc2;
+ fuse_req_t req;
+
+ int32_t flags;
+ off_t off;
+ size_t size;
+ unsigned long nlookup;
+ fd_t *fd;
+ dict_t *dict;
+ char *name;
+ char is_revalidate;
+} fuse_state_t;
+
+
+static void
+loc_wipe (loc_t *loc)
+{
+ if (loc->inode) {
+ inode_unref (loc->inode);
+ loc->inode = NULL;
+ }
+ if (loc->path) {
+ FREE (loc->path);
+ loc->path = NULL;
+ }
+}
+
+
+static inode_t *
+dummy_inode (inode_table_t *table)
+{
+ inode_t *dummy;
+
+ dummy = CALLOC (1, sizeof (*dummy));
+ ERR_ABORT (dummy);
+
+ dummy->table = table;
+
+ INIT_LIST_HEAD (&dummy->list);
+ INIT_LIST_HEAD (&dummy->inode_hash);
+ INIT_LIST_HEAD (&dummy->fds);
+ INIT_LIST_HEAD (&dummy->dentry.name_hash);
+ INIT_LIST_HEAD (&dummy->dentry.inode_list);
+
+ dummy->ref = 1;
+ dummy->ctx = get_new_dict ();
+
+ LOCK_INIT (&dummy->lock);
+ return dummy;
+}
+
+static void
+fuse_loc_wipe (fuse_loc_t *fuse_loc)
+{
+ loc_wipe (&fuse_loc->loc);
+ if (fuse_loc->name) {
+ FREE (fuse_loc->name);
+ fuse_loc->name = NULL;
+ }
+ if (fuse_loc->inode) {
+ inode_unref (fuse_loc->inode);
+ fuse_loc->inode = NULL;
+ }
+ if (fuse_loc->parent) {
+ inode_unref (fuse_loc->parent);
+ fuse_loc->parent = NULL;
+ }
+}
+
+
+static void
+free_state (fuse_state_t *state)
+{
+ fuse_loc_wipe (&state->fuse_loc);
+
+ fuse_loc_wipe (&state->fuse_loc2);
+
+ if (state->dict) {
+ dict_unref (state->dict);
+ state->dict = (void *)0xaaaaeeee;
+ }
+ if (state->name) {
+ FREE (state->name);
+ state->name = NULL;
+ }
+#ifdef DEBUG
+ memset (state, 0x90, sizeof (*state));
+#endif
+ FREE (state);
+ state = NULL;
+}
+
+
+static int32_t
+fuse_nop_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ if (frame->root->state)
+ free_state (frame->root->state);
+
+ frame->root->state = EEEEKS;
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+
+fuse_state_t *
+state_from_req (fuse_req_t req)
+{
+ fuse_state_t *state;
+ transport_t *trans = fuse_req_userdata (req);
+
+ state = (void *)calloc (1, sizeof (*state));
+ ERR_ABORT (state);
+ state->pool = trans->xl->ctx->pool;
+ state->itable = trans->xl->itable;
+ state->req = req;
+ state->this = trans->xl;
+
+ return state;
+}
+
+
+static call_frame_t *
+get_call_frame_for_req (fuse_state_t *state, char d)
+{
+ call_pool_t *pool = state->pool;
+ fuse_req_t req = state->req;
+ const struct fuse_ctx *ctx = NULL;
+ call_ctx_t *cctx = NULL;
+ transport_t *trans = NULL;
+
+ cctx = CALLOC (1, sizeof (*cctx));
+ ERR_ABORT (cctx);
+ cctx->frames.root = cctx;
+
+ if (req) {
+ ctx = fuse_req_ctx(req);
+
+ cctx->uid = ctx->uid;
+ cctx->gid = ctx->gid;
+ cctx->pid = ctx->pid;
+ cctx->unique = req_callid (req);
+ }
+
+ if (req) {
+ trans = fuse_req_userdata (req);
+ cctx->frames.this = trans->xl;
+ cctx->trans = trans;
+ } else {
+ cctx->frames.this = state->this;
+ }
+
+ if (d) {
+ cctx->req_refs = dict_ref (get_new_dict ());
+ dict_set (cctx->req_refs, NULL, trans->buf);
+ cctx->req_refs->is_locked = 1;
+ }
+
+ cctx->pool = pool;
+ LOCK (&pool->lock);
+ list_add (&cctx->all_frames, &pool->all_frames);
+ UNLOCK (&pool->lock);
+
+ return &cctx->frames;
+}
+
+
+static void
+fuse_loc_fill (fuse_loc_t *fuse_loc,
+ fuse_state_t *state,
+ ino_t ino,
+ const char *name)
+{
+ size_t n;
+ inode_t *inode, *parent = NULL;
+
+ /* resistance against multiple invocation of loc_fill not to get
+ reference leaks via inode_search() */
+ inode = fuse_loc->inode;
+ if (!inode) {
+ inode = inode_search (state->itable, ino, name);
+ }
+ fuse_loc->inode = inode;
+
+ if (name) {
+ if (!fuse_loc->name)
+ fuse_loc->name = strdup (name);
+
+ parent = fuse_loc->parent;
+ if (!parent) {
+ if (inode)
+ parent = inode_parent (inode, ino);
+ else
+ parent = inode_search (state->itable, ino, NULL);
+ }
+ }
+ fuse_loc->parent = parent;
+
+ if (inode) {
+ fuse_loc->loc.inode = inode_ref (inode);
+ fuse_loc->loc.ino = inode->ino;
+ }
+
+ if (parent) {
+ n = inode_path (parent, name, NULL, 0) + 1;
+ fuse_loc->loc.path = CALLOC (1, n);
+ ERR_ABORT (fuse_loc->loc.path);
+ inode_path (parent, name, (char *)fuse_loc->loc.path, n);
+ } else if (inode) {
+ n = inode_path (inode, NULL, NULL, 0) + 1;
+ fuse_loc->loc.path = CALLOC (1, n);
+ ERR_ABORT (fuse_loc->loc.path);
+ inode_path (inode, NULL, (char *)fuse_loc->loc.path, n);
+ }
+}
+
+static int32_t
+fuse_lookup_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *stat,
+ dict_t *dict);
+
+static int32_t
+fuse_entry_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf)
+{
+ fuse_state_t *state;
+ fuse_req_t req;
+ struct fuse_entry_param e = {0, };
+
+ state = frame->root->state;
+ req = state->req;
+
+ if (!op_ret) {
+ if (inode->ino == 1)
+ buf->st_ino = 1;
+ }
+
+ if (!op_ret && inode && inode->ino && buf && inode->ino != buf->st_ino) {
+ /* temporary workaround to handle AFR returning differnt inode number */
+ gf_log ("glusterfs-fuse", GF_LOG_WARNING,
+ "%"PRId64": %s => inode number changed %"PRId64" -> %"PRId64,
+ frame->root->unique, state->fuse_loc.loc.path,
+ inode->ino, buf->st_ino);
+ inode_unref (state->fuse_loc.loc.inode);
+ state->fuse_loc.loc.inode = dummy_inode (state->itable);
+ state->is_revalidate = 2;
+
+ STACK_WIND (frame, fuse_lookup_cbk,
+ FIRST_CHILD (this), FIRST_CHILD (this)->fops->lookup,
+ &state->fuse_loc.loc,
+ 0);
+
+ return 0;
+ }
+
+ if (op_ret == 0) {
+ ino_t ino = buf->st_ino;
+ inode_t *fuse_inode;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => %"PRId64, frame->root->unique,
+ state->fuse_loc.loc.path, ino);
+
+ try_again:
+ fuse_inode = inode_update (state->itable, state->fuse_loc.parent,
+ state->fuse_loc.name, buf);
+
+ if (fuse_inode->ctx) {
+ /* if the inode was already in the hash, checks to flush out
+ old name hashes */
+ if ((fuse_inode->st_mode ^ buf->st_mode) & S_IFMT) {
+ gf_log ("glusterfs-fuse", GF_LOG_WARNING,
+ "%"PRId64": %s => %"PRId64" Rehashing %x/%x",
+ frame->root->unique,
+ state->fuse_loc.loc.path, ino, (S_IFMT & buf->st_ino),
+ (S_IFMT & fuse_inode->st_mode));
+
+ fuse_inode->st_mode = buf->st_mode;
+ inode_unhash_name (state->itable, fuse_inode);
+ inode_unref (fuse_inode);
+ goto try_again;
+ }
+ if (buf->st_nlink == 1) {
+ /* no other name hashes should exist */
+ if (!list_empty (&fuse_inode->dentry.inode_list)) {
+ gf_log ("glusterfs-fuse", GF_LOG_WARNING,
+ "%"PRId64": %s => %"PRId64" Rehashing because st_nlink less than dentry maps",
+ frame->root->unique,
+ state->fuse_loc.loc.path, ino);
+ inode_unhash_name (state->itable, fuse_inode);
+ inode_unref (fuse_inode);
+ goto try_again;
+ }
+ if ((state->fuse_loc.parent != fuse_inode->dentry.parent) ||
+ strcmp (state->fuse_loc.name, fuse_inode->dentry.name)) {
+ gf_log ("glusterfs-fuse", GF_LOG_WARNING,
+ "%"PRId64": %s => %"PRId64" Rehashing because single st_nlink does not match dentry map",
+ frame->root->unique,
+ state->fuse_loc.loc.path, ino);
+ inode_unhash_name (state->itable, fuse_inode);
+ inode_unref (fuse_inode);
+ goto try_again;
+ }
+ }
+ }
+
+ if ((fuse_inode->ctx != inode->ctx) &&
+ list_empty (&fuse_inode->fds)) {
+ dict_t *swap = inode->ctx;
+ inode->ctx = fuse_inode->ctx;
+ fuse_inode->ctx = swap;
+ fuse_inode->generation = inode->generation;
+ fuse_inode->st_mode = buf->st_mode;
+ }
+
+ inode_lookup (fuse_inode);
+
+ inode_unref (fuse_inode);
+
+ /* TODO: make these timeouts configurable (via meta?) */
+ e.ino = fuse_inode->ino;
+ e.generation = buf->st_ctime;
+ e.entry_timeout = glusterfs_fuse_entry_timeout;
+ e.attr_timeout = glusterfs_fuse_attr_timeout;
+ e.attr = *buf;
+ e.attr.st_blksize = BIG_FUSE_CHANNEL_SIZE;
+ if (state->fuse_loc.parent)
+ fuse_reply_entry (req, &e);
+ else
+ fuse_reply_attr (req, buf, glusterfs_fuse_attr_timeout);
+ } else {
+ if (state->is_revalidate == -1 && op_errno == ENOENT) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path, op_errno);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path, op_errno);
+ }
+
+ if (state->is_revalidate == 1) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "unlinking stale dentry for `%s'",
+ state->fuse_loc.loc.path);
+
+ if (state->fuse_loc.parent)
+ inode_unlink (state->itable, state->fuse_loc.parent,
+ state->fuse_loc.name);
+
+ inode_unref (state->fuse_loc.loc.inode);
+ state->fuse_loc.loc.inode = dummy_inode (state->itable);
+ state->is_revalidate = 2;
+
+ STACK_WIND (frame, fuse_lookup_cbk,
+ FIRST_CHILD (this), FIRST_CHILD (this)->fops->lookup,
+ &state->fuse_loc.loc, 0);
+
+ return 0;
+ }
+
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+
+
+static int32_t
+fuse_lookup_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *stat,
+ dict_t *dict)
+{
+ fuse_entry_cbk (frame, cookie, this, op_ret, op_errno, inode, stat);
+ return 0;
+}
+
+
+static void
+fuse_lookup (fuse_req_t req,
+ fuse_ino_t par,
+ const char *name)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": LOOKUP %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ state->fuse_loc.loc.inode = dummy_inode (state->itable);
+ /* to differntiate in entry_cbk what kind of call it is */
+ state->is_revalidate = -1;
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": LOOKUP %s(%"PRId64")", req_callid (req),
+ state->fuse_loc.loc.path, state->fuse_loc.loc.inode->ino);
+ state->is_revalidate = 1;
+ }
+
+ FUSE_FOP (state, fuse_lookup_cbk, lookup,
+ &state->fuse_loc.loc, 0);
+}
+
+
+static void
+fuse_forget (fuse_req_t req,
+ fuse_ino_t ino,
+ unsigned long nlookup)
+{
+ inode_t *fuse_inode;
+ fuse_state_t *state;
+
+ if (ino == 1) {
+ fuse_reply_none (req);
+ return;
+ }
+
+ state = state_from_req (req);
+ fuse_inode = inode_search (state->itable, ino, NULL);
+ inode_forget (fuse_inode, nlookup);
+ inode_unref (fuse_inode);
+
+ free_state (state);
+ fuse_reply_none (req);
+}
+
+
+static int32_t
+fuse_attr_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ fuse_state_t *state;
+ fuse_req_t req;
+
+ state = frame->root->state;
+ req = state->req;
+
+ if (op_ret == 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => %"PRId64, frame->root->unique,
+ state->fuse_loc.loc.path ? state->fuse_loc.loc.path : "ERR",
+ buf->st_ino);
+ /* TODO: make these timeouts configurable via meta */
+ /* TODO: what if the inode number has changed by now */
+ buf->st_blksize = BIG_FUSE_CHANNEL_SIZE;
+ fuse_reply_attr (req, buf, glusterfs_fuse_attr_timeout);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64"; %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path ? state->fuse_loc.loc.path : "ERR",
+ op_errno);
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+
+
+static void
+fuse_getattr (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ if (ino == 1) {
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (state->fuse_loc.loc.inode)
+ state->is_revalidate = 1;
+ else
+ state->is_revalidate = -1;
+ FUSE_FOP (state,
+ fuse_lookup_cbk, lookup, &state->fuse_loc.loc, 0);
+ return;
+ }
+
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": GETATTR %"PRId64" (%s) (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ if (list_empty (&state->fuse_loc.loc.inode->fds) ||
+ S_ISDIR (state->fuse_loc.loc.inode->st_mode)) {
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": GETATTR %"PRId64" (%s)",
+ req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ stat,
+ &state->fuse_loc.loc);
+ } else {
+ fd_t *fd = list_entry (state->fuse_loc.loc.inode->fds.next,
+ fd_t, inode_list);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": FGETATTR %"PRId64" (%s/%p)",
+ req_callid (req), (int64_t)ino, state->fuse_loc.loc.path, fd);
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ fstat, fd);
+ }
+}
+
+
+static int32_t
+fuse_fd_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd)
+{
+ fuse_state_t *state;
+ fuse_req_t req;
+
+ state = frame->root->state;
+ req = state->req;
+ fd = state->fd;
+
+ if (op_ret >= 0) {
+ struct fuse_file_info fi = {0, };
+
+ LOCK (&fd->inode->lock);
+ list_add (&fd->inode_list, &fd->inode->fds);
+ UNLOCK (&fd->inode->lock);
+
+ fi.fh = (unsigned long) fd;
+ fi.flags = state->flags;
+
+ if (!S_ISDIR (fd->inode->st_mode)) {
+ if ((fi.flags & 3) && glusterfs_fuse_direct_io_mode)
+ fi.direct_io = 1;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => %p", frame->root->unique,
+ state->fuse_loc.loc.path, fd);
+
+ if (fuse_reply_open (req, &fi) == -ENOENT) {
+ gf_log ("glusterfs-fuse", GF_LOG_WARNING, "open() got EINTR");
+ state->req = 0;
+
+ if (S_ISDIR (fd->inode->st_mode))
+ FUSE_FOP_NOREPLY (state, closedir, fd);
+ else
+ FUSE_FOP_NOREPLY (state, close, fd);
+ }
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path, op_errno);
+ fuse_reply_err (req, op_errno);
+ fd_destroy (fd);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+
+
+
+static void
+do_chmod (fuse_req_t req,
+ fuse_ino_t ino,
+ struct stat *attr,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state = state_from_req (req);
+
+ if (fi) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": FCHMOD %p", req_callid (req), FI_TO_FD (fi));
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ fchmod,
+ FI_TO_FD (fi),
+ attr->st_mode);
+ } else {
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": CHMOD %"PRId64" (%s) (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": CHMOD %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ chmod,
+ &state->fuse_loc.loc,
+ attr->st_mode);
+ }
+}
+
+static void
+do_chown (fuse_req_t req,
+ fuse_ino_t ino,
+ struct stat *attr,
+ int valid,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ uid_t uid = (valid & FUSE_SET_ATTR_UID) ? attr->st_uid : (uid_t) -1;
+ gid_t gid = (valid & FUSE_SET_ATTR_GID) ? attr->st_gid : (gid_t) -1;
+
+ state = state_from_req (req);
+
+ if (fi) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": FCHOWN %p", req_callid (req), FI_TO_FD (fi));
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ fchown,
+ FI_TO_FD (fi),
+ uid,
+ gid);
+ } else {
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": CHOWN %"PRId64" (%s) (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": CHOWN %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ chown,
+ &state->fuse_loc.loc,
+ uid,
+ gid);
+ }
+}
+
+static void
+do_truncate (fuse_req_t req,
+ fuse_ino_t ino,
+ struct stat *attr,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ if (fi) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": FTRUNCATE %p/%"PRId64, req_callid (req),
+ FI_TO_FD (fi), attr->st_size);
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ ftruncate,
+ FI_TO_FD (fi),
+ attr->st_size);
+ } else {
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": TRUNCATE %s/%"PRId64" (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), state->fuse_loc.loc.path, attr->st_size);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": TRUNCATE %s/%"PRId64, req_callid (req),
+ state->fuse_loc.loc.path, attr->st_size);
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ truncate,
+ &state->fuse_loc.loc,
+ attr->st_size);
+ }
+
+ return;
+}
+
+static void
+do_utimes (fuse_req_t req,
+ fuse_ino_t ino,
+ struct stat *attr)
+{
+ fuse_state_t *state;
+
+ struct timespec tv[2];
+#ifdef FUSE_STAT_HAS_NANOSEC
+ tv[0] = ST_ATIM(attr);
+ tv[1] = ST_MTIM(attr);
+#else
+ tv[0].tv_sec = attr->st_atime;
+ tv[0].tv_nsec = 0;
+ tv[1].tv_sec = attr->st_mtime;
+ tv[1].tv_nsec = 0;
+#endif
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": UTIMENS %s (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": UTIMENS %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_attr_cbk,
+ utimens,
+ &state->fuse_loc.loc,
+ tv);
+}
+
+static void
+fuse_setattr (fuse_req_t req,
+ fuse_ino_t ino,
+ struct stat *attr,
+ int valid,
+ struct fuse_file_info *fi)
+{
+
+ if (valid & FUSE_SET_ATTR_MODE)
+ do_chmod (req, ino, attr, fi);
+ else if (valid & (FUSE_SET_ATTR_UID | FUSE_SET_ATTR_GID))
+ do_chown (req, ino, attr, valid, fi);
+ else if (valid & FUSE_SET_ATTR_SIZE)
+ do_truncate (req, ino, attr, fi);
+ else if ((valid & (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME)) == (FUSE_SET_ATTR_ATIME | FUSE_SET_ATTR_MTIME))
+ do_utimes (req, ino, attr);
+
+ if (!valid)
+ fuse_getattr (req, ino, fi);
+}
+
+
+static int32_t
+fuse_err_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret == 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => 0", frame->root->unique,
+ state->fuse_loc.loc.path ? state->fuse_loc.loc.path : "ERR");
+ fuse_reply_err (req, 0);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path ? state->fuse_loc.loc.path : "ERR",
+ op_errno);
+ fuse_reply_err (req, op_errno);
+ }
+
+ if (state->fd)
+ fd_destroy (state->fd);
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+
+
+static int32_t
+fuse_unlink_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret == 0)
+ inode_unlink (state->itable, state->fuse_loc.parent, state->fuse_loc.name);
+
+ if (op_ret == 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => 0", frame->root->unique,
+ state->fuse_loc.loc.path);
+
+ fuse_reply_err (req, 0);
+ } else {
+ gf_log ("glusterfs-fuse", (op_errno == ENOTEMPTY) ? GF_LOG_DEBUG : GF_LOG_ERROR,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path, op_errno);
+
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+
+static void
+fuse_access (fuse_req_t req,
+ fuse_ino_t ino,
+ int mask)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": ACCESS %"PRId64" (%s) (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), (int64_t)ino, state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ FUSE_FOP (state,
+ fuse_err_cbk,
+ access,
+ &state->fuse_loc.loc,
+ mask);
+
+ return;
+}
+
+
+
+static int32_t
+fuse_readlink_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ const char *linkname)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret > 0) {
+ ((char *)linkname)[op_ret] = '\0';
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => %s", frame->root->unique,
+ state->fuse_loc.loc.path, linkname);
+
+ fuse_reply_readlink(req, linkname);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path, op_errno);
+ fuse_reply_err(req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+static void
+fuse_readlink (fuse_req_t req,
+ fuse_ino_t ino)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64" READLINK %s/%"PRId64" (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), state->fuse_loc.loc.path, state->fuse_loc.loc.inode->ino);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64" READLINK %s/%"PRId64, req_callid (req),
+ state->fuse_loc.loc.path, state->fuse_loc.loc.inode->ino);
+
+ FUSE_FOP (state,
+ fuse_readlink_cbk,
+ readlink,
+ &state->fuse_loc.loc,
+ 4096);
+
+ return;
+}
+
+
+static void
+fuse_mknod (fuse_req_t req,
+ fuse_ino_t par,
+ const char *name,
+ mode_t mode,
+ dev_t rdev)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+
+ state->fuse_loc.loc.inode = dummy_inode (state->itable);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": MKNOD %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_entry_cbk,
+ mknod,
+ &state->fuse_loc.loc,
+ mode,
+ rdev);
+
+ return;
+}
+
+
+static void
+fuse_mkdir (fuse_req_t req,
+ fuse_ino_t par,
+ const char *name,
+ mode_t mode)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+
+ state->fuse_loc.loc.inode = dummy_inode (state->itable);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": MKDIR %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_entry_cbk,
+ mkdir,
+ &state->fuse_loc.loc,
+ mode);
+
+ return;
+}
+
+
+static void
+fuse_unlink (fuse_req_t req,
+ fuse_ino_t par,
+ const char *name)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": UNLINK %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": UNLINK %s (fuse_loc_fill() returned NULL inode)", req_callid (req),
+ state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ FUSE_FOP (state,
+ fuse_unlink_cbk,
+ unlink,
+ &state->fuse_loc.loc);
+
+ return;
+}
+
+
+static void
+fuse_rmdir (fuse_req_t req,
+ fuse_ino_t par,
+ const char *name)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": RMDIR %s (fuse_loc_fill() returned NULL inode)", req_callid (req),
+ state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": RMDIR %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_unlink_cbk,
+ rmdir,
+ &state->fuse_loc.loc);
+
+ return;
+}
+
+
+static void
+fuse_symlink (fuse_req_t req,
+ const char *linkname,
+ fuse_ino_t par,
+ const char *name)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+
+ state->fuse_loc.loc.inode = dummy_inode (state->itable);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": SYMLINK %s -> %s", req_callid (req),
+ state->fuse_loc.loc.path, linkname);
+
+ FUSE_FOP (state,
+ fuse_entry_cbk,
+ symlink,
+ linkname,
+ &state->fuse_loc.loc);
+ return;
+}
+
+
+int32_t
+fuse_rename_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret == 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s -> %s => 0", frame->root->unique,
+ state->fuse_loc.loc.path,
+ state->fuse_loc2.loc.path);
+
+ inode_t *inode;
+ {
+ /* ugly ugly - to stay blind to situation where
+ rename happens on a new inode
+ */
+ buf->st_ino = state->fuse_loc.loc.ino;
+ }
+ inode = inode_rename (state->itable,
+ state->fuse_loc.parent,
+ state->fuse_loc.name,
+ state->fuse_loc2.parent,
+ state->fuse_loc2.name,
+ buf);
+
+ inode_unref (inode);
+ fuse_reply_err (req, 0);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": %s -> %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path,
+ state->fuse_loc2.loc.path, op_errno);
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+
+
+static void
+fuse_rename (fuse_req_t req,
+ fuse_ino_t oldpar,
+ const char *oldname,
+ fuse_ino_t newpar,
+ const char *newname)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ fuse_loc_fill (&state->fuse_loc, state, oldpar, oldname);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "for %s %"PRId64": RENAME `%s' -> `%s' (fuse_loc_fill() returned NULL inode)",
+ state->fuse_loc.loc.path, req_callid (req), state->fuse_loc.loc.path,
+ state->fuse_loc2.loc.path);
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ fuse_loc_fill (&state->fuse_loc2, state, newpar, newname);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": RENAME `%s' -> `%s'",
+ req_callid (req), state->fuse_loc.loc.path,
+ state->fuse_loc2.loc.path);
+
+ FUSE_FOP (state,
+ fuse_rename_cbk,
+ rename,
+ &state->fuse_loc.loc,
+ &state->fuse_loc2.loc);
+
+ return;
+}
+
+
+static void
+fuse_link (fuse_req_t req,
+ fuse_ino_t ino,
+ fuse_ino_t par,
+ const char *name)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+ fuse_loc_fill (&state->fuse_loc2, state, ino, NULL);
+ if (!state->fuse_loc2.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "fuse_loc_fill() returned NULL inode for %s %"PRId64": LINK %s %s",
+ state->fuse_loc2.loc.path, req_callid (req),
+ state->fuse_loc2.loc.path, state->fuse_loc.loc.path);
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ state->fuse_loc.loc.inode = inode_ref (state->fuse_loc2.loc.inode);
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": LINK %s %s", req_callid (req),
+ state->fuse_loc2.loc.path, state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_entry_cbk,
+ link,
+ &state->fuse_loc2.loc,
+ state->fuse_loc.loc.path);
+
+ return;
+}
+
+
+static int32_t
+fuse_create_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd,
+ inode_t *inode,
+ struct stat *buf)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ struct fuse_file_info fi = {0, };
+ struct fuse_entry_param e = {0, };
+
+ fd = state->fd;
+
+ fi.flags = state->flags;
+ if (op_ret >= 0) {
+ inode_t *fuse_inode;
+ fi.fh = (unsigned long) fd;
+
+ if ((fi.flags & 3) && glusterfs_fuse_direct_io_mode)
+ fi.direct_io = 1;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => %p", frame->root->unique,
+ state->fuse_loc.loc.path, fd);
+
+ fuse_inode = inode_update (state->itable,
+ state->fuse_loc.parent,
+ state->fuse_loc.name,
+ buf);
+ if (fuse_inode->ctx) {
+ inode_unhash_name (state->itable, fuse_inode);
+ inode_unref (fuse_inode);
+
+ fuse_inode = inode_update (state->itable,
+ state->fuse_loc.parent,
+ state->fuse_loc.name,
+ buf);
+ }
+
+
+ {
+ if (fuse_inode->ctx != inode->ctx) {
+ dict_t *swap = inode->ctx;
+ inode->ctx = fuse_inode->ctx;
+ fuse_inode->ctx = swap;
+ fuse_inode->generation = inode->generation;
+ fuse_inode->st_mode = buf->st_mode;
+ }
+
+ inode_lookup (fuse_inode);
+
+ /* list_del (&fd->inode_list); */
+
+ LOCK (&fuse_inode->lock);
+ list_add (&fd->inode_list, &fuse_inode->fds);
+ inode_unref (fd->inode);
+ fd->inode = inode_ref (fuse_inode);
+ UNLOCK (&fuse_inode->lock);
+
+ // inode_destroy (inode);
+ }
+
+ inode_unref (fuse_inode);
+
+ e.ino = fuse_inode->ino;
+ e.generation = buf->st_ctime;
+ e.entry_timeout = glusterfs_fuse_entry_timeout;
+ e.attr_timeout = glusterfs_fuse_attr_timeout;
+ e.attr = *buf;
+ e.attr.st_blksize = BIG_FUSE_CHANNEL_SIZE;
+
+ fi.keep_cache = 0;
+
+ // if (fi.flags & 1)
+ // fi.direct_io = 1;
+
+ if (fuse_reply_create (req, &e, &fi) == -ENOENT) {
+ gf_log ("glusterfs-fuse", GF_LOG_WARNING, "create() got EINTR");
+ /* TODO: forget this node too */
+ state->req = 0;
+ FUSE_FOP_NOREPLY (state, close, fd);
+ }
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": %s => -1 (%d)", req_callid (req),
+ state->fuse_loc.loc.path, op_errno);
+ fuse_reply_err (req, op_errno);
+ fd_destroy (fd);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+
+static void
+fuse_create (fuse_req_t req,
+ fuse_ino_t par,
+ const char *name,
+ mode_t mode,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+ fd_t *fd;
+
+ state = state_from_req (req);
+ state->flags = fi->flags;
+
+ fuse_loc_fill (&state->fuse_loc, state, par, name);
+ state->fuse_loc.loc.inode = dummy_inode (state->itable);
+
+ fd = fd_create (state->fuse_loc.loc.inode);
+ state->fd = fd;
+
+
+ LOCK (&fd->inode->lock);
+ list_del_init (&fd->inode_list);
+ UNLOCK (&fd->inode->lock);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": CREATE %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_create_cbk,
+ create,
+ &state->fuse_loc.loc,
+ state->flags,
+ mode, fd);
+
+ return;
+}
+
+
+static void
+fuse_open (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+ fd_t *fd;
+
+ state = state_from_req (req);
+ state->flags = fi->flags;
+
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": OPEN %s (fuse_loc_fill() returned NULL inode)", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+
+ fd = fd_create (state->fuse_loc.loc.inode);
+ state->fd = fd;
+
+ LOCK (&fd->inode->lock);
+ list_del_init (&fd->inode_list);
+ UNLOCK (&fd->inode->lock);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": OPEN %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_fd_cbk,
+ open,
+ &state->fuse_loc.loc,
+ fi->flags, fd);
+
+ return;
+}
+
+
+static int32_t
+fuse_readv_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct iovec *vector,
+ int32_t count,
+ struct stat *stbuf)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret >= 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": READ => %d/%d,%"PRId64"/%"PRId64, frame->root->unique,
+ op_ret, state->size, state->off, stbuf->st_size);
+
+ fuse_reply_vec (req, vector, count);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": READ => -1 (%d)", frame->root->unique, op_errno);
+
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+static void
+fuse_readv (fuse_req_t req,
+ fuse_ino_t ino,
+ size_t size,
+ off_t off,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->size = size;
+ state->off = off;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": READ (%p, size=%d, offset=%"PRId64")",
+ req_callid (req), FI_TO_FD (fi), size, off);
+
+ FUSE_FOP (state,
+ fuse_readv_cbk,
+ readv,
+ FI_TO_FD (fi),
+ size,
+ off);
+
+}
+
+
+static int32_t
+fuse_writev_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *stbuf)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret >= 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": WRITE => %d/%d,%"PRId64"/%"PRId64, frame->root->unique,
+ op_ret, state->size, state->off, stbuf->st_size);
+
+ fuse_reply_write (req, op_ret);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": WRITE => -1 (%d)", frame->root->unique, op_errno);
+
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+
+static void
+fuse_write (fuse_req_t req,
+ fuse_ino_t ino,
+ const char *buf,
+ size_t size,
+ off_t off,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+ struct iovec vector;
+
+ state = state_from_req (req);
+ state->size = size;
+ state->off = off;
+
+ vector.iov_base = (void *)buf;
+ vector.iov_len = size;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": WRITE (%p, size=%d, offset=%"PRId64")",
+ req_callid (req), FI_TO_FD (fi), size, off);
+
+ FUSE_FOP (state,
+ fuse_writev_cbk,
+ writev,
+ FI_TO_FD (fi),
+ &vector,
+ 1,
+ off);
+ return;
+}
+
+
+static void
+fuse_flush (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": FLUSH %p", req_callid (req), FI_TO_FD (fi));
+
+ FUSE_FOP (state,
+ fuse_err_cbk,
+ flush,
+ FI_TO_FD (fi));
+
+ return;
+}
+
+
+static void
+fuse_release (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->fd = FI_TO_FD (fi);
+
+ LOCK (&state->fd->inode->lock);
+ list_del_init (&state->fd->inode_list);
+ UNLOCK (&state->fd->inode->lock);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": CLOSE %p", req_callid (req), FI_TO_FD (fi));
+
+ FUSE_FOP (state, fuse_err_cbk, close, state->fd);
+ return;
+}
+
+
+static void
+fuse_fsync (fuse_req_t req,
+ fuse_ino_t ino,
+ int datasync,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": FSYNC %p", req_callid (req), FI_TO_FD (fi));
+
+ FUSE_FOP (state,
+ fuse_err_cbk,
+ fsync,
+ FI_TO_FD (fi),
+ datasync);
+
+ return;
+}
+
+static void
+fuse_opendir (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+ fd_t *fd;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": OPEN %s (fuse_loc_fill() returned NULL inode)", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+
+ fd = fd_create (state->fuse_loc.loc.inode);
+ state->fd = fd;
+
+ LOCK (&fd->inode->lock);
+ list_del_init (&fd->inode_list);
+ UNLOCK (&fd->inode->lock);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": OPEN %s", req_callid (req),
+ state->fuse_loc.loc.path);
+
+ FUSE_FOP (state,
+ fuse_fd_cbk,
+ opendir,
+ &state->fuse_loc.loc, fd);
+}
+
+#if 0
+
+void
+fuse_dir_reply (fuse_req_t req,
+ size_t size,
+ off_t off,
+ fd_t *fd)
+{
+ char *buf;
+ size_t size_limited;
+ data_t *buf_data;
+
+ buf_data = dict_get (fd->ctx, "__fuse__getdents__internal__@@!!");
+ buf = buf_data->data;
+ size_limited = size;
+
+ if (size_limited > (buf_data->len - off))
+ size_limited = (buf_data->len - off);
+
+ if (off > buf_data->len) {
+ size_limited = 0;
+ off = 0;
+ }
+
+ fuse_reply_buf (req, buf + off, size_limited);
+}
+
+
+static int32_t
+fuse_getdents_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ dir_entry_t *entries,
+ int32_t count)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret < 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": READDIR => -1 (%d)",
+ frame->root->unique, op_errno);
+
+ fuse_reply_err (state->req, op_errno);
+ } else {
+ dir_entry_t *trav;
+ size_t size = 0;
+ char *buf;
+ data_t *buf_data;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": READDIR => %d entries",
+ frame->root->unique, count);
+
+ for (trav = entries->next; trav; trav = trav->next) {
+ size += fuse_add_direntry (req, NULL, 0, trav->name, NULL, 0);
+ }
+
+ buf = CALLOC (1, size);
+ ERR_ABORT (buf);
+ buf_data = data_from_dynptr (buf, size);
+ size = 0;
+
+ for (trav = entries->next; trav; trav = trav->next) {
+ size_t entry_size;
+ entry_size = fuse_add_direntry (req, NULL, 0, trav->name, NULL, 0);
+ fuse_add_direntry (req, buf + size, entry_size, trav->name,
+ &trav->buf, entry_size + size);
+ size += entry_size;
+ }
+
+ dict_set (state->fd->ctx,
+ "__fuse__getdents__internal__@@!!",
+ buf_data);
+
+ fuse_dir_reply (state->req, state->size, state->off, state->fd);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+static void
+fuse_getdents (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi,
+ size_t size,
+ off_t off,
+ int32_t flag)
+{
+ fuse_state_t *state;
+ fd_t *fd = FI_TO_FD (fi);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": GETDENTS %p", req_callid (req), FI_TO_FD (fi));
+
+ if (!off)
+ dict_del (fd->ctx, "__fuse__getdents__internal__@@!!");
+
+ if (dict_get (fd->ctx, "__fuse__getdents__internal__@@!!")) {
+ fuse_dir_reply (req, size, off, fd);
+ return;
+ }
+
+ state = state_from_req (req);
+
+ state->size = size;
+ state->off = off;
+ state->fd = fd;
+
+ FUSE_FOP (state,
+ fuse_getdents_cbk,
+ getdents,
+ fd,
+ size,
+ off,
+ 0);
+}
+
+#endif
+
+static int32_t
+fuse_readdir_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ gf_dirent_t *buf)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (op_ret >= 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": READDIR => %d/%d,%"PRId64, frame->root->unique,
+ op_ret, state->size, state->off);
+
+ fuse_reply_buf (req, (void *)buf, op_ret);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": READDIR => -1 (%d)", frame->root->unique, op_errno);
+
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+
+}
+
+static void
+fuse_readdir (fuse_req_t req,
+ fuse_ino_t ino,
+ size_t size,
+ off_t off,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->size = size;
+ state->off = off;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": READDIR (%p, size=%d, offset=%"PRId64")",
+ req_callid (req), FI_TO_FD (fi), size, off);
+
+ FUSE_FOP (state,
+ fuse_readdir_cbk,
+ readdir,
+ FI_TO_FD (fi),
+ size,
+ off);
+}
+
+
+static void
+fuse_releasedir (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->fd = FI_TO_FD (fi);
+
+ LOCK (&state->fd->inode->lock);
+ list_del_init (&state->fd->inode_list);
+ UNLOCK (&state->fd->inode->lock);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": CLOSEDIR %p", req_callid (req), FI_TO_FD (fi));
+
+ FUSE_FOP (state, fuse_err_cbk, closedir, state->fd);
+}
+
+
+static void
+fuse_fsyncdir (fuse_req_t req,
+ fuse_ino_t ino,
+ int datasync,
+ struct fuse_file_info *fi)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+
+ FUSE_FOP (state,
+ fuse_err_cbk,
+ fsyncdir,
+ FI_TO_FD (fi),
+ datasync);
+
+ return;
+}
+
+
+static int32_t
+fuse_statfs_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct statvfs *buf)
+{
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ /*
+ Filesystems (like ZFS on solaris) reports
+ different ->f_frsize and ->f_bsize. Old coreutils
+ df tools use statfs() and do not see ->f_frsize.
+ the ->f_blocks, ->f_bavail and ->f_bfree are
+ w.r.t ->f_frsize and not ->f_bsize which makes the
+ df tools report wrong values.
+
+ Scale the block counts to match ->f_bsize.
+ */
+ /* TODO: with old coreutils, f_bsize is taken from stat()'s st_blksize
+ * so the df with old coreutils this wont work :(
+ */
+
+ if (op_ret == 0) {
+
+ buf->f_blocks *= buf->f_frsize;
+ buf->f_blocks /= BIG_FUSE_CHANNEL_SIZE;
+
+ buf->f_bavail *= buf->f_frsize;
+ buf->f_bavail /= BIG_FUSE_CHANNEL_SIZE;
+
+ buf->f_bfree *= buf->f_frsize;
+ buf->f_bfree /= BIG_FUSE_CHANNEL_SIZE;
+
+ buf->f_frsize = buf->f_bsize = BIG_FUSE_CHANNEL_SIZE;
+
+ fuse_reply_statfs (req, buf);
+
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": ERR => -1 (%d)", frame->root->unique, op_errno);
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+
+static void
+fuse_statfs (fuse_req_t req,
+ fuse_ino_t ino)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, 1, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": STATFS (fuse_loc_fill() returned NULL inode)", req_callid (req));
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": STATFS", req_callid (req));
+
+ FUSE_FOP (state,
+ fuse_statfs_cbk,
+ statfs,
+ &state->fuse_loc.loc);
+}
+
+static void
+fuse_setxattr (fuse_req_t req,
+ fuse_ino_t ino,
+ const char *name,
+ const char *value,
+ size_t size,
+ int flags)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->size = size;
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": SETXATTR %s/%"PRId64" (%s) (fuse_loc_fill() returned NULL inode)",
+ req_callid (req),
+ state->fuse_loc.loc.path, (int64_t)ino, name);
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ state->dict = get_new_dict ();
+
+ dict_set (state->dict, (char *)name,
+ bin_to_data ((void *)value, size));
+ dict_ref (state->dict);
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": SETXATTR %s/%"PRId64" (%s)", req_callid (req),
+ state->fuse_loc.loc.path, (int64_t)ino, name);
+
+ FUSE_FOP (state,
+ fuse_err_cbk,
+ setxattr,
+ &state->fuse_loc.loc,
+ state->dict,
+ flags);
+
+ return;
+}
+
+
+static int32_t
+fuse_xattr_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ dict_t *dict)
+{
+ int32_t ret = op_ret;
+ char *value = "";
+ fuse_state_t *state = frame->root->state;
+ fuse_req_t req = state->req;
+
+ if (ret >= 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => %d", frame->root->unique,
+ state->fuse_loc.loc.path, op_ret);
+
+ /* if successful */
+ if (state->name) {
+ /* if callback for getxattr */
+ data_t *value_data = dict_get (dict, state->name);
+ if (value_data) {
+ ret = value_data->len; /* Don't return the value for '\0' */
+ value = value_data->data;
+
+ if (state->size) {
+ /* if callback for getxattr and asks for value */
+ fuse_reply_buf (req, value, ret);
+ } else {
+ /* if callback for getxattr and asks for value length only */
+ fuse_reply_xattr (req, ret);
+ }
+ } else {
+ fuse_reply_err (req, ENODATA);
+ }
+ } else {
+ /* if callback for listxattr */
+ int32_t len = 0;
+ data_pair_t *trav = dict->members_list;
+ while (trav) {
+ len += strlen (trav->key) + 1;
+ trav = trav->next;
+ }
+ value = alloca (len + 1);
+ ERR_ABORT (value);
+ len = 0;
+ trav = dict->members_list;
+ while (trav) {
+ strcpy (value + len, trav->key);
+ value[len + strlen(trav->key)] = '\0';
+ len += strlen (trav->key) + 1;
+ trav = trav->next;
+ }
+ if (state->size) {
+ /* if callback for listxattr and asks for list of keys */
+ fuse_reply_buf (req, value, len);
+ } else {
+ /* if callback for listxattr and asks for length of keys only */
+ fuse_reply_xattr (req, len);
+ }
+ }
+ } else {
+ /* if failure - no need to check if listxattr or getxattr */
+ if (op_errno != ENODATA) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path, op_errno);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": %s => -1 (%d)", frame->root->unique,
+ state->fuse_loc.loc.path, op_errno);
+ }
+
+ fuse_reply_err (req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+
+static void
+fuse_getxattr (fuse_req_t req,
+ fuse_ino_t ino,
+ const char *name,
+ size_t size)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->size = size;
+ state->name = strdup (name);
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": GETXATTR %s/%"PRId64" (%s) (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), state->fuse_loc.loc.path, (int64_t)ino, name);
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": GETXATTR %s/%"PRId64" (%s)", req_callid (req),
+ state->fuse_loc.loc.path, (int64_t)ino, name);
+
+ FUSE_FOP (state,
+ fuse_xattr_cbk,
+ getxattr,
+ &state->fuse_loc.loc);
+
+ return;
+}
+
+
+static void
+fuse_listxattr (fuse_req_t req,
+ fuse_ino_t ino,
+ size_t size)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->size = size;
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": LISTXATTR %s/%"PRId64" (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), state->fuse_loc.loc.path, (int64_t)ino);
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": LISTXATTR %s/%"PRId64, req_callid (req),
+ state->fuse_loc.loc.path, (int64_t)ino);
+
+ FUSE_FOP (state,
+ fuse_xattr_cbk,
+ getxattr,
+ &state->fuse_loc.loc);
+
+ return;
+}
+
+
+static void
+fuse_removexattr (fuse_req_t req,
+ fuse_ino_t ino,
+ const char *name)
+
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ fuse_loc_fill (&state->fuse_loc, state, ino, NULL);
+ if (!state->fuse_loc.loc.inode) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": REMOVEXATTR %s/%"PRId64" (%s) (fuse_loc_fill() returned NULL inode)",
+ req_callid (req), state->fuse_loc.loc.path, (int64_t)ino, name);
+
+ fuse_reply_err (req, EINVAL);
+ return;
+ }
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": REMOVEXATTR %s/%"PRId64" (%s)", req_callid (req),
+ state->fuse_loc.loc.path, (int64_t)ino, name);
+
+ FUSE_FOP (state,
+ fuse_err_cbk,
+ removexattr,
+ &state->fuse_loc.loc,
+ name);
+
+ return;
+}
+
+static int32_t
+fuse_getlk_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct flock *lock)
+{
+ fuse_state_t *state = frame->root->state;
+
+ if (op_ret == 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": ERR => 0", frame->root->unique);
+ fuse_reply_lock (state->req, lock);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": ERR => -1 (%d)", frame->root->unique, op_errno);
+ fuse_reply_err (state->req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+static void
+fuse_getlk (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi,
+ struct flock *lock)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->req = req;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": GETLK %p", req_callid (req), FI_TO_FD (fi));
+
+ FUSE_FOP (state,
+ fuse_getlk_cbk,
+ lk,
+ FI_TO_FD (fi),
+ F_GETLK,
+ lock);
+
+ return;
+}
+
+static int32_t
+fuse_setlk_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct flock *lock)
+{
+ fuse_state_t *state = frame->root->state;
+
+ if (op_ret == 0) {
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": ERR => 0", frame->root->unique);
+ fuse_reply_err (state->req, 0);
+ } else {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR,
+ "%"PRId64": ERR => -1 (%d)", frame->root->unique, op_errno);
+ fuse_reply_err (state->req, op_errno);
+ }
+
+ free_state (state);
+ STACK_DESTROY (frame->root);
+
+ return 0;
+}
+
+static void
+fuse_setlk (fuse_req_t req,
+ fuse_ino_t ino,
+ struct fuse_file_info *fi,
+ struct flock *lock,
+ int sleep)
+{
+ fuse_state_t *state;
+
+ state = state_from_req (req);
+ state->req = req;
+
+ gf_log ("glusterfs-fuse", GF_LOG_DEBUG,
+ "%"PRId64": SETLK %p (sleep=%d)", req_callid (req), FI_TO_FD (fi),
+ sleep);
+
+ FUSE_FOP (state,
+ fuse_setlk_cbk,
+ lk,
+ FI_TO_FD(fi),
+ (sleep ? F_SETLKW : F_SETLK),
+ lock);
+
+ return;
+}
+
+
+int32_t
+fuse_forget_notify (call_frame_t *frame, xlator_t *this,
+ inode_t *inode)
+{
+ return 0;
+}
+
+struct xlator_fops fuse_xl_fops = {
+ .forget = fuse_forget_notify
+};
+
+static void
+fuse_init (void *data, struct fuse_conn_info *conn)
+{
+ transport_t *trans = data;
+ struct fuse_private *priv = trans->private;
+ xlator_t *xl = trans->xl;
+ int32_t ret;
+
+ xl->name = "fuse";
+ xl->fops = &fuse_xl_fops;
+ xl->itable = inode_table_new (0, xl);
+ xl->notify = default_notify;
+ ret = xlator_tree_init (xl);
+ if (ret == 0) {
+
+ } else {
+ fuse_unmount (priv->mountpoint, priv->ch);
+ exit (1);
+ }
+}
+
+
+static void
+fuse_destroy (void *data)
+{
+
+}
+
+struct fuse_lowlevel_ops fuse_ops = {
+ .init = fuse_init,
+ .destroy = fuse_destroy,
+ .lookup = fuse_lookup,
+ .forget = fuse_forget,
+ .getattr = fuse_getattr,
+ .setattr = fuse_setattr,
+ .opendir = fuse_opendir,
+ .readdir = fuse_readdir,
+ .releasedir = fuse_releasedir,
+ .access = fuse_access,
+ .readlink = fuse_readlink,
+ .mknod = fuse_mknod,
+ .mkdir = fuse_mkdir,
+ .unlink = fuse_unlink,
+ .rmdir = fuse_rmdir,
+ .symlink = fuse_symlink,
+ .rename = fuse_rename,
+ .link = fuse_link,
+ .create = fuse_create,
+ .open = fuse_open,
+ .read = fuse_readv,
+ .write = fuse_write,
+ .flush = fuse_flush,
+ .release = fuse_release,
+ .fsync = fuse_fsync,
+ .fsyncdir = fuse_fsyncdir,
+ .statfs = fuse_statfs,
+ .setxattr = fuse_setxattr,
+ .getxattr = fuse_getxattr,
+ .listxattr = fuse_listxattr,
+ .removexattr = fuse_removexattr,
+ .getlk = fuse_getlk,
+ .setlk = fuse_setlk
+};
+
+
+static int32_t
+fuse_transport_disconnect (transport_t *this)
+{
+ struct fuse_private *priv = this->private;
+
+ gf_log ("glusterfs-fuse",
+ GF_LOG_DEBUG,
+ "cleaning up fuse transport in disconnect handler");
+
+ fuse_session_remove_chan (priv->ch);
+ fuse_session_destroy (priv->se);
+ fuse_unmount (priv->mountpoint, priv->ch);
+
+ FREE (priv);
+ priv = NULL;
+ this->private = NULL;
+
+ /* TODO: need graceful exit. every xlator should be ->fini()'ed
+ and come out of main poll loop cleanly
+ */
+ exit (0);
+
+ return -1;
+}
+
+
+static int32_t
+fuse_transport_init (transport_t *this,
+ dict_t *options,
+ event_notify_fn_t notify)
+{
+ char *mountpoint = strdup (data_to_str (dict_get (options,
+ "mountpoint")));
+ char *source;
+ asprintf (&source, "fsname=glusterfs");
+ char *argv[] = { "glusterfs",
+
+#ifndef GF_DARWIN_HOST_OS
+ "-o", "nonempty",
+#endif
+ "-o", "allow_other",
+ "-o", "default_permissions",
+ "-o", source,
+ "-o", "max_readahead=1048576",
+ "-o", "max_read=1048576",
+ "-o", "max_write=1048576",
+ NULL };
+#ifdef GF_DARWIN_HOST_OS
+ int argc = 13;
+#else
+ int argc = 15;
+#endif
+
+ struct fuse_args args = FUSE_ARGS_INIT(argc,
+ argv);
+ struct fuse_private *priv = NULL;
+ int32_t res;
+
+ priv = CALLOC (1, sizeof (*priv));
+ ERR_ABORT (priv);
+
+
+ this->notify = notify;
+ this->private = (void *)priv;
+
+ priv->ch = fuse_mount (mountpoint, &args);
+ if (!priv->ch) {
+ gf_log ("glusterfs-fuse",
+ GF_LOG_ERROR, "fuse_mount failed (%s)\n", strerror (errno));
+ fuse_opt_free_args(&args);
+ goto err_free;
+ }
+
+ priv->se = fuse_lowlevel_new (&args, &fuse_ops, sizeof (fuse_ops), this);
+ fuse_opt_free_args(&args);
+
+ res = fuse_set_signal_handlers (priv->se);
+ if (res == -1) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR, "fuse_set_signal_handlers failed");
+ goto err;
+ }
+
+ fuse_session_add_chan (priv->se, priv->ch);
+
+ priv->fd = fuse_chan_fd (priv->ch);
+ this->buf = data_ref (data_from_dynptr (NULL, 0));
+ this->buf->is_locked = 1;
+
+ priv->mountpoint = mountpoint;
+
+ transport_ref (this);
+ //poll_register (this->xl_private, priv->fd, this);
+
+ return 0;
+
+ err:
+ fuse_unmount (mountpoint, priv->ch);
+ err_free:
+ FREE (mountpoint);
+ mountpoint = NULL;
+ return -1;
+}
+
+void
+guts_log_req (void *, int32_t);
+
+static void *
+fuse_thread_proc (void *data)
+{
+ transport_t *trans = data;
+ struct fuse_private *priv = trans->private;
+ int32_t res = 0;
+ data_t *buf = trans->buf;
+ int32_t ref = 0;
+ size_t chan_size = fuse_chan_bufsize (priv->ch);
+ char *recvbuf = CALLOC (1, chan_size);
+ ERR_ABORT (recvbuf);
+
+ while (!fuse_session_exited (priv->se)) {
+ int32_t fuse_chan_receive (struct fuse_chan * ch,
+ char *buf,
+ int32_t size);
+
+
+ res = fuse_chan_receive (priv->ch,
+ recvbuf,
+ chan_size);
+
+ if (res == -1) {
+ transport_disconnect (trans);
+ }
+
+ buf = trans->buf;
+
+ if (res && res != -1) {
+ if (buf->len < (res)) {
+ if (buf->data) {
+ FREE (buf->data);
+ buf->data = NULL;
+ }
+ buf->data = CALLOC (1, res);
+ ERR_ABORT (buf->data);
+ buf->len = res;
+ }
+ memcpy (buf->data, recvbuf, res); // evil evil
+ guts_log_req (buf->data, res);
+ fuse_session_process (priv->se,
+ buf->data,
+ res,
+ priv->ch);
+ }
+
+ LOCK (&buf->lock);
+ ref = buf->refcount;
+ UNLOCK (&buf->lock);
+ if (1) {
+ data_unref (buf);
+
+ trans->buf = data_ref (data_from_dynptr (NULL, 0));
+ trans->buf->is_locked = 1;
+ }
+ }
+
+ exit (0);
+
+ return NULL;
+}
+
+
+static int32_t
+fuse_transport_notify (xlator_t *xl,
+ int32_t event,
+ void *data,
+ ...)
+{
+ transport_t *trans = data;
+ struct fuse_private *priv = trans->private;
+ int32_t res = 0;
+ data_t *buf;
+ int32_t ref = 0;
+
+ if (event == GF_EVENT_POLLERR) {
+ gf_log ("glusterfs-fuse", GF_LOG_ERROR, "got GF_EVENT_POLLERR");
+ transport_disconnect (trans);
+ return -1;
+ }
+
+ if (event != GF_EVENT_POLLIN) {
+ gf_log ("glusterfs-fuse", GF_LOG_WARNING, "Ignoring notify event %d",
+ event);
+ return 0;
+ }
+
+ if (!fuse_session_exited(priv->se)) {
+ static size_t chan_size = 0;
+
+ int32_t fuse_chan_receive (struct fuse_chan * ch,
+ char *buf,
+ int32_t size);
+ if (!chan_size)
+ chan_size = fuse_chan_bufsize (priv->ch) ;
+
+ buf = trans->buf;
+
+ if (!buf->data) {
+ buf->data = MALLOC (chan_size);
+ ERR_ABORT (buf->data);
+ buf->len = chan_size;
+ }
+
+ res = fuse_chan_receive (priv->ch,
+ buf->data,
+ chan_size);
+ /* if (res == -1) {
+ transport_destroy (trans);
+ */
+ if (res && res != -1) {
+ /* trace the request and log it to tio file */
+ guts_log_req (buf->data, res);
+ fuse_session_process (priv->se,
+ buf->data,
+ res,
+ priv->ch);
+ }
+
+ LOCK (&buf->lock);
+ ref = buf->refcount;
+ UNLOCK (&buf->lock);
+ /* TODO do the check with a lock */
+ if (ref > 1) {
+ data_unref (buf);
+
+ // trans->buf = data_ref (data_from_dynptr (malloc (fuse_chan_bufsize (priv->ch)),
+ trans->buf = data_ref (data_from_dynptr (NULL, 0));
+ trans->buf->data = MALLOC (chan_size);
+ ERR_ABORT (trans->buf->data);
+ trans->buf->len = chan_size;
+ trans->buf->is_locked = 1;
+ }
+ } else {
+ transport_disconnect (trans);
+ }
+
+ /*
+ if (fuse_session_exited (priv->se)) {
+ transport_destroy (trans);
+ res = -1;
+ }*/
+
+ return res >= 0 ? 0 : res;
+}
+
+static void
+fuse_transport_fini (transport_t *this)
+{
+
+}
+
+static struct transport_ops fuse_transport_ops = {
+ .disconnect = fuse_transport_disconnect,
+};
+
+static transport_t fuse_transport = {
+ .ops = &fuse_transport_ops,
+ .private = NULL,
+ .xl = NULL,
+ .init = fuse_transport_init,
+ .fini = fuse_transport_fini,
+ .notify = fuse_transport_notify
+};
+
+
+transport_t *
+glusterfs_mount (glusterfs_ctx_t *ctx,
+ const char *mount_point)
+{
+ dict_t *options = get_new_dict ();
+ transport_t *new_fuse = CALLOC (1, sizeof (*new_fuse));
+ ERR_ABORT (new_fuse);
+
+ memcpy (new_fuse, &fuse_transport, sizeof (*new_fuse));
+ new_fuse->ops = &fuse_transport_ops;
+ new_fuse->xl_private = ctx;
+
+ dict_set (options,
+ "mountpoint",
+ str_to_data ((char *)mount_point));
+
+ return (new_fuse->init (new_fuse,
+ options,
+ fuse_transport_notify) == 0 ? new_fuse : NULL);
+}
+
+int32_t
+fuse_thread (pthread_t *thread, void *data)
+{
+ return pthread_create (thread, NULL, fuse_thread_proc, data);
+}
+
+
diff --git a/glusterfs-guts/src/fuse-extra.c b/glusterfs-guts/src/fuse-extra.c
new file mode 100644
index 000000000..93574d174
--- /dev/null
+++ b/glusterfs-guts/src/fuse-extra.c
@@ -0,0 +1,137 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif /* _CONFIG_H */
+
+#include "fuse-extra.h"
+#include "common-utils.h"
+#include <stdio.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common-utils.h"
+
+struct fuse_req;
+struct fuse_ll;
+
+struct fuse_req {
+ struct fuse_ll *f;
+ uint64_t unique;
+ int ctr;
+ pthread_mutex_t lock;
+ struct fuse_ctx ctx;
+ struct fuse_chan *ch;
+ int interrupted;
+ union {
+ struct {
+ uint64_t unique;
+ } i;
+ struct {
+ fuse_interrupt_func_t func;
+ void *data;
+ } ni;
+ } u;
+ struct fuse_req *next;
+ struct fuse_req *prev;
+};
+
+struct fuse_ll {
+ int debug;
+ int allow_root;
+ struct fuse_lowlevel_ops op;
+ int got_init;
+ void *userdata;
+ uid_t owner;
+ struct fuse_conn_info conn;
+ struct fuse_req list;
+ struct fuse_req interrupts;
+ pthread_mutex_t lock;
+ int got_destroy;
+};
+
+struct fuse_out_header {
+ uint32_t len;
+ int32_t error;
+ uint64_t unique;
+};
+
+uint64_t req_callid (fuse_req_t req)
+{
+ return req->unique;
+}
+
+static void destroy_req(fuse_req_t req)
+{
+ pthread_mutex_destroy (&req->lock);
+ FREE (req);
+}
+
+static void list_del_req(struct fuse_req *req)
+{
+ struct fuse_req *prev = req->prev;
+ struct fuse_req *next = req->next;
+ prev->next = next;
+ next->prev = prev;
+}
+
+static void
+free_req (fuse_req_t req)
+{
+ int ctr;
+ struct fuse_ll *f = req->f;
+
+ pthread_mutex_lock(&req->lock);
+ req->u.ni.func = NULL;
+ req->u.ni.data = NULL;
+ pthread_mutex_unlock(&req->lock);
+
+ pthread_mutex_lock(&f->lock);
+ list_del_req(req);
+ ctr = --req->ctr;
+ pthread_mutex_unlock(&f->lock);
+ if (!ctr)
+ destroy_req(req);
+}
+
+int32_t
+fuse_reply_vec (fuse_req_t req,
+ struct iovec *vector,
+ int32_t count)
+{
+ int32_t error = 0;
+ struct fuse_out_header out;
+ struct iovec *iov;
+ int res;
+
+ iov = alloca ((count + 1) * sizeof (*vector));
+ out.unique = req->unique;
+ out.error = error;
+ iov[0].iov_base = &out;
+ iov[0].iov_len = sizeof(struct fuse_out_header);
+ memcpy (&iov[1], vector, count * sizeof (*vector));
+ count++;
+ out.len = iov_length(iov, count);
+ res = fuse_chan_send(req->ch, iov, count);
+ free_req(req);
+
+ return res;
+}
diff --git a/glusterfs-guts/src/fuse-extra.h b/glusterfs-guts/src/fuse-extra.h
new file mode 100644
index 000000000..c7d2877c0
--- /dev/null
+++ b/glusterfs-guts/src/fuse-extra.h
@@ -0,0 +1,38 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _FUSE_EXTRA_H
+#define _FUSE_EXTRA_H
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif /* _CONFIG_H */
+
+#include <stdlib.h>
+#include <fuse/fuse_lowlevel.h>
+
+uint64_t req_callid (fuse_req_t req);
+
+int32_t
+fuse_reply_vec (fuse_req_t req,
+ struct iovec *vector,
+ int32_t count);
+
+#endif /* _FUSE_EXTRA_H */
diff --git a/glusterfs-guts/src/fuse_kernel.h b/glusterfs-guts/src/fuse_kernel.h
new file mode 100644
index 000000000..7ebff8b22
--- /dev/null
+++ b/glusterfs-guts/src/fuse_kernel.h
@@ -0,0 +1,380 @@
+/*
+ FUSE: Filesystem in Userspace
+ Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
+
+ This program can be distributed under the terms of the GNU GPL.
+ See the file COPYING.
+*/
+
+/* This file defines the kernel interface of FUSE */
+
+#ifdef __FreeBSD__
+/*
+ This -- and only this -- header file may also be distributed under
+ the terms of the BSD Licence as follows:
+
+ Copyright (C) 2001-2006 Miklos Szeredi. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+#include <sys/types.h>
+#define __u64 uint64_t
+#define __u32 uint32_t
+#define __s32 int32_t
+#else
+#include <asm/types.h>
+#include <linux/major.h>
+#endif
+
+/** Version number of this interface */
+#define FUSE_KERNEL_VERSION 7
+
+/** Minor version number of this interface */
+#define FUSE_KERNEL_MINOR_VERSION 8
+
+/** The node ID of the root inode */
+#define FUSE_ROOT_ID 1
+
+/** The major number of the fuse character device */
+#define FUSE_MAJOR MISC_MAJOR
+
+/** The minor number of the fuse character device */
+#define FUSE_MINOR 229
+
+/* Make sure all structures are padded to 64bit boundary, so 32bit
+ userspace works under 64bit kernels */
+
+struct fuse_attr {
+ __u64 ino;
+ __u64 size;
+ __u64 blocks;
+ __u64 atime;
+ __u64 mtime;
+ __u64 ctime;
+ __u32 atimensec;
+ __u32 mtimensec;
+ __u32 ctimensec;
+ __u32 mode;
+ __u32 nlink;
+ __u32 uid;
+ __u32 gid;
+ __u32 rdev;
+};
+
+struct fuse_kstatfs {
+ __u64 blocks;
+ __u64 bfree;
+ __u64 bavail;
+ __u64 files;
+ __u64 ffree;
+ __u32 bsize;
+ __u32 namelen;
+ __u32 frsize;
+ __u32 padding;
+ __u32 spare[6];
+};
+
+struct fuse_file_lock {
+ __u64 start;
+ __u64 end;
+ __u32 type;
+ __u32 pid; /* tgid */
+};
+
+/**
+ * Bitmasks for fuse_setattr_in.valid
+ */
+#define FATTR_MODE (1 << 0)
+#define FATTR_UID (1 << 1)
+#define FATTR_GID (1 << 2)
+#define FATTR_SIZE (1 << 3)
+#define FATTR_ATIME (1 << 4)
+#define FATTR_MTIME (1 << 5)
+#define FATTR_FH (1 << 6)
+
+/**
+ * Flags returned by the OPEN request
+ *
+ * FOPEN_DIRECT_IO: bypass page cache for this open file
+ * FOPEN_KEEP_CACHE: don't invalidate the data cache on open
+ */
+#define FOPEN_DIRECT_IO (1 << 0)
+#define FOPEN_KEEP_CACHE (1 << 1)
+
+/**
+ * INIT request/reply flags
+ */
+#define FUSE_ASYNC_READ (1 << 0)
+#define FUSE_POSIX_LOCKS (1 << 1)
+
+/**
+ * Release flags
+ */
+#define FUSE_RELEASE_FLUSH (1 << 0)
+
+enum fuse_opcode {
+ FUSE_LOOKUP = 1,
+ FUSE_FORGET = 2, /* no reply */
+ FUSE_GETATTR = 3,
+ FUSE_SETATTR = 4,
+ FUSE_READLINK = 5,
+ FUSE_SYMLINK = 6,
+ FUSE_MKNOD = 8,
+ FUSE_MKDIR = 9,
+ FUSE_UNLINK = 10,
+ FUSE_RMDIR = 11,
+ FUSE_RENAME = 12,
+ FUSE_LINK = 13,
+ FUSE_OPEN = 14,
+ FUSE_READ = 15,
+ FUSE_WRITE = 16,
+ FUSE_STATFS = 17,
+ FUSE_RELEASE = 18,
+ FUSE_FSYNC = 20,
+ FUSE_SETXATTR = 21,
+ FUSE_GETXATTR = 22,
+ FUSE_LISTXATTR = 23,
+ FUSE_REMOVEXATTR = 24,
+ FUSE_FLUSH = 25,
+ FUSE_INIT = 26,
+ FUSE_OPENDIR = 27,
+ FUSE_READDIR = 28,
+ FUSE_RELEASEDIR = 29,
+ FUSE_FSYNCDIR = 30,
+ FUSE_GETLK = 31,
+ FUSE_SETLK = 32,
+ FUSE_SETLKW = 33,
+ FUSE_ACCESS = 34,
+ FUSE_CREATE = 35,
+ FUSE_INTERRUPT = 36,
+ FUSE_BMAP = 37,
+ FUSE_DESTROY = 38,
+};
+
+/* The read buffer is required to be at least 8k, but may be much larger */
+#define FUSE_MIN_READ_BUFFER 8192
+
+struct fuse_entry_out {
+ __u64 nodeid; /* Inode ID */
+ __u64 generation; /* Inode generation: nodeid:gen must
+ be unique for the fs's lifetime */
+ __u64 entry_valid; /* Cache timeout for the name */
+ __u64 attr_valid; /* Cache timeout for the attributes */
+ __u32 entry_valid_nsec;
+ __u32 attr_valid_nsec;
+ struct fuse_attr attr;
+};
+
+struct fuse_forget_in {
+ __u64 nlookup;
+};
+
+struct fuse_attr_out {
+ __u64 attr_valid; /* Cache timeout for the attributes */
+ __u32 attr_valid_nsec;
+ __u32 dummy;
+ struct fuse_attr attr;
+};
+
+struct fuse_mknod_in {
+ __u32 mode;
+ __u32 rdev;
+};
+
+struct fuse_mkdir_in {
+ __u32 mode;
+ __u32 padding;
+};
+
+struct fuse_rename_in {
+ __u64 newdir;
+};
+
+struct fuse_link_in {
+ __u64 oldnodeid;
+};
+
+struct fuse_setattr_in {
+ __u32 valid;
+ __u32 padding;
+ __u64 fh;
+ __u64 size;
+ __u64 unused1;
+ __u64 atime;
+ __u64 mtime;
+ __u64 unused2;
+ __u32 atimensec;
+ __u32 mtimensec;
+ __u32 unused3;
+ __u32 mode;
+ __u32 unused4;
+ __u32 uid;
+ __u32 gid;
+ __u32 unused5;
+};
+
+struct fuse_open_in {
+ __u32 flags;
+ __u32 mode;
+};
+
+struct fuse_open_out {
+ __u64 fh;
+ __u32 open_flags;
+ __u32 padding;
+};
+
+struct fuse_release_in {
+ __u64 fh;
+ __u32 flags;
+ __u32 release_flags;
+ __u64 lock_owner;
+};
+
+struct fuse_flush_in {
+ __u64 fh;
+ __u32 unused;
+ __u32 padding;
+ __u64 lock_owner;
+};
+
+struct fuse_read_in {
+ __u64 fh;
+ __u64 offset;
+ __u32 size;
+ __u32 padding;
+};
+
+struct fuse_write_in {
+ __u64 fh;
+ __u64 offset;
+ __u32 size;
+ __u32 write_flags;
+};
+
+struct fuse_write_out {
+ __u32 size;
+ __u32 padding;
+};
+
+#define FUSE_COMPAT_STATFS_SIZE 48
+
+struct fuse_statfs_out {
+ struct fuse_kstatfs st;
+};
+
+struct fuse_fsync_in {
+ __u64 fh;
+ __u32 fsync_flags;
+ __u32 padding;
+};
+
+struct fuse_setxattr_in {
+ __u32 size;
+ __u32 flags;
+};
+
+struct fuse_getxattr_in {
+ __u32 size;
+ __u32 padding;
+};
+
+struct fuse_getxattr_out {
+ __u32 size;
+ __u32 padding;
+};
+
+struct fuse_lk_in {
+ __u64 fh;
+ __u64 owner;
+ struct fuse_file_lock lk;
+};
+
+struct fuse_lk_out {
+ struct fuse_file_lock lk;
+};
+
+struct fuse_access_in {
+ __u32 mask;
+ __u32 padding;
+};
+
+struct fuse_init_in {
+ __u32 major;
+ __u32 minor;
+ __u32 max_readahead;
+ __u32 flags;
+};
+
+struct fuse_init_out {
+ __u32 major;
+ __u32 minor;
+ __u32 max_readahead;
+ __u32 flags;
+ __u32 unused;
+ __u32 max_write;
+};
+
+struct fuse_interrupt_in {
+ __u64 unique;
+};
+
+struct fuse_bmap_in {
+ __u64 block;
+ __u32 blocksize;
+ __u32 padding;
+};
+
+struct fuse_bmap_out {
+ __u64 block;
+};
+
+struct fuse_in_header {
+ __u32 len;
+ __u32 opcode;
+ __u64 unique;
+ __u64 nodeid;
+ __u32 uid;
+ __u32 gid;
+ __u32 pid;
+ __u32 padding;
+};
+
+struct fuse_out_header {
+ __u32 len;
+ __s32 error;
+ __u64 unique;
+};
+
+struct fuse_dirent {
+ __u64 ino;
+ __u64 off;
+ __u32 namelen;
+ __u32 type;
+ char name[0];
+};
+
+#define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
+#define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1))
+#define FUSE_DIRENT_SIZE(d) \
+ FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
diff --git a/glusterfs-guts/src/glusterfs-fuse.h b/glusterfs-guts/src/glusterfs-fuse.h
new file mode 100644
index 000000000..f446202fb
--- /dev/null
+++ b/glusterfs-guts/src/glusterfs-fuse.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __GLUSTERFS_FUSE_H__
+#define __GLUSTERFS_FUSE_H__
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif /* _CONFIG_H */
+
+#define DEFAULT_LOG_FILE DATADIR"/log/glusterfs/glusterfs.log"
+#define DEFAULT_GLUSTERFS_CLIENT_VOL CONFDIR "/glusterfs-client.vol"
+
+#define SPEC_LOCAL_FILE 1
+#define SPEC_REMOTE_FILE 2
+
+#if 0
+#define GF_YES 1
+#define GF_NO 0
+#endif
+
+#ifdef GF_LOG_FUSE_ARGS
+#undef GF_LOG_FUSE_ARGS
+#endif
+
+struct gf_spec_location {
+ int32_t where;
+ union {
+ char *file;
+ struct {
+ char *ip;
+ char *port;
+ char *transport;
+ }server;
+ }spec;
+};
+
+transport_t * glusterfs_mount (glusterfs_ctx_t *ctx,
+ const char *mount_point);
+
+#endif /* __GLUSTERFS_FUSE_H__ */
diff --git a/glusterfs-guts/src/glusterfs-guts.c b/glusterfs-guts/src/glusterfs-guts.c
new file mode 100644
index 000000000..3efac3a35
--- /dev/null
+++ b/glusterfs-guts/src/glusterfs-guts.c
@@ -0,0 +1,400 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <argp.h>
+#include <string.h>
+
+#include "glusterfs.h"
+#include "xlator.h"
+#include "glusterfs-guts.h"
+
+/* argp initializations */
+static char doc[] = "glusterfs-guts is unit testing suite for glusterfs";
+static char argp_doc[] = "";
+const char *argp_program_version = PACKAGE_NAME " " PACKAGE_VERSION " built on " __DATE__;
+const char *argp_program_bug_address = PACKAGE_BUGREPORT;
+
+guts_ctx_t guts_ctx;
+error_t parse_opts (int32_t key, char *arg, struct argp_state *_state);
+
+static struct argp_option options[] = {
+ {"spec-file", 'f', "VOLUMESPEC-FILE", 0,\
+ "Load VOLUMESPEC-FILE."},
+ {"threads", 't', "NUMBER", 0,\
+ "Load NUMBER of threads."},
+ {"tio-file", 'i', "FILE", 0,\
+ "Replay fops from FILE."},
+ {"tio-directory", 'I', "DIRECTORY", 0,\
+ "Replay fops from files in DIRECTORY. Valid option only when using more than one thread."},
+ {"log-level", 'L', "LOGLEVEL", 0,
+ "LOGLEVEL should be one of DEBUG, WARNING, [ERROR], CRITICAL, NONE"},
+ {"log-file", 'l', "LOGFILE", 0, \
+ "Specify the file to redirect logs"},
+ {"trace", 'T', "MOUNTPOINT", 0, \
+ "Run guts in trace mode. Guts mounts glusterfs on MOUNTPOINT specified"},
+ {"output", 'o', "OUTPUT-TIOFILE", 0, \
+ "Write trace io output to OUTPUT-TIOFILE. Valid only when run in trace(-T) mode."},
+ {"version", 'V', 0, 0,\
+ "print version information"},
+ { 0, }
+};
+
+static struct argp argp = { options, parse_opts, argp_doc, doc };
+
+/* guts_print_version - used by argument parser routine to print version information for guts */
+static int32_t
+guts_print_version (void)
+{
+ printf ("%s\n", argp_program_version);
+ printf ("Copyright (c) 2006, 2007 Z RESEARCH Inc. <http://www.zresearch.com>\n");
+ printf ("GlusterFS comes with ABSOLUTELY NO WARRANTY.\nYou may redistribute copies of GlusterFS under the terms of the GNU General Public License.\n");
+ exit (0);
+}
+
+/* parse_opts - argument parsing helper routine for argp library */
+error_t
+parse_opts (int32_t key, char *arg, struct argp_state *_state)
+{
+ guts_ctx_t *state = _state->input;
+
+ switch (key) {
+ case 'f':
+ if (!state->specfile) {
+ state->specfile = strdup (arg);
+ }
+ break;
+
+ case 't':
+ if (!state->threads) {
+ state->threads = strtol (arg, NULL, 0);
+ }
+ break;
+
+ case 'i':
+ if (state->threads == 1) {
+ state->file = strdup (arg);
+ } else {
+ fprintf (stderr, "glusterfs-guts: -i option is valid only when guts is running single thread\n");
+ exit (1);
+ }
+ break;
+
+ case 'I':
+ if (state->threads > 1) {
+ state->directory = strdup (arg);
+ } else {
+ fprintf (stderr, "glusterfs-guts: -I option is valid only when guts is running multiple threads\n");
+ exit (1);
+ }
+ break;
+
+ case 'L':
+ /* set log level */
+ if (!strncasecmp (arg, "DEBUG", strlen ("DEBUG"))) {
+ state->loglevel = GF_LOG_DEBUG;
+ } else if (!strncasecmp (arg, "WARNING", strlen ("WARNING"))) {
+ state->loglevel = GF_LOG_WARNING;
+ } else if (!strncasecmp (arg, "CRITICAL", strlen ("CRITICAL"))) {
+ state->loglevel = GF_LOG_CRITICAL;
+ } else if (!strncasecmp (arg, "NONE", strlen ("NONE"))) {
+ state->loglevel = GF_LOG_NONE;
+ } else if (!strncasecmp (arg, "ERROR", strlen ("ERROR"))) {
+ state->loglevel = GF_LOG_ERROR;
+ } else {
+ fprintf (stderr, "glusterfs-guts: Unrecognized log-level \"%s\", possible values are \"DEBUG|WARNING|[ERROR]|CRITICAL|NONE\"\n", arg);
+ exit (EXIT_FAILURE);
+ }
+ break;
+ case 'l':
+ /* set log file */
+ state->logfile = strdup (arg);
+ break;
+
+ case 'T':
+ state->trace = 1;
+ state->mountpoint = strdup (arg);
+ break;
+
+ case 'o':
+ state->file = strdup (arg);
+ break;
+
+ case 'V':
+ guts_print_version ();
+ break;
+
+ }
+ return 0;
+}
+
+/* get_xlator_graph - creates a translator graph and returns the pointer to the root of the xlator tree
+ *
+ * @ctx: guts context structure
+ * @conf: file handle to volume specfile
+ *
+ * returns pointer to the root of the translator tree
+ */
+static xlator_t *
+get_xlator_graph (glusterfs_ctx_t *ctx,
+ FILE *conf)
+{
+ xlator_t *tree, *trav = NULL;
+
+ tree = file_to_xlator_tree (ctx, conf);
+ trav = tree;
+
+ if (tree == NULL) {
+ gf_log ("glusterfs-guts",
+ GF_LOG_ERROR,
+ "specification file parsing failed, exiting");
+ return NULL;
+ }
+
+ tree = trav;
+
+ return tree;
+}
+
+/* get_spec_fp - get file handle to volume spec file specified.
+ *
+ * @ctx: guts context structure
+ *
+ * returns FILE pointer to the volume spec file.
+ */
+static FILE *
+get_spec_fp (guts_ctx_t *ctx)
+{
+ char *specfile = ctx->specfile;
+ FILE *conf = NULL;
+
+ specfile = ctx->specfile;
+
+ conf = fopen (specfile, "r");
+
+ if (!conf) {
+ perror (specfile);
+ return NULL;
+ }
+ gf_log ("glusterfs-guts",
+ GF_LOG_DEBUG,
+ "loading spec from %s",
+ specfile);
+
+ return conf;
+}
+
+static void *
+guts_thread_main (void *ctx)
+{
+ guts_thread_ctx_t *tctx = (guts_thread_ctx_t *) ctx;
+
+ printf ("starting thread main with %s:\n", tctx->file);
+ guts_replay (tctx);
+ printf ("ending thread main.\n");
+
+ return NULL;
+}
+
+/* guts_create_threads - creates different threads based on thread number specified in ctx and assigns a
+ * tio file to each thread and attaches each thread to the graph created by main().
+ * @ctx: guts_ctx_t which contains the context corresponding to the current run of guts
+ *
+ * returns the guts_threads_t structure which contains handles to the different threads created.
+ *
+ */
+static guts_threads_t *
+guts_create_threads (guts_ctx_t *ctx)
+{
+ guts_threads_t *threads = NULL;
+ int32_t thread_count = ctx->threads;
+
+ threads = CALLOC (1, sizeof (*threads));
+ ERR_ABORT (threads);
+
+
+ INIT_LIST_HEAD (&(threads->threads));
+
+ if (thread_count == 1) {
+ /* special case: we have only one thread and we are given a tio-file as argument instead of a directory.
+ * handling differently */
+ guts_thread_ctx_t *thread = NULL;
+ thread = CALLOC (1, sizeof (*thread));
+ ERR_ABORT (thread);
+ list_add (&thread->threads, &threads->threads);
+ thread->file = strdup (ctx->file);
+ thread->ctx = ctx;
+ } else {
+ /* look for .tio files in the directory given and assign to each of the threads */
+ DIR *dir = opendir (ctx->directory);
+
+ if (!dir) {
+ gf_log ("guts",
+ GF_LOG_ERROR,
+ "failed to open directory %s", ctx->directory);
+ } else {
+ guts_thread_ctx_t *thread = NULL;
+ struct dirent *dirp = NULL;
+ /* to pass through "." and ".." */
+ readdir (dir);
+ readdir (dir);
+
+ while (thread_count > 0) {
+ char pathname[256] = {0,};
+
+ thread = CALLOC (1, sizeof (*thread));
+ ERR_ABORT (thread);
+ dirp = NULL;
+
+ list_add (&thread->threads, &threads->threads);
+ dirp = readdir (dir);
+ if (dirp) {
+ sprintf (pathname, "%s/%s", ctx->directory, dirp->d_name);
+ printf ("file name for thread(%d) is %s\n", thread_count, pathname);
+ thread->file = strdup (pathname);
+ thread->ctx = ctx;
+ } else if (thread_count > 0) {
+ gf_log ("guts",
+ GF_LOG_ERROR,
+ "number of tio files less than %d, number of threads specified", ctx->threads);
+ /* TODO: cleanup */
+ return NULL;
+ }
+ --thread_count;
+ }
+ }
+ }
+ return threads;
+}
+
+/* guts_start_threads - starts all the threads in @threads.
+ *
+ * @threads: guts_threads_t structure containing the handles to threads created by guts_create_threads.
+ *
+ * returns <0 on error.
+ *
+ */
+static void
+guts_start_threads (guts_threads_t *gthreads)
+{
+ guts_thread_ctx_t *thread = NULL;
+ list_for_each_entry (thread, &gthreads->threads, threads) {
+ if (pthread_create (&thread->pthread, NULL, guts_thread_main, (void *)thread) < 0) {
+ gf_log ("guts",
+ GF_LOG_ERROR,
+ "failed to start thread");
+ } else {
+ gf_log ("guts",
+ GF_LOG_DEBUG,
+ "started thread with file %s", thread->file);
+ }
+ }
+}
+
+static int32_t
+guts_join_threads (guts_threads_t *gthreads)
+{
+ guts_thread_ctx_t *thread = NULL;
+ list_for_each_entry (thread, &gthreads->threads, threads) {
+ if (pthread_join (thread->pthread, NULL) < 0) {
+ gf_log ("guts",
+ GF_LOG_ERROR,
+ "failed to join thread");
+ } else {
+ gf_log ("guts",
+ GF_LOG_DEBUG,
+ "joined thread with file %s", thread->file);
+ }
+ }
+ return 0;
+}
+
+
+int32_t
+main (int32_t argc, char *argv[])
+{
+ /* glusterfs_ctx_t is required to be passed to
+ * 1. get_xlator_graph
+ * 2. glusterfs_mount
+ */
+ glusterfs_ctx_t gfs_ctx = {
+ .logfile = DATADIR "/log/glusterfs/glusterfs-guts.log",
+ .loglevel = GF_LOG_DEBUG,
+ .poll_type = SYS_POLL_TYPE_EPOLL,
+ };
+
+ guts_ctx_t guts_ctx = {0,};
+ FILE *specfp = NULL;
+ xlator_t *graph = NULL;
+ guts_threads_t *threads = NULL;
+
+ argp_parse (&argp, argc, argv, 0, 0, &guts_ctx);
+
+ if (gf_log_init (gfs_ctx.logfile) == -1 ) {
+ fprintf (stderr,
+ "glusterfs-guts: failed to open logfile \"%s\"\n",
+ gfs_ctx.logfile);
+ return -1;
+ }
+ gf_log_set_loglevel (gfs_ctx.loglevel);
+
+ specfp = get_spec_fp (&guts_ctx);
+ if (!specfp) {
+ fprintf (stderr,
+ "glusterfs-guts: could not open specfile\n");
+ return -1;
+ }
+
+ graph = get_xlator_graph (&gfs_ctx, specfp);
+ if (!graph) {
+ gf_log ("guts", GF_LOG_ERROR,
+ "Unable to get xlator graph");
+ return -1;
+ }
+ fclose (specfp);
+
+ guts_ctx.graph = graph;
+
+ if (guts_ctx.trace) {
+ return guts_trace (&guts_ctx);
+ } else {
+ /* now that we have the xlator graph, we need to create as many threads as requested and assign a tio file
+ * to each of the threads and tell each thread to attach to the graph we just created. */
+
+ if (!guts_ctx.file && !guts_ctx.directory) {
+ fprintf (stderr,
+ "glusterfs-guts: no tio file specified");
+ return -1;
+ }
+
+ threads = guts_create_threads (&guts_ctx);
+
+ if (threads) {
+ guts_start_threads (threads);
+ guts_join_threads (threads);
+ } else {
+ gf_log ("guts", GF_LOG_ERROR,
+ "unable to create threads");
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
diff --git a/glusterfs-guts/src/glusterfs-guts.h b/glusterfs-guts/src/glusterfs-guts.h
new file mode 100644
index 000000000..eda1788a9
--- /dev/null
+++ b/glusterfs-guts/src/glusterfs-guts.h
@@ -0,0 +1,62 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __GLUSTERFS_GUTS_H
+#define __GLUSTERFS_GUTS_H
+
+#include "xlator.h"
+#include "transport.h"
+#include "glusterfs.h"
+#include "glusterfs-fuse.h"
+#include "timer.h"
+
+#ifdef DEFAULT_LOG_FILE
+#undef DEFAULT_LOG_FILE
+#endif
+
+#define DEFAULT_LOG_FILE DATADIR"/log/glusterfs/glusterfs-guts.log"
+
+
+typedef struct {
+ int32_t threads; /* number of threads to start in replay mode */
+ char *logfile; /* logfile path */
+ int32_t loglevel; /* logging level */
+ char *directory; /* path to directory containing tio files, when threads > 1 */
+ char *file; /* path to tio file, when threads == 1 during replay. in trace mode, path to tio output */
+ char *specfile; /* path to specfile to load translator tree */
+ xlator_t *graph; /* translator tree after the specfile is loaded */
+ int32_t trace; /* if trace == 1, glusterfs-guts runs in trace mode, otherwise in replay mode */
+ char *mountpoint; /* valid only when trace == 1, mounpoint to mount glusterfs */
+} guts_ctx_t;
+
+
+typedef struct {
+ struct list_head threads;
+ pthread_t pthread;
+ xlator_t *tree;
+ char *file;
+ guts_ctx_t *ctx;
+} guts_thread_ctx_t;
+
+typedef struct {
+ struct list_head threads;
+} guts_threads_t;
+
+int32_t guts_replay (guts_thread_ctx_t *);
+int32_t guts_trace (guts_ctx_t *);
+#endif
diff --git a/glusterfs-guts/src/guts-extra.c b/glusterfs-guts/src/guts-extra.c
new file mode 100644
index 000000000..dd4ad466f
--- /dev/null
+++ b/glusterfs-guts/src/guts-extra.c
@@ -0,0 +1,18 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
diff --git a/glusterfs-guts/src/guts-lowlevel.h b/glusterfs-guts/src/guts-lowlevel.h
new file mode 100644
index 000000000..498b5d01e
--- /dev/null
+++ b/glusterfs-guts/src/guts-lowlevel.h
@@ -0,0 +1,86 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _GUTS_LOWLEVEL_H_
+#define _GUTS_LOWLEVEL_H_
+
+int
+guts_reply_err (fuse_req_t req,
+ int err);
+
+int
+guts_reply_none (fuse_req_t req);
+
+int
+guts_reply_entry (fuse_req_t req,
+ const struct fuse_entry_param *e);
+
+int
+guts_reply_create (fuse_req_t req,
+ const struct fuse_entry_param *e,
+ const struct fuse_file_info *f);
+
+int
+guts_reply_attr (fuse_req_t req,
+ const struct stat *attr,
+ double attr_timeout);
+
+int
+guts_reply_readlink (fuse_req_t req,
+ const char *linkname);
+
+int
+guts_reply_open (fuse_req_t req,
+ const struct fuse_file_info *f);
+
+int
+guts_reply_write (fuse_req_t req,
+ size_t count);
+
+int
+guts_reply_buf (fuse_req_t req,
+ const char *buf,
+ size_t size);
+
+int
+guts_reply_statfs (fuse_req_t req,
+ const struct statvfs *stbuf);
+
+int
+guts_reply_xattr (fuse_req_t req,
+ size_t count);
+
+int
+guts_reply_lock (fuse_req_t req,
+ struct flock *lock);
+
+/* exploiting the macros to reduce coding work ;) */
+#define fuse_reply_entry guts_reply_entry
+#define fuse_reply_err guts_reply_err
+#define fuse_reply_none guts_reply_none
+#define fuse_reply_attr guts_reply_attr
+#define fuse_reply_open guts_reply_open
+#define fuse_reply_readlink guts_reply_readlink
+#define fuse_reply_create guts_reply_create
+#define fuse_reply_write guts_reply_write
+#define fuse_reply_buf guts_reply_buf
+#define fuse_reply_statfs guts_reply_statfs
+#define fuse_reply_xattr guts_reply_xattr
+#define fuse_reply_lock guts_reply_lock
+
+#endif
diff --git a/glusterfs-guts/src/guts-parse.c b/glusterfs-guts/src/guts-parse.c
new file mode 100644
index 000000000..dd17a737e
--- /dev/null
+++ b/glusterfs-guts/src/guts-parse.c
@@ -0,0 +1,217 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "guts-parse.h"
+#include "guts-tables.h"
+
+/* unavoidable usage of global data.. :'( */
+static int32_t tio_fd = 0;
+
+int32_t
+guts_tio_init (const char *filename)
+{
+ tio_fd = open (filename, O_WRONLY | O_CREAT);
+
+ if (tio_fd < 0) {
+ gf_log ("guts",
+ GF_LOG_ERROR,
+ "failed to open tio file %s", filename);
+ }
+
+ return tio_fd;
+}
+
+void
+guts_reply_dump (fuse_req_t req,
+ const void *arg,
+ int32_t len)
+{
+ uint8_t *buf = NULL;
+ uint8_t *ibuf = NULL;
+ uint32_t buf_size = REP_HEADER_FULL_LEN + len;
+
+ ibuf = buf = CALLOC (1, buf_size);
+
+ /* being paranoid, checking for both ibuf and buf.. ;) */
+ if (ibuf && buf) {
+ memcpy (ibuf, REP_BEGIN, strlen (REP_BEGIN));
+ ibuf += strlen (REP_BEGIN);
+ memcpy (ibuf, req, sizeof (struct fuse_req));
+ ibuf += sizeof (struct fuse_req);
+ memcpy (ibuf, &len, sizeof (len));
+ ibuf += sizeof (len);
+ memcpy (ibuf, arg, len);
+
+ gf_full_write (tio_fd, buf, buf_size);
+
+ free (buf);
+ } else {
+ gf_log ("glusterfs-guts", GF_LOG_DEBUG,
+ "failed to allocate memory while dumping reply");
+ }
+}
+
+void
+guts_req_dump (struct fuse_in_header *in,
+ const void *arg,
+ int32_t len)
+{
+ /* GUTS_REQUEST_BEGIN:<fuse_in_header>:<arg-len>:<args>:GUTS_REQUEST_END */
+ uint8_t *buf = NULL;
+ uint8_t *ibuf = NULL;
+ uint32_t buf_size = REQ_HEADER_FULL_LEN + len;
+
+ ibuf = buf = CALLOC (1, buf_size);
+
+ if (ibuf && buf) {
+ memcpy (ibuf, REQ_BEGIN, strlen (REQ_BEGIN));
+ ibuf += strlen (REQ_BEGIN);
+ memcpy (ibuf, in, sizeof (*in));
+ ibuf += sizeof (*in);
+ memcpy (ibuf, &len, sizeof (len));
+ ibuf += sizeof (len);
+ memcpy (ibuf, arg, len);
+
+ gf_full_write (tio_fd, buf, buf_size);
+
+ free (buf);
+ } else {
+ gf_log ("glusterfs-guts", GF_LOG_DEBUG,
+ "failed to allocate memory while dumping reply");
+ }
+}
+
+
+
+guts_req_t *
+guts_read_entry (guts_replay_ctx_t *ctx)
+{
+ guts_req_t *req = NULL;
+ guts_reply_t *reply = NULL;
+ uint8_t begin[256] = {0,};
+ int32_t ret = 0;
+ int32_t fd = ctx->tio_fd;
+
+ while (!req) {
+ req = guts_get_request (ctx);
+
+ if (!req) {
+ ret = read (fd, begin, strlen (REQ_BEGIN));
+
+ if (ret == 0) {
+ gf_log ("glusterfs-guts", GF_LOG_DEBUG,
+ "guts replay finished");
+ req = NULL;
+ }
+
+ if (is_request (begin)) {
+ req = CALLOC (1, sizeof (*req));
+ ERR_ABORT (req);
+ gf_full_read (fd, (char *)req, REQ_HEADER_LEN);
+
+ req->arg = CALLOC (1, req->arg_len + 1);
+ ERR_ABORT (req->arg);
+ gf_full_read (fd, req->arg, req->arg_len);
+ gf_log ("guts",
+ GF_LOG_DEBUG,
+ "%s: fop %s (%d)\n",
+ begin, guts_log[req->header.opcode].name, req->header.opcode);
+ guts_add_request (ctx, req);
+ req = guts_get_request (ctx);
+ } else {
+ /* whenever a reply is read, we put it to a hash table and we would like to retrieve it whenever
+ * we get a reply for any call
+ */
+ reply = CALLOC (1, sizeof (*reply));
+ ERR_ABORT (reply);
+ gf_full_read (fd, (char *)reply, REP_HEADER_LEN);
+
+ reply->arg = CALLOC (1, reply->arg_len + 1);
+ ERR_ABORT (reply->arg);
+ gf_full_read (fd, reply->arg, reply->arg_len);
+
+ /* add a new reply to */
+ ret = guts_add_reply (ctx, reply);
+ gf_log ("guts",
+ GF_LOG_DEBUG,
+ "got a reply with unique: %ld", reply->req.unique);
+ }
+ }
+ }
+ return req;
+}
+
+guts_reply_t *
+guts_read_reply (guts_replay_ctx_t *ctx,
+ uint64_t unique)
+{
+ guts_req_t *req = NULL;
+ guts_reply_t *reply = NULL, *rep = NULL;
+ uint8_t begin[256] = {0,};
+ int32_t ret = 0;
+ int32_t fd = ctx->tio_fd;
+
+ while (!rep) {
+
+ ret = read (fd, begin, strlen (REQ_BEGIN));
+
+ if (ret == 0) {
+ printf ("\ndone\n");
+ return NULL;
+ }
+
+ if (is_request (begin)) {
+ req = CALLOC (1, sizeof (*req));
+ ERR_ABORT (req);
+ gf_full_read (fd, (char *)req, REQ_HEADER_LEN);
+
+ req->arg = CALLOC (1, req->arg_len + 1);
+ ERR_ABORT (req->arg);
+ gf_full_read (fd, req->arg, req->arg_len);
+ gf_log ("guts",
+ GF_LOG_DEBUG,
+ "%s: fop %s (%d)\n",
+ begin, guts_log[req->header.opcode].name, req->header.opcode);
+
+ ret = guts_add_request (ctx, req);
+
+ } else {
+ /* whenever a reply is read, we put it to a hash table and we would like to retrieve it whenever
+ * we get a reply for any call
+ */
+ reply = CALLOC (1, sizeof (*reply));
+ ERR_ABORT (reply);
+ gf_full_read (fd, (char *)reply, REP_HEADER_LEN);
+
+ reply->arg = CALLOC (1, reply->arg_len + 1);
+ ERR_ABORT (reply->arg);
+ gf_full_read (fd, reply->arg, reply->arg_len);
+
+ /* add a new reply to */
+ if (reply->req.unique == unique) {
+ return reply;
+ } else {
+ ret = guts_add_reply (ctx, reply);
+ gf_log ("guts",
+ GF_LOG_DEBUG,
+ "got a reply with unique: %ld", reply->req.unique);
+ }
+ }
+ }
+ return NULL;
+}
diff --git a/glusterfs-guts/src/guts-parse.h b/glusterfs-guts/src/guts-parse.h
new file mode 100644
index 000000000..7791b1215
--- /dev/null
+++ b/glusterfs-guts/src/guts-parse.h
@@ -0,0 +1,140 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _GUTS_PARSE_H_
+#define _GUTS_PARSE_H_
+
+#include "glusterfs.h"
+#include "glusterfs-guts.h"
+#include "fuse_kernel.h"
+#include <fuse/fuse_lowlevel.h>
+#include "list.h"
+
+#ifndef _FUSE_OPAQUE_
+#define _FUSE_OPAQUE_
+
+struct fuse_private {
+ int fd;
+ struct fuse *fuse;
+ struct fuse_session *se;
+ struct fuse_chan *ch;
+ char *mountpoint;
+};
+
+struct fuse_req {
+ struct fuse_ll *f;
+ uint64_t unique;
+ int ctr;
+ pthread_mutex_t lock;
+ struct fuse_ctx ctx;
+ struct fuse_chan *ch;
+ int interrupted;
+ union {
+ struct {
+ uint64_t unique;
+ } i;
+ struct {
+ fuse_interrupt_func_t func;
+ void *data;
+ } ni;
+ } u;
+ struct fuse_req *next;
+ struct fuse_req *prev;
+};
+
+struct fuse_ll {
+ int debug;
+ int allow_root;
+ struct fuse_lowlevel_ops op;
+ int got_init;
+ void *userdata;
+ uid_t owner;
+ struct fuse_conn_info conn;
+ struct fuse_req list;
+ struct fuse_req interrupts;
+ pthread_mutex_t lock;
+ int got_destroy;
+};
+#endif
+
+#define REQ_BEGIN "GUTS_REQ_BEGIN:"
+#define REQ_HEADER_FULL_LEN (strlen(REQ_BEGIN) + sizeof (struct fuse_in_header) + sizeof (int32_t))
+
+#define REP_BEGIN "GUTS_REP_BEGIN:"
+#define REP_HEADER_FULL_LEN (strlen(REP_BEGIN) + sizeof (struct fuse_req) + sizeof (int32_t))
+
+#define REQ_HEADER_LEN (sizeof (struct fuse_in_header) + sizeof (int32_t))
+#define REP_HEADER_LEN (sizeof (struct fuse_req) + sizeof (int32_t))
+
+#define is_request(begin) (0==strcmp(begin, REQ_BEGIN)?1:0)
+
+typedef void (*func_t)(struct fuse_in_header *, const void *);
+
+typedef struct {
+ func_t func;
+ const char *name;
+} guts_log_t;
+
+typedef struct {
+ struct fuse_in_header header;
+ int32_t arg_len;
+ struct list_head list;
+ void *arg;
+} guts_req_t;
+
+typedef struct {
+ struct fuse_req req;
+ int32_t arg_len;
+ void *arg;
+} guts_reply_t;
+
+struct guts_replay_ctx {
+ int32_t tio_fd;
+ struct fuse_ll *guts_ll;
+ dict_t *replies;
+ dict_t *inodes;
+ dict_t *fds;
+ struct list_head requests;
+ dict_t *requests_dict;
+};
+
+typedef struct guts_replay_ctx guts_replay_ctx_t;
+
+extern guts_log_t guts_log[];
+
+int32_t
+guts_tio_init (const char *);
+
+void
+guts_req_dump (struct fuse_in_header *,
+ const void *,
+ int32_t);
+
+guts_req_t *
+guts_read_entry (guts_replay_ctx_t *ctx);
+
+void
+guts_reply_dump (fuse_req_t,
+ const void *,
+ int32_t);
+
+guts_reply_t *
+guts_read_reply (guts_replay_ctx_t *ctx,
+ uint64_t unique);
+
+#endif /* _GUTS_PARSE_H_ */
diff --git a/glusterfs-guts/src/guts-replay.c b/glusterfs-guts/src/guts-replay.c
new file mode 100644
index 000000000..a5447464d
--- /dev/null
+++ b/glusterfs-guts/src/guts-replay.c
@@ -0,0 +1,834 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "glusterfs-guts.h"
+#include "guts-parse.h"
+#include <signal.h>
+#include "guts-tables.h"
+#include "guts-replay.h"
+#include "guts-trace.h"
+
+static void
+convert_attr (const struct fuse_setattr_in *attr,
+ struct stat *stbuf)
+{
+ stbuf->st_mode = attr->mode;
+ stbuf->st_uid = attr->uid;
+ stbuf->st_gid = attr->gid;
+ stbuf->st_size = attr->size;
+ stbuf->st_atime = attr->atime;
+ /*
+ ST_ATIM_NSEC_SET (stbuf, attr->atimensec);
+ ST_MTIM_NSEC_SET (stbuf, attr->mtimensec);*/
+}
+
+static void
+guts_replay_lookup (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ char *name = (char *) inargs;
+
+ if (req->f->op.lookup)
+ req->f->op.lookup(req, ino, name);
+ else
+ guts_reply_err (req, ENOSYS);
+
+}
+
+static void
+guts_replay_forget (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_forget_in *arg = (struct fuse_forget_in *) inargs;
+
+ if (req->f->op.forget)
+ req->f->op.forget (req, ino, arg->nlookup);
+
+}
+
+static void
+guts_replay_getattr (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ (void) inargs;
+
+ if (req->f->op.getattr)
+ req->f->op.getattr (req, ino, NULL);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_setattr (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_setattr_in *arg = (struct fuse_setattr_in *)inargs;
+
+ if (req->f->op.setattr) {
+ struct fuse_file_info *fi = NULL;
+ struct fuse_file_info fi_store;
+ struct stat stbuf;
+ memset (&stbuf, 0, sizeof (stbuf));
+ convert_attr (arg, &stbuf);
+ if (arg->valid & FATTR_FH) {
+ arg->valid &= ~FATTR_FH;
+ memset (&fi_store, 0, sizeof (fi_store));
+ fi = &fi_store;
+ fi->fh = arg->fh;
+ fi->fh_old = fi->fh;
+ }
+ req->f->op.setattr (req, ino, &stbuf, arg->valid, fi);
+ } else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_access (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_access_in *arg = (struct fuse_access_in *)inargs;
+
+ if (req->f->op.access)
+ req->f->op.access (req, ino, arg->mask);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_readlink (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ (void) inargs;
+
+ if (req->f->op.readlink)
+ req->f->op.readlink (req, ino);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+
+static void
+guts_replay_mknod (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_mknod_in *arg = (struct fuse_mknod_in *) inargs;
+
+ if (req->f->op.mknod)
+ req->f->op.mknod (req, ino, PARAM(arg), arg->mode, arg->rdev);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_mkdir (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_mkdir_in *arg = (struct fuse_mkdir_in *) inargs;
+
+ if (req->f->op.mkdir)
+ req->f->op.mkdir (req, ino, PARAM(arg), arg->mode);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_unlink (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ char *name = (char *)inargs;
+
+ if (req->f->op.unlink) {
+
+ req->f->op.unlink (req, ino, name);
+ } else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_rmdir (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ char *name = (char *)inargs;
+
+ if (req->f->op.rmdir) {
+ req->f->op.rmdir (req, ino, name);
+ } else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_symlink (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ char *name = (char *) inargs;
+ char *linkname = ((char *) inargs) + strlen ((char *) inargs) + 1;
+
+ if (req->f->op.symlink) {
+ req->f->op.symlink (req, linkname, ino, name);
+ } else
+ guts_reply_err (req, ENOSYS);
+}
+
+
+
+static void
+guts_replay_rename (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_rename_in *arg = (struct fuse_rename_in *) inargs;
+ char *oldname = PARAM(arg);
+ char *newname = oldname + strlen (oldname) + 1;
+
+ if (req->f->op.rename) {
+ req->f->op.rename (req, ino, oldname, arg->newdir, newname);
+ } else
+ guts_reply_err (req, ENOSYS);
+
+}
+
+static void
+guts_replay_link (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_link_in *arg = (struct fuse_link_in *) inargs;
+
+ if (req->f->op.link) {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ fuse_ino_t old_ino = guts_inode_search (ctx, arg->oldnodeid);
+
+ req->f->op.link (req, old_ino, ino, PARAM(arg));
+ } else
+ guts_reply_err (req, ENOSYS);
+}
+
+
+static void
+guts_replay_create (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct guts_create_in *arg = (struct guts_create_in *) inargs;
+
+ if (req->f->op.create) {
+ struct fuse_file_info fi;
+ memset (&fi, 0, sizeof (fi));
+ fi.flags = arg->open_in.flags;
+
+ req->f->op.create (req, ino, arg->name, arg->open_in.mode, &fi);
+ } else
+ guts_reply_err (req, ENOSYS);
+
+}
+
+static void
+guts_replay_open (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_open_in *arg = (struct fuse_open_in *) inargs;
+ struct fuse_file_info fi;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.flags = arg->flags;
+
+ if (req->f->op.open) {
+ /* TODO: how efficient is using dict_get here?? */
+ req->f->op.open (req, ino, &fi);
+ } else
+ guts_reply_open (req, &fi);
+}
+
+
+static void
+guts_replay_read(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_read_in *arg = (struct fuse_read_in *) inarg;
+
+ if (req->f->op.read){
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ /* TODO: how efficient is using dict_get here?? */
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+ if (!fi.fh) {
+ /* TODO: make it more meaningful and organized */
+ printf ("readv called without opening the file\n");
+ guts_reply_err (req, EBADFD);
+ } else {
+ fi.fh_old = fi.fh;
+ req->f->op.read (req, ino, arg->size, arg->offset, &fi);
+ }
+ } else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_write(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_write_in *arg = (struct fuse_write_in *) inarg;
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+
+ if (!fi.fh) {
+ /* TODO: make it more meaningful and organized */
+ printf ("writev called without opening the file\n");
+ guts_reply_err (req, EBADFD);
+ } else {
+ fi.fh_old = fi.fh;
+ fi.writepage = arg->write_flags & 1;
+ if (req->f->op.write)
+ req->f->op.write (req, ino, PARAM(arg), arg->size, arg->offset, &fi);
+ else
+ guts_reply_err (req, ENOSYS);
+ }
+}
+
+static void
+guts_replay_flush(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_flush_in *arg = (struct fuse_flush_in *) inarg;
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+ if (!fi.fh) {
+ printf ("flush called without calling open\n");
+ guts_reply_err (req, EBADFD);
+ } else {
+ fi.fh_old = fi.fh;
+ fi.flush = 1;
+
+ if (req->f->conn.proto_minor >= 7)
+ fi.lock_owner = arg->lock_owner;
+
+ if (req->f->op.flush)
+ req->f->op.flush (req, ino, &fi);
+ else
+ guts_reply_err (req, ENOSYS);
+ }
+}
+
+static void
+guts_replay_release(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_release_in *arg = (struct fuse_release_in *) inarg;
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.flags = arg->flags;
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+
+ if (!fi.fh) {
+ printf ("release called without calling open\n");
+ guts_reply_err (req, EBADFD);
+ } else {
+ fi.fh_old = fi.fh;
+ if (req->f->conn.proto_minor >= 8) {
+ fi.flush = (arg->release_flags & FUSE_RELEASE_FLUSH) ? 1 : 0;
+ fi.lock_owner = arg->lock_owner;
+ }
+ if (req->f->op.release)
+ req->f->op.release (req, ino, &fi);
+ else
+ guts_reply_err (req, ENOSYS);
+ }
+}
+
+static void
+guts_replay_fsync(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg;
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+ fi.fh_old = fi.fh;
+
+ if (req->f->op.fsync)
+ req->f->op.fsync (req, ino, arg->fsync_flags & 1, &fi);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_opendir (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_open_in *arg = (struct fuse_open_in *) inarg;
+ struct fuse_file_info fi;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.flags = arg->flags;
+
+ if (req->f->op.opendir) {
+ req->f->op.opendir (req, ino, &fi);
+ } else
+ guts_reply_open (req, &fi);
+}
+
+static void
+guts_replay_readdir(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_read_in *arg = (struct fuse_read_in *) inarg;
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+
+ if (!fi.fh) {
+ /* TODO: make it more meaningful and organized */
+ printf ("readdir called without opening the file\n");
+ guts_reply_err (req, EBADFD);
+ } else {
+ fi.fh_old = fi.fh;
+
+ if (req->f->op.readdir)
+ req->f->op.readdir (req, ino, arg->size, arg->offset, &fi);
+ else
+ guts_reply_err (req, ENOSYS);
+ }
+
+}
+
+static void
+guts_replay_releasedir(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_release_in *arg = (struct fuse_release_in *) inarg;
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.flags = arg->flags;
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+ if (!fi.fh) {
+ printf ("releasedir called without calling opendir\n");
+ guts_reply_err (req, EBADFD);
+ } else {
+
+ fi.fh_old = fi.fh;
+ if (req->f->op.releasedir)
+ req->f->op.releasedir (req, ino, &fi);
+ else
+ guts_reply_err (req, ENOSYS);
+ }
+}
+
+static void
+guts_replay_fsyncdir(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg;
+ struct fuse_file_info fi;
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+
+ memset (&fi, 0, sizeof (fi));
+ fi.fh = (unsigned long) guts_fd_search (ctx, arg->fh);
+ fi.fh_old = fi.fh;
+
+ if (req->f->op.fsyncdir)
+ req->f->op.fsyncdir (req, ino, arg->fsync_flags & 1, &fi);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_statfs (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ (void) ino;
+ (void) inargs;
+
+ if (req->f->op.statfs) {
+ req->f->op.statfs (req, ino);
+ } else {
+ struct statvfs buf = {
+ .f_namemax = 255,
+ .f_bsize = 512,
+ };
+ guts_reply_statfs (req, &buf);
+ }
+}
+
+static void
+guts_replay_setxattr(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_setxattr_in *arg = (struct fuse_setxattr_in *) inarg;
+ char *name = PARAM(arg);
+ char *value = name + strlen(name) + 1;
+
+ if (req->f->op.setxattr)
+ req->f->op.setxattr (req, ino, name, value, arg->size, arg->flags);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_getxattr(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inarg)
+{
+ struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg;
+
+ if (req->f->op.getxattr)
+ req->f->op.getxattr (req, ino, PARAM(arg), arg->size);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_listxattr (fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inargs;
+
+ if (req->f->op.listxattr)
+ req->f->op.listxattr (req, ino, arg->size);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+static void
+guts_replay_removexattr(fuse_req_t req,
+ fuse_ino_t ino,
+ const void *inargs)
+{
+ char *name = (char *)inargs;
+
+ if (req->f->op.removexattr)
+ req->f->op.removexattr (req, ino, name);
+ else
+ guts_reply_err (req, ENOSYS);
+}
+
+guts_replay_t guts_replay_fop[] = {
+ [FUSE_LOOKUP] = { guts_replay_lookup, "lookup" },
+ [FUSE_FORGET] = { guts_replay_forget, "forget" },
+ [FUSE_GETATTR] = { guts_replay_getattr, "getattr" },
+ [FUSE_SETATTR] = { guts_replay_setattr, "setattr" },
+ [FUSE_ACCESS] = { guts_replay_access, "access" },
+ [FUSE_READLINK] = { guts_replay_readlink, "readlink" },
+ [FUSE_MKNOD] = { guts_replay_mknod, "mknod" },
+ [FUSE_MKDIR] = { guts_replay_mkdir, "mkdir" },
+ [FUSE_UNLINK] = { guts_replay_unlink, "unlink" },
+ [FUSE_RMDIR] = { guts_replay_rmdir, "rmdir" },
+ [FUSE_SYMLINK] = { guts_replay_symlink, "symlink" },
+ [FUSE_RENAME] = { guts_replay_rename, "rename" },
+ [FUSE_LINK] = { guts_replay_link, "link" },
+ [FUSE_CREATE] = { guts_replay_create, "create" },
+ [FUSE_OPEN] = { guts_replay_open, "open" },
+ [FUSE_READ] = { guts_replay_read, "read" },
+ [FUSE_WRITE] = { guts_replay_write, "write" },
+ [FUSE_FLUSH] = { guts_replay_flush, "flush" },
+ [FUSE_RELEASE] = { guts_replay_release, "release" },
+ [FUSE_FSYNC] = { guts_replay_fsync, "fsync" },
+ [FUSE_OPENDIR] = { guts_replay_opendir, "opendir" },
+ [FUSE_READDIR] = { guts_replay_readdir, "readdir" },
+ [FUSE_RELEASEDIR] = { guts_replay_releasedir, "releasedir" },
+ [FUSE_FSYNCDIR] = { guts_replay_fsyncdir, "fsyncdir" },
+ [FUSE_STATFS] = { guts_replay_statfs, "statfs" },
+ [FUSE_SETXATTR] = { guts_replay_setxattr, "setxattr" },
+ [FUSE_GETXATTR] = { guts_replay_getxattr, "getxattr" },
+ [FUSE_LISTXATTR] = { guts_replay_listxattr, "listxattr" },
+ [FUSE_REMOVEXATTR] = { guts_replay_removexattr, "removexattr" },
+};
+
+static inline void
+list_init_req (struct fuse_req *req)
+{
+ req->next = req;
+ req->prev = req;
+}
+
+
+static int32_t
+guts_transport_notify (xlator_t *xl,
+ int32_t event,
+ void *data,
+ ...)
+{
+ /* dummy, nobody has got anything to notify me.. ;) */
+ return 0;
+}
+
+static int32_t
+guts_transport_init (transport_t *this,
+ dict_t *options,
+ event_notify_fn_t notify)
+{
+ struct fuse_private *priv = CALLOC (1, sizeof (*priv));
+ ERR_ABORT (priv);
+
+ this->notify = NULL;
+ this->private = (void *)priv;
+
+ /* fuse channel */
+ priv->ch = NULL;
+
+ /* fuse session */
+ priv->se = NULL;
+
+ /* fuse channel fd */
+ priv->fd = -1;
+
+ this->buf = data_ref (data_from_dynptr (NULL, 0));
+ this->buf->is_locked = 1;
+
+ priv->mountpoint = NULL;
+
+ transport_ref (this);
+
+ return 0;
+}
+
+static void
+guts_transport_fini (transport_t *this)
+{
+
+}
+
+static int32_t
+guts_transport_disconnect (transport_t *this)
+{
+ struct fuse_private *priv = this->private;
+
+ gf_log ("glusterfs-guts",
+ GF_LOG_DEBUG,
+ "cleaning up fuse transport in disconnect handler");
+
+ FREE (priv);
+ priv = NULL;
+ this->private = NULL;
+
+ /* TODO: need graceful exit. every xlator should be ->fini()'ed
+ and come out of main poll loop cleanly
+ */
+ return -1;
+}
+
+static struct transport_ops guts_transport_ops = {
+ .disconnect = guts_transport_disconnect,
+};
+
+static transport_t guts_transport = {
+ .ops = &guts_transport_ops,
+ .private = NULL,
+ .xl = NULL,
+ .init = guts_transport_init,
+ .fini = guts_transport_fini,
+ .notify = guts_transport_notify
+};
+
+static inline xlator_t *
+fuse_graph (xlator_t *graph)
+{
+ xlator_t *top = NULL;
+ xlator_list_t *xlchild;
+
+ top = CALLOC (1, sizeof (*top));
+ ERR_ABORT (top);
+
+ xlchild = CALLOC (1, sizeof(*xlchild));
+ ERR_ABORT (xlchild);
+ xlchild->xlator = graph;
+ top->children = xlchild;
+ top->ctx = graph->ctx;
+ top->next = graph;
+ graph->parent = top;
+
+ return top;
+}
+
+static guts_replay_ctx_t *
+guts_replay_init (guts_thread_ctx_t *thread)
+{
+ guts_replay_ctx_t *ctx = NULL;
+ int32_t fd = open (thread->file, O_RDONLY);
+
+ if (fd < 0) {
+ gf_log ("glusterfs-guts", GF_LOG_DEBUG,
+ "failed to open tio_file %s", thread->file);
+ return ctx;
+ } else {
+ struct fuse_ll *guts_ll = CALLOC (1, sizeof (*guts_ll));
+ ERR_ABORT (guts_ll);
+
+ ctx = CALLOC (1, sizeof (*ctx));
+ ERR_ABORT (ctx);
+
+ if (ctx) {
+ /* equivalent to fuse_new_session () */
+ guts_ll->conn.async_read = 1;
+ guts_ll->conn.max_write = UINT_MAX;
+ guts_ll->conn.max_readahead = UINT_MAX;
+ memcpy (&guts_ll->op, &fuse_ops, sizeof (struct fuse_lowlevel_ops));
+ list_init_req (&guts_ll->list);
+ list_init_req (&guts_ll->interrupts);
+ guts_ll->owner = getuid ();
+ guts_ll->userdata = thread;
+
+ /* TODO: need to create transport_t object which whole of the glusterfs
+ * so desperately depends on */
+ transport_t *guts_trans = CALLOC (1, sizeof (*guts_trans));
+
+ if (guts_trans) {
+ memcpy (guts_trans, &guts_transport, sizeof (*guts_trans));
+ guts_trans->ops = &guts_transport_ops;
+ } else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "failed to allocate memory for guts transport object");
+ return NULL;
+ }
+
+ glusterfs_ctx_t *glfs_ctx = CALLOC (1, sizeof (*glfs_ctx));;
+ if (glfs_ctx) {
+ guts_trans->xl_private = glfs_ctx;
+ guts_trans->xl = fuse_graph (thread->ctx->graph);
+ }else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "failed to allocate memory for glusterfs_ctx_t object");
+ return NULL;
+ }
+
+ call_pool_t *pool = CALLOC (1, sizeof (call_pool_t));
+ if (pool) {
+ glfs_ctx->pool = pool;
+ LOCK_INIT (&pool->lock);
+ INIT_LIST_HEAD (&pool->all_frames);
+ } else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "failed to allocate memory for guts call pool");
+ return NULL;
+ }
+
+ guts_trans->xl->ctx = glfs_ctx;
+ guts_trans->init (guts_trans, NULL, guts_transport_notify);
+ guts_ll->userdata = guts_trans;
+
+ /* call fuse_init */
+ guts_ll->op.init (guts_trans, NULL);
+
+ {
+ ctx->guts_ll = guts_ll;
+ ctx->tio_fd = fd;
+ ctx->inodes = get_new_dict ();
+ ctx->fds = get_new_dict ();
+ ctx->replies = get_new_dict ();
+ INIT_LIST_HEAD(&ctx->requests);
+ ctx->requests_dict = get_new_dict ();
+ }
+ } else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "failed to allocate memory for guts_ctx_t object");
+ return NULL;
+ }
+ }
+
+ return ctx;
+}
+
+int32_t
+guts_replay (guts_thread_ctx_t *thread)
+{
+ guts_req_t *entry = NULL;
+ guts_replay_ctx_t *ctx = guts_replay_init (thread);
+
+ if (!ctx) {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "failed to initialize guts_replay");
+ return -1;
+ } else {
+ while ((entry = guts_read_entry (ctx))) {
+ /* here we go ... execute the request */
+ fuse_req_t req = CALLOC (1, sizeof (struct fuse_req));
+ ino_t ino = entry->header.nodeid;
+ void *arg = entry->arg;
+
+ if (req) {
+ req->f = ctx->guts_ll;
+ req->unique = entry->header.unique;
+ req->ctx.uid = entry->header.uid;
+ req->ctx.pid = entry->header.pid;
+
+ /* req->u.ni.data is unused void *, while running in replay mode. Making use of available real-estate
+ * to store useful information of thread specific guts_replay_ctx */
+ req->u.ni.data = (void *) ctx;
+ /* req->ch is of type 'struct fuse_chan', which fuse uses only at the
+ * time of the response it gets and is useful in sending the reply data to correct channel
+ * in /dev/fuse. This is not useful for us, so we ignore it by keeping it NULL */
+ list_init_req (req);
+
+ fuse_ino_t new_ino = guts_inode_search (ctx, ino);
+
+ if (guts_replay_fop[entry->header.opcode].func) {
+ printf ("operation: %s && inode: %ld\n", guts_replay_fop[entry->header.opcode].name, new_ino);
+ guts_replay_fop[entry->header.opcode].func (req, new_ino, arg);
+ }
+
+ if (entry->arg)
+ free (entry->arg);
+ free (entry);
+ } else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "failed to allocate memory for fuse_req_t object");
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
diff --git a/glusterfs-guts/src/guts-replay.h b/glusterfs-guts/src/guts-replay.h
new file mode 100644
index 000000000..532060d2b
--- /dev/null
+++ b/glusterfs-guts/src/guts-replay.h
@@ -0,0 +1,33 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
+
+void guts_reply_err (fuse_req_t, error_t);
+void guts_reply_open (fuse_req_t, struct fuse_file_info *);
+void guts_reply_statfs (fuse_req_t, struct statvfs *);
+
+typedef void (*guts_replay_fop_t)(fuse_req_t, fuse_ino_t, const void *);
+
+typedef struct {
+ guts_replay_fop_t func;
+ const char *name;
+} guts_replay_t;
+
+extern struct fuse_lowlevel_ops fuse_ops;
+
diff --git a/glusterfs-guts/src/guts-tables.c b/glusterfs-guts/src/guts-tables.c
new file mode 100644
index 000000000..2992b3e2c
--- /dev/null
+++ b/glusterfs-guts/src/guts-tables.c
@@ -0,0 +1,248 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include "guts-parse.h"
+#include "dict.h"
+#include "guts-tables.h"
+
+
+int32_t
+guts_attr_cmp (const struct stat *attr,
+ const struct stat *old_attr)
+{
+ return 0;
+}
+
+int32_t
+guts_statvfs_cmp (const struct statvfs *stbuf,
+ const struct statvfs *old_stbuf)
+{
+ return 0;
+}
+
+int32_t
+guts_flock_cmp (struct flock *lock,
+ struct flock *old_lock)
+{
+ return 0;
+}
+
+
+guts_req_t *
+guts_lookup_request (guts_replay_ctx_t *ctx, uint64_t unique)
+{
+ guts_req_t *req = NULL;
+
+ if (unique == 0) {
+ if (list_empty (&ctx->requests))
+ req = NULL;
+ else {
+ /* pick an entry from list, move it out of the list and return it to the caller */
+ char *key = NULL;
+
+ req = list_entry (ctx->requests.next, guts_req_t, list);
+ list_del (&req->list);
+
+ asprintf (&key, "%llu", req->header.unique);
+
+ dict_set (ctx->requests_dict, key, data_from_static_ptr (req));
+
+ if (key)
+ free (key);
+ }
+ } else {
+ char *key = NULL;
+ data_t *req_data = NULL;
+
+ asprintf (&key, "%llu", unique);
+
+ req_data = dict_get (ctx->requests_dict, key);
+
+ if (req_data)
+ req = data_to_ptr (req_data);
+
+ if (key)
+ free (key);
+ }
+ return req;
+}
+
+guts_req_t *
+guts_get_request (guts_replay_ctx_t *ctx)
+{
+ return guts_lookup_request (ctx, 0);
+}
+
+int32_t
+guts_add_request (guts_replay_ctx_t *ctx,
+ guts_req_t *req)
+{
+ list_add_tail (&req->list, &ctx->requests);
+ return 0;
+}
+
+int32_t
+guts_add_reply (guts_replay_ctx_t *ctx,
+ guts_reply_t *reply)
+{
+ char *key = NULL;
+ asprintf (&key, "%llu", reply->req.unique);
+
+ dict_set (ctx->replies, key, data_from_static_ptr(reply));
+
+ if (key)
+ free(key);
+
+ return 0;
+}
+
+
+guts_reply_t *
+guts_lookup_reply (guts_replay_ctx_t *ctx,
+ uint64_t unique)
+{
+ char *key = NULL;
+ data_t *reply_data = NULL;
+ guts_reply_t *new_reply = NULL;
+
+ asprintf (&key, "%llu", unique);
+ reply_data = dict_get (ctx->replies, key);
+
+ if (reply_data) {
+ new_reply = data_to_ptr (reply_data);
+ dict_del (ctx->replies, key);
+ } else {
+ /* reply has not yet been read from tio file */
+ new_reply = guts_read_reply (ctx, unique);
+
+ if (!new_reply) {
+ /* failed to fetch reply for 'unique' from tio file */
+ new_reply;
+ }
+ }
+
+ if (key)
+ free(key);
+
+ return new_reply;
+
+}
+
+int32_t
+guts_inode_update (guts_replay_ctx_t *ctx,
+ fuse_ino_t old_ino,
+ fuse_ino_t new_ino)
+{
+ char *key = NULL;
+ asprintf (&key, "%ld", old_ino);
+ dict_set (ctx->inodes, key, data_from_uint64 (new_ino));
+
+ if (key)
+ free(key);
+
+ return 0;
+}
+
+fuse_ino_t
+guts_inode_search (guts_replay_ctx_t *ctx,
+ fuse_ino_t old_ino)
+{
+ char *key = NULL;
+ data_t *ino_data = NULL;
+ fuse_ino_t new_ino = 0;
+
+ asprintf (&key, "%ld", old_ino);
+ ino_data = dict_get (ctx->inodes, key);
+
+ if (ino_data)
+ new_ino = data_to_uint64 (ino_data);
+ else if (old_ino != /* TODO: FIXME */1 ) {
+ new_ino = 0;
+ } else
+ new_ino = old_ino;
+
+ if (key)
+ free(key);
+
+ return new_ino;
+}
+
+int32_t
+guts_fd_add (guts_replay_ctx_t *ctx,
+ unsigned long old_fd,
+ fd_t *new_fd)
+{
+ char *key = NULL;
+ asprintf (&key, "%ld", old_fd);
+ dict_set (ctx->fds, key, data_from_static_ptr (new_fd));
+
+ if (key)
+ free(key);
+
+ return 0;
+}
+
+fd_t *
+guts_fd_search (guts_replay_ctx_t *ctx,
+ unsigned long old_fd)
+{
+ char *key = NULL;
+ data_t *fd_data = NULL;
+ fd_t *new_fd = NULL;
+
+ asprintf (&key, "%ld", old_fd);
+ fd_data = dict_get (ctx->fds, key);
+
+ if (fd_data)
+ new_fd = data_to_ptr (fd_data);
+
+ if (key)
+ free(key);
+
+ return new_fd;
+}
+
+int32_t
+guts_delete_fd (guts_replay_ctx_t *ctx,
+ unsigned long old_fd)
+{
+ char *key = NULL;
+ data_t *fd_data = NULL;
+
+ asprintf (&key, "%ld", old_fd);
+ fd_data = dict_get (ctx->fds, key);
+
+ if (fd_data)
+ dict_del (ctx->fds, key);
+
+ if (key)
+ free(key);
+
+ return 0;
+}
+
+inline int32_t
+guts_get_opcode (guts_replay_ctx_t *ctx,
+ uint64_t unique)
+{
+ guts_req_t *req = guts_lookup_request (ctx, unique);
+
+ return ((req == NULL) ? -1 : req->header.opcode);
+
+}
diff --git a/glusterfs-guts/src/guts-tables.h b/glusterfs-guts/src/guts-tables.h
new file mode 100644
index 000000000..ff27300fa
--- /dev/null
+++ b/glusterfs-guts/src/guts-tables.h
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _GUTS_TABLES_H_
+#define _GUTS_TABLES_H_
+
+
+int32_t
+guts_attr_cmp (const struct stat *attr,
+ const struct stat *old_attr);
+
+int32_t
+guts_statvfs_cmp (const struct statvfs *stbuf,
+ const struct statvfs *old_stbuf);
+
+int32_t
+guts_inode_update (guts_replay_ctx_t *ctx,
+ fuse_ino_t old_ino,
+ fuse_ino_t new_ino);
+
+fuse_ino_t
+guts_inode_search (guts_replay_ctx_t *ctx,
+ fuse_ino_t old_ino);
+
+int32_t
+guts_add_request (guts_replay_ctx_t *,
+ guts_req_t *);
+
+guts_req_t *
+guts_get_request (guts_replay_ctx_t *ctx);
+
+guts_req_t *
+guts_lookup_request (guts_replay_ctx_t *ctx,
+ uint64_t unique);
+
+guts_reply_t *
+guts_lookup_reply (guts_replay_ctx_t *ctx,
+ uint64_t unique);
+
+int32_t
+guts_add_reply (guts_replay_ctx_t *ctx,
+ guts_reply_t *reply);
+
+int32_t
+guts_flock_cmp (struct flock *lock,
+ struct flock *old_lock);
+
+fd_t *
+guts_fd_search (guts_replay_ctx_t *ctx,
+ unsigned long old_fd);
+
+int32_t
+guts_delete_fd (guts_replay_ctx_t *,
+ unsigned long);
+
+int32_t
+guts_get_opcode (guts_replay_ctx_t *ctx,
+ uint64_t unique);
+int32_t
+guts_fd_add (guts_replay_ctx_t *ctx,
+ unsigned long old_fd,
+ fd_t *new_fd);
+
+#endif
diff --git a/glusterfs-guts/src/guts-trace.c b/glusterfs-guts/src/guts-trace.c
new file mode 100644
index 000000000..51d8a68d6
--- /dev/null
+++ b/glusterfs-guts/src/guts-trace.c
@@ -0,0 +1,650 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include "glusterfs-guts.h"
+#include <signal.h>
+
+#include "guts-parse.h"
+#include "guts-tables.h"
+#include "guts-trace.h"
+
+static xlator_t *
+fuse_graph (xlator_t *graph)
+{
+ xlator_t *top = NULL;
+ xlator_list_t *xlchild;
+
+ top = CALLOC (1, sizeof (*top));
+ ERR_ABORT (top);
+ xlchild = CALLOC (1, sizeof(*xlchild));
+ ERR_ABORT (xlchild);
+ xlchild->xlator = graph;
+ top->children = xlchild;
+ top->ctx = graph->ctx;
+ top->next = graph;
+ graph->parent = top;
+
+ return top;
+}
+
+int32_t
+fuse_thread (pthread_t *thread, void *data);
+
+int32_t
+guts_trace (guts_ctx_t *guts_ctx)
+{
+ transport_t *mp = NULL;
+ glusterfs_ctx_t ctx = {
+ .poll_type = SYS_POLL_TYPE_EPOLL,
+ };
+ xlator_t *graph = NULL;
+ call_pool_t *pool = NULL;
+ int32_t ret = -1;
+ pthread_t thread;
+ /* Ignore SIGPIPE */
+ signal (SIGPIPE, SIG_IGN);
+
+#if HAVE_BACKTRACE
+ /* Handle SIGABORT and SIGSEGV */
+ signal (SIGSEGV, gf_print_trace);
+ signal (SIGABRT, gf_print_trace);
+#endif /* HAVE_BACKTRACE */
+
+ ret = guts_tio_init (guts_ctx->file);
+
+ if (ret < 0) {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "running in trace mode: failed to open tio file %s", guts_ctx->file);
+ return -1;
+ }
+
+ pool = ctx.pool = CALLOC (1, sizeof (call_pool_t));
+ ERR_ABORT (ctx.pool);
+ LOCK_INIT (&pool->lock);
+ INIT_LIST_HEAD (&pool->all_frames);
+
+ /* glusterfs_mount has to be ideally placed after all the initialisation stuff */
+ if (!(mp = glusterfs_mount (&ctx, guts_ctx->mountpoint))) {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR, "Unable to mount glusterfs");
+ return -1;
+ }
+
+ gf_timer_registry_init (&ctx);
+ graph = guts_ctx->graph;
+
+ if (!graph) {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "Unable to get xlator graph for mount_point %s", guts_ctx->mountpoint);
+ transport_disconnect (mp);
+ return -1;
+ }
+
+ ctx.graph = graph;
+
+ mp->xl = fuse_graph (graph);
+ mp->xl->ctx = &ctx;
+
+ fuse_thread (&thread, mp);
+
+ while (!poll_iteration (&ctx));
+
+ return 0;
+}
+
+
+
+static void
+guts_name (struct fuse_in_header *in,
+ const void *inargs)
+{
+ char *name = (char *) inargs;
+
+ guts_req_dump (in, name, strlen (name));
+}
+
+static void
+guts_noarg (struct fuse_in_header *in,
+ const void *inargs)
+{
+ guts_req_dump (in, NULL, 0);
+}
+
+
+static void
+guts_setattr (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct fuse_setattr_in *arg = (struct fuse_setattr_in *)inargs;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_access (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct fuse_access_in *arg = (struct fuse_access_in *)inargs;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+
+static void
+guts_mknod (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct fuse_mknod_in *arg = (struct fuse_mknod_in *) inargs;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_mkdir (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct fuse_mkdir_in *arg = (struct fuse_mkdir_in *) inargs;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+
+static void
+guts_symlink (struct fuse_in_header *in,
+ const void *inargs)
+{
+ char *name = (char *) inargs;
+ char *linkname = ((char *) inargs) + strlen ((char *) inargs) + 1;
+ struct guts_symlink_in symlink_in;
+
+ strcpy (symlink_in.name, name);
+ strcpy (symlink_in.linkname, linkname);
+ guts_req_dump (in, &symlink_in, sizeof (symlink_in));
+}
+
+static void
+guts_rename (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct fuse_rename_in *arg = (struct fuse_rename_in *) inargs;
+ char *oldname = PARAM(arg);
+ char *newname = oldname + strlen (oldname) + 1;
+ struct guts_rename_in rename_in;
+
+ memset (&rename_in, 0, sizeof (rename_in));
+ memcpy (&rename_in, arg, sizeof (*arg));
+ strcpy (rename_in.oldname, oldname);
+ strcpy (rename_in.newname, newname);
+
+ guts_req_dump (in, &rename_in, sizeof (rename_in));
+
+}
+
+static void
+guts_link (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct fuse_link_in *arg = (struct fuse_link_in *) inargs;
+
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+
+static void
+guts_open (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct fuse_open_in *arg = (struct fuse_open_in *) inargs;
+
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_create (struct fuse_in_header *in,
+ const void *inargs)
+{
+ struct guts_create_in create_in;
+ struct fuse_open_in *arg = (struct fuse_open_in *) inargs;
+ char *name = PARAM (arg);
+
+ memset (&create_in, 0, sizeof (create_in));
+ memcpy (&create_in.open_in, arg, sizeof (*arg));
+ memcpy (&create_in.name, name, strlen (name));
+
+ guts_req_dump (in, &create_in, sizeof (create_in));
+}
+
+
+static void
+guts_read(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_read_in *arg = (struct fuse_read_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_write(struct fuse_in_header *in,
+ const void *inarg)
+{
+ /* TODO: where the hell is the data to be written??? */
+ struct fuse_write_in *arg = (struct fuse_write_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_flush(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_flush_in *arg = (struct fuse_flush_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_release(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_release_in *arg = (struct fuse_release_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_fsync(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+
+static void
+guts_readdir(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_read_in *arg = (struct fuse_read_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_releasedir(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_release_in *arg = (struct fuse_release_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+static void
+guts_fsyncdir(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_fsync_in *arg = (struct fuse_fsync_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+
+static void
+guts_setxattr(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_setxattr_in *arg = (struct fuse_setxattr_in *) inarg;
+ char *name = PARAM(arg);
+ char *value = name + strlen(name) + 1;
+ struct guts_xattr_in setxattr_in;
+
+ memset (&setxattr_in, 0, sizeof (setxattr_in));
+ memcpy (&setxattr_in, arg, sizeof (*arg));
+ strcpy (setxattr_in.name, name);
+ strcpy (setxattr_in.value, value);
+
+ guts_req_dump (in, &setxattr_in, sizeof (setxattr_in));
+
+}
+
+static void
+guts_getxattr(struct fuse_in_header *in,
+ const void *inarg)
+{
+ struct fuse_getxattr_in *arg = (struct fuse_getxattr_in *) inarg;
+ guts_req_dump (in, arg, sizeof (*arg));
+}
+
+guts_log_t guts_log[] = {
+ [FUSE_LOOKUP] = { guts_name, "lookup" },
+ [FUSE_GETATTR] = { guts_noarg, "getattr" },
+ [FUSE_SETATTR] = { guts_setattr, "setattr" },
+ [FUSE_ACCESS] = { guts_access, "access" },
+ [FUSE_READLINK] = { guts_noarg, "readlink" },
+ [FUSE_MKNOD] = { guts_mknod, "mknod" },
+ [FUSE_MKDIR] = { guts_mkdir, "mkdir" },
+ [FUSE_UNLINK] = { guts_name, "unlink" },
+ [FUSE_RMDIR] = { guts_name, "rmdir" },
+ [FUSE_SYMLINK] = { guts_symlink, "symlink" },
+ [FUSE_RENAME] = { guts_rename, "rename" },
+ [FUSE_LINK] = { guts_link, "link" },
+ [FUSE_CREATE] = { guts_create, "create" },
+ [FUSE_OPEN] = { guts_open, "open" },
+ [FUSE_READ] = { guts_read, "read" },
+ [FUSE_WRITE] = { guts_write, "write" },
+ [FUSE_FLUSH] = { guts_flush, "flush" },
+ [FUSE_RELEASE] = { guts_release, "release" },
+ [FUSE_FSYNC] = { guts_fsync, "fsync" },
+ [FUSE_OPENDIR] = { guts_open, "opendir" },
+ [FUSE_READDIR] = { guts_readdir, "readdir" },
+ [FUSE_RELEASEDIR] = { guts_releasedir, "releasedir" },
+ [FUSE_FSYNCDIR] = { guts_fsyncdir, "fsyncdir" },
+ [FUSE_STATFS] = { guts_noarg, "statfs" },
+ [FUSE_SETXATTR] = { guts_setxattr, "setxattr" },
+ [FUSE_GETXATTR] = { guts_getxattr, "getxattr" },
+ [FUSE_LISTXATTR] = { guts_getxattr, "listxattr" },
+ [FUSE_REMOVEXATTR] = { guts_name, "removexattr" },
+};
+
+/* used for actual tracing task */
+
+int32_t
+guts_log_req (void *buf,
+ int32_t len)
+{
+ struct fuse_in_header *in = buf;
+ const void *inargs = NULL;
+ int32_t header_len = sizeof (struct fuse_in_header);
+
+ if (header_len < len ) {
+ inargs = buf + header_len;
+ gf_log ("guts-gimmik", GF_LOG_ERROR,
+ "unique: %llu, opcode: %s (%i), nodeid: %lu, insize: %zu\n",
+ (unsigned long long) in->unique, "<null>",
+ /*opname((enum fuse_opcode) in->opcode),*/ in->opcode,
+ (unsigned long) in->nodeid, len);
+ if (guts_log[in->opcode].func)
+ guts_log[in->opcode].func (in, inargs);
+
+ } else {
+ gf_log ("guts", GF_LOG_ERROR,
+ "header is longer than the buffer passed");
+ }
+
+ return 0;
+}
+
+
+int
+guts_reply_err (fuse_req_t req, int err)
+{
+ if (IS_TRACE(req)) {
+ /* we are tracing calls, just dump the reply to file and continue with fuse_reply_err() */
+ guts_reply_dump (req, &err, sizeof (err));
+ return fuse_reply_err (req, err);
+ } else {
+ /* we are replaying. ;) */
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ int32_t opcode = guts_get_opcode (ctx, req->unique);
+
+ /* see if we are called by close/closedir, if yes remove do a guts_fd_delete () */
+ if (opcode == FUSE_RELEASEDIR || opcode == FUSE_RELEASE) {
+ guts_req_t *request = guts_lookup_request (ctx, req->unique);
+ struct fuse_release_in *arg = request->arg;
+
+ guts_delete_fd (ctx, arg->fh);
+ } else if (err == -1) {
+ /* error while replaying?? just quit as of now
+ * TODO: this is not the right way */
+ printf (":O - glusterfs-guts: replay failed\n");
+ exit (0);
+ }
+
+ return 0;
+ }
+}
+
+void
+guts_reply_none (fuse_req_t req)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, NULL, 0);
+ fuse_reply_none (req);
+ } else {
+ return;
+ }
+}
+
+int
+guts_reply_entry (fuse_req_t req,
+ const struct fuse_entry_param *e)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, e, sizeof (*e));
+ return fuse_reply_entry (req, e);
+ } else {
+ /* TODO: is dict_set() the best solution for this case?? */
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ struct fuse_entry_param *old_entry = (struct fuse_entry_param *)reply->arg;
+ guts_inode_update (ctx, old_entry->ino, e->ino);
+ return 0;
+ }
+}
+
+int
+guts_reply_create (fuse_req_t req,
+ const struct fuse_entry_param *e,
+ const struct fuse_file_info *f)
+{
+ if (IS_TRACE(req)) {
+ struct guts_create_out create_out;
+
+ memset (&create_out, 0, sizeof (create_out));
+ memcpy (&create_out.e, e, sizeof (*e));
+ memcpy (&create_out.f, f, sizeof (*f));
+
+ guts_reply_dump (req, &create_out, sizeof (create_out));
+ return fuse_reply_create (req, e, f);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ struct guts_create_out *old_createout = (struct guts_create_out *) reply->arg;
+ struct fuse_file_info *old_f = &old_createout->f;
+
+ /* add a new fd and map it to the file handle, as stored in tio file */
+ guts_fd_add (ctx, old_f->fh, (fd_t *)(long)f->fh);
+
+ return 0;
+ }
+}
+
+
+int
+guts_reply_attr (fuse_req_t req,
+ const struct stat *attr,
+ double attr_timeout)
+{
+ if (IS_TRACE(req)) {
+ struct guts_attr_out attr_out;
+
+ memcpy (&attr_out.attr, attr, sizeof (*attr));
+ attr_out.attr_timeout = attr_timeout;
+
+ guts_reply_dump (req, &attr_out, sizeof (attr_out));
+ return fuse_reply_attr (req, attr, attr_timeout);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ struct guts_attr_out *old_attrout = (struct guts_attr_out *) reply->arg;
+
+ if (!guts_attr_cmp (attr, &old_attrout->attr))
+ return 0;
+ else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "attr failed.");
+ return -1;
+ }
+ }
+}
+
+int
+guts_reply_readlink (fuse_req_t req,
+ const char *linkname)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, linkname, strlen (linkname));
+ return fuse_reply_readlink (req, linkname);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ char *old_linkname = (char *) reply->arg;
+ if (!strcmp (linkname, old_linkname))
+ return 0;
+ else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "readlink failed. linkname in tio file: %s \n linkname recieved on replay: %s",
+ old_linkname, linkname);
+ return -1;
+ }
+ }
+}
+
+int
+guts_reply_open (fuse_req_t req,
+ const struct fuse_file_info *f)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, f, sizeof (*f));
+ return fuse_reply_open (req, f);
+ } else {
+ /* the fd we recieve here is the valid fd for our current session, map the indicative number we have
+ * in mapping */
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+
+ if (reply) {
+ struct fuse_file_info *old_f = reply->arg;
+
+ /* add a new fd and map it to the file handle, as stored in tio file */
+ guts_fd_add (ctx, old_f->fh, (fd_t *)(long)f->fh);
+ }
+
+ return 0;
+ }
+}
+
+int
+guts_reply_write (fuse_req_t req,
+ size_t count)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, &count, sizeof (count));
+ return fuse_reply_write (req, count);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ size_t *old_count = reply->arg;
+ if (count == *old_count)
+ return 0;
+ else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "writev failed. old writev count: %d \n writev count on replay: %d",
+ old_count, count);
+ return -1;
+ }
+ }
+}
+
+int
+guts_reply_buf (fuse_req_t req,
+ const char *buf,
+ size_t size)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, buf, size);
+ return fuse_reply_buf (req, buf, size);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ char *old_buf = reply->arg;
+ size_t old_size = reply->arg_len;
+ if ((size == old_size) && (!memcmp (buf, old_buf, size)))
+ return 0;
+ else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "readv failed. old readv size: %d \n readv size on replay: %d",
+ old_size, size);
+ return -1;
+ }
+ }
+}
+
+int
+guts_reply_statfs (fuse_req_t req,
+ const struct statvfs *stbuf)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, stbuf, sizeof (*stbuf));
+ return fuse_reply_statfs (req, stbuf);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ struct statvfs *old_stbuf = reply->arg;
+
+ if (!guts_statvfs_cmp (old_stbuf, stbuf))
+ return 0;
+ else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "statfs failed.");
+ return -1;
+ }
+ }
+}
+
+int
+guts_reply_xattr (fuse_req_t req,
+ size_t count)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, &count, sizeof (count));
+ return fuse_reply_xattr (req, count);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ size_t *old_count = reply->arg;
+ if (count == *old_count)
+ return 0;
+ else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "xattr failed. old xattr count: %d \n xattr count on replay: %d",
+ old_count, count);
+ return -1;
+ }
+ }
+}
+
+int
+guts_reply_lock (fuse_req_t req,
+ struct flock *lock)
+{
+ if (IS_TRACE(req)) {
+ guts_reply_dump (req, lock , sizeof (*lock));
+ return fuse_reply_lock (req, lock);
+ } else {
+ guts_replay_ctx_t *ctx = (guts_replay_ctx_t *) req->u.ni.data;
+ guts_reply_t *reply = guts_lookup_reply (ctx, req->unique);
+ struct flock *old_lock = (struct flock *)reply->arg;
+ if (!guts_flock_cmp (lock, old_lock))
+ return 0;
+ else {
+ gf_log ("glusterfs-guts", GF_LOG_ERROR,
+ "lock failed.");
+ return -1;
+ }
+ }
+}
diff --git a/glusterfs-guts/src/guts-trace.h b/glusterfs-guts/src/guts-trace.h
new file mode 100644
index 000000000..c877b2bcf
--- /dev/null
+++ b/glusterfs-guts/src/guts-trace.h
@@ -0,0 +1,54 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#define IS_TRACE(req) (req->ch != NULL)
+
+#define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
+
+struct guts_symlink_in {
+ char name[NAME_MAX];
+ char linkname[NAME_MAX];
+};
+
+struct guts_create_in {
+ struct fuse_open_in open_in;
+ char name[NAME_MAX];
+};
+
+struct guts_xattr_in {
+ struct fuse_setxattr_in xattr;
+ char name[NAME_MAX];
+ char value[NAME_MAX];
+};
+
+struct guts_rename_in {
+ struct fuse_rename_in rename;
+ char oldname[NAME_MAX];
+ char newname[NAME_MAX];
+};
+
+struct guts_create_out {
+ struct fuse_entry_param e;
+ struct fuse_file_info f;
+};
+
+struct guts_attr_out {
+ struct stat attr;
+ double attr_timeout;
+};
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
new file mode 100644
index 000000000..1740bbc36
--- /dev/null
+++ b/glusterfs.spec.in
@@ -0,0 +1,256 @@
+# if you make changes, the it is advised to increment this number, and provide
+# a descriptive suffix to identify who owns or what the change represents
+# e.g. release_version 2.MSW
+%define release_version 1
+
+# if you wish to compile an rpm without ibverbs support, compile like this...
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without ibverbs
+%define with_ibverbs %{?_without_ibverbs:0}%{?!_without_ibverbs:1}
+
+# if you wish to compile an rpm without building the client RPMs...
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without client
+%define with_client %{?_without_client:0}%{?!_without_client:1}
+
+# if you wish to compile an rpm without BDB translator...
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without bdb
+%define with_bdb %{?_without_bdb:0}%{?!_without_bdb:1}
+
+# if you wish to compile an rpm without libglusterfsclient...
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without libglfsclient
+%define with_libglfsclient %{?_without_libglfsclient:0}%{?!_without_libglfsclient:1}
+
+# if you wish to compile an rpm without mod_glusterfs support...
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without modglfs
+%define with_modglfs %{?_without_modglfs:0}%{?!_without_modglfs:1}
+
+# if you wish to compile an rpm with apache at nonstandard location
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without apxs_default --define 'apxs_path /usr/local/apache/bin'
+%define with_apxs_default %{?_without_apxs_default:0}%{?!_without_apxs_default:1}
+%{!?apxs_path: %define apxs_path %{nil}}
+
+# if you wish to compile an rpm with apache binaries at nonstandard path
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without apache_auto -define 'apxs_bin_path /usr/local/apache/bin/apxs'
+# rpmbuild -ta @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz --without apache_auto -define 'apache_bin_path /usr/local/apache/bin/apache2'
+%define with_apache_auto %{?_without_apache_auto:0}%{?!_without_apache_auto:1}
+%{!?apxs_bin_path: %define apxs_bin_path %{nil}}
+%{!?apache_bin_path: %define apache_bin_path %{nil}}
+
+Summary: GNU Cluster File System
+Name: @PACKAGE_NAME@
+Version: @PACKAGE_VERSION@
+Release: %release_version
+License: GPLv3 or later
+Group: System Environment/Base
+Vendor: Z RESEARCH Inc
+Packager: @PACKAGE_BUGREPORT@
+BuildRoot: %_tmppath/%name-%version-%release-root
+%if %with_ibverbs
+BuildRequires: libibverbs-devel
+%endif
+%if %with_bdb
+BuildRequires: db4-devel
+%endif
+%if %with_client
+BuildRequires: fuse-devel
+%endif
+# Module needs to be fixed.
+%if %with_modglfs
+%if %with_apxs_default
+BuildRequires: apache-devel >= 1.3
+Requires: apache >= 1.3
+%endif
+%endif
+BuildRequires: libtool
+BuildRequires: byacc bison flex
+BuildRequires: gcc
+BuildRequires: make
+URL: ftp://ftp.zresearch.com/pub/gluster/glusterfs/1.4-qa/@PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz
+Source: %name-%version.tar.gz
+
+%description
+GlusterFS is a clustered file-system capable of scaling to several
+peta-bytes. It aggregates various storage bricks over Infiniband RDMA
+or TCP/IP interconnect into one large parallel network file
+system. GlusterFS is one of the most sophisticated file system in
+terms of features and extensibility. It borrows a powerful concept
+called Translators from GNU Hurd kernel. Much of the code in GlusterFS
+is in userspace and easily manageable.
+
+%package devel
+Summary: GlusterFS Development Libraries
+Group: Development/Libraries
+Requires: %name = %version
+
+%description devel
+GlusterFS is a clustered file-system capable of scaling to several
+peta-bytes. It aggregates various storage bricks over Infiniband RDMA
+or TCP/IP interconnect into one large parallel network file
+system. GlusterFS is one of the most sophisticated file system in
+terms of features and extensibility. It borrows a powerful concept
+called Translators from GNU Hurd kernel. Much of the code in GlusterFS
+is in userspace and easily manageable.
+
+This package provides the development libraries.
+
+
+%prep
+# then -n argument says that the unzipped version is NOT %name-%version
+#%setup -n %name-%version
+%setup
+
+
+%build
+%if "%{with_client}" == "0"
+%define client_options --disable-fuse-client
+%endif
+%if "%{with_ibverbs}" == "0"
+%define ibverbs_options --disable-ibverbs
+%endif
+%if "%{with_bdb}" == "0"
+%define bdb_options --disable-bdb
+%endif
+%if "%{with_libglfsclient}" == "0"
+%define libglfs_options --disable-libglusterfsclient
+%endif
+# Module needs to be fixed.
+%if "%{with_modglfs}" == "0"
+%define modglfs_options --disable-mod_glusterfs
+%endif
+%if "%{with_modglfs}" == "1"
+%if "%{with_apxs_default}" == "0"
+%define apxs_options --with-apxs=%{?apxs_path:%apxs_path}
+%endif
+%endif
+%if "%{with_modglfs}" == "1"
+%if "%{with_apache_auto}" == "0"
+%define apxs_bin_options --with-apxspath=%{?apxs_bin_path:%apxs_bin_path}
+%define apache_bin_options --with-apachepath=%{?apache_bin_path:%apache_bin_path}
+%endif
+%endif
+
+%configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=%_libdir %{?client_options:%client_options} %{?ibverbs_options:%ibverbs_options} %{?bdb_options:%bdb_options} %{?libglfs_options:%libglfs_options} %{?modglfs_options:%modglfs_options} %{?apxs_options:%apxs_options} %{?apxs_bin_options:%apxs_bin_options} %{?apache_bin_options:%apache_bin_options}
+%{__make}
+
+
+%install
+%{__rm} -rf $RPM_BUILD_ROOT
+%{__make} install DESTDIR=$RPM_BUILD_ROOT
+%{__rm} -rf $RPM_BUILD_ROOT/share/
+%{__mkdir_p} $RPM_BUILD_ROOT/usr/include/glusterfs
+%{__mkdir_p} $RPM_BUILD_ROOT/var/log/glusterfs
+%{__cp} %_builddir/%name-%version/libglusterfs/src/*.h $RPM_BUILD_ROOT/usr/include/glusterfs/
+
+
+%files
+%doc AUTHORS ChangeLog COPYING INSTALL NEWS README
+%_libdir
+%dir /var/log/glusterfs
+%exclude %_libdir/*.a
+%exclude %_libdir/*.la
+%exclude /usr/include/libglusterfsclient.h
+%doc /usr/share/doc/glusterfs
+%config /etc/glusterfs
+%_prefix/sbin/glusterfs
+%_prefix/sbin/glusterfsd
+%_mandir/man8/glusterfs.8.gz
+%_infodir/user-guide.info.gz
+%exclude %_infodir/dir
+
+%if %with_client
+/sbin/mount.glusterfs
+%endif
+
+%files devel
+%doc AUTHORS ChangeLog COPYING INSTALL NEWS README THANKS
+%_libdir/*.a
+%exclude %_libdir/*.la
+%_prefix/include
+%exclude /usr/include/glusterfs/y.tab.h
+
+%post
+ldconfig -n %_libdir
+%if %with_modglfs
+%if %with_apxs_default
+%{_sbindir}/apxs -i -a -n glusterfs %{_libdir}/glusterfs/%version/apache-1.3/mod_glusterfs.so
+%else
+%{apxs_path}/apxs -i -a -n glusterfs %{_libdir}/glusterfs/%version/apache-1.3/mod_glusterfs.so
+%endif
+%endif
+
+%postun
+ldconfig
+
+%clean
+%{__rm} -rf $RPM_BUILD_ROOT
+
+
+%changelog
+* Fri Dec 12 2008 Harshavardhana <harsha@gluster.com> - 1.4
+- Added new options with --with-apxspath --with-apachepath
+ new configure options.
+ %post install command ldconfig moved up by one line.
+
+* Thu May 08 2008 Harshavardhana <harsha@zresearch.com> - 1.4
+- Added proper checks for apache-1.3 dependency, and enhanced
+ post install scripts
+
+* Wed Apr 23 2008 Harshavardhana <harsha@zresearch.com> - 1.4
+- Removed two new packages due to Excerpts From Amar's reviews.
+
+* Mon Apr 21 2008 Harshavardhana <harsha@zresearch.com> - 1.4
+- Fixed some build problems. And changed BuildRequires with httpd
+ and lighttpd(1.4) version.
+- created libglusterfsclient and modglusterfs new packages.
+
+* Sat Apr 19 2008 Amar Tumballi <amar@zresearch.com> - 1.3.8pre6
+- Merged common, client and server packages into one package.
+- Added options to disable bdb, mod_glusterfs, libglusterfsclient
+
+* Fri Apr 11 2008 Harshavardhana <harsha@zresearch.com> - 1.3.8pre5
+- Changed many hardcoded variables to standard rpm variables. Removed
+ *.la unnecessary for the release. Python option removed as it
+ is not present with the coming releases.
+
+* Tue Feb 12 2008 Harshavardhana <harsha@zresearch.com> - 1.3.8
+- Replaced configure_options with different names for each configure
+ options as it is observed that configure_options never get appended
+ with extra options provided.
+
+* Wed Jan 16 2008 Matt Paine <matt@mattsoftware.com> - 1.3.8
+- Change all /usr/libx directory references to %_libdir
+- Added new switch to enable build without building client RPMS
+
+* Sun Jan 6 2008 Anand V. Avati <avati@zresearch.com> - 1.3.8
+- glusterfs-booster.so back in libdir
+
+* Fri Nov 09 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.8
+- Bumped to new version fixed problem with build for new glusterfs-booster.so
+ inside /usr/bin
+
+* Sun Oct 18 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.7
+- Bumped to new version
+
+* Sun Oct 18 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.6
+- Bumped to new version
+
+* Sun Oct 14 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.5
+- Bumped to new version
+
+* Tue Oct 09 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.4
+- Bumped to new version
+
+* Tue Oct 02 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.3
+- Bumped to new version
+
+* Tue Oct 02 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.2
+- Bumped to new version
+
+* Thu Sep 20 2007 Harshavardhana Ranganath <harsha@zresearch.com> - 1.3.1
+- built new rpms with ibverbs seperate
+
+* Sat Aug 4 2007 Matt Paine <matt@mattsoftware.com> - 1.3.pre7
+- Added support to build rpm without ibverbs support (use --without ibverbs switch)
+
+* Sun Jul 15 2007 Matt Paine <matt@mattsoftware.com> - 1.3.pre6
+- Initial spec file
+
diff --git a/glusterfsd/Makefile.am b/glusterfsd/Makefile.am
new file mode 100644
index 000000000..d471a3f92
--- /dev/null
+++ b/glusterfsd/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = src
+
+CLEANFILES =
diff --git a/glusterfsd/src/Makefile.am b/glusterfsd/src/Makefile.am
new file mode 100644
index 000000000..060917930
--- /dev/null
+++ b/glusterfsd/src/Makefile.am
@@ -0,0 +1,24 @@
+sbin_PROGRAMS = glusterfsd
+
+glusterfsd_SOURCES = glusterfsd.c fetch-spec.c
+glusterfsd_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(GF_LDADD)
+glusterfsd_LDFLAGS = $(GF_LDFLAGS) $(GF_GLUSTERFS_LDFLAGS)
+noinst_HEADERS = glusterfsd.h
+
+AM_CFLAGS = -fPIC -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(GF_HOST_OS)\
+ -I$(top_srcdir)/libglusterfs/src -DDATADIR=\"$(localstatedir)\" \
+ -DCONFDIR=\"$(sysconfdir)/glusterfs\" $(GF_GLUSTERFS_CFLAGS)
+
+CLEANFILES =
+
+$(top_builddir)/libglusterfs/src/libglusterfs.la:
+ $(MAKE) -C $(top_builddir)/libglusterfs/src/ all
+
+uninstall-local:
+ rm -f $(DESTDIR)$(sbindir)/glusterfs
+
+install-data-local:
+ $(INSTALL) -d -m 755 $(DESTDIR)$(localstatedir)/run
+ $(INSTALL) -d -m 755 $(DESTDIR)$(localstatedir)/log/glusterfs
+ rm -f $(DESTDIR)$(sbindir)/glusterfs
+ ln -s glusterfsd $(DESTDIR)$(sbindir)/glusterfs
diff --git a/glusterfsd/src/fetch-spec.c b/glusterfsd/src/fetch-spec.c
new file mode 100644
index 000000000..4009a55b3
--- /dev/null
+++ b/glusterfsd/src/fetch-spec.c
@@ -0,0 +1,266 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif /* _CONFIG_H */
+
+#include "glusterfs.h"
+#include "stack.h"
+#include "dict.h"
+#include "transport.h"
+#include "event.h"
+#include "defaults.h"
+
+
+static int
+fetch_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ char *spec_data)
+{
+ FILE *spec_fp = NULL;
+
+ spec_fp = frame->local;
+
+ if (op_ret >= 0) {
+ fwrite (spec_data, strlen (spec_data), 1, spec_fp);
+ fflush (spec_fp);
+ fclose (spec_fp);
+ }
+ else {
+ gf_log (frame->this->name, GF_LOG_ERROR,
+ "GETSPEC from server returned -1 (%s)",
+ strerror (op_errno));
+ }
+
+ frame->local = NULL;
+ STACK_DESTROY (frame->root);
+
+ /* exit the child process */
+ exit (op_ret);
+}
+
+
+static int
+fetch_notify (xlator_t *this_xl, int event, void *data, ...)
+{
+ int ret = 0;
+ call_frame_t *frame = NULL;
+
+ switch (event)
+ {
+ case GF_EVENT_CHILD_UP:
+ frame = create_frame (this_xl, this_xl->ctx->pool);
+ frame->local = this_xl->private;
+
+ STACK_WIND (frame, fetch_cbk,
+ this_xl->children->xlator,
+ this_xl->children->xlator->mops->getspec,
+ this_xl->ctx->cmd_args.volfile_id,
+ 0);
+ break;
+ case GF_EVENT_CHILD_DOWN:
+ break;
+ default:
+ ret = default_notify (this_xl, event, data);
+ break;
+ }
+
+ return ret;
+}
+
+
+static int
+fetch_init (xlator_t *xl)
+{
+ return 0;
+}
+
+static xlator_t *
+get_shrub (glusterfs_ctx_t *ctx,
+ const char *remote_host,
+ const char *transport,
+ uint32_t remote_port)
+{
+ int ret = 0;
+ xlator_t *top = NULL;
+ xlator_t *trans = NULL;
+ xlator_list_t *parent = NULL, *tmp = NULL;
+
+ top = CALLOC (1, sizeof (*top));
+ ERR_ABORT (top);
+ trans = CALLOC (1, sizeof (*trans));
+ ERR_ABORT (trans);
+
+ top->name = "top";
+ top->ctx = ctx;
+ top->next = trans;
+ top->init = fetch_init;
+ top->notify = fetch_notify;
+ top->children = (void *) CALLOC (1, sizeof (*top->children));
+ ERR_ABORT (top->children);
+ top->children->xlator = trans;
+
+ trans->name = "trans";
+ trans->ctx = ctx;
+ trans->prev = top;
+ trans->init = fetch_init;
+ trans->notify = default_notify;
+ trans->options = get_new_dict ();
+
+ parent = CALLOC (1, sizeof(*parent));
+ parent->xlator = top;
+ if (trans->parents == NULL)
+ trans->parents = parent;
+ else {
+ tmp = trans->parents;
+ while (tmp->next)
+ tmp = tmp->next;
+ tmp->next = parent;
+ }
+
+ /* TODO: log on failure to set dict */
+ if (remote_host)
+ ret = dict_set_static_ptr (trans->options, "remote-host",
+ (char *)remote_host);
+
+ if (remote_port)
+ ret = dict_set_uint32 (trans->options, "remote-port",
+ remote_port);
+
+ /* 'option remote-subvolume <x>' is needed here even though
+ * its not used
+ */
+ ret = dict_set_static_ptr (trans->options, "remote-subvolume",
+ "brick");
+ ret = dict_set_static_ptr (trans->options, "disable-handshake", "on");
+ ret = dict_set_static_ptr (trans->options, "non-blocking-io", "off");
+
+ if (transport) {
+ char *transport_type = CALLOC (1, strlen (transport) + 10);
+ ERR_ABORT (transport_type);
+ strcpy(transport_type, transport);
+
+ if (strchr (transport_type, ':'))
+ *(strchr (transport_type, ':')) = '\0';
+
+ ret = dict_set_dynstr (trans->options, "transport-type",
+ transport_type);
+ }
+
+ xlator_set_type (trans, "protocol/client");
+
+ if (xlator_tree_init (top) != 0)
+ return NULL;
+
+ return top;
+}
+
+
+static int
+_fetch (glusterfs_ctx_t *ctx,
+ FILE *spec_fp,
+ const char *remote_host,
+ const char *transport,
+ uint32_t remote_port)
+{
+ xlator_t *this = NULL;
+
+ this = get_shrub (ctx, remote_host, transport, remote_port);
+ if (this == NULL)
+ return -1;
+
+ this->private = spec_fp;
+
+ event_dispatch (ctx->event_pool);
+
+ return 0;
+}
+
+
+static int
+_fork_and_fetch (glusterfs_ctx_t *ctx,
+ FILE *spec_fp,
+ const char *remote_host,
+ const char *transport,
+ uint32_t remote_port)
+{
+ int ret;
+
+ ret = fork ();
+ switch (ret) {
+ case -1:
+ perror ("fork()");
+ break;
+ case 0:
+ /* child */
+ ret = _fetch (ctx, spec_fp, remote_host,
+ transport, remote_port);
+ if (ret == -1)
+ exit (ret);
+ default:
+ /* parent */
+ wait (&ret);
+ ret = WEXITSTATUS (ret);
+ }
+ return ret;
+}
+
+FILE *
+fetch_spec (glusterfs_ctx_t *ctx)
+{
+ char *remote_host = NULL;
+ char *transport = NULL;
+ FILE *spec_fp;
+ int32_t ret;
+
+ spec_fp = tmpfile ();
+
+ if (!spec_fp) {
+ perror ("tmpfile ()");
+ return NULL;
+ }
+
+ remote_host = ctx->cmd_args.volfile_server;
+ transport = ctx->cmd_args.volfile_server_transport;
+ if (!transport)
+ transport = "socket";
+
+ ret = _fork_and_fetch (ctx, spec_fp, remote_host, transport,
+ ctx->cmd_args.volfile_server_port);
+
+ if (!ret) {
+ fseek (spec_fp, 0, SEEK_SET);
+ }
+ else {
+ fclose (spec_fp);
+ spec_fp = NULL;
+ }
+
+ return spec_fp;
+}
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
new file mode 100644
index 000000000..545f40e80
--- /dev/null
+++ b/glusterfsd/src/glusterfsd.c
@@ -0,0 +1,1123 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <netdb.h>
+#include <signal.h>
+#include <libgen.h>
+
+#include <sys/utsname.h>
+
+#include <stdint.h>
+#include <pthread.h>
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#ifdef HAVE_MALLOC_STATS
+#ifdef DEBUG
+#include <mcheck.h>
+#endif
+#endif
+
+#include "xlator.h"
+#include "glusterfs.h"
+#include "compat.h"
+#include "logging.h"
+#include "dict.h"
+#include "protocol.h"
+#include "list.h"
+#include "timer.h"
+#include "glusterfsd.h"
+#include "stack.h"
+#include "revision.h"
+#include "common-utils.h"
+#include "event.h"
+
+#include <fnmatch.h>
+
+/* using argp for command line parsing */
+static char gf_doc[] = "";
+static char argp_doc[] = "--volfile-server=SERVER [MOUNT-POINT]\n" \
+ "--volfile=VOLFILE [MOUNT-POINT]";
+const char *argp_program_version = "" \
+ PACKAGE_NAME" "PACKAGE_VERSION" built on "__DATE__" "__TIME__ \
+ "\nRepository revision: " GLUSTERFS_REPOSITORY_REVISION "\n" \
+ "Copyright (c) 2006, 2007, 2008 Z RESEARCH Inc. " \
+ "<http://www.zresearch.com>\n" \
+ "GlusterFS comes with ABSOLUTELY NO WARRANTY.\n" \
+ "You may redistribute copies of GlusterFS under the terms of "\
+ "the GNU General Public License.";
+const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
+
+error_t parse_opts (int32_t key, char *arg, struct argp_state *_state);
+
+static struct argp_option gf_options[] = {
+ {0, 0, 0, 0, "Basic options:"},
+ {"volfile-server", ARGP_VOLFILE_SERVER_KEY, "SERVER", 0,
+ "Server to get the volume file from. This option overrides "
+ "--volfile option"},
+ {"volfile", ARGP_VOLUME_FILE_KEY, "VOLFILE", 0,
+ "File to use as VOLUME_FILE [default: "DEFAULT_CLIENT_VOLUME_FILE" or "
+ DEFAULT_SERVER_VOLUME_FILE"]"},
+ {"spec-file", ARGP_VOLUME_FILE_KEY, "VOLFILE", OPTION_HIDDEN,
+ "File to use as VOLFILE [default : "DEFAULT_CLIENT_VOLUME_FILE" or "
+ DEFAULT_SERVER_VOLUME_FILE"]"},
+ {"log-level", ARGP_LOG_LEVEL_KEY, "LOGLEVEL", 0,
+ "Logging severity. Valid options are DEBUG, NORMAL, WARNING, ERROR, "
+ "CRITICAL and NONE [default: NORMAL]"},
+ {"log-file", ARGP_LOG_FILE_KEY, "LOGFILE", 0,
+ "File to use for logging [default: "
+ DEFAULT_LOG_FILE_DIRECTORY "/" PACKAGE_NAME ".log" "]"},
+
+ {0, 0, 0, 0, "Advanced Options:"},
+ {"volfile-server-port", ARGP_VOLFILE_SERVER_PORT_KEY, "PORT", 0,
+ "Listening port number of volfile server"},
+ {"volfile-server-transport", ARGP_VOLFILE_SERVER_TRANSPORT_KEY,
+ "TRANSPORT", 0,
+ "Transport type to get volfile from server [default: socket]"},
+ {"volfile-id", ARGP_VOLFILE_ID_KEY, "KEY", 0,
+ "'key' of the volfile to be fetched from server"},
+ {"pid-file", ARGP_PID_FILE_KEY, "PIDFILE", 0,
+ "File to use as pid file"},
+ {"no-daemon", ARGP_NO_DAEMON_KEY, 0, 0,
+ "Run in foreground"},
+ {"run-id", ARGP_RUN_ID_KEY, "RUN-ID", OPTION_HIDDEN,
+ "Run ID for the process, used by scripts to keep track of process "
+ "they started, defaults to none"},
+ {"debug", ARGP_DEBUG_KEY, 0, 0,
+ "Run in debug mode. This option sets --no-daemon, --log-level "
+ "to DEBUG and --log-file to console"},
+ {"volume-name", ARGP_VOLUME_NAME_KEY, "VOLUME-NAME", 0,
+ "Volume name to be used for MOUNT-POINT [default: top most volume "
+ "in VOLFILE]"},
+ {"xlator-option", ARGP_XLATOR_OPTION_KEY,"VOLUME-NAME.OPTION=VALUE", 0,
+ "Add/override a translator option for a volume with specified value"},
+
+ {0, 0, 0, 0, "Fuse options:"},
+ {"disable-direct-io-mode", ARGP_DISABLE_DIRECT_IO_MODE_KEY, 0, 0,
+ "Disable direct I/O mode in fuse kernel module"},
+ {"entry-timeout", ARGP_ENTRY_TIMEOUT_KEY, "SECONDS", 0,
+ "Set entry timeout to SECONDS in fuse kernel module [default: 1]"},
+ {"attribute-timeout", ARGP_ATTRIBUTE_TIMEOUT_KEY, "SECONDS", 0,
+ "Set attribute timeout to SECONDS for inodes in fuse kernel module "
+ "[default: 1]"},
+#ifdef GF_DARWIN_HOST_OS
+ {"non-local", ARGP_NON_LOCAL_KEY, 0, 0,
+ "Mount the macfuse volume without '-o local' option"},
+#endif
+ {0, 0, 0, 0, "Miscellaneous Options:"},
+ {0, }
+};
+
+
+static struct argp argp = { gf_options, parse_opts, argp_doc, gf_doc };
+
+
+static void
+_gf_dump_details (int argc, char **argv)
+{
+ extern FILE *gf_log_logfile;
+ int i = 0;
+ char timestr[256];
+ time_t utime = 0;
+ struct tm *tm = NULL;
+ pid_t mypid = 0;
+ struct utsname uname_buf = {{0, }, };
+ int uname_ret = -1;
+
+ utime = time (NULL);
+ tm = localtime (&utime);
+ mypid = getpid ();
+ uname_ret = uname (&uname_buf);
+
+ /* Which TLA? What time? */
+ strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
+ fprintf (gf_log_logfile,
+ "========================================"
+ "========================================\n");
+ fprintf (gf_log_logfile, "Version : %s %s built on %s %s\n",
+ PACKAGE_NAME, PACKAGE_VERSION, __DATE__, __TIME__);
+ fprintf (gf_log_logfile, "TLA Revision : %s\n",
+ GLUSTERFS_REPOSITORY_REVISION);
+ fprintf (gf_log_logfile, "Starting Time: %s\n", timestr);
+ fprintf (gf_log_logfile, "Command line : ");
+ for (i = 0; i < argc; i++) {
+ fprintf (gf_log_logfile, "%s ", argv[i]);
+ }
+
+ fprintf (gf_log_logfile, "\nPID : %d\n", mypid);
+
+ if (uname_ret == 0) {
+ fprintf (gf_log_logfile, "System name : %s\n", uname_buf.sysname);
+ fprintf (gf_log_logfile, "Nodename : %s\n", uname_buf.nodename);
+ fprintf (gf_log_logfile, "Kernel Release : %s\n", uname_buf.release);
+ fprintf (gf_log_logfile, "Hardware Identifier: %s\n", uname_buf.machine);
+ }
+
+
+ fprintf (gf_log_logfile, "\n");
+ fflush (gf_log_logfile);
+}
+
+
+
+static xlator_t *
+_add_fuse_mount (xlator_t *graph)
+{
+ int ret = 0;
+ cmd_args_t *cmd_args = NULL;
+ xlator_t *top = NULL;
+ glusterfs_ctx_t *ctx = NULL;
+ xlator_list_t *xlchild = NULL;
+
+ ctx = graph->ctx;
+ cmd_args = &ctx->cmd_args;
+
+ xlchild = CALLOC (sizeof (*xlchild), 1);
+ ERR_ABORT (xlchild);
+ xlchild->xlator = graph;
+
+ top = CALLOC (1, sizeof (*top));
+ top->name = strdup ("fuse");
+ if (xlator_set_type (top, ZR_XLATOR_FUSE) == -1) {
+ fprintf (stderr,
+ "MOUNT-POINT %s initialization failed",
+ cmd_args->mount_point);
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "MOUNT-POINT %s initialization failed",
+ cmd_args->mount_point);
+ return NULL;
+ }
+ top->children = xlchild;
+ top->ctx = graph->ctx;
+ top->next = graph;
+ top->options = get_new_dict ();
+
+ ret = dict_set_static_ptr (top->options, ZR_MOUNTPOINT_OPT,
+ cmd_args->mount_point);
+ if (ret < 0) {
+ gf_log ("glusterfs", GF_LOG_DEBUG,
+ "failed to set mount-point to options dictionary");
+ }
+
+ if (cmd_args->fuse_attribute_timeout)
+ ret = dict_set_uint32 (top->options, ZR_ATTR_TIMEOUT_OPT,
+ cmd_args->fuse_attribute_timeout);
+ if (cmd_args->fuse_entry_timeout)
+ ret = dict_set_uint32 (top->options, ZR_ENTRY_TIMEOUT_OPT,
+ cmd_args->fuse_entry_timeout);
+
+#ifdef GF_DARWIN_HOST_OS
+ /* On Darwin machines, O_APPEND is not handled,
+ * which may corrupt the data
+ */
+ if (cmd_args->fuse_direct_io_mode_flag == _gf_true) {
+ gf_log ("glusterfs", GF_LOG_DEBUG,
+ "'direct-io-mode' in fuse causes data corruption "
+ "if O_APPEND is used. disabling 'direct-io-mode'");
+ }
+ ret = dict_set_static_ptr (top->options, ZR_DIRECT_IO_OPT, "disable");
+
+ if (cmd_args->non_local)
+ ret = dict_set_uint32 (top->options, "macfuse-local",
+ cmd_args->non_local);
+
+#else /* ! DARWIN HOST OS */
+ if (cmd_args->fuse_direct_io_mode_flag == _gf_true) {
+ ret = dict_set_static_ptr (top->options, ZR_DIRECT_IO_OPT,
+ "enable");
+ } else {
+ ret = dict_set_static_ptr (top->options, ZR_DIRECT_IO_OPT,
+ "disable");
+ }
+
+#endif /* GF_DARWIN_HOST_OS */
+
+ graph->parents = CALLOC (1, sizeof (xlator_list_t));
+ graph->parents->xlator = top;
+
+ return top;
+}
+
+
+static FILE *
+_get_specfp (glusterfs_ctx_t *ctx)
+{
+ int ret = 0;
+ cmd_args_t *cmd_args = NULL;
+ FILE *specfp = NULL;
+ struct stat statbuf;
+
+ cmd_args = &ctx->cmd_args;
+
+ if (cmd_args->volfile_server) {
+ specfp = fetch_spec (ctx);
+
+ if (specfp == NULL) {
+ fprintf (stderr,
+ "error while getting volume file from "
+ "server %s\n", cmd_args->volfile_server);
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "error while getting volume file from "
+ "server %s", cmd_args->volfile_server);
+ }
+ else {
+ gf_log ("glusterfs", GF_LOG_DEBUG,
+ "loading volume file from server %s",
+ cmd_args->volfile_server);
+ }
+
+ return specfp;
+ }
+
+ ret = stat (cmd_args->volume_file, &statbuf);
+ if (ret == -1) {
+ fprintf (stderr, "%s: %s\n",
+ cmd_args->volume_file, strerror (errno));
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "%s: %s", cmd_args->volume_file, strerror (errno));
+ return NULL;
+ }
+ if (!(S_ISREG (statbuf.st_mode) || S_ISLNK (statbuf.st_mode))) {
+ fprintf (stderr,
+ "provide a valid volume file\n");
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "provide a valid volume file");
+ return NULL;
+ }
+ if ((specfp = fopen (cmd_args->volume_file, "r")) == NULL) {
+ fprintf (stderr, "volume file %s: %s\n",
+ cmd_args->volume_file,
+ strerror (errno));
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "volume file %s: %s",
+ cmd_args->volume_file,
+ strerror (errno));
+ return NULL;
+ }
+
+ gf_log ("glusterfs", GF_LOG_DEBUG,
+ "loading volume file %s", cmd_args->volume_file);
+
+ return specfp;
+}
+
+static xlator_t *
+_parse_specfp (glusterfs_ctx_t *ctx,
+ FILE *specfp)
+{
+ cmd_args_t *cmd_args = NULL;
+ xlator_t *tree = NULL, *trav = NULL, *new_tree = NULL;
+
+ cmd_args = &ctx->cmd_args;
+
+ fseek (specfp, 0L, SEEK_SET);
+
+ tree = file_to_xlator_tree (ctx, specfp);
+ trav = tree;
+
+ if (tree == NULL) {
+ if (cmd_args->volfile_server) {
+ fprintf (stderr,
+ "error in parsing volume file given by "
+ "server %s\n", cmd_args->volfile_server);
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "error in parsing volume file given by "
+ "server %s", cmd_args->volfile_server);
+ }
+ else {
+ fprintf (stderr,
+ "error in parsing volume file %s\n",
+ cmd_args->volume_file);
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "error in parsing volume file %s",
+ cmd_args->volume_file);
+ }
+ return NULL;
+ }
+
+ /* if volume_name is given, then we attach to it */
+ if (cmd_args->volume_name) {
+ while (trav) {
+ if (strcmp (trav->name, cmd_args->volume_name) == 0) {
+ new_tree = trav;
+ break;
+ }
+ trav = trav->next;
+ }
+
+ if (!trav) {
+ if (cmd_args->volfile_server) {
+ fprintf (stderr,
+ "volume %s not found in volume "
+ "file given by server %s\n",
+ cmd_args->volume_name,
+ cmd_args->volfile_server);
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "volume %s not found in volume "
+ "file given by server %s",
+ cmd_args->volume_name,
+ cmd_args->volfile_server);
+ } else {
+ fprintf (stderr,
+ "volume %s not found in volume "
+ "file %s\n",
+ cmd_args->volume_name,
+ cmd_args->volume_file);
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "volume %s not found in volume "
+ "file %s", cmd_args->volume_name,
+ cmd_args->volume_file);
+ }
+ return NULL;
+ }
+ tree = trav;
+ }
+ return tree;
+}
+
+static int
+_log_if_option_is_invalid (xlator_t *xl, data_pair_t *pair)
+{
+ volume_opt_list_t *vol_opt = NULL;
+ volume_option_t *opt = NULL;
+ int i = 0;
+ int index = 0;
+ int found = 0;
+
+ /* Get the first volume_option */
+ list_for_each_entry (vol_opt, &xl->volume_options, list) {
+ /* Warn for extra option */
+ if (!vol_opt->given_opt)
+ break;
+
+ opt = vol_opt->given_opt;
+ for (index = 0;
+ ((index < ZR_OPTION_MAX_ARRAY_SIZE) &&
+ (opt[index].key && opt[index].key[0])); index++)
+ for (i = 0; (i < ZR_VOLUME_MAX_NUM_KEY) &&
+ opt[index].key[i]; i++) {
+ if (fnmatch (opt[index].key[i],
+ pair->key,
+ FNM_NOESCAPE) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ }
+
+ if (!found) {
+ gf_log (xl->name, GF_LOG_WARNING,
+ "option '%s' is not recognized",
+ pair->key);
+ }
+ return 0;
+}
+
+static int
+_xlator_graph_init (xlator_t *xl)
+{
+ volume_opt_list_t *vol_opt = NULL;
+ data_pair_t *pair = NULL;
+ xlator_t *trav = NULL;
+ int ret = -1;
+
+ trav = xl;
+
+ while (trav->prev)
+ trav = trav->prev;
+
+ /* Validate phase */
+ while (trav) {
+ /* Get the first volume_option */
+ list_for_each_entry (vol_opt,
+ &trav->volume_options, list)
+ break;
+ if ((ret =
+ validate_xlator_volume_options (trav,
+ vol_opt->given_opt)) < 0) {
+ gf_log (trav->name, GF_LOG_ERROR,
+ "validating translator failed");
+ return ret;
+ }
+ trav = trav->next;
+ }
+
+
+ trav = xl;
+ while (trav->prev)
+ trav = trav->prev;
+ /* Initialization phase */
+ while (trav) {
+ if (!trav->ready) {
+ if ((ret = xlator_tree_init (trav)) < 0) {
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "initializing translator failed");
+ return ret;
+ }
+ }
+ trav = trav->next;
+ }
+
+ /* No error in this phase, just bunch of warning if at all */
+ trav = xl;
+
+ while (trav->prev)
+ trav = trav->prev;
+
+ /* Validate again phase */
+ while (trav) {
+ pair = trav->options->members_list;
+ while (pair) {
+ _log_if_option_is_invalid (trav, pair);
+ pair = pair->next;
+ }
+ trav = trav->next;
+ }
+
+ return ret;
+}
+
+int
+glusterfs_graph_init (xlator_t *graph, int fuse)
+{
+ volume_opt_list_t *vol_opt = NULL;
+
+ if (fuse) {
+ /* FUSE needs to be initialized earlier than the
+ other translators */
+ list_for_each_entry (vol_opt,
+ &graph->volume_options, list)
+ break;
+ if (validate_xlator_volume_options (graph,
+ vol_opt->given_opt) == -1) {
+ gf_log (graph->name, GF_LOG_ERROR,
+ "validating translator failed");
+ return -1;
+ }
+ if (graph->init (graph) != 0)
+ return -1;
+
+ graph->ready = 1;
+ }
+ if (_xlator_graph_init (graph) == -1)
+ return -1;
+
+ /* check server or fuse is given */
+ if (graph->ctx->top == NULL) {
+ fprintf (stderr, "no valid translator loaded at the top, or"
+ "no mount point given. exiting\n");
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "no valid translator loaded at the top or "
+ "no mount point given. exiting");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+gf_remember_xlator_option (struct list_head *options, char *arg)
+{
+ glusterfs_ctx_t *ctx = NULL;
+ cmd_args_t *cmd_args = NULL;
+ xlator_cmdline_option_t *option = NULL;
+ int ret = -1;
+ char *dot = NULL;
+ char *equals = NULL;
+
+ ctx = get_global_ctx_ptr ();
+ cmd_args = &ctx->cmd_args;
+
+ option = CALLOC (1, sizeof (xlator_cmdline_option_t));
+ INIT_LIST_HEAD (&option->cmd_args);
+
+ dot = strchr (arg, '.');
+ if (!dot)
+ goto out;
+
+ option->volume = CALLOC ((dot - arg), sizeof (char));
+ strncpy (option->volume, arg, (dot - arg));
+
+ equals = strchr (arg, '=');
+ if (!equals)
+ goto out;
+
+ option->key = CALLOC ((equals - dot), sizeof (char));
+ strncpy (option->key, dot + 1, (equals - dot - 1));
+
+ if (!*(equals + 1))
+ goto out;
+
+ option->value = strdup (equals + 1);
+
+ list_add (&option->cmd_args, &cmd_args->xlator_options);
+
+ ret = 0;
+out:
+ if (ret == -1) {
+ if (option) {
+ if (option->volume)
+ FREE (option->volume);
+ if (option->key)
+ FREE (option->key);
+ if (option->value)
+ FREE (option->value);
+
+ FREE (option);
+ }
+ }
+
+ return ret;
+}
+
+
+static void
+gf_add_cmdline_options (xlator_t *graph, cmd_args_t *cmd_args)
+{
+ int ret = 0;
+ xlator_t *trav = graph;
+ xlator_cmdline_option_t *cmd_option = NULL;
+
+ while (trav) {
+ list_for_each_entry (cmd_option,
+ &cmd_args->xlator_options, cmd_args) {
+ if (!fnmatch (cmd_option->volume,
+ trav->name, FNM_NOESCAPE)) {
+ ret = dict_set_str (trav->options,
+ cmd_option->key,
+ cmd_option->value);
+ if (ret == 0) {
+ gf_log ("glusterfs", GF_LOG_WARNING,
+ "adding option '%s' for "
+ "volume '%s' with value '%s'",
+ cmd_option->key, trav->name,
+ cmd_option->value);
+ } else {
+ gf_log ("glusterfs", GF_LOG_WARNING,
+ "adding option '%s' for "
+ "volume '%s' failed: %s",
+ cmd_option->key, trav->name,
+ strerror (-ret));
+ }
+ }
+ }
+ trav = trav->next;
+ }
+}
+
+
+error_t
+parse_opts (int key, char *arg, struct argp_state *state)
+{
+ cmd_args_t *cmd_args = NULL;
+ uint32_t n = 0;
+
+ cmd_args = state->input;
+
+ switch (key) {
+ case ARGP_VOLFILE_SERVER_KEY:
+ cmd_args->volfile_server = strdup (arg);
+ break;
+
+ case ARGP_VOLUME_FILE_KEY:
+ cmd_args->volume_file = strdup (arg);
+ break;
+
+ case ARGP_LOG_LEVEL_KEY:
+ if (strcasecmp (arg, ARGP_LOG_LEVEL_NONE_OPTION) == 0) {
+ cmd_args->log_level = GF_LOG_NONE;
+ break;
+ }
+ if (strcasecmp (arg, ARGP_LOG_LEVEL_TRACE_OPTION) == 0) {
+ cmd_args->log_level = GF_LOG_TRACE;
+ break;
+ }
+ if (strcasecmp (arg, ARGP_LOG_LEVEL_CRITICAL_OPTION) == 0) {
+ cmd_args->log_level = GF_LOG_CRITICAL;
+ break;
+ }
+ if (strcasecmp (arg, ARGP_LOG_LEVEL_ERROR_OPTION) == 0) {
+ cmd_args->log_level = GF_LOG_ERROR;
+ break;
+ }
+ if (strcasecmp (arg, ARGP_LOG_LEVEL_WARNING_OPTION) == 0) {
+ cmd_args->log_level = GF_LOG_WARNING;
+ break;
+ }
+ if (strcasecmp (arg, ARGP_LOG_LEVEL_NORMAL_OPTION) == 0) {
+ cmd_args->log_level = GF_LOG_NORMAL;
+ break;
+ }
+ if (strcasecmp (arg, ARGP_LOG_LEVEL_DEBUG_OPTION) == 0) {
+ cmd_args->log_level = GF_LOG_DEBUG;
+ break;
+ }
+
+ argp_failure (state, -1, 0, "unknown log level %s", arg);
+ break;
+
+ case ARGP_LOG_FILE_KEY:
+ cmd_args->log_file = strdup (arg);
+ break;
+
+ case ARGP_VOLFILE_SERVER_PORT_KEY:
+ n = 0;
+
+ if (gf_string2uint_base10 (arg, &n) == 0) {
+ cmd_args->volfile_server_port = n;
+ break;
+ }
+
+ argp_failure (state, -1, 0,
+ "unknown volfile server port %s", arg);
+ break;
+
+ case ARGP_VOLFILE_SERVER_TRANSPORT_KEY:
+ cmd_args->volfile_server_transport = strdup (arg);
+ break;
+
+ case ARGP_VOLFILE_ID_KEY:
+ cmd_args->volfile_id = strdup (arg);
+ break;
+
+ case ARGP_PID_FILE_KEY:
+ cmd_args->pid_file = strdup (arg);
+ break;
+
+ case ARGP_NO_DAEMON_KEY:
+ cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE;
+ break;
+
+ case ARGP_RUN_ID_KEY:
+ cmd_args->run_id = strdup (arg);
+ break;
+
+ case ARGP_DEBUG_KEY:
+ cmd_args->debug_mode = ENABLE_DEBUG_MODE;
+ break;
+
+ case ARGP_DISABLE_DIRECT_IO_MODE_KEY:
+ cmd_args->fuse_direct_io_mode_flag = _gf_false;
+ break;
+
+ case ARGP_ENTRY_TIMEOUT_KEY:
+ n = 0;
+
+ if (gf_string2uint_base10 (arg, &n) == 0) {
+ cmd_args->fuse_entry_timeout = n;
+ break;
+ }
+
+ argp_failure (state, -1, 0, "unknown entry timeout %s", arg);
+ break;
+
+ case ARGP_ATTRIBUTE_TIMEOUT_KEY:
+ n = 0;
+
+ if (gf_string2uint_base10 (arg, &n) == 0) {
+ cmd_args->fuse_attribute_timeout = n;
+ break;
+ }
+
+ argp_failure (state, -1, 0,
+ "unknown attribute timeout %s", arg);
+ break;
+
+ case ARGP_VOLUME_NAME_KEY:
+ cmd_args->volume_name = strdup (arg);
+ break;
+
+ case ARGP_XLATOR_OPTION_KEY:
+ gf_remember_xlator_option (&cmd_args->xlator_options, arg);
+ break;
+
+#ifdef GF_DARWIN_HOST_OS
+ case ARGP_NON_LOCAL_KEY:
+ cmd_args->non_local = _gf_true;
+ break;
+
+#endif /* DARWIN */
+
+ case ARGP_KEY_NO_ARGS:
+ break;
+
+ case ARGP_KEY_ARG:
+ if (state->arg_num >= 1)
+ argp_usage (state);
+
+ cmd_args->mount_point = strdup (arg);
+ break;
+ }
+
+ return 0;
+}
+
+
+void
+cleanup_and_exit (int signum)
+{
+ glusterfs_ctx_t *ctx = NULL;
+ xlator_t *trav = NULL;
+
+ ctx = get_global_ctx_ptr ();
+
+ gf_log ("glusterfs", GF_LOG_WARNING, "shutting down");
+
+ if (ctx->pidfp) {
+ gf_unlockfd (fileno (ctx->pidfp));
+ fclose (ctx->pidfp);
+ ctx->pidfp = NULL;
+ }
+
+ if (ctx->specfp) {
+ fclose (ctx->specfp);
+ ctx->specfp = NULL;
+ }
+
+ if (ctx->cmd_args.pid_file) {
+ unlink (ctx->cmd_args.pid_file);
+ ctx->cmd_args.pid_file = NULL;
+ }
+
+ if (ctx->graph) {
+ trav = ctx->graph;
+ ctx->graph = NULL;
+ while (trav) {
+ trav->fini (trav);
+ trav = trav->next;
+ }
+ exit (0);
+ } else {
+ gf_log ("glusterfs", GF_LOG_DEBUG, "no graph present");
+ }
+}
+
+
+static char *
+zr_build_process_uuid ()
+{
+ char tmp_str[1024] = {0,};
+ char hostname[256] = {0,};
+ struct timeval tv = {0,};
+ struct tm now = {0, };
+ char now_str[32];
+
+ if (-1 == gettimeofday(&tv, NULL)) {
+ gf_log ("", GF_LOG_ERROR,
+ "gettimeofday: failed %s",
+ strerror (errno));
+ }
+
+ if (-1 == gethostname (hostname, 256)) {
+ gf_log ("", GF_LOG_ERROR,
+ "gethostname: failed %s",
+ strerror (errno));
+ }
+
+ localtime_r (&tv.tv_sec, &now);
+ strftime (now_str, 32, "%Y/%m/%d-%H:%M:%S", &now);
+ snprintf (tmp_str, 1024, "%s-%d-%s:%ld",
+ hostname, getpid(), now_str, tv.tv_usec);
+
+ return strdup (tmp_str);
+}
+
+#define GF_SERVER_PROCESS 0
+#define GF_CLIENT_PROCESS 1
+
+static uint8_t
+gf_get_process_mode (char *exec_name)
+{
+ char *dup_execname = NULL, *base = NULL;
+ uint8_t ret = 0;
+
+ dup_execname = strdup (exec_name);
+ base = basename (dup_execname);
+
+ if (!strncmp (base, "glusterfsd", 10)) {
+ ret = GF_SERVER_PROCESS;
+ } else {
+ ret = GF_CLIENT_PROCESS;
+ }
+
+ free (dup_execname);
+
+ return ret;
+}
+
+int
+main (int argc, char *argv[])
+{
+ glusterfs_ctx_t *ctx = NULL;
+ cmd_args_t *cmd_args = NULL;
+ call_pool_t *pool = NULL;
+ struct stat stbuf;
+ char tmp_logfile[1024] = { 0 };
+ char timestr[256] = { 0 };
+ char *base_exec_name = NULL;
+ time_t utime;
+ struct tm *tm = NULL;
+ int ret = 0;
+ struct rlimit lim;
+ FILE *specfp = NULL;
+ xlator_t *graph = NULL;
+ xlator_t *trav = NULL;
+ int fuse_volume_found = 0;
+ int xl_count = 0;
+ uint8_t process_mode = 0;
+
+ utime = time (NULL);
+ ctx = CALLOC (1, sizeof (glusterfs_ctx_t));
+ ERR_ABORT (ctx);
+ base_exec_name = strdup (argv[0]);
+ process_mode = gf_get_process_mode (base_exec_name);
+ set_global_ctx_ptr (ctx);
+ ctx->process_uuid = zr_build_process_uuid ();
+ cmd_args = &ctx->cmd_args;
+
+ /* parsing command line arguments */
+ cmd_args->log_level = DEFAULT_LOG_LEVEL;
+ cmd_args->fuse_direct_io_mode_flag = _gf_true;
+
+ INIT_LIST_HEAD (&cmd_args->xlator_options);
+
+ argp_parse (&argp, argc, argv, ARGP_IN_ORDER, NULL, cmd_args);
+
+ if (ENABLE_DEBUG_MODE == cmd_args->debug_mode) {
+ cmd_args->log_level = GF_LOG_DEBUG;
+ cmd_args->log_file = "/dev/stdout";
+ cmd_args->no_daemon_mode = ENABLE_NO_DAEMON_MODE;
+ }
+
+ if ((cmd_args->volfile_server == NULL)
+ && (cmd_args->volume_file == NULL)) {
+ if (process_mode == GF_SERVER_PROCESS)
+ cmd_args->volume_file = strdup (DEFAULT_SERVER_VOLUME_FILE);
+ else
+ cmd_args->volume_file = strdup (DEFAULT_CLIENT_VOLUME_FILE);
+ }
+
+ if (cmd_args->log_file == NULL)
+ asprintf (&cmd_args->log_file,
+ DEFAULT_LOG_FILE_DIRECTORY "/%s.log",
+ basename (base_exec_name));
+
+ free (base_exec_name);
+
+ ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE);
+ pthread_mutex_init (&(ctx->lock), NULL);
+ pool = ctx->pool = CALLOC (1, sizeof (call_pool_t));
+ ERR_ABORT (ctx->pool);
+ LOCK_INIT (&pool->lock);
+ INIT_LIST_HEAD (&pool->all_frames);
+
+ if (cmd_args->pid_file != NULL) {
+ ctx->pidfp = fopen (cmd_args->pid_file, "a+");
+ if (ctx->pidfp == NULL) {
+ fprintf (stderr,
+ "unable to open pid file %s. %s. exiting\n",
+ cmd_args->pid_file, strerror (errno));
+ /* do cleanup and exit ?! */
+ return -1;
+ }
+ ret = gf_lockfd (fileno (ctx->pidfp));
+ if (ret == -1) {
+ fprintf (stderr, "unable to lock pid file %s. %s. "
+ "Is another instance of %s running?!\n"
+ "exiting\n", cmd_args->pid_file,
+ strerror (errno), argv[0]);
+ fclose (ctx->pidfp);
+ return -1;
+ }
+ ret = ftruncate (fileno (ctx->pidfp), 0);
+ if (ret == -1) {
+ fprintf (stderr,
+ "unable to truncate file %s. %s. exiting\n",
+ cmd_args->pid_file, strerror (errno));
+ gf_unlockfd (fileno (ctx->pidfp));
+ fclose (ctx->pidfp);
+ return -1;
+ }
+ }
+
+ /* initializing logs */
+ if (cmd_args->run_id) {
+ ret = stat (cmd_args->log_file, &stbuf);
+ /* If its /dev/null, or /dev/stdout, /dev/stderr,
+ * let it use the same, no need to alter
+ */
+ if (((ret == 0) &&
+ (S_ISREG (stbuf.st_mode) || S_ISLNK (stbuf.st_mode))) ||
+ (ret == -1)) {
+ /* Have seperate logfile per run */
+ tm = localtime (&utime);
+ strftime (timestr, 256, "%Y%m%d.%H%M%S", tm);
+ sprintf (tmp_logfile, "%s.%s.%d",
+ cmd_args->log_file, timestr, getpid ());
+
+ /* Create symlink to actual log file */
+ unlink (cmd_args->log_file);
+ symlink (tmp_logfile, cmd_args->log_file);
+
+ FREE (cmd_args->log_file);
+ cmd_args->log_file = strdup (tmp_logfile);
+ }
+ }
+
+ gf_global_variable_init ();
+
+ if (gf_log_init (cmd_args->log_file) == -1) {
+ fprintf (stderr,
+ "failed to open logfile %s. exiting\n",
+ cmd_args->log_file);
+ return -1;
+ }
+ gf_log_set_loglevel (cmd_args->log_level);
+
+ /* setting up environment */
+ lim.rlim_cur = RLIM_INFINITY;
+ lim.rlim_max = RLIM_INFINITY;
+ if (setrlimit (RLIMIT_CORE, &lim) == -1) {
+ fprintf (stderr, "ignoring %s\n",
+ strerror (errno));
+ }
+#ifdef HAVE_MALLOC_STATS
+#ifdef DEBUG
+ mtrace ();
+#endif
+ signal (SIGUSR1, (sighandler_t) malloc_stats);
+#endif
+ signal (SIGSEGV, gf_print_trace);
+ signal (SIGABRT, gf_print_trace);
+ signal (SIGPIPE, SIG_IGN);
+ signal (SIGHUP, gf_log_logrotate);
+ signal (SIGTERM, cleanup_and_exit);
+ /* This is used to dump details */
+ /* signal (SIGUSR2, (sighandler_t) glusterfs_stats); */
+
+ /* getting and parsing volume file */
+ if ((specfp = _get_specfp (ctx)) == NULL) {
+ /* _get_specfp() prints necessary error message */
+ gf_log ("glusterfs", GF_LOG_ERROR, "exiting\n");
+ argp_help (&argp, stderr, ARGP_HELP_SEE, (char *) argv[0]);
+ return -1;
+ }
+ _gf_dump_details (argc, argv);
+ gf_log_volume_file (specfp);
+ if ((graph = _parse_specfp (ctx, specfp)) == NULL) {
+ /* _parse_specfp() prints necessary error message */
+ fprintf (stderr, "exiting\n");
+ gf_log ("glusterfs", GF_LOG_ERROR, "exiting");
+ return -1;
+ }
+ ctx->specfp = specfp;
+
+ /* check whether MOUNT-POINT argument and fuse volume are given
+ * at same time or not. If not, add argument MOUNT-POINT to graph
+ * as top volume if given
+ */
+ trav = graph;
+ fuse_volume_found = 0;
+
+ while (trav) {
+ if (strcmp (trav->type, ZR_XLATOR_FUSE) == 0) {
+ if (dict_get (trav->options,
+ ZR_MOUNTPOINT_OPT) != NULL) {
+ trav->ctx = graph->ctx;
+ fuse_volume_found = 1;
+ }
+ }
+
+ xl_count++; /* Getting this value right is very important */
+ trav = trav->next;
+ }
+
+ ctx->xl_count = xl_count + 1;
+
+ if (!fuse_volume_found && (cmd_args->mount_point != NULL)) {
+ if ((graph = _add_fuse_mount (graph)) == NULL) {
+ /* _add_fuse_mount() prints necessary
+ * error message
+ */
+ fprintf (stderr, "exiting\n");
+ gf_log ("glusterfs", GF_LOG_ERROR, "exiting");
+ return -1;
+ }
+ }
+
+ /* daemonize now */
+ if (!cmd_args->no_daemon_mode) {
+ if (daemon (0, 0) == -1) {
+ fprintf (stderr, "unable to run in daemon mode: %s",
+ strerror (errno));
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "unable to run in daemon mode: %s",
+ strerror (errno));
+ return -1;
+ }
+
+ /* we are daemon now */
+ /* update pid file, if given */
+ if (cmd_args->pid_file != NULL) {
+ fprintf (ctx->pidfp, "%d\n", getpid ());
+ fflush (ctx->pidfp);
+ /* we close pid file on exit */
+ }
+ }
+
+ gf_log ("glusterfs", GF_LOG_DEBUG,
+ "running in pid %d", getpid ());
+
+ gf_timer_registry_init (ctx);
+
+ /* override xlator options with command line options
+ * where applicable
+ */
+ gf_add_cmdline_options (graph, cmd_args);
+
+ ctx->graph = graph;
+ if (glusterfs_graph_init (graph, fuse_volume_found) != 0) {
+ gf_log ("glusterfs", GF_LOG_ERROR,
+ "translator initialization failed. exiting");
+ return -1;
+ }
+
+ /* Send PARENT_UP notify to all the translators now */
+ graph->notify (graph, GF_EVENT_PARENT_UP, ctx->graph);
+
+ gf_log ("glusterfs", GF_LOG_NORMAL, "Successfully started");
+
+ event_dispatch (ctx->event_pool);
+
+ return 0;
+}
diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h
new file mode 100644
index 000000000..69ad6b07a
--- /dev/null
+++ b/glusterfsd/src/glusterfsd.h
@@ -0,0 +1,78 @@
+/*
+ Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __GLUSTERFSD_H__
+#define __GLUSTERFSD_H__
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#define DEFAULT_CLIENT_VOLUME_FILE CONFDIR "/glusterfs.vol"
+#define DEFAULT_SERVER_VOLUME_FILE CONFDIR "/glusterfsd.vol"
+#define DEFAULT_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs"
+#define DEFAULT_LOG_LEVEL GF_LOG_NORMAL
+
+#define DEFAULT_EVENT_POOL_SIZE 16384
+
+#define ARGP_LOG_LEVEL_NONE_OPTION "NONE"
+#define ARGP_LOG_LEVEL_TRACE_OPTION "TRACE"
+#define ARGP_LOG_LEVEL_CRITICAL_OPTION "CRITICAL"
+#define ARGP_LOG_LEVEL_ERROR_OPTION "ERROR"
+#define ARGP_LOG_LEVEL_WARNING_OPTION "WARNING"
+#define ARGP_LOG_LEVEL_NORMAL_OPTION "NORMAL"
+#define ARGP_LOG_LEVEL_DEBUG_OPTION "DEBUG"
+
+#define ENABLE_NO_DAEMON_MODE 1
+#define ENABLE_DEBUG_MODE 1
+
+#define ZR_XLATOR_FUSE "mount/fuse"
+#define ZR_MOUNTPOINT_OPT "mountpoint"
+#define ZR_ATTR_TIMEOUT_OPT "attribute-timeout"
+#define ZR_ENTRY_TIMEOUT_OPT "entry-timeout"
+#define ZR_DIRECT_IO_OPT "direct-io-mode"
+
+enum argp_option_keys {
+ ARGP_VOLFILE_SERVER_KEY = 's',
+ ARGP_VOLUME_FILE_KEY = 'f',
+ ARGP_LOG_LEVEL_KEY = 'L',
+ ARGP_LOG_FILE_KEY = 'l',
+ ARGP_VOLFILE_SERVER_PORT_KEY = 131,
+ ARGP_VOLFILE_SERVER_TRANSPORT_KEY = 132,
+ ARGP_PID_FILE_KEY = 'p',
+ ARGP_NO_DAEMON_KEY = 'N',
+ ARGP_RUN_ID_KEY = 'r',
+ ARGP_DEBUG_KEY = 133,
+ ARGP_DISABLE_DIRECT_IO_MODE_KEY = 134,
+ ARGP_ENTRY_TIMEOUT_KEY = 135,
+ ARGP_ATTRIBUTE_TIMEOUT_KEY = 136,
+ ARGP_VOLUME_NAME_KEY = 137,
+ ARGP_XLATOR_OPTION_KEY = 138,
+#ifdef GF_DARWIN_HOST_OS
+ ARGP_NON_LOCAL_KEY = 139,
+#endif /* DARWIN */
+ ARGP_VOLFILE_ID_KEY = 143,
+};
+
+/* Moved here from fetch-spec.h */
+FILE *fetch_spec (glusterfs_ctx_t *ctx);
+
+
+#endif /* __GLUSTERFSD_H__ */
diff --git a/libglusterfs/Makefile.am b/libglusterfs/Makefile.am
new file mode 100644
index 000000000..d471a3f92
--- /dev/null
+++ b/libglusterfs/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = src
+
+CLEANFILES =
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
new file mode 100644
index 000000000..16e6717de
--- /dev/null
+++ b/libglusterfs/src/Makefile.am
@@ -0,0 +1,21 @@
+libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS)
+
+libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\" -DTRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/transport\" -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\"
+
+libglusterfs_la_LIBADD = @LEXLIB@
+
+lib_LTLIBRARIES = libglusterfs.la
+
+libglusterfs_la_SOURCES = dict.c spec.lex.c y.tab.c xlator.c logging.c hashfn.c defaults.c scheduler.c common-utils.c transport.c timer.c inode.c call-stub.c compat.c authenticate.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c
+
+noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h logging.h protocol.h scheduler.h xlator.h transport.h stack.h timer.h list.h inode.h call-stub.h compat.h authenticate.h fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h gf-dirent.h locking.h
+
+EXTRA_DIST = spec.l spec.y
+
+spec.lex.c: spec.l y.tab.h
+ $(LEX) -t $(srcdir)/spec.l > $@
+
+y.tab.c y.tab.h: spec.y
+ $(YACC) -d $(srcdir)/spec.y
+
+CLEANFILES = spec.lex.c y.tab.c y.tab.h
diff --git a/libglusterfs/src/authenticate.c b/libglusterfs/src/authenticate.c
new file mode 100644
index 000000000..69cc8d99c
--- /dev/null
+++ b/libglusterfs/src/authenticate.c
@@ -0,0 +1,240 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdio.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include "authenticate.h"
+
+static void
+init (dict_t *this,
+ char *key,
+ data_t *value,
+ void *data)
+{
+ void *handle = NULL;
+ char *auth_file = NULL;
+ auth_handle_t *auth_handle = NULL;
+ auth_fn_t authenticate = NULL;
+ int *error = NULL;
+
+ /* It gets over written */
+ error = data;
+
+ if (!strncasecmp (key, "ip", strlen ("ip"))) {
+ gf_log ("authenticate", GF_LOG_ERROR,
+ "AUTHENTICATION MODULE \"IP\" HAS BEEN REPLACED "
+ "BY \"ADDR\"");
+ dict_set (this, key, data_from_dynptr (NULL, 0));
+ /* TODO: 1.3.x backword compatibility */
+ // *error = -1;
+ // return;
+ key = "addr";
+ }
+
+ asprintf (&auth_file, "%s/%s.so", LIBDIR, key);
+ handle = dlopen (auth_file, RTLD_LAZY);
+ if (!handle) {
+ gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n",
+ auth_file, dlerror ());
+ dict_set (this, key, data_from_dynptr (NULL, 0));
+ FREE (auth_file);
+ *error = -1;
+ return;
+ }
+ FREE (auth_file);
+
+ authenticate = dlsym (handle, "gf_auth");
+ if (!authenticate) {
+ gf_log ("authenticate", GF_LOG_ERROR,
+ "dlsym(gf_auth) on %s\n", dlerror ());
+ dict_set (this, key, data_from_dynptr (NULL, 0));
+ *error = -1;
+ return;
+ }
+
+ auth_handle = CALLOC (1, sizeof (*auth_handle));
+ if (!auth_handle) {
+ gf_log ("authenticate", GF_LOG_ERROR, "Out of memory");
+ dict_set (this, key, data_from_dynptr (NULL, 0));
+ *error = -1;
+ return;
+ }
+ auth_handle->vol_opt = CALLOC (1, sizeof (volume_opt_list_t));
+ auth_handle->vol_opt->given_opt = dlsym (handle, "options");
+ if (auth_handle->vol_opt->given_opt == NULL) {
+ gf_log ("authenticate", GF_LOG_DEBUG,
+ "volume option validation not specified");
+ }
+
+ auth_handle->authenticate = authenticate;
+ auth_handle->handle = handle;
+
+ dict_set (this, key,
+ data_from_dynptr (auth_handle, sizeof (*auth_handle)));
+}
+
+static void
+fini (dict_t *this,
+ char *key,
+ data_t *value,
+ void *data)
+{
+ auth_handle_t *handle = data_to_ptr (value);
+ if (handle) {
+ dlclose (handle->handle);
+ }
+}
+
+int32_t
+gf_auth_init (xlator_t *xl, dict_t *auth_modules)
+{
+ int ret = 0;
+ auth_handle_t *handle = NULL;
+ data_pair_t *pair = NULL;
+ dict_foreach (auth_modules, init, &ret);
+ if (!ret) {
+ pair = auth_modules->members_list;
+ while (pair) {
+ handle = data_to_ptr (pair->value);
+ if (handle) {
+ list_add_tail (&(handle->vol_opt->list),
+ &(xl->volume_options));
+ if (-1 ==
+ validate_xlator_volume_options (xl,
+ handle->vol_opt->given_opt)) {
+ gf_log ("authenticate", GF_LOG_ERROR,
+ "volume option validation "
+ "failed");
+ ret = -1;
+ }
+ }
+ pair = pair->next;
+ }
+ }
+ if (ret) {
+ gf_log (xl->name, GF_LOG_ERROR, "authentication init failed");
+ dict_foreach (auth_modules, fini, &ret);
+ ret = -1;
+ }
+ return ret;
+}
+
+static dict_t *__input_params;
+static dict_t *__config_params;
+
+void
+map (dict_t *this,
+ char *key,
+ data_t *value,
+ void *data)
+{
+ dict_t *res = data;
+ auth_fn_t authenticate;
+ auth_handle_t *handle = NULL;
+
+ if (value && (handle = data_to_ptr (value)) &&
+ (authenticate = handle->authenticate)) {
+ dict_set (res, key,
+ int_to_data (authenticate (__input_params,
+ __config_params)));
+ } else {
+ dict_set (res, key, int_to_data (AUTH_DONT_CARE));
+ }
+}
+
+void
+reduce (dict_t *this,
+ char *key,
+ data_t *value,
+ void *data)
+{
+ int64_t val = 0;
+ int64_t *res = data;
+ if (!data)
+ return;
+
+ val = data_to_int64 (value);
+ switch (val)
+ {
+ case AUTH_ACCEPT:
+ if (AUTH_DONT_CARE == *res)
+ *res = AUTH_ACCEPT;
+ break;
+
+ case AUTH_REJECT:
+ *res = AUTH_REJECT;
+ break;
+
+ case AUTH_DONT_CARE:
+ break;
+ }
+}
+
+
+auth_result_t
+gf_authenticate (dict_t *input_params,
+ dict_t *config_params,
+ dict_t *auth_modules)
+{
+ dict_t *results = NULL;
+ int64_t result = AUTH_DONT_CARE;
+
+ results = get_new_dict ();
+ __input_params = input_params;
+ __config_params = config_params;
+
+ dict_foreach (auth_modules, map, results);
+
+ dict_foreach (results, reduce, &result);
+ if (AUTH_DONT_CARE == result) {
+ data_t *peerinfo_data = dict_get (input_params, "peer-info");
+ char *name = NULL;
+
+ if (peerinfo_data) {
+ peer_info_t *peerinfo = data_to_ptr (peerinfo_data);
+ name = peerinfo->identifier;
+ }
+
+ gf_log ("auth", GF_LOG_ERROR,
+ "no authentication module is interested in "
+ "accepting remote-client %s", name);
+ result = AUTH_REJECT;
+ }
+
+ dict_destroy (results);
+ return result;
+}
+
+void
+gf_auth_fini (dict_t *auth_modules)
+{
+ int32_t dummy;
+
+ dict_foreach (auth_modules, fini, &dummy);
+}
diff --git a/libglusterfs/src/authenticate.h b/libglusterfs/src/authenticate.h
new file mode 100644
index 000000000..3d9b78527
--- /dev/null
+++ b/libglusterfs/src/authenticate.h
@@ -0,0 +1,61 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _AUTHENTICATE_H
+#define _AUTHENTICATE_H
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdio.h>
+#include <fnmatch.h>
+#include "dict.h"
+#include "compat.h"
+#include "list.h"
+#include "transport.h"
+#include "xlator.h"
+
+typedef enum {
+ AUTH_ACCEPT,
+ AUTH_REJECT,
+ AUTH_DONT_CARE
+} auth_result_t;
+
+typedef auth_result_t (*auth_fn_t) (dict_t *input_params,
+ dict_t *config_params);
+
+typedef struct {
+ void *handle;
+ auth_fn_t authenticate;
+ volume_opt_list_t *vol_opt;
+} auth_handle_t;
+
+auth_result_t gf_authenticate (dict_t *input_params,
+ dict_t *config_params,
+ dict_t *auth_modules);
+int32_t gf_auth_init (xlator_t *xl, dict_t *auth_modules);
+void gf_auth_fini (dict_t *auth_modules);
+
+#endif /* _AUTHENTICATE_H */
diff --git a/libglusterfs/src/byte-order.h b/libglusterfs/src/byte-order.h
new file mode 100644
index 000000000..b0cf90b09
--- /dev/null
+++ b/libglusterfs/src/byte-order.h
@@ -0,0 +1,150 @@
+/*
+ Copyright (c) 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _BYTE_ORDER_H
+#define _BYTE_ORDER_H
+
+#include <inttypes.h>
+
+#define LS1 0x00ffU
+#define MS1 0xff00U
+#define LS2 0x0000ffffU
+#define MS2 0xffff0000U
+#define LS4 0x00000000ffffffffULL
+#define MS4 0xffffffff00000000ULL
+
+
+static uint16_t (*hton16) (uint16_t);
+static uint32_t (*hton32) (uint32_t);
+static uint64_t (*hton64) (uint64_t);
+
+#define ntoh16 hton16
+#define ntoh32 hton32
+#define ntoh64 hton64
+
+#define do_swap2(x) (((x&LS1) << 8)|(((x&MS1) >> 8)))
+#define do_swap4(x) ((do_swap2(x&LS2) << 16)|(do_swap2((x&MS2) >> 16)))
+#define do_swap8(x) ((do_swap4(x&LS4) << 32)|(do_swap4((x&MS4) >> 32)))
+
+
+static inline uint16_t
+__swap16 (uint16_t x)
+{
+ return do_swap2(x);
+}
+
+
+static inline uint32_t
+__swap32 (uint32_t x)
+{
+ return do_swap4(x);
+}
+
+
+static inline uint64_t
+__swap64 (uint64_t x)
+{
+ return do_swap8(x);
+}
+
+
+static inline uint16_t
+__noswap16 (uint16_t x)
+{
+ return do_swap2(x);
+}
+
+
+static inline uint32_t
+__noswap32 (uint32_t x)
+{
+ return do_swap4(x);
+}
+
+
+static inline uint64_t
+__noswap64 (uint64_t x)
+{
+ return do_swap8(x);
+}
+
+
+static inline uint16_t
+__byte_order_init16 (uint16_t i)
+{
+ uint32_t num = 1;
+
+ if (((char *)(&num))[0] == 1) {
+ hton16 = __swap16;
+ hton32 = __swap32;
+ hton64 = __swap64;
+ } else {
+ hton16 = __noswap16;
+ hton32 = __noswap32;
+ hton64 = __noswap64;
+ }
+
+ return hton16 (i);
+}
+
+
+static inline uint32_t
+__byte_order_init32 (uint32_t i)
+{
+ uint32_t num = 1;
+
+ if (((char *)(&num))[0] == 1) {
+ hton16 = __swap16;
+ hton32 = __swap32;
+ hton64 = __swap64;
+ } else {
+ hton16 = __noswap16;
+ hton32 = __noswap32;
+ hton64 = __noswap64;
+ }
+
+ return hton32 (i);
+}
+
+
+static inline uint64_t
+__byte_order_init64 (uint64_t i)
+{
+ uint32_t num = 1;
+
+ if (((char *)(&num))[0] == 1) {
+ hton16 = __swap16;
+ hton32 = __swap32;
+ hton64 = __swap64;
+ } else {
+ hton16 = __noswap16;
+ hton32 = __noswap32;
+ hton64 = __noswap64;
+ }
+
+ return hton64 (i);
+}
+
+
+static uint16_t (*hton16) (uint16_t) = __byte_order_init16;
+static uint32_t (*hton32) (uint32_t) = __byte_order_init32;
+static uint64_t (*hton64) (uint64_t) = __byte_order_init64;
+
+
+#endif /* _BYTE_ORDER_H */
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c
new file mode 100644
index 000000000..cd7357259
--- /dev/null
+++ b/libglusterfs/src/call-stub.c
@@ -0,0 +1,3822 @@
+/*
+ Copyright (c) 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "call-stub.h"
+
+
+static call_stub_t *
+stub_new (call_frame_t *frame,
+ char wind,
+ glusterfs_fop_t fop)
+{
+ call_stub_t *new = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ new = CALLOC (1, sizeof (*new));
+ GF_VALIDATE_OR_GOTO ("call-stub", new, out);
+
+ new->frame = frame;
+ new->wind = wind;
+ new->fop = fop;
+
+ INIT_LIST_HEAD (&new->list);
+out:
+ return new;
+}
+
+
+call_stub_t *
+fop_lookup_stub (call_frame_t *frame,
+ fop_lookup_t fn,
+ loc_t *loc,
+ dict_t *xattr_req)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_LOOKUP);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.lookup.fn = fn;
+
+ if (xattr_req)
+ stub->args.lookup.xattr_req = dict_ref (xattr_req);
+
+ loc_copy (&stub->args.lookup.loc, loc);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_lookup_cbk_stub (call_frame_t *frame,
+ fop_lookup_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf,
+ dict_t *dict)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_LOOKUP);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.lookup_cbk.fn = fn;
+ stub->args.lookup_cbk.op_ret = op_ret;
+ stub->args.lookup_cbk.op_errno = op_errno;
+ if (inode)
+ stub->args.lookup_cbk.inode = inode_ref (inode);
+ if (buf)
+ stub->args.lookup_cbk.buf = *buf;
+ if (dict)
+ stub->args.lookup_cbk.dict = dict_ref (dict);
+out:
+ return stub;
+}
+
+
+
+call_stub_t *
+fop_stat_stub (call_frame_t *frame,
+ fop_stat_t fn,
+ loc_t *loc)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_STAT);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.stat.fn = fn;
+ loc_copy (&stub->args.stat.loc, loc);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_stat_cbk_stub (call_frame_t *frame,
+ fop_stat_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_STAT);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.stat_cbk.fn = fn;
+ stub->args.stat_cbk.op_ret = op_ret;
+ stub->args.stat_cbk.op_errno = op_errno;
+ if (op_ret == 0)
+ stub->args.stat_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fstat_stub (call_frame_t *frame,
+ fop_fstat_t fn,
+ fd_t *fd)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FSTAT);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fstat.fn = fn;
+
+ if (fd)
+ stub->args.fstat.fd = fd_ref (fd);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fstat_cbk_stub (call_frame_t *frame,
+ fop_fstat_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_FSTAT);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fstat_cbk.fn = fn;
+ stub->args.fstat_cbk.op_ret = op_ret;
+ stub->args.fstat_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.fstat_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_chmod_stub (call_frame_t *frame,
+ fop_chmod_t fn,
+ loc_t *loc,
+ mode_t mode)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_CHMOD);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.chmod.fn = fn;
+ loc_copy (&stub->args.chmod.loc, loc);
+ stub->args.chmod.mode = mode;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_chmod_cbk_stub (call_frame_t *frame,
+ fop_chmod_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_CHMOD);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.chmod_cbk.fn = fn;
+ stub->args.chmod_cbk.op_ret = op_ret;
+ stub->args.chmod_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.chmod_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fchmod_stub (call_frame_t *frame,
+ fop_fchmod_t fn,
+ fd_t *fd,
+ mode_t mode)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FCHMOD);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fchmod.fn = fn;
+ if (fd)
+ stub->args.fchmod.fd = fd_ref (fd);
+ stub->args.fchmod.mode = mode;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fchmod_cbk_stub (call_frame_t *frame,
+ fop_fchmod_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_FCHMOD);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fchmod_cbk.fn = fn;
+ stub->args.fchmod_cbk.op_ret = op_ret;
+ stub->args.fchmod_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.fchmod_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_chown_stub (call_frame_t *frame,
+ fop_chown_t fn,
+ loc_t *loc,
+ uid_t uid,
+ gid_t gid)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_CHOWN);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.chown.fn = fn;
+ loc_copy (&stub->args.chown.loc, loc);
+ stub->args.chown.uid = uid;
+ stub->args.chown.gid = gid;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_chown_cbk_stub (call_frame_t *frame,
+ fop_chown_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_CHOWN);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.chown_cbk.fn = fn;
+ stub->args.chown_cbk.op_ret = op_ret;
+ stub->args.chown_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.chown_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fchown_stub (call_frame_t *frame,
+ fop_fchown_t fn,
+ fd_t *fd,
+ uid_t uid,
+ gid_t gid)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FCHOWN);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fchown.fn = fn;
+ if (fd)
+ stub->args.fchown.fd = fd_ref (fd);
+ stub->args.fchown.uid = uid;
+ stub->args.fchown.gid = gid;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fchown_cbk_stub (call_frame_t *frame,
+ fop_fchown_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_FCHOWN);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fchown_cbk.fn = fn;
+ stub->args.fchown_cbk.op_ret = op_ret;
+ stub->args.fchown_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.fchown_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+/* truncate */
+
+call_stub_t *
+fop_truncate_stub (call_frame_t *frame,
+ fop_truncate_t fn,
+ loc_t *loc,
+ off_t off)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_TRUNCATE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.truncate.fn = fn;
+ loc_copy (&stub->args.truncate.loc, loc);
+ stub->args.truncate.off = off;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_truncate_cbk_stub (call_frame_t *frame,
+ fop_truncate_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_TRUNCATE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.truncate_cbk.fn = fn;
+ stub->args.truncate_cbk.op_ret = op_ret;
+ stub->args.truncate_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.truncate_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_ftruncate_stub (call_frame_t *frame,
+ fop_ftruncate_t fn,
+ fd_t *fd,
+ off_t off)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FTRUNCATE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.ftruncate.fn = fn;
+ if (fd)
+ stub->args.ftruncate.fd = fd_ref (fd);
+
+ stub->args.ftruncate.off = off;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_ftruncate_cbk_stub (call_frame_t *frame,
+ fop_ftruncate_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_FTRUNCATE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.ftruncate_cbk.fn = fn;
+ stub->args.ftruncate_cbk.op_ret = op_ret;
+ stub->args.ftruncate_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.ftruncate_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_utimens_stub (call_frame_t *frame,
+ fop_utimens_t fn,
+ loc_t *loc,
+ struct timespec tv[2])
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_UTIMENS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.utimens.fn = fn;
+ loc_copy (&stub->args.utimens.loc, loc);
+ stub->args.utimens.tv[0] = tv[0];
+ stub->args.utimens.tv[1] = tv[1];
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_utimens_cbk_stub (call_frame_t *frame,
+ fop_utimens_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_UTIMENS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.utimens_cbk.fn = fn;
+ stub->args.utimens_cbk.op_ret = op_ret;
+ stub->args.utimens_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.utimens_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_access_stub (call_frame_t *frame,
+ fop_access_t fn,
+ loc_t *loc,
+ int32_t mask)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_ACCESS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.access.fn = fn;
+ loc_copy (&stub->args.access.loc, loc);
+ stub->args.access.mask = mask;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_access_cbk_stub (call_frame_t *frame,
+ fop_access_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_ACCESS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.access_cbk.fn = fn;
+ stub->args.access_cbk.op_ret = op_ret;
+ stub->args.access_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_readlink_stub (call_frame_t *frame,
+ fop_readlink_t fn,
+ loc_t *loc,
+ size_t size)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_READLINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.readlink.fn = fn;
+ loc_copy (&stub->args.readlink.loc, loc);
+ stub->args.readlink.size = size;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_readlink_cbk_stub (call_frame_t *frame,
+ fop_readlink_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ const char *path)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_READLINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.readlink_cbk.fn = fn;
+ stub->args.readlink_cbk.op_ret = op_ret;
+ stub->args.readlink_cbk.op_errno = op_errno;
+ if (path)
+ stub->args.readlink_cbk.buf = strdup (path);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_mknod_stub (call_frame_t *frame,
+ fop_mknod_t fn,
+ loc_t *loc,
+ mode_t mode,
+ dev_t rdev)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_MKNOD);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.mknod.fn = fn;
+ loc_copy (&stub->args.mknod.loc, loc);
+ stub->args.mknod.mode = mode;
+ stub->args.mknod.rdev = rdev;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_mknod_cbk_stub (call_frame_t *frame,
+ fop_mknod_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_MKNOD);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.mknod_cbk.fn = fn;
+ stub->args.mknod_cbk.op_ret = op_ret;
+ stub->args.mknod_cbk.op_errno = op_errno;
+ if (inode)
+ stub->args.mknod_cbk.inode = inode_ref (inode);
+ if (buf)
+ stub->args.mknod_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_mkdir_stub (call_frame_t *frame,
+ fop_mkdir_t fn,
+ loc_t *loc,
+ mode_t mode)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_MKDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.mkdir.fn = fn;
+ loc_copy (&stub->args.mkdir.loc, loc);
+ stub->args.mkdir.mode = mode;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_mkdir_cbk_stub (call_frame_t *frame,
+ fop_mkdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_MKDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.mkdir_cbk.fn = fn;
+ stub->args.mkdir_cbk.op_ret = op_ret;
+ stub->args.mkdir_cbk.op_errno = op_errno;
+ if (inode)
+ stub->args.mkdir_cbk.inode = inode_ref (inode);
+ if (buf)
+ stub->args.mkdir_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_unlink_stub (call_frame_t *frame,
+ fop_unlink_t fn,
+ loc_t *loc)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_UNLINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.unlink.fn = fn;
+ loc_copy (&stub->args.unlink.loc, loc);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_unlink_cbk_stub (call_frame_t *frame,
+ fop_unlink_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_UNLINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.unlink_cbk.fn = fn;
+ stub->args.unlink_cbk.op_ret = op_ret;
+ stub->args.unlink_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+
+
+call_stub_t *
+fop_rmdir_stub (call_frame_t *frame,
+ fop_rmdir_t fn,
+ loc_t *loc)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_RMDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.rmdir.fn = fn;
+ loc_copy (&stub->args.rmdir.loc, loc);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_rmdir_cbk_stub (call_frame_t *frame,
+ fop_rmdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_RMDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.rmdir_cbk.fn = fn;
+ stub->args.rmdir_cbk.op_ret = op_ret;
+ stub->args.rmdir_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_symlink_stub (call_frame_t *frame,
+ fop_symlink_t fn,
+ const char *linkname,
+ loc_t *loc)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", linkname, out);
+
+ stub = stub_new (frame, 1, GF_FOP_SYMLINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.symlink.fn = fn;
+ stub->args.symlink.linkname = strdup (linkname);
+ loc_copy (&stub->args.symlink.loc, loc);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_symlink_cbk_stub (call_frame_t *frame,
+ fop_symlink_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_SYMLINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.symlink_cbk.fn = fn;
+ stub->args.symlink_cbk.op_ret = op_ret;
+ stub->args.symlink_cbk.op_errno = op_errno;
+ if (inode)
+ stub->args.symlink_cbk.inode = inode_ref (inode);
+ if (buf)
+ stub->args.symlink_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_rename_stub (call_frame_t *frame,
+ fop_rename_t fn,
+ loc_t *oldloc,
+ loc_t *newloc)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", oldloc, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", newloc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_RENAME);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.rename.fn = fn;
+ loc_copy (&stub->args.rename.old, oldloc);
+ loc_copy (&stub->args.rename.new, newloc);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_rename_cbk_stub (call_frame_t *frame,
+ fop_rename_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_RENAME);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.rename_cbk.fn = fn;
+ stub->args.rename_cbk.op_ret = op_ret;
+ stub->args.rename_cbk.op_errno = op_errno;
+ if (buf)
+ stub->args.rename_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_link_stub (call_frame_t *frame,
+ fop_link_t fn,
+ loc_t *oldloc,
+ loc_t *newloc)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", oldloc, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", newloc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_LINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.link.fn = fn;
+ loc_copy (&stub->args.link.oldloc, oldloc);
+ loc_copy (&stub->args.link.newloc, newloc);
+
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_link_cbk_stub (call_frame_t *frame,
+ fop_link_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_LINK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.link_cbk.fn = fn;
+ stub->args.link_cbk.op_ret = op_ret;
+ stub->args.link_cbk.op_errno = op_errno;
+ if (inode)
+ stub->args.link_cbk.inode = inode_ref (inode);
+ if (buf)
+ stub->args.link_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_create_stub (call_frame_t *frame,
+ fop_create_t fn,
+ loc_t *loc,
+ int32_t flags,
+ mode_t mode, fd_t *fd)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_CREATE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.create.fn = fn;
+ loc_copy (&stub->args.create.loc, loc);
+ stub->args.create.flags = flags;
+ stub->args.create.mode = mode;
+ if (fd)
+ stub->args.create.fd = fd_ref (fd);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_create_cbk_stub (call_frame_t *frame,
+ fop_create_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd,
+ inode_t *inode,
+ struct stat *buf)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_CREATE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.create_cbk.fn = fn;
+ stub->args.create_cbk.op_ret = op_ret;
+ stub->args.create_cbk.op_errno = op_errno;
+ if (fd)
+ stub->args.create_cbk.fd = fd_ref (fd);
+ if (inode)
+ stub->args.create_cbk.inode = inode_ref (inode);
+ if (buf)
+ stub->args.create_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_open_stub (call_frame_t *frame,
+ fop_open_t fn,
+ loc_t *loc,
+ int32_t flags, fd_t *fd)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_OPEN);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.open.fn = fn;
+ loc_copy (&stub->args.open.loc, loc);
+ stub->args.open.flags = flags;
+ if (fd)
+ stub->args.open.fd = fd_ref (fd);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_open_cbk_stub (call_frame_t *frame,
+ fop_open_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_OPEN);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.open_cbk.fn = fn;
+ stub->args.open_cbk.op_ret = op_ret;
+ stub->args.open_cbk.op_errno = op_errno;
+ if (fd)
+ stub->args.open_cbk.fd = fd_ref (fd);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_readv_stub (call_frame_t *frame,
+ fop_readv_t fn,
+ fd_t *fd,
+ size_t size,
+ off_t off)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_READ);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.readv.fn = fn;
+ if (fd)
+ stub->args.readv.fd = fd_ref (fd);
+ stub->args.readv.size = size;
+ stub->args.readv.off = off;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_readv_cbk_stub (call_frame_t *frame,
+ fop_readv_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct iovec *vector,
+ int32_t count,
+ struct stat *stbuf)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_READ);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.readv_cbk.fn = fn;
+ stub->args.readv_cbk.op_ret = op_ret;
+ stub->args.readv_cbk.op_errno = op_errno;
+ if (op_ret >= 0) {
+ stub->args.readv_cbk.vector = iov_dup (vector, count);
+ stub->args.readv_cbk.count = count;
+ stub->args.readv_cbk.stbuf = *stbuf;
+ stub->args.readv_cbk.rsp_refs =
+ dict_ref (frame->root->rsp_refs);
+ }
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_writev_stub (call_frame_t *frame,
+ fop_writev_t fn,
+ fd_t *fd,
+ struct iovec *vector,
+ int32_t count,
+ off_t off)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", vector, out);
+
+ stub = stub_new (frame, 1, GF_FOP_WRITE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.writev.fn = fn;
+ if (fd)
+ stub->args.writev.fd = fd_ref (fd);
+ stub->args.writev.vector = iov_dup (vector, count);
+ stub->args.writev.count = count;
+ stub->args.writev.off = off;
+
+ if (frame->root->req_refs)
+ stub->args.writev.req_refs = dict_ref (frame->root->req_refs);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_writev_cbk_stub (call_frame_t *frame,
+ fop_writev_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct stat *stbuf)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_WRITE);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.writev_cbk.fn = fn;
+ stub->args.writev_cbk.op_ret = op_ret;
+ stub->args.writev_cbk.op_errno = op_errno;
+ if (op_ret >= 0)
+ stub->args.writev_cbk.stbuf = *stbuf;
+out:
+ return stub;
+}
+
+
+
+call_stub_t *
+fop_flush_stub (call_frame_t *frame,
+ fop_flush_t fn,
+ fd_t *fd)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FLUSH);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.flush.fn = fn;
+ if (fd)
+ stub->args.flush.fd = fd_ref (fd);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_flush_cbk_stub (call_frame_t *frame,
+ fop_flush_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_FLUSH);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.flush_cbk.fn = fn;
+ stub->args.flush_cbk.op_ret = op_ret;
+ stub->args.flush_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+
+
+
+call_stub_t *
+fop_fsync_stub (call_frame_t *frame,
+ fop_fsync_t fn,
+ fd_t *fd,
+ int32_t datasync)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FSYNC);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fsync.fn = fn;
+ if (fd)
+ stub->args.fsync.fd = fd_ref (fd);
+ stub->args.fsync.datasync = datasync;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fsync_cbk_stub (call_frame_t *frame,
+ fop_fsync_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_FSYNC);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fsync_cbk.fn = fn;
+ stub->args.fsync_cbk.op_ret = op_ret;
+ stub->args.fsync_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_opendir_stub (call_frame_t *frame,
+ fop_opendir_t fn,
+ loc_t *loc, fd_t *fd)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_OPENDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.opendir.fn = fn;
+ loc_copy (&stub->args.opendir.loc, loc);
+ if (stub->args.opendir.fd)
+ stub->args.opendir.fd = fd_ref (fd);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_opendir_cbk_stub (call_frame_t *frame,
+ fop_opendir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ fd_t *fd)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_OPENDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.opendir_cbk.fn = fn;
+ stub->args.opendir_cbk.op_ret = op_ret;
+ stub->args.opendir_cbk.op_errno = op_errno;
+
+ if (fd)
+ stub->args.opendir_cbk.fd = fd_ref (fd);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_getdents_stub (call_frame_t *frame,
+ fop_getdents_t fn,
+ fd_t *fd,
+ size_t size,
+ off_t off,
+ int32_t flag)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_GETDENTS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.getdents.fn = fn;
+ stub->args.getdents.size = size;
+ stub->args.getdents.off = off;
+ if (fd)
+ stub->args.getdents.fd = fd_ref (fd);
+ stub->args.getdents.flag = flag;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_getdents_cbk_stub (call_frame_t *frame,
+ fop_getdents_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ dir_entry_t *entries,
+ int32_t count)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_GETDENTS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.getdents_cbk.fn = fn;
+ stub->args.getdents_cbk.op_ret = op_ret;
+ stub->args.getdents_cbk.op_errno = op_errno;
+ if (op_ret >= 0) {
+ stub->args.getdents_cbk.entries.next = entries->next;
+ /* FIXME: are entries not needed in the caller after
+ * creating stub? */
+ entries->next = NULL;
+ }
+
+ stub->args.getdents_cbk.count = count;
+out:
+ return stub;
+}
+
+
+
+call_stub_t *
+fop_fsyncdir_stub (call_frame_t *frame,
+ fop_fsyncdir_t fn,
+ fd_t *fd,
+ int32_t datasync)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FSYNCDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fsyncdir.fn = fn;
+ if (fd)
+ stub->args.fsyncdir.fd = fd_ref (fd);
+ stub->args.fsyncdir.datasync = datasync;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fsyncdir_cbk_stub (call_frame_t *frame,
+ fop_fsyncdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_FSYNCDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.fsyncdir_cbk.fn = fn;
+ stub->args.fsyncdir_cbk.op_ret = op_ret;
+ stub->args.fsyncdir_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_statfs_stub (call_frame_t *frame,
+ fop_statfs_t fn,
+ loc_t *loc)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_STATFS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.statfs.fn = fn;
+ loc_copy (&stub->args.statfs.loc, loc);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_statfs_cbk_stub (call_frame_t *frame,
+ fop_statfs_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct statvfs *buf)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_STATFS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.statfs_cbk.fn = fn;
+ stub->args.statfs_cbk.op_ret = op_ret;
+ stub->args.statfs_cbk.op_errno = op_errno;
+ if (op_ret == 0)
+ stub->args.statfs_cbk.buf = *buf;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_setxattr_stub (call_frame_t *frame,
+ fop_setxattr_t fn,
+ loc_t *loc,
+ dict_t *dict,
+ int32_t flags)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_SETXATTR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.setxattr.fn = fn;
+ loc_copy (&stub->args.setxattr.loc, loc);
+ /* TODO */
+ if (dict)
+ stub->args.setxattr.dict = dict_ref (dict);
+ stub->args.setxattr.flags = flags;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_setxattr_cbk_stub (call_frame_t *frame,
+ fop_setxattr_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_SETXATTR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.setxattr_cbk.fn = fn;
+ stub->args.setxattr_cbk.op_ret = op_ret;
+ stub->args.setxattr_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+call_stub_t *
+fop_getxattr_stub (call_frame_t *frame,
+ fop_getxattr_t fn,
+ loc_t *loc,
+ const char *name)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_GETXATTR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.getxattr.fn = fn;
+ loc_copy (&stub->args.getxattr.loc, loc);
+
+ if (name)
+ stub->args.getxattr.name = strdup (name);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_getxattr_cbk_stub (call_frame_t *frame,
+ fop_getxattr_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ dict_t *dict)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_GETXATTR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.getxattr_cbk.fn = fn;
+ stub->args.getxattr_cbk.op_ret = op_ret;
+ stub->args.getxattr_cbk.op_errno = op_errno;
+ /* TODO */
+ if (dict)
+ stub->args.getxattr_cbk.dict = dict_ref (dict);
+out:
+ return stub;
+}
+
+call_stub_t *
+fop_removexattr_stub (call_frame_t *frame,
+ fop_removexattr_t fn,
+ loc_t *loc,
+ const char *name)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", name, out);
+
+ stub = stub_new (frame, 1, GF_FOP_REMOVEXATTR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.removexattr.fn = fn;
+ loc_copy (&stub->args.removexattr.loc, loc);
+ stub->args.removexattr.name = strdup (name);
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_removexattr_cbk_stub (call_frame_t *frame,
+ fop_removexattr_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_REMOVEXATTR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.removexattr_cbk.fn = fn;
+ stub->args.removexattr_cbk.op_ret = op_ret;
+ stub->args.removexattr_cbk.op_errno = op_errno;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_lk_stub (call_frame_t *frame,
+ fop_lk_t fn,
+ fd_t *fd,
+ int32_t cmd,
+ struct flock *lock)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", lock, out);
+
+ stub = stub_new (frame, 1, GF_FOP_LK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.lk.fn = fn;
+ if (fd)
+ stub->args.lk.fd = fd_ref (fd);
+ stub->args.lk.cmd = cmd;
+ stub->args.lk.lock = *lock;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_lk_cbk_stub (call_frame_t *frame,
+ fop_lk_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ struct flock *lock)
+
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_LK);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.lk_cbk.fn = fn;
+ stub->args.lk_cbk.op_ret = op_ret;
+ stub->args.lk_cbk.op_errno = op_errno;
+ if (op_ret == 0)
+ stub->args.lk_cbk.lock = *lock;
+out:
+ return stub;
+}
+
+call_stub_t *
+fop_inodelk_stub (call_frame_t *frame, fop_inodelk_t fn,
+ loc_t *loc, int32_t cmd, struct flock *lock)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame || !lock)
+ return NULL;
+
+ stub = stub_new (frame, 1, GF_FOP_INODELK);
+ if (!stub)
+ return NULL;
+
+ stub->args.inodelk.fn = fn;
+
+ loc_copy (&stub->args.inodelk.loc, loc);
+ stub->args.inodelk.cmd = cmd;
+ stub->args.inodelk.lock = *lock;
+
+ return stub;
+}
+
+call_stub_t *
+fop_inodelk_cbk_stub (call_frame_t *frame, fop_inodelk_cbk_t fn,
+ int32_t op_ret, int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame)
+ return NULL;
+
+ stub = stub_new (frame, 0, GF_FOP_INODELK);
+ if (!stub)
+ return NULL;
+
+ stub->args.inodelk_cbk.fn = fn;
+ stub->args.inodelk_cbk.op_ret = op_ret;
+ stub->args.inodelk_cbk.op_errno = op_errno;
+
+ return stub;
+}
+
+
+call_stub_t *
+fop_finodelk_stub (call_frame_t *frame, fop_finodelk_t fn,
+ fd_t *fd, int32_t cmd, struct flock *lock)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame || !lock)
+ return NULL;
+
+ stub = stub_new (frame, 1, GF_FOP_FINODELK);
+ if (!stub)
+ return NULL;
+
+ stub->args.finodelk.fn = fn;
+
+ if (fd)
+ stub->args.finodelk.fd = fd_ref (fd);
+ stub->args.finodelk.cmd = cmd;
+ stub->args.finodelk.lock = *lock;
+
+ return stub;
+}
+
+
+call_stub_t *
+fop_finodelk_cbk_stub (call_frame_t *frame, fop_inodelk_cbk_t fn,
+ int32_t op_ret, int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame)
+ return NULL;
+
+ stub = stub_new (frame, 0, GF_FOP_FINODELK);
+ if (!stub)
+ return NULL;
+
+ stub->args.finodelk_cbk.fn = fn;
+ stub->args.finodelk_cbk.op_ret = op_ret;
+ stub->args.finodelk_cbk.op_errno = op_errno;
+
+ return stub;
+}
+
+
+call_stub_t *
+fop_entrylk_stub (call_frame_t *frame, fop_entrylk_t fn,
+ loc_t *loc, const char *name,
+ entrylk_cmd cmd, entrylk_type type)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame)
+ return NULL;
+
+ stub = stub_new (frame, 1, GF_FOP_ENTRYLK);
+ if (!stub)
+ return NULL;
+
+ stub->args.entrylk.fn = fn;
+ loc_copy (&stub->args.entrylk.loc, loc);
+
+ stub->args.entrylk.cmd = cmd;
+ stub->args.entrylk.type = type;
+ if (name)
+ stub->args.entrylk.name = strdup (name);
+
+ return stub;
+}
+
+call_stub_t *
+fop_entrylk_cbk_stub (call_frame_t *frame, fop_entrylk_cbk_t fn,
+ int32_t op_ret, int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame)
+ return NULL;
+
+ stub = stub_new (frame, 0, GF_FOP_ENTRYLK);
+ if (!stub)
+ return NULL;
+
+ stub->args.entrylk_cbk.fn = fn;
+ stub->args.entrylk_cbk.op_ret = op_ret;
+ stub->args.entrylk_cbk.op_errno = op_errno;
+
+ return stub;
+}
+
+
+call_stub_t *
+fop_fentrylk_stub (call_frame_t *frame, fop_fentrylk_t fn,
+ fd_t *fd, const char *name,
+ entrylk_cmd cmd, entrylk_type type)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame)
+ return NULL;
+
+ stub = stub_new (frame, 1, GF_FOP_FENTRYLK);
+ if (!stub)
+ return NULL;
+
+ stub->args.fentrylk.fn = fn;
+
+ if (fd)
+ stub->args.fentrylk.fd = fd_ref (fd);
+ stub->args.fentrylk.cmd = cmd;
+ stub->args.fentrylk.type = type;
+ if (name)
+ stub->args.fentrylk.name = strdup (name);
+
+ return stub;
+}
+
+call_stub_t *
+fop_fentrylk_cbk_stub (call_frame_t *frame, fop_fentrylk_cbk_t fn,
+ int32_t op_ret, int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame)
+ return NULL;
+
+ stub = stub_new (frame, 0, GF_FOP_FENTRYLK);
+ if (!stub)
+ return NULL;
+
+ stub->args.fentrylk_cbk.fn = fn;
+ stub->args.fentrylk_cbk.op_ret = op_ret;
+ stub->args.fentrylk_cbk.op_errno = op_errno;
+
+ return stub;
+}
+
+
+call_stub_t *
+fop_setdents_stub (call_frame_t *frame,
+ fop_setdents_t fn,
+ fd_t *fd,
+ int32_t flags,
+ dir_entry_t *entries,
+ int32_t count)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_SETDENTS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ if (fd)
+ stub->args.setdents.fd = fd_ref (fd);
+ stub->args.setdents.fn = fn;
+ stub->args.setdents.flags = flags;
+ stub->args.setdents.count = count;
+ if (entries) {
+ stub->args.setdents.entries.next = entries->next;
+ entries->next = NULL;
+ }
+out:
+ return stub;
+}
+
+call_stub_t *
+fop_setdents_cbk_stub (call_frame_t *frame,
+ fop_setdents_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_SETDENTS);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.setdents_cbk.fn = fn;
+ stub->args.setdents_cbk.op_ret = op_ret;
+ stub->args.setdents_cbk.op_errno = op_errno;
+out:
+ return stub;
+
+}
+
+call_stub_t *
+fop_readdir_cbk_stub (call_frame_t *frame,
+ fop_readdir_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ gf_dirent_t *entries)
+{
+ call_stub_t *stub = NULL;
+ gf_dirent_t *stub_entry = NULL, *entry = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_READDIR);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.readdir_cbk.fn = fn;
+ stub->args.readdir_cbk.op_ret = op_ret;
+ stub->args.readdir_cbk.op_errno = op_errno;
+ INIT_LIST_HEAD (&stub->args.readdir_cbk.entries.list);
+
+ if (op_ret > 0) {
+ list_for_each_entry (entry, &entries->list, list) {
+ stub_entry = gf_dirent_for_name (entry->d_name);
+ ERR_ABORT (stub_entry);
+ stub_entry->d_off = entry->d_off;
+ stub_entry->d_ino = entry->d_ino;
+
+ list_add_tail (&stub_entry->list,
+ &stub->args.readdir_cbk.entries.list);
+ }
+ }
+out:
+ return stub;
+}
+
+call_stub_t *
+fop_readdir_stub (call_frame_t *frame,
+ fop_readdir_t fn,
+ fd_t *fd,
+ size_t size,
+ off_t off)
+{
+ call_stub_t *stub = NULL;
+
+ stub = stub_new (frame, 1, GF_FOP_READDIR);
+ stub->args.readdir.fn = fn;
+ stub->args.readdir.fd = fd_ref (fd);
+ stub->args.readdir.size = size;
+ stub->args.readdir.off = off;
+
+ return stub;
+}
+call_stub_t *
+fop_checksum_stub (call_frame_t *frame,
+ fop_checksum_t fn,
+ loc_t *loc,
+ int32_t flags)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", loc, out);
+
+ stub = stub_new (frame, 1, GF_FOP_CHECKSUM);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.checksum.fn = fn;
+ loc_copy (&stub->args.checksum.loc, loc);
+ stub->args.checksum.flags = flags;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_checksum_cbk_stub (call_frame_t *frame,
+ fop_checksum_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ uint8_t *file_checksum,
+ uint8_t *dir_checksum)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_CHECKSUM);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.checksum_cbk.fn = fn;
+ stub->args.checksum_cbk.op_ret = op_ret;
+ stub->args.checksum_cbk.op_errno = op_errno;
+ if (op_ret >= 0)
+ {
+ stub->args.checksum_cbk.file_checksum =
+ memdup (file_checksum, ZR_FILENAME_MAX);
+
+ stub->args.checksum_cbk.dir_checksum =
+ memdup (dir_checksum, ZR_FILENAME_MAX);
+ }
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_xattrop_cbk_stub (call_frame_t *frame,
+ fop_xattrop_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_XATTROP);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.xattrop_cbk.fn = fn;
+ stub->args.xattrop_cbk.op_ret = op_ret;
+ stub->args.xattrop_cbk.op_errno = op_errno;
+
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_fxattrop_cbk_stub (call_frame_t *frame,
+ fop_fxattrop_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ dict_t *xattr)
+{
+ call_stub_t *stub = NULL;
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 1, GF_FOP_FXATTROP);
+ stub->args.fxattrop_cbk.fn = fn;
+ stub->args.fxattrop_cbk.op_ret = op_ret;
+ stub->args.fxattrop_cbk.op_errno = op_errno;
+ if (xattr)
+ stub->args.fxattrop_cbk.xattr = dict_ref (xattr);
+
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_xattrop_stub (call_frame_t *frame,
+ fop_xattrop_t fn,
+ loc_t *loc,
+ gf_xattrop_flags_t optype,
+ dict_t *xattr)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame || !xattr)
+ return NULL;
+
+ stub = stub_new (frame, 1, GF_FOP_XATTROP);
+ if (!stub)
+ return NULL;
+
+ stub->args.xattrop.fn = fn;
+
+ loc_copy (&stub->args.xattrop.loc, loc);
+
+ stub->args.xattrop.optype = optype;
+ stub->args.xattrop.xattr = dict_ref (xattr);
+
+ return stub;
+}
+
+call_stub_t *
+fop_fxattrop_stub (call_frame_t *frame,
+ fop_fxattrop_t fn,
+ fd_t *fd,
+ gf_xattrop_flags_t optype,
+ dict_t *xattr)
+{
+ call_stub_t *stub = NULL;
+
+ if (!frame || !xattr)
+ return NULL;
+
+ stub = stub_new (frame, 1, GF_FOP_FXATTROP);
+ if (!stub)
+ return NULL;
+
+ stub->args.fxattrop.fn = fn;
+
+ stub->args.fxattrop.fd = fd_ref (fd);
+
+ stub->args.fxattrop.optype = optype;
+ stub->args.fxattrop.xattr = dict_ref (xattr);
+
+ return stub;
+}
+
+
+static void
+call_resume_wind (call_stub_t *stub)
+{
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ switch (stub->fop) {
+ case GF_FOP_OPEN:
+ {
+ stub->args.open.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.open.loc,
+ stub->args.open.flags, stub->args.open.fd);
+ break;
+ }
+ case GF_FOP_CREATE:
+ {
+ stub->args.create.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.create.loc,
+ stub->args.create.flags,
+ stub->args.create.mode,
+ stub->args.create.fd);
+ break;
+ }
+ case GF_FOP_STAT:
+ {
+ stub->args.stat.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.stat.loc);
+ break;
+ }
+ case GF_FOP_READLINK:
+ {
+ stub->args.readlink.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.readlink.loc,
+ stub->args.readlink.size);
+ break;
+ }
+
+ case GF_FOP_MKNOD:
+ {
+ stub->args.mknod.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.mknod.loc,
+ stub->args.mknod.mode,
+ stub->args.mknod.rdev);
+ }
+ break;
+
+ case GF_FOP_MKDIR:
+ {
+ stub->args.mkdir.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.mkdir.loc,
+ stub->args.mkdir.mode);
+ }
+ break;
+
+ case GF_FOP_UNLINK:
+ {
+ stub->args.unlink.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.unlink.loc);
+ }
+ break;
+
+ case GF_FOP_RMDIR:
+ {
+ stub->args.rmdir.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.rmdir.loc);
+ }
+ break;
+
+ case GF_FOP_SYMLINK:
+ {
+ stub->args.symlink.fn (stub->frame,
+ stub->frame->this,
+ stub->args.symlink.linkname,
+ &stub->args.symlink.loc);
+ }
+ break;
+
+ case GF_FOP_RENAME:
+ {
+ stub->args.rename.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.rename.old,
+ &stub->args.rename.new);
+ }
+ break;
+
+ case GF_FOP_LINK:
+ {
+ stub->args.link.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.link.oldloc,
+ &stub->args.link.newloc);
+ }
+ break;
+
+ case GF_FOP_CHMOD:
+ {
+ stub->args.chmod.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.chmod.loc,
+ stub->args.chmod.mode);
+ }
+ break;
+
+ case GF_FOP_CHOWN:
+ {
+ stub->args.chown.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.chown.loc,
+ stub->args.chown.uid,
+ stub->args.chown.gid);
+ break;
+ }
+ case GF_FOP_TRUNCATE:
+ {
+ stub->args.truncate.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.truncate.loc,
+ stub->args.truncate.off);
+ break;
+ }
+
+ case GF_FOP_READ:
+ {
+ stub->args.readv.fn (stub->frame,
+ stub->frame->this,
+ stub->args.readv.fd,
+ stub->args.readv.size,
+ stub->args.readv.off);
+ break;
+ }
+
+ case GF_FOP_WRITE:
+ {
+ stub->args.writev.fn (stub->frame,
+ stub->frame->this,
+ stub->args.writev.fd,
+ stub->args.writev.vector,
+ stub->args.writev.count,
+ stub->args.writev.off);
+ break;
+ }
+
+ case GF_FOP_STATFS:
+ {
+ stub->args.statfs.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.statfs.loc);
+ break;
+ }
+ case GF_FOP_FLUSH:
+ {
+ stub->args.flush.fn (stub->frame,
+ stub->frame->this,
+ stub->args.flush.fd);
+ break;
+ }
+
+ case GF_FOP_FSYNC:
+ {
+ stub->args.fsync.fn (stub->frame,
+ stub->frame->this,
+ stub->args.fsync.fd,
+ stub->args.fsync.datasync);
+ break;
+ }
+
+ case GF_FOP_SETXATTR:
+ {
+ stub->args.setxattr.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.setxattr.loc,
+ stub->args.setxattr.dict,
+ stub->args.setxattr.flags);
+ break;
+ }
+
+ case GF_FOP_GETXATTR:
+ {
+ stub->args.getxattr.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.getxattr.loc,
+ stub->args.getxattr.name);
+ break;
+ }
+
+ case GF_FOP_REMOVEXATTR:
+ {
+ stub->args.removexattr.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.removexattr.loc,
+ stub->args.removexattr.name);
+ break;
+ }
+
+ case GF_FOP_OPENDIR:
+ {
+ stub->args.opendir.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.opendir.loc,
+ stub->args.opendir.fd);
+ break;
+ }
+
+ case GF_FOP_GETDENTS:
+ {
+ stub->args.getdents.fn (stub->frame,
+ stub->frame->this,
+ stub->args.getdents.fd,
+ stub->args.getdents.size,
+ stub->args.getdents.off,
+ stub->args.getdents.flag);
+ break;
+ }
+
+ case GF_FOP_FSYNCDIR:
+ {
+ stub->args.fsyncdir.fn (stub->frame,
+ stub->frame->this,
+ stub->args.fsyncdir.fd,
+ stub->args.fsyncdir.datasync);
+ break;
+ }
+
+ case GF_FOP_ACCESS:
+ {
+ stub->args.access.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.access.loc,
+ stub->args.access.mask);
+ break;
+ }
+
+ case GF_FOP_FTRUNCATE:
+ {
+ stub->args.ftruncate.fn (stub->frame,
+ stub->frame->this,
+ stub->args.ftruncate.fd,
+ stub->args.ftruncate.off);
+ break;
+ }
+
+ case GF_FOP_FSTAT:
+ {
+ stub->args.fstat.fn (stub->frame,
+ stub->frame->this,
+ stub->args.fstat.fd);
+ break;
+ }
+
+ case GF_FOP_LK:
+ {
+ stub->args.lk.fn (stub->frame,
+ stub->frame->this,
+ stub->args.lk.fd,
+ stub->args.lk.cmd,
+ &stub->args.lk.lock);
+ break;
+ }
+
+ case GF_FOP_INODELK:
+ {
+ stub->args.inodelk.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.inodelk.loc,
+ stub->args.inodelk.cmd,
+ &stub->args.inodelk.lock);
+ break;
+ }
+
+ case GF_FOP_FINODELK:
+ {
+ stub->args.finodelk.fn (stub->frame,
+ stub->frame->this,
+ stub->args.finodelk.fd,
+ stub->args.finodelk.cmd,
+ &stub->args.finodelk.lock);
+ break;
+ }
+
+ case GF_FOP_ENTRYLK:
+ {
+ stub->args.entrylk.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.entrylk.loc,
+ stub->args.entrylk.name,
+ stub->args.entrylk.cmd,
+ stub->args.entrylk.type);
+ break;
+ }
+
+ case GF_FOP_FENTRYLK:
+ {
+ stub->args.fentrylk.fn (stub->frame,
+ stub->frame->this,
+ stub->args.fentrylk.fd,
+ stub->args.fentrylk.name,
+ stub->args.fentrylk.cmd,
+ stub->args.fentrylk.type);
+ break;
+ }
+
+ case GF_FOP_UTIMENS:
+ {
+ stub->args.utimens.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.utimens.loc,
+ stub->args.utimens.tv);
+ break;
+ }
+
+
+ break;
+ case GF_FOP_FCHMOD:
+ {
+ stub->args.fchmod.fn (stub->frame,
+ stub->frame->this,
+ stub->args.fchmod.fd,
+ stub->args.fchmod.mode);
+ break;
+ }
+
+ case GF_FOP_FCHOWN:
+ {
+ stub->args.fchown.fn (stub->frame,
+ stub->frame->this,
+ stub->args.fchown.fd,
+ stub->args.fchown.uid,
+ stub->args.fchown.gid);
+ break;
+ }
+
+ case GF_FOP_LOOKUP:
+ {
+ stub->args.lookup.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.lookup.loc,
+ stub->args.lookup.xattr_req);
+ break;
+ }
+
+ case GF_FOP_SETDENTS:
+ {
+ stub->args.setdents.fn (stub->frame,
+ stub->frame->this,
+ stub->args.setdents.fd,
+ stub->args.setdents.flags,
+ &stub->args.setdents.entries,
+ stub->args.setdents.count);
+ break;
+ }
+
+ case GF_FOP_CHECKSUM:
+ {
+ stub->args.checksum.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.checksum.loc,
+ stub->args.checksum.flags);
+ break;
+ }
+ case GF_FOP_READDIR:
+ {
+ stub->args.readdir.fn (stub->frame,
+ stub->frame->this,
+ stub->args.readdir.fd,
+ stub->args.readdir.size,
+ stub->args.readdir.off);
+ break;
+ }
+ case GF_FOP_XATTROP:
+ {
+ stub->args.xattrop.fn (stub->frame,
+ stub->frame->this,
+ &stub->args.xattrop.loc,
+ stub->args.xattrop.optype,
+ stub->args.xattrop.xattr);
+
+ break;
+ }
+ case GF_FOP_FXATTROP:
+ {
+ stub->args.fxattrop.fn (stub->frame,
+ stub->frame->this,
+ stub->args.fxattrop.fd,
+ stub->args.fxattrop.optype,
+ stub->args.fxattrop.xattr);
+
+ break;
+ }
+ default:
+ {
+ gf_log ("call-stub",
+ GF_LOG_DEBUG,
+ "Invalid value of FOP");
+ }
+ break;
+ }
+out:
+ return;
+}
+
+
+
+static void
+call_resume_unwind (call_stub_t *stub)
+{
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ switch (stub->fop) {
+ case GF_FOP_OPEN:
+ {
+ if (!stub->args.open_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.open_cbk.op_ret,
+ stub->args.open_cbk.op_errno,
+ stub->args.open_cbk.fd);
+ else
+ stub->args.open_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.open_cbk.op_ret,
+ stub->args.open_cbk.op_errno,
+ stub->args.open_cbk.fd);
+ break;
+ }
+
+ case GF_FOP_CREATE:
+ {
+ if (!stub->args.create_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.create_cbk.op_ret,
+ stub->args.create_cbk.op_errno,
+ stub->args.create_cbk.fd,
+ stub->args.create_cbk.inode,
+ &stub->args.create_cbk.buf);
+ else
+ stub->args.create_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.create_cbk.op_ret,
+ stub->args.create_cbk.op_errno,
+ stub->args.create_cbk.fd,
+ stub->args.create_cbk.inode,
+ &stub->args.create_cbk.buf);
+
+ break;
+ }
+
+ case GF_FOP_STAT:
+ {
+ if (!stub->args.stat_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.stat_cbk.op_ret,
+ stub->args.stat_cbk.op_errno,
+ &stub->args.stat_cbk.buf);
+ else
+ stub->args.stat_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.stat_cbk.op_ret,
+ stub->args.stat_cbk.op_errno,
+ &stub->args.stat_cbk.buf);
+
+ break;
+ }
+
+ case GF_FOP_READLINK:
+ {
+ if (!stub->args.readlink_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.readlink_cbk.op_ret,
+ stub->args.readlink_cbk.op_errno,
+ stub->args.readlink_cbk.buf);
+ else
+ stub->args.readlink_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.readlink_cbk.op_ret,
+ stub->args.readlink_cbk.op_errno,
+ stub->args.readlink_cbk.buf);
+
+ break;
+ }
+
+ case GF_FOP_MKNOD:
+ {
+ if (!stub->args.mknod_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.mknod_cbk.op_ret,
+ stub->args.mknod_cbk.op_errno,
+ stub->args.mknod_cbk.inode,
+ &stub->args.mknod_cbk.buf);
+ else
+ stub->args.mknod_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.mknod_cbk.op_ret,
+ stub->args.mknod_cbk.op_errno,
+ stub->args.mknod_cbk.inode,
+ &stub->args.mknod_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_MKDIR:
+ {
+ if (!stub->args.mkdir_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.mkdir_cbk.op_ret,
+ stub->args.mkdir_cbk.op_errno,
+ stub->args.mkdir_cbk.inode,
+ &stub->args.mkdir_cbk.buf);
+ else
+ stub->args.mkdir_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.mkdir_cbk.op_ret,
+ stub->args.mkdir_cbk.op_errno,
+ stub->args.mkdir_cbk.inode,
+ &stub->args.mkdir_cbk.buf);
+
+ if (stub->args.mkdir_cbk.inode)
+ inode_unref (stub->args.mkdir_cbk.inode);
+
+ break;
+ }
+
+ case GF_FOP_UNLINK:
+ {
+ if (!stub->args.unlink_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.unlink_cbk.op_ret,
+ stub->args.unlink_cbk.op_errno);
+ else
+ stub->args.unlink_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.unlink_cbk.op_ret,
+ stub->args.unlink_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_RMDIR:
+ {
+ if (!stub->args.rmdir_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.rmdir_cbk.op_ret,
+ stub->args.rmdir_cbk.op_errno);
+ else
+ stub->args.unlink_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.rmdir_cbk.op_ret,
+ stub->args.rmdir_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_SYMLINK:
+ {
+ if (!stub->args.symlink_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.symlink_cbk.op_ret,
+ stub->args.symlink_cbk.op_errno,
+ stub->args.symlink_cbk.inode,
+ &stub->args.symlink_cbk.buf);
+ else
+ stub->args.symlink_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.symlink_cbk.op_ret,
+ stub->args.symlink_cbk.op_errno,
+ stub->args.symlink_cbk.inode,
+ &stub->args.symlink_cbk.buf);
+ }
+ break;
+
+ case GF_FOP_RENAME:
+ {
+#if 0
+ if (!stub->args.rename_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.rename_cbk.op_ret,
+ stub->args.rename_cbk.op_errno,
+ &stub->args.rename_cbk.buf);
+ else
+ stub->args.rename_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.rename_cbk.op_ret,
+ stub->args.rename_cbk.op_errno,
+ &stub->args.rename_cbk.buf);
+#endif
+ break;
+ }
+
+ case GF_FOP_LINK:
+ {
+ if (!stub->args.link_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.link_cbk.op_ret,
+ stub->args.link_cbk.op_errno,
+ stub->args.link_cbk.inode,
+ &stub->args.link_cbk.buf);
+ else
+ stub->args.link_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.link_cbk.op_ret,
+ stub->args.link_cbk.op_errno,
+ stub->args.link_cbk.inode,
+ &stub->args.link_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_CHMOD:
+ {
+ if (!stub->args.chmod_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.chmod_cbk.op_ret,
+ stub->args.chmod_cbk.op_errno,
+ &stub->args.chmod_cbk.buf);
+ else
+ stub->args.chmod_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.chmod_cbk.op_ret,
+ stub->args.chmod_cbk.op_errno,
+ &stub->args.chmod_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_CHOWN:
+ {
+ if (!stub->args.chown_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.chown_cbk.op_ret,
+ stub->args.chown_cbk.op_errno,
+ &stub->args.chown_cbk.buf);
+ else
+ stub->args.chown_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.chown_cbk.op_ret,
+ stub->args.chown_cbk.op_errno,
+ &stub->args.chown_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_TRUNCATE:
+ {
+ if (!stub->args.truncate_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.truncate_cbk.op_ret,
+ stub->args.truncate_cbk.op_errno,
+ &stub->args.truncate_cbk.buf);
+ else
+ stub->args.truncate_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.truncate_cbk.op_ret,
+ stub->args.truncate_cbk.op_errno,
+ &stub->args.truncate_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_READ:
+ {
+ if (!stub->args.readv_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.readv_cbk.op_ret,
+ stub->args.readv_cbk.op_errno,
+ stub->args.readv_cbk.vector,
+ stub->args.readv_cbk.count,
+ &stub->args.readv_cbk.stbuf);
+ else
+ stub->args.readv_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.readv_cbk.op_ret,
+ stub->args.readv_cbk.op_errno,
+ stub->args.readv_cbk.vector,
+ stub->args.readv_cbk.count,
+ &stub->args.readv_cbk.stbuf);
+ }
+ break;
+
+ case GF_FOP_WRITE:
+ {
+ if (!stub->args.writev_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.writev_cbk.op_ret,
+ stub->args.writev_cbk.op_errno,
+ &stub->args.writev_cbk.stbuf);
+ else
+ stub->args.writev_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.writev_cbk.op_ret,
+ stub->args.writev_cbk.op_errno,
+ &stub->args.writev_cbk.stbuf);
+ break;
+ }
+
+ case GF_FOP_STATFS:
+ {
+ if (!stub->args.statfs_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.statfs_cbk.op_ret,
+ stub->args.statfs_cbk.op_errno,
+ &(stub->args.statfs_cbk.buf));
+ else
+ stub->args.statfs_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.statfs_cbk.op_ret,
+ stub->args.statfs_cbk.op_errno,
+ &(stub->args.statfs_cbk.buf));
+ }
+ break;
+
+ case GF_FOP_FLUSH:
+ {
+ if (!stub->args.flush_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.flush_cbk.op_ret,
+ stub->args.flush_cbk.op_errno);
+ else
+ stub->args.flush_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.flush_cbk.op_ret,
+ stub->args.flush_cbk.op_errno);
+
+ break;
+ }
+
+ case GF_FOP_FSYNC:
+ {
+ if (!stub->args.fsync_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.fsync_cbk.op_ret,
+ stub->args.fsync_cbk.op_errno);
+ else
+ stub->args.fsync_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.fsync_cbk.op_ret,
+ stub->args.fsync_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_SETXATTR:
+ {
+ if (!stub->args.setxattr_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.setxattr_cbk.op_ret,
+ stub->args.setxattr_cbk.op_errno);
+
+ else
+ stub->args.setxattr_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.setxattr_cbk.op_ret,
+ stub->args.setxattr_cbk.op_errno);
+
+ break;
+ }
+
+ case GF_FOP_GETXATTR:
+ {
+ if (!stub->args.getxattr_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.getxattr_cbk.op_ret,
+ stub->args.getxattr_cbk.op_errno,
+ stub->args.getxattr_cbk.dict);
+ else
+ stub->args.getxattr_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.getxattr_cbk.op_ret,
+ stub->args.getxattr_cbk.op_errno,
+ stub->args.getxattr_cbk.dict);
+ break;
+ }
+
+ case GF_FOP_REMOVEXATTR:
+ {
+ if (!stub->args.removexattr_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.removexattr_cbk.op_ret,
+ stub->args.removexattr_cbk.op_errno);
+ else
+ stub->args.removexattr_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.removexattr_cbk.op_ret,
+ stub->args.removexattr_cbk.op_errno);
+
+ break;
+ }
+
+ case GF_FOP_OPENDIR:
+ {
+ if (!stub->args.opendir_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.opendir_cbk.op_ret,
+ stub->args.opendir_cbk.op_errno,
+ stub->args.opendir_cbk.fd);
+ else
+ stub->args.opendir_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.opendir_cbk.op_ret,
+ stub->args.opendir_cbk.op_errno,
+ stub->args.opendir_cbk.fd);
+ break;
+ }
+
+ case GF_FOP_GETDENTS:
+ {
+ if (!stub->args.getdents_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.getdents_cbk.op_ret,
+ stub->args.getdents_cbk.op_errno,
+ &stub->args.getdents_cbk.entries,
+ stub->args.getdents_cbk.count);
+ else
+ stub->args.getdents_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.getdents_cbk.op_ret,
+ stub->args.getdents_cbk.op_errno,
+ &stub->args.getdents_cbk.entries,
+ stub->args.getdents_cbk.count);
+ break;
+ }
+
+ case GF_FOP_FSYNCDIR:
+ {
+ if (!stub->args.fsyncdir_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.fsyncdir_cbk.op_ret,
+ stub->args.fsyncdir_cbk.op_errno);
+ else
+ stub->args.fsyncdir_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.fsyncdir_cbk.op_ret,
+ stub->args.fsyncdir_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_ACCESS:
+ {
+ if (!stub->args.access_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.access_cbk.op_ret,
+ stub->args.access_cbk.op_errno);
+ else
+ stub->args.access_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.access_cbk.op_ret,
+ stub->args.access_cbk.op_errno);
+
+ break;
+ }
+
+ case GF_FOP_FTRUNCATE:
+ {
+ if (!stub->args.ftruncate_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.ftruncate_cbk.op_ret,
+ stub->args.ftruncate_cbk.op_errno,
+ &stub->args.ftruncate_cbk.buf);
+ else
+ stub->args.ftruncate_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.ftruncate_cbk.op_ret,
+ stub->args.ftruncate_cbk.op_errno,
+ &stub->args.ftruncate_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_FSTAT:
+ {
+ if (!stub->args.fstat_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.fstat_cbk.op_ret,
+ stub->args.fstat_cbk.op_errno,
+ &stub->args.fstat_cbk.buf);
+ else
+ stub->args.fstat_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.fstat_cbk.op_ret,
+ stub->args.fstat_cbk.op_errno,
+ &stub->args.fstat_cbk.buf);
+
+ break;
+ }
+
+ case GF_FOP_LK:
+ {
+ if (!stub->args.lk_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.lk_cbk.op_ret,
+ stub->args.lk_cbk.op_errno,
+ &stub->args.lk_cbk.lock);
+ else
+ stub->args.lk_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.lk_cbk.op_ret,
+ stub->args.lk_cbk.op_errno,
+ &stub->args.lk_cbk.lock);
+ break;
+ }
+
+ case GF_FOP_INODELK:
+ {
+ if (!stub->args.inodelk_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.inodelk_cbk.op_ret,
+ stub->args.inodelk_cbk.op_errno);
+
+ else
+ stub->args.inodelk_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.inodelk_cbk.op_ret,
+ stub->args.inodelk_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_FINODELK:
+ {
+ if (!stub->args.finodelk_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.finodelk_cbk.op_ret,
+ stub->args.finodelk_cbk.op_errno);
+
+ else
+ stub->args.finodelk_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.finodelk_cbk.op_ret,
+ stub->args.finodelk_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_ENTRYLK:
+ {
+ if (!stub->args.entrylk_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.entrylk_cbk.op_ret,
+ stub->args.entrylk_cbk.op_errno);
+
+ else
+ stub->args.entrylk_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.entrylk_cbk.op_ret,
+ stub->args.entrylk_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_FENTRYLK:
+ {
+ if (!stub->args.fentrylk_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.fentrylk_cbk.op_ret,
+ stub->args.fentrylk_cbk.op_errno);
+
+ else
+ stub->args.fentrylk_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.fentrylk_cbk.op_ret,
+ stub->args.fentrylk_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_UTIMENS:
+ {
+ if (!stub->args.utimens_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.utimens_cbk.op_ret,
+ stub->args.utimens_cbk.op_errno,
+ &stub->args.utimens_cbk.buf);
+ else
+ stub->args.utimens_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.utimens_cbk.op_ret,
+ stub->args.utimens_cbk.op_errno,
+ &stub->args.utimens_cbk.buf);
+
+ break;
+ }
+
+
+ break;
+ case GF_FOP_FCHMOD:
+ {
+ if (!stub->args.fchmod_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.fchmod_cbk.op_ret,
+ stub->args.fchmod_cbk.op_errno,
+ &stub->args.fchmod_cbk.buf);
+ else
+ stub->args.fchmod_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.fchmod_cbk.op_ret,
+ stub->args.fchmod_cbk.op_errno,
+ &stub->args.fchmod_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_FCHOWN:
+ {
+ if (!stub->args.fchown_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.fchown_cbk.op_ret,
+ stub->args.fchown_cbk.op_errno,
+ &stub->args.fchown_cbk.buf);
+ else
+ stub->args.fchown_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.fchown_cbk.op_ret,
+ stub->args.fchown_cbk.op_errno,
+ &stub->args.fchown_cbk.buf);
+ break;
+ }
+
+ case GF_FOP_LOOKUP:
+ {
+ if (!stub->args.lookup_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.lookup_cbk.op_ret,
+ stub->args.lookup_cbk.op_errno,
+ stub->args.lookup_cbk.inode,
+ &stub->args.lookup_cbk.buf,
+ stub->args.lookup_cbk.dict);
+ else
+ stub->args.lookup_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.lookup_cbk.op_ret,
+ stub->args.lookup_cbk.op_errno,
+ stub->args.lookup_cbk.inode,
+ &stub->args.lookup_cbk.buf,
+ stub->args.lookup_cbk.dict);
+ /* FIXME NULL should not be passed */
+
+ if (stub->args.lookup_cbk.dict)
+ dict_unref (stub->args.lookup_cbk.dict);
+ if (stub->args.lookup_cbk.inode)
+ inode_unref (stub->args.lookup_cbk.inode);
+
+ break;
+ }
+ case GF_FOP_SETDENTS:
+ {
+ if (!stub->args.setdents_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.setdents_cbk.op_ret,
+ stub->args.setdents_cbk.op_errno);
+ else
+ stub->args.setdents_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.setdents_cbk.op_ret,
+ stub->args.setdents_cbk.op_errno);
+ break;
+ }
+
+ case GF_FOP_CHECKSUM:
+ {
+ if (!stub->args.checksum_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.checksum_cbk.op_ret,
+ stub->args.checksum_cbk.op_errno,
+ stub->args.checksum_cbk.file_checksum,
+ stub->args.checksum_cbk.dir_checksum);
+ else
+ stub->args.checksum_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.checksum_cbk.op_ret,
+ stub->args.checksum_cbk.op_errno,
+ stub->args.checksum_cbk.file_checksum,
+ stub->args.checksum_cbk.dir_checksum);
+ if (stub->args.checksum_cbk.op_ret >= 0)
+ {
+ FREE (stub->args.checksum_cbk.file_checksum);
+ FREE (stub->args.checksum_cbk.dir_checksum);
+ }
+
+ break;
+ }
+
+ case GF_FOP_READDIR:
+ {
+ if (!stub->args.readdir_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.readdir_cbk.op_ret,
+ stub->args.readdir_cbk.op_errno,
+ &stub->args.readdir_cbk.entries);
+ else
+ stub->args.readdir_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.readdir_cbk.op_ret,
+ stub->args.readdir_cbk.op_errno,
+ &stub->args.readdir_cbk.entries);
+
+ if (stub->args.readdir_cbk.op_ret > 0)
+ gf_dirent_free (&stub->args.readdir_cbk.entries);
+
+ break;
+ }
+
+ case GF_FOP_XATTROP:
+ {
+ if (!stub->args.xattrop_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.xattrop_cbk.op_ret,
+ stub->args.xattrop_cbk.op_errno);
+ else
+ stub->args.xattrop_cbk.fn (stub->frame,
+ stub->frame->cookie,