1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00
lvm2/lib/metadata
David Teigland 8c87dda195 locking: unify global lock for flock and lockd
There have been two file locks used to protect lvm
"global state": "ORPHANS" and "GLOBAL".

Commands that used the ORPHAN flock in exclusive mode:
  pvcreate, pvremove, vgcreate, vgextend, vgremove,
  vgcfgrestore

Commands that used the ORPHAN flock in shared mode:
  vgimportclone, pvs, pvscan, pvresize, pvmove,
  pvdisplay, pvchange, fullreport

Commands that used the GLOBAL flock in exclusive mode:
  pvchange, pvscan, vgimportclone, vgscan

Commands that used the GLOBAL flock in shared mode:
  pvscan --cache, pvs

The ORPHAN lock covers the important cases of serializing
the use of orphan PVs.  It also partially covers the
reporting of orphan PVs (although not correctly as
explained below.)

The GLOBAL lock doesn't seem to have a clear purpose
(it may have eroded over time.)

Neither lock correctly protects the VG namespace, or
orphan PV properties.

To simplify and correct these issues, the two separate
flocks are combined into the one GLOBAL flock, and this flock
is used from the locking sites that are in place for the
lvmlockd global lock.

The logic behind the lvmlockd (distributed) global lock is
that any command that changes "global state" needs to take
the global lock in ex mode.  Global state in lvm is: the list
of VG names, the set of orphan PVs, and any properties of
orphan PVs.  Reading this global state can use the global lock
in sh mode to ensure it doesn't change while being reported.

The locking of global state now looks like:

lockd_global()
  previously named lockd_gl(), acquires the distributed
  global lock through lvmlockd.  This is unchanged.
  It serializes distributed lvm commands that are changing
  global state.  This is a no-op when lvmlockd is not in use.

lockf_global()
  acquires an flock on a local file.  It serializes local lvm
  commands that are changing global state.

lock_global()
  first calls lockf_global() to acquire the local flock for
  global state, and if this succeeds, it calls lockd_global()
  to acquire the distributed lock for global state.

Replace instances of lockd_gl() with lock_global(), so that the
existing sites for lvmlockd global state locking are now also
used for local file locking of global state.  Remove the previous
file locking calls lock_vol(GLOBAL) and lock_vol(ORPHAN).

The following commands which change global state are now
serialized with the exclusive global flock:

pvchange (of orphan), pvresize (of orphan), pvcreate, pvremove,
vgcreate, vgextend, vgremove, vgreduce, vgrename,
vgcfgrestore, vgimportclone, vgmerge, vgsplit

Commands that use a shared flock to read global state (and will
be serialized against the prior list) are those that use
process_each functions that are based on processing a list of
all VG names, or all PVs.  The list of all VGs or all PVs is
global state and the shared lock prevents those lists from
changing while the command is processing them.

The ORPHAN lock previously attempted to produce an accurate
listing of orphan PVs, but it was only acquired at the end of
the command during the fake vg_read of the fake orphan vg.
This is not when orphan PVs were determined; they were
determined by elimination beforehand by processing all real
VGs, and subtracting the PVs in the real VGs from the list
of all PVs that had been identified during the initial scan.
This is fixed by holding the single global lock in shared mode
while processing all VGs to determine the list of orphan PVs.
2019-04-29 13:01:05 -05:00
..
cache_manip.c vdo: enable caching for vdopool LV and vdo LV 2019-03-20 14:38:31 +01:00
lv_alloc.h build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
lv_manip.c wipe_lv: initially open LV in writable mode 2019-04-26 14:49:27 -05:00
lv.c Use "cachevol" to refer to cache on a single LV 2019-02-27 08:52:34 -06:00
lv.h Remove unused clvm variations for active LVs 2018-06-07 16:17:04 +01:00
merge.c Use "cachevol" to refer to cache on a single LV 2019-02-27 08:52:34 -06:00
metadata-exported.h locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
metadata.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
metadata.h thin: introduce estimate_thin_pool_metadata_size 2019-04-03 13:27:17 +02:00
mirror.c lvmlockd: do not allow mirror LV to be activated shared 2019-04-04 13:21:38 -05:00
pool_manip.c cleanup: indent 2019-01-28 22:39:10 +01:00
pv_alloc.h doc: change fsf address 2016-01-21 12:11:37 +01:00
pv_manip.c pvresize: add missing return 2018-06-08 14:36:56 +02:00
pv_map.c build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
pv_map.h build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
pv.c build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
pv.h Place the first PE at 1 MiB for all defaults 2018-11-26 16:36:50 -06:00
raid_manip.c raid: fix (de)activation of RaidLVs with visible SubLVs 2018-12-11 16:35:34 +01:00
segtype.c segtype: add linear 2018-06-05 16:23:18 +02:00
segtype.h Add dm-writecache support 2018-11-06 14:18:41 -06:00
snapshot_manip.c Remove unused clvm variations for active LVs 2018-06-07 16:17:04 +01:00
takeover_matrix.h lvconvert: add infrastructure for RaidLV reshaping support 2017-02-24 05:20:58 +01:00
thin_manip.c thin: introduce estimate_thin_pool_metadata_size 2019-04-03 13:27:17 +02:00
vdo_manip.c vdo: introduce function for estimation of virtual size 2019-01-21 12:53:16 +01:00
vg.c cov: drop uneeded header files 2018-10-15 17:49:44 +02:00
vg.h Remove lvmetad 2018-07-11 11:26:42 -05:00