stackglue.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * stackglue.c
  4. *
  5. * Code which implements an OCFS2 specific interface to underlying
  6. * cluster stacks.
  7. *
  8. * Copyright (C) 2007, 2009 Oracle. All rights reserved.
  9. */
  10. #include <linux/list.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <linux/kmod.h>
  15. #include <linux/fs.h>
  16. #include <linux/kobject.h>
  17. #include <linux/sysfs.h>
  18. #include <linux/sysctl.h>
  19. #include "ocfs2_fs.h"
  20. #include "stackglue.h"
  21. #define OCFS2_STACK_PLUGIN_O2CB "o2cb"
  22. #define OCFS2_STACK_PLUGIN_USER "user"
  23. #define OCFS2_MAX_HB_CTL_PATH 256
  24. static struct ocfs2_protocol_version locking_max_version;
  25. static DEFINE_SPINLOCK(ocfs2_stack_lock);
  26. static LIST_HEAD(ocfs2_stack_list);
  27. static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1];
  28. static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
  29. /*
  30. * The stack currently in use. If not null, active_stack->sp_count > 0,
  31. * the module is pinned, and the locking protocol cannot be changed.
  32. */
  33. static struct ocfs2_stack_plugin *active_stack;
  34. static struct ocfs2_stack_plugin *ocfs2_stack_lookup(const char *name)
  35. {
  36. struct ocfs2_stack_plugin *p;
  37. assert_spin_locked(&ocfs2_stack_lock);
  38. list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
  39. if (!strcmp(p->sp_name, name))
  40. return p;
  41. }
  42. return NULL;
  43. }
  44. static int ocfs2_stack_driver_request(const char *stack_name,
  45. const char *plugin_name)
  46. {
  47. int rc;
  48. struct ocfs2_stack_plugin *p;
  49. spin_lock(&ocfs2_stack_lock);
  50. /*
  51. * If the stack passed by the filesystem isn't the selected one,
  52. * we can't continue.
  53. */
  54. if (strcmp(stack_name, cluster_stack_name)) {
  55. rc = -EBUSY;
  56. goto out;
  57. }
  58. if (active_stack) {
  59. /*
  60. * If the active stack isn't the one we want, it cannot
  61. * be selected right now.
  62. */
  63. if (!strcmp(active_stack->sp_name, plugin_name))
  64. rc = 0;
  65. else
  66. rc = -EBUSY;
  67. goto out;
  68. }
  69. p = ocfs2_stack_lookup(plugin_name);
  70. if (!p || !try_module_get(p->sp_owner)) {
  71. rc = -ENOENT;
  72. goto out;
  73. }
  74. active_stack = p;
  75. rc = 0;
  76. out:
  77. /* If we found it, pin it */
  78. if (!rc)
  79. active_stack->sp_count++;
  80. spin_unlock(&ocfs2_stack_lock);
  81. return rc;
  82. }
  83. /*
  84. * This function looks up the appropriate stack and makes it active. If
  85. * there is no stack, it tries to load it. It will fail if the stack still
  86. * cannot be found. It will also fail if a different stack is in use.
  87. */
  88. static int ocfs2_stack_driver_get(const char *stack_name)
  89. {
  90. int rc;
  91. char *plugin_name = OCFS2_STACK_PLUGIN_O2CB;
  92. /*
  93. * Classic stack does not pass in a stack name. This is
  94. * compatible with older tools as well.
  95. */
  96. if (!stack_name || !*stack_name)
  97. stack_name = OCFS2_STACK_PLUGIN_O2CB;
  98. if (strlen(stack_name) != OCFS2_STACK_LABEL_LEN) {
  99. printk(KERN_ERR
  100. "ocfs2 passed an invalid cluster stack label: \"%s\"\n",
  101. stack_name);
  102. return -EINVAL;
  103. }
  104. /* Anything that isn't the classic stack is a user stack */
  105. if (strcmp(stack_name, OCFS2_STACK_PLUGIN_O2CB))
  106. plugin_name = OCFS2_STACK_PLUGIN_USER;
  107. rc = ocfs2_stack_driver_request(stack_name, plugin_name);
  108. if (rc == -ENOENT) {
  109. request_module("ocfs2_stack_%s", plugin_name);
  110. rc = ocfs2_stack_driver_request(stack_name, plugin_name);
  111. }
  112. if (rc == -ENOENT) {
  113. printk(KERN_ERR
  114. "ocfs2: Cluster stack driver \"%s\" cannot be found\n",
  115. plugin_name);
  116. } else if (rc == -EBUSY) {
  117. printk(KERN_ERR
  118. "ocfs2: A different cluster stack is in use\n");
  119. }
  120. return rc;
  121. }
  122. static void ocfs2_stack_driver_put(void)
  123. {
  124. spin_lock(&ocfs2_stack_lock);
  125. BUG_ON(active_stack == NULL);
  126. BUG_ON(active_stack->sp_count == 0);
  127. active_stack->sp_count--;
  128. if (!active_stack->sp_count) {
  129. module_put(active_stack->sp_owner);
  130. active_stack = NULL;
  131. }
  132. spin_unlock(&ocfs2_stack_lock);
  133. }
  134. int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin)
  135. {
  136. int rc;
  137. spin_lock(&ocfs2_stack_lock);
  138. if (!ocfs2_stack_lookup(plugin->sp_name)) {
  139. plugin->sp_count = 0;
  140. plugin->sp_max_proto = locking_max_version;
  141. list_add(&plugin->sp_list, &ocfs2_stack_list);
  142. printk(KERN_INFO "ocfs2: Registered cluster interface %s\n",
  143. plugin->sp_name);
  144. rc = 0;
  145. } else {
  146. printk(KERN_ERR "ocfs2: Stack \"%s\" already registered\n",
  147. plugin->sp_name);
  148. rc = -EEXIST;
  149. }
  150. spin_unlock(&ocfs2_stack_lock);
  151. return rc;
  152. }
  153. EXPORT_SYMBOL_GPL(ocfs2_stack_glue_register);
  154. void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin)
  155. {
  156. struct ocfs2_stack_plugin *p;
  157. spin_lock(&ocfs2_stack_lock);
  158. p = ocfs2_stack_lookup(plugin->sp_name);
  159. if (p) {
  160. BUG_ON(p != plugin);
  161. BUG_ON(plugin == active_stack);
  162. BUG_ON(plugin->sp_count != 0);
  163. list_del_init(&plugin->sp_list);
  164. printk(KERN_INFO "ocfs2: Unregistered cluster interface %s\n",
  165. plugin->sp_name);
  166. } else {
  167. printk(KERN_ERR "Stack \"%s\" is not registered\n",
  168. plugin->sp_name);
  169. }
  170. spin_unlock(&ocfs2_stack_lock);
  171. }
  172. EXPORT_SYMBOL_GPL(ocfs2_stack_glue_unregister);
  173. void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto)
  174. {
  175. struct ocfs2_stack_plugin *p;
  176. spin_lock(&ocfs2_stack_lock);
  177. if (memcmp(max_proto, &locking_max_version,
  178. sizeof(struct ocfs2_protocol_version))) {
  179. BUG_ON(locking_max_version.pv_major != 0);
  180. locking_max_version = *max_proto;
  181. list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
  182. p->sp_max_proto = locking_max_version;
  183. }
  184. }
  185. spin_unlock(&ocfs2_stack_lock);
  186. }
  187. EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_max_proto_version);
  188. /*
  189. * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take no argument
  190. * for the ast and bast functions. They will pass the lksb to the ast
  191. * and bast. The caller can wrap the lksb with their own structure to
  192. * get more information.
  193. */
  194. int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
  195. int mode,
  196. struct ocfs2_dlm_lksb *lksb,
  197. u32 flags,
  198. void *name,
  199. unsigned int namelen)
  200. {
  201. if (!lksb->lksb_conn)
  202. lksb->lksb_conn = conn;
  203. else
  204. BUG_ON(lksb->lksb_conn != conn);
  205. return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags,
  206. name, namelen);
  207. }
  208. EXPORT_SYMBOL_GPL(ocfs2_dlm_lock);
  209. int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
  210. struct ocfs2_dlm_lksb *lksb,
  211. u32 flags)
  212. {
  213. BUG_ON(lksb->lksb_conn == NULL);
  214. return active_stack->sp_ops->dlm_unlock(conn, lksb, flags);
  215. }
  216. EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock);
  217. int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb)
  218. {
  219. return active_stack->sp_ops->lock_status(lksb);
  220. }
  221. EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status);
  222. int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb)
  223. {
  224. return active_stack->sp_ops->lvb_valid(lksb);
  225. }
  226. EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb_valid);
  227. void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb)
  228. {
  229. return active_stack->sp_ops->lock_lvb(lksb);
  230. }
  231. EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb);
  232. void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb)
  233. {
  234. active_stack->sp_ops->dump_lksb(lksb);
  235. }
  236. EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb);
  237. int ocfs2_stack_supports_plocks(void)
  238. {
  239. return active_stack && active_stack->sp_ops->plock;
  240. }
  241. EXPORT_SYMBOL_GPL(ocfs2_stack_supports_plocks);
  242. /*
  243. * ocfs2_plock() can only be safely called if
  244. * ocfs2_stack_supports_plocks() returned true
  245. */
  246. int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino,
  247. struct file *file, int cmd, struct file_lock *fl)
  248. {
  249. WARN_ON_ONCE(active_stack->sp_ops->plock == NULL);
  250. if (active_stack->sp_ops->plock)
  251. return active_stack->sp_ops->plock(conn, ino, file, cmd, fl);
  252. return -EOPNOTSUPP;
  253. }
  254. EXPORT_SYMBOL_GPL(ocfs2_plock);
  255. int ocfs2_cluster_connect(const char *stack_name,
  256. const char *cluster_name,
  257. int cluster_name_len,
  258. const char *group,
  259. int grouplen,
  260. struct ocfs2_locking_protocol *lproto,
  261. void (*recovery_handler)(int node_num,
  262. void *recovery_data),
  263. void *recovery_data,
  264. struct ocfs2_cluster_connection **conn)
  265. {
  266. int rc = 0;
  267. struct ocfs2_cluster_connection *new_conn;
  268. BUG_ON(group == NULL);
  269. BUG_ON(conn == NULL);
  270. BUG_ON(recovery_handler == NULL);
  271. if (grouplen > GROUP_NAME_MAX) {
  272. rc = -EINVAL;
  273. goto out;
  274. }
  275. if (memcmp(&lproto->lp_max_version, &locking_max_version,
  276. sizeof(struct ocfs2_protocol_version))) {
  277. rc = -EINVAL;
  278. goto out;
  279. }
  280. new_conn = kzalloc(sizeof(struct ocfs2_cluster_connection),
  281. GFP_KERNEL);
  282. if (!new_conn) {
  283. rc = -ENOMEM;
  284. goto out;
  285. }
  286. strscpy(new_conn->cc_name, group, GROUP_NAME_MAX + 1);
  287. new_conn->cc_namelen = grouplen;
  288. if (cluster_name_len)
  289. strscpy(new_conn->cc_cluster_name, cluster_name,
  290. CLUSTER_NAME_MAX + 1);
  291. new_conn->cc_cluster_name_len = cluster_name_len;
  292. new_conn->cc_recovery_handler = recovery_handler;
  293. new_conn->cc_recovery_data = recovery_data;
  294. new_conn->cc_proto = lproto;
  295. /* Start the new connection at our maximum compatibility level */
  296. new_conn->cc_version = lproto->lp_max_version;
  297. /* This will pin the stack driver if successful */
  298. rc = ocfs2_stack_driver_get(stack_name);
  299. if (rc)
  300. goto out_free;
  301. rc = active_stack->sp_ops->connect(new_conn);
  302. if (rc) {
  303. ocfs2_stack_driver_put();
  304. goto out_free;
  305. }
  306. *conn = new_conn;
  307. out_free:
  308. if (rc)
  309. kfree(new_conn);
  310. out:
  311. return rc;
  312. }
  313. EXPORT_SYMBOL_GPL(ocfs2_cluster_connect);
  314. /* The caller will ensure all nodes have the same cluster stack */
  315. int ocfs2_cluster_connect_agnostic(const char *group,
  316. int grouplen,
  317. struct ocfs2_locking_protocol *lproto,
  318. void (*recovery_handler)(int node_num,
  319. void *recovery_data),
  320. void *recovery_data,
  321. struct ocfs2_cluster_connection **conn)
  322. {
  323. char *stack_name = NULL;
  324. if (cluster_stack_name[0])
  325. stack_name = cluster_stack_name;
  326. return ocfs2_cluster_connect(stack_name, NULL, 0, group, grouplen,
  327. lproto, recovery_handler, recovery_data,
  328. conn);
  329. }
  330. EXPORT_SYMBOL_GPL(ocfs2_cluster_connect_agnostic);
  331. /* If hangup_pending is 0, the stack driver will be dropped */
  332. int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn,
  333. int hangup_pending)
  334. {
  335. int ret;
  336. BUG_ON(conn == NULL);
  337. ret = active_stack->sp_ops->disconnect(conn);
  338. /* XXX Should we free it anyway? */
  339. if (!ret) {
  340. kfree(conn);
  341. if (!hangup_pending)
  342. ocfs2_stack_driver_put();
  343. }
  344. return ret;
  345. }
  346. EXPORT_SYMBOL_GPL(ocfs2_cluster_disconnect);
  347. /*
  348. * Leave the group for this filesystem. This is executed by a userspace
  349. * program (stored in ocfs2_hb_ctl_path).
  350. */
  351. static void ocfs2_leave_group(const char *group)
  352. {
  353. int ret;
  354. char *argv[5], *envp[3];
  355. argv[0] = ocfs2_hb_ctl_path;
  356. argv[1] = "-K";
  357. argv[2] = "-u";
  358. argv[3] = (char *)group;
  359. argv[4] = NULL;
  360. /* minimal command environment taken from cpu_run_sbin_hotplug */
  361. envp[0] = "HOME=/";
  362. envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
  363. envp[2] = NULL;
  364. ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
  365. if (ret < 0) {
  366. printk(KERN_ERR
  367. "ocfs2: Error %d running user helper "
  368. "\"%s %s %s %s\"\n",
  369. ret, argv[0], argv[1], argv[2], argv[3]);
  370. }
  371. }
  372. /*
  373. * Hangup is a required post-umount. ocfs2-tools software expects the
  374. * filesystem to call "ocfs2_hb_ctl" during unmount. This happens
  375. * regardless of whether the DLM got started, so we can't do it
  376. * in ocfs2_cluster_disconnect(). The ocfs2_leave_group() function does
  377. * the actual work.
  378. */
  379. void ocfs2_cluster_hangup(const char *group, int grouplen)
  380. {
  381. BUG_ON(group == NULL);
  382. BUG_ON(group[grouplen] != '\0');
  383. ocfs2_leave_group(group);
  384. /* cluster_disconnect() was called with hangup_pending==1 */
  385. ocfs2_stack_driver_put();
  386. }
  387. EXPORT_SYMBOL_GPL(ocfs2_cluster_hangup);
  388. int ocfs2_cluster_this_node(struct ocfs2_cluster_connection *conn,
  389. unsigned int *node)
  390. {
  391. return active_stack->sp_ops->this_node(conn, node);
  392. }
  393. EXPORT_SYMBOL_GPL(ocfs2_cluster_this_node);
  394. /*
  395. * Sysfs bits
  396. */
  397. static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj,
  398. struct kobj_attribute *attr,
  399. char *buf)
  400. {
  401. ssize_t ret = 0;
  402. spin_lock(&ocfs2_stack_lock);
  403. if (locking_max_version.pv_major)
  404. ret = snprintf(buf, PAGE_SIZE, "%u.%u\n",
  405. locking_max_version.pv_major,
  406. locking_max_version.pv_minor);
  407. spin_unlock(&ocfs2_stack_lock);
  408. return ret;
  409. }
  410. static struct kobj_attribute ocfs2_attr_max_locking_protocol =
  411. __ATTR(max_locking_protocol, S_IRUGO,
  412. ocfs2_max_locking_protocol_show, NULL);
  413. static ssize_t ocfs2_loaded_cluster_plugins_show(struct kobject *kobj,
  414. struct kobj_attribute *attr,
  415. char *buf)
  416. {
  417. ssize_t ret = 0, total = 0, remain = PAGE_SIZE;
  418. struct ocfs2_stack_plugin *p;
  419. spin_lock(&ocfs2_stack_lock);
  420. list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
  421. ret = snprintf(buf, remain, "%s\n",
  422. p->sp_name);
  423. if (ret >= remain) {
  424. /* snprintf() didn't fit */
  425. total = -E2BIG;
  426. break;
  427. }
  428. total += ret;
  429. remain -= ret;
  430. }
  431. spin_unlock(&ocfs2_stack_lock);
  432. return total;
  433. }
  434. static struct kobj_attribute ocfs2_attr_loaded_cluster_plugins =
  435. __ATTR(loaded_cluster_plugins, S_IRUGO,
  436. ocfs2_loaded_cluster_plugins_show, NULL);
  437. static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj,
  438. struct kobj_attribute *attr,
  439. char *buf)
  440. {
  441. ssize_t ret = 0;
  442. spin_lock(&ocfs2_stack_lock);
  443. if (active_stack) {
  444. ret = snprintf(buf, PAGE_SIZE, "%s\n",
  445. active_stack->sp_name);
  446. if (ret >= PAGE_SIZE)
  447. ret = -E2BIG;
  448. }
  449. spin_unlock(&ocfs2_stack_lock);
  450. return ret;
  451. }
  452. static struct kobj_attribute ocfs2_attr_active_cluster_plugin =
  453. __ATTR(active_cluster_plugin, S_IRUGO,
  454. ocfs2_active_cluster_plugin_show, NULL);
  455. static ssize_t ocfs2_cluster_stack_show(struct kobject *kobj,
  456. struct kobj_attribute *attr,
  457. char *buf)
  458. {
  459. ssize_t ret;
  460. spin_lock(&ocfs2_stack_lock);
  461. ret = snprintf(buf, PAGE_SIZE, "%s\n", cluster_stack_name);
  462. spin_unlock(&ocfs2_stack_lock);
  463. return ret;
  464. }
  465. static ssize_t ocfs2_cluster_stack_store(struct kobject *kobj,
  466. struct kobj_attribute *attr,
  467. const char *buf, size_t count)
  468. {
  469. size_t len = count;
  470. ssize_t ret;
  471. if (len == 0)
  472. return len;
  473. if (buf[len - 1] == '\n')
  474. len--;
  475. if ((len != OCFS2_STACK_LABEL_LEN) ||
  476. (strnlen(buf, len) != len))
  477. return -EINVAL;
  478. spin_lock(&ocfs2_stack_lock);
  479. if (active_stack) {
  480. if (!strncmp(buf, cluster_stack_name, len))
  481. ret = count;
  482. else
  483. ret = -EBUSY;
  484. } else {
  485. memcpy(cluster_stack_name, buf, len);
  486. ret = count;
  487. }
  488. spin_unlock(&ocfs2_stack_lock);
  489. return ret;
  490. }
  491. static struct kobj_attribute ocfs2_attr_cluster_stack =
  492. __ATTR(cluster_stack, S_IRUGO | S_IWUSR,
  493. ocfs2_cluster_stack_show,
  494. ocfs2_cluster_stack_store);
  495. static ssize_t ocfs2_dlm_recover_show(struct kobject *kobj,
  496. struct kobj_attribute *attr,
  497. char *buf)
  498. {
  499. return snprintf(buf, PAGE_SIZE, "1\n");
  500. }
  501. static struct kobj_attribute ocfs2_attr_dlm_recover_support =
  502. __ATTR(dlm_recover_callback_support, S_IRUGO,
  503. ocfs2_dlm_recover_show, NULL);
  504. static struct attribute *ocfs2_attrs[] = {
  505. &ocfs2_attr_max_locking_protocol.attr,
  506. &ocfs2_attr_loaded_cluster_plugins.attr,
  507. &ocfs2_attr_active_cluster_plugin.attr,
  508. &ocfs2_attr_cluster_stack.attr,
  509. &ocfs2_attr_dlm_recover_support.attr,
  510. NULL,
  511. };
  512. static const struct attribute_group ocfs2_attr_group = {
  513. .attrs = ocfs2_attrs,
  514. };
  515. struct kset *ocfs2_kset;
  516. EXPORT_SYMBOL_GPL(ocfs2_kset);
  517. static void ocfs2_sysfs_exit(void)
  518. {
  519. kset_unregister(ocfs2_kset);
  520. }
  521. static int ocfs2_sysfs_init(void)
  522. {
  523. int ret;
  524. ocfs2_kset = kset_create_and_add("ocfs2", NULL, fs_kobj);
  525. if (!ocfs2_kset)
  526. return -ENOMEM;
  527. ret = sysfs_create_group(&ocfs2_kset->kobj, &ocfs2_attr_group);
  528. if (ret)
  529. goto error;
  530. return 0;
  531. error:
  532. kset_unregister(ocfs2_kset);
  533. return ret;
  534. }
  535. /*
  536. * Sysctl bits
  537. *
  538. * The sysctl lives at /proc/sys/fs/ocfs2/nm/hb_ctl_path. The 'nm' doesn't
  539. * make as much sense in a multiple cluster stack world, but it's safer
  540. * and easier to preserve the name.
  541. */
  542. static struct ctl_table ocfs2_nm_table[] = {
  543. {
  544. .procname = "hb_ctl_path",
  545. .data = ocfs2_hb_ctl_path,
  546. .maxlen = OCFS2_MAX_HB_CTL_PATH,
  547. .mode = 0644,
  548. .proc_handler = proc_dostring,
  549. },
  550. };
  551. static struct ctl_table_header *ocfs2_table_header;
  552. /*
  553. * Initialization
  554. */
  555. static int __init ocfs2_stack_glue_init(void)
  556. {
  557. int ret;
  558. strcpy(cluster_stack_name, OCFS2_STACK_PLUGIN_O2CB);
  559. ocfs2_table_header = register_sysctl("fs/ocfs2/nm", ocfs2_nm_table);
  560. if (!ocfs2_table_header) {
  561. printk(KERN_ERR
  562. "ocfs2 stack glue: unable to register sysctl\n");
  563. return -ENOMEM; /* or something. */
  564. }
  565. ret = ocfs2_sysfs_init();
  566. if (ret)
  567. unregister_sysctl_table(ocfs2_table_header);
  568. return ret;
  569. }
  570. static void __exit ocfs2_stack_glue_exit(void)
  571. {
  572. memset(&locking_max_version, 0,
  573. sizeof(struct ocfs2_protocol_version));
  574. ocfs2_sysfs_exit();
  575. if (ocfs2_table_header)
  576. unregister_sysctl_table(ocfs2_table_header);
  577. }
  578. MODULE_AUTHOR("Oracle");
  579. MODULE_DESCRIPTION("ocfs2 cluster stack glue layer");
  580. MODULE_LICENSE("GPL");
  581. module_init(ocfs2_stack_glue_init);
  582. module_exit(ocfs2_stack_glue_exit);