fs: 9p: add generic splice_read file operations
Subsystems (2)
PATCH 1/1 fs: 9p: add generic splice_read file operations
The v9fs file operations were missing the splice_read operations, which breaks sendfile() of files on such a filesystem. I discovered this while trying to load an eBPF program using iproute2 inside a 'virtme' environment which uses 9pfs for the virtual file system. iproute2 relies on sendfile() with an AF_ALG socket to hash files, which was erroring out in the virtual environment.
Since generic_file_splice_read() seems to just implement splice_read in terms of the read_iter operation, I simply added the generic implementation to the file operations, which fixed the error I was seeing. A quick grep indicates that this is what most other file systems do as well.
The only caveat is that my test case was only hitting the v9fs_file_operations_dotl implementation. I added it to the other file operations structs as well because it seemed like the sensible thing to do given that they all implement read_iter, but those are only compile tested.
--- fs/9p/vfs_file.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/9p/vfs_file.c +6 -0
@@ -655,6 +655,7 @@ const struct file_operations v9fs_cached_file_operations = { .release = v9fs_dir_release, .lock = v9fs_file_lock, .mmap = v9fs_file_mmap, + .splice_read = generic_file_splice_read, .fsync = v9fs_file_fsync, };
@@ -667,6 +668,7 @@ const struct file_operations v9fs_cached_file_operations_dotl = { .lock = v9fs_file_lock_dotl, .flock = v9fs_file_flock_dotl, .mmap = v9fs_file_mmap, + .splice_read = generic_file_splice_read, .fsync = v9fs_file_fsync_dotl, };
@@ -678,6 +680,7 @@ const struct file_operations v9fs_file_operations = { .release = v9fs_dir_release, .lock = v9fs_file_lock, .mmap = generic_file_readonly_mmap, + .splice_read = generic_file_splice_read, .fsync = v9fs_file_fsync, };
@@ -690,6 +693,7 @@ const struct file_operations v9fs_file_operations_dotl = { .lock = v9fs_file_lock_dotl, .flock = v9fs_file_flock_dotl, .mmap = generic_file_readonly_mmap, + .splice_read = generic_file_splice_read, .fsync = v9fs_file_fsync_dotl, };
@@ -701,6 +705,7 @@ const struct file_operations v9fs_mmap_file_operations = { .release = v9fs_dir_release, .lock = v9fs_file_lock, .mmap = v9fs_mmap_file_mmap, + .splice_read = generic_file_splice_read, .fsync = v9fs_file_fsync, };
@@ -713,5 +718,6 @@ const struct file_operations v9fs_mmap_file_operations_dotl = { .lock = v9fs_file_lock_dotl, .flock = v9fs_file_flock_dotl, .mmap = v9fs_mmap_file_mmap, + .splice_read = generic_file_splice_read, .fsync = v9fs_file_fsync_dotl, };
Signature · 1 line
2.29.2
Dominique Martinet
maintainerToke Høiland-Jørgensen wrote on Tue, Dec 01, 2020:
Quoted 11 lines
The v9fs file operations were missing the
splice_readoperations, which breakssendfile()of files on such a filesystem. I discovered this while trying to load an eBPF program using iproute2 inside a 'virtme' environment which uses 9pfs for the virtual file system. iproute2 relies onsendfile()with anAF_ALGsocket to hash files, which was erroring out in the virtual environment.Since
generic_file_splice_read()seems to just implementsplice_readin terms of theread_iteroperation, I simply added the generic implementation to the file operations, which fixed the error I was seeing. A quick grep indicates that this is what most other file systems do as well.
Good catch, might as well do that.
I'm surprised you didn't hit the same problem with splice_write?
I see iter_file_splice_write being used for it on many filesystems, it's probably better to add both?
Quoted 4 lines
The only caveat is that my test case was only hitting the
v9fs_file_operations_dotlimplementation. I added it to the other file operations structs as well because it seemed like the sensible thing to do given that they all implementread_iter, but those are only compile tested.
The logic is close enough that it should work, I'll run it through in cached mode at least first though (just mount with cache=loose or cache=fscache to hit v9fs_cached_file_operations_dotl yourself if you want to)
non-dotl operations are harder to test, I don't have any server compatible either so we'll have to trust it works close enough...
(note you can write comments such as this one after the three dashes line before the diff chunk so maintainers can reply without having it in commit message itself)
Signature · 1 line
Dominique
Dominique Martinet
maintainerDominique Martinet wrote on Tue, Dec 01, 2020:
Quoted 10 lines
Quoted 4 lines
Since
generic_file_splice_read()seems to just implementsplice_readin terms of theread_iteroperation, I simply added the generic implementation to the file operations, which fixed the error I was seeing. A quick grep indicates that this is what most other file systems do as well.Good catch, might as well do that.
I'm surprised you didn't hit the same problem withsplice_write?I see
iter_file_splice_writebeing used for it on many filesystems, it's probably better to add both?
Yeah, I confirm both are needed (the second for the pipe -> fs side)
This made me test copy_file_range, and it works with both as well (used not to)
interestingly on older kernels this came as default somehow? I have splice working on 5.4.67 :/ so this broke somewhat recently...
I'll add an extra patch with the second and take your patch. Thanks!
Signature · 1 line
Dominique
Quoted 6 lines · Dominique Martinet
Dominique Martinet wrote on Tue, Dec 01, 2020:
Quoted 5 lines
Quoted 4 lines
Since
generic_file_splice_read()seems to just implementsplice_readin terms of theread_iteroperation, I simply added the generic implementation to the file operations, which fixed the error I was seeing. A quick grep indicates that this is what most other file systems do as well.
Quoted 7 lines
Quoted 5 lines
Good catch, might as well do that.
I'm surprised you didn't hit the same problem withsplice_write?I see
iter_file_splice_writebeing used for it on many filesystems, it's probably better to add both?Yeah, I confirm both are needed (the second for the pipe -> fs side)
Yeah, makes sense; I was only testing with a very specific use case where a file is being passed to the kernel with sendfile().
Quoted 5 lines
This made me test
copy_file_range, and it works with both as well (used not to)interestingly on older kernels this came as default somehow? I have splice working on 5.4.67 :/ so this broke somewhat recently...
Huh, no idea; this is my first time digging into filesystem code, I normally do networking and BPF :)
Quoted 2 lines
I'll add an extra patch with the second and take your patch. Thanks!
Awesome, thanks!
-Toke
Dominique Martinet
maintainerToke Høiland-Jørgensen wrote on Tue, Dec 01, 2020:
Quoted 8 lines
Quoted 5 lines
This made me test
copy_file_range, and it works with both as well (used not to)interestingly on older kernels this came as default somehow? I have splice working on 5.4.67 :/ so this broke somewhat recently...
Huh, no idea; this is my first time digging into filesystem code, I normally do networking and BPF :)
In case anyone else wants to know, this broke in 5.10-rc1 with 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops")
So really a recent regression, good catch :)
Signature · 1 line
Dominique
Quoted 7 lines · Dominique Martinet
Toke Høiland-Jørgensen wrote on Tue, Dec 01, 2020:
Quoted 6 lines
Quoted 5 lines
This made me test
copy_file_range, and it works with both as well (used not to)interestingly on older kernels this came as default somehow? I have splice working on 5.4.67 :/ so this broke somewhat recently...
Quoted 7 lines
Quoted 2 lines
Huh, no idea; this is my first time digging into filesystem code, I normally do networking and BPF :)
In case anyone else wants to know, this broke in 5.10-rc1 with
36e2c7421f02("fs: don't allow splice read/write without explicit ops")So really a recent regression, good catch :)
Thanks - and what a lucky coincidence that I happened upon this now so it can be fixed before 5.10-final :)
-Toke
Dominique Martinet
maintainerPATCH 1/1 fs: 9p: add generic splice_write file operation
In reply to Dominique MartinetThe default splice operations got removed recently, add it back to 9p with iter_file_splice_write like many other filesystems do.
--- fs/9p/vfs_file.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/9p/vfs_file.c +6 -0
@@ -668,6 +668,7 @@ const struct file_operations v9fs_cached_file_operations = { .lock = v9fs_file_lock, .mmap = v9fs_file_mmap, .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync, };
@@ -681,6 +682,7 @@ const struct file_operations v9fs_cached_file_operations_dotl = { .flock = v9fs_file_flock_dotl, .mmap = v9fs_file_mmap, .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync_dotl, };
@@ -693,6 +695,7 @@ const struct file_operations v9fs_file_operations = { .lock = v9fs_file_lock, .mmap = generic_file_readonly_mmap, .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync, };
@@ -706,6 +709,7 @@ const struct file_operations v9fs_file_operations_dotl = { .flock = v9fs_file_flock_dotl, .mmap = generic_file_readonly_mmap, .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync_dotl, };
@@ -718,6 +722,7 @@ const struct file_operations v9fs_mmap_file_operations = { .lock = v9fs_file_lock, .mmap = v9fs_mmap_file_mmap, .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync, };
@@ -731,5 +736,6 @@ const struct file_operations v9fs_mmap_file_operations_dotl = { .flock = v9fs_file_flock_dotl, .mmap = v9fs_mmap_file_mmap, .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, .fsync = v9fs_file_fsync_dotl, };
Signature · 1 line
2.28.0
Re: [PATCH] fs: 9p: add generic splice_write file operation
Quoted 6 lines · Dominique Martinet
The default splice operations got removed recently, add it back to 9p with
iter_file_splice_writelike many other filesystems do.Fixes 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops")Cc Toke H??iland-J??rgensen <[email protected]>Signed-off-by Dominique Martinet <[email protected]>
Looks good,
Re: [PATCH] fs: 9p: add generic splice_write file operation
In reply to Dominique MartinetQuoted 6 lines · Dominique Martinet
The default splice operations got removed recently, add it back to 9p with
iter_file_splice_writelike many other filesystems do.Fixes 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops")Cc Toke Høiland-Jørgensen <[email protected]>Signed-off-by Dominique Martinet <[email protected]>
FWIW: