Skip to content

Commit 562108d

Browse files
zhangyi089brauner
authored andcommitted
block: factor out common part in blkdev_fallocate()
Only the flags passed to blkdev_issue_zeroout() differ among the two zeroing branches in blkdev_fallocate(). Therefore, do cleanup by factoring them out. 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 7bd43cc commit 562108d

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

block/fops.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
850850
struct block_device *bdev = I_BDEV(inode);
851851
loff_t end = start + len - 1;
852852
loff_t isize;
853+
unsigned int flags;
853854
int error;
854855

855856
/* Fail if we don't recognize the flags. */
@@ -877,34 +878,29 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start,
877878
inode_lock(inode);
878879
filemap_invalidate_lock(inode->i_mapping);
879880

880-
/*
881-
* Invalidate the page cache, including dirty pages, for valid
882-
* de-allocate mode calls to fallocate().
883-
*/
884881
switch (mode) {
885882
case FALLOC_FL_ZERO_RANGE:
886883
case FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE:
887-
error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end);
888-
if (error)
889-
goto fail;
890-
891-
error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
892-
len >> SECTOR_SHIFT, GFP_KERNEL,
893-
BLKDEV_ZERO_NOUNMAP);
884+
flags = BLKDEV_ZERO_NOUNMAP;
894885
break;
895886
case FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE:
896-
error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end);
897-
if (error)
898-
goto fail;
899-
900-
error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
901-
len >> SECTOR_SHIFT, GFP_KERNEL,
902-
BLKDEV_ZERO_NOFALLBACK);
887+
flags = BLKDEV_ZERO_NOFALLBACK;
903888
break;
904889
default:
905890
error = -EOPNOTSUPP;
891+
goto fail;
906892
}
907893

894+
/*
895+
* Invalidate the page cache, including dirty pages, for valid
896+
* de-allocate mode calls to fallocate().
897+
*/
898+
error = truncate_bdev_range(bdev, file_to_blk_mode(file), start, end);
899+
if (error)
900+
goto fail;
901+
902+
error = blkdev_issue_zeroout(bdev, start >> SECTOR_SHIFT,
903+
len >> SECTOR_SHIFT, GFP_KERNEL, flags);
908904
fail:
909905
filemap_invalidate_unlock(inode->i_mapping);
910906
inode_unlock(inode);

0 commit comments

Comments
 (0)