[Ocfs2-commits] mfasheh commits r2704 - in branches/ocfs2-1.2: . fs fs/debugfs fs/debugfs/include fs/debugfs/include/linux fs/ocfs2 kapi-compat/include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Nov 18 15:48:33 CST 2005


Author: mfasheh
Signed-off-by: jlbec
Signed-off-by: zab
Date: 2005-11-18 15:48:30 -0600 (Fri, 18 Nov 2005)
New Revision: 2704

Added:
   branches/ocfs2-1.2/fs/debugfs/
   branches/ocfs2-1.2/fs/debugfs/Makefile
   branches/ocfs2-1.2/fs/debugfs/debugfs_compat.c
   branches/ocfs2-1.2/fs/debugfs/debugfs_compat.h
   branches/ocfs2-1.2/fs/debugfs/file.c
   branches/ocfs2-1.2/fs/debugfs/include/
   branches/ocfs2-1.2/fs/debugfs/include/linux/
   branches/ocfs2-1.2/fs/debugfs/include/linux/debugfs.h
   branches/ocfs2-1.2/fs/debugfs/inode.c
   branches/ocfs2-1.2/kapi-compat/include/kzalloc.h
Modified:
   branches/ocfs2-1.2/Config.make.in
   branches/ocfs2-1.2/configure.in
   branches/ocfs2-1.2/fs/Makefile
   branches/ocfs2-1.2/fs/ocfs2/Makefile
   branches/ocfs2-1.2/fs/ocfs2/dlmglue.c
   branches/ocfs2-1.2/fs/ocfs2/dlmglue.h
   branches/ocfs2-1.2/fs/ocfs2/ocfs2.h
   branches/ocfs2-1.2/fs/ocfs2/super.c
Log:
* Backport svn r2701 from trunk:
 -Add per mount dlmglue lockres state tracking via debugfs

* Add a debugfs backport module for vendor kernels which don't ship
  with debugfs.

Signed-off-by: jlbec
Signed-off-by: zab



Modified: branches/ocfs2-1.2/Config.make.in
===================================================================
--- branches/ocfs2-1.2/Config.make.in	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/Config.make.in	2005-11-18 21:48:30 UTC (rev 2704)
@@ -59,6 +59,8 @@
 HAVE_GENERIC_READLINK = @HAVE_GENERIC_READLINK@
 NEW_FOLLOW_LINK_API = @NEW_FOLLOW_LINK_API@
 
+BUILD_DEBUGFS_BACKPORT = @BUILD_DEBUGFS_BACKPORT@
+
 OCFS_DEBUG = @OCFS_DEBUG@
 
 ifneq ($(OCFS_DEBUG),)

Modified: branches/ocfs2-1.2/configure.in
===================================================================
--- branches/ocfs2-1.2/configure.in	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/configure.in	2005-11-18 21:48:30 UTC (rev 2704)
@@ -212,6 +212,16 @@
 fi
 AC_SUBST(ARCH_XEN)
 
+AC_MSG_CHECKING(for debugfs)
+BUILD_DEBUGFS_BACKPORT=
+if test -f "$KERNELINC/linux/debugfs.h"; then
+  AC_MSG_RESULT(yes)
+else
+  AC_MSG_RESULT(no; your build will include a backported debugfs module)
+  BUILD_DEBUGFS_BACKPORT=yes
+fi
+AC_SUBST(BUILD_DEBUGFS_BACKPORT)
+
 OCFS2_CHECK_KERNEL(generic_drop_inode, fs.h,
   have_generic_drop_inode=yes, have_generic_drop_inode=no)
 if test "x$have_generic_drop_inode" != "xyes"; then
@@ -226,6 +236,8 @@
 
 OCFS2_KERNEL_COMPAT(assert_spin_locked, spinlock.h)
 
+OCFS2_KERNEL_COMPAT(kzalloc, slab.h)
+
 OCFS2_CHECK_KERNEL([kref_init with release callback], kref.h,
   kref_compat_header="kref_put.h", kref_compat_header="kref_init.h",
   [kref_init.*release])

Modified: branches/ocfs2-1.2/fs/Makefile
===================================================================
--- branches/ocfs2-1.2/fs/Makefile	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/Makefile	2005-11-18 21:48:30 UTC (rev 2704)
@@ -18,6 +18,10 @@
 #
 SAFE_SUBDIRS := configfs ocfs2
 
+ifdef BUILD_DEBUGFS_BACKPORT
+SAFE_SUBDIRS += debugfs
+endif
+
 ifneq ($(KERNELRELEASE),)
 #
 # Called under kbuild 2.6


Property changes on: branches/ocfs2-1.2/fs/debugfs
___________________________________________________________________
Name: svn:ignore
   + cscope*
stamp-md5
.*.sw?
.*.cmd
*.ko
debugfs.mod.c
.tmp_versions
.*.d
.*.tmp


Added: branches/ocfs2-1.2/fs/debugfs/Makefile
===================================================================
--- branches/ocfs2-1.2/fs/debugfs/Makefile	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/debugfs/Makefile	2005-11-18 21:48:30 UTC (rev 2704)
@@ -0,0 +1,59 @@
+
+ifeq ($(KERNELRELEASE),)
+TOPDIR = ../..
+
+include $(TOPDIR)/Preamble.make
+else
+# We are included by kbuild, and the is pre-"Kbuild"-files.
+
+OUR_TOPDIR	:= $(M)/..
+
+include $(OUR_TOPDIR)/Config.make
+
+CPPFLAGS := -I$(OUR_TOPDIR)/include $(CPPFLAGS)
+endif
+
+# Always set this if asked to build the backport module
+EXTRA_CFLAGS += -DCONFIG_DEBUG_FS
+EXTRA_CFLAGS += -I$(OUR_TOPDIR)/fs/debugfs/include
+
+INSTALL_MOD_DIR := fs/debugfs
+
+obj-m		:= debugfs.o
+debugfs-objs	:= inode.o file.o debugfs_compat.o
+
+ifeq ($(KERNELRELEASE),)
+#
+# Called from a regular "make".
+#
+DEBUGFS_HEADERS	=		\
+	debugfs.h		\
+	debugfs_compat.h
+
+DEBUGFS_SOURCES = 		\
+	file.c			\
+	inode.c			\
+	debugfs_compat.c
+
+DEBUGFS_OBJECTS = $(subst .c,.o,$(DEBUGFS_SOURCES))
+
+DIST_FILES = $(DEBUGFS_SOURCES) $(DEBUGFS_HEADERS)
+
+ALL_RULES = build-modules
+
+CLEAN_RULES = clean-modules
+
+INSTALL_RULES = install-modules
+
+build-modules:
+	$(MAKE) -C $(TOPDIR)/fs build-modules
+
+install-modules:
+	$(MAKE) -C $(TOPDIR)/fs install-modules
+
+clean-modules:
+	$(MAKE) -C $(TOPDIR)/fs clean-modules
+
+include $(TOPDIR)/Postamble.make
+
+endif

