* [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
@ 2009-07-16 16:51 Jiri Olsa
2009-07-17 9:37 ` Li Zefan
2009-07-21 1:11 ` Steven Rostedt
0 siblings, 2 replies; 9+ messages in thread
From: Jiri Olsa @ 2009-07-16 16:51 UTC (permalink / raw)
To: Ingo Molnar, Steven Rostedt; +Cc: lkml
If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
with read&write permissions, the previous setup will be removed.
Tested with following program:
[snip]
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
FILE *f;
char *mode = "w+";
char *file = argv[1];
if (argc == 3)
mode = argv[2];
if (NULL == (f = fopen(file, mode))) {
perror("fopen failed");
return -1;
}
while(!feof(f)) {
#define BUFLEN 100
char buf[BUFLEN];
memset(buf, 0, BUFLEN);
fgets(buf, BUFLEN, f);
printf(buf);
}
fclose(f);
return 0;
}
[snip]
wbr,
jirka
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 4521c77..11394bc 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1661,10 +1661,6 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
return -ENOMEM;
mutex_lock(&ftrace_regex_lock);
- if ((file->f_mode & FMODE_WRITE) &&
- !(file->f_flags & O_APPEND))
- ftrace_filter_reset(enable);
-
if (file->f_mode & FMODE_READ) {
iter->pg = ftrace_pages_start;
iter->flags = enable ? FTRACE_ITER_FILTER :
@@ -2260,6 +2256,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
return 0;
mutex_lock(&ftrace_regex_lock);
+ if ((file->f_mode & FMODE_WRITE) &&
+ !(file->f_flags & O_APPEND))
+ ftrace_filter_reset(enable);
if (file->f_mode & FMODE_READ) {
struct seq_file *m = file->private_data;
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-16 16:51 [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm Jiri Olsa
@ 2009-07-17 9:37 ` Li Zefan
2009-07-17 11:10 ` Jiri Olsa
2009-07-21 1:11 ` Steven Rostedt
1 sibling, 1 reply; 9+ messages in thread
From: Li Zefan @ 2009-07-17 9:37 UTC (permalink / raw)
To: Jiri Olsa; +Cc: Ingo Molnar, Steven Rostedt, lkml
Jiri Olsa wrote:
> If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
> with read&write permissions, the previous setup will be removed.
>
Currently:
# echo 'sys_open sys_close' > set_ftrace_filter
# cat set_ftrace_filter
sys_open
sys_close
After your patch:
# echo 'sys_open sys_close' > set_ftrace_filter
# cat set_ftrace_filter
sys_close
> Tested with following program:
...
>
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
>
> ---
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 4521c77..11394bc 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1661,10 +1661,6 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
> return -ENOMEM;
>
> mutex_lock(&ftrace_regex_lock);
> - if ((file->f_mode & FMODE_WRITE) &&
> - !(file->f_flags & O_APPEND))
> - ftrace_filter_reset(enable);
> -
> if (file->f_mode & FMODE_READ) {
> iter->pg = ftrace_pages_start;
> iter->flags = enable ? FTRACE_ITER_FILTER :
> @@ -2260,6 +2256,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> return 0;
>
> mutex_lock(&ftrace_regex_lock);
> + if ((file->f_mode & FMODE_WRITE) &&
> + !(file->f_flags & O_APPEND))
> + ftrace_filter_reset(enable);
>
> if (file->f_mode & FMODE_READ) {
> struct seq_file *m = file->private_data;
> --
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-17 9:37 ` Li Zefan
@ 2009-07-17 11:10 ` Jiri Olsa
2009-07-20 0:55 ` Li Zefan
0 siblings, 1 reply; 9+ messages in thread
From: Jiri Olsa @ 2009-07-17 11:10 UTC (permalink / raw)
To: Li Zefan; +Cc: Ingo Molnar, Steven Rostedt, lkml
On Fri, Jul 17, 2009 at 05:37:24PM +0800, Li Zefan wrote:
> Jiri Olsa wrote:
> > If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
> > with read&write permissions, the previous setup will be removed.
> >
>
> Currently:
>
> # echo 'sys_open sys_close' > set_ftrace_filter
> # cat set_ftrace_filter
> sys_open
> sys_close
>
> After your patch:
>
> # echo 'sys_open sys_close' > set_ftrace_filter
> # cat set_ftrace_filter
> sys_close
>
oops, sry I missed this..
Following patch adds new FTRACE_ITER_RESET flag, as the decision needs
to be taken in "open" and applied in "write". I'm not sure whats the
policy for adding new flags, but it looks ok to me.
wbr,
jirka
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 4521c77..29c4b67 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1364,6 +1364,7 @@ enum {
FTRACE_ITER_FAILURES = (1 << 3),
FTRACE_ITER_PRINTALL = (1 << 4),
FTRACE_ITER_HASH = (1 << 5),
+ FTRACE_ITER_RESET = (1 << 6),
};
#define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
@@ -1663,11 +1664,11 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
mutex_lock(&ftrace_regex_lock);
if ((file->f_mode & FMODE_WRITE) &&
!(file->f_flags & O_APPEND))
- ftrace_filter_reset(enable);
+ iter->flags |= FTRACE_ITER_RESET;
if (file->f_mode & FMODE_READ) {
iter->pg = ftrace_pages_start;
- iter->flags = enable ? FTRACE_ITER_FILTER :
+ iter->flags |= enable ? FTRACE_ITER_FILTER :
FTRACE_ITER_NOTRACE;
ret = seq_open(file, &show_ftrace_seq_ops);
@@ -2267,6 +2268,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
} else
iter = file->private_data;
+ if (iter->flags & FTRACE_ITER_RESET) {
+ ftrace_filter_reset(enable);
+ iter->flags &= ~FTRACE_ITER_RESET;
+ }
+
if (!*ppos) {
iter->flags &= ~FTRACE_ITER_CONT;
iter->buffer_idx = 0;
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-17 11:10 ` Jiri Olsa
@ 2009-07-20 0:55 ` Li Zefan
2009-07-20 1:32 ` Frederic Weisbecker
0 siblings, 1 reply; 9+ messages in thread
From: Li Zefan @ 2009-07-20 0:55 UTC (permalink / raw)
To: Jiri Olsa; +Cc: Ingo Molnar, Steven Rostedt, lkml
Jiri Olsa wrote:
> On Fri, Jul 17, 2009 at 05:37:24PM +0800, Li Zefan wrote:
>> Jiri Olsa wrote:
>>> If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
>>> with read&write permissions, the previous setup will be removed.
>>>
>> Currently:
>>
>> # echo 'sys_open sys_close' > set_ftrace_filter
>> # cat set_ftrace_filter
>> sys_open
>> sys_close
>>
>> After your patch:
>>
>> # echo 'sys_open sys_close' > set_ftrace_filter
>> # cat set_ftrace_filter
>> sys_close
>>
>
> oops, sry I missed this..
>
> Following patch adds new FTRACE_ITER_RESET flag, as the decision needs
> to be taken in "open" and applied in "write". I'm not sure whats the
> policy for adding new flags, but it looks ok to me.
>
I have no strong opinion whether to do the reset in "open" or in first
"write".
All said, I think this is cleaner, without introducing a new flag:
@@ -2260,6 +2256,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
return 0;
mutex_lock(&ftrace_regex_lock);
+ if (file->f_pos == 0 &&
+ (file->f_mode & FMODE_WRITE) && !(file->f_flags & O_APPEND))
+ ftrace_filter_reset(enable);
if (file->f_mode & FMODE_READ) {
struct seq_file *m = file->private_data;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-20 0:55 ` Li Zefan
@ 2009-07-20 1:32 ` Frederic Weisbecker
2009-07-22 12:19 ` Jiri Olsa
0 siblings, 1 reply; 9+ messages in thread
From: Frederic Weisbecker @ 2009-07-20 1:32 UTC (permalink / raw)
To: Li Zefan; +Cc: Jiri Olsa, Ingo Molnar, Steven Rostedt, lkml
On Mon, Jul 20, 2009 at 08:55:54AM +0800, Li Zefan wrote:
> Jiri Olsa wrote:
> > On Fri, Jul 17, 2009 at 05:37:24PM +0800, Li Zefan wrote:
> >> Jiri Olsa wrote:
> >>> If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
> >>> with read&write permissions, the previous setup will be removed.
> >>>
> >> Currently:
> >>
> >> # echo 'sys_open sys_close' > set_ftrace_filter
> >> # cat set_ftrace_filter
> >> sys_open
> >> sys_close
> >>
> >> After your patch:
> >>
> >> # echo 'sys_open sys_close' > set_ftrace_filter
> >> # cat set_ftrace_filter
> >> sys_close
> >>
> >
> > oops, sry I missed this..
> >
> > Following patch adds new FTRACE_ITER_RESET flag, as the decision needs
> > to be taken in "open" and applied in "write". I'm not sure whats the
> > policy for adding new flags, but it looks ok to me.
> >
>
> I have no strong opinion whether to do the reset in "open" or in first
> "write".
>
> All said, I think this is cleaner, without introducing a new flag:
>
> @@ -2260,6 +2256,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> return 0;
>
> mutex_lock(&ftrace_regex_lock);
> + if (file->f_pos == 0 &&
> + (file->f_mode & FMODE_WRITE) && !(file->f_flags & O_APPEND))
> + ftrace_filter_reset(enable);
>
> if (file->f_mode & FMODE_READ) {
> struct seq_file *m = file->private_data;
Yeah, that avoids this need of creating a new flag.
Looks like a good solution.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-16 16:51 [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm Jiri Olsa
2009-07-17 9:37 ` Li Zefan
@ 2009-07-21 1:11 ` Steven Rostedt
2009-07-22 7:42 ` Jiri Olsa
1 sibling, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2009-07-21 1:11 UTC (permalink / raw)
To: Jiri Olsa; +Cc: Ingo Molnar, lkml, Li Zefan, Frederic Weisbecker
On Thu, 16 Jul 2009, Jiri Olsa wrote:
> If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
> with read&write permissions, the previous setup will be removed.
This is exactly what it was suppose to do.
man fopen:
w+ Open for reading and writing. The file is created if it does
not exist, otherwise it is truncated. The stream is positioned
at the beginning of the file.
Which means that if you open a file for "w+" it will truncate it. Hence,
you will remove all previous settings.
What you want is:
a+ Open for reading and appending (writing at end of file). The
file is created if it does not exist. The initial file position
for reading is at the beginning of the file, but output is
always appended to the end of the file.
Change the belowe code from "w+" to "a+" and you get your expected result.
Thus, the current code is correct.
-- Steve
>
> Tested with following program:
>
> [snip]
> #include <stdio.h>
> #include <string.h>
>
> int main(int argc, char **argv)
> {
> FILE *f;
> char *mode = "w+";
> char *file = argv[1];
>
> if (argc == 3)
> mode = argv[2];
>
> if (NULL == (f = fopen(file, mode))) {
> perror("fopen failed");
> return -1;
> }
>
> while(!feof(f)) {
> #define BUFLEN 100
> char buf[BUFLEN];
> memset(buf, 0, BUFLEN);
> fgets(buf, BUFLEN, f);
> printf(buf);
> }
>
> fclose(f);
> return 0;
> }
> [snip]
>
> wbr,
> jirka
>
>
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
>
> ---
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 4521c77..11394bc 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1661,10 +1661,6 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
> return -ENOMEM;
>
> mutex_lock(&ftrace_regex_lock);
> - if ((file->f_mode & FMODE_WRITE) &&
> - !(file->f_flags & O_APPEND))
> - ftrace_filter_reset(enable);
> -
> if (file->f_mode & FMODE_READ) {
> iter->pg = ftrace_pages_start;
> iter->flags = enable ? FTRACE_ITER_FILTER :
> @@ -2260,6 +2256,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> return 0;
>
> mutex_lock(&ftrace_regex_lock);
> + if ((file->f_mode & FMODE_WRITE) &&
> + !(file->f_flags & O_APPEND))
> + ftrace_filter_reset(enable);
>
> if (file->f_mode & FMODE_READ) {
> struct seq_file *m = file->private_data;
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-21 1:11 ` Steven Rostedt
@ 2009-07-22 7:42 ` Jiri Olsa
2009-07-22 15:19 ` Steven Rostedt
0 siblings, 1 reply; 9+ messages in thread
From: Jiri Olsa @ 2009-07-22 7:42 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Ingo Molnar, lkml, Li Zefan, Frederic Weisbecker
On Mon, Jul 20, 2009 at 09:11:34PM -0400, Steven Rostedt wrote:
>
> On Thu, 16 Jul 2009, Jiri Olsa wrote:
>
> > If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
> > with read&write permissions, the previous setup will be removed.
>
> This is exactly what it was suppose to do.
>
> man fopen:
>
> w+ Open for reading and writing. The file is created if it does
> not exist, otherwise it is truncated. The stream is positioned
> at the beginning of the file.
>
> Which means that if you open a file for "w+" it will truncate it. Hence,
> you will remove all previous settings.
>
> What you want is:
>
> a+ Open for reading and appending (writing at end of file). The
> file is created if it does not exist. The initial file position
> for reading is at the beginning of the file, but output is
> always appended to the end of the file.
>
> Change the belowe code from "w+" to "a+" and you get your expected result.
My point was that if you open set_ftrace_filter/set_ftrace_notrace with just O_RDWR
perm. and will use the file just for reading, the filter will reset.
You're right about the "w+", there's the O_CREAT|O_TRUNC, sry I missed that.. ;)
Anyway with "r+" you'll get O_RDWR perm. only, showing the issue:
sh-4.0# echo "sys_open sys_write" > ./set_ftrace_filter
sh-4.0# cat ./set_ftrace_filter
sys_open
sys_write
sh-4.0# /ft ./set_ftrace_filter r+
#### all functions enabled ####
sh-4.0# cat ./set_ftrace_filter
#### all functions enabled ####
sh-4.0#
wbr,
jirka
>
> Thus, the current code is correct.
>
> -- Steve
>
>
>
> >
> > Tested with following program:
> >
> > [snip]
> > #include <stdio.h>
> > #include <string.h>
> >
> > int main(int argc, char **argv)
> > {
> > FILE *f;
> > char *mode = "w+";
> > char *file = argv[1];
> >
> > if (argc == 3)
> > mode = argv[2];
> >
> > if (NULL == (f = fopen(file, mode))) {
> > perror("fopen failed");
> > return -1;
> > }
> >
> > while(!feof(f)) {
> > #define BUFLEN 100
> > char buf[BUFLEN];
> > memset(buf, 0, BUFLEN);
> > fgets(buf, BUFLEN, f);
> > printf(buf);
> > }
> >
> > fclose(f);
> > return 0;
> > }
> > [snip]
> >
> > wbr,
> > jirka
> >
> >
> > Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> >
> > ---
> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> > index 4521c77..11394bc 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -1661,10 +1661,6 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
> > return -ENOMEM;
> >
> > mutex_lock(&ftrace_regex_lock);
> > - if ((file->f_mode & FMODE_WRITE) &&
> > - !(file->f_flags & O_APPEND))
> > - ftrace_filter_reset(enable);
> > -
> > if (file->f_mode & FMODE_READ) {
> > iter->pg = ftrace_pages_start;
> > iter->flags = enable ? FTRACE_ITER_FILTER :
> > @@ -2260,6 +2256,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> > return 0;
> >
> > mutex_lock(&ftrace_regex_lock);
> > + if ((file->f_mode & FMODE_WRITE) &&
> > + !(file->f_flags & O_APPEND))
> > + ftrace_filter_reset(enable);
> >
> > if (file->f_mode & FMODE_READ) {
> > struct seq_file *m = file->private_data;
> >
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-20 1:32 ` Frederic Weisbecker
@ 2009-07-22 12:19 ` Jiri Olsa
0 siblings, 0 replies; 9+ messages in thread
From: Jiri Olsa @ 2009-07-22 12:19 UTC (permalink / raw)
To: Frederic Weisbecker; +Cc: Li Zefan, Ingo Molnar, Steven Rostedt, lkml
On Sun, Jul 19, 2009 at 09:32:25PM -0400, Frederic Weisbecker wrote:
> On Mon, Jul 20, 2009 at 08:55:54AM +0800, Li Zefan wrote:
> > Jiri Olsa wrote:
> > > On Fri, Jul 17, 2009 at 05:37:24PM +0800, Li Zefan wrote:
> > >> Jiri Olsa wrote:
> > >>> If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
> > >>> with read&write permissions, the previous setup will be removed.
> > >>>
> > >> Currently:
> > >>
> > >> # echo 'sys_open sys_close' > set_ftrace_filter
> > >> # cat set_ftrace_filter
> > >> sys_open
> > >> sys_close
> > >>
> > >> After your patch:
> > >>
> > >> # echo 'sys_open sys_close' > set_ftrace_filter
> > >> # cat set_ftrace_filter
> > >> sys_close
> > >>
> > >
> > > oops, sry I missed this..
> > >
> > > Following patch adds new FTRACE_ITER_RESET flag, as the decision needs
> > > to be taken in "open" and applied in "write". I'm not sure whats the
> > > policy for adding new flags, but it looks ok to me.
> > >
> >
> > I have no strong opinion whether to do the reset in "open" or in first
> > "write".
> >
> > All said, I think this is cleaner, without introducing a new flag:
> >
> > @@ -2260,6 +2256,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> > return 0;
> >
> > mutex_lock(&ftrace_regex_lock);
> > + if (file->f_pos == 0 &&
> > + (file->f_mode & FMODE_WRITE) && !(file->f_flags & O_APPEND))
> > + ftrace_filter_reset(enable);
> >
> > if (file->f_mode & FMODE_READ) {
> > struct seq_file *m = file->private_data;
>
>
> Yeah, that avoids this need of creating a new flag.
> Looks like a good solution.
>
yes, but this wont work unless the *ppos value is updated instead of the
file->f_pos, because of:
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
size_t, count)
{
[snip]
loff_t pos = file_pos_read(file);
ret = vfs_write(file, buf, count, &pos);
file_pos_write(file, pos);
[snip]
Together with this fix I included fix for FTRACE_ITER_CONT flag, since
it does not seem to work correctly.
As far as I understand the reason for FTRACE_ITER_CONT flag is when
there's one regexp. in more write calls. I made a program to test it.
[snip]
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, char **argv)
{
int fd, i;
char *file = argv[1];
if (-1 == (fd = open(file, O_WRONLY))) {
perror("open failed");
return -1;
}
for(i = 0; i < (argc - 2); i++) {
int len = strlen(argv[2+i]);
int cnt, off = 0;
while(len) {
cnt = write(fd, argv[2+i] + off, len);
len -= cnt;
off += cnt;
}
}
close(fd);
return 0;
}
[snip]
I got following behaviour on the current tip master:
sh-4.0# /tst ./set_ftrace_filter sys_o "pen "
sh-4.0# cat ./set_ftrace_filter
#### all functions enabled ####
wbr,
jirka
---
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 24e3ff5..041a327 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1616,10 +1616,6 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)
return -ENOMEM;
mutex_lock(&ftrace_regex_lock);
- if ((file->f_mode & FMODE_WRITE) &&
- !(file->f_flags & O_APPEND))
- ftrace_filter_reset(enable);
-
if (file->f_mode & FMODE_READ) {
iter->pg = ftrace_pages_start;
iter->flags = enable ? FTRACE_ITER_FILTER :
@@ -2225,6 +2221,10 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
if (!*ppos) {
iter->flags &= ~FTRACE_ITER_CONT;
iter->buffer_idx = 0;
+
+ if ((file->f_mode & FMODE_WRITE) &&
+ !(file->f_flags & O_APPEND))
+ ftrace_filter_reset(enable);
}
ret = get_user(ch, ubuf++);
@@ -2233,7 +2233,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
read++;
cnt--;
- if (!(iter->flags & ~FTRACE_ITER_CONT)) {
+ /*
+ * If the parses havent finished with the last write,
+ * continue reading the user input without skipping spaces.
+ */
+ if (!(iter->flags & FTRACE_ITER_CONT)) {
/* skip white space */
while (cnt && isspace(ch)) {
ret = get_user(ch, ubuf++);
@@ -2243,8 +2247,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
cnt--;
}
+ /* only spaces were written */
if (isspace(ch)) {
- file->f_pos += read;
+ *ppos += read;
ret = read;
goto out;
}
@@ -2273,12 +2278,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
if (ret)
goto out;
iter->buffer_idx = 0;
- } else
+ } else {
iter->flags |= FTRACE_ITER_CONT;
+ iter->buffer[iter->buffer_idx++] = ch;
+ }
-
- file->f_pos += read;
-
+ *ppos += read;
ret = read;
out:
mutex_unlock(&ftrace_regex_lock);
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm
2009-07-22 7:42 ` Jiri Olsa
@ 2009-07-22 15:19 ` Steven Rostedt
0 siblings, 0 replies; 9+ messages in thread
From: Steven Rostedt @ 2009-07-22 15:19 UTC (permalink / raw)
To: Jiri Olsa; +Cc: Ingo Molnar, lkml, Li Zefan, Frederic Weisbecker
On Wed, 22 Jul 2009, Jiri Olsa wrote:
> On Mon, Jul 20, 2009 at 09:11:34PM -0400, Steven Rostedt wrote:
> >
> > On Thu, 16 Jul 2009, Jiri Olsa wrote:
> >
> > > If user setup set_ftrace_filter/set_ftrace_notrace files and then opens them
> > > with read&write permissions, the previous setup will be removed.
> >
> > This is exactly what it was suppose to do.
> >
> > man fopen:
> >
> > w+ Open for reading and writing. The file is created if it does
> > not exist, otherwise it is truncated. The stream is positioned
> > at the beginning of the file.
> >
> > Which means that if you open a file for "w+" it will truncate it. Hence,
> > you will remove all previous settings.
> >
> > What you want is:
> >
> > a+ Open for reading and appending (writing at end of file). The
> > file is created if it does not exist. The initial file position
> > for reading is at the beginning of the file, but output is
> > always appended to the end of the file.
> >
> > Change the belowe code from "w+" to "a+" and you get your expected result.
>
> My point was that if you open set_ftrace_filter/set_ftrace_notrace with just O_RDWR
> perm. and will use the file just for reading, the filter will reset.
>
> You're right about the "w+", there's the O_CREAT|O_TRUNC, sry I missed that.. ;)
> Anyway with "r+" you'll get O_RDWR perm. only, showing the issue:
Ah, then the fix would be to check against O_TRUNC.
-- Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-07-22 15:19 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-16 16:51 [PATCH] tracing: dont reset set_ftrace_filter/notrace when opened with r/w perm Jiri Olsa
2009-07-17 9:37 ` Li Zefan
2009-07-17 11:10 ` Jiri Olsa
2009-07-20 0:55 ` Li Zefan
2009-07-20 1:32 ` Frederic Weisbecker
2009-07-22 12:19 ` Jiri Olsa
2009-07-21 1:11 ` Steven Rostedt
2009-07-22 7:42 ` Jiri Olsa
2009-07-22 15:19 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox