Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

buffer: return bool from grow_dev_folio()

Patch series "More buffer_head cleanups", v2.

The first patch is a left-over from last cycle. The rest fix "obvious"
block size > PAGE_SIZE problems. I haven't tested with a large block size
setup (but I have done an ext4 xfstests run).


This patch (of 7):

Rename grow_dev_page() to grow_dev_folio() and make it return a bool.
Document what that bool means; it's more subtle than it first appears.
Also rename the 'failed' label to 'unlock' beacuse it's not exactly
'failed'. It just hasn't succeeded.

Link: https://lkml.kernel.org/r/20231109210608.2252323-2-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Pankaj Raghav <p.raghav@samsung.com>
Cc: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
6d840a18 ffda6556

+25 -25
+25 -25
fs/buffer.c
··· 1024 1024 } 1025 1025 1026 1026 /* 1027 - * Create the page-cache page that contains the requested block. 1027 + * Create the page-cache folio that contains the requested block. 1028 1028 * 1029 1029 * This is used purely for blockdev mappings. 1030 + * 1031 + * Returns false if we have a 'permanent' failure. Returns true if 1032 + * we succeeded, or the caller should retry. 1030 1033 */ 1031 - static int 1032 - grow_dev_page(struct block_device *bdev, sector_t block, 1033 - pgoff_t index, int size, int sizebits, gfp_t gfp) 1034 + static bool grow_dev_folio(struct block_device *bdev, sector_t block, 1035 + pgoff_t index, unsigned size, int sizebits, gfp_t gfp) 1034 1036 { 1035 1037 struct inode *inode = bdev->bd_inode; 1036 1038 struct folio *folio; 1037 1039 struct buffer_head *bh; 1038 - sector_t end_block; 1039 - int ret = 0; 1040 + sector_t end_block = 0; 1040 1041 1041 1042 folio = __filemap_get_folio(inode->i_mapping, index, 1042 1043 FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp); 1043 1044 if (IS_ERR(folio)) 1044 - return PTR_ERR(folio); 1045 + return false; 1045 1046 1046 1047 bh = folio_buffers(folio); 1047 1048 if (bh) { 1048 1049 if (bh->b_size == size) { 1049 1050 end_block = folio_init_buffers(folio, bdev, 1050 1051 (sector_t)index << sizebits, size); 1051 - goto done; 1052 + goto unlock; 1052 1053 } 1054 + 1055 + /* Caller should retry if this call fails */ 1056 + end_block = ~0ULL; 1053 1057 if (!try_to_free_buffers(folio)) 1054 - goto failed; 1058 + goto unlock; 1055 1059 } 1056 1060 1057 - ret = -ENOMEM; 1058 1061 bh = folio_alloc_buffers(folio, size, gfp | __GFP_ACCOUNT); 1059 1062 if (!bh) 1060 - goto failed; 1063 + goto unlock; 1061 1064 1062 1065 /* 1063 1066 * Link the folio to the buffers and initialise them. Take the ··· 1072 1069 end_block = folio_init_buffers(folio, bdev, 1073 1070 (sector_t)index << sizebits, size); 1074 1071 spin_unlock(&inode->i_mapping->private_lock); 1075 - done: 1076 - ret = (block < end_block) ? 1 : -ENXIO; 1077 - failed: 1072 + unlock: 1078 1073 folio_unlock(folio); 1079 1074 folio_put(folio); 1080 - return ret; 1075 + return block < end_block; 1081 1076 } 1082 1077 1083 1078 /* 1084 - * Create buffers for the specified block device block's page. If 1085 - * that page was dirty, the buffers are set dirty also. 1079 + * Create buffers for the specified block device block's folio. If 1080 + * that folio was dirty, the buffers are set dirty also. Returns false 1081 + * if we've hit a permanent error. 1086 1082 */ 1087 - static int 1088 - grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp) 1083 + static bool grow_buffers(struct block_device *bdev, sector_t block, 1084 + unsigned size, gfp_t gfp) 1089 1085 { 1090 1086 pgoff_t index; 1091 1087 int sizebits; ··· 1101 1099 "device %pg\n", 1102 1100 __func__, (unsigned long long)block, 1103 1101 bdev); 1104 - return -EIO; 1102 + return false; 1105 1103 } 1106 1104 1107 - /* Create a page with the proper size buffers.. */ 1108 - return grow_dev_page(bdev, block, index, size, sizebits, gfp); 1105 + /* Create a folio with the proper size buffers */ 1106 + return grow_dev_folio(bdev, block, index, size, sizebits, gfp); 1109 1107 } 1110 1108 1111 1109 static struct buffer_head * ··· 1126 1124 1127 1125 for (;;) { 1128 1126 struct buffer_head *bh; 1129 - int ret; 1130 1127 1131 1128 bh = __find_get_block(bdev, block, size); 1132 1129 if (bh) 1133 1130 return bh; 1134 1131 1135 - ret = grow_buffers(bdev, block, size, gfp); 1136 - if (ret < 0) 1132 + if (!grow_buffers(bdev, block, size, gfp)) 1137 1133 return NULL; 1138 1134 } 1139 1135 }