diff options
| author | Zhang Yi <yi.zhang@huawei.com> | 2025-06-19 19:18:05 +0800 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2025-06-23 12:45:14 +0200 |
| commit | 912b6038fe5c985fac06285f8019fd74cab67e81 (patch) | |
| tree | fff3437c079a6b9433bd300eaf13ef4954af859f | |
| parent | block: factor out common part in blkdev_fallocate() (diff) | |
| download | linux-912b6038fe5c985fac06285f8019fd74cab67e81.tar.gz linux-912b6038fe5c985fac06285f8019fd74cab67e81.zip | |
block: add FALLOC_FL_WRITE_ZEROES support
Add support for FALLOC_FL_WRITE_ZEROES, if the block device enables the
unmap write zeroes operation, it will issue a write zeroes command.
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Link: https://lore.kernel.org/20250619111806.3546162-9-yi.zhang@huaweicloud.com
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
| -rw-r--r-- | block/fops.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/block/fops.c b/block/fops.c index e1c921549d28..474656a0de70 100644 --- a/block/fops.c +++ b/block/fops.c @@ -841,7 +841,7 @@ reexpand: #define BLKDEV_FALLOC_FL_SUPPORTED \ (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ - FALLOC_FL_ZERO_RANGE) + FALLOC_FL_ZERO_RANGE | FALLOC_FL_WRITE_ZEROES) static long blkdev_fallocate(struct file *file, int mode, loff_t start, loff_t len) @@ -856,6 +856,13 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, /* Fail if we don't recognize the flags. */ if (mode & ~BLKDEV_FALLOC_FL_SUPPORTED) return -EOPNOTSUPP; + /* + * Don't allow writing zeroes if the device does not enable the + * unmap write zeroes operation. + */ + if ((mode & FALLOC_FL_WRITE_ZEROES) && + !bdev_write_zeroes_unmap_sectors(bdev)) + return -EOPNOTSUPP; /* Don't go off the end of the device. */ isize = bdev_nr_bytes(bdev); @@ -886,6 +893,9 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE: flags = BLKDEV_ZERO_NOFALLBACK; break; + case FALLOC_FL_WRITE_ZEROES: + flags = 0; + break; default: error = -EOPNOTSUPP; goto fail; |
