1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00
lvm2/tools
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
..
.exported_symbols generate liblvm2cmd exported symbols too 2010-06-25 18:23:10 +00:00
.gitignore tools: add generated headers to .gitignore 2017-03-10 13:13:41 +00:00
args.h Use "cachevol" to refer to cache on a single LV 2019-02-27 08:52:34 -06:00
cmdnames.h doc: change fsf address 2016-01-21 12:11:37 +01:00
command-lines.in vdo: enable caching for vdopool LV and vdo LV 2019-03-20 14:38:31 +01:00
command.c add device hints to reduce scanning 2019-01-15 10:23:47 -06:00
command.h cleanup: fix some typos 2017-07-10 14:58:33 +02:00
commands.h add device hints to reduce scanning 2019-01-15 10:23:47 -06:00
dumpconfig.c lvmconfig: Add options to produce file preamble 2017-08-05 16:23:34 +01:00
errors.h tools: Introduce exit code EINIT_FAILED. 2017-07-26 23:18:03 +01:00
formats.c doc: change fsf address 2016-01-21 12:11:37 +01:00
license.inc pre-release 2017-03-28 16:11:35 +01:00
lv_props.h commands: new method for defining commands 2017-02-13 08:20:10 -06:00
lv_types.h Add dm-writecache support 2018-11-06 14:18:41 -06:00
lvchange.c vdo: enable caching for vdopool LV and vdo LV 2019-03-20 14:38:31 +01:00
lvconvert_poll.c debug: more display_lvname usage 2017-06-27 08:28:36 +02:00
lvconvert_poll.h build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
lvconvert.c vdo: enable caching for vdopool LV and vdo LV 2019-03-20 14:38:31 +01:00
lvcreate.c vdo: complete matching with thin syntax 2019-01-28 22:18:17 +01:00
lvdisplay.c process_each_lv: add check_single_lv function 2017-02-13 08:20:10 -06:00
lvextend.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm2cmd-static.c build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
lvm2cmd.c build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
lvm2cmd.h tools: Introduce exit code EINIT_FAILED. 2017-07-26 23:18:03 +01:00
lvm2cmdline.h commands: fix memory debug for cmd defs 2017-05-01 15:27:14 -05:00
lvm-static.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvm.c debug: tracing error path 2017-06-27 00:27:36 +02:00
lvmcmdlib.c dmeventd: lvm vdo support 2018-07-09 15:29:16 +02:00
lvmcmdline.c pvscan: don't print warning about lvmlockd not running 2019-04-05 14:04:42 -05:00
lvmdiskscan.c remove unused full filter 2018-12-04 14:06:46 -06:00
lvpoll.c build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
lvreduce.c doc: change fsf address 2016-01-21 12:11:37 +01:00
lvremove.c process_each_lv: add check_single_lv function 2017-02-13 08:20:10 -06:00
lvrename.c toollib: make it possible to also process internal VGs, add 'include_internal' switch to process_each_vg fn 2016-06-20 11:33:42 +02:00
lvresize.c lvextend: refresh shared LV remotely using dlm/corosync 2019-03-21 12:38:20 -05:00
lvscan.c Remove lvmetad 2018-07-11 11:26:42 -05:00
Makefile.in makefile: fixes build for older system 2018-12-17 11:41:38 +01:00
polldaemon.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
pvchange.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
pvck.c Add cmd arg to more functions 2018-06-15 11:03:55 -05:00
pvcreate.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
pvdisplay.c add device hints to reduce scanning 2019-01-15 10:23:47 -06:00
pvmove_poll.c pvmove: move code from tools to lib 2017-12-01 12:18:32 +01:00
pvmove_poll.h doc: change fsf address 2016-01-21 12:11:37 +01:00
pvmove.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
pvremove.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
pvresize.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
pvscan.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
reporter.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
segtypes.c doc: change fsf address 2016-01-21 12:11:37 +01:00
stub.h Remove vgconvert 2018-06-13 14:14:03 -05:00
tags.c doc: change fsf address 2016-01-21 12:11:37 +01:00
tool.h configure: avoid repeative inclusion of configure.h 2018-12-21 19:19:50 +01:00
toollib.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
toollib.h build: Don't generate symlinks in include/ dir 2018-05-14 10:30:20 +01:00
tools.h Use "cachevol" to refer to cache on a single LV 2019-02-27 08:52:34 -06:00
vals.h vdo: document types vdo and vdo-pool 2019-01-28 22:39:10 +01:00
vgcfgbackup.c device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
vgcfgrestore.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgchange.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgck.c Remove lvmetad 2018-07-11 11:26:42 -05:00
vgcreate.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgdisplay.c tidy: Add missing underscores to statics. 2017-10-18 15:58:13 +01:00
vgexport.c lvmlockd: primarily use vg_is_shared 2018-06-01 13:15:22 -05:00
vgextend.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgimport.c Remove lvmetad 2018-07-11 11:26:42 -05:00
vgimportclone.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgmerge.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgmknodes.c process_each_lv: add check_single_lv function 2017-02-13 08:20:10 -06:00
vgreduce.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgremove.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgrename.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgscan.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00
vgsplit.c locking: unify global lock for flock and lockd 2019-04-29 13:01:05 -05:00