stackglue.c 17.5 KB
Newer Older
1 2 3 4 5 6 7 8
/* -*- mode: c; c-basic-offset: 8; -*-
 * vim: noexpandtab sw=8 ts=8 sts=0:
 *
 * stackglue.c
 *
 * Code which implements an OCFS2 specific interface to underlying
 * cluster stacks.
 *
9
 * Copyright (C) 2007, 2009 Oracle.  All rights reserved.
10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

21 22 23
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/module.h>
24
#include <linux/slab.h>
25
#include <linux/kmod.h>
26 27 28
#include <linux/fs.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
29
#include <linux/sysctl.h>
30

31 32
#include "ocfs2_fs.h"

33
#include "stackglue.h"
34

35 36
#define OCFS2_STACK_PLUGIN_O2CB		"o2cb"
#define OCFS2_STACK_PLUGIN_USER		"user"
37
#define OCFS2_MAX_HB_CTL_PATH		256
38

39
static struct ocfs2_protocol_version locking_max_version;
40 41
static DEFINE_SPINLOCK(ocfs2_stack_lock);
static LIST_HEAD(ocfs2_stack_list);
42
static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1];
43
static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
44

45 46 47 48 49 50
/*
 * The stack currently in use.  If not null, active_stack->sp_count > 0,
 * the module is pinned, and the locking protocol cannot be changed.
 */
static struct ocfs2_stack_plugin *active_stack;

51 52 53 54 55 56
inline int ocfs2_is_o2cb_active(void)
{
	return !strcmp(active_stack->sp_name, OCFS2_STACK_PLUGIN_O2CB);
}
EXPORT_SYMBOL_GPL(ocfs2_is_o2cb_active);

57 58 59 60 61 62 63 64 65 66 67 68 69 70
static struct ocfs2_stack_plugin *ocfs2_stack_lookup(const char *name)
{
	struct ocfs2_stack_plugin *p;

	assert_spin_locked(&ocfs2_stack_lock);

	list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
		if (!strcmp(p->sp_name, name))
			return p;
	}

	return NULL;
}

71 72
static int ocfs2_stack_driver_request(const char *stack_name,
				      const char *plugin_name)
73 74 75 76 77 78
{
	int rc;
	struct ocfs2_stack_plugin *p;

	spin_lock(&ocfs2_stack_lock);

79 80 81 82 83 84 85 86 87
	/*
	 * If the stack passed by the filesystem isn't the selected one,
	 * we can't continue.
	 */
	if (strcmp(stack_name, cluster_stack_name)) {
		rc = -EBUSY;
		goto out;
	}

88 89 90 91 92
	if (active_stack) {
		/*
		 * If the active stack isn't the one we want, it cannot
		 * be selected right now.
		 */
93
		if (!strcmp(active_stack->sp_name, plugin_name))
94 95 96 97 98 99
			rc = 0;
		else
			rc = -EBUSY;
		goto out;
	}

100
	p = ocfs2_stack_lookup(plugin_name);
101 102 103 104 105 106 107 108 109
	if (!p || !try_module_get(p->sp_owner)) {
		rc = -ENOENT;
		goto out;
	}

	active_stack = p;
	rc = 0;

out:
110 111 112 113
	/* If we found it, pin it */
	if (!rc)
		active_stack->sp_count++;

114 115 116 117 118 119 120 121 122
	spin_unlock(&ocfs2_stack_lock);
	return rc;
}

/*
 * This function looks up the appropriate stack and makes it active.  If
 * there is no stack, it tries to load it.  It will fail if the stack still
 * cannot be found.  It will also fail if a different stack is in use.
 */
