stackglue.c 17 KB

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