1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
6 ** This copyrighted material is made available to anyone wishing to use,
7 ** modify, copy, or redistribute it subject to the terms and conditions
8 ** of the GNU General Public License v.2.
10 *******************************************************************************
11 ******************************************************************************/
13 #include "dlm_internal.h"
14 #include "lockspace.h"
22 * Following called by dlm_recoverd thread
25 static void add_ordered_member(struct dlm_ls
*ls
, struct dlm_member
*new)
27 struct dlm_member
*memb
= NULL
;
28 struct list_head
*tmp
;
29 struct list_head
*newlist
= &new->list
;
30 struct list_head
*head
= &ls
->ls_nodes
;
32 list_for_each(tmp
, head
) {
33 memb
= list_entry(tmp
, struct dlm_member
, list
);
34 if (new->nodeid
< memb
->nodeid
)
39 list_add_tail(newlist
, head
);
41 /* FIXME: can use list macro here */
42 newlist
->prev
= tmp
->prev
;
44 tmp
->prev
->next
= newlist
;
49 static int dlm_add_member(struct dlm_ls
*ls
, int nodeid
)
51 struct dlm_member
*memb
;
54 memb
= kzalloc(sizeof(struct dlm_member
), GFP_KERNEL
);
58 w
= dlm_node_weight(ls
->ls_name
, nodeid
);
62 memb
->nodeid
= nodeid
;
64 add_ordered_member(ls
, memb
);
69 static void dlm_remove_member(struct dlm_ls
*ls
, struct dlm_member
*memb
)
71 list_move(&memb
->list
, &ls
->ls_nodes_gone
);
75 static int dlm_is_member(struct dlm_ls
*ls
, int nodeid
)
77 struct dlm_member
*memb
;
79 list_for_each_entry(memb
, &ls
->ls_nodes
, list
) {
80 if (memb
->nodeid
== nodeid
)
86 int dlm_is_removed(struct dlm_ls
*ls
, int nodeid
)
88 struct dlm_member
*memb
;
90 list_for_each_entry(memb
, &ls
->ls_nodes_gone
, list
) {
91 if (memb
->nodeid
== nodeid
)
97 static void clear_memb_list(struct list_head
*head
)
99 struct dlm_member
*memb
;
101 while (!list_empty(head
)) {
102 memb
= list_entry(head
->next
, struct dlm_member
, list
);
103 list_del(&memb
->list
);
108 void dlm_clear_members(struct dlm_ls
*ls
)
110 clear_memb_list(&ls
->ls_nodes
);
111 ls
->ls_num_nodes
= 0;
114 void dlm_clear_members_gone(struct dlm_ls
*ls
)
116 clear_memb_list(&ls
->ls_nodes_gone
);
119 static void make_member_array(struct dlm_ls
*ls
)
121 struct dlm_member
*memb
;
122 int i
, w
, x
= 0, total
= 0, all_zero
= 0, *array
;
124 kfree(ls
->ls_node_array
);
125 ls
->ls_node_array
= NULL
;
127 list_for_each_entry(memb
, &ls
->ls_nodes
, list
) {
129 total
+= memb
->weight
;
132 /* all nodes revert to weight of 1 if all have weight 0 */
135 total
= ls
->ls_num_nodes
;
139 ls
->ls_total_weight
= total
;
141 array
= kmalloc(sizeof(int) * total
, GFP_KERNEL
);
145 list_for_each_entry(memb
, &ls
->ls_nodes
, list
) {
146 if (!all_zero
&& !memb
->weight
)
154 DLM_ASSERT(x
< total
, printk("total %d x %d\n", total
, x
););
156 for (i
= 0; i
< w
; i
++)
157 array
[x
++] = memb
->nodeid
;
160 ls
->ls_node_array
= array
;
163 /* send a status request to all members just to establish comms connections */
165 static int ping_members(struct dlm_ls
*ls
)
167 struct dlm_member
*memb
;
170 list_for_each_entry(memb
, &ls
->ls_nodes
, list
) {
171 error
= dlm_recovery_stopped(ls
);
174 error
= dlm_rcom_status(ls
, memb
->nodeid
);
179 log_debug(ls
, "ping_members aborted %d last nodeid %d",
180 error
, ls
->ls_recover_nodeid
);
184 int dlm_recover_members(struct dlm_ls
*ls
, struct dlm_recover
*rv
, int *neg_out
)
186 struct dlm_member
*memb
, *safe
;
187 int i
, error
, found
, pos
= 0, neg
= 0, low
= -1;
189 /* previously removed members that we've not finished removing need to
190 count as a negative change so the "neg" recovery steps will happen */
192 list_for_each_entry(memb
, &ls
->ls_nodes_gone
, list
) {
193 log_debug(ls
, "prev removed member %d", memb
->nodeid
);
197 /* move departed members from ls_nodes to ls_nodes_gone */
199 list_for_each_entry_safe(memb
, safe
, &ls
->ls_nodes
, list
) {
201 for (i
= 0; i
< rv
->node_count
; i
++) {
202 if (memb
->nodeid
== rv
->nodeids
[i
]) {
210 dlm_remove_member(ls
, memb
);
211 log_debug(ls
, "remove member %d", memb
->nodeid
);
215 /* add new members to ls_nodes */
217 for (i
= 0; i
< rv
->node_count
; i
++) {
218 if (dlm_is_member(ls
, rv
->nodeids
[i
]))
220 dlm_add_member(ls
, rv
->nodeids
[i
]);
222 log_debug(ls
, "add member %d", rv
->nodeids
[i
]);
225 list_for_each_entry(memb
, &ls
->ls_nodes
, list
) {
226 if (low
== -1 || memb
->nodeid
< low
)
229 ls
->ls_low_nodeid
= low
;
231 make_member_array(ls
);
232 dlm_set_recover_status(ls
, DLM_RS_NODES
);
235 error
= ping_members(ls
);
236 if (!error
|| error
== -EPROTO
) {
237 /* new_lockspace() may be waiting to know if the config
239 ls
->ls_members_result
= error
;
240 complete(&ls
->ls_members_done
);
245 error
= dlm_recover_members_wait(ls
);
247 log_debug(ls
, "total members %d error %d", ls
->ls_num_nodes
, error
);
252 * Following called from lockspace.c
255 int dlm_ls_stop(struct dlm_ls
*ls
)
260 * A stop cancels any recovery that's in progress (see RECOVERY_STOP,
261 * dlm_recovery_stopped()) and prevents any new locks from being
262 * processed (see RUNNING, dlm_locking_stopped()).
265 spin_lock(&ls
->ls_recover_lock
);
266 set_bit(LSFL_RECOVERY_STOP
, &ls
->ls_flags
);
267 new = test_and_clear_bit(LSFL_RUNNING
, &ls
->ls_flags
);
268 ls
->ls_recover_seq
++;
269 spin_unlock(&ls
->ls_recover_lock
);
272 * This in_recovery lock does two things:
274 * 1) Keeps this function from returning until all threads are out
275 * of locking routines and locking is truely stopped.
276 * 2) Keeps any new requests from being processed until it's unlocked
277 * when recovery is complete.
281 down_write(&ls
->ls_in_recovery
);
284 * The recoverd suspend/resume makes sure that dlm_recoverd (if
285 * running) has noticed the clearing of RUNNING above and quit
286 * processing the previous recovery. This will be true for all nodes
287 * before any nodes start the new recovery.
290 dlm_recoverd_suspend(ls
);
291 ls
->ls_recover_status
= 0;
292 dlm_recoverd_resume(ls
);
294 if (!ls
->ls_recover_begin
)
295 ls
->ls_recover_begin
= jiffies
;
299 int dlm_ls_start(struct dlm_ls
*ls
)
301 struct dlm_recover
*rv
= NULL
, *rv_old
;
305 rv
= kzalloc(sizeof(struct dlm_recover
), GFP_KERNEL
);
309 error
= count
= dlm_nodeid_list(ls
->ls_name
, &ids
);
313 spin_lock(&ls
->ls_recover_lock
);
315 /* the lockspace needs to be stopped before it can be started */
317 if (!dlm_locking_stopped(ls
)) {
318 spin_unlock(&ls
->ls_recover_lock
);
319 log_error(ls
, "start ignored: lockspace running");
325 rv
->node_count
= count
;
326 rv
->seq
= ++ls
->ls_recover_seq
;
327 rv_old
= ls
->ls_recover_args
;
328 ls
->ls_recover_args
= rv
;
329 spin_unlock(&ls
->ls_recover_lock
);
332 kfree(rv_old
->nodeids
);
336 dlm_recoverd_kick(ls
);
This page took 0.045918 seconds and 5 git commands to generate.