1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-07-07 16:58:58 +03:00

7721 Commits

Author SHA1 Message Date
c901528053 lvconvert: error raid1 LV non-changing image count request
In case a Raid1LV has e.g. 3 images already, running "lvconvert --mirrors 2 $Raid1LV"
results in success even though the image count didn't change.
Make it fail in such case.

Related issue: https://issues.redhat.com/browse/RHEL-82138
2025-07-01 16:00:21 +02:00
4bc52d2dc5 lvmlockd: add repair option to reinitialize sanlock leases
If sanlock leases become corrupted, adding --lockopt repair
to the command will let lvmlockd reinitialize them.
2025-06-30 12:59:49 -05:00
8a7c026451 gcc: fix signness warnings with explicit casts
Add explicit type casts to resolve GCC signness comparison warnings:
- Cast dest_size to int in lvmlockctl.c
- Cast NVME_IDENTIFY_DATA_SIZE to int in nvme.c
- Cast bitwise AND results to int in nvme.c and persist.c
- Cast DM_STATS_GROUP_NOT_PRESENT to int in libdm-stats.c
2025-06-30 16:56:43 +02:00
29dd3800e4 cov: ensure nsid is defined 2025-06-30 16:56:43 +02:00
f1f94d987d cov: add annotations to suppress fp warnings
Add Coverity annotations to suppress false positive warnings in several
files where the static analysis tool incorrectly flags potential issues
that are actually safe due to proper validation or intentional behavior.

The annotations address the following false positives:

- daemons/dmeventd/dmeventd.c: overflow_sink warnings for 'current' variable
  that is validated to be positive before use in buffer operations

- daemons/lvmlockd/lvmlockd-core.c: overflow_sink warning for 'ret' variable
  that is validated to be positive before use

- lib/config/config.c: overflow_sink warning for 'sz' variable that is
  validated to be positive before use in read operations

- libdm/dm-tools/dmsetup.c: overflow_sink, overflow, and deref_overflow
  warnings for 'n' variable that is validated to be positive before use
  in buffer operations and string termination

- libdm/libdm-stats.c: overflow_sink warning for 'i & j' variables that are
  validated to be positive before use in array indexing
2025-06-30 16:56:43 +02:00
29a799961c cov: add checked variants for mda_is_ignored and rlocn_is_ignored
Introduce _mda_is_ignored() and _rlocn_is_ignored() wrapper functions
with warn_unused_result attribute to enforce return value checking.

This follows the established pattern used by dm_strncpy() and _dm_strncpy():
- Functions without underscore prefix can be used without checking return values
- Functions with underscore prefix must have their return values checked

The change improves static analysis coverage by ensuring that critical
metadata area and raw location ignored state checks are properly validated,
reducing the risk of unhandled error conditions in metadata processing.
2025-06-30 16:56:43 +02:00
543a87e12a cov: reduce strcpy usage
Coverity does not like strcpy() calls...
2025-06-30 16:56:43 +02:00
ad016ea4e3 cov: prefer snprintf 2025-06-30 16:56:43 +02:00
39a45f212d cov: ensure read got some bytes 2025-06-30 16:56:43 +02:00
5f73db83bc cov: fix double-close bug in _btrfs_get_mnt function
Ensure file descriptor is closed only once by moving close() call
to immediately after read() and setting fd = -1 to prevent reuse.
2025-06-30 16:56:42 +02:00
11154dfab2 debug: add missing error path traces
Trace failures of close() and unlink() syscalls.
2025-06-30 16:56:42 +02:00
50abb2c2c9 lvmlockd: optimize lock_type access in lockd_start_vg
Store vg->lock_type in a local variable to avoid repeated null checks
and string comparisons throughout the function. This improves code
readability and eliminates redundant conditional evaluations.
2025-06-30 16:56:42 +02:00
8e630ebf2c gcc: keep code compilable with std=c99 2025-06-27 10:26:00 +02:00
83debc25a3 gcc: ensure proper value initialization 2025-06-27 10:26:00 +02:00
70e8ef249b config: add lvresize_fs_helper_executable option
- Add global_lvresize_fs_helper_executable_CFG config option to allow
  specifying the path to the lvresize_fs_helper script.
- Add DEFAULT_LVRESIZE_FS_HELPER_PATH macro for default value.
- Update _get_lvresize_fs_helper_path() in lib/device/filesystem.c
  to read the path from configuration using find_config_tree_str,
  similar to _fsadm_cmd().
- This allows users to override the helper path via configuration,
  improving flexibility and consistency with fsadm_executable handling.
