Skip to contentSkip to conversation

splice: allow direct splicing with chardevs

PATCH Superseded Jason A. Donenfeld 2 participants 4 messages May 20, 2022 – Jun 8, 2022 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 splice: allow direct splicing with chardevs

The original direct splicing mechanism from Jens required the input to be a regular file because it was avoiding the special socket case. It also recognized blkdevs as being close enough to a regular file. But it forgot about chardevs, which behave the same way and work fine here.

This commit adds the missing S_ISCHR condition so that chardevs such as /dev/urandom can be directly spliced without strangely returning -EINVAL.

Cc Jens Axboe <[email protected]>
Cc Al Viro <[email protected]>
Fixes b92ce5589374 ("[PATCH] splice: add direct fd <-> fd splicing support")
---
 fs/splice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/splice.c +1 -1
index 047b79db8eb5..7e673b1786fb 100644
@@ -824,7 +824,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
 	 * piped splicing for that!
 	 */
 	i_mode = file_inode(in)->i_mode;
-	if (unlikely(!S_ISREG(i_mode) && !S_ISBLK(i_mode)))
+	if (unlikely(!S_ISREG(i_mode) && !S_ISBLK(i_mode) && !S_ISCHR(i_mode)))
 		return -EINVAL;
 
 	/*
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jason A. Donenfeld

The original direct splicing mechanism from Jens required the input to be a regular file because it was avoiding the special socket case. It also recognized blkdevs as being close enough to a regular file. But it forgot about chardevs, which behave the same way and work fine here.

This commit adds the missing S_ISCHR condition so that chardevs such as /dev/urandom can be directly spliced without strangely returning -EINVAL.

Should be fine to turn this on for char devices:

Signature · 1 line
Jens Axboe
#2 lore raw

Hey Al,

Quoted 6 lines · Jens Axboe
Quoted 5 lines · Jason A. Donenfeld

The original direct splicing mechanism from Jens required the input to be a regular file because it was avoiding the special socket case. It also recognized blkdevs as being close enough to a regular file. But it forgot about chardevs, which behave the same way and work fine here.

Quoted 8 lines
Quoted 3 lines

This commit adds the missing S_ISCHR condition so that chardevs such as /dev/urandom can be directly spliced without strangely returning -EINVAL.

Should be fine to turn this on for char devices:

Was wondering if this would make 5.19. That'd be nice, as it's the release in which we switch to read_iter().

Jason

#3 lore raw

Hey again,

Quoted 13 lines · Jason A. Donenfeld

Hey Al,

Quoted 10 lines · Jens Axboe
Quoted 8 lines · Jason A. Donenfeld

The original direct splicing mechanism from Jens required the input to be a regular file because it was avoiding the special socket case. It also recognized blkdevs as being close enough to a regular file. But it forgot about chardevs, which behave the same way and work fine here.

This commit adds the missing S_ISCHR condition so that chardevs such as /dev/urandom can be directly spliced without strangely returning -EINVAL.

Quoted 7 lines
Quoted 4 lines

Should be fine to turn this on for char devices:

Was wondering if this would make 5.19. That'd be nice, as it's the release in which we switch to read_iter().

Just thought I should ping once more on this. Should probably be queued up somewhat soon for 5.19 if it's to make 5.19, which I would really appreciate.

Jason