lvm代码分析(四)

来源:互联网 发布:没网络能用泰捷看直播 编辑:程序博客网 时间:2024/05/16 10:12
lvm返回后,在lvm2_main里执行:
  1.     cmd->argv = argv;
  2.     lvm_register_commands();
lvm_register_commands()又是一个似曾相识的构架:
  1. void lvm_register_commands(void)
  2. {
  3. #define xx(a, b, c, d...) _register_command(# a, a, b, c, ## d, /
  4.                         driverloaded_ARG, /
  5.                         debug_ARG, help_ARG, help2_ARG, /
  6.                         version_ARG, verbose_ARG, /
  7.                         quiet_ARG, config_ARG, -1);
  8. #include "commands.h"
  9. #undef xx
  10. }
在commands.h中,xx了好多种命令:
  1. xx(dumpconfig,
  2.    "Dump active configuration",
  3.    0,
  4.    "dumpconfig "
  5.    "/t[-f|--file filename] " "/n"
  6.    "[ConfigurationVariable...]/n",
  7.    file_ARG)
  8. xx(formats,
  9.    "List available metadata formats",
  10.    0,
  11.    "formats/n")
  12. xx(help,
  13.    "Display help for commands",
  14.    0,
  15.    "help <command>" "/n")
  16. /*********
  17. xx(lvactivate,
  18.    "Activate logical volume on given partition(s)",
  19.    "lvactivate "
  20.    "/t[-d|--debug]/n"
  21.    "/t[-h|--help]/n"
  22.    "/t[-v|--verbose]/n"
  23.    "Logical Volume(s)/n")
  24. ***********/
  25. xx(lvchange,
  26.    "Change the attributes of logical volume(s)",
  27.    CACHE_VGMETADATA,
  28.    "lvchange/n"
  29.    "/t[-A|--autobackup y|n]/n"
  30.    "/t[-a|--available [e|l]y|n]/n"
  31.    "/t[--addtag Tag]/n"
  32.    "/t[--alloc AllocationPolicy]/n"
  33.    "/t[-C|--contiguous y|n]/n"
  34.    "/t[-d|--debug]/n"
  35.    "/t[--deltag Tag]/n"
  36.    "/t[-f|--force]/n"
  37.    "/t[-h|--help]/n"
  38.    "/t[--ignorelockingfailure]/n"
  39.    "/t[--ignoremonitoring]/n"
  40.    "/t[--monitor {y|n}]/n"
  41.    "/t[-M|--persistent y|n] [--major major] [--minor minor]/n"
  42.    "/t[-P|--partial] " "/n"
  43.    "/t[-p|--permission r|rw]/n"
  44.    "/t[-r|--readahead ReadAheadSectors|auto|none]/n"
  45.    "/t[--refresh]/n"
  46.    "/t[--resync]/n"
  47.    "/t[-t|--test]/n"
  48.    "/t[-v|--verbose]/n"
  49.    "/t[-y|--yes]/n"
  50.    "/t[--version]" "/n"
  51.    "/tLogicalVolume[Path] [LogicalVolume[Path]...]/n",
  52.    alloc_ARG, autobackup_ARG, available_ARG, contiguous_ARG, force_ARG,
  53.    ignorelockingfailure_ARG, ignoremonitoring_ARG, major_ARG, minor_ARG,
  54.    monitor_ARG, partial_ARG, permission_ARG, persistent_ARG, readahead_ARG,
  55.    resync_ARG, refresh_ARG, addtag_ARG, deltag_ARG, test_ARG, yes_ARG)
  56. xx(lvconvert,
  57.    "Change logical volume layout",
  58.    0,
  59.    "lvconvert "
  60.    "[-m|--mirrors Mirrors [{--mirrorlog {disk|core}|--corelog}]]/n"
  61.    "/t[-R|--regionsize MirrorLogRegionSize]/n"
  62.    "/t[--alloc AllocationPolicy]/n"
  63.    "/t[-b|--background]/n"
  64.    "/t[-d|--debug]/n"
  65.    "/t[-h|-?|--help]/n"
  66.    "/t[-i|--interval seconds]/n"
  67.    "/t[-v|--verbose]/n"
  68.    "/t[--version]" "/n"
  69.    "/tLogicalVolume[Path] [PhysicalVolume[Path]...]/n/n"
  70.    "lvconvert "
  71.    "[-s|--snapshot]/n"
  72.    "/t[-c|--chunksize]/n"
  73.    "/t[-d|--debug]/n"
  74.    "/t[-h|-?|--help]/n"
  75.    "/t[-v|--verbose]/n"
  76.    "/t[-Z|--zero {y|n}]/n"
  77.    "/t[--version]" "/n"
  78.    "/tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]/n",
  79.    alloc_ARG, background_ARG, chunksize_ARG, corelog_ARG, interval_ARG,
  80.    mirrorlog_ARG, mirrors_ARG, regionsize_ARG, snapshot_ARG, test_ARG, zero_ARG)
  81. xx(lvcreate,
  82.    "Create a logical volume",
  83.    0,
  84.    "lvcreate " "/n"
  85.    "/t[-A|--autobackup {y|n}]/n"
  86.    "/t[--addtag Tag]/n"
  87.    "/t[--alloc AllocationPolicy]/n"
  88.    "/t[-C|--contiguous {y|n}]/n"
  89.    "/t[-d|--debug]/n"
  90.    "/t[-h|-?|--help]/n"
  91.    "/t[-i|--stripes Stripes [-I|--stripesize StripeSize]]/n"
  92.    "/t{-l|--extents LogicalExtentsNumber |/n"
  93.    "/t -L|--size LogicalVolumeSize[kKmMgGtTpPeE]}/n"
  94.    "/t[-M|--persistent {y|n}] [--major major] [--minor minor]/n"
  95.    "/t[-m|--mirrors Mirrors [--nosync] [{--mirrorlog {disk|core}|--corelog}]]/n"
  96.    "/t[-n|--name LogicalVolumeName]/n"
  97.    "/t[-p|--permission {r|rw}]/n"
  98.    "/t[-r|--readahead ReadAheadSectors|auto|none]/n"
  99.    "/t[-R|--regionsize MirrorLogRegionSize]/n"
  100.    "/t[-t|--test]/n"
  101.    "/t[--type VolumeType]/n"
  102.    "/t[-v|--verbose]/n"
  103.    "/t[-Z|--zero {y|n}]/n"
  104.    "/t[--version]/n"
  105.    "/tVolumeGroupName [PhysicalVolumePath...]/n/n"
  106.    "lvcreate -s|--snapshot/n"
  107.    "/t[-c|--chunksize]/n"
  108.    "/t[-A|--autobackup {y|n}]/n"
  109.    "/t[--addtag Tag]/n"
  110.    "/t[--alloc AllocationPolicy]/n"
  111.    "/t[-C|--contiguous {y|n}]/n"
  112.    "/t[-d|--debug]/n"
  113.    "/t[-h|-?|--help]/n"
  114.    "/t[-i|--stripes Stripes [-I|--stripesize StripeSize]]/n"
  115.    "/t{-l|--extents LogicalExtentsNumber[%{VG|LV|PVS|FREE}] |/n"
  116.    "/t -L|--size LogicalVolumeSize[kKmMgGtTpPeE]}/n"
  117.    "/t[-M|--persistent {y|n}] [--major major] [--minor minor]/n"
  118.    "/t[-n|--name LogicalVolumeName]/n"
  119.    "/t[-p|--permission {r|rw}]/n"
  120.    "/t[-r|--readahead ReadAheadSectors|auto|none]/n"
  121.    "/t[-t|--test]/n"
  122.    "/t[-v|--verbose]/n"
  123.    "/t[--version]/n"
  124.    "/tOriginalLogicalVolume[Path] [PhysicalVolumePath...]/n/n",
  125.    addtag_ARG, alloc_ARG, autobackup_ARG, chunksize_ARG, contiguous_ARG,
  126.    corelog_ARG, extents_ARG, major_ARG, minor_ARG, mirrorlog_ARG, mirrors_ARG,
  127.    name_ARG, nosync_ARG, permission_ARG, persistent_ARG, readahead_ARG,
  128.    regionsize_ARG, size_ARG, snapshot_ARG, stripes_ARG, stripesize_ARG,
  129.    test_ARG, type_ARG, zero_ARG)
  130. xx(lvdisplay,
  131.    "Display information about a logical volume",
  132.    0,
  133.    "lvdisplay/n"
  134.    "/t[-a|--all]/n"
  135.    "/t[-c|--colon]/n"
  136.    "/t[-d|--debug]/n"
  137.    "/t[-h|--help]/n"
  138.    "/t[--ignorelockingfailure]/n"
  139.    "/t[-m|--maps]/n"
  140.    "/t[--nosuffix]/n"
  141.    "/t[-P|--partial] " "/n"
  142.    "/t[--units hsbkmgtHKMGT]/n"
  143.    "/t[-v|--verbose]/n"
  144.    "/t[--version]" "/n"
  145.    "/t[LogicalVolume[Path] [LogicalVolume[Path]...]]/n"
  146.    "/n"
  147.    "lvdisplay --columns|-C/n"
  148.    "/t[--aligned]/n"
  149.    "/t[-a|--all]/n"
  150.    "/t[-d|--debug]/n"
  151.    "/t[-h|--help]/n"
  152.    "/t[--ignorelockingfailure]/n"
  153.    "/t[--noheadings]/n"
  154.    "/t[--nosuffix]/n"
  155.    "/t[-o|--options [+]Field[,Field]]/n"
  156.    "/t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]/n"
  157.    "/t[-P|--partial] " "/n"
  158.    "/t[--segments]/n"
  159.    "/t[--separator Separator]/n"
  160.    "/t[--unbuffered]/n"
  161.    "/t[--units hsbkmgtHKMGT]/n"
  162.    "/t[-v|--verbose]/n"
  163.    "/t[--version]" "/n"
  164.    "/t[LogicalVolume[Path] [LogicalVolume[Path]...]]/n",
  165.     aligned_ARG, all_ARG, colon_ARG, columns_ARG, disk_ARG,
  166.     ignorelockingfailure_ARG, maps_ARG, noheadings_ARG, nosuffix_ARG,
  167.     options_ARG, sort_ARG, partial_ARG, segments_ARG, separator_ARG,
  168.     unbuffered_ARG, units_ARG)
  169. xx(lvextend,
  170.    "Add space to a logical volume",
  171.    0,
  172.    "lvextend/n"
  173.    "/t[-A|--autobackup y|n]/n"
  174.    "/t[--alloc AllocationPolicy]/n"
  175.    "/t[-d|--debug]/n"
  176.    "/t[-f|--force]/n"
  177.    "/t[-h|--help]/n"
  178.    "/t[-i|--stripes Stripes [-I|--stripesize StripeSize]]/n"
  179.    "/t{-l|--extents [+]LogicalExtentsNumber[%{VG|PVS|FREE}] |/n"
  180.    "/t -L|--size [+]LogicalVolumeSize[kKmMgGtTpPeE]}/n"
  181.    "/t[-m|--mirrors Mirrors]/n"
  182.    "/t[-n|--nofsck]/n"
  183.    "/t[-r|--resizefs]/n"
  184.    "/t[-t|--test]/n"
  185.    "/t[--type VolumeType]/n"
  186.    "/t[-v|--verbose]/n"
  187.    "/t[--version]" "/n"
  188.    "/tLogicalVolume[Path] [ PhysicalVolumePath... ]/n",
  189.    alloc_ARG, autobackup_ARG, extents_ARG, force_ARG, mirrors_ARG,
  190.    nofsck_ARG, resizefs_ARG, size_ARG, stripes_ARG, stripesize_ARG,
  191.    test_ARG, type_ARG)
  192. xx(lvmchange,
  193.    "With the device mapper, this is obsolete and does nothing.",
  194.    0,
  195.    "lvmchange/n"
  196.    "/t[-d|--debug]/n"
  197.    "/t[-h|--help]/n"
  198.    "/t[-R|--reset]/n"
  199.    "/t[-v|--verbose]/n"
  200.    "/t[--version]" "/n",
  201.     reset_ARG)
  202. xx(lvmdiskscan,
  203.    "List devices that may be used as physical volumes",
  204.    0,
  205.    "lvmdiskscan/n"
  206.    "/t[-d|--debug]/n"
  207.    "/t[-h|--help]/n"
  208.    "/t[-l|--lvmpartition]/n"
  209.    "/t[--version]" "/n",
  210.    lvmpartition_ARG)
  211. xx(lvmsadc,
  212.    "Collect activity data",
  213.    0,
  214.    "lvmsadc/n"
  215.    "/t[-d|--debug]/n"
  216.    "/t[-h|--help]/n"
  217.    "/t[-v|--verbose]/n"
  218.    "/t[--version]" "/n"
  219.    "/t[LogFilePath]/n" )
  220. xx(lvmsar,
  221.    "Create activity report",
  222.    0,
  223.    "lvmsar/n"
  224.    "/t[-d|--debug]/n"
  225.    "/t[-f|--full]/n"
  226.    "/t[-h|--help]/n"
  227.    "/t[-s|--stdin]/n"
  228.    "/t[-v|--verbose]/n"
  229.    "/t[--version]" "/n"
  230.    "/tLogFilePath/n",
  231.    full_ARG, stdin_ARG)
  232. xx(lvreduce,
  233.    "Reduce the size of a logical volume",
  234.    0,
  235.    "lvreduce/n"
  236.    "/t[-A|--autobackup y|n]/n"
  237.    "/t[-d|--debug]/n"
  238.    "/t[-f|--force]/n"
  239.    "/t[-h|--help]/n"
  240.    "/t{-l|--extents [-]LogicalExtentsNumber[%{VG|LV|FREE}] |/n"
  241.    "/t -L|--size [-]LogicalVolumeSize[kKmMgGtTpPeE]}/n"
  242.    "/t[-n|--nofsck]/n"
  243.    "/t[-r|--resizefs]/n"
  244.    "/t[-t|--test]/n"
  245.    "/t[-v|--verbose]/n"
  246.    "/t[-y|--yes]/n"
  247.    "/t[--version]" "/n"
  248.    "/tLogicalVolume[Path]/n",
  249.    autobackup_ARG, force_ARG,  extents_ARG, nofsck_ARG, resizefs_ARG,
  250.    size_ARG, test_ARG, yes_ARG)
  251. xx(lvremove,
  252.    "Remove logical volume(s) from the system",
  253.    0,
  254.    "lvremove/n"
  255.    "/t[-A|--autobackup y|n]/n"
  256.    "/t[-d|--debug]/n"
  257.    "/t[-f|--force]/n"
  258.    "/t[-h|--help]/n"
  259.    "/t[-t|--test]/n"
  260.    "/t[-v|--verbose]/n"
  261.    "/t[--version]" "/n"
  262.    "/tLogicalVolume[Path] [LogicalVolume[Path]...]/n",
  263.    autobackup_ARG, force_ARG, test_ARG)
  264. xx(lvrename,
  265.    "Rename a logical volume",
  266.    0,
  267.    "lvrename "
  268.    "/t[-A|--autobackup {y|n}] " "/n"
  269.    "/t[-d|--debug] " "/n"
  270.    "/t[-h|-?|--help] " "/n"
  271.    "/t[-t|--test] " "/n"
  272.    "/t[-v|--verbose]" "/n"
  273.    "/t[--version] " "/n"
  274.    "/t{ OldLogicalVolumePath NewLogicalVolumePath |" "/n"
  275.    "/t  VolumeGroupName OldLogicalVolumeName NewLogicalVolumeName }/n",
  276.    autobackup_ARG, test_ARG)
  277. xx(lvresize,
  278.    "Resize a logical volume",
  279.    0,
  280.    "lvresize/n"
  281.    "/t[-A|--autobackup y|n]/n"
  282.    "/t[--alloc AllocationPolicy]/n"
  283.    "/t[-d|--debug]/n"
  284.    "/t[-f|--force]/n"
  285.    "/t[-h|--help]/n"
  286.    "/t[-i|--stripes Stripes [-I|--stripesize StripeSize]]/n"
  287.    "/t{-l|--extents [+|-]LogicalExtentsNumber[%{VG|LV|PVS|FREE}] |/n"
  288.    "/t -L|--size [+|-]LogicalVolumeSize[kKmMgGtTpPeE]}/n"
  289.    "/t[-n|--nofsck]/n"
  290.    "/t[-r|--resizefs]/n"
  291.    "/t[-t|--test]/n"
  292.    "/t[--type VolumeType]/n"
  293.    "/t[-v|--verbose]/n"
  294.    "/t[--version]" "/n"
  295.    "/tLogicalVolume[Path] [ PhysicalVolumePath... ]/n",
  296.    alloc_ARG, autobackup_ARG, extents_ARG, force_ARG, nofsck_ARG,
  297.    resizefs_ARG, size_ARG, stripes_ARG, stripesize_ARG, test_ARG,
  298.    type_ARG)
  299. xx(lvs,
  300.    "Display information about logical volumes",
  301.    0,
  302.    "lvs" "/n"
  303.    "/t[-a|--all]/n"
  304.    "/t[--aligned]/n"
  305.    "/t[-d|--debug]/n"
  306.    "/t[-h|--help]/n"
  307.    "/t[--ignorelockingfailure]/n"
  308.    "/t[--nameprefixes]/n"
  309.    "/t[--noheadings]/n"
  310.    "/t[--nosuffix]/n"
  311.    "/t[-o|--options [+]Field[,Field]]/n"
  312.    "/t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]/n"
  313.    "/t[-P|--partial] " "/n"
  314.    "/t[--rows]/n"
  315.    "/t[--segments]/n"
  316.    "/t[--separator Separator]/n"
  317.    "/t[--trustcache]/n"
  318.    "/t[--unbuffered]/n"
  319.    "/t[--units hsbkmgtHKMGT]/n"
  320.    "/t[--unquoted]/n"
  321.    "/t[-v|--verbose]/n"
  322.    "/t[--version]" "/n"
  323.    "/t[LogicalVolume[Path] [LogicalVolume[Path]...]]/n",
  324.    aligned_ARG, all_ARG, ignorelockingfailure_ARG, nameprefixes_ARG,
  325.    noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, 
  326.    rows_ARG, segments_ARG, separator_ARG, sort_ARG, trustcache_ARG,
  327.    unbuffered_ARG, units_ARG, unquoted_ARG)
  328. xx(lvscan,
  329.    "List all logical volumes in all volume groups",
  330.    0,
  331.    "lvscan " "/n"
  332.    "/t[-a|--all]/n"
  333.    "/t[-b|--blockdevice] " "/n"
  334.    "/t[-d|--debug] " "/n"
  335.    "/t[-h|-?|--help] " "/n"
  336.    "/t[--ignorelockingfailure]/n"
  337.    "/t[-P|--partial] " "/n"
  338.    "/t[-v|--verbose] " "/n"
  339.    "/t[--version]/n",
  340.    all_ARG, blockdevice_ARG, disk_ARG, ignorelockingfailure_ARG, partial_ARG)
  341. xx(pvchange,
  342.    "Change attributes of physical volume(s)",
  343.    0,
  344.    "pvchange/n"
  345.    "/t[-a|--all]/n"
  346.    "/t[-A|--autobackup y|n]/n"
  347.    "/t[-d|--debug]/n"
  348.    "/t[-h|--help]/n"
  349.    "/t[-t|--test]/n"
  350.    "/t[-u|--uuid]/n"
  351.    "/t[-x|--allocatable y|n]/n"
  352.    "/t[-v|--verbose]/n"
  353.    "/t[--addtag Tag]/n"
  354.    "/t[--deltag Tag]/n"
  355.    "/t[--version]" "/n"
  356.    "/t[PhysicalVolumePath...]/n",
  357.    all_ARG, allocatable_ARG, allocation_ARG, autobackup_ARG, deltag_ARG,
  358.    addtag_ARG, test_ARG, uuid_ARG)
  359. xx(pvresize,
  360.    "Resize physical volume(s)",
  361.    0,
  362.    "pvresize " "/n"
  363.    "/t[-d|--debug]" "/n"
  364.    "/t[-h|-?|--help] " "/n"
  365.    "/t[--setphysicalvolumesize PhysicalVolumeSize[kKmMgGtTpPeE]" "/n"
  366.    "/t[-t|--test] " "/n"
  367.    "/t[-v|--verbose] " "/n"
  368.    "/t[--version] " "/n"
  369.    "/tPhysicalVolume [PhysicalVolume...]/n",
  370.    physicalvolumesize_ARG, test_ARG)
  371. xx(pvck,
  372.    "Check the consistency of physical volume(s)",
  373.    0,
  374.    "pvck "
  375.    "/t[-d|--debug]/n"
  376.    "/t[-h|--help]/n"
  377.    "/t[--labelsector sector] " "/n"
  378.    "/t[-v|--verbose]/n"
  379.    "/t[--version]" "/n"
  380.    "/tPhysicalVolume [PhysicalVolume...]/n",
  381.    labelsector_ARG)
  382. xx(pvcreate,
  383.    "Initialize physical volume(s) for use by LVM",
  384.    0,
  385.    "pvcreate " "/n"
  386.    "/t[--restorefile file]/n"
  387.    "/t[-d|--debug]" "/n"
  388.    "/t[-f[f]|--force [--force]] " "/n"
  389.    "/t[-h|-?|--help] " "/n"
  390.    "/t[--labelsector sector] " "/n"
  391.    "/t[-M|--metadatatype 1|2]" "/n"
  392.    "/t[--metadatacopies #copies]" "/n"
  393.    "/t[--metadatasize MetadataSize[kKmMgGtTpPeE]]" "/n"
  394.    "/t[--setphysicalvolumesize PhysicalVolumeSize[kKmMgGtTpPeE]" "/n"
  395.    "/t[-t|--test] " "/n"
  396.    "/t[-u|--uuid uuid] " "/n"
  397.    "/t[-v|--verbose] " "/n"
  398.    "/t[-y|--yes]" "/n"
  399.    "/t[-Z|--zero {y|n}]/n"
  400.    "/t[--version] " "/n"
  401.    "/tPhysicalVolume [PhysicalVolume...]/n",
  402.    force_ARG, test_ARG, labelsector_ARG, metadatatype_ARG, metadatacopies_ARG,
  403.    metadatasize_ARG, physicalvolumesize_ARG, restorefile_ARG, uuidstr_ARG,
  404.    yes_ARG, zero_ARG)
  405. xx(pvdata,
  406.    "Display the on-disk metadata for physical volume(s)",
  407.    0,
  408.    "pvdata " "/n"
  409.    "/t[-a|--all] " "/n"
  410.    "/t[-d|--debug] " "/n"
  411.    "/t[-E|--physicalextent] " "/n"
  412.    "/t[-h|-?|--help]" "/n"
  413.    "/t[-L|--logicalvolume] " "/n"
  414.    "/t[-P[P]|--physicalvolume [--physicalvolume]]" "/n"
  415.    "/t[-U|--uuidlist] " "/n"
  416.    "/t[-v[v]|--verbose [--verbose]] " "/n"
  417.    "/t[-V|--volumegroup]" "/n"
  418.    "/t[--version] " "/n"
  419.    "/tPhysicalVolume [PhysicalVolume...]/n",
  420.    all_ARG,  logicalextent_ARG, physicalextent_ARG,
  421.    physicalvolume_ARG, uuidlist_ARG, volumegroup_ARG)
  422. xx(pvdisplay,
  423.    "Display various attributes of physical volume(s)",
  424.    0,
  425.    "pvdisplay/n"
  426.    "/t[-c|--colon]/n"
  427.    "/t[-d|--debug]/n"
  428.    "/t[-h|--help]/n"
  429.    "/t[--ignorelockingfailure]/n"
  430.    "/t[-m|--maps]/n"
  431.    "/t[--nosuffix]/n"
  432.    "/t[-s|--short]/n"
  433.    "/t[--units hsbkmgtHKMGT]/n"
  434.    "/t[-v|--verbose]/n"
  435.    "/t[--version]" "/n"
  436.    "/t[PhysicalVolumePath [PhysicalVolumePath...]]/n"
  437.    "/n"
  438.    "pvdisplay --columns|-C/n"
  439.    "/t[--aligned]/n"
  440.    "/t[-a|--all]/n"
  441.    "/t[-d|--debug]/n"
  442.    "/t[-h|--help]/n"
  443.    "/t[--ignorelockingfailure]/n"
  444.    "/t[--noheadings]/n"
  445.    "/t[--nosuffix]/n"
  446.    "/t[-o|--options [+]Field[,Field]]/n"
  447.    "/t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]/n"
  448.    "/t[--separator Separator]/n"
  449.    "/t[--unbuffered]/n"
  450.    "/t[--units hsbkmgtHKMGT]/n"
  451.    "/t[-v|--verbose]/n"
  452.    "/t[--version]" "/n"
  453.    "/t[PhysicalVolumePath [PhysicalVolumePath...]]/n",
  454.    aligned_ARG, all_ARG, colon_ARG, columns_ARG, ignorelockingfailure_ARG,
  455.    maps_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, separator_ARG,
  456.    short_ARG, sort_ARG, unbuffered_ARG, units_ARG)
  457. xx(pvmove,
  458.    "Move extents from one physical volume to another",
  459.    0,
  460.    "pvmove " "/n"
  461.    "/t[--abort]/n"
  462.    "/t[-A|--autobackup {y|n}]/n"
  463.    "/t[--alloc AllocationPolicy]/n"
  464.    "/t[-b|--background]/n"
  465.    "/t[-d|--debug]/n "
  466.    "/t[-h|-?|--help]/n"
  467.    "/t[-i|--interval seconds]/n"
  468.    "/t[-t|--test]/n "
  469.    "/t[-v|--verbose]/n "
  470.    "/t[--version]/n"
  471.    "/t[{-n|--name} LogicalVolume]/n"
  472. /* "/t[{-n|--name} LogicalVolume[:LogicalExtent[-LogicalExtent]...]]/n" */
  473.    "/tSourcePhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]}/n"
  474.    "/t[DestinationPhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]...]/n",
  475.    abort_ARG, alloc_ARG, autobackup_ARG, background_ARG,
  476.    interval_ARG, name_ARG, test_ARG)
  477. xx(pvremove,
  478.    "Remove LVM label(s) from physical volume(s)",
  479.    0,
  480.    "pvremove " "/n"
  481.    "/t[-d|--debug]" "/n"
  482.    "/t[-f[f]|--force [--force]] " "/n"
  483.    "/t[-h|-?|--help] " "/n"
  484.    "/t[-t|--test] " "/n"
  485.    "/t[-v|--verbose] " "/n"
  486.    "/t[-y|--yes]" "/n"
  487.    "/t[--version] " "/n"
  488.    "/tPhysicalVolume [PhysicalVolume...]/n",
  489.    force_ARG, test_ARG, yes_ARG)
  490. xx(pvs,
  491.    "Display information about physical volumes",
  492.    0,
  493.    "pvs" "/n"
  494.    "/t[--aligned]/n"
  495.    "/t[-a|--all]/n"
  496.    "/t[-d|--debug]" "/n"
  497.    "/t[-h|-?|--help] " "/n"
  498.    "/t[--ignorelockingfailure]/n"
  499.    "/t[--nameprefixes]/n"
  500.    "/t[--noheadings]/n"
  501.    "/t[--nosuffix]/n"
  502.    "/t[-o|--options [+]Field[,Field]]/n"
  503.    "/t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]/n"
  504.    "/t[-P|--partial] " "/n"
  505.    "/t[--rows]/n"
  506.    "/t[--segments]/n"
  507.    "/t[--separator Separator]/n"
  508.    "/t[--trustcache]/n"
  509.    "/t[--unbuffered]/n"
  510.    "/t[--units hsbkmgtHKMGT]/n"
  511.    "/t[--unquoted]/n"
  512.    "/t[-v|--verbose]/n"
  513.    "/t[--version]/n"
  514.    "/t[PhysicalVolume [PhysicalVolume...]]/n",
  515.    aligned_ARG, all_ARG, ignorelockingfailure_ARG, nameprefixes_ARG,
  516.    noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG,
  517.    rows_ARG, segments_ARG, separator_ARG, sort_ARG, trustcache_ARG,
  518.    unbuffered_ARG, units_ARG, unquoted_ARG)
  519. xx(pvscan,
  520.    "List all physical volumes",
  521.    0,
  522.    "pvscan " "/n"
  523.    "/t[-d|--debug] " "/n"
  524.    "/t{-e|--exported | -n|--novolumegroup} " "/n"
  525.    "/t[-h|-?|--help]" "/n"
  526.    "/t[--ignorelockingfailure]/n"
  527.    "/t[-P|--partial] " "/n"
  528.    "/t[-s|--short] " "/n"
  529.    "/t[-u|--uuid] " "/n"
  530.    "/t[-v|--verbose] " "/n"
  531.    "/t[--version]/n",
  532.    exported_ARG, ignorelockingfailure_ARG, novolumegroup_ARG, partial_ARG,
  533.    short_ARG, uuid_ARG)
  534. xx(segtypes,
  535.    "List available segment types",
  536.    0,
  537.    "segtypes/n")
  538. xx(vgcfgbackup,
  539.    "Backup volume group configuration(s)",
  540.    0,
  541.    "vgcfgbackup " "/n"
  542.    "/t[-d|--debug] " "/n"
  543.    "/t[-f|--file filename] " "/n"
  544.    "/t[-h|-?|--help] " "/n"
  545.    "/t[--ignorelockingfailure]/n"
  546.    "/t[-P|--partial] " "/n"
  547.    "/t[-v|--verbose]" "/n"
  548.    "/t[--version] " "/n"
  549.    "/t[VolumeGroupName...]/n",
  550.    file_ARG, ignorelockingfailure_ARG, partial_ARG)
  551. xx(vgcfgrestore,
  552.    "Restore volume group configuration",
  553.    0,
  554.    "vgcfgrestore " "/n"
  555.    "/t[-d|--debug] " "/n"
  556.    "/t[-f|--file filename] " "/n"
  557.    "/t[-l[l]|--list [--list]]" "/n"
  558.    "/t[-M|--metadatatype 1|2]" "/n"
  559.    "/t[-n|--name VolumeGroupName] " "/n"
  560.    "/t[-h|--help]" "/n"
  561.    "/t[-t|--test] " "/n"
  562.    "/t[-v|--verbose]" "/n"
  563.    "/t[--version] " "/n"
  564.    "/tVolumeGroupName",
  565.    file_ARG, list_ARG, metadatatype_ARG, name_ARG, test_ARG)
  566. xx(vgchange,
  567.    "Change volume group attributes",
  568.    CACHE_VGMETADATA,
  569.    "vgchange" "/n"
  570.    "/t[-A|--autobackup {y|n}] " "/n"
  571.    "/t[--alloc AllocationPolicy] " "/n"
  572.    "/t[-P|--partial] " "/n"
  573.    "/t[-d|--debug] " "/n"
  574.    "/t[-h|--help] " "/n"
  575.    "/t[--ignorelockingfailure]/n"
  576.    "/t[--ignoremonitoring]/n"
  577.    "/t[--monitor {y|n}]/n"
  578.    "/t[-t|--test]" "/n"
  579.    "/t[-u|--uuid] " "/n"
  580.    "/t[-v|--verbose] " "/n"
  581.    "/t[--version]" "/n"
  582.    "/t{-a|--available [e|l]{y|n}  |" "/n"
  583.    "/t -c|--clustered {y|n} |" "/n"
  584.    "/t -x|--resizeable {y|n} |" "/n"
  585.    "/t -l|--logicalvolume MaxLogicalVolumes |" "/n"
  586.    "/t -p|--maxphysicalvolumes MaxPhysicalVolumes |" "/n"
  587.    "/t -s|--physicalextentsize PhysicalExtentSize[kKmMgGtTpPeE] |" "/n"
  588.    "/t --addtag Tag |/n"
  589.    "/t --deltag Tag}/n"
  590.    "/t[VolumeGroupName...]/n",
  591.    addtag_ARG, alloc_ARG, allocation_ARG, autobackup_ARG, available_ARG,
  592.    clustered_ARG, deltag_ARG, ignorelockingfailure_ARG, ignoremonitoring_ARG,
  593.    logicalvolume_ARG, maxphysicalvolumes_ARG, monitor_ARG, partial_ARG,
  594.    physicalextentsize_ARG, resizeable_ARG, resizable_ARG, test_ARG, uuid_ARG)
  595. xx(vgck,
  596.    "Check the consistency of volume group(s)",
  597.    0,
  598.    "vgck "
  599.    "/t[-d|--debug]/n"
  600.    "/t[-h|--help]/n"
  601.    "/t[-v|--verbose]/n"
  602.    "/t[--version]" "/n"
  603.    "/t[VolumeGroupName...]/n" )
  604. xx(vgconvert,
  605.    "Change volume group metadata format",
  606.    0,
  607.    "vgconvert  " "/n"
  608.    "/t[-d|--debug]" "/n"
  609.    "/t[-h|--help] " "/n"
  610.    "/t[--labelsector sector] " "/n"
  611.    "/t[-M|--metadatatype 1|2]" "/n"
  612.    "/t[--metadatacopies #copies]" "/n"
  613.    "/t[--metadatasize MetadataSize[kKmMgGtTpPeE]]" "/n"
  614.    "/t[-t|--test] " "/n"
  615.    "/t[-v|--verbose] " "/n"
  616.    "/t[--version] " "/n"
  617.    "/tVolumeGroupName [VolumeGroupName...]/n",
  618.    force_ARG, test_ARG, labelsector_ARG, metadatatype_ARG, metadatacopies_ARG,
  619.    metadatasize_ARG )
  620. xx(vgcreate,
  621.    "Create a volume group",
  622.    0,
  623.    "vgcreate" "/n"
  624.    "/t[-A|--autobackup {y|n}] " "/n"
  625.    "/t[--addtag Tag] " "/n"
  626.    "/t[--alloc AllocationPolicy] " "/n"
  627.    "/t[-c|--clustered {y|n}] " "/n"
  628.    "/t[-d|--debug]" "/n"
  629.    "/t[-h|--help]" "/n"
  630.    "/t[-l|--maxlogicalvolumes MaxLogicalVolumes]" "/n"
  631.    "/t[-M|--metadatatype 1|2] " "/n"
  632.    "/t[-p|--maxphysicalvolumes MaxPhysicalVolumes] " "/n"
  633.    "/t[-s|--physicalextentsize PhysicalExtentSize[kKmMgGtTpPeE]] " "/n"
  634.    "/t[-t|--test] " "/n"
  635.    "/t[-v|--verbose]" "/n"
  636.    "/t[--version] " "/n"
  637.    "/tVolumeGroupName PhysicalVolume [PhysicalVolume...]/n",
  638.    addtag_ARG, alloc_ARG, autobackup_ARG, clustered_ARG, maxlogicalvolumes_ARG,
  639.    maxphysicalvolumes_ARG, metadatatype_ARG, physicalextentsize_ARG, test_ARG)
  640. xx(vgdisplay,
  641.    "Display volume group information",
  642.    0,
  643.    "vgdisplay " "/n"
  644.    "/t[-c|--colon | -s|--short | -v|--verbose]" "/n"
  645.    "/t[-d|--debug] " "/n"
  646.    "/t[-h|--help] " "/n"
  647.    "/t[--ignorelockingfailure]" "/n"
  648.    "/t[--nosuffix]/n"
  649.    "/t[-P|--partial] " "/n"
  650.    "/t[--units hsbkmgtHKMGT]/n"
  651.    "/t[-A|--activevolumegroups | [-D|--disk]" "/n"
  652.    "/t[--version]" "/n"
  653.    "/t[VolumeGroupName [VolumeGroupName...]]/n"
  654.    "/n"
  655.    "vgdisplay --columns|-C/n"
  656.    "/t[--aligned]/n"
  657.    "/t[-d|--debug] " "/n"
  658.    "/t[-h|--help] " "/n"
  659.    "/t[--ignorelockingfailure]" "/n"
  660.    "/t[--noheadings]/n"
  661.    "/t[--nosuffix]/n"
  662.    "/t[-o|--options [+]Field[,Field]]/n"
  663.    "/t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]/n"
  664.    "/t[-P|--partial] " "/n"
  665.    "/t[--separator Separator]/n"
  666.    "/t[--unbuffered]/n"
  667.    "/t[--units hsbkmgtHKMGT]/n"
  668.    "/t[--verbose]" "/n"
  669.    "/t[--version]" "/n"
  670.    "/t[VolumeGroupName [VolumeGroupName...]]/n",
  671.    activevolumegroups_ARG, aligned_ARG, colon_ARG, columns_ARG, disk_ARG,
  672.    ignorelockingfailure_ARG, noheadings_ARG, nosuffix_ARG, options_ARG,
  673.    partial_ARG, short_ARG, separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
  674. xx(vgexport,
  675.    "Unregister volume group(s) from the system",
  676.    0,
  677.    "vgexport " "/n"
  678.    "/t[-a|--all] " "/n"
  679.    "/t[-d|--debug] " "/n"
  680.    "/t[-h|--help]" "/n"
  681.    "/t[-v|--verbose] " "/n"
  682.    "/t[--version] " "/n"
  683.    "/tVolumeGroupName [VolumeGroupName...]/n",
  684.    all_ARG, test_ARG)
  685. xx(vgextend,
  686.    "Add physical volumes to a volume group",
  687.    0,
  688.    "vgextend/n"
  689.    "/t[-A|--autobackup y|n]/n"
  690.    "/t[-d|--debug]/n"
  691.    "/t[-h|--help]/n"
  692.    "/t[-t|--test]/n"
  693.    "/t[-v|--verbose]/n"
  694.    "/t[--version]" "/n"
  695.    "/tVolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]/n",
  696.    autobackup_ARG, test_ARG)
  697. xx(vgimport,
  698.    "Register exported volume group with system",
  699.    0,
  700.    "vgimport " "/n"
  701.    "/t[-a|--all]/n"
  702.    "/t[-d|--debug] " "/n"
  703.    "/t[-f|--force] " "/n"
  704.    "/t[-h|--help] " "/n"
  705.    "/t[-t|--test] " "/n"
  706.    "/t[-v|--verbose]" "/n"
  707.    "/t[--version]" "/n"
  708.    "/tVolumeGroupName..." "/n",
  709.    all_ARG, force_ARG, test_ARG)
  710. xx(vgmerge,
  711.    "Merge volume groups",
  712.    0,
  713.    "vgmerge/n"
  714.    "/t[-A|--autobackup y|n]/n"
  715.    "/t[-d|--debug]/n"
  716.    "/t[-h|--help]/n"
  717.    "/t[-l|--list]/n"
  718.    "/t[-t|--test]/n"
  719.    "/t[-v|--verbose]/n"
  720.    "/t[--version]" "/n"
  721.    "/tDestinationVolumeGroupName SourceVolumeGroupName/n",
  722.    autobackup_ARG, list_ARG, test_ARG)
  723. xx(vgmknodes,
  724.    "Create the special files for volume group devices in /dev",
  725.    0,
  726.    "vgmknodes/n"
  727.    "/t[-d|--debug]/n"
  728.    "/t[-h|--help]/n"
  729.    "/t[--ignorelockingfailure]/n"
  730.    "/t[-v|--verbose]/n"
  731.    "/t[--version]" "/n"
  732.    "/t[VolumeGroupName...]/n",
  733.    ignorelockingfailure_ARG)
  734. xx(vgreduce,
  735.    "Remove physical volume(s) from a volume group",
  736.    0,
  737.    "vgreduce/n"
  738.    "/t[-a|--all]/n"
  739.    "/t[-A|--autobackup y|n]/n"
  740.    "/t[-d|--debug]/n"
  741.    "/t[-h|--help]/n"
  742.    "/t[--mirrorsonly]/n"
  743.    "/t[--removemissing]/n"
  744.    "/t[-t|--test]/n"
  745.    "/t[-v|--verbose]/n"
  746.    "/t[--version]" "/n"
  747.    "/tVolumeGroupName/n"
  748.    "/t[PhysicalVolumePath...]/n",
  749.    all_ARG, autobackup_ARG, mirrorsonly_ARG, removemissing_ARG, test_ARG)
  750. xx(vgremove,
  751.    "Remove volume group(s)",
  752.    0,
  753.    "vgremove/n"
  754.    "/t[-d|--debug]/n"
  755.    "/t[-f|--force]/n"
  756.    "/t[-h|--help]/n"
  757.    "/t[-t|--test]/n"
  758.    "/t[-v|--verbose]/n"
  759.    "/t[--version]" "/n"
  760.    "/tVolumeGroupName [VolumeGroupName...]/n",
  761.    force_ARG, test_ARG)
  762. xx(vgrename,
  763.    "Rename a volume group",
  764.    0,
  765.    "vgrename/n"
  766.    "/t[-A|--autobackup y|n]/n"
  767.    "/t[-d|--debug]/n"
  768.    "/t[-h|--help]/n"
  769.    "/t[-t|--test]/n"
  770.    "/t[-v|--verbose]/n"
  771.    "/t[--version]" "/n"
  772.    "/tOldVolumeGroupPath NewVolumeGroupPath |/n"
  773.    "/tOldVolumeGroupName NewVolumeGroupName/n",
  774.    autobackup_ARG, force_ARG, test_ARG)
  775. xx(vgs,
  776.    "Display information about volume groups",
  777.    0,
  778.    "vgs" "/n"
  779.    "/t[--aligned]/n"
  780.    "/t[-a|--all]/n"
  781.    "/t[-d|--debug]/n"
  782.    "/t[-h|--help]/n"
  783.    "/t[--ignorelockingfailure]/n"
  784.    "/t[--nameprefixes]/n"
  785.    "/t[--noheadings]/n"
  786.    "/t[--nosuffix]/n"
  787.    "/t[-o|--options [+]Field[,Field]]/n"
  788.    "/t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]/n"
  789.    "/t[-P|--partial] " "/n"
  790.    "/t[--rows]/n"
  791.    "/t[--separator Separator]/n"
  792.    "/t[--trustcache]/n"
  793.    "/t[--unbuffered]/n"
  794.    "/t[--units hsbkmgtHKMGT]/n"
  795.    "/t[--unquoted]/n"
  796.    "/t[-v|--verbose]/n"
  797.    "/t[--version]/n"
  798.    "/t[VolumeGroupName [VolumeGroupName...]]/n",
  799.    aligned_ARG, all_ARG, ignorelockingfailure_ARG, nameprefixes_ARG,
  800.    noheadings_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, 
  801.    rows_ARG, separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG,
  802.    unquoted_ARG)
  803. xx(vgscan,
  804.    "Search for all volume groups",
  805.    0,
  806.    "vgscan "
  807.    "/t[-d|--debug]/n"
  808.    "/t[-h|--help]/n"
  809.    "/t[--ignorelockingfailure]/n"
  810.    "/t[--mknodes]/n"
  811.    "/t[-P|--partial] " "/n"
  812.    "/t[-v|--verbose]/n"
  813.    "/t[--version]" "/n",
  814.    ignorelockingfailure_ARG, mknodes_ARG, partial_ARG)
  815. xx(vgsplit,
  816.    "Move physical volumes into a new or existing volume group",
  817.    0,
  818.    "vgsplit " "/n"
  819.    "/t[-A|--autobackup {y|n}] " "/n"
  820.    "/t[--alloc AllocationPolicy] " "/n"
  821.    "/t[-c|--clustered {y|n}] " "/n"
  822.    "/t[-d|--debug] " "/n"
  823.    "/t[-h|--help] " "/n"
  824.    "/t[-l|--maxlogicalvolumes MaxLogicalVolumes]" "/n"
  825.    "/t[-M|--metadatatype 1|2] " "/n"
  826.    "/t[-n|--name LogicalVolumeName]/n"
  827.    "/t[-p|--maxphysicalvolumes MaxPhysicalVolumes] " "/n"
  828.    "/t[-t|--test] " "/n"
  829.    "/t[-v|--verbose] " "/n"
  830.    "/t[--version]" "/n"
  831.    "/tSourceVolumeGroupName DestinationVolumeGroupName" "/n"
  832.    "/t[PhysicalVolumePath...]/n",
  833.    alloc_ARG, autobackup_ARG, clustered_ARG,
  834.    maxlogicalvolumes_ARG, maxphysicalvolumes_ARG,
  835.    metadatatype_ARG, name_ARG, test_ARG)
  836. xx(version,
  837.    "Display software and driver version information",
  838.    0,
  839.    "version/n" )
在lvm_register_commands(),应该是commands.h有多少个xx,就会顺序执行多少个
  1. _register_command(# a, a, b, c, ## d, /
  2.                         driverloaded_ARG, /
  3.                         debug_ARG, help_ARG, help2_ARG, /
  4.                         version_ARG, verbose_ARG, /
  5.                         quiet_ARG, config_ARG, -1);
此处有点疑惑,那在用户态下,每调用一次lvm,岂不是都要重新register command()?还每次都要构造树。。。
在_register_command里面,前面部分是获取可变参数的操作,最后调用_create_new_command(name, fn, flags, desc, usagestr, nargs, args);进行创建命令。
  1. static void _create_new_command(const char *name, command_fn command,
  2.                 unsigned flags,
  3.                 const char *desc, const char *usagestr,
  4.                 int nargs, int *args)
  5. {
  6.     struct command *nc;
  7.     _alloc_command();
  8.     nc = _cmdline.commands + _cmdline.num_commands++;
  9.     nc->name = name;
  10.     nc->desc = desc;
  11.     nc->usage = usagestr;
  12.     nc->fn = command;
  13.     nc->flags = flags;
  14.     nc->num_args = nargs;
  15.     nc->valid_args = args;
  16. }
每次调用_create_new_command,静态变量nc都会往后移,将该命令的内容填充到_cmdline中。