- Avoid using static variable to get helper path just once, since
  it may change between commands via lvm.conf in lvm2 shell.
2025-06-27 10:26:00 +02:00
fb250d23f2 nvme: match header prototype for dev_find_key_nvme
Missed to synchronize with previous commit.
2025-06-27 10:26:00 +02:00
2d5ef4a4ef device_id: Fix compiling when versionsort not found
alphasort was replaced with versionsort in 09e508cd43 commit.

This commit fixes the following compiler error.

device/device_id.c:1608:65: error: use of undeclared identifier 'versionsort'
1608 |         sort_count = scandir(dirpath, &namelist, _filter_backup_files, versionsort);
     |                                                                        ^
2025-06-27 10:26:00 +02:00
e3871db279 persistent reservations
Enable lvm to use persistent reservations on a VG, which
are applied to each PV in the VG.

. lvmpersist is a low level script, which uses commands
  sg_persist, mpathpersist, and nvme to do PR operations
  on devices. This script is used by higher level lvm
  commands, and would not often be run by users.

. vgchange --setpersist is a VG metadata configuration command
  that specifies how PR should be started and enforced for a VG
  relative to other lvm commands.

. vgchange --persist is a command to change PR state of PVs in
  the VG, e.g. start PR to register and reserve.

The lvmpersist man page contains a complete description.
2025-06-27 10:26:00 +02:00
e97ce575f4 devices: add dev_is_scsi and dev_is_mpath 2025-06-27 10:26:00 +02:00
97449a611b codespell: fix various typos across codebase
- lib/device/filesystem.c: 'avaiable' -> 'available' in btrfs comment
- lib/format_text/export.c: 'sting' -> 'string' in comment
- lib/log/log.c: 'expectes' -> 'expects' in coverity comment
- lib/metadata/metadata.c: 'damanging' -> 'damaging' in comment
- lib/metadata/metadata.h: 'Aditional' -> 'Additional' in comment
- test/shell/000-basic.sh: 'supression' -> 'suppression' in comment
- test/shell/pvcreate-partition.sh: 'lable' -> 'label' in comment
- test/shell/topology-support.sh: 'standart' -> 'standard' in comment
- WHATS_NEW:
  * 'propperly' -> 'properly'
  * 'cachable' -> 'cacheable'
2025-06-25 22:48:42 +02:00
7417698823 build: fix include paths for out-of-source builds
Fix include paths in cmd_enum.h and command.c by removing the "include/"
prefix from #include directives. This resolves build failures when
building from a directory different from the source directory.

The include paths were incorrectly referencing "include/cmds.h" instead
of "cmds.h", causing compilation errors in out-of-source builds.
2025-06-25 22:48:42 +02:00
f024936924 tools: reporter: override LC_NUMERIC if needed for json_std format
Override LC_NUMERIC part of the locale to "C" if we detect that the
radix character interferes with JSON_STD format. If that's the case,
override LC_NUMERIC locale to "C" in report_format_init, that is,
before any reporting is executed (including log reporting). Restore
it back in report_format_destroy, that is, once we're sure that all
reporting is finished.

Related: https://gitlab.com/lvmteam/lvm2/-/issues/33
2025-06-12 10:18:52 +02:00
0a665d0c17 tools: reporter: cleanup: factor out code to new report_format_destroy
We already have report_format_init. Having report_format_destroy makes
it easier to read and follow the code using these functions.
2025-06-12 10:18:46 +02:00
93013c09be lvresize: add btrfs support
This commit adds lvresize/lvextend/lvreduce support for btrfs.
'btrfs filesystem resize [devid:][+/-]<newsize>[kKmMgGtTpPeE]|[devid:]max <path>'
is used to resize one device only when it's mounted.
The code pattern is like xfs but it supports shrink.

For multi-devices btrfs, There is one difficulty to be handled:

If `lvreduce --fs resize` is given, lvm2 will check newsize vs current fs size
to judge if it's need to shrink fs or not.
For one device btrfs, fslastblock * fsblocksize/FSSIZE is the correct value like
ext* and xfs. But for multi-devices btrfs, the two values are whole fs size.
There is no other way without relying btrfs superblock parse. It's too
complicated and inproper to implemnt the logic in lvm2.
So here just sets fs_last_byte to 0 for btrfs and skips boundary check in
_fs_reduce_allow(). It's safe as btrfs will handle it well.

