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"
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 char *o2nm_fence_method_desc
[O2NM_FENCE_METHODS
] = {
40 "reset", /* O2NM_FENCE_RESET */
41 "panic", /* O2NM_FENCE_PANIC */
44 struct o2nm_node
*o2nm_get_node_by_num(u8 node_num
)
46 struct o2nm_node
*node
= NULL
;
48 if (node_num
>= O2NM_MAX_NODES
|| o2nm_single_cluster
== NULL
)
51 read_lock(&o2nm_single_cluster
->cl_nodes_lock
);
52 node
= o2nm_single_cluster
->cl_nodes
[node_num
];
54 config_item_get(&node
->nd_item
);
55 read_unlock(&o2nm_single_cluster
->cl_nodes_lock
);
59 EXPORT_SYMBOL_GPL(o2nm_get_node_by_num
);
61 int o2nm_configured_node_map(unsigned long *map
, unsigned bytes
)
63 struct o2nm_cluster
*cluster
= o2nm_single_cluster
;
65 BUG_ON(bytes
< (sizeof(cluster
->cl_nodes_bitmap
)));
70 read_lock(&cluster
->cl_nodes_lock
);
71 memcpy(map
, cluster
->cl_nodes_bitmap
, sizeof(cluster
->cl_nodes_bitmap
));
72 read_unlock(&cluster
->cl_nodes_lock
);
76 EXPORT_SYMBOL_GPL(o2nm_configured_node_map
);
78 static struct o2nm_node
*o2nm_node_ip_tree_lookup(struct o2nm_cluster
*cluster
,
80 struct rb_node
***ret_p
,
81 struct rb_node
**ret_parent
)
83 struct rb_node
**p
= &cluster
->cl_node_ip_tree
.rb_node
;
84 struct rb_node
*parent
= NULL
;
85 struct o2nm_node
*node
, *ret
= NULL
;
91 node
= rb_entry(parent
, struct o2nm_node
, nd_ip_node
);
93 cmp
= memcmp(&ip_needle
, &node
->nd_ipv4_address
,
107 if (ret_parent
!= NULL
)
108 *ret_parent
= parent
;
113 struct o2nm_node
*o2nm_get_node_by_ip(__be32 addr
)
115 struct o2nm_node
*node
= NULL
;
116 struct o2nm_cluster
*cluster
= o2nm_single_cluster
;
121 read_lock(&cluster
->cl_nodes_lock
);
122 node
= o2nm_node_ip_tree_lookup(cluster
, addr
, NULL
, NULL
);
124 config_item_get(&node
->nd_item
);
125 read_unlock(&cluster
->cl_nodes_lock
);
130 EXPORT_SYMBOL_GPL(o2nm_get_node_by_ip
);
132 void o2nm_node_put(struct o2nm_node
*node
)
134 config_item_put(&node
->nd_item
);
136 EXPORT_SYMBOL_GPL(o2nm_node_put
);
138 void o2nm_node_get(struct o2nm_node
*node
)
140 config_item_get(&node
->nd_item
);
142 EXPORT_SYMBOL_GPL(o2nm_node_get
);
144 u8
o2nm_this_node(void)
146 u8 node_num
= O2NM_MAX_NODES
;
148 if (o2nm_single_cluster
&& o2nm_single_cluster
->cl_has_local
)
149 node_num
= o2nm_single_cluster
->cl_local_node
;
153 EXPORT_SYMBOL_GPL(o2nm_this_node
);
155 /* node configfs bits */
157 static struct o2nm_cluster
*to_o2nm_cluster(struct config_item
*item
)
160 container_of(to_config_group(item
), struct o2nm_cluster
,
165 static struct o2nm_node
*to_o2nm_node(struct config_item
*item
)
167 return item
? container_of(item
, struct o2nm_node
, nd_item
) : NULL
;
170 static void o2nm_node_release(struct config_item
*item
)
172 struct o2nm_node
*node
= to_o2nm_node(item
);
176 static ssize_t
o2nm_node_num_read(struct o2nm_node
*node
, char *page
)
178 return sprintf(page
, "%d\n", node
->nd_num
);
181 static struct o2nm_cluster
*to_o2nm_cluster_from_node(struct o2nm_node
*node
)
183 /* through the first node_set .parent
184 * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
185 return to_o2nm_cluster(node
->nd_item
.ci_parent
->ci_parent
);
189 O2NM_NODE_ATTR_NUM
= 0,
191 O2NM_NODE_ATTR_ADDRESS
,
192 O2NM_NODE_ATTR_LOCAL
,
195 static ssize_t
o2nm_node_num_write(struct o2nm_node
*node
, const char *page
,
198 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
200 char *p
= (char *)page
;
202 tmp
= simple_strtoul(p
, &p
, 0);
203 if (!p
|| (*p
&& (*p
!= '\n')))
206 if (tmp
>= O2NM_MAX_NODES
)
209 /* once we're in the cl_nodes tree networking can look us up by
210 * node number and try to use our address and port attributes
211 * to connect to this node.. make sure that they've been set
212 * before writing the node attribute? */
213 if (!test_bit(O2NM_NODE_ATTR_ADDRESS
, &node
->nd_set_attributes
) ||
214 !test_bit(O2NM_NODE_ATTR_PORT
, &node
->nd_set_attributes
))
215 return -EINVAL
; /* XXX */
217 write_lock(&cluster
->cl_nodes_lock
);
218 if (cluster
->cl_nodes
[tmp
])
221 cluster
->cl_nodes
[tmp
] = node
;
223 set_bit(tmp
, cluster
->cl_nodes_bitmap
);
225 write_unlock(&cluster
->cl_nodes_lock
);
231 static ssize_t
o2nm_node_ipv4_port_read(struct o2nm_node
*node
, char *page
)
233 return sprintf(page
, "%u\n", ntohs(node
->nd_ipv4_port
));
236 static ssize_t
o2nm_node_ipv4_port_write(struct o2nm_node
*node
,
237 const char *page
, size_t count
)
240 char *p
= (char *)page
;
242 tmp
= simple_strtoul(p
, &p
, 0);
243 if (!p
|| (*p
&& (*p
!= '\n')))
251 node
->nd_ipv4_port
= htons(tmp
);
256 static ssize_t
o2nm_node_ipv4_address_read(struct o2nm_node
*node
, char *page
)
258 return sprintf(page
, "%pI4\n", &node
->nd_ipv4_address
);
261 static ssize_t
o2nm_node_ipv4_address_write(struct o2nm_node
*node
,
265 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
267 struct rb_node
**p
, *parent
;
268 unsigned int octets
[4];
269 __be32 ipv4_addr
= 0;
271 ret
= sscanf(page
, "%3u.%3u.%3u.%3u", &octets
[3], &octets
[2],
272 &octets
[1], &octets
[0]);
276 for (i
= 0; i
< ARRAY_SIZE(octets
); i
++) {
279 be32_add_cpu(&ipv4_addr
, octets
[i
] << (i
* 8));
283 write_lock(&cluster
->cl_nodes_lock
);
284 if (o2nm_node_ip_tree_lookup(cluster
, ipv4_addr
, &p
, &parent
))
287 rb_link_node(&node
->nd_ip_node
, parent
, p
);
288 rb_insert_color(&node
->nd_ip_node
, &cluster
->cl_node_ip_tree
);
290 write_unlock(&cluster
->cl_nodes_lock
);
294 memcpy(&node
->nd_ipv4_address
, &ipv4_addr
, sizeof(ipv4_addr
));
299 static ssize_t
o2nm_node_local_read(struct o2nm_node
*node
, char *page
)
301 return sprintf(page
, "%d\n", node
->nd_local
);
304 static ssize_t
o2nm_node_local_write(struct o2nm_node
*node
, const char *page
,
307 struct o2nm_cluster
*cluster
= to_o2nm_cluster_from_node(node
);
309 char *p
= (char *)page
;
312 tmp
= simple_strtoul(p
, &p
, 0);
313 if (!p
|| (*p
&& (*p
!= '\n')))
316 tmp
= !!tmp
; /* boolean of whether this node wants to be local */
318 /* setting local turns on networking rx for now so we require having
319 * set everything else first */
320 if (!test_bit(O2NM_NODE_ATTR_ADDRESS
, &node
->nd_set_attributes
) ||
321 !test_bit(O2NM_NODE_ATTR_NUM
, &node
->nd_set_attributes
) ||
322 !test_bit(O2NM_NODE_ATTR_PORT
, &node
->nd_set_attributes
))
323 return -EINVAL
; /* XXX */
325 /* the only failure case is trying to set a new local node
326 * when a different one is already set */
327 if (tmp
&& tmp
== cluster
->cl_has_local
&&
328 cluster
->cl_local_node
!= node
->nd_num
)
331 /* bring up the rx thread if we're setting the new local node. */
332 if (tmp
&& !cluster
->cl_has_local
) {
333 ret
= o2net_start_listening(node
);
338 if (!tmp
&& cluster
->cl_has_local
&&
339 cluster
->cl_local_node
== node
->nd_num
) {
340 o2net_stop_listening(node
);
341 cluster
->cl_local_node
= O2NM_INVALID_NODE_NUM
;
344 node
->nd_local
= tmp
;
345 if (node
->nd_local
) {
346 cluster
->cl_has_local
= tmp
;
347 cluster
->cl_local_node
= node
->nd_num
;
353 struct o2nm_node_attribute
{
354 struct configfs_attribute attr
;
355 ssize_t (*show
)(struct o2nm_node
*, char *);
356 ssize_t (*store
)(struct o2nm_node
*, const char *, size_t);
359 static struct o2nm_node_attribute o2nm_node_attr_num
= {
360 .attr
= { .ca_owner
= THIS_MODULE
,
362 .ca_mode
= S_IRUGO
| S_IWUSR
},
363 .show
= o2nm_node_num_read
,
364 .store
= o2nm_node_num_write
,
367 static struct o2nm_node_attribute o2nm_node_attr_ipv4_port
= {
368 .attr
= { .ca_owner
= THIS_MODULE
,
369 .ca_name
= "ipv4_port",
370 .ca_mode
= S_IRUGO
| S_IWUSR
},
371 .show
= o2nm_node_ipv4_port_read
,
372 .store
= o2nm_node_ipv4_port_write
,
375 static struct o2nm_node_attribute o2nm_node_attr_ipv4_address
= {
376 .attr
= { .ca_owner
= THIS_MODULE
,
377 .ca_name
= "ipv4_address",
378 .ca_mode
= S_IRUGO
| S_IWUSR
},
379 .show
= o2nm_node_ipv4_address_read
,
380 .store
= o2nm_node_ipv4_address_write
,
383 static struct o2nm_node_attribute o2nm_node_attr_local
= {
384 .attr
= { .ca_owner
= THIS_MODULE
,
386 .ca_mode
= S_IRUGO
| S_IWUSR
},
387 .show
= o2nm_node_local_read
,
388 .store
= o2nm_node_local_write
,
391 static struct configfs_attribute
*o2nm_node_attrs
[] = {
392 [O2NM_NODE_ATTR_NUM
] = &o2nm_node_attr_num
.attr
,
393 [O2NM_NODE_ATTR_PORT
] = &o2nm_node_attr_ipv4_port
.attr
,
394 [O2NM_NODE_ATTR_ADDRESS
] = &o2nm_node_attr_ipv4_address
.attr
,
395 [O2NM_NODE_ATTR_LOCAL
] = &o2nm_node_attr_local
.attr
,
399 static int o2nm_attr_index(struct configfs_attribute
*attr
)
402 for (i
= 0; i
< ARRAY_SIZE(o2nm_node_attrs
); i
++) {
403 if (attr
== o2nm_node_attrs
[i
])
410 static ssize_t
o2nm_node_show(struct config_item
*item
,
411 struct configfs_attribute
*attr
,
414 struct o2nm_node
*node
= to_o2nm_node(item
);
415 struct o2nm_node_attribute
*o2nm_node_attr
=
416 container_of(attr
, struct o2nm_node_attribute
, attr
);
419 if (o2nm_node_attr
->show
)
420 ret
= o2nm_node_attr
->show(node
, page
);
424 static ssize_t
o2nm_node_store(struct config_item
*item
,
425 struct configfs_attribute
*attr
,
426 const char *page
, size_t count
)
428 struct o2nm_node
*node
= to_o2nm_node(item
);
429 struct o2nm_node_attribute
*o2nm_node_attr
=
430 container_of(attr
, struct o2nm_node_attribute
, attr
);
432 int attr_index
= o2nm_attr_index(attr
);
434 if (o2nm_node_attr
->store
== NULL
) {
439 if (test_bit(attr_index
, &node
->nd_set_attributes
))
442 ret
= o2nm_node_attr
->store(node
, page
, count
);
446 set_bit(attr_index
, &node
->nd_set_attributes
);
451 static struct configfs_item_operations o2nm_node_item_ops
= {
452 .release
= o2nm_node_release
,
453 .show_attribute
= o2nm_node_show
,
454 .store_attribute
= o2nm_node_store
,
457 static struct config_item_type o2nm_node_type
= {
458 .ct_item_ops
= &o2nm_node_item_ops
,
459 .ct_attrs
= o2nm_node_attrs
,
460 .ct_owner
= THIS_MODULE
,
465 struct o2nm_node_group
{
466 struct config_group ns_group
;
471 static struct o2nm_node_group
*to_o2nm_node_group(struct config_group
*group
)
474 container_of(group
, struct o2nm_node_group
, ns_group
)
479 struct o2nm_cluster_attribute
{
480 struct configfs_attribute attr
;
481 ssize_t (*show
)(struct o2nm_cluster
*, char *);
482 ssize_t (*store
)(struct o2nm_cluster
*, const char *, size_t);
485 static ssize_t
o2nm_cluster_attr_write(const char *page
, ssize_t count
,
489 char *p
= (char *)page
;
491 tmp
= simple_strtoul(p
, &p
, 0);
492 if (!p
|| (*p
&& (*p
!= '\n')))
505 static ssize_t
o2nm_cluster_attr_idle_timeout_ms_read(
506 struct o2nm_cluster
*cluster
, char *page
)
508 return sprintf(page
, "%u\n", cluster
->cl_idle_timeout_ms
);
511 static ssize_t
o2nm_cluster_attr_idle_timeout_ms_write(
512 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
517 ret
= o2nm_cluster_attr_write(page
, count
, &val
);
520 if (cluster
->cl_idle_timeout_ms
!= val
521 && o2net_num_connected_peers()) {
523 "o2net: cannot change idle timeout after "
524 "the first peer has agreed to it."
525 " %d connected peers\n",
526 o2net_num_connected_peers());
528 } else if (val
<= cluster
->cl_keepalive_delay_ms
) {
529 mlog(ML_NOTICE
, "o2net: idle timeout must be larger "
530 "than keepalive delay\n");
533 cluster
->cl_idle_timeout_ms
= val
;
540 static ssize_t
o2nm_cluster_attr_keepalive_delay_ms_read(
541 struct o2nm_cluster
*cluster
, char *page
)
543 return sprintf(page
, "%u\n", cluster
->cl_keepalive_delay_ms
);
546 static ssize_t
o2nm_cluster_attr_keepalive_delay_ms_write(
547 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
552 ret
= o2nm_cluster_attr_write(page
, count
, &val
);
555 if (cluster
->cl_keepalive_delay_ms
!= val
556 && o2net_num_connected_peers()) {
558 "o2net: cannot change keepalive delay after"
559 " the first peer has agreed to it."
560 " %d connected peers\n",
561 o2net_num_connected_peers());
563 } else if (val
>= cluster
->cl_idle_timeout_ms
) {
564 mlog(ML_NOTICE
, "o2net: keepalive delay must be "
565 "smaller than idle timeout\n");
568 cluster
->cl_keepalive_delay_ms
= val
;
575 static ssize_t
o2nm_cluster_attr_reconnect_delay_ms_read(
576 struct o2nm_cluster
*cluster
, char *page
)
578 return sprintf(page
, "%u\n", cluster
->cl_reconnect_delay_ms
);
581 static ssize_t
o2nm_cluster_attr_reconnect_delay_ms_write(
582 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
584 return o2nm_cluster_attr_write(page
, count
,
585 &cluster
->cl_reconnect_delay_ms
);
588 static ssize_t
o2nm_cluster_attr_fence_method_read(
589 struct o2nm_cluster
*cluster
, char *page
)
594 ret
= sprintf(page
, "%s\n",
595 o2nm_fence_method_desc
[cluster
->cl_fence_method
]);
599 static ssize_t
o2nm_cluster_attr_fence_method_write(
600 struct o2nm_cluster
*cluster
, const char *page
, size_t count
)
604 if (page
[count
- 1] != '\n')
607 for (i
= 0; i
< O2NM_FENCE_METHODS
; ++i
) {
608 if (count
!= strlen(o2nm_fence_method_desc
[i
]) + 1)
610 if (strncasecmp(page
, o2nm_fence_method_desc
[i
], count
- 1))
612 if (cluster
->cl_fence_method
!= i
) {
613 printk(KERN_INFO
"ocfs2: Changing fence method to %s\n",
614 o2nm_fence_method_desc
[i
]);
615 cluster
->cl_fence_method
= i
;
624 static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms
= {
625 .attr
= { .ca_owner
= THIS_MODULE
,
626 .ca_name
= "idle_timeout_ms",
627 .ca_mode
= S_IRUGO
| S_IWUSR
},
628 .show
= o2nm_cluster_attr_idle_timeout_ms_read
,
629 .store
= o2nm_cluster_attr_idle_timeout_ms_write
,
632 static struct o2nm_cluster_attribute o2nm_cluster_attr_keepalive_delay_ms
= {
633 .attr
= { .ca_owner
= THIS_MODULE
,
634 .ca_name
= "keepalive_delay_ms",
635 .ca_mode
= S_IRUGO
| S_IWUSR
},
636 .show
= o2nm_cluster_attr_keepalive_delay_ms_read
,
637 .store
= o2nm_cluster_attr_keepalive_delay_ms_write
,
640 static struct o2nm_cluster_attribute o2nm_cluster_attr_reconnect_delay_ms
= {
641 .attr
= { .ca_owner
= THIS_MODULE
,
642 .ca_name
= "reconnect_delay_ms",
643 .ca_mode
= S_IRUGO
| S_IWUSR
},
644 .show
= o2nm_cluster_attr_reconnect_delay_ms_read
,
645 .store
= o2nm_cluster_attr_reconnect_delay_ms_write
,
648 static struct o2nm_cluster_attribute o2nm_cluster_attr_fence_method
= {
649 .attr
= { .ca_owner
= THIS_MODULE
,
650 .ca_name
= "fence_method",
651 .ca_mode
= S_IRUGO
| S_IWUSR
},
652 .show
= o2nm_cluster_attr_fence_method_read
,
653 .store
= o2nm_cluster_attr_fence_method_write
,
656 static struct configfs_attribute
*o2nm_cluster_attrs
[] = {
657 &o2nm_cluster_attr_idle_timeout_ms
.attr
,
658 &o2nm_cluster_attr_keepalive_delay_ms
.attr
,
659 &o2nm_cluster_attr_reconnect_delay_ms
.attr
,
660 &o2nm_cluster_attr_fence_method
.attr
,
663 static ssize_t
o2nm_cluster_show(struct config_item
*item
,
664 struct configfs_attribute
*attr
,
667 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
668 struct o2nm_cluster_attribute
*o2nm_cluster_attr
=
669 container_of(attr
, struct o2nm_cluster_attribute
, attr
);
672 if (o2nm_cluster_attr
->show
)
673 ret
= o2nm_cluster_attr
->show(cluster
, page
);
677 static ssize_t
o2nm_cluster_store(struct config_item
*item
,
678 struct configfs_attribute
*attr
,
679 const char *page
, size_t count
)
681 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
682 struct o2nm_cluster_attribute
*o2nm_cluster_attr
=
683 container_of(attr
, struct o2nm_cluster_attribute
, attr
);
686 if (o2nm_cluster_attr
->store
== NULL
) {
691 ret
= o2nm_cluster_attr
->store(cluster
, page
, count
);
698 static struct config_item
*o2nm_node_group_make_item(struct config_group
*group
,
701 struct o2nm_node
*node
= NULL
;
703 if (strlen(name
) > O2NM_MAX_NAME_LEN
)
704 return ERR_PTR(-ENAMETOOLONG
);
706 node
= kzalloc(sizeof(struct o2nm_node
), GFP_KERNEL
);
708 return ERR_PTR(-ENOMEM
);
710 strcpy(node
->nd_name
, name
); /* use item.ci_namebuf instead? */
711 config_item_init_type_name(&node
->nd_item
, name
, &o2nm_node_type
);
712 spin_lock_init(&node
->nd_lock
);
714 mlog(ML_CLUSTER
, "o2nm: Registering node %s\n", name
);
716 return &node
->nd_item
;
719 static void o2nm_node_group_drop_item(struct config_group
*group
,
720 struct config_item
*item
)
722 struct o2nm_node
*node
= to_o2nm_node(item
);
723 struct o2nm_cluster
*cluster
= to_o2nm_cluster(group
->cg_item
.ci_parent
);
725 o2net_disconnect_node(node
);
727 if (cluster
->cl_has_local
&&
728 (cluster
->cl_local_node
== node
->nd_num
)) {
729 cluster
->cl_has_local
= 0;
730 cluster
->cl_local_node
= O2NM_INVALID_NODE_NUM
;
731 o2net_stop_listening(node
);
734 /* XXX call into net to stop this node from trading messages */
736 write_lock(&cluster
->cl_nodes_lock
);
739 if (node
->nd_ipv4_address
)
740 rb_erase(&node
->nd_ip_node
, &cluster
->cl_node_ip_tree
);
742 /* nd_num might be 0 if the node number hasn't been set.. */
743 if (cluster
->cl_nodes
[node
->nd_num
] == node
) {
744 cluster
->cl_nodes
[node
->nd_num
] = NULL
;
745 clear_bit(node
->nd_num
, cluster
->cl_nodes_bitmap
);
747 write_unlock(&cluster
->cl_nodes_lock
);
749 mlog(ML_CLUSTER
, "o2nm: Unregistered node %s\n",
750 config_item_name(&node
->nd_item
));
752 config_item_put(item
);
755 static struct configfs_group_operations o2nm_node_group_group_ops
= {
756 .make_item
= o2nm_node_group_make_item
,
757 .drop_item
= o2nm_node_group_drop_item
,
760 static struct config_item_type o2nm_node_group_type
= {
761 .ct_group_ops
= &o2nm_node_group_group_ops
,
762 .ct_owner
= THIS_MODULE
,
767 static void o2nm_cluster_release(struct config_item
*item
)
769 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
771 kfree(cluster
->cl_group
.default_groups
);
775 static struct configfs_item_operations o2nm_cluster_item_ops
= {
776 .release
= o2nm_cluster_release
,
777 .show_attribute
= o2nm_cluster_show
,
778 .store_attribute
= o2nm_cluster_store
,
781 static struct config_item_type o2nm_cluster_type
= {
782 .ct_item_ops
= &o2nm_cluster_item_ops
,
783 .ct_attrs
= o2nm_cluster_attrs
,
784 .ct_owner
= THIS_MODULE
,
789 struct o2nm_cluster_group
{
790 struct configfs_subsystem cs_subsys
;
795 static struct o2nm_cluster_group
*to_o2nm_cluster_group(struct config_group
*group
)
798 container_of(to_configfs_subsystem(group
), struct o2nm_cluster_group
, cs_subsys
)
803 static struct config_group
*o2nm_cluster_group_make_group(struct config_group
*group
,
806 struct o2nm_cluster
*cluster
= NULL
;
807 struct o2nm_node_group
*ns
= NULL
;
808 struct config_group
*o2hb_group
= NULL
, *ret
= NULL
;
811 /* this runs under the parent dir's i_mutex; there can be only
812 * one caller in here at a time */
813 if (o2nm_single_cluster
)
814 return ERR_PTR(-ENOSPC
);
816 cluster
= kzalloc(sizeof(struct o2nm_cluster
), GFP_KERNEL
);
817 ns
= kzalloc(sizeof(struct o2nm_node_group
), GFP_KERNEL
);
818 defs
= kcalloc(3, sizeof(struct config_group
*), GFP_KERNEL
);
819 o2hb_group
= o2hb_alloc_hb_set();
820 if (cluster
== NULL
|| ns
== NULL
|| o2hb_group
== NULL
|| defs
== NULL
)
823 config_group_init_type_name(&cluster
->cl_group
, name
,
825 config_group_init_type_name(&ns
->ns_group
, "node",
826 &o2nm_node_group_type
);
828 cluster
->cl_group
.default_groups
= defs
;
829 cluster
->cl_group
.default_groups
[0] = &ns
->ns_group
;
830 cluster
->cl_group
.default_groups
[1] = o2hb_group
;
831 cluster
->cl_group
.default_groups
[2] = NULL
;
832 rwlock_init(&cluster
->cl_nodes_lock
);
833 cluster
->cl_node_ip_tree
= RB_ROOT
;
834 cluster
->cl_reconnect_delay_ms
= O2NET_RECONNECT_DELAY_MS_DEFAULT
;
835 cluster
->cl_idle_timeout_ms
= O2NET_IDLE_TIMEOUT_MS_DEFAULT
;
836 cluster
->cl_keepalive_delay_ms
= O2NET_KEEPALIVE_DELAY_MS_DEFAULT
;
837 cluster
->cl_fence_method
= O2NM_FENCE_RESET
;
839 ret
= &cluster
->cl_group
;
840 o2nm_single_cluster
= cluster
;
846 o2hb_free_hb_set(o2hb_group
);
848 ret
= ERR_PTR(-ENOMEM
);
854 static void o2nm_cluster_group_drop_item(struct config_group
*group
, struct config_item
*item
)
856 struct o2nm_cluster
*cluster
= to_o2nm_cluster(item
);
858 struct config_item
*killme
;
860 BUG_ON(o2nm_single_cluster
!= cluster
);
861 o2nm_single_cluster
= NULL
;
863 for (i
= 0; cluster
->cl_group
.default_groups
[i
]; i
++) {
864 killme
= &cluster
->cl_group
.default_groups
[i
]->cg_item
;
865 cluster
->cl_group
.default_groups
[i
] = NULL
;
866 config_item_put(killme
);
869 config_item_put(item
);
872 static struct configfs_group_operations o2nm_cluster_group_group_ops
= {
873 .make_group
= o2nm_cluster_group_make_group
,
874 .drop_item
= o2nm_cluster_group_drop_item
,
877 static struct config_item_type o2nm_cluster_group_type
= {
878 .ct_group_ops
= &o2nm_cluster_group_group_ops
,
879 .ct_owner
= THIS_MODULE
,
882 static struct o2nm_cluster_group o2nm_cluster_group
= {
886 .ci_namebuf
= "cluster",
887 .ci_type
= &o2nm_cluster_group_type
,
893 int o2nm_depend_item(struct config_item
*item
)
895 return configfs_depend_item(&o2nm_cluster_group
.cs_subsys
, item
);
898 void o2nm_undepend_item(struct config_item
*item
)
900 configfs_undepend_item(&o2nm_cluster_group
.cs_subsys
, item
);
903 int o2nm_depend_this_node(void)
906 struct o2nm_node
*local_node
;
908 local_node
= o2nm_get_node_by_num(o2nm_this_node());
914 ret
= o2nm_depend_item(&local_node
->nd_item
);
915 o2nm_node_put(local_node
);
921 void o2nm_undepend_this_node(void)
923 struct o2nm_node
*local_node
;
925 local_node
= o2nm_get_node_by_num(o2nm_this_node());
928 o2nm_undepend_item(&local_node
->nd_item
);
929 o2nm_node_put(local_node
);
933 static void __exit
exit_o2nm(void)
935 /* XXX sync with hb callbacks and shut down hb? */
936 o2net_unregister_hb_callbacks();
937 configfs_unregister_subsystem(&o2nm_cluster_group
.cs_subsys
);
944 static int __init
init_o2nm(void)
948 cluster_print_version();
958 ret
= o2net_register_hb_callbacks();
962 config_group_init(&o2nm_cluster_group
.cs_subsys
.su_group
);
963 mutex_init(&o2nm_cluster_group
.cs_subsys
.su_mutex
);
964 ret
= configfs_register_subsystem(&o2nm_cluster_group
.cs_subsys
);
966 printk(KERN_ERR
"nodemanager: Registration returned %d\n", ret
);
970 ret
= o2cb_sys_init();
974 configfs_unregister_subsystem(&o2nm_cluster_group
.cs_subsys
);
976 o2net_unregister_hb_callbacks();
985 MODULE_AUTHOR("Oracle");
986 MODULE_LICENSE("GPL");
988 module_init(init_o2nm
)
989 module_exit(exit_o2nm
)