splice: fix updating sd->pos wrongly
PATCH v2 4/4 splice: fix updating sd->pos wrongly
fix updating sd->pos wrongly.
In error path, we don't need to updating sd->pos, if the file isn't seekable.
----
fs/splice.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/splice.c +2 -1
@@ -1185,7 +1185,8 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, sd->pos = pos;if (ret < read_len) { - sd->pos = prev_pos + ret; +if (sd->pos) + sd->pos = prev_pos + ret; goto out_release; } }
Quoted 3 lines · Changli Gao
fix updating
sd->poswrongly.In error path, we don't need to updating
sd->pos, if the file isn't seekable.
This patch is nonsense. Why should we handle sd->pos != 0 case differently?
Quoted 24 lines
Signed-off-by Changli Gao <[email protected]>----
fs/splice.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/splice.c +2
-2@@ -1185,7 +1185,8 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, sd->pos = pos;if (ret < read_len) { - sd->pos = prev_pos + ret; +if (sd->pos) + sd->pos = prev_pos + ret; goto out_release; } } --To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao
fix updating
sd->poswrongly.In error path, we don't need to updating
sd->pos, if the file isn't seekable.This patch is nonsense. Why should we handle
sd->pos!= 0 case differently?
If the in file isn't seekable, its splice_read won't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.
ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len, unsigned int flags)
{
struct sock *sk = sock->sk;
struct tcp_splice_state tss = {
.pipe = pipe,
.len = len,
.flags = flags,
};
long timeo;
ssize_t spliced;
int ret;
/*
* We can't seek on a socket input
*/
if (unlikely(*ppos))
return -ESPIPE;Signature · 2 lines
Regards, Changli Gao([email protected])
Quoted 6 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao
fix updating
sd->poswrongly.In error path, we don't need to updating
sd->pos, if the file isn't seekable.
Quoted 7 lines
Quoted 3 lines
This patch is nonsense. Why should we handle
sd->pos!= 0 case differently?If the in file isn't seekable, its
splice_readwon't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.
That may be true, but the patch is still nonsense.
Look, your patch is updating/not updating sd->pos based on whether it is zero or not. It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.
Since these patches modify the behavior of splice in subtle ways, it would be good if you had some test program to verify that you aren't breaking something.
Thanks,
Miklos
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Miklos Szeredi
Quoted 6 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao
fix updating
sd->poswrongly.In error path, we don't need to updating
sd->pos, if the file isn't seekable.Quoted 7 lines
Quoted 3 lines
This patch is nonsense. Why should we handle
sd->pos!= 0 case differently?If the in file isn't seekable, its
splice_readwon't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.
Quoted 6 lines
That may be true, but the patch is still nonsense.
Look, your patch is updating/not updating
sd->posbased on whether it is zero or not. It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.
I think you misread my patch. Before checking the sd->pos, sd->pos already is updated with the value returned by splice_read(), so if in file is seekabble, sd->pos is non-zero when I checking it.
Signature · 6 lines
Regards, Changli Gao([email protected]) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 16 lines · Changli Gao
Quoted 15 lines · Miklos Szeredi
Quoted 13 lines · Changli Gao
Quoted 8 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao
fix updating
sd->poswrongly.In error path, we don't need to updating
sd->pos, if the file isn't seekable.This patch is nonsense. Why should we handle
sd->pos!= 0 case differently?If the in file isn't seekable, its
splice_readwon't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.
Quoted 8 lines
Quoted 6 lines
That may be true, but the patch is still nonsense.
Look, your patch is updating/not updating
sd->posbased on whether it is zero or not. It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.I think you misread my patch.
Right :)
Quoted 3 lines
Before checking the
sd->pos,sd->pos
already is updated with the value returned bysplice_read(), so if in file is seekabble,sd->posis non-zero when I checking it.
I see the logic now. But it's really confusing, at least some comments would be needed.
But I think it would be better not to try reusing sd->pos for reading, but supplying an "loff_t *read_ppos" to splice_direct_to_actor and leaving sd->pos alone (for the write side to use and update as necessary).
Thanks,
Miklos
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao
Before checking the
sd->pos,sd->pos
already is updated with the value returned bysplice_read(), so if in file is seekabble,sd->posis non-zero when I checking it.
Quoted 8 lines
I see the logic now. But it's really confusing, at least some comments would be needed.
But I think it would be better not to try reusing
sd->posfor reading, but supplying an "loff_t*read_ppos" tosplice_direct_to_actorand leavingsd->posalone (for the write side to use and update as necessary).
if (ret < read_len) {I think is much like a hack too. :)
- sd->pos = prev_pos + ret;
+ if (sd->pos)
+ sd->pos = prev_pos + ret;
goto out_release;
}Anyway, it can fix the issue I mentioned above. Any future cleanup should not be mixed in, IMO.
Signature · 2 lines
Regards, Changli Gao([email protected])
Quoted 25 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao
Before checking the
sd->pos,sd->pos
already is updated with the value returned bysplice_read(), so if in file is seekabble,sd->posis non-zero when I checking it.Quoted 8 lines
I see the logic now. But it's really confusing, at least some comments would be needed.
But I think it would be better not to try reusing
sd->posfor reading, but supplying an "loff_t*read_ppos" tosplice_direct_to_actorand leavingsd->posalone (for the write side to use and update as necessary).if (ret < read_len) {I think is much like a hack too. :)
(quoted diff) +2
-1- sd->pos = prev_pos + ret; + if (sd->pos) + sd->pos = prev_pos + ret; goto out_release; }
Quoted 2 lines
Anyway, it can fix the issue I mentioned above. Any future cleanup should not be mixed in, IMO.
Okay, but please add a comment and explaing in the patch header, because others are going to look a that code and go "WTF???"
Thanks,
Miklos
Quoted 18 lines · Changli Gao
Quoted 17 lines · Miklos Szeredi
Quoted 6 lines · Changli Gao
Quoted 5 lines · Miklos Szeredi
Quoted 3 lines · Changli Gao
fix updating
sd->poswrongly.In error path, we don't need to updating
sd->pos, if the file isn't seekable.Quoted 7 lines
Quoted 3 lines
This patch is nonsense. Why should we handle
sd->pos!= 0 case differently?If the in file isn't seekable, its
splice_readwon't update *ppos, so in the error path, we'd better not change it too. Otherwise, some assumption will go wrong.That may be true, but the patch is still nonsense.
Quoted 8 lines
Quoted 4 lines
Look, your patch is updating/not updating
sd->posbased on whether it is zero or not. It will prevent updating the position for sockets, but it will also prevent updating the position for regular files if the position is zero, which is really not what we want.I think you misread my patch. Before checking the
sd->pos,sd->posalready is updated with the value returned bysplice_read(), so if in file is seekabble,sd->posis non-zero when I checking it.
Not true if the "file" is /dev/mem or /dev/kmem. The starting offset can be negative, so can end at zero.
It's an obscure case and I don't know if you can sendfile from /dev/{,k}mem anyway :-) but illustrates why sd->pos != 0 is dubious.
-- Jamie
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Jamie Lokier
Not true if the "file" is
/dev/memor/dev/kmem. The starting offset can be negative, so can end at zero.It's an obscure case and I don't know if you can sendfile from
/dev/{,k}memanyway :-) but illustrates whysd->pos!= 0 is dubious.
So the safe way is checking if splice_read() updates pos or not, isn't it?
if (sd->pos != prev_pos)
sd->pos = prev_pos + ret;
Signature · 2 lines
Regards, Changli Gao([email protected])