[Ocfs2-commits] mfasheh commits r2701 - in trunk: . fs/ocfs2 kapi-compat/include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Nov 17 14:27:09 CST 2005


Author: mfasheh
Signed-off-by: zab
Date: 2005-11-17 14:27:07 -0600 (Thu, 17 Nov 2005)
New Revision: 2701

Added:
   trunk/kapi-compat/include/kzalloc.h
Modified:
   trunk/configure.in
   trunk/fs/ocfs2/dlmglue.c
   trunk/fs/ocfs2/dlmglue.h
   trunk/fs/ocfs2/ocfs2.h
   trunk/fs/ocfs2/super.c
Log:
* Add OCFS2 debugging via debugfs 
  - Begin with per mount dlmglue lockres state tracking

* This uses kzalloc, so add some compat for older kernels

Signed-off-by: zab



Modified: trunk/configure.in
===================================================================
--- trunk/configure.in	2005-11-17 19:22:10 UTC (rev 2700)
+++ trunk/configure.in	2005-11-17 20:27:07 UTC (rev 2701)
@@ -212,6 +212,12 @@
 fi
 AC_SUBST(ARCH_XEN)
 
+AC_MSG_CHECKING(for debugfs)
+if test ! -f "$KERNELINC/linux/debugfs.h"; then
+  AC_MSG_ERROR(no; please build against a kernel with debugfs)
+fi
+AC_MSG_RESULT(yes)
+
 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 +232,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: trunk/fs/ocfs2/dlmglue.c
===================================================================
--- trunk/fs/ocfs2/dlmglue.c	2005-11-17 19:22:10 UTC (rev 2700)
+++ trunk/fs/ocfs2/dlmglue.c	2005-11-17 20:27:07 UTC (rev 2701)
@@ -31,6 +31,8 @@
 #include <linux/crc32.h>
 #include <linux/kthread.h>
 #include <linux/pagemap.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
 
 #include <cluster/heartbeat.h>
 #include <cluster/nodemanager.h>
@@ -240,7 +242,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(struct ocfs2_super *osb,
+				       struct ocfs2_lock_res *res,
 				       enum ocfs2_lock_type type,
 				       u64 blkno,
 				       u32 generation,
@@ -260,6 +283,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)
@@ -294,7 +319,8 @@
 			break;
 	};
 
-	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);
 }
 
@@ -304,7 +330,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);
 }
@@ -315,7 +341,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);
 }
 
@@ -326,6 +352,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);
@@ -1790,6 +1818,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;
+	struct ocfs2_super *osb;
+
+	priv = kzalloc(sizeof(struct ocfs2_dlm_seq_priv), GFP_KERNEL);
+	if (!priv) {
+		ret = -ENOMEM;
+		mlog_errno(ret);
+		goto out;
+	}
+	osb = (struct 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(struct 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(struct 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(struct ocfs2_super *osb)
 {
 	int status;
@@ -1798,6 +2079,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);
@@ -1829,6 +2116,8 @@
 
 	status = 0;
 bail:
+	if (status < 0)
+		ocfs2_dlm_shutdown_debug(osb);
 
 	mlog_exit(status);
 	return status;
@@ -1853,6 +2142,8 @@
 	dlm_unregister_domain(osb->dlm);
 	osb->dlm = NULL;
 
+	ocfs2_dlm_shutdown_debug(osb);
+
 	mlog_exit_void();
 }
 

Modified: trunk/fs/ocfs2/dlmglue.h
===================================================================
--- trunk/fs/ocfs2/dlmglue.h	2005-11-17 19:22:10 UTC (rev 2700)
+++ trunk/fs/ocfs2/dlmglue.h	2005-11-17 20:27:07 UTC (rev 2701)
@@ -98,6 +98,9 @@
 void ocfs2_process_blocked_lock(struct 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: trunk/fs/ocfs2/ocfs2.h
===================================================================
--- trunk/fs/ocfs2/ocfs2.h	2005-11-17 19:22:10 UTC (rev 2700)
+++ trunk/fs/ocfs2/ocfs2.h	2005-11-17 20:27:07 UTC (rev 2701)
@@ -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"
@@ -131,8 +132,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,
@@ -246,7 +255,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: trunk/fs/ocfs2/super.c
===================================================================
--- trunk/fs/ocfs2/super.c	2005-11-17 19:22:10 UTC (rev 2700)
+++ trunk/fs/ocfs2/super.c	2005-11-17 20:27:07 UTC (rev 2701)
@@ -38,6 +38,7 @@
 #include <linux/inet.h>
 #include <linux/parser.h>
 #include <linux/crc32.h>
+#include <linux/debugfs.h>
 
 #include <cluster/nodemanager.h>
 
@@ -84,6 +85,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");
 
@@ -622,6 +625,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);
@@ -817,6 +828,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");
+	}
+
 leave:
 	if (status < 0) {
 		ocfs2_free_mem_caches();
@@ -841,6 +858,8 @@
 		destroy_workqueue(ocfs2_wq);
 	}
 
+	debugfs_remove(ocfs2_debugfs_root);
+
 	ocfs2_free_mem_caches();
 
 	unregister_filesystem(&ocfs2_fs_type);
@@ -1192,6 +1211,8 @@
 
 	ocfs2_clear_hb_callbacks(osb);
 
+	debugfs_remove(osb->osb_debug_root);
+
 	if (!mnt_err)
 		ocfs2_stop_heartbeat(osb);
 
@@ -1430,6 +1451,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 */
@@ -1651,6 +1679,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(struct ocfs2_super));
 
 	mlog_exit_void();

Added: trunk/kapi-compat/include/kzalloc.h
===================================================================
--- trunk/kapi-compat/include/kzalloc.h	2005-11-17 19:22:10 UTC (rev 2700)
+++ trunk/kapi-compat/include/kzalloc.h	2005-11-17 20:27:07 UTC (rev 2701)
@@ -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