Commit 14f693ee authored by Jeremy Kerr's avatar Jeremy Kerr

powerpc/spufs: Don't require full buffer in switch_log read

Currently, read() on the sputrace log will block until the read buffer
is full. This makes it difficult to retrieve the end of the buffer, as
the user will need to read with the right-sized buffer.

In a similar method as 91553a1b5e0df006a3573a88d98ee7cd48a3818a, this
change makes the switch_log return if there has already been data
read.
Signed-off-by: default avatarJeremy Kerr <jk@ozlabs.org>
parent f5ed0eb6
...@@ -2503,15 +2503,21 @@ static ssize_t spufs_switch_log_read(struct file *file, char __user *buf, ...@@ -2503,15 +2503,21 @@ static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
char tbuf[128]; char tbuf[128];
int width; int width;
if (file->f_flags & O_NONBLOCK) {
if (spufs_switch_log_used(ctx) == 0) { if (spufs_switch_log_used(ctx) == 0) {
if (cnt > 0) {
/* If there's data ready to go, we can
* just return straight away */
break;
} else if (file->f_flags & O_NONBLOCK) {
error = -EAGAIN; error = -EAGAIN;
break; break;
}
} else { } else {
/* spufs_wait will drop the mutex and re-acquire, /* spufs_wait will drop the mutex and
* but since we're in read(), the file cannot be * re-acquire, but since we're in read(), the
* _released (and so ctx->switch_log is stable). * file cannot be _released (and so
* ctx->switch_log is stable).
*/ */
error = spufs_wait(ctx->switch_log->wait, error = spufs_wait(ctx->switch_log->wait,
spufs_switch_log_used(ctx) > 0); spufs_switch_log_used(ctx) > 0);
...@@ -2520,12 +2526,14 @@ static ssize_t spufs_switch_log_read(struct file *file, char __user *buf, ...@@ -2520,12 +2526,14 @@ static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
* state mutex held */ * state mutex held */
if (error) if (error)
return error; return error;
}
/* We may have had entries read from underneath us while we /* We may have had entries read from underneath
* dropped the mutex in spufs_wait, so re-check */ * us while we dropped the mutex in spufs_wait,
if (ctx->switch_log->head == ctx->switch_log->tail) * so re-check */
if (spufs_switch_log_used(ctx) == 0)
continue; continue;
}
}
width = switch_log_sprint(ctx, tbuf, sizeof(tbuf)); width = switch_log_sprint(ctx, tbuf, sizeof(tbuf));
if (width < len) if (width < len)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment