mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@redhat.com
Cc: bvanassche@acm.org, joe@perches.com, gregkh@suse.de,
	linux-kernel@vger.kernel.org, gnb@fmeh.org,
	Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH 19/25] dynamic_debug: add flags filtering to flags spec
Date: Mon, 25 Jul 2011 15:42:44 -0600	[thread overview]
Message-ID: <1311630170-26057-20-git-send-email-jim.cromie@gmail.com> (raw)
In-Reply-To: <1311630170-26057-1-git-send-email-jim.cromie@gmail.com>

Change definition of flags spec to [pmflta_]*[-+=][pmflta_]*
The flags preceding the op are optional filter-flags; if provided,
they add an additional constraint to call-site matching done
by ddebug_change; call-sites which do not have all specified flags
are skipped (additional flags are allowed).

This allows query/rules like "p+t" to turn on TID logging for all
currently enabled call-sites, while leaving the others alone.
This will also allow filtering on pending rules (with 'a' flag),
which will support removal of pending rules.

Also allow 0 flags byte, so that active rules can be completely
reset by writing "p=" or "p=_".

Patch factors flag-scanning into ddebug_parse_flag_settings(),
and uses it for both filter-flags and new flags, and adds pr_err()
where useful.

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

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 37f9748..275cf30 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -180,7 +180,8 @@ static bool query_matches_callsite(struct _ddebug *dp,
  * were matched.  Called with ddebug_lock held.
  */
 static int ddebug_change(const struct ddebug_query *query,
-			unsigned int flags, unsigned int mask)
+			unsigned int flags, unsigned int mask,
+			unsigned int filter)
 {
 	int i;
 	struct ddebug_table *dt;
@@ -202,6 +203,9 @@ static int ddebug_change(const struct ddebug_query *query,
 			if (!query_matches_callsite(dp, query))
 				continue;
 
+			if (filter && (dp->flags & filter) != filter)
+				continue;
+
 			nfound++;
 
 			newflags = (dp->flags & mask) | flags;
@@ -402,28 +406,9 @@ static int ddebug_parse_query(char *words[], int nwords,
 	return 0;
 }
 
-/*
- * Parse `str' as a flags specification, format [-+=][p]+.
- * Sets up *maskp and *flagsp to be used when changing the
- * flags fields of matched _ddebug's.  Returns 0 on success
- * or <0 on error.
- */
-static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
-			       unsigned int *maskp)
+static int ddebug_parse_flag_settings(const char *str)
 {
-	unsigned flags = 0;
-	int op = '=', i;
-
-	switch (*str) {
-	case '+':
-	case '-':
-	case '=':
-		op = *str++;
-		break;
-	default:
-		return -EINVAL;
-	}
-	pr_debug("op='%c'\n", op);
+	int i, flags = 0;
 
 	for ( ; *str ; ++str) {
 		for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
@@ -432,12 +417,46 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
 				break;
 			}
 		}
-		if (i < 0)
+		if (i < 0 && *str) {
+			pr_err("unknown flag: %c\n", *str);
 			return -EINVAL;
+		}
 	}
