From ce545519e0f5d3d8b50deb3accbeffe41ef55f1d Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 23 Jan 2025 14:32:39 +0100 Subject: [PATCH 29/30] vg_read: matching missed empty cache lvm2 is caching DM nodes with the use of DM_LIST_DEVICES ioctl(). And tried to preserve the cached structure for the same list, however there was 1 case where cache was empty, and new LIST ioctl returned some elements - if this DM table change has happened in the moment of 'scanning' and locking - lvm2 has then continued to use 'invalid' empty cache. Fix by capturing this missed case and update cache properly. TODO: we could possibly use plain memcmp() with previous ioctl result. (cherry picked from commit b32c0bb9c5474f39abffd9609ed486074ace6a2b) --- lib/device/dev-cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 947995fb1..52f8804c4 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -1314,7 +1314,7 @@ int dm_devs_cache_update(void) unsigned devs_features; uint32_t d; struct dm_list *dm_devs_new, *l; - int cache_changed = 0; + int cache_changed; if (!get_dm_active_devices(NULL, &dm_devs_new, &devs_features)) return 1; @@ -1329,6 +1329,7 @@ int dm_devs_cache_update(void) /* Compare existing cached list with a new one. * When there is any mismatch, just rebuild whole cache */ if ((l = dm_list_first(dm_devs_new))) { + cache_changed = dm_list_empty(_cache.dm_devs); // 1 for empty cache and new list has entries */ dm_list_iterate_items(dm_dev, _cache.dm_devs) { dm_dev_new = dm_list_item(l, struct dm_active_device); if ((dm_dev->devno != dm_dev_new->devno) || -- 2.48.1