summaryrefslogtreecommitdiff
path: root/tools/command.c
Commit message (Collapse)AuthorAgeFilesLines
* make: move cmds.hDavid Teigland2022-09-271-2/+2
| | | | | generate the header in the include dir so it can be easily used from both lib and tools dirs.
* args: add ARG_NONINTERACTIVE for cmds not supported in lvm shellPeter Rajnoha2022-08-261-0/+1
| | | | | | | | | | | Certain args can't be used in lvm shell ("interactive mode") because they are not supported there. Add ARG_NONINTERACTIVE flag to mark such args and error out if we're in interactive mode and at the same time we detect use of such argument. Currently, this is the case for --reportformat arg - we don't support changing the format per command in lvm shell. The whole shell is running under a reportformat chosen at shell's start.
* asan: fix some reports from libasanZdenek Kabelac2022-02-071-1/+1
| | | | | | | | | | | | When compiled and used with: CFLAGS="-fsanitize=address -g -O0" ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 we have few reported issue - they where not normally spotted, since we were still accessing our own memory - but ouf of buffer-range. TODO: there is still something to enhance with handling of #orphan vgids
* cov: add explicit NULL pointer checkZdenek Kabelac2021-09-201-2/+2
| | | | Make obvious to coverity strcmp() is not getting NULL pointer.
* cov: handle better leak reportsZdenek Kabelac2021-09-201-11/+22
| | | | Rewrite code so the leaks are eliminated from Coverity.
* man-generator: initialize struct stat to avoid MSAN errorAdrian Ratiu2021-09-131-1/+1
| | | | | | | | | | | | | | | | | | | When building lvm2 in Gentoo/ChromeOS with the ASAN memory sanitizer enabled, man-generator fails with the following error. Initializing makes the error go away. * SUMMARY: MemorySanitizer: use-of-uninitialized-value /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3316:6 in _include_description_file * Exiting * ASAN error detected: * ==2548047==WARNING: MemorySanitizer: use-of-uninitialized-value * #0 0x558b00ab4730 in _include_description_file /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3316:6 * #1 0x558b00ab4730 in _print_man /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3426:21 * #2 0x558b00ab4730 in main /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3570:7 * #0 0x7fa9b2cbb807 in find_derivation /var/tmp/portage/cross-x86_64-cros-linux-gnu/glibc-2.33-r8/work/glibc-2.33/iconv/gconv_db.c:583:15 * #1 0x558b00a29559 in ?? ??:0 * * Uninitialized value was created by an allocation of 'statbuf.i.i' in the stack frame of function 'main' * #0 0x558b00ab1d4d in main /build/amd64-generic/tmp/portage/sys-fs/lvm2-2.02.187-r3/work/LVM2.2.02.187/tools/man-generator.c:3505
* devices file: limit warnings about devices file entries not foundDavid Teigland2021-08-051-0/+1
| | | | | | All commands were printing a warning if a devices file entry was not found. Limit this to commands that report/display lvm state.
* skip indexing devices used by LVs in more commandsDavid Teigland2021-07-091-1/+1
| | | | | | | | | | | | | | | | | | | | | expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74 "pvscan: skip indexing devices used by LVs" The dev cache index is expensive and slow, so limit it to commands that are used to observe the state of lvm. The index is only used to print warnings about incorrect device use by active LVs, e.g. if an LV is using a multipath component device instead of the multipath device. Commands that continue to use the index and print the warnings: fullreport, lvmdiskscan, vgs, lvs, pvs, vgdisplay, lvdisplay, pvdisplay, vgscan, lvscan, pvscan (excluding --cache) A couple other commands were borrowing the DEV_USED_FOR_LV flag to just check if a device was actively in use by LVs. These are converted to the new dev_is_used_by_active_lv().
* man/help: fix common option listingDavid Teigland2021-06-081-1/+27
|
* cov: ensure there is space for 0 at eolZdenek Kabelac2021-04-231-1/+1
| | | | Reserve 1 char for \0.
* man/help: move implied annotationDavid Teigland2021-04-211-4/+4
| | | | | | | | from [ --type foo (implied) ] to [ --type foo] (implied)
* commands: use AUTOTYPE in definitionsDavid Teigland2021-04-211-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | If a cmd def implies an LV type without --type in the required options, then include the implied type in the cmd def as AUTOTYPE: <type> instead of including the redundant --type foo in the OO list of options. Including an implied --type in the OO list would often cause multiple cmd defs to potentially be identical when options were used, and a user command could match more than one cmd def. The AUTOTYPE values are listed in man page and help output as [ --type foo (implied) ] If a user command includes --type, it will usually match a cmd def with --type in the required options. But, if the user command matches a cmd def with AUTOTYPE, then the specifed --type and AUTOTYPE must match. The man-generator program has a new --check option that compares cmd defs to find any cmd defs that are equivalent with the use of options, and should have their options adjusted.
* man-generator: add option to check for repeated command definitionsdev-dct-cmd-defs-checkDavid Teigland2021-04-201-5/+218
| | | | | | | | | | | | | | | Compares cmd defs based on two principles for avoiding repeated commands (where a given command could match more than one cmd def): . a cmd def should be a unique combination of required option args and position args . avoid adding optional options to a cmd def that if used would make the command match a different cmd def FIXME: record when repeated cmd defs are found so we can avoid reporting them twice, e.g. once for A vs B and second time for B vs A.
* man-generator: markup updatesZdenek Kabelac2021-04-191-82/+84
| | | | | | | | | | | | | | | | | | | | | | Emit .ad l / .ad b less frequently around larger blocks we want to keep left aligned. Avoid emittting empty lines. Reduce .HP usage and replace it with .TP. However keep .HP for all option listings, as i.e. html rendering can't handle well combintion of .TP an .HP together and .TP alone is not indenting 2nd. line of long option line. (For .TP line we don't need to emit .br) Surround .SH with dots for better look. For some .TP use plain more readable .I for a line. Support rendering of optional [Number] (for --units). Use better markup for units and instead of long markup string, show individual units with markup.
* man-generator: use \(emZdenek Kabelac2021-04-191-4/+4
| | | | Use \(em in command title description and command multidefs.
* man-generator: decorate optional option prefixesZdenek Kabelac2021-04-191-0/+20
| | | | | | Enhance man typography decoration of optional option prefixes like --[raid]writebeind and use regular font to render [] as these are not part of the option name itself.
* man/help: change LV type listingDavid Teigland2021-04-141-31/+60
| | | | | | | | | | | | | | | | | | | | | | | | | Previously, accepted LV types were presented as a series of suffixes after the "LV" on the command line. The addition of many new types resulted in this becoming too long, e.g lvconvert --type cache --cachepool LV LV_linear_striped_thinpool_vdo_vdopool_vdopooldata_raid For man pages, move these types from the command line to a new line dedicated to listing accepted LV types: lvconvert --type cache --cachepool LV LV1 ... LV1 types: linear striped thinpool vdo vdopool vdopooldata raid The special "LV1" is used as a reference to avoid confusion with other LVs that may appear on the command line. There are currently no commands with more than one typed LV, but if there are cases with more, then "LV2" could also be used. For command line usage/-h output, drop the LV types from the command line specification. The more detailed is not needed in the help output and can be found in the man page.
* man-generator: spacesZdenek Kabelac2021-04-121-4/+1
|
* man-generator: option description indentedZdenek Kabelac2021-04-121-3/+3
| | | | | Left indention is needed only for options, but is actually unwanted for decription itself.
* man-generator: remove ',' between some optionsZdenek Kabelac2021-04-121-8/+2
| | | | | | It would be complicated to handle ',' alignment after hyphenation changes ATM, but these commas seems to be there rather unneeded so remove them and make the man output more clear.
* man-generator: improve hyphenation for longer option listZdenek Kabelac2021-04-121-13/+34
| | | | | | | | | | | Disable hyphenation around longer option lists (>42 chars) and use \: to markup places for line splits. The code ATM is somewhat mixtured so it's not easy to encapsulate section .nh ... .hy. ATM global _was_hyphen is used to properly finish sections after disabled hyphenation.
* all: fix typosSamanta Navarro2021-03-301-2/+2
|
* cov: initialize valueZdenek Kabelac2021-03-111-1/+1
| | | | Coverity can't understand conditions together, so just keep it quiet.
* cov: remove unnecessary headersZdenek Kabelac2021-03-101-1/+0
|
* cmdline: use binary searchZdenek Kabelac2021-03-021-9/+47
| | | | | Reduce strcmp() call count by using binary search to find commands in cmd_names[] and command_names[] arrays.
* cmdline: drop MAX and check NULLZdenek Kabelac2021-03-021-10/+6
| | | | Remove MAX_COMMAND_NAMES and check for the last element as NULL pointer.
* man: more precise UNITZdenek Kabelac2020-10-241-3/+2
| | | | | | | | Since 'kilobytes' could be seen in 2 way - SI as '1000', while all programmers sees it as '1024' - switch to commonly acceptted KiB, MiB.... Resolves RHBZ 1496255.
* cov: explicitely ignore function resultZdenek Kabelac2020-09-011-2/+2
|
* lvcreate: new cache or writecache lv with single commandDavid Teigland2020-06-161-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To create a new cache or writecache LV with a single command: lvcreate --type cache|writecache -n Name -L Size --cachedevice PVfast VG [PVslow ...] - A new main linear|striped LV is created as usual, using the specified -n Name and -L Size, and using the optionally specified PVslow devices. - Then, a new cachevol LV is created internally, using PVfast specified by the cachedevice option. - Then, the cachevol is attached to the main LV, converting the main LV to type cache|writecache. Include --cachesize Size to specify the size of cache|writecache to create from the specified --cachedevice PVs, otherwise the entire cachedevice PV is used. The --cachedevice option can be repeated to create the cache from multiple devices, or the cachedevice option can contain a tag name specifying a set of PVs to allocate the cache from. To create a new cache or writecache LV with a single command using an existing cachevol LV: lvcreate --type cache|writecache -n Name -L Size --cachevol LVfast VG [PVslow ...] - A new main linear|striped LV is created as usual, using the specified -n Name and -L Size, and using the optionally specified PVslow devices. - Then, the cachevol LVfast is attached to the main LV, converting the main LV to type cache|writecache. In cases where more advanced types (for the main LV or cachevol LV) are needed, they should be created independently and then combined with lvconvert. Example ------- user creates a new VG with one slow device and one fast device: $ vgcreate vg /dev/slow1 /dev/fast1 user creates a new 8G main LV on /dev/slow1 that uses all of /dev/fast1 as a writecache: $ lvcreate --type writecache --cachedevice /dev/fast1 -n main -L 8G vg /dev/slow1 Example ------- user creates a new VG with two slow devs and two fast devs: $ vgcreate vg /dev/slow1 /dev/slow2 /dev/fast1 /dev/fast2 user creates a new 8G main LV on /dev/slow1 and /dev/slow2 that uses all of /dev/fast1 and /dev/fast2 as a writecache: $ lvcreate --type writecache --cachedevice /dev/fast1 --cachedevice /dev/fast2 -n main -L 8G vg /dev/slow1 /dev/slow2 Example ------- A user has several slow devices and several fast devices in their VG, the slow devs have tag @slow, the fast devs have tag @fast. user creates a new 8G main LV on the slow devs with a 2G writecache on the fast devs: $ lvcreate --type writecache -n main -L 8G --cachedevice @fast --cachesize 2G vg @slow
* cov: check strdup for NULLZdenek Kabelac2020-05-201-4/+8
|
* command: validate reporting of previous argumentZdenek Kabelac2020-02-041-8/+8
| | | | | When reporting parsing error, report 'previous' argument only when there is one.
* pvck: show specific dump option valuesDavid Teigland2019-12-101-0/+1
|
* pvck: repair headers and metadataDavid Teigland2019-11-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To write a new/repaired pv_header and label_header: pvck --repairtype pv_header --file <file> <device> This uses the metadata input file to find the PV UUID, device size, and data offset. To write new/repaired metadata text and mda_header: pvck --repairtype metadata --file <file> <device> This requires a good pv_header which points to one or two metadata areas. Any metadata areas referenced by the pv_header are updated with the specified metadata and a new mda_header. "--settings mda_num=1|2" can be used to select one mda to repair. To combine all header and metadata repairs: pvck --repair --file <file> <device> It's best to use a raw metadata file as input, that was extracted from another PV in the same VG (or from another metadata area on the same PV.) pvck will also accept a metadata backup file, but that will produce metadata that is not identical to other metadata copies on other PVs and other areas. So, when using a backup file, consider using it to update metadata on all PVs/areas. To get a raw metadata file to use for the repair, see pvck --dump metadata|metadata_search. List all instances of metadata from the metadata area: pvck --dump metadata_search <device> Save one instance of metadata at the given offset to the specified file (this file can be used for repair): pvck --dump metadata_search --file <file> --settings "metadata_offset=<off>" <device>
* cov: ensure cname exists before derefering itZdenek Kabelac2019-08-091-3/+3
| | | | | Just make it clear to analyzers cname can't be NULL. TODO: maybe exclude NULL at front of the function...
* exported vg handlingDavid Teigland2019-06-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The exported VG checking/enforcement was scattered and inconsistent. This centralizes it and makes it consistent, following the existing approach for foreign and shared VGs/PVs, which are very similar to exported VGs/PVs. The access policy that now applies to foreign/shared/exported VGs/PVs, is that if a foreign/shared/exported VG/PV is named on the command line (i.e. explicitly requested by the user), and the command is not permitted to operate on it because it is foreign/shared/exported, then an access error is reported and the command exits with an error. But, if the command is processing all VGs/PVs, and happens to come across a foreign/shared/exported VG/PV (that is not explicitly named on the command line), then the command silently skips it and does not produce an error. A command using tags or --select handles inaccessible VGs/PVs the same way as a command processing all VGs/PVs, and will not report/return errors if these inaccessible VGs/PVs exist. The new policy fixes the exit codes on a somewhat random set of commands that previously exited with an error if they were looking at all VGs/PVs and an exported VG existed on the system. There should be no change to which commands are allowed/disallowed on exported VGs/PVs. Certain LV commands (lvs/lvdisplay/lvscan) would previously not display LVs from an exported VG (for unknown reasons). This has not changed. The lvm fullreport command would previously report info about an exported VG but not about the LVs in it. This has changed to include all info from the exported VG.
* fix man page generationDavid Teigland2019-06-141-2/+2
| | | | | | The man page generation for pvchange/lvchange/vgchange was incorrect (leaving out some option listings) as a result of commit e225bf5 "fix command definition for pvchange -a"
* fix command definition for pvchange -aDavid Teigland2019-06-101-18/+75
| | | | | | | | | | | The -a was being included in the set of "one or more" options instead of an actual required option. Even though the cmd def was not implementing the restrictions correctly, the command internally was. Adjust the cmd def code which did not support a command with some real required options and a set of "one or more" options.
* add device hints to reduce scanningDavid Teigland2019-01-151-0/+2
| | | | | | | Save the list of PVs in /run/lvm/hints. These hints are used to reduce scanning in a number of commands to only the PVs on the system, or only the PVs in a requested VG (rather than all devices on the system.)
* mangenerator: check strdup was successfullZdenek Kabelac2018-12-211-2/+1
| | | | | Check for strdup != NULL and drop unneeded zeroing when buffer is overwritten.
* remove unneded check to skip filter initDavid Teigland2018-09-121-1/+0
| | | | | There's no more persistent filter so we don't need to check for it.
* Remove lvmetadDavid Teigland2018-07-111-1/+0
| | | | | | | | | | | | | Native disk scanning is now both reduced and async/parallel, which makes it comparable in performance (and often faster) when compared to lvm using lvmetad. Autoactivation now uses local temp files to record online PVs, and no longer requires lvmetad. There should be no apparent command-level change in behavior.
* man-generator: drop macro redefinesZdenek Kabelac2018-06-141-3/+0
|
* device_mapper: remove dbg_malloc.Joe Thornber2018-06-081-18/+18
| | | | | I wrote dbg_malloc before we had valgrind. These days there's just no need.
* scan: skip device rescan in vg_readDavid Teigland2018-04-201-0/+1
| | | | | | | | | | | For reporting commands (pvs,vgs,lvs,pvdisplay,vgdisplay,lvdisplay) we do not need to repeat the label scan of devices in vg_read if they all had matching metadata in the initial label scan. The data read by label scan can just be reused for the vg_read. This cuts the amount of device i/o in half, from two reads of each device to one. We have to be careful to avoid repairing the VG if we've skipped rescanning. (The VG repair code is very poor, and will be redone soon.)
* remove unnecessary REQUIRES_FULL_LABEL_SCANDavid Teigland2018-04-201-2/+1
| | | | we always scan all devices
* [io paths] Unpick agk's aio stuffJoe Thornber2018-04-201-6/+5
|
* cleanup: add _mb_ to regiosize optionZdenek Kabelac2018-04-201-2/+2
| | | | Just like with others mentions default unit in function name.
* cleanup: matching signessZdenek Kabelac2018-03-131-2/+3
|
* cleanup: more usage of dm_strncpyZdenek Kabelac2018-03-061-2/+1
| | | | Use existing wrapper function arournd strncpy + buf[] = 0;
* command: use bigger bufferZdenek Kabelac2018-02-281-2/+4
| | | | | Instead of use 'silently' shortened passed string - always make sure we take either a full copy or return error.