lkml.org 
[lkml]   [2009]   [Feb]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 1/2] trace: Move pipe waiting code out of tracing_read_pipe().
Date
This moves the pipe waiting code from tracing_read_pipe() into
tracing_wait_pipe(), which is useful to implement other fops, like
splice_read.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
---
kernel/trace/trace.c | 69 +++++++++++++++++++++++++++++---------------------
1 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ef4dbac..130c4f5 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2359,37 +2359,15 @@ tracing_poll_pipe(struct file *filp, poll_table *poll_table)
}
}

-/*
- * Consumer reader.
- */
-static ssize_t
-tracing_read_pipe(struct file *filp, char __user *ubuf,
- size_t cnt, loff_t *ppos)
+/* Must be called with trace_types_lock mutex held. */
+static int tracing_wait_pipe(struct file *filp)
{
struct trace_iterator *iter = filp->private_data;
- ssize_t sret;
-
- /* return any leftover data */
- sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
- if (sret != -EBUSY)
- return sret;
-
- trace_seq_reset(&iter->seq);

- mutex_lock(&trace_types_lock);
- if (iter->trace->read) {
- sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
- if (sret)
- goto out;
- }
-
-waitagain:
- sret = 0;
while (trace_empty(iter)) {

if ((filp->f_flags & O_NONBLOCK)) {
- sret = -EAGAIN;
- goto out;
+ return -EAGAIN;
}

/*
@@ -2414,12 +2392,11 @@ waitagain:
iter->tr->waiter = NULL;

if (signal_pending(current)) {
- sret = -EINTR;
- goto out;
+ return -EINTR;
}

if (iter->trace != current_trace)
- goto out;
+ return 0;

/*
* We block until we read something and tracing is disabled.
@@ -2436,9 +2413,43 @@ waitagain:
continue;
}

+ return 1;
+}
+
+/*
+ * Consumer reader.
+ */
+static ssize_t
+tracing_read_pipe(struct file *filp, char __user *ubuf,
+ size_t cnt, loff_t *ppos)
+{
+ struct trace_iterator *iter = filp->private_data;
+ ssize_t sret;
+
+ /* return any leftover data */
+ sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
+ if (sret != -EBUSY)
+ return sret;
+
+ trace_seq_reset(&iter->seq);
+
+ mutex_lock(&trace_types_lock);
+ if (iter->trace->read) {
+ sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
+ if (sret)
+ goto out;
+ }
+
+waitagain:
+ sret = tracing_wait_pipe(filp);
+ if (sret <= 0)
+ goto out;
+
/* stop when tracing is finished */
- if (trace_empty(iter))
+ if (trace_empty(iter)) {
+ sret = 0;
goto out;
+ }

if (cnt >= PAGE_SIZE)
cnt = PAGE_SIZE - 1;
--
1.6.0.6


\
 
 \ /
  Last update: 2009-02-09 07:19    [W:2.396 / U:1.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site