/usr/sbin/lustre_createcsv is in lustre-utils 1.8.5+dfsg-3ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
| 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 | #!/bin/bash
# vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
#
# lustre_createcsv - generate a csv file from a running lustre cluster
#
# This script is used to collect lustre target informations, linux MD/LVM device
# informations and HA software configurations in a lustre cluster to generate a
# csv file. In reverse, the csv file could be parsed by lustre_config to 
# configure multiple lustre servers in parallel.
#
# This script should be run on the MGS node.
#
################################################################################
# Usage
usage() {
	cat <<EOF
Usage:	`basename $0` [-t HAtype] [-d] [-h] [-v] [-f csv_filename]
	This script is used to collect lustre target informations, linux MD/LVM
	device informations and HA software configurations from a running lustre
	cluster to generate a csv file. It should be run on the MGS node.
	-t HAtype	collect High-Availability software configurations
			The argument following -t is used to indicate the High-
			Availability software type. The HA software types which 
			are currently supported are: hbv1 (Heartbeat version 1)
			and hbv2 (Heartbeat version 2).
	-d		collect linux MD/LVM device informations
	-h		help
	-v		verbose mode
	-f csv_filename	designate a name for the csv file
			Default is lustre_config.csv.
EOF
}
# Get the library of functions
. /usr/share/lustre/lc_common
#**************************** Global variables ****************************#
# csv file
LUSTRE_CSV_FILE=${LUSTRE_CSV_FILE:-"lustre_config.csv"}
# Lustre proc files
LUSTRE_PROC=${LUSTRE_PROC:-"/proc/fs/lustre"}
LUSTRE_PROC_DEVICES=${LUSTRE_PROC}/devices
LNET_PROC=${LNET_PROC:-"/proc/sys/lnet"}
LNET_PROC_PEERS=${LNET_PROC}/peers
# Default network module options
DEFAULT_MOD_OPTS=${DEFAULT_MOD_OPTS:-"options lnet networks=tcp"}
# Lustre target obd device types
MGS_TYPE=${MGS_TYPE:-"mgs"}
MDT_TYPE=${MDT_TYPE:-"mds"}
OST_TYPE=${OST_TYPE:-"obdfilter"}
# The obd name of MGS target server
MGS_SVNAME=${MGS_SVNAME:-"MGS"}		
# Hostnames of the lustre cluster nodes
declare -a HOST_NAMES			
MGS_HOSTNAME=${MGS_HOSTNAME:-"`hostname`"} # Hostname of the MGS node
# Configs of lustre targets in one cluster node
declare -a TARGET_CONFIGS		
declare -a TARGET_SVNAMES TARGET_DEVNAMES TARGET_DEVSIZES TARGET_MNTPNTS
declare -a TARGET_DEVTYPES TARGET_FSNAMES TARGET_MGSNIDS TARGET_INDEXES
declare -a TARGET_FMTOPTS TARGET_MKFSOPTS TARGET_MNTOPTS TARGET_FAILNIDS
declare -a HA_CONFIGS
declare -a ALL_TARGET_SVNAMES		# All the target services in the cluster
declare -a FAILOVER_FMTOPTS		# "--noformat"	
# Informations of linux MD/LVM devices in one cluster node
declare -a MD_NAME MD_LEVEL MD_DEVS	# MD
declare -a VG_NAME VG_PVNAMES		# VG
declare -a LV_NAME LV_SIZE LV_VGNAME	# LV
# Lustre target service types
let "LDD_F_SV_TYPE_MDT = 0x0001"
let "LDD_F_SV_TYPE_OST = 0x0002"
let "LDD_F_SV_TYPE_MGS = 0x0004"
# Permanent mount options for ext3 or ldiskfs
ALWAYS_MNTOPTS=${ALWAYS_MNTOPTS:-"errors=remount-ro"}
MDT_MGS_ALWAYS_MNTOPTS=${MDT_MGS_ALWAYS_MNTOPTS:-",iopen_nopriv,user_xattr"}
OST_ALWAYS_MNTOPTS=${OST_ALWAYS_MNTOPTS:-",asyncdel"}
OST_DEFAULT_MNTOPTS=${OST_DEFAULT_MNTOPTS:-",extents,mballoc"}
# User-settable parameter keys
PARAM_MGSNODE=${PARAM_MGSNODE:-"mgsnode="}
PARAM_FAILNODE=${PARAM_FAILNODE:-"failover.node="}
# Block size
L_BLOCK_SIZE=4096
# Option string of mkfs.lustre
OPTSTR_STRIPE_COUNT=${OPTSTR_STRIPE_COUNT:-"--stripe-count-hint="}
# Get and check the positional parameters
VERBOSE_OUTPUT=false
GET_MDLVM_INFO=false
while getopts "t:dhvf:" OPTION; do
	case $OPTION in
	t) 
		HATYPE_OPT=$OPTARG
		if [ "${HATYPE_OPT}" != "${HBVER_HBV1}" ] \
		&& [ "${HATYPE_OPT}" != "${HBVER_HBV2}" ] \
		&& [ "${HATYPE_OPT}" != "${HATYPE_CLUMGR}" ]; then
			error_output "Invalid HA software type" \
				 "- ${HATYPE_OPT}!"
			usage 1>&2
            exit 1
		fi
		;;
	d)	GET_MDLVM_INFO=true;;
	h)	usage && exit 0;;
	v) 	VERBOSE_OUTPUT=true;;
	f)	LUSTRE_CSV_FILE=$OPTARG;;
    ?) 	usage 1>&2 && exit 1;;
	esac
