1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643
|
=head2 Subdirectory F<lib>
=head3 File F<lib/actions-support.c>
Helper functions for the actions code in F<lib/actions-*.c>.
=head3 File F<lib/appliance-cpu.c>
The appliance choice of CPU model.
=head4 Function C<lib/appliance-cpu.c:guestfs_int_get_cpu_model>
const char *
guestfs_int_get_cpu_model (int kvm)
Return the right CPU model to use as the qemu C<-cpu> parameter or its equivalent in libvirt. This returns:
=over 4
=item C<"host">
The literal string C<"host"> means use C<-cpu host>.
=item C<"max">
The literal string C<"max"> means use C<-cpu max> (the best possible). This requires awkward translation for libvirt.
=item some string
Some string such as C<"cortex-a57"> means use C<-cpu cortex-a57>.
=item C<NULL>
C<NULL> means no C<-cpu> option at all. Note returning C<NULL> does not indicate an error.
=back
This is made unnecessarily hard and fragile because of two stupid choices in QEMU:
=over 4
=item *
The default for C<qemu-system-aarch64 -M virt> is to emulate a C<cortex-a15> (WTF?).
=item *
We don't know for sure if KVM will work, but C<-cpu host> is broken with TCG, so we almost always pass a broken C<-cpu> flag if KVM is semi-broken in any way.
=back
=head3 File F<lib/appliance-kcmdline.c>
The appliance kernel command line.
=head4 Definition C<lib/appliance-kcmdline.c:VALID_TERM>
#define VALID_TERM
Check that the $TERM environment variable is reasonable before we pass it through to the appliance.
=head4 Function C<lib/appliance-kcmdline.c:get_root_uuid_with_file>
static char *
get_root_uuid_with_file (guestfs_h *g, const char *appliance)
Given a disk image containing an extX filesystem, return the UUID.
=head4 Function C<lib/appliance-kcmdline.c:run_qemu_img_dd>
static int
run_qemu_img_dd (guestfs_h *g, const char *in_file, char *out_file)
Read the first 256k bytes of the in_file with L<qemu-img(1)> command and write them into the out_file. That may be useful to get UUID of the QCOW2 disk image with C<get_root_uuid_with_file>.
The function returns zero if successful, otherwise -1.
=head4 Function C<lib/appliance-kcmdline.c:get_root_uuid>
static char *
get_root_uuid (guestfs_h *g, const char *appliance)
Get the UUID from the appliance disk image.
=head4 Function C<lib/appliance-kcmdline.c:guestfs_int_appliance_command_line>
char *
guestfs_int_appliance_command_line (guestfs_h *g,
const char *appliance,
int flags)
Construct the Linux command line passed to the appliance. This is used by the C<direct> and C<libvirt> backends, and is simply located in this file because it's a convenient place for this common code.
The C<appliance> parameter is the filename of the appliance (could be NULL) from which we obtain the root UUID.
The C<flags> parameter can contain the following flags logically or'd together (or 0):
=over 4
=item C<APPLIANCE_COMMAND_LINE_IS_TCG>
If we are launching a qemu TCG guest (ie. KVM is known to be disabled or unavailable). If you don't know, don't pass this flag.
=back
Note that this function returns a newly allocated buffer which must be freed by the caller.
=head3 File F<lib/appliance-uefi.c>
Find the UEFI firmware needed to boot the appliance.
See also F<lib/uefi.c> (autogenerated file) containing the firmware file locations.
=head4 Function C<lib/appliance-uefi.c:guestfs_int_get_uefi>
int
guestfs_int_get_uefi (guestfs_h *g, char *const *firmwares,
const char **firmware, char **code, char **vars,
int *flags)
Return the location of firmware needed to boot the appliance. This is aarch64 only currently, since that's the only architecture where UEFI is mandatory (and that only for RHEL).
C<firmwares> is an optional list of allowed values for the firmware autoselection of libvirt. It is C<NULL> to indicate it is not supported. C<*firmware> is set to one of the strings in C<firmwares> in case one can be used.
C<*code> is initialized with the path to the read-only UEFI code file. C<*vars> is initialized with the path to a copy of the UEFI vars file (which is cleaned up automatically on exit).
In case a UEFI firmware is available, either C<*firmware> is set to a non-C<NULL> value, or C<*code> and C<*vars> are.
C<*code> and C<*vars> should be freed by the caller, and C<*firmware> B<must> not.
If the function returns C<-1> then there was a real error which should cause appliance building to fail (no UEFI firmware is not an error).
See also F<virt-v2v.git/v2v/utils.ml>:find_uefi_firmware
=head3 File F<lib/appliance.c>
This file deals with building the libguestfs appliance.
=head4 Function C<lib/appliance.c:guestfs_int_build_appliance>
int
guestfs_int_build_appliance (guestfs_h *g,
char **kernel_rtn,
char **initrd_rtn,
char **appliance_rtn)
Locate or build the appliance.
This function locates or builds the appliance as necessary, handling the supermin appliance, caching of supermin-built appliances, or using either a fixed or old-style appliance.
The return value is C<0> = good, C<-1> = error. Returned in C<appliance.kernel> will be the name of the kernel to use, C<appliance.initrd> the name of the initrd, C<appliance.image> the name of the ext2 root filesystem. C<appliance.image> can be C<NULL>, meaning that we are using an old-style (non-ext2) appliance. All three strings must be freed by the caller. However the referenced files themselves must I<not> be deleted.
The process is as follows:
=over 4
=item 1.
Look in C<path> which contains a supermin appliance skeleton. If no element has this, skip straight to step 3.
=item 2.
Call C<supermin --build> to build the full appliance (if it needs to be rebuilt). If this is successful, return the full appliance.
=item 3.
Check C<path>, looking for a fixed appliance. If one is found, return it.
=item 4.
Check C<path>, looking for an old-style appliance. If one is found, return it.
=back
The supermin appliance cache directory lives in F<$TMPDIR/.guestfs-$UID/> and consists of up to four files:
$TMPDIR/.guestfs-$UID/lock - the supermin lock file
$TMPDIR/.guestfs-$UID/appliance.d/kernel - the kernel
$TMPDIR/.guestfs-$UID/appliance.d/initrd - the supermin initrd
$TMPDIR/.guestfs-$UID/appliance.d/root - the appliance
Multiple instances of libguestfs with the same UID may be racing to create an appliance. However (since supermin E<ge> 5) supermin provides a I<--lock> flag and atomic update of the F<appliance.d> subdirectory.
=head4 Function C<lib/appliance.c:locate_or_build_appliance>
static int
locate_or_build_appliance (guestfs_h *g,
struct appliance_files *appliance,
const char *path)
Check C<path>, looking for one of appliances: supermin appliance, fixed appliance or old-style appliance. If one of the fixed appliances is found, return it. If the supermin appliance skeleton is found, build and return appliance.
Return values:
1 = appliance is found, returns C<appliance>,
0 = appliance not found,
-1 = error which aborts the launch process.
=head4 Function C<lib/appliance.c:search_appliance>
static int
search_appliance (guestfs_h *g, struct appliance_files *appliance)
Search elements of C<g-E<gt>path>, returning the first C<appliance> element which matches the predicate function C<locate_or_build_appliance>.
Return values:
1 = a path element matched, returns C<appliance>,
0 = no path element matched,
-1 = error which aborts the launch process.
=head4 Function C<lib/appliance.c:build_supermin_appliance>
static int
build_supermin_appliance (guestfs_h *g,
const char *supermin_path,
struct appliance_files *appliance)
Build supermin appliance from C<supermin_path> to F<$TMPDIR/.guestfs-$UID>.
Returns: C<0> = built or C<-1> = error (aborts launch).
=head4 Function C<lib/appliance.c:run_supermin_build>
static int
run_supermin_build (guestfs_h *g,
const char *lockfile,
const char *appliancedir,
const char *supermin_path)
Run C<supermin --build> and tell it to generate the appliance.
=head4 Function C<lib/appliance.c:dir_contains_file>
static int
dir_contains_file (guestfs_h *g, const char *dir, const char *file)
Returns true iff C<file> is contained in C<dir>.
=head4 Function C<lib/appliance.c:dir_contains_files>
static int
dir_contains_files (guestfs_h *g, const char *dir, ...)
Returns true iff every listed file is contained in C<dir>.
=head3 File F<lib/command.c>
A wrapper for running external commands, loosely based on libvirt's C<virCommand> interface.
In outline to use this interface you must:
=over 4
=item 1.
Create a new command handle:
struct command *cmd;
cmd = guestfs_int_new_command (g);
=item 2.
I<Either> add arguments:
guestfs_int_cmd_add_arg (cmd, "qemu-img");
guestfs_int_cmd_add_arg (cmd, "info");
guestfs_int_cmd_add_arg (cmd, filename);
(B<NB:> You don't need to add a C<NULL> argument at the end.)
=item 3.
I<Or> construct a command using a mix of quoted and unquoted strings. (This is useful for L<system(3)>/C<popen("r")>-style shell commands, with the added safety of allowing args to be quoted properly).
guestfs_int_cmd_add_string_unquoted (cmd, "qemu-img info ");
guestfs_int_cmd_add_string_quoted (cmd, filename);
=item 4.
Set various flags, such as whether you want to capture errors in the regular libguestfs error log.
=item 5.
Run the command. This is what does the L<fork(2)> call, optionally loops over the output, and then does a L<waitpid(3)> and returns the exit status of the command.
r = guestfs_int_cmd_run (cmd);
if (r == -1)
// error
// else test r using the WIF* functions
=item 6.
Close the handle:
guestfs_int_cmd_close (cmd);
(or use C<CLEANUP_CMD_CLOSE>).
=back
=head4 Function C<lib/command.c:guestfs_int_new_command>
struct command *
guestfs_int_new_command (guestfs_h *g)
Create a new command handle.
=head4 Function C<lib/command.c:guestfs_int_cmd_add_arg>
void
guestfs_int_cmd_add_arg (struct command *cmd, const char *arg)
Add single arg (for C<execv>-style command execution).
=head4 Function C<lib/command.c:guestfs_int_cmd_add_arg_format>
void
guestfs_int_cmd_add_arg_format (struct command *cmd, const char *fs, ...)
Add single arg (for C<execv>-style command execution) using a L<printf(3)>-style format string.
=head4 Function C<lib/command.c:guestfs_int_cmd_add_string_unquoted>
void
guestfs_int_cmd_add_string_unquoted (struct command *cmd, const char *str)
Add a string (for L<system(3)>-style command execution).
This variant adds the strings without quoting them, which is dangerous if the string contains untrusted content.
=head4 Function C<lib/command.c:guestfs_int_cmd_add_string_quoted>
void
guestfs_int_cmd_add_string_quoted (struct command *cmd, const char *str)
Add a string (for L<system(3)>-style command execution).
The string is enclosed in double quotes, with any special characters within the string which need escaping done. This is used to add a single argument to a L<system(3)>-style command string.
=head4 Function C<lib/command.c:guestfs_int_cmd_set_stdout_callback>
void
guestfs_int_cmd_set_stdout_callback (struct command *cmd,
cmd_stdout_callback stdout_callback,
void *stdout_data, unsigned flags)
Set a callback which will capture stdout.
If flags contains C<CMD_STDOUT_FLAG_LINE_BUFFER> (the default), then the callback is called line by line on the output. If there is a trailing C<\n> then it is automatically removed before the callback is called. The line buffer is C<\0>-terminated.
If flags contains C<CMD_STDOUT_FLAG_UNBUFFERED>, then buffers are passed to the callback as it is received from the command. Note in this case the buffer is I<not> C<\0>-terminated, so you need to may attention to the length field in the callback.
If flags contains C<CMD_STDOUT_FLAG_WHOLE_BUFFER>, then the callback is called exactly once, with the entire buffer. Note in this case the buffer is I<not> C<\0>-terminated, so you need to may attention to the length field in the callback.
=head4 Function C<lib/command.c:guestfs_int_cmd_set_stderr_to_stdout>
void
guestfs_int_cmd_set_stderr_to_stdout (struct command *cmd)
Equivalent to adding C<2E<gt>&1> to the end of the command. This is incompatible with the C<capture_errors> flag, because it doesn't make sense to combine them.
=head4 Function C<lib/command.c:guestfs_int_cmd_clear_capture_errors>
void
guestfs_int_cmd_clear_capture_errors (struct command *cmd)
Clear the C<capture_errors> flag. This means that any errors will go to stderr, instead of being captured in the event log, and that is usually undesirable.
=head4 Function C<lib/command.c:guestfs_int_cmd_clear_close_files>
void
guestfs_int_cmd_clear_close_files (struct command *cmd)
Don't close file descriptors after the fork.
XXX Should allow single fds to be sent to child process.
=head4 Function C<lib/command.c:guestfs_int_cmd_set_child_callback>
void
guestfs_int_cmd_set_child_callback (struct command *cmd,
cmd_child_callback child_callback,
void *data)
Set a function to be executed in the child, right before the execution. Can be used to setup the child, for example changing its current directory.
=head4 Function C<lib/command.c:guestfs_int_cmd_set_child_rlimit>
void
guestfs_int_cmd_set_child_rlimit (struct command *cmd, int resource, long limit)
Set up child rlimits, in case the process we are running could consume lots of space or time.
=head4 Function C<lib/command.c:finish_command>
static void
finish_command (struct command *cmd)
Finish off the command by either C<NULL>-terminating the argv array or adding a terminating C<\0> to the string, or die with an internal error if no command has been added.
=head4 Function C<lib/command.c:loop>
static int
loop (struct command *cmd)
The loop which reads errors and output and directs it either to the log or to the stdout callback as appropriate.
=head4 Function C<lib/command.c:guestfs_int_cmd_run>
int
guestfs_int_cmd_run (struct command *cmd)
Fork, run the command, loop over the output, and waitpid.
Returns the exit status. Test it using C<WIF*> macros.
On error: Calls C<error> and returns C<-1>.
=head4 Function C<lib/command.c:guestfs_int_cmd_pipe_run>
int
guestfs_int_cmd_pipe_run (struct command *cmd, const char *mode)
Fork and run the command, but don't wait. Roughly equivalent to S<C<popen (..., "r"|"w")>>.
Returns the file descriptor of the pipe, connected to stdout (C<"r">) or stdin (C<"w">) of the child process.
After reading/writing to this pipe, call C<guestfs_int_cmd_pipe_wait> to wait for the status of the child.
Errors from the subcommand cannot be captured to the error log using this interface. Instead the caller should call C<guestfs_int_cmd_get_pipe_errors> (after C<guestfs_int_cmd_pipe_wait> returns an error).
=head4 Function C<lib/command.c:guestfs_int_cmd_pipe_wait>
int
guestfs_int_cmd_pipe_wait (struct command *cmd)
Wait for a subprocess created by C<guestfs_int_cmd_pipe_run> to finish. On error (eg. failed syscall) this returns C<-1> and sets the error. If the subcommand fails, then use C<WIF*> macros to check this, and call C<guestfs_int_cmd_get_pipe_errors> to read the error messages printed by the child.
=head4 Function C<lib/command.c:guestfs_int_cmd_get_pipe_errors>
char *
guestfs_int_cmd_get_pipe_errors (struct command *cmd)
Read the error messages printed by the child. The caller must free the returned buffer after use.
=head4 Function C<lib/command.c:guestfs_int_cmd_close>
void
guestfs_int_cmd_close (struct command *cmd)
Close the C<cmd> object and free all resources.
=head4 Function C<lib/command.c:process_line_buffer>
static void
process_line_buffer (struct command *cmd, int closed)
Deal with buffering stdout for the callback.
=head3 File F<lib/conn-socket.c>
This file handles connections to the child process where this is done over regular POSIX sockets.
=head4 Function C<lib/conn-socket.c:handle_log_message>
static int
handle_log_message (guestfs_h *g,
struct connection_socket *conn)
This is called if C<conn-E<gt>console_sock> becomes ready to read while we are doing one of the connection operations above. It reads and deals with the log message.
Returns:
=over 4
=item C<1>
log message(s) were handled successfully
=item C<0>
connection to appliance closed
=item C<-1>
error
=back
=head4 Function C<lib/conn-socket.c:guestfs_int_new_conn_socket_listening>
struct connection *
guestfs_int_new_conn_socket_listening (guestfs_h *g,
int daemon_accept_sock,
int console_sock)
Create a new socket connection, listening.
Note that it's OK for C<console_sock> to be passed as C<-1>, meaning there's no console available for this appliance.
After calling this, C<daemon_accept_sock> is owned by the connection, and will be closed properly either in C<accept_connection> or C<free_connection>.
=head4 Function C<lib/conn-socket.c:guestfs_int_new_conn_socket_connected>
struct connection *
guestfs_int_new_conn_socket_connected (guestfs_h *g,
int daemon_sock,
int console_sock)
Create a new socket connection, connected.
As above, but the caller passes us a connected C<daemon_sock> and promises not to call C<accept_connection>.
=head3 File F<lib/create.c>
APIs for creating empty disks.
Mostly this consists of wrappers around the L<qemu-img(1)> program.
=head4 Definition C<lib/create.c:VALID_FORMAT>
#define VALID_FORMAT
Check for valid backing format. Allow any C<^[[:alnum]]+$> (in C locale), but limit the length to something reasonable.
=head3 File F<lib/drives.c>
Drives added are stored in an array in the handle. Code here manages that array and the individual C<struct drive> data.
=head4 Function C<lib/drives.c:create_overlay>
static int
create_overlay (guestfs_h *g, struct drive *drv)
For readonly drives, create an overlay to protect the original drive content. Note we never need to clean up these overlays since they are created in the temporary directory and deleted when the handle is closed.
=head4 Function C<lib/drives.c:create_drive_file>
static struct drive *
create_drive_file (guestfs_h *g,
const struct drive_create_data *data)
Create and free the C<struct drive>.
=head4 Function C<lib/drives.c:create_drive_dev_null>
static struct drive *
create_drive_dev_null (guestfs_h *g,
struct drive_create_data *data)
Create the special F</dev/null> drive.
Traditionally you have been able to use F</dev/null> as a filename, as many times as you like. Ancient KVM (RHEL 5) cannot handle adding F</dev/null> readonly. qemu 1.2 + virtio-scsi segfaults when you use any zero-sized file including F</dev/null>.
Because of these problems, we replace F</dev/null> with a non-zero sized temporary file. This shouldn't make any difference since users are not supposed to try and access a null drive.
=head4 Function C<lib/drives.c:drive_to_string>
static char *
drive_to_string (guestfs_h *g, const struct drive *drv)
Convert a C<struct drive> to a string for debugging. The caller must free this string.
=head4 Function C<lib/drives.c:add_drive_to_handle_at>
static void
add_drive_to_handle_at (guestfs_h *g, struct drive *d, size_t drv_index)
Add C<struct drive> to the C<g-E<gt>drives> vector at the given index C<drv_index>. If the array isn't large enough it is reallocated. The index must not contain a drive already.
=head4 Function C<lib/drives.c:add_drive_to_handle>
static void
add_drive_to_handle (guestfs_h *g, struct drive *d)
Add struct drive to the end of the C<g-E<gt>drives> vector in the handle.
=head4 Function C<lib/drives.c:guestfs_int_add_dummy_appliance_drive>
void
guestfs_int_add_dummy_appliance_drive (guestfs_h *g)
Called during launch to add a dummy slot to C<g-E<gt>drives>.
=head4 Function C<lib/drives.c:guestfs_int_free_drives>
void
guestfs_int_free_drives (guestfs_h *g)
Free up all the drives in the handle.
=head4 Definition C<lib/drives.c:VALID_FORMAT_IFACE>
#define VALID_FORMAT_IFACE
Check string parameter matches regular expression C<^[-_[:alnum:]]+$> (in C locale).
=head4 Definition C<lib/drives.c:VALID_DISK_LABEL>
#define VALID_DISK_LABEL
Check the disk label is reasonable. It can't contain certain characters, eg. C<'/'>, C<','>. However be stricter here and ensure it's just alphabetic and E<le> 20 characters in length.
=head4 Definition C<lib/drives.c:VALID_HOSTNAME>
#define VALID_HOSTNAME
Check the server hostname is reasonable.
=head4 Function C<lib/drives.c:valid_port>
static int
valid_port (int port)
Check the port number is reasonable.
=head4 Function C<lib/drives.c:valid_blocksize>
static int
valid_blocksize (int blocksize)
Check the block size is reasonable. It can't be other then 512 or 4096.
=head4 Function C<lib/drives.c:guestfs_int_checkpoint_drives>
size_t
guestfs_int_checkpoint_drives (guestfs_h *g)
Checkpoint and roll back drives, so that groups of drives can be added atomically. Only used by L<guestfs(3)/guestfs_add_domain>.
=head4 Function C<lib/drives.c:guestfs_impl_debug_drives>
char **
guestfs_impl_debug_drives (guestfs_h *g)
Internal function to return the list of drives.
=head3 File F<lib/errors.c>
This file handles errors, and also debug, trace and warning messages.
Errors in libguestfs API calls are handled by setting an error message and optional errno in the handle. The caller has the choice of testing API calls to find out if they failed and then querying the last error from the handle, and/or getting a callback.
From the point of view of the library source, generally you should use the C<error> or C<perrorf> macros along error paths, eg:
if (something_bad) {
error (g, "something bad happened");
return -1;
}
Make sure to call the C<error> or C<perrorf> macro exactly once along each error path, since the handle can only store a single error and the previous error will be overwritten.
=head4 Function C<lib/errors.c:guestfs_int_warning>
void
guestfs_int_warning (guestfs_h *g, const char *fs, ...)
Print a warning.
Code should I<not> call this function directly. Use the S<C<warning (g, fs, ...)>> macro.
Warnings are printed unconditionally. We try to make these rare: Generally speaking, a warning should either be an error, or if it's not important for end users then it should be a debug message.
=head4 Function C<lib/errors.c:guestfs_int_debug>
void
guestfs_int_debug (guestfs_h *g, const char *fs, ...)
Print a debug message.
Code should I<not> call this function directly. To add debug messages in the library, use the S<C<debug (g, fs, ...)>> macro. The macro checks if C<g-E<gt>verbose> is false and avoids the function call, meaning the macro is more efficient.
=head4 Function C<lib/errors.c:guestfs_int_trace>
void
guestfs_int_trace (guestfs_h *g, const char *fs, ...)
Print a trace message.
Do not call this function. All calls are generated automatically.
=head4 Function C<lib/errors.c:guestfs_int_error_errno>
void
guestfs_int_error_errno (guestfs_h *g, int errnum, const char *fs, ...)
Set the last error and errno in the handle, and optionally raise the error callback if one is defined.
If you don't need to set errno, use the S<C<error (g, fs, ...)>> macro instead of calling this directly. If you need to set errno then there is no macro wrapper, so calling this function directly is fine.
=head4 Function C<lib/errors.c:guestfs_int_perrorf>
void
guestfs_int_perrorf (guestfs_h *g, const char *fs, ...)
Similar to L<perror(3)>, but it sets the last error in the handle, raises the error callback if one is defined, and supports format strings.
You should probably use the S<C<perrorf (g, fs, ...)>> macro instead of calling this directly.
=head4 Function C<lib/errors.c:guestfs_int_launch_failed_error>
void
guestfs_int_launch_failed_error (guestfs_h *g)
Raise a launch failed error in a standard format.
Since this is the most common error seen by people who have installation problems, buggy qemu, etc, and since no one reads the FAQ, describe in this error message what resources are available to debug launch problems.
=head4 Function C<lib/errors.c:guestfs_int_unexpected_close_error>
void
guestfs_int_unexpected_close_error (guestfs_h *g)
Raise an error if the appliance unexpectedly crashes after launch.
=head4 Function C<lib/errors.c:guestfs_int_launch_timeout>
void
guestfs_int_launch_timeout (guestfs_h *g)
Raise an error if the appliance hangs during launch.
=head4 Function C<lib/errors.c:guestfs_int_external_command_failed>
void
guestfs_int_external_command_failed (guestfs_h *g, int status,
const char *cmd_name, const char *extra)
Raise an error if an external command fails.
C<status> is the status code of the command (eg. returned from L<waitpid(2)> or L<system(3)>). This function turns the status code into an explanatory string.
=head3 File F<lib/events.c>
=head4 Function C<lib/events.c:replace_old_style_event_callback>
static void
replace_old_style_event_callback (guestfs_h *g,
guestfs_event_callback cb,
uint64_t event_bitmask,
void *opaque,
void *opaque2)
Emulate old-style callback API.
There were no event handles, so multiple callbacks per event were not supported. Calling the same C<guestfs_set_*_callback> function would replace the existing event. Calling it with C<cb == NULL> meant that the caller wanted to remove the callback.
=head3 File F<lib/guestfs-internal-all.h>
This header contains definitions which are shared by all parts of libguestfs, ie. the daemon, the library, language bindings and virt tools (ie. I<all> C code).
If you need a definition used by only the library, put it in F<lib/guestfs-internal.h> instead.
If a definition is used by only a single tool, it should not be in any shared header file at all.
=head3 File F<lib/guestfs-internal.h>
This header file is included in the libguestfs library (F<lib/>) only.
See also F<lib/guestfs-internal-all.h>.
=head4 Structure C<lib/guestfs-internal.h:event>
struct event {
uint64_t event_bitmask;
guestfs_event_callback cb;
void *opaque;
/* opaque2 is not exposed through the API, but is used internally to
* emulate the old-style callback API.
*/
void *opaque2;
};
This struct is used to maintain a list of events registered against the handle. See C<g-E<gt>events> in the handle.
=head4 Structure C<lib/guestfs-internal.h:drive>
struct drive {
/* Original source of the drive, eg. file:..., http:... */
struct drive_source src;
/* If the drive is readonly, then an overlay [a local file] is
* created before launch to protect the original drive content, and
* the filename is stored here. Backends should open this file if
* it is non-NULL, else consult the original source above.
*
* Note that the overlay is in a backend-specific format, probably
* different from the source format. eg. qcow2
*/
char *overlay;
/* Various per-drive flags. */
bool readonly;
char *iface;
char *name;
char *disk_label;
char *cachemode;
enum discard discard;
bool copyonread;
int blocksize;
};
There is one C<struct drive> per drive.
=head4 Structure C<lib/guestfs-internal.h:backend_ops>
struct backend_ops {
/* Size (in bytes) of the per-handle data structure needed by this
* backend. The data pointer is allocated and freed by libguestfs
* and passed to the functions in the 'void *data' parameter.
* Inside the data structure is opaque to libguestfs. Any strings
* etc pointed to by it must be freed by the backend during
* shutdown.
*/
size_t data_size;
/* Create a COW overlay on top of a drive. This must be a local
* file, created in the temporary directory. This is called when
* the drive is added to the handle.
*/
char *(*create_cow_overlay) (guestfs_h *g, void *data, struct drive *drv);
/* Launch and shut down. */
int (*launch) (guestfs_h *g, void *data, const char *arg);
int (*shutdown) (guestfs_h *g, void *data, int check_for_errors);
/* Miscellaneous. */
int (*get_pid) (guestfs_h *g, void *data);
int (*max_disks) (guestfs_h *g, void *data);
};
Backend operations.
Each backend (eg. libvirt, direct) defines some functions which get run at various places in the handle lifecycle (eg. at launch, shutdown). The backend defines this struct pointing to those functions.
=head4 Structure C<lib/guestfs-internal.h:connection>
struct connection {
const struct connection_ops *ops;
/* In the real struct, private data used by each connection module
* follows here.
*/
};
Connection module.
A C<connection> represents the appliance console connection plus the daemon connection. It hides the underlying representation (POSIX sockets, C<virStreamPtr>).
=head4 Structure C<lib/guestfs-internal.h:cached_feature>
struct cached_feature {
char *group;
int result;
};
Cache of queried features.
Used to cache the appliance features (see F<lib/available.c>).
=head4 Structure C<lib/guestfs-internal.h:guestfs_h>
struct guestfs_h {
struct guestfs_h *next; /* Linked list of open handles. */
enum state state; /* See the state machine diagram in guestfs(3)*/
/* Lock acquired when entering any public guestfs_* function to
* protect the handle.
*/
pthread_mutex_t lock;
/**** Configuration of the handle. ****/
bool verbose; /* Debugging. */
bool trace; /* Trace calls. */
bool autosync; /* Autosync. */
bool direct_mode; /* Direct mode. */
bool recovery_proc; /* Create a recovery process. */
bool enable_network; /* Enable the network. */
bool selinux; /* selinux enabled? */
bool pgroup; /* Create process group for children? */
bool close_on_exit; /* Is this handle on the atexit list? */
int smp; /* If > 1, -smp flag passed to hv. */
int memsize; /* Size of RAM (megabytes). */
char *path; /* Path to the appliance. */
char *hv; /* Hypervisor (HV) binary. */
char *append; /* Append to kernel command line. */
struct hv_param *hv_params; /* Extra hv parameters. */
char *program; /* Program name. */
char *identifier; /* Handle identifier. */
/* Array of drives added by add-drive* APIs.
*
* Before launch this list can be empty or contain some drives.
*
* During launch, a dummy slot may be added which represents the
* slot taken up by the appliance drive.
*
* During shutdown, this list is deleted, so that each launch gets a
* fresh set of drives (however callers: don't do this, create a new
* handle each time).
*
* Always use ITER_DRIVES macro to iterate over this list!
*/
struct drive **drives;
size_t nr_drives;
#define ITER_DRIVES(g,i,drv) \
for (i = 0; i < (g)->nr_drives; ++i) \
if (((drv) = (g)->drives[i]) != NULL)
/* Backend. NB: Use guestfs_int_set_backend to change the backend. */
char *backend; /* The full string, always non-NULL. */
char *backend_arg; /* Pointer to the argument part. */
const struct backend_ops *backend_ops;
void *backend_data; /* Per-handle data. */
char **backend_settings; /* Backend settings (can be NULL). */
/**** Runtime information. ****/
/* Temporary and cache directories. */
/* The actual temporary directory - this is not created with the
* handle, you have to call guestfs_int_lazy_make_tmpdir.
*/
char *tmpdir;
char *sockdir;
/* Environment variables that affect tmpdir/cachedir/sockdir locations. */
char *env_tmpdir; /* $TMPDIR (NULL if not set) */
char *env_runtimedir; /* $XDG_RUNTIME_DIR (NULL if not set)*/
char *int_tmpdir; /* $LIBGUESTFS_TMPDIR or guestfs_set_tmpdir or NULL */
char *int_cachedir; /* $LIBGUESTFS_CACHEDIR or guestfs_set_cachedir or NULL */
/* Error handler, plus stack of old error handlers. */
pthread_key_t error_data;
/* Linked list of error_data structures allocated for this handle,
* plus a mutex to protect the linked list.
*/
pthread_mutex_t error_data_list_lock;
struct error_data *error_data_list;
/* Out of memory error handler. */
guestfs_abort_cb abort_cb;
/* Events. */
struct event *events;
size_t nr_events;
/* Private data area. */
struct hash_table *pda;
struct pda_entry *pda_next;
/* User cancelled transfer. Not signal-atomic, but it doesn't
* matter for this case because we only care if it is != 0.
*/
int user_cancel;
struct timeval launch_t; /* The time that we called guestfs_launch. */
/* Used by bindtests. */
FILE *test_fp;
/* Used to generate unique numbers, eg for temp files. To use this,
* '++g->unique'. Note these are only unique per-handle, not
* globally unique.
*/
int unique;
/*** Protocol. ***/
struct connection *conn; /* Connection to appliance. */
int msg_next_serial;
#if HAVE_FUSE
/**** Used by the mount-local APIs. ****/
char *localmountpoint;
struct fuse *fuse; /* FUSE handle. */
int ml_dir_cache_timeout; /* Directory cache timeout. */
Hash_table *lsc_ht, *xac_ht, *rlc_ht; /* Directory cache. */
int ml_read_only; /* If mounted read-only. */
int ml_debug_calls; /* Extra debug info on each FUSE call. */
#endif
#ifdef HAVE_LIBVIRT_BACKEND
/* Used by lib/libvirt-auth.c. */
#define NR_CREDENTIAL_TYPES 9
unsigned int nr_supported_credentials;
int supported_credentials[NR_CREDENTIAL_TYPES];
const char *saved_libvirt_uri; /* Doesn't need to be freed. */
bool wrapper_warning_done;
unsigned int nr_requested_credentials;
virConnectCredentialPtr requested_credentials;
#endif
/* Cached features. */
struct cached_feature *features;
size_t nr_features;
/* Used by lib/info.c. -1 = not tested or error; else 0 or 1. */
int qemu_img_supports_U_option;
};
The libguestfs handle.
=head4 Structure C<lib/guestfs-internal.h:version>
struct version {
int v_major;
int v_minor;
int v_micro;
};
Used for storing major.minor.micro version numbers. See F<lib/version.c> for more information.
=head3 File F<lib/guid.c>
=head4 Function C<lib/guid.c:guestfs_int_validate_guid>
int
guestfs_int_validate_guid (const char *str)
Check whether a string supposed to contain a GUID actually contains it. It can recognize strings either as C<{21EC2020-3AEA-1069-A2DD-08002B30309D}> or C<21EC2020-3AEA-1069-A2DD-08002B30309D>.
=head3 File F<lib/handle.c>
This file deals with the C<guestfs_h> handle, creating it, closing it, and initializing/setting/getting fields.
=head4 Function C<lib/handle.c:init_libguestfs>
static void
init_libguestfs (void)
No initialization is required by libguestfs, but libvirt and libxml2 require initialization if they might be called from multiple threads. Hence this constructor function which is called when libguestfs is first loaded.
=head4 Function C<lib/handle.c:shutdown_backend>
static int
shutdown_backend (guestfs_h *g, int check_for_errors)
This function is the common path for shutting down the backend qemu process.
C<guestfs_shutdown> calls C<shutdown_backend> with C<check_for_errors=1>. C<guestfs_close> calls C<shutdown_backend> with C<check_for_errors=0>.
C<check_for_errors> is a hint to the backend about whether we care about errors or not. In the libvirt case it can be used to optimize the shutdown for speed when we don't care.
=head4 Function C<lib/handle.c:close_handles>
static void
close_handles (void)
Close all open handles (called from L<atexit(3)>).
=head4 Function C<lib/handle.c:guestfs_int_get_backend_setting_bool>
int
guestfs_int_get_backend_setting_bool (guestfs_h *g, const char *name)
This is a convenience function, but we might consider exporting it as an API in future.
=head3 File F<lib/info.c>
=head4 Function C<lib/info.c:qemu_img_supports_U_option>
static int
qemu_img_supports_U_option (guestfs_h *g)
Test if the qemu-img info command supports the C<-U> option to disable locking. The result is memoized in the handle.
Note this option was added in qemu 2.11. We can remove this test when we can assume everyone is using qemu >= 2.11.
=head3 File F<lib/inspect-icon.c>
=head4 Function C<lib/inspect-icon.c:guestfs_int_download_to_tmp>
char *
guestfs_int_download_to_tmp (guestfs_h *g, const char *filename,
const char *extension,
uint64_t max_size)
Download a guest file to a local temporary file.
The name of the temporary (downloaded) file is returned. The caller must free the pointer, but does I<not> need to delete the temporary file. It will be deleted when the handle is closed.
The name of the temporary file is randomly generated, but an extension can be specified using C<extension> (or pass C<NULL> for none).
Refuse to download the guest file if it is larger than C<max_size>. On this and other errors, C<NULL> is returned.
=head3 File F<lib/launch-direct.c>
Implementation of the C<direct> backend.
For more details see L<guestfs(3)/BACKENDS>.
=head4 Function C<lib/launch-direct.c:add_drive_standard_params>
static int
add_drive_standard_params (guestfs_h *g, struct backend_direct_data *data,
struct qemuopts *qopts,
size_t i, struct drive *drv)
Add the standard elements of the C<-drive> parameter.
=head4 Function C<lib/launch-direct.c:add_device_blocksize_params>
static int
add_device_blocksize_params (guestfs_h *g, struct qemuopts *qopts,
struct drive *drv)
Add the physical_block_size and logical_block_size elements of the C<-device> parameter.
=head3 File F<lib/launch-libvirt.c>
=head4 Function C<lib/launch-libvirt.c:get_source_format_or_autodetect>
static char *
get_source_format_or_autodetect (guestfs_h *g, struct drive *drv)
Return C<drv-E<gt>src.format>, but if it is C<NULL>, autodetect the format.
libvirt has disabled the feature of detecting the disk format, unless the administrator sets C<allow_disk_format_probing=1> in F</etc/libvirt/qemu.conf>. There is no way to detect if this option is set, so we have to do format detection here using C<qemu-img> and pass that to libvirt.
This can still be a security issue, so in most cases it is recommended the users pass the format to libguestfs which will faithfully pass that straight through to libvirt without doing autodetection.
Caller must free the returned string. On error this function sets the error in the handle and returns C<NULL>.
=head4 Function C<lib/launch-libvirt.c:make_qcow2_overlay>
static char *
make_qcow2_overlay (guestfs_h *g, const char *backing_drive,
const char *format)
Create a qcow2 format overlay, with the given C<backing_drive> (file). The C<format> parameter is the backing file format. The C<format> parameter can be NULL, in this case the backing format will be determined automatically. This is used to create the appliance overlay, and also for read-only drives.
=head3 File F<lib/launch.c>
This file implements L<guestfs(3)/guestfs_launch>.
Most of the work is done by the backends (see L<guestfs(3)/BACKEND>), which are implemented in F<lib/launch-direct.c>, F<lib/launch-libvirt.c> etc, so this file mostly passes calls through to the current backend.
=head4 Function C<lib/launch.c:guestfs_int_launch_send_progress>
void
guestfs_int_launch_send_progress (guestfs_h *g, int perdozen)
This function sends a launch progress message.
Launching the appliance generates approximate progress messages. Currently these are defined as follows:
0 / 12: launch clock starts
3 / 12: appliance created
6 / 12: detected that guest kernel started
9 / 12: detected that /init script is running
12 / 12: launch completed successfully
注:
=over 4
=item 1.
This is not a documented ABI and the behaviour may be changed or removed in future.
=item 2.
Messages are only sent if more than 5 seconds has elapsed since the launch clock started.
=item 3.
There is a hack in F<lib/proto.c> to make this work.
=back
=head4 Function C<lib/launch.c:guestfs_int_timeval_diff>
int64_t
guestfs_int_timeval_diff (const struct timeval *x, const struct timeval *y)
Compute C<y - x> and return the result in milliseconds.
Approximately the same as this code: L<http://www.mpp.mpg.de/~huber/util/timevaldiff.c>
=head4 Function C<lib/launch.c:guestfs_int_unblock_sigterm>
void
guestfs_int_unblock_sigterm (void)
Unblock the C<SIGTERM> signal. Call this after L<fork(2)> so that the parent process can send C<SIGTERM> to the child process in case C<SIGTERM> is blocked. See L<https://bugzilla.redhat.com/1460338>.
=head4 Function C<lib/launch.c:guestfs_impl_max_disks>
int
guestfs_impl_max_disks (guestfs_h *g)
Returns the maximum number of disks allowed to be added to the backend (backend dependent).
=head4 Function C<lib/launch.c:guestfs_impl_wait_ready>
int
guestfs_impl_wait_ready (guestfs_h *g)
Implementation of L<guestfs(3)/guestfs_wait_ready>. You had to call this function after launch in versions E<le> 1.0.70, but it is now an (almost) no-op.
=head4 Function C<lib/launch.c:guestfs_int_create_socketname>
int
guestfs_int_create_socketname (guestfs_h *g, const char *filename,
char (*sockpath)[UNIX_PATH_MAX])
Create the path for a socket with the selected filename in the tmpdir.
=head4 Function C<lib/launch.c:guestfs_int_register_backend>
void
guestfs_int_register_backend (const char *name, const struct backend_ops *ops)
When the library is loaded, each backend calls this function to register itself in a global list.
=head4 Function C<lib/launch.c:guestfs_int_set_backend>
int
guestfs_int_set_backend (guestfs_h *g, const char *method)
Implementation of L<guestfs(3)/guestfs_set_backend>.
=over 4
=item *
Callers must ensure this is only called in the config state.
=item *
This shouldn't call C<error> since it may be called early in handle initialization. It can return an error code however.
=back
=head3 File F<lib/private-data.c>
Implement a private data area where libguestfs C API users can attach arbitrary pieces of data to a C<guestfs_h> handle.
For more information see L<guestfs(3)/PRIVATE DATA AREA>.
Language bindings do not generally expose this, largely because in non-C languages it is easy to associate data with handles in other ways (using hash tables or maps).
=head4 Structure C<lib/private-data.c:pda_entry>
struct pda_entry {
char *key; /* key */
void *data; /* opaque user data pointer */
};
The private data area is internally stored as a gnulib hash table containing C<pda_entry> structures.
Note the private data area is allocated lazily, since the vast majority of callers will never use it. This means C<g-E<gt>pda> is likely to be C<NULL>.
=head3 File F<lib/proto.c>
This is the code used to send and receive RPC messages and (for certain types of message) to perform file transfers. This code is driven from the generated actions (F<lib/actions-*.c>). There are five different cases to consider:
=over 4
=item 1.
A non-daemon function (eg. L<guestfs(3)/guestfs_set_verbose>). There is no RPC involved at all, it's all handled inside the library.
=item 2.
A simple RPC (eg. L<guestfs(3)/guestfs_mount>). We write the request, then read the reply. The sequence of calls is:
guestfs_int_send
guestfs_int_recv
=item 3.
An RPC with C<FileIn> parameters (eg. L<guestfs(3)/guestfs_upload>). We write the request, then write the file(s), then read the reply. The sequence of calls is:
guestfs_int_send
guestfs_int_send_file (possibly multiple times)
guestfs_int_recv
=item 4.
An RPC with C<FileOut> parameters (eg. L<guestfs(3)/guestfs_download>). We write the request, then read the reply, then read the file(s). The sequence of calls is:
guestfs_int_send
guestfs_int_recv
guestfs_int_recv_file (possibly multiple times)
=item 5.
Both C<FileIn> and C<FileOut> parameters. There are no calls like this in the current API, but they would be implemented as a combination of cases 3 and 4.
=back
All read/write/etc operations are performed using the current connection module (C<g-E<gt>conn>). During operations the connection module transparently handles log messages that appear on the console.
=head4 Function C<lib/proto.c:child_cleanup>
static void
child_cleanup (guestfs_h *g)
This is called if we detect EOF, ie. qemu died.
=head4 Function C<lib/proto.c:guestfs_int_progress_message_callback>
void
guestfs_int_progress_message_callback (guestfs_h *g,
const guestfs_progress *message)
Convenient wrapper to generate a progress message callback.
=head4 Function C<lib/proto.c:guestfs_int_log_message_callback>
void
guestfs_int_log_message_callback (guestfs_h *g, const char *buf, size_t len)
Connection modules call us back here when they get a log message.
=head4 Function C<lib/proto.c:check_daemon_socket>
static ssize_t
check_daemon_socket (guestfs_h *g)
Before writing to the daemon socket, check the read side of the daemon socket for any of these conditions:
=over 4
=item error
return -1
=item daemon cancellation message
return -2
=item progress message
handle it here
=item end of input or appliance exited unexpectedly
return 0
=item anything else
return 1
=back
=head4 Function C<lib/proto.c:guestfs_int_send_file>
int
guestfs_int_send_file (guestfs_h *g, const char *filename)
Send a file.
Returns C<0> on success, C<-1> for error, C<-2> if the daemon cancelled (we must read the error message).
=head4 Function C<lib/proto.c:send_file_data>
static int
send_file_data (guestfs_h *g, const char *buf, size_t len)
Send a chunk of file data.
=head4 Function C<lib/proto.c:send_file_cancellation>
static int
send_file_cancellation (guestfs_h *g)
Send a cancellation message.
=head4 Function C<lib/proto.c:send_file_complete>
static int
send_file_complete (guestfs_h *g)
Send a file complete chunk.
=head4 Function C<lib/proto.c:recv_from_daemon>
static int
recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
This function reads a single message, file chunk, launch flag or cancellation flag from the daemon. If something was read, it returns C<0>, otherwise C<-1>.
Both C<size_rtn> and C<buf_rtn> must be passed by the caller as non-NULL.
C<*size_rtn> returns the size of the returned message or it may be C<GUESTFS_LAUNCH_FLAG> or C<GUESTFS_CANCEL_FLAG>.
C<*buf_rtn> is returned containing the message (if any) or will be set to C<NULL>. C<*buf_rtn> must be freed by the caller.
This checks for EOF (appliance died) and passes that up through the child_cleanup function above.
Log message, progress messages are handled transparently here.
=head4 Function C<lib/proto.c:guestfs_int_recv>
int
guestfs_int_recv (guestfs_h *g, const char *fn,
guestfs_message_header *hdr,
guestfs_message_error *err,
xdrproc_t xdrp, char *ret)
Receive a reply.
=head4 Function C<lib/proto.c:guestfs_int_recv_discard>
int
guestfs_int_recv_discard (guestfs_h *g, const char *fn)
Same as C<guestfs_int_recv>, but it discards the reply message.
Notes (XXX):
=over 4
=item *
This returns an int, but all current callers ignore it.
=item *
The error string may end up being set twice on error paths.
=back
=head4 Function C<lib/proto.c:guestfs_int_recv_file>
int
guestfs_int_recv_file (guestfs_h *g, const char *filename)
Returns C<-1> = error, C<0> = EOF, C<E<gt>0> = more data
=head4 Function C<lib/proto.c:receive_file_data>
static ssize_t
receive_file_data (guestfs_h *g, void **buf_r)
Receive a chunk of file data.
Returns C<-1> = error, C<0> = EOF, C<E<gt>0> = more data
=head3 File F<lib/qemu.c>
Functions to handle qemu versions and features.
=head4 Function C<lib/qemu.c:guestfs_int_test_qemu>
struct qemu_data *
guestfs_int_test_qemu (guestfs_h *g)
Test that the qemu binary (or wrapper) runs, and do C<qemu -help> and other commands so we can find out the version of qemu and what options this qemu supports.
This caches the results in the cachedir so that as long as the qemu binary does not change, calling this is effectively free.
=head4 Function C<lib/qemu.c:cache_filename>
static char *
cache_filename (guestfs_h *g, const char *cachedir,
const struct stat *statbuf, const char *suffix)
Generate the filenames, for the stat file and the other cache files.
By including the size and mtime in the filename we also ensure that the same user can use multiple versions of qemu without conflicts.
=head4 Function C<lib/qemu.c:parse_qemu_version>
static void
parse_qemu_version (guestfs_h *g, const char *qemu_help,
struct version *qemu_version)
Parse the first line of C<qemu_help> into the major and minor version of qemu, but don't fail if parsing is not possible.
=head4 Function C<lib/qemu.c:parse_json>
static void
parse_json (guestfs_h *g, const char *json, json_t **treep)
Parse the json output from QMP. But don't fail if parsing is not possible.
=head4 Function C<lib/qemu.c:parse_has_kvm>
static void
parse_has_kvm (guestfs_h *g, const char *json, bool *ret)
Parse the json output from QMP query-kvm to find out if KVM is enabled on this machine. Don't fail if parsing is not possible, assume KVM is available.
The JSON output looks like: {"return": {"enabled": true, "present": true}}
=head4 Function C<lib/qemu.c:generic_read_cache>
static int
generic_read_cache (guestfs_h *g, const char *filename, char **strp)
Generic functions for reading and writing the cache files, used where we are just reading and writing plain text strings.
=head4 Function C<lib/qemu.c:generic_qmp_test>
static int
generic_qmp_test (guestfs_h *g, struct qemu_data *data,
const char *qmp_command,
char **outp)
Run a generic QMP test on the QEMU binary.
=head4 Function C<lib/qemu.c:guestfs_int_qemu_version>
struct version
guestfs_int_qemu_version (guestfs_h *g, struct qemu_data *data)
Return the parsed version of qemu.
=head4 Function C<lib/qemu.c:guestfs_int_qemu_supports>
int
guestfs_int_qemu_supports (guestfs_h *g, const struct qemu_data *data,
const char *option)
Test if option is supported by qemu command line (just by grepping the help text).
=head4 Function C<lib/qemu.c:guestfs_int_qemu_supports_device>
int
guestfs_int_qemu_supports_device (guestfs_h *g,
const struct qemu_data *data,
const char *device_name)
Test if device is supported by qemu (currently just greps the C<qemu -device ?> output).
=head4 Function C<lib/qemu.c:guestfs_int_qemu_mandatory_locking>
int
guestfs_int_qemu_mandatory_locking (guestfs_h *g,
const struct qemu_data *data)
Test if the qemu binary uses mandatory file locking, added in QEMU >= 2.10 (but sometimes disabled).
=head4 Function C<lib/qemu.c:guestfs_int_qemu_escape_param>
char *
guestfs_int_qemu_escape_param (guestfs_h *g, const char *param)
Escape a qemu parameter.
Every C<,> becomes C<,,>. The caller must free the returned string.
XXX This functionality is now only used when constructing a qemu-img command in F<lib/create.c>. We should extend the qemuopts library to cover this use case.
=head4 Function C<lib/qemu.c:guestfs_int_drive_source_qemu_param>
char *
guestfs_int_drive_source_qemu_param (guestfs_h *g,
const struct drive_source *src)
Useful function to format a drive + protocol for qemu.
Note that the qemu parameter is the bit after C<"file=">. It is not escaped here, but would usually be escaped if passed to qemu as part of a full -drive parameter (but not for L<qemu-img(1)>).
=head4 Function C<lib/qemu.c:guestfs_int_discard_possible>
bool
guestfs_int_discard_possible (guestfs_h *g, struct drive *drv,
const struct version *qemu_version)
Test if discard is both supported by qemu AND possible with the underlying file or device. This returns C<1> if discard is possible. It returns C<0> if not possible and sets the error to the reason why.
This function is called when the user set C<discard == "enable">.
=head4 Function C<lib/qemu.c:guestfs_int_free_qemu_data>
void
guestfs_int_free_qemu_data (struct qemu_data *data)
Free the C<struct qemu_data>.
=head3 File F<lib/rescue.c>
Support for virt-rescue(1).
=head3 File F<lib/stringsbuf.c>
An expandable NULL-terminated vector of strings (like C<argv>).
Use the C<DECLARE_STRINGSBUF> macro to declare the stringsbuf.
Note: Don't confuse this with stringsbuf in the daemon which is a different type with different methods.
=head4 Function C<lib/stringsbuf.c:guestfs_int_add_string_nodup>
void
guestfs_int_add_string_nodup (guestfs_h *g, struct stringsbuf *sb, char *str)
Add a string to the end of the list.
This doesn't call L<strdup(3)> on the string, so the string itself is stored inside the vector.
=head4 Function C<lib/stringsbuf.c:guestfs_int_add_string>
void
guestfs_int_add_string (guestfs_h *g, struct stringsbuf *sb, const char *str)
Add a string to the end of the list.
This makes a copy of the string.
=head4 Function C<lib/stringsbuf.c:guestfs_int_add_sprintf>
void
guestfs_int_add_sprintf (guestfs_h *g, struct stringsbuf *sb,
const char *fs, ...)
Add a string to the end of the list.
Uses an sprintf-like format string when creating the string.
=head4 Function C<lib/stringsbuf.c:guestfs_int_end_stringsbuf>
void
guestfs_int_end_stringsbuf (guestfs_h *g, struct stringsbuf *sb)
Finish the string buffer.
This adds the terminating NULL to the end of the vector.
=head4 Function C<lib/stringsbuf.c:guestfs_int_free_stringsbuf>
void
guestfs_int_free_stringsbuf (struct stringsbuf *sb)
Free the string buffer and the strings.
=head3 File F<lib/tmpdirs.c>
Handle temporary directories.
=head4 Function C<lib/tmpdirs.c:set_abs_path>
static int
set_abs_path (guestfs_h *g, const char *ctxstr,
const char *tmpdir, char **tmpdir_ret)
We need to make all tmpdir paths absolute because lots of places in the code assume this. Do it at the time we set the path or read the environment variable (L<https://bugzilla.redhat.com/882417>).
The C<ctxstr> parameter is a string displayed in error messages giving the context of the operation (eg. name of environment variable being used, or API function being called).
=head4 Function C<lib/tmpdirs.c:guestfs_impl_get_tmpdir>
char *
guestfs_impl_get_tmpdir (guestfs_h *g)
Implements the C<guestfs_get_tmpdir> API.
Note this actually calculates the tmpdir, so it never returns C<NULL>.
=head4 Function C<lib/tmpdirs.c:guestfs_impl_get_cachedir>
char *
guestfs_impl_get_cachedir (guestfs_h *g)
Implements the C<guestfs_get_cachedir> API.
Note this actually calculates the cachedir, so it never returns C<NULL>.
=head4 Function C<lib/tmpdirs.c:guestfs_impl_get_sockdir>
char *
guestfs_impl_get_sockdir (guestfs_h *g)
Implements the C<guestfs_get_sockdir> API.
Note this actually calculates the sockdir, so it never returns C<NULL>.
=head4 Function C<lib/tmpdirs.c:guestfs_int_lazy_make_tmpdir>
int
guestfs_int_lazy_make_tmpdir (guestfs_h *g)
The C<g-E<gt>tmpdir> (per-handle temporary directory) is not created when the handle is created. Instead we create it lazily before the first time it is used, or during launch.
=head4 Function C<lib/tmpdirs.c:guestfs_int_make_temp_path>
char *
guestfs_int_make_temp_path (guestfs_h *g,
const char *name, const char *extension)
Generate unique temporary paths for temporary files.
Returns a unique path or NULL on error.
=head4 Function C<lib/tmpdirs.c:guestfs_int_lazy_make_supermin_appliance_dir>
char *
guestfs_int_lazy_make_supermin_appliance_dir (guestfs_h *g)
Create the supermin appliance directory under cachedir, if it does not exist.
Sanity-check that the permissions on the cachedir are safe, in case it has been pre-created maliciously or tampered with.
Returns the directory name which the caller must free.
=head4 Function C<lib/tmpdirs.c:guestfs_int_recursive_remove_dir>
void
guestfs_int_recursive_remove_dir (guestfs_h *g, const char *dir)
Recursively remove a temporary directory. If removal fails, just return (it's a temporary directory so it'll eventually be cleaned up by a temp cleaner).
This is implemented using C<rm -rf> because that's simpler and safer.
=head3 File F<lib/umask.c>
Return current umask in a thread-safe way.
glibc documents, but does not actually implement, a "getumask(3)" call.
We use C<Umask> from F</proc/self/status> for Linux E<ge> 4.7. For older Linux and other Unix, this file implements an expensive but thread-safe way to get the current process's umask.
Thanks to: Josh Stone, Jiri Jaburek, Eric Blake.
=head4 Function C<lib/umask.c:guestfs_int_getumask>
int
guestfs_int_getumask (guestfs_h *g)
Returns the current process's umask. On failure, returns C<-1> and sets the error in the guestfs handle.
=head4 Function C<lib/umask.c:get_umask_from_proc>
static int
get_umask_from_proc (guestfs_h *g)
For Linux E<ge> 4.7 get the umask from F</proc/self/status>.
On failure this returns C<-1>. However if we could not open the F</proc> file or find the C<Umask> entry in it, return C<-2> which causes the fallback path to run.
=head4 Function C<lib/umask.c:get_umask_from_fork>
static int
get_umask_from_fork (guestfs_h *g)
Fallback method of getting the umask using fork.
=head3 File F<lib/unit-tests.c>
Unit tests of internal functions.
These tests may use a libguestfs handle, but must not launch the handle. Also, avoid long-running tests.
=head4 Function C<lib/unit-tests.c:test_split>
static void
test_split (void)
Test C<guestfs_int_split_string>.
=head4 Function C<lib/unit-tests.c:test_concat>
static void
test_concat (void)
Test C<guestfs_int_concat_strings>.
=head4 Function C<lib/unit-tests.c:test_join>
static void
test_join (void)
Test C<guestfs_int_join_strings>.
=head4 Function C<lib/unit-tests.c:test_validate_guid>
static void
test_validate_guid (void)
Test C<guestfs_int_validate_guid>.
=head4 Function C<lib/unit-tests.c:test_drive_name>
static void
test_drive_name (void)
Test C<guestfs_int_drive_name>.
=head4 Function C<lib/unit-tests.c:test_drive_index>
static void
test_drive_index (void)
Test C<guestfs_int_drive_index>.
=head4 Function C<lib/unit-tests.c:test_getumask>
static void
test_getumask (void)
Test C<guestfs_int_getumask>.
=head4 Function C<lib/unit-tests.c:test_command>
static void
test_command (void)
Test C<guestfs_int_new_command> etc.
XXX These tests could be made much more thorough. So far we simply test that it's not obviously broken.
=head4 Function C<lib/unit-tests.c:test_qemu_escape_param>
static void
test_qemu_escape_param (void)
Test C<guestfs_int_qemu_escape_param>
XXX I wanted to make this test run qemu, passing some parameters which need to be escaped, but I cannot think of a way to do that without launching a VM.
=head4 Function C<lib/unit-tests.c:test_timeval_diff>
static void
test_timeval_diff (void)
Test C<guestfs_int_timeval_diff>.
=head3 File F<lib/version.c>
This file provides simple version number management.
=head4 Function C<lib/version.c:guestfs_int_version_from_x_y>
int
guestfs_int_version_from_x_y (guestfs_h *g, struct version *v, const char *str)
Parses a version from a string, looking for a C<X.Y> pattern.
Returns C<-1> on failure (like failed integer parsing), C<0> on missing match, and C<1> on match and successful parsing. C<v> is changed only on successful match.
=head4 Function C<lib/version.c:guestfs_int_version_from_x_y_re>
int
guestfs_int_version_from_x_y_re (guestfs_h *g, struct version *v,
const char *str, const pcre2_code *re)
Parses a version from a string, using the specified C<re> as regular expression which I<must> provide (at least) two matches.
Returns C<-1> on failure (like failed integer parsing), C<0> on missing match, and C<1> on match and successful parsing. C<v> is changed only on successful match.
=head4 Function C<lib/version.c:guestfs_int_version_from_x_y_or_x>
int
guestfs_int_version_from_x_y_or_x (guestfs_h *g, struct version *v,
const char *str)
Parses a version from a string, either looking for a C<X.Y> pattern or considering it as whole integer.
Returns C<-1> on failure (like failed integer parsing), C<0> on missing match, and C<1> on match and successful parsing. C<v> is changed only on successful match.
=head4 Function C<lib/version.c:guestfs_int_parse_unsigned_int>
int
guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str)
Parse small, unsigned ints, as used in version numbers.
This will fail with an error if trailing characters are found after the integer.
Returns E<ge> C<0> on success, or C<-1> on failure.
=head3 File F<lib/wait.c>
=head4 Function C<lib/wait.c:guestfs_int_waitpid>
int
guestfs_int_waitpid (guestfs_h *g, pid_t pid, int *status, const char *errmsg)
A safe version of L<waitpid(3)> which retries if C<EINTR> is returned.
I<Note:> this only needs to be used in the library, or in programs that install a non-restartable C<SIGCHLD> handler (which is not the case for any current libguestfs virt tools).
If the main program installs a SIGCHLD handler and sets it to be non-restartable, then what can happen is the library is waiting in a wait syscall, the child exits, C<SIGCHLD> is sent to the process, and the wait syscall returns C<EINTR>. Since the library cannot control the signal handler, we have to instead restart the wait syscall, which is the purpose of this wrapper.
=head4 Function C<lib/wait.c:guestfs_int_waitpid_noerror>
void
guestfs_int_waitpid_noerror (pid_t pid)
Like C<guestfs_int_waitpid>, but ignore errors.
=head4 Function C<lib/wait.c:guestfs_int_wait4>
int
guestfs_int_wait4 (guestfs_h *g, pid_t pid, int *status,
struct rusage *rusage, const char *errmsg)
A safe version of L<wait4(2)> which retries if C<EINTR> is returned.
=head3 File F<lib/whole-file.c>
=head4 Function C<lib/whole-file.c:guestfs_int_read_whole_file>
int
guestfs_int_read_whole_file (guestfs_h *g, const char *filename,
char **data_r, size_t *size_r)
Read the whole file C<filename> into a memory buffer.
The memory buffer is initialized and returned in C<data_r>. The size of the file in bytes is returned in C<size_r>. The return buffer must be freed by the caller.
On error this sets the error in the handle and returns C<-1>.
For the convenience of callers, the returned buffer is NUL-terminated (the NUL is not included in the size).
The file must be a B<regular>, B<local>, B<trusted> file. In particular, do not use this function to read files that might be under control of an untrusted user since that will lead to a denial-of-service attack.
=head2 Subdirectory F<common/edit>
=head3 File F<common/edit/file-edit.c>
This file implements common file editing in a range of utilities including L<guestfish(1)>, L<virt-edit(1)>, L<virt-customize(1)> and L<virt-builder(1)>.
It contains the code for both interactive-(editor-)based editing and non-interactive editing using Perl snippets.
=head4 Function C<common/edit/file-edit.c:edit_file_editor>
int
edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
const char *backup_extension, int verbose)
Edit C<filename> using the specified C<editor> application.
If C<backup_extension> is not null, then a copy of C<filename> is saved with C<backup_extension> appended to its file name.
If C<editor> is null, then the C<$EDITOR> environment variable will be queried for the editor application, leaving C<vi> as fallback if not set.
Returns C<-1> for failure, C<0> on success, C<1> if the editor did not change the file (e.g. the user closed the editor without saving).
=head4 Function C<common/edit/file-edit.c:edit_file_perl>
int
edit_file_perl (guestfs_h *g, const char *filename, const char *perl_expr,
const char *backup_extension, int verbose)
Edit C<filename> running the specified C<perl_expr> using Perl.
If C<backup_extension> is not null, then a copy of C<filename> is saved with C<backup_extension> appended to its file name.
Returns C<-1> for failure, C<0> on success.
=head2 Subdirectory F<common/options>
=head3 File F<common/options/config.c>
This file parses the guestfish configuration file, usually F<~/.libguestfs-tools.rc> or F</etc/libguestfs-tools.conf>.
Note that C<parse_config> is called very early, before command line parsing, before the C<verbose> flag has been set, even before the global handle C<g> is opened.
=head3 File F<common/options/decrypt.c>
This file implements the decryption of disk images, usually done before mounting their partitions.
=head4 Function C<common/options/decrypt.c:make_mapname>
static char *
make_mapname (const char *device)
Make a LUKS map name from the partition or logical volume name, eg. C<"/dev/vda2" =E<gt> "cryptvda2">, or C<"/dev/vg-ssd/lv-root7" =E<gt> "cryptvgssdlvroot7">. Note that, in logical volume device names, c_isalnum() eliminates the "/" separator from between the VG and the LV, so this mapping is not unique; but for our purposes, it will do.
=head4 Function C<common/options/decrypt.c:inspect_do_decrypt>
void
inspect_do_decrypt (guestfs_h *g, struct key_store *ks)
Simple implementation of decryption: look for any encrypted partitions and decrypt them, then rescan for VGs.
=head3 File F<common/options/display-options.c>
This file contains common code used to implement I<--short-options> and I<--long-options> in C virt tools. (The equivalent for OCaml virt tools is implemented by F<common/mltools/getopt.ml>).
These "hidden" options are used to implement bash tab completion.
=head4 Function C<common/options/display-options.c:display_short_options>
void
display_short_options (const char *format)
Implements the internal C<tool I<--short-options>> flag, which just lists out the short options available. Used by bash completion.
=head4 Function C<common/options/display-options.c:display_long_options>
void
display_long_options (const struct option *long_options)
Implements the internal C<tool I<--long-options>> flag, which just lists out the long options available. Used by bash completion.
=head3 File F<common/options/domain.c>
Implements the guestfish (and other tools) I<-d> option.
=head4 Function C<common/options/domain.c:add_libvirt_drives>
int
add_libvirt_drives (guestfs_h *g, const char *guest)
This function is called when a user invokes S<C<guestfish -d guest>>.
Returns the number of drives added (S<C<E<gt> 0>>), or C<-1> for failure.
=head3 File F<common/options/inspect.c>
This file implements inspecting the guest and mounting the filesystems found in the right places. It is used by the L<guestfish(1)> I<-i> option and some utilities such as L<virt-cat(1)>.
=head4 Function C<common/options/inspect.c:inspect_mount_handle>
void
inspect_mount_handle (guestfs_h *g, struct key_store *ks)
This function implements the I<-i> option.
=head4 Function C<common/options/inspect.c:print_inspect_prompt>
void
print_inspect_prompt (void)
This function is called only if C<inspect_mount_root> was called, and only after we've printed the prompt in interactive mode.
=head3 File F<common/options/keys.c>
=head4 Function C<common/options/keys.c:read_key>
char *
read_key (const char *param)
Read a passphrase ('Key') from F</dev/tty> with echo off.
The caller (F<fish/cmds.c>) will call free on the string afterwards. Based on the code in cryptsetup file F<lib/utils.c>.
=head3 File F<common/options/options.c>
This file contains common options parsing code used by guestfish and many other tools which share a common options syntax.
For example, guestfish, virt-cat, virt-ls etc all support the I<-a> option, and that is handled in all of those tools using a macro C<OPTION_a> defined in F<fish/options.h>.
There are a lot of common global variables used, C<drvs> accumulates the list of drives, C<verbose> for the I<-v> flag, and many more.
=head4 Function C<common/options/options.c:option_a>
void
option_a (const char *arg, const char *format, int blocksize,
struct drv **drvsp)
Handle the guestfish I<-a> option on the command line.
=head4 Function C<common/options/options.c:option_d>
void
option_d (const char *arg, struct drv **drvsp)
Handle the I<-d> option when passed on the command line.
=head4 Function C<common/options/options.c:display_mountpoints_on_failure>
static void
display_mountpoints_on_failure (const char *mp_device,
const char *user_supplied_options)
If the I<-m> option fails on any command, display a useful error message listing the mountpoints.
=head3 File F<common/options/uri.c>
This file implements URI parsing for the I<-a> option, in many utilities including L<guestfish(1)>, L<virt-cat(1)>, L<virt-builder(1)>, L<virt-customize(1)>, etc.
=head2 Subdirectory F<common/parallel>
=head3 File F<common/parallel/domains.c>
This file is used by C<virt-df> and some of the other tools when they are implicitly asked to operate over all libvirt domains (VMs), for example when C<virt-df> is called without specifying any particular disk image.
It hides the complexity of querying the list of domains from libvirt.
=head4 Function C<common/parallel/domains.c:free_domains>
void
free_domains (void)
Frees up everything allocated by C<get_all_libvirt_domains>.
=head4 Function C<common/parallel/domains.c:get_all_libvirt_domains>
void
get_all_libvirt_domains (const char *libvirt_uri)
Read all libguest guests into the global variables C<domains> and C<nr_domains>. The guests are ordered by name. This exits on any error.
=head3 File F<common/parallel/estimate-max-threads.c>
=head4 Function C<common/parallel/estimate-max-threads.c:estimate_max_threads>
size_t
estimate_max_threads (void)
This function uses the output of C<free -m> to estimate how many libguestfs appliances could be safely started in parallel. Note that it always returns E<ge> 1.
=head4 Function C<common/parallel/estimate-max-threads.c:read_line_from>
static char *
read_line_from (const char *cmd)
Run external command and read the first line of output.
=head3 File F<common/parallel/parallel.c>
This file is used by C<virt-df> and some of the other tools when they need to run multiple parallel libguestfs instances to operate on a large number of libvirt domains efficiently.
It implements a multithreaded work queue. In addition it reorders the output so the output still appears in the same order as the input (ie. still ordered alphabetically).
=head4 Function C<common/parallel/parallel.c:start_threads>
int
start_threads (size_t option_P, guestfs_h *options_handle, work_fn work)
Run the threads and work through the global list of libvirt domains.
C<option_P> is whatever the user passed in the I<-P> option, or C<0> if the user didn't use the I<-P> option (in which case the number of threads is chosen heuristically).
C<options_handle> (which may be C<NULL>) is the global guestfs handle created by the options mini-library.
The work function (C<work>) should do the work (inspecting the domain, etc.) on domain index C<i>. However it I<must not> print out any result directly. Instead it prints anything it needs to the supplied C<FILE *>. The work function should return C<0> on success or C<-1> on error.
The C<start_threads> function returns C<0> if all work items completed successfully, or C<-1> if there was an error.
=head2 Subdirectory F<common/progress>
=head3 File F<common/progress/progress.c>
This file implements the progress bar in L<guestfish(1)>, L<virt-resize(1)> and L<virt-sparsify(1)>.
=head4 Function C<common/progress/progress.c:progress_bar_init>
struct progress_bar *
progress_bar_init (unsigned flags)
Initialize a progress bar struct.
It is intended that you can reuse the same struct for multiple commands (but only in a single thread). Call C<progress_bar_reset> before each new command.
=head4 Function C<common/progress/progress.c:progress_bar_free>
void
progress_bar_free (struct progress_bar *bar)
Free a progress bar struct.
=head4 Function C<common/progress/progress.c:progress_bar_reset>
void
progress_bar_reset (struct progress_bar *bar)
This function should be called just before you issue any command.
=head4 Function C<common/progress/progress.c:estimate_remaining_time>
static double
estimate_remaining_time (struct progress_bar *bar, double ratio)
Return remaining time estimate (in seconds) for current call.
This returns the running mean estimate of remaining time, but if the latest estimate of total time is greater than two s.d.'s from the running mean then we don't print anything because we're not confident that the estimate is meaningful. (Returned value is E<lt>0.0 when nothing should be printed).
=head4 Function C<common/progress/progress.c:progress_bar_set>
void
progress_bar_set (struct progress_bar *bar,
uint64_t position, uint64_t total)
Set the position of the progress bar.
This should be called from a C<GUESTFS_EVENT_PROGRESS> event callback.
=head2 Subdirectory F<common/qemuopts>
=head3 File F<common/qemuopts/qemuopts-tests.c>
Unit tests of internal functions.
These tests may use a libguestfs handle, but must not launch the handle. Also, avoid long-running tests.
=head3 File F<common/qemuopts/qemuopts.c>
Mini-library for writing qemu command lines and qemu config files.
There are some shortcomings with the model used for qemu options which aren't clear until you try to convert options into a configuration file. However if we attempted to model the options in more detail then this library would be both very difficult to use and incompatible with older versions of qemu. Hopefully the current model is a decent compromise.
For reference here are the problems:
=over 4
=item *
There's inconsistency in qemu between options and config file, eg. C<-smp 4> becomes:
[smp-opts]
cpus = "4"
=item *
Similar to the previous point, you can write either C<-smp 4> or C<-smp cpus=4> (although this won't work in very old qemu). When generating a config file you need to know the implicit key name.
=item *
In C<-opt key=value,...> the C<key> is really a tree/array specifier. The way this works is complicated but hinted at here: L<http://git.qemu.org/?p=qemu.git;a=blob;f=util/keyval.c;h=93d5db6b590427e412dfb172f1c406d6dd8958c1;hb=HEAD>
=item *
Some options are syntactic sugar. eg. C<-kernel foo> is sugar for C<-machine kernel=foo>.
=back
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_create>
struct qemuopts *
qemuopts_create (void)
Create an empty list of qemu options.
The caller must eventually free the list by calling C<qemuopts_free>.
Returns C<NULL> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_free>
void
qemuopts_free (struct qemuopts *qopts)
Free the list of qemu options.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_add_flag>
int
qemuopts_add_flag (struct qemuopts *qopts, const char *flag)
Add a command line flag which has no argument. eg:
qemuopts_add_flag (qopts, "-no-user-config");
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_add_arg>
int
qemuopts_add_arg (struct qemuopts *qopts, const char *flag, const char *value)
Add a command line flag which has a single argument. eg:
qemuopts_add_arg (qopts, "-m", "1024");
Don't use this if the argument is a comma-separated list, since quoting will not be done properly. See C<qemuopts_add_arg_list>.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_add_arg_format>
int
qemuopts_add_arg_format (struct qemuopts *qopts, const char *flag,
const char *fs, ...)
Add a command line flag which has a single formatted argument. eg:
qemuopts_add_arg_format (qopts, "-m", "%d", 1024);
Don't use this if the argument is a comma-separated list, since quoting will not be done properly. See C<qemuopts_add_arg_list>.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_add_arg_noquote>
int
qemuopts_add_arg_noquote (struct qemuopts *qopts, const char *flag,
const char *value)
This is like C<qemuopts_add_arg> except that no quoting is done on the value.
For C<qemuopts_to_script> and C<qemuopts_to_channel>, this means that neither shell quoting nor qemu comma quoting is done on the value.
For C<qemuopts_to_argv> this means that qemu comma quoting is not done.
C<qemuopts_to_config*> will fail.
You should use this with great care.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_start_arg_list>
int
qemuopts_start_arg_list (struct qemuopts *qopts, const char *flag)
Start an argument that takes a comma-separated list of fields.
Typical usage is like this (with error handling omitted):
qemuopts_start_arg_list (qopts, "-drive");
qemuopts_append_arg_list (qopts, "file=foo");
qemuopts_append_arg_list_format (qopts, "if=%s", "ide");
qemuopts_end_arg_list (qopts);
which would construct C<-drive file=foo,if=ide>
See also C<qemuopts_add_arg_list> for a way to do simple cases in one call.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_add_arg_list>
int
qemuopts_add_arg_list (struct qemuopts *qopts, const char *flag,
const char *elem0, ...)
Add a command line flag which has a list of arguments. eg:
qemuopts_add_arg_list (qopts, "-drive", "file=foo", "if=ide", NULL);
This is turned into a comma-separated list, like: C<-drive file=foo,if=ide>. Note that this handles qemu quoting properly, so individual elements may contain commas and this will do the right thing.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_set_binary>
int
qemuopts_set_binary (struct qemuopts *qopts, const char *binary)
Set the qemu binary name.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_set_binary_by_arch>
int
qemuopts_set_binary_by_arch (struct qemuopts *qopts, const char *arch)
Set the qemu binary name to C<qemu-system-[arch]>.
As a special case if C<arch> is C<NULL>, the binary is set to the KVM binary for the current host architecture:
qemuopts_set_binary_by_arch (qopts, NULL);
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_to_script>
int
qemuopts_to_script (struct qemuopts *qopts, const char *filename)
Write the qemu options to a script.
C<qemuopts_set_binary*> must be called first.
The script file will start with C<#!/bin/sh> and will be chmod to mode C<0755>.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:shell_quote>
static void
shell_quote (const char *str, FILE *fp)
Print C<str> to C<fp>, shell-quoting it if necessary.
=head4 Function C<common/qemuopts/qemuopts.c:shell_and_comma_quote>
static void
shell_and_comma_quote (const char *str, FILE *fp)
Print C<str> to C<fp> doing both shell and qemu comma quoting.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_to_channel>
int
qemuopts_to_channel (struct qemuopts *qopts, FILE *fp)
Write the qemu options to a C<FILE *fp>.
C<qemuopts_set_binary*> must be called first.
Only the qemu command line is written. The caller may need to add C<#!/bin/sh> and may need to chmod the resulting file to C<0755>.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_to_argv>
char **
qemuopts_to_argv (struct qemuopts *qopts)
Return a NULL-terminated argument list, of the kind that can be passed directly to L<execv(3)>.
C<qemuopts_set_binary*> must be called first. It will be returned as C<argv[0]> in the returned list.
The list of strings and the strings themselves must be freed by the caller.
Returns C<NULL> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_to_config_file>
int
qemuopts_to_config_file (struct qemuopts *qopts, const char *filename)
Write the qemu options to a qemu config file, suitable for reading in using C<qemu -readconfig filename>.
Note that qemu config files have limitations on content and quoting, so not all qemuopts structs can be written (this function returns an error in these cases). For more information see L<https://habkost.net/posts/2016/12/qemu-apis-qemuopts.html> L<https://bugs.launchpad.net/qemu/+bug/1686364>
Also, command line argument names and config file sections sometimes have different names. For example the equivalent of C<-m 1024> is:
[memory]
size = "1024"
This code does I<not> attempt to convert between the two forms. You just need to know how to do that yourself.
Returns C<0> on success. Returns C<-1> on error, setting C<errno>.
=head4 Function C<common/qemuopts/qemuopts.c:qemuopts_to_config_channel>
int
qemuopts_to_config_channel (struct qemuopts *qopts, FILE *fp)
Same as C<qemuopts_to_config_file>, but this writes to a C<FILE *fp>.
=head2 Subdirectory F<common/utils>
=head3 File F<common/utils/cleanups.c>
Libguestfs uses C<CLEANUP_*> macros to simplify temporary allocations. They are implemented using the C<__attribute__((cleanup))> feature of gcc and clang. Typical usage is:
fn ()
{
CLEANUP_FREE char *str = NULL;
str = safe_asprintf (g, "foo");
// str is freed automatically when the function returns
}
There are a few catches to be aware of with the cleanup mechanism:
=over 4
=item *
If a cleanup variable is not initialized, then you can end up calling L<free(3)> with an undefined value, resulting in the program crashing. For this reason, you should usually initialize every cleanup variable with something, eg. C<NULL>
=item *
Don't mark variables holding return values as cleanup variables.
=item *
The C<main()> function shouldn't use cleanup variables since it is normally exited by calling L<exit(3)>, and that doesn't call the cleanup handlers.
=back
The functions in this file are used internally by the C<CLEANUP_*> macros. Don't call them directly.
=head3 File F<common/utils/gnulib-cleanups.c>
Libguestfs uses C<CLEANUP_*> macros to simplify temporary allocations. They are implemented using the C<__attribute__((cleanup))> feature of gcc and clang. Typical usage is:
fn ()
{
CLEANUP_FREE char *str = NULL;
str = safe_asprintf (g, "foo");
// str is freed automatically when the function returns
}
There are a few catches to be aware of with the cleanup mechanism:
=over 4
=item *
If a cleanup variable is not initialized, then you can end up calling L<free(3)> with an undefined value, resulting in the program crashing. For this reason, you should usually initialize every cleanup variable with something, eg. C<NULL>
=item *
Don't mark variables holding return values as cleanup variables.
=item *
The C<main()> function shouldn't use cleanup variables since it is normally exited by calling L<exit(3)>, and that doesn't call the cleanup handlers.
=back
The functions in this file are used internally by the C<CLEANUP_*> macros. Don't call them directly.
=head3 File F<common/utils/guestfs-utils.h>
This header file is included in all "frontend" parts of libguestfs, namely the library, non-C language bindings, virt tools and tests.
The daemon does B<not> use this header. If you need a place to put something shared with absolutely everything including the daemon, put it in F<lib/guestfs-internal-all.h>
If a definition is only needed by a single component of libguestfs (eg. just the library, or just a single virt tool) then it should B<not> be here!
=head3 File F<common/utils/libxml2-writer-macros.h>
These macros make it easier to write XML. To use them correctly you must be aware of these assumptions:
=over 4
=item *
The C<xmlTextWriterPtr> is called C<xo>. It is used implicitly by all the macros.
=item *
On failure, a function called C<xml_error> is called which you must define (usually as a macro). You must use C<CLEANUP_*> macros in your functions if you want correct cleanup of local variables along the error path.
=item *
All the "bad" casting is hidden inside the macros.
=back
=head4 Definition C<common/utils/libxml2-writer-macros.h:start_element>
#define start_element
To define an XML element use:
start_element ("name") {
...
} end_element ();
which produces C<<< <name>...</name> >>>
=head4 Definition C<common/utils/libxml2-writer-macros.h:empty_element>
#define empty_element
To define an empty element:
empty_element ("name");
which produces C<<< <name/> >>>
=head4 Definition C<common/utils/libxml2-writer-macros.h:single_element>
#define single_element
To define a single element with no attributes containing some text:
single_element ("name", text);
which produces C<<< <name>text</name> >>>
=head4 Definition C<common/utils/libxml2-writer-macros.h:single_element_format>
#define single_element_format
To define a single element with no attributes containing some text using a format string:
single_element_format ("cores", "%d", nr_cores);
which produces C<<< <cores>4</cores> >>>
=head4 Definition C<common/utils/libxml2-writer-macros.h:attribute>
#define attribute
To define an XML element with attributes, use:
start_element ("name") {
attribute ("foo", "bar");
attribute_format ("count", "%d", count);
...
} end_element ();
which produces C<<< <name foo="bar" count="123">...</name> >>>
=head4 Definition C<common/utils/libxml2-writer-macros.h:attribute_ns>
#define attribute_ns
C<attribute_ns (prefix, key, namespace_uri, value)> defines a namespaced attribute.
=head4 Definition C<common/utils/libxml2-writer-macros.h:string>
#define string
To define a verbatim string, use:
string ("hello");
=head4 Definition C<common/utils/libxml2-writer-macros.h:string_format>
#define string_format
To define a verbatim string using a format string, use:
string ("%s, world", greeting);
=head4 Definition C<common/utils/libxml2-writer-macros.h:base64>
#define base64
To write a string encoded as base64:
base64 (data, size);
=head4 Definition C<common/utils/libxml2-writer-macros.h:comment>
#define comment
To define a comment in the XML, use:
comment ("number of items = %d", nr_items);
=head3 File F<common/utils/stringlists-utils.c>
Utility functions used by the library, tools and language bindings.
These functions I<must not> call internal library functions such as C<safe_*>, C<error> or C<perrorf>, or any C<guestfs_int_*>.
=head4 Function C<common/utils/stringlists-utils.c:guestfs_int_split_string>
char **
guestfs_int_split_string (char sep, const char *str)
Split string at separator character C<sep>, returning the list of strings. Returns C<NULL> on memory allocation failure.
Note (assuming C<sep> is C<:>):
=over 4
=item C<str == NULL>
aborts
=item C<str == "">
returns C<[]>
=item C<str == "abc">
returns C<["abc"]>
=item C<str == ":">
returns C<["", ""]>
=back
=head3 File F<common/utils/utils.c>
Utility functions used by the library, tools and language bindings.
These functions I<must not> call internal library functions such as C<safe_*>, C<error> or C<perrorf>, or any C<guestfs_int_*>.
=head4 Function C<common/utils/utils.c:guestfs_int_replace_string>
char *
guestfs_int_replace_string (const char *str, const char *s1, const char *s2)
Replace every instance of C<s1> appearing in C<str> with C<s2>. A newly allocated string is returned which must be freed by the caller. If allocation fails this can return C<NULL>.
例:
replace_string ("abcabb", "ab", "a");
would return C<"acab">.
=head4 Function C<common/utils/utils.c:guestfs_int_exit_status_to_string>
char *
guestfs_int_exit_status_to_string (int status, const char *cmd_name,
char *buffer, size_t buflen)
Translate a wait/system exit status into a printable string.
=head4 Function C<common/utils/utils.c:guestfs_int_random_string>
int
guestfs_int_random_string (char *ret, size_t len)
Return a random string of characters.
注:
=over 4
=item *
The C<ret> buffer must have length C<len+1> in order to store the final C<\0> character.
=item *
There is about 5 bits of randomness per output character (so about C<5*len> bits of randomness in the resulting string).
=back
=head4 Function C<common/utils/utils.c:guestfs_int_drive_name>
char *
guestfs_int_drive_name (size_t index, char *ret)
This turns a drive index (eg. C<27>) into a drive name (eg. C<"ab">).
Drive indexes count from C<0>. The return buffer has to be large enough for the resulting string, and the returned pointer points to the *end* of the string.
L<https://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-named-beyond-drive-26-devsdz/>
=head4 Function C<common/utils/utils.c:guestfs_int_drive_index>
ssize_t
guestfs_int_drive_index (const char *name)
The opposite of C<guestfs_int_drive_name>. Take a string like C<"ab"> and return the index (eg C<27>).
Note that you must remove any prefix such as C<"hd">, C<"sd"> etc, or any partition number before calling the function.
=head4 Function C<common/utils/utils.c:guestfs_int_is_true>
int
guestfs_int_is_true (const char *str)
Similar to C<Tcl_GetBoolean>.
=head4 Function C<common/utils/utils.c:guestfs_int_string_is_valid>
bool
guestfs_int_string_is_valid (const char *str,
size_t min_length, size_t max_length,
int flags, const char *extra)
Check a string for validity, that it contains only certain characters, and minimum and maximum length. This function is usually wrapped in a VALID_* macro, see F<lib/drives.c> for an example.
C<str> is the string to check.
C<min_length> and C<max_length> are the minimum and maximum length checks. C<0> means no check.
The flags control:
=over 4
=item C<VALID_FLAG_ALPHA>
7-bit ASCII-only alphabetic characters are permitted.
=item C<VALID_FLAG_DIGIT>
7-bit ASCII-only digits are permitted.
=back
C<extra> is a set of extra characters permitted, in addition to alphabetic and/or digits. (C<extra = NULL> for no extra).
Returns boolean C<true> if the string is valid (passes all the tests), or C<false> if not.
=head4 Function C<common/utils/utils.c:guestfs_int_fadvise_normal>
void
guestfs_int_fadvise_normal (int fd)
Hint that we will read or write the file descriptor normally.
On Linux, this clears the C<FMODE_RANDOM> flag on the file [see below] and sets the per-file number of readahead pages to equal the block device readahead setting.
It's OK to call this on a non-file since we ignore failure as it is only a hint.
=head4 Function C<common/utils/utils.c:guestfs_int_fadvise_sequential>
void
guestfs_int_fadvise_sequential (int fd)
Hint that we will read or write the file descriptor sequentially.
On Linux, this clears the C<FMODE_RANDOM> flag on the file [see below] and sets the per-file number of readahead pages to twice the block device readahead setting.
It's OK to call this on a non-file since we ignore failure as it is only a hint.
=head4 Function C<common/utils/utils.c:guestfs_int_fadvise_random>
void
guestfs_int_fadvise_random (int fd)
Hint that we will read or write the file descriptor randomly.
On Linux, this sets the C<FMODE_RANDOM> flag on the file. The effect of this flag is to:
=over 4
=item *
Disable normal sequential file readahead.
=item *
If any read of the file is done which misses in the page cache, 2MB are read into the page cache. [I think - I'm not sure I totally understand what this is doing]
=back
It's OK to call this on a non-file since we ignore failure as it is only a hint.
=head4 Function C<common/utils/utils.c:guestfs_int_fadvise_noreuse>
void
guestfs_int_fadvise_noreuse (int fd)
Hint that we will access the data only once.
On Linux, this does nothing.
It's OK to call this on a non-file since we ignore failure as it is only a hint.
=head4 Function C<common/utils/utils.c:guestfs_int_fadvise_dontneed>
void
guestfs_int_fadvise_dontneed (int fd)
Hint that we will not access the data in the near future.
On Linux, this immediately writes out any dirty pages in the page cache and then invalidates (drops) all pages associated with this file from the page cache. Apparently it does this even if the file is opened or being used by other processes. This setting is not persistent; if you subsequently read the file it will be cached in the page cache as normal.
It's OK to call this on a non-file since we ignore failure as it is only a hint.
=head4 Function C<common/utils/utils.c:guestfs_int_fadvise_willneed>
void
guestfs_int_fadvise_willneed (int fd)
Hint that we will access the data in the near future.
On Linux, this immediately reads the whole file into the page cache. This setting is not persistent; subsequently pages may be dropped from the page cache as normal.
It's OK to call this on a non-file since we ignore failure as it is only a hint.
=head4 Function C<common/utils/utils.c:guestfs_int_shell_unquote>
char *
guestfs_int_shell_unquote (const char *str)
Unquote a shell-quoted string.
Augeas passes strings to us which may be quoted, eg. if they come from files in F</etc/sysconfig>. This function can do simple unquoting of these strings.
Note this function does not do variable substitution, since that is impossible without knowing the file context and indeed the environment under which the shell script is run. Configuration files should not use complex quoting.
C<str> is the input string from Augeas, a string that may be single- or double-quoted or may not be quoted. The returned string is unquoted, and must be freed by the caller. C<NULL> is returned on error and C<errno> is set accordingly.
For information on double-quoting in bash, see L<https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html>
=head4 Function C<common/utils/utils.c:guestfs_int_is_reg>
int
guestfs_int_is_reg (int64_t mode)
Return true if the C<guestfs_statns> or C<guestfs_lstatns> C<st_mode> field represents a regular file.
=head4 Function C<common/utils/utils.c:guestfs_int_is_dir>
int
guestfs_int_is_dir (int64_t mode)
Return true if the C<guestfs_statns> or C<guestfs_lstatns> C<st_mode> field represents a directory.
=head4 Function C<common/utils/utils.c:guestfs_int_is_chr>
int
guestfs_int_is_chr (int64_t mode)
Return true if the C<guestfs_statns> or C<guestfs_lstatns> C<st_mode> field represents a char device.
=head4 Function C<common/utils/utils.c:guestfs_int_is_blk>
int
guestfs_int_is_blk (int64_t mode)
Return true if the C<guestfs_statns> or C<guestfs_lstatns> C<st_mode> field represents a block device.
=head4 Function C<common/utils/utils.c:guestfs_int_is_fifo>
int
guestfs_int_is_fifo (int64_t mode)
Return true if the C<guestfs_statns> or C<guestfs_lstatns> C<st_mode> field represents a named pipe (FIFO).
=head4 Function C<common/utils/utils.c:guestfs_int_is_lnk>
int
guestfs_int_is_lnk (int64_t mode)
Return true if the C<guestfs_statns> or C<guestfs_lstatns> C<st_mode> field represents a symbolic link.
=head4 Function C<common/utils/utils.c:guestfs_int_is_sock>
int
guestfs_int_is_sock (int64_t mode)
Return true if the C<guestfs_statns> or C<guestfs_lstatns> C<st_mode> field represents a Unix domain socket.
=head4 Function C<common/utils/utils.c:guestfs_int_full_path>
char *
guestfs_int_full_path (const char *dir, const char *name)
Concatenate C<dir> and C<name> to create a path. This correctly handles the case of concatenating C<"/" + "filename"> as well as C<"/dir" + "filename">. C<name> may be C<NULL>.
The caller must free the returned path.
This function sets C<errno> and returns C<NULL> on error.
=head4 Function C<common/utils/utils.c:guestfs_int_hexdump>
void
guestfs_int_hexdump (const void *data, size_t len, FILE *fp)
Hexdump a block of memory to C<FILE *>, used for debugging.
=head4 Function C<common/utils/utils.c:guestfs_int_strerror>
const char *
guestfs_int_strerror (int errnum, char *buf, size_t buflen)
Thread-safe strerror_r.
This is a wrapper around the two variants of L<strerror_r(3)> in glibc since it is hard to use correctly (RHBZ#2030396).
The buffer passed in should be large enough to store the error message (256 chars at least) and should be non-static. Note that the buffer might not be used, use the return value.
=head2 Subdirectory F<common/visit>
=head3 File F<common/visit/visit.c>
This file contains a recursive function for visiting all files and directories in a guestfs filesystem.
Adapted from L<https://rwmj.wordpress.com/2010/12/15/tip-audit-virtual-machine-for-setuid-files/>
=head4 Function C<common/visit/visit.c:visit>
int
visit (guestfs_h *g, const char *dir, visitor_function f, void *opaque)
Visit every file and directory in a guestfs filesystem, starting at C<dir>.
C<dir> may be C<"/"> to visit the entire filesystem, or may be some subdirectory. Symbolic links are not followed.
The visitor function C<f> is called once for every directory and every file. The parameters passed to C<f> include the current directory name, the current file name (or C<NULL> when we're visiting a directory), the C<guestfs_statns> (file permissions etc), and the list of extended attributes of the file. The visitor function may return C<-1> which causes the whole recursion to stop with an error.
Also passed to this function is an C<opaque> pointer which is passed through to the visitor function.
Returns C<0> if everything went OK, or C<-1> if there was an error. Error handling is not particularly well defined. It will either set an error in the libguestfs handle or print an error on stderr, but there is no way for the caller to tell the difference.
=head2 Subdirectory F<common/windows>
=head3 File F<common/windows/windows.c>
This file implements C<win:> Windows file path support in L<guestfish(1)>.
=head4 Function C<common/windows/windows.c:is_windows>
int
is_windows (guestfs_h *g, const char *root)
Checks whether C<root> is a Windows installation.
This relies on an already being done introspection.
=head4 Function C<common/windows/windows.c:windows_path>
char *
windows_path (guestfs_h *g, const char *root, const char *path, int readonly)
Resolves C<path> as possible Windows path according to C<root>, giving a new path that can be used in libguestfs API calls.
注:
=over 4
=item *
C<root> must be a Windows installation
=item *
relies on an already being done introspection
=item *
will unmount all the existing mount points and mount the Windows root (according to C<readonly>)
=item *
calls L<exit(3)> on memory allocation failures
=back
=head2 Subdirectory F<daemon>
=head3 File F<daemon/command.c>
This file contains a number of useful functions for running external commands and capturing their output.
=head4 Function C<daemon/command.c:commandf>
int
commandf (char **stdoutput, char **stderror, unsigned flags,
const char *name, ...)
Run a command. Optionally capture stdout and stderr as strings.
Returns C<0> if the command ran successfully, or C<-1> if there was any error.
For a description of the C<flags> see C<commandrvf>.
There is also a macro C<command(out,err,name,...)> which calls C<commandf> with C<flags=0>.
=head4 Function C<daemon/command.c:commandrf>
int
commandrf (char **stdoutput, char **stderror, unsigned flags,
const char *name, ...)
Same as C<command>, but we allow the status code from the subcommand to be non-zero, and return that status code.
We still return C<-1> if there was some other error.
There is also a macro C<commandr(out,err,name,...)> which calls C<commandrf> with C<flags=0>.
=head4 Function C<daemon/command.c:commandvf>
int
commandvf (char **stdoutput, char **stderror, unsigned flags,
char const *const *argv)
Same as C<command>, but passing in an argv array.
There is also a macro C<commandv(out,err,argv)> which calls C<commandvf> with C<flags=0>.
=head4 Function C<daemon/command.c:commandrvf>
int
commandrvf (char **stdoutput, char **stderror, unsigned flags,
char const* const *argv)
This is a more sane version of L<system(3)> for running external commands. It uses fork/execvp, so we don't need to worry about quoting of parameters, and it allows us to capture any error messages in a buffer.
If C<stdoutput> is not C<NULL>, then C<*stdoutput> will return the stdout of the command as a string.
If C<stderror> is not C<NULL>, then C<*stderror> will return the stderr of the command. If there is a final \n character, it is removed so you can use the error string directly in a call to C<reply_with_error>.
Flags are:
=over 4
=item C<COMMAND_FLAG_FOLD_STDOUT_ON_STDERR>
For broken external commands that send error messages to stdout (hello, parted) but that don't have any useful stdout information, use this flag to capture the error messages in the C<*stderror> buffer. If using this flag, you should pass C<stdoutput=NULL> because nothing could ever be captured in that buffer.
=item C<COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN>
For running external commands on chrooted files correctly (see L<https://bugzilla.redhat.com/579608>) specifying this flag causes another process to be forked which chroots into sysroot and just copies the input file to stdin of the specified command. The file descriptor is ORed with the flags, and that file descriptor is always closed by this function. See F<daemon/hexdump.c> for an example of usage.
=back
There is also a macro C<commandrv(out,err,argv)> which calls C<commandrvf> with C<flags=0>.
=head3 File F<daemon/device-name-translation.c>
=head4 Function C<daemon/device-name-translation.c:device_name_translation_init>
void
device_name_translation_init (void)
Cache daemon disk mapping.
When the daemon starts up, populate a cache with the contents of /dev/disk/by-path. It's easiest to use C<ls -lv> here since the names are sorted awkwardly.
=head4 Function C<daemon/device-name-translation.c:device_name_translation>
char *
device_name_translation (const char *device)
Perform device name translation.
Libguestfs defines a few standard formats for device names. (see also L<guestfs(3)/BLOCK DEVICE NAMING> and L<guestfs(3)/guestfs_canonical_device_name>). They are:
=over 4
=item F</dev/sdX[N]>
=item F</dev/hdX[N]>
=item F</dev/vdX[N]>
These mean the Nth partition on the Xth device. Because Linux no longer enumerates devices in the order they are passed to qemu, we must translate these by looking up the actual device using /dev/disk/by-path/
=item F</dev/mdX>
=item F</dev/VG/LV>
=item F</dev/mapper/...>
=item F</dev/dm-N>
These are not translated here.
=back
It returns a newly allocated string which the caller must free.
It returns C<NULL> on error. B<Note> it does I<not> call C<reply_with_*>.
We have to open the device and test for C<ENXIO>, because the device nodes may exist in the appliance.
=head3 File F<daemon/guestfsd.c>
This is the guestfs daemon which runs inside the guestfs appliance. This file handles start up and connecting back to the library.
=head4 Function C<daemon/guestfsd.c:shell_quote>
void
shell_quote (const char *str, FILE *fp)
Write C<str> to the file C<fp>, ensuring it is shell quoted.
=head4 Function C<daemon/guestfsd.c:sysroot_shell_quote>
void
sysroot_shell_quote (const char *path, FILE *fp)
Write C<sysroot> + C<path> to the file C<fp>, ensuring it is shell quoted. The path must be an absolute path.
=head3 File F<daemon/internal.c>
Internal functions that are not part of the public API.
=head3 File F<daemon/utils-c.c>
Bindings for utility functions.
Note that functions called from OCaml code B<must never> call any of the C<reply*> functions.
=head3 File F<daemon/utils.c>
Miscellaneous utility functions used by the daemon.
=head4 Function C<daemon/utils.c:is_root_device_stat>
static int
is_root_device_stat (struct stat *statbuf)
Return true iff device is the root device (and therefore should be ignored from the point of view of user calls).
=head4 Function C<daemon/utils.c:is_device_parameter>
int
is_device_parameter (const char *device)
Parameters marked as C<Device>, C<Dev_or_Path>, etc can be passed a block device name. This function tests if the parameter is a block device name.
It can also be used in daemon code to test if the string passed as a C<Dev_or_Path> parameter is a device or path.
=head4 Function C<daemon/utils.c:sysroot_path>
char *
sysroot_path (const char *path)
Turn C<"/path"> into C<"/sysroot/path">.
Returns C<NULL> on failure. The caller I<must> check for this and call S<C<reply_with_perror ("malloc")>>. The caller must also free the returned string.
See also the custom C<%R> printf formatter which does shell quoting too.
=head4 Function C<daemon/utils.c:sysroot_realpath>
char *
sysroot_realpath (const char *path)
Resolve path within sysroot, calling C<sysroot_path> on the resolved path.
Returns C<NULL> on failure. The caller I<must> check for this and call S<C<reply_with_perror ("malloc")>>. The caller must also free the returned string.
See also the custom C<%R> printf formatter which does shell quoting too.
=head4 Function C<daemon/utils.c:is_power_of_2>
int
is_power_of_2 (unsigned long v)
Returns true if C<v> is a power of 2.
Uses the algorithm described at L<http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2>
=head4 Function C<daemon/utils.c:split_lines_sb>
struct stringsbuf
split_lines_sb (char *str)
Split an output string into a NULL-terminated list of lines, wrapped into a stringsbuf.
Typically this is used where we have run an external command which has printed out a list of things, and we want to return an actual list.
The corner cases here are quite tricky. Note in particular:
=over 4
=item C<"">
returns C<[]>
=item C<"\n">
returns C<[""]>
=item C<"a\nb">
returns C<["a"; "b"]>
=item C<"a\nb\n">
returns C<["a"; "b"]>
=item C<"a\nb\n\n">
returns C<["a"; "b"; ""]>
=back
The original string is written over and destroyed by this function (which is usually OK because it's the 'out' string from C<command*()>). You can free the original string, because C<add_string()> strdups the strings.
C<argv> in the C<struct stringsbuf> will be C<NULL> in case of errors.
=head4 Function C<daemon/utils.c:filter_list>
char **
filter_list (bool (*p) (const char *str), char **strs)
Filter a list of strings. Returns a newly allocated list of only the strings where C<p (str) == true>.
B<Note> it does not copy the strings, be careful not to double-free them.
=head4 Function C<daemon/utils.c:trim>
void
trim (char *str)
Skip leading and trailing whitespace, updating the original string in-place.
=head4 Function C<daemon/utils.c:parse_btrfsvol>
int
parse_btrfsvol (const char *desc_orig, mountable_t *mountable)
Parse the mountable descriptor for a btrfs subvolume. Don't call this directly; it is only used from the stubs.
A btrfs subvolume is given as:
btrfsvol:/dev/sda3/root
where F</dev/sda3> is a block device containing a btrfs filesystem, and root is the name of a subvolume on it. This function is passed the string following C<"btrfsvol:">.
On success, C<mountable-E<gt>device> and C<mountable-E<gt>volume> must be freed by the caller.
=head4 Function C<daemon/utils.c:mountable_to_string>
char *
mountable_to_string (const mountable_t *mountable)
Convert a C<mountable_t> back to its string representation
This function can be used in an error path, so must not call C<reply_with_error>.
=head4 Function C<daemon/utils.c:prog_exists>
int
prog_exists (const char *prog)
Check program exists and is executable on C<$PATH>.
=head4 Function C<daemon/utils.c:random_name>
int
random_name (char *template)
Pass a template such as C<"/sysroot/XXXXXXXX.XXX">. This updates the template to contain a randomly named file. Any C<'X'> characters after the final C<'/'> in the template are replaced with random characters.
Notes: You should probably use an 8.3 path, so it's compatible with all filesystems including basic FAT. Also this only substitutes lowercase ASCII letters and numbers, again for compatibility with lowest common denominator filesystems.
This doesn't create a file or check whether or not the file exists (it would be extremely unlikely to exist as long as the RNG is working).
If there is an error, C<-1> is returned.
=head4 Function C<daemon/utils.c:udev_settle_file>
void
udev_settle_file (const char *file)
LVM and other commands aren't synchronous, especially when udev is involved. eg. You can create or remove some device, but the C</dev> device node won't appear until some time later. This means that you get an error if you run one command followed by another.
Use C<udevadm settle> after certain commands, but don't be too fussed if it fails.
=head4 Function C<daemon/utils.c:make_exclude_from_file>
char *
make_exclude_from_file (const char *function, char *const *excludes)
Turn list C<excludes> into a temporary file, and return a string containing the temporary file name. Caller must unlink the file and free the string.
C<function> is the function that invoked this helper, and it is used mainly for errors/debugging.
=head4 Function C<daemon/utils.c:read_whole_file>
char *
read_whole_file (const char *filename, size_t *size_r)
Read whole file into dynamically allocated array. If there is an error, DON'T call reply_with_perror, just return NULL. Returns a C<\0>-terminated string. C<size_r> can be specified to get the size of the returned data.
=head3 File F<daemon/xattr.c>
=head4 Function C<daemon/xattr.c:split_attr_names>
static char **
split_attr_names (char *buf, size_t len)
L<listxattr(2)> returns the string C<"foo\0bar\0baz"> of length C<len>. (The last string in the list is \0-terminated but the \0 is not included in C<len>).
This function splits it into a regular list of strings.
B<Note> that the returned list contains pointers to the original strings in C<buf> so be careful that you do not double-free them.
=head2 Subdirectory F<fish>
=head3 File F<fish/alloc.c>
This file implements the guestfish C<alloc> and C<sparse> commands.
=head4 Function C<fish/alloc.c:alloc_disk>
int
alloc_disk (const char *filename, const char *size_str, int add, int sparse)
This is the underlying allocation function. It's called from a few other places in guestfish.
=head3 File F<fish/copy.c>
This file implements the guestfish commands C<copy-in> and C<copy-out>.
=head3 File F<fish/destpaths.c>
The file handles tab-completion of filesystem paths in guestfish.
=head3 File F<fish/display.c>
The file implements the guestfish C<display> command, for displaying graphical files (icons, images) in disk images.
=head3 File F<fish/echo.c>
The file implements the guestfish C<echo> command.
=head3 File F<fish/edit.c>
guestfish C<edit> command, suggested by Ján Ondrej.
=head3 File F<fish/events.c>
This file implements the guestfish event-related commands, C<event>, C<delete-event> and C<list-events>.
=head3 File F<fish/fish.c>
guestfish, the guest filesystem shell. This file contains the main loop and utilities.
=head4 Function C<fish/fish.c:parse_command_line>
static struct parsed_command
parse_command_line (char *buf, int *exit_on_error_rtn)
Parse a command string, splitting at whitespace, handling C<'!'>, C<'#'> etc. This destructively updates C<buf>.
C<exit_on_error_rtn> is used to pass in the global C<exit_on_error> setting and to return the local setting (eg. if the command begins with C<'-'>).
Returns in C<parsed_command.status>:
=over 4
=item C<1>
got a guestfish command (returned in C<cmd_rtn>/C<argv_rtn>/C<pipe_rtn>)
=item C<0>
no guestfish command, but otherwise OK
=item C<-1>
an error
=back
=head4 Function C<fish/fish.c:parse_quoted_string>
static ssize_t
parse_quoted_string (char *p)
Parse double-quoted strings, replacing backslash escape sequences with the true character. Since the string is returned in place, the escapes must make the string shorter.
=head4 Function C<fish/fish.c:execute_and_inline>
static int
execute_and_inline (const char *cmd, int global_exit_on_error)
Used to handle C<E<lt>!> (execute command and inline result).
=head4 Function C<fish/fish.c:issue_command>
int
issue_command (const char *cmd, char *argv[], const char *pipecmd,
int rc_exit_on_error_flag)
Run a command.
C<rc_exit_on_error_flag> is the C<exit_on_error> flag that we pass to the remote server (when issuing I<--remote> commands). It does not cause C<issue_command> itself to exit on error.
=head4 Function C<fish/fish.c:extended_help_message>
void
extended_help_message (void)
Print an extended help message when the user types in an unknown command for the first command issued. A common case is the user doing:
guestfish disk.img
expecting guestfish to open F<disk.img> (in fact, this tried to run a non-existent command C<disk.img>).
=head4 Function C<fish/fish.c:error_cb>
static void
error_cb (guestfs_h *g, void *data, const char *msg)
Error callback. This replaces the standard libguestfs error handler.
=head4 Function C<fish/fish.c:free_n_strings>
static void
free_n_strings (char **str, size_t len)
Free strings from a non-NULL terminated C<char**>.
=head4 Function C<fish/fish.c:decode_ps1>
static char *
decode_ps1 (const char *str)
Decode C<str> into the final printable prompt string.
=head4 Function C<fish/fish.c:win_prefix>
char *
win_prefix (const char *path)
Resolve the special C<win:...> form for Windows-specific paths. The generated code calls this for all device or path arguments.
The function returns a newly allocated string, and the caller must free this string; else display an error and return C<NULL>.
=head4 Function C<fish/fish.c:file_in>
char *
file_in (const char *arg)
Resolve the special C<FileIn> paths (C<-> or C<-<<END> or filename).
The caller (F<fish/cmds.c>) will call C<free_file_in> after the command has run which should clean up resources.
=head4 Function C<fish/fish.c:file_out>
char *
file_out (const char *arg)
Resolve the special C<FileOut> paths (C<-> or filename).
The caller (F<fish/cmds.c>) will call S<C<free (str)>> after the command has run.
=head4 Function C<fish/fish.c:progress_callback>
void
progress_callback (guestfs_h *g, void *data,
uint64_t event, int event_handle, int flags,
const char *buf, size_t buf_len,
const uint64_t *array, size_t array_len)
Callback which displays a progress bar.
=head3 File F<fish/glob.c>
This file implements the guestfish C<glob> command.
=head4 Function C<fish/glob.c:expand_devicename>
static char **
expand_devicename (guestfs_h *g, const char *device)
Glob-expand device patterns, such as C</dev/sd*> (L<https://bugzilla.redhat.com/635971>).
There is no C<guestfs_glob_expand_device> function because the equivalent can be implemented using functions like C<guestfs_list_devices>.
It's not immediately clear what it means to expand a pattern like C</dev/sd*>. Should that include device name translation? Should the result include partitions as well as devices?
Should C<"/dev/"> + C<"*"> return every possible device and filesystem? How about VGs? LVs?
To solve this what we do is build up a list of every device, partition, etc., then glob against that list.
Notes for future work (XXX):
=over 4
=item *
This doesn't handle device name translation. It wouldn't be too hard to add.
=item *
Could have an API function for returning all device-like things.
=back
=head4 Function C<fish/glob.c:add_strings_matching>
static int
add_strings_matching (char **pp, const char *glob,
char ***ret, size_t *size_r)
Using POSIX L<fnmatch(3)>, find strings in the list C<pp> which match pattern C<glob>. Add strings which match to the C<ret> array. C<*size_r> is the current size of the C<ret> array, which is updated with the new size.
=head4 Function C<fish/glob.c:single_element_list>
static char **
single_element_list (const char *element)
Return a single element list containing C<element>.
=head3 File F<fish/help.c>
The file implements the guestfish C<help> command.
=head4 Function C<fish/help.c:display_help>
int
display_help (const char *cmd, size_t argc, char *argv[])
The C<help> command.
This used to just list all commands, but that's not very useful. Instead display some useful context-sensitive help. This could be improved if we knew how many drives had been added already, and whether anything was mounted.
=head3 File F<fish/hexedit.c>
This file implements the guestfish C<hexedit> command.
=head3 File F<fish/lcd.c>
=head4 Function C<fish/lcd.c:run_lcd>
int
run_lcd (const char *cmd, size_t argc, char *argv[])
guestfish C<lcd> command (similar to the C<lcd> command in BSD ftp).
=head3 File F<fish/man.c>
=head4 Function C<fish/man.c:run_man>
int
run_man (const char *cmd, size_t argc, char *argv[])
guestfish C<man> command
=head3 File F<fish/more.c>
This file implements the guestfish C<more> command.
=head3 File F<fish/prep.c>
This file implements the guestfish I<-N> option for creating pre-prepared disk layouts.
=head3 File F<fish/rc.c>
This file implements guestfish remote (command) support.
=head4 Function C<fish/rc.c:rc_listen>
void
rc_listen (void)
The remote control server (ie. C<guestfish --listen>).
=head4 Function C<fish/rc.c:rc_remote>
int
rc_remote (int pid, const char *cmd, size_t argc, char *argv[],
int exit_on_error)
The remote control client (ie. C<guestfish --remote>).
=head3 File F<fish/reopen.c>
This file implements the guestfish C<reopen> command.
=head3 File F<fish/setenv.c>
This file implements the guestfish C<setenv> and C<unsetenv> commands.
=head3 File F<fish/supported.c>
This file implements the guestfish C<supported> command.
=head3 File F<fish/tilde.c>
This file implements tilde (C<~>) expansion of home directories in L<guestfish(1)>.
=head4 Function C<fish/tilde.c:try_tilde_expansion>
char *
try_tilde_expansion (char *str)
This is called from the script loop if we find a candidate for C<~username> (tilde-expansion).
=head4 Function C<fish/tilde.c:expand_home>
static char *
expand_home (char *orig, const char *append)
Return C<$HOME> + append string.
=head4 Function C<fish/tilde.c:find_home_for_username>
static const char *
find_home_for_username (const char *username, size_t ulen)
Lookup C<username> (of length C<ulen>), return home directory if found, or C<NULL> if not found.
=head3 File F<fish/time.c>
This file implements the guestfish C<time> command.
=head2 Subdirectory F<python>
=head3 File F<python/handle.c>
This file contains a small number of functions that are written by hand. The majority of the bindings are generated (see F<python/actions-*.c>).
|