mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-01 09:47:48 +03:00
Enforce an alphabetical lock ordering for vgname locks.
Add a new constraint that vgname locks must be obtained in alphabetical order. At this point, we have test coverage for the 3 commands affected - vgsplit, vgmerge, and vgrename. Tests have been updated to cover these commands. Going forward any command or library call that must obtain more than one vgname lock must do so in alphabetical order. Future patches will update lvm2app to enforce this ordering. Author: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
parent
b40b65fb3c
commit
3de6df8410
@ -1,5 +1,7 @@
|
||||
Version 2.02.52 -
|
||||
=================================
|
||||
Enforce an alphabetical lock ordering for vgname locks.
|
||||
Refactor vgsplit, vgmerge, and vgrename to obey vgname ordering rules.
|
||||
Implement write lock prioritisation for file locking and make it default.
|
||||
Fix clogd build direcory.
|
||||
Drop unrequired clogd Makefile.
|
||||
|
39
lib/cache/lvmcache.c
vendored
39
lib/cache/lvmcache.c
vendored
@ -186,6 +186,45 @@ void lvmcache_drop_metadata(const char *vgname)
|
||||
_drop_metadata(vgname);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure vgname2 comes after vgname1 alphabetically.
|
||||
* Special VG names beginning with '#' don't count.
|
||||
*/
|
||||
static int _vgname_order_correct(const char *vgname1, const char *vgname2)
|
||||
{
|
||||
if ((*vgname1 == '#')|(*vgname2 == '#'))
|
||||
return 1;
|
||||
|
||||
if (strcmp(vgname1, vgname2) < 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure VG locks are acquired in alphabetical order.
|
||||
*/
|
||||
int lvmcache_verify_lock_order(const char *vgname)
|
||||
{
|
||||
struct dm_hash_node *n;
|
||||
const char *vgname2;
|
||||
|
||||
if (!_lock_hash)
|
||||
return_0;
|
||||
|
||||
dm_hash_iterate(n, _lock_hash) {
|
||||
if (!dm_hash_get_data(_lock_hash, n))
|
||||
return_0;
|
||||
vgname2 = dm_hash_get_key(_lock_hash, n);
|
||||
if (!_vgname_order_correct(vgname2, vgname)) {
|
||||
log_errno(EDEADLK, "Internal error: VG lock %s must "
|
||||
"be requested before %s, not after.",
|
||||
vgname, vgname2);
|
||||
return_0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void lvmcache_lock_vgname(const char *vgname, int read_only __attribute((unused)))
|
||||
{
|
||||
if (!_lock_hash && !lvmcache_init()) {
|
||||
|
1
lib/cache/lvmcache.h
vendored
1
lib/cache/lvmcache.h
vendored
@ -84,6 +84,7 @@ int lvmcache_update_vg(struct volume_group *vg, unsigned precommitted);
|
||||
|
||||
void lvmcache_lock_vgname(const char *vgname, int read_only);
|
||||
void lvmcache_unlock_vgname(const char *vgname);
|
||||
int lvmcache_verify_lock_order(const char *vgname);
|
||||
|
||||
/* Queries */
|
||||
const struct format_type *fmt_from_vgname(const char *vgname, const char *vgid);
|
||||
|
@ -387,6 +387,12 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags)
|
||||
if (!_blocking_supported || vgs_locked())
|
||||
flags |= LCK_NONBLOCK;
|
||||
|
||||
if (vol[0] != '#' &&
|
||||
((flags & LCK_TYPE_MASK) != LCK_UNLOCK) &&
|
||||
(!(flags & LCK_CACHE)) &&
|
||||
!lvmcache_verify_lock_order(vol))
|
||||
return 0;
|
||||
|
||||
/* Lock VG to change on-disk metadata. */
|
||||
/* If LVM1 driver knows about the VG, it can't be accessed. */
|
||||
if (!check_lvm1_vg_inactive(cmd, vol))
|
||||
|
@ -34,6 +34,8 @@ int remote_lock_held(const char *vol);
|
||||
* Use VG_GLOBAL as a global lock and to wipe the internal cache.
|
||||
* char *vol holds volume group name.
|
||||
* Set the LCK_CACHE flag to invalidate 'vol' in the internal cache.
|
||||
* If more than one lock needs to be held simultaneously, they must be
|
||||
* acquired in alphabetical order of 'vol' (to avoid deadlocks).
|
||||
*
|
||||
* LCK_LV:
|
||||
* Lock/unlock an individual logical volume
|
||||
|
Loading…
x
Reference in New Issue
Block a user