done
# Verify the local host is the MGS node
mgs_node() {
	if [ ! -e ${LUSTRE_PROC_DEVICES} ]; then
		error_output "${LUSTRE_PROC_DEVICES} does" \
			 "not exist. Lustre kernel modules may not be loaded!"
		return 1
	fi
	if [ -z "`cat ${LUSTRE_PROC_DEVICES}`" ]; then
		error_output "${LUSTRE_PROC_DEVICES} is" \
			 "empty. Lustre services may not be started!"
		return 1
	fi
	if [ -z "`grep ${MGS_TYPE} ${LUSTRE_PROC_DEVICES}`" ]; then
		error_output "This node is not a MGS node." \
                         "The script should be run on the MGS node!"
		return 1
	fi
	return 0
}
# get_hostnames
# Get lustre cluster node names
get_hostnames() {
	declare -a HOST_NIDS
	declare -i idx		# Index of HOST_NIDS array
	declare -i i		# Index of HOST_NAMES array
	if ! mgs_node; then
		return 1
	fi
	if [ ! -e ${LNET_PROC_PEERS} ]; then
		error_output "${LNET_PROC_PEERS} does not" \
                         "exist. LNET kernel modules may not be loaded" \
			 "or LNET network may not be up!"
		return 1
	fi
	HOST_NAMES[0]=${MGS_HOSTNAME} # MGS node
	HOST_NIDS[0]=${HOST_NAMES[0]}
	# Get the nids of the nodes which have contacted MGS
	idx=1
	for nid in `cat ${LNET_PROC_PEERS} | awk '{print $1}'`; do
		if [ "${nid}" = "nid" ]; then
			continue
		fi
		HOST_NIDS[idx]=${nid}
		let "idx += 1"
	done
	if [ ${idx} -eq 1 ]; then
		verbose_output "Only one node running in the lustre cluster." \
			       "It's ${HOST_NAMES[0]}."
		return 0		
	fi
	# Get the hostnames of the nodes
	for ((idx = 1, i = 1; idx < ${#HOST_NIDS[@]}; idx++, i++)); do
		if [ -z "${HOST_NIDS[idx]}" ]; then
			error_output "get_hostnames():" \
				 "Invalid nid - \"${HOST_NIDS[idx]}\"!"
			return 1
		fi
		HOST_NAMES[i]=$(nid2hostname ${HOST_NIDS[idx]})
		if [ $? -ne 0 ]; then
			error_output "${HOST_NAMES[i]}"
			return 1
		fi
		if [ "${HOST_NAMES[i]}" = "${HOST_NAMES[0]}" ]; then
			unset HOST_NAMES[i]
			let "i -= 1"
		fi
	done
	return 0
}
#********************** Linux MD/LVM device informations **********************#
# get_md_configs hostname
# Get all the active MD device informations from the node @hostname
get_md_configs() {
	declare -i i=0
	declare -i j=0
	local host_name=$1
	local ret_line line first_item
	# Initialize the arrays
	unset MD_NAME
	unset MD_LEVEL
	unset MD_DEVS
	
	# Execute remote command to the node ${host_name} and get all the
	# active MD device informations.
	while read -r ret_line; do
		if is_pdsh; then
                	set -- ${ret_line}
			shift
			line="$*"
		else
			line="${ret_line}"
		fi
		first_item=`echo "${line}" | awk '{print $1}'`
		# Get the MD device name and raid level
		if [ "${first_item}" = "ARRAY" ]; then
			MD_NAME[i]=`echo "${line}" | awk '{print $2}'`
			MD_LEVEL[i]=`echo "${line}" | awk '{print $3}' | sed -e 's/level=//'`
			let "j = i"
			let "i += 1"
		fi
		# Get the MD component devices
		if [ "${first_item}" != "${first_item#devices=}" ]; then
			MD_DEVS[j]=`echo "${line}" | sed -e 's/devices=//' -e 's/,/ /g'`
		fi
        done < <(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin
        ${MDADM} --detail --scan --verbose")
	if [ $i -eq 0 ]; then
		verbose_output "There are no active MD devices" \
			       "in the host ${host_name}!"
	fi
	return 0
}
# get_pv_configs hostname
# Get all the LVM PV informations from the node @hostname
get_pv_configs() {
	PV_NAMES=
	local host_name=$1
	local cmd ret_str
	# Execute remote command to get all the PV informations.
	cmd="PATH=\$PATH:/sbin:/usr/sbin \
pvdisplay -c | awk -F: '{print \$1}' | xargs"
	ret_str=`${REMOTE} ${host_name} "${cmd}" 2>&1`
	if [ $? -ne 0 ]; then
		if [ -n "${ret_str}" ]; then
			error_output "get_pv_configs():" \
			"remote command to ${host_name} error: ${ret_str}"
		else
			remote_error "get_pv_configs" ${host_name}
		fi
		return 1
	fi
	PV_NAMES=`echo "${ret_str}" | sed -e 's/^'${host_name}':[[:space:]]//'`
	if [ -z "${PV_NAMES}" ]; then
		verbose_output "There are no PVs in the host ${host_name}!"
		return 0
	fi
	return 0
}
# get_vg_pvnames hostname vgname
# Get the PVs contained in @vgname from the node @hostname
get_vg_pvnames() {
	local host_name=$1
	local vg_name=$2
	local pv_names=
	local cmd ret_str
	# Execute remote command to get the PV names.
	cmd="PATH=\$PATH:/sbin:/usr/sbin vgdisplay -v ${vg_name} 2>/dev/null\
	     | grep \"PV Name\" | awk '{print \$3}' | xargs"
	ret_str=`${REMOTE} ${host_name} "${cmd}" 2>&1`
	if [ $? -ne 0 ]; then
		if [ -n "${ret_str}" ]; then
			echo "`basename $0`: get_vg_pvnames() error:" \
			"remote command to ${host_name} error: ${ret_str}"
		else
			remote_error "get_vg_pvnames" ${host_name}
		fi
		return 1
	fi
	pv_names=`echo "${ret_str}" | sed -e 's/^'${host_name}':[[:space:]]//'`
	if [ -z "${pv_names}" ]; then
		echo "`basename $0`: get_vg_pvnames() error:" \
		"There are no PVs in VG ${vg_name} in the host ${host_name}!"\
		"Or VG ${vg_name} does not exist."
		return 1
	fi
	echo "${pv_names}"
	return 0
}
# get_vg_configs hostname
# Get all the LVM VG informations from the node @hostname
get_vg_configs() {
	declare -i i=0
	local host_name=$1
	local cmd ret_str
	local vg_name
	# Initialize the arrays
	unset VG_NAME
	unset VG_PVNAMES
	# Execute remote command to get all the VG names.
	cmd="PATH=\$PATH:/sbin:/usr/sbin vgdisplay \
	     | grep \"VG Name\" | awk '{print \$3}' | xargs"
	ret_str=`${REMOTE} ${host_name} "${cmd}" 2>&1`
	if [ $? -ne 0 ]; then
		if [ -n "${ret_str}" ]; then
			error_output "get_vg_configs():" \
			"remote command to ${host_name} error: ${ret_str}"
		else
			remote_error "get_vg_configs" ${host_name}
		fi
		return 1
	fi
	if [ -z "${ret_str}" ] \
	|| [ "${ret_str}" != "${ret_str#*No volume groups found*}" ]; then
		verbose_output "There are no VGs in the host ${host_name}!"
		return 0
	fi
	# Get all the VG informations
	for vg_name in `echo "${ret_str}" | sed -e 's/^'${host_name}'://'`; do
		VG_NAME[i]=${vg_name}
		VG_PVNAMES[i]=$(get_vg_pvnames ${host_name} ${VG_NAME[i]})
		if [ $? -ne 0 ]; then
			error_output "${VG_PVNAMES[i]}"
			return 1
		fi
		let "i += 1"
	done
	return 0
}
# get_lv_configs hostname
# Get all the LVM LV informations from the node @hostname
get_lv_configs() {
	declare -i i=0
	local host_name=$1
	local ret_line line
	# Initialize the arrays
	unset LV_NAME
	unset LV_SIZE
	unset LV_VGNAME
	# Execute remote command to get all the LV informations.
	while read -r ret_line; do
		if is_pdsh; then
                	set -- ${ret_line}
			shift
			line="$*"
		else
			line="${ret_line}"
		fi
		[ "${line}" != "${line#*volume group*}" ] && break
		LV_NAME[i]=`echo "${line}" | awk -F: '{print $1}' | sed -e 's/.*\///g'`
		LV_VGNAME[i]=`echo "${line}" | awk -F: '{print $2}'`
		LV_SIZE[i]=`echo "${line}" | awk -F: '{print $7}' | sed -e 's/.*/&K/'`
		let "i += 1"
        done < <(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin lvdisplay -c")
	if [ $i -eq 0 ]; then
		verbose_output "There are no LVs in the host ${host_name}"
	fi
	return 0
}
#*************************** Network module options ***************************#
# last_is_backslash line
# Check whether the last effective letter of @line is a backslash
last_is_backslash() {
	local line="$*"
	declare -i i
	declare -i length
	local letter last_letter
	length=${#line}
	for ((i = ${length}-1; i >= 0; i--)); do
		letter=${line:${i}:1}
        	[ "x${letter}" != "x " -a "x${letter}" != "x	" -a -n "${letter}" ]\
		&& last_letter=${letter} && break
	done
	[ "x${last_letter}" = "x\\" ] && return 0
	return 1
}
# get_module_opts hostname
# Get the network module options from the node @hostname 
get_module_opts() {
	local host_name=$1
	local ret_str
	local MODULE_CONF KERNEL_VER
	local ret_line line find_options
	local continue_flag
	MODULE_OPTS=${DEFAULT_MOD_OPTS}
	# Execute remote command to get the kernel version
	ret_str=`${REMOTE} ${host_name} "uname -r" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		error_output "get_module_opts():" \
			 "remote command error: ${ret_str}"
		return 1
	fi
	remote_error "get_module_opts" ${host_name} "${ret_str}" && return 1
	if is_pdsh; then
		KERNEL_VER=`echo ${ret_str} | awk '{print $2}'`
	else
		KERNEL_VER=`echo ${ret_str} | awk '{print $1}'`
	fi
	# Get the module configuration file name
	if [ "${KERNEL_VER:0:3}" = "2.4" ]; then
        	MODULE_CONF=/etc/modules.conf
	else
        	MODULE_CONF=/etc/modprobe.conf
	fi
	# Execute remote command to get the lustre network module options
	continue_flag=false
	find_options=false
	while read -r ret_line; do
		if is_pdsh; then
                	set -- ${ret_line}
			shift
			line="$*"
		else
			line="${ret_line}"
		fi
		# Get rid of the comment line
		[ -z "`echo \"${line}\"|egrep -v \"^#\"`" ] && continue
		if [ "${line}" != "${line#*options lnet*}" ]; then
			if ! ${find_options}; then
				find_options=true
				MODULE_OPTS=${line}
			else
				MODULE_OPTS=${MODULE_OPTS}$" \n "${line}
			fi
			last_is_backslash "${line}" && continue_flag=true \
			|| continue_flag=false
			continue
		fi	
		if ${continue_flag}; then
			MODULE_OPTS=${MODULE_OPTS}$" \n "${line}
			! last_is_backslash "${line}" && continue_flag=false
		fi
        done < <(${REMOTE} ${host_name} "cat ${MODULE_CONF}")
	if [ -z "${MODULE_OPTS}" ]; then
		MODULE_OPTS=${DEFAULT_MOD_OPTS}
	fi
	return 0
}
#************************ HA software configurations ************************#
# is_ha_target hostname target_devname
# Check whether the target @target_devname was made to be high-available
is_ha_target() {
	local host_name=$1
	local target_svname=$2
	local res_file
	local ret_str
	case "${HATYPE_OPT}" in
	"${HBVER_HBV1}")	res_file=${HA_RES};;
	"${HBVER_HBV2}")	res_file=${HA_CIB};;
	"${HATYPE_CLUMGR}")	res_file=${CLUMAN_CONFIG};;
	esac
	# Execute remote command to check the resource file
	ret_str=`${REMOTE} ${host_name} \
		"grep ${target_svname} ${res_file}" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		error_output "is_ha_target():" \
			 "remote command error: ${ret_str}"
		return 1
	fi
	[ "${ret_str}" = "${ret_str#*${target_svname}*}" ] && return 1
	return 0
}
# get_hb_configs hostname
# Get the Heartbeat configurations from the node @hostname
get_hb_configs() {
	local host_name=$1
	local ret_line line
	declare -i i
	unset HA_CONFIGS
	HB_CHANNELS=
	SRV_IPADDRS=
	HB_OPTIONS=
	# Execute remote command to get the configs of Heartbeat channels, etc
	while read -r ret_line; do
		if is_pdsh; then
                	set -- ${ret_line}
			shift
			line="$*"
		else
			line="${ret_line}"
		fi
                # Get rid of the comment line
                [ -z "`echo \"${line}\"|egrep -v \"^#\"`" ] && continue
		if [ "${line}" != "${line#*serial*}" ] \
		|| [ "${line}" != "${line#*cast*}" ]; then
			if [ -z "${HB_CHANNELS}" ]; then
				HB_CHANNELS=${line}
			else
				HB_CHANNELS=${HB_CHANNELS}:${line}
			fi
		fi
		if [ "${line}" != "${line#*stonith*}" ] \
		|| [ "${line}" != "${line#*ping*}" ] \
		|| [ "${line}" != "${line#*respawn*}" ] \
		|| [ "${line}" != "${line#*apiauth*}" ] \
		|| [ "${line}" != "${line#*compression*}" ]; then
			if [ -z "${HB_OPTIONS}" ]; then
				HB_OPTIONS=${line}
			else
				HB_OPTIONS=${HB_OPTIONS}:${line}
			fi
		fi
        done < <(${REMOTE} ${host_name} "cat ${HA_CF}")
	if [ -z "${HB_CHANNELS}" ]; then
		error_output "get_hb_configs():" \
			 "There are no heartbeat channel configs in ${HA_CF}" \
			 "of host ${host_name} or ${HA_CF} does not exist!"
		return 0
	fi
	# Execute remote command to get Heartbeat service address
	if [ "${HATYPE_OPT}" = "${HBVER_HBV1}" ]; then
		while read -r ret_line; do
			if is_pdsh; then
                		set -- ${ret_line}
				shift
				line="$*"
			else
				line="${ret_line}"
			fi
			# Get rid of the empty line
                	[ -z "`echo ${line}|awk '/[[:alnum:]]/ {print $0}'`" ]\
                        && continue
                	# Get rid of the comment line
                	[ -z "`echo \"${line}\"|egrep -v \"^#\"`" ] && continue
			SRV_IPADDRS=`echo ${line} | awk '{print $2}'`
			[ -n "${SRV_IPADDRS}" ] \
			&& [ "`echo ${line} | awk '{print $1}'`" = "${host_name}" ] && break
        	done < <(${REMOTE} ${host_name} "cat ${HA_RES}")
	
		if [ -z "${SRV_IPADDRS}" ]; then
			error_output "get_hb_configs(): There"\
			 	 "are no service address in ${HA_RES} of host"\
			 	 "${host_name} or ${HA_RES} does not exist!"
			return 0
		fi
	fi
	# Construct HA configuration items 
	for ((i = 0; i < ${#TARGET_DEVNAMES[@]}; i++)); do
		[ -z "${TARGET_DEVNAMES[i]}" ] && continue
		# Execute remote command to check whether this target service 
		# was made to be high-available
		if is_ha_target ${host_name} ${TARGET_DEVNAMES[i]}; then
			HA_CONFIGS[i]=${HB_CHANNELS},${SRV_IPADDRS},${HB_OPTIONS}
		fi
	done
	return 0
}
# get_cluman_channel hostname
# Get the Heartbeat channel of CluManager from the node @hostname
get_cluman_channel() {
	local host_name=$1
	local ret_line line
	local cluman_channel=
	local mcast_ipaddr
	while read -r ret_line; do
		if is_pdsh; then
                	set -- ${ret_line}
			shift
			line="$*"
		else
			line="${ret_line}"
		fi
		if [ "${line}" != "${line#*broadcast*}" ] \
		&& [ "`echo ${line}|awk '{print $3}'`" = "yes" ]; then
			cluman_channel="broadcast"
			break
		fi
		if [ "${line}" != "${line#*multicast_ipaddress*}" ]; then
			mcast_ipaddr=`echo ${line}|awk '{print $3}'`
			if [ "${mcast_ipaddr}" != "225.0.0.11" ]; then
				cluman_channel="multicast ${mcast_ipaddr}"
				break
			fi
		fi
        done < <(${REMOTE} ${host_name} "${CONFIG_CMD} --clumembd")
	echo ${cluman_channel}
	return 0
}
# get_cluman_srvaddr hostname target_svname
# Get the service IP addresses of @target_svname from the node @hostname 
get_cluman_srvaddr() {
	local host_name=$1
	local target_svname=$2
	local ret_line line
	local srvaddr cluman_srvaddr=
	while read -r ret_line; do
		if is_pdsh; then
                	set -- ${ret_line}
			shift
			line="$*"
		else
			line="${ret_line}"
		fi
		if [ "${line}" != "${line#*ipaddress = *}" ]; then
			srvaddr=`echo ${line}|awk '{print $3}'`
			if [ -z "${cluman_srvaddr}" ]; then
				cluman_srvaddr=${srvaddr}			
			else
				cluman_srvaddr=${cluman_srvaddr}:${srvaddr}
			fi
		fi
        done < <(${REMOTE} ${host_name} "${CONFIG_CMD} \
		--service=${target_svname} --service_ipaddresses")
	if [ -z "${cluman_srvaddr}" ]; then
		echo "`basename $0`: get_cluman_srvaddr() error: Cannot" \
		"get the service IP addresses of ${target_svname} in" \
		"${host_name}! Check ${CONFIG_CMD} command!"
		return 1
	fi
	echo ${cluman_srvaddr}
	return 0
}
# get_cluman_configs hostname
# Get the CluManager configurations from the node @hostname
get_cluman_configs() {
	local host_name=$1
	local ret_str
	declare -i i
	unset HA_CONFIGS
	# Execute remote command to get the configs of CluManager
	for ((i = 0; i < ${#TARGET_DEVNAMES[@]}; i++)); do
		HB_CHANNELS=
		SRV_IPADDRS=
		HB_OPTIONS=
		[ -z "${TARGET_DEVNAMES[i]}" ] && continue
		# Execute remote command to check whether this target service 
		# was made to be high-available
		! is_ha_target ${host_name} ${TARGET_DEVNAMES[i]} && continue
		# Execute remote command to get Heartbeat channel
		HB_CHANNELS=$(get_cluman_channel ${host_name})
		if [ $? -ne 0 ]; then
			error_output "${HB_CHANNELS}"
		fi
		# Execute remote command to get service IP address 
		SRV_IPADDRS=$(get_cluman_srvaddr ${host_name} \
			      ${TARGET_SVNAMES[i]})
		if [ $? -ne 0 ]; then
			error_output "${SRV_IPADDRS}"
			return 0
		fi
		HA_CONFIGS[i]=${HB_CHANNELS},${SRV_IPADDRS},${HB_OPTIONS}
	done
	return 0
}
# get_ha_configs hostname
# Get the HA software configurations from the node @hostname
get_ha_configs() {
	local host_name=$1
	unset HA_CONFIGS
	if [ -z "${HATYPE_OPT}" ]; then
		return 0
	fi
	verbose_output "Collecting HA software configurations from host $1..."
	case "${HATYPE_OPT}" in
	"${HBVER_HBV1}" | "${HBVER_HBV2}") # Heartbeat
		if ! get_hb_configs ${host_name}; then
			return 1
		fi
		;;
	"${HATYPE_CLUMGR}") # CluManager
		if ! get_cluman_configs ${host_name}; then
			return 1
		fi
		;;
	esac
	return 0
}
#*********************** Lustre targets configurations ***********************#
# is_failover_service target_svname
# Check whether a target service @target_svname is a failover service.
is_failover_service() {
	local target_svname=$1
	declare -i i
	for ((i = 0; i < ${#ALL_TARGET_SVNAMES[@]}; i++)); do
		[ "${target_svname}" = "${ALL_TARGET_SVNAMES[i]}" ] && return 0
	done
	return 1
}
# get_svnames hostname
# Get the lustre target server obd names from the node @hostname
get_svnames(){
	declare -i i
	declare -i j
	local host_name=$1
	local ret_line line
        # Initialize the TARGET_SVNAMES array
	unset TARGET_SVNAMES
	unset FAILOVER_FMTOPTS
	
	# Execute remote command to the node @hostname and figure out what
	# lustre services are running.
	i=0
	j=${#ALL_TARGET_SVNAMES[@]}
	while read -r ret_line; do
		if is_pdsh; then
                	set -- ${ret_line}
			shift
			line="$*"
		else
			line="${ret_line}"
		fi
		if [ -z "`echo ${line} | grep ${MGS_TYPE}`" ] \
		&& [ -z "`echo ${line} | grep ${MDT_TYPE}`" ] \
		&& [ -z "`echo ${line} | grep ${OST_TYPE}`" ]; then
			continue
		fi
		# Get target server name
		TARGET_SVNAMES[i]=`echo ${line} | awk '{print $4}'`
		if [ -n "${TARGET_SVNAMES[i]}" ]; then
			if is_failover_service ${TARGET_SVNAMES[i]}; then
				FAILOVER_FMTOPTS[i]="--noformat"
			fi
			ALL_TARGET_SVNAMES[j]=${TARGET_SVNAMES[i]}
			let "i += 1"
			let "j += 1"
		else
			error_output "get_svnames(): Invalid"\
			      "line in ${host_name}'s ${LUSTRE_PROC_DEVICES}"\
			      "- \"${line}\"!"
			return 1
		fi
        done < <(${REMOTE} ${host_name} "cat ${LUSTRE_PROC_DEVICES}")
	if [ $i -eq 0 ]; then
		verbose_output "There are no lustre services running" \
			       "on the node ${host_name}!"
	fi
	return 0
} 
# is_loopdev devname
# Check whether a device @devname is a loop device or not
is_loopdev() {
	local devname=$1
	if [ -z "${devname}" ] || \
	[ -z "`echo ${devname}|awk '/\/dev\/loop[[:digit:]]/ {print $0}'`" ]
	then
		return 1
	fi
	return 0
}
# get_devname hostname svname
# Get the device name of lustre target @svname from node @hostname
get_devname() {
	local host_name=$1
	local target_svname=$2
	local target_devname=
	local ret_str
	local target_type target_obdtype mntdev_file
	if [ "${target_svname}" = "${MGS_SVNAME}" ]; then
		# Execute remote command to get the device name of mgs target
		ret_str=`${REMOTE} ${host_name} \
			"PATH=\$PATH:/sbin:/usr/sbin findfs LABEL=${target_svname}" 2>&1`
		if [ $? -ne 0 -a -n "${ret_str}" ]; then
			if [ "${ret_str}" = "${ret_str#*Unable to resolve*}" ]
			then
				echo "`basename $0`: get_devname() error:" \
			     	     "remote command error: ${ret_str}"
				return 1
			fi
		fi
		if [ "${ret_str}" = "${ret_str#*Unable to resolve*}" ]; then
			if is_pdsh; then
				target_devname=`echo ${ret_str} | awk '{print $2}'`
			else
				target_devname=`echo ${ret_str} | awk '{print $1}'`
			fi
		fi
	else	# Execute remote command to get the device name of mdt/ost target
		target_type=`echo ${target_svname} | cut -d - -f 2`
		target_obdtype=${target_type:0:3}_TYPE
		
		mntdev_file=${LUSTRE_PROC}/${!target_obdtype}/${target_svname}/mntdev
		ret_str=`${REMOTE} ${host_name} "cat ${mntdev_file}" 2>&1`
		if [ $? -ne 0 -a -n "${ret_str}" ]; then
			echo "`basename $0`: get_devname() error:" \
			     "remote command error: ${ret_str}"
			return 1
		fi
		if [ "${ret_str}" != "${ret_str#*No such file*}" ]; then
			echo "`basename $0`: get_devname() error:"\
			     "${mntdev_file} does not exist in ${host_name}!"
			return 1
		else
			if is_pdsh; then
				target_devname=`echo ${ret_str} | awk '{print $2}'`
			else
				target_devname=`echo ${ret_str} | awk '{print $1}'`
			fi
		fi
	fi
	echo ${target_devname}
	return 0
}
# get_devsize hostname target_devname 
# Get the device size (KB) of @target_devname from node @hostname
get_devsize() {
	local host_name=$1
	local target_devname=$2
	local target_devsize=
	local ret_str
	# Execute remote command to get the device size
	ret_str=`${REMOTE} ${host_name} \
		"PATH=\$PATH:/sbin:/usr/sbin blockdev --getsize ${target_devname}" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_devsize() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	if is_pdsh; then
		target_devsize=`echo ${ret_str} | awk '{print $2}'`
	else
		target_devsize=`echo ${ret_str} | awk '{print $1}'`
	fi
	
	if [ -z "`echo ${target_devsize}|awk '/^[[:digit:]]/ {print $0}'`" ]
	then
		echo "`basename $0`: get_devsize() error: can't" \
		"get device size of ${target_devname} in ${host_name}!"
		return 1
	fi
	let " target_devsize /= 2"
	echo ${target_devsize}
	return 0
}
# get_realdevname hostname loop_dev
# Get the real device name of loop device @loop_dev from node @hostname
get_realdevname() {
	local host_name=$1
	local loop_dev=$2
	local target_devname=
	local ret_str
	# Execute remote command to get the real device name
	ret_str=`${REMOTE} ${host_name} \
		"PATH=\$PATH:/sbin:/usr/sbin losetup ${loop_dev}" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_realdevname() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	if is_pdsh; then
		target_devname=`echo ${ret_str} | awk '{print $4}' \
				| sed 's/^(//' | sed 's/)$//'`
	else
		target_devname=`echo ${ret_str} | awk '{print $3}' \
				| sed 's/^(//' | sed 's/)$//'`
	fi
	if [ "${ret_str}" != "${ret_str#*No such*}" ] \
	|| [ -z "${target_devname}" ]; then
		echo "`basename $0`: get_realdevname() error: can't" \
		"get info on device ${loop_dev} in ${host_name}!"
		return 1
	fi
	echo ${target_devname}
	return 0
}
# get_mntpnt hostname target_devname
# Get the lustre target mount point from the node @hostname
get_mntpnt(){
	local host_name=$1
	local target_devname=$2
	local mnt_point=
	local ret_str
	# Execute remote command to get the mount point
	ret_str=`${REMOTE} ${host_name} \
		"cat /etc/mtab | grep ${target_devname}" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_mntpnt() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	if is_pdsh; then
		mnt_point=`echo ${ret_str} | awk '{print $3}'`
	else
		mnt_point=`echo ${ret_str} | awk '{print $2}'`
	fi
	
	if [ -z "${mnt_point}" ]; then
		echo "`basename $0`: get_mntpnt() error: can't" \
		"get the mount point of ${target_devname} in ${host_name}!"
		return 1
	fi
	echo ${mnt_point}
	return 0
}
# get_devnames hostname
# Get the lustre target device names, mount points
# and loop device sizes from the node @hostname
get_devnames(){
	declare -i i
	local host_name=$1
	local ret_line line
        # Initialize the arrays
	unset TARGET_DEVNAMES
	unset TARGET_DEVSIZES
	unset TARGET_MNTPNTS
	for ((i = 0; i < ${#TARGET_SVNAMES[@]}; i++)); do
		TARGET_DEVNAMES[i]=$(get_devname ${host_name} \
				     ${TARGET_SVNAMES[i]})
		if [ $? -ne 0 ]; then
			error_output "${TARGET_DEVNAMES[i]}"
			return 1
		fi
		if [ -z "${TARGET_DEVNAMES[i]}" ]; then
			if [ "${TARGET_SVNAMES[i]}" = "${MGS_SVNAME}" ]; then
				verbose_output "There exists combo mgs/mdt"\
					       "target in ${host_name}."
				continue
			else
				error_output "get_devname():"\
			      		 "No device corresponding to target" \
					 "${TARGET_SVNAMES[i]} in ${host_name}!"
				return 1
			fi
		fi
		# Get the mount point of the target
		TARGET_MNTPNTS[i]=$(get_mntpnt ${host_name} \
				     ${TARGET_DEVNAMES[i]})
		if [ $? -ne 0 ]; then
			error_output "${TARGET_MNTPNTS[i]}"
			return 1
		fi
		# The target device is a loop device?
		if [ -n "${TARGET_DEVNAMES[i]}" ] \
		&& is_loopdev ${TARGET_DEVNAMES[i]}; then 
			# Get the device size
			TARGET_DEVSIZES[i]=$(get_devsize ${host_name} \
					     ${TARGET_DEVNAMES[i]})
			if [ $? -ne 0 ]; then
				error_output "${TARGET_DEVSIZES[i]}"
				return 1
			fi
			# Get the real device name
			TARGET_DEVNAMES[i]=$(get_realdevname ${host_name} \
					     ${TARGET_DEVNAMES[i]})
			if [ $? -ne 0 ]; then
				error_output "${TARGET_DEVNAMES[i]}"
				return 1
			fi
		fi
        done
	return 0
}
# is_target target_svtype ldd_flags
# Check the service type of a lustre target
is_target() {
	case "$1" in
	"mdt") let "ret = $2 & LDD_F_SV_TYPE_MDT";;
	"ost") let "ret = $2 & LDD_F_SV_TYPE_OST";;
	"mgs") let "ret = $2 & LDD_F_SV_TYPE_MGS";;
	"*") 
		error_output "is_target(): Invalid" \
		"target service type - \"$1\"!"
		return 1
		;;
	esac
	if [ ${ret} -eq 0 ]; then
		return 1
	fi
	return 0
}
# get_devtype ldd_flags
# Get the service type of a lustre target from @ldd_flags
get_devtype() {
	local target_devtype=
	if [ -z "${flags}" ]; then
		echo "`basename $0`: get_devtype() error: Invalid" \
			"ldd_flags - it's value is null!"
		return 1
	fi
	if is_target "mgs" $1; then
		if is_target "mdt" $1; then
			target_devtype="mgs|mdt"
		else
			target_devtype="mgs"
		fi
	elif is_target "mdt" $1; then
		target_devtype="mdt"
	elif is_target "ost" $1; then
		target_devtype="ost"
	else
		echo "`basename $0`: get_devtype() error: Invalid" \
		"ldd_flags - \"$1\"!"
		return 1
	fi
	echo ${target_devtype}
	return 0
}
# get_mntopts ldd_mount_opts
# Get the user-specified lustre target mount options from @ldd_mount_opts
get_mntopts() {
	local mount_opts=
	local ldd_mount_opts=$1
	mount_opts="${ldd_mount_opts#${ALWAYS_MNTOPTS}}"
	mount_opts="${mount_opts#${MDT_MGS_ALWAYS_MNTOPTS}}"
	mount_opts="${mount_opts#${OST_ALWAYS_MNTOPTS}}"
	mount_opts="${mount_opts#${OST_DEFAULT_MNTOPTS}}"
	mount_opts="`echo \"${mount_opts}\" | sed 's/^,//'`"
	[ "${mount_opts}" != "${mount_opts#*,*}" ] && echo "\""${mount_opts}"\"" \
	|| echo ${mount_opts}
	return 0
}
# get_mgsnids ldd_params
# Get the mgs nids of lustre target from @ldd_params
get_mgsnids() {
	local mgs_nids=		# mgs nids in one mgs node
	local all_mgs_nids=	# mgs nids in all mgs failover nodes
	local param=
	local ldd_params="$*"
	for param in ${ldd_params}; do
		if [ -n "`echo ${param}|awk '/mgsnode=/ {print $0}'`" ]; then
			mgs_nids=`echo ${param#${PARAM_MGSNODE}}`
			if [ -n "${all_mgs_nids}" ]; then
				all_mgs_nids=${all_mgs_nids}:${mgs_nids}
			else
				all_mgs_nids=${mgs_nids}
			fi
		fi
	done
	[ "${all_mgs_nids}" != "${all_mgs_nids#*,*}" ] \
	&& echo "\""${all_mgs_nids}"\"" || echo ${all_mgs_nids}
	return 0
}
# get_failnids ldd_params
# Get the failover nids of lustre target from @ldd_params
get_failnids() {
	local fail_nids=	# failover nids in one failover node
	local all_fail_nids=	# failover nids in all failover nodes
				# of this target
	local param=
	local ldd_params="$*"
	for param in ${ldd_params}; do
		if [ -n "`echo ${param}|awk '/failover.node=/ {print $0}'`" ]; then
			fail_nids=`echo ${param#${PARAM_FAILNODE}}`
			if [ -n "${all_fail_nids}" ]; then
				all_fail_nids=${all_fail_nids}:${fail_nids}
			else
				all_fail_nids=${fail_nids}
			fi
		fi
	done
	[ "${all_fail_nids}" != "${all_fail_nids#*,*}" ] \
	&& echo "\""${all_fail_nids}"\"" || echo ${all_fail_nids}
	return 0
}
# get_fmtopts target_devname hostname ldd_params
# Get other format options of the lustre target @target_devname from @ldd_params
get_fmtopts() {
	local target_devname=$1
	local host_name=$2
	shift
	shift
	local ldd_params="$*"
	local param= 
	local fmt_opts=
	for param in ${ldd_params}; do
		[ -n "`echo ${param}|awk '/mgsnode=/ {print $0}'`" ] && continue
		[ -n "`echo ${param}|awk '/failover.node=/ {print $0}'`" ] && continue
		if [ -n "${param}" ]; then
			if [ -n "${fmt_opts}" ]; then
				fmt_opts=${fmt_opts}" --param=\""${param}"\""
			else
				fmt_opts="--param=\""${param}"\""
			fi
		fi
	done
	echo ${fmt_opts}
	return 0
}
# get_stripecount host_name target_fsname
# Get the stripe count for @target_fsname
get_stripecount() {
	local host_name=$1
	local target_fsname=$2
	local stripe_count=
	local stripecount_file
	local ret_str
	# Get the stripe count
	stripecount_file=${LUSTRE_PROC}/lov/${target_fsname}-mdtlov/stripecount
	ret_str=`${REMOTE} ${host_name} "cat ${stripecount_file}" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_stripecount() error:" \
		"remote command to ${host_name} error: ${ret_str}"
		return 1
	fi
	if is_pdsh; then
		stripe_count=`echo ${ret_str} | awk '{print $2}'`
	else
		stripe_count=`echo ${ret_str} | awk '{print $1}'`
	fi
    if [ "$stripe_count" != "-1" ] && \
    [ -z "`echo ${stripe_count}|awk '/^[[:digit:]]/ {print $0}'`" ]; then
		echo "`basename $0`: get_stripecount() error: can't" \
		"get stripe count of ${target_fsname} in ${host_name}!"
		return 1
	fi
	echo ${stripe_count}
	return 0
}
# get_stripecount_opt host_name target_fsname
# Get the stripe count option for lustre mdt target
get_stripecount_opt() {
	local host_name=$1
	local target_fsname=$2
	local stripe_count=
	local stripecount_opt=
	# Get the stripe count
	[ -z "${target_fsname}" ] && target_fsname="lustre"
	stripe_count=$(get_stripecount ${host_name} ${target_fsname})
	if [ $? -ne 0 ]; then
		echo "${stripe_count}"
		return 1
	fi
	
	if [ "${stripe_count}" != "1" ]; then
		stripecount_opt=${OPTSTR_STRIPE_COUNT}${stripe_count}
	fi
	echo ${stripecount_opt}
	return 0
}
# get_ldds hostname
# Get the lustre target disk data from the node @hostname
get_ldds(){
	declare -i i
	local host_name=$1
	local ret_line line
	local flags mnt_opts params
	local stripecount_opt
        # Initialize the arrays
	unset TARGET_DEVTYPES TARGET_FSNAMES TARGET_MGSNIDS TARGET_INDEXES
	unset TARGET_FMTOPTS  TARGET_MNTOPTS TARGET_FAILNIDS
	
	# Get lustre target device type, fsname, index, etc.
	# from MOUNT_DATA_FILE. Using tunefs.lustre to read it.
	for ((i = 0; i < ${#TARGET_DEVNAMES[@]}; i++)); do
		flags=
		mnt_opts=
		params=
		stripecount_opt=
		[ -z "${TARGET_DEVNAMES[i]}" ] && continue
		# Execute remote command to read MOUNT_DATA_FILE
		while read -r ret_line; do
			if is_pdsh; then
                		set -- ${ret_line}
				shift
				line="$*"
			else
				line="${ret_line}"
			fi
			if [ -n "`echo ${line}|awk '/Index:/ {print $0}'`" ]; then
				TARGET_INDEXES[i]=`echo ${line}|awk '{print $2}'`
				continue
			fi
			if [ -n "`echo ${line}|awk '/Lustre FS:/ {print $0}'`" ]; then
				TARGET_FSNAMES[i]=`echo ${line}|awk '{print $3}'`
				continue
			fi
			
			if [ -n "`echo ${line}|awk '/Flags:/ {print $0}'`" ]; then
				flags=`echo ${line}|awk '{print $2}'`
				continue
			fi
			if [ -n "`echo ${line}|awk '/Persistent mount opts:/ {print $0}'`" ]; then
				mnt_opts=`echo ${line}|awk '{print $0}'`
				mnt_opts=`echo ${mnt_opts#Persistent mount opts: }`
				continue
			fi
			if [ -n "`echo ${line}|awk '/Parameters:/ {print $0}'`" ]; then
				params=`echo ${line}|awk '{print $0}'`
				params=`echo ${params#Parameters:}`
				break
			fi
		done < <(${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin
		${TUNEFS} --print --verbose ${TARGET_DEVNAMES[i]} 2>/dev/null")
		if [ -z "${flags}" ]; then
			error_output "get_ldds(): Invalid" \
				 "ldd_flags of target ${TARGET_DEVNAMES[i]}" \
				 "in host ${host_name} - it's value is null!"\
				 "Check ${TUNEFS} command!"
			return 1
		fi
		
		if [ "${TARGET_INDEXES[i]}" = "unassigned" ] \
		|| is_target "mgs" ${flags}; then
			TARGET_INDEXES[i]=
		fi
		[ "${TARGET_FSNAMES[i]}" = "lustre" ] && TARGET_FSNAMES[i]=
		# Get the lustre target service type
		TARGET_DEVTYPES[i]=$(get_devtype ${flags})
		if [ $? -ne 0 ]; then
			error_output "${TARGET_DEVTYPES[i]} From device" \
			"${TARGET_DEVNAMES[i]} in host ${host_name}!"
			return 1
		fi
		# Get the lustre target mount options
		TARGET_MNTOPTS[i]=$(get_mntopts "${mnt_opts}")
		# Get mgs nids of the lustre target
		TARGET_MGSNIDS[i]=$(get_mgsnids "${params}")
		# Get failover nids of the lustre target
		TARGET_FAILNIDS[i]=$(get_failnids "${params}")
		if [ $? -ne 0 ]; then
			error_output "${TARGET_FAILNIDS[i]} From device" \
			"${TARGET_DEVNAMES[i]} in host ${host_name}!"
			return 1
		fi
		# Get other format options of the lustre target
		TARGET_FMTOPTS[i]=$(get_fmtopts ${TARGET_DEVNAMES[i]} ${host_name} "${params}")
		if [ $? -ne 0 ]; then
			error_output "${TARGET_FMTOPTS[i]}"
			return 1
		fi
		if [ -n "${TARGET_DEVSIZES[i]}" ]; then
			if [ -n "${TARGET_FMTOPTS[i]}" ]; then
				TARGET_FMTOPTS[i]="--device-size=${TARGET_DEVSIZES[i]} ""${TARGET_FMTOPTS[i]}"
			else
				TARGET_FMTOPTS[i]="--device-size=${TARGET_DEVSIZES[i]}"
			fi
		fi
		if [ -n "${FAILOVER_FMTOPTS[i]}" ]; then
			if [ -n "${TARGET_FMTOPTS[i]}" ]; then
				TARGET_FMTOPTS[i]=${TARGET_FMTOPTS[i]}" "${FAILOVER_FMTOPTS[i]}
			else
				TARGET_FMTOPTS[i]=${FAILOVER_FMTOPTS[i]}
			fi
		fi
		if is_target "mdt" ${flags}; then
			# Get the stripe count option
			stripecount_opt=$(get_stripecount_opt ${host_name} ${TARGET_FSNAMES[i]})
			if [ $? -ne 0 ]; then
				error_output "${stripecount_opt}"
				return 1
			fi
			if [ -n "${stripecount_opt}" ]; then
				if [ -n "${TARGET_FMTOPTS[i]}" ]; then
					TARGET_FMTOPTS[i]=${TARGET_FMTOPTS[i]}" "${stripecount_opt}
				else
					TARGET_FMTOPTS[i]=${stripecount_opt}
				fi
			fi
		fi
		if [ "${TARGET_FMTOPTS[i]}" != "${TARGET_FMTOPTS[i]#*,*}" ]; then
			TARGET_FMTOPTS[i]="\""${TARGET_FMTOPTS[i]}"\""
		fi
        done
	return 0
}
# get_journalsize target_devname hostname
# Get the journal size of lustre target @target_devname from @hostname
get_journalsize() {
	local target_devname=$1
	local host_name=$2
	local journal_inode= 
	local journal_size=
	local ret_str
	# Execute remote command to get the journal inode number
	ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
debugfs -R 'stats -h' ${target_devname} | grep 'Journal inode:'" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_journalsize() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	ret_str=${ret_str#${ret_str%Journal inode:*}}
	journal_inode=`echo ${ret_str} | awk '{print $3}'`
	if [ -z "`echo ${journal_inode}|awk '/^[[:digit:]]/ {print $0}'`" ]
	then
		echo "`basename $0`: get_journalsize() error: can't" \
		"get journal inode of ${target_devname} in ${host_name}!"
		return 1
	fi
	# Execute remote command to get the journal size
	ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
debugfs -R 'stat <${journal_inode}>' ${target_devname}|grep '^User:'" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_journalsize() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	ret_str=${ret_str#${ret_str%User:*}}
	journal_size=`echo ${ret_str} | awk '{print $6}'`
	if [ -z "`echo ${journal_size}|awk '/^[[:digit:]]/ {print $0}'`" ]
	then
		echo "`basename $0`: get_journalsize() error: can't" \
		"get journal size of ${target_devname} in ${host_name}!"
		return 1
	fi
	let "journal_size /= 1024*1024" # MB
	echo ${journal_size}
	return 0
}
# get_defaultjournalsize target_devsize
# Calculate the default journal size from target device size @target_devsize
get_defaultjournalsize() {
	declare -i target_devsize=$1
	declare -i journal_size=0 
	declare -i max_size base_size 
	let "base_size = 1024*1024"
	if [ ${target_devsize} -gt ${base_size} ]; then  # 1GB
		let "journal_size = target_devsize / 102400"
		let "journal_size *= 4"
	fi
	let "max_size = 102400 * L_BLOCK_SIZE"
	let "max_size >>= 20" # 400MB
	if [ ${journal_size} -gt ${max_size} ]; then
		let "journal_size = max_size"
	fi
	echo ${journal_size}
	return 0
}
# figure_journal_size target_devname hostname
# Find a reasonable journal file size given the number of blocks 
# in the filesystem. This algorithm is derived from figure_journal_size()
# function in util.c of e2fsprogs-1.38.cfs2-1.src.rpm.
figure_journal_size() {
	local target_devname=$1
	local host_name=$2
	local ret_str
	declare -i block_count
	declare -i journal_blocks
	declare -i journal_size
	# Execute remote command to get the block count 
	ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
debugfs -R 'stats -h' ${target_devname} | grep 'Block count:'" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: figure_journal_size() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	ret_str=${ret_str#${ret_str%Block count:*}}
	block_count=`echo ${ret_str} | awk '{print $3}'`
	if [ -z "`echo ${block_count}|awk '/^[[:digit:]]/ {print $0}'`" ]
	then
		echo "`basename $0`: figure_journal_size() error: can't" \
		"get block count of ${target_devname} in ${host_name}!"
		return 1
	fi
	if ((block_count < 32768)); then
		let "journal_blocks = 1024"
	elif ((block_count < 256*1024)); then
		let "journal_blocks = 4096"
	elif ((block_count < 512*1024)); then
		let "journal_blocks = 8192"
	elif ((block_count < 1024*1024)); then
		let "journal_blocks = 16384"
	else
		let "journal_blocks = 32768"
	fi
	let "journal_size = journal_blocks * L_BLOCK_SIZE / 1048576"
	echo ${journal_size}
	return 0
}
# get_J_opt hostname target_devname target_devsize
# Get the mkfs -J option of lustre target @target_devname 
# from the node @hostname
get_J_opt() {
	local host_name=$1
	local target_devname=$2
	local target_devsize=$3
	local journal_size=
	local default_journal_size=
	local journal_opt=
	# Get the real journal size of lustre target
	journal_size=$(get_journalsize ${target_devname} ${host_name})
	if [ $? -ne 0 ]; then
		echo "${journal_size}"
		return 1
	fi
	# Get the default journal size of lustre target
	default_journal_size=$(get_defaultjournalsize ${target_devsize})
	if [ "${default_journal_size}" = "0" ]; then
		default_journal_size=$(figure_journal_size ${target_devname} \
				       ${host_name})
		if [ $? -ne 0 ]; then
			echo "${default_journal_size}"
			return 1
		fi
	fi
	if [ "${journal_size}" != "${default_journal_size}" ]; then
		journal_opt="-J size=${journal_size}"
	fi
		
	echo ${journal_opt}
	return 0
}
# get_ratio target_devname hostname
# Get the bytes/inode ratio of lustre target @target_devname from @hostname
get_ratio() {
	local target_devname=$1
	local host_name=$2
	local inode_count= 
	local block_count=
	local ratio=
	local ret_str
	# Execute remote command to get the inode count
	ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
debugfs -R 'stats -h' ${target_devname} | grep 'Inode count:'" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_ratio() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	ret_str=${ret_str#${ret_str%Inode count:*}}
	inode_count=`echo ${ret_str} | awk '{print $3}'`
	if [ -z "`echo ${inode_count}|awk '/^[[:digit:]]/ {print $0}'`" ]
	then
		echo "`basename $0`: get_ratio() error: can't" \
		"get inode count of ${target_devname} in ${host_name}!"
		return 1
	fi
	# Execute remote command to get the block count
	ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
debugfs -R 'stats -h' ${target_devname} | grep 'Block count:'" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_ratio() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	ret_str=${ret_str#${ret_str%Block count:*}}
	block_count=`echo ${ret_str} | awk '{print $3}'`
	if [ -z "`echo ${block_count}|awk '/^[[:digit:]]/ {print $0}'`" ]
	then
		echo "`basename $0`: get_ratio() error: can't" \
		"get block count of ${target_devname} in ${host_name}!"
		return 1
	fi
	let "ratio = block_count*L_BLOCK_SIZE/inode_count"
	echo ${ratio}
	return 0
}
# get_default_ratio target_devtype target_devsize
# Calculate the default bytes/inode ratio from target type @target_devtype
get_default_ratio() {
	local target_devtype=$1
	declare -i target_devsize=$2
	local ratio=
	case "${target_devtype}" in
	"mdt" | "mgs|mdt" | "mdt|mgs")
		ratio=4096;;
	"ost")
		[ ${target_devsize} -gt 1000000 ] && ratio=16384;;
	esac
	[ -z "${ratio}" ] && ratio=${L_BLOCK_SIZE}
	echo ${ratio}
	return 0
}
# get_i_opt hostname target_devname target_devtype target_devsize
# Get the mkfs -i option of lustre target @target_devname 
# from the node @hostname
get_i_opt() {
	local host_name=$1
	local target_devname=$2
	local target_devtype=$3
	local target_devsize=$4
	local ratio=
	local default_ratio=
	local ratio_opt=
	# Get the real bytes/inode ratio of lustre target
	ratio=$(get_ratio ${target_devname} ${host_name})
	if [ $? -ne 0 ]; then
		echo "${ratio}"
		return 1
	fi
	# Get the default bytes/inode ratio of lustre target
	default_ratio=$(get_default_ratio ${target_devtype} ${target_devsize})
	if [ "${ratio}" != "${default_ratio}" ]; then
		ratio_opt="-i ${ratio}"
	fi
		
	echo ${ratio_opt}
	return 0
}
# get_isize target_devname hostname
# Get the inode size of lustre target @target_devname from @hostname
get_isize() {
	local target_devname=$1
	local host_name=$2
	local inode_size= 
	local ret_str
	# Execute remote command to get the inode size 
	ret_str=`${REMOTE} ${host_name} "PATH=\$PATH:/sbin:/usr/sbin \
debugfs -R 'stats -h' ${target_devname} | grep 'Inode size:'" 2>&1`
	if [ $? -ne 0 -a -n "${ret_str}" ]; then
		echo "`basename $0`: get_isize() error:" \
		     "remote command error: ${ret_str}"
		return 1
	fi
	ret_str=${ret_str#${ret_str%Inode size:*}}
	inode_size=`echo ${ret_str} | awk '{print $3}'`
	if [ -z "`echo ${inode_size}|awk '/^[[:digit:]]/ {print $0}'`" ]
	then
		echo "`basename $0`: get_isize() error: can't" \
		"get inode size of ${target_devname} in ${host_name}!"
		return 1
	fi
	echo ${inode_size}
	return 0
}
# get_mdt_default_isize host_name target_fsname
# Calculate the default inode size of lustre mdt target
get_mdt_default_isize() {
	local host_name=$1
	local target_fsname=$2
	declare -i stripe_count
	local inode_size=
	# Get the stripe count
	stripe_count=$(get_stripecount ${host_name} ${target_fsname})
	if [ $? -ne 0 ]; then
		echo "${stripe_count}"
		return 1
	fi
	if ((stripe_count > 77)); then
		inode_size=512
	elif ((stripe_count > 34)); then
		inode_size=2048
	elif ((stripe_count > 13)); then
		inode_size=1024
	else
		inode_size=512
	fi
	echo ${inode_size}
	return 0
}
# get_default_isize host_name target_devtype target_fsname
# Calculate the default inode size of lustre target type @target_devtype
get_default_isize() {
	local host_name=$1
	local target_devtype=$2
	local target_fsname=$3
	local inode_size=
	case "${target_devtype}" in
	"mdt" | "mgs|mdt" | "mdt|mgs")
		inode_size=$(get_mdt_default_isize ${host_name} ${target_fsname})
		if [ $? -ne 0 ]; then
			echo "${inode_size}"
			return 1
		fi
		;;
	"ost")
		inode_size=256;;
	esac
	[ -z "${inode_size}" ] && inode_size=128
	echo ${inode_size}
	return 0
}
# get_I_opt hostname target_devname target_devtype target_fsname
# Get the mkfs -I option of lustre target @target_devname 
# from the node @hostname
get_I_opt() {
	local host_name=$1
	local target_devname=$2
	local target_devtype=$3
	local target_fsname=$4
	local isize=
	local default_isize=
	local isize_opt=
	# Get the real inode size of lustre target
	isize=$(get_isize ${target_devname} ${host_name})
	if [ $? -ne 0 ]; then
		echo "${isize}"
		return 1
	fi
	# Get the default inode size of lustre target
	[ -z "${target_fsname}" ] && target_fsname="lustre"
	default_isize=$(get_default_isize ${host_name} ${target_devtype} \
			${target_fsname})
	if [ $? -ne 0 ]; then
		echo "${default_isize}"
		return 1
	fi
	if [ "${isize}" != "${default_isize}" ]; then
		isize_opt="-I ${isize}"
	fi
		
	echo ${isize_opt}
	return 0
}
# get_mkfsopts hostname
# Get the mkfs options of lustre targets from the node @hostname
get_mkfsopts(){
	declare -i i
	local host_name=$1
	local journal_opt
	local ratio_opt
	local inode_size_opt
        # Initialize the arrays
	unset TARGET_MKFSOPTS
	
	# FIXME: Get other mkfs options of ext3/ldiskfs besides -J, -i and -I
	for ((i = 0; i < ${#TARGET_DEVNAMES[@]}; i++)); do
		journal_opt=
		ratio_opt=
		inode_size_opt=
		[ -z "${TARGET_DEVNAMES[i]}" ] && continue
		if [ -z "${TARGET_DEVSIZES[i]}" ]; then
			# Get the device size
			TARGET_DEVSIZES[i]=$(get_devsize ${host_name} \
				         ${TARGET_DEVNAMES[i]})
			if [ $? -ne 0 ]; then
				error_output "${TARGET_DEVSIZES[i]}"
				return 1
			fi
		fi
		# Get the journal option
		journal_opt=$(get_J_opt ${host_name} ${TARGET_DEVNAMES[i]} \
			      ${TARGET_DEVSIZES[i]})
		if [ $? -ne 0 ]; then
			error_output "${journal_opt}"
			return 1
		fi
		if [ -n "${journal_opt}" ]; then
			if [ -z "${TARGET_MKFSOPTS[i]}" ]; then
				TARGET_MKFSOPTS[i]="${journal_opt}"
			else
				TARGET_MKFSOPTS[i]=${TARGET_MKFSOPTS[i]}" ${journal_opt}"
			fi
		fi
		
		# Get the bytes-per-inode ratio option
		ratio_opt=$(get_i_opt ${host_name} ${TARGET_DEVNAMES[i]} \
			    ${TARGET_DEVTYPES[i]} ${TARGET_DEVSIZES[i]})
		if [ $? -ne 0 ]; then
			error_output "${ratio_opt}"
			return 1
		fi
		if [ -n "${ratio_opt}" ]; then
			if [ -z "${TARGET_MKFSOPTS[i]}" ]; then
				TARGET_MKFSOPTS[i]="${ratio_opt}"
			else
				TARGET_MKFSOPTS[i]=${TARGET_MKFSOPTS[i]}" ${ratio_opt}"
			fi
		fi
		# Get the inode size option
		inode_size_opt=$(get_I_opt ${host_name} ${TARGET_DEVNAMES[i]} \
				 ${TARGET_DEVTYPES[i]} ${TARGET_FSNAMES[i]})
		if [ $? -ne 0 ]; then
			error_output "${inode_size_opt}"
			return 1
		fi
		if [ -n "${inode_size_opt}" ]; then
			if [ -z "${TARGET_MKFSOPTS[i]}" ]; then
				TARGET_MKFSOPTS[i]="${inode_size_opt}"
			else
				TARGET_MKFSOPTS[i]=${TARGET_MKFSOPTS[i]}" ${inode_size_opt}"
			fi
		fi
		if [ "${TARGET_MKFSOPTS[i]}" != "${TARGET_MKFSOPTS[i]#*,*}" ]; then
			TARGET_MKFSOPTS[i]="\""${TARGET_MKFSOPTS[i]}"\""
		fi
	done
	return 0
}
# get_target_configs hostname
# Get the lustre target informations from the node @hostname
get_target_configs() {
	declare -i i
	local host_name=$1
	local ret_line line
        # Initialize the arrays
	unset TARGET_CONFIGS
	# Get lustre target server names
	if ! get_svnames ${host_name}; then
		return 1
	fi
	# Get lustre target device names, mount points and loop device sizes
	if ! get_devnames ${host_name}; then
		return 1
	fi
	# Get lustre target device type, fsname, index, etc.
	if ! get_ldds ${host_name}; then
		return 1
	fi
	# Get mkfs options of lustre targets
	if ! get_mkfsopts ${host_name}; then
		return 1
	fi
	# Construct lustre target configs
	for ((i = 0; i < ${#TARGET_DEVNAMES[@]}; i++)); do
		[ -z "${TARGET_DEVNAMES[i]}" ] && continue
		TARGET_CONFIGS[i]=${TARGET_DEVNAMES[i]},${TARGET_MNTPNTS[i]},${TARGET_DEVTYPES[i]},${TARGET_FSNAMES[i]},${TARGET_MGSNIDS[i]},${TARGET_INDEXES[i]},${TARGET_FMTOPTS[i]},${TARGET_MKFSOPTS[i]},${TARGET_MNTOPTS[i]},${TARGET_FAILNIDS[i]}
	done
	return 0
}
# get_configs hostname
# Get all the informations needed to generate a csv file from 
# the node @hostname
get_configs() {
	# Check the hostname
	if [ -z "$1" ]; then
		error_output "get_configs():" \
			 "Missing hostname!"
		return 1
	fi
	# Get network module options
	verbose_output ""
	verbose_output "Collecting network module options from host $1..."
	if ! get_module_opts $1; then
		return 1
	fi
	verbose_output "OK"
	# Get lustre target informations
	verbose_output "Collecting Lustre targets informations from host $1..."
	if ! get_target_configs $1; then
		return 1
	fi
	verbose_output "OK"
	# Get HA software configurations
	if ! get_ha_configs $1; then
		return 1
	fi
	return 0
}
# Collect linux MD/LVM device informations from the lustre cluster and
# append them to the csv file
get_mdlvm_info() {
	declare -i idx
	declare -i i
	local line
	# Collect and append linux MD/LVM informations to the csv file
	for ((idx = 0; idx < ${#HOST_NAMES[@]}; idx++)); do
		[ -z "${HOST_NAMES[idx]}" ] && continue
		# Collect MD device informations
		! get_md_configs ${HOST_NAMES[idx]} && return 1
		# Append MD device informations to the csv file
		for ((i = 0; i < ${#MD_NAME[@]}; i++)); do
			line=${HOST_NAMES[idx]},${MD_MARKER},${MD_NAME[i]},,,${MD_LEVEL[i]},${MD_DEVS[i]}
			verbose_output "Informations of MD device ${MD_NAME[i]}" \
				       "in host ${HOST_NAMES[idx]} are as follows:"
			verbose_output "${line}"
			echo "${line}" >> ${LUSTRE_CSV_FILE}
		done
		# Collect PV informations
		! get_pv_configs ${HOST_NAMES[idx]} && return 1
		# Append PV informations to the csv file
		if [ -n "${PV_NAMES}" ]; then
			line=${HOST_NAMES[idx]},${PV_MARKER},${PV_NAMES}
			verbose_output "Informations of PVs" \
				       "in host ${HOST_NAMES[idx]} are as follows:"
			verbose_output "${line}"
			echo "${line}" >> ${LUSTRE_CSV_FILE}
		fi
		# Collect VG informations
		! get_vg_configs ${HOST_NAMES[idx]} && return 1
		# Append VG informations to the csv file
		for ((i = 0; i < ${#VG_NAME[@]}; i++)); do
			line=${HOST_NAMES[idx]},${VG_MARKER},${VG_NAME[i]},,,${VG_PVNAMES[i]}
			verbose_output "Informations of VG ${VG_NAME[i]}" \
				       "in host ${HOST_NAMES[idx]} are as follows:"
			verbose_output "${line}"
			echo "${line}" >> ${LUSTRE_CSV_FILE}
		done
		# Collect LV informations
		! get_lv_configs ${HOST_NAMES[idx]} && return 1
		# Append LV informations to the csv file
		for ((i = 0; i < ${#LV_NAME[@]}; i++)); do
			line=${HOST_NAMES[idx]},${LV_MARKER},${LV_NAME[i]},,,${LV_SIZE[i]},${LV_VGNAME[i]}
			verbose_output "Informations of LV /dev/${LV_VGNAME[i]}/${LV_NAME[i]}"\
				       "in host ${HOST_NAMES[idx]} are as follows:"
			verbose_output "${line}"
			echo "${line}" >> ${LUSTRE_CSV_FILE}
		done
	done
	return 0
}
# Generate the csv file from the lustre cluster
gen_csvfile() {
	declare -i idx
	declare -i i
	local line
	# Get lustre cluster node names
	verbose_output "Collecting Lustre cluster node names..."
	if ! get_hostnames; then
		return 1
	fi
	verbose_output "OK"
	: > ${LUSTRE_CSV_FILE}
	${GET_MDLVM_INFO} && get_mdlvm_info
	# Collect and append lustre target informations to the csv file
	for ((idx = 0; idx < ${#HOST_NAMES[@]}; idx++)); do
		# Collect informations
		if ! get_configs ${HOST_NAMES[idx]}; then
			rm -f ${LUSTRE_CSV_FILE}
			return 1
		fi
		# Append informations to the csv file
		for ((i = 0; i < ${#TARGET_DEVNAMES[@]}; i++)); do
			[ -z "${TARGET_DEVNAMES[i]}" ] && continue
			if [ -z "${HA_CONFIGS[i]}" ]; then
				line=${HOST_NAMES[idx]},${MODULE_OPTS},${TARGET_CONFIGS[i]}
			else
				line=${HOST_NAMES[idx]},${MODULE_OPTS},${TARGET_CONFIGS[i]},${HA_CONFIGS[i]}
			fi
			verbose_output "Informations of target ${TARGET_DEVNAMES[i]}" \
				       "in host ${HOST_NAMES[idx]} are as follows:"
			verbose_output "${line}"
			echo "" >> ${LUSTRE_CSV_FILE}
			echo "${line}" >> ${LUSTRE_CSV_FILE}
		done
    	done
	return 0
}
# Main flow
echo "`basename $0`: ******** Generate csv file -- ${LUSTRE_CSV_FILE} START ********"
if ! gen_csvfile; then
	exit 1
fi
echo "`basename $0`: ******** Generate csv file -- ${LUSTRE_CSV_FILE} OK **********"
exit 0
 |