linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: jim.cromie@gmail.com
To: jbaron@redhat.com
Cc: greg@kroah.com, joe@perches.com, bart.vanassche@gmail.com,
	linux-kernel@vger.kernel.org, Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH 21/26] dynamic_debug: add $DBGFS/dynamic_debug/pending file
Date: Fri,  7 Oct 2011 14:33:27 -0600	[thread overview]
Message-ID: <1318019612-20068-22-git-send-email-jim.cromie@gmail.com> (raw)
In-Reply-To: <1318019612-20068-1-git-send-email-jim.cromie@gmail.com>

From: Jim Cromie <jim.cromie@gmail.com>

Add pending file so user can see queries that are pending.  Output
format imitates that used to submit commands/queries.  This simplifies
cut-paste-edit to delete pending queries when they're no longer wanted.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 lib/dynamic_debug.c |  191 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 188 insertions(+), 3 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index d7b71a6..80b5322 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -64,6 +64,10 @@ struct ddebug_iter {
 	unsigned int idx;
 };
 
+struct pending_iter {
+	struct pending_query *elem;
+};
+
 static DEFINE_MUTEX(ddebug_lock);
 static LIST_HEAD(ddebug_tables);
 static int verbose = 0;
@@ -842,7 +846,8 @@ static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
 	int n = *pos;
 
 	if (verbose >= VERBOSE_PROC)
-		pr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos);
+		pr_info("called m=%p *pos=%lld\n",
+			m, (unsigned long long)*pos);
 
 	mutex_lock(&ddebug_lock);
 
@@ -963,7 +968,180 @@ static const struct file_operations ddebug_proc_fops = {
 	.write = ddebug_proc_write
 };
 
