Commit | Line | Data |
---|---|---|
e7fd4179 DT |
1 | /****************************************************************************** |
2 | ******************************************************************************* | |
3 | ** | |
4 | ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | |
60f98d18 | 5 | ** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. |
e7fd4179 DT |
6 | ** |
7 | ** This copyrighted material is made available to anyone wishing to use, | |
8 | ** modify, copy, or redistribute it subject to the terms and conditions | |
9 | ** of the GNU General Public License v.2. | |
10 | ** | |
11 | ******************************************************************************* | |
12 | ******************************************************************************/ | |
13 | ||
14 | #include "dlm_internal.h" | |
15 | #include "lockspace.h" | |
16 | #include "member.h" | |
17 | #include "dir.h" | |
18 | #include "ast.h" | |
19 | #include "recover.h" | |
20 | #include "lowcomms.h" | |
21 | #include "lock.h" | |
22 | #include "requestqueue.h" | |
23 | #include "recoverd.h" | |
24 | ||
25 | ||
26 | /* If the start for which we're re-enabling locking (seq) has been superseded | |
c36258b5 DT |
27 | by a newer stop (ls_recover_seq), we need to leave locking disabled. |
28 | ||
29 | We suspend dlm_recv threads here to avoid the race where dlm_recv a) sees | |
30 | locking stopped and b) adds a message to the requestqueue, but dlm_recoverd | |
31 | enables locking and clears the requestqueue between a and b. */ | |
e7fd4179 DT |
32 | |
33 | static int enable_locking(struct dlm_ls *ls, uint64_t seq) | |
34 | { | |
35 | int error = -EINTR; | |
36 | ||
c36258b5 DT |
37 | down_write(&ls->ls_recv_active); |
38 | ||
e7fd4179 DT |
39 | spin_lock(&ls->ls_recover_lock); |
40 | if (ls->ls_recover_seq == seq) { | |
41 | set_bit(LSFL_RUNNING, &ls->ls_flags); | |
c36258b5 | 42 | /* unblocks processes waiting to enter the dlm */ |
e7fd4179 DT |
43 | up_write(&ls->ls_in_recovery); |
44 | error = 0; | |
45 | } | |
46 | spin_unlock(&ls->ls_recover_lock); | |
c36258b5 DT |
47 | |
48 | up_write(&ls->ls_recv_active); | |
e7fd4179 DT |
49 | return error; |
50 | } | |
51 | ||
52 | static int ls_recover(struct dlm_ls *ls, struct dlm_recover *rv) | |
53 | { | |
54 | unsigned long start; | |
55 | int error, neg = 0; | |
56 | ||
6d40c4a7 | 57 | log_debug(ls, "dlm_recover %llu", (unsigned long long)rv->seq); |
e7fd4179 | 58 | |
90135925 | 59 | mutex_lock(&ls->ls_recoverd_active); |
e7fd4179 | 60 | |
23e8e1aa | 61 | dlm_callback_suspend(ls); |
e7fd4179 DT |
62 | |
63 | /* | |
85f0379a DT |
64 | * Free non-master tossed rsb's. Master rsb's are kept on toss |
65 | * list and put on root list to be included in resdir recovery. | |
e7fd4179 DT |
66 | */ |
67 | ||
85f0379a | 68 | dlm_clear_toss_list(ls); |
e7fd4179 DT |
69 | |
70 | /* | |
85f0379a DT |
71 | * This list of root rsb's will be the basis of most of the recovery |
72 | * routines. | |
e7fd4179 DT |
73 | */ |
74 | ||
85f0379a | 75 | dlm_create_root_list(ls); |
e7fd4179 DT |
76 | |
77 | /* | |
78 | * Add or remove nodes from the lockspace's ls_nodes list. | |
e7fd4179 DT |
79 | */ |
80 | ||
81 | error = dlm_recover_members(ls, rv, &neg); | |
82 | if (error) { | |
f95a34c6 | 83 | log_debug(ls, "dlm_recover_members error %d", error); |
e7fd4179 DT |
84 | goto fail; |
85 | } | |
f95a34c6 | 86 | |
4875647a DT |
87 | ls->ls_recover_locks_in = 0; |
88 | ||
f95a34c6 DT |
89 | dlm_set_recover_status(ls, DLM_RS_NODES); |
90 | ||
91 | error = dlm_recover_members_wait(ls); | |
92 | if (error) { | |
93 | log_debug(ls, "dlm_recover_members_wait error %d", error); | |
94 | goto fail; | |
95 | } | |
96 | ||
e7fd4179 DT |
97 | start = jiffies; |
98 | ||
99 | /* | |
100 | * Rebuild our own share of the directory by collecting from all other | |
101 | * nodes their master rsb names that hash to us. | |
102 | */ | |
103 | ||
104 | error = dlm_recover_directory(ls); | |
105 | if (error) { | |
f95a34c6 | 106 | log_debug(ls, "dlm_recover_directory error %d", error); |
e7fd4179 DT |
107 | goto fail; |
108 | } | |
109 | ||
f95a34c6 | 110 | dlm_set_recover_status(ls, DLM_RS_DIR); |
e7fd4179 DT |
111 | |
112 | error = dlm_recover_directory_wait(ls); | |
113 | if (error) { | |
f95a34c6 | 114 | log_debug(ls, "dlm_recover_directory_wait error %d", error); |
e7fd4179 DT |
115 | goto fail; |
116 | } | |
117 | ||
118 | /* | |
119 | * We may have outstanding operations that are waiting for a reply from | |
120 | * a failed node. Mark these to be resent after recovery. Unlock and | |
121 | * cancel ops can just be completed. | |
122 | */ | |
123 | ||
124 | dlm_recover_waiters_pre(ls); | |
125 | ||
126 | error = dlm_recovery_stopped(ls); | |
127 | if (error) | |
128 | goto fail; | |
129 | ||
130 | if (neg || dlm_no_directory(ls)) { | |
131 | /* | |
132 | * Clear lkb's for departed nodes. | |
133 | */ | |
134 | ||
4875647a | 135 | dlm_recover_purge(ls); |
e7fd4179 DT |
136 | |
137 | /* | |
138 | * Get new master nodeid's for rsb's that were mastered on | |
139 | * departed nodes. | |
140 | */ | |
141 | ||
142 | error = dlm_recover_masters(ls); | |
143 | if (error) { | |
f95a34c6 | 144 | log_debug(ls, "dlm_recover_masters error %d", error); |
e7fd4179 DT |
145 | goto fail; |
146 | } | |
147 | ||
148 | /* | |
149 | * Send our locks on remastered rsb's to the new masters. | |
150 | */ | |
151 | ||
152 | error = dlm_recover_locks(ls); | |
153 | if (error) { | |
f95a34c6 | 154 | log_debug(ls, "dlm_recover_locks error %d", error); |
e7fd4179 DT |
155 | goto fail; |
156 | } | |
157 | ||
f95a34c6 DT |
158 | dlm_set_recover_status(ls, DLM_RS_LOCKS); |
159 | ||
e7fd4179 DT |
160 | error = dlm_recover_locks_wait(ls); |
161 | if (error) { | |
f95a34c6 | 162 | log_debug(ls, "dlm_recover_locks_wait error %d", error); |
e7fd4179 DT |
163 | goto fail; |
164 | } | |
165 | ||
4875647a DT |
166 | log_debug(ls, "dlm_recover_locks %u in", |
167 | ls->ls_recover_locks_in); | |
168 | ||
e7fd4179 DT |
169 | /* |
170 | * Finalize state in master rsb's now that all locks can be | |
171 | * checked. This includes conversion resolution and lvb | |
172 | * settings. | |
173 | */ | |
174 | ||
175 | dlm_recover_rsbs(ls); | |
91c0dc93 DT |
176 | } else { |
177 | /* | |
178 | * Other lockspace members may be going through the "neg" steps | |
179 | * while also adding us to the lockspace, in which case they'll | |
4b77f2c9 | 180 | * be doing the recover_locks (RS_LOCKS) barrier. |
91c0dc93 DT |
181 | */ |
182 | dlm_set_recover_status(ls, DLM_RS_LOCKS); | |
4b77f2c9 DT |
183 | |
184 | error = dlm_recover_locks_wait(ls); | |
185 | if (error) { | |
f95a34c6 | 186 | log_debug(ls, "dlm_recover_locks_wait error %d", error); |
4b77f2c9 DT |
187 | goto fail; |
188 | } | |
e7fd4179 DT |
189 | } |
190 | ||
191 | dlm_release_root_list(ls); | |
192 | ||
2896ee37 DT |
193 | /* |
194 | * Purge directory-related requests that are saved in requestqueue. | |
195 | * All dir requests from before recovery are invalid now due to the dir | |
196 | * rebuild and will be resent by the requesting nodes. | |
197 | */ | |
198 | ||
199 | dlm_purge_requestqueue(ls); | |
200 | ||
e7fd4179 | 201 | dlm_set_recover_status(ls, DLM_RS_DONE); |
f95a34c6 | 202 | |
e7fd4179 DT |
203 | error = dlm_recover_done_wait(ls); |
204 | if (error) { | |
f95a34c6 | 205 | log_debug(ls, "dlm_recover_done_wait error %d", error); |
e7fd4179 DT |
206 | goto fail; |
207 | } | |
208 | ||
209 | dlm_clear_members_gone(ls); | |
210 | ||
3ae1acf9 DT |
211 | dlm_adjust_timeouts(ls); |
212 | ||
23e8e1aa DT |
213 | dlm_callback_resume(ls); |
214 | ||
e7fd4179 DT |
215 | error = enable_locking(ls, rv->seq); |
216 | if (error) { | |
f95a34c6 | 217 | log_debug(ls, "enable_locking error %d", error); |
e7fd4179 DT |
218 | goto fail; |
219 | } | |
220 | ||
221 | error = dlm_process_requestqueue(ls); | |
222 | if (error) { | |
f95a34c6 | 223 | log_debug(ls, "dlm_process_requestqueue error %d", error); |
e7fd4179 DT |
224 | goto fail; |
225 | } | |
226 | ||
227 | error = dlm_recover_waiters_post(ls); | |
228 | if (error) { | |
f95a34c6 | 229 | log_debug(ls, "dlm_recover_waiters_post error %d", error); |
e7fd4179 DT |
230 | goto fail; |
231 | } | |
232 | ||
4875647a | 233 | dlm_recover_grant(ls); |
e7fd4179 | 234 | |
6d40c4a7 | 235 | log_debug(ls, "dlm_recover %llu generation %u done: %u ms", |
60f98d18 | 236 | (unsigned long long)rv->seq, ls->ls_generation, |
e7fd4179 | 237 | jiffies_to_msecs(jiffies - start)); |
90135925 | 238 | mutex_unlock(&ls->ls_recoverd_active); |
e7fd4179 | 239 | |
60f98d18 | 240 | dlm_lsop_recover_done(ls); |
e7fd4179 DT |
241 | return 0; |
242 | ||
243 | fail: | |
244 | dlm_release_root_list(ls); | |
6d40c4a7 | 245 | log_debug(ls, "dlm_recover %llu error %d", |
57adf7ee | 246 | (unsigned long long)rv->seq, error); |
90135925 | 247 | mutex_unlock(&ls->ls_recoverd_active); |
e7fd4179 DT |
248 | return error; |
249 | } | |
250 | ||
2cdc98aa DT |
251 | /* The dlm_ls_start() that created the rv we take here may already have been |
252 | stopped via dlm_ls_stop(); in that case we need to leave the RECOVERY_STOP | |
253 | flag set. */ | |
254 | ||
e7fd4179 DT |
255 | static void do_ls_recovery(struct dlm_ls *ls) |
256 | { | |
257 | struct dlm_recover *rv = NULL; | |
258 | ||
259 | spin_lock(&ls->ls_recover_lock); | |
260 | rv = ls->ls_recover_args; | |
261 | ls->ls_recover_args = NULL; | |
2cdc98aa DT |
262 | if (rv && ls->ls_recover_seq == rv->seq) |
263 | clear_bit(LSFL_RECOVERY_STOP, &ls->ls_flags); | |
e7fd4179 DT |
264 | spin_unlock(&ls->ls_recover_lock); |
265 | ||
266 | if (rv) { | |
267 | ls_recover(ls, rv); | |
60f98d18 | 268 | kfree(rv->nodes); |
e7fd4179 DT |
269 | kfree(rv); |
270 | } | |
271 | } | |
272 | ||
273 | static int dlm_recoverd(void *arg) | |
274 | { | |
275 | struct dlm_ls *ls; | |
276 | ||
277 | ls = dlm_find_lockspace_local(arg); | |
5f88f1ea DT |
278 | if (!ls) { |
279 | log_print("dlm_recoverd: no lockspace %p", arg); | |
280 | return -1; | |
281 | } | |
e7fd4179 DT |
282 | |
283 | while (!kthread_should_stop()) { | |
284 | set_current_state(TASK_INTERRUPTIBLE); | |
285 | if (!test_bit(LSFL_WORK, &ls->ls_flags)) | |
286 | schedule(); | |
287 | set_current_state(TASK_RUNNING); | |
288 | ||
289 | if (test_and_clear_bit(LSFL_WORK, &ls->ls_flags)) | |
290 | do_ls_recovery(ls); | |
291 | } | |
292 | ||
293 | dlm_put_lockspace(ls); | |
294 | return 0; | |
295 | } | |
296 | ||
297 | void dlm_recoverd_kick(struct dlm_ls *ls) | |
298 | { | |
299 | set_bit(LSFL_WORK, &ls->ls_flags); | |
300 | wake_up_process(ls->ls_recoverd_task); | |
301 | } | |
302 | ||
303 | int dlm_recoverd_start(struct dlm_ls *ls) | |
304 | { | |
305 | struct task_struct *p; | |
306 | int error = 0; | |
307 | ||
308 | p = kthread_run(dlm_recoverd, ls, "dlm_recoverd"); | |
309 | if (IS_ERR(p)) | |
310 | error = PTR_ERR(p); | |
311 | else | |
312 | ls->ls_recoverd_task = p; | |
313 | return error; | |
314 | } | |
315 | ||
316 | void dlm_recoverd_stop(struct dlm_ls *ls) | |
317 | { | |
318 | kthread_stop(ls->ls_recoverd_task); | |
319 | } | |
320 | ||
321 | void dlm_recoverd_suspend(struct dlm_ls *ls) | |
322 | { | |
f6db1b8e | 323 | wake_up(&ls->ls_wait_general); |
90135925 | 324 | mutex_lock(&ls->ls_recoverd_active); |
e7fd4179 DT |
325 | } |
326 | ||
327 | void dlm_recoverd_resume(struct dlm_ls *ls) | |
328 | { | |
90135925 | 329 | mutex_unlock(&ls->ls_recoverd_active); |
e7fd4179 DT |
330 | } |
331 |