summaryrefslogtreecommitdiff
path: root/drivers/char/mem.c
diff options
context:
space:
mode:
authorMax Kellermann <max.kellermann@ionos.com>2023-09-19 09:37:42 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-10-05 13:34:05 +0200
commit1b057bd800c3ea0c926191d7950cd2365eddc9bb (patch)
treefd2479575d90eea9432fb808cc0ed3119197f9bf /drivers/char/mem.c
parent19e3e6cdfdc73400eb68d1102cdbad4f9493f474 (diff)
drivers/char/mem: implement splice() for /dev/zero, /dev/full
This allows splicing zeroed pages into a pipe, and allows discarding pages from a pipe by splicing them to /dev/zero. Writing to /dev/zero should have the same effect as writing to /dev/null, and a "splice_write" implementation exists only for /dev/null. (The /dev/zero splice_read implementation could be optimized by pushing references to the global zero page to the pipe, but that's an optimization for another day.) Signed-off-by: Max Kellermann <max.kellermann@ionos.com> Link: https://lore.kernel.org/r/20230919073743.1066313-1-max.kellermann@ionos.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/char/mem.c')
-rw-r--r--drivers/char/mem.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 1052b0f2d4cf..263c19cd6fb9 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -640,6 +640,7 @@ static int open_port(struct inode *inode, struct file *filp)
#define full_lseek null_lseek
#define write_zero write_null
#define write_iter_zero write_iter_null
+#define splice_write_zero splice_write_null
#define open_mem open_port
static const struct file_operations __maybe_unused mem_fops = {
@@ -677,6 +678,8 @@ static const struct file_operations zero_fops = {
.read_iter = read_iter_zero,
.read = read_zero,
.write_iter = write_iter_zero,
+ .splice_read = copy_splice_read,
+ .splice_write = splice_write_zero,
.mmap = mmap_zero,
.get_unmapped_area = get_unmapped_area_zero,
#ifndef CONFIG_MMU
@@ -688,6 +691,7 @@ static const struct file_operations full_fops = {
.llseek = full_lseek,
.read_iter = read_iter_zero,
.write = write_full,
+ .splice_read = copy_splice_read,
};
static const struct memdev {