dlm: move rsb root_list to ls_recover() stack

Move the rsb root_list from the lockspace to a stack variable since
it is now only used by the ls_recover() function.

Signed-off-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: David Teigland <teigland@redhat.com>
This commit is contained in:
Alexander Aring 2024-04-02 15:18:01 -04:00 committed by David Teigland
parent aff46e0f24
commit 3a747f4a2e
9 changed files with 47 additions and 70 deletions

View File

@ -47,15 +47,13 @@ int dlm_dir_nodeid(struct dlm_rsb *r)
return r->res_dir_nodeid; return r->res_dir_nodeid;
} }
void dlm_recover_dir_nodeid(struct dlm_ls *ls) void dlm_recover_dir_nodeid(struct dlm_ls *ls, const struct list_head *root_list)
{ {
struct dlm_rsb *r; struct dlm_rsb *r;
down_read(&ls->ls_root_sem); list_for_each_entry(r, root_list, res_root_list) {
list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
r->res_dir_nodeid = dlm_hash2nodeid(ls, r->res_hash); r->res_dir_nodeid = dlm_hash2nodeid(ls, r->res_hash);
} }
up_read(&ls->ls_root_sem);
} }
int dlm_recover_directory(struct dlm_ls *ls, uint64_t seq) int dlm_recover_directory(struct dlm_ls *ls, uint64_t seq)

View File

@ -14,7 +14,8 @@
int dlm_dir_nodeid(struct dlm_rsb *rsb); int dlm_dir_nodeid(struct dlm_rsb *rsb);
int dlm_hash2nodeid(struct dlm_ls *ls, uint32_t hash); int dlm_hash2nodeid(struct dlm_ls *ls, uint32_t hash);
void dlm_recover_dir_nodeid(struct dlm_ls *ls); void dlm_recover_dir_nodeid(struct dlm_ls *ls,
const struct list_head *root_list);
int dlm_recover_directory(struct dlm_ls *ls, uint64_t seq); int dlm_recover_directory(struct dlm_ls *ls, uint64_t seq);
void dlm_copy_master_names(struct dlm_ls *ls, const char *inbuf, int inlen, void dlm_copy_master_names(struct dlm_ls *ls, const char *inbuf, int inlen,
char *outbuf, int outlen, int nodeid); char *outbuf, int outlen, int nodeid);

View File

