Commit a66e356c authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Linus Torvalds

relayfs: fix overwrites

When I use relayfs with "overwrite" mode, read() still sets incorrect
number of consumed bytes.
Signed-off-by: default avatarMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: default avatarTom Zanussi <zanussi@us.ibm.com>
Acked-by: default avatarDavid Wilder <dwilder@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8d62fdeb
...@@ -812,7 +812,10 @@ static void relay_file_read_consume(struct rchan_buf *buf, ...@@ -812,7 +812,10 @@ static void relay_file_read_consume(struct rchan_buf *buf,
} }
buf->bytes_consumed += bytes_consumed; buf->bytes_consumed += bytes_consumed;
read_subbuf = read_pos / buf->chan->subbuf_size; if (!read_pos)
read_subbuf = buf->subbufs_consumed % n_subbufs;
else
read_subbuf = read_pos / buf->chan->subbuf_size;
if (buf->bytes_consumed + buf->padding[read_subbuf] == subbuf_size) { if (buf->bytes_consumed + buf->padding[read_subbuf] == subbuf_size) {
if ((read_subbuf == buf->subbufs_produced % n_subbufs) && if ((read_subbuf == buf->subbufs_produced % n_subbufs) &&
(buf->offset == subbuf_size)) (buf->offset == subbuf_size))
...@@ -841,8 +844,9 @@ static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos) ...@@ -841,8 +844,9 @@ static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos)
} }
if (unlikely(produced - consumed >= n_subbufs)) { if (unlikely(produced - consumed >= n_subbufs)) {
consumed = (produced / n_subbufs) * n_subbufs; consumed = produced - n_subbufs + 1;
buf->subbufs_consumed = consumed; buf->subbufs_consumed = consumed;
buf->bytes_consumed = 0;
} }
produced = (produced % n_subbufs) * subbuf_size + buf->offset; produced = (produced % n_subbufs) * subbuf_size + buf->offset;
......
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