Added: branches/ocfs2-1.2/fs/debugfs/debugfs_compat.c
===================================================================
--- branches/ocfs2-1.2/fs/debugfs/debugfs_compat.c	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/debugfs/debugfs_compat.c	2005-11-18 21:48:30 UTC (rev 2704)
@@ -0,0 +1,152 @@
+#include <linux/module.h>
+#include <linux/pagemap.h>
+#include <linux/mount.h>
+#include <linux/vfs.h>
+#include <asm/uaccess.h>
+
+#include "debugfs_compat.h"
+
+/*
+ * "nonseekable_open is so trivial, it's not worth putting in the kapi
+ * compat stuff just for the one use in this file.
+ * This code ripped from fs/open.c in the 2.6.14 kernel
+ */
+
+/* And of course, these FMODE_* may not be defined in older
+ * kernels. */
+#ifndef FMODE_LSEEK
+#define FMODE_LSEEK	4
+#endif
+#ifndef FMODE_PREAD
+#define FMODE_PREAD	8
+#endif
+#ifndef FMODE_PWRITE
+#define FMODE_PWRITE	FMODE_PREAD	/* These go hand in hand */
+#endif
+
+/*
+ * This is used by subsystems that don't want seekable
+ * file descriptors
+ */
+static int compat_nonseekable_open(struct inode *inode, struct file *filp)
+{
+	filp->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
+	return 0;
+}
+
+/* 
+ * Ripped from fs/libfs.c in the 2.6.14 kernel.
+ */
+
+ssize_t compat_simple_read_from_buffer(void __user *to, size_t count,
+				       loff_t *ppos, const void *from,
+				       size_t available)
+{
+	loff_t pos = *ppos;
+	if (pos < 0)
+		return -EINVAL;
+	if (pos >= available)
+		return 0;
+	if (count > available - pos)
+		count = available - pos;
+	if (copy_to_user(to, from + pos, count))
+		return -EFAULT;
+	*ppos = pos + count;
+	return count;
+}
+
+/* Simple attribute files */
+
+struct simple_attr {
+	u64 (*get)(void *);
+	void (*set)(void *, u64);
+	char get_buf[24];	/* enough to store a u64 and "\n\0" */
+	char set_buf[24];
+	void *data;
+	const char *fmt;	/* format for read operation */
+	struct semaphore sem;	/* protects access to these buffers */
+};
+
+/* simple_attr_open is called by an actual attribute open file operation
+ * to set the attribute specific access operations. */
+int simple_attr_open(struct inode *inode, struct file *file,
+		     u64 (*get)(void *), void (*set)(void *, u64),
+		     const char *fmt)
+{
+	struct simple_attr *attr;
+
+	attr = kmalloc(sizeof(*attr), GFP_KERNEL);
+	if (!attr)
+		return -ENOMEM;
+
+	attr->get = get;
+	attr->set = set;
+	attr->data = inode->u.generic_ip;
+	attr->fmt = fmt;
+	init_MUTEX(&attr->sem);
+
+	file->private_data = attr;
+
+	return compat_nonseekable_open(inode, file);
+}
+
+int simple_attr_close(struct inode *inode, struct file *file)
+{
+	kfree(file->private_data);
+	return 0;
+}
+
+/* read from the buffer that is filled with the get function */
+ssize_t simple_attr_read(struct file *file, char __user *buf,
+			 size_t len, loff_t *ppos)
+{
+	struct simple_attr *attr;
+	size_t size;
+	ssize_t ret;
+
+	attr = file->private_data;
+
+	if (!attr->get)
+		return -EACCES;
+
+	down(&attr->sem);
+	if (*ppos) /* continued read */
+		size = strlen(attr->get_buf);
+	else	  /* first read */
+		size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
+				 attr->fmt,
+				 (unsigned long long)attr->get(attr->data));
+
+	ret = compat_simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
+	up(&attr->sem);
+	return ret;
+}
+
+/* interpret the buffer as a number to call the set function with */
+ssize_t simple_attr_write(struct file *file, const char __user *buf,
+			  size_t len, loff_t *ppos)
+{
+	struct simple_attr *attr;
+	u64 val;
+	size_t size;
+	ssize_t ret;
+
+	attr = file->private_data;
+
+	if (!attr->set)
+		return -EACCES;
+
+	down(&attr->sem);
+	ret = -EFAULT;
+	size = min(sizeof(attr->set_buf) - 1, len);
+	if (copy_from_user(attr->set_buf, buf, size))
+		goto out;
+
+	ret = len; /* claim we got the whole input */
+	attr->set_buf[size] = '\0';
+	val = simple_strtol(attr->set_buf, NULL, 0);
+	attr->set(attr->data, val);
+out:
+	up(&attr->sem);
+	return ret;
+}

Added: branches/ocfs2-1.2/fs/debugfs/debugfs_compat.h
===================================================================
--- branches/ocfs2-1.2/fs/debugfs/debugfs_compat.h	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/debugfs/debugfs_compat.h	2005-11-18 21:48:30 UTC (rev 2704)
@@ -0,0 +1,55 @@
+/* Ripped from include/linux/fs.h in the 2.6.14 kernel. */
+
+#ifndef _DEBUGFS_COMPAT_H
+#define _DEBUGFS_COMPAT_H
+
+/*
+ * simple attribute files
+ *
+ * These attributes behave similar to those in sysfs:
+ *
+ * Writing to an attribute immediately sets a value, an open file can be
+ * written to multiple times.
+ *
+ * Reading from an attribute creates a buffer from the value that might get
+ * read with multiple read calls. When the attribute has been read
+ * completely, no further read calls are possible until the file is opened
+ * again.
+ *
+ * All attributes contain a text representation of a numeric value
+ * that are accessed with the get() and set() functions.
+ */
+#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt)		\
+static int __fops ## _open(struct inode *inode, struct file *file)	\
+{									\
+	__simple_attr_check_format(__fmt, 0ull);			\
+	return simple_attr_open(inode, file, __get, __set, __fmt);	\
+}									\
+static struct file_operations __fops = {				\
+	.owner	 = THIS_MODULE,						\
+	.open	 = __fops ## _open,					\
+	.release = simple_attr_close,					\
+	.read	 = simple_attr_read,					\
+	.write	 = simple_attr_write,					\
+};
+
+static inline void __attribute__((format(printf, 1, 2)))
+__simple_attr_check_format(const char *fmt, ...)
+{
+	/* don't do anything, just let the compiler check the arguments; */
+}
+
+int simple_attr_open(struct inode *inode, struct file *file,
+		     u64 (*get)(void *), void (*set)(void *, u64),
+		     const char *fmt);
+int simple_attr_close(struct inode *inode, struct file *file);
+ssize_t simple_attr_read(struct file *file, char __user *buf,
+			 size_t len, loff_t *ppos);
+ssize_t simple_attr_write(struct file *file, const char __user *buf,
+			  size_t len, loff_t *ppos);
+
+ssize_t compat_simple_read_from_buffer(void __user *to, size_t count,
+				       loff_t *ppos, const void *from,
+				       size_t available);
+
+#endif /* _DEBUGFS_COMPAT_H */