@ -674,10 +674,8 @@ struct dlm_ls {
wait_queue_head_t ls_recover_lock_wait; wait_queue_head_t ls_recover_lock_wait;
spinlock_t ls_clear_proc_locks; spinlock_t ls_clear_proc_locks;
struct list_head ls_root_list; /* root resources */ struct list_head ls_masters_list; /* root resources */
struct rw_semaphore ls_root_sem; /* protect root_list */ rwlock_t ls_masters_lock; /* protect root_list */
struct list_head ls_masters_list; /* root resources */
rwlock_t ls_masters_lock; /* protect root_list */
const struct dlm_lockspace_ops *ls_ops; const struct dlm_lockspace_ops *ls_ops;
void *ls_ops_arg; void *ls_ops_arg;

View File

@ -5227,7 +5227,7 @@ static void purge_dead_list(struct dlm_ls *ls, struct dlm_rsb *r,
/* Get rid of locks held by nodes that are gone. */ /* Get rid of locks held by nodes that are gone. */
void dlm_recover_purge(struct dlm_ls *ls) void dlm_recover_purge(struct dlm_ls *ls, const struct list_head *root_list)
{ {
struct dlm_rsb *r; struct dlm_rsb *r;
struct dlm_member *memb; struct dlm_member *memb;
@ -5246,8 +5246,7 @@ void dlm_recover_purge(struct dlm_ls *ls)
if (!nodes_count) if (!nodes_count)
return; return;
down_write(&ls->ls_root_sem); list_for_each_entry(r, root_list, res_root_list) {
list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
hold_rsb(r); hold_rsb(r);
lock_rsb(r); lock_rsb(r);
if (is_master(r)) { if (is_master(r)) {
@ -5262,7 +5261,6 @@ void dlm_recover_purge(struct dlm_ls *ls)
unhold_rsb(r); unhold_rsb(r);
cond_resched(); cond_resched();
} }
up_write(&ls->ls_root_sem);
if (lkb_count) if (lkb_count)
log_rinfo(ls, "dlm_recover_purge %u locks for %u nodes", log_rinfo(ls, "dlm_recover_purge %u locks for %u nodes",

View File

@ -31,7 +31,7 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,
int dlm_search_rsb_tree(struct rb_root *tree, const void *name, int len, int dlm_search_rsb_tree(struct rb_root *tree, const void *name, int len,
struct dlm_rsb **r_ret); struct dlm_rsb **r_ret);
void dlm_recover_purge(struct dlm_ls *ls); void dlm_recover_purge(struct dlm_ls *ls, const struct list_head *root_list);
void dlm_purge_mstcpy_locks(struct dlm_rsb *r); void dlm_purge_mstcpy_locks(struct dlm_rsb *r);
void dlm_recover_grant(struct dlm_ls *ls); void dlm_recover_grant(struct dlm_ls *ls);
int dlm_recover_waiters_post(struct dlm_ls *ls); int dlm_recover_waiters_post(struct dlm_ls *ls);

View File

@ -580,8 +580,6 @@ static int new_lockspace(const char *name, const char *cluster,
ls->ls_recover_list_count = 0; ls->ls_recover_list_count = 0;
ls->ls_local_handle = ls; ls->ls_local_handle = ls;
init_waitqueue_head(&ls->ls_wait_general); init_waitqueue_head(&ls->ls_wait_general);
INIT_LIST_HEAD(&ls->ls_root_list);
init_rwsem(&ls->ls_root_sem);
INIT_LIST_HEAD(&ls->ls_masters_list); INIT_LIST_HEAD(&ls->ls_masters_list);
rwlock_init(&ls->ls_masters_lock); rwlock_init(&ls->ls_masters_lock);

View File

@ -519,7 +519,8 @@ static int recover_master_static(struct dlm_rsb *r, unsigned int *count)
* the correct dir node. * the correct dir node.
*/ */
int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq) int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq,
const struct list_head *root_list)
{ {
struct dlm_rsb *r; struct dlm_rsb *r;
unsigned int total = 0; unsigned int total = 0;
@ -529,10 +530,8 @@ int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq)
log_rinfo(ls, "dlm_recover_masters"); log_rinfo(ls, "dlm_recover_masters");
down_read(&ls->ls_root_sem); list_for_each_entry(r, root_list, res_root_list) {
list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
if (dlm_recovery_stopped(ls)) { if (dlm_recovery_stopped(ls)) {
up_read(&ls->ls_root_sem);
error = -EINTR; error = -EINTR;
goto out; goto out;
} }
@ -546,12 +545,9 @@ int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq)
cond_resched(); cond_resched();
total++; total++;
if (error) { if (error)
up_read(&ls->ls_root_sem);
goto out; goto out;
}
} }
up_read(&ls->ls_root_sem);
log_rinfo(ls, "dlm_recover_masters %u of %u", count, total); log_rinfo(ls, "dlm_recover_masters %u of %u", count, total);
@ -656,13 +652,13 @@ static int recover_locks(struct dlm_rsb *r, uint64_t seq)
return error; return error;
} }
int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq) int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq,
const struct list_head *root_list)
{ {
struct dlm_rsb *r; struct dlm_rsb *r;
int error, count = 0; int error, count = 0;
down_read(&ls->ls_root_sem); list_for_each_entry(r, root_list, res_root_list) {
list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
if (is_master(r)) { if (is_master(r)) {
rsb_clear_flag(r, RSB_NEW_MASTER); rsb_clear_flag(r, RSB_NEW_MASTER);
continue; continue;
@ -673,19 +669,15 @@ int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq)
if (dlm_recovery_stopped(ls)) { if (dlm_recovery_stopped(ls)) {
error = -EINTR; error = -EINTR;
up_read(&ls->ls_root_sem);
goto out; goto out;
} }
error = recover_locks(r, seq); error = recover_locks(r, seq);
if (error) { if (error)
up_read(&ls->ls_root_sem);
goto out; goto out;
}
count += r->res_recover_locks_count; count += r->res_recover_locks_count;
} }
up_read(&ls->ls_root_sem);
log_rinfo(ls, "dlm_recover_locks %d out", count); log_rinfo(ls, "dlm_recover_locks %d out", count);
@ -854,13 +846,12 @@ static void recover_grant(struct dlm_rsb *r)
rsb_set_flag(r, RSB_RECOVER_GRANT); rsb_set_flag(r, RSB_RECOVER_GRANT);
} }
void dlm_recover_rsbs(struct dlm_ls *ls) void dlm_recover_rsbs(struct dlm_ls *ls, const struct list_head *root_list)
{ {
struct dlm_rsb *r; struct dlm_rsb *r;
unsigned int count = 0; unsigned int count = 0;
down_read(&ls->ls_root_sem); list_for_each_entry(r, root_list, res_root_list) {
list_for_each_entry(r, &ls->ls_root_list, res_root_list) {
lock_rsb(r); lock_rsb(r);
if (is_master(r)) { if (is_master(r)) {
if (rsb_flag(r, RSB_RECOVER_CONVERT)) if (rsb_flag(r, RSB_RECOVER_CONVERT))
@ -881,7 +872,6 @@ void dlm_recover_rsbs(struct dlm_ls *ls)
rsb_clear_flag(r, RSB_NEW_MASTER2); rsb_clear_flag(r, RSB_NEW_MASTER2);
unlock_rsb(r); unlock_rsb(r);
} }
up_read(&ls->ls_root_sem);
if (count) if (count)
log_rinfo(ls, "dlm_recover_rsbs %d done", count); log_rinfo(ls, "dlm_recover_rsbs %d done", count);

View File

@ -19,12 +19,14 @@ int dlm_recover_members_wait(struct dlm_ls *ls, uint64_t seq);
int dlm_recover_directory_wait(struct dlm_ls *ls, uint64_t seq); int dlm_recover_directory_wait(struct dlm_ls *ls, uint64_t seq);
int dlm_recover_locks_wait(struct dlm_ls *ls, uint64_t seq); int dlm_recover_locks_wait(struct dlm_ls *ls, uint64_t seq);
int dlm_recover_done_wait(struct dlm_ls *ls, uint64_t seq); int dlm_recover_done_wait(struct dlm_ls *ls, uint64_t seq);
int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq); int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq,
const struct list_head *root_list);
int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc); int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc);
int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq); int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq,
const struct list_head *root_list);
void dlm_recovered_lock(struct dlm_rsb *r); void dlm_recovered_lock(struct dlm_rsb *r);
void dlm_clear_toss(struct dlm_ls *ls); void dlm_clear_toss(struct dlm_ls *ls);
void dlm_recover_rsbs(struct dlm_ls *ls); void dlm_recover_rsbs(struct dlm_ls *ls, const struct list_head *root_list);
#endif /* __RECOVER_DOT_H__ */ #endif /* __RECOVER_DOT_H__ */

