stackglue.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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/string.h>
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/kmod.h>
  16. #include <linux/fs.h>
  17. #include <linux/kobject.h>
  18. #include <linux/sysfs.h>
  19. #include <linux/sysctl.h>
  20. #include "ocfs2_fs.h"
  21. #include "stackglue.h"
  22. #define OCFS2_STACK_PLUGIN_O2CB "o2cb"
  23. #define OCFS2_STACK_PLUGIN_USER "user"
  24. #define OCFS2_MAX_HB_CTL_PATH 256
  25. static struct ocfs2_protocol_version locking_max_version;
  26. static DEFINE_SPINLOCK(ocfs2_stack_lock);
  27. static LIST_HEAD(ocfs2_stack_list);
  28. static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1];
  29. static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
  30. /*
  31. * The stack currently in use. If not null, active_stack->sp_count > 0,
  32. * the module is pinned, and the locking protocol cannot be changed.
  33. */
  34. static struct ocfs2_stack_plugin *active_stack;
  35. static struct ocfs2_stack_plugin *ocfs2_stack_lookup(const char *name)
  36. {
  37. struct ocfs2_stack_plugin *p;
  38. assert_spin_locked(&ocfs2_stack_lock);
  39. list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
  40. if (!strcmp(p->sp_name, name))
  41. return p;
  42. }
  43. return NULL;
  44. }
  45. static int ocfs2_stack_driver_request(const char *stack_name,
  46. const char *plugin_name)
  47. {
  48. int rc;
  49. struct ocfs2_stack_plugin *p;
  50. spin_lock(&ocfs2_stack_lock);
  51. /*
  52. * If the stack passed by the filesystem isn't the selected one,
  53. * we can't continue.
  54. */
  55. if (strcmp(stack_name, cluster_stack_name)) {
  56. rc = -EBUSY;
  57. goto out;
  58. }
  59. if (active_stack) {
  60. /*
  61. * If the active stack isn't the one we want, it cannot
  62. * be selected right now.
  63. */
  64. if (!strcmp(active_stack->sp_name, plugin_name))
  65. rc = 0;
  66. else
  67. rc = -EBUSY;
  68. goto out;
  69. }
  70. p = ocfs2_stack_lookup(plugin_name);
  71. if (!p || !try_module_get(p->sp_owner)) {
  72. rc = -ENOENT;
  73. goto out;
  74. }
  75. active_stack = p;
  76. rc = 0;
  77. out:
  78. /* If we found it, pin it */
  79. if (!rc)
  80. active_stack->sp_count++;
  81. spin_unlock(&ocfs2_stack_lock);
  82. return rc;
  83. }
  84. /*
  85. * This function looks up the appropriate stack and makes it active. If
  86. * there is no stack, it tries to load it. It will fail if the stack still
  87. * cannot be found. It will also fail if a different stack is in use.
  88. */
  89. static int ocfs2_stack_driver_get(const char *stack_name)
  90. {
  91. int rc;
  92. char *plugin_name = OCFS2_STACK_PLUGIN_O2CB;
  93. /*
  94. * Classic stack does not pass in a stack name. This is
  95. * compatible with older tools as well.
  96. */
  97. if (!stack_name || !*stack_name)
  98. stack_name = OCFS2_STACK_PLUGIN_O2CB;
  99. if (strlen(stack_name) != OCFS2_STACK_LABEL_LEN) {
  100. printk(KERN_ERR
  101. "ocfs2 passed an invalid cluster stack label: \"%s\"\n",
  102. stack_name);
  103. return -EINVAL;
  104. }
  105. /* Anything that isn't the classic stack is a user stack */
  106. if (strcmp(stack_name, OCFS2_STACK_PLUGIN_O2CB))
  107. plugin_name = OCFS2_STACK_PLUGIN_USER;
  108. rc = ocfs2_stack_driver_request(stack_name, plugin_name);
  109. if (rc == -ENOENT) {
  110. request_module("ocfs2_stack_%s", plugin_name);
  111. rc = ocfs2_stack_driver_request(stack_name, plugin_name);
  112. }
  113. if (rc == -ENOENT) {
  114. printk(KERN_ERR
  115. "ocfs2: Cluster stack driver \"%s\" cannot be found\n",
  116. plugin_name);
  117. } else if (rc == -EBUSY) {
  118. printk(KERN_ERR
  119. "ocfs2: A different cluster stack is in use\n");
  120. }
  121. return rc;
  122. }
  123. static void ocfs2_stack_driver_put(void)
  124. {
  125. spin_lock(&ocfs2_stack_lock);
  126. BUG_ON(active_stack == NULL);
  127. BUG_ON(active_stack->sp_count == 0);
  128. active_stack->sp_count--;
  129. if (!active_stack->sp_count) {
  130. module_put(active_stack->sp_owner);
  131. active_stack = NULL;
  132. }
  133. spin_unlock(&ocfs2_stack_lock);
  134. }
  135. int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin)
  136. {
  137. int rc;
  138. spin_lock(&ocfs2_stack_lock);
  139. if (!ocfs2_stack_lookup(plugin->sp_name)) {
  140. plugin->sp_count = 0;
  141. plugin->sp_max_proto = locking_max_version;
  142. list_add(&plugin->sp_list, &ocfs2_stack_list);
  143. printk(KERN_INFO "ocfs2: Registered cluster interface %s\n",
  144. plugin->sp_name);
  145. rc = 0;
  146. } else {
  147. printk(KERN_ERR "ocfs2: Stack \"%s\" already registered\n",
  148. plugin->sp_name);
  149. rc = -EEXIST;
  150. }
  151. spin_unlock(&ocfs2_stack_lock);
  152. return rc;
  153. }
  154. EXPORT_SYMBOL_GPL(ocfs2_stack_glue_register);
  155. void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin)
  156. {
  157. struct ocfs2_stack_plugin *p;
  158. spin_lock(&ocfs2_stack_lock);
  159. p = ocfs2_stack_lookup(plugin->sp_name);
  160. if (p) {
  161. BUG_ON(p != plugin);
  162. BUG_ON(plugin == active_stack);
  163. BUG_ON(plugin->sp_count != 0);
  164. list_del_init(&plugin->sp_list);
  165. printk(KERN_INFO "ocfs2: Unregistered cluster interface %s\n",
  166. plugin->sp_name);
  167. } else {
  168. printk(KERN_ERR "Stack \"%s\" is not registered\n",
  169. plugin->sp_name);
  170. }
  171. spin_unlock(&ocfs2_stack_lock);
  172. }
  173. EXPORT_SYMBOL_GPL(ocfs2_stack_glue_unregister);
  174. void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto)
  175. {
  176. struct ocfs2_stack_plugin *p;
  177. spin_lock(&ocfs2_stack_lock);
  178. if (memcmp(max_proto, &locking_max_version,
  179. sizeof(struct ocfs2_protocol_version))) {
  180. BUG_ON(locking_max_version.pv_major != 0);
  181. locking_max_version = *max_proto;
  182. list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
  183. p->sp_max_proto = locking_max_version;
  184. }
  185. }
  186. spin_unlock(&ocfs2_stack_lock);
  187. }
  188. EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_max_proto_version);
  189. /*
  190. * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take no argument
  191. * for the ast and bast functions. They will pass the lksb to the ast
  192. * and bast. The caller can wrap the lksb with their own structure to
  193. * get more information.
  194. */
  195. int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
  196. int mode,
  197. struct ocfs2_dlm_lksb *lksb,
  198. u32 flags,
  199. void *name,
  200. unsigned int namelen)
  201. {
  202. if (!lksb->lksb_conn)
  203. lksb->lksb_conn = conn;
  204. else
  205. BUG_ON(lksb->lksb_conn != conn);
  206. return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags,
  207. name, namelen);
  208. }
  209. EXPORT_SYMBOL_GPL(ocfs2_dlm_lock);
  210. int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
  211. struct ocfs2_dlm_lksb *lksb,
  212. u32 flags)
  213. {
  214. BUG_ON(lksb->lksb_conn == NULL);
  215. return active_stack->sp_ops->dlm_unlock(conn, lksb, flags);
  216. }
  217. EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock);
  218. int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb)
  219. {
  220. return active_stack->sp_ops->lock_status(lksb);
  221. }
  222. EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status);
  223. int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb)
  224. {
  225. return active_stack->sp_ops->lvb_valid(lksb);
  226. }
  227. EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb_valid);
  228. void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb)
  229. {
  230. return active_stack->sp_ops->lock_lvb(lksb);
  231. }
  232. EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb);
  233. void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb)
  234. {
  235. active_stack->sp_ops->dump_lksb(lksb);
  236. }
  237. EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb);
  238. int ocfs2_stack_supports_plocks(void)
  239. {
  240. return active_stack && active_stack->sp_ops->plock;
  241. }
  242. EXPORT_SYMBOL_GPL(ocfs2_stack_supports_plocks);
  243. /*
  244. * ocfs2_plock() can only be safely called if
  245. * ocfs2_stack_supports_plocks() returned true
  246. */
  247. int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino,
  248. struct file *file, int cmd, struct file_lock *fl)
  249. {
  250. WARN_ON_ONCE(active_stack->sp_ops->plock == NULL);
  251. if (active_stack->sp_ops->plock)
  252. return active_stack->sp_ops->plock(conn, ino, file, cmd, fl);
  253. return -EOPNOTSUPP;
  254. }
  255. EXPORT_SYMBOL_GPL(ocfs2_plock);
  256. int ocfs2_cluster_connect(const char *stack_name,
  257. const char *cluster_name,
  258. int cluster_name_len,
  259. const char *group,
  260. int grouplen,
  261. struct ocfs2_locking_protocol *lproto,
  262. void (*recovery_handler)(int node_num,
  263. void *recovery_data),
  264. void *recovery_data,
  265. struct ocfs2_cluster_connection **conn)
  266. {
  267. int rc = 0;
  268. struct ocfs2_cluster_connection *new_conn;
  269. BUG_ON(group == NULL);
  270. BUG_ON(conn == NULL);
  271. BUG_ON(recovery_handler == NULL);
  272. if (grouplen > GROUP_NAME_MAX) {
  273. rc = -EINVAL;
  274. goto out;
  275. }
  276. if (memcmp(&lproto->lp_max_version, &locking_max_version,
  277. sizeof(struct ocfs2_protocol_version))) {
  278. rc = -EINVAL;
  279. goto out;
  280. }
  281. new_conn = kzalloc_obj(struct ocfs2_cluster_connection);
  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 const 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. strscpy(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. unregister_sysctl_table(ocfs2_table_header);
  576. }
  577. MODULE_AUTHOR("Oracle");
  578. MODULE_DESCRIPTION("ocfs2 cluster stack glue layer");
  579. MODULE_LICENSE("GPL");
  580. module_init(ocfs2_stack_glue_init);
  581. module_exit(ocfs2_stack_glue_exit);