123
static int ocfs2_stack_driver_get(const char *stack_name)
124 125
{
	int rc;
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	char *plugin_name = OCFS2_STACK_PLUGIN_O2CB;

	/*
	 * Classic stack does not pass in a stack name.  This is
	 * compatible with older tools as well.
	 */
	if (!stack_name || !*stack_name)
		stack_name = OCFS2_STACK_PLUGIN_O2CB;

	if (strlen(stack_name) != OCFS2_STACK_LABEL_LEN) {
		printk(KERN_ERR
		       "ocfs2 passed an invalid cluster stack label: \"%s\"\n",
		       stack_name);
		return -EINVAL;
	}
141

142 143 144 145 146
	/* Anything that isn't the classic stack is a user stack */
	if (strcmp(stack_name, OCFS2_STACK_PLUGIN_O2CB))
		plugin_name = OCFS2_STACK_PLUGIN_USER;

	rc = ocfs2_stack_driver_request(stack_name, plugin_name);
147
	if (rc == -ENOENT) {
148 149
		request_module("ocfs2_stack_%s", plugin_name);
		rc = ocfs2_stack_driver_request(stack_name, plugin_name);
150 151 152 153 154
	}

	if (rc == -ENOENT) {
		printk(KERN_ERR
		       "ocfs2: Cluster stack driver \"%s\" cannot be found\n",
155
		       plugin_name);
156 157
	} else if (rc == -EBUSY) {
		printk(KERN_ERR
158
		       "ocfs2: A different cluster stack is in use\n");
159 160 161 162
	}

	return rc;
}
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
static void ocfs2_stack_driver_put(void)
{
	spin_lock(&ocfs2_stack_lock);
	BUG_ON(active_stack == NULL);
	BUG_ON(active_stack->sp_count == 0);

	active_stack->sp_count--;
	if (!active_stack->sp_count) {
		module_put(active_stack->sp_owner);
		active_stack = NULL;
	}
	spin_unlock(&ocfs2_stack_lock);
}

int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin)
{
	int rc;

	spin_lock(&ocfs2_stack_lock);
	if (!ocfs2_stack_lookup(plugin->sp_name)) {
		plugin->sp_count = 0;
185
		plugin->sp_max_proto = locking_max_version;
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
		list_add(&plugin->sp_list, &ocfs2_stack_list);
		printk(KERN_INFO "ocfs2: Registered cluster interface %s\n",
		       plugin->sp_name);
		rc = 0;
	} else {
		printk(KERN_ERR "ocfs2: Stack \"%s\" already registered\n",
		       plugin->sp_name);
		rc = -EEXIST;
	}
	spin_unlock(&ocfs2_stack_lock);

	return rc;
}
EXPORT_SYMBOL_GPL(ocfs2_stack_glue_register);

void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin)
{
	struct ocfs2_stack_plugin *p;

	spin_lock(&ocfs2_stack_lock);
	p = ocfs2_stack_lookup(plugin->sp_name);
	if (p) {
		BUG_ON(p != plugin);
		BUG_ON(plugin == active_stack);
		BUG_ON(plugin->sp_count != 0);
		list_del_init(&plugin->sp_list);
		printk(KERN_INFO "ocfs2: Unregistered cluster interface %s\n",
		       plugin->sp_name);
	} else {
		printk(KERN_ERR "Stack \"%s\" is not registered\n",
		       plugin->sp_name);
	}
	spin_unlock(&ocfs2_stack_lock);
}
EXPORT_SYMBOL_GPL(ocfs2_stack_glue_unregister);

222
void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto)
223 224 225 226
{
	struct ocfs2_stack_plugin *p;

	spin_lock(&ocfs2_stack_lock);
227 228 229
	if (memcmp(max_proto, &locking_max_version,
		   sizeof(struct ocfs2_protocol_version))) {
		BUG_ON(locking_max_version.pv_major != 0);
230

231 232 233 234
		locking_max_version = *max_proto;
		list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
			p->sp_max_proto = locking_max_version;
		}
235 236 237
	}
	spin_unlock(&ocfs2_stack_lock);
}
238
EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_max_proto_version);
239

240

241
/*
242 243 244 245
 * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take no argument
 * for the ast and bast functions.  They will pass the lksb to the ast
 * and bast.  The caller can wrap the lksb with their own structure to
 * get more information.
246
 */
247 248
int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
		   int mode,
249
		   struct ocfs2_dlm_lksb *lksb,
250 251
		   u32 flags,
		   void *name,
252
		   unsigned int namelen)
