static struct dm_hash_table *_pvid_hash = NULL;
static struct dm_hash_table *_vgid_hash = NULL;
static struct dm_hash_table *_vgname_hash = NULL;
-static struct dm_hash_table *_lock_hash = NULL;
static DM_LIST_INIT(_vginfos);
static DM_LIST_INIT(_found_duplicate_devs);
static DM_LIST_INIT(_unused_duplicate_devs);
static int _scanning_in_progress = 0;
static int _has_scanned = 0;
static int _vgs_locked = 0;
-static int _vg_global_lock_held = 0; /* Global lock held when cache wiped? */
static int _found_duplicate_pvs = 0; /* If we never see a duplicate PV we can skip checking for them later. */
int lvmcache_init(struct cmd_context *cmd)
if (!(_pvid_hash = dm_hash_create(128)))
return 0;
- if (!(_lock_hash = dm_hash_create(128)))
- return 0;
-
- /*
- * Reinitialising the cache clears the internal record of
- * which locks are held. The global lock can be held during
- * this operation so its state must be restored afterwards.
- */
- if (_vg_global_lock_held) {
- lvmcache_lock_vgname(VG_GLOBAL, 0);
- _vg_global_lock_held = 0;
- }
-
return 1;
}
void lvmcache_lock_vgname(const char *vgname, int read_only __attribute__((unused)))
{
- if (dm_hash_lookup(_lock_hash, vgname))
- log_error(INTERNAL_ERROR "Nested locking attempted on VG %s.",
- vgname);
-
- if (!dm_hash_insert(_lock_hash, vgname, (void *) 1))
- log_error("Cache locking failure for %s", vgname);
-
if (strcmp(vgname, VG_GLOBAL))
_vgs_locked++;
}
void lvmcache_unlock_vgname(const char *vgname)
{
- if (!dm_hash_lookup(_lock_hash, vgname))
- log_error(INTERNAL_ERROR "Attempt to unlock unlocked VG %s.",
- vgname);
-
- dm_hash_remove(_lock_hash, vgname);
-
/* FIXME Do this per-VG */
if (strcmp(vgname, VG_GLOBAL) && !--_vgs_locked) {
dev_size_seqno_inc(); /* invalidate all cached dev sizes */
} while ((vginfo = next));
}
-static void _lvmcache_destroy_lockname(struct dm_hash_node *n)
-{
- char *vgname;
-
- if (!dm_hash_get_data(_lock_hash, n))
- return;
-
- vgname = dm_hash_get_key(_lock_hash, n);
-
- if (!strcmp(vgname, VG_GLOBAL))
- _vg_global_lock_held = 1;
- else
- log_error(INTERNAL_ERROR "Volume Group %s was not unlocked",
- dm_hash_get_key(_lock_hash, n));
-}
-
void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
{
- struct dm_hash_node *n;
-
log_debug_cache("Dropping VG info");
_has_scanned = 0;
_vgname_hash = NULL;
}
- if (_lock_hash) {
- if (reset)
- _vg_global_lock_held = 0;
- else
- dm_hash_iterate(n, _lock_hash)
- _lvmcache_destroy_lockname(n);
- dm_hash_destroy(_lock_hash);
- _lock_hash = NULL;
- }
-
if (!dm_list_empty(&_vginfos))
log_error(INTERNAL_ERROR "_vginfos list should be empty");
dm_list_init(&_vginfos);