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

Change definition of flags spec to [ptlmfa]*[-+=][ptlmfa]+
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.

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

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 44ccc02..9514071 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -174,7 +174,8 @@ static int 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;
@@ -196,6 +197,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;
@@ -396,29 +400,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;
-	}
-	if (verbose)
-		pr_info("op='%c'\n", op);
+	int i, flags = 0;
 
 	for ( ; *str ; ++str) {
 		for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
@@ -427,13 +411,49 @@ 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;
+	} 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;
+	}
 	if (verbose)
-		pr_info("flags=0x%x\n", flags);
+		pr_info(" flags_filter=0x%x\n op='%c'\n flags=0x%x\n",
+			filter, op, flags);
 
 	/* calculate final *flagsp, *maskp according to mask and op */
 	switch (op) {
@@ -526,7 +546,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;
@@ -538,12 +558,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);
 	if (!nfound) {
 		if (flags & _DPRINTK_FLAGS_APPEND)
 			rc = ddebug_save_pending(&query, flags, mask);
@@ -921,8 +941,7 @@ static void apply_pending_queries(struct ddebug_table *dt)
 			pr_info("check: %s <-> %s\n",
 				dt->mod_name, show_pending_query(pq));
 
-		nfound = ddebug_change(&pq->query, pq->flags, pq->mask);
-
+		nfound = ddebug_change(&pq->query, pq->flags, pq->mask, 0);
 		if (nfound) {
 			list_del(&pq->link);
 			kfree(pq);
-- 
1.7.4.1


  parent reply	other threads:[~2011-07-11  7:48 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-28  7:09 [PATCH 0/11] dynamic_debug: allow multiple pending queries on boot-line Jim Cromie
2011-06-28  7:09 ` [PATCH 01/11] dynamic_debug: allow changing of dynamic_debug verbosity any time Jim Cromie
2011-06-29 10:41   ` Bart Van Assche
2011-07-01 21:57     ` Greg KH
2011-07-02  8:39       ` Jim Cromie
2011-06-28  7:09 ` [PATCH 02/11] dynamic_debug: trim source-path prefix from dynamic_debug/control Jim Cromie
2011-06-28 10:08   ` Bart Van Assche
2011-06-28 18:29     ` Jim Cromie
2011-06-28  7:09 ` [PATCH 03/11] dynamic_debug: process multiple commands on a line Jim Cromie
2011-06-29 10:50   ` Bart Van Assche
2011-07-05 16:12     ` Jim Cromie
2011-06-28  7:09 ` [PATCH 04/11] dynamic_debug: warn when >1 of each type of match-spec is given Jim Cromie
2011-06-28 10:17   ` Bart Van Assche
2011-06-28 15:21     ` Jim Cromie
2011-06-28  7:09 ` [PATCH 05/11] dynamic_debug: use pr_info instead of printk(KERN_INFO Jim Cromie
2011-06-28  7:09 ` [PATCH 06/11] dynamic_debug: KERN_ERR should not depend upon verbosity Jim Cromie
2011-06-28  7:09 ` [PATCH 07/11] dynamic_debug: dont kill entire facility on error parsing ddebug_query Jim Cromie
2011-06-28  7:09 ` [PATCH 08/11] dynamic_debug: return int from ddebug_change Jim Cromie
2011-06-28 10:24   ` Bart Van Assche
2011-06-28 14:54     ` Jason Baron
2011-06-28 17:48       ` Bart Van Assche
2011-06-28 18:24         ` Jim Cromie
2011-06-28  7:09 ` [PATCH 09/11] dynamic_debug: add_to_pending() saves non-matching queries for later Jim Cromie
2011-06-28 14:48   ` Jason Baron
2011-07-03  8:27     ` Bart Van Assche
2011-06-28 19:17   ` Jim Cromie
2011-07-03  8:24     ` Bart Van Assche
2011-07-03  8:32   ` Bart Van Assche
2011-06-28  7:09 ` [PATCH 10/11] dynamic_debug: call apply_pending_queries from ddebug_add_module Jim Cromie
2011-07-03  8:37   ` Bart Van Assche
2011-06-28  7:09 ` [PATCH 11/11] dynamic_debug: document use of pendinq queries at boot-time Jim Cromie
2011-07-03  8:19 ` [PATCH 0/11] dynamic_debug: allow multiple pending queries on boot-line Bart Van Assche
2011-07-11  7:46 ` Jim Cromie
2011-07-11  7:46   ` [PATCH 01/21] dynamic_debug: add pending flag 'a' to make pending queries explicit Jim Cromie
2011-07-11  7:46   ` [PATCH 02/21] dynamic_debug: allow changing of dynamic_debug verbosity any time Jim Cromie
2011-07-11  7:46   ` [PATCH 03/21] dynamic_debug: process multiple commands on a line Jim Cromie
2011-07-12  5:54     ` Bart Van Assche
2011-07-13  7:25       ` Jim Cromie
2011-07-13 17:44         ` Bart Van Assche
2011-07-11  7:46   ` [PATCH 04/21] dynamic_debug: warn when >1 of each type of match-spec is given Jim Cromie
2011-07-11  7:46   ` [PATCH 05/21] dynamic_debug: pr_err() call should not depend upon verbosity Jim Cromie
2011-07-11  7:46   ` [PATCH 06/21] dynamic_debug: dont kill entire facility on error parsing ddebug_query Jim Cromie
2011-07-11  7:46   ` [PATCH 07/21] dynamic_debug: return int from ddebug_change Jim Cromie
2011-07-11 18:39     ` Bart Van Assche
2011-07-11  7:46   ` [PATCH 08/21] dynamic_debug: factor show_ddebug_query out of ddebug_parse_query Jim Cromie
2011-07-11 18:36     ` Bart Van Assche
2011-07-16 21:32       ` Jim Cromie
2011-07-25 11:10         ` Bart Van Assche
2011-07-25 13:56           ` Jim Cromie
2011-07-11  7:46   ` [PATCH 09/21] dynamic_debug: save_pending() saves non-matching queries for later Jim Cromie
2011-07-11 18:32     ` Bart Van Assche
2011-07-12  5:55     ` Bart Van Assche
2011-07-11  7:46   ` [PATCH 10/21] dynamic_debug: call apply_pending_queries from ddebug_add_module Jim Cromie
2011-07-11  7:46   ` [PATCH 11/21] dynamic_debug: refactor query_matches_callsite out of ddebug_change Jim Cromie
2011-07-11  7:46   ` [PATCH 12/21] dynamic_debug: document use of pending queries at boot-time Jim Cromie
2011-07-11  7:46   ` [PATCH 13/21] dynamic_debug: require 'a' flag to explicitly mark pending queries Jim Cromie
2011-07-12  9:20     ` Bart Van Assche
2011-07-11  7:46   ` [PATCH 14/21] dynamic_debug: hoist locking in ddebug_change to callers Jim Cromie
2011-07-11  7:46   ` [PATCH 15/21] dynamic_debug: describe_flags with '=[ptmfl]*' Jim Cromie
2011-07-11  7:46   ` [PATCH 16/21] dynamic_debug: define several levels of verbosity Jim Cromie
2011-07-11  7:46   ` [PATCH 17/21] dynamic_debug: non-optimization - remove != NULL Jim Cromie
2011-07-11  7:46   ` [PATCH 18/21] dynamic_debug: trim source-path prefix from dynamic_debug/control Jim Cromie
2011-07-11  7:46   ` Jim Cromie [this message]
2011-07-11  7:46   ` [PATCH 20/21] dynamic_debug: clear pending_queries list in remove_all_tables Jim Cromie
2011-07-11  7:46   ` [PATCH 21/21] dynamic_debug: delete pending queries Jim Cromie
2011-07-11 10:49     ` Bart Van Assche
2011-07-11 13:43       ` Jim Cromie
2011-07-12  0:25     ` Joe Perches
2011-07-12 20:50       ` Jason Baron
2011-07-20  5:39         ` Jim Cromie
2011-07-20 17:43       ` Jim Cromie
2011-07-20 22:08         ` Joe Perches

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=1310370416-6322-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®