1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

Tidy lv_hash[_lock] use inside clvmd.

- Rename unlock_all to destroy_lvhash,
this function is called in cluster shutdown
unlocks everything and clean up allocated info space.

 - Tidy lv_hash_lock use
.
Except adding free(lvi) in lv_has destructror
there is no functional change.
This commit is contained in:
Milan Broz 2009-04-21 13:11:28 +00:00
parent d66abfb82a
commit c4ff133840
7 changed files with 69 additions and 39 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.46 - Version 2.02.46 -
================================ ================================
Tidy clvmd volume lock cache functions.
Fix pvs report for orphan PVs when segment attributes are requested. Fix pvs report for orphan PVs when segment attributes are requested.
Fix pvs -a output to not read volume groups from non-PV devices. Fix pvs -a output to not read volume groups from non-PV devices.
Add MMC (mmcblk) device type to filters. Add MMC (mmcblk) device type to filters.

View File

@ -263,7 +263,7 @@ static void _add_up_node(const char *csid)
static void _cluster_closedown() static void _cluster_closedown()
{ {
unlock_all(); destroy_lvhash();
dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1); dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1);
cman_finish(c_handle); cman_finish(c_handle);
} }

View File

@ -359,7 +359,7 @@ static int _init_cluster(void)
static void _cluster_closedown(void) static void _cluster_closedown(void)
{ {
DEBUGLOG("cluster_closedown\n"); DEBUGLOG("cluster_closedown\n");
unlock_all(); destroy_lvhash();
dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1); dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1);
cpg_finalize(cpg_handle); cpg_finalize(cpg_handle);

View File