The another complicated part is how to get mount point info if multi-devices.
There is only one mnt entry per mounted fs in /etc/mtab even it's a
multi-devices btrfs. So we first get uuid from lv device then traverse devices
under /sys/fs/btrfs/$uuid/devices and compare them to the mnt entry to get the
mount point.

Signed-off-by: Su Yue <glass.su@suse.com>
2025-05-13 12:27:17 -05:00
9edb10b5f4 filesystem: factor out get mount point logic from fs_get_info() into _fs_get_mnt()
The new _fs_get_mnt() is used to get mount point info for fses.
No functional change.

Signed-off-by: Su Yue <glass.su@suse.com>
2025-05-13 12:27:17 -05:00
7c65c16a66 filesystem: get device uuid in fs_get_blkid
Add new field fs_info::uuid to record device uuid when calling
fs_get_blkid() for further use.

No functional change.

Signed-off-by: Su Yue <glass.su@suse.com>
2025-05-13 12:27:17 -05:00
03d8661657 raid: count or clear transiently failed devices
Count or clear transiently failed devices as of dm-raid superblocks.
Updated debuging.
Use lvconvert --repair to repair transiently failed legs.
Activating all 'meta' LVs with single sync_local_dev_names().
Using proper DM path for meta LV.

Modified-by: zkabelac@redhat.com
2025-05-07 16:54:12 +02:00
a1b27f0656 lvmlockd: use error for corrupted sanlock lease in start
if sanlock delta lease for host_id is corrupt, then
return ELOCKREPAIR.
2025-05-06 11:34:51 -05:00
47a48fd0b6 lvmlockd: add error for corrupted sanlock lease
A specific error message can be printed for this case:
"sanlock lease needs repair"
2025-05-06 11:34:51 -05:00
9b51b3d3f1 lvmlockd: use new sanlock_acquire2 to return owner info
Use the new sanlock_acquire2() which returns info about the owner
of a lease.  Pass this info back to the lvm command, where it's
initially used to print the host_id of a host holding a lock
when it cannot be acquired.
2025-05-06 11:34:51 -05:00
b8b0fcfa10 cov: remove unused header 2025-04-01 15:37:36 +02:00
d0c9bcf6d7 validation: add check for single vdo segments
Add check for VDO LV and VDOPOOL LV having just
a single segment in LV.
Also add couple missing '.'  in error messages.
2025-04-01 15:37:36 +02:00
43a755d568 device-types: support zram
See Linux source Documentation/admin-guide/blockdev/zram.rst .
zram devices offer a good performance and efficient resource utilization
through the use of compression.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2025-04-01 15:37:36 +02:00
12419e3b67 snapshot: fix lvresize when greater than max COW size
If lvresize is given a size > the maximum COW size for a given origin
the command will fail with an internal error and no error message:

  # lvresize --size 1.6g fedora/snaptest-snap
    Rounding size to boundary between physical extents: <1.59 GiB.
    Reached maximum COW size <1.01 GiB (258 extents).
    Command failed with status code 5.

  With -vvv:

  Found snapshot target v1.16.0.
  Getting target version for snapshot-origin
  dm versions   [ opencount flush ]   [2048] (*1)
  Found snapshot-origin target v1.9.0.
  Reached maximum COW size <1.01 GiB (258 extents). <<<
  Unlock: Memlock counters: prioritized:0 locked:0 critical:0 daemon:0 suspended:0
  Syncing device names
  Unlocking /run/lock/lvm/V_fedora
  _undo_flock /run/lock/lvm/V_fedora
  Freeing VG fedora at 0x55781b142890.
  Freeing VG fedora at 0x55781b136860.
  global/notify_dbus not found in config: defaulting to 1
  Destroy lvmcache content
  Completed: lvresize -vvv --debug --size 1706243072b fedora/snaptest-snap
  Internal error: Failed command did not use log_error

This happens because in this case _lvresize_adjust_extents() returns
early without setting lp->resize to either LV_EXTEND or LV_REDUCE after
capping lp->extents to the maximum COW size.

Fix this by just capping lp->extents and relying on the existing code in
_lvresize_adjust_extents() to fixup lp->resize in the case that
lp->extents == existing_logical_extents. This is consistent with the
no-op case where -l is given as the existing size:

root@localhost:~/src/git/lvm2# LD_LIBRARY_PATH="$PWD/tools" ./tools/lvm lvresize -L 1.6g fedora/snaptest-snap
  Rounding size to boundary between physical extents: 1.60 GiB.
  Reached maximum COW size <1.01 GiB (258 extents).
  New size (258 extents) matches existing size (258 extents).
  No size change.