Added: branches/ocfs2-1.2/fs/debugfs/file.c
===================================================================
--- branches/ocfs2-1.2/fs/debugfs/file.c	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/debugfs/file.c	2005-11-18 21:48:30 UTC (rev 2704)
@@ -0,0 +1,255 @@
+/*
+ *  file.c - part of debugfs, a tiny little debug file system
+ *
+ *  Copyright (C) 2004 Greg Kroah-Hartman <greg at kroah.com>
+ *  Copyright (C) 2004 IBM Inc.
+ *
+ *	This program is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU General Public License version
+ *	2 as published by the Free Software Foundation.
+ *
+ *  debugfs is for people to use instead of /proc or /sys.
+ *  See Documentation/DocBook/kernel-api for more details.
+ *
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/pagemap.h>
+#include <linux/debugfs.h>
+
+#include "debugfs_compat.h"
+
+static ssize_t default_read_file(struct file *file, char __user *buf,
+				 size_t count, loff_t *ppos)
+{
+	return 0;
+}
+
+static ssize_t default_write_file(struct file *file, const char __user *buf,
+				   size_t count, loff_t *ppos)
+{
+	return count;
+}
+
+static int default_open(struct inode *inode, struct file *file)
+{
+	if (inode->u.generic_ip)
+		file->private_data = inode->u.generic_ip;
+
+	return 0;
+}
+
+struct file_operations debugfs_file_operations = {
+	.read =		default_read_file,
+	.write =	default_write_file,
+	.open =		default_open,
+};
+
+static void debugfs_u8_set(void *data, u64 val)
+{
+	*(u8 *)data = val;
+}
+static u64 debugfs_u8_get(void *data)
+{
+	return *(u8 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
+
+/**
+ * debugfs_create_u8 - create a file in the debugfs filesystem that is used to read and write a unsigned 8 bit value.
+ *
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this paramater is NULL, then the
+ *          file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ *         from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value.  If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds.  This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.)  If an error occurs, NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -ENODEV will be
+ * returned.  It is not wise to check for this value, but rather, check for
+ * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_u8(const char *name, mode_t mode,
+				 struct dentry *parent, u8 *value)
+{
+	return debugfs_create_file(name, mode, parent, value, &fops_u8);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_u8);
+
+static void debugfs_u16_set(void *data, u64 val)
+{
+	*(u16 *)data = val;
+}
+static u64 debugfs_u16_get(void *data)
+{
+	return *(u16 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
+
+/**
+ * debugfs_create_u16 - create a file in the debugfs filesystem that is used to read and write a unsigned 8 bit value.
+ *
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this paramater is NULL, then the
+ *          file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ *         from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value.  If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds.  This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.)  If an error occurs, NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -ENODEV will be
+ * returned.  It is not wise to check for this value, but rather, check for
+ * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_u16(const char *name, mode_t mode,
+				  struct dentry *parent, u16 *value)
+{
+	return debugfs_create_file(name, mode, parent, value, &fops_u16);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_u16);
+
+static void debugfs_u32_set(void *data, u64 val)
+{
+	*(u32 *)data = val;
+}
+static u64 debugfs_u32_get(void *data)
+{
+	return *(u32 *)data;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
+
+/**
+ * debugfs_create_u32 - create a file in the debugfs filesystem that is used to read and write a unsigned 8 bit value.
+ *
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this paramater is NULL, then the
+ *          file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ *         from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value.  If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds.  This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.)  If an error occurs, NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -ENODEV will be
+ * returned.  It is not wise to check for this value, but rather, check for
+ * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_u32(const char *name, mode_t mode,
+				 struct dentry *parent, u32 *value)
+{
+	return debugfs_create_file(name, mode, parent, value, &fops_u32);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_u32);
+
+static ssize_t read_file_bool(struct file *file, char __user *user_buf,
+			      size_t count, loff_t *ppos)
+{
+	char buf[3];
+	u32 *val = file->private_data;
+	
+	if (*val)
+		buf[0] = 'Y';
+	else
+		buf[0] = 'N';
+	buf[1] = '\n';
+	buf[2] = 0x00;
+	return compat_simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t write_file_bool(struct file *file, const char __user *user_buf,
+			       size_t count, loff_t *ppos)
+{
+	char buf[32];
+	int buf_size;
+	u32 *val = file->private_data;
+
+	buf_size = min(count, (sizeof(buf)-1));
+	if (copy_from_user(buf, user_buf, buf_size))
+		return -EFAULT;
+
+	switch (buf[0]) {
+	case 'y':
+	case 'Y':
+	case '1':
+		*val = 1;
+		break;
+	case 'n':
+	case 'N':
+	case '0':
+		*val = 0;
+		break;
+	}
+	
+	return count;
+}
+
+static struct file_operations fops_bool = {
+	.read =		read_file_bool,
+	.write =	write_file_bool,
+	.open =		default_open,
+};
+
+/**
+ * debugfs_create_bool - create a file in the debugfs filesystem that is used to read and write a boolean value.
+ *
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this paramater is NULL, then the
+ *          file will be created in the root of the debugfs filesystem.
+ * @value: a pointer to the variable that the file should read to and write
+ *         from.
+ *
+ * This function creates a file in debugfs with the given name that
+ * contains the value of the variable @value.  If the @mode variable is so
+ * set, it can be read from, and written to.
+ *
+ * This function will return a pointer to a dentry if it succeeds.  This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.)  If an error occurs, NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -ENODEV will be
+ * returned.  It is not wise to check for this value, but rather, check for
+ * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_bool(const char *name, mode_t mode,
+				   struct dentry *parent, u32 *value)
+{
+	return debugfs_create_file(name, mode, parent, value, &fops_bool);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_bool);
+

Added: branches/ocfs2-1.2/fs/debugfs/include/linux/debugfs.h
===================================================================
--- branches/ocfs2-1.2/fs/debugfs/include/linux/debugfs.h	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/debugfs/include/linux/debugfs.h	2005-11-18 21:48:30 UTC (rev 2704)
@@ -0,0 +1,99 @@
+/*
+ *  debugfs.h - a tiny little debug file system
+ *
+ *  Copyright (C) 2004 Greg Kroah-Hartman <greg at kroah.com>
+ *  Copyright (C) 2004 IBM Inc.
+ *
+ *	This program is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU General Public License version
+ *	2 as published by the Free Software Foundation.
+ *
+ *  debugfs is for people to use instead of /proc or /sys.
+ *  See Documentation/DocBook/kernel-api for more details.
+ */
+
+#ifndef _DEBUGFS_H_
+#define _DEBUGFS_H_
+
+#include <linux/fs.h>
+
+#include <linux/types.h>
+
+struct file_operations;
+
+#if defined(CONFIG_DEBUG_FS)
+struct dentry *debugfs_create_file(const char *name, mode_t mode,
+				   struct dentry *parent, void *data,
+				   struct file_operations *fops);
+
+struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
+
+void debugfs_remove(struct dentry *dentry);
+
+struct dentry *debugfs_create_u8(const char *name, mode_t mode,
+				 struct dentry *parent, u8 *value);
+struct dentry *debugfs_create_u16(const char *name, mode_t mode,
+				  struct dentry *parent, u16 *value);
+struct dentry *debugfs_create_u32(const char *name, mode_t mode,
+				  struct dentry *parent, u32 *value);
+struct dentry *debugfs_create_bool(const char *name, mode_t mode,
+				  struct dentry *parent, u32 *value);
+
+#else
+
+#include <linux/err.h>
+
+/* 
+ * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
+ * so users have a chance to detect if there was a real error or not.  We don't
+ * want to duplicate the design decision mistakes of procfs and devfs again.
+ */
+
+static inline struct dentry *debugfs_create_file(const char *name, mode_t mode,
+						 struct dentry *parent,
+						 void *data,
+						 struct file_operations *fops)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline struct dentry *debugfs_create_dir(const char *name,
+						struct dentry *parent)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline void debugfs_remove(struct dentry *dentry)
+{ }
+
+static inline struct dentry *debugfs_create_u8(const char *name, mode_t mode,
+					       struct dentry *parent,
+					       u8 *value)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline struct dentry *debugfs_create_u16(const char *name, mode_t mode,
+						struct dentry *parent,
+						u16 *value)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline struct dentry *debugfs_create_u32(const char *name, mode_t mode,
+						struct dentry *parent,
+						u32 *value)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+static inline struct dentry *debugfs_create_bool(const char *name, mode_t mode,
+						 struct dentry *parent,
+						 u32 *value)
+{
+	return ERR_PTR(-ENODEV);
+}
+
+#endif
+
+#endif