253
{
254 255 256 257
	if (!lksb->lksb_conn)
		lksb->lksb_conn = conn;
	else
		BUG_ON(lksb->lksb_conn != conn);
258
	return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags,
259
					      name, namelen);
260
}
261
EXPORT_SYMBOL_GPL(ocfs2_dlm_lock);
262

263
int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
264
		     struct ocfs2_dlm_lksb *lksb,
265
		     u32 flags)
266
{
267
	BUG_ON(lksb->lksb_conn == NULL);
268

269
	return active_stack->sp_ops->dlm_unlock(conn, lksb, flags);
270
}
271
EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock);
272

273
int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb)
274
{
275
	return active_stack->sp_ops->lock_status(lksb);
276
}
277
EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status);
278

279
int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb)
280 281 282 283 284
{
	return active_stack->sp_ops->lvb_valid(lksb);
}
EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb_valid);

285
void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb)
286
{
287
	return active_stack->sp_ops->lock_lvb(lksb);
288
}
289
EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb);
290

291
void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb)
292
{
293
	active_stack->sp_ops->dump_lksb(lksb);
294
}
295
EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb);
296

297 298
int ocfs2_stack_supports_plocks(void)
{
Mark Fasheh's avatar
Mark Fasheh committed
299
	return active_stack && active_stack->sp_ops->plock;
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
}
EXPORT_SYMBOL_GPL(ocfs2_stack_supports_plocks);

/*
 * ocfs2_plock() can only be safely called if
 * ocfs2_stack_supports_plocks() returned true
 */
int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino,
		struct file *file, int cmd, struct file_lock *fl)
{
	WARN_ON_ONCE(active_stack->sp_ops->plock == NULL);
	if (active_stack->sp_ops->plock)
		return active_stack->sp_ops->plock(conn, ino, file, cmd, fl);
	return -EOPNOTSUPP;
}
EXPORT_SYMBOL_GPL(ocfs2_plock);

317
int ocfs2_cluster_connect(const char *stack_name,
318 319
			  const char *cluster_name,
			  int cluster_name_len,
320
			  const char *group,
321
			  int grouplen,
322
			  struct ocfs2_locking_protocol *lproto,
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
			  void (*recovery_handler)(int node_num,
						   void *recovery_data),
			  void *recovery_data,
			  struct ocfs2_cluster_connection **conn)
{
	int rc = 0;
	struct ocfs2_cluster_connection *new_conn;

	BUG_ON(group == NULL);
	BUG_ON(conn == NULL);
	BUG_ON(recovery_handler == NULL);

	if (grouplen > GROUP_NAME_MAX) {
		rc = -EINVAL;
		goto out;
	}

340 341 342 343 344 345
	if (memcmp(&lproto->lp_max_version, &locking_max_version,
		   sizeof(struct ocfs2_protocol_version))) {
		rc = -EINVAL;
		goto out;
	}

346 347 348 349 350 351 352
	new_conn = kzalloc(sizeof(struct ocfs2_cluster_connection),
			   GFP_KERNEL);
	if (!new_conn) {
		rc = -ENOMEM;
		goto out;
	}

353
	strlcpy(new_conn->cc_name, group, GROUP_NAME_MAX + 1);
354
	new_conn->cc_namelen = grouplen;
355 356 357
	if (cluster_name_len)
		strlcpy(new_conn->cc_cluster_name, cluster_name,
			CLUSTER_NAME_MAX + 1);
358
	new_conn->cc_cluster_name_len = cluster_name_len;
359 360 361
	new_conn->cc_recovery_handler = recovery_handler;
	new_conn->cc_recovery_data = recovery_data;

362
	new_conn->cc_proto = lproto;
363
	/* Start the new connection at our maximum compatibility level */
364 365 366
	new_conn->cc_version = lproto->lp_max_version;

	/* This will pin the stack driver if successful */
367
	rc = ocfs2_stack_driver_get(stack_name);
368 369
	if (rc)
		goto out_free;
370

371
	rc = active_stack->sp_ops->connect(new_conn);
372
	if (rc) {
373
		ocfs2_stack_driver_put();
374 375 376 377 378 379
		goto out_free;
	}

	*conn = new_conn;

out_free:
380
	if (rc)
381 382 383 384 385
		kfree(new_conn);

out:
	return rc;
}
386
EXPORT_SYMBOL_GPL(ocfs2_cluster_connect);
387

388 389 390 391 392 393 394 395 396 397 398 399 400
/* The caller will ensure all nodes have the same cluster stack */
int ocfs2_cluster_connect_agnostic(const char *group,
				   int grouplen,
				   struct ocfs2_locking_protocol *lproto,
				   void (*recovery_handler)(int node_num,
							    void *recovery_data),
				   void *recovery_data,
				   struct ocfs2_cluster_connection **conn)
{
	char *stack_name = NULL;

	if (cluster_stack_name[0])
		stack_name = cluster_stack_name;
401 402 403
	return ocfs2_cluster_connect(stack_name, NULL, 0, group, grouplen,
				     lproto, recovery_handler, recovery_data,
				     conn);
404 405 406
}
EXPORT_SYMBOL_GPL(ocfs2_cluster_connect_agnostic);

407 408 409
/* If hangup_pending is 0, the stack driver will be dropped */
int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn,
			     int hangup_pending)
410 411 412 413 414
{
	int ret;

	BUG_ON(conn == NULL);

415
	ret = active_stack->sp_ops->disconnect(conn);
416 417

	/* XXX Should we free it anyway? */
418
	if (!ret) {
419
		kfree(conn);
420 421 422
		if (!hangup_pending)
			ocfs2_stack_driver_put();
	}
423 424 425

	return ret;
}
426
EXPORT_SYMBOL_GPL(ocfs2_cluster_disconnect);
427

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
/*
 * Leave the group for this filesystem.  This is executed by a userspace
 * program (stored in ocfs2_hb_ctl_path).
 */
static void ocfs2_leave_group(const char *group)
{
	int ret;
	char *argv[5], *envp[3];

	argv[0] = ocfs2_hb_ctl_path;
	argv[1] = "-K";
	argv[2] = "-u";
	argv[3] = (char *)group;
	argv[4] = NULL;

	/* minimal command environment taken from cpu_run_sbin_hotplug */
	envp[0] = "HOME=/";
	envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
	envp[2] = NULL;

	ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
	if (ret < 0) {
		printk(KERN_ERR
		       "ocfs2: Error %d running user helper "
		       "\"%s %s %s %s\"\n",
		       ret, argv[0], argv[1], argv[2], argv[3]);
	}
}

/*
 * Hangup is a required post-umount.  ocfs2-tools software expects the
 * filesystem to call "ocfs2_hb_ctl" during unmount.  This happens
 * regardless of whether the DLM got started, so we can't do it
 * in ocfs2_cluster_disconnect().  The ocfs2_leave_group() function does
 * the actual work.
 */
464 465 466 467 468
void ocfs2_cluster_hangup(const char *group, int grouplen)
{
	BUG_ON(group == NULL);
	BUG_ON(group[grouplen] != '\0');

469 470
	ocfs2_leave_group(group);

471 472
	/* cluster_disconnect() was called with hangup_pending==1 */
	ocfs2_stack_driver_put();
473
}
474
EXPORT_SYMBOL_GPL(ocfs2_cluster_hangup);
475

476 477
int ocfs2_cluster_this_node(struct ocfs2_cluster_connection *conn,
			    unsigned int *node)
478
{
479
	return active_stack->sp_ops->this_node(conn, node);
480
}
481
EXPORT_SYMBOL_GPL(ocfs2_cluster_this_node);
482

483

484 485 486 487 488 489 490 491 492 493 494
/*
 * Sysfs bits
 */

static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj,
					       struct kobj_attribute *attr,
					       char *buf)
{
	ssize_t ret = 0;

	spin_lock(&ocfs2_stack_lock);
495
	if (locking_max_version.pv_major)
496
		ret = snprintf(buf, PAGE_SIZE, "%u.%u\n",
497 498
			       locking_max_version.pv_major,
			       locking_max_version.pv_minor);
499 500 501 502 503 504
	spin_unlock(&ocfs2_stack_lock);

	return ret;
}

