History

Merge tag 'dlm-6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm

Pull dlm updates from David Teigland: - New flag DLM_LSFL_SOFTIRQ_SAFE can be set by code using dlm to indicate callbacks can be run from softirq - Change md-cluster to set DLM_LSFL_SOFTIRQ_SAFE - Clean up for previous changes, e.g. unused code and parameters - Remove custom pre-allocation of rsb structs which is unnecessary with kmem caches - Change idr to xarray for lkb structs in use - Change idr to xarray for rsb structs being recovered - Change outdated naming related to internal rsb states - Fix some incorrect add/remove of rsb on scan list - Use rcu to free rsb structs * tag 'dlm-6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm: dlm: add rcu_barrier before destroy kmem cache dlm: remove DLM_LSFL_SOFTIRQ from exflags fs: dlm: remove unused struct 'dlm_processed_nodes' md-cluster: use DLM_LSFL_SOFTIRQ for dlm_new_lockspace() dlm: implement LSFL_SOFTIRQ_SAFE dlm: introduce DLM_LSFL_SOFTIRQ_SAFE dlm: use LSFL_FS to check for kernel lockspace dlm: use rcu to avoid an extra rsb struct lookup dlm: fix add_scan and del_scan usage dlm: change list and timer names dlm: move recover idr to xarray datastructure dlm: move lkb idr to xarray datastructure dlm: drop own rsb pre allocation mechanism dlm: remove ls_local_handle from struct dlm_ls dlm: remove unused parameter in dlm_midcomms_addr dlm: don't kref_init rsbs created for toss list dlm: remove scand leftovers

Linus Torvalds committed 2 years ago

Commit f097ef02 parents 586f14a 89b019121 files · +584 −562Browse files

Unified · Split

21 files
  1. drivers/md/md-cluster.c +1 −1
  2. fs/dlm/ast.c +111 −61
  3. fs/dlm/ast.h +5 −6
  4. fs/dlm/config.c +1 −1
  5. fs/dlm/debug_fs.c +5 −5
  6. fs/dlm/dlm_internal.h +22 −38
  7. fs/dlm/lock.c +279 −289
  8. fs/dlm/lock.h +3 −4
  9. fs/dlm/lockspace.c +58 −73
  10. fs/dlm/lowcomms.c +1 −7
  11. fs/dlm/lowcomms.h +1 −1
  12. fs/dlm/member.c +1 −1
  13. fs/dlm/memory.c +9 −1
  14. fs/dlm/midcomms.c +2 −2
  15. fs/dlm/midcomms.h +1 −1
  16. fs/dlm/recover.c +40 −38
  17. fs/dlm/recover.h +1 −1
  18. fs/dlm/recoverd.c +7 −7
  19. fs/dlm/user.c +18 −24
  20. include/linux/dlm.h +16 −1
  21. include/uapi/linux/dlm.h +2 −0
