Skip to contentSkip to conversation

pvscan: Increase orphans global lock to prevent lvmetad from being modified when pvscan --cache is executed

PATCH New Wu Guanghao 1 participant 1 message Aug 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pvscan: Increase orphans global lock to prevent lvmetad from being modified when pvscan --cache is executed

Hi,

Appeared by accident during the test,the metadata of the disk is inconsistent with the data saved by lvmetad.

start pvscan --cache x:x (read metadata from disk, no vg info)
pvcreate /dev/sdb
vgcreate vg /dev/sdb
(write vg information to metadata, and update lvmetad)

finish pvscan --cache x:x (No vg information in metadata,overwrite lvmetad)

# vgs
couldn't find vg
---
 tools/pvscan.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/pvscan.c +6 -0
index 2e7a864de..51b5daa9a 100644
@@ -491,6 +491,11 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
                return ECMD_FAILED;
        }
 
+       if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_READ, NULL)) {
+               log_error("Can't get lock for orphan PVs.");
+               return ECMD_FAILED;
+       }
+
        /*
         * This a special case where use_lvmetad=1 in lvm.conf but pvscan
         * cannot use lvmetad for some reason.  In this case pvscan should
@@ -780,6 +785,7 @@ out:
 
        if (!sync_local_dev_names(cmd))
                stack;
+       unlock_vg(cmd, NULL, VG_ORPHANS);
        unlock_vg(cmd, NULL, VG_GLOBAL);
        return ret;
 }

--
2.23.0