From 8b4701d7c4c962fc906ca49bee1fbd496a3376b8 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 1 Jul 2024 11:30:51 -0500 Subject: [PATCH] devices: redo bcache invalidation of PVs on LV --- lib/device/dev-cache.c | 15 +++++++++++++++ lib/device/dev-cache.h | 1 + lib/label/label.c | 8 ++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index c89280e1f..2ba3f1290 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -18,6 +18,7 @@ #include "lib/misc/lib.h" #include "lib/device/dev-type.h" #include "lib/device/device_id.h" +#include "lib/label/label.h" #include "lib/config/config.h" #include "lib/commands/toolcontext.h" #include "device_mapper/misc/dm-ioctl.h" @@ -1395,6 +1396,20 @@ int dev_cache_update_dm_devs(void) return 1; } +void dev_cache_dm_devs_label_invalidate(struct cmd_context *cmd) +{ + struct dm_active_device *dm_dev; + struct device *dev; + + dm_list_iterate_items(dm_dev, _cache.dm_devs) { + if (dm_dev->uuid && + strncmp(dm_dev->uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1) == 0) { + if ((dev = dev_cache_get_by_devt(cmd, dm_dev->devno))) + label_scan_invalidate(dev); + } + } +} + /* Find active DM device in devs array for given major:minor */ const struct dm_active_device * dev_cache_get_dm_dev_by_devno(struct cmd_context *cmd, dev_t devno) diff --git a/lib/device/dev-cache.h b/lib/device/dev-cache.h index a68ba757e..5fba2c0da 100644 --- a/lib/device/dev-cache.h +++ b/lib/device/dev-cache.h @@ -40,6 +40,7 @@ struct dm_list *dev_cache_get_dev_list_for_lvid(const char *lvid); int dev_cache_use_dm_devs_cache(void); int dev_cache_update_dm_devs(void); void dev_cache_destroy_dm_devs(void); +void dev_cache_dm_devs_label_invalidate(struct cmd_context *cmd); const struct dm_active_device * dev_cache_get_dm_dev_by_devno(struct cmd_context *cmd, dev_t devno); const struct dm_active_device * diff --git a/lib/label/label.c b/lib/label/label.c index 5e09eeff2..66f809a96 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -1670,8 +1670,12 @@ void label_scan_invalidate_lvs(struct cmd_context *cmd, struct dm_list *lvs) log_debug("Invalidating devs for any PVs on LVs."); - dm_list_iterate_items(lvl, lvs) - label_scan_invalidate_lv(cmd, lvl->lv); + if (dev_cache_use_dm_devs_cache()) + dev_cache_dm_devs_label_invalidate(cmd); + else { + dm_list_iterate_items(lvl, lvs) + label_scan_invalidate_lv(cmd, lvl->lv); + } } /*