1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * defines domain join / leave apis
8 * Copyright (C) 2004 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
27 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/init.h>
32 #include <linux/spinlock.h>
33 #include <linux/delay.h>
34 #include <linux/err.h>
35 #include <linux/debugfs.h>
37 #include "cluster/heartbeat.h"
38 #include "cluster/nodemanager.h"
39 #include "cluster/tcp.h"
42 #include "dlmcommon.h"
43 #include "dlmdomain.h"
46 #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_DOMAIN)
47 #include "cluster/masklog.h"
50 * ocfs2 node maps are array of long int, which limits to send them freely
51 * across the wire due to endianness issues. To workaround this, we convert
52 * long ints to byte arrays. Following 3 routines are helper functions to
53 * set/test/copy bits within those array of bytes
55 static inline void byte_set_bit(u8 nr
, u8 map
[])
57 map
[nr
>> 3] |= (1UL << (nr
& 7));
60 static inline int byte_test_bit(u8 nr
, u8 map
[])
62 return ((1UL << (nr
& 7)) & (map
[nr
>> 3])) != 0;
65 static inline void byte_copymap(u8 dmap
[], unsigned long smap
[],
73 memset(dmap
, 0, ((sz
+ 7) >> 3));
74 for (nn
= 0 ; nn
< sz
; nn
++)
75 if (test_bit(nn
, smap
))
76 byte_set_bit(nn
, dmap
);
79 static void dlm_free_pagevec(void **vec
, int pages
)
82 free_page((unsigned long)vec
[pages
]);
86 static void **dlm_alloc_pagevec(int pages
)
88 void **vec
= kmalloc(pages
* sizeof(void *), GFP_KERNEL
);
94 for (i
= 0; i
< pages
; i
++)
95 if (!(vec
[i
] = (void *)__get_free_page(GFP_KERNEL
)))
98 mlog(0, "Allocated DLM hash pagevec; %d pages (%lu expected), %lu buckets per page\n",
99 pages
, (unsigned long)DLM_HASH_PAGES
,
100 (unsigned long)DLM_BUCKETS_PER_PAGE
);
103 dlm_free_pagevec(vec
, i
);
109 * spinlock lock ordering: if multiple locks are needed, obey this ordering:
111 * struct dlm_ctxt->spinlock
112 * struct dlm_lock_resource->spinlock
113 * struct dlm_ctxt->master_lock
114 * struct dlm_ctxt->ast_lock
115 * dlm_master_list_entry->spinlock
120 DEFINE_SPINLOCK(dlm_domain_lock
);
121 LIST_HEAD(dlm_domains
);
122 static DECLARE_WAIT_QUEUE_HEAD(dlm_domain_events
);
125 * The supported protocol version for DLM communication. Running domains
126 * will have a negotiated version with the same major number and a minor
127 * number equal or smaller. The dlm_ctxt->dlm_locking_proto field should
128 * be used to determine what a running domain is actually using.
130 * New in version 1.1:
131 * - Message DLM_QUERY_REGION added to support global heartbeat
132 * - Message DLM_QUERY_NODEINFO added to allow online node removes
133 * New in version 1.2:
134 * - Message DLM_BEGIN_EXIT_DOMAIN_MSG added to mark start of exit domain
135 * New in version 1.3:
136 * - Message DLM_DEREF_LOCKRES_DONE added to inform non-master that the
139 static const struct dlm_protocol_version dlm_protocol
= {
144 #define DLM_DOMAIN_BACKOFF_MS 200
146 static int dlm_query_join_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
148 static int dlm_assert_joined_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
150 static int dlm_cancel_join_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
152 static int dlm_query_region_handler(struct o2net_msg
*msg
, u32 len
,
153 void *data
, void **ret_data
);
154 static int dlm_exit_domain_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
156 static int dlm_protocol_compare(struct dlm_protocol_version
*existing
,
157 struct dlm_protocol_version
*request
);
159 static void dlm_unregister_domain_handlers(struct dlm_ctxt
*dlm
);
161 void __dlm_unhash_lockres(struct dlm_ctxt
*dlm
, struct dlm_lock_resource
*res
)
163 if (hlist_unhashed(&res
->hash_node
))
166 mlog(0, "%s: Unhash res %.*s\n", dlm
->name
, res
->lockname
.len
,
168 hlist_del_init(&res
->hash_node
);
169 dlm_lockres_put(res
);
172 void __dlm_insert_lockres(struct dlm_ctxt
*dlm
, struct dlm_lock_resource
*res
)
174 struct hlist_head
*bucket
;
177 assert_spin_locked(&dlm
->spinlock
);
180 bucket
= dlm_lockres_hash(dlm
, q
->hash
);
182 /* get a reference for our hashtable */
183 dlm_lockres_get(res
);
185 hlist_add_head(&res
->hash_node
, bucket
);
187 mlog(0, "%s: Hash res %.*s\n", dlm
->name
, res
->lockname
.len
,
191 struct dlm_lock_resource
* __dlm_lookup_lockres_full(struct dlm_ctxt
*dlm
,
196 struct hlist_head
*bucket
;
197 struct dlm_lock_resource
*res
;
199 mlog(0, "%.*s\n", len
, name
);
201 assert_spin_locked(&dlm
->spinlock
);
203 bucket
= dlm_lockres_hash(dlm
, hash
);
205 hlist_for_each_entry(res
, bucket
, hash_node
) {
206 if (res
->lockname
.name
[0] != name
[0])
208 if (unlikely(res
->lockname
.len
!= len
))
210 if (memcmp(res
->lockname
.name
+ 1, name
+ 1, len
- 1))
212 dlm_lockres_get(res
);
218 /* intended to be called by functions which do not care about lock
219 * resources which are being purged (most net _handler functions).
220 * this will return NULL for any lock resource which is found but
221 * currently in the process of dropping its mastery reference.
222 * use __dlm_lookup_lockres_full when you need the lock resource
223 * regardless (e.g. dlm_get_lock_resource) */
224 struct dlm_lock_resource
* __dlm_lookup_lockres(struct dlm_ctxt
*dlm
,
229 struct dlm_lock_resource
*res
= NULL
;
231 mlog(0, "%.*s\n", len
, name
);
233 assert_spin_locked(&dlm
->spinlock
);
235 res
= __dlm_lookup_lockres_full(dlm
, name
, len
, hash
);
237 spin_lock(&res
->spinlock
);
238 if (res
->state
& DLM_LOCK_RES_DROPPING_REF
) {
239 spin_unlock(&res
->spinlock
);
240 dlm_lockres_put(res
);
243 spin_unlock(&res
->spinlock
);
249 struct dlm_lock_resource
* dlm_lookup_lockres(struct dlm_ctxt
*dlm
,
253 struct dlm_lock_resource
*res
;
254 unsigned int hash
= dlm_lockid_hash(name
, len
);
256 spin_lock(&dlm
->spinlock
);
257 res
= __dlm_lookup_lockres(dlm
, name
, len
, hash
);
258 spin_unlock(&dlm
->spinlock
);
262 static struct dlm_ctxt
* __dlm_lookup_domain_full(const char *domain
, int len
)
264 struct dlm_ctxt
*tmp
;
266 assert_spin_locked(&dlm_domain_lock
);
268 /* tmp->name here is always NULL terminated,
269 * but domain may not be! */
270 list_for_each_entry(tmp
, &dlm_domains
, list
) {
271 if (strlen(tmp
->name
) == len
&&
272 memcmp(tmp
->name
, domain
, len
)==0)
279 /* For null terminated domain strings ONLY */
280 static struct dlm_ctxt
* __dlm_lookup_domain(const char *domain
)
282 assert_spin_locked(&dlm_domain_lock
);
284 return __dlm_lookup_domain_full(domain
, strlen(domain
));
288 /* returns true on one of two conditions:
289 * 1) the domain does not exist
290 * 2) the domain exists and it's state is "joined" */
291 static int dlm_wait_on_domain_helper(const char *domain
)
294 struct dlm_ctxt
*tmp
= NULL
;
296 spin_lock(&dlm_domain_lock
);
298 tmp
= __dlm_lookup_domain(domain
);
301 else if (tmp
->dlm_state
== DLM_CTXT_JOINED
)
304 spin_unlock(&dlm_domain_lock
);
308 static void dlm_free_ctxt_mem(struct dlm_ctxt
*dlm
)
310 dlm_destroy_debugfs_subroot(dlm
);
312 if (dlm
->lockres_hash
)
313 dlm_free_pagevec((void **)dlm
->lockres_hash
, DLM_HASH_PAGES
);
315 if (dlm
->master_hash
)
316 dlm_free_pagevec((void **)dlm
->master_hash
, DLM_HASH_PAGES
);
322 /* A little strange - this function will be called while holding
323 * dlm_domain_lock and is expected to be holding it on the way out. We
324 * will however drop and reacquire it multiple times */
325 static void dlm_ctxt_release(struct kref
*kref
)
327 struct dlm_ctxt
*dlm
;
329 dlm
= container_of(kref
, struct dlm_ctxt
, dlm_refs
);
331 BUG_ON(dlm
->num_joins
);
332 BUG_ON(dlm
->dlm_state
== DLM_CTXT_JOINED
);
334 /* we may still be in the list if we hit an error during join. */
335 list_del_init(&dlm
->list
);
337 spin_unlock(&dlm_domain_lock
);
339 mlog(0, "freeing memory from domain %s\n", dlm
->name
);
341 wake_up(&dlm_domain_events
);
343 dlm_free_ctxt_mem(dlm
);
345 spin_lock(&dlm_domain_lock
);
348 void dlm_put(struct dlm_ctxt
*dlm
)
350 spin_lock(&dlm_domain_lock
);
351 kref_put(&dlm
->dlm_refs
, dlm_ctxt_release
);
352 spin_unlock(&dlm_domain_lock
);
355 static void __dlm_get(struct dlm_ctxt
*dlm
)
357 kref_get(&dlm
->dlm_refs
);
360 /* given a questionable reference to a dlm object, gets a reference if
361 * it can find it in the list, otherwise returns NULL in which case
362 * you shouldn't trust your pointer. */
363 struct dlm_ctxt
*dlm_grab(struct dlm_ctxt
*dlm
)
365 struct dlm_ctxt
*target
;
366 struct dlm_ctxt
*ret
= NULL
;
368 spin_lock(&dlm_domain_lock
);
370 list_for_each_entry(target
, &dlm_domains
, list
) {
378 spin_unlock(&dlm_domain_lock
);
383 int dlm_domain_fully_joined(struct dlm_ctxt
*dlm
)
387 spin_lock(&dlm_domain_lock
);
388 ret
= (dlm
->dlm_state
== DLM_CTXT_JOINED
) ||
389 (dlm
->dlm_state
== DLM_CTXT_IN_SHUTDOWN
);
390 spin_unlock(&dlm_domain_lock
);
395 static void dlm_destroy_dlm_worker(struct dlm_ctxt
*dlm
)
397 if (dlm
->dlm_worker
) {
398 flush_workqueue(dlm
->dlm_worker
);
399 destroy_workqueue(dlm
->dlm_worker
);
400 dlm
->dlm_worker
= NULL
;
404 static void dlm_complete_dlm_shutdown(struct dlm_ctxt
*dlm
)
406 dlm_unregister_domain_handlers(dlm
);
407 dlm_debug_shutdown(dlm
);
408 dlm_complete_thread(dlm
);
409 dlm_complete_recovery_thread(dlm
);
410 dlm_destroy_dlm_worker(dlm
);
412 /* We've left the domain. Now we can take ourselves out of the
413 * list and allow the kref stuff to help us free the
415 spin_lock(&dlm_domain_lock
);
416 list_del_init(&dlm
->list
);
417 spin_unlock(&dlm_domain_lock
);
419 /* Wake up anyone waiting for us to remove this domain */
420 wake_up(&dlm_domain_events
);
423 static int dlm_migrate_all_locks(struct dlm_ctxt
*dlm
)
425 int i
, num
, n
, ret
= 0;
426 struct dlm_lock_resource
*res
;
427 struct hlist_node
*iter
;
428 struct hlist_head
*bucket
;
431 mlog(0, "Migrating locks from domain %s\n", dlm
->name
);
434 spin_lock(&dlm
->spinlock
);
435 for (i
= 0; i
< DLM_HASH_BUCKETS
; i
++) {
438 bucket
= dlm_lockres_hash(dlm
, i
);
439 iter
= bucket
->first
;
442 res
= hlist_entry(iter
, struct dlm_lock_resource
,
444 dlm_lockres_get(res
);
445 /* migrate, if necessary. this will drop the dlm
446 * spinlock and retake it if it does migration. */
447 dropped
= dlm_empty_lockres(dlm
, res
);
449 spin_lock(&res
->spinlock
);
451 __dlm_lockres_calc_usage(dlm
, res
);
453 iter
= res
->hash_node
.next
;
454 spin_unlock(&res
->spinlock
);
456 dlm_lockres_put(res
);
459 cond_resched_lock(&dlm
->spinlock
);
463 cond_resched_lock(&dlm
->spinlock
);
466 spin_unlock(&dlm
->spinlock
);
467 wake_up(&dlm
->dlm_thread_wq
);
469 /* let the dlm thread take care of purging, keep scanning until
470 * nothing remains in the hash */
472 mlog(0, "%s: %d lock resources in hash last pass\n",
476 mlog(0, "DONE Migrating locks from domain %s\n", dlm
->name
);
480 static int dlm_no_joining_node(struct dlm_ctxt
*dlm
)
484 spin_lock(&dlm
->spinlock
);
485 ret
= dlm
->joining_node
== DLM_LOCK_RES_OWNER_UNKNOWN
;
486 spin_unlock(&dlm
->spinlock
);
491 static int dlm_begin_exit_domain_handler(struct o2net_msg
*msg
, u32 len
,
492 void *data
, void **ret_data
)
494 struct dlm_ctxt
*dlm
= data
;
496 struct dlm_exit_domain
*exit_msg
= (struct dlm_exit_domain
*) msg
->buf
;
501 node
= exit_msg
->node_idx
;
502 mlog(0, "%s: Node %u sent a begin exit domain message\n", dlm
->name
, node
);
504 spin_lock(&dlm
->spinlock
);
505 set_bit(node
, dlm
->exit_domain_map
);
506 spin_unlock(&dlm
->spinlock
);
513 static void dlm_mark_domain_leaving(struct dlm_ctxt
*dlm
)
515 /* Yikes, a double spinlock! I need domain_lock for the dlm
516 * state and the dlm spinlock for join state... Sorry! */
518 spin_lock(&dlm_domain_lock
);
519 spin_lock(&dlm
->spinlock
);
521 if (dlm
->joining_node
!= DLM_LOCK_RES_OWNER_UNKNOWN
) {
522 mlog(0, "Node %d is joining, we wait on it.\n",
524 spin_unlock(&dlm
->spinlock
);
525 spin_unlock(&dlm_domain_lock
);
527 wait_event(dlm
->dlm_join_events
, dlm_no_joining_node(dlm
));
531 dlm
->dlm_state
= DLM_CTXT_LEAVING
;
532 spin_unlock(&dlm
->spinlock
);
533 spin_unlock(&dlm_domain_lock
);
536 static void __dlm_print_nodes(struct dlm_ctxt
*dlm
)
538 int node
= -1, num
= 0;
540 assert_spin_locked(&dlm
->spinlock
);
543 while ((node
= find_next_bit(dlm
->domain_map
, O2NM_MAX_NODES
,
544 node
+ 1)) < O2NM_MAX_NODES
) {
548 printk(") %u nodes\n", num
);
551 static int dlm_exit_domain_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
554 struct dlm_ctxt
*dlm
= data
;
556 struct dlm_exit_domain
*exit_msg
= (struct dlm_exit_domain
*) msg
->buf
;
558 mlog(0, "%p %u %p", msg
, len
, data
);
563 node
= exit_msg
->node_idx
;
565 spin_lock(&dlm
->spinlock
);
566 clear_bit(node
, dlm
->domain_map
);
567 clear_bit(node
, dlm
->exit_domain_map
);
568 printk(KERN_NOTICE
"o2dlm: Node %u leaves domain %s ", node
, dlm
->name
);
569 __dlm_print_nodes(dlm
);
571 /* notify anything attached to the heartbeat events */
572 dlm_hb_event_notify_attached(dlm
, node
, 0);
574 spin_unlock(&dlm
->spinlock
);
581 static int dlm_send_one_domain_exit(struct dlm_ctxt
*dlm
, u32 msg_type
,
585 struct dlm_exit_domain leave_msg
;
587 mlog(0, "%s: Sending domain exit message %u to node %u\n", dlm
->name
,
590 memset(&leave_msg
, 0, sizeof(leave_msg
));
591 leave_msg
.node_idx
= dlm
->node_num
;
593 status
= o2net_send_message(msg_type
, dlm
->key
, &leave_msg
,
594 sizeof(leave_msg
), node
, NULL
);
596 mlog(ML_ERROR
, "Error %d sending domain exit message %u "
597 "to node %u on domain %s\n", status
, msg_type
, node
,
603 static void dlm_begin_exit_domain(struct dlm_ctxt
*dlm
)
607 /* Support for begin exit domain was added in 1.2 */
608 if (dlm
->dlm_locking_proto
.pv_major
== 1 &&
609 dlm
->dlm_locking_proto
.pv_minor
< 2)
613 * Unlike DLM_EXIT_DOMAIN_MSG, DLM_BEGIN_EXIT_DOMAIN_MSG is purely
614 * informational. Meaning if a node does not receive the message,
617 spin_lock(&dlm
->spinlock
);
619 node
= find_next_bit(dlm
->domain_map
, O2NM_MAX_NODES
, node
+ 1);
620 if (node
>= O2NM_MAX_NODES
)
622 if (node
== dlm
->node_num
)
625 spin_unlock(&dlm
->spinlock
);
626 dlm_send_one_domain_exit(dlm
, DLM_BEGIN_EXIT_DOMAIN_MSG
, node
);
627 spin_lock(&dlm
->spinlock
);
629 spin_unlock(&dlm
->spinlock
);
632 static void dlm_leave_domain(struct dlm_ctxt
*dlm
)
634 int node
, clear_node
, status
;
636 /* At this point we've migrated away all our locks and won't
637 * accept mastership of new ones. The dlm is responsible for
638 * almost nothing now. We make sure not to confuse any joining
639 * nodes and then commence shutdown procedure. */
641 spin_lock(&dlm
->spinlock
);
642 /* Clear ourselves from the domain map */
643 clear_bit(dlm
->node_num
, dlm
->domain_map
);
644 while ((node
= find_next_bit(dlm
->domain_map
, O2NM_MAX_NODES
,
645 0)) < O2NM_MAX_NODES
) {
646 /* Drop the dlm spinlock. This is safe wrt the domain_map.
647 * -nodes cannot be added now as the
648 * query_join_handlers knows to respond with OK_NO_MAP
649 * -we catch the right network errors if a node is
650 * removed from the map while we're sending him the
652 spin_unlock(&dlm
->spinlock
);
656 status
= dlm_send_one_domain_exit(dlm
, DLM_EXIT_DOMAIN_MSG
,
659 status
!= -ENOPROTOOPT
&&
660 status
!= -ENOTCONN
) {
661 mlog(ML_NOTICE
, "Error %d sending domain exit message "
662 "to node %d\n", status
, node
);
664 /* Not sure what to do here but lets sleep for
665 * a bit in case this was a transient
667 msleep(DLM_DOMAIN_BACKOFF_MS
);
671 spin_lock(&dlm
->spinlock
);
672 /* If we're not clearing the node bit then we intend
673 * to loop back around to try again. */
675 clear_bit(node
, dlm
->domain_map
);
677 spin_unlock(&dlm
->spinlock
);
680 int dlm_shutting_down(struct dlm_ctxt
*dlm
)
684 spin_lock(&dlm_domain_lock
);
686 if (dlm
->dlm_state
== DLM_CTXT_IN_SHUTDOWN
)
689 spin_unlock(&dlm_domain_lock
);
694 void dlm_unregister_domain(struct dlm_ctxt
*dlm
)
697 struct dlm_lock_resource
*res
;
699 spin_lock(&dlm_domain_lock
);
700 BUG_ON(dlm
->dlm_state
!= DLM_CTXT_JOINED
);
701 BUG_ON(!dlm
->num_joins
);
704 if (!dlm
->num_joins
) {
705 /* We mark it "in shutdown" now so new register
706 * requests wait until we've completely left the
707 * domain. Don't use DLM_CTXT_LEAVING yet as we still
708 * want new domain joins to communicate with us at
709 * least until we've completed migration of our
711 dlm
->dlm_state
= DLM_CTXT_IN_SHUTDOWN
;
714 spin_unlock(&dlm_domain_lock
);
717 mlog(0, "shutting down domain %s\n", dlm
->name
);
718 dlm_begin_exit_domain(dlm
);
720 /* We changed dlm state, notify the thread */
721 dlm_kick_thread(dlm
, NULL
);
723 while (dlm_migrate_all_locks(dlm
)) {
724 /* Give dlm_thread time to purge the lockres' */
726 mlog(0, "%s: more migration to do\n", dlm
->name
);
729 /* This list should be empty. If not, print remaining lockres */
730 if (!list_empty(&dlm
->tracking_list
)) {
731 mlog(ML_ERROR
, "Following lockres' are still on the "
733 list_for_each_entry(res
, &dlm
->tracking_list
, tracking
)
734 dlm_print_one_lock_resource(res
);
737 dlm_mark_domain_leaving(dlm
);
738 dlm_leave_domain(dlm
);
739 printk(KERN_NOTICE
"o2dlm: Leaving domain %s\n", dlm
->name
);
740 dlm_force_free_mles(dlm
);
741 dlm_complete_dlm_shutdown(dlm
);
745 EXPORT_SYMBOL_GPL(dlm_unregister_domain
);
747 static int dlm_query_join_proto_check(char *proto_type
, int node
,
748 struct dlm_protocol_version
*ours
,
749 struct dlm_protocol_version
*request
)
752 struct dlm_protocol_version proto
= *request
;
754 if (!dlm_protocol_compare(ours
, &proto
)) {
756 "node %u wanted to join with %s locking protocol "
757 "%u.%u, we respond with %u.%u\n",
761 proto
.pv_major
, proto
.pv_minor
);
762 request
->pv_minor
= proto
.pv_minor
;
766 "Node %u wanted to join with %s locking "
767 "protocol %u.%u, but we have %u.%u, disallowing\n",
780 * struct dlm_query_join_packet is made up of four one-byte fields. They
781 * are effectively in big-endian order already. However, little-endian
782 * machines swap them before putting the packet on the wire (because
783 * query_join's response is a status, and that status is treated as a u32
784 * on the wire). Thus, a big-endian and little-endian machines will treat
785 * this structure differently.
787 * The solution is to have little-endian machines swap the structure when
788 * converting from the structure to the u32 representation. This will
789 * result in the structure having the correct format on the wire no matter
790 * the host endian format.
792 static void dlm_query_join_packet_to_wire(struct dlm_query_join_packet
*packet
,
795 union dlm_query_join_response response
;
797 response
.packet
= *packet
;
798 *wire
= be32_to_cpu(response
.intval
);
801 static void dlm_query_join_wire_to_packet(u32 wire
,
802 struct dlm_query_join_packet
*packet
)
804 union dlm_query_join_response response
;
806 response
.intval
= cpu_to_be32(wire
);
807 *packet
= response
.packet
;
810 static int dlm_query_join_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
813 struct dlm_query_join_request
*query
;
814 struct dlm_query_join_packet packet
= {
815 .code
= JOIN_DISALLOW
,
817 struct dlm_ctxt
*dlm
= NULL
;
821 query
= (struct dlm_query_join_request
*) msg
->buf
;
823 mlog(0, "node %u wants to join domain %s\n", query
->node_idx
,
827 * If heartbeat doesn't consider the node live, tell it
828 * to back off and try again. This gives heartbeat a chance
831 if (!o2hb_check_node_heartbeating_no_sem(query
->node_idx
)) {
832 mlog(0, "node %u is not in our live map yet\n",
835 packet
.code
= JOIN_DISALLOW
;
839 packet
.code
= JOIN_OK_NO_MAP
;
841 spin_lock(&dlm_domain_lock
);
842 dlm
= __dlm_lookup_domain_full(query
->domain
, query
->name_len
);
847 * There is a small window where the joining node may not see the
848 * node(s) that just left but still part of the cluster. DISALLOW
849 * join request if joining node has different node map.
852 while (nodenum
< O2NM_MAX_NODES
) {
853 if (test_bit(nodenum
, dlm
->domain_map
)) {
854 if (!byte_test_bit(nodenum
, query
->node_map
)) {
855 mlog(0, "disallow join as node %u does not "
856 "have node %u in its nodemap\n",
857 query
->node_idx
, nodenum
);
858 packet
.code
= JOIN_DISALLOW
;
865 /* Once the dlm ctxt is marked as leaving then we don't want
866 * to be put in someone's domain map.
867 * Also, explicitly disallow joining at certain troublesome
868 * times (ie. during recovery). */
869 if (dlm
->dlm_state
!= DLM_CTXT_LEAVING
) {
870 int bit
= query
->node_idx
;
871 spin_lock(&dlm
->spinlock
);
873 if (dlm
->dlm_state
== DLM_CTXT_NEW
&&
874 dlm
->joining_node
== DLM_LOCK_RES_OWNER_UNKNOWN
) {
875 /*If this is a brand new context and we
876 * haven't started our join process yet, then
877 * the other node won the race. */
878 packet
.code
= JOIN_OK_NO_MAP
;
879 } else if (dlm
->joining_node
!= DLM_LOCK_RES_OWNER_UNKNOWN
) {
880 /* Disallow parallel joins. */
881 packet
.code
= JOIN_DISALLOW
;
882 } else if (dlm
->reco
.state
& DLM_RECO_STATE_ACTIVE
) {
883 mlog(0, "node %u trying to join, but recovery "
884 "is ongoing.\n", bit
);
885 packet
.code
= JOIN_DISALLOW
;
886 } else if (test_bit(bit
, dlm
->recovery_map
)) {
887 mlog(0, "node %u trying to join, but it "
888 "still needs recovery.\n", bit
);
889 packet
.code
= JOIN_DISALLOW
;
890 } else if (test_bit(bit
, dlm
->domain_map
)) {
891 mlog(0, "node %u trying to join, but it "
892 "is still in the domain! needs recovery?\n",
894 packet
.code
= JOIN_DISALLOW
;
896 /* Alright we're fully a part of this domain
897 * so we keep some state as to who's joining
898 * and indicate to him that needs to be fixed
901 /* Make sure we speak compatible locking protocols. */
902 if (dlm_query_join_proto_check("DLM", bit
,
903 &dlm
->dlm_locking_proto
,
904 &query
->dlm_proto
)) {
905 packet
.code
= JOIN_PROTOCOL_MISMATCH
;
906 } else if (dlm_query_join_proto_check("fs", bit
,
907 &dlm
->fs_locking_proto
,
909 packet
.code
= JOIN_PROTOCOL_MISMATCH
;
911 packet
.dlm_minor
= query
->dlm_proto
.pv_minor
;
912 packet
.fs_minor
= query
->fs_proto
.pv_minor
;
913 packet
.code
= JOIN_OK
;
914 __dlm_set_joining_node(dlm
, query
->node_idx
);
918 spin_unlock(&dlm
->spinlock
);
921 spin_unlock(&dlm_domain_lock
);
924 mlog(0, "We respond with %u\n", packet
.code
);
926 dlm_query_join_packet_to_wire(&packet
, &response
);
930 static int dlm_assert_joined_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
933 struct dlm_assert_joined
*assert;
934 struct dlm_ctxt
*dlm
= NULL
;
936 assert = (struct dlm_assert_joined
*) msg
->buf
;
938 mlog(0, "node %u asserts join on domain %s\n", assert->node_idx
,
941 spin_lock(&dlm_domain_lock
);
942 dlm
= __dlm_lookup_domain_full(assert->domain
, assert->name_len
);
943 /* XXX should we consider no dlm ctxt an error? */
945 spin_lock(&dlm
->spinlock
);
947 /* Alright, this node has officially joined our
948 * domain. Set him in the map and clean up our
949 * leftover join state. */
950 BUG_ON(dlm
->joining_node
!= assert->node_idx
);
952 if (dlm
->reco
.state
& DLM_RECO_STATE_ACTIVE
) {
953 mlog(0, "dlm recovery is ongoing, disallow join\n");
954 spin_unlock(&dlm
->spinlock
);
955 spin_unlock(&dlm_domain_lock
);
959 set_bit(assert->node_idx
, dlm
->domain_map
);
960 clear_bit(assert->node_idx
, dlm
->exit_domain_map
);
961 __dlm_set_joining_node(dlm
, DLM_LOCK_RES_OWNER_UNKNOWN
);
963 printk(KERN_NOTICE
"o2dlm: Node %u joins domain %s ",
964 assert->node_idx
, dlm
->name
);
965 __dlm_print_nodes(dlm
);
967 /* notify anything attached to the heartbeat events */
968 dlm_hb_event_notify_attached(dlm
, assert->node_idx
, 1);
970 spin_unlock(&dlm
->spinlock
);
972 spin_unlock(&dlm_domain_lock
);
977 static int dlm_match_regions(struct dlm_ctxt
*dlm
,
978 struct dlm_query_region
*qr
,
979 char *local
, int locallen
)
981 char *remote
= qr
->qr_regions
;
983 int localnr
, i
, j
, foundit
;
986 if (!o2hb_global_heartbeat_active()) {
987 if (qr
->qr_numregions
) {
988 mlog(ML_ERROR
, "Domain %s: Joining node %d has global "
989 "heartbeat enabled but local node %d does not\n",
990 qr
->qr_domain
, qr
->qr_node
, dlm
->node_num
);
996 if (o2hb_global_heartbeat_active() && !qr
->qr_numregions
) {
997 mlog(ML_ERROR
, "Domain %s: Local node %d has global "
998 "heartbeat enabled but joining node %d does not\n",
999 qr
->qr_domain
, dlm
->node_num
, qr
->qr_node
);
1005 for (i
= 0; i
< qr
->qr_numregions
; ++i
) {
1006 mlog(0, "Region %.*s\n", O2HB_MAX_REGION_NAME_LEN
, r
);
1007 r
+= O2HB_MAX_REGION_NAME_LEN
;
1010 localnr
= min(O2NM_MAX_REGIONS
, locallen
/O2HB_MAX_REGION_NAME_LEN
);
1011 localnr
= o2hb_get_all_regions(local
, (u8
)localnr
);
1013 /* compare local regions with remote */
1015 for (i
= 0; i
< localnr
; ++i
) {
1018 for (j
= 0; j
<= qr
->qr_numregions
; ++j
) {
1019 if (!memcmp(l
, r
, O2HB_MAX_REGION_NAME_LEN
)) {
1023 r
+= O2HB_MAX_REGION_NAME_LEN
;
1027 mlog(ML_ERROR
, "Domain %s: Region '%.*s' registered "
1028 "in local node %d but not in joining node %d\n",
1029 qr
->qr_domain
, O2HB_MAX_REGION_NAME_LEN
, l
,
1030 dlm
->node_num
, qr
->qr_node
);
1033 l
+= O2HB_MAX_REGION_NAME_LEN
;
1036 /* compare remote with local regions */
1038 for (i
= 0; i
< qr
->qr_numregions
; ++i
) {
1041 for (j
= 0; j
< localnr
; ++j
) {
1042 if (!memcmp(r
, l
, O2HB_MAX_REGION_NAME_LEN
)) {
1046 l
+= O2HB_MAX_REGION_NAME_LEN
;
1050 mlog(ML_ERROR
, "Domain %s: Region '%.*s' registered "
1051 "in joining node %d but not in local node %d\n",
1052 qr
->qr_domain
, O2HB_MAX_REGION_NAME_LEN
, r
,
1053 qr
->qr_node
, dlm
->node_num
);
1056 r
+= O2HB_MAX_REGION_NAME_LEN
;
1063 static int dlm_send_regions(struct dlm_ctxt
*dlm
, unsigned long *node_map
)
1065 struct dlm_query_region
*qr
= NULL
;
1066 int status
, ret
= 0, i
;
1069 if (find_next_bit(node_map
, O2NM_MAX_NODES
, 0) >= O2NM_MAX_NODES
)
1072 qr
= kzalloc(sizeof(struct dlm_query_region
), GFP_KERNEL
);
1079 qr
->qr_node
= dlm
->node_num
;
1080 qr
->qr_namelen
= strlen(dlm
->name
);
1081 memcpy(qr
->qr_domain
, dlm
->name
, qr
->qr_namelen
);
1082 /* if local hb, the numregions will be zero */
1083 if (o2hb_global_heartbeat_active())
1084 qr
->qr_numregions
= o2hb_get_all_regions(qr
->qr_regions
,
1088 for (i
= 0; i
< qr
->qr_numregions
; ++i
, p
+= O2HB_MAX_REGION_NAME_LEN
)
1089 mlog(0, "Region %.*s\n", O2HB_MAX_REGION_NAME_LEN
, p
);
1092 while ((i
= find_next_bit(node_map
, O2NM_MAX_NODES
,
1093 i
+ 1)) < O2NM_MAX_NODES
) {
1094 if (i
== dlm
->node_num
)
1097 mlog(0, "Sending regions to node %d\n", i
);
1099 ret
= o2net_send_message(DLM_QUERY_REGION
, DLM_MOD_KEY
, qr
,
1100 sizeof(struct dlm_query_region
),
1105 mlog(ML_ERROR
, "Region mismatch %d, node %d\n",
1116 static int dlm_query_region_handler(struct o2net_msg
*msg
, u32 len
,
1117 void *data
, void **ret_data
)
1119 struct dlm_query_region
*qr
;
1120 struct dlm_ctxt
*dlm
= NULL
;
1124 qr
= (struct dlm_query_region
*) msg
->buf
;
1126 mlog(0, "Node %u queries hb regions on domain %s\n", qr
->qr_node
,
1129 /* buffer used in dlm_mast_regions() */
1130 local
= kmalloc(sizeof(qr
->qr_regions
), GFP_KERNEL
);
1136 spin_lock(&dlm_domain_lock
);
1137 dlm
= __dlm_lookup_domain_full(qr
->qr_domain
, qr
->qr_namelen
);
1139 mlog(ML_ERROR
, "Node %d queried hb regions on domain %s "
1140 "before join domain\n", qr
->qr_node
, qr
->qr_domain
);
1141 goto out_domain_lock
;
1144 spin_lock(&dlm
->spinlock
);
1145 if (dlm
->joining_node
!= qr
->qr_node
) {
1146 mlog(ML_ERROR
, "Node %d queried hb regions on domain %s "
1147 "but joining node is %d\n", qr
->qr_node
, qr
->qr_domain
,
1152 /* Support for global heartbeat was added in 1.1 */
1153 if (dlm
->dlm_locking_proto
.pv_major
== 1 &&
1154 dlm
->dlm_locking_proto
.pv_minor
== 0) {
1155 mlog(ML_ERROR
, "Node %d queried hb regions on domain %s "
1156 "but active dlm protocol is %d.%d\n", qr
->qr_node
,
1157 qr
->qr_domain
, dlm
->dlm_locking_proto
.pv_major
,
1158 dlm
->dlm_locking_proto
.pv_minor
);
1162 status
= dlm_match_regions(dlm
, qr
, local
, sizeof(qr
->qr_regions
));
1165 spin_unlock(&dlm
->spinlock
);
1168 spin_unlock(&dlm_domain_lock
);
1175 static int dlm_match_nodes(struct dlm_ctxt
*dlm
, struct dlm_query_nodeinfo
*qn
)
1177 struct o2nm_node
*local
;
1178 struct dlm_node_info
*remote
;
1182 for (j
= 0; j
< qn
->qn_numnodes
; ++j
)
1183 mlog(0, "Node %3d, %pI4:%u\n", qn
->qn_nodes
[j
].ni_nodenum
,
1184 &(qn
->qn_nodes
[j
].ni_ipv4_address
),
1185 ntohs(qn
->qn_nodes
[j
].ni_ipv4_port
));
1187 for (i
= 0; i
< O2NM_MAX_NODES
&& !status
; ++i
) {
1188 local
= o2nm_get_node_by_num(i
);
1190 for (j
= 0; j
< qn
->qn_numnodes
; ++j
) {
1191 if (qn
->qn_nodes
[j
].ni_nodenum
== i
) {
1192 remote
= &(qn
->qn_nodes
[j
]);
1197 if (!local
&& !remote
)
1200 if ((local
&& !remote
) || (!local
&& remote
))
1204 ((remote
->ni_nodenum
!= local
->nd_num
) ||
1205 (remote
->ni_ipv4_port
!= local
->nd_ipv4_port
) ||
1206 (remote
->ni_ipv4_address
!= local
->nd_ipv4_address
)))
1210 if (remote
&& !local
)
1211 mlog(ML_ERROR
, "Domain %s: Node %d (%pI4:%u) "
1212 "registered in joining node %d but not in "
1213 "local node %d\n", qn
->qn_domain
,
1215 &(remote
->ni_ipv4_address
),
1216 ntohs(remote
->ni_ipv4_port
),
1217 qn
->qn_nodenum
, dlm
->node_num
);
1218 if (local
&& !remote
)
1219 mlog(ML_ERROR
, "Domain %s: Node %d (%pI4:%u) "
1220 "registered in local node %d but not in "
1221 "joining node %d\n", qn
->qn_domain
,
1222 local
->nd_num
, &(local
->nd_ipv4_address
),
1223 ntohs(local
->nd_ipv4_port
),
1224 dlm
->node_num
, qn
->qn_nodenum
);
1225 BUG_ON((!local
&& !remote
));
1229 o2nm_node_put(local
);
1235 static int dlm_send_nodeinfo(struct dlm_ctxt
*dlm
, unsigned long *node_map
)
1237 struct dlm_query_nodeinfo
*qn
= NULL
;
1238 struct o2nm_node
*node
;
1239 int ret
= 0, status
, count
, i
;
1241 if (find_next_bit(node_map
, O2NM_MAX_NODES
, 0) >= O2NM_MAX_NODES
)
1244 qn
= kzalloc(sizeof(struct dlm_query_nodeinfo
), GFP_KERNEL
);
1251 for (i
= 0, count
= 0; i
< O2NM_MAX_NODES
; ++i
) {
1252 node
= o2nm_get_node_by_num(i
);
1255 qn
->qn_nodes
[count
].ni_nodenum
= node
->nd_num
;
1256 qn
->qn_nodes
[count
].ni_ipv4_port
= node
->nd_ipv4_port
;
1257 qn
->qn_nodes
[count
].ni_ipv4_address
= node
->nd_ipv4_address
;
1258 mlog(0, "Node %3d, %pI4:%u\n", node
->nd_num
,
1259 &(node
->nd_ipv4_address
), ntohs(node
->nd_ipv4_port
));
1261 o2nm_node_put(node
);
1264 qn
->qn_nodenum
= dlm
->node_num
;
1265 qn
->qn_numnodes
= count
;
1266 qn
->qn_namelen
= strlen(dlm
->name
);
1267 memcpy(qn
->qn_domain
, dlm
->name
, qn
->qn_namelen
);
1270 while ((i
= find_next_bit(node_map
, O2NM_MAX_NODES
,
1271 i
+ 1)) < O2NM_MAX_NODES
) {
1272 if (i
== dlm
->node_num
)
1275 mlog(0, "Sending nodeinfo to node %d\n", i
);
1277 ret
= o2net_send_message(DLM_QUERY_NODEINFO
, DLM_MOD_KEY
,
1278 qn
, sizeof(struct dlm_query_nodeinfo
),
1283 mlog(ML_ERROR
, "node mismatch %d, node %d\n", ret
, i
);
1293 static int dlm_query_nodeinfo_handler(struct o2net_msg
*msg
, u32 len
,
1294 void *data
, void **ret_data
)
1296 struct dlm_query_nodeinfo
*qn
;
1297 struct dlm_ctxt
*dlm
= NULL
;
1298 int locked
= 0, status
= -EINVAL
;
1300 qn
= (struct dlm_query_nodeinfo
*) msg
->buf
;
1302 mlog(0, "Node %u queries nodes on domain %s\n", qn
->qn_nodenum
,
1305 spin_lock(&dlm_domain_lock
);
1306 dlm
= __dlm_lookup_domain_full(qn
->qn_domain
, qn
->qn_namelen
);
1308 mlog(ML_ERROR
, "Node %d queried nodes on domain %s before "
1309 "join domain\n", qn
->qn_nodenum
, qn
->qn_domain
);
1313 spin_lock(&dlm
->spinlock
);
1315 if (dlm
->joining_node
!= qn
->qn_nodenum
) {
1316 mlog(ML_ERROR
, "Node %d queried nodes on domain %s but "
1317 "joining node is %d\n", qn
->qn_nodenum
, qn
->qn_domain
,
1322 /* Support for node query was added in 1.1 */
1323 if (dlm
->dlm_locking_proto
.pv_major
== 1 &&
1324 dlm
->dlm_locking_proto
.pv_minor
== 0) {
1325 mlog(ML_ERROR
, "Node %d queried nodes on domain %s "
1326 "but active dlm protocol is %d.%d\n", qn
->qn_nodenum
,
1327 qn
->qn_domain
, dlm
->dlm_locking_proto
.pv_major
,
1328 dlm
->dlm_locking_proto
.pv_minor
);
1332 status
= dlm_match_nodes(dlm
, qn
);
1336 spin_unlock(&dlm
->spinlock
);
1337 spin_unlock(&dlm_domain_lock
);
1342 static int dlm_cancel_join_handler(struct o2net_msg
*msg
, u32 len
, void *data
,
1345 struct dlm_cancel_join
*cancel
;
1346 struct dlm_ctxt
*dlm
= NULL
;
1348 cancel
= (struct dlm_cancel_join
*) msg
->buf
;
1350 mlog(0, "node %u cancels join on domain %s\n", cancel
->node_idx
,
1353 spin_lock(&dlm_domain_lock
);
1354 dlm
= __dlm_lookup_domain_full(cancel
->domain
, cancel
->name_len
);
1357 spin_lock(&dlm
->spinlock
);
1359 /* Yikes, this guy wants to cancel his join. No
1360 * problem, we simply cleanup our join state. */
1361 BUG_ON(dlm
->joining_node
!= cancel
->node_idx
);
1362 __dlm_set_joining_node(dlm
, DLM_LOCK_RES_OWNER_UNKNOWN
);
1364 spin_unlock(&dlm
->spinlock
);
1366 spin_unlock(&dlm_domain_lock
);
1371 static int dlm_send_one_join_cancel(struct dlm_ctxt
*dlm
,
1375 struct dlm_cancel_join cancel_msg
;
1377 memset(&cancel_msg
, 0, sizeof(cancel_msg
));
1378 cancel_msg
.node_idx
= dlm
->node_num
;
1379 cancel_msg
.name_len
= strlen(dlm
->name
);
1380 memcpy(cancel_msg
.domain
, dlm
->name
, cancel_msg
.name_len
);
1382 status
= o2net_send_message(DLM_CANCEL_JOIN_MSG
, DLM_MOD_KEY
,
1383 &cancel_msg
, sizeof(cancel_msg
), node
,
1386 mlog(ML_ERROR
, "Error %d when sending message %u (key 0x%x) to "
1387 "node %u\n", status
, DLM_CANCEL_JOIN_MSG
, DLM_MOD_KEY
,
1396 /* map_size should be in bytes. */
1397 static int dlm_send_join_cancels(struct dlm_ctxt
*dlm
,
1398 unsigned long *node_map
,
1399 unsigned int map_size
)
1401 int status
, tmpstat
;
1404 if (map_size
!= (BITS_TO_LONGS(O2NM_MAX_NODES
) *
1405 sizeof(unsigned long))) {
1407 "map_size %u != BITS_TO_LONGS(O2NM_MAX_NODES) %u\n",
1408 map_size
, (unsigned)BITS_TO_LONGS(O2NM_MAX_NODES
));
1414 while ((node
= find_next_bit(node_map
, O2NM_MAX_NODES
,
1415 node
+ 1)) < O2NM_MAX_NODES
) {
1416 if (node
== dlm
->node_num
)
1419 tmpstat
= dlm_send_one_join_cancel(dlm
, node
);
1421 mlog(ML_ERROR
, "Error return %d cancelling join on "
1422 "node %d\n", tmpstat
, node
);
1433 static int dlm_request_join(struct dlm_ctxt
*dlm
,
1435 enum dlm_query_join_response_code
*response
)
1438 struct dlm_query_join_request join_msg
;
1439 struct dlm_query_join_packet packet
;
1442 mlog(0, "querying node %d\n", node
);
1444 memset(&join_msg
, 0, sizeof(join_msg
));
1445 join_msg
.node_idx
= dlm
->node_num
;
1446 join_msg
.name_len
= strlen(dlm
->name
);
1447 memcpy(join_msg
.domain
, dlm
->name
, join_msg
.name_len
);
1448 join_msg
.dlm_proto
= dlm
->dlm_locking_proto
;
1449 join_msg
.fs_proto
= dlm
->fs_locking_proto
;
1451 /* copy live node map to join message */
1452 byte_copymap(join_msg
.node_map
, dlm
->live_nodes_map
, O2NM_MAX_NODES
);
1454 status
= o2net_send_message(DLM_QUERY_JOIN_MSG
, DLM_MOD_KEY
, &join_msg
,
1455 sizeof(join_msg
), node
, &join_resp
);
1456 if (status
< 0 && status
!= -ENOPROTOOPT
) {
1457 mlog(ML_ERROR
, "Error %d when sending message %u (key 0x%x) to "
1458 "node %u\n", status
, DLM_QUERY_JOIN_MSG
, DLM_MOD_KEY
,
1462 dlm_query_join_wire_to_packet(join_resp
, &packet
);
1464 /* -ENOPROTOOPT from the net code means the other side isn't
1465 listening for our message type -- that's fine, it means
1466 his dlm isn't up, so we can consider him a 'yes' but not
1467 joined into the domain. */
1468 if (status
== -ENOPROTOOPT
) {
1470 *response
= JOIN_OK_NO_MAP
;
1472 *response
= packet
.code
;
1473 switch (packet
.code
) {
1475 case JOIN_OK_NO_MAP
:
1477 case JOIN_PROTOCOL_MISMATCH
:
1479 "This node requested DLM locking protocol %u.%u and "
1480 "filesystem locking protocol %u.%u. At least one of "
1481 "the protocol versions on node %d is not compatible, "
1483 dlm
->dlm_locking_proto
.pv_major
,
1484 dlm
->dlm_locking_proto
.pv_minor
,
1485 dlm
->fs_locking_proto
.pv_major
,
1486 dlm
->fs_locking_proto
.pv_minor
,
1491 /* Use the same locking protocol as the remote node */
1492 dlm
->dlm_locking_proto
.pv_minor
= packet
.dlm_minor
;
1493 dlm
->fs_locking_proto
.pv_minor
= packet
.fs_minor
;
1495 "Node %d responds JOIN_OK with DLM locking protocol "
1496 "%u.%u and fs locking protocol %u.%u\n",
1498 dlm
->dlm_locking_proto
.pv_major
,
1499 dlm
->dlm_locking_proto
.pv_minor
,
1500 dlm
->fs_locking_proto
.pv_major
,
1501 dlm
->fs_locking_proto
.pv_minor
);
1505 mlog(ML_ERROR
, "invalid response %d from node %u\n",
1507 /* Reset response to JOIN_DISALLOW */
1508 *response
= JOIN_DISALLOW
;
1513 mlog(0, "status %d, node %d response is %d\n", status
, node
,
1520 static int dlm_send_one_join_assert(struct dlm_ctxt
*dlm
,
1525 struct dlm_assert_joined assert_msg
;
1527 mlog(0, "Sending join assert to node %u\n", node
);
1529 memset(&assert_msg
, 0, sizeof(assert_msg
));
1530 assert_msg
.node_idx
= dlm
->node_num
;
1531 assert_msg
.name_len
= strlen(dlm
->name
);
1532 memcpy(assert_msg
.domain
, dlm
->name
, assert_msg
.name_len
);
1534 status
= o2net_send_message(DLM_ASSERT_JOINED_MSG
, DLM_MOD_KEY
,
1535 &assert_msg
, sizeof(assert_msg
), node
,
1538 mlog(ML_ERROR
, "Error %d when sending message %u (key 0x%x) to "
1539 "node %u\n", status
, DLM_ASSERT_JOINED_MSG
, DLM_MOD_KEY
,
1547 static void dlm_send_join_asserts(struct dlm_ctxt
*dlm
,
1548 unsigned long *node_map
)
1550 int status
, node
, live
;
1554 while ((node
= find_next_bit(node_map
, O2NM_MAX_NODES
,
1555 node
+ 1)) < O2NM_MAX_NODES
) {
1556 if (node
== dlm
->node_num
)
1560 /* It is very important that this message be
1561 * received so we spin until either the node
1562 * has died or it gets the message. */
1563 status
= dlm_send_one_join_assert(dlm
, node
);
1565 spin_lock(&dlm
->spinlock
);
1566 live
= test_bit(node
, dlm
->live_nodes_map
);
1567 spin_unlock(&dlm
->spinlock
);
1570 mlog(ML_ERROR
, "Error return %d asserting "
1571 "join on node %d\n", status
, node
);
1573 /* give us some time between errors... */
1575 msleep(DLM_DOMAIN_BACKOFF_MS
);
1577 } while (status
&& live
);
1581 struct domain_join_ctxt
{
1582 unsigned long live_map
[BITS_TO_LONGS(O2NM_MAX_NODES
)];
1583 unsigned long yes_resp_map
[BITS_TO_LONGS(O2NM_MAX_NODES
)];
1586 static int dlm_should_restart_join(struct dlm_ctxt
*dlm
,
1587 struct domain_join_ctxt
*ctxt
,
1588 enum dlm_query_join_response_code response
)
1592 if (response
== JOIN_DISALLOW
) {
1593 mlog(0, "Latest response of disallow -- should restart\n");
1597 spin_lock(&dlm
->spinlock
);
1598 /* For now, we restart the process if the node maps have
1600 ret
= memcmp(ctxt
->live_map
, dlm
->live_nodes_map
,
1601 sizeof(dlm
->live_nodes_map
));
1602 spin_unlock(&dlm
->spinlock
);
1605 mlog(0, "Node maps changed -- should restart\n");
1610 static int dlm_try_to_join_domain(struct dlm_ctxt
*dlm
)
1612 int status
= 0, tmpstat
, node
;
1613 struct domain_join_ctxt
*ctxt
;
1614 enum dlm_query_join_response_code response
= JOIN_DISALLOW
;
1618 ctxt
= kzalloc(sizeof(*ctxt
), GFP_KERNEL
);
1625 /* group sem locking should work for us here -- we're already
1626 * registered for heartbeat events so filling this should be
1627 * atomic wrt getting those handlers called. */
1628 o2hb_fill_node_map(dlm
->live_nodes_map
, sizeof(dlm
->live_nodes_map
));
1630 spin_lock(&dlm
->spinlock
);
1631 memcpy(ctxt
->live_map
, dlm
->live_nodes_map
, sizeof(ctxt
->live_map
));
1633 __dlm_set_joining_node(dlm
, dlm
->node_num
);
1635 spin_unlock(&dlm
->spinlock
);
1638 while ((node
= find_next_bit(ctxt
->live_map
, O2NM_MAX_NODES
,
1639 node
+ 1)) < O2NM_MAX_NODES
) {
1640 if (node
== dlm
->node_num
)
1643 status
= dlm_request_join(dlm
, node
, &response
);
1649 /* Ok, either we got a response or the node doesn't have a
1651 if (response
== JOIN_OK
)
1652 set_bit(node
, ctxt
->yes_resp_map
);
1654 if (dlm_should_restart_join(dlm
, ctxt
, response
)) {
1660 mlog(0, "Yay, done querying nodes!\n");
1662 /* Yay, everyone agree's we can join the domain. My domain is
1663 * comprised of all nodes who were put in the
1664 * yes_resp_map. Copy that into our domain map and send a join
1665 * assert message to clean up everyone elses state. */
1666 spin_lock(&dlm
->spinlock
);
1667 memcpy(dlm
->domain_map
, ctxt
->yes_resp_map
,
1668 sizeof(ctxt
->yes_resp_map
));
1669 set_bit(dlm
->node_num
, dlm
->domain_map
);
1670 spin_unlock(&dlm
->spinlock
);
1672 /* Support for global heartbeat and node info was added in 1.1 */
1673 if (dlm
->dlm_locking_proto
.pv_major
> 1 ||
1674 dlm
->dlm_locking_proto
.pv_minor
> 0) {
1675 status
= dlm_send_nodeinfo(dlm
, ctxt
->yes_resp_map
);
1680 status
= dlm_send_regions(dlm
, ctxt
->yes_resp_map
);
1687 dlm_send_join_asserts(dlm
, ctxt
->yes_resp_map
);
1689 /* Joined state *must* be set before the joining node
1690 * information, otherwise the query_join handler may read no
1691 * current joiner but a state of NEW and tell joining nodes
1692 * we're not in the domain. */
1693 spin_lock(&dlm_domain_lock
);
1694 dlm
->dlm_state
= DLM_CTXT_JOINED
;
1696 spin_unlock(&dlm_domain_lock
);
1699 spin_lock(&dlm
->spinlock
);
1700 __dlm_set_joining_node(dlm
, DLM_LOCK_RES_OWNER_UNKNOWN
);
1702 printk(KERN_NOTICE
"o2dlm: Joining domain %s ", dlm
->name
);
1703 __dlm_print_nodes(dlm
);
1705 spin_unlock(&dlm
->spinlock
);
1708 /* Do we need to send a cancel message to any nodes? */
1710 tmpstat
= dlm_send_join_cancels(dlm
,
1712 sizeof(ctxt
->yes_resp_map
));
1714 mlog_errno(tmpstat
);
1719 mlog(0, "returning %d\n", status
);
1723 static void dlm_unregister_domain_handlers(struct dlm_ctxt
*dlm
)
1725 o2hb_unregister_callback(dlm
->name
, &dlm
->dlm_hb_up
);
1726 o2hb_unregister_callback(dlm
->name
, &dlm
->dlm_hb_down
);
1727 o2net_unregister_handler_list(&dlm
->dlm_domain_handlers
);
1730 static int dlm_register_domain_handlers(struct dlm_ctxt
*dlm
)
1734 mlog(0, "registering handlers.\n");
1736 o2hb_setup_callback(&dlm
->dlm_hb_down
, O2HB_NODE_DOWN_CB
,
1737 dlm_hb_node_down_cb
, dlm
, DLM_HB_NODE_DOWN_PRI
);
1738 o2hb_setup_callback(&dlm
->dlm_hb_up
, O2HB_NODE_UP_CB
,
1739 dlm_hb_node_up_cb
, dlm
, DLM_HB_NODE_UP_PRI
);
1741 status
= o2hb_register_callback(dlm
->name
, &dlm
->dlm_hb_down
);
1745 status
= o2hb_register_callback(dlm
->name
, &dlm
->dlm_hb_up
);
1749 status
= o2net_register_handler(DLM_MASTER_REQUEST_MSG
, dlm
->key
,
1750 sizeof(struct dlm_master_request
),
1751 dlm_master_request_handler
,
1752 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1756 status
= o2net_register_handler(DLM_ASSERT_MASTER_MSG
, dlm
->key
,
1757 sizeof(struct dlm_assert_master
),
1758 dlm_assert_master_handler
,
1759 dlm
, dlm_assert_master_post_handler
,
1760 &dlm
->dlm_domain_handlers
);
1764 status
= o2net_register_handler(DLM_CREATE_LOCK_MSG
, dlm
->key
,
1765 sizeof(struct dlm_create_lock
),
1766 dlm_create_lock_handler
,
1767 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1771 status
= o2net_register_handler(DLM_CONVERT_LOCK_MSG
, dlm
->key
,
1772 DLM_CONVERT_LOCK_MAX_LEN
,
1773 dlm_convert_lock_handler
,
1774 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1778 status
= o2net_register_handler(DLM_UNLOCK_LOCK_MSG
, dlm
->key
,
1779 DLM_UNLOCK_LOCK_MAX_LEN
,
1780 dlm_unlock_lock_handler
,
1781 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1785 status
= o2net_register_handler(DLM_PROXY_AST_MSG
, dlm
->key
,
1786 DLM_PROXY_AST_MAX_LEN
,
1787 dlm_proxy_ast_handler
,
1788 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1792 status
= o2net_register_handler(DLM_EXIT_DOMAIN_MSG
, dlm
->key
,
1793 sizeof(struct dlm_exit_domain
),
1794 dlm_exit_domain_handler
,
1795 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1799 status
= o2net_register_handler(DLM_DEREF_LOCKRES_MSG
, dlm
->key
,
1800 sizeof(struct dlm_deref_lockres
),
1801 dlm_deref_lockres_handler
,
1802 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1806 status
= o2net_register_handler(DLM_MIGRATE_REQUEST_MSG
, dlm
->key
,
1807 sizeof(struct dlm_migrate_request
),
1808 dlm_migrate_request_handler
,
1809 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1813 status
= o2net_register_handler(DLM_MIG_LOCKRES_MSG
, dlm
->key
,
1814 DLM_MIG_LOCKRES_MAX_LEN
,
1815 dlm_mig_lockres_handler
,
1816 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1820 status
= o2net_register_handler(DLM_MASTER_REQUERY_MSG
, dlm
->key
,
1821 sizeof(struct dlm_master_requery
),
1822 dlm_master_requery_handler
,
1823 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1827 status
= o2net_register_handler(DLM_LOCK_REQUEST_MSG
, dlm
->key
,
1828 sizeof(struct dlm_lock_request
),
1829 dlm_request_all_locks_handler
,
1830 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1834 status
= o2net_register_handler(DLM_RECO_DATA_DONE_MSG
, dlm
->key
,
1835 sizeof(struct dlm_reco_data_done
),
1836 dlm_reco_data_done_handler
,
1837 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1841 status
= o2net_register_handler(DLM_BEGIN_RECO_MSG
, dlm
->key
,
1842 sizeof(struct dlm_begin_reco
),
1843 dlm_begin_reco_handler
,
1844 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1848 status
= o2net_register_handler(DLM_FINALIZE_RECO_MSG
, dlm
->key
,
1849 sizeof(struct dlm_finalize_reco
),
1850 dlm_finalize_reco_handler
,
1851 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1855 status
= o2net_register_handler(DLM_BEGIN_EXIT_DOMAIN_MSG
, dlm
->key
,
1856 sizeof(struct dlm_exit_domain
),
1857 dlm_begin_exit_domain_handler
,
1858 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1862 status
= o2net_register_handler(DLM_DEREF_LOCKRES_DONE
, dlm
->key
,
1863 sizeof(struct dlm_deref_lockres_done
),
1864 dlm_deref_lockres_done_handler
,
1865 dlm
, NULL
, &dlm
->dlm_domain_handlers
);
1868 dlm_unregister_domain_handlers(dlm
);
1873 static int dlm_join_domain(struct dlm_ctxt
*dlm
)
1876 unsigned int backoff
;
1877 unsigned int total_backoff
= 0;
1878 char wq_name
[O2NM_MAX_NAME_LEN
];
1882 mlog(0, "Join domain %s\n", dlm
->name
);
1884 status
= dlm_register_domain_handlers(dlm
);
1890 status
= dlm_launch_thread(dlm
);
1896 status
= dlm_launch_recovery_thread(dlm
);
1902 status
= dlm_debug_init(dlm
);
1908 snprintf(wq_name
, O2NM_MAX_NAME_LEN
, "dlm_wq-%s", dlm
->name
);
1909 dlm
->dlm_worker
= create_singlethread_workqueue(wq_name
);
1910 if (!dlm
->dlm_worker
) {
1917 status
= dlm_try_to_join_domain(dlm
);
1919 /* If we're racing another node to the join, then we
1920 * need to back off temporarily and let them
1922 #define DLM_JOIN_TIMEOUT_MSECS 90000
1923 if (status
== -EAGAIN
) {
1924 if (signal_pending(current
)) {
1925 status
= -ERESTARTSYS
;
1929 if (total_backoff
> DLM_JOIN_TIMEOUT_MSECS
) {
1930 status
= -ERESTARTSYS
;
1931 mlog(ML_NOTICE
, "Timed out joining dlm domain "
1932 "%s after %u msecs\n", dlm
->name
,
1939 * <dale> No, after you!
1941 * <dale> But you first!
1944 backoff
= (unsigned int)(jiffies
& 0x3);
1945 backoff
*= DLM_DOMAIN_BACKOFF_MS
;
1946 total_backoff
+= backoff
;
1947 mlog(0, "backoff %d\n", backoff
);
1950 } while (status
== -EAGAIN
);
1959 wake_up(&dlm_domain_events
);
1962 dlm_unregister_domain_handlers(dlm
);
1963 dlm_debug_shutdown(dlm
);
1964 dlm_complete_thread(dlm
);
1965 dlm_complete_recovery_thread(dlm
);
1966 dlm_destroy_dlm_worker(dlm
);
1972 static struct dlm_ctxt
*dlm_alloc_ctxt(const char *domain
,
1977 struct dlm_ctxt
*dlm
= NULL
;
1979 dlm
= kzalloc(sizeof(*dlm
), GFP_KERNEL
);
1986 dlm
->name
= kstrdup(domain
, GFP_KERNEL
);
1987 if (dlm
->name
== NULL
) {
1993 dlm
->lockres_hash
= (struct hlist_head
**)dlm_alloc_pagevec(DLM_HASH_PAGES
);
1994 if (!dlm
->lockres_hash
) {
2000 for (i
= 0; i
< DLM_HASH_BUCKETS
; i
++)
2001 INIT_HLIST_HEAD(dlm_lockres_hash(dlm
, i
));
2003 dlm
->master_hash
= (struct hlist_head
**)
2004 dlm_alloc_pagevec(DLM_HASH_PAGES
);
2005 if (!dlm
->master_hash
) {
2011 for (i
= 0; i
< DLM_HASH_BUCKETS
; i
++)
2012 INIT_HLIST_HEAD(dlm_master_hash(dlm
, i
));
2015 dlm
->node_num
= o2nm_this_node();
2017 ret
= dlm_create_debugfs_subroot(dlm
);
2021 spin_lock_init(&dlm
->spinlock
);
2022 spin_lock_init(&dlm
->master_lock
);
2023 spin_lock_init(&dlm
->ast_lock
);
2024 spin_lock_init(&dlm
->track_lock
);
2025 INIT_LIST_HEAD(&dlm
->list
);
2026 INIT_LIST_HEAD(&dlm
->dirty_list
);
2027 INIT_LIST_HEAD(&dlm
->reco
.resources
);
2028 INIT_LIST_HEAD(&dlm
->reco
.node_data
);
2029 INIT_LIST_HEAD(&dlm
->purge_list
);
2030 INIT_LIST_HEAD(&dlm
->dlm_domain_handlers
);
2031 INIT_LIST_HEAD(&dlm
->tracking_list
);
2032 dlm
->reco
.state
= 0;
2034 INIT_LIST_HEAD(&dlm
->pending_asts
);
2035 INIT_LIST_HEAD(&dlm
->pending_basts
);
2037 mlog(0, "dlm->recovery_map=%p, &(dlm->recovery_map[0])=%p\n",
2038 dlm
->recovery_map
, &(dlm
->recovery_map
[0]));
2040 memset(dlm
->recovery_map
, 0, sizeof(dlm
->recovery_map
));
2041 memset(dlm
->live_nodes_map
, 0, sizeof(dlm
->live_nodes_map
));
2042 memset(dlm
->domain_map
, 0, sizeof(dlm
->domain_map
));
2044 dlm
->dlm_thread_task
= NULL
;
2045 dlm
->dlm_reco_thread_task
= NULL
;
2046 dlm
->dlm_worker
= NULL
;
2047 init_waitqueue_head(&dlm
->dlm_thread_wq
);
2048 init_waitqueue_head(&dlm
->dlm_reco_thread_wq
);
2049 init_waitqueue_head(&dlm
->reco
.event
);
2050 init_waitqueue_head(&dlm
->ast_wq
);
2051 init_waitqueue_head(&dlm
->migration_wq
);
2052 INIT_LIST_HEAD(&dlm
->mle_hb_events
);
2054 dlm
->joining_node
= DLM_LOCK_RES_OWNER_UNKNOWN
;
2055 init_waitqueue_head(&dlm
->dlm_join_events
);
2057 dlm
->reco
.new_master
= O2NM_INVALID_NODE_NUM
;
2058 dlm
->reco
.dead_node
= O2NM_INVALID_NODE_NUM
;
2060 atomic_set(&dlm
->res_tot_count
, 0);
2061 atomic_set(&dlm
->res_cur_count
, 0);
2062 for (i
= 0; i
< DLM_MLE_NUM_TYPES
; ++i
) {
2063 atomic_set(&dlm
->mle_tot_count
[i
], 0);
2064 atomic_set(&dlm
->mle_cur_count
[i
], 0);
2067 spin_lock_init(&dlm
->work_lock
);
2068 INIT_LIST_HEAD(&dlm
->work_list
);
2069 INIT_WORK(&dlm
->dispatched_work
, dlm_dispatch_work
);
2071 kref_init(&dlm
->dlm_refs
);
2072 dlm
->dlm_state
= DLM_CTXT_NEW
;
2074 INIT_LIST_HEAD(&dlm
->dlm_eviction_callbacks
);
2076 mlog(0, "context init: refcount %u\n",
2077 atomic_read(&dlm
->dlm_refs
.refcount
));
2080 if (ret
< 0 && dlm
) {
2081 if (dlm
->master_hash
)
2082 dlm_free_pagevec((void **)dlm
->master_hash
,
2085 if (dlm
->lockres_hash
)
2086 dlm_free_pagevec((void **)dlm
->lockres_hash
,
2097 * Compare a requested locking protocol version against the current one.
2099 * If the major numbers are different, they are incompatible.
2100 * If the current minor is greater than the request, they are incompatible.
2101 * If the current minor is less than or equal to the request, they are
2102 * compatible, and the requester should run at the current minor version.
2104 static int dlm_protocol_compare(struct dlm_protocol_version
*existing
,
2105 struct dlm_protocol_version
*request
)
2107 if (existing
->pv_major
!= request
->pv_major
)
2110 if (existing
->pv_minor
> request
->pv_minor
)
2113 if (existing
->pv_minor
< request
->pv_minor
)
2114 request
->pv_minor
= existing
->pv_minor
;
2120 * dlm_register_domain: one-time setup per "domain".
2122 * The filesystem passes in the requested locking version via proto.
2123 * If registration was successful, proto will contain the negotiated
2126 struct dlm_ctxt
* dlm_register_domain(const char *domain
,
2128 struct dlm_protocol_version
*fs_proto
)
2131 struct dlm_ctxt
*dlm
= NULL
;
2132 struct dlm_ctxt
*new_ctxt
= NULL
;
2134 if (strlen(domain
) >= O2NM_MAX_NAME_LEN
) {
2135 ret
= -ENAMETOOLONG
;
2136 mlog(ML_ERROR
, "domain name length too long\n");
2140 mlog(0, "register called for domain \"%s\"\n", domain
);
2144 if (signal_pending(current
)) {
2150 spin_lock(&dlm_domain_lock
);
2152 dlm
= __dlm_lookup_domain(domain
);
2154 if (dlm
->dlm_state
!= DLM_CTXT_JOINED
) {
2155 spin_unlock(&dlm_domain_lock
);
2157 mlog(0, "This ctxt is not joined yet!\n");
2158 wait_event_interruptible(dlm_domain_events
,
2159 dlm_wait_on_domain_helper(
2164 if (dlm_protocol_compare(&dlm
->fs_locking_proto
, fs_proto
)) {
2165 spin_unlock(&dlm_domain_lock
);
2167 "Requested locking protocol version is not "
2168 "compatible with already registered domain "
2169 "\"%s\"\n", domain
);
2177 spin_unlock(&dlm_domain_lock
);
2185 spin_unlock(&dlm_domain_lock
);
2187 new_ctxt
= dlm_alloc_ctxt(domain
, key
);
2196 /* a little variable switch-a-roo here... */
2200 /* add the new domain */
2201 list_add_tail(&dlm
->list
, &dlm_domains
);
2202 spin_unlock(&dlm_domain_lock
);
2205 * Pass the locking protocol version into the join. If the join
2206 * succeeds, it will have the negotiated protocol set.
2208 dlm
->dlm_locking_proto
= dlm_protocol
;
2209 dlm
->fs_locking_proto
= *fs_proto
;
2211 ret
= dlm_join_domain(dlm
);
2218 /* Tell the caller what locking protocol we negotiated */
2219 *fs_proto
= dlm
->fs_locking_proto
;
2224 dlm_free_ctxt_mem(new_ctxt
);
2231 EXPORT_SYMBOL_GPL(dlm_register_domain
);
2233 static LIST_HEAD(dlm_join_handlers
);
2235 static void dlm_unregister_net_handlers(void)
2237 o2net_unregister_handler_list(&dlm_join_handlers
);
2240 static int dlm_register_net_handlers(void)
2244 status
= o2net_register_handler(DLM_QUERY_JOIN_MSG
, DLM_MOD_KEY
,
2245 sizeof(struct dlm_query_join_request
),
2246 dlm_query_join_handler
,
2247 NULL
, NULL
, &dlm_join_handlers
);
2251 status
= o2net_register_handler(DLM_ASSERT_JOINED_MSG
, DLM_MOD_KEY
,
2252 sizeof(struct dlm_assert_joined
),
2253 dlm_assert_joined_handler
,
2254 NULL
, NULL
, &dlm_join_handlers
);
2258 status
= o2net_register_handler(DLM_CANCEL_JOIN_MSG
, DLM_MOD_KEY
,
2259 sizeof(struct dlm_cancel_join
),
2260 dlm_cancel_join_handler
,
2261 NULL
, NULL
, &dlm_join_handlers
);
2265 status
= o2net_register_handler(DLM_QUERY_REGION
, DLM_MOD_KEY
,
2266 sizeof(struct dlm_query_region
),
2267 dlm_query_region_handler
,
2268 NULL
, NULL
, &dlm_join_handlers
);
2273 status
= o2net_register_handler(DLM_QUERY_NODEINFO
, DLM_MOD_KEY
,
2274 sizeof(struct dlm_query_nodeinfo
),
2275 dlm_query_nodeinfo_handler
,
2276 NULL
, NULL
, &dlm_join_handlers
);
2279 dlm_unregister_net_handlers();
2284 /* Domain eviction callback handling.
2286 * The file system requires notification of node death *before* the
2287 * dlm completes it's recovery work, otherwise it may be able to
2288 * acquire locks on resources requiring recovery. Since the dlm can
2289 * evict a node from it's domain *before* heartbeat fires, a similar
2290 * mechanism is required. */
2292 /* Eviction is not expected to happen often, so a per-domain lock is
2293 * not necessary. Eviction callbacks are allowed to sleep for short
2294 * periods of time. */
2295 static DECLARE_RWSEM(dlm_callback_sem
);
2297 void dlm_fire_domain_eviction_callbacks(struct dlm_ctxt
*dlm
,
2300 struct dlm_eviction_cb
*cb
;
2302 down_read(&dlm_callback_sem
);
2303 list_for_each_entry(cb
, &dlm
->dlm_eviction_callbacks
, ec_item
) {
2304 cb
->ec_func(node_num
, cb
->ec_data
);
2306 up_read(&dlm_callback_sem
);
2309 void dlm_setup_eviction_cb(struct dlm_eviction_cb
*cb
,
2310 dlm_eviction_func
*f
,
2313 INIT_LIST_HEAD(&cb
->ec_item
);
2317 EXPORT_SYMBOL_GPL(dlm_setup_eviction_cb
);
2319 void dlm_register_eviction_cb(struct dlm_ctxt
*dlm
,
2320 struct dlm_eviction_cb
*cb
)
2322 down_write(&dlm_callback_sem
);
2323 list_add_tail(&cb
->ec_item
, &dlm
->dlm_eviction_callbacks
);
2324 up_write(&dlm_callback_sem
);
2326 EXPORT_SYMBOL_GPL(dlm_register_eviction_cb
);
2328 void dlm_unregister_eviction_cb(struct dlm_eviction_cb
*cb
)
2330 down_write(&dlm_callback_sem
);
2331 list_del_init(&cb
->ec_item
);
2332 up_write(&dlm_callback_sem
);
2334 EXPORT_SYMBOL_GPL(dlm_unregister_eviction_cb
);
2336 static int __init
dlm_init(void)
2340 status
= dlm_init_mle_cache();
2342 mlog(ML_ERROR
, "Could not create o2dlm_mle slabcache\n");
2346 status
= dlm_init_master_caches();
2348 mlog(ML_ERROR
, "Could not create o2dlm_lockres and "
2349 "o2dlm_lockname slabcaches\n");
2353 status
= dlm_init_lock_cache();
2355 mlog(ML_ERROR
, "Count not create o2dlm_lock slabcache\n");
2359 status
= dlm_register_net_handlers();
2361 mlog(ML_ERROR
, "Unable to register network handlers\n");
2365 status
= dlm_create_debugfs_root();
2371 dlm_unregister_net_handlers();
2372 dlm_destroy_lock_cache();
2373 dlm_destroy_master_caches();
2374 dlm_destroy_mle_cache();
2378 static void __exit
dlm_exit (void)
2380 dlm_destroy_debugfs_root();
2381 dlm_unregister_net_handlers();
2382 dlm_destroy_lock_cache();
2383 dlm_destroy_master_caches();
2384 dlm_destroy_mle_cache();
2387 MODULE_AUTHOR("Oracle");
2388 MODULE_LICENSE("GPL");
2389 MODULE_DESCRIPTION("OCFS2 Distributed Lock Management");
2391 module_init(dlm_init
);
2392 module_exit(dlm_exit
);