1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

pvscan: use orphans lock to fix parallel pvscan and vgcreate

start pvscan --cache /dev/sdb
  (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 /dev/sdb
  (No vg information in metadata from disk, overwrite lvmetad)

vgs
couldn't find vg

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
This commit is contained in:
Wu Guanghao 2021-08-19 09:30:08 -05:00 committed by David Teigland
parent 1afa67f4b9
commit 90597a4b6e

View File

@ -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;
}