nodemanager.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * Copyright (C) 2004, 2005 Oracle. All rights reserved.
  5. *
  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.
  10. *
  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.
  15. *
  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.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/sysctl.h>
  24. #include <linux/configfs.h>
  25. #include "endian.h"
  26. #include "tcp.h"
  27. #include "nodemanager.h"
  28. #include "heartbeat.h"
  29. #include "masklog.h"
  30. #include "sys.h"
  31. #include "ver.h"
  32. /* for now we operate under the assertion that there can be only one
  33. * cluster active at a time. Changing this will require trickling
  34. * cluster references throughout where nodes are looked up */
  35. static struct o2nm_cluster *o2nm_single_cluster = NULL;
  36. #define OCFS2_MAX_HB_CTL_PATH 256
  37. static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
  38. static ctl_table ocfs2_nm_table[] = {
  39. {
  40. .ctl_name = 1,
  41. .procname = "hb_ctl_path",
  42. .data = ocfs2_hb_ctl_path,
  43. .maxlen = OCFS2_MAX_HB_CTL_PATH,
  44. .mode = 0644,
  45. .proc_handler = &proc_dostring,
  46. .strategy = &sysctl_string,
  47. },
  48. { .ctl_name = 0 }
  49. };
  50. static ctl_table ocfs2_mod_table[] = {
  51. {
  52. .ctl_name = KERN_OCFS2_NM,
  53. .procname = "nm",
  54. .data = NULL,
  55. .maxlen = 0,
  56. .mode = 0555,
  57. .child = ocfs2_nm_table
  58. },
  59. { .ctl_name = 0}
  60. };
  61. static ctl_table ocfs2_kern_table[] = {
  62. {
  63. .ctl_name = KERN_OCFS2,
  64. .procname = "ocfs2",
  65. .data = NULL,
  66. .maxlen = 0,
  67. .mode = 0555,
  68. .child = ocfs2_mod_table
  69. },
  70. { .ctl_name = 0}
  71. };
  72. static ctl_table ocfs2_root_table[] = {
  73. {
  74. .ctl_name = CTL_FS,
  75. .procname = "fs",
  76. .data = NULL,
  77. .maxlen = 0,
  78. .mode = 0555,
  79. .child = ocfs2_kern_table
  80. },
  81. { .ctl_name = 0 }
  82. };
  83. static struct ctl_table_header *ocfs2_table_header = NULL;
  84. const char *o2nm_get_hb_ctl_path(void)
  85. {
  86. return ocfs2_hb_ctl_path;
  87. }
  88. EXPORT_SYMBOL_GPL(o2nm_get_hb_ctl_path);
  89. struct o2nm_cluster {
  90. struct config_group cl_group;
  91. unsigned cl_has_local:1;
  92. u8 cl_local_node;
  93. rwlock_t cl_nodes_lock;
  94. struct o2nm_node *cl_nodes[O2NM_MAX_NODES];
  95. struct rb_root cl_node_ip_tree;
  96. /* this bitmap is part of a hack for disk bitmap.. will go eventually. - zab */
  97. unsigned long cl_nodes_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
  98. };
  99. struct o2nm_node *o2nm_get_node_by_num(u8 node_num)
  100. {
  101. struct o2nm_node *node = NULL;
  102. if (node_num >= O2NM_MAX_NODES || o2nm_single_cluster == NULL)
  103. goto out;
  104. read_lock(&o2nm_single_cluster->cl_nodes_lock);
  105. node = o2nm_single_cluster->cl_nodes[node_num];
  106. if (node)
  107. config_item_get(&node->nd_item);
  108. read_unlock(&o2nm_single_cluster->cl_nodes_lock);
  109. out:
  110. return node;
  111. }
  112. EXPORT_SYMBOL_GPL(o2nm_get_node_by_num);
  113. int o2nm_configured_node_map(unsigned long *map, unsigned bytes)
  114. {
  115. struct o2nm_cluster *cluster = o2nm_single_cluster;
  116. BUG_ON(bytes < (sizeof(cluster->cl_nodes_bitmap)));
  117. if (cluster == NULL)
  118. return -EINVAL;
  119. read_lock(&cluster->cl_nodes_lock);
  120. memcpy(map, cluster->cl_nodes_bitmap, sizeof(cluster->cl_nodes_bitmap));
  121. read_unlock(&cluster->cl_nodes_lock);
  122. return 0;
  123. }
  124. EXPORT_SYMBOL_GPL(o2nm_configured_node_map);
  125. static struct o2nm_node *o2nm_node_ip_tree_lookup(struct o2nm_cluster *cluster,
  126. __be32 ip_needle,
  127. struct rb_node ***ret_p,
  128. struct rb_node **ret_parent)
  129. {
  130. struct rb_node **p = &cluster->cl_node_ip_tree.rb_node;
  131. struct rb_node *parent = NULL;
  132. struct o2nm_node *node, *ret = NULL;
  133. while (*p) {
  134. int cmp;
  135. parent = *p;
  136. node = rb_entry(parent, struct o2nm_node, nd_ip_node);
  137. cmp = memcmp(&ip_needle, &node->nd_ipv4_address,
  138. sizeof(ip_needle));
  139. if (cmp < 0)
  140. p = &(*p)->rb_left;
  141. else if (cmp > 0)
  142. p = &(*p)->rb_right;
  143. else {
  144. ret = node;
  145. break;
  146. }
  147. }
  148. if (ret_p != NULL)
  149. *ret_p = p;
  150. if (ret_parent != NULL)
  151. *ret_parent = parent;
  152. return ret;
  153. }
  154. struct o2nm_node *o2nm_get_node_by_ip(__be32 addr)
  155. {
  156. struct o2nm_node *node = NULL;
  157. struct o2nm_cluster *cluster = o2nm_single_cluster;
  158. if (cluster == NULL)
  159. goto out;
  160. read_lock(&cluster->cl_nodes_lock);
  161. node = o2nm_node_ip_tree_lookup(cluster, addr, NULL, NULL);
  162. if (node)
  163. config_item_get(&node->nd_item);
  164. read_unlock(&cluster->cl_nodes_lock);
  165. out:
  166. return node;
  167. }
  168. EXPORT_SYMBOL_GPL(o2nm_get_node_by_ip);
  169. void o2nm_node_put(struct o2nm_node *node)
  170. {
  171. config_item_put(&node->nd_item);
  172. }
  173. EXPORT_SYMBOL_GPL(o2nm_node_put);
  174. void o2nm_node_get(struct o2nm_node *node)
  175. {
  176. config_item_get(&node->nd_item);
  177. }
  178. EXPORT_SYMBOL_GPL(o2nm_node_get);
  179. u8 o2nm_this_node(void)
  180. {
  181. u8 node_num = O2NM_MAX_NODES;
  182. if (o2nm_single_cluster && o2nm_single_cluster->cl_has_local)
  183. node_num = o2nm_single_cluster->cl_local_node;
  184. return node_num;
  185. }
  186. EXPORT_SYMBOL_GPL(o2nm_this_node);
  187. /* node configfs bits */
  188. static struct o2nm_cluster *to_o2nm_cluster(struct config_item *item)
  189. {
  190. return item ?
  191. container_of(to_config_group(item), struct o2nm_cluster,
  192. cl_group)
  193. : NULL;
  194. }
  195. static struct o2nm_node *to_o2nm_node(struct config_item *item)
  196. {
  197. return item ? container_of(item, struct o2nm_node, nd_item) : NULL;
  198. }
  199. static void o2nm_node_release(struct config_item *item)
  200. {
  201. struct o2nm_node *node = to_o2nm_node(item);
  202. kfree(node);
  203. }
  204. static ssize_t o2nm_node_num_read(struct o2nm_node *node, char *page)
  205. {
  206. return sprintf(page, "%d\n", node->nd_num);
  207. }
  208. static struct o2nm_cluster *to_o2nm_cluster_from_node(struct o2nm_node *node)
  209. {
  210. /* through the first node_set .parent
  211. * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
  212. return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
  213. }
  214. enum {
  215. O2NM_NODE_ATTR_NUM = 0,
  216. O2NM_NODE_ATTR_PORT,
  217. O2NM_NODE_ATTR_ADDRESS,
  218. O2NM_NODE_ATTR_LOCAL,
  219. };
  220. static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
  221. size_t count)
  222. {
  223. struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
  224. unsigned long tmp;
  225. char *p = (char *)page;
  226. tmp = simple_strtoul(p, &p, 0);
  227. if (!p || (*p && (*p != '\n')))
  228. return -EINVAL;
  229. if (tmp >= O2NM_MAX_NODES)
  230. return -ERANGE;
  231. /* once we're in the cl_nodes tree networking can look us up by
  232. * node number and try to use our address and port attributes
  233. * to connect to this node.. make sure that they've been set
  234. * before writing the node attribute? */
  235. if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
  236. !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
  237. return -EINVAL; /* XXX */
  238. write_lock(&cluster->cl_nodes_lock);
  239. if (cluster->cl_nodes[tmp])
  240. p = NULL;
  241. else {
  242. cluster->cl_nodes[tmp] = node;
  243. node->nd_num = tmp;
  244. set_bit(tmp, cluster->cl_nodes_bitmap);
  245. }
  246. write_unlock(&cluster->cl_nodes_lock);
  247. if (p == NULL)
  248. return -EEXIST;
  249. return count;
  250. }
  251. static ssize_t o2nm_node_ipv4_port_read(struct o2nm_node *node, char *page)
  252. {
  253. return sprintf(page, "%u\n", ntohs(node->nd_ipv4_port));
  254. }
  255. static ssize_t o2nm_node_ipv4_port_write(struct o2nm_node *node,
  256. const char *page, size_t count)
  257. {
  258. unsigned long tmp;
  259. char *p = (char *)page;
  260. tmp = simple_strtoul(p, &p, 0);
  261. if (!p || (*p && (*p != '\n')))
  262. return -EINVAL;
  263. if (tmp == 0)
  264. return -EINVAL;
  265. if (tmp >= (u16)-1)
  266. return -ERANGE;
  267. node->nd_ipv4_port = htons(tmp);
  268. return count;
  269. }
  270. static ssize_t o2nm_node_ipv4_address_read(struct o2nm_node *node, char *page)
  271. {
  272. return sprintf(page, "%u.%u.%u.%u\n", NIPQUAD(node->nd_ipv4_address));
  273. }
  274. static ssize_t o2nm_node_ipv4_address_write(struct o2nm_node *node,
  275. const char *page,
  276. size_t count)
  277. {
  278. struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
  279. int ret, i;
  280. struct rb_node **p, *parent;
  281. unsigned int octets[4];
  282. __be32 ipv4_addr = 0;
  283. ret = sscanf(page, "%3u.%3u.%3u.%3u", &octets[3], &octets[2],
  284. &octets[1], &octets[0]);
  285. if (ret != 4)
  286. return -EINVAL;
  287. for (i = 0; i < ARRAY_SIZE(octets); i++) {
  288. if (octets[i] > 255)
  289. return -ERANGE;
  290. be32_add_cpu(&ipv4_addr, octets[i] << (i * 8));
  291. }
  292. ret = 0;
  293. write_lock(&cluster->cl_nodes_lock);
  294. if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
  295. ret = -EEXIST;
  296. else {
  297. rb_link_node(&node->nd_ip_node, parent, p);
  298. rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
  299. }
  300. write_unlock(&cluster->cl_nodes_lock);
  301. if (ret)
  302. return ret;
  303. memcpy(&node->nd_ipv4_address, &ipv4_addr, sizeof(ipv4_addr));
  304. return count;
  305. }
  306. static ssize_t o2nm_node_local_read(struct o2nm_node *node, char *page)
  307. {
  308. return sprintf(page, "%d\n", node->nd_local);
  309. }
  310. static ssize_t o2nm_node_local_write(struct o2nm_node *node, const char *page,
  311. size_t count)
  312. {
  313. struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
  314. unsigned long tmp;
  315. char *p = (char *)page;
  316. ssize_t ret;
  317. tmp = simple_strtoul(p, &p, 0);
  318. if (!p || (*p && (*p != '\n')))
  319. return -EINVAL;
  320. tmp = !!tmp; /* boolean of whether this node wants to be local */
  321. /* setting local turns on networking rx for now so we require having
  322. * set everything else first */
  323. if (!test_bit(O2NM_NODE_ATTR_ADDRESS, &node->nd_set_attributes) ||
  324. !test_bit(O2NM_NODE_ATTR_NUM, &node->nd_set_attributes) ||
  325. !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
  326. return -EINVAL; /* XXX */
  327. /* the only failure case is trying to set a new local node
  328. * when a different one is already set */
  329. if (tmp && tmp == cluster->cl_has_local &&
  330. cluster->cl_local_node != node->nd_num)
  331. return -EBUSY;
  332. /* bring up the rx thread if we're setting the new local node. */
  333. if (tmp && !cluster->cl_has_local) {
  334. ret = o2net_start_listening(node);
  335. if (ret)
  336. return ret;
  337. }
  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;
  342. }
  343. node->nd_local = tmp;
  344. if (node->nd_local) {
  345. cluster->cl_has_local = tmp;
  346. cluster->cl_local_node = node->nd_num;
  347. }
  348. return count;
  349. }
  350. struct o2nm_node_attribute {
  351. struct configfs_attribute attr;
  352. ssize_t (*show)(struct o2nm_node *, char *);
  353. ssize_t (*store)(struct o2nm_node *, const char *, size_t);
  354. };
  355. static struct o2nm_node_attribute o2nm_node_attr_num = {
  356. .attr = { .ca_owner = THIS_MODULE,
  357. .ca_name = "num",
  358. .ca_mode = S_IRUGO | S_IWUSR },
  359. .show = o2nm_node_num_read,
  360. .store = o2nm_node_num_write,
  361. };
  362. static struct o2nm_node_attribute o2nm_node_attr_ipv4_port = {
  363. .attr = { .ca_owner = THIS_MODULE,
  364. .ca_name = "ipv4_port",
  365. .ca_mode = S_IRUGO | S_IWUSR },
  366. .show = o2nm_node_ipv4_port_read,
  367. .store = o2nm_node_ipv4_port_write,
  368. };
  369. static struct o2nm_node_attribute o2nm_node_attr_ipv4_address = {
  370. .attr = { .ca_owner = THIS_MODULE,
  371. .ca_name = "ipv4_address",
  372. .ca_mode = S_IRUGO | S_IWUSR },
  373. .show = o2nm_node_ipv4_address_read,
  374. .store = o2nm_node_ipv4_address_write,
  375. };
  376. static struct o2nm_node_attribute o2nm_node_attr_local = {
  377. .attr = { .ca_owner = THIS_MODULE,
  378. .ca_name = "local",
  379. .ca_mode = S_IRUGO | S_IWUSR },
  380. .show = o2nm_node_local_read,
  381. .store = o2nm_node_local_write,
  382. };
  383. static struct configfs_attribute *o2nm_node_attrs[] = {
  384. [O2NM_NODE_ATTR_NUM] = &o2nm_node_attr_num.attr,
  385. [O2NM_NODE_ATTR_PORT] = &o2nm_node_attr_ipv4_port.attr,
  386. [O2NM_NODE_ATTR_ADDRESS] = &o2nm_node_attr_ipv4_address.attr,
  387. [O2NM_NODE_ATTR_LOCAL] = &o2nm_node_attr_local.attr,
  388. NULL,
  389. };
  390. static int o2nm_attr_index(struct configfs_attribute *attr)
  391. {
  392. int i;
  393. for (i = 0; i < ARRAY_SIZE(o2nm_node_attrs); i++) {
  394. if (attr == o2nm_node_attrs[i])
  395. return i;
  396. }
  397. BUG();
  398. return 0;
  399. }
  400. static ssize_t o2nm_node_show(struct config_item *item,
  401. struct configfs_attribute *attr,
  402. char *page)
  403. {
  404. struct o2nm_node *node = to_o2nm_node(item);
  405. struct o2nm_node_attribute *o2nm_node_attr =
  406. container_of(attr, struct o2nm_node_attribute, attr);
  407. ssize_t ret = 0;
  408. if (o2nm_node_attr->show)
  409. ret = o2nm_node_attr->show(node, page);
  410. return ret;
  411. }
  412. static ssize_t o2nm_node_store(struct config_item *item,
  413. struct configfs_attribute *attr,
  414. const char *page, size_t count)
  415. {
  416. struct o2nm_node *node = to_o2nm_node(item);
  417. struct o2nm_node_attribute *o2nm_node_attr =
  418. container_of(attr, struct o2nm_node_attribute, attr);
  419. ssize_t ret;
  420. int attr_index = o2nm_attr_index(attr);
  421. if (o2nm_node_attr->store == NULL) {
  422. ret = -EINVAL;
  423. goto out;
  424. }
  425. if (test_bit(attr_index, &node->nd_set_attributes))
  426. return -EBUSY;
  427. ret = o2nm_node_attr->store(node, page, count);
  428. if (ret < count)
  429. goto out;
  430. set_bit(attr_index, &node->nd_set_attributes);
  431. out:
  432. return ret;
  433. }
  434. static struct configfs_item_operations o2nm_node_item_ops = {
  435. .release = o2nm_node_release,
  436. .show_attribute = o2nm_node_show,
  437. .store_attribute = o2nm_node_store,
  438. };
  439. static struct config_item_type o2nm_node_type = {
  440. .ct_item_ops = &o2nm_node_item_ops,
  441. .ct_attrs = o2nm_node_attrs,
  442. .ct_owner = THIS_MODULE,
  443. };
  444. /* node set */
  445. struct o2nm_node_group {
  446. struct config_group ns_group;
  447. /* some stuff? */
  448. };
  449. #if 0
  450. static struct o2nm_node_group *to_o2nm_node_group(struct config_group *group)
  451. {
  452. return group ?
  453. container_of(group, struct o2nm_node_group, ns_group)
  454. : NULL;
  455. }
  456. #endif
  457. static struct config_item *o2nm_node_group_make_item(struct config_group *group,
  458. const char *name)
  459. {
  460. struct o2nm_node *node = NULL;
  461. struct config_item *ret = NULL;
  462. if (strlen(name) > O2NM_MAX_NAME_LEN)
  463. goto out; /* ENAMETOOLONG */
  464. node = kcalloc(1, sizeof(struct o2nm_node), GFP_KERNEL);
  465. if (node == NULL)
  466. goto out; /* ENOMEM */
  467. strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */
  468. config_item_init_type_name(&node->nd_item, name, &o2nm_node_type);
  469. spin_lock_init(&node->nd_lock);
  470. ret = &node->nd_item;
  471. out:
  472. if (ret == NULL)
  473. kfree(node);
  474. return ret;
  475. }
  476. static void o2nm_node_group_drop_item(struct config_group *group,
  477. struct config_item *item)
  478. {
  479. struct o2nm_node *node = to_o2nm_node(item);
  480. struct o2nm_cluster *cluster = to_o2nm_cluster(group->cg_item.ci_parent);
  481. o2net_disconnect_node(node);
  482. if (cluster->cl_has_local &&
  483. (cluster->cl_local_node == node->nd_num)) {
  484. cluster->cl_has_local = 0;
  485. cluster->cl_local_node = O2NM_INVALID_NODE_NUM;
  486. o2net_stop_listening(node);
  487. }
  488. /* XXX call into net to stop this node from trading messages */
  489. write_lock(&cluster->cl_nodes_lock);
  490. /* XXX sloppy */
  491. if (node->nd_ipv4_address)
  492. rb_erase(&node->nd_ip_node, &cluster->cl_node_ip_tree);
  493. /* nd_num might be 0 if the node number hasn't been set.. */
  494. if (cluster->cl_nodes[node->nd_num] == node) {
  495. cluster->cl_nodes[node->nd_num] = NULL;
  496. clear_bit(node->nd_num, cluster->cl_nodes_bitmap);
  497. }
  498. write_unlock(&cluster->cl_nodes_lock);
  499. config_item_put(item);
  500. }
  501. static struct configfs_group_operations o2nm_node_group_group_ops = {
  502. .make_item = o2nm_node_group_make_item,
  503. .drop_item = o2nm_node_group_drop_item,
  504. };
  505. static struct config_item_type o2nm_node_group_type = {
  506. .ct_group_ops = &o2nm_node_group_group_ops,
  507. .ct_owner = THIS_MODULE,
  508. };
  509. /* cluster */
  510. static void o2nm_cluster_release(struct config_item *item)
  511. {
  512. struct o2nm_cluster *cluster = to_o2nm_cluster(item);
  513. kfree(cluster->cl_group.default_groups);
  514. kfree(cluster);
  515. }
  516. static struct configfs_item_operations o2nm_cluster_item_ops = {
  517. .release = o2nm_cluster_release,
  518. };
  519. static struct config_item_type o2nm_cluster_type = {
  520. .ct_item_ops = &o2nm_cluster_item_ops,
  521. .ct_owner = THIS_MODULE,
  522. };
  523. /* cluster set */
  524. struct o2nm_cluster_group {
  525. struct configfs_subsystem cs_subsys;
  526. /* some stuff? */
  527. };
  528. #if 0
  529. static struct o2nm_cluster_group *to_o2nm_cluster_group(struct config_group *group)
  530. {
  531. return group ?
  532. container_of(to_configfs_subsystem(group), struct o2nm_cluster_group, cs_subsys)
  533. : NULL;
  534. }
  535. #endif
  536. static struct config_group *o2nm_cluster_group_make_group(struct config_group *group,
  537. const char *name)
  538. {
  539. struct o2nm_cluster *cluster = NULL;
  540. struct o2nm_node_group *ns = NULL;
  541. struct config_group *o2hb_group = NULL, *ret = NULL;
  542. void *defs = NULL;
  543. /* this runs under the parent dir's i_mutex; there can be only
  544. * one caller in here at a time */
  545. if (o2nm_single_cluster)
  546. goto out; /* ENOSPC */
  547. cluster = kcalloc(1, sizeof(struct o2nm_cluster), GFP_KERNEL);
  548. ns = kcalloc(1, sizeof(struct o2nm_node_group), GFP_KERNEL);
  549. defs = kcalloc(3, sizeof(struct config_group *), GFP_KERNEL);
  550. o2hb_group = o2hb_alloc_hb_set();
  551. if (cluster == NULL || ns == NULL || o2hb_group == NULL || defs == NULL)
  552. goto out;
  553. config_group_init_type_name(&cluster->cl_group, name,
  554. &o2nm_cluster_type);
  555. config_group_init_type_name(&ns->ns_group, "node",
  556. &o2nm_node_group_type);
  557. cluster->cl_group.default_groups = defs;
  558. cluster->cl_group.default_groups[0] = &ns->ns_group;
  559. cluster->cl_group.default_groups[1] = o2hb_group;
  560. cluster->cl_group.default_groups[2] = NULL;
  561. rwlock_init(&cluster->cl_nodes_lock);
  562. cluster->cl_node_ip_tree = RB_ROOT;
  563. ret = &cluster->cl_group;
  564. o2nm_single_cluster = cluster;
  565. out:
  566. if (ret == NULL) {
  567. kfree(cluster);
  568. kfree(ns);
  569. o2hb_free_hb_set(o2hb_group);
  570. kfree(defs);
  571. }
  572. return ret;
  573. }
  574. static void o2nm_cluster_group_drop_item(struct config_group *group, struct config_item *item)
  575. {
  576. struct o2nm_cluster *cluster = to_o2nm_cluster(item);
  577. int i;
  578. struct config_item *killme;
  579. BUG_ON(o2nm_single_cluster != cluster);
  580. o2nm_single_cluster = NULL;
  581. for (i = 0; cluster->cl_group.default_groups[i]; i++) {
  582. killme = &cluster->cl_group.default_groups[i]->cg_item;
  583. cluster->cl_group.default_groups[i] = NULL;
  584. config_item_put(killme);
  585. }
  586. config_item_put(item);
  587. }
  588. static struct configfs_group_operations o2nm_cluster_group_group_ops = {
  589. .make_group = o2nm_cluster_group_make_group,
  590. .drop_item = o2nm_cluster_group_drop_item,
  591. };
  592. static struct config_item_type o2nm_cluster_group_type = {
  593. .ct_group_ops = &o2nm_cluster_group_group_ops,
  594. .ct_owner = THIS_MODULE,
  595. };
  596. static struct o2nm_cluster_group o2nm_cluster_group = {
  597. .cs_subsys = {
  598. .su_group = {
  599. .cg_item = {
  600. .ci_namebuf = "cluster",
  601. .ci_type = &o2nm_cluster_group_type,
  602. },
  603. },
  604. },
  605. };
  606. static void __exit exit_o2nm(void)
  607. {
  608. if (ocfs2_table_header)
  609. unregister_sysctl_table(ocfs2_table_header);
  610. /* XXX sync with hb callbacks and shut down hb? */
  611. o2net_unregister_hb_callbacks();
  612. configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
  613. o2cb_sys_shutdown();
  614. o2net_exit();
  615. }
  616. static int __init init_o2nm(void)
  617. {
  618. int ret = -1;
  619. cluster_print_version();
  620. o2hb_init();
  621. o2net_init();
  622. ocfs2_table_header = register_sysctl_table(ocfs2_root_table, 0);
  623. if (!ocfs2_table_header) {
  624. printk(KERN_ERR "nodemanager: unable to register sysctl\n");
  625. ret = -ENOMEM; /* or something. */
  626. goto out_o2net;
  627. }
  628. ret = o2net_register_hb_callbacks();
  629. if (ret)
  630. goto out_sysctl;
  631. config_group_init(&o2nm_cluster_group.cs_subsys.su_group);
  632. init_MUTEX(&o2nm_cluster_group.cs_subsys.su_sem);
  633. ret = configfs_register_subsystem(&o2nm_cluster_group.cs_subsys);
  634. if (ret) {
  635. printk(KERN_ERR "nodemanager: Registration returned %d\n", ret);
  636. goto out_callbacks;
  637. }
  638. ret = o2cb_sys_init();
  639. if (!ret)
  640. goto out;
  641. configfs_unregister_subsystem(&o2nm_cluster_group.cs_subsys);
  642. out_callbacks:
  643. o2net_unregister_hb_callbacks();
  644. out_sysctl:
  645. unregister_sysctl_table(ocfs2_table_header);
  646. out_o2net:
  647. o2net_exit();
  648. out:
  649. return ret;
  650. }
  651. MODULE_AUTHOR("Oracle");
  652. MODULE_LICENSE("GPL");
  653. module_init(init_o2nm)
  654. module_exit(exit_o2nm)