Added: branches/ocfs2-1.2/fs/debugfs/inode.c
===================================================================
--- branches/ocfs2-1.2/fs/debugfs/inode.c	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/debugfs/inode.c	2005-11-18 21:48:30 UTC (rev 2704)
@@ -0,0 +1,308 @@
+/*
+ *  file.c - part of debugfs, a tiny little debug file system
+ *
+ *  Copyright (C) 2004 Greg Kroah-Hartman <greg at kroah.com>
+ *  Copyright (C) 2004 IBM Inc.
+ *
+ *	This program is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU General Public License version
+ *	2 as published by the Free Software Foundation.
+ *
+ *  debugfs is for people to use instead of /proc or /sys.
+ *  See Documentation/DocBook/kernel-api for more details.
+ *
+ */
+
+/* uncomment to get debug messages from the debug filesystem, ah the irony. */
+/* #define DEBUG */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/mount.h>
+#include <linux/pagemap.h>
+#include <linux/init.h>
+#include <linux/namei.h>
+#include <linux/debugfs.h>
+
+#define DEBUGFS_MAGIC	0x64626720
+
+/* declared over in file.c */
+extern struct file_operations debugfs_file_operations;
+
+static struct vfsmount *debugfs_mount;
+static int debugfs_mount_count;
+
+static struct inode *debugfs_get_inode(struct super_block *sb, int mode, dev_t dev)
+{
+	struct inode *inode = new_inode(sb);
+
+	if (inode) {
+		inode->i_mode = mode;
+		inode->i_uid = 0;
+		inode->i_gid = 0;
+		inode->i_blksize = PAGE_CACHE_SIZE;
+		inode->i_blocks = 0;
+		inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+		switch (mode & S_IFMT) {
+		default:
+			init_special_inode(inode, mode, dev);
+			break;
+		case S_IFREG:
+			inode->i_fop = &debugfs_file_operations;
+			break;
+		case S_IFDIR:
+			inode->i_op = &simple_dir_inode_operations;
+			inode->i_fop = &simple_dir_operations;
+
+			/* directory inodes start off with i_nlink == 2 (for "." entry) */
+			inode->i_nlink++;
+			break;
+		}
+	}
+	return inode; 
+}
+
+/* SMP-safe */
+static int debugfs_mknod(struct inode *dir, struct dentry *dentry,
+			 int mode, dev_t dev)
+{
+	struct inode *inode = debugfs_get_inode(dir->i_sb, mode, dev);
+	int error = -EPERM;
+
+	if (dentry->d_inode)
+		return -EEXIST;
+
+	if (inode) {
+		d_instantiate(dentry, inode);
+		dget(dentry);
+		error = 0;
+	}
+	return error;
+}
+
+static int debugfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
+{
+	int res;
+
+	mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
+	res = debugfs_mknod(dir, dentry, mode, 0);
+	if (!res)
+		dir->i_nlink++;
+	return res;
+}
+
+static int debugfs_create(struct inode *dir, struct dentry *dentry, int mode)
+{
+	mode = (mode & S_IALLUGO) | S_IFREG;
+	return debugfs_mknod(dir, dentry, mode, 0);
+}
+
+static inline int debugfs_positive(struct dentry *dentry)
+{
+	return dentry->d_inode && !d_unhashed(dentry);
+}
+
+static int debug_fill_super(struct super_block *sb, void *data, int silent)
+{
+	static struct tree_descr debug_files[] = {{""}};
+
+	return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
+}
+
+static struct super_block *debug_get_sb(struct file_system_type *fs_type,
+				        int flags, const char *dev_name,
+					void *data)
+{
+	return get_sb_single(fs_type, flags, data, debug_fill_super);
+}
+
+static struct file_system_type debug_fs_type = {
+	.owner =	THIS_MODULE,
+	.name =		"debugfs",
+	.get_sb =	debug_get_sb,
+	.kill_sb =	kill_litter_super,
+};
+
+static int debugfs_create_by_name(const char *name, mode_t mode,
+				  struct dentry *parent,
+				  struct dentry **dentry)
+{
+	int error = 0;
+
+	/* If the parent is not specified, we create it in the root.
+	 * We need the root dentry to do this, which is in the super 
+	 * block. A pointer to that is in the struct vfsmount that we
+	 * have around.
+	 */
+	if (!parent ) {
+		if (debugfs_mount && debugfs_mount->mnt_sb) {
+			parent = debugfs_mount->mnt_sb->s_root;
+		}
+	}
+	if (!parent) {
+		pr_debug("debugfs: Ah! can not find a parent!\n");
+		return -EFAULT;
+	}
+
+	*dentry = NULL;
+	down(&parent->d_inode->i_sem);
+	*dentry = lookup_one_len(name, parent, strlen(name));
+	if (!IS_ERR(dentry)) {
+		if ((mode & S_IFMT) == S_IFDIR)
+			error = debugfs_mkdir(parent->d_inode, *dentry, mode);
+		else 
+			error = debugfs_create(parent->d_inode, *dentry, mode);
+	} else
+		error = PTR_ERR(dentry);
+	up(&parent->d_inode->i_sem);
+
+	return error;
+}
+
+/**
+ * debugfs_create_file - create a file in the debugfs filesystem
+ *
+ * @name: a pointer to a string containing the name of the file to create.
+ * @mode: the permission that the file should have
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this paramater is NULL, then the
+ *          file will be created in the root of the debugfs filesystem.
+ * @data: a pointer to something that the caller will want to get to later
+ *        on.  The inode.u.generic_ip pointer will point to this value on
+ *        the open() call.
+ * @fops: a pointer to a struct file_operations that should be used for
+ *        this file.
+ *
+ * This is the basic "create a file" function for debugfs.  It allows for a
+ * wide range of flexibility in createing a file, or a directory (if you
+ * want to create a directory, the debugfs_create_dir() function is
+ * recommended to be used instead.)
+ *
+ * This function will return a pointer to a dentry if it succeeds.  This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.)  If an error occurs, NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -ENODEV will be
+ * returned.  It is not wise to check for this value, but rather, check for
+ * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_file(const char *name, mode_t mode,
+				   struct dentry *parent, void *data,
+				   struct file_operations *fops)
+{
+	struct dentry *dentry = NULL;
+	int error;
+
+	pr_debug("debugfs: creating file '%s'\n",name);
+
+	error = simple_pin_fs("debugfs", &debugfs_mount, &debugfs_mount_count);
+	if (error)
+		goto exit;
+
+	error = debugfs_create_by_name(name, mode, parent, &dentry);
+	if (error) {
+		dentry = NULL;
+		goto exit;
+	}
+
+	if (dentry->d_inode) {
+		if (data)
+			dentry->d_inode->u.generic_ip = data;
+		if (fops)
+			dentry->d_inode->i_fop = fops;
+	}
+exit:
+	return dentry;
+}
+EXPORT_SYMBOL_GPL(debugfs_create_file);
+
+/**
+ * debugfs_create_dir - create a directory in the debugfs filesystem
+ *
+ * @name: a pointer to a string containing the name of the directory to
+ *        create.
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this paramater is NULL, then the
+ *          directory will be created in the root of the debugfs filesystem.
+ *
+ * This function creates a directory in debugfs with the given name.
+ *
+ * This function will return a pointer to a dentry if it succeeds.  This
+ * pointer must be passed to the debugfs_remove() function when the file is
+ * to be removed (no automatic cleanup happens if your module is unloaded,
+ * you are responsible here.)  If an error occurs, NULL will be returned.
+ *
+ * If debugfs is not enabled in the kernel, the value -ENODEV will be
+ * returned.  It is not wise to check for this value, but rather, check for
+ * NULL or !NULL instead as to eliminate the need for #ifdef in the calling
+ * code.
+ */
+struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
+{
+	return debugfs_create_file(name, 
+				   S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
+				   parent, NULL, NULL);
+}
+EXPORT_SYMBOL_GPL(debugfs_create_dir);
+
+/**
+ * debugfs_remove - removes a file or directory from the debugfs filesystem
+ *
+ * @dentry: a pointer to a the dentry of the file or directory to be
+ *          removed.
+ *
+ * This function removes a file or directory in debugfs that was previously
+ * created with a call to another debugfs function (like
+ * debufs_create_file() or variants thereof.)
+ *
+ * This function is required to be called in order for the file to be
+ * removed, no automatic cleanup of files will happen when a module is
+ * removed, you are responsible here.
+ */
+void debugfs_remove(struct dentry *dentry)
+{
+	struct dentry *parent;
+	
+	if (!dentry)
+		return;
+
+	parent = dentry->d_parent;
+	if (!parent || !parent->d_inode)
+		return;
+
+	down(&parent->d_inode->i_sem);
+	if (debugfs_positive(dentry)) {
+		if (dentry->d_inode) {
+			if (S_ISDIR(dentry->d_inode->i_mode))
+				simple_rmdir(parent->d_inode, dentry);
+			else
+				simple_unlink(parent->d_inode, dentry);
+		dput(dentry);
+		}
+	}
+	up(&parent->d_inode->i_sem);
+	simple_release_fs(&debugfs_mount, &debugfs_mount_count);
+}
+EXPORT_SYMBOL_GPL(debugfs_remove);
+
+static int __init debugfs_init(void)
+{
+	int retval;
+
+	retval = register_filesystem(&debug_fs_type);
+	return retval;
+}
+
+static void __exit debugfs_exit(void)
+{
+	simple_release_fs(&debugfs_mount, &debugfs_mount_count);
+	unregister_filesystem(&debug_fs_type);
+}
+
+core_initcall(debugfs_init);
+module_exit(debugfs_exit);
+MODULE_LICENSE("GPL");
+

