ext4: Optimize ext4 DIO overwrites
[linux/fpc-iii.git] / fs / ocfs2 / cluster / nodemanager.c
blob7a7640c59f3ca3c31cbc782d80e1db2097202053
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* -*- mode: c; c-basic-offset: 8; -*-
3 * vim: noexpandtab sw=8 ts=8 sts=0:
5 * Copyright (C) 2004, 2005 Oracle. All rights reserved.
6 */
8 #include <linux/slab.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/configfs.h>
13 #include "tcp.h"
14 #include "nodemanager.h"
15 #include "heartbeat.h"
16 #include "masklog.h"
17 #include "sys.h"
19 /* for now we operate under the assertion that there can be only one
20 * cluster active at a time. Changing this will require trickling
21 * cluster references throughout where nodes are looked up */
22 struct o2nm_cluster *o2nm_single_cluster = NULL;
24 static const char *o2nm_fence_method_desc[O2NM_FENCE_METHODS] = {
25 "reset", /* O2NM_FENCE_RESET */
26 "panic", /* O2NM_FENCE_PANIC */
29 static inline void o2nm_lock_subsystem(void);
30 static inline void o2nm_unlock_subsystem(void);
32 struct o2nm_node *o2nm_get_node_by_num(u8 node_num)
34 struct o2nm_node *node = NULL;
36 if (node_num >= O2NM_MAX_NODES || o2nm_single_cluster == NULL)
37 goto out;
39 read_lock(&o2nm_single_cluster->cl_nodes_lock);
40 node = o2nm_single_cluster->cl_nodes[node_num];
41 if (node)
42 config_item_get(&node->nd_item);
43 read_unlock(&o2nm_single_cluster->cl_nodes_lock);
44 out:
45 return node;
47 EXPORT_SYMBOL_GPL(o2nm_get_node_by_num);
49 int o2nm_configured_node_map(unsigned long *map, unsigned bytes)
51 struct o2nm_cluster *cluster = o2nm_single_cluster;
53 BUG_ON(bytes < (sizeof(cluster->cl_nodes_bitmap)));
55 if (cluster == NULL)
56 return -EINVAL;
58 read_lock(&cluster->cl_nodes_lock);
59 memcpy(map, cluster->cl_nodes_bitmap, sizeof(cluster->cl_nodes_bitmap));
60 read_unlock(&cluster->cl_nodes_lock);
62 return 0;
64 EXPORT_SYMBOL_GPL(o2nm_configured_node_map);
66 static struct o2nm_node *o2nm_node_ip_tree_lookup(struct o2nm_cluster *cluster,
67 __be32 ip_needle,
68 struct rb_node ***ret_p,
69 struct rb_node **ret_parent)
71 struct rb_node **p = &cluster->cl_node_ip_tree.rb_node;
72 struct rb_node *parent = NULL;
73 struct o2nm_node *node, *ret = NULL;
75 while (*p) {
76 int cmp;
78 parent = *p;
79 node = rb_entry(parent, struct o2nm_node, nd_ip_node);
81 cmp = memcmp(&ip_needle, &node->nd_ipv4_address,
82 sizeof(ip_needle));
83 if (cmp < 0)
84 p = &(*p)->rb_left;
85 else if (cmp > 0)
86 p = &(*p)->rb_right;
87 else {
88 ret = node;
89 break;
93 if (ret_p != NULL)
94 *ret_p = p;
95 if (ret_parent != NULL)
96 *ret_parent = parent;
98 return ret;
101 struct o2nm_node *o2nm_get_node_by_ip(__be32 addr)
103 struct o2nm_node *node = NULL;
104 struct o2nm_cluster *cluster = o2nm_single_cluster;
106 if (cluster == NULL)
107 goto out;
109 read_lock(&cluster->cl_nodes_lock);
110 node = o2nm_node_ip_tree_lookup(cluster, addr, NULL, NULL);
111 if (node)
112 config_item_get(&node->nd_item);
113 read_unlock(&cluster->cl_nodes_lock);
115 out:
116 return node;
118 EXPORT_SYMBOL_GPL(o2nm_get_node_by_ip);
120 void o2nm_node_put(struct o2nm_node *node)
122 config_item_put(&node->nd_item);
124 EXPORT_SYMBOL_GPL(o2nm_node_put);
126 void o2nm_node_get(struct o2nm_node *node)
128 config_item_get(&node->nd_item);
130 EXPORT_SYMBOL_GPL(o2nm_node_get);
132 u8 o2nm_this_node(void)
134 u8 node_num = O2NM_MAX_NODES;
136 if (o2nm_single_cluster && o2nm_single_cluster->cl_has_local)
137 node_num = o2nm_single_cluster->cl_local_node;
139 return node_num;
141 EXPORT_SYMBOL_GPL(o2nm_this_node);
143 /* node configfs bits */
145 static struct o2nm_cluster *to_o2nm_cluster(struct config_item *item)
147 return item ?
148 container_of(to_config_group(item), struct o2nm_cluster,
149 cl_group)
150 : NULL;
153 static struct o2nm_node *to_o2nm_node(struct config_item *item)
155 return item ? container_of(item, struct o2nm_node, nd_item) : NULL;
158 static void o2nm_node_release(struct config_item *item)
160 struct o2nm_node *node = to_o2nm_node(item);
161 kfree(node);
164 static ssize_t o2nm_node_num_show(struct config_item *item, char *page)
166 return sprintf(page, "%d\n", to_o2nm_node(item)->nd_num);
169 static struct o2nm_cluster *to_o2nm_cluster_from_node(struct o2nm_node *node)
171 /* through the first node_set .parent
172 * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
173 if (node->nd_item.ci_parent)
174 return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
175 else
176 return NULL;
179 enum {
180 O2NM_NODE_ATTR_NUM = 0,
181 O2NM_NODE_ATTR_PORT,
182 O2NM_NODE_ATTR_ADDRESS,
185 static ssize_t o2nm_node_num_store(struct config_item *item, const char *page,
186 size_t count)
188 struct o2nm_node *node = to_o2nm_node(item);
189 struct o2nm_cluster *cluster;
190 unsigned long tmp;
191 char *p = (char *)page;
192 int ret = 0;
194 tmp = simple_strtoul(p, &p, 0);
195 if (!p || (*p && (*p != '\n')))
196 return -EINVAL;
198 if (tmp >= O2NM_MAX_NODES)
199 return -ERANGE;
201 /* once we're in the cl_nodes tree networking can look us up by
202 * node number and try to use our address and port attributes
203 * to connect to this node.. make sure that they've been set
204 * before writing the node attribute? */
205 if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
206 !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
207 return -EINVAL; /* XXX */
209 o2nm_lock_subsystem();
210 cluster = to_o2nm_cluster_from_node(node);
211 if (!cluster) {
212 o2nm_unlock_subsystem();
213 return -EINVAL;
216 write_lock(&cluster->cl_nodes_lock);
217 if (cluster->cl_nodes[tmp])
218 ret = -EEXIST;
219 else if (test_and_set_bit(O2NM_NODE_ATTR_NUM,
220 &node->nd_set_attributes))
221 ret = -EBUSY;
222 else {
223 cluster->cl_nodes[tmp] = node;
224 node->nd_num = tmp;
225 set_bit(tmp, cluster->cl_nodes_bitmap);
227 write_unlock(&cluster->cl_nodes_lock);
228 o2nm_unlock_subsystem();
230 if (ret)
231 return ret;
233 return count;
235 static ssize_t o2nm_node_ipv4_port_show(struct config_item *item, char *page)
237 return sprintf(page, "%u\n", ntohs(to_o2nm_node(item)->nd_ipv4_port));
240 static ssize_t o2nm_node_ipv4_port_store(struct config_item *item,
241 const char *page, size_t count)
243 struct o2nm_node *node = to_o2nm_node(item);
244 unsigned long tmp;
245 char *p = (char *)page;
247 tmp = simple_strtoul(p, &p, 0);
248 if (!p || (*p && (*p != '\n')))
249 return -EINVAL;
251 if (tmp == 0)
252 return -EINVAL;
253 if (tmp >= (u16)-1)
254 return -ERANGE;
256 if (test_and_set_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
257 return -EBUSY;
258 node->nd_ipv4_port = htons(tmp);
260 return count;
263 static ssize_t o2nm_node_ipv4_address_show(struct config_item *item, char *page)
265 return sprintf(page, "%pI4\n", &to_o2nm_node(item)->nd_ipv4_address);
268 static ssize_t o2nm_node_ipv4_address_store(struct config_item *item,
269 const char *page,
270 size_t count)
272 struct o2nm_node *node = to_o2nm_node(item);
273 struct o2nm_cluster *cluster;
274 int ret, i;
275 struct rb_node **p, *parent;
276 unsigned int octets[4];
277 __be32 ipv4_addr = 0;
279 ret = sscanf(page, "%3u.%3u.%3u.%3u", &octets[3], &octets[2],
280 &octets[1], &octets[0]);
281 if (ret != 4)
282 return -EINVAL;
284 for (i = 0; i < ARRAY_SIZE(octets); i++) {
285 if (octets[i] > 255)
286 return -ERANGE;
287 be32_add_cpu(&ipv4_addr, octets[i] << (i * 8));
290 o2nm_lock_subsystem();
291 cluster = to_o2nm_cluster_from_node(node);
292 if (!cluster) {
293 o2nm_unlock_subsystem();
294 return -EINVAL;
297 ret = 0;
298 write_lock(&cluster->cl_nodes_lock);
299 if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
300 ret = -EEXIST;
301 else if (test_and_set_bit(O2NM_NODE_ATTR_ADDRESS,
302 &node->nd_set_attributes))
303 ret = -EBUSY;
304 else {
305 rb_link_node(&node->nd_ip_node, parent, p);
306 rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
308 write_unlock(&cluster->cl_nodes_lock);
309 o2nm_unlock_subsystem();
311 if (ret)
312 return ret;
314 memcpy(&node->nd_ipv4_address, &ipv4_addr, sizeof(ipv4_addr));
316 return count;
319 static ssize_t o2nm_node_local_show(struct config_item *item, char *page)
321 return sprintf(page, "%d\n", to_o2nm_node(item)->nd_local);
324 static ssize_t o2nm_node_local_store(struct config_item *item, const char *page,
325 size_t count)
327 struct o2nm_node *node = to_o2nm_node(item);
328 struct o2nm_cluster *cluster;
329 unsigned long tmp;
330 char *p = (char *)page;
331 ssize_t ret;
333 tmp = simple_strtoul(p, &p, 0);
334 if (!p || (*p && (*p != '\n')))
335 return -EINVAL;
337 tmp = !!tmp; /* boolean of whether this node wants to be local */
339 /* setting local turns on networking rx for now so we require having
340 * set everything else first */
341 if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
342 !test_bit(O2NM_NODE_ATTR_NUM, &node->nd_set_attributes) ||
343 !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
344 return -EINVAL; /* XXX */
346 o2nm_lock_subsystem();
347 cluster = to_o2nm_cluster_from_node(node);
348 if (!cluster) {
349 ret = -EINVAL;
350 goto out;
353 /* the only failure case is trying to set a new local node
354 * when a different one is already set */
355 if (tmp && tmp == cluster->cl_has_local &&
356 cluster->cl_local_node != node->nd_num) {
357 ret = -EBUSY;
358 goto out;
361 /* bring up the rx thread if we're setting the new local node. */
362 if (tmp && !cluster->cl_has_local) {
363 ret = o2net_start_listening(node);
364 if (ret)
365 goto out;
368 if (!tmp && cluster->cl_has_local &&
369 cluster->cl_local_node == node->nd_num) {
370 o2net_stop_listening(node);
371 cluster->cl_local_node = O2NM_INVALID_NODE_NUM;
374 node->nd_local = tmp;
375 if (node->nd_local) {
376 cluster->cl_has_local = tmp;
377 cluster->cl_local_node = node->nd_num;
380 ret = count;
382 out:
383 o2nm_unlock_subsystem();
384 return ret;
387 CONFIGFS_ATTR(o2nm_node_, num);
388 CONFIGFS_ATTR(o2nm_node_, ipv4_port);
389 CONFIGFS_ATTR(o2nm_node_, ipv4_address);
390 CONFIGFS_ATTR(o2nm_node_, local);
392 static struct configfs_attribute *o2nm_node_attrs[] = {
393 &o2nm_node_attr_num,
394 &o2nm_node_attr_ipv4_port,
395 &o2nm_node_attr_ipv4_address,
396 &o2nm_node_attr_local,
397 NULL,
400 static struct configfs_item_operations o2nm_node_item_ops = {
401 .release = o2nm_node_release,
404 static const struct config_item_type o2nm_node_type = {
405 .ct_item_ops = &o2nm_node_item_ops,
406 .ct_attrs = o2nm_node_attrs,
407 .ct_owner = THIS_MODULE,
410 /* node set */
412 struct o2nm_node_group {
413 struct config_group ns_group;
414 /* some stuff? */
417 #if 0
418 static struct o2nm_node_group *to_o2nm_node_group(struct config_group *group)
420 return group ?
421 container_of(group, struct o2nm_node_group, ns_group)
422 : NULL;
424 #endif
426 static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count,
427 unsigned int *val)
429 unsigned long tmp;
430 char *p = (char *)page;
432 tmp = simple_strtoul(p, &p, 0);
433 if (!p || (*p && (*p != '\n')))
434 return -EINVAL;
436 if (tmp == 0)
437 return -EINVAL;
438 if (tmp >= (u32)-1)
439 return -ERANGE;
441 *val = tmp;
443 return count;
446 static ssize_t o2nm_cluster_idle_timeout_ms_show(struct config_item *item,
447 char *page)
449 return sprintf(page, "%u\n", to_o2nm_cluster(item)->cl_idle_timeout_ms);
452 static ssize_t o2nm_cluster_idle_timeout_ms_store(struct config_item *item,
453 const char *page, size_t count)
455 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
456 ssize_t ret;
457 unsigned int val;
459 ret = o2nm_cluster_attr_write(page, count, &val);
461 if (ret > 0) {
462 if (cluster->cl_idle_timeout_ms != val
463 && o2net_num_connected_peers()) {
464 mlog(ML_NOTICE,
465 "o2net: cannot change idle timeout after "
466 "the first peer has agreed to it."
467 " %d connected peers\n",
468 o2net_num_connected_peers());
469 ret = -EINVAL;
470 } else if (val <= cluster->cl_keepalive_delay_ms) {
471 mlog(ML_NOTICE, "o2net: idle timeout must be larger "
472 "than keepalive delay\n");
473 ret = -EINVAL;
474 } else {
475 cluster->cl_idle_timeout_ms = val;
479 return ret;
482 static ssize_t o2nm_cluster_keepalive_delay_ms_show(
483 struct config_item *item, char *page)
485 return sprintf(page, "%u\n",
486 to_o2nm_cluster(item)->cl_keepalive_delay_ms);
489 static ssize_t o2nm_cluster_keepalive_delay_ms_store(
490 struct config_item *item, const char *page, size_t count)
492 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
493 ssize_t ret;
494 unsigned int val;
496 ret = o2nm_cluster_attr_write(page, count, &val);
498 if (ret > 0) {
499 if (cluster->cl_keepalive_delay_ms != val
500 && o2net_num_connected_peers()) {
501 mlog(ML_NOTICE,
502 "o2net: cannot change keepalive delay after"
503 " the first peer has agreed to it."
504 " %d connected peers\n",
505 o2net_num_connected_peers());
506 ret = -EINVAL;
507 } else if (val >= cluster->cl_idle_timeout_ms) {
508 mlog(ML_NOTICE, "o2net: keepalive delay must be "
509 "smaller than idle timeout\n");
510 ret = -EINVAL;
511 } else {
512 cluster->cl_keepalive_delay_ms = val;
516 return ret;
519 static ssize_t o2nm_cluster_reconnect_delay_ms_show(
520 struct config_item *item, char *page)
522 return sprintf(page, "%u\n",
523 to_o2nm_cluster(item)->cl_reconnect_delay_ms);
526 static ssize_t o2nm_cluster_reconnect_delay_ms_store(
527 struct config_item *item, const char *page, size_t count)
529 return o2nm_cluster_attr_write(page, count,
530 &to_o2nm_cluster(item)->cl_reconnect_delay_ms);
533 static ssize_t o2nm_cluster_fence_method_show(
534 struct config_item *item, char *page)
536 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
537 ssize_t ret = 0;
539 if (cluster)
540 ret = sprintf(page, "%s\n",
541 o2nm_fence_method_desc[cluster->cl_fence_method]);
542 return ret;
545 static ssize_t o2nm_cluster_fence_method_store(
546 struct config_item *item, const char *page, size_t count)
548 unsigned int i;
550 if (page[count - 1] != '\n')
551 goto bail;
553 for (i = 0; i < O2NM_FENCE_METHODS; ++i) {
554 if (count != strlen(o2nm_fence_method_desc[i]) + 1)
555 continue;
556 if (strncasecmp(page, o2nm_fence_method_desc[i], count - 1))
557 continue;
558 if (to_o2nm_cluster(item)->cl_fence_method != i) {
559 printk(KERN_INFO "ocfs2: Changing fence method to %s\n",
560 o2nm_fence_method_desc[i]);
561 to_o2nm_cluster(item)->cl_fence_method = i;
563 return count;
566 bail:
567 return -EINVAL;
570 CONFIGFS_ATTR(o2nm_cluster_, idle_timeout_ms);
571 CONFIGFS_ATTR(o2nm_cluster_, keepalive_delay_ms);
572 CONFIGFS_ATTR(o2nm_cluster_, reconnect_delay_ms);
573 CONFIGFS_ATTR(o2nm_cluster_, fence_method);
575 static struct configfs_attribute *o2nm_cluster_attrs[] = {
576 &o2nm_cluster_attr_idle_timeout_ms,
577 &o2nm_cluster_attr_keepalive_delay_ms,
578 &o2nm_cluster_attr_reconnect_delay_ms,
579 &o2nm_cluster_attr_fence_method,
580 NULL,
583 static struct config_item *o2nm_node_group_make_item(struct config_group *group,
584 const char *name)
586 struct o2nm_node *node = NULL;
588 if (strlen(name) > O2NM_MAX_NAME_LEN)
589 return ERR_PTR(-ENAMETOOLONG);
591 node = kzalloc(sizeof(struct o2nm_node), GFP_KERNEL);
592 if (node == NULL)
593 return ERR_PTR(-ENOMEM);
595 strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */
596 config_item_init_type_name(&node->nd_item, name, &o2nm_node_type);
597 spin_lock_init(&node->nd_lock);
599 mlog(ML_CLUSTER, "o2nm: Registering node %s\n", name);
601 return &node->nd_item;
604 static void o2nm_node_group_drop_item(struct config_group *group,
605 struct config_item *item)
607 struct o2nm_node *node = to_o2nm_node(item);
608 struct o2nm_cluster *cluster = to_o2nm_cluster(group->cg_item.ci_parent);
610 if (cluster->cl_nodes[node->nd_num] == node) {
611 o2net_disconnect_node(node);
613 if (cluster->cl_has_local &&
614 (cluster->cl_local_node == node->nd_num)) {
615 cluster->cl_has_local = 0;
616 cluster->cl_local_node = O2NM_INVALID_NODE_NUM;
617 o2net_stop_listening(node);
621 /* XXX call into net to stop this node from trading messages */
623 write_lock(&cluster->cl_nodes_lock);
625 /* XXX sloppy */
626 if (node->nd_ipv4_address)
627 rb_erase(&node->nd_ip_node, &cluster->cl_node_ip_tree);
629 /* nd_num might be 0 if the node number hasn't been set.. */
630 if (cluster->cl_nodes[node->nd_num] == node) {
631 cluster->cl_nodes[node->nd_num] = NULL;
632 clear_bit(node->nd_num, cluster->cl_nodes_bitmap);
634 write_unlock(&cluster->cl_nodes_lock);
636 mlog(ML_CLUSTER, "o2nm: Unregistered node %s\n",
637 config_item_name(&node->nd_item));
639 config_item_put(item);
642 static struct configfs_group_operations o2nm_node_group_group_ops = {
643 .make_item = o2nm_node_group_make_item,
644 .drop_item = o2nm_node_group_drop_item,
647 static const struct config_item_type o2nm_node_group_type = {
648 .ct_group_ops = &o2nm_node_group_group_ops,
649 .ct_owner = THIS_MODULE,
652 /* cluster */
654 static void o2nm_cluster_release(struct config_item *item)
656 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
658 kfree(cluster);
661 static struct configfs_item_operations o2nm_cluster_item_ops = {
662 .release = o2nm_cluster_release,
665 static const struct config_item_type o2nm_cluster_type = {
666 .ct_item_ops = &o2nm_cluster_item_ops,
667 .ct_attrs = o2nm_cluster_attrs,
668 .ct_owner = THIS_MODULE,
671 /* cluster set */
673 struct o2nm_cluster_group {
674 struct configfs_subsystem cs_subsys;
675 /* some stuff? */
678 #if 0
679 static struct o2nm_cluster_group *to_o2nm_cluster_group(struct config_group *group)
681 return group ?
682 container_of(to_configfs_subsystem(group), struct o2nm_cluster_group, cs_subsys)
683 : NULL;
685 #endif
687 static struct config_group *o2nm_cluster_group_make_group(struct config_group *group,
688 const char *name)
690 struct o2nm_cluster *cluster = NULL;
691 struct o2nm_node_group *ns = NULL;
692 struct config_group *o2hb_group = NULL, *ret = NULL;
694 /* this runs under the parent dir's i_mutex; there can be only
695 * one caller in here at a time */
696 if (o2nm_single_cluster)
697 return ERR_PTR(-ENOSPC);
699 cluster = kzalloc(sizeof(struct o2nm_cluster), GFP_KERNEL);
700 ns = kzalloc(sizeof(struct o2nm_node_group), GFP_KERNEL);
701 o2hb_group = o2hb_alloc_hb_set();
702 if (cluster == NULL || ns == NULL || o2hb_group == NULL)
703 goto out;
705 config_group_init_type_name(&cluster->cl_group, name,
706 &o2nm_cluster_type);
707 configfs_add_default_group(&ns->ns_group, &cluster->cl_group);
709 config_group_init_type_name(&ns->ns_group, "node",
710 &o2nm_node_group_type);
711 configfs_add_default_group(o2hb_group, &cluster->cl_group);
713 rwlock_init(&cluster->cl_nodes_lock);
714 cluster->cl_node_ip_tree = RB_ROOT;
715 cluster->cl_reconnect_delay_ms = O2NET_RECONNECT_DELAY_MS_DEFAULT;
716 cluster->cl_idle_timeout_ms = O2NET_IDLE_TIMEOUT_MS_DEFAULT;
717 cluster->cl_keepalive_delay_ms = O2NET_KEEPALIVE_DELAY_MS_DEFAULT;
718 cluster->cl_fence_method = O2NM_FENCE_RESET;
720 ret = &cluster->cl_group;
721 o2nm_single_cluster = cluster;
723 out:
724 if (ret == NULL) {
725 kfree(cluster);
726 kfree(ns);
727 o2hb_free_hb_set(o2hb_group);
728 ret = ERR_PTR(-ENOMEM);
731 return ret;
734 static void o2nm_cluster_group_drop_item(struct config_group *group, struct config_item *item)
736 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
738 BUG_ON(o2nm_single_cluster != cluster);
739 o2nm_single_cluster = NULL;
741 configfs_remove_default_groups(&cluster->cl_group);
742 config_item_put(item);
745 static struct configfs_group_operations o2nm_cluster_group_group_ops = {
746 .make_group = o2nm_cluster_group_make_group,
747 .drop_item = o2nm_cluster_group_drop_item,
750 static const struct config_item_type o2nm_cluster_group_type = {
751 .ct_group_ops = &o2nm_cluster_group_group_ops,
752 .ct_owner = THIS_MODULE,
755 static struct o2nm_cluster_group o2nm_cluster_group = {
756 .cs_subsys = {
757 .su_group = {
758 .cg_item = {
759 .ci_namebuf = "cluster",
760 .ci_type = &o2nm_cluster_group_type,
766 static inline void o2nm_lock_subsystem(void)
768 mutex_lock(&o2nm_cluster_group.cs_subsys.su_mutex);
771 static inline void o2nm_unlock_subsystem(void)
773 mutex_unlock(&o2nm_cluster_group.cs_subsys.su_mutex);
776 int o2nm_depend_item(struct config_item *item)
778 return configfs_depend_item(&o2nm_cluster_group.cs_subsys, item);
781 void o2nm_undepend_item(struct config_item *item)
783 configfs_undepend_item(item);
786 int o2nm_depend_this_node(void)
788 int ret = 0;
789 struct o2nm_node *local_node;
791 local_node = o2nm_get_node_by_num(o2nm_this_node());
792 if (!local_node) {
793 ret = -EINVAL;
794 goto out;
797 ret = o2nm_depend_item(&local_node->nd_item);
798 o2nm_node_put(local_node);
800 out:
801 return ret;
804 void o2nm_undepend_this_node(void)
806 struct o2nm_node *local_node;
808 local_node = o2nm_get_node_by_num(o2nm_this_node());
809 BUG_ON(!local_node);
811 o2nm_undepend_item(&local_node->nd_item);
812 o2nm_node_put(local_node);
816 static void __exit exit_o2nm(void)
818 /* XXX sync with hb callbacks and shut down hb? */
819 o2net_unregister_hb_callbacks();
820 configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
821 o2cb_sys_shutdown();
823 o2net_exit();
824 o2hb_exit();
827 static int __init init_o2nm(void)
829 int ret = -1;
831 o2hb_init();
833 ret = o2net_init();
834 if (ret)
835 goto out_o2hb;
837 ret = o2net_register_hb_callbacks();
838 if (ret)
839 goto out_o2net;
841 config_group_init(&o2nm_cluster_group.cs_subsys.su_group);
842 mutex_init(&o2nm_cluster_group.cs_subsys.su_mutex);
843 ret = configfs_register_subsystem(&o2nm_cluster_group.cs_subsys);
844 if (ret) {
845 printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
846 goto out_callbacks;
849 ret = o2cb_sys_init();
850 if (!ret)
851 goto out;
853 configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
854 out_callbacks:
855 o2net_unregister_hb_callbacks();
856 out_o2net:
857 o2net_exit();
858 out_o2hb:
859 o2hb_exit();
860 out:
861 return ret;
864 MODULE_AUTHOR("Oracle");
865 MODULE_LICENSE("GPL");
866 MODULE_DESCRIPTION("OCFS2 cluster management");
868 module_init(init_o2nm)
869 module_exit(exit_o2nm)