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>
28 #include "nodemanager.h"
29 #include "heartbeat.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
)
50 read_lock(&o2nm_single_cluster
->cl_nodes_lock
);
51 node
= o2nm_single_cluster
->cl_nodes
[node_num
];
53 config_item_get(&node
->nd_item
);
54 read_unlock(&o2nm_single_cluster
->cl_nodes_lock
);
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
)));
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
);
75 EXPORT_SYMBOL_GPL(o2nm_configured_node_map
);
77 static struct o2nm_node
*o2nm_node_ip_tree_lookup(struct o2nm_cluster
*cluster
,
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
;
90 node
= rb_entry(parent
, struct o2nm_node
, nd_ip_node
);
92 cmp
= memcmp(&ip_needle
, &node
->nd_ipv4_address
,
106 if (ret_parent
!= NULL
)
107 *ret_parent
= parent
;
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
;
120 read_lock(&cluster
->cl_nodes_lock
);
121 node
= o2nm_node_ip_tree_lookup(cluster
, addr
, NULL
, NULL
);
123 config_item_get(&node
->nd_item
);
124 read_unlock(&cluster
->cl_nodes_lock
);
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
;
152 EXPORT_SYMBOL_GPL(o2nm_this_node
);
154 /* node configfs bits */
156 static struct o2nm_cluster
*to_o2nm_cluster(struct config_item
*item
)
159 container_of(to_config_group(item
), struct o2nm_cluster
,
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
);
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
);
188 O2NM_NODE_ATTR_NUM
= 0,
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
,
197 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
199 char *p
= (char *)page
;
201 tmp
= simple_strtoul(p
, &p
, 0);
202 if (!p
|| (*p
&& (*p
!= '\n')))
205 if (tmp
>= O2NM_MAX_NODES
)
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
])
220 cluster
->cl_nodes
[tmp
] = node
;
222 set_bit(tmp
, cluster
->cl_nodes_bitmap
);
224 write_unlock(&cluster
->cl_nodes_lock
);
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
)
239 char *p
= (char *)page
;
241 tmp
= simple_strtoul(p
, &p
, 0);
242 if (!p
|| (*p
&& (*p
!= '\n')))
250 node
->nd_ipv4_port
= htons(tmp
);
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
,
264 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
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]);
275 for (i
= 0; i
< ARRAY_SIZE(octets
); i
++) {
278 be32_add_cpu(&ipv4_addr
, octets
[i
] << (i
* 8));
282 write_lock(&cluster
->cl_nodes_lock
);
283 if (o2nm_node_ip_tree_lookup(cluster
, ipv4_addr
, &p
, &parent
))
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
);
293 memcpy(&node
->nd_ipv4_address
, &ipv4_addr
, sizeof(ipv4_addr
));
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
,
306 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
308 char *p
= (char *)page
;
311 tmp
= simple_strtoul(p
, &p
, 0);
312 if (!p
|| (*p
&& (*p
!= '\n')))
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
)
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
);
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
;
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
,
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
,
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
,
398 static int o2nm_attr_index(struct configfs_attribute
*attr
)
401 for (i
= 0; i
< ARRAY_SIZE(o2nm_node_attrs
); i
++) {
402 if (attr
== o2nm_node_attrs
[i
])
409 static ssize_t
o2nm_node_show(struct config_item
*item
,
410 struct configfs_attribute
*attr
,
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
);
418 if (o2nm_node_attr
->show
)
419 ret
= o2nm_node_attr
->show(node
, page
);
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
);
431 int attr_index
= o2nm_attr_index(attr
);
433 if (o2nm_node_attr
->store
== NULL
) {
438 if (test_bit(attr_index
, &node
->nd_set_attributes
))
441 ret
= o2nm_node_attr
->store(node
, page
, count
);
445 set_bit(attr_index
, &node
->nd_set_attributes
);
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
,
464 struct o2nm_node_group
{
465 struct config_group ns_group
;
470 static struct o2nm_node_group
*to_o2nm_node_group(struct config_group
*group
)
473 container_of(group
, struct o2nm_node_group
, ns_group
)
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
,
488 char *p
= (char *)page
;
490 tmp
= simple_strtoul(p
, &p
, 0);
491 if (!p
|| (*p
&& (*p
!= '\n')))
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
)
516 ret
= o2nm_cluster_attr_write(page
, count
, &val
);
519 if (cluster
->cl_idle_timeout_ms
!= val
520 && o2net_num_connected_peers()) {
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());
527 } else if (val
<= cluster
->cl_keepalive_delay_ms
) {
528 mlog(ML_NOTICE
, "o2net: idle timeout must be larger "
529 "than keepalive delay\n");
532 cluster
->cl_idle_timeout_ms
= val
;
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
)
551 ret
= o2nm_cluster_attr_write(page
, count
, &val
);
554 if (cluster
->cl_keepalive_delay_ms
!= val
555 && o2net_num_connected_peers()) {
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());
562 } else if (val
>= cluster
->cl_idle_timeout_ms
) {
563 mlog(ML_NOTICE
, "o2net: keepalive delay must be "
564 "smaller than idle timeout\n");
567 cluster
->cl_keepalive_delay_ms
= val
;
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
)
593 ret
= sprintf(page
, "%s\n",
594 o2nm_fence_method_desc
[cluster
->cl_fence_method
]);
598 static ssize_t
o2nm_cluster_attr_fence_method_write(
599 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
603 if (page
[count
- 1] != '\n')
606 for (i
= 0; i
< O2NM_FENCE_METHODS
; ++i
) {
607 if (count
!= strlen(o2nm_fence_method_desc
[i
]) + 1)
609 if (strncasecmp(page
, o2nm_fence_method_desc
[i
], count
- 1))
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
;
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
,
662 static ssize_t
o2nm_cluster_show(struct config_item
*item
,
663 struct configfs_attribute
*attr
,
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
);
671 if (o2nm_cluster_attr
->show
)
672 ret
= o2nm_cluster_attr
->show(cluster
, page
);
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
);
685 if (o2nm_cluster_attr
->store
== NULL
) {
690 ret
= o2nm_cluster_attr
->store(cluster
, page
, count
);
697 static struct config_item
*o2nm_node_group_make_item(struct config_group
*group
,
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
);
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
);
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
,
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
);
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
,
788 struct o2nm_cluster_group
{
789 struct configfs_subsystem cs_subsys
;
794 static struct o2nm_cluster_group
*to_o2nm_cluster_group(struct config_group
*group
)
797 container_of(to_configfs_subsystem(group
), struct o2nm_cluster_group
, cs_subsys
)
802 static struct config_group
*o2nm_cluster_group_make_group(struct config_group
*group
,
805 struct o2nm_cluster
*cluster
= NULL
;
806 struct o2nm_node_group
*ns
= NULL
;
807 struct config_group
*o2hb_group
= NULL
, *ret
= 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
)
822 config_group_init_type_name(&cluster
->cl_group
, name
,
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
;
845 o2hb_free_hb_set(o2hb_group
);
847 ret
= ERR_PTR(-ENOMEM
);
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
);
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
= {
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)
905 struct o2nm_node
*local_node
;
907 local_node
= o2nm_get_node_by_num(o2nm_this_node());
913 ret
= o2nm_depend_item(&local_node
->nd_item
);
914 o2nm_node_put(local_node
);
920 void o2nm_undepend_this_node(void)
922 struct o2nm_node
*local_node
;
924 local_node
= o2nm_get_node_by_num(o2nm_this_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
);
943 static int __init
init_o2nm(void)
955 ret
= o2net_register_hb_callbacks();
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
);
963 printk(KERN_ERR
"nodemanager: Registration returned %d\n", ret
);
967 ret
= o2cb_sys_init();
971 configfs_unregister_subsystem(&o2nm_cluster_group
.cs_subsys
);
973 o2net_unregister_hb_callbacks();
982 MODULE_AUTHOR("Oracle");
983 MODULE_LICENSE("GPL");
984 MODULE_DESCRIPTION("OCFS2 cluster management");
986 module_init(init_o2nm
)
987 module_exit(exit_o2nm
)