-/* apply matching queries in pending-queries list */
+/*
+ * Set the iterator to point to the first pending_query object
+ * and return a pointer to that first object.  Returns
+ * NULL if there are no pending_querys at all.
+ */
+static struct pending_query *pending_iter_first(struct pending_iter *iter)
+{
+	if (list_empty(&pending_queries)) {
+		iter->elem = NULL;
+		return NULL;
+	}
+	iter->elem = list_entry(pending_queries.next,
+				 struct pending_query, link);
+	return iter->elem;
+}
+
+/*
+ * Advance the iterator to point to the next pending_query
+ * object from the one the iterator currently points at,
+ * and returns a pointer to the new pending_query.  Returns
+ * NULL if the iterator has seen all the pending_querys.
+ */
+static struct pending_query *pending_iter_next(struct pending_iter *iter)
+{
+	if (iter->elem == NULL)
+		return NULL;
+	if (list_is_last(&iter->elem->link, &pending_queries)) {
+		iter->elem = NULL;
+		return NULL;
+	}
+	iter->elem = list_entry(iter->elem->link.next,
+				struct pending_query, link);
+	return iter->elem;
+}
+
+/*
+ * Seq_ops start method.  Called at the start of every read() call on
+ * pending file from userspace.  Takes the ddebug_lock and seeks the
+ * seq_file's iterator to the given position.
+ */
+static void *pending_proc_start(struct seq_file *m, loff_t *pos)
+{
+	struct pending_iter *iter = m->private;
+	struct pending_query *pq;
+	int n = *pos;
+
+	if (verbose >= VERBOSE_PROC)
+		pr_info("called m=%p *pos=%lld\n",
+			m, (unsigned long long)*pos);
+
+	mutex_lock(&ddebug_lock);
+
+	if (!n)
+		return SEQ_START_TOKEN;
+	if (n < 0)
+		return NULL;
+	pq = pending_iter_first(iter);
+	while (pq != NULL && --n > 0)
+		pq = pending_iter_next(iter);
+	return pq;
+}
+
+/*
+ * Seq_ops next method.  Called several times within a read()
+ * call from userspace, with pending_lock held.  Walks to the
+ * next pending_query object with a special case for the header line.
+ */
+static void *pending_proc_next(struct seq_file *m, void *p, loff_t *pos)
+{
+	struct pending_iter *iter = m->private;
+	struct pending_query *pq;
+
+	if (verbose >= VERBOSE_PROC_SHOW)
+		pr_info("called m=%p p=%p *pos=%lld\n",
+			m, p, (unsigned long long)*pos);
+
+	if (p == SEQ_START_TOKEN)
+		pq = pending_iter_first(iter);
+	else
+		pq = pending_iter_next(iter);
+	++*pos;
+	return pq;
+}
+
+/*
+ * Seq_ops show method.  Called several times within a read()
+ * call from userspace, with pending_lock held.  Formats the
+ * current pending_query as a single human-readable line, with a
+ * special case for the header line.
+ */
+static int pending_proc_show(struct seq_file *m, void *p)
+{
+	struct pending_iter *iter = m->private;
+	struct pending_query *pq = iter->elem;
+	struct ddebug_query *q = &pq->query;
+	char flagsbuf[10];
+
+	if (verbose >= VERBOSE_PROC_SHOW)
+		pr_info("called m=%p p=%p\n", m, p);
+
+	if (p == SEQ_START_TOKEN) {
+		seq_puts(m, "# func file module format line flags mask\n");
+		return 0;
+	}
+
+	seq_printf(m, "%s%s%s%s%s%s%s%s line %d-%d %s\n",
+		q->module ? "module " : "",
+		q->module ? q->module : "",
+		q->function ? " func " : "",
+		q->function ? q->function : "",
+		q->filename ? " file " : "",
+		q->filename ? q->filename : "",
+		q->format ? " format " : "",
+		q->format ? q->format : "",
+		q->first_lineno, q->last_lineno,
+		ddebug_describe_flags(pq->flags, flagsbuf, sizeof(flagsbuf)));
+
+	return 0;
+}
+
+/*
+ * Seq_ops stop method.  Called at the end of each read()
+ * call from userspace.  Drops pending_lock.
+ */
+static void pending_proc_stop(struct seq_file *m, void *p)
+{
+	if (verbose >= VERBOSE_PROC)
+		pr_info("called m=%p p=%p\n", m, p);
+	mutex_unlock(&ddebug_lock);
+}
+
+static const struct seq_operations pending_proc_seqops = {
+	.start = pending_proc_start,
+	.next = pending_proc_next,
+	.show = pending_proc_show,
+	.stop = pending_proc_stop
+};
+
+/*
+ * File_ops->open method for <debugfs>/dynamic_debug/control.  Does the seq_file
+ * setup dance, and also creates an iterator to walk the pending_querys.
+ * Note that we create a seq_file always, even for O_WRONLY files
+ * where it's not needed, as doing so simplifies the ->release method.
+ */
+static int pending_proc_open(struct inode *inode, struct file *file)
+{
+	struct pending_iter *iter;
+	int err;
+
+	if (verbose)
+		pr_info("called\n");
+
+	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
+	if (iter == NULL)
+		return -ENOMEM;
+
+	err = seq_open(file, &pending_proc_seqops);
+	if (err) {
+		kfree(iter);
+		return err;
+	}
+	((struct seq_file *) file->private_data)->private = iter;
+	return 0;
+}
+
+static const struct file_operations pending_proc_fops = {
+	.owner = THIS_MODULE,
+	.open = pending_proc_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release_private,
+};
+
+/* apply matching queries in pending-queries list. Called with lock held */
 static void apply_pending_queries(struct ddebug_table *dt)
 {
 	struct pending_query *pq, *pqnext;
@@ -1063,7 +1241,7 @@ static __initdata int ddebug_init_success;
 
 static int __init dynamic_debug_init_debugfs(void)
 {
-	struct dentry *dir, *file;
+	struct dentry *dir, *file, *file2;
 
 	if (!ddebug_init_success)
 		return -ENODEV;
@@ -1077,6 +1255,13 @@ static int __init dynamic_debug_init_debugfs(void)
 		debugfs_remove(dir);
 		return -ENOMEM;
 	}
+	file2 = debugfs_create_file("pending", 0444, dir, NULL,
+					&pending_proc_fops);
+	if (!file2) {
+		debugfs_remove(file);
+		debugfs_remove(dir);
+		return -ENOMEM;
+	}
 	return 0;
 }
 