drivers/md/md-cluster.c+1−1
@@ -887,7 +887,7 @@ static int join(struct mddev *mddev, int nodes) · 886 unmodified lines
887 memset(str, 0, 64);887 memset(str, 0, 64);
888 sprintf(str, "%pU", mddev->uuid);888 sprintf(str, "%pU", mddev->uuid);
889 ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name,889 ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name,
890 0, LVB_SIZE, &md_ls_ops, mddev,890 DLM_LSFL_SOFTIRQ, LVB_SIZE, &md_ls_ops, mddev,
891 &ops_rv, &cinfo->lockspace);891 &ops_rv, &cinfo->lockspace);
892 if (ret)892 if (ret)
893 goto err;893 goto err;
fs/dlm/ast.c+111−61
@@ -18,35 +18,52 @@ · 17 unmodified lines
18#include "user.h"18#include "user.h"
19#include "ast.h"19#include "ast.h"
20 20
21static void dlm_callback_work(struct work_struct *work)21static void dlm_run_callback(uint32_t ls_id, uint32_t lkb_id, int8_t mode,
22 uint32_t flags, uint8_t sb_flags, int sb_status,
23 struct dlm_lksb *lksb,
24 void (*astfn)(void *astparam),
25 void (*bastfn)(void *astparam, int mode),
26 void *astparam, const char *res_name,
27 size_t res_length)
22{28{
23 struct dlm_callback *cb = container_of(work, struct dlm_callback, work);29 if (flags & DLM_CB_BAST) {
24 30 trace_dlm_bast(ls_id, lkb_id, mode, res_name, res_length);
25 if (cb->flags & DLM_CB_BAST) {31 bastfn(astparam, mode);
26 trace_dlm_bast(cb->ls_id, cb->lkb_id, cb->mode, cb->res_name,32 } else if (flags & DLM_CB_CAST) {
27 cb->res_length);33 trace_dlm_ast(ls_id, lkb_id, sb_status, sb_flags, res_name,
28 cb->bastfn(cb->astparam, cb->mode);34 res_length);
29 } else if (cb->flags & DLM_CB_CAST) {35 lksb->sb_status = sb_status;
30 trace_dlm_ast(cb->ls_id, cb->lkb_id, cb->sb_status,36 lksb->sb_flags = sb_flags;
31 cb->sb_flags, cb->res_name, cb->res_length);37 astfn(astparam);
32 cb->lkb_lksb->sb_status = cb->sb_status;
33 cb->lkb_lksb->sb_flags = cb->sb_flags;
34 cb->astfn(cb->astparam);
35 }38 }
39}
36 40
41static void dlm_do_callback(struct dlm_callback *cb)
42{
43 dlm_run_callback(cb->ls_id, cb->lkb_id, cb->mode, cb->flags,
44 cb->sb_flags, cb->sb_status, cb->lkb_lksb,
45 cb->astfn, cb->bastfn, cb->astparam,
46 cb->res_name, cb->res_length);
37 dlm_free_cb(cb);47 dlm_free_cb(cb);
38}48}
39 49
40int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,50static void dlm_callback_work(struct work_struct *work)
41 int status, uint32_t sbflags,51{
42 struct dlm_callback **cb)52 struct dlm_callback *cb = container_of(work, struct dlm_callback, work);
53
54 dlm_do_callback(cb);
55}
56
57bool dlm_may_skip_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
58 int status, uint32_t sbflags, int *copy_lvb)
43{59{
44 struct dlm_rsb *rsb = lkb->lkb_resource;60 struct dlm_rsb *rsb = lkb->lkb_resource;
45 int rv = DLM_ENQUEUE_CALLBACK_SUCCESS;
46 struct dlm_ls *ls = rsb->res_ls;61 struct dlm_ls *ls = rsb->res_ls;
47 int copy_lvb = 0;
48 int prev_mode;62 int prev_mode;
49 63
64 if (copy_lvb)
65 *copy_lvb = 0;
66
50 if (flags & DLM_CB_BAST) {67 if (flags & DLM_CB_BAST) {
51 /* if cb is a bast, it should be skipped if the blocking mode is68 /* if cb is a bast, it should be skipped if the blocking mode is
52 * compatible with the last granted mode69 * compatible with the last granted mode
@@ -56,7 +73,7 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode, · 3 unmodified lines
56 log_debug(ls, "skip %x bast mode %d for cast mode %d",73 log_debug(ls, "skip %x bast mode %d for cast mode %d",
57 lkb->lkb_id, mode,74 lkb->lkb_id, mode,
58 lkb->lkb_last_cast_cb_mode);75 lkb->lkb_last_cast_cb_mode);
59 goto out;76 return true;
60 }77 }
61 }78 }
62 79
@@ -74,7 +91,7 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode, · 11 unmodified lines
74 (prev_mode > mode && prev_mode > DLM_LOCK_PR)) {91 (prev_mode > mode && prev_mode > DLM_LOCK_PR)) {
75 log_debug(ls, "skip %x add bast mode %d for bast mode %d",92 log_debug(ls, "skip %x add bast mode %d for bast mode %d",
76 lkb->lkb_id, mode, prev_mode);93 lkb->lkb_id, mode, prev_mode);
77 goto out;94 return true;
78 }95 }
79 }96 }
80 97
@@ -85,8 +102,10 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode, · 4 unmodified lines
85 prev_mode = lkb->lkb_last_cast_cb_mode;102 prev_mode = lkb->lkb_last_cast_cb_mode;
86 103
87 if (!status && lkb->lkb_lksb->sb_lvbptr &&104 if (!status && lkb->lkb_lksb->sb_lvbptr &&
88 dlm_lvb_operations[prev_mode + 1][mode + 1])105 dlm_lvb_operations[prev_mode + 1][mode + 1]) {
89 copy_lvb = 1;106 if (copy_lvb)
107 *copy_lvb = 1;
108 }
90 }109 }
91 110
92 lkb->lkb_last_cast_cb_mode = mode;111 lkb->lkb_last_cast_cb_mode = mode;
@@ -96,11 +115,19 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode, · 3 unmodified lines
96 lkb->lkb_last_cb_mode = mode;115 lkb->lkb_last_cb_mode = mode;
97 lkb->lkb_last_cb_flags = flags;116 lkb->lkb_last_cb_flags = flags;
98 117
118 return false;
119}
120
121int dlm_get_cb(struct dlm_lkb *lkb, uint32_t flags, int mode,
122 int status, uint32_t sbflags,
123 struct dlm_callback **cb)
124{
125 struct dlm_rsb *rsb = lkb->lkb_resource;
126 struct dlm_ls *ls = rsb->res_ls;
127
99 *cb = dlm_allocate_cb();128 *cb = dlm_allocate_cb();
100 if (!*cb) {129 if (WARN_ON_ONCE(!*cb))
101 rv = DLM_ENQUEUE_CALLBACK_FAILURE;130 return -ENOMEM;
102 goto out;
103 }
104 131
105 /* for tracing */132 /* for tracing */
106 (*cb)->lkb_id = lkb->lkb_id;133 (*cb)->lkb_id = lkb->lkb_id;
@@ -112,19 +139,34 @@ int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode, · 5 unmodified lines
112 (*cb)->mode = mode;139 (*cb)->mode = mode;
113 (*cb)->sb_status = status;140 (*cb)->sb_status = status;
114 (*cb)->sb_flags = (sbflags & 0x000000FF);141 (*cb)->sb_flags = (sbflags & 0x000000FF);
115 (*cb)->copy_lvb = copy_lvb;
116 (*cb)->lkb_lksb = lkb->lkb_lksb;142 (*cb)->lkb_lksb = lkb->lkb_lksb;
117 143
118 rv = DLM_ENQUEUE_CALLBACK_NEED_SCHED;144 return 0;
145}
146
147static int dlm_get_queue_cb(struct dlm_lkb *lkb, uint32_t flags, int mode,
148 int status, uint32_t sbflags,
149 struct dlm_callback **cb)
150{
151 int rv;
152
153 rv = dlm_get_cb(lkb, flags, mode, status, sbflags, cb);
154 if (rv)
155 return rv;
119 156
120out:157 (*cb)->astfn = lkb->lkb_astfn;
121 return rv;158 (*cb)->bastfn = lkb->lkb_bastfn;
159 (*cb)->astparam = lkb->lkb_astparam;
160 INIT_WORK(&(*cb)->work, dlm_callback_work);
161
162 return 0;
122}163}
123 164
124void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status,165void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status,
125 uint32_t sbflags)166 uint32_t sbflags)
126{167{
127 struct dlm_ls *ls = lkb->lkb_resource->res_ls;168 struct dlm_rsb *rsb = lkb->lkb_resource;
169 struct dlm_ls *ls = rsb->res_ls;
128 struct dlm_callback *cb;170 struct dlm_callback *cb;
129 int rv;171 int rv;
130 172
@@ -133,34 +175,36 @@ void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status, · 2 unmodified lines
133 return;175 return;
134 }176 }
135 177
136 rv = dlm_queue_lkb_callback(lkb, flags, mode, status, sbflags,178 if (dlm_may_skip_callback(lkb, flags, mode, status, sbflags, NULL))
137 &cb);179 return;
138 switch (rv) {180
139 case DLM_ENQUEUE_CALLBACK_NEED_SCHED:181 spin_lock_bh(&ls->ls_cb_lock);
140 cb->astfn = lkb->lkb_astfn;182 if (test_bit(LSFL_CB_DELAY, &ls->ls_flags)) {
141 cb->bastfn = lkb->lkb_bastfn;183 rv = dlm_get_queue_cb(lkb, flags, mode, status, sbflags, &cb);
142 cb->astparam = lkb->lkb_astparam;184 if (!rv)
143 INIT_WORK(&cb->work, dlm_callback_work);
144
145 spin_lock_bh(&ls->ls_cb_lock);
146 if (test_bit(LSFL_CB_DELAY, &ls->ls_flags))
147 list_add(&cb->list, &ls->ls_cb_delay);185 list_add(&cb->list, &ls->ls_cb_delay);
148 else186 } else {
149 queue_work(ls->ls_callback_wq, &cb->work);187 if (test_bit(LSFL_SOFTIRQ, &ls->ls_flags)) {
150 spin_unlock_bh(&ls->ls_cb_lock);188 dlm_run_callback(ls->ls_global_id, lkb->lkb_id, mode, flags,
151 break;189 sbflags, status, lkb->lkb_lksb,
152 case DLM_ENQUEUE_CALLBACK_SUCCESS:190 lkb->lkb_astfn, lkb->lkb_bastfn,
153 break;191 lkb->lkb_astparam, rsb->res_name,
154 case DLM_ENQUEUE_CALLBACK_FAILURE:192 rsb->res_length);
155 fallthrough;193 } else {
156 default:194 rv = dlm_get_queue_cb(lkb, flags, mode, status, sbflags, &cb);
157 WARN_ON_ONCE(1);195 if (!rv)
158 break;196 queue_work(ls->ls_callback_wq, &cb->work);
197 }
159 }198 }
199 spin_unlock_bh(&ls->ls_cb_lock);
160}200}
161 201
162int dlm_callback_start(struct dlm_ls *ls)202int dlm_callback_start(struct dlm_ls *ls)
163{203{
204 if (!test_bit(LSFL_FS, &ls->ls_flags) ||
205 test_bit(LSFL_SOFTIRQ, &ls->ls_flags))
206 return 0;
207
164 ls->ls_callback_wq = alloc_ordered_workqueue("dlm_callback",208 ls->ls_callback_wq = alloc_ordered_workqueue("dlm_callback",
165 WQ_HIGHPRI | WQ_MEM_RECLAIM);209 WQ_HIGHPRI | WQ_MEM_RECLAIM);
166 if (!ls->ls_callback_wq) {210 if (!ls->ls_callback_wq) {
@@ -178,13 +222,15 @@ void dlm_callback_stop(struct dlm_ls *ls) · 11 unmodified lines
178 222
179void dlm_callback_suspend(struct dlm_ls *ls)223void dlm_callback_suspend(struct dlm_ls *ls)
180{224{
181 if (ls->ls_callback_wq) {225 if (!test_bit(LSFL_FS, &ls->ls_flags))
182 spin_lock_bh(&ls->ls_cb_lock);226 return;
183 set_bit(LSFL_CB_DELAY, &ls->ls_flags);227
184 spin_unlock_bh(&ls->ls_cb_lock);228 spin_lock_bh(&ls->ls_cb_lock);
229 set_bit(LSFL_CB_DELAY, &ls->ls_flags);
230 spin_unlock_bh(&ls->ls_cb_lock);
185 231
232 if (ls->ls_callback_wq)
186 flush_workqueue(ls->ls_callback_wq);233 flush_workqueue(ls->ls_callback_wq);
187 }
188}234}
189 235
190#define MAX_CB_QUEUE 25236#define MAX_CB_QUEUE 25
@@ -195,14 +241,18 @@ void dlm_callback_resume(struct dlm_ls *ls) · 4 unmodified lines
195 int count = 0, sum = 0;241 int count = 0, sum = 0;
196 bool empty;242 bool empty;
197 243
198 if (!ls->ls_callback_wq)244 if (!test_bit(LSFL_FS, &ls->ls_flags))
199 return;245 return;
200 246
201more:247more:
202 spin_lock_bh(&ls->ls_cb_lock);248 spin_lock_bh(&ls->ls_cb_lock);
203 list_for_each_entry_safe(cb, safe, &ls->ls_cb_delay, list) {249 list_for_each_entry_safe(cb, safe, &ls->ls_cb_delay, list) {
204 list_del(&cb->list);250 list_del(&cb->list);
205 queue_work(ls->ls_callback_wq, &cb->work);251 if (test_bit(LSFL_SOFTIRQ, &ls->ls_flags))
252 dlm_do_callback(cb);
253 else
254 queue_work(ls->ls_callback_wq, &cb->work);
255
206 count++;256 count++;
207 if (count == MAX_CB_QUEUE)257 if (count == MAX_CB_QUEUE)
208 break;258 break;
fs/dlm/ast.h+5−6
@@ -11,12 +11,11 @@ · 10 unmodified lines
11#ifndef __ASTD_DOT_H__11#ifndef __ASTD_DOT_H__
12#define __ASTD_DOT_H__12#define __ASTD_DOT_H__
13 13
14#define DLM_ENQUEUE_CALLBACK_NEED_SCHED 114bool dlm_may_skip_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,
15#define DLM_ENQUEUE_CALLBACK_SUCCESS 015 int status, uint32_t sbflags, int *copy_lvb);
16#define DLM_ENQUEUE_CALLBACK_FAILURE -116int dlm_get_cb(struct dlm_lkb *lkb, uint32_t flags, int mode,
17int dlm_queue_lkb_callback(struct dlm_lkb *lkb, uint32_t flags, int mode,17 int status, uint32_t sbflags,
18 int status, uint32_t sbflags,18 struct dlm_callback **cb);
19 struct dlm_callback **cb);
20void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status,19void dlm_add_cb(struct dlm_lkb *lkb, uint32_t flags, int mode, int status,
21 uint32_t sbflags);20 uint32_t sbflags);
22 21
fs/dlm/config.c+1−1
@@ -672,7 +672,7 @@ static ssize_t comm_addr_store(struct config_item *item, const char *buf, · 671 unmodified lines
672 672
673 memcpy(addr, buf, len);673 memcpy(addr, buf, len);
674 674
675 rv = dlm_midcomms_addr(cm->nodeid, addr, len);675 rv = dlm_midcomms_addr(cm->nodeid, addr);
676 if (rv) {676 if (rv) {
677 kfree(addr);677 kfree(addr);
678 return rv;678 return rv;
fs/dlm/debug_fs.c+5−5
@@ -380,7 +380,7 @@ static const struct seq_operations format4_seq_ops; · 379 unmodified lines
380 380
381static int table_seq_show(struct seq_file *seq, void *iter_ptr)381static int table_seq_show(struct seq_file *seq, void *iter_ptr)
382{382{
383 struct dlm_rsb *rsb = list_entry(iter_ptr, struct dlm_rsb, res_rsbs_list);383 struct dlm_rsb *rsb = list_entry(iter_ptr, struct dlm_rsb, res_slow_list);
384 384
385 if (seq->op == &format1_seq_ops)385 if (seq->op == &format1_seq_ops)
386 print_format1(rsb, seq);386 print_format1(rsb, seq);
@@ -409,9 +409,9 @@ static void *table_seq_start(struct seq_file *seq, loff_t *pos) · 22 unmodified lines
409 }409 }
410 410
411 if (seq->op == &format4_seq_ops)411 if (seq->op == &format4_seq_ops)
412 list = &ls->ls_toss;412 list = &ls->ls_slow_inactive;
413 else413 else
414 list = &ls->ls_keep;414 list = &ls->ls_slow_active;
415 415
416 read_lock_bh(&ls->ls_rsbtbl_lock);416 read_lock_bh(&ls->ls_rsbtbl_lock);
417 return seq_list_start(list, *pos);417 return seq_list_start(list, *pos);
@@ -423,9 +423,9 @@ static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos) · 5 unmodified lines
423 struct list_head *list;423 struct list_head *list;
424 424
425 if (seq->op == &format4_seq_ops)425 if (seq->op == &format4_seq_ops)
426 list = &ls->ls_toss;426 list = &ls->ls_slow_inactive;
427 else427 else
428 list = &ls->ls_keep;428 list = &ls->ls_slow_active;
429 429
430 return seq_list_next(iter_ptr, list, pos);430 return seq_list_next(iter_ptr, list, pos);
431}431}
fs/dlm/dlm_internal.h+22−38
@@ -36,7 +36,7 @@ · 35 unmodified lines
36#include <linux/miscdevice.h>36#include <linux/miscdevice.h>
37#include <linux/rhashtable.h>37#include <linux/rhashtable.h>
38#include <linux/mutex.h>38#include <linux/mutex.h>
39#include <linux/idr.h>39#include <linux/xarray.h>
40#include <linux/ratelimit.h>40#include <linux/ratelimit.h>
41#include <linux/uaccess.h>41#include <linux/uaccess.h>
42 42
@@ -316,26 +316,24 @@ struct dlm_rsb { · 273 unmodified lines
316 int res_nodeid;316 int res_nodeid;
317 int res_master_nodeid;317 int res_master_nodeid;
318 int res_dir_nodeid;318 int res_dir_nodeid;
319 int res_id; /* for ls_recover_idr */319 unsigned long res_id; /* for ls_recover_xa */
320 uint32_t res_lvbseq;320 uint32_t res_lvbseq;
321 uint32_t res_hash;321 uint32_t res_hash;
322 unsigned long res_toss_time;322 unsigned long res_toss_time;
323 uint32_t res_first_lkid;323 uint32_t res_first_lkid;
324 struct list_head res_lookup; /* lkbs waiting on first */324 struct list_head res_lookup; /* lkbs waiting on first */
325 union {325 struct rhash_head res_node; /* rsbtbl */
326 struct list_head res_hashchain;
327 struct rhash_head res_node; /* rsbtbl */
328 };
329 struct list_head res_grantqueue;326 struct list_head res_grantqueue;
330 struct list_head res_convertqueue;327 struct list_head res_convertqueue;
331 struct list_head res_waitqueue;328 struct list_head res_waitqueue;
332 329
333 struct list_head res_rsbs_list;330 struct list_head res_slow_list; /* ls_slow_* */
331 struct list_head res_scan_list;
334 struct list_head res_root_list; /* used for recovery */332 struct list_head res_root_list; /* used for recovery */
335 struct list_head res_masters_list; /* used for recovery */333 struct list_head res_masters_list; /* used for recovery */
336 struct list_head res_recover_list; /* used for recovery */334 struct list_head res_recover_list; /* used for recovery */
337 struct list_head res_toss_q_list;
338 int res_recover_locks_count;335 int res_recover_locks_count;
336 struct rcu_head rcu;
339 337
340 char *res_lvbptr;338 char *res_lvbptr;
341 char res_name[DLM_RESNAME_MAXLEN+1];339 char res_name[DLM_RESNAME_MAXLEN+1];
@@ -368,7 +366,8 @@ enum rsb_flags { · 26 unmodified lines
368 RSB_RECOVER_CONVERT,366 RSB_RECOVER_CONVERT,
369 RSB_RECOVER_GRANT,367 RSB_RECOVER_GRANT,
370 RSB_RECOVER_LVB_INVAL,368 RSB_RECOVER_LVB_INVAL,
371 RSB_TOSS,369 RSB_INACTIVE,
370 RSB_HASHED, /* set while rsb is on ls_rsbtbl */
372};371};
373 372
374static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag)373static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag)
@@ -559,16 +558,8 @@ struct rcom_lock { · 184 unmodified lines
559 char rl_lvb[];558 char rl_lvb[];
560};559};
561 560
562/*
563 * The max number of resources per rsbtbl bucket that shrink will attempt
564 * to remove in each iteration.
565 */
566
567#define DLM_REMOVE_NAMES_MAX 8
568
569struct dlm_ls {561struct dlm_ls {
570 struct list_head ls_list; /* list of lockspaces */562 struct list_head ls_list; /* list of lockspaces */
571 dlm_lockspace_t *ls_local_handle;
572 uint32_t ls_global_id; /* global unique lockspace ID */563 uint32_t ls_global_id; /* global unique lockspace ID */
573 uint32_t ls_generation;564 uint32_t ls_generation;
574 uint32_t ls_exflags;565 uint32_t ls_exflags;
@@ -578,26 +569,21 @@ struct dlm_ls { · 3 unmodified lines
578 wait_queue_head_t ls_count_wait;569 wait_queue_head_t ls_count_wait;
579 int ls_create_count; /* create/release refcount */570 int ls_create_count; /* create/release refcount */
580 unsigned long ls_flags; /* LSFL_ */571 unsigned long ls_flags; /* LSFL_ */
581 unsigned long ls_scan_time;
582 struct kobject ls_kobj;572 struct kobject ls_kobj;
583 573
584 struct idr ls_lkbidr;574 struct xarray ls_lkbxa;
585 rwlock_t ls_lkbidr_lock;575 rwlock_t ls_lkbxa_lock;
586 576
577 /* an rsb is on rsbtl for primary locking functions,
578 and on a slow list for recovery/dump iteration */
587 struct rhashtable ls_rsbtbl;579 struct rhashtable ls_rsbtbl;
588 rwlock_t ls_rsbtbl_lock;580 rwlock_t ls_rsbtbl_lock; /* for ls_rsbtbl and ls_slow */
581 struct list_head ls_slow_inactive; /* to iterate rsbtbl */
582 struct list_head ls_slow_active; /* to iterate rsbtbl */
589 583
590 struct list_head ls_toss;584 struct timer_list ls_scan_timer; /* based on first scan_list rsb toss_time */
591 struct list_head ls_keep;585 struct list_head ls_scan_list; /* rsbs ordered by res_toss_time */
592 586 spinlock_t ls_scan_lock;
593 struct timer_list ls_timer;
594 /* this queue is ordered according the
595 * absolute res_toss_time jiffies time
596 * to mod_timer() with the first element
597 * if necessary.
598 */
599 struct list_head ls_toss_q;
600 spinlock_t ls_toss_q_lock;
601 587
602 spinlock_t ls_waiters_lock;588 spinlock_t ls_waiters_lock;
603 struct list_head ls_waiters; /* lkbs needing a reply */589 struct list_head ls_waiters; /* lkbs needing a reply */
@@ -605,10 +591,6 @@ struct dlm_ls { · 1 unmodified line
605 spinlock_t ls_orphans_lock;591 spinlock_t ls_orphans_lock;
606 struct list_head ls_orphans;592 struct list_head ls_orphans;
607 593
608 spinlock_t ls_new_rsb_spin;
609 int ls_new_rsb_count;
610 struct list_head ls_new_rsb; /* new rsb structs */
611
612 struct list_head ls_nodes; /* current nodes in ls */594 struct list_head ls_nodes; /* current nodes in ls */
613 struct list_head ls_nodes_gone; /* dead node list, recovery */595 struct list_head ls_nodes_gone; /* dead node list, recovery */
614 int ls_num_nodes; /* number of nodes in ls */596 int ls_num_nodes; /* number of nodes in ls */
@@ -664,8 +646,8 @@ struct dlm_ls { · 49 unmodified lines
664 struct list_head ls_recover_list;646 struct list_head ls_recover_list;
665 spinlock_t ls_recover_list_lock;647 spinlock_t ls_recover_list_lock;
666 int ls_recover_list_count;648 int ls_recover_list_count;
667 struct idr ls_recover_idr;649 struct xarray ls_recover_xa;
668 spinlock_t ls_recover_idr_lock;650 spinlock_t ls_recover_xa_lock;
669 wait_queue_head_t ls_wait_general;651 wait_queue_head_t ls_wait_general;
670 wait_queue_head_t ls_recover_lock_wait;652 wait_queue_head_t ls_recover_lock_wait;
671 spinlock_t ls_clear_proc_locks;653 spinlock_t ls_clear_proc_locks;
@@ -716,6 +698,8 @@ struct dlm_ls { · 44 unmodified lines
716#define LSFL_CB_DELAY 9698#define LSFL_CB_DELAY 9
717#define LSFL_NODIR 10699#define LSFL_NODIR 10
718#define LSFL_RECV_MSG_BLOCKED 11700#define LSFL_RECV_MSG_BLOCKED 11
701#define LSFL_FS 12
702#define LSFL_SOFTIRQ 13
719 703
720#define DLM_PROC_FLAGS_CLOSING 1704#define DLM_PROC_FLAGS_CLOSING 1
721#define DLM_PROC_FLAGS_COMPAT 2705#define DLM_PROC_FLAGS_COMPAT 2
fs/dlm/lock.c+279−289
@@ -89,7 +89,7 @@ static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb, · 88 unmodified lines
89 const struct dlm_message *ms, bool local);89 const struct dlm_message *ms, bool local);
90static int receive_extralen(const struct dlm_message *ms);90static int receive_extralen(const struct dlm_message *ms);
91static void do_purge(struct dlm_ls *ls, int nodeid, int pid);91static void do_purge(struct dlm_ls *ls, int nodeid, int pid);
92static void toss_rsb(struct kref *kref);92static void deactivate_rsb(struct kref *kref);
93 93
94/*94/*
95 * Lock compatibilty matrix - thanks Steve95 * Lock compatibilty matrix - thanks Steve
@@ -330,8 +330,8 @@ static inline unsigned long rsb_toss_jiffies(void) · 234 unmodified lines
330 330
331static inline void hold_rsb(struct dlm_rsb *r)331static inline void hold_rsb(struct dlm_rsb *r)
332{332{
333 /* rsbs in toss state never get referenced */333 /* inactive rsbs are not ref counted */
334 WARN_ON(rsb_flag(r, RSB_TOSS));334 WARN_ON(rsb_flag(r, RSB_INACTIVE));
335 kref_get(&r->res_ref);335 kref_get(&r->res_ref);
336}336}
337 337
@@ -370,15 +370,12 @@ static inline int dlm_kref_put_write_lock_bh(struct kref *kref, · 32 unmodified lines
370 return 0;370 return 0;
371}371}
372 372
373/* When all references to the rsb are gone it's transferred to
374 the tossed list for later disposal. */
375
376static void put_rsb(struct dlm_rsb *r)373static void put_rsb(struct dlm_rsb *r)
377{374{
378 struct dlm_ls *ls = r->res_ls;375 struct dlm_ls *ls = r->res_ls;
379 int rv;376 int rv;
380 377
381 rv = dlm_kref_put_write_lock_bh(&r->res_ref, toss_rsb,378 rv = dlm_kref_put_write_lock_bh(&r->res_ref, deactivate_rsb,
382 &ls->ls_rsbtbl_lock);379 &ls->ls_rsbtbl_lock);
383 if (rv)380 if (rv)
384 write_unlock_bh(&ls->ls_rsbtbl_lock);381 write_unlock_bh(&ls->ls_rsbtbl_lock);
@@ -389,82 +386,54 @@ void dlm_put_rsb(struct dlm_rsb *r) · 4 unmodified lines
389 put_rsb(r);386 put_rsb(r);
390}387}
391 388
392static int pre_rsb_struct(struct dlm_ls *ls)
393{
394 struct dlm_rsb *r1, *r2;
395 int count = 0;
396
397 spin_lock_bh(&ls->ls_new_rsb_spin);
398 if (ls->ls_new_rsb_count > dlm_config.ci_new_rsb_count / 2) {
399 spin_unlock_bh(&ls->ls_new_rsb_spin);
400 return 0;
401 }
402 spin_unlock_bh(&ls->ls_new_rsb_spin);
403
404 r1 = dlm_allocate_rsb(ls);
405 r2 = dlm_allocate_rsb(ls);
406
407 spin_lock_bh(&ls->ls_new_rsb_spin);
408 if (r1) {
409 list_add(&r1->res_hashchain, &ls->ls_new_rsb);
410 ls->ls_new_rsb_count++;
411 }
412 if (r2) {
413 list_add(&r2->res_hashchain, &ls->ls_new_rsb);
414 ls->ls_new_rsb_count++;
415 }
416 count = ls->ls_new_rsb_count;
417 spin_unlock_bh(&ls->ls_new_rsb_spin);
418
419 if (!count)
420 return -ENOMEM;
421 return 0;
422}
423
424/* connected with timer_delete_sync() in dlm_ls_stop() to stop389/* connected with timer_delete_sync() in dlm_ls_stop() to stop
425 * new timers when recovery is triggered and don't run them390 * new timers when recovery is triggered and don't run them
426 * again until a dlm_timer_resume() tries it again.391 * again until a resume_scan_timer() tries it again.
427 */392 */
428static void __rsb_mod_timer(struct dlm_ls *ls, unsigned long jiffies)393static void enable_scan_timer(struct dlm_ls *ls, unsigned long jiffies)
429{394{
430 if (!dlm_locking_stopped(ls))395 if (!dlm_locking_stopped(ls))
431 mod_timer(&ls->ls_timer, jiffies);396 mod_timer(&ls->ls_scan_timer, jiffies);
432}397}
433 398
434/* This function tries to resume the timer callback if a rsb399/* This function tries to resume the timer callback if a rsb
435 * is on the toss list and no timer is pending. It might that400 * is on the scan list and no timer is pending. It might that
436 * the first entry is on currently executed as timer callback401 * the first entry is on currently executed as timer callback
437 * but we don't care if a timer queued up again and does402 * but we don't care if a timer queued up again and does
438 * nothing. Should be a rare case.403 * nothing. Should be a rare case.
439 */404 */
440void dlm_timer_resume(struct dlm_ls *ls)405void resume_scan_timer(struct dlm_ls *ls)
441{406{
442 struct dlm_rsb *r;407 struct dlm_rsb *r;
443 408
444 spin_lock_bh(&ls->ls_toss_q_lock);409 spin_lock_bh(&ls->ls_scan_lock);
445 r = list_first_entry_or_null(&ls->ls_toss_q, struct dlm_rsb,410 r = list_first_entry_or_null(&ls->ls_scan_list, struct dlm_rsb,
446 res_toss_q_list);411 res_scan_list);
447 if (r && !timer_pending(&ls->ls_timer))412 if (r && !timer_pending(&ls->ls_scan_timer))
448 __rsb_mod_timer(ls, r->res_toss_time);413 enable_scan_timer(ls, r->res_toss_time);
449 spin_unlock_bh(&ls->ls_toss_q_lock);414 spin_unlock_bh(&ls->ls_scan_lock);
450}415}
451 416
452/* ls_rsbtbl_lock must be held and being sure the rsb is in toss state */417/* ls_rsbtbl_lock must be held */
453static void rsb_delete_toss_timer(struct dlm_ls *ls, struct dlm_rsb *r)418
419static void del_scan(struct dlm_ls *ls, struct dlm_rsb *r)
454{420{
455 struct dlm_rsb *first;421 struct dlm_rsb *first;
456 422
457 spin_lock_bh(&ls->ls_toss_q_lock);423 /* active rsbs should never be on the scan list */
424 WARN_ON(!rsb_flag(r, RSB_INACTIVE));
425
426 spin_lock_bh(&ls->ls_scan_lock);
458 r->res_toss_time = 0;427 r->res_toss_time = 0;
459 428
460 /* if the rsb is not queued do nothing */429 /* if the rsb is not queued do nothing */
461 if (list_empty(&r->res_toss_q_list))430 if (list_empty(&r->res_scan_list))
462 goto out;431 goto out;
463 432
464 /* get the first element before delete */433 /* get the first element before delete */
465 first = list_first_entry(&ls->ls_toss_q, struct dlm_rsb,434 first = list_first_entry(&ls->ls_scan_list, struct dlm_rsb,
466 res_toss_q_list);435 res_scan_list);
467 list_del_init(&r->res_toss_q_list);436 list_del_init(&r->res_scan_list);
468 /* check if the first element was the rsb we deleted */437 /* check if the first element was the rsb we deleted */
469 if (first == r) {438 if (first == r) {
470 /* try to get the new first element, if the list439 /* try to get the new first element, if the list
@@ -474,70 +443,59 @@ static void rsb_delete_toss_timer(struct dlm_ls *ls, struct dlm_rsb *r) · 3 unmodified lines
474 * if the list isn't empty and a new first element got443 * if the list isn't empty and a new first element got
475 * in place, set the new timer expire time.444 * in place, set the new timer expire time.
476 */445 */
477 first = list_first_entry_or_null(&ls->ls_toss_q, struct dlm_rsb,446 first = list_first_entry_or_null(&ls->ls_scan_list, struct dlm_rsb,
478 res_toss_q_list);447 res_scan_list);
479 if (!first)448 if (!first)
480 timer_delete(&ls->ls_timer);449 timer_delete(&ls->ls_scan_timer);
481 else450 else
482 __rsb_mod_timer(ls, first->res_toss_time);451 enable_scan_timer(ls, first->res_toss_time);
483 }452 }
484 453
485out:454out:
486 spin_unlock_bh(&ls->ls_toss_q_lock);455 spin_unlock_bh(&ls->ls_scan_lock);
487}456}
488 457
489/* Caller must held ls_rsbtbl_lock and need to be called every time458static void add_scan(struct dlm_ls *ls, struct dlm_rsb *r)
490 * when either the rsb enters toss state or the toss state changes
491 * the dir/master nodeid.
492 */
493static void rsb_mod_timer(struct dlm_ls *ls, struct dlm_rsb *r)
494{459{
495 int our_nodeid = dlm_our_nodeid();460 int our_nodeid = dlm_our_nodeid();
496 struct dlm_rsb *first;461 struct dlm_rsb *first;
497 462
498 /* If we're the directory record for this rsb, and463 /* A dir record for a remote master rsb should never be on the scan list. */
499 * we're not the master of it, then we need to wait464 WARN_ON(!dlm_no_directory(ls) &&
500 * for the master node to send us a dir remove for465 (r->res_master_nodeid != our_nodeid) &&
501 * before removing the dir record.466 (dlm_dir_nodeid(r) == our_nodeid));
502 */467
503 if (!dlm_no_directory(ls) &&468 /* An active rsb should never be on the scan list. */
504 (r->res_master_nodeid != our_nodeid) &&469 WARN_ON(!rsb_flag(r, RSB_INACTIVE));
505 (dlm_dir_nodeid(r) == our_nodeid)) {
506 rsb_delete_toss_timer(ls, r);
507 return;
508 }
509 470
510 spin_lock_bh(&ls->ls_toss_q_lock);471 /* An rsb should not already be on the scan list. */
472 WARN_ON(!list_empty(&r->res_scan_list));
473
474 spin_lock_bh(&ls->ls_scan_lock);
511 /* set the new rsb absolute expire time in the rsb */475 /* set the new rsb absolute expire time in the rsb */
512 r->res_toss_time = rsb_toss_jiffies();476 r->res_toss_time = rsb_toss_jiffies();
513 if (list_empty(&ls->ls_toss_q)) {477 if (list_empty(&ls->ls_scan_list)) {
514 /* if the queue is empty add the element and it's478 /* if the queue is empty add the element and it's
515 * our new expire time479 * our new expire time
516 */480 */
517 list_add_tail(&r->res_toss_q_list, &ls->ls_toss_q);481 list_add_tail(&r->res_scan_list, &ls->ls_scan_list);
518 __rsb_mod_timer(ls, r->res_toss_time);482 enable_scan_timer(ls, r->res_toss_time);
519 } else {483 } else {
520 /* check if the rsb was already queued, if so delete
521 * it from the toss queue
522 */
523 if (!list_empty(&r->res_toss_q_list))
524 list_del(&r->res_toss_q_list);
525
526 /* try to get the maybe new first element and then add484 /* try to get the maybe new first element and then add
527 * to this rsb with the oldest expire time to the end485 * to this rsb with the oldest expire time to the end
528 * of the queue. If the list was empty before this486 * of the queue. If the list was empty before this
529 * rsb expire time is our next expiration if it wasn't487 * rsb expire time is our next expiration if it wasn't
530 * the now new first elemet is our new expiration time488 * the now new first elemet is our new expiration time
531 */489 */
532 first = list_first_entry_or_null(&ls->ls_toss_q, struct dlm_rsb,490 first = list_first_entry_or_null(&ls->ls_scan_list, struct dlm_rsb,
533 res_toss_q_list);491 res_scan_list);
534 list_add_tail(&r->res_toss_q_list, &ls->ls_toss_q);492 list_add_tail(&r->res_scan_list, &ls->ls_scan_list);
535 if (!first)493 if (!first)
536 __rsb_mod_timer(ls, r->res_toss_time);494 enable_scan_timer(ls, r->res_toss_time);
537 else495 else
538 __rsb_mod_timer(ls, first->res_toss_time);496 enable_scan_timer(ls, first->res_toss_time);
539 }497 }
540 spin_unlock_bh(&ls->ls_toss_q_lock);498 spin_unlock_bh(&ls->ls_scan_lock);
541}499}
542 500
543/* if we hit contention we do in 250 ms a retry to trylock.501/* if we hit contention we do in 250 ms a retry to trylock.
@@ -547,9 +505,11 @@ static void rsb_mod_timer(struct dlm_ls *ls, struct dlm_rsb *r) · 3 unmodified lines
547 */505 */
548#define DLM_TOSS_TIMER_RETRY (jiffies + msecs_to_jiffies(250))506#define DLM_TOSS_TIMER_RETRY (jiffies + msecs_to_jiffies(250))
549 507
550void dlm_rsb_toss_timer(struct timer_list *timer)508/* Called by lockspace scan_timer to free unused rsb's. */
509
510void dlm_rsb_scan(struct timer_list *timer)
551{511{
552 struct dlm_ls *ls = from_timer(ls, timer, ls_timer);512 struct dlm_ls *ls = from_timer(ls, timer, ls_scan_timer);
553 int our_nodeid = dlm_our_nodeid();513 int our_nodeid = dlm_our_nodeid();
554 struct dlm_rsb *r;514 struct dlm_rsb *r;
555 int rv;515 int rv;
@@ -557,76 +517,63 @@ void dlm_rsb_toss_timer(struct timer_list *timer) · 1 unmodified line
557 while (1) {517 while (1) {
558 /* interrupting point to leave iteration when518 /* interrupting point to leave iteration when
559 * recovery waits for timer_delete_sync(), recovery519 * recovery waits for timer_delete_sync(), recovery
560 * will take care to delete everything in toss queue.520 * will take care to delete everything in scan list.
561 */521 */
562 if (dlm_locking_stopped(ls))522 if (dlm_locking_stopped(ls))
563 break;523 break;
564 524
565 rv = spin_trylock(&ls->ls_toss_q_lock);525 rv = spin_trylock(&ls->ls_scan_lock);
566 if (!rv) {526 if (!rv) {
567 /* rearm again try timer */527 /* rearm again try timer */
568 __rsb_mod_timer(ls, DLM_TOSS_TIMER_RETRY);528 enable_scan_timer(ls, DLM_TOSS_TIMER_RETRY);
569 break;529 break;
570 }530 }
571 531
572 r = list_first_entry_or_null(&ls->ls_toss_q, struct dlm_rsb,532 r = list_first_entry_or_null(&ls->ls_scan_list, struct dlm_rsb,
573 res_toss_q_list);533 res_scan_list);
574 if (!r) {534 if (!r) {
575 /* nothing to do anymore next rsb queue will535 /* the next add_scan will enable the timer again */
576 * set next mod_timer() expire.536 spin_unlock(&ls->ls_scan_lock);
577 */
578 spin_unlock(&ls->ls_toss_q_lock);
579 break;537 break;
580 }538 }
581 539
582 /* test if the first rsb isn't expired yet, if540 /*
583 * so we stop freeing rsb from toss queue as541 * If the first rsb is not yet expired, then stop because the
584 * the order in queue is ascending to the542 * list is sorted with nearest expiration first.
585 * absolute res_toss_time jiffies
586 */543 */
587 if (time_before(jiffies, r->res_toss_time)) {544 if (time_before(jiffies, r->res_toss_time)) {
588 /* rearm with the next rsb to expire in the future */545 /* rearm with the next rsb to expire in the future */
589 __rsb_mod_timer(ls, r->res_toss_time);546 enable_scan_timer(ls, r->res_toss_time);
590 spin_unlock(&ls->ls_toss_q_lock);547 spin_unlock(&ls->ls_scan_lock);
591 break;548 break;
592 }549 }
593 550
594 /* in find_rsb_dir/nodir there is a reverse order of this551 /* in find_rsb_dir/nodir there is a reverse order of this
595 * lock, however this is only a trylock if we hit some552 * lock, however this is only a trylock if we hit some
596 * possible contention we try it again.553 * possible contention we try it again.
597 *
598 * This lock synchronized while holding ls_toss_q_lock
599 * synchronize everything that rsb_delete_toss_timer()
600 * or rsb_mod_timer() can't run after this timer callback
601 * deletes the rsb from the ls_toss_q. Whereas the other
602 * holders have always a priority to run as this is only
603 * a caching handling and the other holders might to put
604 * this rsb out of the toss state.
605 */554 */
606 rv = write_trylock(&ls->ls_rsbtbl_lock);555 rv = write_trylock(&ls->ls_rsbtbl_lock);
607 if (!rv) {556 if (!rv) {
608 spin_unlock(&ls->ls_toss_q_lock);557 spin_unlock(&ls->ls_scan_lock);
609 /* rearm again try timer */558 /* rearm again try timer */
610 __rsb_mod_timer(ls, DLM_TOSS_TIMER_RETRY);559 enable_scan_timer(ls, DLM_TOSS_TIMER_RETRY);
611 break;560 break;
612 }561 }
613 562
614 list_del(&r->res_rsbs_list);563 list_del(&r->res_slow_list);
615 rhashtable_remove_fast(&ls->ls_rsbtbl, &r->res_node,564 rhashtable_remove_fast(&ls->ls_rsbtbl, &r->res_node,
616 dlm_rhash_rsb_params);565 dlm_rhash_rsb_params);
566 rsb_clear_flag(r, RSB_HASHED);
617 567
618 /* not necessary to held the ls_rsbtbl_lock when568 /* ls_rsbtbl_lock is not needed when calling send_remove() */
619 * calling send_remove()
620 */
621 write_unlock(&ls->ls_rsbtbl_lock);569 write_unlock(&ls->ls_rsbtbl_lock);
622 570
623 /* remove the rsb out of the toss queue its gone571 list_del_init(&r->res_scan_list);
624 * drom DLM now572 spin_unlock(&ls->ls_scan_lock);
625 */
626 list_del_init(&r->res_toss_q_list);
627 spin_unlock(&ls->ls_toss_q_lock);
628 573
629 /* no rsb in this state should ever run a timer */574 /* An rsb that is a dir record for a remote master rsb
575 * cannot be removed, and should not have a timer enabled.
576 */
630 WARN_ON(!dlm_no_directory(ls) &&577 WARN_ON(!dlm_no_directory(ls) &&
631 (r->res_master_nodeid != our_nodeid) &&578 (r->res_master_nodeid != our_nodeid) &&
632 (dlm_dir_nodeid(r) == our_nodeid));579 (dlm_dir_nodeid(r) == our_nodeid));
@@ -640,7 +587,7 @@ void dlm_rsb_toss_timer(struct timer_list *timer) · 7 unmodified lines
640 (dlm_dir_nodeid(r) != our_nodeid))587 (dlm_dir_nodeid(r) != our_nodeid))
641 send_remove(r);588 send_remove(r);
642 589
643 free_toss_rsb(r);590 free_inactive_rsb(r);
644 }591 }
645}592}
646 593
@@ -652,22 +599,10 @@ static int get_rsb_struct(struct dlm_ls *ls, const void *name, int len, · 5 unmodified lines
652 struct dlm_rsb **r_ret)599 struct dlm_rsb **r_ret)
653{600{
654 struct dlm_rsb *r;601 struct dlm_rsb *r;
655 int count;
656 602
657 spin_lock_bh(&ls->ls_new_rsb_spin);603 r = dlm_allocate_rsb(ls);
658 if (list_empty(&ls->ls_new_rsb)) {604 if (!r)
659 count = ls->ls_new_rsb_count;605 return -ENOMEM;
660 spin_unlock_bh(&ls->ls_new_rsb_spin);
661 log_debug(ls, "find_rsb retry %d %d %s",
662 count, dlm_config.ci_new_rsb_count,
663 (const char *)name);
664 return -EAGAIN;
665 }
666
667 r = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb, res_hashchain);
668 list_del(&r->res_hashchain);
669 ls->ls_new_rsb_count--;
670 spin_unlock_bh(&ls->ls_new_rsb_spin);
671 606
672 r->res_ls = ls;607 r->res_ls = ls;
673 r->res_length = len;608 r->res_length = len;
@@ -679,7 +614,7 @@ static int get_rsb_struct(struct dlm_ls *ls, const void *name, int len, · 5 unmodified lines
679 INIT_LIST_HEAD(&r->res_convertqueue);614 INIT_LIST_HEAD(&r->res_convertqueue);
680 INIT_LIST_HEAD(&r->res_waitqueue);615 INIT_LIST_HEAD(&r->res_waitqueue);
681 INIT_LIST_HEAD(&r->res_root_list);616 INIT_LIST_HEAD(&r->res_root_list);
682 INIT_LIST_HEAD(&r->res_toss_q_list);617 INIT_LIST_HEAD(&r->res_scan_list);
683 INIT_LIST_HEAD(&r->res_recover_list);618 INIT_LIST_HEAD(&r->res_recover_list);
684 INIT_LIST_HEAD(&r->res_masters_list);619 INIT_LIST_HEAD(&r->res_masters_list);
685 620
@@ -702,8 +637,14 @@ int dlm_search_rsb_tree(struct rhashtable *rhash, const void *name, int len, · 16 unmodified lines
702 637
703static int rsb_insert(struct dlm_rsb *rsb, struct rhashtable *rhash)638static int rsb_insert(struct dlm_rsb *rsb, struct rhashtable *rhash)
704{639{
705 return rhashtable_insert_fast(rhash, &rsb->res_node,640 int rv;
706 dlm_rhash_rsb_params);641
642 rv = rhashtable_insert_fast(rhash, &rsb->res_node,
643 dlm_rhash_rsb_params);
644 if (!rv)
645 rsb_set_flag(rsb, RSB_HASHED);
646
647 return rv;
707}648}
708 649
709/*650/*
@@ -733,7 +674,7 @@ static int rsb_insert(struct dlm_rsb *rsb, struct rhashtable *rhash) · 23 unmodified lines
733 * So, if the given rsb is on the toss list, it is moved to the keep list674 * So, if the given rsb is on the toss list, it is moved to the keep list
734 * before being returned.675 * before being returned.
735 *676 *
736 * toss_rsb() happens when all local usage of the rsb is done, i.e. no677 * deactivate_rsb() happens when all local usage of the rsb is done, i.e. no
737 * more refcounts exist, so the rsb is moved from the keep list to the678 * more refcounts exist, so the rsb is moved from the keep list to the
738 * toss list.679 * toss list.
739 *680 *
@@ -781,9 +722,9 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 41 unmodified lines
781 *722 *
782 * If someone sends us a request, we are the dir node, and we do723 * If someone sends us a request, we are the dir node, and we do
783 * not find the rsb anywhere, then recreate it. This happens if724 * not find the rsb anywhere, then recreate it. This happens if
784 * someone sends us a request after we have removed/freed an rsb725 * someone sends us a request after we have removed/freed an rsb.
785 * from our toss list. (They sent a request instead of lookup726 * (They sent a request instead of lookup because they are using
786 * because they are using an rsb from their toss list.)727 * an rsb taken from their scan list.)
787 */728 */
788 729
789 if (from_local || from_dir ||730 if (from_local || from_dir ||
@@ -792,15 +733,8 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 2 unmodified lines
792 }733 }
793 734
794 retry:735 retry:
795 if (create) {
796 error = pre_rsb_struct(ls);
797 if (error < 0)
798 goto out;
799 }
800 736
801 retry_lookup:737 /* check if the rsb is active under read lock - likely path */
802
803 /* check if the rsb is in keep state under read lock - likely path */
804 read_lock_bh(&ls->ls_rsbtbl_lock);738 read_lock_bh(&ls->ls_rsbtbl_lock);
805 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);739 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);
806 if (error) {740 if (error) {
@@ -812,9 +746,9 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 5 unmodified lines
812 * rsb is active, so we can't check master_nodeid without lock_rsb.746 * rsb is active, so we can't check master_nodeid without lock_rsb.
813 */747 */
814 748
815 if (rsb_flag(r, RSB_TOSS)) {749 if (rsb_flag(r, RSB_INACTIVE)) {
816 read_unlock_bh(&ls->ls_rsbtbl_lock);750 read_unlock_bh(&ls->ls_rsbtbl_lock);
817 goto do_toss;751 goto do_inactive;
818 }752 }
819 753
820 kref_get(&r->res_ref);754 kref_get(&r->res_ref);
@@ -822,17 +756,29 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 1 unmodified line
822 goto out;756 goto out;
823 757
824 758
825 do_toss:759 do_inactive:
826 write_lock_bh(&ls->ls_rsbtbl_lock);760 write_lock_bh(&ls->ls_rsbtbl_lock);
827 761
828 /* retry lookup under write lock to see if its still in toss state762 /*
829 * if not it's in keep state and we relookup - unlikely path.763 * The expectation here is that the rsb will have HASHED and
764 * INACTIVE flags set, and that the rsb can be moved from
765 * inactive back to active again. However, between releasing
766 * the read lock and acquiring the write lock, this rsb could
767 * have been removed from rsbtbl, and had HASHED cleared, to
768 * be freed. To deal with this case, we would normally need
769 * to repeat dlm_search_rsb_tree while holding the write lock,
770 * but rcu allows us to simply check the HASHED flag, because
771 * the rcu read lock means the rsb will not be freed yet.
772 * If the HASHED flag is not set, then the rsb is being freed,
773 * so we add a new rsb struct. If the HASHED flag is set,
774 * and INACTIVE is not set, it means another thread has
775 * made the rsb active, as we're expecting to do here, and
776 * we just repeat the lookup (this will be very unlikely.)
830 */777 */
831 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);778 if (rsb_flag(r, RSB_HASHED)) {
832 if (!error) {779 if (!rsb_flag(r, RSB_INACTIVE)) {
833 if (!rsb_flag(r, RSB_TOSS)) {
834 write_unlock_bh(&ls->ls_rsbtbl_lock);780 write_unlock_bh(&ls->ls_rsbtbl_lock);
835 goto retry_lookup;781 goto retry;
836 }782 }
837 } else {783 } else {
838 write_unlock_bh(&ls->ls_rsbtbl_lock);784 write_unlock_bh(&ls->ls_rsbtbl_lock);
@@ -842,14 +788,14 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 3 unmodified lines
842 /*788 /*
843 * rsb found inactive (master_nodeid may be out of date unless789 * rsb found inactive (master_nodeid may be out of date unless
844 * we are the dir_nodeid or were the master) No other thread790 * we are the dir_nodeid or were the master) No other thread
845 * is using this rsb because it's on the toss list, so we can791 * is using this rsb because it's inactive, so we can
846 * look at or update res_master_nodeid without lock_rsb.792 * look at or update res_master_nodeid without lock_rsb.
847 */793 */
848 794
849 if ((r->res_master_nodeid != our_nodeid) && from_other) {795 if ((r->res_master_nodeid != our_nodeid) && from_other) {
850 /* our rsb was not master, and another node (not the dir node)796 /* our rsb was not master, and another node (not the dir node)
851 has sent us a request */797 has sent us a request */
852 log_debug(ls, "find_rsb toss from_other %d master %d dir %d %s",798 log_debug(ls, "find_rsb inactive from_other %d master %d dir %d %s",
853 from_nodeid, r->res_master_nodeid, dir_nodeid,799 from_nodeid, r->res_master_nodeid, dir_nodeid,
854 r->res_name);800 r->res_name);
855 write_unlock_bh(&ls->ls_rsbtbl_lock);801 write_unlock_bh(&ls->ls_rsbtbl_lock);
@@ -859,7 +805,7 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 3 unmodified lines
859 805
860 if ((r->res_master_nodeid != our_nodeid) && from_dir) {806 if ((r->res_master_nodeid != our_nodeid) && from_dir) {
861 /* don't think this should ever happen */807 /* don't think this should ever happen */
862 log_error(ls, "find_rsb toss from_dir %d master %d",808 log_error(ls, "find_rsb inactive from_dir %d master %d",
863 from_nodeid, r->res_master_nodeid);809 from_nodeid, r->res_master_nodeid);
864 dlm_print_rsb(r);810 dlm_print_rsb(r);
865 /* fix it and go on */811 /* fix it and go on */
@@ -876,14 +822,12 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 10 unmodified lines
876 r->res_first_lkid = 0;822 r->res_first_lkid = 0;
877 }823 }
878 824
879 list_move(&r->res_rsbs_list, &ls->ls_keep);825 /* A dir record will not be on the scan list. */
880 rsb_clear_flag(r, RSB_TOSS);826 if (r->res_dir_nodeid != our_nodeid)
881 /* rsb got out of toss state, it becomes alive again827 del_scan(ls, r);
882 * and we reinit the reference counter that is only828 list_move(&r->res_slow_list, &ls->ls_slow_active);
883 * valid for keep state rsbs829 rsb_clear_flag(r, RSB_INACTIVE);
884 */830 kref_init(&r->res_ref); /* ref is now used in active state */
885 kref_init(&r->res_ref);
886 rsb_delete_toss_timer(ls, r);
887 write_unlock_bh(&ls->ls_rsbtbl_lock);831 write_unlock_bh(&ls->ls_rsbtbl_lock);
888 832
889 goto out;833 goto out;
@@ -898,9 +842,7 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 8 unmodified lines
898 goto out;842 goto out;
899 843
900 error = get_rsb_struct(ls, name, len, &r);844 error = get_rsb_struct(ls, name, len, &r);
901 if (error == -EAGAIN)845 if (WARN_ON_ONCE(error))
902 goto retry;
903 if (error)
904 goto out;846 goto out;
905 847
906 r->res_hash = hash;848 r->res_hash = hash;
@@ -952,9 +894,9 @@ static int find_rsb_dir(struct dlm_ls *ls, const void *name, int len, · 45 unmodified lines
952 */894 */
953 write_unlock_bh(&ls->ls_rsbtbl_lock);895 write_unlock_bh(&ls->ls_rsbtbl_lock);
954 dlm_free_rsb(r);896 dlm_free_rsb(r);
955 goto retry_lookup;897 goto retry;
956 } else if (!error) {898 } else if (!error) {
957 list_add(&r->res_rsbs_list, &ls->ls_keep);899 list_add(&r->res_slow_list, &ls->ls_slow_active);
958 }900 }
959 write_unlock_bh(&ls->ls_rsbtbl_lock);901 write_unlock_bh(&ls->ls_rsbtbl_lock);
960 out:902 out:
@@ -976,13 +918,8 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 15 unmodified lines
976 int error;918 int error;
977 919
978 retry:920 retry:
979 error = pre_rsb_struct(ls);
980 if (error < 0)
981 goto out;
982 921
983 retry_lookup:922 /* check if the rsb is in active state under read lock - likely path */
984
985 /* check if the rsb is in keep state under read lock - likely path */
986 read_lock_bh(&ls->ls_rsbtbl_lock);923 read_lock_bh(&ls->ls_rsbtbl_lock);
987 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);924 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);
988 if (error) {925 if (error) {
@@ -990,9 +927,9 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 1 unmodified line
990 goto do_new;927 goto do_new;
991 }928 }
992 929
993 if (rsb_flag(r, RSB_TOSS)) {930 if (rsb_flag(r, RSB_INACTIVE)) {
994 read_unlock_bh(&ls->ls_rsbtbl_lock);931 read_unlock_bh(&ls->ls_rsbtbl_lock);
995 goto do_toss;932 goto do_inactive;
996 }933 }
997 934
998 /*935 /*
@@ -1005,17 +942,14 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 6 unmodified lines
1005 goto out;942 goto out;
1006 943
1007 944
1008 do_toss:945 do_inactive:
1009 write_lock_bh(&ls->ls_rsbtbl_lock);946 write_lock_bh(&ls->ls_rsbtbl_lock);
1010 947
1011 /* retry lookup under write lock to see if its still in toss state948 /* See comment in find_rsb_dir. */
1012 * if not it's in keep state and we relookup - unlikely path.949 if (rsb_flag(r, RSB_HASHED)) {
1013 */950 if (!rsb_flag(r, RSB_INACTIVE)) {
1014 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);
1015 if (!error) {
1016 if (!rsb_flag(r, RSB_TOSS)) {
1017 write_unlock_bh(&ls->ls_rsbtbl_lock);951 write_unlock_bh(&ls->ls_rsbtbl_lock);
1018 goto retry_lookup;952 goto retry;
1019 }953 }
1020 } else {954 } else {
1021 write_unlock_bh(&ls->ls_rsbtbl_lock);955 write_unlock_bh(&ls->ls_rsbtbl_lock);
@@ -1025,14 +959,14 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 3 unmodified lines
1025 959
1026 /*960 /*
1027 * rsb found inactive. No other thread is using this rsb because961 * rsb found inactive. No other thread is using this rsb because
1028 * it's on the toss list, so we can look at or update962 * it's inactive, so we can look at or update res_master_nodeid
1029 * res_master_nodeid without lock_rsb.963 * without lock_rsb.
1030 */964 */
1031 965
1032 if (!recover && (r->res_master_nodeid != our_nodeid) && from_nodeid) {966 if (!recover && (r->res_master_nodeid != our_nodeid) && from_nodeid) {
1033 /* our rsb is not master, and another node has sent us a967 /* our rsb is not master, and another node has sent us a
1034 request; this should never happen */968 request; this should never happen */
1035 log_error(ls, "find_rsb toss from_nodeid %d master %d dir %d",969 log_error(ls, "find_rsb inactive from_nodeid %d master %d dir %d",
1036 from_nodeid, r->res_master_nodeid, dir_nodeid);970 from_nodeid, r->res_master_nodeid, dir_nodeid);
1037 dlm_print_rsb(r);971 dlm_print_rsb(r);
1038 write_unlock_bh(&ls->ls_rsbtbl_lock);972 write_unlock_bh(&ls->ls_rsbtbl_lock);
@@ -1044,21 +978,17 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 5 unmodified lines
1044 (dir_nodeid == our_nodeid)) {978 (dir_nodeid == our_nodeid)) {
1045 /* our rsb is not master, and we are dir; may as well fix it;979 /* our rsb is not master, and we are dir; may as well fix it;
1046 this should never happen */980 this should never happen */
1047 log_error(ls, "find_rsb toss our %d master %d dir %d",981 log_error(ls, "find_rsb inactive our %d master %d dir %d",
1048 our_nodeid, r->res_master_nodeid, dir_nodeid);982 our_nodeid, r->res_master_nodeid, dir_nodeid);
1049 dlm_print_rsb(r);983 dlm_print_rsb(r);
1050 r->res_master_nodeid = our_nodeid;984 r->res_master_nodeid = our_nodeid;
1051 r->res_nodeid = 0;985 r->res_nodeid = 0;
1052 }986 }
1053 987
1054 list_move(&r->res_rsbs_list, &ls->ls_keep);988 list_move(&r->res_slow_list, &ls->ls_slow_active);
1055 rsb_clear_flag(r, RSB_TOSS);989 rsb_clear_flag(r, RSB_INACTIVE);
1056 /* rsb got out of toss state, it becomes alive again
1057 * and we reinit the reference counter that is only
1058 * valid for keep state rsbs
1059 */
1060 kref_init(&r->res_ref);990 kref_init(&r->res_ref);
1061 rsb_delete_toss_timer(ls, r);991 del_scan(ls, r);
1062 write_unlock_bh(&ls->ls_rsbtbl_lock);992 write_unlock_bh(&ls->ls_rsbtbl_lock);
1063 993
1064 goto out;994 goto out;
@@ -1070,10 +1000,7 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 5 unmodified lines
1070 */1000 */
1071 1001
1072 error = get_rsb_struct(ls, name, len, &r);1002 error = get_rsb_struct(ls, name, len, &r);
1073 if (error == -EAGAIN) {1003 if (WARN_ON_ONCE(error))
1074 goto retry;
1075 }
1076 if (error)
1077 goto out;1004 goto out;
1078 1005
1079 r->res_hash = hash;1006 r->res_hash = hash;
@@ -1090,9 +1017,9 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 10 unmodified lines
1090 */1017 */
1091 write_unlock_bh(&ls->ls_rsbtbl_lock);1018 write_unlock_bh(&ls->ls_rsbtbl_lock);
1092 dlm_free_rsb(r);1019 dlm_free_rsb(r);
1093 goto retry_lookup;1020 goto retry;
1094 } else if (!error) {1021 } else if (!error) {
1095 list_add(&r->res_rsbs_list, &ls->ls_keep);1022 list_add(&r->res_slow_list, &ls->ls_slow_active);
1096 }1023 }
1097 write_unlock_bh(&ls->ls_rsbtbl_lock);1024 write_unlock_bh(&ls->ls_rsbtbl_lock);
1098 1025
@@ -1101,12 +1028,54 @@ static int find_rsb_nodir(struct dlm_ls *ls, const void *name, int len, · 2 unmodified lines
1101 return error;1028 return error;
1102}1029}
1103 1030
1031/*
1032 * rsb rcu usage
1033 *
1034 * While rcu read lock is held, the rsb cannot be freed,
1035 * which allows a lookup optimization.
1036 *
1037 * Two threads are accessing the same rsb concurrently,
1038 * the first (A) is trying to use the rsb, the second (B)
1039 * is trying to free the rsb.
1040 *
1041 * thread A thread B
1042 * (trying to use rsb) (trying to free rsb)
1043 *
1044 * A1. rcu read lock
1045 * A2. rsbtbl read lock
1046 * A3. look up rsb in rsbtbl
1047 * A4. rsbtbl read unlock
1048 * B1. rsbtbl write lock
1049 * B2. look up rsb in rsbtbl
1050 * B3. remove rsb from rsbtbl
1051 * B4. clear rsb HASHED flag
1052 * B5. rsbtbl write unlock
1053 * B6. begin freeing rsb using rcu...
1054 *
1055 * (rsb is inactive, so try to make it active again)
1056 * A5. read rsb HASHED flag (safe because rsb is not freed yet)
1057 * A6. the rsb HASHED flag is not set, which it means the rsb
1058 * is being removed from rsbtbl and freed, so don't use it.
1059 * A7. rcu read unlock
1060 *
1061 * B7. ...finish freeing rsb using rcu
1062 * A8. create a new rsb
1063 *
1064 * Without the rcu optimization, steps A5-8 would need to do
1065 * an extra rsbtbl lookup:
1066 * A5. rsbtbl write lock
1067 * A6. look up rsb in rsbtbl, not found
1068 * A7. rsbtbl write unlock
1069 * A8. create a new rsb
1070 */
1071
1104static int find_rsb(struct dlm_ls *ls, const void *name, int len,1072static int find_rsb(struct dlm_ls *ls, const void *name, int len,
1105 int from_nodeid, unsigned int flags,1073 int from_nodeid, unsigned int flags,
1106 struct dlm_rsb **r_ret)1074 struct dlm_rsb **r_ret)
1107{1075{
1108 int dir_nodeid;1076 int dir_nodeid;
1109 uint32_t hash;1077 uint32_t hash;
1078 int rv;
1110 1079
1111 if (len > DLM_RESNAME_MAXLEN)1080 if (len > DLM_RESNAME_MAXLEN)
1112 return -EINVAL;1081 return -EINVAL;
@@ -1114,12 +1083,15 @@ static int find_rsb(struct dlm_ls *ls, const void *name, int len, · 1 unmodified line
1114 hash = jhash(name, len, 0);1083 hash = jhash(name, len, 0);
1115 dir_nodeid = dlm_hash2nodeid(ls, hash);1084 dir_nodeid = dlm_hash2nodeid(ls, hash);
1116 1085
1086 rcu_read_lock();
1117 if (dlm_no_directory(ls))1087 if (dlm_no_directory(ls))
1118 return find_rsb_nodir(ls, name, len, hash, dir_nodeid,1088 rv = find_rsb_nodir(ls, name, len, hash, dir_nodeid,
1119 from_nodeid, flags, r_ret);1089 from_nodeid, flags, r_ret);
1120 else1090 else
1121 return find_rsb_dir(ls, name, len, hash, dir_nodeid,1091 rv = find_rsb_dir(ls, name, len, hash, dir_nodeid,
1122 from_nodeid, flags, r_ret);1092 from_nodeid, flags, r_ret);
1093 rcu_read_unlock();
1094 return rv;
1123}1095}
1124 1096
1125/* we have received a request and found that res_master_nodeid != our_nodeid,1097/* we have received a request and found that res_master_nodeid != our_nodeid,
@@ -1166,7 +1138,7 @@ static int validate_master_nodeid(struct dlm_ls *ls, struct dlm_rsb *r, · 40 unmodified lines
1166}1138}
1167 1139
1168static void __dlm_master_lookup(struct dlm_ls *ls, struct dlm_rsb *r, int our_nodeid,1140static void __dlm_master_lookup(struct dlm_ls *ls, struct dlm_rsb *r, int our_nodeid,
1169 int from_nodeid, bool toss_list, unsigned int flags,1141 int from_nodeid, bool is_inactive, unsigned int flags,
1170 int *r_nodeid, int *result)1142 int *r_nodeid, int *result)
1171{1143{
1172 int fix_master = (flags & DLM_LU_RECOVER_MASTER);1144 int fix_master = (flags & DLM_LU_RECOVER_MASTER);
@@ -1190,9 +1162,9 @@ static void __dlm_master_lookup(struct dlm_ls *ls, struct dlm_rsb *r, int our_no · 17 unmodified lines
1190 r->res_nodeid = from_nodeid;1162 r->res_nodeid = from_nodeid;
1191 rsb_set_flag(r, RSB_NEW_MASTER);1163 rsb_set_flag(r, RSB_NEW_MASTER);
1192 1164
1193 if (toss_list) {1165 if (is_inactive) {
1194 /* I don't think we should ever find it on toss list. */1166 /* I don't think we should ever find it inactive. */
1195 log_error(ls, "%s fix_master on toss", __func__);1167 log_error(ls, "%s fix_master inactive", __func__);
1196 dlm_dump_rsb(r);1168 dlm_dump_rsb(r);
1197 }1169 }
1198 }1170 }
@@ -1232,7 +1204,7 @@ static void __dlm_master_lookup(struct dlm_ls *ls, struct dlm_rsb *r, int our_no · 33 unmodified lines
1232 if (!from_master && !fix_master &&1204 if (!from_master && !fix_master &&
1233 (r->res_master_nodeid == from_nodeid)) {1205 (r->res_master_nodeid == from_nodeid)) {
1234 /* this can happen when the master sends remove, the dir node1206 /* this can happen when the master sends remove, the dir node
1235 * finds the rsb on the keep list and ignores the remove,1207 * finds the rsb on the active list and ignores the remove,
1236 * and the former master sends a lookup1208 * and the former master sends a lookup
1237 */1209 */
1238 1210
@@ -1276,8 +1248,8 @@ static void __dlm_master_lookup(struct dlm_ls *ls, struct dlm_rsb *r, int our_no · 37 unmodified lines
1276 * . dlm_master_lookup RECOVER_MASTER (fix_master 1, from_master 0)1248 * . dlm_master_lookup RECOVER_MASTER (fix_master 1, from_master 0)
1277 */1249 */
1278 1250
1279int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,1251static int _dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,
1280 int len, unsigned int flags, int *r_nodeid, int *result)1252 int len, unsigned int flags, int *r_nodeid, int *result)
1281{1253{
1282 struct dlm_rsb *r = NULL;1254 struct dlm_rsb *r = NULL;
1283 uint32_t hash;1255 uint32_t hash;
@@ -1304,19 +1276,14 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name, · 20 unmodified lines
1304 }1276 }
1305 1277
1306 retry:1278 retry:
1307 error = pre_rsb_struct(ls);
1308 if (error < 0)
1309 return error;
1310
1311 retry_lookup:
1312 1279
1313 /* check if the rsb is in keep state under read lock - likely path */1280 /* check if the rsb is active under read lock - likely path */
1314 read_lock_bh(&ls->ls_rsbtbl_lock);1281 read_lock_bh(&ls->ls_rsbtbl_lock);
1315 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);1282 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);
1316 if (!error) {1283 if (!error) {
1317 if (rsb_flag(r, RSB_TOSS)) {1284 if (rsb_flag(r, RSB_INACTIVE)) {
1318 read_unlock_bh(&ls->ls_rsbtbl_lock);1285 read_unlock_bh(&ls->ls_rsbtbl_lock);
1319 goto do_toss;1286 goto do_inactive;
1320 }1287 }
1321 1288
1322 /* because the rsb is active, we need to lock_rsb before1289 /* because the rsb is active, we need to lock_rsb before
@@ -1340,53 +1307,48 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name, · 17 unmodified lines
1340 goto not_found;1307 goto not_found;
1341 }1308 }
1342 1309
1343 do_toss:1310 do_inactive:
1344 /* unlikely path - relookup under write */1311 /* unlikely path - relookup under write */
1345 write_lock_bh(&ls->ls_rsbtbl_lock);1312 write_lock_bh(&ls->ls_rsbtbl_lock);
1346 1313
1347 /* rsb_mod_timer() requires to held ls_rsbtbl_lock in write lock
1348 * check if the rsb is still in toss state, if not relookup
1349 */
1350 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);1314 error = dlm_search_rsb_tree(&ls->ls_rsbtbl, name, len, &r);
1351 if (!error) {1315 if (!error) {
1352 if (!rsb_flag(r, RSB_TOSS)) {1316 if (!rsb_flag(r, RSB_INACTIVE)) {
1353 write_unlock_bh(&ls->ls_rsbtbl_lock);1317 write_unlock_bh(&ls->ls_rsbtbl_lock);
1354 /* something as changed, very unlikely but1318 /* something as changed, very unlikely but
1355 * try again1319 * try again
1356 */1320 */
1357 goto retry_lookup;1321 goto retry;
1358 }1322 }
1359 } else {1323 } else {
1360 write_unlock_bh(&ls->ls_rsbtbl_lock);1324 write_unlock_bh(&ls->ls_rsbtbl_lock);
1361 goto not_found;1325 goto not_found;
1362 }1326 }
1363 1327
1364 /* because the rsb is inactive (on toss list), it's not refcounted1328 /* because the rsb is inactive, it's not refcounted and lock_rsb
1365 * and lock_rsb is not used, but is protected by the rsbtbl lock1329 is not used, but is protected by the rsbtbl lock */
1366 */
1367 1330
1368 __dlm_master_lookup(ls, r, our_nodeid, from_nodeid, true, flags,1331 __dlm_master_lookup(ls, r, our_nodeid, from_nodeid, true, flags,
1369 r_nodeid, result);1332 r_nodeid, result);
1370 1333
1371 rsb_mod_timer(ls, r);1334 /* A dir record rsb should never be on scan list. */
1372 /* the rsb was inactive (on toss list) */1335 /* Try to fix this with del_scan? */
1336 WARN_ON(!list_empty(&r->res_scan_list));
1337
1373 write_unlock_bh(&ls->ls_rsbtbl_lock);1338 write_unlock_bh(&ls->ls_rsbtbl_lock);
1374 1339
1375 return 0;1340 return 0;
1376 1341
1377 not_found:1342 not_found:
1378 error = get_rsb_struct(ls, name, len, &r);1343 error = get_rsb_struct(ls, name, len, &r);
1379 if (error == -EAGAIN)1344 if (WARN_ON_ONCE(error))
1380 goto retry;
1381 if (error)
1382 goto out;1345 goto out;
1383 1346
1384 r->res_hash = hash;1347 r->res_hash = hash;
1385 r->res_dir_nodeid = our_nodeid;1348 r->res_dir_nodeid = our_nodeid;
1386 r->res_master_nodeid = from_nodeid;1349 r->res_master_nodeid = from_nodeid;
1387 r->res_nodeid = from_nodeid;1350 r->res_nodeid = from_nodeid;
1388 kref_init(&r->res_ref);1351 rsb_set_flag(r, RSB_INACTIVE);
1389 rsb_set_flag(r, RSB_TOSS);
1390 1352
1391 write_lock_bh(&ls->ls_rsbtbl_lock);1353 write_lock_bh(&ls->ls_rsbtbl_lock);
1392 error = rsb_insert(r, &ls->ls_rsbtbl);1354 error = rsb_insert(r, &ls->ls_rsbtbl);
@@ -1396,7 +1358,7 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name, · 3 unmodified lines
1396 */1358 */
1397 write_unlock_bh(&ls->ls_rsbtbl_lock);1359 write_unlock_bh(&ls->ls_rsbtbl_lock);
1398 dlm_free_rsb(r);1360 dlm_free_rsb(r);
1399 goto retry_lookup;1361 goto retry;
1400 } else if (error) {1362 } else if (error) {
1401 write_unlock_bh(&ls->ls_rsbtbl_lock);1363 write_unlock_bh(&ls->ls_rsbtbl_lock);
1402 /* should never happen */1364 /* should never happen */
@@ -1404,8 +1366,7 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name, · 1 unmodified line
1404 goto retry;1366 goto retry;
1405 }1367 }
1406 1368
1407 list_add(&r->res_rsbs_list, &ls->ls_toss);1369 list_add(&r->res_slow_list, &ls->ls_slow_inactive);
1408 rsb_mod_timer(ls, r);
1409 write_unlock_bh(&ls->ls_rsbtbl_lock);1370 write_unlock_bh(&ls->ls_rsbtbl_lock);
1410 1371
1411 if (result)1372 if (result)
@@ -1415,12 +1376,22 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name, · 3 unmodified lines
1415 return error;1376 return error;
1416}1377}
1417 1378
1379int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,
1380 int len, unsigned int flags, int *r_nodeid, int *result)
1381{
1382 int rv;
1383 rcu_read_lock();
1384 rv = _dlm_master_lookup(ls, from_nodeid, name, len, flags, r_nodeid, result);
1385 rcu_read_unlock();
1386 return rv;
1387}
1388
1418static void dlm_dump_rsb_hash(struct dlm_ls *ls, uint32_t hash)1389static void dlm_dump_rsb_hash(struct dlm_ls *ls, uint32_t hash)
1419{1390{
1420 struct dlm_rsb *r;1391 struct dlm_rsb *r;
1421 1392
1422 read_lock_bh(&ls->ls_rsbtbl_lock);1393 read_lock_bh(&ls->ls_rsbtbl_lock);
1423 list_for_each_entry(r, &ls->ls_keep, res_rsbs_list) {1394 list_for_each_entry(r, &ls->ls_slow_active, res_slow_list) {
1424 if (r->res_hash == hash)1395 if (r->res_hash == hash)
1425 dlm_dump_rsb(r);1396 dlm_dump_rsb(r);
1426 }1397 }
@@ -1442,15 +1413,28 @@ void dlm_dump_rsb_name(struct dlm_ls *ls, const char *name, int len) · 15 unmodified lines
1442 read_unlock_bh(&ls->ls_rsbtbl_lock);1413 read_unlock_bh(&ls->ls_rsbtbl_lock);
1443}1414}
1444 1415
1445static void toss_rsb(struct kref *kref)1416static void deactivate_rsb(struct kref *kref)
1446{1417{
1447 struct dlm_rsb *r = container_of(kref, struct dlm_rsb, res_ref);1418 struct dlm_rsb *r = container_of(kref, struct dlm_rsb, res_ref);
1448 struct dlm_ls *ls = r->res_ls;1419 struct dlm_ls *ls = r->res_ls;
1420 int our_nodeid = dlm_our_nodeid();
1449 1421
1450 DLM_ASSERT(list_empty(&r->res_root_list), dlm_print_rsb(r););1422 DLM_ASSERT(list_empty(&r->res_root_list), dlm_print_rsb(r););
1451 rsb_set_flag(r, RSB_TOSS);1423 rsb_set_flag(r, RSB_INACTIVE);
1452 list_move(&r->res_rsbs_list, &ls->ls_toss);1424 list_move(&r->res_slow_list, &ls->ls_slow_inactive);
1453 rsb_mod_timer(ls, r);1425
1426 /*
1427 * When the rsb becomes unused:
1428 * - If it's not a dir record for a remote master rsb,
1429 * then it is put on the scan list to be freed.
1430 * - If it's a dir record for a remote master rsb,
1431 * then it is kept in the inactive state until
1432 * receive_remove() from the master node.
1433 */
1434 if (!dlm_no_directory(ls) &&
1435 (r->res_master_nodeid != our_nodeid) &&
1436 (dlm_dir_nodeid(r) != our_nodeid))
1437 add_scan(ls, r);
1454 1438
1455 if (r->res_lvbptr) {1439 if (r->res_lvbptr) {
1456 dlm_free_lvb(r->res_lvbptr);1440 dlm_free_lvb(r->res_lvbptr);
@@ -1464,22 +1448,22 @@ static void unhold_rsb(struct dlm_rsb *r) · 7 unmodified lines
1464{1448{
1465 int rv;1449 int rv;
1466 1450
1467 /* rsbs in toss state never get referenced */1451 /* inactive rsbs are not ref counted */
1468 WARN_ON(rsb_flag(r, RSB_TOSS));1452 WARN_ON(rsb_flag(r, RSB_INACTIVE));
1469 rv = kref_put(&r->res_ref, toss_rsb);1453 rv = kref_put(&r->res_ref, deactivate_rsb);
1470 DLM_ASSERT(!rv, dlm_dump_rsb(r););1454 DLM_ASSERT(!rv, dlm_dump_rsb(r););
1471}1455}
1472 1456
1473void free_toss_rsb(struct dlm_rsb *r)1457void free_inactive_rsb(struct dlm_rsb *r)
1474{1458{
1475 WARN_ON_ONCE(!rsb_flag(r, RSB_TOSS));1459 WARN_ON_ONCE(!rsb_flag(r, RSB_INACTIVE));
1476 1460
1477 DLM_ASSERT(list_empty(&r->res_lookup), dlm_dump_rsb(r););1461 DLM_ASSERT(list_empty(&r->res_lookup), dlm_dump_rsb(r););
1478 DLM_ASSERT(list_empty(&r->res_grantqueue), dlm_dump_rsb(r););1462 DLM_ASSERT(list_empty(&r->res_grantqueue), dlm_dump_rsb(r););
1479 DLM_ASSERT(list_empty(&r->res_convertqueue), dlm_dump_rsb(r););1463 DLM_ASSERT(list_empty(&r->res_convertqueue), dlm_dump_rsb(r););
1480 DLM_ASSERT(list_empty(&r->res_waitqueue), dlm_dump_rsb(r););1464 DLM_ASSERT(list_empty(&r->res_waitqueue), dlm_dump_rsb(r););
1481 DLM_ASSERT(list_empty(&r->res_root_list), dlm_dump_rsb(r););1465 DLM_ASSERT(list_empty(&r->res_root_list), dlm_dump_rsb(r););
1482 DLM_ASSERT(list_empty(&r->res_toss_q_list), dlm_dump_rsb(r););1466 DLM_ASSERT(list_empty(&r->res_scan_list), dlm_dump_rsb(r););
1483 DLM_ASSERT(list_empty(&r->res_recover_list), dlm_dump_rsb(r););1467 DLM_ASSERT(list_empty(&r->res_recover_list), dlm_dump_rsb(r););
1484 DLM_ASSERT(list_empty(&r->res_masters_list), dlm_dump_rsb(r););1468 DLM_ASSERT(list_empty(&r->res_masters_list), dlm_dump_rsb(r););
1485 1469
@@ -1504,11 +1488,15 @@ static void detach_lkb(struct dlm_lkb *lkb) · 18 unmodified lines
1504}1488}
1505 1489
1506static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,1490static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret,
1507 int start, int end)1491 unsigned long start, unsigned long end)
1508{1492{
1493 struct xa_limit limit;
1509 struct dlm_lkb *lkb;1494 struct dlm_lkb *lkb;
1510 int rv;1495 int rv;
1511 1496
1497 limit.max = end;
1498 limit.min = start;
1499
1512 lkb = dlm_allocate_lkb(ls);1500 lkb = dlm_allocate_lkb(ls);
1513 if (!lkb)1501 if (!lkb)
1514 return -ENOMEM;1502 return -ENOMEM;
@@ -1522,14 +1510,12 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret, · 7 unmodified lines
1522 INIT_LIST_HEAD(&lkb->lkb_ownqueue);1510 INIT_LIST_HEAD(&lkb->lkb_ownqueue);
1523 INIT_LIST_HEAD(&lkb->lkb_rsb_lookup);1511 INIT_LIST_HEAD(&lkb->lkb_rsb_lookup);
1524 1512
1525 write_lock_bh(&ls->ls_lkbidr_lock);1513 write_lock_bh(&ls->ls_lkbxa_lock);
1526 rv = idr_alloc(&ls->ls_lkbidr, lkb, start, end, GFP_NOWAIT);1514 rv = xa_alloc(&ls->ls_lkbxa, &lkb->lkb_id, lkb, limit, GFP_ATOMIC);
1527 if (rv >= 0)1515 write_unlock_bh(&ls->ls_lkbxa_lock);
1528 lkb->lkb_id = rv;
1529 write_unlock_bh(&ls->ls_lkbidr_lock);
1530 1516
1531 if (rv < 0) {1517 if (rv < 0) {
1532 log_error(ls, "create_lkb idr error %d", rv);1518 log_error(ls, "create_lkb xa error %d", rv);
1533 dlm_free_lkb(lkb);1519 dlm_free_lkb(lkb);
1534 return rv;1520 return rv;
1535 }1521 }
@@ -1540,18 +1526,18 @@ static int _create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret, · 4 unmodified lines
1540 1526
1541static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret)1527static int create_lkb(struct dlm_ls *ls, struct dlm_lkb **lkb_ret)
1542{1528{
1543 return _create_lkb(ls, lkb_ret, 1, 0);1529 return _create_lkb(ls, lkb_ret, 1, ULONG_MAX);
1544}1530}
1545 1531
1546static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)1532static int find_lkb(struct dlm_ls *ls, uint32_t lkid, struct dlm_lkb **lkb_ret)
1547{1533{
1548 struct dlm_lkb *lkb;1534 struct dlm_lkb *lkb;
1549 1535
1550 read_lock_bh(&ls->ls_lkbidr_lock);1536 read_lock_bh(&ls->ls_lkbxa_lock);
1551 lkb = idr_find(&ls->ls_lkbidr, lkid);1537 lkb = xa_load(&ls->ls_lkbxa, lkid);
1552 if (lkb)1538 if (lkb)
1553 kref_get(&lkb->lkb_ref);1539 kref_get(&lkb->lkb_ref);
1554 read_unlock_bh(&ls->ls_lkbidr_lock);1540 read_unlock_bh(&ls->ls_lkbxa_lock);
1555 1541
1556 *lkb_ret = lkb;1542 *lkb_ret = lkb;
1557 return lkb ? 0 : -ENOENT;1543 return lkb ? 0 : -ENOENT;
@@ -1576,10 +1562,10 @@ static int __put_lkb(struct dlm_ls *ls, struct dlm_lkb *lkb) · 18 unmodified lines
1576 int rv;1562 int rv;
1577 1563
1578 rv = dlm_kref_put_write_lock_bh(&lkb->lkb_ref, kill_lkb,1564 rv = dlm_kref_put_write_lock_bh(&lkb->lkb_ref, kill_lkb,
1579 &ls->ls_lkbidr_lock);1565 &ls->ls_lkbxa_lock);
1580 if (rv) {1566 if (rv) {
1581 idr_remove(&ls->ls_lkbidr, lkid);1567 xa_erase(&ls->ls_lkbxa, lkid);
1582 write_unlock_bh(&ls->ls_lkbidr_lock);1568 write_unlock_bh(&ls->ls_lkbxa_lock);
1583 1569
1584 detach_lkb(lkb);1570 detach_lkb(lkb);
1585 1571
@@ -4323,8 +4309,9 @@ static void receive_remove(struct dlm_ls *ls, const struct dlm_message *ms) · 2737 unmodified lines
4323 return;4309 return;
4324 }4310 }
4325 4311
4326 /* Look for name in rsb toss state, if it's there, kill it.4312 /*
4327 * If it's in non toss state, it's being used, and we should ignore this4313 * Look for inactive rsb, if it's there, free it.
4314 * If the rsb is active, it's being used, and we should ignore this
4328 * message. This is an expected race between the dir node sending a4315 * message. This is an expected race between the dir node sending a
4329 * request to the master node at the same time as the master node sends4316 * request to the master node at the same time as the master node sends
4330 * a remove to the dir node. The resolution to that race is for the4317 * a remove to the dir node. The resolution to that race is for the
@@ -4347,16 +4334,18 @@ static void receive_remove(struct dlm_ls *ls, const struct dlm_message *ms) · 16 unmodified lines
4347 return;4334 return;
4348 }4335 }
4349 4336
4350 if (!rsb_flag(r, RSB_TOSS)) {4337 if (!rsb_flag(r, RSB_INACTIVE)) {
4351 if (r->res_master_nodeid != from_nodeid) {4338 if (r->res_master_nodeid != from_nodeid) {
4352 /* should not happen */4339 /* should not happen */
4353 log_error(ls, "receive_remove keep from %d master %d",4340 log_error(ls, "receive_remove on active rsb from %d master %d",
4354 from_nodeid, r->res_master_nodeid);4341 from_nodeid, r->res_master_nodeid);
4355 dlm_print_rsb(r);4342 dlm_print_rsb(r);
4356 write_unlock_bh(&ls->ls_rsbtbl_lock);4343 write_unlock_bh(&ls->ls_rsbtbl_lock);
4357 return;4344 return;
4358 }4345 }
4359 4346
4347 /* Ignore the remove message, see race comment above. */
4348
4360 log_debug(ls, "receive_remove from %d master %d first %x %s",4349 log_debug(ls, "receive_remove from %d master %d first %x %s",
4361 from_nodeid, r->res_master_nodeid, r->res_first_lkid,4350 from_nodeid, r->res_master_nodeid, r->res_first_lkid,
4362 name);4351 name);
@@ -4365,19 +4354,20 @@ static void receive_remove(struct dlm_ls *ls, const struct dlm_message *ms) · 2 unmodified lines
4365 }4354 }
4366 4355
4367 if (r->res_master_nodeid != from_nodeid) {4356 if (r->res_master_nodeid != from_nodeid) {
4368 log_error(ls, "receive_remove toss from %d master %d",4357 log_error(ls, "receive_remove inactive from %d master %d",
4369 from_nodeid, r->res_master_nodeid);4358 from_nodeid, r->res_master_nodeid);
4370 dlm_print_rsb(r);4359 dlm_print_rsb(r);
4371 write_unlock_bh(&ls->ls_rsbtbl_lock);4360 write_unlock_bh(&ls->ls_rsbtbl_lock);
4372 return;4361 return;
4373 }4362 }
4374 4363
4375 list_del(&r->res_rsbs_list);4364 list_del(&r->res_slow_list);
4376 rhashtable_remove_fast(&ls->ls_rsbtbl, &r->res_node,4365 rhashtable_remove_fast(&ls->ls_rsbtbl, &r->res_node,
4377 dlm_rhash_rsb_params);4366 dlm_rhash_rsb_params);
4367 rsb_clear_flag(r, RSB_HASHED);
4378 write_unlock_bh(&ls->ls_rsbtbl_lock);4368 write_unlock_bh(&ls->ls_rsbtbl_lock);
4379 4369
4380 free_toss_rsb(r);4370 free_inactive_rsb(r);
4381}4371}
4382 4372
4383static void receive_purge(struct dlm_ls *ls, const struct dlm_message *ms)4373static void receive_purge(struct dlm_ls *ls, const struct dlm_message *ms)
@@ -5444,7 +5434,7 @@ static struct dlm_rsb *find_grant_rsb(struct dlm_ls *ls) · 1060 unmodified lines
5444 struct dlm_rsb *r;5434 struct dlm_rsb *r;
5445 5435
5446 read_lock_bh(&ls->ls_rsbtbl_lock);5436 read_lock_bh(&ls->ls_rsbtbl_lock);
5447 list_for_each_entry(r, &ls->ls_keep, res_rsbs_list) {5437 list_for_each_entry(r, &ls->ls_slow_active, res_slow_list) {
5448 if (!rsb_flag(r, RSB_RECOVER_GRANT))5438 if (!rsb_flag(r, RSB_RECOVER_GRANT))
5449 continue;5439 continue;
5450 if (!is_master(r)) {5440 if (!is_master(r)) {
fs/dlm/lock.h+3−4
@@ -11,7 +11,6 @@ · 10 unmodified lines
11#ifndef __LOCK_DOT_H__11#ifndef __LOCK_DOT_H__
12#define __LOCK_DOT_H__12#define __LOCK_DOT_H__
13 13
14void dlm_rsb_toss_timer(struct timer_list *timer);
15void dlm_dump_rsb(struct dlm_rsb *r);14void dlm_dump_rsb(struct dlm_rsb *r);
16void dlm_dump_rsb_name(struct dlm_ls *ls, const char *name, int len);15void dlm_dump_rsb_name(struct dlm_ls *ls, const char *name, int len);
17void dlm_print_lkb(struct dlm_lkb *lkb);16void dlm_print_lkb(struct dlm_lkb *lkb);
@@ -19,15 +18,15 @@ void dlm_receive_message_saved(struct dlm_ls *ls, const struct dlm_message *ms, · 1 unmodified line
19 uint32_t saved_seq);18 uint32_t saved_seq);
20void dlm_receive_buffer(const union dlm_packet *p, int nodeid);19void dlm_receive_buffer(const union dlm_packet *p, int nodeid);
21int dlm_modes_compat(int mode1, int mode2);20int dlm_modes_compat(int mode1, int mode2);
22void free_toss_rsb(struct dlm_rsb *r);21void free_inactive_rsb(struct dlm_rsb *r);
23void dlm_put_rsb(struct dlm_rsb *r);22void dlm_put_rsb(struct dlm_rsb *r);
24void dlm_hold_rsb(struct dlm_rsb *r);23void dlm_hold_rsb(struct dlm_rsb *r);
25int dlm_put_lkb(struct dlm_lkb *lkb);24int dlm_put_lkb(struct dlm_lkb *lkb);
26void dlm_scan_rsbs(struct dlm_ls *ls);
27int dlm_lock_recovery_try(struct dlm_ls *ls);25int dlm_lock_recovery_try(struct dlm_ls *ls);
28void dlm_lock_recovery(struct dlm_ls *ls);26void dlm_lock_recovery(struct dlm_ls *ls);
29void dlm_unlock_recovery(struct dlm_ls *ls);27void dlm_unlock_recovery(struct dlm_ls *ls);
30void dlm_timer_resume(struct dlm_ls *ls);28void dlm_rsb_scan(struct timer_list *timer);
29void resume_scan_timer(struct dlm_ls *ls);
31 30
32int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,31int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, const char *name,
33 int len, unsigned int flags, int *r_nodeid, int *result);32 int len, unsigned int flags, int *r_nodeid, int *result);
fs/dlm/lockspace.c+58−73
@@ -38,7 +38,7 @@ static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len) · 37 unmodified lines
38 38
39 if (rc)39 if (rc)
40 return rc;40 return rc;
41 ls = dlm_find_lockspace_local(ls->ls_local_handle);41 ls = dlm_find_lockspace_local(ls);
42 if (!ls)42 if (!ls)
43 return -EINVAL;43 return -EINVAL;
44 44
@@ -265,18 +265,9 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id) · 220 unmodified lines
265 265
266struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)266struct dlm_ls *dlm_find_lockspace_local(dlm_lockspace_t *lockspace)
267{267{
268 struct dlm_ls *ls;268 struct dlm_ls *ls = lockspace;
269 269
270 spin_lock_bh(&lslist_lock);270 atomic_inc(&ls->ls_count);
271 list_for_each_entry(ls, &lslist, ls_list) {
272 if (ls->ls_local_handle == lockspace) {
273 atomic_inc(&ls->ls_count);
274 goto out;
275 }
276 }
277 ls = NULL;
278 out:
279 spin_unlock_bh(&lslist_lock);
280 return ls;271 return ls;
281}272}
282 273
@@ -410,37 +401,37 @@ static int new_lockspace(const char *name, const char *cluster, · 127 unmodified lines
410 atomic_set(&ls->ls_count, 0);401 atomic_set(&ls->ls_count, 0);
411 init_waitqueue_head(&ls->ls_count_wait);402 init_waitqueue_head(&ls->ls_count_wait);
412 ls->ls_flags = 0;403 ls->ls_flags = 0;
413 ls->ls_scan_time = jiffies;
414 404
415 if (ops && dlm_config.ci_recover_callbacks) {405 if (ops && dlm_config.ci_recover_callbacks) {
416 ls->ls_ops = ops;406 ls->ls_ops = ops;
417 ls->ls_ops_arg = ops_arg;407 ls->ls_ops_arg = ops_arg;
418 }408 }
419 409
410 if (flags & DLM_LSFL_SOFTIRQ)
411 set_bit(LSFL_SOFTIRQ, &ls->ls_flags);
412
420 /* ls_exflags are forced to match among nodes, and we don't413 /* ls_exflags are forced to match among nodes, and we don't
421 * need to require all nodes to have some flags set414 * need to require all nodes to have some flags set
422 */415 */
423 ls->ls_exflags = (flags & ~(DLM_LSFL_FS | DLM_LSFL_NEWEXCL));416 ls->ls_exflags = (flags & ~(DLM_LSFL_FS | DLM_LSFL_NEWEXCL |
417 DLM_LSFL_SOFTIRQ));
424 418
425 INIT_LIST_HEAD(&ls->ls_toss);419 INIT_LIST_HEAD(&ls->ls_slow_inactive);
426 INIT_LIST_HEAD(&ls->ls_keep);420 INIT_LIST_HEAD(&ls->ls_slow_active);
427 rwlock_init(&ls->ls_rsbtbl_lock);421 rwlock_init(&ls->ls_rsbtbl_lock);
428 422
429 error = rhashtable_init(&ls->ls_rsbtbl, &dlm_rhash_rsb_params);423 error = rhashtable_init(&ls->ls_rsbtbl, &dlm_rhash_rsb_params);
430 if (error)424 if (error)
431 goto out_lsfree;425 goto out_lsfree;
432 426
433 idr_init(&ls->ls_lkbidr);427 xa_init_flags(&ls->ls_lkbxa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_BH);
434 rwlock_init(&ls->ls_lkbidr_lock);428 rwlock_init(&ls->ls_lkbxa_lock);
435 429
436 INIT_LIST_HEAD(&ls->ls_waiters);430 INIT_LIST_HEAD(&ls->ls_waiters);
437 spin_lock_init(&ls->ls_waiters_lock);431 spin_lock_init(&ls->ls_waiters_lock);
438 INIT_LIST_HEAD(&ls->ls_orphans);432 INIT_LIST_HEAD(&ls->ls_orphans);
439 spin_lock_init(&ls->ls_orphans_lock);433 spin_lock_init(&ls->ls_orphans_lock);
440 434
441 INIT_LIST_HEAD(&ls->ls_new_rsb);
442 spin_lock_init(&ls->ls_new_rsb_spin);
443
444 INIT_LIST_HEAD(&ls->ls_nodes);435 INIT_LIST_HEAD(&ls->ls_nodes);
445 INIT_LIST_HEAD(&ls->ls_nodes_gone);436 INIT_LIST_HEAD(&ls->ls_nodes_gone);
446 ls->ls_num_nodes = 0;437 ls->ls_num_nodes = 0;
@@ -484,7 +475,7 @@ static int new_lockspace(const char *name, const char *cluster, · 37 unmodified lines
484 ls->ls_recover_buf = kmalloc(DLM_MAX_SOCKET_BUFSIZE, GFP_NOFS);475 ls->ls_recover_buf = kmalloc(DLM_MAX_SOCKET_BUFSIZE, GFP_NOFS);
485 if (!ls->ls_recover_buf) {476 if (!ls->ls_recover_buf) {
486 error = -ENOMEM;477 error = -ENOMEM;
487 goto out_lkbidr;478 goto out_lkbxa;
488 }479 }
489 480
490 ls->ls_slot = 0;481 ls->ls_slot = 0;
@@ -494,32 +485,31 @@ static int new_lockspace(const char *name, const char *cluster, · 3 unmodified lines
494 485
495 INIT_LIST_HEAD(&ls->ls_recover_list);486 INIT_LIST_HEAD(&ls->ls_recover_list);
496 spin_lock_init(&ls->ls_recover_list_lock);487 spin_lock_init(&ls->ls_recover_list_lock);
497 idr_init(&ls->ls_recover_idr);488 xa_init_flags(&ls->ls_recover_xa, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_BH);
498 spin_lock_init(&ls->ls_recover_idr_lock);489 spin_lock_init(&ls->ls_recover_xa_lock);
499 ls->ls_recover_list_count = 0;490 ls->ls_recover_list_count = 0;
500 ls->ls_local_handle = ls;
501 init_waitqueue_head(&ls->ls_wait_general);491 init_waitqueue_head(&ls->ls_wait_general);
502 INIT_LIST_HEAD(&ls->ls_masters_list);492 INIT_LIST_HEAD(&ls->ls_masters_list);
503 rwlock_init(&ls->ls_masters_lock);493 rwlock_init(&ls->ls_masters_lock);
504 INIT_LIST_HEAD(&ls->ls_dir_dump_list);494 INIT_LIST_HEAD(&ls->ls_dir_dump_list);
505 rwlock_init(&ls->ls_dir_dump_lock);495 rwlock_init(&ls->ls_dir_dump_lock);
506 496
507 INIT_LIST_HEAD(&ls->ls_toss_q);497 INIT_LIST_HEAD(&ls->ls_scan_list);
508 spin_lock_init(&ls->ls_toss_q_lock);498 spin_lock_init(&ls->ls_scan_lock);
509 timer_setup(&ls->ls_timer, dlm_rsb_toss_timer,499 timer_setup(&ls->ls_scan_timer, dlm_rsb_scan, TIMER_DEFERRABLE);
510 TIMER_DEFERRABLE);
511 500
512 spin_lock_bh(&lslist_lock);501 spin_lock_bh(&lslist_lock);
513 ls->ls_create_count = 1;502 ls->ls_create_count = 1;
514 list_add(&ls->ls_list, &lslist);503 list_add(&ls->ls_list, &lslist);
515 spin_unlock_bh(&lslist_lock);504 spin_unlock_bh(&lslist_lock);
516 505
517 if (flags & DLM_LSFL_FS) {506 if (flags & DLM_LSFL_FS)
518 error = dlm_callback_start(ls);507 set_bit(LSFL_FS, &ls->ls_flags);
519 if (error) {508
520 log_error(ls, "can't start dlm_callback %d", error);509 error = dlm_callback_start(ls);
521 goto out_delist;510 if (error) {
522 }511 log_error(ls, "can't start dlm_callback %d", error);
512 goto out_delist;
523 }513 }
524 514
525 init_waitqueue_head(&ls->ls_recover_lock_wait);515 init_waitqueue_head(&ls->ls_recover_lock_wait);
@@ -584,10 +574,10 @@ static int new_lockspace(const char *name, const char *cluster, · 58 unmodified lines
584 spin_lock_bh(&lslist_lock);574 spin_lock_bh(&lslist_lock);
585 list_del(&ls->ls_list);575 list_del(&ls->ls_list);
586 spin_unlock_bh(&lslist_lock);576 spin_unlock_bh(&lslist_lock);
587 idr_destroy(&ls->ls_recover_idr);577 xa_destroy(&ls->ls_recover_xa);
588 kfree(ls->ls_recover_buf);578 kfree(ls->ls_recover_buf);
589 out_lkbidr:579 out_lkbxa:
590 idr_destroy(&ls->ls_lkbidr);580 xa_destroy(&ls->ls_lkbxa);
591 rhashtable_destroy(&ls->ls_rsbtbl);581 rhashtable_destroy(&ls->ls_rsbtbl);
592 out_lsfree:582 out_lsfree:
593 if (do_unreg)583 if (do_unreg)
@@ -643,26 +633,15 @@ int dlm_new_user_lockspace(const char *name, const char *cluster, · 49 unmodified lines
643 void *ops_arg, int *ops_result,633 void *ops_arg, int *ops_result,
644 dlm_lockspace_t **lockspace)634 dlm_lockspace_t **lockspace)
645{635{
636 if (flags & DLM_LSFL_SOFTIRQ)
637 return -EINVAL;
638
646 return __dlm_new_lockspace(name, cluster, flags, lvblen, ops,639 return __dlm_new_lockspace(name, cluster, flags, lvblen, ops,
647 ops_arg, ops_result, lockspace);640 ops_arg, ops_result, lockspace);
648}641}
649 642
650static int lkb_idr_is_local(int id, void *p, void *data)643static int lkb_idr_free(struct dlm_lkb *lkb)
651{
652 struct dlm_lkb *lkb = p;
653
654 return lkb->lkb_nodeid == 0 && lkb->lkb_grmode != DLM_LOCK_IV;
655}
656
657static int lkb_idr_is_any(int id, void *p, void *data)
658{
659 return 1;
660}
661
662static int lkb_idr_free(int id, void *p, void *data)
663{644{
664 struct dlm_lkb *lkb = p;
665
666 if (lkb->lkb_lvbptr && test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags))645 if (lkb->lkb_lvbptr && test_bit(DLM_IFL_MSTCPY_BIT, &lkb->lkb_iflags))
667 dlm_free_lvb(lkb->lkb_lvbptr);646 dlm_free_lvb(lkb->lkb_lvbptr);
668 647
@@ -670,23 +649,34 @@ static int lkb_idr_free(int id, void *p, void *data) · 1 unmodified line
670 return 0;649 return 0;
671}650}
672 651
673/* NOTE: We check the lkbidr here rather than the resource table.652/* NOTE: We check the lkbxa here rather than the resource table.
674 This is because there may be LKBs queued as ASTs that have been unlinked653 This is because there may be LKBs queued as ASTs that have been unlinked
675 from their RSBs and are pending deletion once the AST has been delivered */654 from their RSBs and are pending deletion once the AST has been delivered */
676 655
677static int lockspace_busy(struct dlm_ls *ls, int force)656static int lockspace_busy(struct dlm_ls *ls, int force)
678{657{
679 int rv;658 struct dlm_lkb *lkb;
659 unsigned long id;
660 int rv = 0;
680 661
681 read_lock_bh(&ls->ls_lkbidr_lock);662 read_lock_bh(&ls->ls_lkbxa_lock);
682 if (force == 0) {663 if (force == 0) {
683 rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls);664 xa_for_each(&ls->ls_lkbxa, id, lkb) {
665 rv = 1;
666 break;
667 }
684 } else if (force == 1) {668 } else if (force == 1) {
685 rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls);669 xa_for_each(&ls->ls_lkbxa, id, lkb) {
670 if (lkb->lkb_nodeid == 0 &&
671 lkb->lkb_grmode != DLM_LOCK_IV) {
672 rv = 1;
673 break;
674 }
675 }
686 } else {676 } else {
687 rv = 0;677 rv = 0;
688 }678 }
689 read_unlock_bh(&ls->ls_lkbidr_lock);679 read_unlock_bh(&ls->ls_lkbxa_lock);
690 return rv;680 return rv;
691}681}
692 682
@@ -699,7 +689,8 @@ static void rhash_free_rsb(void *ptr, void *arg) · 6 unmodified lines
699 689
700static int release_lockspace(struct dlm_ls *ls, int force)690static int release_lockspace(struct dlm_ls *ls, int force)
701{691{
702 struct dlm_rsb *rsb;692 struct dlm_lkb *lkb;
693 unsigned long id;
703 int busy, rv;694 int busy, rv;
704 695
705 busy = lockspace_busy(ls, force);696 busy = lockspace_busy(ls, force);
@@ -739,7 +730,7 @@ static int release_lockspace(struct dlm_ls *ls, int force) · 33 unmodified lines
739 * time_shutdown_sync(), we don't care anymore730 * time_shutdown_sync(), we don't care anymore
740 */731 */
741 clear_bit(LSFL_RUNNING, &ls->ls_flags);732 clear_bit(LSFL_RUNNING, &ls->ls_flags);
742 timer_shutdown_sync(&ls->ls_timer);733 timer_shutdown_sync(&ls->ls_scan_timer);
743 734
744 if (ls_count == 1) {735 if (ls_count == 1) {
745 dlm_clear_members(ls);736 dlm_clear_members(ls);
@@ -752,28 +743,22 @@ static int release_lockspace(struct dlm_ls *ls, int force) · 6 unmodified lines
752 743
753 dlm_delete_debug_file(ls);744 dlm_delete_debug_file(ls);
754 745
755 idr_destroy(&ls->ls_recover_idr);746 xa_destroy(&ls->ls_recover_xa);
756 kfree(ls->ls_recover_buf);747 kfree(ls->ls_recover_buf);
757 748
758 /*749 /*
759 * Free all lkb's in idr750 * Free all lkb's in xa
760 */751 */
761 752 xa_for_each(&ls->ls_lkbxa, id, lkb) {
762 idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls);753 lkb_idr_free(lkb);
763 idr_destroy(&ls->ls_lkbidr);754 }
755 xa_destroy(&ls->ls_lkbxa);
764 756
765 /*757 /*
766 * Free all rsb's on rsbtbl758 * Free all rsb's on rsbtbl
767 */759 */
768 rhashtable_free_and_destroy(&ls->ls_rsbtbl, rhash_free_rsb, NULL);760 rhashtable_free_and_destroy(&ls->ls_rsbtbl, rhash_free_rsb, NULL);
769 761
770 while (!list_empty(&ls->ls_new_rsb)) {
771 rsb = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb,
772 res_hashchain);
773 list_del(&rsb->res_hashchain);
774 dlm_free_rsb(rsb);
775 }
776
777 /*762 /*
778 * Free structures on any other lists763 * Free structures on any other lists
779 */764 */
fs/dlm/lowcomms.c+1−7
@@ -461,7 +461,7 @@ static bool dlm_lowcomms_con_has_addr(const struct connection *con, · 460 unmodified lines
461 return false;461 return false;
462}462}
463 463
464int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len)464int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr)
465{465{
466 struct connection *con;466 struct connection *con;
467 bool ret, idx;467 bool ret, idx;
@@ -858,12 +858,6 @@ static void free_processqueue_entry(struct processqueue_entry *pentry) · 390 unmodified lines
858 kfree(pentry);858 kfree(pentry);
859}859}
860 860
861struct dlm_processed_nodes {
862 int nodeid;
863
864 struct list_head list;
865};
866
867static void process_dlm_messages(struct work_struct *work)861static void process_dlm_messages(struct work_struct *work)
868{862{
869 struct processqueue_entry *pentry;863 struct processqueue_entry *pentry;
fs/dlm/lowcomms.h+1−1
@@ -46,7 +46,7 @@ void dlm_lowcomms_put_msg(struct dlm_msg *msg); · 45 unmodified lines
46int dlm_lowcomms_resend_msg(struct dlm_msg *msg);46int dlm_lowcomms_resend_msg(struct dlm_msg *msg);
47int dlm_lowcomms_connect_node(int nodeid);47int dlm_lowcomms_connect_node(int nodeid);
48int dlm_lowcomms_nodes_set_mark(int nodeid, unsigned int mark);48int dlm_lowcomms_nodes_set_mark(int nodeid, unsigned int mark);
49int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr, int len);49int dlm_lowcomms_addr(int nodeid, struct sockaddr_storage *addr);
50void dlm_midcomms_receive_done(int nodeid);50void dlm_midcomms_receive_done(int nodeid);
51struct kmem_cache *dlm_lowcomms_writequeue_cache_create(void);51struct kmem_cache *dlm_lowcomms_writequeue_cache_create(void);
52struct kmem_cache *dlm_lowcomms_msg_cache_create(void);52struct kmem_cache *dlm_lowcomms_msg_cache_create(void);
fs/dlm/member.c+1−1
@@ -642,7 +642,7 @@ int dlm_ls_stop(struct dlm_ls *ls) · 641 unmodified lines
642 set_bit(LSFL_RECOVER_STOP, &ls->ls_flags);642 set_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
643 new = test_and_clear_bit(LSFL_RUNNING, &ls->ls_flags);643 new = test_and_clear_bit(LSFL_RUNNING, &ls->ls_flags);
644 if (new)644 if (new)
645 timer_delete_sync(&ls->ls_timer);645 timer_delete_sync(&ls->ls_scan_timer);
646 ls->ls_recover_seq++;646 ls->ls_recover_seq++;
647 647
648 /* activate requestqueue and stop processing */648 /* activate requestqueue and stop processing */
fs/dlm/memory.c+9−1
@@ -72,6 +72,8 @@ out: · 71 unmodified lines
72 72
73void dlm_memory_exit(void)73void dlm_memory_exit(void)
74{74{
75 rcu_barrier();
76
75 kmem_cache_destroy(writequeue_cache);77 kmem_cache_destroy(writequeue_cache);
76 kmem_cache_destroy(mhandle_cache);78 kmem_cache_destroy(mhandle_cache);
77 kmem_cache_destroy(msg_cache);79 kmem_cache_destroy(msg_cache);
@@ -101,13 +103,19 @@ struct dlm_rsb *dlm_allocate_rsb(struct dlm_ls *ls) · 23 unmodified lines
101 return r;103 return r;
102}104}
103 105
104void dlm_free_rsb(struct dlm_rsb *r)106static void __free_rsb_rcu(struct rcu_head *rcu)
105{107{
108 struct dlm_rsb *r = container_of(rcu, struct dlm_rsb, rcu);
106 if (r->res_lvbptr)109 if (r->res_lvbptr)
107 dlm_free_lvb(r->res_lvbptr);110 dlm_free_lvb(r->res_lvbptr);
108 kmem_cache_free(rsb_cache, r);111 kmem_cache_free(rsb_cache, r);
109}112}
110 113
114void dlm_free_rsb(struct dlm_rsb *r)
115{
116 call_rcu(&r->rcu, __free_rsb_rcu);
117}
118
111struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)119struct dlm_lkb *dlm_allocate_lkb(struct dlm_ls *ls)
112{120{
113 struct dlm_lkb *lkb;121 struct dlm_lkb *lkb;
fs/dlm/midcomms.c+2−2
@@ -334,12 +334,12 @@ static struct midcomms_node *nodeid2node(int nodeid) · 333 unmodified lines
334 return __find_node(nodeid, nodeid_hash(nodeid));334 return __find_node(nodeid, nodeid_hash(nodeid));
335}335}
336 336
337int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr, int len)337int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr)
338{338{
339 int ret, idx, r = nodeid_hash(nodeid);339 int ret, idx, r = nodeid_hash(nodeid);
340 struct midcomms_node *node;340 struct midcomms_node *node;
341 341
342 ret = dlm_lowcomms_addr(nodeid, addr, len);342 ret = dlm_lowcomms_addr(nodeid, addr);
343 if (ret)343 if (ret)
344 return ret;344 return ret;
345 345
fs/dlm/midcomms.h+1−1
@@ -19,7 +19,7 @@ int dlm_process_incoming_buffer(int nodeid, unsigned char *buf, int buflen); · 18 unmodified lines
19struct dlm_mhandle *dlm_midcomms_get_mhandle(int nodeid, int len, char **ppc);19struct dlm_mhandle *dlm_midcomms_get_mhandle(int nodeid, int len, char **ppc);
20void dlm_midcomms_commit_mhandle(struct dlm_mhandle *mh, const void *name,20void dlm_midcomms_commit_mhandle(struct dlm_mhandle *mh, const void *name,
21 int namelen);21 int namelen);
22int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr, int len);22int dlm_midcomms_addr(int nodeid, struct sockaddr_storage *addr);
23void dlm_midcomms_version_wait(void);23void dlm_midcomms_version_wait(void);
24int dlm_midcomms_close(int nodeid);24int dlm_midcomms_close(int nodeid);
25int dlm_midcomms_start(void);25int dlm_midcomms_start(void);
fs/dlm/recover.c+40−38
@@ -293,73 +293,78 @@ static void recover_list_clear(struct dlm_ls *ls) · 292 unmodified lines
293 spin_unlock_bh(&ls->ls_recover_list_lock);293 spin_unlock_bh(&ls->ls_recover_list_lock);
294}294}
295 295
296static int recover_idr_empty(struct dlm_ls *ls)296static int recover_xa_empty(struct dlm_ls *ls)
297{297{
298 int empty = 1;298 int empty = 1;
299 299
300 spin_lock_bh(&ls->ls_recover_idr_lock);300 spin_lock_bh(&ls->ls_recover_xa_lock);
301 if (ls->ls_recover_list_count)301 if (ls->ls_recover_list_count)
302 empty = 0;302 empty = 0;
303 spin_unlock_bh(&ls->ls_recover_idr_lock);303 spin_unlock_bh(&ls->ls_recover_xa_lock);
304 304
305 return empty;305 return empty;
306}306}
307 307
308static int recover_idr_add(struct dlm_rsb *r)308static int recover_xa_add(struct dlm_rsb *r)
309{309{
310 struct dlm_ls *ls = r->res_ls;310 struct dlm_ls *ls = r->res_ls;
311 struct xa_limit limit = {
312 .min = 1,
313 .max = UINT_MAX,
314 };
315 uint32_t id;
311 int rv;316 int rv;
312 317
313 spin_lock_bh(&ls->ls_recover_idr_lock);318 spin_lock_bh(&ls->ls_recover_xa_lock);
314 if (r->res_id) {319 if (r->res_id) {
315 rv = -1;320 rv = -1;
316 goto out_unlock;321 goto out_unlock;
317 }322 }
318 rv = idr_alloc(&ls->ls_recover_idr, r, 1, 0, GFP_NOWAIT);323 rv = xa_alloc(&ls->ls_recover_xa, &id, r, limit, GFP_ATOMIC);
319 if (rv < 0)324 if (rv < 0)
320 goto out_unlock;325 goto out_unlock;
321 326
322 r->res_id = rv;327 r->res_id = id;
323 ls->ls_recover_list_count++;328 ls->ls_recover_list_count++;
324 dlm_hold_rsb(r);329 dlm_hold_rsb(r);
325 rv = 0;330 rv = 0;
326out_unlock:331out_unlock:
327 spin_unlock_bh(&ls->ls_recover_idr_lock);332 spin_unlock_bh(&ls->ls_recover_xa_lock);
328 return rv;333 return rv;
329}334}
330 335
331static void recover_idr_del(struct dlm_rsb *r)336static void recover_xa_del(struct dlm_rsb *r)
332{337{
333 struct dlm_ls *ls = r->res_ls;338 struct dlm_ls *ls = r->res_ls;
334 339
335 spin_lock_bh(&ls->ls_recover_idr_lock);340 spin_lock_bh(&ls->ls_recover_xa_lock);
336 idr_remove(&ls->ls_recover_idr, r->res_id);341 xa_erase_bh(&ls->ls_recover_xa, r->res_id);
337 r->res_id = 0;342 r->res_id = 0;
338 ls->ls_recover_list_count--;343 ls->ls_recover_list_count--;
339 spin_unlock_bh(&ls->ls_recover_idr_lock);344 spin_unlock_bh(&ls->ls_recover_xa_lock);
340 345
341 dlm_put_rsb(r);346 dlm_put_rsb(r);
342}347}
343 348
344static struct dlm_rsb *recover_idr_find(struct dlm_ls *ls, uint64_t id)349static struct dlm_rsb *recover_xa_find(struct dlm_ls *ls, uint64_t id)
345{350{
346 struct dlm_rsb *r;351 struct dlm_rsb *r;
347 352
348 spin_lock_bh(&ls->ls_recover_idr_lock);353 spin_lock_bh(&ls->ls_recover_xa_lock);
349 r = idr_find(&ls->ls_recover_idr, (int)id);354 r = xa_load(&ls->ls_recover_xa, (int)id);
350 spin_unlock_bh(&ls->ls_recover_idr_lock);355 spin_unlock_bh(&ls->ls_recover_xa_lock);
351 return r;356 return r;
352}357}
353 358
354static void recover_idr_clear(struct dlm_ls *ls)359static void recover_xa_clear(struct dlm_ls *ls)
355{360{
356 struct dlm_rsb *r;361 struct dlm_rsb *r;
357 int id;362 unsigned long id;
358 363
359 spin_lock_bh(&ls->ls_recover_idr_lock);364 spin_lock_bh(&ls->ls_recover_xa_lock);
360 365
361 idr_for_each_entry(&ls->ls_recover_idr, r, id) {366 xa_for_each(&ls->ls_recover_xa, id, r) {
362 idr_remove(&ls->ls_recover_idr, id);367 xa_erase_bh(&ls->ls_recover_xa, id);
363 r->res_id = 0;368 r->res_id = 0;
364 r->res_recover_locks_count = 0;369 r->res_recover_locks_count = 0;
365 ls->ls_recover_list_count--;370 ls->ls_recover_list_count--;
@@ -372,7 +377,7 @@ static void recover_idr_clear(struct dlm_ls *ls) · 6 unmodified lines
372 ls->ls_recover_list_count);377 ls->ls_recover_list_count);
373 ls->ls_recover_list_count = 0;378 ls->ls_recover_list_count = 0;
374 }379 }
375 spin_unlock_bh(&ls->ls_recover_idr_lock);380 spin_unlock_bh(&ls->ls_recover_xa_lock);
376}381}
377 382
378 383
@@ -470,7 +475,7 @@ static int recover_master(struct dlm_rsb *r, unsigned int *count, uint64_t seq) · 91 unmodified lines
470 set_new_master(r);475 set_new_master(r);
471 error = 0;476 error = 0;
472 } else {477 } else {
473 recover_idr_add(r);478 recover_xa_add(r);
474 error = dlm_send_rcom_lookup(r, dir_nodeid, seq);479 error = dlm_send_rcom_lookup(r, dir_nodeid, seq);
475 }480 }
476 481
@@ -551,10 +556,10 @@ int dlm_recover_masters(struct dlm_ls *ls, uint64_t seq, · 74 unmodified lines
551 556
552 log_rinfo(ls, "dlm_recover_masters %u of %u", count, total);557 log_rinfo(ls, "dlm_recover_masters %u of %u", count, total);
553 558
554 error = dlm_wait_function(ls, &recover_idr_empty);559 error = dlm_wait_function(ls, &recover_xa_empty);
555 out:560 out:
556 if (error)561 if (error)
557 recover_idr_clear(ls);562 recover_xa_clear(ls);
558 return error;563 return error;
559}564}
560 565
@@ -563,7 +568,7 @@ int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc) · 2 unmodified lines
563 struct dlm_rsb *r;568 struct dlm_rsb *r;
564 int ret_nodeid, new_master;569 int ret_nodeid, new_master;
565 570
566 r = recover_idr_find(ls, le64_to_cpu(rc->rc_id));571 r = recover_xa_find(ls, le64_to_cpu(rc->rc_id));
567 if (!r) {572 if (!r) {
568 log_error(ls, "dlm_recover_master_reply no id %llx",573 log_error(ls, "dlm_recover_master_reply no id %llx",
569 (unsigned long long)le64_to_cpu(rc->rc_id));574 (unsigned long long)le64_to_cpu(rc->rc_id));
@@ -582,9 +587,9 @@ int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc) · 12 unmodified lines
582 r->res_nodeid = new_master;587 r->res_nodeid = new_master;
583 set_new_master(r);588 set_new_master(r);
584 unlock_rsb(r);589 unlock_rsb(r);
585 recover_idr_del(r);590 recover_xa_del(r);
586 591
587 if (recover_idr_empty(ls))592 if (recover_xa_empty(ls))
588 wake_up(&ls->ls_wait_general);593 wake_up(&ls->ls_wait_general);
589 out:594 out:
590 return 0;595 return 0;
@@ -877,29 +882,26 @@ void dlm_recover_rsbs(struct dlm_ls *ls, const struct list_head *root_list) · 286 unmodified lines
877 log_rinfo(ls, "dlm_recover_rsbs %d done", count);882 log_rinfo(ls, "dlm_recover_rsbs %d done", count);
878}883}
879 884
880/* Create a single list of all root rsb's to be used during recovery */885void dlm_clear_inactive(struct dlm_ls *ls)
881
882void dlm_clear_toss(struct dlm_ls *ls)
883{886{
884 struct dlm_rsb *r, *safe;887 struct dlm_rsb *r, *safe;
885 unsigned int count = 0;888 unsigned int count = 0;
886 889
887 write_lock_bh(&ls->ls_rsbtbl_lock);890 write_lock_bh(&ls->ls_rsbtbl_lock);
888 list_for_each_entry_safe(r, safe, &ls->ls_toss, res_rsbs_list) {891 list_for_each_entry_safe(r, safe, &ls->ls_slow_inactive, res_slow_list) {
889 list_del(&r->res_rsbs_list);892 list_del(&r->res_slow_list);
890 rhashtable_remove_fast(&ls->ls_rsbtbl, &r->res_node,893 rhashtable_remove_fast(&ls->ls_rsbtbl, &r->res_node,
891 dlm_rhash_rsb_params);894 dlm_rhash_rsb_params);
892 895
893 /* remove it from the toss queue if its part of it */896 if (!list_empty(&r->res_scan_list))
894 if (!list_empty(&r->res_toss_q_list))897 list_del_init(&r->res_scan_list);
895 list_del_init(&r->res_toss_q_list);
896 898
897 free_toss_rsb(r);899 free_inactive_rsb(r);
898 count++;900 count++;
899 }901 }
900 write_unlock_bh(&ls->ls_rsbtbl_lock);902 write_unlock_bh(&ls->ls_rsbtbl_lock);
901 903
902 if (count)904 if (count)
903 log_rinfo(ls, "dlm_clear_toss %u done", count);905 log_rinfo(ls, "dlm_clear_inactive %u done", count);
904}906}
905 907
fs/dlm/recover.h+1−1
@@ -25,7 +25,7 @@ int dlm_recover_master_reply(struct dlm_ls *ls, const struct dlm_rcom *rc); · 24 unmodified lines
25int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq,25int dlm_recover_locks(struct dlm_ls *ls, uint64_t seq,
26 const struct list_head *root_list);26 const struct list_head *root_list);
27void dlm_recovered_lock(struct dlm_rsb *r);27void dlm_recovered_lock(struct dlm_rsb *r);
28void dlm_clear_toss(struct dlm_ls *ls);28void dlm_clear_inactive(struct dlm_ls *ls);
29void dlm_recover_rsbs(struct dlm_ls *ls, const struct list_head *root_list);29void dlm_recover_rsbs(struct dlm_ls *ls, const struct list_head *root_list);
30 30
31#endif /* __RECOVER_DOT_H__ */31#endif /* __RECOVER_DOT_H__ */
fs/dlm/recoverd.c+7−7
@@ -33,7 +33,7 @@ static int dlm_create_masters_list(struct dlm_ls *ls) · 32 unmodified lines
33 }33 }
34 34
35 read_lock_bh(&ls->ls_rsbtbl_lock);35 read_lock_bh(&ls->ls_rsbtbl_lock);
36 list_for_each_entry(r, &ls->ls_keep, res_rsbs_list) {36 list_for_each_entry(r, &ls->ls_slow_active, res_slow_list) {
37 if (r->res_nodeid)37 if (r->res_nodeid)
38 continue;38 continue;
39 39
@@ -63,12 +63,12 @@ static void dlm_create_root_list(struct dlm_ls *ls, struct list_head *root_list) · 23 unmodified lines
63 struct dlm_rsb *r;63 struct dlm_rsb *r;
64 64
65 read_lock_bh(&ls->ls_rsbtbl_lock);65 read_lock_bh(&ls->ls_rsbtbl_lock);
66 list_for_each_entry(r, &ls->ls_keep, res_rsbs_list) {66 list_for_each_entry(r, &ls->ls_slow_active, res_slow_list) {
67 list_add(&r->res_root_list, root_list);67 list_add(&r->res_root_list, root_list);
68 dlm_hold_rsb(r);68 dlm_hold_rsb(r);
69 }69 }
70 70
71 WARN_ON_ONCE(!list_empty(&ls->ls_toss));71 WARN_ON_ONCE(!list_empty(&ls->ls_slow_inactive));
72 read_unlock_bh(&ls->ls_rsbtbl_lock);72 read_unlock_bh(&ls->ls_rsbtbl_lock);
73}73}
74 74
@@ -98,16 +98,16 @@ static int enable_locking(struct dlm_ls *ls, uint64_t seq) · 23 unmodified lines
98 spin_lock_bh(&ls->ls_recover_lock);98 spin_lock_bh(&ls->ls_recover_lock);
99 if (ls->ls_recover_seq == seq) {99 if (ls->ls_recover_seq == seq) {
100 set_bit(LSFL_RUNNING, &ls->ls_flags);100 set_bit(LSFL_RUNNING, &ls->ls_flags);
101 /* Schedule next timer if recovery put something on toss.101 /* Schedule next timer if recovery put something on inactive.
102 *102 *
103 * The rsbs that was queued while recovery on toss hasn't103 * The rsbs that was queued while recovery on toss hasn't
104 * started yet because LSFL_RUNNING was set everything104 * started yet because LSFL_RUNNING was set everything
105 * else recovery hasn't started as well because ls_in_recovery105 * else recovery hasn't started as well because ls_in_recovery
106 * is still hold. So we should not run into the case that106 * is still hold. So we should not run into the case that
107 * dlm_timer_resume() queues a timer that can occur in107 * resume_scan_timer() queues a timer that can occur in
108 * a no op.108 * a no op.
109 */109 */
110 dlm_timer_resume(ls);110 resume_scan_timer(ls);
111 /* unblocks processes waiting to enter the dlm */111 /* unblocks processes waiting to enter the dlm */
112 up_write(&ls->ls_in_recovery);112 up_write(&ls->ls_in_recovery);
113 clear_bit(LSFL_RECOVER_LOCK, &ls->ls_flags);113 clear_bit(LSFL_RECOVER_LOCK, &ls->ls_flags);
@@ -131,7 +131,7 @@ static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv) · 17 unmodified lines
131 131
132 dlm_callback_suspend(ls);132 dlm_callback_suspend(ls);
133 133
134 dlm_clear_toss(ls);134 dlm_clear_inactive(ls);
135 135
136 /*136 /*
137 * This list of root rsb's will be the basis of most of the recovery137 * This list of root rsb's will be the basis of most of the recovery
fs/dlm/user.c+18−24
@@ -182,7 +182,7 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, uint32_t flags, int mode, · 181 unmodified lines
182 struct dlm_user_args *ua;182 struct dlm_user_args *ua;
183 struct dlm_user_proc *proc;183 struct dlm_user_proc *proc;
184 struct dlm_callback *cb;184 struct dlm_callback *cb;
185 int rv;185 int rv, copy_lvb;
186 186
187 if (test_bit(DLM_DFL_ORPHAN_BIT, &lkb->lkb_dflags) ||187 if (test_bit(DLM_DFL_ORPHAN_BIT, &lkb->lkb_dflags) ||
188 test_bit(DLM_IFL_DEAD_BIT, &lkb->lkb_iflags))188 test_bit(DLM_IFL_DEAD_BIT, &lkb->lkb_iflags))
@@ -213,28 +213,22 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, uint32_t flags, int mode, · 24 unmodified lines
213 213
214 spin_lock_bh(&proc->asts_spin);214 spin_lock_bh(&proc->asts_spin);
215 215
216 rv = dlm_queue_lkb_callback(lkb, flags, mode, status, sbflags, &cb);216 if (!dlm_may_skip_callback(lkb, flags, mode, status, sbflags,
217 switch (rv) {217 &copy_lvb)) {
218 case DLM_ENQUEUE_CALLBACK_NEED_SCHED:218 rv = dlm_get_cb(lkb, flags, mode, status, sbflags, &cb);
219 cb->ua = *ua;219 if (!rv) {
220 cb->lkb_lksb = &cb->ua.lksb;220 cb->copy_lvb = copy_lvb;
221 if (cb->copy_lvb) {221 cb->ua = *ua;
222 memcpy(cb->lvbptr, ua->lksb.sb_lvbptr,222 cb->lkb_lksb = &cb->ua.lksb;
223 DLM_USER_LVB_LEN);223 if (copy_lvb) {
224 cb->lkb_lksb->sb_lvbptr = cb->lvbptr;224 memcpy(cb->lvbptr, ua->lksb.sb_lvbptr,
225 DLM_USER_LVB_LEN);
226 cb->lkb_lksb->sb_lvbptr = cb->lvbptr;
227 }
228
229 list_add_tail(&cb->list, &proc->asts);
230 wake_up_interruptible(&proc->wait);
225 }231 }
226
227 list_add_tail(&cb->list, &proc->asts);
228 wake_up_interruptible(&proc->wait);
229 break;
230 case DLM_ENQUEUE_CALLBACK_SUCCESS:
231 break;
232 case DLM_ENQUEUE_CALLBACK_FAILURE:
233 fallthrough;
234 default:
235 spin_unlock_bh(&proc->asts_spin);
236 WARN_ON_ONCE(1);
237 goto out;
238 }232 }
239 spin_unlock_bh(&proc->asts_spin);233 spin_unlock_bh(&proc->asts_spin);
240 234
@@ -454,7 +448,7 @@ static int device_remove_lockspace(struct dlm_lspace_params *params) · 213 unmodified lines
454 if (params->flags & DLM_USER_LSFLG_FORCEFREE)448 if (params->flags & DLM_USER_LSFLG_FORCEFREE)
455 force = 2;449 force = 2;
456 450
457 lockspace = ls->ls_local_handle;451 lockspace = ls;
458 dlm_put_lockspace(ls);452 dlm_put_lockspace(ls);
459 453
460 /* The final dlm_release_lockspace waits for references to go to454 /* The final dlm_release_lockspace waits for references to go to
@@ -657,7 +651,7 @@ static int device_open(struct inode *inode, struct file *file) · 196 unmodified lines
657 return -ENOMEM;651 return -ENOMEM;
658 }652 }
659 653
660 proc->lockspace = ls->ls_local_handle;654 proc->lockspace = ls;
661 INIT_LIST_HEAD(&proc->asts);655 INIT_LIST_HEAD(&proc->asts);
662 INIT_LIST_HEAD(&proc->locks);656 INIT_LIST_HEAD(&proc->locks);
663 INIT_LIST_HEAD(&proc->unlocking);657 INIT_LIST_HEAD(&proc->unlocking);
include/linux/dlm.h+16−1
@@ -35,6 +35,9 @@ struct dlm_lockspace_ops { · 34 unmodified lines
35 int num_slots, int our_slot, uint32_t generation);35 int num_slots, int our_slot, uint32_t generation);
36};36};
37 37
38/* only relevant for kernel lockspaces, will be removed in future */
39#define DLM_LSFL_SOFTIRQ __DLM_LSFL_RESERVED0
40
38/*41/*
39 * dlm_new_lockspace42 * dlm_new_lockspace
40 *43 *
@@ -55,6 +58,11 @@ struct dlm_lockspace_ops { · 14 unmodified lines
55 * used to select the directory node. Must be the same on all nodes.58 * used to select the directory node. Must be the same on all nodes.
56 * DLM_LSFL_NEWEXCL59 * DLM_LSFL_NEWEXCL
57 * dlm_new_lockspace() should return -EEXIST if the lockspace exists.60 * dlm_new_lockspace() should return -EEXIST if the lockspace exists.
61 * DLM_LSFL_SOFTIRQ
62 * dlm request callbacks (ast, bast) are softirq safe. Flag should be
63 * preferred by users. Will be default in some future. If set the
64 * strongest context for ast, bast callback is softirq as it avoids
65 * an additional context switch.
58 *66 *
59 * lvblen: length of lvb in bytes. Must be multiple of 8.67 * lvblen: length of lvb in bytes. Must be multiple of 8.
60 * dlm_new_lockspace() returns an error if this does not match68 * dlm_new_lockspace() returns an error if this does not match
@@ -121,7 +129,14 @@ int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force); · 60 unmodified lines
121 * call.129 * call.
122 *130 *
123 * AST routines should not block (at least not for long), but may make131 * AST routines should not block (at least not for long), but may make
124 * any locking calls they please.132 * any locking calls they please. If DLM_LSFL_SOFTIRQ for kernel
133 * users of dlm_new_lockspace() is passed the ast and bast callbacks
134 * can be processed in softirq context. Also some of the callback
135 * contexts are in the same context as the DLM lock request API, users
136 * must not hold locks while calling dlm lock request API and trying
137 * to acquire this lock in the callback again, this will end in a
138 * lock recursion. For newer implementation the DLM_LSFL_SOFTIRQ
139 * should be used.
125 */140 */
126 141
127int dlm_lock(dlm_lockspace_t *lockspace,142int dlm_lock(dlm_lockspace_t *lockspace,
include/uapi/linux/dlm.h+2−0
@@ -71,6 +71,8 @@ struct dlm_lksb { · 70 unmodified lines
71/* DLM_LSFL_TIMEWARN is deprecated and reserved. DO NOT USE! */71/* DLM_LSFL_TIMEWARN is deprecated and reserved. DO NOT USE! */
72#define DLM_LSFL_TIMEWARN 0x0000000272#define DLM_LSFL_TIMEWARN 0x00000002
73#define DLM_LSFL_NEWEXCL 0x0000000873#define DLM_LSFL_NEWEXCL 0x00000008
74/* currently reserved due in-kernel use */
75#define __DLM_LSFL_RESERVED0 0x00000010
74 76
75 77
76#endif /* _UAPI__DLM_DOT_H__ */78#endif /* _UAPI__DLM_DOT_H__ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t