dlmdebug.c

来自「ocfs1.4.1 oracle分布式文件系统」· C语言 代码 · 共 1,038 行 · 第 1/2 页

C
1,038
字号
/* -*- mode: c; c-basic-offset: 8; -*- * vim: noexpandtab sw=8 ts=8 sts=0: * * dlmdebug.c * * debug functionality for the dlm * * Copyright (C) 2004, 2008 Oracle.  All rights reserved. * * 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; either * version 2 of the License, or (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 021110-1307, USA. * */#include <linux/types.h>#include <linux/slab.h>#include <linux/highmem.h>#include <linux/utsname.h>#include <linux/sysctl.h>#include <linux/spinlock.h>#include <linux/debugfs.h>#include "cluster/heartbeat.h"#include "cluster/nodemanager.h"#include "cluster/tcp.h"#include "dlmapi.h"#include "dlmcommon.h"#include "dlmdomain.h"#include "dlmdebug.h"#define MLOG_MASK_PREFIX ML_DLM#include "cluster/masklog.h"static int stringify_lockname(const char *lockname, int locklen, char *buf,			      int len);void dlm_print_one_lock_resource(struct dlm_lock_resource *res){	spin_lock(&res->spinlock);	__dlm_print_one_lock_resource(res);	spin_unlock(&res->spinlock);}static void dlm_print_lockres_refmap(struct dlm_lock_resource *res){	int bit;	assert_spin_locked(&res->spinlock);	printk("  refmap nodes: [ ");	bit = 0;	while (1) {		bit = find_next_bit(res->refmap, O2NM_MAX_NODES, bit);		if (bit >= O2NM_MAX_NODES)			break;		printk("%u ", bit);		bit++;	}	printk("], inflight=%u\n", res->inflight_locks);}static void __dlm_print_lock(struct dlm_lock *lock){	spin_lock(&lock->spinlock);	printk("    type=%d, conv=%d, node=%u, cookie=%u:%llu, "	       "ref=%u, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c), "	       "pending=(conv=%c,lock=%c,cancel=%c,unlock=%c)\n",	       lock->ml.type, lock->ml.convert_type, lock->ml.node,	       dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),	       dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),	       atomic_read(&lock->lock_refs.refcount),	       (list_empty(&lock->ast_list) ? 'y' : 'n'),	       (lock->ast_pending ? 'y' : 'n'),	       (list_empty(&lock->bast_list) ? 'y' : 'n'),	       (lock->bast_pending ? 'y' : 'n'),	       (lock->convert_pending ? 'y' : 'n'),	       (lock->lock_pending ? 'y' : 'n'),	       (lock->cancel_pending ? 'y' : 'n'),	       (lock->unlock_pending ? 'y' : 'n'));	spin_unlock(&lock->spinlock);}void __dlm_print_one_lock_resource(struct dlm_lock_resource *res){	struct list_head *iter2;	struct dlm_lock *lock;	char buf[DLM_LOCKID_NAME_MAX];	assert_spin_locked(&res->spinlock);	stringify_lockname(res->lockname.name, res->lockname.len,			   buf, sizeof(buf) - 1);	printk("lockres: %s, owner=%u, state=%u\n",	       buf, res->owner, res->state);	printk("  last used: %lu, refcnt: %u, on purge list: %s\n",	       res->last_used, atomic_read(&res->refs.refcount),	       list_empty(&res->purge) ? "no" : "yes");	printk("  on dirty list: %s, on reco list: %s, "	       "migrating pending: %s\n",	       list_empty(&res->dirty) ? "no" : "yes",	       list_empty(&res->recovering) ? "no" : "yes",	       res->migration_pending ? "yes" : "no");	printk("  inflight locks: %d, asts reserved: %d\n",	       res->inflight_locks, atomic_read(&res->asts_reserved));	dlm_print_lockres_refmap(res);	printk("  granted queue:\n");	list_for_each(iter2, &res->granted) {		lock = list_entry(iter2, struct dlm_lock, list);		__dlm_print_lock(lock);	}	printk("  converting queue:\n");	list_for_each(iter2, &res->converting) {		lock = list_entry(iter2, struct dlm_lock, list);		__dlm_print_lock(lock);	}	printk("  blocked queue:\n");	list_for_each(iter2, &res->blocked) {		lock = list_entry(iter2, struct dlm_lock, list);		__dlm_print_lock(lock);	}}void dlm_print_one_lock(struct dlm_lock *lockid){	dlm_print_one_lock_resource(lockid->lockres);}EXPORT_SYMBOL_GPL(dlm_print_one_lock);static const char *dlm_errnames[] = {	[DLM_NORMAL] =			"DLM_NORMAL",	[DLM_GRANTED] =			"DLM_GRANTED",	[DLM_DENIED] =			"DLM_DENIED",	[DLM_DENIED_NOLOCKS] =		"DLM_DENIED_NOLOCKS",	[DLM_WORKING] =			"DLM_WORKING",	[DLM_BLOCKED] =			"DLM_BLOCKED",	[DLM_BLOCKED_ORPHAN] =		"DLM_BLOCKED_ORPHAN",	[DLM_DENIED_GRACE_PERIOD] =	"DLM_DENIED_GRACE_PERIOD",	[DLM_SYSERR] =			"DLM_SYSERR",	[DLM_NOSUPPORT] =		"DLM_NOSUPPORT",	[DLM_CANCELGRANT] =		"DLM_CANCELGRANT",	[DLM_IVLOCKID] =		"DLM_IVLOCKID",	[DLM_SYNC] =			"DLM_SYNC",	[DLM_BADTYPE] =			"DLM_BADTYPE",	[DLM_BADRESOURCE] =		"DLM_BADRESOURCE",	[DLM_MAXHANDLES] =		"DLM_MAXHANDLES",	[DLM_NOCLINFO] =		"DLM_NOCLINFO",	[DLM_NOLOCKMGR] =		"DLM_NOLOCKMGR",	[DLM_NOPURGED] =		"DLM_NOPURGED",	[DLM_BADARGS] =			"DLM_BADARGS",	[DLM_VOID] =			"DLM_VOID",	[DLM_NOTQUEUED] =		"DLM_NOTQUEUED",	[DLM_IVBUFLEN] =		"DLM_IVBUFLEN",	[DLM_CVTUNGRANT] =		"DLM_CVTUNGRANT",	[DLM_BADPARAM] =		"DLM_BADPARAM",	[DLM_VALNOTVALID] =		"DLM_VALNOTVALID",	[DLM_REJECTED] =		"DLM_REJECTED",	[DLM_ABORT] =			"DLM_ABORT",	[DLM_CANCEL] =			"DLM_CANCEL",	[DLM_IVRESHANDLE] =		"DLM_IVRESHANDLE",	[DLM_DEADLOCK] =		"DLM_DEADLOCK",	[DLM_DENIED_NOASTS] =		"DLM_DENIED_NOASTS",	[DLM_FORWARD] =			"DLM_FORWARD",	[DLM_TIMEOUT] =			"DLM_TIMEOUT",	[DLM_IVGROUPID] =		"DLM_IVGROUPID",	[DLM_VERS_CONFLICT] =		"DLM_VERS_CONFLICT",	[DLM_BAD_DEVICE_PATH] =		"DLM_BAD_DEVICE_PATH",	[DLM_NO_DEVICE_PERMISSION] =	"DLM_NO_DEVICE_PERMISSION",	[DLM_NO_CONTROL_DEVICE ] =	"DLM_NO_CONTROL_DEVICE ",	[DLM_RECOVERING] =		"DLM_RECOVERING",	[DLM_MIGRATING] =		"DLM_MIGRATING",	[DLM_MAXSTATS] =		"DLM_MAXSTATS",};static const char *dlm_errmsgs[] = {	[DLM_NORMAL] = 			"request in progress",	[DLM_GRANTED] = 		"request granted",	[DLM_DENIED] = 			"request denied",	[DLM_DENIED_NOLOCKS] = 		"request denied, out of system resources",	[DLM_WORKING] = 		"async request in progress",	[DLM_BLOCKED] = 		"lock request blocked",	[DLM_BLOCKED_ORPHAN] = 		"lock request blocked by a orphan lock",	[DLM_DENIED_GRACE_PERIOD] = 	"topological change in progress",	[DLM_SYSERR] = 			"system error",	[DLM_NOSUPPORT] = 		"unsupported",	[DLM_CANCELGRANT] = 		"can't cancel convert: already granted",	[DLM_IVLOCKID] = 		"bad lockid",	[DLM_SYNC] = 			"synchronous request granted",	[DLM_BADTYPE] = 		"bad resource type",	[DLM_BADRESOURCE] = 		"bad resource handle",	[DLM_MAXHANDLES] = 		"no more resource handles",	[DLM_NOCLINFO] = 		"can't contact cluster manager",	[DLM_NOLOCKMGR] = 		"can't contact lock manager",	[DLM_NOPURGED] = 		"can't contact purge daemon",	[DLM_BADARGS] = 		"bad api args",	[DLM_VOID] = 			"no status",	[DLM_NOTQUEUED] = 		"NOQUEUE was specified and request failed",	[DLM_IVBUFLEN] = 		"invalid resource name length",	[DLM_CVTUNGRANT] = 		"attempted to convert ungranted lock",	[DLM_BADPARAM] = 		"invalid lock mode specified",	[DLM_VALNOTVALID] = 		"value block has been invalidated",	[DLM_REJECTED] = 		"request rejected, unrecognized client",	[DLM_ABORT] = 			"blocked lock request cancelled",	[DLM_CANCEL] = 			"conversion request cancelled",	[DLM_IVRESHANDLE] = 		"invalid resource handle",	[DLM_DEADLOCK] = 		"deadlock recovery refused this request",	[DLM_DENIED_NOASTS] = 		"failed to allocate AST",	[DLM_FORWARD] = 		"request must wait for primary's response",	[DLM_TIMEOUT] = 		"timeout value for lock has expired",	[DLM_IVGROUPID] = 		"invalid group specification",	[DLM_VERS_CONFLICT] = 		"version conflicts prevent request handling",	[DLM_BAD_DEVICE_PATH] = 	"Locks device does not exist or path wrong",	[DLM_NO_DEVICE_PERMISSION] = 	"Client has insufficient perms for device",	[DLM_NO_CONTROL_DEVICE] = 	"Cannot set options on opened device ",	[DLM_RECOVERING] = 		"lock resource being recovered",	[DLM_MIGRATING] = 		"lock resource being migrated",	[DLM_MAXSTATS] = 		"invalid error number",};const char *dlm_errmsg(enum dlm_status err){	if (err >= DLM_MAXSTATS || err < 0)		return dlm_errmsgs[DLM_MAXSTATS];	return dlm_errmsgs[err];}EXPORT_SYMBOL_GPL(dlm_errmsg);const char *dlm_errname(enum dlm_status err){	if (err >= DLM_MAXSTATS || err < 0)		return dlm_errnames[DLM_MAXSTATS];	return dlm_errnames[err];}EXPORT_SYMBOL_GPL(dlm_errname);/* NOTE: This function converts a lockname into a string. It uses knowledge * of the format of the lockname that should be outside the purview of the dlm. * We are adding only to make dlm debugging slightly easier. * * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h. */static int stringify_lockname(const char *lockname, int locklen, char *buf,			      int len){	int out = 0;	__be64 inode_blkno_be;#define OCFS2_DENTRY_LOCK_INO_START	18	if (*lockname == 'N') {		memcpy((__be64 *)&inode_blkno_be,		       (char *)&lockname[OCFS2_DENTRY_LOCK_INO_START],		       sizeof(__be64));		out += snprintf(buf + out, len - out, "%.*s%08x",				OCFS2_DENTRY_LOCK_INO_START - 1, lockname,				(unsigned int)be64_to_cpu(inode_blkno_be));	} else		out += snprintf(buf + out, len - out, "%.*s",				locklen, lockname);	return out;}static int stringify_nodemap(unsigned long *nodemap, int maxnodes,			     char *buf, int len){	int out = 0;	int i = -1;	while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)		out += snprintf(buf + out, len - out, "%d ", i);	return out;}static int dump_mle(struct dlm_master_list_entry *mle, char *buf, int len){	int out = 0;	unsigned int namelen;	const char *name;	char *mle_type;	if (mle->type != DLM_MLE_MASTER) {		namelen = mle->u.name.len;		name = mle->u.name.name;	} else {		namelen = mle->u.res->lockname.len;		name = mle->u.res->lockname.name;	}	if (mle->type == DLM_MLE_BLOCK)		mle_type = "BLK";	else if (mle->type == DLM_MLE_MASTER)		mle_type = "MAS";	else		mle_type = "MIG";	out += stringify_lockname(name, namelen, buf + out, len - out);	out += snprintf(buf + out, len - out,			"\t%3s\tmas=%3u\tnew=%3u\tevt=%1d\tuse=%1d\tref=%3d\n",			mle_type, mle->master, mle->new_master,			!list_empty(&mle->hb_events),			!!mle->inuse,			atomic_read(&mle->mle_refs.refcount));	out += snprintf(buf + out, len - out, "Maybe=");	out += stringify_nodemap(mle->maybe_map, O2NM_MAX_NODES,				 buf + out, len - out);	out += snprintf(buf + out, len - out, "\n");	out += snprintf(buf + out, len - out, "Vote=");	out += stringify_nodemap(mle->vote_map, O2NM_MAX_NODES,				 buf + out, len - out);	out += snprintf(buf + out, len - out, "\n");	out += snprintf(buf + out, len - out, "Response=");	out += stringify_nodemap(mle->response_map, O2NM_MAX_NODES,				 buf + out, len - out);	out += snprintf(buf + out, len - out, "\n");	out += snprintf(buf + out, len - out, "Node=");	out += stringify_nodemap(mle->node_map, O2NM_MAX_NODES,				 buf + out, len - out);	out += snprintf(buf + out, len - out, "\n");	out += snprintf(buf + out, len - out, "\n");	return out;}void dlm_print_one_mle(struct dlm_master_list_entry *mle){	char *buf;	buf = (char *) get_zeroed_page(GFP_NOFS);	if (buf) {		dump_mle(mle, buf, PAGE_SIZE - 1);		free_page((unsigned long)buf);	}}#ifdef CONFIG_DEBUG_FSstatic struct dentry *dlm_debugfs_root = NULL;#define DLM_DEBUGFS_DIR				"o2dlm"#define DLM_DEBUGFS_DLM_STATE			"dlm_state"#define DLM_DEBUGFS_LOCKING_STATE		"locking_state"#define DLM_DEBUGFS_MLE_STATE			"mle_state"#define DLM_DEBUGFS_PURGE_LIST			"purge_list"/* begin - utils funcs */static void dlm_debug_free(struct kref *kref){	struct dlm_debug_ctxt *dc;	dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);	kfree(dc);}static void dlm_debug_put(struct dlm_debug_ctxt *dc){	if (dc)		kref_put(&dc->debug_refcnt, dlm_debug_free);}static void dlm_debug_get(struct dlm_debug_ctxt *dc){	kref_get(&dc->debug_refcnt);}static struct debug_buffer *debug_buffer_allocate(void){	struct debug_buffer *db = NULL;	db = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);	if (!db)		goto bail;	db->len = PAGE_SIZE;	db->buf = kmalloc(db->len, GFP_KERNEL);	if (!db->buf)		goto bail;	return db;bail:	kfree(db);	return NULL;}static ssize_t debug_buffer_read(struct file *file, char __user *buf,				 size_t nbytes, loff_t *ppos){	struct debug_buffer *db = file->private_data;	return simple_read_from_buffer(buf, nbytes, ppos, db->buf, db->len);}static loff_t debug_buffer_llseek(struct file *file, loff_t off, int whence){	struct debug_buffer *db = file->private_data;	loff_t new = -1;	switch (whence) {	case 0:		new = off;		break;	case 1:		new = file->f_pos + off;		break;	}	if (new < 0 || new > db->len)		return -EINVAL;	return (file->f_pos = new);}static int debug_buffer_release(struct inode *inode, struct file *file){	struct debug_buffer *db = (struct debug_buffer *)file->private_data;	if (db)		kfree(db->buf);	kfree(db);	return 0;}/* end - util funcs *//* begin - purge list funcs */static int debug_purgelist_print(struct dlm_ctxt *dlm, struct debug_buffer *db){	struct dlm_lock_resource *res;	int out = 0;	unsigned long total = 0;	out += snprintf(db->buf + out, db->len - out,			"Dumping Purgelist for Domain: %s\n", dlm->name);	spin_lock(&dlm->spinlock);	list_for_each_entry(res, &dlm->purge_list, purge) {		++total;		if (db->len - out < 100)			continue;		spin_lock(&res->spinlock);		out += stringify_lockname(res->lockname.name,					  res->lockname.len,					  db->buf + out, db->len - out);		out += snprintf(db->buf + out, db->len - out, "\t%ld\n",				(jiffies - res->last_used)/HZ);		spin_unlock(&res->spinlock);	}	spin_unlock(&dlm->spinlock);	out += snprintf(db->buf + out, db->len - out,			"Total on list: %ld\n", total);	return out;}static int debug_purgelist_open(struct inode *inode, struct file *file){	struct dlm_ctxt *dlm = inode->i_private;	struct debug_buffer *db;	db = debug_buffer_allocate();	if (!db)		goto bail;	db->len = debug_purgelist_print(dlm, db);	file->private_data = db;	return 0;bail:	return -ENOMEM;}static struct file_operations debug_purgelist_fops = {	.open =		debug_purgelist_open,	.release =	debug_buffer_release,	.read =		debug_buffer_read,	.llseek =	debug_buffer_llseek,};/* end - purge list funcs *//* begin - debug mle funcs */static int debug_mle_print(struct dlm_ctxt *dlm, struct debug_buffer *db){	struct dlm_master_list_entry *mle;	int out = 0;	unsigned long total = 0;	out += snprintf(db->buf + out, db->len - out,			"Dumping MLEs for Domain: %s\n", dlm->name);	spin_lock(&dlm->master_lock);	list_for_each_entry(mle, &dlm->master_list, list) {		++total;		if (db->len - out < 200)			continue;		out += dump_mle(mle, db->buf + out, db->len - out);	}	spin_unlock(&dlm->master_lock);	out += snprintf(db->buf + out, db->len - out,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?