2025-04-01 15:36:26 +02:00
154befd4b8 cache: ensure UUID ends with \0
Initialization of union is somewhat tricky as it initialize only
the first member + padding, but in our case this does not clear
the whole size of union so explicitly set \0 after 2 'struct id'
and make sure DM uuid is not using random characters from stack.

Also add explicit .id designators (c99).
2025-03-17 13:48:58 +01:00
951fd6358b metadata: replace pv status WRONG_VG with pv bit field
Avoid any special meaning associated with the status field.
2025-03-06 10:52:50 -06:00
8efbffe086 lvmcache: unpair wrong PV devs and improve duplicate name warnings
After detecting that a VG has wrongly claimed a PV, unpair
the pv->dev setting.  This will cause the usual "missing PV"
message to appear for that VG.  Make this message, and some
others, clearer by using the VGID rather than the VG name
when there are multiple VGs with the same name.
2025-03-06 10:02:29 -06:00
cff93e4d5c lvmcache: fix check for no pvid 2025-03-05 16:03:42 -06:00
227d3ca507 lvmcache: add WRONG_VG PV status flag
_vg_read() calls lvmcache_update_vg_from_read() which detects
that the VG metadata is incorrectly claiming the PV.  Flag this
condition in the PV status as WRONG_VG.  Later, vg_read() can
simply check the WRONG_VG flag rather than repeating the same
PV/VG checks that were already done in lvmcache_update_vg_from_read.
2025-03-05 14:28:42 -06:00
cc843151b4 lvmcache: ignore incorrect PV claim from old metadata
Outdated VG metadata that appears when an old device is attached
to the system can result in PVs appearing to belong to the
old/wrong VG, and commands are allowed to use (corrupt) the PVs.

- vgcreate old /dev/sda /dev/sdb /dev/sdc
- offline /dev/sda
- vgreduce --removemissing old
- vgremove old
- vgcreate new /dev/sdb /dev/sdc
- online /dev/sda

When sda is reattached, sdb and sdc will appear to be
in VG old again.  An attempt to correct the problem,
e.g. with vgremove old or vgreduce old, would modify
sdb and sdc, removing them from the new VG.

To fix this, check that sdb and sdc contain metadata for
VG old before allowing VG old to claim ownership of them.
With the fix, sdb and sdc are not displayed as part of
VG old, and commands to change VG old will fail as long
as it references incorrect PVs.

To fix VG old (sda), remove the incorrect PVs from VG old
while limiting the command to see only the correct PVs:
vgreduce --removemissing --devices /dev/sda old
2025-03-05 14:16:46 -06:00
7dd2f101c7 integrity: round meta size up to minimum one extent
If VG extents are larger than the required integrity metadata size,
use one extent as the size.
2025-03-03 11:31:40 -05:00
381b45b5a9 lvmlockd: add helpful error message for vgremove
Print a helpful error message when the lockspace is not started.
2025-03-03 11:05:04 -05:00
1dcd9fbe08 misc: Typo fix s/loose/lose/
Signed-off-by: Eric Blake <eblake@redhat.com>
2025-02-26 10:32:19 +00:00
a853649565 misc: Typo fix s/more then/more than/
Also a few instances of s/less then/less than/.

Signed-off-by: Eric Blake <eblake@redhat.com>
2025-02-26 10:32:19 +00:00
4fa6c76181 lvmlockd: drop return from void function 2025-02-26 01:31:49 +01:00
80ee9e45cb uncache and splitcache should restore inactive state
If an inactive LV is being cached in writeback mode, then
removing the cache does a temporary activation to flush
the cache back to the main LV.  However, it forgot to
deactivate the LV again, so the temporary activation
was left in place.
2025-02-25 15:48:28 -06:00
dfb4ed13f6 lvmlockd: expand lockopt skip options
The lockopt options for skipping locks were not being used
in many places, making it impossible to override locking to
forcibly run some commands.
2025-02-25 12:40:36 -06:00
d5ac344465 clang: match prototype 2025-02-25 01:10:04 +01:00
7d0acdbcb0 thin: fix checking monitor mode
Previous commit 874a8ab4d0 missed 'IGNORE' mode.
Fix it by adding rather 'explicit' test for this value,
so the code is better readable.

Also unlock memory earlier and drop unneeded <backtrace>
from return since we already logged error in this function.
2025-02-25 01:09:49 +01:00
5430eec2b9 lvmlockd: fix missing lvremove free_lv
Fix missing lockd_free_lv in commit
e3f0af8f1f lvmlockd: fixes for lvremove
2025-02-24 16:36:01 -06:00