mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-11 16:44:22 -07:00
[PR #10596/92ca3793 backport][stable-11] lvm_pv - Fixes #10444 - Partition device not found (#10639)
lvm_pv - Fixes #10444 - Partition device not found (#10596)
* Skip rescan for partition devices in LVM PV module
Adds a check to prevent unnecessary rescan attempts on partition devices in the LVM physical volume module. When a device is actually a partition, attempting to rescan it via sysfs would fail since partitions don't have a rescan interface.
This change improves error handling by gracefully skipping the rescan operation when dealing with partition devices, avoiding misleading warning messages.
* Rewrote device rescan logic
Added changelog fragment
* Add issue reference to lvm_pv changelog entry
(cherry picked from commit 92ca379319
)
Co-authored-by: Klention Mali <45871249+klention@users.noreply.github.com>
This commit is contained in:
parent
fe922a26f0
commit
cf8107b628
2 changed files with 19 additions and 4 deletions
3
changelogs/fragments/lvm_pv.yml
Normal file
3
changelogs/fragments/lvm_pv.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- lvm_pv - properly detect SCSI or NVMe devices to rescan (https://github.com/ansible-collections/community.general/issues/10444, https://github.com/ansible-collections/community.general/pull/10596).
|
|
@ -91,9 +91,22 @@ def get_pv_size(module, device):
|
||||||
|
|
||||||
def rescan_device(module, device):
|
def rescan_device(module, device):
|
||||||
"""Perform storage rescan for the device."""
|
"""Perform storage rescan for the device."""
|
||||||
# Extract the base device name (e.g., /dev/sdb -> sdb)
|
|
||||||
base_device = os.path.basename(device)
|
base_device = os.path.basename(device)
|
||||||
rescan_path = "/sys/block/{0}/device/rescan".format(base_device)
|
is_partition = "/sys/class/block/{0}/partition".format(base_device)
|
||||||
|
|
||||||
|
# Determine parent device if partition exists
|
||||||
|
parent_device = base_device
|
||||||
|
if os.path.exists(is_partition):
|
||||||
|
parent_device = (
|
||||||
|
base_device.rpartition('p')[0] if base_device.startswith('nvme')
|
||||||
|
else base_device.rstrip('0123456789')
|
||||||
|
)
|
||||||
|
|
||||||
|
# Determine rescan path
|
||||||
|
rescan_path = "/sys/block/{0}/device/{1}".format(
|
||||||
|
parent_device,
|
||||||
|
"rescan_controller" if base_device.startswith('nvme') else "rescan"
|
||||||
|
)
|
||||||
|
|
||||||
if os.path.exists(rescan_path):
|
if os.path.exists(rescan_path):
|
||||||
try:
|
try:
|
||||||
|
@ -102,9 +115,8 @@ def rescan_device(module, device):
|
||||||
return True
|
return True
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
module.warn("Failed to rescan device {0}: {1}".format(device, str(e)))
|
module.warn("Failed to rescan device {0}: {1}".format(device, str(e)))
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
module.warn("Rescan path not found for device {0}".format(device))
|
module.warn("Rescan path does not exist for device {0}".format(device))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue