summaryrefslogtreecommitdiff
path: root/lib/label
Commit message (Collapse)AuthorAgeFilesLines
* cov: remove unneeded header file inclusionZdenek Kabelac2023-05-101-1/+0
|
* cleanup: correcting some log_printZdenek Kabelac2023-05-061-11/+12
| | | | | Correcting to log_print_unless_silent(), so -qq can do some work.
* pvscan: filter does not need to be checked for symlink namesDavid Teigland2023-02-151-4/+1
| | | | | | | With the recent use of DEVLINKS, there is no longer any real point in checking the filter for symlink names. Removing this check should not change behavior with or without symlinks in the filter.
* vgchange autoactivation: skip regex filter containing symlinksDavid Teigland2023-01-311-0/+17
| | | | | | | | | | | | "vgchange -aay --autoactivation event" is called by our udev rule. When the udev rule runs, symlinks for devices may not all be created yet. If the regex filter contains symlinks, it won't work correctly. This command uses devices that already passed through pvscan. Since pvscan applies the regex filter correctly, this command inherits the filtering from pvscan and can skip the regex filter itself. See the previous commit "pvscan: use alternate device names from DEVLINKS to check filter"
* cov: remove unused headersZdenek Kabelac2022-07-111-1/+0
|
* exit with error when --devicesfile name doesn't existDavid Teigland2022-07-061-2/+2
|
* 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.
* devices: only close PVs on LVs when scan_lvs is enabledDavid Teigland2022-03-011-2/+4
| | | | This code is only needed when lvm scans PVs that are stacked on LVs.
* devices: use dev-cache aliases handling from label scan functionsDavid Teigland2022-02-281-110/+33
| | | | | | The label scan functions where doing some device alias validation which is now better handled by the dev-cache layer, so just use that.
* devices: fix dev_name assumptionsDavid Teigland2022-02-242-1/+24
| | | | | | | | | | dev_name(dev) returns "[unknown]" if there are no names on dev->aliases. It's meant mainly for log messages. Many places assume a valid path name is returned, and use it directly. A caller that wants to use the path from dev_name() must first check if the dev has any paths with dm_list_empty(&dev->aliases).
* devices: simplify dev_cache_get_by_devtDavid Teigland2022-02-241-3/+3
| | | | | | remove unused args, and no callers need or want a repeated dev_cache_scan if there is no dev from the lookup.
* devices file: do not clear PVID of unread devicesDavid Teigland2022-02-102-0/+22
| | | | | | | | | | | | | | | | In a certain disconnected state, a block device is present on the system, can be opened, reports a valid size, reports the correct device id (wwid), and matches a devices file entry. But, reading the device can still fail. In this case, device_ids_validate() was misinterpreting the read error as the device having no data/label on it (and no PVID). The validate function would then clear the PVID from the devices file entry for the device, thinking that it was fixing the devices file (making it consistent with the on disk state.) Fix this by not attempting to check and correct a devices file entry that cannot be read. Also make this case explicit in the hints validation code (which was doing the right thing but indirectly.)
* label: cache dm device listZdenek Kabelac2021-12-202-0/+36
| | | | | | | | | | | | | | Since we check for present DM devices - cache result for futher use of checking presence of such device. lvm2 uses cache result for label scan, but also when it tries to activate or deactivate LV - however only simple target 'striped' is reasonably supported. Use disable_dm_devs to be able to control when lv_info() get cache or uncached results. TODO: support more type, however this is getting very complicated.
* device_id: searched_devnames improvementsDavid Teigland2021-11-161-0/+10
| | | | | | | | | | Remove the searched_devnames file in a couple more places: . When hints need refreshing it's possible that a missing devices file entry could be found by searching devices again. . When a devices file entry devname is first found to be incorrect, a new search for missing entries may be useful.
* vgchange autoactivation: error path cleanupDavid Teigland2021-11-151-3/+60
| | | | | | | If the optimized label scan fails (using online files), then clear the device state prior to falling back to the standard label_scan. This avoids printing output about unexpected state.
* vgchange autoactivation: lock vg early to avoid second label scanDavid Teigland2021-11-101-4/+0
| | | | | | | Copy another optimization from pvscan -aay to vgchange -aay. When using the optimized label scan for only one VG, acquire the VG lock prior to the scan. This allows vg_read to then skip the repeated label scan that normally happens after locking the vg.
* pvs_online: include devname in pvid filesDavid Teigland2021-11-091-13/+5
| | | | | | | | 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: improve unexpected command variationsDavid Teigland2021-11-082-16/+36
| | | | | | | | | | | | | | | | | | | | | | | | | For completeness and consistency, adjust the behavior for some variations of: vgchange -aay --autoactivation event [vgname] The current standard use is with a VG name arg, and the command is only called when all pvs_online files exist. This is the optimal case, in which only pvs_online devs are read. This remains the same. Clean up behaviors for some other unexpected uses of the command: . With no VG name arg, the command activates any VGs that are complete according to pvs_online. If no pvs_online files exist, it does nothing. . If a VG name is used but no PVs online files exist for the VG, or the PVs online files are incomplete, then consider there could be a problem with the pvs_online files, and fall back to a full label scan prior to attempting the activation.
* vgchange -aay: fall back to dev_cache_scan if optimization failsDavid Teigland2021-11-051-6/+37
| | | | | | | | | | Part of the optimization to avoid a full dev_cache_scan requires translating major:minor numbers to a device name. If this devno translation fails, then fall back to doing a full dev_cache_scan which is slower but certain to provide the info. This preserves the most important part of the label scanning optimization in the vgchange aay (avoiding dev_cache_scan is a relatively small part of the optimized activation compared to label scanning.)
* vgchange -aay: optimize device list using pvs_online filesDavid Teigland2021-11-054-120/+195
| | | | | | | | | | | | | | | | | | | | | | | 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-2/+1
| | | | | related to managing files in /run/lvm/pvs_online and /run/lvm/vgs_online
* add hints interface to the pvs_online file informationDavid Teigland2021-11-042-1/+123
| | | | | | | | | | | | | | | 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.
* lvmdevices: increase open file limitDavid Teigland2021-11-032-2/+4
|
* hints: remove the cmd hints listDavid Teigland2021-11-012-7/+2
| | | | | which is no longer used after commit "toollib: remove all devices list from process_each_pv"
* fix segfault handling duplicate PVsDavid Teigland2021-10-142-3/+3
| | | | | cmd arg was missing when switching to use an alternative duplicate dev.
* toollib: remove all devices list from process_each_pvDavid Teigland2021-10-131-0/+1
| | | | | | | | | Reporting non-PVs / "all devices" is only done by pvs -a or pvdisplay -a, so avoid the work managing a list of all devices in process_each_pv. In the case when it's needed, use the results of label_scan which already determines which devs are not PVs.
* gcc: use more zero length arraysZdenek Kabelac2021-09-221-1/+1
| | | | Define last array struct member with zero size.
* gcc-fanalyzer: zallocate memory for clean bufferZdenek Kabelac2021-09-211-1/+1
|
* cov: add some initializersZdenek Kabelac2021-09-131-1/+1
|
* cov: clean up pvid and vgid usageDavid Teigland2021-08-161-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.)
* scan: retry reading metadata on errorDavid Teigland2021-07-062-0/+6
| | | | | | | | | | | | | If label_scan encounters bad vg metadata, invalidate bcache data for the device and reread the mda_header and metadata text back to back. With concurrent commands modifying large metadata, it's possible that the entire metadata area can be rewritten in the time between a command reading the mda_header and reading the metadata text that the header points to. Since the label_scan is just assembling an initial overview of devices, it doesn't use locking to serialize with other commands that may be modifying the vg metadata at the same time.
* scan: don't hold bcache block during scanDavid Teigland2021-07-061-33/+38
| | | | | This allows data from the bcache block to be invalidated and reread if needed.
* label_read_pvid: separate error and no-pvidDavid Teigland2021-04-232-5/+11
| | | | | | | | | | | 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.
* cleanup: indentZdenek Kabelac2021-04-231-1/+1
|
* cov: explicitely ignore return valueZdenek Kabelac2021-04-231-1/+1
|
* debug: drop stack from regular code flowZdenek Kabelac2021-03-151-1/+1
|
* debug: more tracingZdenek Kabelac2021-03-101-2/+4
| | | | Check result of device_ids_write() and at least provide stack;
* hints: keep strings aligned in structureZdenek Kabelac2021-03-081-3/+3
| | | | Preffer aligned string access.
* label: check only with active device for rescanZdenek Kabelac2021-03-021-6/+6
| | | | | | When 'lv_info()' is called with &info structure, the presence of node has to be checked from this structure. Without this we were needlesly trying to look out 0:0 device.
* device usage based on devices fileDavid Teigland2021-02-233-25/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* scan: wipe filters when dropping scanned dataDavid Teigland2021-02-101-13/+1
| | | | | | | | | | | | | | | | | | | | | | | Fix clearing persistent filter state when clearing all the state from a label_scan. label_scan reads devs and saves info in bcache, lvmcache, and in the persistent filter. In some uncommon cases, an lvm command wants to clear all info from a prior label_scan, and repeat label_scan from scratch. In these cases, info in lvmcache, bcache and the persistent filter all need to be cleared before repeating label_scan. By missing the persistent filter wiping, outdated persistent filter info, from a prior label_scan, could cause lvm to incorrectly filter devices that change between polling intervals. (i.e. if the device changes in such a way that the filtering results change.) A case where lvm wants to do multiple label_scans is a polling command (like lvconvert --merge), when lvmpolld has been disabled, so that the command itself needs to to do repeated polling checks.
* label: avoid rescaning unusable DM devicesZdenek Kabelac2021-02-101-0/+13
|
* md component detection changesDavid Teigland2021-02-051-28/+12
| | | | | | | | | | | | | | | | | 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.
* label_scan: fix missing free of filtered_devsDavid Teigland2021-01-181-0/+5
| | | | | missing free of devl entries on filtered_devs list in commit 2c9bb676048fda86867df165aa297f7078dffc4b
* pvcreate: clean up opening and filtering of argsDavid Teigland2020-10-262-12/+14
| | | | | | | | | | | | | | | | | | | | | | | | | The args for pvcreate/pvremove (and vgcreate/vgextend when applicable) were not efficiently opened, scanned, and filtered. This change reorganizes the opening and filtering in the following steps: - label scan and filter all devs . open ro . standard label scan at the start of command - label scan and filter dev args . open ro . uses full md component check . typically the first scan and filter of pvcreate devs - close and reopen dev args . open rw and excl - repeat label scan and filter dev args . using reopened rw excl fd - wipe and write new headers . using reopened rw excl fd
* add label_scan_devs_cachedDavid Teigland2020-10-212-0/+16
| | | | | | label_scan_devs without invalidating data first for cases where the caller wants to use any bcache data they have already read.
* add label_read_pvidDavid Teigland2020-10-212-0/+49
| | | | | | | To read the lvm headers and set dev->pvid if the device is a PV. Difference from label_scan_ functions is this does not read any vg metadata or add any info to lvmcache.
* lvmcache: rename label_read label_scan_devDavid Teigland2020-10-212-3/+2
| | | | for consistent naming with other similar functions
* scanning: improve filtering controlDavid Teigland2020-10-211-48/+70
| | | | | | | | | | | | | | | | | | | | | Filtering in label_scan was controlled indirectly by the fact that bcache was not yet set up when label_scan first ran. The result is that filters that needed data would not run and would return -EAGAIN, which would result in the dev flag FILTER_AFTER_SCAN being set. After the dev header was read for checking the label, filters would be rechecked because of FILTER_AFTER_SCAN. All filters would be checked this time because bcache was now set up, and the filters needing data would largely use data already scanned for reading the label. This design worked but is hard to adjust for future cases where bcache is already set up. Replace this method (based on setting up bcache, or not) with a new cmd flag filter_nodata_only. When this flag is set filters that need data will not run. This allows the same label_scan behavior when bcache has been set up. There are no expected changes in behavior.
* debug: no backtraceZdenek Kabelac2020-10-021-1/+1
| | | | As the path already printed verbose message drop backtrace.