stackglue.c 18 KB

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