From: Joel Becker <Joel.Becker@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH 09/18] ocfs2_dlm: Dumps the lockres' into a debugfs file
Date: Thu Feb 28 17:11:37 2008 [thread overview]
Message-ID: <20080229011005.GD17860@mail.oracle.com> (raw)
In-Reply-To: <1203970862-8790-10-git-send-email-sunil.mushran@oracle.com>
On Mon, Feb 25, 2008 at 12:20:53PM -0800, Sunil Mushran wrote:
> This patch dumps all the lockres' alongwith all the locks into
> a debugfs file. Useful for debugging.
This one also needs checkpatch.pl.
Joel
> Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com>
> ---
> fs/ocfs2/dlm/dlmdebug.c | 248 +++++++++++++++++++++++++++++++++++++++++++++++
> fs/ocfs2/dlm/dlmdebug.h | 9 ++
> 2 files changed, 257 insertions(+), 0 deletions(-)
>
> diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c
> index 83f3ac6..905145a 100644
> --- a/fs/ocfs2/dlm/dlmdebug.c
> +++ b/fs/ocfs2/dlm/dlmdebug.c
> @@ -705,7 +705,34 @@ EXPORT_SYMBOL_GPL(dlm_errname);
>
> #define DLM_DEBUGFS_DIR "o2dlm"
> #define DLM_DEBUGFS_DLM_STATE "dlm_state"
> +#define DLM_DEBUGFS_LOCKING_STATE "locking_state"
>
> +/* 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;
> +}
> +
> /* begin - utils funcs */
> static void dlm_debug_free(struct kref *kref)
> {
> @@ -800,6 +827,214 @@ static int debug_buffer_release(struct inode *inode, struct file *file)
> }
> /* end - util funcs */
>
> +/* begin - debug lockres funcs */
> +static int dump_lock(struct dlm_lock *lock, int list_type, char *buf, int len)
> +{
> + int out;
> +
> +#define DEBUG_LOCK_VERSION 1
> + spin_lock(&lock->spinlock);
> + out = snprintf(buf, len, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
> + "%d,%d,%d,%d\n",
> + DEBUG_LOCK_VERSION,
> + list_type, 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)),
> + !list_empty(&lock->ast_list),
> + !list_empty(&lock->bast_list),
> + lock->ast_pending, lock->bast_pending,
> + lock->convert_pending, lock->lock_pending,
> + lock->cancel_pending, lock->unlock_pending,
> + atomic_read(&lock->lock_refs.refcount));
> + spin_unlock(&lock->spinlock);
> +
> + return out;
> +}
> +
> +static int dump_lockres(struct dlm_lock_resource *res, char *buf, int len)
> +{
> + struct dlm_lock *lock;
> + int i;
> + int out = 0;
> +
> + out += snprintf(buf + out, len - out, "NAME:");
> + out += stringify_lockname(res->lockname.name, res->lockname.len,
> + buf + out, len - out);
> + out += snprintf(buf + out, len - out, "\n");
> +
> +#define DEBUG_LRES_VERSION 1
> + out += snprintf(buf + out, len - out,
> + "LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
> + DEBUG_LRES_VERSION,
> + res->owner, res->state, res->last_used,
> + !list_empty(&res->purge),
> + !list_empty(&res->dirty),
> + !list_empty(&res->recovering),
> + res->inflight_locks, res->migration_pending,
> + atomic_read(&res->asts_reserved),
> + atomic_read(&res->refs.refcount));
> +
> + /* refmap */
> + out += snprintf(buf + out, len - out, "RMAP:");
> + out += stringify_nodemap(res->refmap, O2NM_MAX_NODES,
> + buf + out, len - out);
> + out += snprintf(buf + out, len - out, "\n");
> +
> + /* lvb */
> + out += snprintf(buf + out, len - out, "LVBX:");
> + for (i = 0; i < DLM_LVB_LEN; i++)
> + out += snprintf(buf + out, len - out,
> + "%02x", (unsigned char)res->lvb[i]);
> + out += snprintf(buf + out, len - out, "\n");
> +
> + /* granted */
> + list_for_each_entry(lock, &res->granted, list)
> + out += dump_lock(lock, 0, buf + out, len - out);
> +
> + /* converting */
> + list_for_each_entry(lock, &res->converting, list)
> + out += dump_lock(lock, 1, buf + out, len - out);
> +
> + /* blocked */
> + list_for_each_entry(lock, &res->blocked, list)
> + out += dump_lock(lock, 2, buf + out, len - out);
> +
> + out += snprintf(buf + out, len - out, "\n");
> +
> + return out;
> +}
> +
> +static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
> +{
> + struct debug_lockres *dl = m->private;
> + struct dlm_ctxt *dlm = dl->dl_ctxt;
> + struct dlm_lock_resource *res = NULL;
> +
> + spin_lock(&dlm->spinlock);
> +
> + if (dl->dl_res) {
> + list_for_each_entry(res, &dl->dl_res->tracking, tracking) {
> + if (dl->dl_res) {
> + dlm_lockres_put(dl->dl_res);
> + dl->dl_res = NULL;
> + }
> + if (&res->tracking == &dlm->tracking_list) {
> + mlog(0, "End of list found, %p\n", res);
> + dl = NULL;
> + break;
> + }
> + dlm_lockres_get(res);
> + dl->dl_res = res;
> + break;
> + }
> + } else {
> + if (!list_empty(&dlm->tracking_list)) {
> + list_for_each_entry(res, &dlm->tracking_list, tracking)
> + break;
> + dlm_lockres_get(res);
> + dl->dl_res = res;
> + } else
> + dl = NULL;
> + }
> +
> + if (dl) {
> + spin_lock(&dl->dl_res->spinlock);
> + dump_lockres(dl->dl_res, dl->dl_buf, dl->dl_len - 1);
> + spin_unlock(&dl->dl_res->spinlock);
> + }
> +
> + spin_unlock(&dlm->spinlock);
> +
> + return dl;
> +}
> +
> +static void lockres_seq_stop(struct seq_file *m, void *v)
> +{
> +}
> +
> +static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
> +{
> + return NULL;
> +}
> +
> +static int lockres_seq_show(struct seq_file *s, void *v)
> +{
> + struct debug_lockres *dl = (struct debug_lockres *)v;
> +
> + seq_printf(s, "%s", dl->dl_buf);
> +
> + return 0;
> +}
> +
> +static struct seq_operations debug_lockres_ops = {
> + .start = lockres_seq_start,
> + .stop = lockres_seq_stop,
> + .next = lockres_seq_next,
> + .show = lockres_seq_show,
> +};
> +
> +static int debug_lockres_open(struct inode *inode, struct file *file)
> +{
> + struct dlm_ctxt *dlm = inode->i_private;
> + int ret = -ENOMEM;
> + struct seq_file *seq;
> + struct debug_lockres *dl = NULL;
> +
> + dl = kzalloc(sizeof(struct debug_lockres), GFP_KERNEL);
> + if (!dl) {
> + mlog_errno(ret);
> + goto bail;
> + }
> +
> + dl->dl_len = PAGE_SIZE;
> + dl->dl_buf = kmalloc(dl->dl_len, GFP_KERNEL);
> + if (!dl->dl_buf) {
> + mlog_errno(ret);
> + goto bail;
> + }
> +
> + ret = seq_open(file, &debug_lockres_ops);
> + if (ret) {
> + mlog_errno(ret);
> + goto bail;
> + }
> +
> + seq = (struct seq_file *) file->private_data;
> + seq->private = dl;
> +
> + dlm_grab(dlm);
> + dl->dl_ctxt = dlm;
> +
> + return 0;
> +bail:
> + if (dl && dl->dl_buf)
> + kfree(dl->dl_buf);
> + if (dl)
> + kfree(dl);
> + return ret;
> +}
> +
> +static int debug_lockres_release(struct inode *inode, struct file *file)
> +{
> + struct seq_file *seq = (struct seq_file *)file->private_data;
> + struct debug_lockres *dl = (struct debug_lockres *)seq->private;
> +
> + if (dl->dl_res)
> + dlm_lockres_put(dl->dl_res);
> + dlm_put(dl->dl_ctxt);
> + kfree(dl->dl_buf);
> + return seq_release_private(inode, file);
> +}
> +
> +static struct file_operations debug_lockres_fops = {
> + .open = debug_lockres_open,
> + .release = debug_lockres_release,
> + .read = seq_read,
> + .llseek = seq_lseek,
> +};
> +/* end - debug lockres funcs */
> +
> /* begin - debug state funcs */
> static int debug_state_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
> {
> @@ -976,6 +1211,17 @@ int dlm_debug_init(struct dlm_ctxt *dlm)
> goto bail;
> }
>
> + /* for dumping lockres */
> + dc->debug_lockres_dentry =
> + debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE,
> + S_IFREG|S_IRUSR,
> + dlm->dlm_debugfs_subroot,
> + dlm, &debug_lockres_fops);
> + if (!dc->debug_lockres_dentry) {
> + mlog_errno(-ENOMEM);
> + goto bail;
> + }
> +
> dlm_debug_get(dc);
> return 0;
>
> @@ -989,6 +1235,8 @@ void dlm_debug_shutdown(struct dlm_ctxt *dlm)
> struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
>
> if (dc) {
> + if (dc->debug_lockres_dentry)
> + debugfs_remove(dc->debug_lockres_dentry);
> if (dc->debug_state_dentry)
> debugfs_remove(dc->debug_state_dentry);
> dlm_debug_put(dc);
> diff --git a/fs/ocfs2/dlm/dlmdebug.h b/fs/ocfs2/dlm/dlmdebug.h
> index 50cb10f..86d02f4 100644
> --- a/fs/ocfs2/dlm/dlmdebug.h
> +++ b/fs/ocfs2/dlm/dlmdebug.h
> @@ -28,6 +28,7 @@
> struct dlm_debug_ctxt {
> struct kref debug_refcnt;
> struct dentry *debug_state_dentry;
> + struct dentry *debug_lockres_dentry;
> };
>
> struct debug_buffer
> @@ -36,6 +37,14 @@ struct debug_buffer
> char *buf;
> };
>
> +struct debug_lockres
> +{
> + int dl_len;
> + char *dl_buf;
> + struct dlm_ctxt *dl_ctxt;
> + struct dlm_lock_resource *dl_res;
> +};
> +
> void dlm_remove_proc(void);
> void dlm_init_proc(void);
> void dlm_dump_lock_resources(struct dlm_ctxt *dlm);
> --
> 1.5.2.5
>
>
> _______________________________________________
> Ocfs2-devel mailing list
> Ocfs2-devel@oss.oracle.com
> http://oss.oracle.com/mailman/listinfo/ocfs2-devel
--
Joel's First Law:
Nature abhors a GUI.
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127
next prev parent reply other threads:[~2008-02-28 17:11 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-25 12:21 [Ocfs2-devel] New dlm debug infrastructure Sunil Mushran
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 06/18] ocfs2_dlm: Link all lockres' to a tracking list Sunil Mushran
2008-02-28 16:32 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 12/18] ocfs2_dlm: Dumps the purgelist into a debugfs file Sunil Mushran
2008-02-28 16:53 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 10/18] ocfs2_dlm: Moves struct dlm_master_list_entry to dlmcommon.h Sunil Mushran
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 05/18] ocfs2_dlm: Add missing dlm_lockres_put()s Sunil Mushran
2008-02-28 14:50 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 15/18] ocfs2_dlm: Move dlm_print_one_mle() from dlmmaster.c to dlmdebug.c Sunil Mushran
2008-02-28 16:55 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 18/18] ocfs2_dlm: Print message showing the recomaster Sunil Mushran
2008-02-28 16:57 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 01/18] ocfs2_dlm: Rename slabcache dlm_mle_cache to o2dlm_mle Sunil Mushran
2008-02-28 14:12 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 02/18] ocfs2_dlm: Creates slabcaches for the lockres' and the locks Sunil Mushran
2008-02-28 14:37 ` Joel Becker
2008-02-28 17:09 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 04/18] ocfs2_dlm: Add missing dlm_lockres_put()s in migration path Sunil Mushran
2008-02-28 14:41 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 07/18] ocfs2_dlm: Create debugfs dirs Sunil Mushran
2008-02-28 16:34 ` Joel Becker
2008-02-28 17:09 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 16/18] ocfs2_dlm: Small fix regarding dlm_print_one_lock_resource() Sunil Mushran
2008-02-28 16:55 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 17/18] ocfs2_dlm: Fix lockname in lockres print function Sunil Mushran
2008-02-28 16:57 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 09/18] ocfs2_dlm: Dumps the lockres' into a debugfs file Sunil Mushran
2008-02-28 16:51 ` Joel Becker
2008-02-28 17:11 ` Joel Becker [this message]
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 03/18] ocfs2_dlm: Add missing dlm_lock_put()s Sunil Mushran
2008-02-28 14:39 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 13/18] ocfs2_dlm: Dumps the workqueue into a debugfs file Sunil Mushran
2008-02-28 16:53 ` Joel Becker
2008-02-28 17:11 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 14/18] ocfs2_dlm: Remove the proc interface Sunil Mushran
2008-02-28 16:55 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 11/18] ocfs2_dlm: Dumps the mles into a debugfs file Sunil Mushran
2008-02-28 16:53 ` Joel Becker
2008-02-25 12:21 ` [Ocfs2-devel] [PATCH 08/18] ocfs2_dlm: Dump the dlm state in " Sunil Mushran
2008-02-28 16:38 ` Joel Becker
2008-02-28 17:11 ` Joel Becker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080229011005.GD17860@mail.oracle.com \
--to=joel.becker@oracle.com \
--cc=ocfs2-devel@oss.oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.