ocfs2: fix locking for res->tracking and dlm->tracking_list
[linux/fpc-iii.git] / fs / ocfs2 / cluster / nodemanager.c
blob3c45a9301a096973b4348b37eed3489090268eb6
1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
4 * Copyright (C) 2004, 2005 Oracle. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA.
22 #include <linux/slab.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/configfs.h>
27 #include "tcp.h"
28 #include "nodemanager.h"
29 #include "heartbeat.h"
30 #include "masklog.h"
31 #include "sys.h"
33 /* for now we operate under the assertion that there can be only one
34 * cluster active at a time. Changing this will require trickling
35 * cluster references throughout where nodes are looked up */
36 struct o2nm_cluster *o2nm_single_cluster = NULL;
38 char *o2nm_fence_method_desc[O2NM_FENCE_METHODS] = {
39 "reset", /* O2NM_FENCE_RESET */
40 "panic", /* O2NM_FENCE_PANIC */
43 static inline void o2nm_lock_subsystem(void);
44 static inline void o2nm_unlock_subsystem(void);
46 struct o2nm_node *o2nm_get_node_by_num(u8 node_num)
48 struct o2nm_node *node = NULL;
50 if (node_num >= O2NM_MAX_NODES || o2nm_single_cluster == NULL)
51 goto out;
53 read_lock(&o2nm_single_cluster->cl_nodes_lock);
54 node = o2nm_single_cluster->cl_nodes[node_num];
55 if (node)
56 config_item_get(&node->nd_item);
57 read_unlock(&o2nm_single_cluster->cl_nodes_lock);
58 out:
59 return node;
61 EXPORT_SYMBOL_GPL(o2nm_get_node_by_num);
63 int o2nm_configured_node_map(unsigned long *map, unsigned bytes)
65 struct o2nm_cluster *cluster = o2nm_single_cluster;
67 BUG_ON(bytes < (sizeof(cluster->cl_nodes_bitmap)));
69 if (cluster == NULL)
70 return -EINVAL;
72 read_lock(&cluster->cl_nodes_lock);
73 memcpy(map, cluster->cl_nodes_bitmap, sizeof(cluster->cl_nodes_bitmap));
74 read_unlock(&cluster->cl_nodes_lock);
76 return 0;
78 EXPORT_SYMBOL_GPL(o2nm_configured_node_map);
80 static struct o2nm_node *o2nm_node_ip_tree_lookup(struct o2nm_cluster *cluster,
81 __be32 ip_needle,
82 struct rb_node ***ret_p,
83 struct rb_node **ret_parent)
85 struct rb_node **p = &cluster->cl_node_ip_tree.rb_node;
86 struct rb_node *parent = NULL;
87 struct o2nm_node *node, *ret = NULL;
89 while (*p) {
90 int cmp;
92 parent = *p;
93 node = rb_entry(parent, struct o2nm_node, nd_ip_node);
95 cmp = memcmp(&ip_needle, &node->nd_ipv4_address,
96 sizeof(ip_needle));
97 if (cmp < 0)
98 p = &(*p)->rb_left;
99 else if (cmp > 0)
100 p = &(*p)->rb_right;
101 else {
102 ret = node;
103 break;
107 if (ret_p != NULL)
108 *ret_p = p;
109 if (ret_parent != NULL)
110 *ret_parent = parent;
112 return ret;
115 struct o2nm_node *o2nm_get_node_by_ip(__be32 addr)
117 struct o2nm_node *node = NULL;
118 struct o2nm_cluster *cluster = o2nm_single_cluster;
120 if (cluster == NULL)
121 goto out;
123 read_lock(&cluster->cl_nodes_lock);
124 node = o2nm_node_ip_tree_lookup(cluster, addr, NULL, NULL);
125 if (node)
126 config_item_get(&node->nd_item);
127 read_unlock(&cluster->cl_nodes_lock);
129 out:
130 return node;
132 EXPORT_SYMBOL_GPL(o2nm_get_node_by_ip);
134 void o2nm_node_put(struct o2nm_node *node)
136 config_item_put(&node->nd_item);
138 EXPORT_SYMBOL_GPL(o2nm_node_put);
140 void o2nm_node_get(struct o2nm_node *node)
142 config_item_get(&node->nd_item);
144 EXPORT_SYMBOL_GPL(o2nm_node_get);
146 u8 o2nm_this_node(void)
148 u8 node_num = O2NM_MAX_NODES;
150 if (o2nm_single_cluster && o2nm_single_cluster->cl_has_local)
151 node_num = o2nm_single_cluster->cl_local_node;
153 return node_num;
155 EXPORT_SYMBOL_GPL(o2nm_this_node);
157 /* node configfs bits */
159 static struct o2nm_cluster *to_o2nm_cluster(struct config_item *item)
161 return item ?
162 container_of(to_config_group(item), struct o2nm_cluster,
163 cl_group)
164 : NULL;
167 static struct o2nm_node *to_o2nm_node(struct config_item *item)
169 return item ? container_of(item, struct o2nm_node, nd_item) : NULL;
172 static void o2nm_node_release(struct config_item *item)
174 struct o2nm_node *node = to_o2nm_node(item);
175 kfree(node);
178 static ssize_t o2nm_node_num_show(struct config_item *item, char *page)
180 return sprintf(page, "%d\n", to_o2nm_node(item)->nd_num);
183 static struct o2nm_cluster *to_o2nm_cluster_from_node(struct o2nm_node *node)
185 /* through the first node_set .parent
186 * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
187 if (node->nd_item.ci_parent)
188 return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
189 else
190 return NULL;
193 enum {
194 O2NM_NODE_ATTR_NUM = 0,
195 O2NM_NODE_ATTR_PORT,
196 O2NM_NODE_ATTR_ADDRESS,
199 static ssize_t o2nm_node_num_store(struct config_item *item, const char *page,
200 size_t count)
202 struct o2nm_node *node = to_o2nm_node(item);
203 struct o2nm_cluster *cluster;
204 unsigned long tmp;
205 char *p = (char *)page;
206 int ret = 0;
208 tmp = simple_strtoul(p, &p, 0);
209 if (!p || (*p && (*p != '\n')))
210 return -EINVAL;
212 if (tmp >= O2NM_MAX_NODES)
213 return -ERANGE;
215 /* once we're in the cl_nodes tree networking can look us up by
216 * node number and try to use our address and port attributes
217 * to connect to this node.. make sure that they've been set
218 * before writing the node attribute? */
219 if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
220 !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
221 return -EINVAL; /* XXX */
223 o2nm_lock_subsystem();
224 cluster = to_o2nm_cluster_from_node(node);
225 if (!cluster) {
226 o2nm_unlock_subsystem();
227 return -EINVAL;
230 write_lock(&cluster->cl_nodes_lock);
231 if (cluster->cl_nodes[tmp])
232 ret = -EEXIST;
233 else if (test_and_set_bit(O2NM_NODE_ATTR_NUM,
234 &node->nd_set_attributes))
235 ret = -EBUSY;
236 else {
237 cluster->cl_nodes[tmp] = node;
238 node->nd_num = tmp;
239 set_bit(tmp, cluster->cl_nodes_bitmap);
241 write_unlock(&cluster->cl_nodes_lock);
242 o2nm_unlock_subsystem();
244 if (ret)
245 return ret;
247 return count;
249 static ssize_t o2nm_node_ipv4_port_show(struct config_item *item, char *page)
251 return sprintf(page, "%u\n", ntohs(to_o2nm_node(item)->nd_ipv4_port));
254 static ssize_t o2nm_node_ipv4_port_store(struct config_item *item,
255 const char *page, size_t count)
257 struct o2nm_node *node = to_o2nm_node(item);
258 unsigned long tmp;
259 char *p = (char *)page;
261 tmp = simple_strtoul(p, &p, 0);
262 if (!p || (*p && (*p != '\n')))
263 return -EINVAL;
265 if (tmp == 0)
266 return -EINVAL;
267 if (tmp >= (u16)-1)
268 return -ERANGE;
270 if (test_and_set_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
271 return -EBUSY;
272 node->nd_ipv4_port = htons(tmp);
274 return count;
277 static ssize_t o2nm_node_ipv4_address_show(struct config_item *item, char *page)
279 return sprintf(page, "%pI4\n", &to_o2nm_node(item)->nd_ipv4_address);
282 static ssize_t o2nm_node_ipv4_address_store(struct config_item *item,
283 const char *page,
284 size_t count)
286 struct o2nm_node *node = to_o2nm_node(item);
287 struct o2nm_cluster *cluster;
288 int ret, i;
289 struct rb_node **p, *parent;
290 unsigned int octets[4];
291 __be32 ipv4_addr = 0;
293 ret = sscanf(page, "%3u.%3u.%3u.%3u", &octets[3], &octets[2],
294 &octets[1], &octets[0]);
295 if (ret != 4)
296 return -EINVAL;
298 for (i = 0; i < ARRAY_SIZE(octets); i++) {
299 if (octets[i] > 255)
300 return -ERANGE;
301 be32_add_cpu(&ipv4_addr, octets[i] << (i * 8));
304 o2nm_lock_subsystem();
305 cluster = to_o2nm_cluster_from_node(node);
306 if (!cluster) {
307 o2nm_unlock_subsystem();
308 return -EINVAL;
311 ret = 0;
312 write_lock(&cluster->cl_nodes_lock);
313 if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
314 ret = -EEXIST;
315 else if (test_and_set_bit(O2NM_NODE_ATTR_ADDRESS,
316 &node->nd_set_attributes))
317 ret = -EBUSY;
318 else {
319 rb_link_node(&node->nd_ip_node, parent, p);
320 rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
322 write_unlock(&cluster->cl_nodes_lock);
323 o2nm_unlock_subsystem();
325 if (ret)
326 return ret;
328 memcpy(&node->nd_ipv4_address, &ipv4_addr, sizeof(ipv4_addr));
330 return count;
333 static ssize_t o2nm_node_local_show(struct config_item *item, char *page)
335 return sprintf(page, "%d\n", to_o2nm_node(item)->nd_local);
338 static ssize_t o2nm_node_local_store(struct config_item *item, const char *page,
339 size_t count)
341 struct o2nm_node *node = to_o2nm_node(item);
342 struct o2nm_cluster *cluster;
343 unsigned long tmp;
344 char *p = (char *)page;
345 ssize_t ret;
347 tmp = simple_strtoul(p, &p, 0);
348 if (!p || (*p && (*p != '\n')))
349 return -EINVAL;
351 tmp = !!tmp; /* boolean of whether this node wants to be local */
353 /* setting local turns on networking rx for now so we require having
354 * set everything else first */
355 if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
356 !test_bit(O2NM_NODE_ATTR_NUM, &node->nd_set_attributes) ||
357 !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
358 return -EINVAL; /* XXX */
360 o2nm_lock_subsystem();
361 cluster = to_o2nm_cluster_from_node(node);
362 if (!cluster) {
363 ret = -EINVAL;
364 goto out;
367 /* the only failure case is trying to set a new local node
368 * when a different one is already set */
369 if (tmp && tmp == cluster->cl_has_local &&
370 cluster->cl_local_node != node->nd_num) {
371 ret = -EBUSY;
372 goto out;
375 /* bring up the rx thread if we're setting the new local node. */
376 if (tmp && !cluster->cl_has_local) {
377 ret = o2net_start_listening(node);
378 if (ret)
379 goto out;
382 if (!tmp && cluster->cl_has_local &&
383 cluster->cl_local_node == node->nd_num) {
384 o2net_stop_listening(node);
385 cluster->cl_local_node = O2NM_INVALID_NODE_NUM;
388 node->nd_local = tmp;
389 if (node->nd_local) {
390 cluster->cl_has_local = tmp;
391 cluster->cl_local_node = node->nd_num;
394 ret = count;
396 out:
397 o2nm_unlock_subsystem();
398 return ret;
401 CONFIGFS_ATTR(o2nm_node_, num);
402 CONFIGFS_ATTR(o2nm_node_, ipv4_port);
403 CONFIGFS_ATTR(o2nm_node_, ipv4_address);
404 CONFIGFS_ATTR(o2nm_node_, local);
406 static struct configfs_attribute *o2nm_node_attrs[] = {
407 &o2nm_node_attr_num,
408 &o2nm_node_attr_ipv4_port,
409 &o2nm_node_attr_ipv4_address,
410 &o2nm_node_attr_local,
411 NULL,
414 static struct configfs_item_operations o2nm_node_item_ops = {
415 .release = o2nm_node_release,
418 static struct config_item_type o2nm_node_type = {
419 .ct_item_ops = &o2nm_node_item_ops,
420 .ct_attrs = o2nm_node_attrs,
421 .ct_owner = THIS_MODULE,
424 /* node set */
426 struct o2nm_node_group {
427 struct config_group ns_group;
428 /* some stuff? */
431 #if 0
432 static struct o2nm_node_group *to_o2nm_node_group(struct config_group *group)
434 return group ?
435 container_of(group, struct o2nm_node_group, ns_group)
436 : NULL;
438 #endif
440 static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count,
441 unsigned int *val)
443 unsigned long tmp;
444 char *p = (char *)page;
446 tmp = simple_strtoul(p, &p, 0);
447 if (!p || (*p && (*p != '\n')))
448 return -EINVAL;
450 if (tmp == 0)
451 return -EINVAL;
452 if (tmp >= (u32)-1)
453 return -ERANGE;
455 *val = tmp;
457 return count;
460 static ssize_t o2nm_cluster_idle_timeout_ms_show(struct config_item *item,
461 char *page)
463 return sprintf(page, "%u\n", to_o2nm_cluster(item)->cl_idle_timeout_ms);
466 static ssize_t o2nm_cluster_idle_timeout_ms_store(struct config_item *item,
467 const char *page, size_t count)
469 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
470 ssize_t ret;
471 unsigned int val;
473 ret = o2nm_cluster_attr_write(page, count, &val);
475 if (ret > 0) {
476 if (cluster->cl_idle_timeout_ms != val
477 && o2net_num_connected_peers()) {
478 mlog(ML_NOTICE,
479 "o2net: cannot change idle timeout after "
480 "the first peer has agreed to it."
481 " %d connected peers\n",
482 o2net_num_connected_peers());
483 ret = -EINVAL;
484 } else if (val <= cluster->cl_keepalive_delay_ms) {
485 mlog(ML_NOTICE, "o2net: idle timeout must be larger "
486 "than keepalive delay\n");
487 ret = -EINVAL;
488 } else {
489 cluster->cl_idle_timeout_ms = val;
493 return ret;
496 static ssize_t o2nm_cluster_keepalive_delay_ms_show(
497 struct config_item *item, char *page)
499 return sprintf(page, "%u\n",
500 to_o2nm_cluster(item)->cl_keepalive_delay_ms);
503 static ssize_t o2nm_cluster_keepalive_delay_ms_store(
504 struct config_item *item, const char *page, size_t count)
506 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
507 ssize_t ret;
508 unsigned int val;
510 ret = o2nm_cluster_attr_write(page, count, &val);
512 if (ret > 0) {
513 if (cluster->cl_keepalive_delay_ms != val
514 && o2net_num_connected_peers()) {
515 mlog(ML_NOTICE,
516 "o2net: cannot change keepalive delay after"
517 " the first peer has agreed to it."
518 " %d connected peers\n",
519 o2net_num_connected_peers());
520 ret = -EINVAL;
521 } else if (val >= cluster->cl_idle_timeout_ms) {
522 mlog(ML_NOTICE, "o2net: keepalive delay must be "
523 "smaller than idle timeout\n");
524 ret = -EINVAL;
525 } else {
526 cluster->cl_keepalive_delay_ms = val;
530 return ret;
533 static ssize_t o2nm_cluster_reconnect_delay_ms_show(
534 struct config_item *item, char *page)
536 return sprintf(page, "%u\n",
537 to_o2nm_cluster(item)->cl_reconnect_delay_ms);
540 static ssize_t o2nm_cluster_reconnect_delay_ms_store(
541 struct config_item *item, const char *page, size_t count)
543 return o2nm_cluster_attr_write(page, count,
544 &to_o2nm_cluster(item)->cl_reconnect_delay_ms);
547 static ssize_t o2nm_cluster_fence_method_show(
548 struct config_item *item, char *page)
550 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
551 ssize_t ret = 0;
553 if (cluster)
554 ret = sprintf(page, "%s\n",
555 o2nm_fence_method_desc[cluster->cl_fence_method]);
556 return ret;
559 static ssize_t o2nm_cluster_fence_method_store(
560 struct config_item *item, const char *page, size_t count)
562 unsigned int i;
564 if (page[count - 1] != '\n')
565 goto bail;
567 for (i = 0; i < O2NM_FENCE_METHODS; ++i) {
568 if (count != strlen(o2nm_fence_method_desc[i]) + 1)
569 continue;
570 if (strncasecmp(page, o2nm_fence_method_desc[i], count - 1))
571 continue;
572 if (to_o2nm_cluster(item)->cl_fence_method != i) {
573 printk(KERN_INFO "ocfs2: Changing fence method to %s\n",
574 o2nm_fence_method_desc[i]);
575 to_o2nm_cluster(item)->cl_fence_method = i;
577 return count;
580 bail:
581 return -EINVAL;
584 CONFIGFS_ATTR(o2nm_cluster_, idle_timeout_ms);
585 CONFIGFS_ATTR(o2nm_cluster_, keepalive_delay_ms);
586 CONFIGFS_ATTR(o2nm_cluster_, reconnect_delay_ms);
587 CONFIGFS_ATTR(o2nm_cluster_, fence_method);
589 static struct configfs_attribute *o2nm_cluster_attrs[] = {
590 &o2nm_cluster_attr_idle_timeout_ms,
591 &o2nm_cluster_attr_keepalive_delay_ms,
592 &o2nm_cluster_attr_reconnect_delay_ms,
593 &o2nm_cluster_attr_fence_method,
594 NULL,
597 static struct config_item *o2nm_node_group_make_item(struct config_group *group,
598 const char *name)
600 struct o2nm_node *node = NULL;
602 if (strlen(name) > O2NM_MAX_NAME_LEN)
603 return ERR_PTR(-ENAMETOOLONG);
605 node = kzalloc(sizeof(struct o2nm_node), GFP_KERNEL);
606 if (node == NULL)
607 return ERR_PTR(-ENOMEM);
609 strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */
610 config_item_init_type_name(&node->nd_item, name, &o2nm_node_type);
611 spin_lock_init(&node->nd_lock);
613 mlog(ML_CLUSTER, "o2nm: Registering node %s\n", name);
615 return &node->nd_item;
618 static void o2nm_node_group_drop_item(struct config_group *group,
619 struct config_item *item)
621 struct o2nm_node *node = to_o2nm_node(item);
622 struct o2nm_cluster *cluster = to_o2nm_cluster(group->cg_item.ci_parent);
624 o2net_disconnect_node(node);
626 if (cluster->cl_has_local &&
627 (cluster->cl_local_node == node->nd_num)) {
628 cluster->cl_has_local = 0;
629 cluster->cl_local_node = O2NM_INVALID_NODE_NUM;
630 o2net_stop_listening(node);
633 /* XXX call into net to stop this node from trading messages */
635 write_lock(&cluster->cl_nodes_lock);
637 /* XXX sloppy */
638 if (node->nd_ipv4_address)
639 rb_erase(&node->nd_ip_node, &cluster->cl_node_ip_tree);
641 /* nd_num might be 0 if the node number hasn't been set.. */
642 if (cluster->cl_nodes[node->nd_num] == node) {
643 cluster->cl_nodes[node->nd_num] = NULL;
644 clear_bit(node->nd_num, cluster->cl_nodes_bitmap);
646 write_unlock(&cluster->cl_nodes_lock);
648 mlog(ML_CLUSTER, "o2nm: Unregistered node %s\n",
649 config_item_name(&node->nd_item));
651 config_item_put(item);
654 static struct configfs_group_operations o2nm_node_group_group_ops = {
655 .make_item = o2nm_node_group_make_item,
656 .drop_item = o2nm_node_group_drop_item,
659 static struct config_item_type o2nm_node_group_type = {
660 .ct_group_ops = &o2nm_node_group_group_ops,
661 .ct_owner = THIS_MODULE,
664 /* cluster */
666 static void o2nm_cluster_release(struct config_item *item)
668 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
670 kfree(cluster->cl_group.default_groups);
671 kfree(cluster);
674 static struct configfs_item_operations o2nm_cluster_item_ops = {
675 .release = o2nm_cluster_release,
678 static struct config_item_type o2nm_cluster_type = {
679 .ct_item_ops = &o2nm_cluster_item_ops,
680 .ct_attrs = o2nm_cluster_attrs,
681 .ct_owner = THIS_MODULE,
684 /* cluster set */
686 struct o2nm_cluster_group {
687 struct configfs_subsystem cs_subsys;
688 /* some stuff? */
691 #if 0
692 static struct o2nm_cluster_group *to_o2nm_cluster_group(struct config_group *group)
694 return group ?
695 container_of(to_configfs_subsystem(group), struct o2nm_cluster_group, cs_subsys)
696 : NULL;
698 #endif
700 static struct config_group *o2nm_cluster_group_make_group(struct config_group *group,
701 const char *name)
703 struct o2nm_cluster *cluster = NULL;
704 struct o2nm_node_group *ns = NULL;
705 struct config_group *o2hb_group = NULL, *ret = NULL;
706 void *defs = NULL;
708 /* this runs under the parent dir's i_mutex; there can be only
709 * one caller in here at a time */
710 if (o2nm_single_cluster)
711 return ERR_PTR(-ENOSPC);
713 cluster = kzalloc(sizeof(struct o2nm_cluster), GFP_KERNEL);
714 ns = kzalloc(sizeof(struct o2nm_node_group), GFP_KERNEL);
715 defs = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL);
716 o2hb_group = o2hb_alloc_hb_set();
717 if (cluster == NULL || ns == NULL || o2hb_group == NULL || defs == NULL)
718 goto out;
720 config_group_init_type_name(&cluster->cl_group, name,
721 &o2nm_cluster_type);
722 config_group_init_type_name(&ns->ns_group, "node",
723 &o2nm_node_group_type);
725 cluster->cl_group.default_groups = defs;
726 cluster->cl_group.default_groups[0] = &ns->ns_group;
727 cluster->cl_group.default_groups[1] = o2hb_group;
728 cluster->cl_group.default_groups[2] = NULL;
729 rwlock_init(&cluster->cl_nodes_lock);
730 cluster->cl_node_ip_tree = RB_ROOT;
731 cluster->cl_reconnect_delay_ms = O2NET_RECONNECT_DELAY_MS_DEFAULT;
732 cluster->cl_idle_timeout_ms = O2NET_IDLE_TIMEOUT_MS_DEFAULT;
733 cluster->cl_keepalive_delay_ms = O2NET_KEEPALIVE_DELAY_MS_DEFAULT;
734 cluster->cl_fence_method = O2NM_FENCE_RESET;
736 ret = &cluster->cl_group;
737 o2nm_single_cluster = cluster;
739 out:
740 if (ret == NULL) {
741 kfree(cluster);
742 kfree(ns);
743 o2hb_free_hb_set(o2hb_group);
744 kfree(defs);
745 ret = ERR_PTR(-ENOMEM);
748 return ret;
751 static void o2nm_cluster_group_drop_item(struct config_group *group, struct config_item *item)
753 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
754 int i;
755 struct config_item *killme;
757 BUG_ON(o2nm_single_cluster != cluster);
758 o2nm_single_cluster = NULL;
760 for (i = 0; cluster->cl_group.default_groups[i]; i++) {
761 killme = &cluster->cl_group.default_groups[i]->cg_item;
762 cluster->cl_group.default_groups[i] = NULL;
763 config_item_put(killme);
766 config_item_put(item);
769 static struct configfs_group_operations o2nm_cluster_group_group_ops = {
770 .make_group = o2nm_cluster_group_make_group,
771 .drop_item = o2nm_cluster_group_drop_item,
774 static struct config_item_type o2nm_cluster_group_type = {
775 .ct_group_ops = &o2nm_cluster_group_group_ops,
776 .ct_owner = THIS_MODULE,
779 static struct o2nm_cluster_group o2nm_cluster_group = {
780 .cs_subsys = {
781 .su_group = {
782 .cg_item = {
783 .ci_namebuf = "cluster",
784 .ci_type = &o2nm_cluster_group_type,
790 static inline void o2nm_lock_subsystem(void)
792 mutex_lock(&o2nm_cluster_group.cs_subsys.su_mutex);
795 static inline void o2nm_unlock_subsystem(void)
797 mutex_unlock(&o2nm_cluster_group.cs_subsys.su_mutex);
800 int o2nm_depend_item(struct config_item *item)
802 return configfs_depend_item(&o2nm_cluster_group.cs_subsys, item);
805 void o2nm_undepend_item(struct config_item *item)
807 configfs_undepend_item(&o2nm_cluster_group.cs_subsys, item);
810 int o2nm_depend_this_node(void)
812 int ret = 0;
813 struct o2nm_node *local_node;
815 local_node = o2nm_get_node_by_num(o2nm_this_node());
816 if (!local_node) {
817 ret = -EINVAL;
818 goto out;
821 ret = o2nm_depend_item(&local_node->nd_item);
822 o2nm_node_put(local_node);
824 out:
825 return ret;
828 void o2nm_undepend_this_node(void)
830 struct o2nm_node *local_node;
832 local_node = o2nm_get_node_by_num(o2nm_this_node());
833 BUG_ON(!local_node);
835 o2nm_undepend_item(&local_node->nd_item);
836 o2nm_node_put(local_node);
840 static void __exit exit_o2nm(void)
842 /* XXX sync with hb callbacks and shut down hb? */
843 o2net_unregister_hb_callbacks();
844 configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
845 o2cb_sys_shutdown();
847 o2net_exit();
848 o2hb_exit();
851 static int __init init_o2nm(void)
853 int ret = -1;
855 ret = o2hb_init();
856 if (ret)
857 goto out;
859 ret = o2net_init();
860 if (ret)
861 goto out_o2hb;
863 ret = o2net_register_hb_callbacks();
864 if (ret)
865 goto out_o2net;
867 config_group_init(&o2nm_cluster_group.cs_subsys.su_group);
868 mutex_init(&o2nm_cluster_group.cs_subsys.su_mutex);
869 ret = configfs_register_subsystem(&o2nm_cluster_group.cs_subsys);
870 if (ret) {
871 printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
872 goto out_callbacks;
875 ret = o2cb_sys_init();
876 if (!ret)
877 goto out;
879 configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
880 out_callbacks:
881 o2net_unregister_hb_callbacks();
882 out_o2net:
883 o2net_exit();
884 out_o2hb:
885 o2hb_exit();
886 out:
887 return ret;
890 MODULE_AUTHOR("Oracle");
891 MODULE_LICENSE("GPL");
892 MODULE_DESCRIPTION("OCFS2 cluster management");
894 module_init(init_o2nm)
895 module_exit(exit_o2nm)