@ -248,7 +248,7 @@ static void _cluster_closedown(void)
{ {
DEBUGLOG("cluster_closedown\n"); DEBUGLOG("cluster_closedown\n");
in_shutdown = 1; in_shutdown = 1;
unlock_all(); destroy_lvhash();
lg_lock_logout(gulm_if); lg_lock_logout(gulm_if);
lg_core_logout(gulm_if); lg_core_logout(gulm_if);
lg_release(gulm_if); lg_release(gulm_if);

View File

@ -382,7 +382,7 @@ static int _init_cluster(void)
static void _cluster_closedown(void) static void _cluster_closedown(void)
{ {
DEBUGLOG("cluster_closedown\n"); DEBUGLOG("cluster_closedown\n");
unlock_all(); destroy_lvhash();
saLckFinalize(lck_handle); saLckFinalize(lck_handle);
cpg_finalize(cpg_handle); cpg_finalize(cpg_handle);

View File

@ -157,32 +157,79 @@ char *get_last_lvm_error()
return last_error; return last_error;
} }
/* Return the mode a lock is currently held at (or -1 if not held) */ /*
static int get_current_lock(char *resource) * Hash lock info helpers
*/
static struct lv_info *lookup_info(const char *resource)
{ {
struct lv_info *lvi; struct lv_info *lvi;
pthread_mutex_lock(&lv_hash_lock); pthread_mutex_lock(&lv_hash_lock);
lvi = dm_hash_lookup(lv_hash, resource); lvi = dm_hash_lookup(lv_hash, resource);
pthread_mutex_unlock(&lv_hash_lock); pthread_mutex_unlock(&lv_hash_lock);
if (lvi) {
return lvi;
}
static void insert_info(const char *resource, struct lv_info *lvi)
{
pthread_mutex_lock(&lv_hash_lock);
dm_hash_insert(lv_hash, resource, lvi);
pthread_mutex_unlock(&lv_hash_lock);
}
static void remove_info(const char *resource)
{
pthread_mutex_lock(&lv_hash_lock);
dm_hash_remove(lv_hash, resource);
pthread_mutex_unlock(&lv_hash_lock);
}
/*
* Return the mode a lock is currently held at (or -1 if not held)
*/
static int get_current_lock(char *resource)
{
struct lv_info *lvi;
if ((lvi = lookup_info(resource)))
return lvi->lock_mode; return lvi->lock_mode;
} else {
return -1; return -1;
} }
void init_lvhash()
{
/* Create hash table for keeping LV locks & status */
lv_hash = dm_hash_create(100);
pthread_mutex_init(&lv_hash_lock, NULL);
pthread_mutex_init(&lvm_lock, NULL);
} }
/* Called at shutdown to tidy the lockspace */ /* Called at shutdown to tidy the lockspace */
void unlock_all() void destroy_lvhash()
{ {
struct dm_hash_node *v; struct dm_hash_node *v;
struct lv_info *lvi;
char *resource;
int status;
pthread_mutex_lock(&lv_hash_lock); pthread_mutex_lock(&lv_hash_lock);
dm_hash_iterate(v, lv_hash) {
struct lv_info *lvi = dm_hash_get_data(lv_hash, v);
sync_unlock(dm_hash_get_key(lv_hash, v), lvi->lock_id); dm_hash_iterate(v, lv_hash) {
lvi = dm_hash_get_data(lv_hash, v);
resource = dm_hash_get_key(lv_hash, v);
if ((status = sync_unlock(resource, lvi->lock_id)))
DEBUGLOG("unlock_all. unlock failed(%d): %s\n",
status, strerror(errno));
free(lvi);
} }
dm_hash_destroy(lv_hash);
lv_hash = NULL;
pthread_mutex_unlock(&lv_hash_lock); pthread_mutex_unlock(&lv_hash_lock);
} }
@ -195,10 +242,7 @@ int hold_lock(char *resource, int mode, int flags)
flags &= LKF_NOQUEUE; /* Only LKF_NOQUEUE is valid here */ flags &= LKF_NOQUEUE; /* Only LKF_NOQUEUE is valid here */
pthread_mutex_lock(&lv_hash_lock); if ((lvi = lookup_info(resource))) {
lvi = dm_hash_lookup(lv_hash, resource);
pthread_mutex_unlock(&lv_hash_lock);
if (lvi) {
/* Already exists - convert it */ /* Already exists - convert it */
status = status =
sync_lock(resource, mode, LKF_CONVERT | flags, sync_lock(resource, mode, LKF_CONVERT | flags,
@ -224,11 +268,9 @@ int hold_lock(char *resource, int mode, int flags)
free(lvi); free(lvi);
DEBUGLOG("hold_lock. lock at %d failed: %s\n", mode, DEBUGLOG("hold_lock. lock at %d failed: %s\n", mode,
strerror(errno)); strerror(errno));
} else { } else
pthread_mutex_lock(&lv_hash_lock); insert_info(resource, lvi);
dm_hash_insert(lv_hash, resource, lvi);
pthread_mutex_unlock(&lv_hash_lock);
}
errno = saved_errno; errno = saved_errno;
} }
return status; return status;
@ -241,10 +283,7 @@ int hold_unlock(char *resource)
int status; int status;
int saved_errno; int saved_errno;
pthread_mutex_lock(&lv_hash_lock); if (!(lvi = lookup_info(resource))) {
lvi = dm_hash_lookup(lv_hash, resource);
pthread_mutex_unlock(&lv_hash_lock);
if (!lvi) {
DEBUGLOG("hold_unlock, lock not already held\n"); DEBUGLOG("hold_unlock, lock not already held\n");
return 0; return 0;
} }
@ -252,9 +291,7 @@ int hold_unlock(char *resource)
status = sync_unlock(resource, lvi->lock_id); status = sync_unlock(resource, lvi->lock_id);
saved_errno = errno; saved_errno = errno;
if (!status) { if (!status) {
pthread_mutex_lock(&lv_hash_lock); remove_info(resource);
dm_hash_remove(lv_hash, resource);
pthread_mutex_unlock(&lv_hash_lock);
free(lvi); free(lvi);
} else { } else {
DEBUGLOG("hold_unlock. unlock failed(%d): %s\n", status, DEBUGLOG("hold_unlock. unlock failed(%d): %s\n", status,
@ -699,14 +736,6 @@ static void check_config()
log_error("locking_type not set correctly in lvm.conf, cluster operations will not work."); log_error("locking_type not set correctly in lvm.conf, cluster operations will not work.");
} }
void init_lvhash()
{
/* Create hash table for keeping LV locks & status */
lv_hash = dm_hash_create(100);
pthread_mutex_init(&lv_hash_lock, NULL);
pthread_mutex_init(&lvm_lock, NULL);
}
/* Backups up the LVM metadata if it's changed */ /* Backups up the LVM metadata if it's changed */
void lvm_do_backup(const char *vgname) void lvm_do_backup(const char *vgname)
{ {

View File

@ -28,10 +28,10 @@ extern int do_check_lvm1(const char *vgname);
extern int do_refresh_cache(void); extern int do_refresh_cache(void);
extern int init_lvm(int using_gulm); extern int init_lvm(int using_gulm);
extern void init_lvhash(void); extern void init_lvhash(void);
extern void destroy_lvhash(void);
extern void lvm_do_backup(const char *vgname); extern void lvm_do_backup(const char *vgname);
extern int hold_unlock(char *resource); extern int hold_unlock(char *resource);
extern int hold_lock(char *resource, int mode, int flags); extern int hold_lock(char *resource, int mode, int flags);
extern void unlock_all(void);
extern char *get_last_lvm_error(void); extern char *get_last_lvm_error(void);
extern void drop_metadata(const char *vgname); extern void drop_metadata(const char *vgname);