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/kernel.h>
23 #include <linux/module.h>
24 #include <linux/sysctl.h>
25 #include <linux/configfs.h>
28 #include "nodemanager.h"
29 #include "heartbeat.h"
34 /* for now we operate under the assertion that there can be only one
35 * cluster active at a time. Changing this will require trickling
36 * cluster references throughout where nodes are looked up */
37 struct o2nm_cluster
*o2nm_single_cluster
= NULL
;
39 #define OCFS2_MAX_HB_CTL_PATH 256
40 static char ocfs2_hb_ctl_path
[OCFS2_MAX_HB_CTL_PATH
] = "/sbin/ocfs2_hb_ctl";
42 static ctl_table ocfs2_nm_table
[] = {
45 .procname
= "hb_ctl_path",
46 .data
= ocfs2_hb_ctl_path
,
47 .maxlen
= OCFS2_MAX_HB_CTL_PATH
,
49 .proc_handler
= &proc_dostring
,
50 .strategy
= &sysctl_string
,
55 static ctl_table ocfs2_mod_table
[] = {
57 .ctl_name
= FS_OCFS2_NM
,
62 .child
= ocfs2_nm_table
67 static ctl_table ocfs2_kern_table
[] = {
74 .child
= ocfs2_mod_table
79 static ctl_table ocfs2_root_table
[] = {
86 .child
= ocfs2_kern_table
91 static struct ctl_table_header
*ocfs2_table_header
= NULL
;
93 const char *o2nm_get_hb_ctl_path(void)
95 return ocfs2_hb_ctl_path
;
97 EXPORT_SYMBOL_GPL(o2nm_get_hb_ctl_path
);
99 struct o2nm_node
*o2nm_get_node_by_num(u8 node_num
)
101 struct o2nm_node
*node
= NULL
;
103 if (node_num
>= O2NM_MAX_NODES
|| o2nm_single_cluster
== NULL
)
106 read_lock(&o2nm_single_cluster
->cl_nodes_lock
);
107 node
= o2nm_single_cluster
->cl_nodes
[node_num
];
109 config_item_get(&node
->nd_item
);
110 read_unlock(&o2nm_single_cluster
->cl_nodes_lock
);
114 EXPORT_SYMBOL_GPL(o2nm_get_node_by_num
);
116 int o2nm_configured_node_map(unsigned long *map
, unsigned bytes
)
118 struct o2nm_cluster
*cluster
= o2nm_single_cluster
;
120 BUG_ON(bytes
< (sizeof(cluster
->cl_nodes_bitmap
)));
125 read_lock(&cluster
->cl_nodes_lock
);
126 memcpy(map
, cluster
->cl_nodes_bitmap
, sizeof(cluster
->cl_nodes_bitmap
));
127 read_unlock(&cluster
->cl_nodes_lock
);
131 EXPORT_SYMBOL_GPL(o2nm_configured_node_map
);
133 static struct o2nm_node
*o2nm_node_ip_tree_lookup(struct o2nm_cluster
*cluster
,
135 struct rb_node
***ret_p
,
136 struct rb_node
**ret_parent
)
138 struct rb_node
**p
= &cluster
->cl_node_ip_tree
.rb_node
;
139 struct rb_node
*parent
= NULL
;
140 struct o2nm_node
*node
, *ret
= NULL
;
146 node
= rb_entry(parent
, struct o2nm_node
, nd_ip_node
);
148 cmp
= memcmp(&ip_needle
, &node
->nd_ipv4_address
,
162 if (ret_parent
!= NULL
)
163 *ret_parent
= parent
;
168 struct o2nm_node
*o2nm_get_node_by_ip(__be32 addr
)
170 struct o2nm_node
*node
= NULL
;
171 struct o2nm_cluster
*cluster
= o2nm_single_cluster
;
176 read_lock(&cluster
->cl_nodes_lock
);
177 node
= o2nm_node_ip_tree_lookup(cluster
, addr
, NULL
, NULL
);
179 config_item_get(&node
->nd_item
);
180 read_unlock(&cluster
->cl_nodes_lock
);
185 EXPORT_SYMBOL_GPL(o2nm_get_node_by_ip
);
187 void o2nm_node_put(struct o2nm_node
*node
)
189 config_item_put(&node
->nd_item
);
191 EXPORT_SYMBOL_GPL(o2nm_node_put
);
193 void o2nm_node_get(struct o2nm_node
*node
)
195 config_item_get(&node
->nd_item
);
197 EXPORT_SYMBOL_GPL(o2nm_node_get
);
199 u8
o2nm_this_node(void)
201 u8 node_num
= O2NM_MAX_NODES
;
203 if (o2nm_single_cluster
&& o2nm_single_cluster
->cl_has_local
)
204 node_num
= o2nm_single_cluster
->cl_local_node
;
208 EXPORT_SYMBOL_GPL(o2nm_this_node
);
210 /* node configfs bits */
212 static struct o2nm_cluster
*to_o2nm_cluster(struct config_item
*item
)
215 container_of(to_config_group(item
), struct o2nm_cluster
,
220 static struct o2nm_node
*to_o2nm_node(struct config_item
*item
)
222 return item
? container_of(item
, struct o2nm_node
, nd_item
) : NULL
;
225 static void o2nm_node_release(struct config_item
*item
)
227 struct o2nm_node
*node
= to_o2nm_node(item
);
231 static ssize_t
o2nm_node_num_read(struct o2nm_node
*node
, char *page
)
233 return sprintf(page
, "%d\n", node
->nd_num
);
236 static struct o2nm_cluster
*to_o2nm_cluster_from_node(struct o2nm_node
*node
)
238 /* through the first node_set .parent
239 * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
240 return to_o2nm_cluster(node
->nd_item
.ci_parent
->ci_parent
);
244 O2NM_NODE_ATTR_NUM
= 0,
246 O2NM_NODE_ATTR_ADDRESS
,
247 O2NM_NODE_ATTR_LOCAL
,
250 static ssize_t
o2nm_node_num_write(struct o2nm_node
*node
, const char *page
,
253 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
255 char *p
= (char *)page
;
257 tmp
= simple_strtoul(p
, &p
, 0);
258 if (!p
|| (*p
&& (*p
!= '\n')))
261 if (tmp
>= O2NM_MAX_NODES
)
264 /* once we're in the cl_nodes tree networking can look us up by
265 * node number and try to use our address and port attributes
266 * to connect to this node.. make sure that they've been set
267 * before writing the node attribute? */
268 if (!test_bit(O2NM_NODE_ATTR_ADDRESS
, &node
->nd_set_attributes
) ||
269 !test_bit(O2NM_NODE_ATTR_PORT
, &node
->nd_set_attributes
))
270 return -EINVAL
; /* XXX */
272 write_lock(&cluster
->cl_nodes_lock
);
273 if (cluster
->cl_nodes
[tmp
])
276 cluster
->cl_nodes
[tmp
] = node
;
278 set_bit(tmp
, cluster
->cl_nodes_bitmap
);
280 write_unlock(&cluster
->cl_nodes_lock
);
286 static ssize_t
o2nm_node_ipv4_port_read(struct o2nm_node
*node
, char *page
)
288 return sprintf(page
, "%u\n", ntohs(node
->nd_ipv4_port
));
291 static ssize_t
o2nm_node_ipv4_port_write(struct o2nm_node
*node
,
292 const char *page
, size_t count
)
295 char *p
= (char *)page
;
297 tmp
= simple_strtoul(p
, &p
, 0);
298 if (!p
|| (*p
&& (*p
!= '\n')))
306 node
->nd_ipv4_port
= htons(tmp
);
311 static ssize_t
o2nm_node_ipv4_address_read(struct o2nm_node
*node
, char *page
)
313 return sprintf(page
, "%u.%u.%u.%u\n", NIPQUAD(node
->nd_ipv4_address
));
316 static ssize_t
o2nm_node_ipv4_address_write(struct o2nm_node
*node
,
320 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
322 struct rb_node
**p
, *parent
;
323 unsigned int octets
[4];
324 __be32 ipv4_addr
= 0;
326 ret
= sscanf(page
, "%3u.%3u.%3u.%3u", &octets
[3], &octets
[2],
327 &octets
[1], &octets
[0]);
331 for (i
= 0; i
< ARRAY_SIZE(octets
); i
++) {
334 be32_add_cpu(&ipv4_addr
, octets
[i
] << (i
* 8));
338 write_lock(&cluster
->cl_nodes_lock
);
339 if (o2nm_node_ip_tree_lookup(cluster
, ipv4_addr
, &p
, &parent
))
342 rb_link_node(&node
->nd_ip_node
, parent
, p
);
343 rb_insert_color(&node
->nd_ip_node
, &cluster
->cl_node_ip_tree
);
345 write_unlock(&cluster
->cl_nodes_lock
);
349 memcpy(&node
->nd_ipv4_address
, &ipv4_addr
, sizeof(ipv4_addr
));
354 static ssize_t
o2nm_node_local_read(struct o2nm_node
*node
, char *page
)
356 return sprintf(page
, "%d\n", node
->nd_local
);
359 static ssize_t
o2nm_node_local_write(struct o2nm_node
*node
, const char *page
,
362 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
364 char *p
= (char *)page
;
367 tmp
= simple_strtoul(p
, &p
, 0);
368 if (!p
|| (*p
&& (*p
!= '\n')))
371 tmp
= !!tmp
; /* boolean of whether this node wants to be local */
373 /* setting local turns on networking rx for now so we require having
374 * set everything else first */
375 if (!test_bit(O2NM_NODE_ATTR_ADDRESS
, &node
->nd_set_attributes
) ||
376 !test_bit(O2NM_NODE_ATTR_NUM
, &node
->nd_set_attributes
) ||
377 !test_bit(O2NM_NODE_ATTR_PORT
, &node
->nd_set_attributes
))
378 return -EINVAL
; /* XXX */
380 /* the only failure case is trying to set a new local node
381 * when a different one is already set */
382 if (tmp
&& tmp
== cluster
->cl_has_local
&&
383 cluster
->cl_local_node
!= node
->nd_num
)
386 /* bring up the rx thread if we're setting the new local node. */
387 if (tmp
&& !cluster
->cl_has_local
) {
388 ret
= o2net_start_listening(node
);
393 if (!tmp
&& cluster
->cl_has_local
&&
394 cluster
->cl_local_node
== node
->nd_num
) {
395 o2net_stop_listening(node
);
396 cluster
->cl_local_node
= O2NM_INVALID_NODE_NUM
;
399 node
->nd_local
= tmp
;
400 if (node
->nd_local
) {
401 cluster
->cl_has_local
= tmp
;
402 cluster
->cl_local_node
= node
->nd_num
;
408 struct o2nm_node_attribute
{
409 struct configfs_attribute attr
;
410 ssize_t (*show
)(struct o2nm_node
*, char *);
411 ssize_t (*store
)(struct o2nm_node
*, const char *, size_t);
414 static struct o2nm_node_attribute o2nm_node_attr_num
= {
415 .attr
= { .ca_owner
= THIS_MODULE
,
417 .ca_mode
= S_IRUGO
| S_IWUSR
},
418 .show
= o2nm_node_num_read
,
419 .store
= o2nm_node_num_write
,
422 static struct o2nm_node_attribute o2nm_node_attr_ipv4_port
= {
423 .attr
= { .ca_owner
= THIS_MODULE
,
424 .ca_name
= "ipv4_port",
425 .ca_mode
= S_IRUGO
| S_IWUSR
},
426 .show
= o2nm_node_ipv4_port_read
,
427 .store
= o2nm_node_ipv4_port_write
,
430 static struct o2nm_node_attribute o2nm_node_attr_ipv4_address
= {
431 .attr
= { .ca_owner
= THIS_MODULE
,
432 .ca_name
= "ipv4_address",
433 .ca_mode
= S_IRUGO
| S_IWUSR
},
434 .show
= o2nm_node_ipv4_address_read
,
435 .store
= o2nm_node_ipv4_address_write
,
438 static struct o2nm_node_attribute o2nm_node_attr_local
= {
439 .attr
= { .ca_owner
= THIS_MODULE
,
441 .ca_mode
= S_IRUGO
| S_IWUSR
},
442 .show
= o2nm_node_local_read
,
443 .store
= o2nm_node_local_write
,
446 static struct configfs_attribute
*o2nm_node_attrs
[] = {
447 [O2NM_NODE_ATTR_NUM
] = &o2nm_node_attr_num
.attr
,
448 [O2NM_NODE_ATTR_PORT
] = &o2nm_node_attr_ipv4_port
.attr
,
449 [O2NM_NODE_ATTR_ADDRESS
] = &o2nm_node_attr_ipv4_address
.attr
,
450 [O2NM_NODE_ATTR_LOCAL
] = &o2nm_node_attr_local
.attr
,
454 static int o2nm_attr_index(struct configfs_attribute
*attr
)
457 for (i
= 0; i
< ARRAY_SIZE(o2nm_node_attrs
); i
++) {
458 if (attr
== o2nm_node_attrs
[i
])
465 static ssize_t
o2nm_node_show(struct config_item
*item
,
466 struct configfs_attribute
*attr
,
469 struct o2nm_node
*node
= to_o2nm_node(item
);
470 struct o2nm_node_attribute
*o2nm_node_attr
=
471 container_of(attr
, struct o2nm_node_attribute
, attr
);
474 if (o2nm_node_attr
->show
)
475 ret
= o2nm_node_attr
->show(node
, page
);
479 static ssize_t
o2nm_node_store(struct config_item
*item
,
480 struct configfs_attribute
*attr
,
481 const char *page
, size_t count
)
483 struct o2nm_node
*node
= to_o2nm_node(item
);
484 struct o2nm_node_attribute
*o2nm_node_attr
=
485 container_of(attr
, struct o2nm_node_attribute
, attr
);
487 int attr_index
= o2nm_attr_index(attr
);
489 if (o2nm_node_attr
->store
== NULL
) {
494 if (test_bit(attr_index
, &node
->nd_set_attributes
))
497 ret
= o2nm_node_attr
->store(node
, page
, count
);
501 set_bit(attr_index
, &node
->nd_set_attributes
);
506 static struct configfs_item_operations o2nm_node_item_ops
= {
507 .release
= o2nm_node_release
,
508 .show_attribute
= o2nm_node_show
,
509 .store_attribute
= o2nm_node_store
,
512 static struct config_item_type o2nm_node_type
= {
513 .ct_item_ops
= &o2nm_node_item_ops
,
514 .ct_attrs
= o2nm_node_attrs
,
515 .ct_owner
= THIS_MODULE
,
520 struct o2nm_node_group
{
521 struct config_group ns_group
;
526 static struct o2nm_node_group
*to_o2nm_node_group(struct config_group
*group
)
529 container_of(group
, struct o2nm_node_group
, ns_group
)
534 struct o2nm_cluster_attribute
{
535 struct configfs_attribute attr
;
536 ssize_t (*show
)(struct o2nm_cluster
*, char *);
537 ssize_t (*store
)(struct o2nm_cluster
*, const char *, size_t);
540 static ssize_t
o2nm_cluster_attr_write(const char *page
, ssize_t count
,
544 char *p
= (char *)page
;
546 tmp
= simple_strtoul(p
, &p
, 0);
547 if (!p
|| (*p
&& (*p
!= '\n')))
560 static ssize_t
o2nm_cluster_attr_idle_timeout_ms_read(
561 struct o2nm_cluster
*cluster
, char *page
)
563 return sprintf(page
, "%u\n", cluster
->cl_idle_timeout_ms
);
566 static ssize_t
o2nm_cluster_attr_idle_timeout_ms_write(
567 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
572 ret
= o2nm_cluster_attr_write(page
, count
, &val
);
575 if (cluster
->cl_idle_timeout_ms
!= val
576 && o2net_num_connected_peers()) {
578 "o2net: cannot change idle timeout after "
579 "the first peer has agreed to it."
580 " %d connected peers\n",
581 o2net_num_connected_peers());
583 } else if (val
<= cluster
->cl_keepalive_delay_ms
) {
584 mlog(ML_NOTICE
, "o2net: idle timeout must be larger "
585 "than keepalive delay\n");
588 cluster
->cl_idle_timeout_ms
= val
;
595 static ssize_t
o2nm_cluster_attr_keepalive_delay_ms_read(
596 struct o2nm_cluster
*cluster
, char *page
)
598 return sprintf(page
, "%u\n", cluster
->cl_keepalive_delay_ms
);
601 static ssize_t
o2nm_cluster_attr_keepalive_delay_ms_write(
602 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
607 ret
= o2nm_cluster_attr_write(page
, count
, &val
);
610 if (cluster
->cl_keepalive_delay_ms
!= val
611 && o2net_num_connected_peers()) {
613 "o2net: cannot change keepalive delay after"
614 " the first peer has agreed to it."
615 " %d connected peers\n",
616 o2net_num_connected_peers());
618 } else if (val
>= cluster
->cl_idle_timeout_ms
) {
619 mlog(ML_NOTICE
, "o2net: keepalive delay must be "
620 "smaller than idle timeout\n");
623 cluster
->cl_keepalive_delay_ms
= val
;
630 static ssize_t
o2nm_cluster_attr_reconnect_delay_ms_read(
631 struct o2nm_cluster
*cluster
, char *page
)
633 return sprintf(page
, "%u\n", cluster
->cl_reconnect_delay_ms
);
636 static ssize_t
o2nm_cluster_attr_reconnect_delay_ms_write(
637 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
639 return o2nm_cluster_attr_write(page
, count
,
640 &cluster
->cl_reconnect_delay_ms
);
642 static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms
= {
643 .attr
= { .ca_owner
= THIS_MODULE
,
644 .ca_name
= "idle_timeout_ms",
645 .ca_mode
= S_IRUGO
| S_IWUSR
},
646 .show
= o2nm_cluster_attr_idle_timeout_ms_read
,
647 .store
= o2nm_cluster_attr_idle_timeout_ms_write
,
650 static struct o2nm_cluster_attribute o2nm_cluster_attr_keepalive_delay_ms
= {
651 .attr
= { .ca_owner
= THIS_MODULE
,
652 .ca_name
= "keepalive_delay_ms",
653 .ca_mode
= S_IRUGO
| S_IWUSR
},
654 .show
= o2nm_cluster_attr_keepalive_delay_ms_read
,
655 .store
= o2nm_cluster_attr_keepalive_delay_ms_write
,
658 static struct o2nm_cluster_attribute o2nm_cluster_attr_reconnect_delay_ms
= {
659 .attr
= { .ca_owner
= THIS_MODULE
,
660 .ca_name
= "reconnect_delay_ms",
661 .ca_mode
= S_IRUGO
| S_IWUSR
},
662 .show
= o2nm_cluster_attr_reconnect_delay_ms_read
,
663 .store
= o2nm_cluster_attr_reconnect_delay_ms_write
,
666 static struct configfs_attribute
*o2nm_cluster_attrs
[] = {
667 &o2nm_cluster_attr_idle_timeout_ms
.attr
,
668 &o2nm_cluster_attr_keepalive_delay_ms
.attr
,
669 &o2nm_cluster_attr_reconnect_delay_ms
.attr
,
672 static ssize_t
o2nm_cluster_show(struct config_item
*item
,
673 struct configfs_attribute
*attr
,
676 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
677 struct o2nm_cluster_attribute
*o2nm_cluster_attr
=
678 container_of(attr
, struct o2nm_cluster_attribute
, attr
);
681 if (o2nm_cluster_attr
->show
)
682 ret
= o2nm_cluster_attr
->show(cluster
, page
);
686 static ssize_t
o2nm_cluster_store(struct config_item
*item
,
687 struct configfs_attribute
*attr
,
688 const char *page
, size_t count
)
690 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
691 struct o2nm_cluster_attribute
*o2nm_cluster_attr
=
692 container_of(attr
, struct o2nm_cluster_attribute
, attr
);
695 if (o2nm_cluster_attr
->store
== NULL
) {
700 ret
= o2nm_cluster_attr
->store(cluster
, page
, count
);
707 static struct config_item
*o2nm_node_group_make_item(struct config_group
*group
,
710 struct o2nm_node
*node
= NULL
;
711 struct config_item
*ret
= NULL
;
713 if (strlen(name
) > O2NM_MAX_NAME_LEN
)
714 goto out
; /* ENAMETOOLONG */
716 node
= kzalloc(sizeof(struct o2nm_node
), GFP_KERNEL
);
718 goto out
; /* ENOMEM */
720 strcpy(node
->nd_name
, name
); /* use item.ci_namebuf instead? */
721 config_item_init_type_name(&node
->nd_item
, name
, &o2nm_node_type
);
722 spin_lock_init(&node
->nd_lock
);
724 ret
= &node
->nd_item
;
733 static void o2nm_node_group_drop_item(struct config_group
*group
,
734 struct config_item
*item
)
736 struct o2nm_node
*node
= to_o2nm_node(item
);
737 struct o2nm_cluster
*cluster
= to_o2nm_cluster(group
->cg_item
.ci_parent
);
739 o2net_disconnect_node(node
);
741 if (cluster
->cl_has_local
&&
742 (cluster
->cl_local_node
== node
->nd_num
)) {
743 cluster
->cl_has_local
= 0;
744 cluster
->cl_local_node
= O2NM_INVALID_NODE_NUM
;
745 o2net_stop_listening(node
);
748 /* XXX call into net to stop this node from trading messages */
750 write_lock(&cluster
->cl_nodes_lock
);
753 if (node
->nd_ipv4_address
)
754 rb_erase(&node
->nd_ip_node
, &cluster
->cl_node_ip_tree
);
756 /* nd_num might be 0 if the node number hasn't been set.. */
757 if (cluster
->cl_nodes
[node
->nd_num
] == node
) {
758 cluster
->cl_nodes
[node
->nd_num
] = NULL
;
759 clear_bit(node
->nd_num
, cluster
->cl_nodes_bitmap
);
761 write_unlock(&cluster
->cl_nodes_lock
);
763 config_item_put(item
);
766 static struct configfs_group_operations o2nm_node_group_group_ops
= {
767 .make_item
= o2nm_node_group_make_item
,
768 .drop_item
= o2nm_node_group_drop_item
,
771 static struct config_item_type o2nm_node_group_type
= {
772 .ct_group_ops
= &o2nm_node_group_group_ops
,
773 .ct_owner
= THIS_MODULE
,
778 static void o2nm_cluster_release(struct config_item
*item
)
780 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
782 kfree(cluster
->cl_group
.default_groups
);
786 static struct configfs_item_operations o2nm_cluster_item_ops
= {
787 .release
= o2nm_cluster_release
,
788 .show_attribute
= o2nm_cluster_show
,
789 .store_attribute
= o2nm_cluster_store
,
792 static struct config_item_type o2nm_cluster_type
= {
793 .ct_item_ops
= &o2nm_cluster_item_ops
,
794 .ct_attrs
= o2nm_cluster_attrs
,
795 .ct_owner
= THIS_MODULE
,
800 struct o2nm_cluster_group
{
801 struct configfs_subsystem cs_subsys
;
806 static struct o2nm_cluster_group
*to_o2nm_cluster_group(struct config_group
*group
)
809 container_of(to_configfs_subsystem(group
), struct o2nm_cluster_group
, cs_subsys
)
814 static struct config_group
*o2nm_cluster_group_make_group(struct config_group
*group
,
817 struct o2nm_cluster
*cluster
= NULL
;
818 struct o2nm_node_group
*ns
= NULL
;
819 struct config_group
*o2hb_group
= NULL
, *ret
= NULL
;
822 /* this runs under the parent dir's i_mutex; there can be only
823 * one caller in here at a time */
824 if (o2nm_single_cluster
)
825 goto out
; /* ENOSPC */
827 cluster
= kzalloc(sizeof(struct o2nm_cluster
), GFP_KERNEL
);
828 ns
= kzalloc(sizeof(struct o2nm_node_group
), GFP_KERNEL
);
829 defs
= kcalloc(3, sizeof(struct config_group
*), GFP_KERNEL
);
830 o2hb_group
= o2hb_alloc_hb_set();
831 if (cluster
== NULL
|| ns
== NULL
|| o2hb_group
== NULL
|| defs
== NULL
)
834 config_group_init_type_name(&cluster
->cl_group
, name
,
836 config_group_init_type_name(&ns
->ns_group
, "node",
837 &o2nm_node_group_type
);
839 cluster
->cl_group
.default_groups
= defs
;
840 cluster
->cl_group
.default_groups
[0] = &ns
->ns_group
;
841 cluster
->cl_group
.default_groups
[1] = o2hb_group
;
842 cluster
->cl_group
.default_groups
[2] = NULL
;
843 rwlock_init(&cluster
->cl_nodes_lock
);
844 cluster
->cl_node_ip_tree
= RB_ROOT
;
845 cluster
->cl_reconnect_delay_ms
= O2NET_RECONNECT_DELAY_MS_DEFAULT
;
846 cluster
->cl_idle_timeout_ms
= O2NET_IDLE_TIMEOUT_MS_DEFAULT
;
847 cluster
->cl_keepalive_delay_ms
= O2NET_KEEPALIVE_DELAY_MS_DEFAULT
;
849 ret
= &cluster
->cl_group
;
850 o2nm_single_cluster
= cluster
;
856 o2hb_free_hb_set(o2hb_group
);
863 static void o2nm_cluster_group_drop_item(struct config_group
*group
, struct config_item
*item
)
865 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
867 struct config_item
*killme
;
869 BUG_ON(o2nm_single_cluster
!= cluster
);
870 o2nm_single_cluster
= NULL
;
872 for (i
= 0; cluster
->cl_group
.default_groups
[i
]; i
++) {
873 killme
= &cluster
->cl_group
.default_groups
[i
]->cg_item
;
874 cluster
->cl_group
.default_groups
[i
] = NULL
;
875 config_item_put(killme
);
878 config_item_put(item
);
881 static struct configfs_group_operations o2nm_cluster_group_group_ops
= {
882 .make_group
= o2nm_cluster_group_make_group
,
883 .drop_item
= o2nm_cluster_group_drop_item
,
886 static struct config_item_type o2nm_cluster_group_type
= {
887 .ct_group_ops
= &o2nm_cluster_group_group_ops
,
888 .ct_owner
= THIS_MODULE
,
891 static struct o2nm_cluster_group o2nm_cluster_group
= {
895 .ci_namebuf
= "cluster",
896 .ci_type
= &o2nm_cluster_group_type
,
902 int o2nm_depend_item(struct config_item
*item
)
904 return configfs_depend_item(&o2nm_cluster_group
.cs_subsys
, item
);
907 void o2nm_undepend_item(struct config_item
*item
)
909 configfs_undepend_item(&o2nm_cluster_group
.cs_subsys
, item
);
912 int o2nm_depend_this_node(void)
915 struct o2nm_node
*local_node
;
917 local_node
= o2nm_get_node_by_num(o2nm_this_node());
923 ret
= o2nm_depend_item(&local_node
->nd_item
);
924 o2nm_node_put(local_node
);
930 void o2nm_undepend_this_node(void)
932 struct o2nm_node
*local_node
;
934 local_node
= o2nm_get_node_by_num(o2nm_this_node());
937 o2nm_undepend_item(&local_node
->nd_item
);
938 o2nm_node_put(local_node
);
942 static void __exit
exit_o2nm(void)
944 if (ocfs2_table_header
)
945 unregister_sysctl_table(ocfs2_table_header
);
947 /* XXX sync with hb callbacks and shut down hb? */
948 o2net_unregister_hb_callbacks();
949 configfs_unregister_subsystem(&o2nm_cluster_group
.cs_subsys
);
955 static int __init
init_o2nm(void)
959 cluster_print_version();
964 ocfs2_table_header
= register_sysctl_table(ocfs2_root_table
);
965 if (!ocfs2_table_header
) {
966 printk(KERN_ERR
"nodemanager: unable to register sysctl\n");
967 ret
= -ENOMEM
; /* or something. */
971 ret
= o2net_register_hb_callbacks();
975 config_group_init(&o2nm_cluster_group
.cs_subsys
.su_group
);
976 mutex_init(&o2nm_cluster_group
.cs_subsys
.su_mutex
);
977 ret
= configfs_register_subsystem(&o2nm_cluster_group
.cs_subsys
);
979 printk(KERN_ERR
"nodemanager: Registration returned %d\n", ret
);
983 ret
= o2cb_sys_init();
987 configfs_unregister_subsystem(&o2nm_cluster_group
.cs_subsys
);
989 o2net_unregister_hb_callbacks();
991 unregister_sysctl_table(ocfs2_table_header
);
998 MODULE_AUTHOR("Oracle");
999 MODULE_LICENSE("GPL");
1001 module_init(init_o2nm
)
1002 module_exit(exit_o2nm
)