summaryrefslogtreecommitdiff
path: root/lib/misc
Commit message (Collapse)AuthorAgeFilesLines
* utils: define macro for ffsZdenek Kabelac2021-09-271-0/+8
| | | | | | | Provide ffs() macro using __builtin_ffs(), when there is missing ffs() implementation in header file. Reported-by: adamboardman of gemian
* cov: initialize attrZdenek Kabelac2021-09-131-1/+1
|
* devices: rework libudev usageDavid Teigland2021-07-131-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* lib: remove unused macrosZdenek Kabelac2021-04-061-54/+0
| | | | Internally lvm2 is not using versioning for device-mapper.
* signals: support also SIGTERM for breaking commandZdenek Kabelac2021-04-061-27/+49
| | | | | | | | If we are signaled with SIGTERM it should be at least as good as with SIGINT - as the command should stop ASAP. So when lvm2 command allows signal handling we also enable SIGTERM handling. If there are some other signals we should handle equally - we could just extend array.
* configure: support builds without versioningZdenek Kabelac2021-03-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Not all libc (like musl, uclibc dietlibc) libraries support full symbol version resolution in runtime like glibc. Add support to not generate symbol versions when compiling against them. Additionally libdevmapper.so was broken when compiled against uclibc. Runtime linker loader caused calling dm_task_get_info_base() function recursively, leading to segmentation fault. Introduce --with-symvers=STYLE option, which allows to choose between gnu and disabled symbol versioning. By default gnu symbol versioning is used. __GNUC__ check is replaced now with GNU_SYMVER. Additionally ld version script is included only in case of gnu option, which slightly reduces output size. Providing --without-symvers to configure script when building against uclibc library fixes segmentation fault error described above, due to lack of several versions of the same symbol in libdevmapper.so library. Based on: https://patchwork.kernel.org/project/dm-devel/patch/20180831144817.31207-1-m.niestroj@grinn-global.com/ Suggested-by: Marcin Niestroj <m.niestroj@grinn-global.com>
* signals: add interruptible usleepZdenek Kabelac2021-03-142-0/+16
| | | | | Add small wrapper that temporarily enables signal handling during usleep() and return '0' when interrupted.
* lvm-file: remove duplication of dm_is_empty_dirZdenek Kabelac2021-03-102-25/+0
|
* Allow dm-integrity to be used for raid imagesDavid Teigland2020-04-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | dm-integrity stores checksums of the data written to an LV, and returns an error if data read from the LV does not match the previously saved checksum. When used on raid images, dm-raid will correct the error by reading the block from another image, and the device user sees no error. The integrity metadata (checksums) are stored on an internal LV allocated by lvm for each linear image. The internal LV is allocated on the same PV as the image. Create a raid LV with an integrity layer over each raid image (for raid levels 1,4,5,6,10): lvcreate --type raidN --raidintegrity y [options] Add an integrity layer to images of an existing raid LV: lvconvert --raidintegrity y LV Remove the integrity layer from images of a raid LV: lvconvert --raidintegrity n LV Settings Use --raidintegritymode journal|bitmap (journal is default) to configure the method used by dm-integrity to ensure crash consistency. Initialization When integrity is added to an LV, the kernel needs to initialize the integrity metadata/checksums for all blocks in the LV. The data corruption checking performed by dm-integrity will only operate on areas of the LV that are already initialized. The progress of integrity initialization is reported by the "syncpercent" LV reporting field (and under the Cpy%Sync lvs column.) Example: create a raid1 LV with integrity: $ lvcreate --type raid1 -m1 --raidintegrity y -n rr -L1G foo Creating integrity metadata LV rr_rimage_0_imeta with size 12.00 MiB. Logical volume "rr_rimage_0_imeta" created. Creating integrity metadata LV rr_rimage_1_imeta with size 12.00 MiB. Logical volume "rr_rimage_1_imeta" created. Logical volume "rr" created. $ lvs -a foo LV VG Attr LSize Origin Cpy%Sync rr foo rwi-a-r--- 1.00g 4.93 [rr_rimage_0] foo gwi-aor--- 1.00g [rr_rimage_0_iorig] 41.02 [rr_rimage_0_imeta] foo ewi-ao---- 12.00m [rr_rimage_0_iorig] foo -wi-ao---- 1.00g [rr_rimage_1] foo gwi-aor--- 1.00g [rr_rimage_1_iorig] 39.45 [rr_rimage_1_imeta] foo ewi-ao---- 12.00m [rr_rimage_1_iorig] foo -wi-ao---- 1.00g [rr_rmeta_0] foo ewi-aor--- 4.00m [rr_rmeta_1] foo ewi-aor--- 4.00m
* writecache: working real dm uuid suffix for wcorig lvDavid Teigland2020-02-201-0/+1
|
* writecache: drop real dm suffixDavid Teigland2020-02-171-1/+0
| | | | fixes the problem of adding writecache to an active LV
* pvcreate,pvremove: fix reacquiring global lock after promptDavid Teigland2019-11-261-1/+1
| | | | | | | | | | When pvcreate/pvremove prompt the user, they first release the global lock, then acquire it again after the prompt, to avoid blocking other commands while waiting for a user response. This release/reacquire changes the locking order with respect to the hints flock (and potentially other locks). So, to avoid deadlock, use a nonblocking request when reacquiring the global lock.
* cache: _cpool is protected suffix nowZdenek Kabelac2019-10-221-0/+1
|
* lvm-string: add drop_lvname_suffixZdenek Kabelac2019-10-212-0/+25
| | | | Internal function to drop suffix out of lvname.
* cachevol: put _cvol as protected suffix.Zdenek Kabelac2019-10-141-0/+2
| | | | | | This revert "drop cvol dm uuid suffix for cachevol LVs" commit 5191057d9df3e5b92db3f80c412b99aea1074358. Start using -cvol for DM UUID.
* drop cvol dm uuid suffix for cachevol LVsDavid Teigland2019-09-231-2/+0
| | | | | The "-cvol" suffix on the uuid is interfering with activation code, so drop the suffix for now.
* writecache: use dm suffixes and lv attributesDavid Teigland2019-09-201-0/+2
| | | | | | | - use internal CACHE_VOL flag on cachevol LV - add suffixes to dm uuids for internal LVs - display appropriate letters in the LV attr field - display writecache's cachevol in lvs output
* cachevol: add dm uuid suffixes to hidden lvsDavid Teigland2019-09-201-0/+2
| | | | to indicate they are private lvm devs
* vdo: enhance activation with layer -vpoolZdenek Kabelac2019-09-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Enhance 'activation' experience for VDO pool to more closely match what happens for thin-pools where we do use a 'fake' LV to keep pool running even when no thinLVs are active. This gives user a choice whether he want to keep thin-pool running (wihout possibly lenghty activation/deactivation process) As we do plan to support multple VDO LVs to be mapped into a single VDO, we want to give user same experience and 'use-patter' as with thin-pools. This patch gives option to activate VDO pool only without activating VDO LV. Also due to 'fake' layering LV we can protect usage of VDO pool from command like 'mkfs' which do require exlusive access to the volume, which is no longer possible. Note: VDO pool contains 1024 initial sectors as 'empty' header - such header is also exposed in layered LV (as read-only LV). For blkid we are indentified as LV with UUID suffix - thus private DM device of lvm2 - so we do not need to store any extra info in this header space (aka zero is good enough).
* pvscan: disable sleeping and retrying for udevDavid Teigland2019-08-162-0/+13
| | | | | | When systemd is running pvscans, udev may not be entirely initialized, so the pvscan should not sleep and retry waiting for udev info.
* remove unused trustcache optionDavid Teigland2019-06-112-13/+0
|
* locking: unify global lock for flock and lockdDavid Teigland2019-04-291-1/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There have been two file locks used to protect lvm "global state": "ORPHANS" and "GLOBAL". Commands that used the ORPHAN flock in exclusive mode: pvcreate, pvremove, vgcreate, vgextend, vgremove, vgcfgrestore Commands that used the ORPHAN flock in shared mode: vgimportclone, pvs, pvscan, pvresize, pvmove, pvdisplay, pvchange, fullreport Commands that used the GLOBAL flock in exclusive mode: pvchange, pvscan, vgimportclone, vgscan Commands that used the GLOBAL flock in shared mode: pvscan --cache, pvs The ORPHAN lock covers the important cases of serializing the use of orphan PVs. It also partially covers the reporting of orphan PVs (although not correctly as explained below.) The GLOBAL lock doesn't seem to have a clear purpose (it may have eroded over time.) Neither lock correctly protects the VG namespace, or orphan PV properties. To simplify and correct these issues, the two separate flocks are combined into the one GLOBAL flock, and this flock is used from the locking sites that are in place for the lvmlockd global lock. The logic behind the lvmlockd (distributed) global lock is that any command that changes "global state" needs to take the global lock in ex mode. Global state in lvm is: the list of VG names, the set of orphan PVs, and any properties of orphan PVs. Reading this global state can use the global lock in sh mode to ensure it doesn't change while being reported. The locking of global state now looks like: lockd_global() previously named lockd_gl(), acquires the distributed global lock through lvmlockd. This is unchanged. It serializes distributed lvm commands that are changing global state. This is a no-op when lvmlockd is not in use. lockf_global() acquires an flock on a local file. It serializes local lvm commands that are changing global state. lock_global() first calls lockf_global() to acquire the local flock for global state, and if this succeeds, it calls lockd_global() to acquire the distributed lock for global state. Replace instances of lockd_gl() with lock_global(), so that the existing sites for lvmlockd global state locking are now also used for local file locking of global state. Remove the previous file locking calls lock_vol(GLOBAL) and lock_vol(ORPHAN). The following commands which change global state are now serialized with the exclusive global flock: pvchange (of orphan), pvresize (of orphan), pvcreate, pvremove, vgcreate, vgextend, vgremove, vgreduce, vgrename, vgcfgrestore, vgimportclone, vgmerge, vgsplit Commands that use a shared flock to read global state (and will be serialized against the prior list) are those that use process_each functions that are based on processing a list of all VG names, or all PVs. The list of all VGs or all PVs is global state and the shared lock prevents those lists from changing while the command is processing them. The ORPHAN lock previously attempted to produce an accurate listing of orphan PVs, but it was only acquired at the end of the command during the fake vg_read of the fake orphan vg. This is not when orphan PVs were determined; they were determined by elimination beforehand by processing all real VGs, and subtracting the PVs in the real VGs from the list of all PVs that had been identified during the initial scan. This is fixed by holding the single global lock in shared mode while processing all VGs to determine the list of orphan PVs.
* config: add new setting io_memory_sizeDavid Teigland2019-03-042-0/+12
| | | | | | which defines the amount of memory that lvm will allocate for bcache. Increasing this setting is required if it is smaller than a single copy of VG metadata.
* logging: add command[pid] and timestamp to file and verbose outputDavid Teigland2019-02-262-9/+39
| | | | | | | | | Without this, the output from different commands in a single log file could not be separated. Change the default "indent" setting to 0 so that the default debug output does not include variable spaces in the middle of debug lines.
* lvm: drop usage of dl libraryZdenek Kabelac2018-12-172-32/+1
| | | | | | Since lvm no longer supports any dlopen-able plugins (which in practice was never really usable) drop linking with -ldl.
* headers: use configure.h as 1st. headerZdenek Kabelac2018-12-141-7/+2
| | | | | | | | | | | Ensure configure.h is always 1st. included header. Maybe we could eventually introduce gcc -include option, but for now this better uses dependency tracking. Also move _REENTRANT and _GNU_SOURCE into configure.h so it doesn't need to be present in various source files. This ensures consistent compilation of headers like stdio.h since it may produce different declaration.
* gcc: avoid shadowing use_aioZdenek Kabelac2018-12-012-3/+3
| | | | | Function use_aio() is already declared, avoid its shadowing. lvm-globals.h:59: warning: shadowed declaration is here
* io: use sync io if aio failsDavid Teigland2018-11-202-0/+13
| | | | | | | | | | | | | | | | | | io_setup() for aio may fail if a system has reached the aio request limit. In this case, fall back to using sync io. Also, lvm use of aio can be disabled entirely with config setting global/use_aio=0. The system limit for aio requests can be seen from /proc/sys/fs/aio-max-nr The current usage of aio requests can be seen from /proc/sys/fs/aio-nr The system limit for aio requests can be increased by setting fs.aio-max-nr using sysctl. Also add last-byte limit to the sync io code.
* vdo: component activation of VDO data LVZdenek Kabelac2018-07-091-1/+2
| | | | Allow component activation of VDO data LV.
* vdo: introduce segment types and manip functionsZdenek Kabelac2018-07-091-0/+2
| | | | Core functionality introducing lvm VDO support.
* utils: add clzllZdenek Kabelac2018-06-221-1/+14
| | | | Check for __builtin_clzll and add wrapper when missing.
* Remove unused device error countingDavid Teigland2018-06-152-15/+0
|
* device_mapper: remove dbg_malloc.Joe Thornber2018-06-083-12/+13
| | | | | I wrote dbg_malloc before we had valgrind. These days there's just no need.
* device_mapper: rename libdevmapper.h -> all.hJoe Thornber2018-06-081-1/+1
| | | | | I'm paranoid a file will include the global one in /usr/include by accident.
* Rework lock-override options and locking_type settingsDavid Teigland2018-06-073-16/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The last commit related to this was incomplete: "Implement lock-override options without locking type" This is further reworking and reduction of the locking.[ch] layer which handled all clustering, but is now only used for file locking. The "locking types" that this layer implemented were removed previously, leaving only the standard file locking. (Some cluster-related artifacts remain to be cleared out later.) Command options to override or modify locking behavior are reimplemented here without using the locking types. Also, deprecated locking_type values are recognized, and implemented as if one of the equivalent override options was set. Options that override file locking are: . --nolocking disables all file locking. . --readonly grants read lock requests without actually taking a file lock, and refuses write lock requests. . --ignorelockingfailure tries to set up file locks and uses them normally if possible. When not possible, it behaves like --readonly, but allows activation. . --sysinit is the same as ignorelockingfailure. . global/metadata_read_only acquires actual read file locks, and refuses write lock requests. (Some of these options could probably be deprecated because they were added as workarounds to various locking_type behaviors that are now deprecated.) The locking_type setting now has one valid value: 1 which refers to standard file locking. Configs that contain deprecated values are recognized and still work in largely the same way: . 0 disabled all locking, now implemented like --nolocking is set. Allow the nolocking option in all commands. . 1 is the normal file locking setting and is unchanged. . 2 was for external locking which was not used, and reverts to normal file locking. . 3 was for cluster/clvm. This reverts to normal file locking, and prints messages about lvmlockd. . 4 was equivalent to readonly, now implemented like --readonly is set. . 5 disabled all locking, now implemented like --nolocking is set.
* Merge branch 'master' into 2018-05-11-fork-libdmJoe Thornber2018-05-161-1/+0
|\
| * dev_cache: drop open_listDavid Teigland2018-05-111-1/+0
| | | | | | | | | | | | devices are now held open only in bcache, so drop the dev_cache list of open devices which is unused.
* | device-mapper: Fork libdm internally.Joe Thornber2018-05-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | The device-mapper directory now holds a copy of libdm source. At the moment this code is identical to libdm. Over time code will migrate out to appropriate places (see doc/refactoring.txt). The libdm directory still exists, and contains the source for the libdevmapper shared library, which we will continue to ship (though not neccessarily update). All code using libdm should now use the version in device-mapper.
* | build: Don't generate symlinks in include/ dirJoe Thornber2018-05-1415-46/+46
|/ | | | | | | As we start refactoring the code to break dependencies (see doc/refactoring.txt), I want us to use full paths in the includes (eg, #include "base/data-struct/list.h"). This makes it more obvious when we're breaking abstraction boundaries, eg, including a file in metadata/ from base/
* build: add -D_FILE_OFFSET_BITS=64Joe Thornber2018-05-021-1/+0
| | | | | | | I don't like having this in a common header because it means you end up including too much and causing unneccessary dependencies. eg, lib/misc/lib.h includes libdevmapper.h, internationalisation, and logging stuff.
* dev_cache: clean up scanDavid Teigland2018-04-202-13/+0
| | | | | Pull out all of the twisted logic and simply call dev_cache_scan at the start of the command prior to label scan.
* lvmcache: simplify metadata cacheDavid Teigland2018-04-202-14/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The copy of VG metadata stored in lvmcache was not being used in general. It pretended to be a generic VG metadata cache, but was not being used except for clvmd activation. There it was used to avoid reading from disk while devices were suspended, i.e. in resume. This removes the code that attempted to make this look like a generic metadata cache, and replaces with with something narrowly targetted to what it's actually used for. This is a way of passing the VG from suspend to resume in clvmd. Since in the case of clvmd one caller can't simply pass the same VG to both suspend and resume, suspend needs to stash the VG somewhere that resume can grab it from. (resume doesn't want to read it from disk since devices are suspended.) The lvmcache vginfo struct is used as a convenient place to stash the VG to pass it from suspend to resume, even though it isn't related to the lvmcache or vginfo. These suspended_vg* vginfo fields should not be used or touched anywhere else, they are only to be used for passing the VG data from suspend to resume in clvmd. The VG data being passed between suspend and resume is never modified, and will only exist in the brief period between suspend and resume in clvmd. suspend has both old (current) and new (precommitted) copies of the VG metadata. It stashes both of these in the vginfo prior to suspending devices. When vg_commit is successful, it sets a flag in vginfo as before, signaling the transition from old to new metadata. resume grabs the VG stashed by suspend. If the vg_commit happened, it grabs the new VG, and if the vg_commit didn't happen it grabs the old VG. The VG is then used to resume LVs. This isolates clvmd-specific code and usage from the normal lvm vg_read code, making the code simpler and the behavior easier to verify. Sequence of operations: - lv_suspend() has both vg_old and vg_new and stashes a copy of each onto the vginfo: lvmcache_save_suspended_vg(vg_old); lvmcache_save_suspended_vg(vg_new); - vg_commit() happens, which causes all clvmd instances to call lvmcache_commit_metadata(vg). A flag is set in the vginfo indicating the transition from the old to new VG: vginfo->suspended_vg_committed = 1; - lv_resume() needs either vg_old or vg_new to use in resuming LVs. It doesn't want to read the VG from disk since devices are suspended, so it gets the VG stashed by lv_suspend: vg = lvmcache_get_suspended_vg(vgid); If the vg_commit did not happen, suspended_vg_committed will not be set, and in this case, lvmcache_get_suspended_vg() will return the old VG instead of the new VG, and it will resume LVs based on the old metadata.
* coverity: drop unneeded header filesZdenek Kabelac2018-03-171-1/+0
|
* cleanup: more usage of dm_strncpyZdenek Kabelac2018-03-062-6/+3
| | | | Use existing wrapper function arournd strncpy + buf[] = 0;
* lvm-string: add function to detect component LV suffixZdenek Kabelac2017-12-192-3/+28
| | | | Add is_component_lvname() function to recognize component LV name.
* locking: avoid descriptor leak for nonblocking modeZdenek Kabelac2017-08-251-5/+8
| | | | | | | | | When file-locking mode failed on locking, such description was leaked (typically not an issue since command usually exists afterwards). So shirt close() at the end of function and use it in all error paths. Also make sure, when interrrupt is detected, it's really not holding lock and returns 0.
* cleanup: whitespaceZdenek Kabelac2017-07-111-1/+1
|
* signals: fix comparison flawHeinz Mauelshagen2017-04-101-1/+1
| | | | | | | | commit 9a689fb8f0a6b1675a4e819f4837bf2e0269832f fixed SIGINT blocking but introduced a comparision flaw to sigint_restore(). Related: rhbz1440766
* signals: fix SIGINT blocking flaw causing inconsistent metadataHeinz Mauelshagen2017-04-101-4/+4
| | | | | | | | | | | | | | | | | | | | SIGINT isn't blocked properly after a sigint_allow(), sigint_restore() cycle leading to illicit interruptable metadata updates. These can leave corrupted metadata behind. Issues addressed in this commit: sigint_allow() fails to set _oldmasked[] members properly due to an offset by one bug on indexing the members of the array. It bails out prematurely comparing to MAX_SIGINTS causing nesting depths to be one less than MAX_SIGINTS. Fix the comparision. Correct the related comparison flaw in sigint_restore(). Initialize all sig_atomic_t variables consequently. Resolves: rhbz1440766
* coverity: remove unneeded header filesZdenek Kabelac2017-02-111-1/+0
|