Skip to content

Commit 9898abb

Browse files
Greg Banksgregkh
authored andcommitted
Dynamic debug: allow simple quoting of words
Allow simple quoting of words in the dynamic debug control language. This allows more natural specification when using the control language to match against printk formats, e.g #echo -n 'format "Setting node for non-present cpu" +p' > /mnt/debugfs/dynamic_debug/control instead of #echo -n 'format Setting\040node\040for\040non-present\040cpu +p' > /mnt/debugfs/dynamic_debug/control Adjust the dynamic debug documention to describe that and provide a new example. Adjust the existing examples in the documentation to reflect the current whitespace escaping behaviour when reading the control file. Fix some minor documentation trailing whitespace. Signed-off-by: Greg Banks <gnb@melbourne.sgi.com> Acked-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 86151fd commit 9898abb

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

Documentation/dynamic-debug-howto.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ via:
4949

5050
nullarbor:~ # cat <debugfs>/dynamic_debug/control
5151
# filename:lineno [module]function flags format
52-
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:323 [svcxprt_rdma]svc_rdma_cleanup - "SVCRDMA\040Module\040Removed,\040deregister\040RPC\040RDMA\040transport\012"
53-
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:341 [svcxprt_rdma]svc_rdma_init - "\011max_inline\040\040\040\040\040\040\040:\040%d\012"
54-
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:340 [svcxprt_rdma]svc_rdma_init - "\011sq_depth\040\040\040\040\040\040\040\040\040:\040%d\012"
55-
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:338 [svcxprt_rdma]svc_rdma_init - "\011max_requests\040\040\040\040\040:\040%d\012"
52+
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:323 [svcxprt_rdma]svc_rdma_cleanup - "SVCRDMA Module Removed, deregister RPC RDMA transport\012"
53+
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:341 [svcxprt_rdma]svc_rdma_init - "\011max_inline : %d\012"
54+
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:340 [svcxprt_rdma]svc_rdma_init - "\011sq_depth : %d\012"
55+
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:338 [svcxprt_rdma]svc_rdma_init - "\011max_requests : %d\012"
5656
...
5757

5858

@@ -72,7 +72,7 @@ you can view all the debug statement callsites with any non-default flags:
7272

7373
nullarbor:~ # awk '$3 != "-"' <debugfs>/dynamic_debug/control
7474
# filename:lineno [module]function flags format
75-
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c:1603 [sunrpc]svc_send p "svc_process:\040st_sendto\040returned\040%d\012"
75+
/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c:1603 [sunrpc]svc_send p "svc_process: st_sendto returned %d\012"
7676

7777

7878
Command Language Reference
@@ -166,11 +166,15 @@ format
166166
entire format, only some part. Whitespace and other
167167
special characters can be escaped using C octal character
168168
escape \ooo notation, e.g. the space character is \040.
169+
Alternatively, the string can be enclosed in double quote
170+
characters (") or single quote characters (').
169171
Examples:
170172

171173
format svcrdma: // many of the NFS/RDMA server dprintks
172174
format readahead // some dprintks in the readahead cache
173-
format nfsd:\040SETATTR // how to match a format with whitespace
175+
format nfsd:\040SETATTR // one way to match a format with whitespace
176+
format "nfsd: SETATTR" // a neater way to match a format with whitespace
177+
format 'nfsd: SETATTR' // yet another way to match a format with whitespace
174178

175179
line
176180
The given line number or range of line numbers is compared
@@ -230,3 +234,7 @@ nullarbor:~ # echo -n 'func svc_process +p' >
230234
// disable all 12 messages in the function svc_process()
231235
nullarbor:~ # echo -n 'func svc_process -p' >
232236
<debugfs>/dynamic_debug/control
237+
238+
// enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
239+
nullarbor:~ # echo -n 'format "nfsd: READ" +p' >
240+
<debugfs>/dynamic_debug/control

lib/dynamic_debug.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,33 +195,46 @@ static void ddebug_change(const struct ddebug_query *query,
195195
printk(KERN_INFO "ddebug: no matches for query\n");
196196
}
197197

198-
/*
199-
* Wrapper around strsep() to collapse the multiple empty tokens
200-
* that it returns when fed sequences of separator characters.
201-
* Now, if we had strtok_r()...
202-
*/
203-
static inline char *nearly_strtok_r(char **p, const char *sep)
204-
{
205-
char *r;
206-
207-
while ((r = strsep(p, sep)) != NULL && *r == '\0')
208-
;
209-
return r;
210-
}
211-
212198
/*
213199
* Split the buffer `buf' into space-separated words.
214-
* Return the number of such words or <0 on error.
200+
* Handles simple " and ' quoting, i.e. without nested,
201+
* embedded or escaped \". Return the number of words
202+
* or <0 on error.
215203
*/
216204
static int ddebug_tokenize(char *buf, char *words[], int maxwords)
217205
{
218206
int nwords = 0;
219207

220-
while (nwords < maxwords &&
221-
(words[nwords] = nearly_strtok_r(&buf, " \t\r\n")) != NULL)
222-
nwords++;
223-
if (buf)
224-
return -EINVAL; /* ran out of words[] before bytes */
208+
while (*buf) {
209+
char *end;
210+
211+
/* Skip leading whitespace */
212+
while (*buf && isspace(*buf))
213+
buf++;
214+
if (!*buf)
215+
break; /* oh, it was trailing whitespace */
216+
217+
/* Run `end' over a word, either whitespace separated or quoted */
218+
if (*buf == '"' || *buf == '\'') {
219+
int quote = *buf++;
220+
for (end = buf ; *end && *end != quote ; end++)
221+
;
222+
if (!*end)
223+
return -EINVAL; /* unclosed quote */
224+
} else {
225+
for (end = buf ; *end && !isspace(*end) ; end++)
226+
;
227+
BUG_ON(end == buf);
228+
}
229+
/* Here `buf' is the start of the word, `end' is one past the end */
230+
231+
if (nwords == maxwords)
232+
return -EINVAL; /* ran out of words[] before bytes */
233+
if (*end)
234+
*end++ = '\0'; /* terminate the word */
235+
words[nwords++] = buf;
236+
buf = end;
237+
}
225238

226239
if (verbose) {
227240
int i;

0 commit comments

Comments
 (0)