Modified: branches/ocfs2-1.2/fs/ocfs2/Makefile
===================================================================
--- branches/ocfs2-1.2/fs/ocfs2/Makefile	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/ocfs2/Makefile	2005-11-18 21:48:30 UTC (rev 2704)
@@ -30,6 +30,11 @@
 EXTRA_CFLAGS += -DNEW_FOLLOW_LINK_API
 endif
 
+ifdef BUILD_DEBUGFS_BACKPORT
+EXTRA_CFLAGS += -DCONFIG_DEBUG_FS
+EXTRA_CFLAGS += -I$(OUR_TOPDIR)/fs/debugfs/include
+endif
+
 EXTRA_CFLAGS += -DOCFS2_DELETE_INODE_WORKAROUND
 EXTRA_CFLAGS += -DOCFS2_CDSL
 

Modified: branches/ocfs2-1.2/fs/ocfs2/dlmglue.c
===================================================================
--- branches/ocfs2-1.2/fs/ocfs2/dlmglue.c	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/ocfs2/dlmglue.c	2005-11-18 21:48:30 UTC (rev 2704)
@@ -30,6 +30,8 @@
 #include <linux/smp_lock.h>
 #include <linux/crc32.h>
 #include <linux/kthread.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
 
 #include <cluster/heartbeat.h>
 #include <cluster/nodemanager.h>