View File

@ -62,23 +62,17 @@ static void dlm_release_masters_list(struct dlm_ls *ls)
write_unlock(&ls->ls_masters_lock); write_unlock(&ls->ls_masters_lock);
} }
static void dlm_create_root_list(struct dlm_ls *ls) static void dlm_create_root_list(struct dlm_ls *ls, struct list_head *root_list)
{ {
struct rb_node *n; struct rb_node *n;
struct dlm_rsb *r; struct dlm_rsb *r;
int i; int i;
down_write(&ls->ls_root_sem);
if (!list_empty(&ls->ls_root_list)) {
log_error(ls, "root list not empty");
goto out;
}
for (i = 0; i < ls->ls_rsbtbl_size; i++) { for (i = 0; i < ls->ls_rsbtbl_size; i++) {
spin_lock_bh(&ls->ls_rsbtbl[i].lock); spin_lock_bh(&ls->ls_rsbtbl[i].lock);
for (n = rb_first(&ls->ls_rsbtbl[i].keep); n; n = rb_next(n)) { for (n = rb_first(&ls->ls_rsbtbl[i].keep); n; n = rb_next(n)) {
r = rb_entry(n, struct dlm_rsb, res_hashnode); r = rb_entry(n, struct dlm_rsb, res_hashnode);
list_add(&r->res_root_list, &ls->ls_root_list); list_add(&r->res_root_list, root_list);
dlm_hold_rsb(r); dlm_hold_rsb(r);
} }
@ -86,20 +80,16 @@ static void dlm_create_root_list(struct dlm_ls *ls)
log_error(ls, "%s toss not empty", __func__); log_error(ls, "%s toss not empty", __func__);
spin_unlock_bh(&ls->ls_rsbtbl[i].lock); spin_unlock_bh(&ls->ls_rsbtbl[i].lock);
} }
out:
up_write(&ls->ls_root_sem);
} }
static void dlm_release_root_list(struct dlm_ls *ls) static void dlm_release_root_list(struct list_head *root_list)
{ {
struct dlm_rsb *r, *safe; struct dlm_rsb *r, *safe;
down_write(&ls->ls_root_sem); list_for_each_entry_safe(r, safe, root_list, res_root_list) {
list_for_each_entry_safe(r, safe, &ls->ls_root_list, res_root_list) {
list_del_init(&r->res_root_list); list_del_init(&r->res_root_list);
dlm_put_rsb(r); dlm_put_rsb(r);
} }
up_write(&ls->ls_root_sem);
} }
/* If the start for which we're re-enabling locking (seq) has been superseded /* If the start for which we're re-enabling locking (seq) has been superseded
@ -131,6 +121,7 @@ static int enable_locking(struct dlm_ls *ls, uint64_t seq)
static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv) static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
{ {
LIST_HEAD(root_list);
unsigned long start; unsigned long start;
int error, neg = 0; int error, neg = 0;
@ -147,7 +138,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
* routines. * routines.
*/ */
dlm_create_root_list(ls); dlm_create_root_list(ls, &root_list);
/* /*
* Add or remove nodes from the lockspace's ls_nodes list. * Add or remove nodes from the lockspace's ls_nodes list.
@ -163,7 +154,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
goto fail; goto fail;
} }
dlm_recover_dir_nodeid(ls); dlm_recover_dir_nodeid(ls, &root_list);
/* Create a snapshot of all active rsbs were we are the master of. /* Create a snapshot of all active rsbs were we are the master of.
* During the barrier between dlm_recover_members_wait() and * During the barrier between dlm_recover_members_wait() and
@ -179,7 +170,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
error = dlm_create_masters_list(ls); error = dlm_create_masters_list(ls);
if (error) { if (error) {
log_rinfo(ls, "dlm_create_masters_list error %d", error); log_rinfo(ls, "dlm_create_masters_list error %d", error);
goto fail; goto fail_root_list;
} }
ls->ls_recover_dir_sent_res = 0; ls->ls_recover_dir_sent_res = 0;
@ -192,7 +183,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
if (error) { if (error) {
log_rinfo(ls, "dlm_recover_members_wait error %d", error); log_rinfo(ls, "dlm_recover_members_wait error %d", error);
dlm_release_masters_list(ls); dlm_release_masters_list(ls);
goto fail; goto fail_root_list;
} }
start = jiffies; start = jiffies;
@ -206,7 +197,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
if (error) { if (error) {
log_rinfo(ls, "dlm_recover_directory error %d", error); log_rinfo(ls, "dlm_recover_directory error %d", error);
dlm_release_masters_list(ls); dlm_release_masters_list(ls);
goto fail; goto fail_root_list;
} }
dlm_set_recover_status(ls, DLM_RS_DIR); dlm_set_recover_status(ls, DLM_RS_DIR);
@ -215,7 +206,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
if (error) { if (error) {
log_rinfo(ls, "dlm_recover_directory_wait error %d", error); log_rinfo(ls, "dlm_recover_directory_wait error %d", error);
dlm_release_masters_list(ls); dlm_release_masters_list(ls);
goto fail; goto fail_root_list;
} }
dlm_release_masters_list(ls); dlm_release_masters_list(ls);
@ -233,7 +224,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
if (dlm_recovery_stopped(ls)) { if (dlm_recovery_stopped(ls)) {
error = -EINTR; error = -EINTR;
goto fail; goto fail_root_list;
} }
if (neg || dlm_no_directory(ls)) { if (neg || dlm_no_directory(ls)) {
@ -241,27 +232,27 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
* Clear lkb's for departed nodes. * Clear lkb's for departed nodes.
*/ */
dlm_recover_purge(ls); dlm_recover_purge(ls, &root_list);
/* /*
* Get new master nodeid's for rsb's that were mastered on * Get new master nodeid's for rsb's that were mastered on
* departed nodes. * departed nodes.
*/ */
error = dlm_recover_masters(ls, rv->seq); error = dlm_recover_masters(ls, rv->seq, &root_list);
if (error) { if (error) {
log_rinfo(ls, "dlm_recover_masters error %d", error); log_rinfo(ls, "dlm_recover_masters error %d", error);
goto fail; goto fail_root_list;
} }
/* /*
* Send our locks on remastered rsb's to the new masters. * Send our locks on remastered rsb's to the new masters.
*/ */
error = dlm_recover_locks(ls, rv->seq); error = dlm_recover_locks(ls, rv->seq, &root_list);
if (error) { if (error) {
log_rinfo(ls, "dlm_recover_locks error %d", error); log_rinfo(ls, "dlm_recover_locks error %d", error);
goto fail; goto fail_root_list;
} }
dlm_set_recover_status(ls, DLM_RS_LOCKS); dlm_set_recover_status(ls, DLM_RS_LOCKS);
@ -269,7 +260,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
error = dlm_recover_locks_wait(ls, rv->seq); error = dlm_recover_locks_wait(ls, rv->seq);
if (error) { if (error) {
log_rinfo(ls, "dlm_recover_locks_wait error %d", error); log_rinfo(ls, "dlm_recover_locks_wait error %d", error);
goto fail; goto fail_root_list;
} }
log_rinfo(ls, "dlm_recover_locks %u in", log_rinfo(ls, "dlm_recover_locks %u in",
@ -281,7 +272,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
* settings. * settings.
*/ */
dlm_recover_rsbs(ls); dlm_recover_rsbs(ls, &root_list);
} else { } else {
/* /*
* Other lockspace members may be going through the "neg" steps * Other lockspace members may be going through the "neg" steps
@ -293,11 +284,11 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
error = dlm_recover_locks_wait(ls, rv->seq); error = dlm_recover_locks_wait(ls, rv->seq);
if (error) { if (error) {
log_rinfo(ls, "dlm_recover_locks_wait error %d", error); log_rinfo(ls, "dlm_recover_locks_wait error %d", error);
goto fail; goto fail_root_list;
} }
} }
dlm_release_root_list(ls); dlm_release_root_list(&root_list);
/* /*
* Purge directory-related requests that are saved in requestqueue. * Purge directory-related requests that are saved in requestqueue.
@ -346,8 +337,9 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv)
return 0; return 0;
fail_root_list:
dlm_release_root_list(&root_list);
fail: fail:
dlm_release_root_list(ls);
mutex_unlock(&ls->ls_recoverd_active); mutex_unlock(&ls->ls_recoverd_active);
return error; return error;