1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00
lvm2/lib
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
..
activate activation: synchronize before removing devices 2019-03-20 14:39:09 +01:00
cache locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
cache_segtype Use "cachevol" to refer to cache on a single LV 2019-02-27 08:52:34 -06:00
commands locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
config thin: max thin 2019-03-20 14:37:44 +01:00
datastruct build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
device pvscan: print more reasons for ignoring devices 2019-04-05 15:48:12 -05:00
display display: basic vdo segment lvdisplay and lvs support 2018-07-09 15:28:35 +02:00
error device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
filters filter: fix mpath test 2019-04-03 13:27:17 +02:00
format_text io: warn when metadata size approaches io memory size 2019-03-04 12:13:09 -06:00
freeseg device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
label locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
locking locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
log logging: remove unused code 2019-02-28 10:30:54 -06:00
lvmpolld device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
metadata locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
mirror lvmlockd: do not allow mirror LV to be activated shared 2019-04-04 13:21:38 -05:00
misc locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
mm memlock: extend exception list 2018-07-02 10:24:20 +02:00
notify build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
properties build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
raid Merge branch '2018-06-04-data-structs' 2018-06-08 14:21:07 +01:00
report Use "cachevol" to refer to cache on a single LV 2019-02-27 08:52:34 -06:00
snapshot Merge branch '2018-06-04-data-structs' 2018-06-08 14:21:07 +01:00
striped device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
thin Merge branch '2018-06-04-data-structs' 2018-06-08 14:21:07 +01:00
unknown device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
uuid build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
vdo vdo: fix archived metadata comment 2019-01-21 12:37:52 +01:00
writecache Add dm-writecache support 2018-11-06 14:18:41 -06:00
zero device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
Makefile.in add device hints to reduce scanning 2019-01-15 10:23:47 -06:00