1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* NVM-Express command line utility.
*
* Copyright (c) 2014-2015, Intel Corporation.
*
* Written by Keith Busch <kbusch@kernel.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* This program uses NVMe IOCTLs to run native nvme commands to a device.
*/
#include "config.h"
#include "nvme/tree.h"
#include "nvme/types.h"
#include "util/cleanup.h"
#include <errno.h>
#include <getopt.h>
#include <fcntl.h>
#include <inttypes.h>
#include <locale.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <dirent.h>
#include <libgen.h>
#include <signal.h>
#include <linux/fs.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#if HAVE_SYS_RANDOM
#include <sys/random.h>
#endif
#include <libnvme.h>
#include "common.h"
#include "nvme.h"
#include "nvme-print.h"
#include "plugin.h"
#include "util/base64.h"
#include "util/crc32.h"
#include "nvme-wrap.h"
#include "util/argconfig.h"
#include "util/suffix.h"
#include "logging.h"
#include "util/sighdl.h"
#include "fabrics.h"
#define CREATE_CMD
#include "nvme-builtin.h"
#include "malloc.h"
struct feat_cfg {
__u8 feature_id; /* enum nvme_features_id */
__u8 sel; /* enum nvme_get_features_sel */
__u32 namespace_id;
__u32 cdw11;
__u32 cdw12;
__u8 uuid_index;
__u32 data_len;
bool raw_binary;
bool human_readable;
bool changed;
};
struct passthru_config {
__u8 opcode;
__u8 flags;
__u16 rsvd;
__u32 namespace_id;
__u32 data_len;
__u32 metadata_len;
__u32 cdw2;
__u32 cdw3;
__u32 cdw10;
__u32 cdw11;
__u32 cdw12;
__u32 cdw13;
__u32 cdw14;
__u32 cdw15;
char *input_file;
char *metadata;
bool raw_binary;
bool show_command;
bool read;
bool write;
__u8 prefill;
bool latency;
};
struct get_reg_config {
int offset;
bool human_readable;
bool cap;
bool vs;
bool intms;
bool intmc;
bool cc;
bool csts;
bool nssr;
bool aqa;
bool asq;
bool acq;
bool cmbloc;
bool cmbsz;
bool bpinfo;
bool bprsel;
bool bpmbl;
bool cmbmsc;
bool cmbsts;
bool cmbebs;
bool cmbswtp;
bool nssd;
bool crto;
bool pmrcap;
bool pmrctl;
bool pmrsts;
bool pmrebs;
bool pmrswtp;
bool pmrmscl;
bool pmrmscu;
bool fabrics;
};
struct set_reg_config {
int offset;
bool mmio32;
__u64 value;
__u32 intms;
__u32 intmc;
__u32 cc;
__u32 csts;
__u32 nssr;
__u32 aqa;
__u64 asq;
__u64 acq;
__u32 bprsel;
__u64 bpmbl;
__u64 cmbmsc;
__u32 nssd;
__u32 pmrctl;
__u32 pmrmscl;
__u32 pmrmscu;
};
static const char nvme_version_string[] = NVME_VERSION;
static struct plugin builtin = {
.commands = commands,
.name = NULL,
.desc = NULL,
.next = NULL,
.tail = &builtin,
};
static struct program nvme = {
.name = "nvme",
.version = nvme_version_string,
.usage = "<command> [<device>] [<args>]",
.desc = "The '<device>' may be either an NVMe character "
"device (ex: /dev/nvme0), an nvme block device "
"(ex: /dev/nvme0n1), or a mctp address in the form "
"mctp:<net>,<eid>[:ctrl-id]",
.extensions = &builtin,
};
#ifdef CONFIG_JSONC
const char *output_format = "Output format: normal|json|binary";
#else /* CONFIG_JSONC */
const char *output_format = "Output format: normal|binary";
#endif /* CONFIG_JSONC */
const char *timeout = "timeout value, in milliseconds";
const char *verbose = "Increase output verbosity";
const char *dry_run = "show command instead of sending";
static const char *app_tag = "app tag for end-to-end PI";
static const char *app_tag_mask = "app tag mask for end-to-end PI";
static const char *block_count = "number of blocks (zeroes based) on device to access";
static const char *crkey = "current reservation key";
static const char *csi = "command set identifier";
static const char *buf_len = "buffer len (if) data is sent or received";
static const char *deprecated = "deprecated; does nothing";
static const char *domainid = "Domain Identifier";
static const char *doper = "directive operation";
static const char *dspec_w_dtype = "directive specification associated with directive type";
static const char *dtype = "directive type";
static const char *endgid = "Endurance Group Identifier (ENDGID)";
static const char *force_unit_access = "force device to commit data before command completes";
static const char *human_readable_directive = "show directive in readable format";
static const char *human_readable_identify = "show identify in readable format";
static const char *human_readable_info = "show info in readable format";
static const char *human_readable_log = "show log in readable format";
static const char *iekey = "ignore existing res. key";
static const char *latency = "output latency statistics";
static const char *lba_format_index = "The index into the LBA Format list\n"
"identifying the LBA Format capabilities that are to be returned";
static const char *limited_retry = "limit media access attempts";
static const char *lsp = "log specific field";
static const char *mos = "management operation specific";
static const char *mo = "management operation";
static const char *namespace_desired = "desired namespace";
static const char *namespace_id_desired = "identifier of desired namespace";
static const char *namespace_id_optional = "optional namespace attached to controller";
static const char *nssf = "NVMe Security Specific Field";
static const char *prinfo = "PI and check field";
static const char *rae = "Retain an Asynchronous Event";
static const char *raw_directive = "show directive in binary format";
static const char *raw_dump = "dump output in binary format";
static const char *raw_identify = "show identify in binary format";
static const char *raw_log = "show log in binary format";
static const char *raw_output = "output in binary format";
static const char *ref_tag = "reference tag for end-to-end PI";
static const char *raw_use = "use binary output";
static const char *rtype = "reservation type";
static const char *secp = "security protocol (cf. SPC-4)";
static const char *spsp = "security-protocol-specific (cf. SPC-4)";
static const char *start_block = "64-bit LBA of first block to access";
static const char *storage_tag = "storage tag for end-to-end PI";
static const char *uuid_index = "UUID index";
static const char *uuid_index_specify = "specify uuid index";
static const char dash[51] = {[0 ... 49] = '=', '\0'};
static const char space[51] = {[0 ... 49] = ' ', '\0'};
static const char *offset = "offset of the requested register";
static const char *intms = "INTMS=0xc register offset";
static const char *intmc = "INTMC=0x10 register offset";
static const char *cc = "CC=0x14 register offset";
static const char *csts = "CSTS=0x1c register offset";
static const char *nssr = "NSSR=0x20 register offset";
static const char *aqa = "AQA=0x24 register offset";
static const char *asq = "ASQ=0x28 register offset";
static const char *acq = "ACQ=0x30 register offset";
static const char *bprsel = "BPRSEL=0x44 register offset";
static const char *bpmbl = "BPMBL=0x48 register offset";
static const char *cmbmsc = "CMBMSC=0x50 register offset";
static const char *nssd = "NSSD=0x64 register offset";
static const char *pmrctl = "PMRCTL=0xe04 register offset";
static const char *pmrmscl = "PMRMSCL=0xe14 register offset";
static const char *pmrmscu = "PMRMSCU=0xe18 register offset";
struct nvme_config nvme_cfg = {
.output_format = "normal",
.output_format_ver = 1,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
};
static void *mmap_registers(struct nvme_dev *dev, bool writable);
static OPT_VALS(feature_name) = {
VAL_BYTE("arbitration", NVME_FEAT_FID_ARBITRATION),
VAL_BYTE("power-mgmt", NVME_FEAT_FID_POWER_MGMT),
VAL_BYTE("lba-range", NVME_FEAT_FID_LBA_RANGE),
VAL_BYTE("temp-thresh", NVME_FEAT_FID_TEMP_THRESH),
VAL_BYTE("err-recovery", NVME_FEAT_FID_ERR_RECOVERY),
VAL_BYTE("volatile-wc", NVME_FEAT_FID_VOLATILE_WC),
VAL_BYTE("num-queues", NVME_FEAT_FID_NUM_QUEUES),
VAL_BYTE("irq-coalesce", NVME_FEAT_FID_IRQ_COALESCE),
VAL_BYTE("irq-config", NVME_FEAT_FID_IRQ_CONFIG),
VAL_BYTE("write-atomic", NVME_FEAT_FID_WRITE_ATOMIC),
VAL_BYTE("async-event", NVME_FEAT_FID_ASYNC_EVENT),
VAL_BYTE("auto-pst", NVME_FEAT_FID_AUTO_PST),
VAL_BYTE("host-mem-buf", NVME_FEAT_FID_HOST_MEM_BUF),
VAL_BYTE("timestamp", NVME_FEAT_FID_TIMESTAMP),
VAL_BYTE("kato", NVME_FEAT_FID_KATO),
VAL_BYTE("hctm", NVME_FEAT_FID_HCTM),
VAL_BYTE("nopsc", NVME_FEAT_FID_NOPSC),
VAL_BYTE("rrl", NVME_FEAT_FID_RRL),
VAL_BYTE("plm-config", NVME_FEAT_FID_PLM_CONFIG),
VAL_BYTE("plm-window", NVME_FEAT_FID_PLM_WINDOW),
VAL_BYTE("lba-sts-interval", NVME_FEAT_FID_LBA_STS_INTERVAL),
VAL_BYTE("host-behavior", NVME_FEAT_FID_HOST_BEHAVIOR),
VAL_BYTE("sanitize", NVME_FEAT_FID_SANITIZE),
VAL_BYTE("endurance-evt-cfg", NVME_FEAT_FID_ENDURANCE_EVT_CFG),
VAL_BYTE("iocs-profile", NVME_FEAT_FID_IOCS_PROFILE),
VAL_BYTE("spinup-control", NVME_FEAT_FID_SPINUP_CONTROL),
VAL_BYTE("power-loss-signal", NVME_FEAT_FID_POWER_LOSS_SIGNAL),
VAL_BYTE("perf-characteristics", NVME_FEAT_FID_PERF_CHARACTERISTICS),
VAL_BYTE("fdp", NVME_FEAT_FID_FDP),
VAL_BYTE("fdp-events", NVME_FEAT_FID_FDP_EVENTS),
VAL_BYTE("ns-admin-label", NVME_FEAT_FID_NS_ADMIN_LABEL),
VAL_BYTE("key-value", NVME_FEAT_FID_KEY_VALUE),
VAL_BYTE("ctrl-data-queue", NVME_FEAT_FID_CTRL_DATA_QUEUE),
VAL_BYTE("emb-mgmt-ctrl-addr", NVME_FEAT_FID_EMB_MGMT_CTRL_ADDR),
VAL_BYTE("host-mgmt-agent-addr", NVME_FEAT_FID_HOST_MGMT_AGENT_ADDR),
VAL_BYTE("enh-ctrl-metadata", NVME_FEAT_FID_ENH_CTRL_METADATA),
VAL_BYTE("ctrl-metadata", NVME_FEAT_FID_CTRL_METADATA),
VAL_BYTE("ns-metadata", NVME_FEAT_FID_NS_METADATA),
VAL_BYTE("sw-progress", NVME_FEAT_FID_SW_PROGRESS),
VAL_BYTE("host-id", NVME_FEAT_FID_HOST_ID),
VAL_BYTE("resv-mask", NVME_FEAT_FID_RESV_MASK),
VAL_BYTE("resv-persist", NVME_FEAT_FID_RESV_PERSIST),
VAL_BYTE("write-protect", NVME_FEAT_FID_WRITE_PROTECT),
VAL_BYTE("bp-write-protect", NVME_FEAT_FID_BP_WRITE_PROTECT),
VAL_END()
};
const char *nvme_strerror(int errnum)
{
if (errnum >= ENVME_CONNECT_RESOLVE)
return nvme_errno_to_string(errnum);
return strerror(errnum);
}
static ssize_t getrandom_bytes(void *buf, size_t buflen)
{
#if HAVE_SYS_RANDOM
return getrandom(buf, buflen, GRND_NONBLOCK);
#else
ssize_t result;
int fd, err = 0;
fd = open("/dev/urandom", O_RDONLY);
if (fd < 0)
return fd;
result = read(fd, buf, buflen);
if (result < 0)
err = errno;
close(fd);
errno = err;
return result;
#endif
}
static bool is_chardev(struct nvme_dev *dev)
{
return S_ISCHR(dev->direct.stat.st_mode);
}
static bool is_blkdev(struct nvme_dev *dev)
{
return S_ISBLK(dev->direct.stat.st_mode);
}
static int open_dev_direct(struct nvme_dev **devp, char *devstr, int flags)
{
struct nvme_dev *dev;
int err;
dev = calloc(1, sizeof(*dev));
if (!dev)
return -1;
dev->type = NVME_DEV_DIRECT;
dev->name = basename(devstr);
err = open(devstr, flags);
if (err < 0) {
nvme_show_perror(devstr);
goto err_free;
}
dev->direct.fd = err;
err = fstat(dev_fd(dev), &dev->direct.stat);
if (err < 0) {
nvme_show_perror(devstr);
goto err_close;
}
if (!is_chardev(dev) && !is_blkdev(dev)) {
nvme_show_error("%s is not a block or character device", devstr);
errno = ENODEV;
err = -1;
goto err_close;
}
*devp = dev;
return 0;
err_close:
close(dev_fd(dev));
err_free:
free(dev);
return err;
}
static int parse_mi_dev(char *dev, unsigned int *net, uint8_t *eid,
unsigned int *ctrl)
{
int rc;
/* <net>,<eid>:<ctrl-id> form */
rc = sscanf(dev, "mctp:%u,%hhu:%u", net, eid, ctrl);
if (rc == 3)
return 0;
/* <net>,<eid> form, implicit ctrl-id = 0 */
*ctrl = 0;
rc = sscanf(dev, "mctp:%u,%hhu", net, eid);
if (rc == 2)
return 0;
return -1;
}
static int open_dev_mi_mctp(struct nvme_dev **devp, char *devstr)
{
unsigned int net, ctrl_id;
struct nvme_dev *dev;
unsigned char eid;
int rc;
rc = parse_mi_dev(devstr, &net, &eid, &ctrl_id);
if (rc) {
nvme_show_error("invalid device specifier '%s'", devstr);
return rc;
}
dev = calloc(1, sizeof(*dev));
if (!dev)
return -1;
dev->type = NVME_DEV_MI;
dev->name = devstr;
/* todo: verbose argument */
dev->mi.root = nvme_mi_create_root(stderr, LOG_WARNING);
if (!dev->mi.root)
goto err_free;
dev->mi.ep = nvme_mi_open_mctp(dev->mi.root, net, eid);
if (!dev->mi.ep)
goto err_free_root;
dev->mi.ctrl = nvme_mi_init_ctrl(dev->mi.ep, ctrl_id);
if (!dev->mi.ctrl)
goto err_close_ep;
*devp = dev;
return 0;
err_close_ep:
nvme_mi_close(dev->mi.ep);
err_free_root:
nvme_mi_free_root(dev->mi.root);
err_free:
free(dev);
return -1;
}
static int check_arg_dev(int argc, char **argv)
{
if (optind >= argc) {
errno = EINVAL;
nvme_show_perror(argv[0]);
return -EINVAL;
}
return 0;
}
static int get_dev(struct nvme_dev **dev, int argc, char **argv, int flags)
{
char *devname;
int ret;
ret = check_arg_dev(argc, argv);
if (ret)
return ret;
devname = argv[optind];
errno = ENXIO;
if (!strncmp(devname, "mctp:", strlen("mctp:")))
ret = open_dev_mi_mctp(dev, devname);
else
ret = open_dev_direct(dev, devname, flags);
if (!ret && log_level >= LOG_DEBUG)
nvme_show_init();
return ret ? -errno : 0;
}
static int parse_args(int argc, char *argv[], const char *desc,
struct argconfig_commandline_options *opts)
{
int ret;
ret = argconfig_parse(argc, argv, desc, opts);
if (ret)
return ret;
log_level = map_log_level(nvme_cfg.verbose, false);
nvme_init_default_logging(stderr, log_level, false, false);
return 0;
}
int parse_and_open(struct nvme_dev **dev, int argc, char **argv,
const char *desc,
struct argconfig_commandline_options *opts)
{
int ret;
ret = parse_args(argc, argv, desc, opts);
if (ret)
return ret;
ret = get_dev(dev, argc, argv, O_RDONLY);
if (ret < 0)
argconfig_print_help(desc, opts);
return ret;
}
int open_exclusive(struct nvme_dev **dev, int argc, char **argv,
int ignore_exclusive)
{
int flags = O_RDONLY;
if (!ignore_exclusive)
flags |= O_EXCL;
return get_dev(dev, argc, argv, flags);
}
int validate_output_format(const char *format, nvme_print_flags_t *flags)
{
nvme_print_flags_t f;
if (!format)
return -EINVAL;
if (!strcmp(format, "normal"))
f = NORMAL;
#ifdef CONFIG_JSONC
else if (!strcmp(format, "json"))
f = JSON;
#endif /* CONFIG_JSONC */
else if (!strcmp(format, "binary"))
f = BINARY;
else if (!strcmp(format, "tabular"))
f = TABULAR;
else
return -EINVAL;
*flags = f;
return 0;
}
bool nvme_is_output_format_json(void)
{
nvme_print_flags_t flags;
if (validate_output_format(nvme_cfg.output_format, &flags))
return false;
return flags == JSON;
}
void dev_close(struct nvme_dev *dev)
{
if (log_level >= LOG_DEBUG)
nvme_show_finish();
switch (dev->type) {
case NVME_DEV_DIRECT:
close(dev_fd(dev));
break;
case NVME_DEV_MI:
nvme_mi_close(dev->mi.ep);
nvme_mi_free_root(dev->mi.root);
break;
}
free(dev);
}
static int get_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve SMART log for the given device "
"(or optionally a namespace) in either decoded format "
"(default) or binary.";
_cleanup_free_ struct nvme_smart_log *smart_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
const char *namespace = "(optional) desired namespace";
nvme_print_flags_t flags;
int err = -1;
struct config {
__u32 namespace_id;
bool raw_binary;
bool human_readable;
};
struct config cfg = {
.namespace_id = NVME_NSID_ALL,
.raw_binary = false,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_output),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_info));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
smart_log = nvme_alloc(sizeof(*smart_log));
if (!smart_log)
return -ENOMEM;
err = nvme_cli_get_log_smart(dev, cfg.namespace_id, false,
smart_log);
if (!err)
nvme_show_smart_log(smart_log, cfg.namespace_id,
dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("smart log: %s", nvme_strerror(errno));
return err;
}
static int get_ana_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve ANA log for the given device in "
"decoded format (default), json or binary.";
const char *groups = "Return ANA groups only.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_free_ struct nvme_ana_log *ana_log = NULL;
size_t max_ana_log_len;
__u32 ana_log_len;
nvme_print_flags_t flags;
int err = -1;
struct config {
bool groups;
};
struct config cfg = {
.groups = false,
};
NVME_ARGS(opts,
OPT_FLAG("groups", 'g', &cfg.groups, groups));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err) {
nvme_show_error("ERROR : nvme_identify_ctrl() failed: %s",
nvme_strerror(errno));
return err;
}
max_ana_log_len = nvme_get_ana_log_len_from_id_ctrl(ctrl, cfg.groups);
ana_log_len = max_ana_log_len;
if (ana_log_len < max_ana_log_len) {
nvme_show_error("ANA log length %zu too large", max_ana_log_len);
return -ENOMEM;
}
ana_log = nvme_alloc(ana_log_len);
if (!ana_log)
return -ENOMEM;
err = nvme_cli_get_ana_log_atomic(dev, cfg.groups, true, 10,
ana_log, &ana_log_len);
if (!err)
nvme_show_ana_log(ana_log, dev->name, ana_log_len, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("ana-log: %s", nvme_strerror(errno));
return err;
}
static int parse_telemetry_da(struct nvme_dev *dev,
enum nvme_telemetry_da da,
struct nvme_telemetry_log *telem,
size_t *size,
bool da4_support)
{
size_t dalb, da1lb = le16_to_cpu(telem->dalb1), da2lb = le16_to_cpu(telem->dalb2),
da3lb = le16_to_cpu(telem->dalb3), da4lb = le32_to_cpu(telem->dalb4);
switch (da) {
case NVME_TELEMETRY_DA_CTRL_DETERMINE:
if (da4_support)
dalb = da4lb;
else
dalb = da3lb;
break;
case NVME_TELEMETRY_DA_1:
dalb = da1lb;
break;
case NVME_TELEMETRY_DA_2:
dalb = da2lb;
break;
case NVME_TELEMETRY_DA_3:
/* dalb3 >= dalb2 >= dalb1 */
dalb = da3lb;
break;
case NVME_TELEMETRY_DA_4:
if (da4_support) {
dalb = da4lb;
} else {
nvme_show_error(
"Data area 4 unsupported, bit 6 of Log Page Attributes not set");
return -EINVAL;
}
break;
default:
nvme_show_error("Invalid data area parameter - %d", da);
return -EINVAL;
}
if (dalb == 0) {
nvme_show_error("ERROR: No telemetry data block");
return -ENOENT;
}
*size = (dalb + 1) * NVME_LOG_TELEM_BLOCK_SIZE;
return 0;
}
static int get_log_telemetry_ctrl(struct nvme_dev *dev, bool rae, size_t size,
struct nvme_telemetry_log **buf)
{
struct nvme_telemetry_log *log;
int err;
log = nvme_alloc(size);
if (!log)
return -errno;
err = nvme_cli_get_log_telemetry_ctrl(dev, rae, 0, size, log);
if (err) {
free(log);
if (errno)
return -errno;
else
return err;
}
*buf = log;
return 0;
}
static int get_log_telemetry_host(struct nvme_dev *dev, size_t size,
struct nvme_telemetry_log **buf)
{
struct nvme_telemetry_log *log;
int err;
log = nvme_alloc(size);
if (!log)
return -errno;
err = nvme_cli_get_log_telemetry_host(dev, 0, size, log);
if (err) {
free(log);
if (errno)
return -errno;
else
return err;
}
*buf = log;
return 0;
}
static int __create_telemetry_log_host(struct nvme_dev *dev,
enum nvme_telemetry_da da,
size_t *size,
struct nvme_telemetry_log **buf,
bool da4_support)
{
_cleanup_free_ struct nvme_telemetry_log *log = NULL;
int err;
log = nvme_alloc(sizeof(*log));
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_create_telemetry_host_mcda(dev, da, log);
if (err) {
if (errno)
return -errno;
else
return err;
}
err = parse_telemetry_da(dev, da, log, size, da4_support);
if (err)
return err;
return get_log_telemetry_host(dev, *size, buf);
}
static int __get_telemetry_log_ctrl(struct nvme_dev *dev,
bool rae,
enum nvme_telemetry_da da,
size_t *size,
struct nvme_telemetry_log **buf,
bool da4_support)
{
struct nvme_telemetry_log *log;
int err;
log = nvme_alloc(NVME_LOG_TELEM_BLOCK_SIZE);
if (!log)
return -errno;
/*
* set rae = true so it won't clear the current telemetry log in
* controller
*/
err = nvme_cli_get_log_telemetry_ctrl(dev, true, 0,
NVME_LOG_TELEM_BLOCK_SIZE,
log);
if (err)
goto free;
if (!log->ctrlavail) {
if (!rae) {
err = nvme_cli_get_log_telemetry_ctrl(dev, rae, 0,
NVME_LOG_TELEM_BLOCK_SIZE,
log);
goto free;
}
*size = NVME_LOG_TELEM_BLOCK_SIZE;
*buf = log;
printf("Warning: Telemetry Controller-Initiated Data Not Available.\n");
return 0;
}
err = parse_telemetry_da(dev, da, log, size, da4_support);
if (err)
goto free;
return get_log_telemetry_ctrl(dev, rae, *size, buf);
free:
free(log);
return err;
}
static int __get_telemetry_log_host(struct nvme_dev *dev,
enum nvme_telemetry_da da,
size_t *size,
struct nvme_telemetry_log **buf,
bool da4_support)
{
_cleanup_free_ struct nvme_telemetry_log *log = NULL;
int err;
log = nvme_alloc(sizeof(*log));
if (!log)
return -errno;
err = nvme_cli_get_log_telemetry_host(dev, 0,
NVME_LOG_TELEM_BLOCK_SIZE,
log);
if (err)
return err;
err = parse_telemetry_da(dev, da, log, size, da4_support);
if (err)
return err;
return get_log_telemetry_host(dev, *size, buf);
}
static int get_telemetry_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve telemetry log and write to binary file";
const char *fname = "File name to save raw binary, includes header";
const char *hgen = "Have the host tell the controller to generate the report";
const char *cgen = "Gather report generated by the controller.";
const char *dgen = "Pick which telemetry data area to report. Default is 3 to fetch areas 1-3. Valid options are 1, 2, 3, 4.";
const char *mcda = "Host-init Maximum Created Data Area. Valid options are 0 ~ 4 "
"If given, This option will override dgen. 0 : controller determines data area";
_cleanup_free_ struct nvme_telemetry_log *log = NULL;
_cleanup_free_ struct nvme_id_ctrl *id_ctrl = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_fd_ int output = -1;
int err = 0;
size_t total_size = 0;
__u8 *data_ptr = NULL;
int data_written = 0, data_remaining = 0;
nvme_print_flags_t flags;
bool da4_support = false,
host_behavior_changed = false;
struct config {
char *file_name;
__u32 host_gen;
bool ctrl_init;
int data_area;
bool rae;
__u8 mcda;
};
struct config cfg = {
.file_name = NULL,
.host_gen = 1,
.ctrl_init = false,
.data_area = 3,
.rae = false,
.mcda = 0xff,
};
NVME_ARGS(opts,
OPT_FILE("output-file", 'O', &cfg.file_name, fname),
OPT_UINT("host-generate", 'g', &cfg.host_gen, hgen),
OPT_FLAG("controller-init", 'c', &cfg.ctrl_init, cgen),
OPT_UINT("data-area", 'd', &cfg.data_area, dgen),
OPT_FLAG("rae", 'r', &cfg.rae, rae),
OPT_BYTE("mcda", 'm', &cfg.mcda, mcda));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.file_name) {
nvme_show_error("Please provide an output file!");
return -EINVAL;
}
cfg.host_gen = !!cfg.host_gen;
if (cfg.mcda != 0xff) {
if (cfg.ctrl_init || !cfg.host_gen) {
nvme_show_error("mcda allowed for Host-init Creation!");
return -EINVAL;
}
cfg.data_area = cfg.mcda;
}
if (cfg.data_area == 4) {
id_ctrl = nvme_alloc(sizeof(*id_ctrl));
if (!id_ctrl)
return -ENOMEM;
if (nvme_cli_identify_ctrl(dev, id_ctrl)) {
perror("identify-ctrl");
return -errno;
}
da4_support = id_ctrl->lpa & 0x40;
if (!da4_support) {
fprintf(stderr, "%s: Telemetry data area 4 not supported by device\n",
__func__);
return -EINVAL;
}
err = nvme_set_etdas(dev_fd(dev), &host_behavior_changed);
if (err) {
fprintf(stderr, "%s: Failed to set ETDAS bit\n", __func__);
return err;
}
}
output = open(cfg.file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (output < 0) {
nvme_show_error("Failed to open output file %s: %s!",
cfg.file_name, strerror(errno));
return output;
}
log = nvme_alloc(sizeof(*log));
if (!log)
return -ENOMEM;
if (cfg.ctrl_init)
err = __get_telemetry_log_ctrl(dev, cfg.rae, cfg.data_area,
&total_size, &log, da4_support);
else if (cfg.host_gen)
err = __create_telemetry_log_host(dev, cfg.data_area,
&total_size, &log, da4_support);
else
err = __get_telemetry_log_host(dev, cfg.data_area,
&total_size, &log, da4_support);
if (err < 0) {
nvme_show_error("get-telemetry-log: %s", nvme_strerror(errno));
return err;
} else if (err > 0) {
nvme_show_status(err);
fprintf(stderr, "Failed to acquire telemetry log %d!\n", err);
return err;
}
data_written = 0;
data_remaining = total_size;
data_ptr = (__u8 *)log;
while (data_remaining) {
data_written = write(output, data_ptr, data_remaining);
if (data_written < 0) {
err = -errno;
nvme_show_error("ERROR: %s: : write failed with error : %s",
__func__, strerror(errno));
break;
} else if (data_written <= data_remaining) {
data_remaining -= data_written;
data_ptr += data_written;
} else {
/* Unexpected overwrite */
fprintf(stderr, "Failure: Unexpected telemetry log overwrite - data_remaining = 0x%x, data_written = 0x%x\n",
data_remaining, data_written);
err = -1;
break;
}
}
if (fsync(output) < 0) {
nvme_show_error("ERROR : %s: : fsync : %s", __func__, strerror(errno));
return -1;
}
if (host_behavior_changed) {
host_behavior_changed = false;
err = nvme_clear_etdas(dev_fd(dev), &host_behavior_changed);
if (err) {
fprintf(stderr, "%s: Failed to clear ETDAS bit\n", __func__);
return err;
}
}
return err;
}
static int get_endurance_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieves endurance groups log page and prints the log.";
const char *group_id = "The endurance group identifier";
_cleanup_free_ struct nvme_endurance_group_log *endurance_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 group_id;
};
struct config cfg = {
.group_id = 0,
};
NVME_ARGS(opts,
OPT_SHRT("group-id", 'g', &cfg.group_id, group_id));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
endurance_log = nvme_alloc(sizeof(*endurance_log));
if (!endurance_log)
return -ENOMEM;
err = nvme_cli_get_log_endurance_group(dev, cfg.group_id,
endurance_log);
if (!err)
nvme_show_endurance_log(endurance_log, cfg.group_id,
dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("endurance log: %s", nvme_strerror(errno));
return err;
}
static int collect_effects_log(struct nvme_dev *dev, enum nvme_csi csi,
struct list_head *list, int flags)
{
nvme_effects_log_node_t *node;
int err;
node = nvme_alloc(sizeof(*node));
if (!node)
return -ENOMEM;
node->csi = csi;
err = nvme_cli_get_log_cmd_effects(dev, csi, &node->effects);
if (err) {
free(node);
return err;
}
list_add(list, &node->node);
return 0;
}
static int get_effects_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve command effects log page and print the table.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct list_head log_pages;
nvme_effects_log_node_t *node;
void *bar = NULL;
int err = -1;
nvme_print_flags_t flags;
struct config {
bool human_readable;
bool raw_binary;
int csi;
};
struct config cfg = {
.human_readable = false,
.raw_binary = false,
.csi = -1,
};
NVME_ARGS(opts,
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_log),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_log),
OPT_INT("csi", 'c', &cfg.csi, csi));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
list_head_init(&log_pages);
if (cfg.csi < 0) {
__u64 cap;
if (is_blkdev(dev)) {
nvme_show_error("Block device isn't allowed without csi");
return -EINVAL;
}
bar = mmap_registers(dev, false);
if (bar) {
cap = mmio_read64(bar + NVME_REG_CAP);
munmap(bar, getpagesize());
} else {
struct nvme_get_property_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.offset = NVME_REG_CAP,
.value = &cap,
.timeout = nvme_cfg.timeout,
};
err = nvme_get_property(&args);
if (err)
goto cleanup_list;
}
if (NVME_CAP_CSS(cap) & NVME_CAP_CSS_NVM)
err = collect_effects_log(dev, NVME_CSI_NVM,
&log_pages, flags);
if (!err && (NVME_CAP_CSS(cap) & NVME_CAP_CSS_CSI))
err = collect_effects_log(dev, NVME_CSI_ZNS,
&log_pages, flags);
} else {
err = collect_effects_log(dev, cfg.csi, &log_pages, flags);
}
if (!err)
nvme_print_effects_log_pages(&log_pages, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("effects log page");
cleanup_list:
while ((node = list_pop(&log_pages, nvme_effects_log_node_t, node)))
free(node);
return err;
}
static int get_supported_log_pages(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve supported logs and print the table.";
_cleanup_free_ struct nvme_supported_log_pages *supports = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
supports = nvme_alloc(sizeof(*supports));
if (!supports)
return -ENOMEM;
err = nvme_cli_get_log_supported_log_pages(dev, false, supports);
if (!err)
nvme_show_supported_log(supports, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("supported log pages: %s", nvme_strerror(errno));
return err;
}
static int get_error_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve specified number of "
"error log entries from a given device "
"in either decoded format (default) or binary.";
const char *log_entries = "number of entries to retrieve";
const char *raw = "dump in binary format";
_cleanup_free_ struct nvme_error_log_page *err_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct nvme_id_ctrl ctrl = { 0 };
nvme_print_flags_t flags;
int err = -1;
struct config {
__u32 log_entries;
bool raw_binary;
};
struct config cfg = {
.log_entries = 64,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("log-entries", 'e', &cfg.log_entries, log_entries),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (!cfg.log_entries) {
nvme_show_error("non-zero log-entries is required param");
return -1;
}
err = nvme_cli_identify_ctrl(dev, &ctrl);
if (err < 0) {
nvme_show_perror("identify controller");
return err;
} else if (err) {
nvme_show_error("could not identify controller");
return err;
}
cfg.log_entries = min(cfg.log_entries, ctrl.elpe + 1);
err_log = nvme_alloc(cfg.log_entries * sizeof(struct nvme_error_log_page));
if (!err_log)
return -ENOMEM;
err = nvme_cli_get_log_error(dev, cfg.log_entries, false, err_log);
if (!err)
nvme_show_error_log(err_log, cfg.log_entries,
dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("error log");
return err;
}
static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve the firmware log for the "
"specified device in either decoded format (default) or binary.";
_cleanup_free_ struct nvme_firmware_slot *fw_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
bool raw_binary;
};
struct config cfg = {
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
fw_log = nvme_alloc(sizeof(*fw_log));
if (!fw_log)
return -ENOMEM;
err = nvme_cli_get_log_fw_slot(dev, false, fw_log);
if (!err)
nvme_show_fw_log(fw_log, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("fw log: %s", nvme_strerror(errno));
return err;
}
static int get_changed_ns_list_log(int argc, char **argv, bool alloc)
{
_cleanup_free_ char *desc = NULL;
_cleanup_free_ struct nvme_ns_list *changed_ns_list_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
bool raw_binary;
};
struct config cfg = {
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_output));
if (asprintf(&desc, "Retrieve Changed %s Namespaces log for the given device %s",
alloc ? "Allocated" : "Attached",
"in either decoded format (default) or binary.") < 0)
desc = NULL;
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
changed_ns_list_log = nvme_alloc(sizeof(*changed_ns_list_log));
if (!changed_ns_list_log)
return -ENOMEM;
if (alloc)
err = nvme_cli_get_log_changed_alloc_ns_list(dev, true,
sizeof(*changed_ns_list_log),
changed_ns_list_log);
else
err = nvme_cli_get_log_changed_ns_list(dev, true,
changed_ns_list_log);
if (!err)
nvme_show_changed_ns_list_log(changed_ns_list_log, dev->name, flags, alloc);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("changed %s ns list log: %s", alloc ? "allocated" : "attached",
nvme_strerror(errno));
return err;
}
static int get_changed_attach_ns_list_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
return get_changed_ns_list_log(argc, argv, false);
}
static int get_changed_alloc_ns_list_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
return get_changed_ns_list_log(argc, argv, true);
}
static int get_pred_lat_per_nvmset_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Predictable latency per nvm set log "
"page and prints it for the given device in either decoded "
"format(default),json or binary.";
const char *nvmset_id = "NVM Set Identifier";
_cleanup_free_ struct nvme_nvmset_predictable_lat_log *plpns_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 nvmset_id;
bool raw_binary;
};
struct config cfg = {
.nvmset_id = 1,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_SHRT("nvmset-id", 'i', &cfg.nvmset_id, nvmset_id),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
plpns_log = nvme_alloc(sizeof(*plpns_log));
if (!plpns_log)
return -ENOMEM;
err = nvme_cli_get_log_predictable_lat_nvmset(dev, cfg.nvmset_id,
plpns_log);
if (!err)
nvme_show_predictable_latency_per_nvmset(plpns_log, cfg.nvmset_id, dev->name,
flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("predictable latency per nvm set: %s", nvme_strerror(errno));
return err;
}
static int get_pred_lat_event_agg_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Predictable Latency Event "
"Aggregate Log page and prints it, for the given "
"device in either decoded format(default), json or binary.";
const char *log_entries = "Number of pending NVM Set log Entries list";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_free_ void *pea_log = NULL;
nvme_print_flags_t flags;
__u32 log_size;
int err;
struct config {
__u64 log_entries;
bool rae;
bool raw_binary;
};
struct config cfg = {
.log_entries = 2044,
.rae = false,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("log-entries", 'e', &cfg.log_entries, log_entries),
OPT_FLAG("rae", 'r', &cfg.rae, rae),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (!cfg.log_entries) {
nvme_show_error("non-zero log-entries is required param");
return -EINVAL;
}
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err < 0) {
nvme_show_error("identify controller: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_status(err);
return err;
}
cfg.log_entries = min(cfg.log_entries, le32_to_cpu(ctrl->nsetidmax));
log_size = sizeof(__u64) + cfg.log_entries * sizeof(__u16);
pea_log = nvme_alloc(log_size);
if (!pea_log)
return -ENOMEM;
err = nvme_cli_get_log_predictable_lat_event(dev, cfg.rae, 0,
log_size, pea_log);
if (!err)
nvme_show_predictable_latency_event_agg_log(pea_log, cfg.log_entries, log_size,
dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("predictable latency event aggregate log page: %s",
nvme_strerror(errno));
return err;
}
static int get_persistent_event_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Persistent Event log info for "
"the given device in either decoded format(default), json or binary.";
const char *action = "action the controller shall take during "
"processing this persistent log page command.";
const char *log_len = "number of bytes to retrieve";
_cleanup_free_ struct nvme_persistent_event_log *pevent = NULL;
struct nvme_persistent_event_log *pevent_collected = NULL;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
void *pevent_log_info;
int err;
struct config {
__u8 action;
__u32 log_len;
bool raw_binary;
};
struct config cfg = {
.action = 0xff,
.log_len = 0,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_BYTE("action", 'a', &cfg.action, action),
OPT_UINT("log_len", 'l', &cfg.log_len, log_len),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
pevent = nvme_alloc(sizeof(*pevent));
if (!pevent)
return -ENOMEM;
err = nvme_cli_get_log_persistent_event(dev, cfg.action,
sizeof(*pevent), pevent);
if (err < 0) {
nvme_show_error("persistent event log: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_status(err);
return err;
}
if (cfg.action == NVME_PEVENT_LOG_RELEASE_CTX) {
printf("Releasing Persistent Event Log Context\n");
return 0;
}
if (!cfg.log_len && cfg.action != NVME_PEVENT_LOG_EST_CTX_AND_READ) {
cfg.log_len = le64_to_cpu(pevent->tll);
} else if (!cfg.log_len && cfg.action == NVME_PEVENT_LOG_EST_CTX_AND_READ) {
printf("Establishing Persistent Event Log Context\n");
return 0;
}
/*
* if header already read with context establish action 0x1,
* action shall not be 0x1 again in the subsequent request,
* until the current context is released by issuing action
* with 0x2, otherwise throws command sequence error, make
* it as zero to read the log page
*/
if (cfg.action == NVME_PEVENT_LOG_EST_CTX_AND_READ)
cfg.action = NVME_PEVENT_LOG_READ;
pevent_log_info = nvme_alloc_huge(cfg.log_len, &mh);
if (!pevent_log_info) {
nvme_show_error("failed to allocate huge memory");
return -ENOMEM;
}
err = nvme_cli_get_log_persistent_event(dev, cfg.action,
cfg.log_len, pevent_log_info);
if (!err) {
err = nvme_cli_get_log_persistent_event(dev, cfg.action,
sizeof(*pevent),
pevent);
if (err < 0) {
nvme_show_error("persistent event log: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_status(err);
return err;
}
pevent_collected = pevent_log_info;
if (pevent_collected->gen_number != pevent->gen_number) {
printf("Collected Persistent Event Log may be invalid,\n"
"Re-read the log is required\n");
return -EINVAL;
}
nvme_show_persistent_event_log(pevent_log_info, cfg.action,
cfg.log_len, dev->name, flags);
} else if (err > 0) {
nvme_show_status(err);
} else {
nvme_show_error("persistent event log: %s", nvme_strerror(errno));
}
return err;
}
static int get_endurance_event_agg_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Retrieve Predictable Latency "
"Event Aggregate page and prints it, for the given "
"device in either decoded format(default), json or binary.";
const char *log_entries = "Number of pending Endurance Group Event log Entries list";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_free_ void *endurance_log = NULL;
nvme_print_flags_t flags;
__u32 log_size;
int err;
struct config {
__u64 log_entries;
bool rae;
bool raw_binary;
};
struct config cfg = {
.log_entries = 2044,
.rae = false,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("log-entries", 'e', &cfg.log_entries, log_entries),
OPT_FLAG("rae", 'r', &cfg.rae, rae),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (!cfg.log_entries) {
nvme_show_error("non-zero log-entries is required param");
return -EINVAL;
}
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err < 0) {
nvme_show_error("identify controller: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_error("could not identify controller");
return -ENODEV;
}
cfg.log_entries = min(cfg.log_entries, le16_to_cpu(ctrl->endgidmax));
log_size = sizeof(__u64) + cfg.log_entries * sizeof(__u16);
endurance_log = nvme_alloc(log_size);
if (!endurance_log)
return -ENOMEM;
err = nvme_cli_get_log_endurance_grp_evt(dev, cfg.rae, 0, log_size,
endurance_log);
if (!err)
nvme_show_endurance_group_event_agg_log(endurance_log, cfg.log_entries, log_size,
dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("endurance group event aggregate log page: %s",
nvme_strerror(errno));
return err;
}
static int get_lba_status_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Get LBA Status Info Log and prints it, "
"for the given device in either decoded format(default),json or binary.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *lba_status = NULL;
nvme_print_flags_t flags;
__u32 lslplen;
int err;
struct config {
bool rae;
};
struct config cfg = {
.rae = false,
};
NVME_ARGS(opts,
OPT_FLAG("rae", 'r', &cfg.rae, rae));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = nvme_cli_get_log_lba_status(dev, true, 0, sizeof(__u32),
&lslplen);
if (err < 0) {
nvme_show_error("lba status log page: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_status(err);
return err;
}
lba_status = nvme_alloc(lslplen);
if (!lba_status)
return -ENOMEM;
err = nvme_cli_get_log_lba_status(dev, cfg.rae, 0, lslplen, lba_status);
if (!err)
nvme_show_lba_status_log(lba_status, lslplen, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("lba status log page: %s", nvme_strerror(errno));
return err;
}
static int get_resv_notif_log(int argc, char **argv,
struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Reservation Notification "
"log page and prints it, for the given "
"device in either decoded format(default), json or binary.";
_cleanup_free_ struct nvme_resv_notification_log *resv = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
resv = nvme_alloc(sizeof(*resv));
if (!resv)
return -ENOMEM;
err = nvme_cli_get_log_reservation(dev, false, resv);
if (!err)
nvme_show_resv_notif_log(resv, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("resv notifi log: %s", nvme_strerror(errno));
return err;
}
static int get_boot_part_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Boot Partition "
"log page and prints it, for the given "
"device in either decoded format(default), json or binary.";
const char *fname = "boot partition data output file name";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_boot_partition *boot = NULL;
_cleanup_free_ __u8 *bp_log = NULL;
nvme_print_flags_t flags;
int err = -1;
_cleanup_fd_ int output = -1;
__u32 bpsz = 0;
struct config {
__u8 lsp;
char *file_name;
};
struct config cfg = {
.lsp = 0,
.file_name = NULL,
};
NVME_ARGS(opts,
OPT_BYTE("lsp", 's', &cfg.lsp, lsp),
OPT_FILE("output-file", 'f', &cfg.file_name, fname));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.file_name) {
nvme_show_error("Please provide an output file!");
return -1;
}
if (cfg.lsp > 127) {
nvme_show_error("invalid lsp param: %u", cfg.lsp);
return -1;
}
output = open(cfg.file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (output < 0) {
nvme_show_error("Failed to open output file %s: %s!",
cfg.file_name, strerror(errno));
return output;
}
boot = nvme_alloc(sizeof(*boot));
if (!boot)
return -ENOMEM;
err = nvme_cli_get_log_boot_partition(dev, false, cfg.lsp,
sizeof(*boot), boot);
if (err < 0) {
nvme_show_error("boot partition log: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_status(err);
return err;
}
bpsz = (boot->bpinfo & 0x7fff) * 128 * 1024;
bp_log = nvme_alloc(sizeof(*boot) + bpsz);
if (!bp_log)
return -ENOMEM;
err = nvme_cli_get_log_boot_partition(dev, false, cfg.lsp,
sizeof(*boot) + bpsz,
(struct nvme_boot_partition *)bp_log);
if (!err)
nvme_show_boot_part_log(&bp_log, dev->name, sizeof(*boot) + bpsz, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("boot partition log: %s", nvme_strerror(errno));
err = write(output, (void *) bp_log + sizeof(*boot), bpsz);
if (err != bpsz)
fprintf(stderr, "Failed to flush all data to file!\n");
else
printf("Data flushed into file %s\n", cfg.file_name);
err = 0;
return err;
}
static int get_phy_rx_eom_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve Physical Interface Receiver Eye Opening "
"Measurement log for the given device in decoded format "
"(default), json or binary.";
const char *controller = "Target Controller ID.";
_cleanup_free_ struct nvme_phy_rx_eom_log *phy_rx_eom_log = NULL;
size_t phy_rx_eom_log_len;
nvme_print_flags_t flags;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err = -1;
__u8 lsp_tmp;
struct config {
__u8 lsp;
__u16 controller;
};
struct config cfg = {
.lsp = 0,
.controller = NVME_LOG_LSI_NONE,
};
NVME_ARGS(opts,
OPT_BYTE("lsp", 's', &cfg.lsp, lsp),
OPT_SHRT("controller", 'c', &cfg.controller, controller));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.lsp > 127) {
nvme_show_error("invalid lsp param: %u", cfg.lsp);
return -1;
} else if ((cfg.lsp & 3) == 3) {
nvme_show_error("invalid measurement quality: %u", cfg.lsp & 3);
return -1;
} else if ((cfg.lsp & 12) == 12) {
nvme_show_error("invalid action: %u", cfg.lsp & 12);
return -1;
}
/* Fetching header to calculate total log length */
phy_rx_eom_log_len = sizeof(struct nvme_phy_rx_eom_log);
phy_rx_eom_log = nvme_alloc(phy_rx_eom_log_len);
if (!phy_rx_eom_log)
return -ENOMEM;
/* Just read measurement, take given action when fetching full log */
lsp_tmp = cfg.lsp & 0xf3;
err = nvme_cli_get_log_phy_rx_eom(dev, lsp_tmp, cfg.controller, phy_rx_eom_log_len,
phy_rx_eom_log);
if (err) {
if (err > 0)
nvme_show_status(err);
else
nvme_show_error("phy-rx-eom-log: %s", nvme_strerror(errno));
return err;
}
if (phy_rx_eom_log->eomip == NVME_PHY_RX_EOM_COMPLETED)
phy_rx_eom_log_len = le16_to_cpu(phy_rx_eom_log->hsize) +
le32_to_cpu(phy_rx_eom_log->dsize) *
le16_to_cpu(phy_rx_eom_log->nd);
else
phy_rx_eom_log_len = le16_to_cpu(phy_rx_eom_log->hsize);
phy_rx_eom_log = nvme_realloc(phy_rx_eom_log, phy_rx_eom_log_len);
if (!phy_rx_eom_log)
return -ENOMEM;
err = nvme_cli_get_log_phy_rx_eom(dev, cfg.lsp, cfg.controller, phy_rx_eom_log_len,
phy_rx_eom_log);
if (!err)
nvme_show_phy_rx_eom_log(phy_rx_eom_log, cfg.controller, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("phy-rx-eom-log: %s", nvme_strerror(errno));
return err;
}
static int get_media_unit_stat_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve the configuration and wear of media units and print it";
_cleanup_free_ struct nvme_media_unit_stat_log *mus = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
__u16 domainid;
bool raw_binary;
};
struct config cfg = {
.domainid = 0,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("domain-id", 'd', &cfg.domainid, domainid),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
mus = nvme_alloc(sizeof(*mus));
if (!mus)
return -ENOMEM;
err = nvme_cli_get_log_media_unit_stat(dev, cfg.domainid, mus);
if (!err)
nvme_show_media_unit_stat_log(mus, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("media unit status log: %s", nvme_strerror(errno));
return err;
}
static int get_supp_cap_config_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve the list of Supported Capacity Configuration Descriptors";
_cleanup_free_ struct nvme_supported_cap_config_list_log *cap_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
__u16 domainid;
bool raw_binary;
};
struct config cfg = {
.domainid = 0,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("domain-id", 'd', &cfg.domainid, domainid),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_use));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
cap_log = nvme_alloc(sizeof(*cap_log));
if (!cap_log)
return -ENOMEM;
err = nvme_cli_get_log_support_cap_config_list(dev, cfg.domainid,
cap_log);
if (!err)
nvme_show_supported_cap_config_log(cap_log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("supported capacity configuration list log");
return err;
}
static int io_mgmt_send(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "I/O Management Send";
const char *data = "optional file for data (default stdin)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *buf = NULL;
int err = -1;
_cleanup_fd_ int dfd = STDIN_FILENO;
struct config {
__u16 mos;
__u8 mo;
__u32 namespace_id;
char *file;
__u32 data_len;
};
struct config cfg = {
.mos = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SHRT("mos", 's', &cfg.mos, mos),
OPT_BYTE("mo", 'm', &cfg.mo, mo),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_perror("get-namespace-id");
return err;
}
}
if (cfg.data_len) {
buf = nvme_alloc(cfg.data_len);
if (!buf)
return -ENOMEM;
}
if (cfg.file) {
dfd = open(cfg.file, O_RDONLY);
if (dfd < 0) {
nvme_show_perror(cfg.file);
return -errno;
}
}
err = read(dfd, buf, cfg.data_len);
if (err < 0) {
nvme_show_perror("read");
return err;
}
struct nvme_io_mgmt_send_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.mos = cfg.mos,
.mo = cfg.mo,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
};
err = nvme_io_mgmt_send(&args);
if (!err)
printf("io-mgmt-send: Success, mos:%u mo:%u nsid:%d\n",
cfg.mos, cfg.mo, cfg.namespace_id);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("io-mgmt-send");
return err;
}
static int io_mgmt_recv(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "I/O Management Receive";
const char *data = "optional file for data (default stdout)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *buf = NULL;
int err = -1;
_cleanup_fd_ int dfd = -1;
struct config {
__u16 mos;
__u8 mo;
__u32 namespace_id;
char *file;
__u32 data_len;
};
struct config cfg = {
.mos = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SHRT("mos", 's', &cfg.mos, mos),
OPT_BYTE("mo", 'm', &cfg.mo, mo),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_perror("get-namespace-id");
return err;
}
}
if (cfg.data_len) {
buf = nvme_alloc(cfg.data_len);
if (!buf)
return -ENOMEM;
}
struct nvme_io_mgmt_recv_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.mos = cfg.mos,
.mo = cfg.mo,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
};
err = nvme_io_mgmt_recv(&args);
if (!err) {
printf("io-mgmt-recv: Success, mos:%u mo:%u nsid:%d\n",
cfg.mos, cfg.mo, cfg.namespace_id);
if (cfg.file) {
dfd = open(cfg.file, O_WRONLY | O_CREAT, 0644);
if (dfd < 0) {
nvme_show_perror(cfg.file);
return -errno;
}
err = write(dfd, buf, cfg.data_len);
if (err < 0) {
nvme_show_perror("write");
return -errno;
}
} else {
d((unsigned char *)buf, cfg.data_len, 16, 1);
}
} else if (err > 0) {
nvme_show_status(err);
} else {
nvme_show_perror("io-mgmt-recv");
}
return err;
}
static int get_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve desired number of bytes "
"from a given log on a specified device in either "
"hex-dump (default) or binary format";
const char *log_id = "identifier of log to retrieve";
const char *log_len = "how many bytes to retrieve";
const char *aen = "result of the aen, use to override log id";
const char *lpo = "log page offset specifies the location within a log page from where to start returning data";
const char *lsi = "log specific identifier specifies an identifier that is required for a particular log page";
const char *raw = "output in raw format";
const char *offset_type = "offset type";
const char *xfer_len = "read chunk size (default 4k)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ unsigned char *log = NULL;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
__u8 log_id;
__u32 log_len;
__u32 aen;
__u64 lpo;
__u8 lsp;
__u16 lsi;
bool rae;
__u8 uuid_index;
bool raw_binary;
__u8 csi;
bool ot;
__u32 xfer_len;
};
struct config cfg = {
.namespace_id = NVME_NSID_ALL,
.log_id = 0xff,
.log_len = 0,
.aen = 0,
.lpo = NVME_LOG_LPO_NONE,
.lsp = NVME_LOG_LSP_NONE,
.lsi = NVME_LOG_LSI_NONE,
.rae = false,
.uuid_index = NVME_UUID_NONE,
.raw_binary = false,
.csi = NVME_CSI_NVM,
.ot = false,
.xfer_len = 4096,
};
OPT_VALS(log_name) = {
VAL_BYTE("supported-log-pages", NVME_LOG_LID_SUPPORTED_LOG_PAGES),
VAL_BYTE("error", NVME_LOG_LID_ERROR),
VAL_BYTE("smart", NVME_LOG_LID_SMART),
VAL_BYTE("fw-slot", NVME_LOG_LID_FW_SLOT),
VAL_BYTE("changed-ns", NVME_LOG_LID_CHANGED_NS),
VAL_BYTE("cmd-effects", NVME_LOG_LID_CMD_EFFECTS),
VAL_BYTE("device-self-test", NVME_LOG_LID_DEVICE_SELF_TEST),
VAL_BYTE("telemetry-host", NVME_LOG_LID_TELEMETRY_HOST),
VAL_BYTE("telemetry-ctrl", NVME_LOG_LID_TELEMETRY_CTRL),
VAL_BYTE("endurance-group", NVME_LOG_LID_ENDURANCE_GROUP),
VAL_BYTE("predictable-lat-nvmset", NVME_LOG_LID_PREDICTABLE_LAT_NVMSET),
VAL_BYTE("predictable-lat-agg", NVME_LOG_LID_PREDICTABLE_LAT_AGG),
VAL_BYTE("ana", NVME_LOG_LID_ANA),
VAL_BYTE("persistent-event", NVME_LOG_LID_PERSISTENT_EVENT),
VAL_BYTE("lba-status", NVME_LOG_LID_LBA_STATUS),
VAL_BYTE("endurance-grp-evt", NVME_LOG_LID_ENDURANCE_GRP_EVT),
VAL_BYTE("media-unit-status", NVME_LOG_LID_MEDIA_UNIT_STATUS),
VAL_BYTE("supported-cap-config-list", NVME_LOG_LID_SUPPORTED_CAP_CONFIG_LIST),
VAL_BYTE("fid-supported-effects", NVME_LOG_LID_FID_SUPPORTED_EFFECTS),
VAL_BYTE("mi-cmd-supported-effects", NVME_LOG_LID_MI_CMD_SUPPORTED_EFFECTS),
VAL_BYTE("cmd-and-feat-lockdown", NVME_LOG_LID_CMD_AND_FEAT_LOCKDOWN),
VAL_BYTE("boot-partition", NVME_LOG_LID_BOOT_PARTITION),
VAL_BYTE("rotational-media-info",
NVME_LOG_LID_ROTATIONAL_MEDIA_INFO),
VAL_BYTE("dispersed-ns-participating-ns",
NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS),
VAL_BYTE("mgmt-addr-list", NVME_LOG_LID_MGMT_ADDR_LIST),
VAL_BYTE("phy-rx-eom", NVME_LOG_LID_PHY_RX_EOM),
VAL_BYTE("reachability-groups", NVME_LOG_LID_REACHABILITY_GROUPS),
VAL_BYTE("reachability-associations", NVME_LOG_LID_REACHABILITY_ASSOCIATIONS),
VAL_BYTE("changed-alloc-ns-list", NVME_LOG_LID_CHANGED_ALLOC_NS_LIST),
VAL_BYTE("fdp-configs", NVME_LOG_LID_FDP_CONFIGS),
VAL_BYTE("fdp-ruh-usage", NVME_LOG_LID_FDP_RUH_USAGE),
VAL_BYTE("fdp-stats", NVME_LOG_LID_FDP_STATS),
VAL_BYTE("fdp-events", NVME_LOG_LID_FDP_EVENTS),
VAL_BYTE("discover", NVME_LOG_LID_DISCOVER),
VAL_BYTE("host-discover", NVME_LOG_LID_HOST_DISCOVER),
VAL_BYTE("ave-discover", NVME_LOG_LID_AVE_DISCOVER),
VAL_BYTE("pull-model-ddc-req", NVME_LOG_LID_PULL_MODEL_DDC_REQ),
VAL_BYTE("reservation", NVME_LOG_LID_RESERVATION),
VAL_BYTE("sanitize", NVME_LOG_LID_SANITIZE),
VAL_BYTE("zns-changed-zones", NVME_LOG_LID_ZNS_CHANGED_ZONES),
VAL_END()
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_BYTE("log-id", 'i', &cfg.log_id, log_id, log_name),
OPT_UINT("log-len", 'l', &cfg.log_len, log_len),
OPT_UINT("aen", 'a', &cfg.aen, aen),
OPT_SUFFIX("lpo", 'L', &cfg.lpo, lpo),
OPT_BYTE("lsp", 's', &cfg.lsp, lsp),
OPT_SHRT("lsi", 'S', &cfg.lsi, lsi),
OPT_FLAG("rae", 'r', &cfg.rae, rae),
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
OPT_BYTE("csi", 'y', &cfg.csi, csi),
OPT_FLAG("ot", 'O', &cfg.ot, offset_type),
OPT_UINT("xfer-len", 'x', &cfg.xfer_len, xfer_len));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.aen) {
cfg.log_len = 4096;
cfg.log_id = (cfg.aen >> 16) & 0xff;
}
if (!cfg.log_len || cfg.log_len & 0x3) {
nvme_show_error("non-zero or non-dw alignment log-len is required param");
return -EINVAL;
}
if (cfg.lsp > 127) {
nvme_show_error("invalid lsp param");
return -EINVAL;
}
if (cfg.uuid_index > 127) {
nvme_show_error("invalid uuid index param");
return -EINVAL;
}
if (cfg.xfer_len == 0 || cfg.xfer_len % 4096) {
nvme_show_error("xfer-len argument invalid. It needs to be multiple of 4k");
return -EINVAL;
}
log = nvme_alloc(cfg.log_len);
if (!log)
return -ENOMEM;
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.lid = cfg.log_id,
.nsid = cfg.namespace_id,
.lpo = cfg.lpo,
.lsp = cfg.lsp,
.lsi = cfg.lsi,
.rae = cfg.rae,
.uuidx = cfg.uuid_index,
.csi = cfg.csi,
.ot = cfg.ot,
.len = cfg.log_len,
.log = log,
.result = NULL,
};
err = nvme_cli_get_log_page(dev, cfg.xfer_len, &args);
if (!err) {
if (!cfg.raw_binary) {
printf("Device:%s log-id:%d namespace-id:%#x\n", dev->name, cfg.log_id,
cfg.namespace_id);
d(log, cfg.log_len, 16, 1);
if (argconfig_parse_seen(opts, "verbose"))
nvme_show_log(dev->name, &args, VERBOSE);
} else {
d_raw((unsigned char *)log, cfg.log_len);
}
} else if (err > 0) {
nvme_show_status(err);
} else {
nvme_show_error("log page: %s", nvme_strerror(errno));
}
return err;
}
static int sanitize_log(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Retrieve sanitize log and show it.";
_cleanup_free_ struct nvme_sanitize_log_page *sanitize_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
bool rae;
bool human_readable;
bool raw_binary;
};
struct config cfg = {
.rae = false,
.human_readable = false,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_FLAG("rae", 'r', &cfg.rae, rae),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_log),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_log));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
sanitize_log = nvme_alloc(sizeof(*sanitize_log));
if (!sanitize_log)
return -ENOMEM;
err = nvme_cli_get_log_sanitize(dev, cfg.rae, sanitize_log);
if (!err)
nvme_show_sanitize_log(sanitize_log, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("sanitize status log: %s", nvme_strerror(errno));
return err;
}
static int get_fid_support_effects_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve FID Support and Effects log and show it.";
_cleanup_free_ struct nvme_fid_supported_effects_log *fid_support_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
bool human_readable;
};
struct config cfg = {
.human_readable = false,
};
NVME_ARGS(opts,
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_log));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
fid_support_log = nvme_alloc(sizeof(*fid_support_log));
if (!fid_support_log)
return -ENOMEM;
err = nvme_cli_get_log_fid_supported_effects(dev, false, fid_support_log);
if (!err)
nvme_show_fid_support_effects_log(fid_support_log, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("fid support effects log: %s", nvme_strerror(errno));
return err;
}
static int get_mi_cmd_support_effects_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve NVMe-MI Command Support and Effects log and show it.";
_cleanup_free_ struct nvme_mi_cmd_supported_effects_log *mi_cmd_support_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
bool human_readable;
};
struct config cfg = {
.human_readable = false,
};
NVME_ARGS(opts,
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_log));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
mi_cmd_support_log = nvme_alloc(sizeof(*mi_cmd_support_log));
if (!mi_cmd_support_log)
return -ENOMEM;
err = nvme_cli_get_log_mi_cmd_supported_effects(dev, false, mi_cmd_support_log);
if (!err)
nvme_show_mi_cmd_support_effects_log(mi_cmd_support_log, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("mi command support effects log: %s", nvme_strerror(errno));
return err;
}
static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Show controller list information for the subsystem the "
"given device is part of, or optionally controllers attached to a specific namespace.";
const char *controller = "controller to display";
_cleanup_free_ struct nvme_ctrl_list *cntlist = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 cntid;
__u32 namespace_id;
};
struct config cfg = {
.cntid = 0,
.namespace_id = NVME_NSID_NONE,
};
NVME_ARGS(opts,
OPT_SHRT("cntid", 'c', &cfg.cntid, controller),
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_optional));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0 || (flags != JSON && flags != NORMAL)) {
nvme_show_error("Invalid output format");
return err;
}
cntlist = nvme_alloc(sizeof(*cntlist));
if (!cntlist)
return -ENOMEM;
if (cfg.namespace_id == NVME_NSID_NONE)
err = nvme_cli_identify_ctrl_list(dev, cfg.cntid, cntlist);
else
err = nvme_cli_identify_nsid_ctrl_list(dev, cfg.namespace_id,
cfg.cntid, cntlist);
if (!err)
nvme_show_list_ctrl(cntlist, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("id controller list: %s", nvme_strerror(errno));
return err;
}
static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "For the specified controller handle, show the "
"namespace list in the associated NVMe subsystem, optionally starting with a given nsid.";
const char *namespace_id = "first nsid returned list should start from";
const char *csi = "I/O command set identifier";
const char *all = "show all namespaces in the subsystem, whether attached or inactive";
_cleanup_free_ struct nvme_ns_list *ns_list = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u32 namespace_id;
int csi;
bool all;
};
struct config cfg = {
.namespace_id = 1,
.csi = -1,
.all = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
OPT_INT("csi", 'y', &cfg.csi, csi),
OPT_FLAG("all", 'a', &cfg.all, all));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0 || (flags != JSON && flags != NORMAL)) {
nvme_show_error("Invalid output format");
return -EINVAL;
}
if (!cfg.namespace_id) {
nvme_show_error("invalid nsid parameter");
return -EINVAL;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
ns_list = nvme_alloc(sizeof(*ns_list));
if (!ns_list)
return -ENOMEM;
struct nvme_identify_args args = {
.args_size = sizeof(args),
.timeout = nvme_cfg.timeout,
.data = ns_list,
.nsid = cfg.namespace_id - 1.
};
if (cfg.csi < 0) {
args.cns = cfg.all ? NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST :
NVME_IDENTIFY_CNS_NS_ACTIVE_LIST;
} else {
args.cns = cfg.all ? NVME_IDENTIFY_CNS_CSI_ALLOCATED_NS_LIST :
NVME_IDENTIFY_CNS_CSI_NS_ACTIVE_LIST;
args.csi = cfg.csi;
}
err = nvme_cli_identify(dev, &args);
if (!err)
nvme_show_list_ns(ns_list, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("id namespace list: %s", nvme_strerror(errno));
return err;
}
static int id_ns_lba_format(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an Identify Namespace command to the given "
"device, returns capability field properties of the specified "
"LBA Format index in various formats.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
__u16 lba_format_index;
__u8 uuid_index;
};
struct config cfg = {
.lba_format_index = 0,
.uuid_index = NVME_UUID_NONE,
};
NVME_ARGS(opts,
OPT_UINT("lba-format-index", 'i', &cfg.lba_format_index, lba_format_index),
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_identify_ns_csi_user_data_format(dev_fd(dev),
cfg.lba_format_index,
cfg.uuid_index, NVME_CSI_NVM, ns);
if (!err)
nvme_show_id_ns(ns, 0, cfg.lba_format_index, true, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("identify namespace for specific LBA format");
return err;
}
static int id_endurance_grp_list(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Show endurance group list information for the given endurance group id";
const char *endurance_grp_id = "Endurance Group ID";
_cleanup_free_ struct nvme_id_endurance_group_list *endgrp_list = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
__u16 endgrp_id;
};
struct config cfg = {
.endgrp_id = 0,
};
NVME_ARGS(opts,
OPT_SHRT("endgrp-id", 'i', &cfg.endgrp_id, endurance_grp_id));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0 || (flags != JSON && flags != NORMAL)) {
nvme_show_error("invalid output format");
return -EINVAL;
}
endgrp_list = nvme_alloc(sizeof(*endgrp_list));
if (!endgrp_list)
return -ENOMEM;
err = nvme_identify_endurance_group_list(dev_fd(dev), cfg.endgrp_id, endgrp_list);
if (!err)
nvme_show_endurance_group_list(endgrp_list, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("Id endurance group list: %s", nvme_strerror(errno));
return err;
}
static bool is_ns_mgmt_support(struct nvme_dev *dev)
{
int err;
_cleanup_free_ struct nvme_id_ctrl *ctrl = nvme_alloc(sizeof(*ctrl));
if (ctrl)
return false;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err)
return false;
return le16_to_cpu(ctrl->oacs) & NVME_CTRL_OACS_NS_MGMT;
}
static void ns_mgmt_show_status(struct nvme_dev *dev, int err, char *cmd, __u32 nsid)
{
if (err < 0) {
nvme_show_error("%s: %s", cmd, nvme_strerror(errno));
return;
}
nvme_show_init();
if (!err) {
nvme_show_key_value(cmd, "success");
nvme_show_key_value("nsid", "%d", nsid);
} else {
nvme_show_status(err);
if (!is_ns_mgmt_support(dev))
nvme_show_error("NS management and attachment not supported");
}
nvme_show_finish();
}
static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Delete the given namespace by "
"sending a namespace management command to "
"the provided device. All controllers should be detached from "
"the namespace prior to namespace deletion. A namespace ID "
"becomes inactive when that namespace is detached or, if "
"the namespace is not already inactive, once deleted.";
const char *namespace_id = "namespace to delete";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
};
struct config cfg = {
.namespace_id = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
err = nvme_cli_ns_mgmt_delete(dev, cfg.namespace_id, nvme_cfg.timeout);
ns_mgmt_show_status(dev, err, cmd->name, cfg.namespace_id);
return err;
}
static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, struct command *cmd)
{
_cleanup_free_ struct nvme_ctrl_list *cntlist = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err, num;
__u16 list[NVME_ID_CTRL_LIST_MAX];
nvme_print_flags_t flags;
const char *namespace_id = "namespace to attach";
const char *cont = "optional comma-sep controller id list";
struct config {
__u32 namespace_id;
char *cntlist;
};
struct config cfg = {
.namespace_id = 0,
.cntlist = "",
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
OPT_LIST("controllers", 'c', &cfg.cntlist, cont));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (is_blkdev(dev)) {
nvme_show_error("%s: a block device opened (dev: %s, nsid: %d)", cmd->name,
dev->name, cfg.namespace_id);
return -EINVAL;
}
if (!cfg.namespace_id) {
nvme_show_error("%s: namespace-id parameter required", cmd->name);
return -EINVAL;
}
num = argconfig_parse_comma_sep_array_u16(cfg.cntlist,
list, ARRAY_SIZE(list));
if (num == -1) {
nvme_show_error("%s: controller id list is malformed", cmd->name);
return -EINVAL;
}
cntlist = nvme_alloc(sizeof(*cntlist));
if (!cntlist)
return -ENOMEM;
if (argconfig_parse_seen(opts, "controllers")) {
nvme_init_ctrl_list(cntlist, num, list);
} else {
struct nvme_id_ctrl ctrl = { 0 };
if (nvme_cli_identify_ctrl(dev, &ctrl)) {
perror("identify-ctrl");
return -errno;
}
cntlist->num = cpu_to_le16(1);
cntlist->identifier[0] = ctrl.cntlid;
}
if (attach)
err = nvme_cli_ns_attach_ctrls(dev, cfg.namespace_id,
cntlist);
else
err = nvme_cli_ns_detach_ctrls(dev, cfg.namespace_id,
cntlist);
ns_mgmt_show_status(dev, err, cmd->name, cfg.namespace_id);
return err;
}
static int attach_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Attach the given namespace to the "
"given controller or comma-sep list of controllers. ID of the "
"given namespace becomes active upon attachment to a "
"controller. A namespace must be attached to a controller "
"before IO commands may be directed to that namespace.";
return nvme_attach_ns(argc, argv, 1, desc, cmd);
}
static int detach_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Detach the given namespace from the "
"given controller; de-activates the given namespace's ID. A "
"namespace must be attached to a controller before IO "
"commands may be directed to that namespace.";
return nvme_attach_ns(argc, argv, 0, desc, cmd);
}
static int parse_lba_num_si(struct nvme_dev *dev, const char *opt,
const char *val, __u8 flbas, __u64 *num, __u64 align)
{
_cleanup_free_ struct nvme_ns_list *ns_list = NULL;
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
__u32 nsid = 1;
__u8 lbaf;
unsigned int remainder;
char *endptr;
int err = -EINVAL;
int lbas;
struct nvme_identify_args args = {
.args_size = sizeof(args),
.timeout = nvme_cfg.timeout,
.cns = NVME_IDENTIFY_CNS_NS_ACTIVE_LIST,
.nsid = nsid - 1.
};
if (!val)
return 0;
if (*num) {
nvme_show_error(
"Invalid specification of both %s and its SI argument, please specify only one",
opt);
return err;
}
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err) {
if (err < 0)
nvme_show_error("identify controller: %s", nvme_strerror(errno));
else
nvme_show_status(err);
return err;
}
ns_list = nvme_alloc(sizeof(*ns_list));
if (!ns_list)
return -ENOMEM;
args.data = ns_list;
if ((ctrl->oacs & 0x8) >> 3)
nsid = NVME_NSID_ALL;
else {
err = nvme_cli_identify(dev, &args);
if (err) {
if (err < 0)
nvme_show_error("identify namespace list: %s",
nvme_strerror(errno));
else
nvme_show_status(err);
return err;
}
nsid = le32_to_cpu(ns_list->ns[0]);
}
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, nsid, ns);
if (err) {
if (err < 0)
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
else
nvme_show_status(err);
return err;
}
nvme_id_ns_flbas_to_lbaf_inuse(flbas, &lbaf);
lbas = (1 << ns->lbaf[lbaf].ds) + le16_to_cpu(ns->lbaf[lbaf].ms);
if (suffix_si_parse(val, &endptr, (uint64_t *)num)) {
nvme_show_error("Expected long suffixed integer argument for '%s-si' but got '%s'!",
opt, val);
return -errno;
}
if (endptr[0]) {
remainder = *num % align;
if (remainder)
*num += align - remainder;
}
if (endptr[0] != '\0')
*num /= lbas;
return 0;
}
static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send a namespace management command "
"to the specified device to create a namespace with the given "
"parameters. The next available namespace ID is used for the "
"create operation. Note that create-ns does not attach the "
"namespace to a controller, the attach-ns command is needed.";
const char *nsze = "size of ns (NSZE)";
const char *ncap = "capacity of ns (NCAP)";
const char *flbas =
"Formatted LBA size (FLBAS), if entering this value ignore \'block-size\' field";
const char *dps = "data protection settings (DPS)";
const char *nmic = "multipath and sharing capabilities (NMIC)";
const char *anagrpid = "ANA Group Identifier (ANAGRPID)";
const char *nvmsetid = "NVM Set Identifier (NVMSETID)";
const char *csi = "command set identifier (CSI)";
const char *lbstm = "logical block storage tag mask (LBSTM)";
const char *nphndls = "Number of Placement Handles (NPHNDLS)";
const char *bs = "target block size, specify only if \'FLBAS\' value not entered";
const char *nsze_si = "size of ns (NSZE) in standard SI units";
const char *ncap_si = "capacity of ns (NCAP) in standard SI units";
const char *azr = "Allocate ZRWA Resources (AZR) for Zoned Namespace Command Set";
const char *rar = "Requested Active Resources (RAR) for Zoned Namespace Command Set";
const char *ror = "Requested Open Resources (ROR) for Zoned Namespace Command Set";
const char *rnumzrwa =
"Requested Number of ZRWA Resources (RNUMZRWA) for Zoned Namespace Command Set";
const char *phndls = "Comma separated list of Placement Handle Associated RUH";
_cleanup_free_ struct nvme_ns_mgmt_host_sw_specified *data = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err = 0, i;
__u32 nsid;
uint16_t num_phandle;
uint16_t phndl[128] = { 0, };
_cleanup_free_ struct nvme_id_ctrl *id = NULL;
_cleanup_free_ struct nvme_id_ns_granularity_list *gr_list = NULL;
__u64 align_nsze = 1 << 20; /* Default 1 MiB */
__u64 align_ncap = align_nsze;
nvme_print_flags_t flags;
struct config {
__u64 nsze;
__u64 ncap;
__u8 flbas;
__u8 dps;
__u8 nmic;
__u32 anagrpid;
__u16 nvmsetid;
__u16 endgid;
__u64 bs;
__u8 csi;
__u64 lbstm;
__u16 nphndls;
char *nsze_si;
char *ncap_si;
bool azr;
__u32 rar;
__u32 ror;
__u32 rnumzrwa;
char *phndls;
};
struct config cfg = {
.nsze = 0,
.ncap = 0,
.flbas = 0xff,
.dps = 0,
.nmic = 0,
.anagrpid = 0,
.nvmsetid = 0,
.endgid = 0,
.bs = 0x00,
.csi = 0,
.lbstm = 0,
.nphndls = 0,
.nsze_si = NULL,
.ncap_si = NULL,
.azr = false,
.rar = 0,
.ror = 0,
.rnumzrwa = 0,
.phndls = "",
};
NVME_ARGS(opts,
OPT_SUFFIX("nsze", 's', &cfg.nsze, nsze),
OPT_SUFFIX("ncap", 'c', &cfg.ncap, ncap),
OPT_BYTE("flbas", 'f', &cfg.flbas, flbas),
OPT_BYTE("dps", 'd', &cfg.dps, dps),
OPT_BYTE("nmic", 'm', &cfg.nmic, nmic),
OPT_UINT("anagrp-id", 'a', &cfg.anagrpid, anagrpid),
OPT_SHRT("nvmset-id", 'i', &cfg.nvmsetid, nvmsetid),
OPT_SHRT("endg-id", 'e', &cfg.endgid, endgid),
OPT_SUFFIX("block-size", 'b', &cfg.bs, bs),
OPT_BYTE("csi", 'y', &cfg.csi, csi),
OPT_SUFFIX("lbstm", 'l', &cfg.lbstm, lbstm),
OPT_SHRT("nphndls", 'n', &cfg.nphndls, nphndls),
OPT_STR("nsze-si", 'S', &cfg.nsze_si, nsze_si),
OPT_STR("ncap-si", 'C', &cfg.ncap_si, ncap_si),
OPT_FLAG("azr", 'z', &cfg.azr, azr),
OPT_UINT("rar", 'r', &cfg.rar, rar),
OPT_UINT("ror", 'O', &cfg.ror, ror),
OPT_UINT("rnumzrwa", 'u', &cfg.rnumzrwa, rnumzrwa),
OPT_LIST("phndls", 'p', &cfg.phndls, phndls));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.flbas != 0xff && cfg.bs != 0x00) {
nvme_show_error(
"Invalid specification of both FLBAS and Block Size, please specify only one");
return -EINVAL;
}
if (cfg.bs) {
if ((cfg.bs & (~cfg.bs + 1)) != cfg.bs) {
nvme_show_error(
"Invalid value for block size (%"PRIu64"). Block size must be a power of two",
(uint64_t)cfg.bs);
return -EINVAL;
}
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, NVME_NSID_ALL, ns);
if (err) {
if (err < 0) {
nvme_show_error("identify-namespace: %s", nvme_strerror(errno));
} else {
fprintf(stderr, "identify failed\n");
nvme_show_status(err);
}
return err;
}
for (i = 0; i <= ns->nlbaf; ++i) {
if ((1 << ns->lbaf[i].ds) == cfg.bs && ns->lbaf[i].ms == 0) {
cfg.flbas = i;
break;
}
}
}
if (cfg.flbas == 0xff) {
fprintf(stderr, "FLBAS corresponding to block size %"PRIu64" not found\n",
(uint64_t)cfg.bs);
fprintf(stderr, "Please correct block size, or specify FLBAS directly\n");
return -EINVAL;
}
id = nvme_alloc(sizeof(*id));
if (!id)
return -ENOMEM;
err = nvme_identify_ctrl(dev_fd(dev), id);
if (err) {
if (err < 0) {
nvme_show_error("identify-controller: %s", nvme_strerror(errno));
} else {
fprintf(stderr, "identify controller failed\n");
nvme_show_status(err);
}
return err;
}
if (id->ctratt & NVME_CTRL_CTRATT_NAMESPACE_GRANULARITY) {
gr_list = nvme_alloc(sizeof(*gr_list));
if (!gr_list)
return -ENOMEM;
if (!nvme_identify_ns_granularity(dev_fd(dev), gr_list)) {
struct nvme_id_ns_granularity_desc *desc;
int index = cfg.flbas;
/* FIXME: add a proper bitmask to libnvme */
if (!(le32_to_cpu(gr_list->attributes) & 1)) {
/* Only the first descriptor is valid */
index = 0;
} else if (index > gr_list->num_descriptors) {
/*
* The descriptor will contain only zeroes
* so we don't need to read it.
*/
goto parse_lba;
}
desc = &gr_list->entry[index];
if (desc->nszegran) {
print_info("enforce nsze alignment to %"PRIx64
" because of namespace granularity requirements\n",
le64_to_cpu(desc->nszegran));
align_nsze = le64_to_cpu(desc->nszegran);
}
if (desc->ncapgran) {
print_info("enforce ncap alignment to %"PRIx64
" because of namespace granularity requirements\n",
le64_to_cpu(desc->ncapgran));
align_ncap = le64_to_cpu(desc->ncapgran);
}
}
}
parse_lba:
err = parse_lba_num_si(dev, "nsze", cfg.nsze_si, cfg.flbas, &cfg.nsze, align_nsze);
if (err)
return err;
err = parse_lba_num_si(dev, "ncap", cfg.ncap_si, cfg.flbas, &cfg.ncap, align_ncap);
if (err)
return err;
if (cfg.csi != NVME_CSI_ZNS && (cfg.azr || cfg.rar || cfg.ror || cfg.rnumzrwa)) {
nvme_show_error("Invalid ZNS argument is given (CSI:%#x)", cfg.csi);
return -EINVAL;
}
data = nvme_alloc(sizeof(*data));
if (!data)
return -ENOMEM;
data->nsze = cpu_to_le64(cfg.nsze);
data->ncap = cpu_to_le64(cfg.ncap);
data->flbas = cfg.flbas;
data->dps = cfg.dps;
data->nmic = cfg.nmic;
data->anagrpid = cpu_to_le32(cfg.anagrpid);
data->nvmsetid = cpu_to_le16(cfg.nvmsetid);
data->endgid = cpu_to_le16(cfg.endgid);
data->lbstm = cpu_to_le64(cfg.lbstm);
data->zns.znsco = cfg.azr;
data->zns.rar = cpu_to_le32(cfg.rar);
data->zns.ror = cpu_to_le32(cfg.ror);
data->zns.rnumzrwa = cpu_to_le32(cfg.rnumzrwa);
data->nphndls = cpu_to_le16(cfg.nphndls);
num_phandle = argconfig_parse_comma_sep_array_short(cfg.phndls, phndl, ARRAY_SIZE(phndl));
if (cfg.nphndls != num_phandle) {
nvme_show_error("Invalid Placement handle list");
return -EINVAL;
}
for (i = 0; i < num_phandle; i++)
data->phndl[i] = cpu_to_le16(phndl[i]);
err = nvme_cli_ns_mgmt_create(dev, data, &nsid, nvme_cfg.timeout, cfg.csi);
ns_mgmt_show_status(dev, err, cmd->name, nsid);
return err;
}
static bool nvme_match_device_filter(nvme_subsystem_t s,
nvme_ctrl_t c, nvme_ns_t ns, void *f_args)
{
char *devname = f_args;
nvme_ns_t n;
if (ns && !strcmp(devname, nvme_ns_get_name(ns)))
return true;
if (c) {
s = nvme_ctrl_get_subsystem(c);
nvme_ctrl_for_each_ns(c, n) {
if (!strcmp(devname, nvme_ns_get_name(n)))
return true;
}
}
if (s) {
nvme_subsystem_for_each_ns(s, n) {
if (!strcmp(devname, nvme_ns_get_name(n)))
return true;
}
}
return false;
}
static int list_subsys(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
_cleanup_nvme_root_ nvme_root_t r = NULL;
nvme_print_flags_t flags;
const char *desc = "Retrieve information for subsystems";
nvme_scan_filter_t filter = NULL;
char *devname;
int err;
int nsid = NVME_NSID_ALL;
NVME_ARGS(opts);
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
devname = NULL;
if (optind < argc)
devname = basename(argv[optind++]);
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0 || (flags != JSON && flags != NORMAL)) {
nvme_show_error("Invalid output format");
return -EINVAL;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
r = nvme_create_root(stderr, log_level);
if (!r) {
if (devname)
nvme_show_error("Failed to scan nvme subsystem for %s", devname);
else
nvme_show_error("Failed to scan nvme subsystem");
return -errno;
}
if (devname) {
int subsys_num;
if (sscanf(devname, "nvme%dn%d", &subsys_num, &nsid) != 2) {
nvme_show_error("Invalid device name %s", devname);
return -EINVAL;
}
filter = nvme_match_device_filter;
}
err = nvme_scan_topology(r, filter, (void *)devname);
if (err) {
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
return -errno;
}
nvme_show_subsystem_list(r, nsid != NVME_NSID_ALL, flags);
return 0;
}
static int list(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve basic information for all NVMe namespaces";
nvme_print_flags_t flags;
_cleanup_nvme_root_ nvme_root_t r = NULL;
int err = 0;
NVME_ARGS(opts);
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0 || (flags != JSON && flags != NORMAL)) {
nvme_show_error("Invalid output format");
return -EINVAL;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
r = nvme_create_root(stderr, log_level);
if (!r) {
nvme_show_error("Failed to create topology root: %s", nvme_strerror(errno));
return -errno;
}
err = nvme_scan_topology(r, NULL, NULL);
if (err < 0) {
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
return err;
}
nvme_show_list_items(r, flags);
return err;
}
int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin,
void (*vs)(__u8 *vs, struct json_object *root))
{
const char *desc = "Send an Identify Controller command to "
"the given device and report information about the specified "
"controller in human-readable or "
"binary format. May also return vendor-specific "
"controller attributes in hex-dump if requested.";
const char *vendor_specific = "dump binary vendor field";
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
bool vendor_specific;
bool raw_binary;
bool human_readable;
};
struct config cfg = {
.vendor_specific = false,
.raw_binary = false,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_FLAG("vendor-specific", 'V', &cfg.vendor_specific, vendor_specific),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_identify),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_identify));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (cfg.vendor_specific)
flags |= VS;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (!err)
nvme_show_id_ctrl(ctrl, flags, vs);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("identify controller: %s", nvme_strerror(errno));
return err;
}
static int id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
return __id_ctrl(argc, argv, cmd, plugin, NULL);
}
static int nvm_id_ctrl(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Send an Identify Controller NVM Command Set "
"command to the given device and report information about "
"the specified controller in various formats.";
_cleanup_free_ struct nvme_id_ctrl_nvm *ctrl_nvm = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
ctrl_nvm = nvme_alloc(sizeof(*ctrl_nvm));
if (!ctrl_nvm)
return -ENOMEM;
err = nvme_nvm_identify_ctrl(dev_fd(dev), ctrl_nvm);
if (!err)
nvme_show_id_ctrl_nvm(ctrl_nvm, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("nvm identify controller: %s", nvme_strerror(errno));
return err;
}
static int nvm_id_ns(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Send an Identify Namespace NVM Command Set "
"command to the given device and report information about "
"the specified namespace in various formats.";
_cleanup_free_ struct nvme_nvm_id_ns *id_ns = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
__u32 namespace_id;
__u8 uuid_index;
};
struct config cfg = {
.namespace_id = 0,
.uuid_index = NVME_UUID_NONE,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_perror("get-namespace-id");
return err;
}
}
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
if (err) {
nvme_show_status(err);
return err;
}
id_ns = nvme_alloc(sizeof(*id_ns));
if (!id_ns)
return -ENOMEM;
err = nvme_identify_ns_csi(dev_fd(dev), cfg.namespace_id,
cfg.uuid_index,
NVME_CSI_NVM, id_ns);
if (!err)
nvme_show_nvm_id_ns(id_ns, cfg.namespace_id, ns, 0, false, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("nvm identify namespace");
return err;
}
static int nvm_id_ns_lba_format(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an NVM Command Set specific Identify Namespace "
"command to the given device, returns capability field properties of "
"the specified LBA Format index in the specified namespace in various formats.";
_cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
__u16 lba_format_index;
__u8 uuid_index;
};
struct config cfg = {
.lba_format_index = 0,
.uuid_index = NVME_UUID_NONE,
};
NVME_ARGS(opts,
OPT_UINT("lba-format-index", 'i', &cfg.lba_format_index, lba_format_index),
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, NVME_NSID_ALL, ns);
if (err) {
ns->nlbaf = NVME_FEAT_LBA_RANGE_MAX - 1;
ns->nulbaf = 0;
}
nvm_ns = nvme_alloc(sizeof(*nvm_ns));
if (!nvm_ns)
return -ENOMEM;
err = nvme_identify_iocs_ns_csi_user_data_format(dev_fd(dev), cfg.lba_format_index,
cfg.uuid_index, NVME_CSI_NVM, nvm_ns);
if (!err)
nvme_show_nvm_id_ns(nvm_ns, 0, ns, cfg.lba_format_index, true, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("NVM identify namespace for specific LBA format");
return err;
}
static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send Namespace Identification Descriptors command to the "
"given device, returns the namespace identification descriptors "
"of the specific namespace in either human-readable or binary format.";
const char *raw = "show descriptors in binary format";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *nsdescs = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u32 namespace_id;
bool raw_binary;
};
struct config cfg = {
.namespace_id = 0,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
nsdescs = nvme_alloc(NVME_IDENTIFY_DATA_SIZE);
if (!nsdescs)
return -ENOMEM;
err = nvme_cli_identify_ns_descs(dev, cfg.namespace_id, nsdescs);
if (!err)
nvme_show_id_ns_descs(nsdescs, cfg.namespace_id, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
return err;
}
static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an Identify Namespace command to the "
"given device, returns properties of the specified namespace "
"in either human-readable or binary format. Can also return "
"binary vendor-specific namespace attributes.";
const char *force = "Return this namespace, even if not attached (1.2 devices only)";
const char *vendor_specific = "dump binary vendor fields";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u32 namespace_id;
bool force;
bool vendor_specific;
bool raw_binary;
bool human_readable;
};
struct config cfg = {
.namespace_id = 0,
.force = false,
.vendor_specific = false,
.raw_binary = false,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_FLAG("force", 0, &cfg.force, force),
OPT_FLAG("vendor-specific", 'V', &cfg.vendor_specific, vendor_specific),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_identify),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_identify));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (cfg.vendor_specific)
flags |= VS;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
if (cfg.force)
err = nvme_cli_identify_allocated_ns(dev, cfg.namespace_id, ns);
else
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
if (!err)
nvme_show_id_ns(ns, cfg.namespace_id, 0, false, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
return err;
}
static int cmd_set_independent_id_ns(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Send an I/O Command Set Independent Identify "
"Namespace command to the given device, returns properties of the "
"specified namespace in human-readable or binary or json format.";
_cleanup_free_ struct nvme_id_independent_id_ns *ns = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err = -1;
struct config {
__u32 namespace_id;
bool raw_binary;
bool human_readable;
};
struct config cfg = {
.namespace_id = 0,
.raw_binary = false,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_identify),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_identify));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_perror("get-namespace-id");
return err;
}
}
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_identify_independent_identify_ns(dev_fd(dev), cfg.namespace_id, ns);
if (!err)
nvme_show_cmd_set_independent_id_ns(ns, cfg.namespace_id, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("I/O command set independent identify namespace: %s",
nvme_strerror(errno));
return err;
}
static int id_ns_granularity(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an Identify Namespace Granularity List command to the "
"given device, returns namespace granularity list "
"in either human-readable or binary format.";
_cleanup_free_ struct nvme_id_ns_granularity_list *granularity_list = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
granularity_list = nvme_alloc(NVME_IDENTIFY_DATA_SIZE);
if (!granularity_list)
return -ENOMEM;
err = nvme_identify_ns_granularity(dev_fd(dev), granularity_list);
if (!err)
nvme_show_id_ns_granularity_list(granularity_list, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("identify namespace granularity: %s", nvme_strerror(errno));
return err;
}
static int id_nvmset(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an Identify NVM Set List command to the "
"given device, returns entries for NVM Set identifiers greater "
"than or equal to the value specified CDW11.NVMSETID "
"in either binary format or json format";
const char *nvmset_id = "NVM Set Identify value";
_cleanup_free_ struct nvme_id_nvmset_list *nvmset = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 nvmset_id;
};
struct config cfg = {
.nvmset_id = 0,
};
NVME_ARGS(opts,
OPT_SHRT("nvmset_id", 'i', &cfg.nvmset_id, nvmset_id));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
nvmset = nvme_alloc(sizeof(*nvmset));
if (!nvmset)
return -ENOMEM;
err = nvme_identify_nvmset_list(dev_fd(dev), cfg.nvmset_id, nvmset);
if (!err)
nvme_show_id_nvmset(nvmset, cfg.nvmset_id, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("identify nvm set list: %s", nvme_strerror(errno));
return err;
}
static int id_uuid(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an Identify UUID List command to the "
"given device, returns list of supported Vendor Specific UUIDs "
"in either human-readable or binary format.";
const char *raw = "show uuid in binary format";
const char *human_readable = "show uuid in readable format";
_cleanup_free_ struct nvme_id_uuid_list *uuid_list = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
bool raw_binary;
bool human_readable;
};
struct config cfg = {
.raw_binary = false,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
uuid_list = nvme_alloc(sizeof(*uuid_list));
if (!uuid_list)
return -ENOMEM;
err = nvme_identify_uuid(dev_fd(dev), uuid_list);
if (!err)
nvme_show_id_uuid_list(uuid_list, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("identify UUID list: %s", nvme_strerror(errno));
return err;
}
static int id_iocs(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an Identify Command Set Data command to "
"the given device, returns properties of the specified controller "
"in either human-readable or binary format.";
const char *controller_id = "identifier of desired controller";
_cleanup_free_ struct nvme_id_iocs *iocs = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 cntid;
};
struct config cfg = {
.cntid = 0xffff,
};
NVME_ARGS(opts,
OPT_SHRT("controller-id", 'c', &cfg.cntid, controller_id));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
iocs = nvme_alloc(sizeof(*iocs));
if (!iocs)
return -ENOMEM;
err = nvme_identify_iocs(dev_fd(dev), cfg.cntid, iocs);
if (!err) {
printf("NVMe Identify I/O Command Set:\n");
nvme_show_id_iocs(iocs, flags);
} else if (err > 0) {
nvme_show_status(err);
} else {
nvme_show_error("NVMe Identify I/O Command Set: %s", nvme_strerror(errno));
}
return err;
}
static int id_domain(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send an Identify Domain List command to the "
"given device, returns properties of the specified domain "
"in either normal|json|binary format.";
const char *domain_id = "identifier of desired domain";
_cleanup_free_ struct nvme_id_domain_list *id_domain = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 dom_id;
};
struct config cfg = {
.dom_id = 0xffff,
};
NVME_ARGS(opts,
OPT_SHRT("dom-id", 'd', &cfg.dom_id, domain_id));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
id_domain = nvme_alloc(sizeof(*id_domain));
if (!id_domain)
return -ENOMEM;
err = nvme_identify_domain_list(dev_fd(dev), cfg.dom_id, id_domain);
if (!err) {
printf("NVMe Identify command for Domain List is successful:\n");
printf("NVMe Identify Domain List:\n");
nvme_show_id_domain_list(id_domain, flags);
} else if (err > 0) {
nvme_show_status(err);
} else {
nvme_show_error("NVMe Identify Domain List: %s", nvme_strerror(errno));
}
return err;
}
static int get_ns_id(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Get namespace ID of a the block device.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
unsigned int nsid;
int err;
nvme_print_flags_t flags;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = nvme_get_nsid(dev_fd(dev), &nsid);
if (err < 0) {
nvme_show_error("get namespace ID: %s", nvme_strerror(errno));
return -errno;
}
printf("%s: namespace-id:%d\n", dev->name, nsid);
return 0;
}
static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "The Virtualization Management command is supported by primary controllers "
"that support the Virtualization Enhancements capability. This command is used for:\n"
" 1. Modifying Flexible Resource allocation for the primary controller\n"
" 2. Assigning Flexible Resources for secondary controllers\n"
" 3. Setting the Online and Offline state for secondary controllers";
const char *cntlid = "Controller Identifier(CNTLID)";
const char *rt = "Resource Type(RT): [0,1]\n"
"0h: VQ Resources\n"
"1h: VI Resources";
const char *act = "Action(ACT): [1,7,8,9]\n"
"1h: Primary Flexible\n"
"7h: Secondary Offline\n"
"8h: Secondary Assign\n"
"9h: Secondary Online";
const char *nr = "Number of Controller Resources(NR)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u32 result;
int err;
struct config {
__u16 cntlid;
__u8 rt;
__u8 act;
__u16 nr;
};
struct config cfg = {
.cntlid = 0,
.rt = 0,
.act = 0,
.nr = 0,
};
NVME_ARGS(opts,
OPT_UINT("cntlid", 'c', &cfg.cntlid, cntlid),
OPT_BYTE("rt", 'r', &cfg.rt, rt),
OPT_BYTE("act", 'a', &cfg.act, act),
OPT_SHRT("nr", 'n', &cfg.nr, nr));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
struct nvme_virtual_mgmt_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.act = cfg.act,
.rt = cfg.rt,
.cntlid = cfg.cntlid,
.nr = cfg.nr,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_virtual_mgmt(&args);
if (!err)
printf("success, Number of Controller Resources Modified (NRM):%#x\n", result);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("virt-mgmt: %s", nvme_strerror(errno));
return err;
}
static int primary_ctrl_caps(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *cntlid = "Controller ID";
const char *desc = "Send an Identify Primary Controller Capabilities "
"command to the given device and report the information in a "
"decoded format (default), json or binary.";
_cleanup_free_ struct nvme_primary_ctrl_cap *caps = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 cntlid;
bool human_readable;
};
struct config cfg = {
.cntlid = 0,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_UINT("cntlid", 'c', &cfg.cntlid, cntlid),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_info));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
caps = nvme_alloc(sizeof(*caps));
if (!caps)
return -ENOMEM;
err = nvme_cli_identify_primary_ctrl(dev, cfg.cntlid, caps);
if (!err)
nvme_show_primary_ctrl_cap(caps, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("identify primary controller capabilities: %s",
nvme_strerror(errno));
return err;
}
static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc =
"Show secondary controller list associated with the primary controller of the given device.";
const char *controller = "lowest controller identifier to display";
const char *num_entries = "number of entries to retrieve";
_cleanup_free_ struct nvme_secondary_ctrl_list *sc_list = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u16 cntid;
__u32 num_entries;
};
struct config cfg = {
.cntid = 0,
.num_entries = ARRAY_SIZE(sc_list->sc_entry),
};
NVME_ARGS(opts,
OPT_SHRT("cntid", 'c', &cfg.cntid, controller),
OPT_UINT("num-entries", 'e', &cfg.num_entries, num_entries));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.num_entries) {
nvme_show_error("non-zero num-entries is required param");
return -EINVAL;
}
sc_list = nvme_alloc(sizeof(*sc_list));
if (!sc_list)
return -ENOMEM;
err = nvme_cli_identify_secondary_ctrl_list(dev, cfg.cntid, sc_list);
if (!err)
nvme_show_list_secondary_ctrl(sc_list, cfg.num_entries, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("id secondary controller list: %s", nvme_strerror(errno));
return err;
}
static int sleep_self_test(unsigned int seconds)
{
nvme_sigint_received = false;
sleep(seconds);
if (nvme_sigint_received) {
printf("\nInterrupted device self-test operation by SIGINT\n");
return -SIGINT;
}
return 0;
}
static int wait_self_test(struct nvme_dev *dev)
{
static const char spin[] = {'-', '\\', '|', '/' };
_cleanup_free_ struct nvme_self_test_log *log = NULL;
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
int err, i = 0, p = 0, cnt = 0;
int wthr;
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
log = nvme_alloc(sizeof(*log));
if (!log)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err) {
nvme_show_error("identify-ctrl: %s", nvme_strerror(errno));
return err;
}
wthr = le16_to_cpu(ctrl->edstt) * 60 / 100 + 60;
printf("Waiting for self test completion...\n");
while (true) {
printf("\r[%.*s%c%.*s] %3d%%", p / 2, dash, spin[i % 4], 49 - p / 2, space, p);
fflush(stdout);
err = sleep_self_test(1);
if (err)
return err;
err = nvme_cli_get_log_device_self_test(dev, log);
if (err) {
printf("\n");
if (err < 0)
perror("self test log\n");
else
nvme_show_status(err);
return err;
}
if (++cnt > wthr) {
nvme_show_error("no progress for %d seconds, stop waiting", wthr);
return -EIO;
}
if (log->completion == 0 && p > 0) {
printf("\r[%.*s] %3d%%\n", 50, dash, 100);
break;
}
if (log->completion < p) {
printf("\n");
nvme_show_error("progress broken");
return -EIO;
} else if (log->completion != p) {
p = log->completion;
cnt = 0;
}
i++;
}
return 0;
}
static void abort_self_test(struct nvme_dev_self_test_args *args)
{
int err;
args->stc = NVME_DST_STC_ABORT;
err = nvme_dev_self_test(args);
if (!err)
printf("Aborting device self-test operation\n");
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("Device self-test: %s", nvme_strerror(errno));
}
static int device_self_test(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Implementing the device self-test feature "
"which provides the necessary log to determine the state of the device";
const char *namespace_id =
"Indicate the namespace in which the device self-test has to be carried out";
const char *self_test_code =
"This field specifies the action taken by the device self-test command :\n"
"0h Show current state of device self-test operation\n"
"1h Start a short device self-test operation\n"
"2h Start a extended device self-test operation\n"
"3h Start a Host-Initiated Refresh operation\n"
"eh Start a vendor specific device self-test operation\n"
"fh Abort the device self-test operation";
const char *wait = "Wait for the test to finish";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
__u8 stc;
bool wait;
};
struct config cfg = {
.namespace_id = NVME_NSID_ALL,
.stc = NVME_ST_CODE_RESERVED,
.wait = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id),
OPT_BYTE("self-test-code", 's', &cfg.stc, self_test_code),
OPT_FLAG("wait", 'w', &cfg.wait, wait));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.stc == NVME_ST_CODE_RESERVED) {
_cleanup_free_ struct nvme_self_test_log *log = NULL;
log = nvme_alloc(sizeof(*log));
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_device_self_test(dev, log);
if (err) {
printf("\n");
if (err < 0)
perror("self test log\n");
else
nvme_show_status(err);
}
if (log->completion == 0) {
printf("no self test running\n");
} else {
if (cfg.wait)
err = wait_self_test(dev);
else
printf("progress %d%%\n", log->completion);
}
goto check_abort;
}
struct nvme_dev_self_test_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.stc = cfg.stc,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_dev_self_test(&args);
if (!err) {
if (cfg.stc == NVME_ST_CODE_ABORT)
printf("Aborting device self-test operation\n");
else if (cfg.stc == NVME_ST_CODE_EXTENDED)
printf("Extended Device self-test started\n");
else if (cfg.stc == NVME_ST_CODE_SHORT)
printf("Short Device self-test started\n");
else if (cfg.stc == NVME_ST_CODE_HOST_INIT)
printf("Host-Initiated Refresh started\n");
if (cfg.wait && cfg.stc != NVME_ST_CODE_ABORT)
err = wait_self_test(dev);
} else if (err > 0) {
nvme_show_status(err);
} else {
nvme_show_error("Device self-test: %s", nvme_strerror(errno));
}
check_abort:
if (err == -EINTR)
abort_self_test(&args);
return err;
}
static int self_test_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve the self-test log for the given device and given test "
"(or optionally a namespace) in either decoded format (default) or binary.";
const char *dst_entries = "Indicate how many DST log entries to be retrieved, "
"by default all the 20 entries will be retrieved";
_cleanup_free_ struct nvme_self_test_log *log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err;
struct config {
__u8 dst_entries;
};
struct config cfg = {
.dst_entries = NVME_LOG_ST_MAX_RESULTS,
};
NVME_ARGS(opts,
OPT_BYTE("dst-entries", 'e', &cfg.dst_entries, dst_entries));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
log = nvme_alloc(sizeof(*log));
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_device_self_test(dev, log);
if (!err)
nvme_show_self_test_log(log, cfg.dst_entries, 0, dev->name, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("self test log: %s", nvme_strerror(errno));
return err;
}
static int get_feature_id(struct nvme_dev *dev, struct feat_cfg *cfg,
void **buf, __u32 *result)
{
if (!cfg->data_len)
nvme_get_feature_length(cfg->feature_id, cfg->cdw11,
&cfg->data_len);
if (cfg->feature_id == NVME_FEAT_FID_FDP_EVENTS) {
cfg->data_len = 0xff * sizeof(__u16);
cfg->cdw11 |= 0xff << 16;
}
if (NVME_CHECK(cfg->sel, GET_FEATURES_SEL, SUPPORTED))
cfg->data_len = 0;
if (cfg->data_len) {
*buf = nvme_alloc(cfg->data_len - 1);
if (!*buf)
return -1;
}
struct nvme_get_features_args args = {
.args_size = sizeof(args),
.fid = cfg->feature_id,
.nsid = cfg->namespace_id,
.sel = cfg->sel,
.cdw11 = cfg->cdw11,
.uuidx = cfg->uuid_index,
.data_len = cfg->data_len,
.data = *buf,
.timeout = nvme_cfg.timeout,
.result = result,
};
return nvme_cli_get_features(dev, &args);
}
static int filter_out_flags(int status)
{
return status & (NVME_VAL(SCT) | NVME_VAL(SC));
}
static void get_feature_id_print(struct feat_cfg cfg, int err, __u32 result,
void *buf, nvme_print_flags_t flags)
{
int status = filter_out_flags(err);
int verbose = flags & VERBOSE;
enum nvme_status_type type = NVME_STATUS_TYPE_NVME;
if (!err) {
if (!cfg.raw_binary || !buf) {
nvme_feature_show(cfg.feature_id, cfg.sel, result);
if (NVME_CHECK(cfg.sel, GET_FEATURES_SEL, SUPPORTED))
nvme_show_select_result(cfg.feature_id, result);
else if (verbose || !strcmp(nvme_cfg.output_format, "json"))
nvme_feature_show_fields(cfg.feature_id, result, buf);
else if (buf)
d(buf, cfg.data_len, 16, 1);
} else if (buf) {
d_raw(buf, cfg.data_len);
}
} else if (err > 0) {
if (!nvme_status_equals(status, type, NVME_SC_INVALID_FIELD) &&
!nvme_status_equals(status, type, NVME_SC_INVALID_NS))
nvme_show_status(err);
} else {
nvme_show_error("get-feature: %s", nvme_strerror(errno));
}
}
static bool is_get_feature_result_set(enum nvme_features_id feature_id)
{
switch (feature_id) {
case NVME_FEAT_FID_PERF_CHARACTERISTICS:
return false;
default:
break;
}
return true;
}
static int get_feature_id_changed(struct nvme_dev *dev, struct feat_cfg cfg,
nvme_print_flags_t flags)
{
int err;
int err_def = 0;
__u32 result;
__u32 result_def;
_cleanup_free_ void *buf = NULL;
_cleanup_free_ void *buf_def = NULL;
if (cfg.changed)
cfg.sel = NVME_GET_FEATURES_SEL_CURRENT;
err = get_feature_id(dev, &cfg, &buf, &result);
if (!err && cfg.changed) {
cfg.sel = NVME_GET_FEATURES_SEL_DEFAULT;
err_def = get_feature_id(dev, &cfg, &buf_def, &result_def);
}
if (!err && !is_get_feature_result_set(cfg.feature_id))
result = cfg.cdw11;
if (err || !cfg.changed || err_def || result != result_def ||
(buf && buf_def && !strcmp(buf, buf_def)))
get_feature_id_print(cfg, err, result, buf, flags);
return err;
}
static int get_feature_ids(struct nvme_dev *dev, struct feat_cfg cfg,
nvme_print_flags_t flags)
{
int err = 0;
int i;
int feat_max = 0x100;
int feat_num = 0;
int status = 0;
enum nvme_status_type type = NVME_STATUS_TYPE_NVME;
if (cfg.feature_id)
feat_max = cfg.feature_id + 1;
for (i = cfg.feature_id; i < feat_max; i++, feat_num++) {
cfg.feature_id = i;
err = get_feature_id_changed(dev, cfg, flags);
if (!err)
continue;
status = filter_out_flags(err);
if (nvme_status_equals(status, type, NVME_SC_INVALID_FIELD))
continue;
if (!nvme_status_equals(status, type, NVME_SC_INVALID_NS))
break;
nvme_show_error_status(err, "get-feature:%#0*x (%s)", cfg.feature_id ? 4 : 2,
cfg.feature_id, nvme_feature_to_string(cfg.feature_id));
}
if (feat_num == 1 && nvme_status_equals(status, type, NVME_SC_INVALID_FIELD))
nvme_show_status(err);
return err;
}
static int get_feature(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Read operating parameters of the "
"specified controller. Operating parameters are grouped "
"and identified by Feature Identifiers; each Feature "
"Identifier contains one or more attributes that may affect "
"behavior of the feature. Each Feature has three possible "
"settings: default, saveable, and current. If a Feature is "
"saveable, it may be modified by set-feature. Default values "
"are vendor-specific and not changeable. Use set-feature to "
"change saveable Features.";
const char *raw = "show feature in binary format";
const char *feature_id = "feature identifier";
const char *sel = "[0-3]: current/default/saved/supported";
const char *cdw11 = "feature specific dword 11";
const char *human_readable = "show feature in readable format";
const char *changed = "show feature changed";
nvme_print_flags_t flags = NORMAL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
struct feat_cfg cfg = {
.feature_id = 0,
.namespace_id = 0,
.sel = NVME_GET_FEATURES_SEL_CURRENT,
.data_len = 0,
.raw_binary = false,
.cdw11 = 0,
.uuid_index = 0,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_BYTE("feature-id", 'f', &cfg.feature_id, feature_id, feature_name),
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_BYTE("sel", 's', &cfg.sel, sel),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
OPT_UINT("cdw11", 'c', &cfg.cdw11, cdw11),
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index_specify),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable),
OPT_FLAG("changed", 'C', &cfg.changed, changed));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!argconfig_parse_seen(opts, "namespace-id")) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
if (errno != ENOTTY) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
cfg.namespace_id = NVME_NSID_ALL;
}
}
if (cfg.sel > NVME_GET_FEATURES_SEL_SUPPORTED) {
nvme_show_error("invalid 'select' param:%d", cfg.sel);
return -EINVAL;
}
if (cfg.uuid_index > 127) {
nvme_show_error("invalid uuid index param: %u", cfg.uuid_index);
return -1;
}
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
nvme_show_init();
err = get_feature_ids(dev, cfg, flags);
nvme_show_finish();
return err;
}
/*
* Transfers one chunk of firmware to the device, and decodes & reports any
* errors. Returns -1 on (fatal) error; signifying that the transfer should
* be aborted.
*/
static int fw_download_single(struct nvme_dev *dev, void *fw_buf,
unsigned int fw_len, uint32_t offset,
uint32_t len, bool progress, bool ignore_ovr)
{
const unsigned int max_retries = 3;
bool retryable, ovr;
int err, try;
if (progress) {
printf("Firmware download: transferring 0x%08x/0x%08x bytes: %03d%%\r",
offset, fw_len, (int)(100 * offset / fw_len));
}
struct nvme_fw_download_args args = {
.args_size = sizeof(args),
.offset = offset,
.data_len = len,
.data = fw_buf,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
for (try = 0; try < max_retries; try++) {
if (try > 0) {
fprintf(stderr, "retrying offset %x (%u/%u)\n",
offset, try, max_retries);
}
err = nvme_cli_fw_download(dev, &args);
if (!err)
return 0;
/*
* don't retry if the NVMe-type error indicates Do Not Resend.
*/
retryable = !((err > 0) &&
(nvme_status_get_type(err) == NVME_STATUS_TYPE_NVME) &&
(nvme_status_get_value(err) & NVME_SC_DNR));
/*
* detect overwrite errors, which are handled differently
* depending on ignore_ovr
*/
ovr = (err > 0) &&
(nvme_status_get_type(err) == NVME_STATUS_TYPE_NVME) &&
(NVME_GET(err, SCT) == NVME_SCT_CMD_SPECIFIC) &&
(NVME_GET(err, SC) == NVME_SC_OVERLAPPING_RANGE);
if (ovr && ignore_ovr)
return 0;
/*
* if we're printing progress, we'll need a newline to separate
* error output from the progress data (which doesn't have a
* \n), and flush before we write to stderr.
*/
if (progress) {
printf("\n");
fflush(stdout);
}
fprintf(stderr, "fw-download: error on offset 0x%08x/0x%08x\n",
offset, fw_len);
if (err < 0) {
fprintf(stderr, "fw-download: %s\n", nvme_strerror(errno));
} else {
nvme_show_status(err);
if (ovr) {
/*
* non-ignored ovr error: print a little extra info
* about recovering
*/
fprintf(stderr,
"Use --ignore-ovr to ignore overwrite errors\n");
/*
* We'll just be attempting more overwrites if
* we retry. DNR will likely be set, but force
* an exit anyway.
*/
retryable = false;
}
}
if (!retryable)
break;
}
return -1;
}
static int fw_download(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Copy all or part of a firmware image to "
"a controller for future update. Optionally, specify how "
"many KiB of the firmware to transfer at once. The offset will "
"start at 0 and automatically adjust based on xfer size "
"unless fw is split across multiple files. May be submitted "
"while outstanding commands exist on the Admin and IO "
"Submission Queues. Activate downloaded firmware with "
"fw-activate, and then reset the device to apply the downloaded firmware.";
const char *fw = "firmware file (required)";
const char *xfer = "transfer chunksize limit";
const char *offset = "starting dword offset, default 0";
const char *progress = "display firmware transfer progress";
const char *ignore_ovr = "ignore overwrite errors";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_cleanup_fd_ int fw_fd = -1;
unsigned int fw_size, pos;
int err;
struct stat sb;
void *fw_buf;
struct nvme_id_ctrl ctrl = { 0 };
nvme_print_flags_t flags;
struct config {
char *fw;
__u32 xfer;
__u32 offset;
bool progress;
bool ignore_ovr;
};
struct config cfg = {
.fw = "",
.xfer = 0,
.offset = 0,
.progress = false,
.ignore_ovr = false,
};
NVME_ARGS(opts,
OPT_FILE("fw", 'f', &cfg.fw, fw),
OPT_UINT("xfer", 'x', &cfg.xfer, xfer),
OPT_UINT("offset", 'O', &cfg.offset, offset),
OPT_FLAG("progress", 'p', &cfg.progress, progress),
OPT_FLAG("ignore-ovr", 'i', &cfg.ignore_ovr, ignore_ovr));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
fw_fd = open(cfg.fw, O_RDONLY);
cfg.offset <<= 2;
if (fw_fd < 0) {
nvme_show_error("Failed to open firmware file %s: %s", cfg.fw, strerror(errno));
return -EINVAL;
}
err = fstat(fw_fd, &sb);
if (err < 0) {
nvme_show_perror("fstat");
return err;
}
fw_size = sb.st_size;
if ((fw_size & 0x3) || (fw_size == 0)) {
nvme_show_error("Invalid size:%d for f/w image", fw_size);
return -EINVAL;
}
if (cfg.xfer == 0) {
err = nvme_cli_identify_ctrl(dev, &ctrl);
if (err) {
nvme_show_error("identify-ctrl: %s", nvme_strerror(errno));
return err;
}
if (ctrl.fwug == 0 || ctrl.fwug == 0xff)
cfg.xfer = 4096;
else
cfg.xfer = ctrl.fwug * 4096;
} else if (cfg.xfer % 4096)
cfg.xfer = 4096;
if (ctrl.fwug && ctrl.fwug != 0xff && fw_size % cfg.xfer)
nvme_show_error("WARNING: firmware file size %u not conform to FWUG alignment %lu",
fw_size, cfg.xfer);
fw_buf = nvme_alloc_huge(fw_size, &mh);
if (!fw_buf) {
nvme_show_error("failed to allocate huge memory");
return -ENOMEM;
}
if (read(fw_fd, fw_buf, fw_size) != ((ssize_t)(fw_size))) {
err = -errno;
nvme_show_error("read :%s :%s", cfg.fw, strerror(errno));
return err;
}
for (pos = 0; pos < fw_size; pos += cfg.xfer) {
cfg.xfer = min(cfg.xfer, fw_size - pos);
err = fw_download_single(dev, fw_buf + pos, fw_size,
cfg.offset + pos, cfg.xfer,
cfg.progress, cfg.ignore_ovr);
if (err)
break;
}
if (!err) {
/* end the progress output */
if (cfg.progress)
printf("\n");
printf("Firmware download success\n");
}
return err;
}
static char *nvme_fw_status_reset_type(__u16 status)
{
switch (status & 0x7ff) {
case NVME_SC_FW_NEEDS_CONV_RESET:
return "conventional";
case NVME_SC_FW_NEEDS_SUBSYS_RESET:
return "subsystem";
case NVME_SC_FW_NEEDS_RESET:
return "any controller";
default:
return "unknown";
}
}
static bool fw_commit_support_mud(struct nvme_dev *dev)
{
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
int err;
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return false;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err)
nvme_show_error("identify-ctrl: %s", nvme_strerror(errno));
else if (ctrl->frmw >> 5 & 0x1)
return true;
return false;
}
static void fw_commit_print_mud(struct nvme_dev *dev, __u32 result)
{
if (!fw_commit_support_mud(dev))
return;
printf("Multiple Update Detected (MUD) Value: %u\n", result);
if (result & 0x1)
printf("Detected an overlapping firmware/boot partition image update command\n"
"sequence due to processing a command from an Admin SQ on a controller\n");
if (result >> 1 & 0x1)
printf("Detected an overlapping firmware/boot partition image update command\n"
"sequence due to processing a command from a Management Endpoint\n");
}
static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Verify downloaded firmware image and "
"commit to specific firmware slot. Device is not automatically "
"reset following firmware activation. A reset may be issued "
"with an 'echo 1 > /sys/class/nvme/nvmeX/reset_controller'. "
"Ensure nvmeX is the device you just activated before reset.";
const char *slot = "[0-7]: firmware slot for commit action";
const char *action = "[0-7]: commit action";
const char *bpid = "[0,1]: boot partition identifier, if applicable (default: 0)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u32 result;
int err;
nvme_print_flags_t flags;
struct config {
__u8 slot;
__u8 action;
__u8 bpid;
};
struct config cfg = {
.slot = 0,
.action = 0,
.bpid = 0,
};
NVME_ARGS(opts,
OPT_BYTE("slot", 's', &cfg.slot, slot),
OPT_BYTE("action", 'a', &cfg.action, action),
OPT_BYTE("bpid", 'b', &cfg.bpid, bpid));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.slot > 7) {
nvme_show_error("invalid slot:%d", cfg.slot);
return -EINVAL;
}
if (cfg.action > 7 || cfg.action == 4 || cfg.action == 5) {
nvme_show_error("invalid action:%d", cfg.action);
return -EINVAL;
}
if (cfg.bpid > 1) {
nvme_show_error("invalid boot partition id:%d", cfg.bpid);
return -EINVAL;
}
struct nvme_fw_commit_args args = {
.args_size = sizeof(args),
.slot = cfg.slot,
.action = cfg.action,
.bpid = cfg.bpid,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_cli_fw_commit(dev, &args);
if (err < 0) {
nvme_show_error("fw-commit: %s", nvme_strerror(errno));
} else if (err != 0) {
__u32 val = nvme_status_get_value(err);
int type = nvme_status_get_type(err);
if (type == NVME_STATUS_TYPE_NVME) {
switch (val & 0x7ff) {
case NVME_SC_FW_NEEDS_CONV_RESET:
case NVME_SC_FW_NEEDS_SUBSYS_RESET:
case NVME_SC_FW_NEEDS_RESET:
printf("Success activating firmware action:%d slot:%d",
cfg.action, cfg.slot);
if (cfg.action == 6 || cfg.action == 7)
printf(" bpid:%d", cfg.bpid);
printf(", but firmware requires %s reset\n",
nvme_fw_status_reset_type(val));
break;
default:
nvme_show_status(err);
break;
}
} else {
nvme_show_status(err);
}
} else {
printf("Success committing firmware action:%d slot:%d",
cfg.action, cfg.slot);
if (cfg.action == 6 || cfg.action == 7)
printf(" bpid:%d", cfg.bpid);
printf("\n");
fw_commit_print_mud(dev, result);
}
return err;
}
static int subsystem_reset(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Resets the NVMe subsystem";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = nvme_subsystem_reset(dev_fd(dev));
if (err < 0) {
if (errno == ENOTTY)
nvme_show_error("Subsystem-reset: NVM Subsystem Reset not supported.");
else
nvme_show_error("Subsystem-reset: %s", nvme_strerror(errno));
} else if (argconfig_parse_seen(opts, "verbose"))
printf("resetting subsystem through %s\n", dev->name);
return err;
}
static int reset(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Resets the NVMe controller\n";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = nvme_ctrl_reset(dev_fd(dev));
if (err < 0)
nvme_show_error("Reset: %s", nvme_strerror(errno));
else if (argconfig_parse_seen(opts, "verbose"))
printf("resetting controller %s\n", dev->name);
return err;
}
static int ns_rescan(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Rescans the NVMe namespaces\n";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = nvme_ns_rescan(dev_fd(dev));
if (err < 0)
nvme_show_error("Namespace Rescan: %s\n", nvme_strerror(errno));
else if (argconfig_parse_seen(opts, "verbose"))
printf("rescanning namespaces through %s\n", dev->name);
return err;
}
static int sanitize_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send a sanitize command.";
const char *emvs_desc = "Enter media verification state.";
const char *no_dealloc_desc = "No deallocate after sanitize.";
const char *oipbp_desc = "Overwrite invert pattern between passes.";
const char *owpass_desc = "Overwrite pass count.";
const char *ause_desc = "Allow unrestricted sanitize exit.";
const char *sanact_desc = "Sanitize action: 1 = Exit failure mode, 2 = Start block erase,"
"3 = Start overwrite, 4 = Start crypto erase, 5 = Exit media verification";
const char *ovrpat_desc = "Overwrite pattern.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
struct config {
bool no_dealloc;
bool oipbp;
__u8 owpass;
bool ause;
__u8 sanact;
__u32 ovrpat;
bool emvs;
};
struct config cfg = {
.no_dealloc = false,
.oipbp = false,
.owpass = 0,
.ause = false,
.sanact = 0,
.ovrpat = 0,
.emvs = false,
};
OPT_VALS(sanact) = {
VAL_BYTE("exit-failure", NVME_SANITIZE_SANACT_EXIT_FAILURE),
VAL_BYTE("start-block-erase", NVME_SANITIZE_SANACT_START_BLOCK_ERASE),
VAL_BYTE("start-overwrite", NVME_SANITIZE_SANACT_START_OVERWRITE),
VAL_BYTE("start-crypto-erase", NVME_SANITIZE_SANACT_START_CRYPTO_ERASE),
VAL_BYTE("exit-media-verification", NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF),
VAL_END()
};
NVME_ARGS(opts,
OPT_FLAG("no-dealloc", 'd', &cfg.no_dealloc, no_dealloc_desc),
OPT_FLAG("oipbp", 'i', &cfg.oipbp, oipbp_desc),
OPT_BYTE("owpass", 'n', &cfg.owpass, owpass_desc),
OPT_FLAG("ause", 'u', &cfg.ause, ause_desc),
OPT_BYTE("sanact", 'a', &cfg.sanact, sanact_desc, sanact),
OPT_UINT("ovrpat", 'p', &cfg.ovrpat, ovrpat_desc),
OPT_FLAG("emvs", 'e', &cfg.emvs, emvs_desc));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
switch (cfg.sanact) {
case NVME_SANITIZE_SANACT_EXIT_FAILURE:
case NVME_SANITIZE_SANACT_START_BLOCK_ERASE:
case NVME_SANITIZE_SANACT_START_OVERWRITE:
case NVME_SANITIZE_SANACT_START_CRYPTO_ERASE:
case NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF:
break;
default:
nvme_show_error("Invalid Sanitize Action");
return -EINVAL;
}
if (cfg.ause || cfg.no_dealloc) {
if (cfg.sanact == NVME_SANITIZE_SANACT_EXIT_FAILURE) {
nvme_show_error("SANACT is Exit Failure Mode");
return -EINVAL;
} else if (cfg.sanact == NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF) {
nvme_show_error("SANACT is Exit Media Verification State");
return -EINVAL;
}
}
if (cfg.sanact == NVME_SANITIZE_SANACT_START_OVERWRITE) {
if (cfg.owpass > 15) {
nvme_show_error("OWPASS out of range [0-15]");
return -EINVAL;
}
} else {
if (cfg.owpass || cfg.oipbp || cfg.ovrpat) {
nvme_show_error("SANACT is not Overwrite");
return -EINVAL;
}
}
struct nvme_sanitize_nvm_args args = {
.args_size = sizeof(args),
.sanact = cfg.sanact,
.ause = cfg.ause,
.owpass = cfg.owpass,
.oipbp = cfg.oipbp,
.nodas = cfg.no_dealloc,
.ovrpat = cfg.ovrpat,
.result = NULL,
.emvs = cfg.emvs,
};
err = nvme_cli_sanitize_nvm(dev, &args);
if (err < 0)
nvme_show_error("sanitize: %s", nvme_strerror(errno));
else if (err > 0)
nvme_show_status(err);
return err;
}
static int nvme_get_single_property(int fd, struct get_reg_config *cfg, __u64 *value)
{
int err;
struct nvme_get_property_args args = {
.args_size = sizeof(args),
.fd = fd,
.offset = cfg->offset,
.value = value,
.timeout = nvme_cfg.timeout,
};
err = nvme_get_property(&args);
if (!err)
return 0;
if (cfg->fabrics && nvme_is_fabrics_optional_reg(cfg->offset)) {
*value = -1;
return 0;
}
if (!cfg->fabrics &&
nvme_status_equals(err, NVME_STATUS_TYPE_NVME, NVME_SC_INVALID_FIELD)) {
*value = -1;
return 0;
}
if (cfg->fabrics && err > 0)
nvme_show_status(err);
else
nvme_show_error("get-property: %s", nvme_strerror(errno));
return err;
}
static int nvme_get_properties(int fd, void **pbar, struct get_reg_config *cfg)
{
int err, size = getpagesize();
bool is_64bit = false;
__u64 value;
void *bar;
int offset;
bar = malloc(size);
if (!bar) {
nvme_show_error("malloc: %s", strerror(errno));
return -errno;
}
memset(bar, 0xff, size);
for (offset = NVME_REG_CAP; offset <= NVME_REG_CMBSZ;
offset += is_64bit ? sizeof(uint64_t) : sizeof(uint32_t)) {
if (!nvme_is_fabrics_reg(offset))
continue;
cfg->offset = offset;
err = nvme_get_single_property(fd, cfg, &value);
if (err)
break;
is_64bit = nvme_is_64bit_reg(cfg->offset);
if (is_64bit)
*(uint64_t *)(bar + cfg->offset) = value;
else
*(uint32_t *)(bar + cfg->offset) = value;
}
if (err)
free(bar);
else
*pbar = bar;
return err;
}
static void *mmap_registers(struct nvme_dev *dev, bool writable)
{
char path[512];
void *membase;
int fd;
int prot = PROT_READ;
if (writable)
prot |= PROT_WRITE;
sprintf(path, "/sys/class/nvme/%s/device/resource0", dev->name);
fd = open(path, writable ? O_RDWR : O_RDONLY);
if (fd < 0) {
if (log_level >= LOG_INFO)
nvme_show_error("%s did not find a pci resource, open failed %s",
dev->name, strerror(errno));
return NULL;
}
membase = mmap(NULL, getpagesize(), prot, MAP_SHARED, fd, 0);
if (membase == MAP_FAILED) {
if (log_level >= LOG_INFO) {
fprintf(stderr, "Failed to map registers to userspace.\n\n"
"Did your kernel enable CONFIG_IO_STRICT_DEVMEM?\n"
"You can disable this feature with command line argument\n\n"
"\tio_memory=relaxed\n\n"
"Also ensure secure boot is disabled.\n\n");
}
membase = NULL;
}
close(fd);
return membase;
}
static int show_registers(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Reads and shows the defined NVMe controller registers\n"
"in binary or human-readable format";
const char *human_readable =
"show info in readable format in case of output_format == normal";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
void *bar;
int err;
struct get_reg_config cfg = {
.human_readable = false,
.fabrics = false,
};
NVME_ARGS(opts,
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (is_blkdev(dev)) {
nvme_show_error("Only character device is allowed");
return -EINVAL;
}
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
bar = mmap_registers(dev, false);
if (!bar) {
cfg.fabrics = true;
err = nvme_get_properties(dev_fd(dev), &bar, &cfg);
if (err)
return err;
}
nvme_show_ctrl_registers(bar, cfg.fabrics, flags);
if (cfg.fabrics)
free(bar);
else
munmap(bar, getpagesize());
return 0;
}
int get_reg_size(int offset)
{
return nvme_is_64bit_reg(offset) ? sizeof(uint64_t) : sizeof(uint32_t);
}
static bool is_reg_selected(struct get_reg_config *cfg, int offset)
{
switch (offset) {
case NVME_REG_CAP:
return cfg->cap;
case NVME_REG_VS:
return cfg->vs;
case NVME_REG_INTMS:
return cfg->intms;
case NVME_REG_INTMC:
return cfg->intmc;
case NVME_REG_CC:
return cfg->cc;
case NVME_REG_CSTS:
return cfg->csts;
case NVME_REG_NSSR:
return cfg->nssr;
case NVME_REG_AQA:
return cfg->aqa;
case NVME_REG_ASQ:
return cfg->asq;
case NVME_REG_ACQ:
return cfg->acq;
case NVME_REG_CMBLOC:
return cfg->cmbloc;
case NVME_REG_CMBSZ:
return cfg->cmbsz;
case NVME_REG_BPINFO:
return cfg->bpinfo;
case NVME_REG_BPRSEL:
return cfg->bprsel;
case NVME_REG_BPMBL:
return cfg->bpmbl;
case NVME_REG_CMBMSC:
return cfg->cmbmsc;
case NVME_REG_CMBSTS:
return cfg->cmbsts;
case NVME_REG_CMBEBS:
return cfg->cmbebs;
case NVME_REG_CMBSWTP:
return cfg->cmbswtp;
case NVME_REG_NSSD:
return cfg->nssd;
case NVME_REG_CRTO:
return cfg->crto;
case NVME_REG_PMRCAP:
return cfg->pmrcap;
case NVME_REG_PMRCTL:
return cfg->pmrctl;
case NVME_REG_PMRSTS:
return cfg->pmrsts;
case NVME_REG_PMREBS:
return cfg->pmrebs;
case NVME_REG_PMRSWTP:
return cfg->pmrswtp;
case NVME_REG_PMRMSCL:
return cfg->pmrmscl;
case NVME_REG_PMRMSCU:
return cfg->pmrmscu;
default:
break;
}
return false;
}
static int get_register_properties(int fd, void **pbar, struct get_reg_config *cfg)
{
int offset = NVME_REG_CRTO;
__u64 value;
int size;
int err;
void *bar;
struct nvme_get_property_args args = {
.args_size = sizeof(args),
.fd = fd,
.value = &value,
.timeout = nvme_cfg.timeout,
};
size = offset + get_reg_size(offset);
bar = malloc(size);
if (!bar) {
nvme_show_error("malloc: %s", strerror(errno));
return -1;
}
for (offset = NVME_REG_CAP; offset <= NVME_REG_CRTO; offset += get_reg_size(offset)) {
if ((cfg->offset != offset && !is_reg_selected(cfg, offset)) ||
!nvme_is_fabrics_reg(offset))
continue;
args.offset = offset;
err = nvme_get_property(&args);
if (nvme_status_equals(err, NVME_STATUS_TYPE_NVME, NVME_SC_INVALID_FIELD)) {
value = -1;
} else if (err) {
nvme_show_error("get-property: %s", nvme_strerror(errno));
free(bar);
return err;
}
if (nvme_is_64bit_reg(offset))
*(uint64_t *)(bar + offset) = value;
else
*(uint32_t *)(bar + offset) = value;
}
*pbar = bar;
return 0;
}
bool nvme_is_ctrl_reg(int offset)
{
switch (offset) {
case NVME_REG_CAP:
case NVME_REG_VS:
case NVME_REG_INTMS:
case NVME_REG_INTMC:
case NVME_REG_CC:
case NVME_REG_CSTS:
case NVME_REG_NSSR:
case NVME_REG_AQA:
case NVME_REG_ASQ:
case NVME_REG_ACQ:
case NVME_REG_CMBLOC:
case NVME_REG_CMBSZ:
case NVME_REG_BPINFO:
case NVME_REG_BPRSEL:
case NVME_REG_BPMBL:
case NVME_REG_CMBMSC:
case NVME_REG_CMBSTS:
case NVME_REG_CMBEBS:
case NVME_REG_CMBSWTP:
case NVME_REG_NSSD:
case NVME_REG_CRTO:
case NVME_REG_PMRCAP:
case NVME_REG_PMRCTL:
case NVME_REG_PMRSTS:
case NVME_REG_PMREBS:
case NVME_REG_PMRSWTP:
case NVME_REG_PMRMSCL:
case NVME_REG_PMRMSCU:
return true;
default:
break;
}
return false;
}
static bool get_register_offset(void *bar, bool fabrics, struct get_reg_config *cfg,
nvme_print_flags_t flags)
{
bool offset_matched = cfg->offset >= 0;
int offset;
if (offset_matched)
nvme_show_ctrl_register(bar, fabrics, cfg->offset, flags);
for (offset = NVME_REG_CAP; offset <= NVME_REG_PMRMSCU; offset += get_reg_size(offset)) {
if (!nvme_is_ctrl_reg(offset) || offset == cfg->offset || !is_reg_selected(cfg, offset))
continue;
nvme_show_ctrl_register(bar, fabrics, offset, flags);
if (!offset_matched)
offset_matched = true;
}
return offset_matched;
}
static int get_register(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Reads and shows the defined NVMe controller register.\n"
"Register offset must be one of:\n"
"CAP=0x0, VS=0x8, INTMS=0xc, INTMC=0x10, CC=0x14, CSTS=0x1c,\n"
"NSSR=0x20, AQA=0x24, ASQ=0x28, ACQ=0x30, CMBLOC=0x38,\n"
"CMBSZ=0x3c, BPINFO=0x40, BPRSEL=0x44, BPMBL=0x48, CMBMSC=0x50,\n"
"CMBSTS=0x58, CRTO=0x68, PMRCAP=0xe00, PMRCTL=0xe04,\n"
"PMRSTS=0xe08, PMREBS=0xe0c, PMRSWTP=0xe10, PMRMSCL=0xe14, PMRMSCU=0xe18";
const char *human_readable = "show register in readable format";
const char *cap = "CAP=0x0 register offset";
const char *vs = "VS=0x8 register offset";
const char *cmbloc = "CMBLOC=0x38 register offset";
const char *cmbsz = "CMBSZ=0x3c register offset";
const char *bpinfo = "BPINFO=0x40 register offset";
const char *cmbsts = "CMBSTS=0x58 register offset";
const char *cmbebs = "CMBEBS=0x5c register offset";
const char *cmbswtp = "CMBSWTP=0x60 register offset";
const char *crto = "CRTO=0x68 register offset";
const char *pmrcap = "PMRCAP=0xe00 register offset";
const char *pmrsts = "PMRSTS=0xe08 register offset";
const char *pmrebs = "PMREBS=0xe0c register offset";
const char *pmrswtp = "PMRSWTP=0xe10 register offset";
const char *pmrmscl = "PMRMSCL=0xe14 register offset";
const char *pmrmscu = "PMRMSCU=0xe18 register offset";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
bool fabrics = false;
void *bar;
struct get_reg_config cfg = {
.offset = -1,
};
NVME_ARGS(opts,
OPT_UINT("offset", 'O', &cfg.offset, offset),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable),
OPT_FLAG("cap", 0, &cfg.cap, cap),
OPT_FLAG("vs", 0, &cfg.vs, vs),
OPT_FLAG("cmbloc", 0, &cfg.cmbloc, cmbloc),
OPT_FLAG("cmbsz", 0, &cfg.cmbsz, cmbsz),
OPT_FLAG("bpinfo", 0, &cfg.bpinfo, bpinfo),
OPT_FLAG("cmbsts", 0, &cfg.cmbsts, cmbsts),
OPT_FLAG("cmbebs", 0, &cfg.cmbebs, cmbebs),
OPT_FLAG("cmbswtp", 0, &cfg.cmbswtp, cmbswtp),
OPT_FLAG("crto", 0, &cfg.crto, crto),
OPT_FLAG("pmrcap", 0, &cfg.pmrcap, pmrcap),
OPT_FLAG("pmrsts", 0, &cfg.pmrsts, pmrsts),
OPT_FLAG("pmrebs", 0, &cfg.pmrebs, pmrebs),
OPT_FLAG("pmrswtp", 0, &cfg.pmrswtp, pmrswtp),
OPT_FLAG("intms", 0, &cfg.intms, intms),
OPT_FLAG("intmc", 0, &cfg.intmc, intmc),
OPT_FLAG("cc", 0, &cfg.cc, cc),
OPT_FLAG("csts", 0, &cfg.csts, csts),
OPT_FLAG("nssr", 0, &cfg.nssr, nssr),
OPT_FLAG("aqa", 0, &cfg.aqa, aqa),
OPT_FLAG("asq", 0, &cfg.asq, asq),
OPT_FLAG("acq", 0, &cfg.acq, acq),
OPT_FLAG("bprsel", 0, &cfg.bprsel, bprsel),
OPT_FLAG("bpmbl", 0, &cfg.bpmbl, bpmbl),
OPT_FLAG("cmbmsc", 0, &cfg.cmbmsc, cmbmsc),
OPT_FLAG("nssd", 0, &cfg.nssd, nssd),
OPT_FLAG("pmrctl", 0, &cfg.pmrctl, pmrctl),
OPT_FLAG("pmrmscl", 0, &cfg.pmrmscl, pmrmscl),
OPT_FLAG("pmrmscu", 0, &cfg.pmrmscu, pmrmscu));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (is_blkdev(dev)) {
nvme_show_error("Only character device is allowed");
return -EINVAL;
}
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
bar = mmap_registers(dev, false);
if (!bar) {
err = get_register_properties(dev_fd(dev), &bar, &cfg);
if (err)
return err;
fabrics = true;
}
nvme_show_init();
if (!get_register_offset(bar, fabrics, &cfg, flags)) {
nvme_show_error("offset required param");
err = -EINVAL;
}
nvme_show_finish();
if (fabrics)
free(bar);
else
munmap(bar, getpagesize());
return err;
}
static int nvme_set_single_property(int fd, int offset, uint64_t value)
{
struct nvme_set_property_args args = {
.args_size = sizeof(args),
.fd = fd,
.offset = offset,
.value = value,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
int err = nvme_set_property(&args);
if (err < 0)
nvme_show_error("set-property: %s", nvme_strerror(errno));
else if (!err)
printf("set-property: %#02x (%s), value: %#"PRIx64"\n", offset,
nvme_register_to_string(offset), value);
else if (err > 0)
nvme_show_status(err);
return err;
}
static int set_register_property(int fd, int offset, uint64_t value)
{
if (!nvme_is_fabrics_reg(offset)) {
printf("register: %#04x (%s) not fabrics\n", offset,
nvme_register_to_string(offset));
return -EINVAL;
}
return nvme_set_single_property(fd, offset, value);
}
static int nvme_set_register(int fd, void *bar, int offset, uint64_t value, bool mmio32)
{
if (!bar)
return set_register_property(fd, offset, value);
if (nvme_is_64bit_reg(offset))
mmio_write64(bar + offset, value, mmio32);
else
mmio_write32(bar + offset, value);
printf("set-register: %#02x (%s), value: %#"PRIx64"\n", offset,
nvme_register_to_string(offset), value);
return 0;
}
static inline int set_register_names_check(struct argconfig_commandline_options *opts, int offset)
{
switch (offset) {
case NVME_REG_INTMS:
if (argconfig_parse_seen(opts, "intms"))
return -EINVAL;
break;
case NVME_REG_INTMC:
if (argconfig_parse_seen(opts, "intmc"))
return -EINVAL;
break;
case NVME_REG_CC:
if (argconfig_parse_seen(opts, "cc"))
return -EINVAL;
break;
case NVME_REG_CSTS:
if (argconfig_parse_seen(opts, "csts"))
return -EINVAL;
break;
case NVME_REG_NSSR:
if (argconfig_parse_seen(opts, "nssr"))
return -EINVAL;
break;
case NVME_REG_AQA:
if (argconfig_parse_seen(opts, "aqa"))
return -EINVAL;
break;
case NVME_REG_ASQ:
if (argconfig_parse_seen(opts, "asq"))
return -EINVAL;
break;
case NVME_REG_ACQ:
if (argconfig_parse_seen(opts, "acq"))
return -EINVAL;
break;
case NVME_REG_BPRSEL:
if (argconfig_parse_seen(opts, "bprsel"))
return -EINVAL;
break;
case NVME_REG_CMBMSC:
if (argconfig_parse_seen(opts, "cmbmsc"))
return -EINVAL;
break;
case NVME_REG_NSSD:
if (argconfig_parse_seen(opts, "nssd"))
return -EINVAL;
break;
case NVME_REG_PMRCTL:
if (argconfig_parse_seen(opts, "pmrctl"))
return -EINVAL;
break;
case NVME_REG_PMRMSCL:
if (argconfig_parse_seen(opts, "pmrmscl"))
return -EINVAL;
break;
case NVME_REG_PMRMSCU:
if (argconfig_parse_seen(opts, "pmrmscu"))
return -EINVAL;
break;
default:
break;
}
return 0;
}
static int set_register_offset(int fd, void *bar, struct argconfig_commandline_options *opts,
struct set_reg_config *cfg)
{
int err;
if (!argconfig_parse_seen(opts, "value")) {
nvme_show_error("value required param");
return -EINVAL;
}
err = set_register_names_check(opts, cfg->offset);
if (err) {
nvme_show_error("offset duplicated param");
return err;
}
err = nvme_set_register(fd, bar, cfg->offset, cfg->value, cfg->mmio32);
if (err)
return err;
return 0;
}
static int set_register_names(int fd, void *bar, struct argconfig_commandline_options *opts,
struct set_reg_config *cfg)
{
int err;
if (argconfig_parse_seen(opts, "intms")) {
err = nvme_set_register(fd, bar, NVME_REG_INTMS, cfg->intms, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "intmc")) {
err = nvme_set_register(fd, bar, NVME_REG_INTMC, cfg->intmc, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "cc")) {
err = nvme_set_register(fd, bar, NVME_REG_CC, cfg->cc, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "csts")) {
err = nvme_set_register(fd, bar, NVME_REG_CSTS, cfg->csts, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "nssr")) {
err = nvme_set_register(fd, bar, NVME_REG_NSSR, cfg->nssr, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "aqa")) {
err = nvme_set_register(fd, bar, NVME_REG_AQA, cfg->aqa, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "asq")) {
err = nvme_set_register(fd, bar, NVME_REG_ASQ, cfg->asq, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "acq")) {
err = nvme_set_register(fd, bar, NVME_REG_ACQ, cfg->acq, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "bprsel")) {
err = nvme_set_register(fd, bar, NVME_REG_BPRSEL, cfg->bprsel, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "cmbmsc")) {
err = nvme_set_register(fd, bar, NVME_REG_CMBMSC, cfg->cmbmsc, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "nssd")) {
err = nvme_set_register(fd, bar, NVME_REG_NSSD, cfg->nssd, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "pmrctl")) {
err = nvme_set_register(fd, bar, NVME_REG_PMRCTL, cfg->pmrctl, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "pmrmscl")) {
err = nvme_set_register(fd, bar, NVME_REG_PMRMSCL, cfg->pmrmscl, cfg->mmio32);
if (err)
return err;
}
if (argconfig_parse_seen(opts, "pmrmscu")) {
err = nvme_set_register(fd, bar, NVME_REG_PMRMSCU, cfg->pmrmscu, cfg->mmio32);
if (err)
return err;
}
return 0;
}
static int set_register(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Writes and shows the defined NVMe controller register";
const char *value = "the value of the register to be set";
const char *mmio32 = "Access 64-bit registers as 2 32-bit";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
void *bar;
struct set_reg_config cfg = {
.offset = -1,
};
NVME_ARGS(opts,
OPT_UINT("offset", 'O', &cfg.offset, offset),
OPT_SUFFIX("value", 'V', &cfg.value, value),
OPT_FLAG("mmio32", 'm', &cfg.mmio32, mmio32),
OPT_UINT("intms", 0, &cfg.intms, intms),
OPT_UINT("intmc", 0, &cfg.intmc, intmc),
OPT_UINT("cc", 0, &cfg.cc, cc),
OPT_UINT("csts", 0, &cfg.csts, csts),
OPT_UINT("nssr", 0, &cfg.nssr, nssr),
OPT_UINT("aqa", 0, &cfg.aqa, aqa),
OPT_SUFFIX("asq", 0, &cfg.asq, asq),
OPT_SUFFIX("acq", 0, &cfg.acq, acq),
OPT_UINT("bprsel", 0, &cfg.bprsel, bprsel),
OPT_SUFFIX("bpmbl", 0, &cfg.bpmbl, bpmbl),
OPT_SUFFIX("cmbmsc", 0, &cfg.cmbmsc, cmbmsc),
OPT_UINT("nssd", 0, &cfg.nssd, nssd),
OPT_UINT("pmrctl", 0, &cfg.pmrctl, pmrctl),
OPT_UINT("pmrmscl", 0, &cfg.pmrmscl, pmrmscl),
OPT_UINT("pmrmscu", 0, &cfg.pmrmscu, pmrmscu));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (is_blkdev(dev)) {
nvme_show_error("Only character device is allowed");
return -EINVAL;
}
bar = mmap_registers(dev, true);
if (argconfig_parse_seen(opts, "offset"))
err = set_register_offset(dev_fd(dev), bar, opts, &cfg);
if (!err)
err = set_register_names(dev_fd(dev), bar, opts, &cfg);
if (bar)
munmap(bar, getpagesize());
return err;
}
static int get_property(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Reads and shows the defined NVMe controller property\n"
"for NVMe over Fabric. Property offset must be one of:\n"
"CAP=0x0, VS=0x8, CC=0x14, CSTS=0x1c, NSSR=0x20, NSSD=0x64, CRTO=0x68";
const char *offset = "offset of the requested property";
const char *human_readable = "show property in readable format";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u64 value;
int err;
nvme_print_flags_t flags = NORMAL;
struct get_reg_config cfg = {
.offset = -1,
.human_readable = false,
.fabrics = true,
};
NVME_ARGS(opts,
OPT_UINT("offset", 'O', &cfg.offset, offset),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.offset == -1) {
nvme_show_error("offset required param");
return -EINVAL;
}
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
err = nvme_get_single_property(dev_fd(dev), &cfg, &value);
if (!err)
nvme_show_single_property(cfg.offset, value, flags);
return err;
}
static int set_property(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc =
"Writes and shows the defined NVMe controller property for NVMe over Fabric";
const char *offset = "the offset of the property";
const char *value = "the value of the property to be set";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
struct set_reg_config cfg = {
.offset = -1,
.value = -1,
};
NVME_ARGS(opts,
OPT_UINT("offset", 'O', &cfg.offset, offset),
OPT_UINT("value", 'V', &cfg.value, value));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.offset == -1) {
nvme_show_error("offset required param");
return -EINVAL;
}
if (cfg.value == -1) {
nvme_show_error("value required param");
return -EINVAL;
}
return nvme_set_single_property(dev_fd(dev), cfg.offset, cfg.value);
}
static void show_relatives(const char *name, nvme_print_flags_t flags)
{
int err = 0;
_cleanup_nvme_root_ nvme_root_t r = nvme_create_root(stderr, log_level);
if (!r) {
nvme_show_error("Failed to create topology root: %s", nvme_strerror(errno));
return;
}
err = nvme_scan_topology(r, NULL, NULL);
if (err < 0) {
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
return;
}
nvme_show_relatives(r, name, flags);
}
static int format_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Re-format a specified namespace on the\n"
"given device. Can erase all data in namespace (user\n"
"data erase) or delete data encryption key if specified.\n"
"Can also be used to change LBAF to change the namespaces reported physical block format.";
const char *lbaf = "LBA format to apply (required)";
const char *ses = "[0-2]: secure erase";
const char *pil = "[0-1]: protection info location last/first bytes of metadata";
const char *pi = "[0-3]: protection info off/Type 1/Type 2/Type 3";
const char *ms = "[0-1]: extended format off/on";
const char *reset = "Automatically reset the controller after successful format";
const char *bs = "target block size";
const char *force = "The \"I know what I'm doing\" flag, skip confirmation before sending command";
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u32 timeout_ms = 600000;
__u8 prev_lbaf = 0;
int block_size;
int err, i;
nvme_print_flags_t flags = NORMAL;
struct config {
__u32 namespace_id;
__u8 lbaf;
__u8 ses;
__u8 pi;
__u8 pil;
__u8 ms;
bool reset;
bool force;
__u64 bs;
};
struct config cfg = {
.namespace_id = 0,
.lbaf = 0xff,
.ses = 0,
.pi = 0,
.pil = 0,
.ms = 0,
.reset = false,
.force = false,
.bs = 0,
};
if (nvme_cfg.timeout != NVME_DEFAULT_IOCTL_TIMEOUT)
timeout_ms = nvme_cfg.timeout;
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_BYTE("lbaf", 'l', &cfg.lbaf, lbaf),
OPT_BYTE("ses", 's', &cfg.ses, ses),
OPT_BYTE("pi", 'i', &cfg.pi, pi),
OPT_BYTE("pil", 'p', &cfg.pil, pil),
OPT_BYTE("ms", 'm', &cfg.ms, ms),
OPT_FLAG("reset", 'r', &cfg.reset, reset),
OPT_FLAG("force", 0, &cfg.force, force),
OPT_SUFFIX("block-size", 'b', &cfg.bs, bs));
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
err = open_exclusive(&dev, argc, argv, cfg.force);
if (err) {
if (errno == EBUSY) {
fprintf(stderr, "Failed to open %s.\n", basename(argv[optind]));
fprintf(stderr, "Namespace is currently busy.\n");
if (!cfg.force)
fprintf(stderr, "Use the force [--force] option to ignore that.\n");
} else {
argconfig_print_help(desc, opts);
}
return err;
}
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.lbaf != 0xff && cfg.bs != 0) {
nvme_show_error(
"Invalid specification of both LBAF and Block Size, please specify only one");
return -EINVAL;
}
if (cfg.bs) {
if ((cfg.bs & (~cfg.bs + 1)) != cfg.bs) {
nvme_show_error(
"Invalid value for block size (%"PRIu64"), must be a power of two",
(uint64_t) cfg.bs);
return -EINVAL;
}
}
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err) {
nvme_show_error("identify-ctrl: %s", nvme_strerror(errno));
return -errno;
}
if (ctrl->fna & NVME_CTRL_FNA_FMT_ALL_NAMESPACES) {
/*
* FNA bit 0 set to 1: all namespaces ... shall be configured with the same
* attributes and a format (excluding secure erase) of any namespace results in a
* format of all namespaces.
*/
cfg.namespace_id = NVME_NSID_ALL;
} else if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return -errno;
}
}
if (cfg.namespace_id == 0) {
nvme_show_error(
"Invalid namespace ID, specify a namespace to format or use\n"
"'-n 0xffffffff' to format all namespaces on this controller.");
return -EINVAL;
}
if (cfg.namespace_id != NVME_NSID_ALL) {
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
if (err) {
if (err < 0) {
nvme_show_error("identify-namespace: %s", nvme_strerror(errno));
} else {
fprintf(stderr, "identify failed\n");
nvme_show_status(err);
}
return err;
}
nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &prev_lbaf);
if (cfg.bs) {
for (i = 0; i <= ns->nlbaf; ++i) {
if ((1ULL << ns->lbaf[i].ds) == cfg.bs && ns->lbaf[i].ms == 0) {
cfg.lbaf = i;
break;
}
}
if (cfg.lbaf == 0xff) {
fprintf(stderr,
"LBAF corresponding to given block size %"PRIu64" not found\n",
(uint64_t)cfg.bs);
fprintf(stderr,
"Please correct block size, or specify LBAF directly\n");
return -EINVAL;
}
} else if (cfg.lbaf == 0xff) {
cfg.lbaf = prev_lbaf;
}
} else {
if (cfg.lbaf == 0xff)
cfg.lbaf = 0;
}
/* ses & pi checks set to 7 for forward-compatibility */
if (cfg.ses > 7) {
nvme_show_error("invalid secure erase settings:%d", cfg.ses);
return -EINVAL;
}
if (cfg.lbaf > 63) {
nvme_show_error("invalid lbaf:%d", cfg.lbaf);
return -EINVAL;
}
if (cfg.pi > 7) {
nvme_show_error("invalid pi:%d", cfg.pi);
return -EINVAL;
}
if (cfg.pil > 1) {
nvme_show_error("invalid pil:%d", cfg.pil);
return -EINVAL;
}
if (cfg.ms > 1) {
nvme_show_error("invalid ms:%d", cfg.ms);
return -EINVAL;
}
if (!cfg.force) {
fprintf(stderr, "You are about to format %s, namespace %#x%s.\n",
dev->name, cfg.namespace_id,
cfg.namespace_id == NVME_NSID_ALL ? "(ALL namespaces)" : "");
show_relatives(dev->name, flags);
fprintf(stderr,
"WARNING: Format may irrevocably delete this device's data.\n"
"You have 10 seconds to press Ctrl-C to cancel this operation.\n\n"
"Use the force [--force] option to suppress this warning.\n");
sleep(10);
fprintf(stderr, "Sending format operation ...\n");
}
struct nvme_format_nvm_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.lbafu = (cfg.lbaf >> 4) & 0x3,
.lbaf = cfg.lbaf & 0xf,
.mset = cfg.ms,
.pi = cfg.pi,
.pil = cfg.pil,
.ses = cfg.ses,
.timeout = timeout_ms,
.result = NULL,
};
err = nvme_cli_format_nvm(dev, &args);
if (err < 0) {
nvme_show_error("format: %s", nvme_strerror(errno));
} else if (err != 0) {
nvme_show_status(err);
} else {
printf("Success formatting namespace:%x\n", cfg.namespace_id);
if (dev->type == NVME_DEV_DIRECT && cfg.lbaf != prev_lbaf) {
if (is_chardev(dev)) {
if (ioctl(dev_fd(dev), NVME_IOCTL_RESCAN) < 0) {
nvme_show_error("failed to rescan namespaces");
return -errno;
}
} else if (cfg.namespace_id != NVME_NSID_ALL) {
block_size = 1 << ns->lbaf[cfg.lbaf].ds;
/*
* If block size has been changed by the format
* command up there, we should notify it to
* kernel blkdev to update its own block size
* to the given one because blkdev will not
* update by itself without re-opening fd.
*/
if (ioctl(dev_fd(dev), BLKBSZSET, &block_size) < 0) {
nvme_show_error("failed to set block size to %d",
block_size);
return -errno;
}
if (ioctl(dev_fd(dev), BLKRRPART) < 0) {
nvme_show_error("failed to re-read partition table");
return -errno;
}
}
}
if (dev->type == NVME_DEV_DIRECT && cfg.reset && is_chardev(dev))
nvme_ctrl_reset(dev_fd(dev));
}
return err;
}
#define STRTOUL_AUTO_BASE (0)
#define NVME_FEAT_TIMESTAMP_DATA_SIZE (6)
static int set_feature(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Modify the saveable or changeable "
"current operating parameters of the controller. "
"Operating parameters are grouped and identified by Feature"
"Identifiers. Feature settings can be applied to the entire"
"controller and all associated namespaces, or to only a few"
"namespace(s) associated with the controller. Default values"
"for each Feature are vendor-specific and may not be modified."
"Use get-feature to determine which Features are supported by"
"the controller and are saveable/changeable.";
const char *feature_id = "feature identifier (required)";
const char *data = "optional file for feature data (default stdin)";
const char *value = "new value of feature (required)";
const char *cdw12 = "feature cdw12, if used";
const char *save = "specifies that the controller shall save the attribute";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *buf = NULL;
_cleanup_fd_ int ffd = STDIN_FILENO;
int err;
__u32 result;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
__u8 feature_id;
__u64 value;
__u32 cdw12;
__u8 uuid_index;
__u32 data_len;
char *file;
bool save;
};
struct config cfg = {
.namespace_id = 0,
.feature_id = 0,
.value = 0,
.uuid_index = 0,
.data_len = 0,
.file = "",
.save = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_BYTE("feature-id", 'f', &cfg.feature_id, feature_id, feature_name),
OPT_SUFFIX("value", 'V', &cfg.value, value),
OPT_UINT("cdw12", 'c', &cfg.cdw12, cdw12),
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index_specify),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_FLAG("save", 's', &cfg.save, save));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!argconfig_parse_seen(opts, "namespace-id")) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
if (errno != ENOTTY) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return -errno;
}
cfg.namespace_id = NVME_NSID_ALL;
}
}
if (!cfg.feature_id) {
nvme_show_error("feature-id required param");
return -EINVAL;
}
if (cfg.uuid_index > 127) {
nvme_show_error("invalid uuid index param: %u", cfg.uuid_index);
return -1;
}
if (!cfg.data_len)
nvme_cli_get_feature_length2(cfg.feature_id, cfg.value,
NVME_DATA_TFR_HOST_TO_CTRL,
&cfg.data_len);
if (cfg.data_len) {
buf = nvme_alloc(cfg.data_len);
if (!buf)
return -ENOMEM;
}
if (buf) {
/*
* Use the '-v' value for the timestamp feature if provided as
* a convenience since it can often fit in 4-bytes. The user
* should use the buffer method if the value exceeds this
* length.
*/
if (cfg.feature_id == NVME_FEAT_FID_TIMESTAMP &&
argconfig_parse_seen(opts, "value")) {
memcpy(buf, &cfg.value, NVME_FEAT_TIMESTAMP_DATA_SIZE);
} else {
if (strlen(cfg.file))
ffd = open(cfg.file, O_RDONLY);
if (ffd < 0) {
nvme_show_error("Failed to open file %s: %s",
cfg.file, strerror(errno));
return -EINVAL;
}
err = read(ffd, buf, cfg.data_len);
if (err < 0) {
nvme_show_error("failed to read data buffer from input file: %s",
strerror(errno));
return -errno;
}
}
}
struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.fid = cfg.feature_id,
.nsid = cfg.namespace_id,
.cdw11 = cfg.value,
.cdw12 = cfg.cdw12,
.save = cfg.save,
.uuidx = cfg.uuid_index,
.cdw15 = 0,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_set_features(&args);
if (err < 0) {
nvme_show_error("set-feature: %s", nvme_strerror(errno));
} else if (!err) {
printf("set-feature:%#0*x (%s), value:%#0*"PRIx64", cdw12:%#0*x, save:%#x\n",
cfg.feature_id ? 4 : 2, cfg.feature_id,
nvme_feature_to_string(cfg.feature_id),
cfg.value ? 10 : 8, (uint64_t)cfg.value,
cfg.cdw12 ? 10 : 8, cfg.cdw12, cfg.save);
if (cfg.feature_id == NVME_FEAT_FID_LBA_STS_INTERVAL)
nvme_show_lba_status_info(result);
if (buf) {
if (cfg.feature_id == NVME_FEAT_FID_LBA_RANGE)
nvme_show_lba_range((struct nvme_lba_range_type *)buf, result, 0);
else
d(buf, cfg.data_len, 16, 1);
}
} else if (err > 0) {
nvme_show_status(err);
}
return err;
}
static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
struct stat sb;
const char *desc = "Transfer security protocol data to\n"
"a controller. Security Receives for the same protocol should be\n"
"performed after Security Sends. The security protocol field\n"
"associates Security Sends (security-send) and Security Receives (security-recv).";
const char *file = "transfer payload";
const char *tl = "transfer length (cf. SPC-4)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *sec_buf = NULL;
_cleanup_fd_ int sec_fd = -1;
unsigned int sec_size;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
char *file;
__u8 nssf;
__u8 secp;
__u16 spsp;
__u32 tl;
};
struct config cfg = {
.namespace_id = 0,
.file = "",
.nssf = 0,
.secp = 0,
.spsp = 0,
.tl = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_FILE("file", 'f', &cfg.file, file),
OPT_BYTE("nssf", 'N', &cfg.nssf, nssf),
OPT_BYTE("secp", 'p', &cfg.secp, secp),
OPT_SHRT("spsp", 's', &cfg.spsp, spsp),
OPT_UINT("tl", 't', &cfg.tl, tl));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.tl == 0) {
nvme_show_error("--tl unspecified or zero");
return -EINVAL;
}
if ((cfg.tl & 3) != 0)
nvme_show_error(
"WARNING: --tl not dword aligned; unaligned bytes may be truncated");
if (strlen(cfg.file) == 0) {
sec_fd = STDIN_FILENO;
sec_size = cfg.tl;
} else {
sec_fd = open(cfg.file, O_RDONLY);
if (sec_fd < 0) {
nvme_show_error("Failed to open %s: %s", cfg.file, strerror(errno));
return -EINVAL;
}
err = fstat(sec_fd, &sb);
if (err < 0) {
nvme_show_perror("fstat");
return err;
}
sec_size = cfg.tl > sb.st_size ? cfg.tl : sb.st_size;
}
sec_buf = nvme_alloc(cfg.tl);
if (!sec_buf)
return -ENOMEM;
err = read(sec_fd, sec_buf, sec_size);
if (err < 0) {
nvme_show_error("Failed to read data from security file %s with %s", cfg.file,
strerror(errno));
return -errno;
}
struct nvme_security_send_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.nssf = cfg.nssf,
.spsp0 = cfg.spsp & 0xff,
.spsp1 = cfg.spsp >> 8,
.secp = cfg.secp,
.tl = cfg.tl,
.data_len = cfg.tl,
.data = sec_buf,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_cli_security_send(dev, &args);
if (err < 0)
nvme_show_error("security-send: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVME Security Send Command Success\n");
return err;
}
static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Set directive parameters of the specified directive type.";
const char *endir = "directive enable";
const char *ttype = "target directive type to be enabled/disabled";
const char *input = "write/send file (default stdin)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *buf = NULL;
__u32 result;
__u32 dw12 = 0;
_cleanup_fd_ int ffd = STDIN_FILENO;
int err;
struct config {
__u32 namespace_id;
__u32 data_len;
__u8 dtype;
__u8 ttype;
__u16 dspec;
__u8 doper;
__u16 endir;
bool human_readable;
bool raw_binary;
char *file;
};
struct config cfg = {
.namespace_id = 1,
.data_len = 0,
.dtype = 0,
.ttype = 0,
.dspec = 0,
.doper = 0,
.endir = 1,
.human_readable = false,
.raw_binary = false,
.file = "",
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
OPT_BYTE("dir-type", 'D', &cfg.dtype, dtype),
OPT_BYTE("target-dir", 'T', &cfg.ttype, ttype),
OPT_SHRT("dir-spec", 'S', &cfg.dspec, dspec_w_dtype),
OPT_BYTE("dir-oper", 'O', &cfg.doper, doper),
OPT_SHRT("endir", 'e', &cfg.endir, endir),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, deprecated),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_directive),
OPT_FILE("input-file", 'i', &cfg.file, input));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
switch (cfg.dtype) {
case NVME_DIRECTIVE_DTYPE_IDENTIFY:
switch (cfg.doper) {
case NVME_DIRECTIVE_SEND_IDENTIFY_DOPER_ENDIR:
if (!cfg.ttype) {
nvme_show_error("target-dir required param\n");
return -EINVAL;
}
dw12 = cfg.ttype << 8 | cfg.endir;
break;
default:
nvme_show_error("invalid directive operations for Identify Directives");
return -EINVAL;
}
break;
case NVME_DIRECTIVE_DTYPE_STREAMS:
switch (cfg.doper) {
case NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_IDENTIFIER:
case NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE:
break;
default:
nvme_show_error("invalid directive operations for Streams Directives");
return -EINVAL;
}
break;
default:
nvme_show_error("invalid directive type");
return -EINVAL;
}
if (cfg.data_len) {
buf = nvme_alloc(cfg.data_len);
if (!buf)
return -ENOMEM;
}
if (buf) {
if (strlen(cfg.file)) {
ffd = open(cfg.file, O_RDONLY);
if (ffd <= 0) {
nvme_show_error("Failed to open file %s: %s",
cfg.file, strerror(errno));
return -EINVAL;
}
}
err = read(ffd, (void *)buf, cfg.data_len);
if (err < 0) {
nvme_show_error("failed to read data buffer from input file %s",
strerror(errno));
return -errno;
}
}
struct nvme_directive_send_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.dspec = cfg.dspec,
.doper = cfg.doper,
.dtype = cfg.dtype,
.cdw12 = dw12,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_directive_send(&args);
if (err < 0) {
nvme_show_error("dir-send: %s", nvme_strerror(errno));
return err;
}
if (!err) {
printf("dir-send: type %#x, operation %#x, spec_val %#x, nsid %#x, result %#x\n",
cfg.dtype, cfg.doper, cfg.dspec, cfg.namespace_id, result);
if (buf) {
if (!cfg.raw_binary)
d(buf, cfg.data_len, 16, 1);
else
d_raw(buf, cfg.data_len);
}
} else if (err > 0) {
nvme_show_status(err);
}
return err;
}
static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc =
"The Write Uncorrectable command is used to set a range of logical blocks to invalid.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
struct config {
__u32 namespace_id;
__u64 start_block;
__u16 block_count;
__u8 dtype;
__u16 dspec;
};
struct config cfg = {
.namespace_id = 0,
.start_block = 0,
.block_count = 0,
.dtype = 0,
.dspec = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_SUFFIX("start-block", 's', &cfg.start_block, start_block),
OPT_SHRT("block-count", 'c', &cfg.block_count, block_count),
OPT_BYTE("dir-type", 'T', &cfg.dtype, dtype),
OPT_SHRT("dir-spec", 'S', &cfg.dspec, dspec_w_dtype));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
if (cfg.dtype > 0xf) {
nvme_show_error("Invalid directive type, %x", cfg.dtype);
return -EINVAL;
}
struct nvme_io_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.slba = cfg.start_block,
.nlb = cfg.block_count,
.control = cfg.dtype << 4,
.dspec = cfg.dspec,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_write_uncorrectable(&args);
if (err < 0)
nvme_show_error("write uncorrectable: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVME Write Uncorrectable Success\n");
return err;
}
static int invalid_tags(__u64 storage_tag, __u64 ref_tag, __u8 sts, __u8 pif)
{
int result = 0;
if (sts < 64 && storage_tag >= (1LL << sts)) {
nvme_show_error("Storage tag larger than storage tag size");
return 1;
}
switch (pif) {
case NVME_NVM_PIF_16B_GUARD:
if (ref_tag >= (1LL << (32 - sts)))
result = 1;
break;
case NVME_NVM_PIF_32B_GUARD:
if (sts > 16 && ref_tag >= (1LL << (80 - sts)))
result = 1;
break;
case NVME_NVM_PIF_64B_GUARD:
if (sts > 0 && ref_tag >= (1LL << (48 - sts)))
result = 1;
break;
default:
nvme_show_error("Invalid PIF");
result = 1;
break;
}
if (result)
nvme_show_error("Reference tag larger than allowed by PIF");
return result;
}
static void get_pif_sts(struct nvme_id_ns *ns, struct nvme_nvm_id_ns *nvm_ns, __u8 *pif, __u8 *sts)
{
__u8 lba_index;
__u32 elbaf;
nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index);
elbaf = le32_to_cpu(nvm_ns->elbaf[lba_index]);
*sts = elbaf & NVME_NVM_ELBAF_STS_MASK;
*pif = (elbaf & NVME_NVM_ELBAF_PIF_MASK) >> 7;
if (*pif == NVME_NVM_PIF_QTYPE && (nvm_ns->pic & 0x8))
*pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9;
}
static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
_cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u8 sts = 0, pif = 0;
__u16 control = 0;
__u32 result = 0;
int err;
const char *desc =
"The Write Zeroes command is used to set a range of logical blocks to zero.";
const char *deac =
"Set DEAC bit, requesting controller to deallocate specified logical blocks";
const char *storage_tag_check =
"This bit specifies the Storage Tag field shall be checked as\n"
"part of end-to-end data protection processing";
const char *nsz = "Clear all logical blocks to zero in the entire namespace";
struct config {
__u32 namespace_id;
__u64 start_block;
__u16 block_count;
__u8 dtype;
bool deac;
bool limited_retry;
bool force_unit_access;
__u8 prinfo;
__u64 ref_tag;
__u16 app_tag_mask;
__u16 app_tag;
__u64 storage_tag;
bool storage_tag_check;
__u16 dspec;
bool nsz;
};
struct config cfg = {
.namespace_id = 0,
.start_block = 0,
.block_count = 0,
.dtype = 0,
.deac = false,
.limited_retry = false,
.force_unit_access = false,
.prinfo = 0,
.ref_tag = 0,
.app_tag_mask = 0,
.app_tag = 0,
.storage_tag = 0,
.storage_tag_check = false,
.dspec = 0,
.nsz = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_SUFFIX("start-block", 's', &cfg.start_block, start_block),
OPT_SHRT("block-count", 'c', &cfg.block_count, block_count),
OPT_BYTE("dir-type", 'T', &cfg.dtype, dtype),
OPT_FLAG("deac", 'd', &cfg.deac, deac),
OPT_FLAG("limited-retry", 'l', &cfg.limited_retry, limited_retry),
OPT_FLAG("force-unit-access", 'f', &cfg.force_unit_access, force_unit_access),
OPT_BYTE("prinfo", 'p', &cfg.prinfo, prinfo),
OPT_SUFFIX("ref-tag", 'r', &cfg.ref_tag, ref_tag),
OPT_SHRT("app-tag-mask", 'm', &cfg.app_tag_mask, app_tag_mask),
OPT_SHRT("app-tag", 'a', &cfg.app_tag, app_tag),
OPT_SUFFIX("storage-tag", 'S', &cfg.storage_tag, storage_tag),
OPT_FLAG("storage-tag-check", 'C', &cfg.storage_tag_check, storage_tag_check),
OPT_SHRT("dir-spec", 'D', &cfg.dspec, dspec_w_dtype),
OPT_FLAG("namespace-zeroes", 'Z', &cfg.nsz, nsz));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (cfg.prinfo > 0xf)
return -EINVAL;
if (cfg.dtype > 0x7) {
nvme_show_error("Invalid directive type, %x", cfg.dtype);
return -EINVAL;
}
control |= (cfg.prinfo << 10);
if (cfg.limited_retry)
control |= NVME_IO_LR;
if (cfg.force_unit_access)
control |= NVME_IO_FUA;
if (cfg.deac)
control |= NVME_IO_DEAC;
if (cfg.storage_tag_check)
control |= NVME_IO_STC;
if (cfg.nsz)
control |= NVME_IO_NSZ;
control |= (cfg.dtype << 4);
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
if (err < 0) {
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_status(err);
return err;
}
nvm_ns = nvme_alloc(sizeof(*nvm_ns));
if (!nvm_ns)
return -ENOMEM;
err = nvme_identify_ns_csi(dev_fd(dev), cfg.namespace_id, 0, NVME_CSI_NVM, nvm_ns);
if (!err) {
get_pif_sts(ns, nvm_ns, &pif, &sts);
}
if (invalid_tags(cfg.storage_tag, cfg.ref_tag, sts, pif))
return -EINVAL;
struct nvme_io_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.slba = cfg.start_block,
.nlb = cfg.block_count,
.control = control,
.reftag = (__u32)cfg.ref_tag,
.reftag_u64 = cfg.ref_tag,
.apptag = cfg.app_tag,
.appmask = cfg.app_tag_mask,
.sts = sts,
.pif = pif,
.storage_tag = cfg.storage_tag,
.dspec = cfg.dspec,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_write_zeros(&args);
if (err < 0)
nvme_show_error("write-zeroes: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else {
printf("NVME Write Zeroes Success\n");
if (cfg.nsz && argconfig_parse_seen(opts, "verbose")) {
if (result & 0x1)
printf("All logical blocks in the entire namespace cleared to zero\n");
else
printf("%d logical blocks cleared to zero\n", cfg.block_count);
}
}
return err;
}
static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "The Dataset Management command is used by the host to\n"
"indicate attributes for ranges of logical blocks. This includes attributes\n"
"for discarding unused blocks, data read and write frequency, access size, and other\n"
"information that may be used to optimize performance and reliability.";
const char *blocks = "Comma separated list of the number of blocks in each range";
const char *starting_blocks = "Comma separated list of the starting block in each range";
const char *context_attrs = "Comma separated list of the context attributes in each range";
const char *ad = "Attribute Deallocate";
const char *idw = "Attribute Integral Dataset for Write";
const char *idr = "Attribute Integral Dataset for Read";
const char *cdw11 = "All the command DWORD 11 attributes. Use instead of specifying individual attributes";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_dsm_range *dsm = NULL;
uint16_t nr, nc, nb, ns;
__u32 ctx_attrs[256] = {0,};
__u32 nlbs[256] = {0,};
__u64 slbas[256] = {0,};
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
char *ctx_attrs;
char *blocks;
char *slbas;
bool ad;
bool idw;
bool idr;
__u32 cdw11;
};
struct config cfg = {
.namespace_id = 0,
.ctx_attrs = "",
.blocks = "",
.slbas = "",
.ad = false,
.idw = false,
.idr = false,
.cdw11 = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_LIST("ctx-attrs", 'a', &cfg.ctx_attrs, context_attrs),
OPT_LIST("blocks", 'b', &cfg.blocks, blocks),
OPT_LIST("slbs", 's', &cfg.slbas, starting_blocks),
OPT_FLAG("ad", 'd', &cfg.ad, ad),
OPT_FLAG("idw", 'w', &cfg.idw, idw),
OPT_FLAG("idr", 'r', &cfg.idr, idr),
OPT_UINT("cdw11", 'c', &cfg.cdw11, cdw11));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
nc = argconfig_parse_comma_sep_array_u32(cfg.ctx_attrs, ctx_attrs, ARRAY_SIZE(ctx_attrs));
nb = argconfig_parse_comma_sep_array_u32(cfg.blocks, nlbs, ARRAY_SIZE(nlbs));
ns = argconfig_parse_comma_sep_array_u64(cfg.slbas, slbas, ARRAY_SIZE(slbas));
nr = max(nc, max(nb, ns));
if (!nr || nr > 256) {
nvme_show_error("No range definition provided");
return -EINVAL;
}
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
if (!cfg.cdw11)
cfg.cdw11 = (cfg.ad << 2) | (cfg.idw << 1) | (cfg.idr << 0);
dsm = nvme_alloc(sizeof(*dsm) * 256);
if (!dsm)
return -ENOMEM;
nvme_init_dsm_range(dsm, ctx_attrs, nlbs, slbas, nr);
struct nvme_dsm_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.attrs = cfg.cdw11,
.nr_ranges = nr,
.dsm = dsm,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_dsm(&args);
if (err < 0)
nvme_show_error("data-set management: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVMe DSM: success\n");
return err;
}
static int copy_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "The Copy command is used by the host to copy data\n"
"from one or more source logical block ranges to a\n"
"single consecutive destination logical block range.";
const char *d_sdlba = "64-bit addr of first destination logical block";
const char *d_slbas = "64-bit addr of first block per range (comma-separated list)";
const char *d_nlbs = "number of blocks per range (comma-separated list, zeroes-based values)";
const char *d_snsids = "source namespace identifier per range (comma-separated list)";
const char *d_sopts = "source options per range (comma-separated list)";
const char *d_lr = "limited retry";
const char *d_fua = "force unit access";
const char *d_prinfor = "protection information and check field (read part)";
const char *d_prinfow = "protection information and check field (write part)";
const char *d_ilbrt = "initial lba reference tag (write part)";
const char *d_eilbrts = "expected lba reference tags (read part, comma-separated list)";
const char *d_lbat = "lba application tag (write part)";
const char *d_elbats = "expected lba application tags (read part, comma-separated list)";
const char *d_lbatm = "lba application tag mask (write part)";
const char *d_elbatms = "expected lba application tag masks (read part, comma-separated list)";
const char *d_dtype = "directive type (write part)";
const char *d_dspec = "directive specific (write part)";
const char *d_format = "source range entry format";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u16 nr, nb, ns, nrts, natms, nats, nids;
__u16 nlbs[256] = { 0 };
__u64 slbas[256] = { 0 };
__u32 snsids[256] = { 0 };
__u16 sopts[256] = { 0 };
int err;
union {
__u32 short_pi[256];
__u64 long_pi[256];
} eilbrts;
__u32 elbatms[256] = { 0 };
__u32 elbats[256] = { 0 };
_cleanup_free_ union {
struct nvme_copy_range f0[256];
struct nvme_copy_range_f1 f1[256];
struct nvme_copy_range_f2 f2[256];
struct nvme_copy_range_f3 f3[256];
} *copy = NULL;
struct config {
__u32 namespace_id;
__u64 sdlba;
char *slbas;
char *nlbs;
char *snsids;
char *sopts;
bool lr;
bool fua;
__u8 prinfow;
__u8 prinfor;
__u64 ilbrt;
char *eilbrts;
__u16 lbat;
char *elbats;
__u16 lbatm;
char *elbatms;
__u8 dtype;
__u16 dspec;
__u8 format;
};
struct config cfg = {
.namespace_id = 0,
.sdlba = 0,
.slbas = "",
.nlbs = "",
.snsids = "",
.sopts = "",
.lr = false,
.fua = false,
.prinfow = 0,
.prinfor = 0,
.ilbrt = 0,
.eilbrts = "",
.lbat = 0,
.elbats = "",
.lbatm = 0,
.elbatms = "",
.dtype = 0,
.dspec = 0,
.format = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SUFFIX("sdlba", 'd', &cfg.sdlba, d_sdlba),
OPT_LIST("slbs", 's', &cfg.slbas, d_slbas),
OPT_LIST("blocks", 'b', &cfg.nlbs, d_nlbs),
OPT_LIST("snsids", 'N', &cfg.snsids, d_snsids),
OPT_LIST("sopts", 'O', &cfg.sopts, d_sopts),
OPT_FLAG("limited-retry", 'l', &cfg.lr, d_lr),
OPT_FLAG("force-unit-access", 'f', &cfg.fua, d_fua),
OPT_BYTE("prinfow", 'p', &cfg.prinfow, d_prinfow),
OPT_BYTE("prinfor", 'P', &cfg.prinfor, d_prinfor),
OPT_SUFFIX("ref-tag", 'r', &cfg.ilbrt, d_ilbrt),
OPT_LIST("expected-ref-tags", 'R', &cfg.eilbrts, d_eilbrts),
OPT_SHRT("app-tag", 'a', &cfg.lbat, d_lbat),
OPT_LIST("expected-app-tags", 'A', &cfg.elbats, d_elbats),
OPT_SHRT("app-tag-mask", 'm', &cfg.lbatm, d_lbatm),
OPT_LIST("expected-app-tag-masks", 'M', &cfg.elbatms, d_elbatms),
OPT_BYTE("dir-type", 'T', &cfg.dtype, d_dtype),
OPT_SHRT("dir-spec", 'S', &cfg.dspec, d_dspec),
OPT_BYTE("format", 'F', &cfg.format, d_format));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
nb = argconfig_parse_comma_sep_array_u16(cfg.nlbs, nlbs, ARRAY_SIZE(nlbs));
ns = argconfig_parse_comma_sep_array_u64(cfg.slbas, slbas, ARRAY_SIZE(slbas));
nids = argconfig_parse_comma_sep_array_u32(cfg.snsids, snsids, ARRAY_SIZE(snsids));
argconfig_parse_comma_sep_array_u16(cfg.sopts, sopts, ARRAY_SIZE(sopts));
if (cfg.format == 0 || cfg.format == 2) {
nrts = argconfig_parse_comma_sep_array_u32(cfg.eilbrts, eilbrts.short_pi,
ARRAY_SIZE(eilbrts.short_pi));
} else if (cfg.format == 1 || cfg.format == 3) {
nrts = argconfig_parse_comma_sep_array_u64(cfg.eilbrts, eilbrts.long_pi,
ARRAY_SIZE(eilbrts.long_pi));
} else {
nvme_show_error("invalid format");
return -EINVAL;
}
natms = argconfig_parse_comma_sep_array_u32(cfg.elbatms, elbatms, ARRAY_SIZE(elbatms));
nats = argconfig_parse_comma_sep_array_u32(cfg.elbats, elbats, ARRAY_SIZE(elbats));
nr = max(nb, max(ns, max(nrts, max(natms, nats))));
if (cfg.format == 2 || cfg.format == 3) {
if (nr != nids) {
nvme_show_error("formats 2 and 3 require source namespace ids for each source range");
return -EINVAL;
}
} else if (nids) {
nvme_show_error("formats 0 and 1 do not support cross-namespace copy");
return -EINVAL;
}
if (!nr || nr > 256) {
nvme_show_error("invalid range");
return -EINVAL;
}
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
copy = nvme_alloc(sizeof(*copy));
if (!copy)
return -ENOMEM;
if (cfg.format == 0)
nvme_init_copy_range(copy->f0, nlbs, slbas, eilbrts.short_pi, elbatms, elbats, nr);
else if (cfg.format == 1)
nvme_init_copy_range_f1(copy->f1, nlbs, slbas, eilbrts.long_pi, elbatms, elbats, nr);
else if (cfg.format == 2)
nvme_init_copy_range_f2(copy->f2, snsids, nlbs, slbas, sopts, eilbrts.short_pi, elbatms,
elbats, nr);
else if (cfg.format == 3)
nvme_init_copy_range_f3(copy->f3, snsids, nlbs, slbas, sopts, eilbrts.long_pi, elbatms,
elbats, nr);
struct nvme_copy_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.copy = copy->f0,
.sdlba = cfg.sdlba,
.nr = nr,
.prinfor = cfg.prinfor,
.prinfow = cfg.prinfow,
.dtype = cfg.dtype,
.dspec = cfg.dspec,
.format = cfg.format,
.lr = cfg.lr,
.fua = cfg.fua,
.ilbrt_u64 = cfg.ilbrt,
.lbatm = cfg.lbatm,
.lbat = cfg.lbat,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_copy(&args);
if (err < 0)
nvme_show_error("NVMe Copy: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
nvme_show_key_value("NVMe Copy", "success");
return err;
}
static int flush_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Commit data and metadata associated with\n"
"given namespaces to nonvolatile media. Applies to all commands\n"
"finished before the flush was submitted. Additional data may also be\n"
"flushed by the controller, from any namespace, depending on controller and\n"
"associated namespace status.";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
struct config {
__u32 namespace_id;
};
struct config cfg = {
.namespace_id = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
err = nvme_flush(dev_fd(dev), cfg.namespace_id);
if (err < 0)
nvme_show_error("flush: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVMe Flush: success\n");
return err;
}
static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Obtain a reservation on a given\n"
"namespace. Only one reservation is allowed at a time on a\n"
"given namespace, though multiple controllers may register\n"
"with that namespace. Namespace reservation will abort with\n"
"status Reservation Conflict if the given namespace is already reserved.";
const char *prkey = "pre-empt reservation key";
const char *racqa = "reservation acquire action";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
__u64 crkey;
__u64 prkey;
__u8 rtype;
__u8 racqa;
bool iekey;
};
struct config cfg = {
.namespace_id = 0,
.crkey = 0,
.prkey = 0,
.rtype = 0,
.racqa = 0,
.iekey = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SUFFIX("crkey", 'c', &cfg.crkey, crkey),
OPT_SUFFIX("prkey", 'p', &cfg.prkey, prkey),
OPT_BYTE("rtype", 't', &cfg.rtype, rtype),
OPT_BYTE("racqa", 'a', &cfg.racqa, racqa),
OPT_FLAG("iekey", 'i', &cfg.iekey, iekey));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
if (cfg.racqa > 7) {
nvme_show_error("invalid racqa:%d", cfg.racqa);
return -EINVAL;
}
struct nvme_resv_acquire_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.rtype = cfg.rtype,
.racqa = cfg.racqa,
.iekey = !!cfg.iekey,
.crkey = cfg.crkey,
.nrkey = cfg.prkey,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_resv_acquire(&args);
if (err < 0)
nvme_show_error("reservation acquire: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVME Reservation Acquire success\n");
return err;
}
static int resv_register(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Register, de-register, or\n"
"replace a controller's reservation on a given namespace.\n"
"Only one reservation at a time is allowed on any namespace.";
const char *nrkey = "new reservation key";
const char *rrega = "reservation registration action";
const char *cptpl = "change persistence through power loss setting";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
__u64 crkey;
__u64 nrkey;
__u8 rrega;
__u8 cptpl;
bool iekey;
};
struct config cfg = {
.namespace_id = 0,
.crkey = 0,
.nrkey = 0,
.rrega = 0,
.cptpl = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SUFFIX("crkey", 'c', &cfg.crkey, crkey),
OPT_SUFFIX("nrkey", 'k', &cfg.nrkey, nrkey),
OPT_BYTE("rrega", 'r', &cfg.rrega, rrega),
OPT_BYTE("cptpl", 'p', &cfg.cptpl, cptpl),
OPT_FLAG("iekey", 'i', &cfg.iekey, iekey));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
if (cfg.cptpl > 3) {
nvme_show_error("invalid cptpl:%d", cfg.cptpl);
return -EINVAL;
}
if (cfg.rrega > 7) {
nvme_show_error("invalid rrega:%d", cfg.rrega);
return -EINVAL;
}
struct nvme_resv_register_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.rrega = cfg.rrega,
.cptpl = cfg.cptpl,
.iekey = !!cfg.iekey,
.crkey = cfg.crkey,
.nrkey = cfg.nrkey,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_resv_register(&args);
if (err < 0)
nvme_show_error("reservation register: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVME Reservation success\n");
return err;
}
static int resv_release(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Releases reservation held on a\n"
"namespace by the given controller. If rtype != current reservation\n"
"type, release will fails. If the given controller holds no\n"
"reservation on the namespace or is not the namespace's current\n"
"reservation holder, the release command completes with no\n"
"effect. If the reservation type is not Write Exclusive or\n"
"Exclusive Access, all registrants on the namespace except\n"
"the issuing controller are notified.";
const char *rrela = "reservation release action";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
__u64 crkey;
__u8 rtype;
__u8 rrela;
__u8 iekey;
};
struct config cfg = {
.namespace_id = 0,
.crkey = 0,
.rtype = 0,
.rrela = 0,
.iekey = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_SUFFIX("crkey", 'c', &cfg.crkey, crkey),
OPT_BYTE("rtype", 't', &cfg.rtype, rtype),
OPT_BYTE("rrela", 'a', &cfg.rrela, rrela),
OPT_FLAG("iekey", 'i', &cfg.iekey, iekey));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
if (cfg.rrela > 7) {
nvme_show_error("invalid rrela:%d", cfg.rrela);
return -EINVAL;
}
struct nvme_resv_release_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.rtype = cfg.rtype,
.rrela = cfg.rrela,
.iekey = !!cfg.iekey,
.crkey = cfg.crkey,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_resv_release(&args);
if (err < 0)
nvme_show_error("reservation release: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVME Reservation Release success\n");
return err;
}
static int resv_report(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Returns Reservation Status data\n"
"structure describing any existing reservations on and the\n"
"status of a given namespace. Namespace Reservation Status\n"
"depends on the number of controllers registered for that namespace.";
const char *numd = "number of dwords to transfer";
const char *eds = "request extended data structure";
_cleanup_free_ struct nvme_resv_status *status = NULL;
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
nvme_print_flags_t flags;
int err, size;
struct config {
__u32 namespace_id;
__u32 numd;
__u8 eds;
bool raw_binary;
};
struct config cfg = {
.namespace_id = 0,
.numd = 0,
.eds = false,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_UINT("numd", 'd', &cfg.numd, numd),
OPT_FLAG("eds", 'e', &cfg.eds, eds),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.raw_binary)
flags = BINARY;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
if (!cfg.numd || cfg.numd >= (0x1000 >> 2))
cfg.numd = (0x1000 >> 2) - 1;
if (cfg.numd < 3)
cfg.numd = 3;
size = (cfg.numd + 1) << 2;
ctrl = nvme_alloc(sizeof(*ctrl));
if (!ctrl)
return -ENOMEM;
err = nvme_cli_identify_ctrl(dev, ctrl);
if (err) {
nvme_show_error("identify-ctrl: %s", nvme_strerror(errno));
return -errno;
}
if (ctrl->ctratt & NVME_CTRL_CTRATT_128_ID)
cfg.eds = true;
status = nvme_alloc(size);
if (!status)
return -ENOMEM;
struct nvme_resv_report_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.eds = cfg.eds,
.len = size,
.report = status,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_resv_report(&args);
if (!err)
nvme_show_resv_report(status, size, cfg.eds, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("reservation report: %s", nvme_strerror(errno));
return err;
}
unsigned long long elapsed_utime(struct timeval start_time,
struct timeval end_time)
{
unsigned long long err = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
(end_time.tv_usec - start_time.tv_usec);
return err;
}
static int submit_io(int opcode, char *command, const char *desc, int argc, char **argv)
{
struct timeval start_time, end_time;
void *buffer;
_cleanup_free_ void *mbuffer = NULL;
int err = 0;
_cleanup_fd_ int dfd = -1, mfd = -1;
int flags, pi_size;
int mode = 0644;
__u16 control = 0, nblocks = 0;
__u32 dsmgmt = 0;
unsigned int logical_block_size = 0;
unsigned long long buffer_size = 0, mbuffer_size = 0;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
__u8 lba_index, sts = 0, pif = 0;
__u16 ms;
const char *start_block_addr = "64-bit addr of first block to access";
const char *block_size = "if specified, logical block size in bytes;\n"
"discovered by identify namespace otherwise";
const char *data_size = "size of data in bytes";
const char *metadata_size = "size of metadata in bytes";
const char *data = "data file";
const char *metadata = "metadata file";
const char *limited_retry_num = "limit num. media access attempts";
const char *show = "show command before sending";
const char *dtype_for_write = "directive type (for write-only)";
const char *dspec = "directive specific (for write-only)";
const char *dsm = "dataset management attributes (lower 8 bits)";
const char *storage_tag_check = "This bit specifies the Storage Tag field shall be\n"
"checked as part of end-to-end data protection processing";
const char *force = "The \"I know what I'm doing\" flag, do not enforce exclusive access for write";
struct config {
__u32 namespace_id;
__u64 start_block;
__u16 block_count;
__u16 block_size;
__u64 data_size;
__u64 metadata_size;
__u64 ref_tag;
char *data;
char *metadata;
__u8 prinfo;
__u16 app_tag_mask;
__u16 app_tag;
__u64 storage_tag;
bool limited_retry;
bool force_unit_access;
bool storage_tag_check;
__u8 dtype;
__u16 dspec;
__u8 dsmgmt;
bool show;
bool latency;
bool force;
};
struct config cfg = {
.namespace_id = 0,
.start_block = 0,
.block_count = 0,
.block_size = 0,
.data_size = 0,
.metadata_size = 0,
.ref_tag = 0,
.data = "",
.metadata = "",
.prinfo = 0,
.app_tag_mask = 0,
.app_tag = 0,
.storage_tag = 0,
.limited_retry = false,
.force_unit_access = false,
.storage_tag_check = false,
.dtype = 0,
.dspec = 0,
.dsmgmt = 0,
.show = false,
.latency = false,
.force = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_SUFFIX("start-block", 's', &cfg.start_block, start_block_addr),
OPT_SHRT("block-count", 'c', &cfg.block_count, block_count),
OPT_SHRT("block-size", 'b', &cfg.block_size, block_size),
OPT_SUFFIX("data-size", 'z', &cfg.data_size, data_size),
OPT_SUFFIX("metadata-size", 'y', &cfg.metadata_size, metadata_size),
OPT_SUFFIX("ref-tag", 'r', &cfg.ref_tag, ref_tag),
OPT_FILE("data", 'd', &cfg.data, data),
OPT_FILE("metadata", 'M', &cfg.metadata, metadata),
OPT_BYTE("prinfo", 'p', &cfg.prinfo, prinfo),
OPT_SHRT("app-tag-mask", 'm', &cfg.app_tag_mask, app_tag_mask),
OPT_SHRT("app-tag", 'a', &cfg.app_tag, app_tag),
OPT_SUFFIX("storage-tag", 'g', &cfg.storage_tag, storage_tag),
OPT_FLAG("limited-retry", 'l', &cfg.limited_retry, limited_retry_num),
OPT_FLAG("force-unit-access", 'f', &cfg.force_unit_access, force_unit_access),
OPT_FLAG("storage-tag-check", 'C', &cfg.storage_tag_check, storage_tag_check),
OPT_BYTE("dir-type", 'T', &cfg.dtype, dtype_for_write),
OPT_SHRT("dir-spec", 'S', &cfg.dspec, dspec),
OPT_BYTE("dsm", 'D', &cfg.dsmgmt, dsm),
OPT_FLAG("show-command", 'V', &cfg.show, show),
OPT_FLAG("dry-run", 'w', &nvme_cfg.dry_run, dry_run),
OPT_FLAG("latency", 't', &cfg.latency, latency),
OPT_FLAG("force", 0, &cfg.force, force));
if (opcode != nvme_cmd_write) {
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
} else {
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
err = open_exclusive(&dev, argc, argv, cfg.force);
if (err) {
if (errno == EBUSY) {
fprintf(stderr, "Failed to open %s.\n", basename(argv[optind]));
fprintf(stderr, "Namespace is currently busy.\n");
if (!cfg.force)
fprintf(stderr,
"Use the force [--force] option to ignore that.\n");
} else {
argconfig_print_help(desc, opts);
}
return err;
}
}
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
if (cfg.prinfo > 0xf)
return err;
dsmgmt = cfg.dsmgmt;
control |= (cfg.prinfo << 10);
if (cfg.limited_retry)
control |= NVME_IO_LR;
if (cfg.force_unit_access)
control |= NVME_IO_FUA;
if (cfg.storage_tag_check)
control |= NVME_IO_STC;
if (cfg.dtype) {
if (cfg.dtype > 0xf) {
nvme_show_error("Invalid directive type, %x", cfg.dtype);
return -EINVAL;
}
control |= cfg.dtype << 4;
dsmgmt |= ((__u32)cfg.dspec) << 16;
}
if (opcode & 1) {
dfd = mfd = STDIN_FILENO;
flags = O_RDONLY;
} else {
dfd = mfd = STDOUT_FILENO;
flags = O_WRONLY | O_CREAT;
}
if (strlen(cfg.data)) {
dfd = open(cfg.data, flags, mode);
if (dfd < 0) {
nvme_show_perror(cfg.data);
return -EINVAL;
}
}
if (strlen(cfg.metadata)) {
mfd = open(cfg.metadata, flags, mode);
if (mfd < 0) {
nvme_show_perror(cfg.metadata);
return -EINVAL;
}
}
if (!cfg.data_size) {
nvme_show_error("data size not provided");
return -EINVAL;
}
if (cfg.block_size) {
logical_block_size = cfg.block_size;
ms = cfg.metadata_size;
} else {
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
if (err > 0) {
nvme_show_status(err);
return err;
} else if (err < 0) {
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
return err;
}
nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &lba_index);
logical_block_size = 1 << ns->lbaf[lba_index].ds;
ms = le16_to_cpu(ns->lbaf[lba_index].ms);
nvm_ns = nvme_alloc(sizeof(*nvm_ns));
if (!nvm_ns)
return -ENOMEM;
err = nvme_identify_ns_csi(dev_fd(dev), cfg.namespace_id, 0, NVME_CSI_NVM, nvm_ns);
if (!err)
get_pif_sts(ns, nvm_ns, &pif, &sts);
pi_size = (pif == NVME_NVM_PIF_16B_GUARD) ? 8 : 16;
if (NVME_FLBAS_META_EXT(ns->flbas)) {
/*
* No meta data is transferred for PRACT=1 and MD=PI size:
* 5.2.2.1 Protection Information and Write Commands
* 5.2.2.2 Protection Information and Read Commands
*/
if (!((cfg.prinfo & 0x8) != 0 && ms == pi_size))
logical_block_size += ms;
}
if (invalid_tags(cfg.storage_tag, cfg.ref_tag, sts, pif))
return -EINVAL;
}
buffer_size = ((long long)cfg.block_count + 1) * logical_block_size;
if (cfg.data_size < buffer_size)
nvme_show_error("Rounding data size to fit block count (%lld bytes)", buffer_size);
else
buffer_size = cfg.data_size;
if (argconfig_parse_seen(opts, "block-count")) {
/* Use the value provided */
nblocks = cfg.block_count;
} else {
/* Get the required block count. Note this is a zeroes based value. */
nblocks = ((buffer_size + (logical_block_size - 1)) / logical_block_size) - 1;
/* Update the data size based on the required block count */
buffer_size = ((unsigned long long)nblocks + 1) * logical_block_size;
}
buffer = nvme_alloc_huge(buffer_size, &mh);
if (!buffer) {
nvme_show_error("failed to allocate huge memory");
return -ENOMEM;
}
if (cfg.metadata_size) {
mbuffer_size = ((unsigned long long)cfg.block_count + 1) * ms;
if (ms && cfg.metadata_size < mbuffer_size)
nvme_show_error("Rounding metadata size to fit block count (%lld bytes)",
mbuffer_size);
else
mbuffer_size = cfg.metadata_size;
mbuffer = malloc(mbuffer_size);
if (!mbuffer)
return -ENOMEM;
memset(mbuffer, 0, mbuffer_size);
}
if (opcode & 1) {
err = read(dfd, (void *)buffer, cfg.data_size);
if (err < 0) {
err = -errno;
nvme_show_error("failed to read data buffer from input file %s", strerror(errno));
return err;
}
}
if ((opcode & 1) && cfg.metadata_size) {
err = read(mfd, (void *)mbuffer, mbuffer_size);
if (err < 0) {
err = -errno;
nvme_show_error("failed to read meta-data buffer from input file %s", strerror(errno));
return err;
}
}
if (cfg.show || nvme_cfg.dry_run) {
printf("opcode : %02x\n", opcode);
printf("nsid : %02x\n", cfg.namespace_id);
printf("flags : %02x\n", 0);
printf("control : %04x\n", control);
printf("nblocks : %04x\n", nblocks);
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)mbuffer);
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)buffer);
printf("slba : %"PRIx64"\n", (uint64_t)cfg.start_block);
printf("dsmgmt : %08x\n", dsmgmt);
printf("reftag : %"PRIx64"\n", (uint64_t)cfg.ref_tag);
printf("apptag : %04x\n", cfg.app_tag);
printf("appmask : %04x\n", cfg.app_tag_mask);
printf("storagetagcheck : %04x\n", cfg.storage_tag_check);
printf("storagetag : %"PRIx64"\n", (uint64_t)cfg.storage_tag);
printf("pif : %02x\n", pif);
printf("sts : %02x\n", sts);
}
if (nvme_cfg.dry_run)
return 0;
struct nvme_io_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.slba = cfg.start_block,
.nlb = nblocks,
.control = control,
.dsm = cfg.dsmgmt,
.sts = sts,
.pif = pif,
.dspec = cfg.dspec,
.reftag = (__u32)cfg.ref_tag,
.reftag_u64 = cfg.ref_tag,
.apptag = cfg.app_tag,
.appmask = cfg.app_tag_mask,
.storage_tag = cfg.storage_tag,
.data_len = buffer_size,
.data = buffer,
.metadata_len = mbuffer_size,
.metadata = mbuffer,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
gettimeofday(&start_time, NULL);
err = nvme_io(&args, opcode);
gettimeofday(&end_time, NULL);
if (cfg.latency)
printf(" latency: %s: %llu us\n", command, elapsed_utime(start_time, end_time));
if (err < 0) {
nvme_show_error("submit-io: %s", nvme_strerror(errno));
} else if (err) {
nvme_show_status(err);
} else {
if (!(opcode & 1) && write(dfd, (void *)buffer, buffer_size) < 0) {
nvme_show_error("write: %s: failed to write buffer to output file",
strerror(errno));
err = -EINVAL;
} else if (!(opcode & 1) && cfg.metadata_size &&
write(mfd, (void *)mbuffer, mbuffer_size) < 0) {
nvme_show_error(
"write: %s: failed to write meta-data buffer to output file",
strerror(errno));
err = -EINVAL;
} else {
fprintf(stderr, "%s: Success\n", command);
}
}
return err;
}
static int compare(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Compare specified logical blocks on\n"
"device with specified data buffer; return failure if buffer\n"
"and block(s) are dissimilar";
return submit_io(nvme_cmd_compare, "compare", desc, argc, argv);
}
static int read_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Copy specified logical blocks on the given\n"
"device to specified data buffer (default buffer is stdout).";
return submit_io(nvme_cmd_read, "read", desc, argc, argv);
}
static int write_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Copy from provided data buffer (default\n"
"buffer is stdin) to specified logical blocks on the given device.";
return submit_io(nvme_cmd_write, "write", desc, argc, argv);
}
static int verify_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
_cleanup_free_ struct nvme_nvm_id_ns *nvm_ns = NULL;
_cleanup_free_ struct nvme_id_ns *ns = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u8 sts = 0, pif = 0;
__u16 control = 0;
int err;
const char *desc = "Verify specified logical blocks on the given device.";
const char *force_unit_access_verify =
"force device to commit cached data before performing the verify operation";
const char *storage_tag_check =
"This bit specifies the Storage Tag field shall be checked as part of Verify operation";
struct config {
__u32 namespace_id;
__u64 start_block;
__u16 block_count;
bool limited_retry;
bool force_unit_access;
__u8 prinfo;
__u32 ref_tag;
__u16 app_tag;
__u16 app_tag_mask;
__u64 storage_tag;
bool storage_tag_check;
};
struct config cfg = {
.namespace_id = 0,
.start_block = 0,
.block_count = 0,
.limited_retry = false,
.force_unit_access = false,
.prinfo = 0,
.ref_tag = 0,
.app_tag = 0,
.app_tag_mask = 0,
.storage_tag = 0,
.storage_tag_check = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_SUFFIX("start-block", 's', &cfg.start_block, start_block),
OPT_SHRT("block-count", 'c', &cfg.block_count, block_count),
OPT_FLAG("limited-retry", 'l', &cfg.limited_retry, limited_retry),
OPT_FLAG("force-unit-access", 'f', &cfg.force_unit_access, force_unit_access_verify),
OPT_BYTE("prinfo", 'p', &cfg.prinfo, prinfo),
OPT_SUFFIX("ref-tag", 'r', &cfg.ref_tag, ref_tag),
OPT_SHRT("app-tag", 'a', &cfg.app_tag, app_tag),
OPT_SHRT("app-tag-mask", 'm', &cfg.app_tag_mask, app_tag_mask),
OPT_SUFFIX("storage-tag", 'S', &cfg.storage_tag, storage_tag),
OPT_FLAG("storage-tag-check", 'C', &cfg.storage_tag_check, storage_tag_check));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (cfg.prinfo > 0xf)
return -EINVAL;
control |= (cfg.prinfo << 10);
if (cfg.limited_retry)
control |= NVME_IO_LR;
if (cfg.force_unit_access)
control |= NVME_IO_FUA;
if (cfg.storage_tag_check)
control |= NVME_IO_STC;
if (!cfg.namespace_id) {
err = nvme_get_nsid(dev_fd(dev), &cfg.namespace_id);
if (err < 0) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(errno));
return err;
}
}
ns = nvme_alloc(sizeof(*ns));
if (!ns)
return -ENOMEM;
err = nvme_cli_identify_ns(dev, cfg.namespace_id, ns);
if (err < 0) {
nvme_show_error("identify namespace: %s", nvme_strerror(errno));
return err;
} else if (err) {
nvme_show_status(err);
return err;
}
nvm_ns = nvme_alloc(sizeof(*nvm_ns));
if (!nvm_ns)
return -ENOMEM;
err = nvme_identify_ns_csi(dev_fd(dev), cfg.namespace_id, 0,
NVME_CSI_NVM, nvm_ns);
if (!err) {
get_pif_sts(ns, nvm_ns, &pif, &sts);
}
if (invalid_tags(cfg.storage_tag, cfg.ref_tag, sts, pif))
return -EINVAL;
struct nvme_io_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.slba = cfg.start_block,
.nlb = cfg.block_count,
.control = control,
.reftag = cfg.ref_tag,
.reftag_u64 = cfg.ref_tag,
.apptag = cfg.app_tag,
.appmask = cfg.app_tag_mask,
.sts = sts,
.pif = pif,
.storage_tag = cfg.storage_tag,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_verify(&args);
if (err < 0)
nvme_show_error("verify: %s", nvme_strerror(errno));
else if (err != 0)
nvme_show_status(err);
else
printf("NVME Verify Success\n");
return err;
}
static int sec_recv(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Obtain results of one or more\n"
"previously submitted security-sends. Results, and association\n"
"between Security Send and Receive, depend on the security\n"
"protocol field as they are defined by the security protocol\n"
"used. A Security Receive must follow a Security Send made with\n"
"the same security protocol.";
const char *size = "size of buffer (prints to stdout on success)";
const char *al = "allocation length (cf. SPC-4)";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *sec_buf = NULL;
int err;
nvme_print_flags_t flags;
struct config {
__u32 namespace_id;
__u32 size;
__u8 nssf;
__u8 secp;
__u16 spsp;
__u32 al;
bool raw_binary;
};
struct config cfg = {
.namespace_id = 0,
.size = 0,
.nssf = 0,
.secp = 0,
.spsp = 0,
.al = 0,
.raw_binary = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_UINT("size", 'x', &cfg.size, size),
OPT_BYTE("nssf", 'N', &cfg.nssf, nssf),
OPT_BYTE("secp", 'p', &cfg.secp, secp),
OPT_SHRT("spsp", 's', &cfg.spsp, spsp),
OPT_UINT("al", 't', &cfg.al, al),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.size) {
sec_buf = nvme_alloc(cfg.size);
if (!sec_buf)
return -ENOMEM;
}
struct nvme_security_receive_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.nssf = cfg.nssf,
.spsp0 = cfg.spsp & 0xff,
.spsp1 = cfg.spsp >> 8,
.secp = cfg.secp,
.al = cfg.al,
.data_len = cfg.size,
.data = sec_buf,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_cli_security_receive(dev, &args);
if (err < 0) {
nvme_show_error("security receive: %s", nvme_strerror(errno));
} else if (err != 0) {
nvme_show_status(err);
} else {
printf("NVME Security Receive Command Success\n");
if (!cfg.raw_binary)
d(sec_buf, cfg.size, 16, 1);
else if (cfg.size)
d_raw((unsigned char *)sec_buf, cfg.size);
}
return err;
}
static int get_lba_status(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Information about potentially unrecoverable LBAs.";
const char *slba =
"Starting LBA(SLBA) in 64-bit address of the first logical block addressed by this command";
const char *mndw =
"Maximum Number of Dwords(MNDW) specifies maximum number of dwords to return";
const char *atype = "Action Type(ATYPE) specifies the mechanism\n"
"the controller uses in determining the LBA Status Descriptors to return.";
const char *rl =
"Range Length(RL) specifies the length of the range of contiguous LBAs beginning at SLBA";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *buf = NULL;
nvme_print_flags_t flags;
unsigned long buf_len;
int err;
struct config {
__u32 namespace_id;
__u64 slba;
__u32 mndw;
__u8 atype;
__u16 rl;
};
struct config cfg = {
.namespace_id = 0,
.slba = 0,
.mndw = 0,
.atype = 0,
.rl = 0,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_SUFFIX("start-lba", 's', &cfg.slba, slba),
OPT_UINT("max-dw", 'm', &cfg.mndw, mndw),
OPT_BYTE("action", 'a', &cfg.atype, atype),
OPT_SHRT("range-len", 'l', &cfg.rl, rl));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!cfg.atype) {
nvme_show_error("action type (--action) has to be given");
return -EINVAL;
}
buf_len = (cfg.mndw + 1) * 4;
buf = nvme_alloc(buf_len);
if (!buf)
return -ENOMEM;
struct nvme_get_lba_status_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.slba = cfg.slba,
.mndw = cfg.mndw,
.rl = cfg.rl,
.atype = cfg.atype,
.lbas = buf,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_get_lba_status(&args);
if (!err)
nvme_show_lba_status(buf, buf_len, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_error("get lba status: %s", nvme_strerror(errno));
return err;
}
static int capacity_mgmt(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Host software uses the Capacity Management command to\n"
"configure Endurance Groups and NVM Sets in an NVM subsystem by either\n"
"selecting one of a set of supported configurations or by specifying the\n"
"capacity of the Endurance Group or NVM Set to be created";
const char *operation = "Operation to be performed by the controller";
const char *element_id = "Value specific to the value of the Operation field.";
const char *cap_lower =
"Least significant 32 bits of the capacity in bytes of the Endurance Group or NVM Set to be created";
const char *cap_upper =
"Most significant 32 bits of the capacity in bytes of the Endurance Group or NVM Set to be created";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err = -1;
__u32 result;
nvme_print_flags_t flags;
struct config {
__u8 operation;
__u16 element_id;
__u32 dw11;
__u32 dw12;
};
struct config cfg = {
.operation = 0xff,
.element_id = 0xffff,
.dw11 = 0,
.dw12 = 0,
};
NVME_ARGS(opts,
OPT_BYTE("operation", 'O', &cfg.operation, operation),
OPT_SHRT("element-id", 'i', &cfg.element_id, element_id),
OPT_UINT("cap-lower", 'l', &cfg.dw11, cap_lower),
OPT_UINT("cap-upper", 'u', &cfg.dw12, cap_upper));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (cfg.operation > 0xf) {
nvme_show_error("invalid operation field: %u", cfg.operation);
return -1;
}
struct nvme_capacity_mgmt_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.op = cfg.operation,
.element_id = cfg.element_id,
.cdw11 = cfg.dw11,
.cdw12 = cfg.dw12,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_capacity_mgmt(&args);
if (!err) {
printf("Capacity Management Command is Success\n");
if (cfg.operation == 1)
printf("Created Element Identifier for Endurance Group is: %u\n", result);
else if (cfg.operation == 3)
printf("Created Element Identifier for NVM Set is: %u\n", result);
} else if (err > 0) {
nvme_show_status(err);
} else if (err < 0) {
nvme_show_error("capacity management: %s", nvme_strerror(errno));
}
return err;
}
static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Read directive parameters of the specified directive type.";
const char *nsr = "namespace stream requested";
nvme_print_flags_t flags = NORMAL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ void *buf = NULL;
__u32 result;
__u32 dw12 = 0;
int err;
struct config {
__u32 namespace_id;
__u32 data_len;
bool raw_binary;
__u8 dtype;
__u16 dspec;
__u8 doper;
__u16 nsr; /* dw12 for NVME_DIR_ST_RCVOP_STATUS */
bool human_readable;
};
struct config cfg = {
.namespace_id = 1,
.data_len = 0,
.raw_binary = false,
.dtype = 0,
.dspec = 0,
.doper = 0,
.nsr = 0,
.human_readable = false,
};
NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_directive),
OPT_BYTE("dir-type", 'D', &cfg.dtype, dtype),
OPT_SHRT("dir-spec", 'S', &cfg.dspec, dspec_w_dtype),
OPT_BYTE("dir-oper", 'O', &cfg.doper, doper),
OPT_SHRT("req-resource", 'r', &cfg.nsr, nsr),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable_directive));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (cfg.human_readable || argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
if (cfg.raw_binary)
flags = BINARY;
switch (cfg.dtype) {
case NVME_DIRECTIVE_DTYPE_IDENTIFY:
switch (cfg.doper) {
case NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM:
if (!cfg.data_len)
cfg.data_len = 4096;
break;
default:
nvme_show_error("invalid directive operations for Identify Directives");
return -EINVAL;
}
break;
case NVME_DIRECTIVE_DTYPE_STREAMS:
switch (cfg.doper) {
case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM:
if (!cfg.data_len)
cfg.data_len = 32;
break;
case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS:
if (!cfg.data_len)
cfg.data_len = 128 * 1024;
break;
case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE:
dw12 = cfg.nsr;
break;
default:
nvme_show_error("invalid directive operations for Streams Directives");
return -EINVAL;
}
break;
default:
nvme_show_error("invalid directive type");
return -EINVAL;
}
if (cfg.data_len) {
buf = nvme_alloc(cfg.data_len);
if (!buf)
return -ENOMEM;
}
struct nvme_directive_recv_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.nsid = cfg.namespace_id,
.dspec = cfg.dspec,
.doper = cfg.doper,
.dtype = cfg.dtype,
.cdw12 = dw12,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_directive_recv(&args);
if (!err)
nvme_directive_show(cfg.dtype, cfg.doper, cfg.dspec, cfg.namespace_id,
result, buf, cfg.data_len, flags);
else if (err > 0)
nvme_show_status(err);
else if (err < 0)
nvme_show_error("dir-receive: %s", nvme_strerror(errno));
return err;
}
/* rpmb_cmd_option is defined in nvme-rpmb.c */
extern int rpmb_cmd_option(int, char **, struct command *, struct plugin *);
static int rpmb_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
return rpmb_cmd_option(argc, argv, cmd, plugin);
}
static int lockdown_cmd(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "The Lockdown command is used to control the\n"
"Command and Feature Lockdown capability which configures the\n"
"prohibition or allowance of execution of the specified command\n"
"or Set Features command targeting a specific Feature Identifier.";
const char *ofi_desc = "Opcode or Feature Identifier (OFI)\n"
"specifies the command opcode or Set Features Feature Identifier\n"
"identified by the Scope field.";
const char *ifc_desc =
"[0-3] Interface (INF) field identifies the interfaces affected by this command.";
const char *prhbt_desc = "[0-1]Prohibit(PRHBT) bit specifies whether\n"
"to prohibit or allow the command opcode or Set Features Feature\n"
"Identifier specified by this command.";
const char *scp_desc =
"[0-15]Scope(SCP) field specifies the contents of the Opcode or Feature Identifier field.";
const char *uuid_desc = "UUID Index - If this field is set to a non-zero\n"
"value, then the value of this field is the index of a UUID in the UUID\n"
"List that is used by the command.If this field is cleared to 0h,\n"
"then no UUID index is specified";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err = -1;
struct config {
__u8 ofi;
__u8 ifc;
__u8 prhbt;
__u8 scp;
__u8 uuid;
};
struct config cfg = {
.ofi = 0,
.ifc = 0,
.prhbt = 0,
.scp = 0,
.uuid = 0,
};
NVME_ARGS(opts,
OPT_BYTE("ofi", 'O', &cfg.ofi, ofi_desc),
OPT_BYTE("ifc", 'f', &cfg.ifc, ifc_desc),
OPT_BYTE("prhbt", 'p', &cfg.prhbt, prhbt_desc),
OPT_BYTE("scp", 's', &cfg.scp, scp_desc),
OPT_BYTE("uuid", 'U', &cfg.uuid, uuid_desc));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
/* check for input argument limit */
if (cfg.ifc > 3) {
nvme_show_error("invalid interface settings:%d", cfg.ifc);
return -1;
}
if (cfg.prhbt > 1) {
nvme_show_error("invalid prohibit settings:%d", cfg.prhbt);
return -1;
}
if (cfg.scp > 15) {
nvme_show_error("invalid scope settings:%d", cfg.scp);
return -1;
}
if (cfg.uuid > 127) {
nvme_show_error("invalid UUID index settings:%d", cfg.uuid);
return -1;
}
struct nvme_lockdown_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.scp = cfg.scp,
.prhbt = cfg.prhbt,
.ifc = cfg.ifc,
.ofi = cfg.ofi,
.uuidx = cfg.uuid,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_lockdown(&args);
if (err < 0)
nvme_show_error("lockdown: %s", nvme_strerror(errno));
else if (err > 0)
nvme_show_status(err);
else
printf("Lockdown Command is Successful\n");
return err;
}
static void passthru_print_read_output(struct passthru_config cfg, void *data, int dfd, void *mdata,
int mfd, int err)
{
if (strlen(cfg.input_file)) {
if (write(dfd, (void *)data, cfg.data_len) < 0)
perror("failed to write data buffer");
} else if (data) {
if (cfg.raw_binary)
d_raw((unsigned char *)data, cfg.data_len);
else if (!err)
d((unsigned char *)data, cfg.data_len, 16, 1);
}
if (cfg.metadata_len && cfg.metadata) {
if (strlen(cfg.metadata)) {
if (write(mfd, (void *)mdata, cfg.metadata_len) < 0)
perror("failed to write metadata buffer");
} else {
if (cfg.raw_binary)
d_raw((unsigned char *)mdata, cfg.metadata_len);
else if (!err)
d((unsigned char *)mdata, cfg.metadata_len, 16, 1);
}
}
}
static int passthru(int argc, char **argv, bool admin,
const char *desc, struct command *cmd)
{
const char *opcode = "opcode (required)";
const char *cflags = "command flags";
const char *rsvd = "value for reserved field";
const char *data_len = "data I/O length (bytes)";
const char *metadata_len = "metadata seg. length (bytes)";
const char *metadata = "metadata input or output file";
const char *cdw2 = "command dword 2 value";
const char *cdw3 = "command dword 3 value";
const char *cdw10 = "command dword 10 value";
const char *cdw11 = "command dword 11 value";
const char *cdw12 = "command dword 12 value";
const char *cdw13 = "command dword 13 value";
const char *cdw14 = "command dword 14 value";
const char *cdw15 = "command dword 15 value";
const char *input = "data input or output file";
const char *show = "print command before sending";
const char *re = "set dataflow direction to receive";
const char *wr = "set dataflow direction to send";
const char *prefill = "prefill buffers with known byte-value, default 0";
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_fd_ int dfd = -1, mfd = -1;
int flags;
int mode = 0644;
void *data = NULL;
_cleanup_free_ void *mdata = NULL;
int err = 0;
__u32 result;
const char *cmd_name = NULL;
struct timeval start_time, end_time;
nvme_print_flags_t flags_t;
struct passthru_config cfg = {
.opcode = 0,
.flags = 0,
.prefill = 0,
.rsvd = 0,
.namespace_id = 0,
.data_len = 0,
.metadata_len = 0,
.cdw2 = 0,
.cdw3 = 0,
.cdw10 = 0,
.cdw11 = 0,
.cdw12 = 0,
.cdw13 = 0,
.cdw14 = 0,
.cdw15 = 0,
.input_file = "",
.metadata = "",
.raw_binary = false,
.show_command = false,
.read = false,
.write = false,
.latency = false,
};
NVME_ARGS(opts,
OPT_BYTE("opcode", 'O', &cfg.opcode, opcode),
OPT_BYTE("flags", 'f', &cfg.flags, cflags),
OPT_BYTE("prefill", 'p', &cfg.prefill, prefill),
OPT_SHRT("rsvd", 'R', &cfg.rsvd, rsvd),
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_UINT("data-len", 'l', &cfg.data_len, data_len),
OPT_UINT("metadata-len", 'm', &cfg.metadata_len, metadata_len),
OPT_UINT("cdw2", '2', &cfg.cdw2, cdw2),
OPT_UINT("cdw3", '3', &cfg.cdw3, cdw3),
OPT_UINT("cdw10", '4', &cfg.cdw10, cdw10),
OPT_UINT("cdw11", '5', &cfg.cdw11, cdw11),
OPT_UINT("cdw12", '6', &cfg.cdw12, cdw12),
OPT_UINT("cdw13", '7', &cfg.cdw13, cdw13),
OPT_UINT("cdw14", '8', &cfg.cdw14, cdw14),
OPT_UINT("cdw15", '9', &cfg.cdw15, cdw15),
OPT_FILE("input-file", 'i', &cfg.input_file, input),
OPT_FILE("metadata", 'M', &cfg.metadata, metadata),
OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw_dump),
OPT_FLAG("show-command", 's', &cfg.show_command, show),
OPT_FLAG("dry-run", 'd', &nvme_cfg.dry_run, dry_run),
OPT_FLAG("read", 'r', &cfg.read, re),
OPT_FLAG("write", 'w', &cfg.write, wr),
OPT_FLAG("latency", 'T', &cfg.latency, latency));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags_t);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (!argconfig_parse_seen(opts, "opcode")) {
nvme_show_error("%s: opcode parameter required", cmd->name);
return -EINVAL;
}
if (cfg.opcode & 0x01) {
cfg.write = true;
flags = O_RDONLY;
dfd = mfd = STDIN_FILENO;
}
if (cfg.opcode & 0x02) {
cfg.read = true;
flags = O_WRONLY | O_CREAT;
dfd = mfd = STDOUT_FILENO;
}
if (strlen(cfg.input_file)) {
dfd = open(cfg.input_file, flags, mode);
if (dfd < 0) {
nvme_show_perror(cfg.input_file);
return -EINVAL;
}
}
if (cfg.metadata && strlen(cfg.metadata)) {
mfd = open(cfg.metadata, flags, mode);
if (mfd < 0) {
nvme_show_perror(cfg.metadata);
return -EINVAL;
}
}
if (cfg.metadata_len) {
mdata = malloc(cfg.metadata_len);
if (!mdata)
return -ENOMEM;
if (cfg.write) {
if (read(mfd, mdata, cfg.metadata_len) < 0) {
err = -errno;
nvme_show_perror("failed to read metadata write buffer");
return err;
}
} else {
memset(mdata, cfg.prefill, cfg.metadata_len);
}
}
if (cfg.data_len) {
data = nvme_alloc_huge(cfg.data_len, &mh);
if (!data) {
nvme_show_error("failed to allocate huge memory");
return -ENOMEM;
}
memset(data, cfg.prefill, cfg.data_len);
if (!cfg.read && !cfg.write) {
nvme_show_error("data direction not given");
return -EINVAL;
} else if (cfg.write) {
if (read(dfd, data, cfg.data_len) < 0) {
err = -errno;
nvme_show_error("failed to read write buffer %s", strerror(errno));
return err;
}
}
}
if (cfg.show_command || nvme_cfg.dry_run) {
printf("opcode : %02x\n", cfg.opcode);
printf("flags : %02x\n", cfg.flags);
printf("rsvd1 : %04x\n", cfg.rsvd);
printf("nsid : %08x\n", cfg.namespace_id);
printf("cdw2 : %08x\n", cfg.cdw2);
printf("cdw3 : %08x\n", cfg.cdw3);
printf("data_len : %08x\n", cfg.data_len);
printf("metadata_len : %08x\n", cfg.metadata_len);
printf("addr : %"PRIx64"\n", (uint64_t)(uintptr_t)data);
printf("metadata : %"PRIx64"\n", (uint64_t)(uintptr_t)mdata);
printf("cdw10 : %08x\n", cfg.cdw10);
printf("cdw11 : %08x\n", cfg.cdw11);
printf("cdw12 : %08x\n", cfg.cdw12);
printf("cdw13 : %08x\n", cfg.cdw13);
printf("cdw14 : %08x\n", cfg.cdw14);
printf("cdw15 : %08x\n", cfg.cdw15);
printf("timeout_ms : %08x\n", nvme_cfg.timeout);
}
if (nvme_cfg.dry_run)
return 0;
gettimeofday(&start_time, NULL);
if (admin)
err = nvme_cli_admin_passthru(dev, cfg.opcode, cfg.flags,
cfg.rsvd,
cfg.namespace_id, cfg.cdw2,
cfg.cdw3, cfg.cdw10,
cfg.cdw11, cfg.cdw12, cfg.cdw13,
cfg.cdw14,
cfg.cdw15, cfg.data_len, data,
cfg.metadata_len,
mdata, nvme_cfg.timeout, &result);
else
err = nvme_io_passthru(dev_fd(dev), cfg.opcode, cfg.flags,
cfg.rsvd,
cfg.namespace_id, cfg.cdw2, cfg.cdw3,
cfg.cdw10,
cfg.cdw11, cfg.cdw12, cfg.cdw13,
cfg.cdw14,
cfg.cdw15, cfg.data_len, data,
cfg.metadata_len,
mdata, nvme_cfg.timeout, &result);
gettimeofday(&end_time, NULL);
cmd_name = nvme_cmd_to_string(admin, cfg.opcode);
if (cfg.latency)
printf("%s Command %s latency: %llu us\n", admin ? "Admin" : "IO",
strcmp(cmd_name, "Unknown") ? cmd_name : "Vendor Specific",
elapsed_utime(start_time, end_time));
if (err < 0) {
nvme_show_error("%s: %s", __func__, nvme_strerror(errno));
} else if (err) {
nvme_show_status(err);
} else {
fprintf(stderr, "%s Command %s is Success and result: 0x%08x\n", admin ? "Admin" : "IO",
strcmp(cmd_name, "Unknown") ? cmd_name : "Vendor Specific", result);
if (cfg.read)
passthru_print_read_output(cfg, data, dfd, mdata, mfd, err);
}
return err;
}
static int io_passthru(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc =
"Send a user-defined IO command to the specified device via IOCTL passthrough, return results.";
return passthru(argc, argv, false, desc, cmd);
}
static int admin_passthru(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc =
"Send a user-defined Admin command to the specified device via IOCTL passthrough, return results.";
return passthru(argc, argv, true, desc, cmd);
}
static int gen_hostnqn_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
char *hostnqn;
hostnqn = nvmf_hostnqn_generate();
if (!hostnqn) {
nvme_show_error("\"%s\" not supported. Install lib uuid and rebuild.",
command->name);
return -ENOTSUP;
}
printf("%s\n", hostnqn);
free(hostnqn);
return 0;
}
static int show_hostnqn_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
char *hostnqn;
hostnqn = nvmf_hostnqn_from_file();
if (!hostnqn)
hostnqn = nvmf_hostnqn_generate();
if (!hostnqn) {
nvme_show_error("hostnqn is not available -- use nvme gen-hostnqn");
return -ENOENT;
}
fprintf(stdout, "%s\n", hostnqn);
free(hostnqn);
return 0;
}
static int gen_dhchap_key(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc =
"Generate a DH-HMAC-CHAP host key usable for NVMe In-Band Authentication.";
const char *secret =
"Optional secret (in hexadecimal characters) to be used to initialize the host key.";
const char *key_len = "Length of the resulting key (32, 48, or 64 bytes).";
const char *hmac =
"HMAC function to use for key transformation (0 = none, 1 = SHA-256, 2 = SHA-384, 3 = SHA-512).";
const char *nqn = "Host NQN to use for key transformation.";
_cleanup_free_ unsigned char *raw_secret = NULL;
_cleanup_free_ char *hnqn = NULL;
unsigned char key[68];
char encoded_key[128];
unsigned long crc = crc32(0L, NULL, 0);
int err = 0;
struct config {
char *secret;
unsigned int key_len;
char *nqn;
unsigned int hmac;
};
struct config cfg = {
.secret = NULL,
.key_len = 0,
.nqn = NULL,
.hmac = 0,
};
NVME_ARGS(opts,
OPT_STR("secret", 's', &cfg.secret, secret),
OPT_UINT("key-length", 'l', &cfg.key_len, key_len),
OPT_STR("nqn", 'n', &cfg.nqn, nqn),
OPT_UINT("hmac", 'm', &cfg.hmac, hmac));
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
if (cfg.hmac > 3) {
nvme_show_error("Invalid HMAC identifier %u", cfg.hmac);
return -EINVAL;
}
if (cfg.hmac > 0) {
switch (cfg.hmac) {
case 1:
if (!cfg.key_len) {
cfg.key_len = 32;
} else if (cfg.key_len != 32) {
nvme_show_error("Invalid key length %d for SHA(256)", cfg.key_len);
return -EINVAL;
}
break;
case 2:
if (!cfg.key_len) {
cfg.key_len = 48;
} else if (cfg.key_len != 48) {
nvme_show_error("Invalid key length %d for SHA(384)", cfg.key_len);
return -EINVAL;
}
break;
case 3:
if (!cfg.key_len) {
cfg.key_len = 64;
} else if (cfg.key_len != 64) {
nvme_show_error("Invalid key length %d for SHA(512)", cfg.key_len);
return -EINVAL;
}
break;
default:
break;
}
} else if (!cfg.key_len) {
cfg.key_len = 32;
}
if (cfg.key_len != 32 && cfg.key_len != 48 && cfg.key_len != 64) {
nvme_show_error("Invalid key length %u", cfg.key_len);
return -EINVAL;
}
raw_secret = malloc(cfg.key_len);
if (!raw_secret)
return -ENOMEM;
if (!cfg.secret) {
if (getrandom_bytes(raw_secret, cfg.key_len) < 0)
return -errno;
} else {
int secret_len = 0, i;
unsigned int c;
for (i = 0; i < strlen(cfg.secret); i += 2) {
if (sscanf(&cfg.secret[i], "%02x", &c) != 1) {
nvme_show_error("Invalid secret '%s'", cfg.secret);
return -EINVAL;
}
raw_secret[secret_len++] = (unsigned char)c;
}
if (secret_len != cfg.key_len) {
nvme_show_error("Invalid key length (%d bytes)", secret_len);
return -EINVAL;
}
}
if (!cfg.nqn) {
cfg.nqn = hnqn = nvmf_hostnqn_from_file();
if (!cfg.nqn) {
nvme_show_error("Could not read host NQN");
return -ENOENT;
}
}
if (nvme_gen_dhchap_key(cfg.nqn, cfg.hmac, cfg.key_len, raw_secret, key) < 0)
return -errno;
crc = crc32(crc, key, cfg.key_len);
key[cfg.key_len++] = crc & 0xff;
key[cfg.key_len++] = (crc >> 8) & 0xff;
key[cfg.key_len++] = (crc >> 16) & 0xff;
key[cfg.key_len++] = (crc >> 24) & 0xff;
memset(encoded_key, 0, sizeof(encoded_key));
base64_encode(key, cfg.key_len, encoded_key);
printf("DHHC-1:%02x:%s:\n", cfg.hmac, encoded_key);
return 0;
}
static int check_dhchap_key(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc =
"Check a DH-HMAC-CHAP host key for usability for NVMe In-Band Authentication.";
const char *key = "DH-HMAC-CHAP key (in hexadecimal characters) to be validated.";
unsigned char decoded_key[128];
unsigned int decoded_len;
uint32_t crc = crc32(0L, NULL, 0);
uint32_t key_crc;
int err = 0, hmac;
struct config {
char *key;
};
struct config cfg = {
.key = NULL,
};
NVME_ARGS(opts,
OPT_STR("key", 'k', &cfg.key, key));
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
if (!cfg.key) {
nvme_show_error("Key not specified");
return -EINVAL;
}
if (sscanf(cfg.key, "DHHC-1:%02x:*s", &hmac) != 1) {
nvme_show_error("Invalid key header '%s'", cfg.key);
return -EINVAL;
}
switch (hmac) {
case 0:
break;
case 1:
if (strlen(cfg.key) != 59) {
nvme_show_error("Invalid key length for SHA(256)");
return -EINVAL;
}
break;
case 2:
if (strlen(cfg.key) != 83) {
nvme_show_error("Invalid key length for SHA(384)");
return -EINVAL;
}
break;
case 3:
if (strlen(cfg.key) != 103) {
nvme_show_error("Invalid key length for SHA(512)");
return -EINVAL;
}
break;
default:
nvme_show_error("Invalid HMAC identifier %d", hmac);
return -EINVAL;
}
err = base64_decode(cfg.key + 10, strlen(cfg.key) - 11, decoded_key);
if (err < 0) {
nvme_show_error("Base64 decoding failed, error %d", err);
return err;
}
decoded_len = err;
if (decoded_len < 32) {
nvme_show_error("Base64 decoding failed (%s, size %u)", cfg.key + 10, decoded_len);
return -EINVAL;
}
decoded_len -= 4;
if (decoded_len != 32 && decoded_len != 48 && decoded_len != 64) {
nvme_show_error("Invalid key length %d", decoded_len);
return -EINVAL;
}
crc = crc32(crc, decoded_key, decoded_len);
key_crc = ((uint32_t)decoded_key[decoded_len]) |
((uint32_t)decoded_key[decoded_len + 1] << 8) |
((uint32_t)decoded_key[decoded_len + 2] << 16) |
((uint32_t)decoded_key[decoded_len + 3] << 24);
if (key_crc != crc) {
nvme_show_error("CRC mismatch (key %08x, crc %08x)", key_crc, crc);
return -EINVAL;
}
printf("Key is valid (HMAC %d, length %d, CRC %08x)\n", hmac, decoded_len, crc);
return 0;
}
static int append_keyfile(const char *keyring, long id, const char *keyfile)
{
_cleanup_free_ unsigned char *key_data = NULL;
_cleanup_free_ char *exported_key = NULL;
_cleanup_free_ char *identity = NULL;
_cleanup_file_ FILE *fd = NULL;
int err, ver, hmac, key_len;
mode_t old_umask;
long kr_id;
char type;
kr_id = nvme_lookup_keyring(keyring);
if (kr_id <= 0) {
nvme_show_error("Failed to lookup keyring '%s', %s",
keyring, strerror(errno));
return -errno;
}
identity = nvme_describe_key_serial(id);
if (!identity) {
nvme_show_error("Failed to get identity info, %s",
strerror(errno));
return -errno;
}
if (sscanf(identity, "NVMe%01d%c%02d %*s", &ver, &type, &hmac) != 3) {
nvme_show_error("Failed to parse identity\n");
return -EINVAL;
}
key_data = nvme_read_key(kr_id, id, &key_len);
if (!key_data) {
nvme_show_error("Failed to read back derive TLS PSK, %s",
strerror(errno));
return -errno;
}
exported_key = nvme_export_tls_key_versioned(ver, hmac,
key_data, key_len);
if (!exported_key) {
nvme_show_error("Failed to export key, %s",
strerror(errno));
return -errno;
}
old_umask = umask(0);
fd = fopen(keyfile, "a");
if (!fd) {
nvme_show_error("Failed to open '%s', %s",
keyfile, strerror(errno));
err = -errno;
goto out;
}
err = fprintf(fd, "%s %s\n", identity, exported_key);
if (err < 0) {
nvme_show_error("Failed to append key to '%', %s",
keyfile, strerror(errno));
err = -errno;
} else {
err = 0;
}
out:
chmod(keyfile, 0600);
umask(old_umask);
return err;
}
static int gen_tls_key(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Generate a TLS key in NVMe PSK Interchange format.";
const char *secret =
"Optional secret (in hexadecimal characters) to be used for the TLS key.";
const char *hmac = "HMAC function to use for the retained key (1 = SHA-256, 2 = SHA-384).";
const char *version = "TLS identity version to use (0 = NVMe TCP 1.0c, 1 = NVMe TCP 2.0";
const char *hostnqn = "Host NQN for the retained key.";
const char *subsysnqn = "Subsystem NQN for the retained key.";
const char *keyring = "Keyring for the retained key.";
const char *keytype = "Key type of the retained key.";
const char *insert = "Insert retained key into the keyring.";
const char *keyfile = "Update key file with the derive TLS PSK.";
const char *compat = "Use non-RFC 8446 compliant algorithm for deriving TLS PSK for older implementations";
_cleanup_free_ unsigned char *raw_secret = NULL;
_cleanup_free_ char *encoded_key = NULL;
_cleanup_free_ char *hnqn = NULL;
int key_len = 32;
int err;
long tls_key;
struct config {
char *keyring;
char *keytype;
char *hostnqn;
char *subsysnqn;
char *secret;
char *keyfile;
unsigned char hmac;
unsigned char version;
bool insert;
bool compat;
};
struct config cfg = {
.keyring = ".nvme",
.keytype = "psk",
.hostnqn = NULL,
.subsysnqn = NULL,
.secret = NULL,
.keyfile = NULL,
.hmac = 1,
.version = 0,
.insert = false,
.compat = false,
};
NVME_ARGS(opts,
OPT_STR("keyring", 'k', &cfg.keyring, keyring),
OPT_STR("keytype", 't', &cfg.keytype, keytype),
OPT_STR("hostnqn", 'n', &cfg.hostnqn, hostnqn),
OPT_STR("subsysnqn", 'c', &cfg.subsysnqn, subsysnqn),
OPT_STR("secret", 's', &cfg.secret, secret),
OPT_STR("keyfile", 'f', &cfg.keyfile, keyfile),
OPT_BYTE("hmac", 'm', &cfg.hmac, hmac),
OPT_BYTE("identity", 'I', &cfg.version, version),
OPT_FLAG("insert", 'i', &cfg.insert, insert),
OPT_FLAG("compat", 'C', &cfg.compat, compat));
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
if (cfg.hmac < 1 || cfg.hmac > 2) {
nvme_show_error("Invalid HMAC identifier %u", cfg.hmac);
return -EINVAL;
}
if (cfg.version > 1) {
nvme_show_error("Invalid TLS identity version %u",
cfg.version);
return -EINVAL;
}
if (cfg.insert) {
if (!cfg.subsysnqn) {
nvme_show_error("No subsystem NQN specified");
return -EINVAL;
}
if (!cfg.hostnqn) {
cfg.hostnqn = hnqn = nvmf_hostnqn_from_file();
if (!cfg.hostnqn) {
nvme_show_error("Failed to read host NQN");
return -EINVAL;
}
}
}
if (cfg.hmac == 2)
key_len = 48;
raw_secret = malloc(key_len + 4);
if (!raw_secret)
return -ENOMEM;
if (!cfg.secret) {
if (getrandom_bytes(raw_secret, key_len) < 0)
return -errno;
} else {
int secret_len = 0, i;
unsigned int c;
for (i = 0; i < strlen(cfg.secret); i += 2) {
if (sscanf(&cfg.secret[i], "%02x", &c) != 1) {
nvme_show_error("Invalid secret '%s'", cfg.secret);
return -EINVAL;
}
if (i >= key_len * 2) {
fprintf(stderr, "Skipping excess secret bytes\n");
break;
}
raw_secret[secret_len++] = (unsigned char)c;
}
if (secret_len != key_len) {
nvme_show_error("Invalid key length (%d bytes)", secret_len);
return -EINVAL;
}
}
encoded_key = nvme_export_tls_key(raw_secret, key_len);
printf("%s\n", encoded_key);
if (cfg.insert) {
if (cfg.compat)
tls_key = nvme_insert_tls_key_compat(cfg.keyring,
cfg.keytype, cfg.hostnqn,
cfg.subsysnqn, cfg.version,
cfg.hmac, raw_secret, key_len);
else
tls_key = nvme_insert_tls_key_versioned(cfg.keyring,
cfg.keytype, cfg.hostnqn,
cfg.subsysnqn, cfg.version,
cfg.hmac, raw_secret, key_len);
if (tls_key <= 0) {
nvme_show_error("Failed to insert key, error %d", errno);
return -errno;
}
printf("Inserted TLS key %08x\n", (unsigned int)tls_key);
if (cfg.keyfile) {
err = append_keyfile(cfg.keyring, tls_key, cfg.keyfile);
if (err)
return err;
}
}
return 0;
}
static int check_tls_key(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Check a TLS key for NVMe PSK Interchange format.\n";
const char *keydata = "TLS key (in PSK Interchange format) to be validated.";
const char *identity = "TLS identity version to use (0 = NVMe TCP 1.0c, 1 = NVMe TCP 2.0)";
const char *hostnqn = "Host NQN for the retained key.";
const char *subsysnqn = "Subsystem NQN for the retained key.";
const char *keyring = "Keyring for the retained key.";
const char *keytype = "Key type of the retained key.";
const char *insert = "Insert retained key into the keyring.";
const char *keyfile = "Update key file with the derive TLS PSK.";
const char *compat = "Use non-RFC 8446 compliant algorithm for checking TLS PSK for older implementations.";
_cleanup_free_ unsigned char *decoded_key = NULL;
_cleanup_free_ char *hnqn = NULL;
int decoded_len, err = 0;
unsigned int hmac;
long tls_key;
struct config {
char *keyring;
char *keytype;
char *hostnqn;
char *subsysnqn;
char *keydata;
char *keyfile;
unsigned char identity;
bool insert;
bool compat;
};
struct config cfg = {
.keyring = ".nvme",
.keytype = "psk",
.hostnqn = NULL,
.subsysnqn = NULL,
.keydata = NULL,
.keyfile = NULL,
.identity = 0,
.insert = false,
.compat = false,
};
NVME_ARGS(opts,
OPT_STR("keyring", 'k', &cfg.keyring, keyring),
OPT_STR("keytype", 't', &cfg.keytype, keytype),
OPT_STR("hostnqn", 'n', &cfg.hostnqn, hostnqn),
OPT_STR("subsysnqn", 'c', &cfg.subsysnqn, subsysnqn),
OPT_STR("keydata", 'd', &cfg.keydata, keydata),
OPT_STR("keyfile", 'f', &cfg.keyfile, keyfile),
OPT_BYTE("identity", 'I', &cfg.identity, identity),
OPT_FLAG("insert", 'i', &cfg.insert, insert),
OPT_FLAG("compat", 'C', &cfg.compat, compat));
err = parse_args(argc, argv, desc, opts);
if (err)
return err;
if (!cfg.keydata) {
nvme_show_error("No key data");
return -EINVAL;
}
if (cfg.identity > 1) {
nvme_show_error("Invalid TLS identity version %u",
cfg.identity);
return -EINVAL;
}
decoded_key = nvme_import_tls_key(cfg.keydata, &decoded_len, &hmac);
if (!decoded_key) {
nvme_show_error("Key decoding failed, error %d\n", errno);
return -errno;
}
if (cfg.subsysnqn) {
if (!cfg.hostnqn) {
cfg.hostnqn = hnqn = nvmf_hostnqn_from_file();
if (!cfg.hostnqn) {
nvme_show_error("Failed to read host NQN");
return -EINVAL;
}
}
} else {
nvme_show_error("Need to specify a subsystem NQN");
return -EINVAL;
}
if (cfg.insert) {
if (cfg.compat)
tls_key = nvme_insert_tls_key_compat(cfg.keyring,
cfg.keytype, cfg.hostnqn,
cfg.subsysnqn, cfg.identity,
hmac, decoded_key, decoded_len);
else
tls_key = nvme_insert_tls_key_versioned(cfg.keyring,
cfg.keytype, cfg.hostnqn,
cfg.subsysnqn, cfg.identity,
hmac, decoded_key, decoded_len);
if (tls_key <= 0) {
nvme_show_error("Failed to insert key, error %d", errno);
return -errno;
}
printf("Inserted TLS key %08x\n", (unsigned int)tls_key);
if (cfg.keyfile) {
err = append_keyfile(cfg.keyring, tls_key, cfg.keyfile);
if (err)
return err;
}
} else {
_cleanup_free_ char *tls_id = NULL;
if (cfg.compat)
tls_id = nvme_generate_tls_key_identity_compat(cfg.hostnqn,
cfg.subsysnqn, cfg.identity,
hmac, decoded_key, decoded_len);
else
tls_id = nvme_generate_tls_key_identity(cfg.hostnqn,
cfg.subsysnqn, cfg.identity,
hmac, decoded_key, decoded_len);
if (!tls_id) {
nvme_show_error("Failed to generate identity, error %d",
errno);
return -errno;
}
printf("%s\n", tls_id);
}
return 0;
}
static void __scan_tls_key(long keyring_id, long key_id,
char *desc, int desc_len, void *data)
{
FILE *fd = data;
_cleanup_free_ const unsigned char *key_data = NULL;
_cleanup_free_ char *encoded_key = NULL;
int key_len;
int ver, hmac;
char type;
key_data = nvme_read_key(keyring_id, key_id, &key_len);
if (!key_data)
return;
if (sscanf(desc, "NVMe%01d%c%02d %*s", &ver, &type, &hmac) != 3)
return;
encoded_key = nvme_export_tls_key_versioned(ver, hmac,
key_data, key_len);
if (!encoded_key)
return;
fprintf(fd, "%s %s\n", desc, encoded_key);
}
static int import_key(const char *keyring, FILE *fd)
{
long keyring_id;
char tls_str[512];
char *tls_key;
unsigned char *psk;
unsigned int hmac;
int linenum = -1, key_len;
keyring_id = nvme_lookup_keyring(keyring);
if (!keyring_id) {
nvme_show_error("Invalid keyring '%s'", keyring);
return -ENOKEY;
}
while (fgets(tls_str, 512, fd)) {
linenum++;
tls_key = strrchr(tls_str, ' ');
if (!tls_key) {
nvme_show_error("Parse error in line %d",
linenum);
continue;
}
*tls_key = '\0';
tls_key++;
tls_key[strcspn(tls_key, "\n")] = 0;
psk = nvme_import_tls_key(tls_key, &key_len, &hmac);
if (!psk) {
nvme_show_error("Failed to import key in line %d",
linenum);
continue;
}
nvme_update_key(keyring_id, "psk", tls_str,
psk, key_len);
free(psk);
}
return 0;
}
static int tls_key(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Manipulation of TLS keys.\n";
const char *keyring = "Keyring for the retained key.";
const char *keytype = "Key type of the retained key.";
const char *keyfile = "File for list of keys.";
const char *import = "Import all keys into the keyring.";
const char *export = "Export all keys from the keyring.";
const char *revoke = "Revoke key from the keyring.";
_cleanup_file_ FILE *fd = NULL;
mode_t old_umask = 0;
int cnt, err = 0;
struct config {
char *keyring;
char *keytype;
char *keyfile;
bool import;
bool export;
char *revoke;
};
struct config cfg = {
.keyring = ".nvme",
.keytype = "psk",
.keyfile = NULL,
.import = false,
.export = false,
.revoke = NULL,
};
NVME_ARGS(opts,
OPT_STR("keyring", 'k', &cfg.keyring, keyring),
OPT_STR("keytype", 't', &cfg.keytype, keytype),
OPT_STR("keyfile", 'f', &cfg.keyfile, keyfile),
OPT_FLAG("import", 'i', &cfg.import, import),
OPT_FLAG("export", 'e', &cfg.export, export),
OPT_STR("revoke", 'r', &cfg.revoke, revoke));
err = argconfig_parse(argc, argv, desc, opts);
if (err)
return err;
if (cfg.keyfile) {
const char *mode;
if (cfg.import)
mode = "r";
else
mode = "w";
old_umask = umask(0);
fd = fopen(cfg.keyfile, mode);
if (!fd) {
nvme_show_error("Cannot open keyfile %s, error %d",
cfg.keyfile, errno);
return -errno;
}
} else {
if (cfg.import)
fd = freopen(NULL, "r", stdin);
else
fd = freopen(NULL, "w", stdout);
}
cnt = 0;
if (cfg.export) cnt++;
if (cfg.import) cnt++;
if (cfg.revoke) cnt++;
if (cnt != 1) {
nvme_show_error("Must specify either --import, --export or --revoke");
return -EINVAL;
} else if (cfg.export) {
err = nvme_scan_tls_keys(cfg.keyring, __scan_tls_key, fd);
if (err < 0) {
nvme_show_error("Export of TLS keys failed with '%s'",
nvme_strerror(errno));
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
printf("exporting to %s\n", cfg.keyfile);
return 0;
} else if (cfg.import) {
err = import_key(cfg.keyring, fd);
if (err) {
nvme_show_error("Import of TLS keys failed with '%s'",
nvme_strerror(errno));
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
printf("importing from %s\n", cfg.keyfile);
} else {
err = nvme_revoke_tls_key(cfg.keyring, cfg.keytype, cfg.revoke);
if (err) {
nvme_show_error("Failed to revoke key '%s'",
nvme_strerror(errno));
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
printf("revoking key\n");
}
if (old_umask != 0 && fd) {
umask(old_umask);
chmod(cfg.keyfile, 0600);
}
return err;
}
static int show_topology_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Show the topology\n";
const char *output_format = "Output format: normal|json|binary|tabular";
const char *ranking = "Ranking order: namespace|ctrl|multipath";
nvme_print_flags_t flags;
_cleanup_nvme_root_ nvme_root_t r = NULL;
char *devname = NULL;
nvme_scan_filter_t filter = NULL;
enum nvme_cli_topo_ranking rank;
int err;
struct config {
char *ranking;
};
struct config cfg = {
.ranking = "namespace",
};
NVME_ARGS(opts,
OPT_FMT("ranking", 'r', &cfg.ranking, ranking));
err = argconfig_parse(argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
if (argconfig_parse_seen(opts, "verbose"))
flags |= VERBOSE;
if (!strcmp(cfg.ranking, "namespace")) {
rank = NVME_CLI_TOPO_NAMESPACE;
} else if (!strcmp(cfg.ranking, "ctrl")) {
rank = NVME_CLI_TOPO_CTRL;
} else if (!strcmp(cfg.ranking, "multipath")) {
rank = NVME_CLI_TOPO_MULTIPATH;
} else {
nvme_show_error("Invalid ranking argument: %s", cfg.ranking);
return -EINVAL;
}
r = nvme_create_root(stderr, log_level);
if (!r) {
nvme_show_error("Failed to create topology root: %s", nvme_strerror(errno));
return -errno;
}
if (optind < argc)
devname = basename(argv[optind++]);
if (devname) {
int subsys_id, nsid;
if (sscanf(devname, "nvme%dn%d", &subsys_id, &nsid) != 2) {
nvme_show_error("Invalid device name %s\n", devname);
return -EINVAL;
}
filter = nvme_match_device_filter;
}
err = nvme_scan_topology(r, filter, (void *)devname);
if (err < 0) {
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
return err;
}
if (flags & TABULAR)
nvme_show_topology_tabular(r, flags);
else
nvme_show_topology(r, rank, flags);
return err;
}
static int discover_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Send Get Log Page request to Discovery Controller.";
return nvmf_discover(desc, argc, argv, false);
}
static int connect_all_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Discover NVMeoF subsystems and connect to them";
return nvmf_discover(desc, argc, argv, true);
}
static int connect_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Connect to NVMeoF subsystem";
return nvmf_connect(desc, argc, argv);
}
static int disconnect_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Disconnect from NVMeoF subsystem";
return nvmf_disconnect(desc, argc, argv);
}
int disconnect_all_cmd(int argc, char **argv, struct command *command,
struct plugin *plugin)
{
const char *desc = "Disconnect from all connected NVMeoF subsystems";
return nvmf_disconnect_all(desc, argc, argv);
}
static int config_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc = "Configuration of NVMeoF subsystems";
return nvmf_config(desc, argc, argv);
}
static int dim_cmd(int argc, char **argv, struct command *command, struct plugin *plugin)
{
const char *desc =
"Send Discovery Information Management command to a Discovery Controller (DC)";
return nvmf_dim(desc, argc, argv);
}
static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc)
{
const char *opcode = "opcode (required)";
const char *data_len = "data I/O length (bytes)";
const char *nmimt = "nvme-mi message type";
const char *nmd0 = "nvme management dword 0 value";
const char *nmd1 = "nvme management dword 1 value";
const char *input = "data input or output file";
int mode = 0644;
void *data = NULL;
int err = 0;
bool send;
_cleanup_fd_ int fd = -1;
int flags;
_cleanup_huge_ struct nvme_mem_huge mh = { 0, };
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u32 result;
struct config {
__u8 opcode;
__u32 namespace_id;
__u32 data_len;
__u32 nmimt;
__u32 nmd0;
__u32 nmd1;
char *input_file;
};
struct config cfg = {
.opcode = 0,
.namespace_id = 0,
.data_len = 0,
.nmimt = 0,
.nmd0 = 0,
.nmd1 = 0,
.input_file = "",
};
NVME_ARGS(opts,
OPT_BYTE("opcode", 'O', &cfg.opcode, opcode),
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_UINT("data-len", 'l', &cfg.data_len, data_len),
OPT_UINT("nmimt", 'm', &cfg.nmimt, nmimt),
OPT_UINT("nmd0", '0', &cfg.nmd0, nmd0),
OPT_UINT("nmd1", '1', &cfg.nmd1, nmd1),
OPT_FILE("input-file", 'i', &cfg.input_file, input));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (!argconfig_parse_seen(opts, "opcode")) {
nvme_show_error("%s: opcode parameter required", *argv);
return -EINVAL;
}
if (admin_opcode == nvme_admin_nvme_mi_send) {
flags = O_RDONLY;
fd = STDIN_FILENO;
send = true;
} else {
flags = O_WRONLY | O_CREAT;
fd = STDOUT_FILENO;
send = false;
}
if (strlen(cfg.input_file)) {
fd = open(cfg.input_file, flags, mode);
if (fd < 0) {
nvme_show_perror(cfg.input_file);
return -EINVAL;
}
}
if (cfg.data_len) {
data = nvme_alloc_huge(cfg.data_len, &mh);
if (!data) {
nvme_show_error("failed to allocate huge memory");
return -ENOMEM;
}
if (send) {
if (read(fd, data, cfg.data_len) < 0) {
err = -errno;
nvme_show_error("failed to read write buffer %s", strerror(errno));
return err;
}
}
}
err = nvme_cli_admin_passthru(dev, admin_opcode, 0, 0, cfg.namespace_id, 0, 0,
cfg.nmimt << 11 | 4, cfg.opcode, cfg.nmd0, cfg.nmd1, 0, 0,
cfg.data_len, data, 0, NULL, 0, &result);
if (err < 0) {
nvme_show_error("nmi_recv: %s", nvme_strerror(errno));
} else if (err) {
nvme_show_status(err);
} else {
printf(
"%s Command is Success and result: 0x%08x (status: 0x%02x, response: 0x%06x)\n",
nvme_cmd_to_string(true, admin_opcode), result, result & 0xff, result >> 8);
if (result & 0xff)
printf("status: %s\n", nvme_mi_status_to_string(result & 0xff));
if (!send && strlen(cfg.input_file)) {
if (write(fd, (void *)data, cfg.data_len) < 0)
perror("failed to write data buffer");
} else if (data && !send && !err) {
d((unsigned char *)data, cfg.data_len, 16, 1);
}
}
return err;
}
static int nmi_recv(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc =
"Send a NVMe-MI Receive command to the specified device, return results.";
return nvme_mi(argc, argv, nvme_admin_nvme_mi_recv, desc);
}
static int nmi_send(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Send a NVMe-MI Send command to the specified device, return results.";
return nvme_mi(argc, argv, nvme_admin_nvme_mi_send, desc);
}
static int get_mgmt_addr_list_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Management Address List Log, show it";
nvme_print_flags_t flags;
int err = -1;
_cleanup_free_ struct nvme_mgmt_addr_list_log *ma_log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
NVME_ARGS(opts);
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
ma_log = nvme_alloc(sizeof(*ma_log));
if (!ma_log)
return -ENOMEM;
err = nvme_cli_get_log_mgmt_addr_list(dev, sizeof(*ma_log), ma_log);
if (!err)
nvme_show_mgmt_addr_list_log(ma_log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("management address list log");
return err;
}
static int get_rotational_media_info_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve Rotational Media Information Log, show it";
nvme_print_flags_t flags;
int err = -1;
_cleanup_free_ struct nvme_rotational_media_info_log *info = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct config {
__u16 endgid;
};
struct config cfg = {
.endgid = 0,
};
NVME_ARGS(opts,
OPT_UINT("endg-id", 'e', &cfg.endgid, endgid));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
info = nvme_alloc(sizeof(*info));
if (!info)
return -ENOMEM;
err = nvme_cli_get_log_rotational_media_info(dev, cfg.endgid, sizeof(*info), info);
if (!err)
nvme_show_rotational_media_info_log(info, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("rotational media info log");
return err;
}
static int get_dispersed_ns_psub(struct nvme_dev *dev, __u32 nsid,
struct nvme_dispersed_ns_participating_nss_log **logp)
{
int err;
__u64 header_len = sizeof(**logp);
__u64 psub_list_len;
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = nvme_cfg.timeout,
.lid = NVME_LOG_LID_DISPERSED_NS_PARTICIPATING_NSS,
.nsid = nsid,
.lpo = header_len,
};
struct nvme_dispersed_ns_participating_nss_log *log = nvme_alloc(header_len);
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_dispersed_ns_participating_nss(dev, nsid, header_len, log);
if (err)
goto err_free;
psub_list_len = le64_to_cpu(log->numpsub) * NVME_NQN_LENGTH;
log = nvme_realloc(log, header_len + psub_list_len);
if (!log) {
err = -ENOMEM;
goto err_free;
}
args.log = log->participating_nss,
args.len = psub_list_len;
err = nvme_cli_get_log_page(dev, NVME_LOG_PAGE_PDU_SIZE, &args);
if (err)
goto err_free;
*logp = log;
return 0;
err_free:
free(log);
return err;
}
static int get_dispersed_ns_participating_nss_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve Dispersed Namespace Participating NVM Subsystems Log, show it";
nvme_print_flags_t flags;
int err;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
_cleanup_free_ struct nvme_dispersed_ns_participating_nss_log *log = NULL;
struct config {
__u32 namespace_id;
};
struct config cfg = {
.namespace_id = 1,
};
NVME_ARGS(opts, OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_id_desired));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = get_dispersed_ns_psub(dev, cfg.namespace_id, &log);
if (!err)
nvme_show_dispersed_ns_psub_log(log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("dispersed ns participating nss log");
return err;
}
static int get_log_offset(struct nvme_dev *dev, struct nvme_get_log_args *args, __u64 *offset,
__u32 len, void **log)
{
args->lpo = *offset,
args->log = *log + *offset,
args->len = len;
*offset += args->len;
*log = nvme_realloc(*log, *offset);
if (!*log)
return -ENOMEM;
return nvme_cli_get_log_page(dev, NVME_LOG_PAGE_PDU_SIZE, args);
}
static int get_reachability_group_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
__u64 *offset, struct nvme_reachability_groups_log **logp)
{
int err;
struct nvme_reachability_groups_log *log = *logp;
__u16 i;
__u32 len;
for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
len = sizeof(*log->rgd);
err = get_log_offset(dev, args, offset, len, (void **)&log);
if (err)
goto err_free;
len = le32_to_cpu(log->rgd[i].nnid) * sizeof(*log->rgd[i].nsid);
err = get_log_offset(dev, args, offset, len, (void **)&log);
if (err)
goto err_free;
}
*logp = log;
return 0;
err_free:
free(log);
*logp = NULL;
return err;
}
static int get_reachability_groups(struct nvme_dev *dev, bool rgo, bool rae,
struct nvme_reachability_groups_log **logp,
__u64 *lenp)
{
int err;
struct nvme_reachability_groups_log *log;
__u64 log_len = sizeof(*log);
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = nvme_cfg.timeout,
.lid = NVME_LOG_LID_REACHABILITY_GROUPS,
.nsid = NVME_NSID_ALL,
.lsp = rgo,
.rae = rae,
};
log = nvme_alloc(log_len);
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_reachability_groups(dev, rgo, rae, log_len, log);
if (err)
goto err_free;
err = get_reachability_group_desc(dev, &args, &log_len, &log);
if (err)
goto err_free;
*logp = log;
*lenp = log_len;
return 0;
err_free:
free(log);
return err;
}
static int get_reachability_groups_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve Reachability Groups Log, show it";
const char *rgo = "Return Groups Only";
nvme_print_flags_t flags;
int err;
__u64 len = 0;
_cleanup_free_ struct nvme_reachability_groups_log *log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct config {
bool rgo;
bool rae;
};
struct config cfg = {
.rgo = false,
.rae = false,
};
NVME_ARGS(opts,
OPT_FLAG("groups-only", 'g', &cfg.rgo, rgo),
OPT_FLAG("rae", 'r', &cfg.rae, rae));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = get_reachability_groups(dev, cfg.rgo, cfg.rae, &log, &len);
if (!err)
nvme_show_reachability_groups_log(log, len, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("reachability groups log");
return err;
}
static int get_reachability_association_desc(struct nvme_dev *dev, struct nvme_get_log_args *args,
__u64 *offset,
struct nvme_reachability_associations_log **logp)
{
int err;
struct nvme_reachability_associations_log *log = *logp;
__u16 i;
__u32 len;
for (i = 0; i < le16_to_cpu(log->nrad); i++) {
len = sizeof(*log->rad);
err = get_log_offset(dev, args, offset, len, (void **)&log);
if (err)
goto err_free;
len = le32_to_cpu(log->rad[i].nrid) * sizeof(*log->rad[i].rgid);
err = get_log_offset(dev, args, offset, len, (void **)&log);
if (err)
goto err_free;
}
*logp = log;
return 0;
err_free:
free(log);
*logp = NULL;
return err;
}
static int get_reachability_associations(struct nvme_dev *dev, bool rao, bool rae,
struct nvme_reachability_associations_log **logp,
__u64 *lenp)
{
int err;
struct nvme_reachability_associations_log *log;
__u64 log_len = sizeof(*log);
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = nvme_cfg.timeout,
.lid = NVME_LOG_LID_REACHABILITY_ASSOCIATIONS,
.nsid = NVME_NSID_ALL,
.lsp = rao,
.rae = rae,
};
log = nvme_alloc(log_len);
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_reachability_associations(dev, rao, rae, log_len, log);
if (err)
goto err_free;
err = get_reachability_association_desc(dev, &args, &log_len, &log);
if (err)
goto err_free;
*logp = log;
*lenp = log_len;
return 0;
err_free:
free(log);
return err;
}
static int get_reachability_associations_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve Reachability Associations Log, show it";
const char *rao = "Return Associations Only";
nvme_print_flags_t flags;
int err;
__u64 len = 0;
_cleanup_free_ struct nvme_reachability_associations_log *log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct config {
bool rao;
bool rae;
};
struct config cfg = {
.rao = false,
.rae = false,
};
NVME_ARGS(opts,
OPT_FLAG("associations-only", 'a', &cfg.rao, rao),
OPT_FLAG("rae", 'r', &cfg.rae, rae));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = get_reachability_associations(dev, cfg.rao, cfg.rae, &log, &len);
if (!err)
nvme_show_reachability_associations_log(log, len, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("reachability associations log");
return err;
}
static int get_host_discovery(struct nvme_dev *dev, bool allhoste, bool rae,
struct nvme_host_discover_log **logp)
{
int err;
struct nvme_host_discover_log *log;
__u64 log_len = sizeof(*log);
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = nvme_cfg.timeout,
.lid = NVME_LOG_LID_HOST_DISCOVER,
.nsid = NVME_NSID_ALL,
.lsp = allhoste,
.rae = rae,
};
log = nvme_alloc(log_len);
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_host_discovery(dev, allhoste, rae, log_len, log);
if (err)
goto err_free;
log_len = le32_to_cpu(log->thdlpl);
err = get_log_offset(dev, &args, &log_len, le32_to_cpu(log->thdlpl) - log_len,
(void **)&log);
if (err)
goto err_free;
*logp = log;
return 0;
err_free:
free(log);
return err;
}
static int get_host_discovery_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve Host Discovery Log, show it";
const char *allhoste = "All Host Entries";
nvme_print_flags_t flags;
int err;
_cleanup_free_ struct nvme_host_discover_log *log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct config {
bool allhoste;
bool rae;
};
struct config cfg = {
.allhoste = false,
.rae = false,
};
NVME_ARGS(opts,
OPT_FLAG("all-host-entries", 'a', &cfg.allhoste, allhoste),
OPT_FLAG("rae", 'r', &cfg.rae, rae));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = get_host_discovery(dev, cfg.allhoste, cfg.rae, &log);
if (!err)
nvme_show_host_discovery_log(log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("host discovery log");
return err;
}
static int get_ave_discovery(struct nvme_dev *dev, bool rae, struct nvme_ave_discover_log **logp)
{
int err;
struct nvme_ave_discover_log *log;
__u64 log_len = sizeof(*log);
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = nvme_cfg.timeout,
.lid = NVME_LOG_LID_AVE_DISCOVER,
.nsid = NVME_NSID_ALL,
.rae = rae,
};
log = nvme_alloc(log_len);
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_ave_discovery(dev, rae, log_len, log);
if (err)
goto err_free;
log_len = le32_to_cpu(log->tadlpl);
err = get_log_offset(dev, &args, &log_len, le32_to_cpu(log->tadlpl) - log_len,
(void **)&log);
if (err)
goto err_free;
*logp = log;
return 0;
err_free:
free(log);
return err;
}
static int get_ave_discovery_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
const char *desc = "Retrieve AVE Discovery Log, show it";
nvme_print_flags_t flags;
int err;
_cleanup_free_ struct nvme_ave_discover_log *log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct config {
bool rae;
};
struct config cfg = {
.rae = false,
};
NVME_ARGS(opts, OPT_FLAG("rae", 'r', &cfg.rae, rae));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = get_ave_discovery(dev, cfg.rae, &log);
if (!err)
nvme_show_ave_discovery_log(log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("ave discovery log");
return err;
}
static int get_pull_model_ddc_req(struct nvme_dev *dev,
bool rae, struct nvme_pull_model_ddc_req_log **logp)
{
int err;
struct nvme_pull_model_ddc_req_log *log;
__u64 log_len = sizeof(*log);
struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.timeout = nvme_cfg.timeout,
.lid = NVME_LOG_LID_PULL_MODEL_DDC_REQ,
.nsid = NVME_NSID_ALL,
.rae = rae,
};
log = nvme_alloc(log_len);
if (!log)
return -ENOMEM;
err = nvme_cli_get_log_pull_model_ddc_req(dev, rae, log_len, log);
if (err)
goto err_free;
log_len = le32_to_cpu(log->tpdrpl);
err = get_log_offset(dev, &args, &log_len, le32_to_cpu(log->tpdrpl) - log_len,
(void **)&log);
if (err)
goto err_free;
*logp = log;
return 0;
err_free:
free(log);
return err;
}
static int get_pull_model_ddc_req_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Retrieve Pull Model DDC Request Log, show it";
nvme_print_flags_t flags;
int err;
_cleanup_free_ struct nvme_pull_model_ddc_req_log *log = NULL;
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
struct config {
bool rae;
};
struct config cfg = {
.rae = false,
};
NVME_ARGS(opts, OPT_FLAG("rae", 'r', &cfg.rae, rae));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
return err;
}
err = get_pull_model_ddc_req(dev, cfg.rae, &log);
if (!err)
nvme_show_pull_model_ddc_req_log(log, flags);
else if (err > 0)
nvme_show_status(err);
else
nvme_show_perror("pull model ddc req log");
return err;
}
void register_extension(struct plugin *plugin)
{
plugin->parent = &nvme;
nvme.extensions->tail->next = plugin;
nvme.extensions->tail = plugin;
}
int main(int argc, char **argv)
{
int err;
nvme.extensions->parent = &nvme;
if (argc < 2) {
general_help(&builtin, NULL);
return 0;
}
setlocale(LC_ALL, "");
err = nvme_install_sigint_handler();
if (err)
return err;
err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
if (err == -ENOTTY)
general_help(&builtin, NULL);
return err ? 1 : 0;
}
|