-	if (flags == 0)
+	return flags;
+}
+
+/*
+ * Parse `str' as a flags filter and specification, with format
+ * [ptlmfa]*[-+=][ptlmfa]+.  Sets up *maskp, *flagsp and *filterp to
+ * be used when changing the flags fields of matched _ddebug's.
+ * Returns 0 on success or <0 on error.
+ */
+static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
+			unsigned int *maskp, unsigned int *filterp)
+{
+	int flags, filter;
+	int op = '=';
+	char *s = strpbrk(str, "+-=");
+
+	if (!s) {
+		pr_err("flags spec missing op, expecting [+-=]\n");
 		return -EINVAL;
-	pr_debug("flags=0x%x\n", flags);
+	} else {
+		op = *s;
+		*s++ = '\0';
+	}
+	filter = ddebug_parse_flag_settings(str);
+	if (filter < 0) {
+		pr_err("flags_filter=0x%x\n", filter);
+		return -EINVAL;
+	}
+	*filterp = filter;
+
+	flags = ddebug_parse_flag_settings(s);
+	if (flags < 0) {
+		pr_err("flags=0x%x\n", flags);
+		return -EINVAL;
+	}
 
 	/* calculate final *flagsp, *maskp according to mask and op */
 	switch (op) {
@@ -454,7 +473,9 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
 		*flagsp = 0;
 		break;
 	}
-	pr_debug("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
+	pr_debug("filter=0x%x op='%c' flags=0x%x *flagsp=0x%x *maskp=0x%x\n",
+		filter, op, flags, *flagsp, *maskp);
+
 	return 0;
 }
 
@@ -539,7 +560,7 @@ static int ddebug_save_pending(struct ddebug_query *query,
 
 static int ddebug_exec_query(char *query_string)
 {
-	unsigned int flags = 0, mask = 0;
+	unsigned int flags = 0, mask = 0, filter = 0;
 	struct ddebug_query query;
 #define MAXWORDS 9
 	int nwords;
@@ -551,12 +572,12 @@ static int ddebug_exec_query(char *query_string)
 		return -EINVAL;
 	if (ddebug_parse_query(words, nwords-1, &query))
 		return -EINVAL;
-	if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
+	if (ddebug_parse_flags(words[nwords-1], &flags, &mask, &filter))
 		return -EINVAL;
 
 	/* actually go and implement the change */
 	mutex_lock(&ddebug_lock);
-	nfound = ddebug_change(&query, flags, mask);
+	nfound = ddebug_change(&query, flags, mask, filter);
 	qstr = show_ddebug_query(&query);
 	pr_debug("nfound %d on %s\n", nfound, qstr);
 	if (!nfound) {
@@ -917,7 +938,7 @@ static void apply_pending_queries(struct ddebug_table *dt)
 	char *qstr;
 
 	list_for_each_entry_safe(pq, pqnext, &pending_queries, link) {
-		nfound = ddebug_change(&pq->query, pq->flags, pq->mask);
+		nfound = ddebug_change(&pq->query, pq->flags, pq->mask, 0);
 		qstr = show_pending_query(pq);
 		pr_debug("%s: %s\n", (nfound) ? "applied" : "no-match", qstr);
 		kfree(qstr);
-- 
1.7.4.1


  parent reply	other threads:[~2011-07-25 21:43 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-25 21:42 [patch 00/25] dynamic_debug: multiple, pending queries in boot-arg Jim Cromie
2011-07-25 21:42 ` [PATCH 01/25] dynamic_debug: add pending flag 'a' to make pending queries explicit Jim Cromie
2011-07-25 21:42 ` [PATCH 02/25] dynamic_debug: change verbosity at runtime Jim Cromie
2011-07-25 21:42 ` [PATCH 03/25] dynamic_debug: use pr_debug instead of pr_info Jim Cromie
2011-07-26  7:08   ` Bart Van Assche
2011-07-27 21:34     ` Jim Cromie
2011-07-28  9:18       ` Bart Van Assche
2011-07-28 18:24         ` Jason Baron
2011-07-28 21:15           ` Jim Cromie
2011-08-03 18:27             ` Jason Baron
2011-08-03 19:52               ` Jim Cromie
2011-08-10 17:14                 ` Jason Baron
2011-08-10 19:28                   ` Jim Cromie
2011-07-25 21:42 ` [PATCH 04/25] dynamic_debug: replace strcpy with strlcpy, in ddebug_setup_query() Jim Cromie
2011-07-25 21:42 ` [PATCH 05/25] dynamic_debug: trim source-path prefix from dynamic_debug/control Jim Cromie
2011-07-25 21:42 ` [PATCH 06/25] dynamic_debug: process multiple commands on a line Jim Cromie
2011-07-25 21:42 ` [PATCH 07/25] dynamic_debug: enlarge command/query write buffer Jim Cromie
2011-07-25 21:42 ` [PATCH 08/25] dynamic_debug: warn when >1 of each type of match-spec is given Jim Cromie
2011-07-25 21:42 ` [PATCH 09/25] dynamic_debug: pr_err() call should not depend upon verbosity Jim Cromie
2011-07-25 21:42 ` [PATCH 10/25] dynamic_debug: dont kill entire facility on error parsing ddebug_query Jim Cromie
2011-07-25 21:42 ` [PATCH 11/25] dynamic_debug: factor show_ddebug_query out of ddebug_parse_query Jim Cromie
2011-07-26  7:13   ` Bart Van Assche
2011-07-26  7:15   ` Bart Van Assche
2011-07-26 16:21     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 12/25] dynamic_debug: save non-matching queries to pending-list for later application Jim Cromie
2011-07-25 21:42 ` [PATCH 13/25] dynamic_debug: apply_pending_queries() from ddebug_add_module() Jim Cromie
2011-07-25 21:42 ` [PATCH 14/25] dynamic_debug: refactor query_matches_callsite out of ddebug_change Jim Cromie
2011-07-25 21:42 ` [PATCH 15/25] dynamic_debug: remove explicit foo != NULL checks Jim Cromie
2011-07-25 21:42 ` [PATCH 16/25] dynamic_debug: require 'a' flag to explicitly mark pending queries Jim Cromie
2011-07-26  7:26   ` Bart Van Assche
2011-07-27 17:27     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 17/25] dynamic_debug: hoist locking in ddebug_change to callers Jim Cromie
2011-07-25 21:42 ` [PATCH 18/25] dynamic_debug: describe_flags with '=[pmflta_]*' Jim Cromie
2011-07-26  7:37   ` Bart Van Assche
2011-07-27 17:28     ` Jim Cromie
2011-07-25 21:42 ` Jim Cromie [this message]
2011-07-25 21:42 ` [PATCH 20/25] dynamic_debug: remove pending query when flags zeroed Jim Cromie
2011-07-25 21:42 ` [PATCH 21/25] dynamic_debug: shrink struct pending query to size actually needed Jim Cromie
2011-07-26  7:32   ` Bart Van Assche
2011-07-27 18:41     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 22/25] dynamic_debug: call ddebug_add_module() on dynamic_debug first Jim Cromie
2011-07-25 21:42 ` [PATCH 23/25] dynamic_debug: document pending queries, flags-filter, multiple queries Jim Cromie
2011-07-25 21:42 ` [PATCH 24/25] dynamic_debug: drop pr_fmt() from dynamic_pr_debug Jim Cromie
2011-07-26  2:23   ` Joe Perches
2011-07-26  3:45   ` Joe Perches
2011-07-26  5:54     ` Jim Cromie
2011-07-25 21:42 ` [PATCH 25/25] dynamic_debug: add $DBGFS/dynamic_debug/pending Jim Cromie

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=1311630170-26057-20-git-send-email-jim.cromie@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=bvanassche@acm.org \
    --cc=gnb@fmeh.org \
    --cc=gregkh@suse.de \
    --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

all inboxes | Powered by JetHome®