@@ -217,7 +219,28 @@
 	mlog_exit_void();
 }
 
-static void ocfs2_lock_res_init_common(struct ocfs2_lock_res *res,
+static spinlock_t ocfs2_dlm_tracking_lock = SPIN_LOCK_UNLOCKED;
+
+static void ocfs2_add_lockres_tracking(struct ocfs2_lock_res *res,
+				       struct ocfs2_dlm_debug *dlm_debug)
+{
+	mlog(0, "Add tracking for lockres %s\n", res->l_name);
+
+	spin_lock(&ocfs2_dlm_tracking_lock);
+	list_add(&res->l_debug_list, &dlm_debug->d_lockres_tracking);
+	spin_unlock(&ocfs2_dlm_tracking_lock);
+}
+
+static void ocfs2_remove_lockres_tracking(struct ocfs2_lock_res *res)
+{
+	spin_lock(&ocfs2_dlm_tracking_lock);
+	if (!list_empty(&res->l_debug_list))
+		list_del_init(&res->l_debug_list);
+	spin_unlock(&ocfs2_dlm_tracking_lock);
+}
+
+static void ocfs2_lock_res_init_common(ocfs2_super *osb,
+				       struct ocfs2_lock_res *res,
 				       enum ocfs2_lock_type type,
 				       u64 blkno,
 				       u32 generation,
@@ -237,6 +260,8 @@
 	res->l_unlock_action = OCFS2_UNLOCK_INVALID;
 
 	res->l_flags         = OCFS2_LOCK_INITIALIZED;
+
+	ocfs2_add_lockres_tracking(res, osb->osb_dlm_debug);
 }
 
 void ocfs2_lock_res_init_once(struct ocfs2_lock_res *res)
@@ -263,7 +288,8 @@
 	else
 		ops = &ocfs2_inode_data_lops;
 
-	ocfs2_lock_res_init_common(res, type, OCFS2_I(inode)->ip_blkno,
+	ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), res, type,
+				   OCFS2_I(inode)->ip_blkno,
 				   inode->i_generation, ops, inode);
 }
 
@@ -273,7 +299,7 @@
 	/* Superblock lockres doesn't come from a slab so we call init
 	 * once on it manually.  */
 	ocfs2_lock_res_init_once(res);
-	ocfs2_lock_res_init_common(res, OCFS2_LOCK_TYPE_SUPER,
+	ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_SUPER,
 				   OCFS2_SUPER_BLOCK_BLKNO, 0,
 				   &ocfs2_super_lops, osb);
 }
@@ -284,7 +310,7 @@
 	/* Rename lockres doesn't come from a slab so we call init
 	 * once on it manually.  */
 	ocfs2_lock_res_init_once(res);
-	ocfs2_lock_res_init_common(res, OCFS2_LOCK_TYPE_RENAME, 0, 0,
+	ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_RENAME, 0, 0,
 				   &ocfs2_rename_lops, osb);
 }
 
@@ -295,6 +321,8 @@
 	if (!(res->l_flags & OCFS2_LOCK_INITIALIZED))
 		return;
 
+	ocfs2_remove_lockres_tracking(res);
+
 	mlog_bug_on_msg(!list_empty(&res->l_blocked_list),
 			"Lockres %s is on the blocked list\n",
 			res->l_name);
@@ -1677,6 +1705,259 @@
 	ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
 }
 