static struct kobj_attribute ocfs2_attr_max_locking_protocol =
505
	__ATTR(max_locking_protocol, S_IRUGO,
506 507 508 509 510
	       ocfs2_max_locking_protocol_show, NULL);

static ssize_t ocfs2_loaded_cluster_plugins_show(struct kobject *kobj,
						 struct kobj_attribute *attr,
						 char *buf)
511
{
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
	ssize_t ret = 0, total = 0, remain = PAGE_SIZE;
	struct ocfs2_stack_plugin *p;

	spin_lock(&ocfs2_stack_lock);
	list_for_each_entry(p, &ocfs2_stack_list, sp_list) {
		ret = snprintf(buf, remain, "%s\n",
			       p->sp_name);
		if (ret < 0) {
			total = ret;
			break;
		}
		if (ret == remain) {
			/* snprintf() didn't fit */
			total = -E2BIG;
			break;
		}
		total += ret;
		remain -= ret;
	}
	spin_unlock(&ocfs2_stack_lock);

	return total;
}

static struct kobj_attribute ocfs2_attr_loaded_cluster_plugins =
537
	__ATTR(loaded_cluster_plugins, S_IRUGO,
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
	       ocfs2_loaded_cluster_plugins_show, NULL);

static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj,
						struct kobj_attribute *attr,
						char *buf)
{
	ssize_t ret = 0;

	spin_lock(&ocfs2_stack_lock);
	if (active_stack) {
		ret = snprintf(buf, PAGE_SIZE, "%s\n",
			       active_stack->sp_name);
		if (ret == PAGE_SIZE)
			ret = -E2BIG;
	}
	spin_unlock(&ocfs2_stack_lock);

	return ret;
}

static struct kobj_attribute ocfs2_attr_active_cluster_plugin =
559
	__ATTR(active_cluster_plugin, S_IRUGO,
560 561
	       ocfs2_active_cluster_plugin_show, NULL);

562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
static ssize_t ocfs2_cluster_stack_show(struct kobject *kobj,
					struct kobj_attribute *attr,
					char *buf)
{
	ssize_t ret;
	spin_lock(&ocfs2_stack_lock);
	ret = snprintf(buf, PAGE_SIZE, "%s\n", cluster_stack_name);
	spin_unlock(&ocfs2_stack_lock);

	return ret;
}

static ssize_t ocfs2_cluster_stack_store(struct kobject *kobj,
					 struct kobj_attribute *attr,
					 const char *buf, size_t count)
{
	size_t len = count;
	ssize_t ret;

	if (len == 0)
		return len;

	if (buf[len - 1] == '\n')
		len--;

	if ((len != OCFS2_STACK_LABEL_LEN) ||
	    (strnlen(buf, len) != len))
		return -EINVAL;

	spin_lock(&ocfs2_stack_lock);
	if (active_stack) {
		if (!strncmp(buf, cluster_stack_name, len))
			ret = count;
		else
			ret = -EBUSY;
	} else {
		memcpy(cluster_stack_name, buf, len);
		ret = count;
	}
	spin_unlock(&ocfs2_stack_lock);

	return ret;
}


static struct kobj_attribute ocfs2_attr_cluster_stack =
608
	__ATTR(cluster_stack, S_IRUGO | S_IWUSR,
609 610 611
	       ocfs2_cluster_stack_show,
	       ocfs2_cluster_stack_store);

612 613 614 615 616 617 618 619 620 621 622 623 624


static ssize_t ocfs2_dlm_recover_show(struct kobject *kobj,
					struct kobj_attribute *attr,
					char *buf)
{
	return snprintf(buf, PAGE_SIZE, "1\n");
}

static struct kobj_attribute ocfs2_attr_dlm_recover_support =
	__ATTR(dlm_recover_callback_support, S_IRUGO,
	       ocfs2_dlm_recover_show, NULL);