-- 
1.7.4.4


  parent reply	other threads:[~2011-10-07 20:36 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-21 21:54 jim.cromie
2011-09-21 21:54 ` [PATCH 01/26] dynamic_debug: drop enabled field from struct _ddebug, use flags & _DPRINTK_FLAGS_PRINT jim.cromie
2011-09-21 21:54 ` [PATCH 02/26] dynamic_debug: make dynamic-debug supersede DEBUG ccflag jim.cromie
2011-09-21 21:54 ` [PATCH 03/26] dynamic_debug: replace strcpy with strlcpy, in ddebug_setup_query() jim.cromie
2011-09-21 21:54 ` [PATCH 04/26] dynamic_debug: warn when >1 of each type of match-spec is given jim.cromie
2011-09-21 21:54 ` [PATCH 05/26] dynamic_debug: pr_err() call should not depend upon verbosity jim.cromie
2011-09-21 21:54 ` [PATCH 06/26] dynamic_debug: add trim_prefix() to provide source-root relative paths jim.cromie
2011-09-21 21:54 ` [PATCH 07/26] dynamic_debug: change verbosity at runtime jim.cromie
2011-09-21 21:54 ` [PATCH 08/26] dynamic_debug: define several levels of verbosity jim.cromie
2011-09-21 21:54 ` [PATCH 09/26] dynamic_debug: process multiple commands on a line jim.cromie
2011-09-21 21:54 ` [PATCH 10/26] dynamic_debug: enlarge command/query write buffer jim.cromie
2011-09-21 22:29   ` Joe Perches
2011-09-21 21:55 ` [PATCH 11/26] dynamic_debug: hoist locking in ddebug_change to callers jim.cromie
2011-09-21 21:55 ` [PATCH 12/26] dynamic_debug: dont kill entire facility on error parsing ddebug_query jim.cromie
2011-09-21 21:55 ` [PATCH 13/26] dynamic_debug: factor vpr_info_dq out of ddebug_parse_query jim.cromie
2011-09-21 21:55 ` [PATCH 14/26] dynamic_debug: refactor query_matches_callsite out of ddebug_change jim.cromie
2011-09-21 21:55 ` [PATCH 15/26] dynamic_debug: drop explicit foo != NULL checks jim.cromie
2011-09-21 21:55 ` [PATCH 16/26] dynamic_debug: save 'a' queries to pending-list for later (re)application jim.cromie
2011-09-21 21:55 ` [PATCH 17/26] dynamic_debug: remove pending query when flags zeroed jim.cromie
2011-09-21 21:55 ` [PATCH 18/26] dynamic_debug: describe_flags with '=[pmflta_]*' jim.cromie
2011-09-21 21:55 ` [PATCH 19/26] dynamic_debug: add flags filtering to flags spec jim.cromie
2011-09-21 21:55 ` [PATCH 20/26] dynamic_debug: make ddebug_describe_flags more generic jim.cromie
2011-09-21 21:55 ` [PATCH 21/26] dynamic_debug: add $DBGFS/dynamic_debug/pending file jim.cromie
2011-09-21 21:55 ` [PATCH 22/26] dynamic_debug: early return if _ddebug table is empty jim.cromie
2011-09-21 21:55 ` [PATCH 23/26] dynamic_debug: document pending queries, flags-filter, multiple queries jim.cromie
2011-09-21 22:35   ` Randy Dunlap
2011-09-27 16:33     ` [patch 23/26 revised] jim.cromie
2011-09-27 16:33       ` [PATCH 23/26] dynamic_debug: document pending queries, flags-filter, multiple queries jim.cromie
2011-10-10 18:54   ` Jonathan Corbet
2011-10-10 19:27     ` Jason Baron
2011-10-18 20:41     ` Jim Cromie
2011-10-19 20:52       ` Jason Baron
2011-09-21 21:55 ` [PATCH 24/26] dynamic_debug: reduce lineno field to a saner 18 bits jim.cromie
2011-09-21 21:55 ` [PATCH 25/26] dynamic_debug: add pr_fmt_dbg() for dynamic_pr_debug jim.cromie
2011-09-22 20:57   ` Joe Perches
2011-09-23 10:31     ` Bart Van Assche
2011-09-23 17:42       ` Joe Perches
2011-09-27 20:37     ` Jim Cromie
2011-09-27 23:36       ` Joe Perches
2011-09-28  2:54         ` Jim Cromie
2011-09-28  4:51           ` Joe Perches
2011-09-28 17:27             ` Jim Cromie
2011-09-29 15:24               ` Joe Perches
2011-10-08 19:07             ` Bart Van Assche
2011-10-08 20:53               ` Joe Perches
2011-09-27 21:40     ` [revised patches 25,26/26] dynamic_debug: add pr_fmt_*() jim.cromie
2011-09-27 21:40       ` [PATCH 25/26] dynamic_debug: add pr_fmt_debug() for dynamic_pr_debug jim.cromie
2011-09-27 21:41       ` [PATCH 26/26] scx200_acb: use pr_(info|warn|err|debug) and dynamic-debug facilities jim.cromie
2011-09-21 21:55 ` jim.cromie
2011-09-26 23:23 ` your mail Greg KH
2011-10-07 20:33 ` [PATCH 00/26] dynamic_debug: add pending queries, etc (~resend) jim.cromie
2011-10-07 20:33   ` [PATCH 01/26] dynamic_debug: drop enabled field from struct _ddebug, use flags & _DPRINTK_FLAGS_PRINT jim.cromie
2011-10-07 20:33   ` [PATCH 02/26] dynamic_debug: make dynamic-debug supersede DEBUG ccflag jim.cromie
2011-10-07 20:33   ` [PATCH 03/26] dynamic_debug: replace strcpy with strlcpy, in ddebug_setup_query() jim.cromie
2011-10-07 20:33   ` [PATCH 04/26] dynamic_debug: warn when >1 of each type of match-spec is given jim.cromie
2011-10-07 20:33   ` [PATCH 05/26] dynamic_debug: pr_err() call should not depend upon verbosity jim.cromie
2011-10-07 21:21     ` Joe Perches
2011-10-07 20:33   ` [PATCH 06/26] dynamic_debug: add trim_prefix() to provide source-root relative paths jim.cromie
2011-10-07 20:33   ` [PATCH 07/26] dynamic_debug: change verbosity at runtime jim.cromie
2011-10-07 20:33   ` [PATCH 08/26] dynamic_debug: define several levels of verbosity jim.cromie
2011-10-07 20:33   ` [PATCH 09/26] dynamic_debug: process multiple commands on a line jim.cromie
2011-10-07 20:33   ` [PATCH 10/26] dynamic_debug: enlarge command/query write buffer jim.cromie
2011-10-07 20:33   ` [PATCH 11/26] dynamic_debug: hoist locking in ddebug_change to callers jim.cromie
2011-10-07 20:33   ` [PATCH 12/26] dynamic_debug: dont kill entire facility on error parsing ddebug_query jim.cromie
2011-10-07 20:33   ` [PATCH 13/26] dynamic_debug: factor vpr_info_dq out of ddebug_parse_query jim.cromie
2011-10-07 20:33   ` [PATCH 14/26] dynamic_debug: refactor query_matches_callsite out of ddebug_change jim.cromie
2011-10-07 20:33   ` [PATCH 15/26] dynamic_debug: drop explicit foo != NULL checks jim.cromie
2011-10-07 20:33   ` [PATCH 16/26] dynamic_debug: save 'a' queries to pending-list for later (re)application jim.cromie
2011-10-07 20:33   ` [PATCH 17/26] dynamic_debug: remove pending query when flags zeroed jim.cromie
2011-10-07 20:33   ` [PATCH 18/26] dynamic_debug: describe_flags with '=[pmflta_]*' jim.cromie
2011-10-07 20:33   ` [PATCH 19/26] dynamic_debug: add flags filtering to flags spec jim.cromie
2011-10-07 20:33   ` [PATCH 20/26] dynamic_debug: make ddebug_describe_flags more generic jim.cromie
2011-10-07 20:33   ` jim.cromie [this message]
2011-10-07 20:33   ` [PATCH 22/26] dynamic_debug: early return if _ddebug table is empty jim.cromie
2011-10-07 20:33   ` [PATCH 23/26] dynamic_debug: document pending queries, flags-filter, multiple queries jim.cromie
2011-10-07 20:33   ` [PATCH 24/26] dynamic_debug: reduce lineno field to a saner 18 bits jim.cromie
2011-10-07 20:33   ` [PATCH 25/26] dynamic_debug: add pr_fmt_*() for each severity jim.cromie
2011-10-07 20:33   ` [PATCH 26/26] printk.h: fix pr_cont_once() to not use pr_fmt() jim.cromie
2011-10-07 20:45     ` Joe Perches
2011-10-18 18:52   ` [PATCH 00/26] dynamic_debug: add pending queries, etc (~resend) Greg KH
2011-10-19 20:57     ` Jason Baron
2011-10-19 22:29       ` Greg KH

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=1318019612-20068-22-git-send-email-jim.cromie@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=bart.vanassche@gmail.com \
    --cc=greg@kroah.com \
    --cc=jbaron@redhat.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).