+/* Reference counting of the dlm debug structure. We want this because
+ * open references on the debug inodes can live on after a mount, so
+ * we can't rely on the ocfs2_super to always exist. */
+static void ocfs2_dlm_debug_free(struct kref *kref)
+{
+	struct ocfs2_dlm_debug *dlm_debug;
+
+	dlm_debug = container_of(kref, struct ocfs2_dlm_debug, d_refcnt);
+
+	kfree(dlm_debug);
+}
+
+void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug)
+{
+	if (dlm_debug)
+		kref_put(&dlm_debug->d_refcnt, ocfs2_dlm_debug_free);
+}
+
+static void ocfs2_get_dlm_debug(struct ocfs2_dlm_debug *debug)
+{
+	kref_get(&debug->d_refcnt);
+}
+
+struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
+{
+	struct ocfs2_dlm_debug *dlm_debug;
+
+	dlm_debug = kmalloc(sizeof(struct ocfs2_dlm_debug), GFP_KERNEL);
+	if (!dlm_debug) {
+		mlog_errno(-ENOMEM);
+		goto out;
+	}
+
+	kref_init(&dlm_debug->d_refcnt, ocfs2_dlm_debug_free);
+	INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
+	dlm_debug->d_locking_state = NULL;
+out:
+	return dlm_debug;
+}
+
+/* Access to this is arbitrated for us via seq_file->sem. */
+struct ocfs2_dlm_seq_priv {
+	struct ocfs2_dlm_debug *p_dlm_debug;
+	struct ocfs2_lock_res p_iter_res;
+	struct ocfs2_lock_res p_tmp_res;
+};
+
+static struct ocfs2_lock_res *ocfs2_dlm_next_res(struct ocfs2_lock_res *start,
+						 struct ocfs2_dlm_seq_priv *priv)
+{
+	struct ocfs2_lock_res *iter, *ret = NULL;
+	struct ocfs2_dlm_debug *dlm_debug = priv->p_dlm_debug;
+
+	assert_spin_locked(&ocfs2_dlm_tracking_lock);
+
+	list_for_each_entry(iter, &start->l_debug_list, l_debug_list) {
+		/* discover the head of the list */
+		if (&iter->l_debug_list == &dlm_debug->d_lockres_tracking) {
+			mlog(0, "End of list found, %p\n", ret);
+			break;
+		}
+
+		/* We track our "dummy" iteration lockres' by a NULL
+		 * l_ops field. */
+		if (iter->l_ops != NULL) {
+			ret = iter;
+			break;
+		}
+	}
+
+	return ret;
+}
+
+static void *ocfs2_dlm_seq_start(struct seq_file *m, loff_t *pos)
+{
+	struct ocfs2_dlm_seq_priv *priv = m->private;
+	struct ocfs2_lock_res *iter;
+
+	spin_lock(&ocfs2_dlm_tracking_lock);
+	iter = ocfs2_dlm_next_res(&priv->p_iter_res, priv);
+	if (iter) {
+		/* Since lockres' have the lifetime of their container
+		 * (which can be inodes, ocfs2_supers, etc) we want to
+		 * copy this out to a temporary lockres while still
+		 * under the spinlock. Obviously after this we can't
+		 * trust any pointers on the copy returned, but that's
+		 * ok as the information we want isn't typically held
+		 * in them. */
+		priv->p_tmp_res = *iter;
+		iter = &priv->p_tmp_res;
+	}
+	spin_unlock(&ocfs2_dlm_tracking_lock);
+
+	return iter;
+}
+
+static void ocfs2_dlm_seq_stop(struct seq_file *m, void *v)
+{
+}
+
+static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)
+{
+	struct ocfs2_dlm_seq_priv *priv = m->private;
+	struct ocfs2_lock_res *iter = v;
+	struct ocfs2_lock_res *dummy = &priv->p_iter_res;
+
+	spin_lock(&ocfs2_dlm_tracking_lock);
+	iter = ocfs2_dlm_next_res(iter, priv);
+	list_del_init(&dummy->l_debug_list);
+	if (iter) {
+		list_add(&dummy->l_debug_list, &iter->l_debug_list);
+		priv->p_tmp_res = *iter;
+		iter = &priv->p_tmp_res;
+	}
+	spin_unlock(&ocfs2_dlm_tracking_lock);
+
+	return iter;
+}
+
+/* So that debugfs.ocfs2 can determine which format is being used */
+#define OCFS2_DLM_DEBUG_STR_VERSION 1
+static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
+{
+	int i;
+	char *lvb;
+	struct ocfs2_lock_res *lockres = v;
+
+	if (!lockres)
+		return -EINVAL;
+
+	seq_printf(m, "0x%x\t"
+		   "%.*s\t"
+		   "%d\t"
+		   "0x%lx\t"
+		   "0x%x\t"
+		   "0x%x\t"
+		   "%u\t"
+		   "%u\t"
+		   "%d\t"
+		   "%d\t",
+		   OCFS2_DLM_DEBUG_STR_VERSION,
+		   OCFS2_LOCK_ID_MAX_LEN, lockres->l_name,
+		   lockres->l_level,
+		   lockres->l_flags,
+		   lockres->l_action,
+		   lockres->l_unlock_action,
+		   lockres->l_ro_holders,
+		   lockres->l_ex_holders,
+		   lockres->l_requested,
+		   lockres->l_blocking);
+
+	/* Dump the raw LVB */
+	lvb = lockres->l_lksb.lvb;
+	for(i = 0; i < DLM_LVB_LEN; i++)
+		seq_printf(m, "0x%x\t", lvb[i]);
+
+	/* End the line */
+	seq_printf(m, "\n");
+	return 0;
+}
+
+static struct seq_operations ocfs2_dlm_seq_ops = {
+	.start =	ocfs2_dlm_seq_start,
+	.stop =		ocfs2_dlm_seq_stop,
+	.next =		ocfs2_dlm_seq_next,
+	.show =		ocfs2_dlm_seq_show,
+};
+
+static int ocfs2_dlm_debug_release(struct inode *inode, struct file *file)
+{
+	struct seq_file *seq = (struct seq_file *) file->private_data;
+	struct ocfs2_dlm_seq_priv *priv = seq->private;
+	struct ocfs2_lock_res *res = &priv->p_iter_res;
+
+	ocfs2_remove_lockres_tracking(res);
+	ocfs2_put_dlm_debug(priv->p_dlm_debug);
+	return seq_release_private(inode, file);
+}
+
+static int ocfs2_dlm_debug_open(struct inode *inode, struct file *file)
+{
+	int ret;
+	struct ocfs2_dlm_seq_priv *priv;
+	struct seq_file *seq;
+	ocfs2_super *osb;
+
+	priv = kzalloc(sizeof(struct ocfs2_dlm_seq_priv), GFP_KERNEL);
+	if (!priv) {
+		ret = -ENOMEM;
+		mlog_errno(ret);
+		goto out;
+	}
+	osb = (ocfs2_super *) inode->u.generic_ip;
+	ocfs2_get_dlm_debug(osb->osb_dlm_debug);
+	priv->p_dlm_debug = osb->osb_dlm_debug;
+	INIT_LIST_HEAD(&priv->p_iter_res.l_debug_list);
+
+	ret = seq_open(file, &ocfs2_dlm_seq_ops);
+	if (ret) {
+		kfree(priv);
+		mlog_errno(ret);
+		goto out;
+	}
+
+	seq = (struct seq_file *) file->private_data;
+	seq->private = priv;
+
+	ocfs2_add_lockres_tracking(&priv->p_iter_res,
+				   priv->p_dlm_debug);
+
+out:
+	return ret;
+}
+
+static struct file_operations ocfs2_dlm_debug_fops = {
+	.open =		ocfs2_dlm_debug_open,
+	.release =	ocfs2_dlm_debug_release,
+	.read =		seq_read,
+	.llseek =	seq_lseek,
+};
+
+static int ocfs2_dlm_init_debug(ocfs2_super *osb)
+{
+	int ret = 0;
+	struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
+
+	dlm_debug->d_locking_state = debugfs_create_file("locking_state",
+							 S_IFREG|S_IRUSR,
+							 osb->osb_debug_root,
+							 osb,
+							 &ocfs2_dlm_debug_fops);
+	if (!dlm_debug->d_locking_state) {
+		ret = -EINVAL;
+		mlog(ML_ERROR,
+		     "Unable to create locking state debugfs file.\n");
+		goto out;
+	}
+
+	ocfs2_get_dlm_debug(dlm_debug);
+out:
+	return ret;
+}
+
+static void ocfs2_dlm_shutdown_debug(ocfs2_super *osb)
+{
+	struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
+
+	if (dlm_debug) {
+		debugfs_remove(dlm_debug->d_locking_state);
+		ocfs2_put_dlm_debug(dlm_debug);
+	}
+}
+
 int ocfs2_dlm_init(ocfs2_super *osb)
 {
 	int status;
@@ -1685,6 +1966,12 @@
 
 	mlog_entry_void();
 
+	status = ocfs2_dlm_init_debug(osb);
+	if (status < 0) {
+		mlog_errno(status);
+		goto bail;
+	}
+
 	/* launch vote thread */
 	osb->vote_task = kthread_run(ocfs2_vote_thread, osb, "ocfs2vote-%d",
 				     osb->osb_id);
@@ -1716,6 +2003,8 @@
 
 	status = 0;
 bail:
+	if (status < 0)
+		ocfs2_dlm_shutdown_debug(osb);
 
 	mlog_exit(status);
 	return status;
@@ -1740,6 +2029,8 @@
 	dlm_unregister_domain(osb->dlm);
 	osb->dlm = NULL;
 
+	ocfs2_dlm_shutdown_debug(osb);
+
 	mlog_exit_void();
 }
 

