blob: fb9b8e0db2602a73438f843d1628860e75e5ef28 [file] [log] [blame]
Joel Becker24ef1812008-01-29 17:37:32 -08001/* -*- 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 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
Joel Becker286eaa92008-02-01 15:03:57 -080021#include <linux/list.h>
22#include <linux/spinlock.h>
23#include <linux/module.h>
Joel Becker4670c462008-02-01 14:39:35 -080024#include <linux/slab.h>
Joel Becker6953b4c2008-01-29 16:59:56 -080025#include <linux/kmod.h>
Joel Becker74ae4e12008-01-31 23:56:17 -080026#include <linux/fs.h>
27#include <linux/kobject.h>
28#include <linux/sysfs.h>
Joel Becker3878f112008-05-30 15:30:49 -070029#include <linux/sysctl.h>
Joel Becker4670c462008-02-01 14:39:35 -080030
Joel Becker9c6c8772008-02-01 15:17:30 -080031#include "ocfs2_fs.h"
32
Joel Becker24ef1812008-01-29 17:37:32 -080033#include "stackglue.h"
34
Joel Becker9c6c8772008-02-01 15:17:30 -080035#define OCFS2_STACK_PLUGIN_O2CB "o2cb"
36#define OCFS2_STACK_PLUGIN_USER "user"
37
Joel Becker286eaa92008-02-01 15:03:57 -080038static struct ocfs2_locking_protocol *lproto;
39static DEFINE_SPINLOCK(ocfs2_stack_lock);
40static LIST_HEAD(ocfs2_stack_list);
Joel Becker9c6c8772008-02-01 15:17:30 -080041static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1];
Joel Becker286eaa92008-02-01 15:03:57 -080042
43/*
44 * The stack currently in use. If not null, active_stack->sp_count > 0,
45 * the module is pinned, and the locking protocol cannot be changed.
46 */
47static struct ocfs2_stack_plugin *active_stack;
48
49static struct ocfs2_stack_plugin *ocfs2_stack_lookup(const char *name)
50{
51 struct ocfs2_stack_plugin *p;
52
53 assert_spin_locked(&ocfs2_stack_lock);
54
55 list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
56 if (!strcmp(p->sp_name, name))
57 return p;
58 }
59
60 return NULL;
61}
62
Joel Becker9c6c8772008-02-01 15:17:30 -080063static int ocfs2_stack_driver_request(const char *stack_name,
64 const char *plugin_name)
Joel Becker286eaa92008-02-01 15:03:57 -080065{
66 int rc;
67 struct ocfs2_stack_plugin *p;
68
69 spin_lock(&ocfs2_stack_lock);
70
Joel Becker9c6c8772008-02-01 15:17:30 -080071 /*
72 * If the stack passed by the filesystem isn't the selected one,
73 * we can't continue.
74 */
75 if (strcmp(stack_name, cluster_stack_name)) {
76 rc = -EBUSY;
77 goto out;
78 }
79
Joel Becker286eaa92008-02-01 15:03:57 -080080 if (active_stack) {
81 /*
82 * If the active stack isn't the one we want, it cannot
83 * be selected right now.
84 */
Joel Becker9c6c8772008-02-01 15:17:30 -080085 if (!strcmp(active_stack->sp_name, plugin_name))
Joel Becker286eaa92008-02-01 15:03:57 -080086 rc = 0;
87 else
88 rc = -EBUSY;
89 goto out;
90 }
91
Joel Becker9c6c8772008-02-01 15:17:30 -080092 p = ocfs2_stack_lookup(plugin_name);
Joel Becker286eaa92008-02-01 15:03:57 -080093 if (!p || !try_module_get(p->sp_owner)) {
94 rc = -ENOENT;
95 goto out;
96 }
97
98 /* Ok, the stack is pinned */
99 p->sp_count++;
100 active_stack = p;
101
102 rc = 0;
103
104out:
105 spin_unlock(&ocfs2_stack_lock);
106 return rc;
107}
108
109/*
110 * This function looks up the appropriate stack and makes it active. If
111 * there is no stack, it tries to load it. It will fail if the stack still
112 * cannot be found. It will also fail if a different stack is in use.
113 */
Joel Becker9c6c8772008-02-01 15:17:30 -0800114static int ocfs2_stack_driver_get(const char *stack_name)
Joel Becker286eaa92008-02-01 15:03:57 -0800115{
116 int rc;
Joel Becker9c6c8772008-02-01 15:17:30 -0800117 char *plugin_name = OCFS2_STACK_PLUGIN_O2CB;
Joel Becker286eaa92008-02-01 15:03:57 -0800118
Joel Becker9c6c8772008-02-01 15:17:30 -0800119 /*
120 * Classic stack does not pass in a stack name. This is
121 * compatible with older tools as well.
122 */
123 if (!stack_name || !*stack_name)
124 stack_name = OCFS2_STACK_PLUGIN_O2CB;
125
126 if (strlen(stack_name) != OCFS2_STACK_LABEL_LEN) {
127 printk(KERN_ERR
128 "ocfs2 passed an invalid cluster stack label: \"%s\"\n",
129 stack_name);
130 return -EINVAL;
131 }
132
133 /* Anything that isn't the classic stack is a user stack */
134 if (strcmp(stack_name, OCFS2_STACK_PLUGIN_O2CB))
135 plugin_name = OCFS2_STACK_PLUGIN_USER;
136
137 rc = ocfs2_stack_driver_request(stack_name, plugin_name);
Joel Becker286eaa92008-02-01 15:03:57 -0800138 if (rc == -ENOENT) {
Joel Becker9c6c8772008-02-01 15:17:30 -0800139 request_module("ocfs2_stack_%s", plugin_name);
140 rc = ocfs2_stack_driver_request(stack_name, plugin_name);
Joel Becker286eaa92008-02-01 15:03:57 -0800141 }
142
143 if (rc == -ENOENT) {
144 printk(KERN_ERR
145 "ocfs2: Cluster stack driver \"%s\" cannot be found\n",
Joel Becker9c6c8772008-02-01 15:17:30 -0800146 plugin_name);
Joel Becker286eaa92008-02-01 15:03:57 -0800147 } else if (rc == -EBUSY) {
148 printk(KERN_ERR
Joel Becker9c6c8772008-02-01 15:17:30 -0800149 "ocfs2: A different cluster stack is in use\n");
Joel Becker286eaa92008-02-01 15:03:57 -0800150 }
151
152 return rc;
153}
154
155static void ocfs2_stack_driver_put(void)
156{
157 spin_lock(&ocfs2_stack_lock);
158 BUG_ON(active_stack == NULL);
159 BUG_ON(active_stack->sp_count == 0);
160
161 active_stack->sp_count--;
162 if (!active_stack->sp_count) {
163 module_put(active_stack->sp_owner);
164 active_stack = NULL;
165 }
166 spin_unlock(&ocfs2_stack_lock);
167}
168
169int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin)
170{
171 int rc;
172
173 spin_lock(&ocfs2_stack_lock);
174 if (!ocfs2_stack_lookup(plugin->sp_name)) {
175 plugin->sp_count = 0;
176 plugin->sp_proto = lproto;
177 list_add(&plugin->sp_list, &ocfs2_stack_list);
178 printk(KERN_INFO "ocfs2: Registered cluster interface %s\n",
179 plugin->sp_name);
180 rc = 0;
181 } else {
182 printk(KERN_ERR "ocfs2: Stack \"%s\" already registered\n",
183 plugin->sp_name);
184 rc = -EEXIST;
185 }
186 spin_unlock(&ocfs2_stack_lock);
187
188 return rc;
189}
190EXPORT_SYMBOL_GPL(ocfs2_stack_glue_register);
191
192void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin)
193{
194 struct ocfs2_stack_plugin *p;
195
196 spin_lock(&ocfs2_stack_lock);
197 p = ocfs2_stack_lookup(plugin->sp_name);
198 if (p) {
199 BUG_ON(p != plugin);
200 BUG_ON(plugin == active_stack);
201 BUG_ON(plugin->sp_count != 0);
202 list_del_init(&plugin->sp_list);
203 printk(KERN_INFO "ocfs2: Unregistered cluster interface %s\n",
204 plugin->sp_name);
205 } else {
206 printk(KERN_ERR "Stack \"%s\" is not registered\n",
207 plugin->sp_name);
208 }
209 spin_unlock(&ocfs2_stack_lock);
210}
211EXPORT_SYMBOL_GPL(ocfs2_stack_glue_unregister);
212
213void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto)
214{
215 struct ocfs2_stack_plugin *p;
216
217 BUG_ON(proto == NULL);
218
219 spin_lock(&ocfs2_stack_lock);
220 BUG_ON(active_stack != NULL);
221
222 lproto = proto;
223 list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
224 p->sp_proto = lproto;
225 }
226
227 spin_unlock(&ocfs2_stack_lock);
228}
229EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_locking_protocol);
Joel Becker24ef1812008-01-29 17:37:32 -0800230
Joel Becker24ef1812008-01-29 17:37:32 -0800231
David Teiglandcf4d8d72008-02-20 14:29:27 -0800232/*
233 * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take
234 * "struct ocfs2_lock_res *astarg" instead of "void *astarg" because the
235 * underlying stack plugins need to pilfer the lksb off of the lock_res.
236 * If some other structure needs to be passed as an astarg, the plugins
237 * will need to be given a different avenue to the lksb.
238 */
Joel Becker553aa7e2008-02-01 14:51:03 -0800239int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
240 int mode,
241 union ocfs2_dlm_lksb *lksb,
242 u32 flags,
243 void *name,
244 unsigned int namelen,
David Teiglandcf4d8d72008-02-20 14:29:27 -0800245 struct ocfs2_lock_res *astarg)
Joel Becker553aa7e2008-02-01 14:51:03 -0800246{
Joel Becker286eaa92008-02-01 15:03:57 -0800247 BUG_ON(lproto == NULL);
Joel Becker553aa7e2008-02-01 14:51:03 -0800248
Joel Becker286eaa92008-02-01 15:03:57 -0800249 return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags,
250 name, namelen, astarg);
Joel Becker24ef1812008-01-29 17:37:32 -0800251}
Joel Becker286eaa92008-02-01 15:03:57 -0800252EXPORT_SYMBOL_GPL(ocfs2_dlm_lock);
Joel Becker24ef1812008-01-29 17:37:32 -0800253
Joel Becker553aa7e2008-02-01 14:51:03 -0800254int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
255 union ocfs2_dlm_lksb *lksb,
256 u32 flags,
David Teiglandcf4d8d72008-02-20 14:29:27 -0800257 struct ocfs2_lock_res *astarg)
Joel Becker553aa7e2008-02-01 14:51:03 -0800258{
Joel Becker286eaa92008-02-01 15:03:57 -0800259 BUG_ON(lproto == NULL);
Joel Becker553aa7e2008-02-01 14:51:03 -0800260
Joel Becker286eaa92008-02-01 15:03:57 -0800261 return active_stack->sp_ops->dlm_unlock(conn, lksb, flags, astarg);
Joel Becker8f2c9c12008-02-01 12:16:57 -0800262}
Joel Becker286eaa92008-02-01 15:03:57 -0800263EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock);
Joel Becker8f2c9c12008-02-01 12:16:57 -0800264
Joel Becker553aa7e2008-02-01 14:51:03 -0800265int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb)
266{
Joel Becker286eaa92008-02-01 15:03:57 -0800267 return active_stack->sp_ops->lock_status(lksb);
Joel Becker553aa7e2008-02-01 14:51:03 -0800268}
Joel Becker286eaa92008-02-01 15:03:57 -0800269EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status);
Joel Becker553aa7e2008-02-01 14:51:03 -0800270
Joel Becker8f2c9c12008-02-01 12:16:57 -0800271/*
272 * Why don't we cast to ocfs2_meta_lvb? The "clean" answer is that we
273 * don't cast at the glue level. The real answer is that the header
274 * ordering is nigh impossible.
275 */
Joel Becker553aa7e2008-02-01 14:51:03 -0800276void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb)
277{
Joel Becker286eaa92008-02-01 15:03:57 -0800278 return active_stack->sp_ops->lock_lvb(lksb);
Joel Beckercf0acdc2008-01-29 16:59:55 -0800279}
Joel Becker286eaa92008-02-01 15:03:57 -0800280EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb);
Joel Beckercf0acdc2008-01-29 16:59:55 -0800281
Joel Becker553aa7e2008-02-01 14:51:03 -0800282void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb)
283{
Joel Becker286eaa92008-02-01 15:03:57 -0800284 active_stack->sp_ops->dump_lksb(lksb);
Joel Becker553aa7e2008-02-01 14:51:03 -0800285}
Joel Becker286eaa92008-02-01 15:03:57 -0800286EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb);
Joel Becker553aa7e2008-02-01 14:51:03 -0800287
Joel Becker9c6c8772008-02-01 15:17:30 -0800288int ocfs2_cluster_connect(const char *stack_name,
289 const char *group,
Joel Becker4670c462008-02-01 14:39:35 -0800290 int grouplen,
291 void (*recovery_handler)(int node_num,
292 void *recovery_data),
293 void *recovery_data,
294 struct ocfs2_cluster_connection **conn)
295{
296 int rc = 0;
297 struct ocfs2_cluster_connection *new_conn;
Joel Becker4670c462008-02-01 14:39:35 -0800298
299 BUG_ON(group == NULL);
300 BUG_ON(conn == NULL);
301 BUG_ON(recovery_handler == NULL);
302
303 if (grouplen > GROUP_NAME_MAX) {
304 rc = -EINVAL;
305 goto out;
306 }
307
308 new_conn = kzalloc(sizeof(struct ocfs2_cluster_connection),
309 GFP_KERNEL);
310 if (!new_conn) {
311 rc = -ENOMEM;
312 goto out;
313 }
314
315 memcpy(new_conn->cc_name, group, grouplen);
316 new_conn->cc_namelen = grouplen;
317 new_conn->cc_recovery_handler = recovery_handler;
318 new_conn->cc_recovery_data = recovery_data;
319
320 /* Start the new connection at our maximum compatibility level */
Joel Becker286eaa92008-02-01 15:03:57 -0800321 new_conn->cc_version = lproto->lp_max_version;
Joel Becker4670c462008-02-01 14:39:35 -0800322
Joel Becker286eaa92008-02-01 15:03:57 -0800323 /* This will pin the stack driver if successful */
Joel Becker9c6c8772008-02-01 15:17:30 -0800324 rc = ocfs2_stack_driver_get(stack_name);
Joel Becker286eaa92008-02-01 15:03:57 -0800325 if (rc)
326 goto out_free;
327
328 rc = active_stack->sp_ops->connect(new_conn);
Joel Becker553aa7e2008-02-01 14:51:03 -0800329 if (rc) {
Joel Becker286eaa92008-02-01 15:03:57 -0800330 ocfs2_stack_driver_put();
Joel Becker4670c462008-02-01 14:39:35 -0800331 goto out_free;
332 }
333
Joel Becker4670c462008-02-01 14:39:35 -0800334 *conn = new_conn;
335
336out_free:
Joel Becker553aa7e2008-02-01 14:51:03 -0800337 if (rc)
Joel Becker4670c462008-02-01 14:39:35 -0800338 kfree(new_conn);
Joel Becker4670c462008-02-01 14:39:35 -0800339
340out:
341 return rc;
342}
Joel Becker286eaa92008-02-01 15:03:57 -0800343EXPORT_SYMBOL_GPL(ocfs2_cluster_connect);
Joel Becker4670c462008-02-01 14:39:35 -0800344
Joel Becker286eaa92008-02-01 15:03:57 -0800345/* If hangup_pending is 0, the stack driver will be dropped */
346int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn,
347 int hangup_pending)
Joel Becker553aa7e2008-02-01 14:51:03 -0800348{
349 int ret;
350
351 BUG_ON(conn == NULL);
352
Joel Becker286eaa92008-02-01 15:03:57 -0800353 ret = active_stack->sp_ops->disconnect(conn, hangup_pending);
Joel Becker553aa7e2008-02-01 14:51:03 -0800354
355 /* XXX Should we free it anyway? */
Joel Becker286eaa92008-02-01 15:03:57 -0800356 if (!ret) {
Joel Becker553aa7e2008-02-01 14:51:03 -0800357 kfree(conn);
Joel Becker286eaa92008-02-01 15:03:57 -0800358 if (!hangup_pending)
359 ocfs2_stack_driver_put();
360 }
Joel Becker553aa7e2008-02-01 14:51:03 -0800361
362 return ret;
363}
Joel Becker286eaa92008-02-01 15:03:57 -0800364EXPORT_SYMBOL_GPL(ocfs2_cluster_disconnect);
Joel Becker553aa7e2008-02-01 14:51:03 -0800365
Joel Becker6953b4c2008-01-29 16:59:56 -0800366void ocfs2_cluster_hangup(const char *group, int grouplen)
367{
368 BUG_ON(group == NULL);
369 BUG_ON(group[grouplen] != '\0');
370
David Teiglandcf4d8d72008-02-20 14:29:27 -0800371 if (active_stack->sp_ops->hangup)
372 active_stack->sp_ops->hangup(group, grouplen);
Joel Becker286eaa92008-02-01 15:03:57 -0800373
374 /* cluster_disconnect() was called with hangup_pending==1 */
375 ocfs2_stack_driver_put();
Joel Becker19fdb622008-01-30 15:38:24 -0800376}
Joel Becker286eaa92008-02-01 15:03:57 -0800377EXPORT_SYMBOL_GPL(ocfs2_cluster_hangup);
Joel Becker19fdb622008-01-30 15:38:24 -0800378
Joel Becker553aa7e2008-02-01 14:51:03 -0800379int ocfs2_cluster_this_node(unsigned int *node)
380{
Joel Becker286eaa92008-02-01 15:03:57 -0800381 return active_stack->sp_ops->this_node(node);
Joel Becker553aa7e2008-02-01 14:51:03 -0800382}
Joel Becker286eaa92008-02-01 15:03:57 -0800383EXPORT_SYMBOL_GPL(ocfs2_cluster_this_node);
Joel Becker553aa7e2008-02-01 14:51:03 -0800384
Joel Becker286eaa92008-02-01 15:03:57 -0800385
Joel Becker74ae4e12008-01-31 23:56:17 -0800386/*
387 * Sysfs bits
388 */
389
390static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj,
391 struct kobj_attribute *attr,
392 char *buf)
393{
394 ssize_t ret = 0;
395
396 spin_lock(&ocfs2_stack_lock);
397 if (lproto)
398 ret = snprintf(buf, PAGE_SIZE, "%u.%u\n",
399 lproto->lp_max_version.pv_major,
400 lproto->lp_max_version.pv_minor);
401 spin_unlock(&ocfs2_stack_lock);
402
403 return ret;
404}
405
406static struct kobj_attribute ocfs2_attr_max_locking_protocol =
407 __ATTR(max_locking_protocol, S_IFREG | S_IRUGO,
408 ocfs2_max_locking_protocol_show, NULL);
409
410static ssize_t ocfs2_loaded_cluster_plugins_show(struct kobject *kobj,
411 struct kobj_attribute *attr,
412 char *buf)
413{
414 ssize_t ret = 0, total = 0, remain = PAGE_SIZE;
415 struct ocfs2_stack_plugin *p;
416
417 spin_lock(&ocfs2_stack_lock);
418 list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
419 ret = snprintf(buf, remain, "%s\n",
420 p->sp_name);
421 if (ret < 0) {
422 total = ret;
423 break;
424 }
425 if (ret == remain) {
426 /* snprintf() didn't fit */
427 total = -E2BIG;
428 break;
429 }
430 total += ret;
431 remain -= ret;
432 }
433 spin_unlock(&ocfs2_stack_lock);
434
435 return total;
436}
437
438static struct kobj_attribute ocfs2_attr_loaded_cluster_plugins =
439 __ATTR(loaded_cluster_plugins, S_IFREG | S_IRUGO,
440 ocfs2_loaded_cluster_plugins_show, NULL);
441
442static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj,
443 struct kobj_attribute *attr,
444 char *buf)
445{
446 ssize_t ret = 0;
447
448 spin_lock(&ocfs2_stack_lock);
449 if (active_stack) {
450 ret = snprintf(buf, PAGE_SIZE, "%s\n",
451 active_stack->sp_name);
452 if (ret == PAGE_SIZE)
453 ret = -E2BIG;
454 }
455 spin_unlock(&ocfs2_stack_lock);
456
457 return ret;
458}
459
460static struct kobj_attribute ocfs2_attr_active_cluster_plugin =
461 __ATTR(active_cluster_plugin, S_IFREG | S_IRUGO,
462 ocfs2_active_cluster_plugin_show, NULL);
463
Joel Becker9c6c8772008-02-01 15:17:30 -0800464static ssize_t ocfs2_cluster_stack_show(struct kobject *kobj,
465 struct kobj_attribute *attr,
466 char *buf)
467{
468 ssize_t ret;
469 spin_lock(&ocfs2_stack_lock);
470 ret = snprintf(buf, PAGE_SIZE, "%s\n", cluster_stack_name);
471 spin_unlock(&ocfs2_stack_lock);
472
473 return ret;
474}
475
476static ssize_t ocfs2_cluster_stack_store(struct kobject *kobj,
477 struct kobj_attribute *attr,
478 const char *buf, size_t count)
479{
480 size_t len = count;
481 ssize_t ret;
482
483 if (len == 0)
484 return len;
485
486 if (buf[len - 1] == '\n')
487 len--;
488
489 if ((len != OCFS2_STACK_LABEL_LEN) ||
490 (strnlen(buf, len) != len))
491 return -EINVAL;
492
493 spin_lock(&ocfs2_stack_lock);
494 if (active_stack) {
495 if (!strncmp(buf, cluster_stack_name, len))
496 ret = count;
497 else
498 ret = -EBUSY;
499 } else {
500 memcpy(cluster_stack_name, buf, len);
501 ret = count;
502 }
503 spin_unlock(&ocfs2_stack_lock);
504
505 return ret;
506}
507
508
509static struct kobj_attribute ocfs2_attr_cluster_stack =
510 __ATTR(cluster_stack, S_IFREG | S_IRUGO | S_IWUSR,
511 ocfs2_cluster_stack_show,
512 ocfs2_cluster_stack_store);
513
Joel Becker74ae4e12008-01-31 23:56:17 -0800514static struct attribute *ocfs2_attrs[] = {
515 &ocfs2_attr_max_locking_protocol.attr,
516 &ocfs2_attr_loaded_cluster_plugins.attr,
517 &ocfs2_attr_active_cluster_plugin.attr,
Joel Becker9c6c8772008-02-01 15:17:30 -0800518 &ocfs2_attr_cluster_stack.attr,
Joel Becker74ae4e12008-01-31 23:56:17 -0800519 NULL,
520};
521
522static struct attribute_group ocfs2_attr_group = {
523 .attrs = ocfs2_attrs,
524};
525
526static struct kset *ocfs2_kset;
527
528static void ocfs2_sysfs_exit(void)
529{
530 kset_unregister(ocfs2_kset);
531}
532
533static int ocfs2_sysfs_init(void)
534{
535 int ret;
536
537 ocfs2_kset = kset_create_and_add("ocfs2", NULL, fs_kobj);
538 if (!ocfs2_kset)
539 return -ENOMEM;
540
541 ret = sysfs_create_group(&ocfs2_kset->kobj, &ocfs2_attr_group);
542 if (ret)
543 goto error;
544
545 return 0;
546
547error:
548 kset_unregister(ocfs2_kset);
549 return ret;
550}
551
Joel Becker3878f112008-05-30 15:30:49 -0700552/*
553 * Sysctl bits
554 *
555 * The sysctl lives at /proc/sys/fs/ocfs2/nm/hb_ctl_path. The 'nm' doesn't
556 * make as much sense in a multiple cluster stack world, but it's safer
557 * and easier to preserve the name.
558 */
559
560#define FS_OCFS2_NM 1
561
562#define OCFS2_MAX_HB_CTL_PATH 256
563static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
564
565static ctl_table ocfs2_nm_table[] = {
566 {
567 .ctl_name = 1,
568 .procname = "hb_ctl_path",
569 .data = ocfs2_hb_ctl_path,
570 .maxlen = OCFS2_MAX_HB_CTL_PATH,
571 .mode = 0644,
572 .proc_handler = &proc_dostring,
573 .strategy = &sysctl_string,
574 },
575 { .ctl_name = 0 }
576};
577
578static ctl_table ocfs2_mod_table[] = {
579 {
580 .ctl_name = FS_OCFS2_NM,
581 .procname = "nm",
582 .data = NULL,
583 .maxlen = 0,
584 .mode = 0555,
585 .child = ocfs2_nm_table
586 },
587 { .ctl_name = 0}
588};
589
590static ctl_table ocfs2_kern_table[] = {
591 {
592 .ctl_name = FS_OCFS2,
593 .procname = "ocfs2",
594 .data = NULL,
595 .maxlen = 0,
596 .mode = 0555,
597 .child = ocfs2_mod_table
598 },
599 { .ctl_name = 0}
600};
601
602static ctl_table ocfs2_root_table[] = {
603 {
604 .ctl_name = CTL_FS,
605 .procname = "fs",
606 .data = NULL,
607 .maxlen = 0,
608 .mode = 0555,
609 .child = ocfs2_kern_table
610 },
611 { .ctl_name = 0 }
612};
613
614static struct ctl_table_header *ocfs2_table_header = NULL;
615
616const char *ocfs2_get_hb_ctl_path(void)
617{
618 return ocfs2_hb_ctl_path;
619}
620EXPORT_SYMBOL_GPL(ocfs2_get_hb_ctl_path);
621
622
623/*
624 * Initialization
625 */
626
Joel Becker286eaa92008-02-01 15:03:57 -0800627static int __init ocfs2_stack_glue_init(void)
Joel Becker24ef1812008-01-29 17:37:32 -0800628{
Joel Becker9c6c8772008-02-01 15:17:30 -0800629 strcpy(cluster_stack_name, OCFS2_STACK_PLUGIN_O2CB);
630
Joel Becker3878f112008-05-30 15:30:49 -0700631 ocfs2_table_header = register_sysctl_table(ocfs2_root_table);
632 if (!ocfs2_table_header) {
633 printk(KERN_ERR
634 "ocfs2 stack glue: unable to register sysctl\n");
635 return -ENOMEM; /* or something. */
636 }
637
Joel Becker74ae4e12008-01-31 23:56:17 -0800638 return ocfs2_sysfs_init();
Joel Becker24ef1812008-01-29 17:37:32 -0800639}
640
Joel Becker286eaa92008-02-01 15:03:57 -0800641static void __exit ocfs2_stack_glue_exit(void)
642{
643 lproto = NULL;
Joel Becker74ae4e12008-01-31 23:56:17 -0800644 ocfs2_sysfs_exit();
Joel Becker3878f112008-05-30 15:30:49 -0700645 if (ocfs2_table_header)
646 unregister_sysctl_table(ocfs2_table_header);
Joel Becker286eaa92008-02-01 15:03:57 -0800647}
648
649MODULE_AUTHOR("Oracle");
650MODULE_DESCRIPTION("ocfs2 cluter stack glue layer");
651MODULE_LICENSE("GPL");
652module_init(ocfs2_stack_glue_init);
653module_exit(ocfs2_stack_glue_exit);