625 626 627 628
static struct attribute *ocfs2_attrs[] = {
	&ocfs2_attr_max_locking_protocol.attr,
	&ocfs2_attr_loaded_cluster_plugins.attr,
	&ocfs2_attr_active_cluster_plugin.attr,
629
	&ocfs2_attr_cluster_stack.attr,
630
	&ocfs2_attr_dlm_recover_support.attr,
631 632 633
	NULL,
};

634
static const struct attribute_group ocfs2_attr_group = {
635 636 637
	.attrs = ocfs2_attrs,
};

638 639
struct kset *ocfs2_kset;
EXPORT_SYMBOL_GPL(ocfs2_kset);
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657

static void ocfs2_sysfs_exit(void)
{
	kset_unregister(ocfs2_kset);
}

static int ocfs2_sysfs_init(void)
{
	int ret;

	ocfs2_kset = kset_create_and_add("ocfs2", NULL, fs_kobj);
	if (!ocfs2_kset)
		return -ENOMEM;

	ret = sysfs_create_group(&ocfs2_kset->kobj, &ocfs2_attr_group);
	if (ret)
		goto error;

658
	return 0;
659 660 661 662 663 664

error:
	kset_unregister(ocfs2_kset);
	return ret;
}

665 666 667 668 669 670 671 672 673 674
/*
 * Sysctl bits
 *
 * The sysctl lives at /proc/sys/fs/ocfs2/nm/hb_ctl_path.  The 'nm' doesn't
 * make as much sense in a multiple cluster stack world, but it's safer
 * and easier to preserve the name.
 */

#define FS_OCFS2_NM		1

675
static struct ctl_table ocfs2_nm_table[] = {
676 677 678 679 680
	{
		.procname	= "hb_ctl_path",
		.data		= ocfs2_hb_ctl_path,
		.maxlen		= OCFS2_MAX_HB_CTL_PATH,
		.mode		= 0644,
681
		.proc_handler	= proc_dostring,
682
	},
683
	{ }
684 685
};

686
static struct ctl_table ocfs2_mod_table[] = {
687 688 689 690 691 692 693
	{
		.procname	= "nm",
		.data		= NULL,
		.maxlen		= 0,
		.mode		= 0555,
		.child		= ocfs2_nm_table
	},
694
	{ }
695 696
};

697
static struct ctl_table ocfs2_kern_table[] = {
698 699 700 701 702 703 704
	{
		.procname	= "ocfs2",
		.data		= NULL,
		.maxlen		= 0,
		.mode		= 0555,
		.child		= ocfs2_mod_table
	},
705
	{ }
706 707
};

708
static struct ctl_table ocfs2_root_table[] = {
709 710 711 712 713 714 715
	{
		.procname	= "fs",
		.data		= NULL,
		.maxlen		= 0,
		.mode		= 0555,
		.child		= ocfs2_kern_table
	},
716
	{ }
717 718
};

719
static struct ctl_table_header *ocfs2_table_header;
720 721 722 723 724 725


/*
 * Initialization
 */

726 727
static int __init ocfs2_stack_glue_init(void)
{
728 729
	strcpy(cluster_stack_name, OCFS2_STACK_PLUGIN_O2CB);

730 731 732 733 734 735 736
	ocfs2_table_header = register_sysctl_table(ocfs2_root_table);
	if (!ocfs2_table_header) {
		printk(KERN_ERR
		       "ocfs2 stack glue: unable to register sysctl\n");
		return -ENOMEM; /* or something. */
	}

737
	return ocfs2_sysfs_init();
738
}
739

740 741
static void __exit ocfs2_stack_glue_exit(void)
{
742 743
	memset(&locking_max_version, 0,
	       sizeof(struct ocfs2_protocol_version));
744
	ocfs2_sysfs_exit();
745 746
	if (ocfs2_table_header)
		unregister_sysctl_table(ocfs2_table_header);
747 748
}

749 750 751 752 753
MODULE_AUTHOR("Oracle");
MODULE_DESCRIPTION("ocfs2 cluter stack glue layer");
MODULE_LICENSE("GPL");
module_init(ocfs2_stack_glue_init);
module_exit(ocfs2_stack_glue_exit);