summaryrefslogtreecommitdiff
path: root/tools/pvscan.c
Commit message (Collapse)AuthorAgeFilesLines
* pvscan: warn about /dev/sda excluded by devices fileDavid Teigland2022-04-011-0/+28
| | | | | | | | | | In most installations, /dev/sda* or /dev/vda* should be included in system.devices because the root, home, etc LVs are usually on sda or vda. Add a special case warning when a pvscan autoactivation command sees that /dev/sda* or /dev/vda* are excluded by system.devices, either not listed or having a different device id.
* change messages about filtered devicesDavid Teigland2022-04-011-2/+2
| | | | | | Change messages that refer to devices being "excluded by filters" to say just "excluded". This will avoid mistaking the word "filters" with the lvm.conf filter setting.
* pvscan: don't use udev for external device infoDavid Teigland2022-03-091-5/+3
| | | | | pvscan is used to populate udev info, so it can't expect to use that udev info.
* pvscan: fix filter symlink checksDavid Teigland2021-12-011-7/+11
| | | | | | Fixes commit "pvscan: match device arg to filter symlink" which failed to account for the fact that filter entries are not just path names but include "a" or "r", etc.
* pvscan: limit md device_hint for slow autoactivationDavid Teigland2021-11-301-2/+3
| | | | | | The device_hint name in the metadata was meant to prevent autoactivation from md components, but the name checks were more general and would catch unnecessary cases.
* pvscan: match device arg to filter symlinkDavid Teigland2021-11-291-0/+63
| | | | | | | | | | | | | | This fixes an issue related to the optimization in "pvscan: only add device args to dev cache" If the devices file is not used, and the lvm.conf filter accepts devices via symlink names, then those devices won't be accepted by pvscan for autoactivation. To resolve this, recognize when the filter contains symlinks and disable the optimization. When the optimization is disabled, a full dev_cache_scan is performed, and symlinks are associated with the device names passed to pvscan. filter-regex will accept a device if symlinks to that device are accepted.
* pvscan: consistent creation of pvs_lookup fileDavid Teigland2021-11-121-13/+30
| | | | | | | | | Consistently create the pvs_lookup file for VGs with more than one PV. Previously the file create would be skipped if all the PVs happened to already be online. That led to unpredicatable results in an uncommon case (when the last PV to come online is the only PV with metadata.)
* pvs_online: include devname in pvid filesDavid Teigland2021-11-091-23/+18
| | | | | | | | Include the device name in the /run/lvm/pvs_online/pvid files. Commands using the pvid file can use the devname to more quickly find the correct device, vs finding the device using the major:minor number. If the devname in the pvid file is missing or incorrect, fall back to using the devno.
* vgchange -aay: optimize device list using pvs_online filesDavid Teigland2021-11-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Port another optimization from pvscan -aay to vgchange -aay: "pvscan: only add device args to dev cache" This optimization avoids doing a full dev_cache_scan, and instead populates dev-cache with only the devices in the VG being activated. This involves shifting the use of pvs_online files from the hints interface up to the higher level label_scan interface. This specialized label_scan is structured around creating a list of devices from the pvs_online files. Previously, a list of all devices was created first, and then reduced based on the pvs_online files. The initial step of listing all devices was slow when thousands of devices are present on the system. This optimization extends the previous optimization that used pvs_online files to limit the devices that were actually scanned (i.e. reading to identify the device): "vgchange -aay: optimize device scan using pvs_online files"
* move code from pvscan.c to online.cDavid Teigland2021-11-041-335/+25
| | | | | related to managing files in /run/lvm/pvs_online and /run/lvm/vgs_online
* vgchange -aay: optimize device scan using pvs_online filesDavid Teigland2021-11-041-2/+32
| | | | | | | | | | | | | | | | | | | Port the old pvscan -aay scanning optimization to vgchange -aay. The optimization uses pvs_online files created by pvscan --cache to derive a list of devices to use when activating a VG. This allows autoactivation of a VG to avoid scanning all devices, and only scan the devices used by the VG itself. The optimization is applied internally using the device hints interface. The new option "--autoactivation event" is given to pvscan and vgchange commands that are called by event activation. This informs the command that it is being used for event activation, so that it can apply checks and optimizations that are specific to event activation. Those include: - skipping the command if lvm.conf event_activation=0 - checking that a VG is complete before activating it - using pvs_online files to limit device scanning
* rename pvscan_cache_single to expect_missing_vg_device in cmdDavid Teigland2021-11-041-1/+1
|
* add hints interface to the pvs_online file informationDavid Teigland2021-11-041-5/+7
| | | | | | | | | | | | | | | The information in /run/lvm/pvs_online/<pvid> files can be used to build a list of devices for a given VG. The pvscan -aay command has long used this information to activate a VG while scanning only devices in that VG, which is an important optimization for autoactivation. This patch implements the same thing through the existing device hints interface, so that the optimization can be applied elsewhere. A future patch will take advantage of this optimization in vgchange -aay, which is now used in place of pvscan -aay for event activation.
* pvscan: fix messages from coverity changesDavid Teigland2021-10-201-2/+2
|
* pvscan: only add device args to dev cacheDavid Teigland2021-10-191-22/+36
| | | | | Optimize the common pvscan --cache command by only adding the necessary devs to dev-cache.
* gcc: always initialize vg_completeZdenek Kabelac2021-10-151-1/+1
|
* debug: reduce some debugging noiseZdenek Kabelac2021-10-141-4/+4
| | | | | | | | | | | Resolve event_activation configure option just once. Do not print debug_devs about 'bad' filtering, when actually filter already printed reason for skipping Do not trace more then once about backup being disabled. No debug when unlinked file does not exists in pvscan.
* pvscan: add options listlvs listvg checkcompleteDavid Teigland2021-10-071-97/+321
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pvscan --cache <dev> . read only dev . create online file for dev pvscan --listvg <dev> . read only dev . list VG using dev pvscan --listlvs <dev> . read only dev . list VG using dev . list LVs using dev pvscan --cache --listvg [--checkcomplete] <dev> . read only dev . create online file for dev . list VG using dev . [check online files and report if VG is complete] pvscan --cache --listlvs [--checkcomplete] <dev> . read only dev . create online file for dev . list VG using dev . list LVs using dev . [check online files and report if VG is complete] . [check online files and report if LVs are complete] [--vgonline] can be used with --checkcomplete, to enable use of a vg online file. This results in only the first pvscan command to see the complete VG to report 'VG complete', and others will report 'VG finished'. This allows the caller to easily run a single activation of the VG. [--udevoutput] can be used with --cache --listvg --checkcomplete, to enable an output mode that prints LVM_VG_NAME_COMPLETE='vgname' that a udev rule can import, and prevents other output from the command (other output causes udev to ignore the command.) The list of complete LVs is meant to be passed to lvchange -aay, or the complete VG used with vgchange -aay. When --checkcomplete is used, lvm assumes that that the output will be used to trigger event-based autoactivation, so the pvscan does nothing if event_activation=0 and --checkcomplete is used. Example of listlvs ------------------ $ lvs -a vg -olvname,devices LV Devices lv_a /dev/loop0(0) lv_ab /dev/loop0(1),/dev/loop1(1) lv_abc /dev/loop0(3),/dev/loop1(3),/dev/loop2(1) lv_b /dev/loop1(0) lv_c /dev/loop2(0) $ pvscan --cache --listlvs --checkcomplete /dev/loop0 pvscan[35680] PV /dev/loop0 online, VG vg incomplete (need 2). VG vg incomplete LV vg/lv_a complete LV vg/lv_ab incomplete LV vg/lv_abc incomplete $ pvscan --cache --listlvs --checkcomplete /dev/loop1 pvscan[35681] PV /dev/loop1 online, VG vg incomplete (need 1). VG vg incomplete LV vg/lv_b complete LV vg/lv_ab complete LV vg/lv_abc incomplete $ pvscan --cache --listlvs --checkcomplete /dev/loop2 pvscan[35682] PV /dev/loop2 online, VG vg is complete. VG vg complete LV vg/lv_c complete LV vg/lv_abc complete Example of listvg ----------------- $ pvscan --cache --listvg --checkcomplete /dev/loop0 pvscan[35684] PV /dev/loop0 online, VG vg incomplete (need 2). VG vg incomplete $ pvscan --cache --listvg --checkcomplete /dev/loop1 pvscan[35685] PV /dev/loop1 online, VG vg incomplete (need 1). VG vg incomplete $ pvscan --cache --listvg --checkcomplete /dev/loop2 pvscan[35686] PV /dev/loop2 online, VG vg is complete. VG vg complete
* cov: check dev_get_size resultZdenek Kabelac2021-09-211-2/+6
| | | | Check we have obtained some device size out of dev_get_size().
* cov: make read buffer obviously zero endedZdenek Kabelac2021-09-201-0/+1
| | | | Coverity doesn't get the idea from memset() here.
* cov: check fid instance is createdZdenek Kabelac2021-09-201-1/+6
|
* cov: clean up pvid and vgid usageDavid Teigland2021-08-161-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pvid and vgid are sometimes a null-terminated string, and other times a 'struct id', and the two types were often cast between each other. When a struct id was cast to a char pointer, the resulting string would not necessarily be null terminated. Casting a null-terminated string id to a struct id is fine, but is still avoided when possible. A struct id is: int8_t uuid[ID_LEN] A string id is: char pvid[ID_LEN + 1] A convention is introduced to help distinguish them: - variables and struct fields named "pvid" or "vgid" should be null-terminated strings. - variables and struct fields named "pv_id" or "vg_id" should be struct id's. - examples: char pvid[ID_LEN + 1]; char vgid[ID_LEN + 1]; struct id pv_id; struct id vg_id; Function names also attempt to follow this convention. Avoid casting between the two types as much as possible, with limited exceptions when known to be safe and clearly commented. Avoid using variations of strcpy and strcmp, and instead use memcpy/memcmp with ID_LEN (with similar limited exceptions possible.)
* pvscan: only match devices file for command argsDavid Teigland2021-08-051-2/+44
| | | | | Avoid matching all devices with the devices file to avoid delays during startup.
* devices file: avoid updating entry dev names in some casesDavid Teigland2021-08-051-0/+2
| | | | | | Avoid thrashing changes to devices file device names by some commands that are run during startup when devnames are still being set up.
* devices file: limit warnings about devices file entries not foundDavid Teigland2021-08-051-0/+2
| | | | | | All commands were printing a warning if a devices file entry was not found. Limit this to commands that report/display lvm state.
* pvscan: narrow the previous commit slightlyDavid Teigland2021-07-131-5/+13
| | | | to avoid change to pvscan-autoactivate.sh
* pvscan: do nothing for device removal and event_activation=0David Teigland2021-07-131-6/+5
| | | | | | | | | The lvm2-pvscan service runs pvscan --cache -aay <dev> for device addition, and pvscan --cache <dev> on device removal. For event_activation=0, the addition does nothing. Fix device removal to also do nothing for event_activation=0. Device removal was previously doing some work to process the removal which slowed down stopping lvm2-pvscan services.
* devices: rework libudev usageDavid Teigland2021-07-131-11/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | related to config settings: obtain_device_info_from_udev (controls if lvm gets a list of devices from readdir /dev or from libudev) external_device_info_source (controls if lvm asks libudev for device information) . Make the obtain_device_list_from_udev setting affect only the choice of readdir /dev vs libudev. The setting no longer controls if udev is used for device type checks. . Change obtain_device_list_from_udev default to 0. This helps avoid boot timeouts due to slow libudev queries, avoids reported failures from udev_enumerate_scan_devices, and avoids delays from "device not initialized in udev database" errors. Even without errors, for a system booting with 1024 PVs, lvm2-pvscan times improve from about 100 sec to 15 sec, and the pvscan command from about 64 sec to about 4 sec. . For external_device_info_source="none", remove all libudev device info queries, and use only lvm native device info. . For external_device_info_source="udev", first check lvm native device info, then check libudev info. . Remove sleep/retry loop when attempting libudev queries for device info. udev info will simply be skipped if it's not immediately available. . Only set up a libdev connection if it will be used by obtain_device_list_from_udev/external_device_info_source. . For native multipath component detection, use /etc/multipath/wwids. If a device has a wwid matching an entry in the wwids file, then it's considered a multipath component. This is necessary to natively detect multipath components when the mpath device is not set up.
* pvscan: skip indexing devices used by LVsDavid Teigland2021-07-061-0/+2
| | | | | | | | | | | | | | | dev_cache_index_devs() is taking a large amount of time when there are many PVs. The index keeps track of devices that are currently in use by active LVs. This info is used to print warnings for users in some limited cases. The checks/warnings that are enabled by the index are not needed by pvscan --cache, so disable it in this case. This may be expanded to other cases in future commits. dev_cache_index_devs should also be improved in another commit to avoid the extreme delays with many devices.
* label_read_pvid: separate error and no-pvidDavid Teigland2021-04-231-1/+9
| | | | | | | | | | | error reading dev and no pvid on dev were both returning 0. make it easier for callers to know which, if they care. return 1 if the device could be read, regardless of whether a pvid was found or not. set has_pvid=1 if a pvid is found and 0 if no pvid is found.
* cov: ensure fid is not nullZdenek Kabelac2021-04-231-1/+2
|
* pvscan: fix memleakZdenek Kabelac2021-04-231-1/+1
| | | | | Commit 25b58310e3d606a85abc9bd50991ccb7ddcbfe25 add zalloc() without correspoding free(), switch to use cmd mempool.
* cleanup: use already set vg_completeZdenek Kabelac2021-03-111-5/+2
| | | | Already set to 0.
* cov: variable initializationZdenek Kabelac2021-03-101-1/+1
|
* cleanup: no backtraces needed after log_errorZdenek Kabelac2021-03-101-1/+1
| | | | Reduce double backtracing.
* device usage based on devices fileDavid Teigland2021-02-231-4/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The LVM devices file lists devices that lvm can use. The default file is /etc/lvm/devices/system.devices, and the lvmdevices(8) command is used to add or remove device entries. If the file does not exist, or if lvm.conf includes use_devicesfile=0, then lvm will not use a devices file. When the devices file is in use, the regex filter is not used, and the filter settings in lvm.conf or on the command line are ignored. LVM records devices in the devices file using hardware-specific IDs, such as the WWID, and attempts to use subsystem-specific IDs for virtual device types. These device IDs are also written in the VG metadata. When no hardware or virtual ID is available, lvm falls back using the unstable device name as the device ID. When devnames are used, lvm performs extra scanning to find devices if their devname changes, e.g. after reboot. When proper device IDs are used, an lvm command will not look at devices outside the devices file, but when devnames are used as a fallback, lvm will scan devices outside the devices file to locate PVs on renamed devices. A config setting search_for_devnames can be used to control the scanning for renamed devname entries. Related to the devices file, the new command option --devices <devnames> allows a list of devices to be specified for the command to use, overriding the devices file. The listed devices act as a sort of devices file in terms of limiting which devices lvm will see and use. Devices that are not listed will appear to be missing to the lvm command. Multiple devices files can be kept in /etc/lvm/devices, which allows lvm to be used with different sets of devices, e.g. system devices do not need to be exposed to a specific application, and the application can use lvm on its own set of devices that are not exposed to the system. The option --devicesfile <filename> is used to select the devices file to use with the command. Without the option set, the default system devices file is used. Setting --devicesfile "" causes lvm to not use a devices file. An existing, empty devices file means lvm will see no devices. The new command vgimportdevices adds PVs from a VG to the devices file and updates the VG metadata to include the device IDs. vgimportdevices -a will import all VGs into the system devices file. LVM commands run by dmeventd not use a devices file by default, and will look at all devices on the system. A devices file can be created for dmeventd (/etc/lvm/devices/dmeventd.devices) If this file exists, lvm commands run by dmeventd will use it. Internal implementaion: - device_ids_read - read the devices file . add struct dev_use (du) to cmd->use_devices for each devices file entry - dev_cache_scan - get /dev entries . add struct device (dev) to dev_cache for each device on the system - device_ids_match - match devices file entries to /dev entries . match each du on cmd->use_devices to a dev in dev_cache, using device ID . on match, set du->dev, dev->id, dev->flags MATCHED_USE_ID - label_scan - read lvm headers and metadata from devices . filters are applied, those that do not need data from the device . filter-deviceid skips devs without MATCHED_USE_ID, i.e. skips /dev entries that are not listed in the devices file . read lvm label from dev . filters are applied, those that use data from the device . read lvm metadata from dev . add info/vginfo structs for PVs/VGs (info is "lvmcache") - device_ids_find_renamed_devs - handle devices with unstable devname ID where devname changed . this step only needed when devs do not have proper device IDs, and their dev names change, e.g. after reboot sdb becomes sdc. . detect incorrect match because PVID in the devices file entry does not match the PVID found when the device was read above . undo incorrect match between du and dev above . search system devices for new location of PVID . update devices file with new devnames for PVIDs on renamed devices . label_scan the renamed devs - continue with command processing
* pvscan: support disabled event_activationZdenek Kabelac2021-02-081-0/+6
| | | | | | | | | | | In past we had this control with use_lvmetad check for pvscan --cache -aay Howerer this got lost with lvmetad removal commit: 117160b27e510dceb1ed6acf995115c040acd88d When user sets lvm.conf global/event_activation=0 pvscan service will no longer auto activate any LVs on appeared PVs.
* md component detection changesDavid Teigland2021-02-051-7/+23
| | | | | | | | | | | | | | | | | Move extra md component detection into the label scan phase. It had been in set_pv_devices which was deep within the vg_read phase, which wasn't a good place (better to detect that earlier.) Now that pv metadata info is available in the scan phase, the pv details (size and device_hint) can be used for extra md checking. Use the device_hint from the pv metadata to trigger a full md component check if the device_hint begins with /dev/md. Stop triggering full md component checks based on missing udev info for a dev. Changes to tests to reflect that the code is now detecting md components in some test case that it wasn't before.
* pvscan: enhance _count_pvid_files_from_lookup_fileZdenek Kabelac2021-02-011-31/+25
| | | | Ensure all vars are always properly defined in all paths.
* pvscan: ensure read buffer ends with 0Zdenek Kabelac2021-01-221-11/+8
| | | | | | | Read buffersize - 1 so the last byte is always 0. Simplify init of 0 buffers. Check snprintf result for error and report internal error as it could happen only via bad compile parameters.
* pvscan: make ret value definedZdenek Kabelac2021-01-221-2/+1
|
* pvscan: rework to improve PVs without metadataDavid Teigland2020-10-221-589/+723
| | | | | | | | | | | | | | | Restructure the pvscan code, and add new temporary files that list pvids in a VG, used for processing PVs that have no metadata. The new temp files, in /run/lvm/pvs_lookup/<vgname>, allow a proper pvscan --cache to be done on PVs that have no metadata. pvscan --cache <dev> is only supposed to read <dev>, but when <dev> has no metadata, this had not been possible. The command had to fall back to scanning all devices to read all VG metadata to get the list of all PVIDs needed to check for a complete VG. Now, the temp file can be used in place of reading metadata from all PVs on the system.
* pass cmd struct through more functionsDavid Teigland2020-04-211-1/+1
| | | | no functional change
* cov: unused header file removalZdenek Kabelac2020-02-041-1/+0
| | | | | | cov: unused header removed Also ensure library header file with config settings goes first. Move inclusion of format-text.h into layout.h
* cov: check for NULLZdenek Kabelac2019-11-141-1/+1
| | | | | | | | | | | Since we check for NULL pointers earlier we need to be consistent across function - since the NULL would applies across whole function. When dropping 'mda' check - we are actually already dereferencing it before - so it can't be NULL at that places (and it's validated before entering _read_mda_header_and_metadata).
* pvscan: use quick activation only with matching PV device namesDavid Teigland2019-09-301-8/+22
| | | | | | | | | | | | | | | | When the PV device names in the VG metadata do not match the current PV device names seen on the system, do not use the optimized activation function (that avoids extra device scanning.) When the device names do not match, it's a clue that there could be duplicate PVs, in which case we want to scan all devicess to find any duplicates and stop the activation if found. This does not prevent autoactivating a VG from the incorrect duplicate PV, because the incorrect duplicate may appear by itself first. At that point its duplicate PV does not exist to be seen. (A future enhancement could use the WWID to strengthen this detection.)
* pvscan: avoid full scan for activationDavid Teigland2019-09-031-75/+377
| | | | | | | | | | | | | | | | | | | When an online PV completed a VG, the standard activation functions were used to activate the VG. These functions use a full scan of all devs. When many pvscans are run during startup and need to activate many VGs, scanning all devs from all the pvscans can take a long time. Optimize VG activation in pvscan to scan only the devs in the VG being activated. This makes use of the online file info that was used to determine the VG was complete. The downside of this approach is that pvscan activation will not detect duplicate PVs and block activation, where a normal activation command (which scans all devices) would.
* pvscan: disable sleeping and retrying for udevDavid Teigland2019-08-161-0/+7
| | | | | | When systemd is running pvscans, udev may not be entirely initialized, so the pvscan should not sleep and retry waiting for udev info.
* pvscan cache: use lvmcache_label_scanDavid Teigland2019-08-161-1/+1
| | | | | | instead of the lower level label_scan. The lvmcache wrapper around label_scan checks for and eliminates more duplicate devs and md components.
* md component detection addition in vg_readDavid Teigland2019-08-161-1/+1
| | | | | | | | | | | | | | | | Usually md components are eliminated in label scan and/or duplicate resolution, but they could sometimes get into the vg_read stage, where set_pv_devices compares the device to the PV. If set_pv_devices runs an md component check and finds one, vg_read should eliminate the components. In set_pv_devices, run an md component check always if the PV is smaller than the device (this is not very common.) If the PV is larger than the device, (more common), do the component check when the config setting is "auto" (the default).