Skip to content

Commit 912b603

Browse files
zhangyi089brauner
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: "Martin K. Petersen" <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 562108d commit 912b603

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

block/fops.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
841841

842842
#define BLKDEV_FALLOC_FL_SUPPORTED \
843843
(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \
844-
FALLOC_FL_ZERO_RANGE)
844+
FALLOC_FL_ZERO_RANGE | FALLOC_FL_WRITE_ZEROES)
845845

846846
static long blkdev_fallocate(struct file *file, int mode, loff_t start,
847847
loff_t len)
@@ -856,6 +856,13 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
856856
/* Fail if we don't recognize the flags. */
857857
if (mode & ~BLKDEV_FALLOC_FL_SUPPORTED)
858858
return -EOPNOTSUPP;
859+
/*
860+
* Don't allow writing zeroes if the device does not enable the
861+
* unmap write zeroes operation.
862+
*/
863+
if ((mode & FALLOC_FL_WRITE_ZEROES) &&
864+
!bdev_write_zeroes_unmap_sectors(bdev))
865+
return -EOPNOTSUPP;
859866

860867
/* Don't go off the end of the device. */
861868
isize = bdev_nr_bytes(bdev);
@@ -886,6 +893,9 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
886893
case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE:
887894
flags = BLKDEV_ZERO_NOFALLBACK;
888895
break;
896+
case FALLOC_FL_WRITE_ZEROES:
897+
flags = 0;
898+
break;
889899
default:
890900
error = -EOPNOTSUPP;
891901
goto fail;

0 commit comments

Comments
 (0)