Modified: branches/ocfs2-1.2/fs/ocfs2/dlmglue.h
===================================================================
--- branches/ocfs2-1.2/fs/ocfs2/dlmglue.h	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/ocfs2/dlmglue.h	2005-11-18 21:48:30 UTC (rev 2704)
@@ -85,6 +85,9 @@
 void ocfs2_process_blocked_lock(ocfs2_super *osb,
 				struct ocfs2_lock_res *lockres);
 
+struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void);
+void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug);
+
 /* aids in debugging and tracking lvbs */
 void ocfs2_dump_meta_lvb_info(u64 level,
 			      const char *function,

Modified: branches/ocfs2-1.2/fs/ocfs2/ocfs2.h
===================================================================
--- branches/ocfs2-1.2/fs/ocfs2/ocfs2.h	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/ocfs2/ocfs2.h	2005-11-18 21:48:30 UTC (rev 2704)
@@ -32,6 +32,7 @@
 #include <linux/list.h>
 #include <linux/rbtree.h>
 #include <linux/workqueue.h>
+#include <linux/kref.h>
 
 #include "cluster/nodemanager.h"
 #include "cluster/heartbeat.h"
@@ -142,8 +143,16 @@
 	int                      l_blocking;
 
 	wait_queue_head_t        l_event;
+
+	struct list_head         l_debug_list;
 };
 
+struct ocfs2_dlm_debug {
+	struct kref d_refcnt;
+	struct dentry *d_locking_state;
+	struct list_head d_lockres_tracking;
+};
+
 enum ocfs2_vol_state
 {
 	VOLUME_INIT = 0,
@@ -257,7 +266,10 @@
 	struct ocfs2_lock_res osb_super_lockres;
 	struct ocfs2_lock_res osb_rename_lockres;
 	struct dlm_eviction_cb osb_eviction_cb;
+	struct ocfs2_dlm_debug *osb_dlm_debug;
 
+	struct dentry *osb_debug_root;
+
 	wait_queue_head_t recovery_event;
 
 	spinlock_t vote_task_lock;

Modified: branches/ocfs2-1.2/fs/ocfs2/super.c
===================================================================
--- branches/ocfs2-1.2/fs/ocfs2/super.c	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/fs/ocfs2/super.c	2005-11-18 21:48:30 UTC (rev 2704)
@@ -38,6 +38,7 @@
 #include <linux/inet.h>
 #include <linux/parser.h>
 #include <linux/crc32.h>
+#include <linux/debugfs.h>
 
 #include <cluster/nodemanager.h>
 
@@ -86,6 +87,8 @@
  * workqueue and schedule on our own. */
 struct workqueue_struct *ocfs2_wq = NULL;
 
+static struct dentry *ocfs2_debugfs_root = NULL;
+
 MODULE_AUTHOR("Oracle");
 MODULE_LICENSE("GPL");
 
@@ -606,6 +609,14 @@
 			ocfs2_set_ro_flag(osb, 0);
 	}
 
+	osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
+						 ocfs2_debugfs_root);
+	if (!osb->osb_debug_root) {
+		status = -EINVAL;
+		mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
+		goto read_super_error;
+	}
+
 	status = ocfs2_mount_volume(sb);
 	if (osb->root_inode)
 		inode = igrab(osb->root_inode);
@@ -792,6 +803,12 @@
 	osb_id = 0;
 	spin_unlock(&ocfs2_globals_lock);
 
+	ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
+	if (!ocfs2_debugfs_root) {
+		status = -EFAULT;
+		mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
+	}
+
 	/* Initialize the proc interface */
 	ocfs2_proc_init();
 
@@ -824,6 +841,8 @@
 	/* Deinit the proc interface */
 	ocfs2_proc_deinit();
 
+	debugfs_remove(ocfs2_debugfs_root);
+
 	unregister_filesystem(&ocfs2_fs_type);
 
 	exit_ocfs2_extent_maps();
@@ -1181,6 +1200,8 @@
 
 	ocfs2_clear_hb_callbacks(osb);
 
+	debugfs_remove(osb->osb_debug_root);
+
 	if (!mnt_err)
 		ocfs2_stop_heartbeat(osb);
 
@@ -1425,6 +1446,13 @@
 	mlog(0, "root_blkno=%"MLFu64", system_dir_blkno=%"MLFu64"\n",
 	     osb->root_blkno, osb->system_dir_blkno);
 
+	osb->osb_dlm_debug = ocfs2_new_dlm_debug();
+	if (!osb->osb_dlm_debug) {
+		status = -ENOMEM;
+		mlog_errno(status);
+		goto bail;
+	}
+
 	atomic_set(&osb->vol_state, VOLUME_INIT);
 
 	/* load root, system_dir, and all global system inodes */
@@ -1645,6 +1673,7 @@
 	if (osb->local_alloc_copy)
 		kfree(osb->local_alloc_copy);
 	kfree(osb->uuid_str);
+	ocfs2_put_dlm_debug(osb->osb_dlm_debug);
 	memset(osb, 0, sizeof(ocfs2_super));
 
 	mlog_exit_void();

Added: branches/ocfs2-1.2/kapi-compat/include/kzalloc.h
===================================================================
--- branches/ocfs2-1.2/kapi-compat/include/kzalloc.h	2005-11-17 20:33:31 UTC (rev 2703)
+++ branches/ocfs2-1.2/kapi-compat/include/kzalloc.h	2005-11-18 21:48:30 UTC (rev 2704)
@@ -0,0 +1,6 @@
+#ifndef KAPI_KZALLOC_H
+#define KAPI_KZALLOC_H
+
+#define kzalloc(_size, _gfp_flags)	kcalloc(1, _size, _gfp_flags)
+
+#endif /* KAPI_KZALLOC_H */



More information about the Ocfs2-commits mailing list