gro: Allow tunnel stacking in the case of FOU/GUE
[linux/fpc-iii.git] / fs / ocfs2 / cluster / nodemanager.c
blob441c84e169e6f05e819d7331027f6e519d02b3be
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 struct o2nm_node *o2nm_get_node_by_num(u8 node_num)
45 struct o2nm_node *node = NULL;
47 if (node_num >= O2NM_MAX_NODES || o2nm_single_cluster == NULL)
48 goto out;
50 read_lock(&o2nm_single_cluster->cl_nodes_lock);
51 node = o2nm_single_cluster->cl_nodes[node_num];
52 if (node)
53 config_item_get(&node->nd_item);
54 read_unlock(&o2nm_single_cluster->cl_nodes_lock);
55 out:
56 return node;
58 EXPORT_SYMBOL_GPL(o2nm_get_node_by_num);
60 int o2nm_configured_node_map(unsigned long *map, unsigned bytes)
62 struct o2nm_cluster *cluster = o2nm_single_cluster;
64 BUG_ON(bytes < (sizeof(cluster->cl_nodes_bitmap)));
66 if (cluster == NULL)
67 return -EINVAL;
69 read_lock(&cluster->cl_nodes_lock);
70 memcpy(map, cluster->cl_nodes_bitmap, sizeof(cluster->cl_nodes_bitmap));
71 read_unlock(&cluster->cl_nodes_lock);
73 return 0;
75 EXPORT_SYMBOL_GPL(o2nm_configured_node_map);
77 static struct o2nm_node *o2nm_node_ip_tree_lookup(struct o2nm_cluster *cluster,
78 __be32 ip_needle,
79 struct rb_node ***ret_p,
80 struct rb_node **ret_parent)
82 struct rb_node **p = &cluster->cl_node_ip_tree.rb_node;
83 struct rb_node *parent = NULL;
84 struct o2nm_node *node, *ret = NULL;
86 while (*p) {
87 int cmp;
89 parent = *p;
90 node = rb_entry(parent, struct o2nm_node, nd_ip_node);
92 cmp = memcmp(&ip_needle, &node->nd_ipv4_address,
93 sizeof(ip_needle));
94 if (cmp < 0)
95 p = &(*p)->rb_left;
96 else if (cmp > 0)
97 p = &(*p)->rb_right;
98 else {
99 ret = node;
100 break;
104 if (ret_p != NULL)
105 *ret_p = p;
106 if (ret_parent != NULL)
107 *ret_parent = parent;
109 return ret;
112 struct o2nm_node *o2nm_get_node_by_ip(__be32 addr)
114 struct o2nm_node *node = NULL;
115 struct o2nm_cluster *cluster = o2nm_single_cluster;
117 if (cluster == NULL)
118 goto out;
120 read_lock(&cluster->cl_nodes_lock);
121 node = o2nm_node_ip_tree_lookup(cluster, addr, NULL, NULL);
122 if (node)
123 config_item_get(&node->nd_item);
124 read_unlock(&cluster->cl_nodes_lock);
126 out:
127 return node;
129 EXPORT_SYMBOL_GPL(o2nm_get_node_by_ip);
131 void o2nm_node_put(struct o2nm_node *node)
133 config_item_put(&node->nd_item);
135 EXPORT_SYMBOL_GPL(o2nm_node_put);
137 void o2nm_node_get(struct o2nm_node *node)
139 config_item_get(&node->nd_item);
141 EXPORT_SYMBOL_GPL(o2nm_node_get);
143 u8 o2nm_this_node(void)
145 u8 node_num = O2NM_MAX_NODES;
147 if (o2nm_single_cluster && o2nm_single_cluster->cl_has_local)
148 node_num = o2nm_single_cluster->cl_local_node;
150 return node_num;
152 EXPORT_SYMBOL_GPL(o2nm_this_node);
154 /* node configfs bits */
156 static struct o2nm_cluster *to_o2nm_cluster(struct config_item *item)
158 return item ?
159 container_of(to_config_group(item), struct o2nm_cluster,
160 cl_group)
161 : NULL;
164 static struct o2nm_node *to_o2nm_node(struct config_item *item)
166 return item ? container_of(item, struct o2nm_node, nd_item) : NULL;
169 static void o2nm_node_release(struct config_item *item)
171 struct o2nm_node *node = to_o2nm_node(item);
172 kfree(node);
175 static ssize_t o2nm_node_num_read(struct o2nm_node *node, char *page)
177 return sprintf(page, "%d\n", node->nd_num);
180 static struct o2nm_cluster *to_o2nm_cluster_from_node(struct o2nm_node *node)
182 /* through the first node_set .parent
183 * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
184 return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
187 enum {
188 O2NM_NODE_ATTR_NUM = 0,
189 O2NM_NODE_ATTR_PORT,
190 O2NM_NODE_ATTR_ADDRESS,
191 O2NM_NODE_ATTR_LOCAL,
194 static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
195 size_t count)
197 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
198 unsigned long tmp;
199 char *p = (char *)page;
201 tmp = simple_strtoul(p, &p, 0);
202 if (!p || (*p && (*p != '\n')))
203 return -EINVAL;
205 if (tmp >= O2NM_MAX_NODES)
206 return -ERANGE;
208 /* once we're in the cl_nodes tree networking can look us up by
209 * node number and try to use our address and port attributes
210 * to connect to this node.. make sure that they've been set
211 * before writing the node attribute? */
212 if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
213 !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
214 return -EINVAL; /* XXX */
216 write_lock(&cluster->cl_nodes_lock);
217 if (cluster->cl_nodes[tmp])
218 p = NULL;
219 else {
220 cluster->cl_nodes[tmp] = node;
221 node->nd_num = tmp;
222 set_bit(tmp, cluster->cl_nodes_bitmap);
224 write_unlock(&cluster->cl_nodes_lock);
225 if (p == NULL)
226 return -EEXIST;
228 return count;
230 static ssize_t o2nm_node_ipv4_port_read(struct o2nm_node *node, char *page)
232 return sprintf(page, "%u\n", ntohs(node->nd_ipv4_port));
235 static ssize_t o2nm_node_ipv4_port_write(struct o2nm_node *node,
236 const char *page, size_t count)
238 unsigned long tmp;
239 char *p = (char *)page;
241 tmp = simple_strtoul(p, &p, 0);
242 if (!p || (*p && (*p != '\n')))
243 return -EINVAL;
245 if (tmp == 0)
246 return -EINVAL;
247 if (tmp >= (u16)-1)
248 return -ERANGE;
250 node->nd_ipv4_port = htons(tmp);
252 return count;
255 static ssize_t o2nm_node_ipv4_address_read(struct o2nm_node *node, char *page)
257 return sprintf(page, "%pI4\n", &node->nd_ipv4_address);
260 static ssize_t o2nm_node_ipv4_address_write(struct o2nm_node *node,
261 const char *page,
262 size_t count)
264 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
265 int ret, i;
266 struct rb_node **p, *parent;
267 unsigned int octets[4];
268 __be32 ipv4_addr = 0;
270 ret = sscanf(page, "%3u.%3u.%3u.%3u", &octets[3], &octets[2],
271 &octets[1], &octets[0]);
272 if (ret != 4)
273 return -EINVAL;
275 for (i = 0; i < ARRAY_SIZE(octets); i++) {
276 if (octets[i] > 255)
277 return -ERANGE;
278 be32_add_cpu(&ipv4_addr, octets[i] << (i * 8));
281 ret = 0;
282 write_lock(&cluster->cl_nodes_lock);
283 if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
284 ret = -EEXIST;
285 else {
286 rb_link_node(&node->nd_ip_node, parent, p);
287 rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
289 write_unlock(&cluster->cl_nodes_lock);
290 if (ret)
291 return ret;
293 memcpy(&node->nd_ipv4_address, &ipv4_addr, sizeof(ipv4_addr));
295 return count;
298 static ssize_t o2nm_node_local_read(struct o2nm_node *node, char *page)
300 return sprintf(page, "%d\n", node->nd_local);
303 static ssize_t o2nm_node_local_write(struct o2nm_node *node, const char *page,
304 size_t count)
306 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
307 unsigned long tmp;
308 char *p = (char *)page;
309 ssize_t ret;
311 tmp = simple_strtoul(p, &p, 0);
312 if (!p || (*p && (*p != '\n')))
313 return -EINVAL;
315 tmp = !!tmp; /* boolean of whether this node wants to be local */
317 /* setting local turns on networking rx for now so we require having
318 * set everything else first */
319 if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
320 !test_bit(O2NM_NODE_ATTR_NUM, &node->nd_set_attributes) ||
321 !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
322 return -EINVAL; /* XXX */
324 /* the only failure case is trying to set a new local node
325 * when a different one is already set */
326 if (tmp && tmp == cluster->cl_has_local &&
327 cluster->cl_local_node != node->nd_num)
328 return -EBUSY;
330 /* bring up the rx thread if we're setting the new local node. */
331 if (tmp && !cluster->cl_has_local) {
332 ret = o2net_start_listening(node);
333 if (ret)
334 return ret;
337 if (!tmp && cluster->cl_has_local &&
338 cluster->cl_local_node == node->nd_num) {
339 o2net_stop_listening(node);
340 cluster->cl_local_node = O2NM_INVALID_NODE_NUM;
343 node->nd_local = tmp;
344 if (node->nd_local) {
345 cluster->cl_has_local = tmp;
346 cluster->cl_local_node = node->nd_num;
349 return count;
352 struct o2nm_node_attribute {
353 struct configfs_attribute attr;
354 ssize_t (*show)(struct o2nm_node *, char *);
355 ssize_t (*store)(struct o2nm_node *, const char *, size_t);
358 static struct o2nm_node_attribute o2nm_node_attr_num = {
359 .attr = { .ca_owner = THIS_MODULE,
360 .ca_name = "num",
361 .ca_mode = S_IRUGO | S_IWUSR },
362 .show = o2nm_node_num_read,
363 .store = o2nm_node_num_write,
366 static struct o2nm_node_attribute o2nm_node_attr_ipv4_port = {
367 .attr = { .ca_owner = THIS_MODULE,
368 .ca_name = "ipv4_port",
369 .ca_mode = S_IRUGO | S_IWUSR },
370 .show = o2nm_node_ipv4_port_read,
371 .store = o2nm_node_ipv4_port_write,
374 static struct o2nm_node_attribute o2nm_node_attr_ipv4_address = {
375 .attr = { .ca_owner = THIS_MODULE,
376 .ca_name = "ipv4_address",
377 .ca_mode = S_IRUGO | S_IWUSR },
378 .show = o2nm_node_ipv4_address_read,
379 .store = o2nm_node_ipv4_address_write,
382 static struct o2nm_node_attribute o2nm_node_attr_local = {
383 .attr = { .ca_owner = THIS_MODULE,
384 .ca_name = "local",
385 .ca_mode = S_IRUGO | S_IWUSR },
386 .show = o2nm_node_local_read,
387 .store = o2nm_node_local_write,
390 static struct configfs_attribute *o2nm_node_attrs[] = {
391 [O2NM_NODE_ATTR_NUM] = &o2nm_node_attr_num.attr,
392 [O2NM_NODE_ATTR_PORT] = &o2nm_node_attr_ipv4_port.attr,
393 [O2NM_NODE_ATTR_ADDRESS] = &o2nm_node_attr_ipv4_address.attr,
394 [O2NM_NODE_ATTR_LOCAL] = &o2nm_node_attr_local.attr,
395 NULL,
398 static int o2nm_attr_index(struct configfs_attribute *attr)
400 int i;
401 for (i = 0; i < ARRAY_SIZE(o2nm_node_attrs); i++) {
402 if (attr == o2nm_node_attrs[i])
403 return i;
405 BUG();
406 return 0;
409 static ssize_t o2nm_node_show(struct config_item *item,
410 struct configfs_attribute *attr,
411 char *page)
413 struct o2nm_node *node = to_o2nm_node(item);
414 struct o2nm_node_attribute *o2nm_node_attr =
415 container_of(attr, struct o2nm_node_attribute, attr);
416 ssize_t ret = 0;
418 if (o2nm_node_attr->show)
419 ret = o2nm_node_attr->show(node, page);
420 return ret;
423 static ssize_t o2nm_node_store(struct config_item *item,
424 struct configfs_attribute *attr,
425 const char *page, size_t count)
427 struct o2nm_node *node = to_o2nm_node(item);
428 struct o2nm_node_attribute *o2nm_node_attr =
429 container_of(attr, struct o2nm_node_attribute, attr);
430 ssize_t ret;
431 int attr_index = o2nm_attr_index(attr);
433 if (o2nm_node_attr->store == NULL) {
434 ret = -EINVAL;
435 goto out;
438 if (test_bit(attr_index, &node->nd_set_attributes))
439 return -EBUSY;
441 ret = o2nm_node_attr->store(node, page, count);
442 if (ret < count)
443 goto out;
445 set_bit(attr_index, &node->nd_set_attributes);
446 out:
447 return ret;
450 static struct configfs_item_operations o2nm_node_item_ops = {
451 .release = o2nm_node_release,
452 .show_attribute = o2nm_node_show,
453 .store_attribute = o2nm_node_store,
456 static struct config_item_type o2nm_node_type = {
457 .ct_item_ops = &o2nm_node_item_ops,
458 .ct_attrs = o2nm_node_attrs,
459 .ct_owner = THIS_MODULE,
462 /* node set */
464 struct o2nm_node_group {
465 struct config_group ns_group;
466 /* some stuff? */
469 #if 0
470 static struct o2nm_node_group *to_o2nm_node_group(struct config_group *group)
472 return group ?
473 container_of(group, struct o2nm_node_group, ns_group)
474 : NULL;
476 #endif
478 struct o2nm_cluster_attribute {
479 struct configfs_attribute attr;
480 ssize_t (*show)(struct o2nm_cluster *, char *);
481 ssize_t (*store)(struct o2nm_cluster *, const char *, size_t);
484 static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count,
485 unsigned int *val)
487 unsigned long tmp;
488 char *p = (char *)page;
490 tmp = simple_strtoul(p, &p, 0);
491 if (!p || (*p && (*p != '\n')))
492 return -EINVAL;
494 if (tmp == 0)
495 return -EINVAL;
496 if (tmp >= (u32)-1)
497 return -ERANGE;
499 *val = tmp;
501 return count;
504 static ssize_t o2nm_cluster_attr_idle_timeout_ms_read(
505 struct o2nm_cluster *cluster, char *page)
507 return sprintf(page, "%u\n", cluster->cl_idle_timeout_ms);
510 static ssize_t o2nm_cluster_attr_idle_timeout_ms_write(
511 struct o2nm_cluster *cluster, const char *page, size_t count)
513 ssize_t ret;
514 unsigned int val;
516 ret = o2nm_cluster_attr_write(page, count, &val);
518 if (ret > 0) {
519 if (cluster->cl_idle_timeout_ms != val
520 && o2net_num_connected_peers()) {
521 mlog(ML_NOTICE,
522 "o2net: cannot change idle timeout after "
523 "the first peer has agreed to it."
524 " %d connected peers\n",
525 o2net_num_connected_peers());
526 ret = -EINVAL;
527 } else if (val <= cluster->cl_keepalive_delay_ms) {
528 mlog(ML_NOTICE, "o2net: idle timeout must be larger "
529 "than keepalive delay\n");
530 ret = -EINVAL;
531 } else {
532 cluster->cl_idle_timeout_ms = val;
536 return ret;
539 static ssize_t o2nm_cluster_attr_keepalive_delay_ms_read(
540 struct o2nm_cluster *cluster, char *page)
542 return sprintf(page, "%u\n", cluster->cl_keepalive_delay_ms);
545 static ssize_t o2nm_cluster_attr_keepalive_delay_ms_write(
546 struct o2nm_cluster *cluster, const char *page, size_t count)
548 ssize_t ret;
549 unsigned int val;
551 ret = o2nm_cluster_attr_write(page, count, &val);
553 if (ret > 0) {
554 if (cluster->cl_keepalive_delay_ms != val
555 && o2net_num_connected_peers()) {
556 mlog(ML_NOTICE,
557 "o2net: cannot change keepalive delay after"
558 " the first peer has agreed to it."
559 " %d connected peers\n",
560 o2net_num_connected_peers());
561 ret = -EINVAL;
562 } else if (val >= cluster->cl_idle_timeout_ms) {
563 mlog(ML_NOTICE, "o2net: keepalive delay must be "
564 "smaller than idle timeout\n");
565 ret = -EINVAL;
566 } else {
567 cluster->cl_keepalive_delay_ms = val;
571 return ret;
574 static ssize_t o2nm_cluster_attr_reconnect_delay_ms_read(
575 struct o2nm_cluster *cluster, char *page)
577 return sprintf(page, "%u\n", cluster->cl_reconnect_delay_ms);
580 static ssize_t o2nm_cluster_attr_reconnect_delay_ms_write(
581 struct o2nm_cluster *cluster, const char *page, size_t count)
583 return o2nm_cluster_attr_write(page, count,
584 &cluster->cl_reconnect_delay_ms);
587 static ssize_t o2nm_cluster_attr_fence_method_read(
588 struct o2nm_cluster *cluster, char *page)
590 ssize_t ret = 0;
592 if (cluster)
593 ret = sprintf(page, "%s\n",
594 o2nm_fence_method_desc[cluster->cl_fence_method]);
595 return ret;
598 static ssize_t o2nm_cluster_attr_fence_method_write(
599 struct o2nm_cluster *cluster, const char *page, size_t count)
601 unsigned int i;
603 if (page[count - 1] != '\n')
604 goto bail;
606 for (i = 0; i < O2NM_FENCE_METHODS; ++i) {
607 if (count != strlen(o2nm_fence_method_desc[i]) + 1)
608 continue;
609 if (strncasecmp(page, o2nm_fence_method_desc[i], count - 1))
610 continue;
611 if (cluster->cl_fence_method != i) {
612 printk(KERN_INFO "ocfs2: Changing fence method to %s\n",
613 o2nm_fence_method_desc[i]);
614 cluster->cl_fence_method = i;
616 return count;
619 bail:
620 return -EINVAL;
623 static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms = {
624 .attr = { .ca_owner = THIS_MODULE,
625 .ca_name = "idle_timeout_ms",
626 .ca_mode = S_IRUGO | S_IWUSR },
627 .show = o2nm_cluster_attr_idle_timeout_ms_read,
628 .store = o2nm_cluster_attr_idle_timeout_ms_write,
631 static struct o2nm_cluster_attribute o2nm_cluster_attr_keepalive_delay_ms = {
632 .attr = { .ca_owner = THIS_MODULE,
633 .ca_name = "keepalive_delay_ms",
634 .ca_mode = S_IRUGO | S_IWUSR },
635 .show = o2nm_cluster_attr_keepalive_delay_ms_read,
636 .store = o2nm_cluster_attr_keepalive_delay_ms_write,
639 static struct o2nm_cluster_attribute o2nm_cluster_attr_reconnect_delay_ms = {
640 .attr = { .ca_owner = THIS_MODULE,
641 .ca_name = "reconnect_delay_ms",
642 .ca_mode = S_IRUGO | S_IWUSR },
643 .show = o2nm_cluster_attr_reconnect_delay_ms_read,
644 .store = o2nm_cluster_attr_reconnect_delay_ms_write,
647 static struct o2nm_cluster_attribute o2nm_cluster_attr_fence_method = {
648 .attr = { .ca_owner = THIS_MODULE,
649 .ca_name = "fence_method",
650 .ca_mode = S_IRUGO | S_IWUSR },
651 .show = o2nm_cluster_attr_fence_method_read,
652 .store = o2nm_cluster_attr_fence_method_write,
655 static struct configfs_attribute *o2nm_cluster_attrs[] = {
656 &o2nm_cluster_attr_idle_timeout_ms.attr,
657 &o2nm_cluster_attr_keepalive_delay_ms.attr,
658 &o2nm_cluster_attr_reconnect_delay_ms.attr,
659 &o2nm_cluster_attr_fence_method.attr,
660 NULL,
662 static ssize_t o2nm_cluster_show(struct config_item *item,
663 struct configfs_attribute *attr,
664 char *page)
666 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
667 struct o2nm_cluster_attribute *o2nm_cluster_attr =
668 container_of(attr, struct o2nm_cluster_attribute, attr);
669 ssize_t ret = 0;
671 if (o2nm_cluster_attr->show)
672 ret = o2nm_cluster_attr->show(cluster, page);
673 return ret;
676 static ssize_t o2nm_cluster_store(struct config_item *item,
677 struct configfs_attribute *attr,
678 const char *page, size_t count)
680 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
681 struct o2nm_cluster_attribute *o2nm_cluster_attr =
682 container_of(attr, struct o2nm_cluster_attribute, attr);
683 ssize_t ret;
685 if (o2nm_cluster_attr->store == NULL) {
686 ret = -EINVAL;
687 goto out;
690 ret = o2nm_cluster_attr->store(cluster, page, count);
691 if (ret < count)
692 goto out;
693 out:
694 return ret;
697 static struct config_item *o2nm_node_group_make_item(struct config_group *group,
698 const char *name)
700 struct o2nm_node *node = NULL;
702 if (strlen(name) > O2NM_MAX_NAME_LEN)
703 return ERR_PTR(-ENAMETOOLONG);
705 node = kzalloc(sizeof(struct o2nm_node), GFP_KERNEL);
706 if (node == NULL)
707 return ERR_PTR(-ENOMEM);
709 strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */
710 config_item_init_type_name(&node->nd_item, name, &o2nm_node_type);
711 spin_lock_init(&node->nd_lock);
713 mlog(ML_CLUSTER, "o2nm: Registering node %s\n", name);
715 return &node->nd_item;
718 static void o2nm_node_group_drop_item(struct config_group *group,
719 struct config_item *item)
721 struct o2nm_node *node = to_o2nm_node(item);
722 struct o2nm_cluster *cluster = to_o2nm_cluster(group->cg_item.ci_parent);
724 o2net_disconnect_node(node);
726 if (cluster->cl_has_local &&
727 (cluster->cl_local_node == node->nd_num)) {
728 cluster->cl_has_local = 0;
729 cluster->cl_local_node = O2NM_INVALID_NODE_NUM;
730 o2net_stop_listening(node);
733 /* XXX call into net to stop this node from trading messages */
735 write_lock(&cluster->cl_nodes_lock);
737 /* XXX sloppy */
738 if (node->nd_ipv4_address)
739 rb_erase(&node->nd_ip_node, &cluster->cl_node_ip_tree);
741 /* nd_num might be 0 if the node number hasn't been set.. */
742 if (cluster->cl_nodes[node->nd_num] == node) {
743 cluster->cl_nodes[node->nd_num] = NULL;
744 clear_bit(node->nd_num, cluster->cl_nodes_bitmap);
746 write_unlock(&cluster->cl_nodes_lock);
748 mlog(ML_CLUSTER, "o2nm: Unregistered node %s\n",
749 config_item_name(&node->nd_item));
751 config_item_put(item);
754 static struct configfs_group_operations o2nm_node_group_group_ops = {
755 .make_item = o2nm_node_group_make_item,
756 .drop_item = o2nm_node_group_drop_item,
759 static struct config_item_type o2nm_node_group_type = {
760 .ct_group_ops = &o2nm_node_group_group_ops,
761 .ct_owner = THIS_MODULE,
764 /* cluster */
766 static void o2nm_cluster_release(struct config_item *item)
768 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
770 kfree(cluster->cl_group.default_groups);
771 kfree(cluster);
774 static struct configfs_item_operations o2nm_cluster_item_ops = {
775 .release = o2nm_cluster_release,
776 .show_attribute = o2nm_cluster_show,
777 .store_attribute = o2nm_cluster_store,
780 static struct config_item_type o2nm_cluster_type = {
781 .ct_item_ops = &o2nm_cluster_item_ops,
782 .ct_attrs = o2nm_cluster_attrs,
783 .ct_owner = THIS_MODULE,
786 /* cluster set */
788 struct o2nm_cluster_group {
789 struct configfs_subsystem cs_subsys;
790 /* some stuff? */
793 #if 0
794 static struct o2nm_cluster_group *to_o2nm_cluster_group(struct config_group *group)
796 return group ?
797 container_of(to_configfs_subsystem(group), struct o2nm_cluster_group, cs_subsys)
798 : NULL;
800 #endif
802 static struct config_group *o2nm_cluster_group_make_group(struct config_group *group,
803 const char *name)
805 struct o2nm_cluster *cluster = NULL;
806 struct o2nm_node_group *ns = NULL;
807 struct config_group *o2hb_group = NULL, *ret = NULL;
808 void *defs = NULL;
810 /* this runs under the parent dir's i_mutex; there can be only
811 * one caller in here at a time */
812 if (o2nm_single_cluster)
813 return ERR_PTR(-ENOSPC);
815 cluster = kzalloc(sizeof(struct o2nm_cluster), GFP_KERNEL);
816 ns = kzalloc(sizeof(struct o2nm_node_group), GFP_KERNEL);
817 defs = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL);
818 o2hb_group = o2hb_alloc_hb_set();
819 if (cluster == NULL || ns == NULL || o2hb_group == NULL || defs == NULL)
820 goto out;
822 config_group_init_type_name(&cluster->cl_group, name,
823 &o2nm_cluster_type);
824 config_group_init_type_name(&ns->ns_group, "node",
825 &o2nm_node_group_type);
827 cluster->cl_group.default_groups = defs;
828 cluster->cl_group.default_groups[0] = &ns->ns_group;
829 cluster->cl_group.default_groups[1] = o2hb_group;
830 cluster->cl_group.default_groups[2] = NULL;
831 rwlock_init(&cluster->cl_nodes_lock);
832 cluster->cl_node_ip_tree = RB_ROOT;
833 cluster->cl_reconnect_delay_ms = O2NET_RECONNECT_DELAY_MS_DEFAULT;
834 cluster->cl_idle_timeout_ms = O2NET_IDLE_TIMEOUT_MS_DEFAULT;
835 cluster->cl_keepalive_delay_ms = O2NET_KEEPALIVE_DELAY_MS_DEFAULT;
836 cluster->cl_fence_method = O2NM_FENCE_RESET;
838 ret = &cluster->cl_group;
839 o2nm_single_cluster = cluster;
841 out:
842 if (ret == NULL) {
843 kfree(cluster);
844 kfree(ns);
845 o2hb_free_hb_set(o2hb_group);
846 kfree(defs);
847 ret = ERR_PTR(-ENOMEM);
850 return ret;
853 static void o2nm_cluster_group_drop_item(struct config_group *group, struct config_item *item)
855 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
856 int i;
857 struct config_item *killme;
859 BUG_ON(o2nm_single_cluster != cluster);
860 o2nm_single_cluster = NULL;
862 for (i = 0; cluster->cl_group.default_groups[i]; i++) {
863 killme = &cluster->cl_group.default_groups[i]->cg_item;
864 cluster->cl_group.default_groups[i] = NULL;
865 config_item_put(killme);
868 config_item_put(item);
871 static struct configfs_group_operations o2nm_cluster_group_group_ops = {
872 .make_group = o2nm_cluster_group_make_group,
873 .drop_item = o2nm_cluster_group_drop_item,
876 static struct config_item_type o2nm_cluster_group_type = {
877 .ct_group_ops = &o2nm_cluster_group_group_ops,
878 .ct_owner = THIS_MODULE,
881 static struct o2nm_cluster_group o2nm_cluster_group = {
882 .cs_subsys = {
883 .su_group = {
884 .cg_item = {
885 .ci_namebuf = "cluster",
886 .ci_type = &o2nm_cluster_group_type,
892 int o2nm_depend_item(struct config_item *item)
894 return configfs_depend_item(&o2nm_cluster_group.cs_subsys, item);
897 void o2nm_undepend_item(struct config_item *item)
899 configfs_undepend_item(&o2nm_cluster_group.cs_subsys, item);
902 int o2nm_depend_this_node(void)
904 int ret = 0;
905 struct o2nm_node *local_node;
907 local_node = o2nm_get_node_by_num(o2nm_this_node());
908 if (!local_node) {
909 ret = -EINVAL;
910 goto out;
913 ret = o2nm_depend_item(&local_node->nd_item);
914 o2nm_node_put(local_node);
916 out:
917 return ret;
920 void o2nm_undepend_this_node(void)
922 struct o2nm_node *local_node;
924 local_node = o2nm_get_node_by_num(o2nm_this_node());
925 BUG_ON(!local_node);
927 o2nm_undepend_item(&local_node->nd_item);
928 o2nm_node_put(local_node);
932 static void __exit exit_o2nm(void)
934 /* XXX sync with hb callbacks and shut down hb? */
935 o2net_unregister_hb_callbacks();
936 configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
937 o2cb_sys_shutdown();
939 o2net_exit();
940 o2hb_exit();
943 static int __init init_o2nm(void)
945 int ret = -1;
947 ret = o2hb_init();
948 if (ret)
949 goto out;
951 ret = o2net_init();
952 if (ret)
953 goto out_o2hb;
955 ret = o2net_register_hb_callbacks();
956 if (ret)
957 goto out_o2net;
959 config_group_init(&o2nm_cluster_group.cs_subsys.su_group);
960 mutex_init(&o2nm_cluster_group.cs_subsys.su_mutex);
961 ret = configfs_register_subsystem(&o2nm_cluster_group.cs_subsys);
962 if (ret) {
963 printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
964 goto out_callbacks;
967 ret = o2cb_sys_init();
968 if (!ret)
969 goto out;
971 configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
972 out_callbacks:
973 o2net_unregister_hb_callbacks();
974 out_o2net:
975 o2net_exit();
976 out_o2hb:
977 o2hb_exit();
978 out:
979 return ret;
982 MODULE_AUTHOR("Oracle");
983 MODULE_LICENSE("GPL");
984 MODULE_DESCRIPTION("OCFS2 cluster management");
986 module_init(init_o2nm)
987 module_exit(exit_o2nm)