diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-02-10 14:35:36 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-02-10 14:35:36 -0500 |
commit | 4ba24fef3eb3b142197135223b90ced2f319cd53 (patch) | |
tree | a20c125b27740ec7b4c761b11d801108e1b316b2 /fs/buffer.c | |
parent | 47c1ffb2b6b630894e9a16442611c056ab21c057 (diff) | |
parent | 98a4a59ee31a12105a2b84f5b8b515ac2cb208ef (diff) |
Merge branch 'next' into for-linus
Prepare first round of input updates for 3.20.
Diffstat (limited to 'fs/buffer.c')
-rw-r--r-- | fs/buffer.c | 123 |
1 files changed, 58 insertions, 65 deletions
diff --git a/fs/buffer.c b/fs/buffer.c index 3588a80854b2..20805db2c987 100644 --- a/fs/buffer.c +++ b/fs/buffer.c | |||
@@ -128,21 +128,15 @@ __clear_page_buffers(struct page *page) | |||
128 | page_cache_release(page); | 128 | page_cache_release(page); |
129 | } | 129 | } |
130 | 130 | ||
131 | 131 | static void buffer_io_error(struct buffer_head *bh, char *msg) | |
132 | static int quiet_error(struct buffer_head *bh) | ||
133 | { | ||
134 | if (!test_bit(BH_Quiet, &bh->b_state) && printk_ratelimit()) | ||
135 | return 0; | ||
136 | return 1; | ||
137 | } | ||
138 | |||
139 | |||
140 | static void buffer_io_error(struct buffer_head *bh) | ||
141 | { | 132 | { |
142 | char b[BDEVNAME_SIZE]; | 133 | char b[BDEVNAME_SIZE]; |
143 | printk(KERN_ERR "Buffer I/O error on device %s, logical block %Lu\n", | 134 | |
135 | if (!test_bit(BH_Quiet, &bh->b_state)) | ||
136 | printk_ratelimited(KERN_ERR | ||
137 | "Buffer I/O error on dev %s, logical block %llu%s\n", | ||
144 | bdevname(bh->b_bdev, b), | 138 | bdevname(bh->b_bdev, b), |
145 | (unsigned long long)bh->b_blocknr); | 139 | (unsigned long long)bh->b_blocknr, msg); |
146 | } | 140 | } |
147 | 141 | ||
148 | /* | 142 | /* |
@@ -177,17 +171,10 @@ EXPORT_SYMBOL(end_buffer_read_sync); | |||
177 | 171 | ||
178 | void end_buffer_write_sync(struct buffer_head *bh, int uptodate) | 172 | void end_buffer_write_sync(struct buffer_head *bh, int uptodate) |
179 | { | 173 | { |
180 | char b[BDEVNAME_SIZE]; | ||
181 | |||
182 | if (uptodate) { | 174 | if (uptodate) { |
183 | set_buffer_uptodate(bh); | 175 | set_buffer_uptodate(bh); |
184 | } else { | 176 | } else { |
185 | if (!quiet_error(bh)) { | 177 | buffer_io_error(bh, ", lost sync page write"); |
186 | buffer_io_error(bh); | ||
187 | printk(KERN_WARNING "lost page write due to " | ||
188 | "I/O error on %s\n", | ||
189 | bdevname(bh->b_bdev, b)); | ||
190 | } | ||
191 | set_buffer_write_io_error(bh); | 178 | set_buffer_write_io_error(bh); |
192 | clear_buffer_uptodate(bh); | 179 | clear_buffer_uptodate(bh); |
193 | } | 180 | } |
@@ -304,8 +291,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) | |||
304 | set_buffer_uptodate(bh); | 291 | set_buffer_uptodate(bh); |
305 | } else { | 292 | } else { |
306 | clear_buffer_uptodate(bh); | 293 | clear_buffer_uptodate(bh); |
307 | if (!quiet_error(bh)) | 294 | buffer_io_error(bh, ", async page read"); |
308 | buffer_io_error(bh); | ||
309 | SetPageError(page); | 295 | SetPageError(page); |
310 | } | 296 | } |
311 | 297 | ||
@@ -353,7 +339,6 @@ still_busy: | |||
353 | */ | 339 | */ |
354 | void end_buffer_async_write(struct buffer_head *bh, int uptodate) | 340 | void end_buffer_async_write(struct buffer_head *bh, int uptodate) |
355 | { | 341 | { |
356 | char b[BDEVNAME_SIZE]; | ||
357 | unsigned long flags; | 342 | unsigned long flags; |
358 | struct buffer_head *first; | 343 | struct buffer_head *first; |
359 | struct buffer_head *tmp; | 344 | struct buffer_head *tmp; |
@@ -365,12 +350,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) | |||
365 | if (uptodate) { | 350 | if (uptodate) { |
366 | set_buffer_uptodate(bh); | 351 | set_buffer_uptodate(bh); |
367 | } else { | 352 | } else { |
368 | if (!quiet_error(bh)) { | 353 | buffer_io_error(bh, ", lost async page write"); |
369 | buffer_io_error(bh); | ||
370 | printk(KERN_WARNING "lost page write due to " | ||
371 | "I/O error on %s\n", | ||
372 | bdevname(bh->b_bdev, b)); | ||
373 | } | ||
374 | set_bit(AS_EIO, &page->mapping->flags); | 354 | set_bit(AS_EIO, &page->mapping->flags); |
375 | set_buffer_write_io_error(bh); | 355 | set_buffer_write_io_error(bh); |
376 | clear_buffer_uptodate(bh); | 356 | clear_buffer_uptodate(bh); |
@@ -993,7 +973,7 @@ init_page_buffers(struct page *page, struct block_device *bdev, | |||
993 | */ | 973 | */ |
994 | static int | 974 | static int |
995 | grow_dev_page(struct block_device *bdev, sector_t block, | 975 | grow_dev_page(struct block_device *bdev, sector_t block, |
996 | pgoff_t index, int size, int sizebits) | 976 | pgoff_t index, int size, int sizebits, gfp_t gfp) |
997 | { | 977 | { |
998 | struct inode *inode = bdev->bd_inode; | 978 | struct inode *inode = bdev->bd_inode; |
999 | struct page *page; | 979 | struct page *page; |
@@ -1002,8 +982,8 @@ grow_dev_page(struct block_device *bdev, sector_t block, | |||
1002 | int ret = 0; /* Will call free_more_memory() */ | 982 | int ret = 0; /* Will call free_more_memory() */ |
1003 | gfp_t gfp_mask; | 983 | gfp_t gfp_mask; |
1004 | 984 | ||
1005 | gfp_mask = mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS; | 985 | gfp_mask = (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS) | gfp; |
1006 | gfp_mask |= __GFP_MOVABLE; | 986 | |
1007 | /* | 987 | /* |
1008 | * XXX: __getblk_slow() can not really deal with failure and | 988 | * XXX: __getblk_slow() can not really deal with failure and |
1009 | * will endlessly loop on improvised global reclaim. Prefer | 989 | * will endlessly loop on improvised global reclaim. Prefer |
@@ -1060,7 +1040,7 @@ failed: | |||
1060 | * that page was dirty, the buffers are set dirty also. | 1040 | * that page was dirty, the buffers are set dirty also. |
1061 | */ | 1041 | */ |
1062 | static int | 1042 | static int |
1063 | grow_buffers(struct block_device *bdev, sector_t block, int size) | 1043 | grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp) |
1064 | { | 1044 | { |
1065 | pgoff_t index; | 1045 | pgoff_t index; |
1066 | int sizebits; | 1046 | int sizebits; |
@@ -1087,11 +1067,12 @@ grow_buffers(struct block_device *bdev, sector_t block, int size) | |||
1087 | } | 1067 | } |
1088 | 1068 | ||
1089 | /* Create a page with the proper size buffers.. */ | 1069 | /* Create a page with the proper size buffers.. */ |
1090 | return grow_dev_page(bdev, block, index, size, sizebits); | 1070 | return grow_dev_page(bdev, block, index, size, sizebits, gfp); |
1091 | } | 1071 | } |
1092 | 1072 | ||
1093 | static struct buffer_head * | 1073 | struct buffer_head * |
1094 | __getblk_slow(struct block_device *bdev, sector_t block, int size) | 1074 | __getblk_slow(struct block_device *bdev, sector_t block, |
1075 | unsigned size, gfp_t gfp) | ||
1095 | { | 1076 | { |
1096 | /* Size must be multiple of hard sectorsize */ | 1077 | /* Size must be multiple of hard sectorsize */ |
1097 | if (unlikely(size & (bdev_logical_block_size(bdev)-1) || | 1078 | if (unlikely(size & (bdev_logical_block_size(bdev)-1) || |
@@ -1113,13 +1094,14 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size) | |||
1113 | if (bh) | 1094 | if (bh) |
1114 | return bh; | 1095 | return bh; |
1115 | 1096 | ||
1116 | ret = grow_buffers(bdev, block, size); | 1097 | ret = grow_buffers(bdev, block, size, gfp); |
1117 | if (ret < 0) | 1098 | if (ret < 0) |
1118 | return NULL; | 1099 | return NULL; |
1119 | if (ret == 0) | 1100 | if (ret == 0) |
1120 | free_more_memory(); | 1101 | free_more_memory(); |
1121 | } | 1102 | } |
1122 | } | 1103 | } |
1104 | EXPORT_SYMBOL(__getblk_slow); | ||
1123 | 1105 | ||
1124 | /* | 1106 | /* |
1125 | * The relationship between dirty buffers and dirty pages: | 1107 | * The relationship between dirty buffers and dirty pages: |
@@ -1253,7 +1235,7 @@ static struct buffer_head *__bread_slow(struct buffer_head *bh) | |||
1253 | * a local interrupt disable for that. | 1235 | * a local interrupt disable for that. |
1254 | */ | 1236 | */ |
1255 | 1237 | ||
1256 | #define BH_LRU_SIZE 8 | 1238 | #define BH_LRU_SIZE 16 |
1257 | 1239 | ||
1258 | struct bh_lru { | 1240 | struct bh_lru { |
1259 | struct buffer_head *bhs[BH_LRU_SIZE]; | 1241 | struct buffer_head *bhs[BH_LRU_SIZE]; |
@@ -1331,8 +1313,8 @@ lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) | |||
1331 | for (i = 0; i < BH_LRU_SIZE; i++) { | 1313 | for (i = 0; i < BH_LRU_SIZE; i++) { |
1332 | struct buffer_head *bh = __this_cpu_read(bh_lrus.bhs[i]); | 1314 | struct buffer_head *bh = __this_cpu_read(bh_lrus.bhs[i]); |
1333 | 1315 | ||
1334 | if (bh && bh->b_bdev == bdev && | 1316 | if (bh && bh->b_blocknr == block && bh->b_bdev == bdev && |
1335 | bh->b_blocknr == block && bh->b_size == size) { | 1317 | bh->b_size == size) { |
1336 | if (i) { | 1318 | if (i) { |
1337 | while (i) { | 1319 | while (i) { |
1338 | __this_cpu_write(bh_lrus.bhs[i], | 1320 | __this_cpu_write(bh_lrus.bhs[i], |
@@ -1373,24 +1355,25 @@ __find_get_block(struct block_device *bdev, sector_t block, unsigned size) | |||
1373 | EXPORT_SYMBOL(__find_get_block); | 1355 | EXPORT_SYMBOL(__find_get_block); |
1374 | 1356 | ||
1375 | /* | 1357 | /* |
1376 | * __getblk will locate (and, if necessary, create) the buffer_head | 1358 | * __getblk_gfp() will locate (and, if necessary, create) the buffer_head |
1377 | * which corresponds to the passed block_device, block and size. The | 1359 | * which corresponds to the passed block_device, block and size. The |
1378 | * returned buffer has its reference count incremented. | 1360 | * returned buffer has its reference count incremented. |
1379 | * | 1361 | * |
1380 | * __getblk() will lock up the machine if grow_dev_page's try_to_free_buffers() | 1362 | * __getblk_gfp() will lock up the machine if grow_dev_page's |
1381 | * attempt is failing. FIXME, perhaps? | 1363 | * try_to_free_buffers() attempt is failing. FIXME, perhaps? |
1382 | */ | 1364 | */ |
1383 | struct buffer_head * | 1365 | struct buffer_head * |
1384 | __getblk(struct block_device *bdev, sector_t block, unsigned size) | 1366 | __getblk_gfp(struct block_device *bdev, sector_t block, |
1367 | unsigned size, gfp_t gfp) | ||
1385 | { | 1368 | { |
1386 | struct buffer_head *bh = __find_get_block(bdev, block, size); | 1369 | struct buffer_head *bh = __find_get_block(bdev, block, size); |
1387 | 1370 | ||
1388 | might_sleep(); | 1371 | might_sleep(); |
1389 | if (bh == NULL) | 1372 | if (bh == NULL) |
1390 | bh = __getblk_slow(bdev, block, size); | 1373 | bh = __getblk_slow(bdev, block, size, gfp); |
1391 | return bh; | 1374 | return bh; |
1392 | } | 1375 | } |
1393 | EXPORT_SYMBOL(__getblk); | 1376 | EXPORT_SYMBOL(__getblk_gfp); |
1394 | 1377 | ||
1395 | /* | 1378 | /* |
1396 | * Do async read-ahead on a buffer.. | 1379 | * Do async read-ahead on a buffer.. |
@@ -1406,24 +1389,28 @@ void __breadahead(struct block_device *bdev, sector_t block, unsigned size) | |||
1406 | EXPORT_SYMBOL(__breadahead); | 1389 | EXPORT_SYMBOL(__breadahead); |
1407 | 1390 | ||
1408 | /** | 1391 | /** |
1409 | * __bread() - reads a specified block and returns the bh | 1392 | * __bread_gfp() - reads a specified block and returns the bh |
1410 | * @bdev: the block_device to read from | 1393 | * @bdev: the block_device to read from |
1411 | * @block: number of block | 1394 | * @block: number of block |
1412 | * @size: size (in bytes) to read | 1395 | * @size: size (in bytes) to read |
1413 | * | 1396 | * @gfp: page allocation flag |
1397 | * | ||
1414 | * Reads a specified block, and returns buffer head that contains it. | 1398 | * Reads a specified block, and returns buffer head that contains it. |
1399 | * The page cache can be allocated from non-movable area | ||
1400 | * not to prevent page migration if you set gfp to zero. | ||
1415 | * It returns NULL if the block was unreadable. | 1401 | * It returns NULL if the block was unreadable. |
1416 | */ | 1402 | */ |
1417 | struct buffer_head * | 1403 | struct buffer_head * |
1418 | __bread(struct block_device *bdev, sector_t block, unsigned size) | 1404 | __bread_gfp(struct block_device *bdev, sector_t block, |
1405 | unsigned size, gfp_t gfp) | ||
1419 | { | 1406 | { |
1420 | struct buffer_head *bh = __getblk(bdev, block, size); | 1407 | struct buffer_head *bh = __getblk_gfp(bdev, block, size, gfp); |
1421 | 1408 | ||
1422 | if (likely(bh) && !buffer_uptodate(bh)) | 1409 | if (likely(bh) && !buffer_uptodate(bh)) |
1423 | bh = __bread_slow(bh); | 1410 | bh = __bread_slow(bh); |
1424 | return bh; | 1411 | return bh; |
1425 | } | 1412 | } |
1426 | EXPORT_SYMBOL(__bread); | 1413 | EXPORT_SYMBOL(__bread_gfp); |
1427 | 1414 | ||
1428 | /* | 1415 | /* |
1429 | * invalidate_bh_lrus() is called rarely - but not only at unmount. | 1416 | * invalidate_bh_lrus() is called rarely - but not only at unmount. |
@@ -2082,6 +2069,7 @@ int generic_write_end(struct file *file, struct address_space *mapping, | |||
2082 | struct page *page, void *fsdata) | 2069 | struct page *page, void *fsdata) |
2083 | { | 2070 | { |
2084 | struct inode *inode = mapping->host; | 2071 | struct inode *inode = mapping->host; |
2072 | loff_t old_size = inode->i_size; | ||
2085 | int i_size_changed = 0; | 2073 | int i_size_changed = 0; |
2086 | 2074 | ||
2087 | copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); | 2075 | copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); |
@@ -2101,6 +2089,8 @@ int generic_write_end(struct file *file, struct address_space *mapping, | |||
2101 | unlock_page(page); | 2089 | unlock_page(page); |
2102 | page_cache_release(page); | 2090 | page_cache_release(page); |
2103 | 2091 | ||
2092 | if (old_size < pos) | ||
2093 | pagecache_isize_extended(inode, old_size, pos); | ||
2104 | /* | 2094 | /* |
2105 | * Don't mark the inode dirty under page lock. First, it unnecessarily | 2095 | * Don't mark the inode dirty under page lock. First, it unnecessarily |
2106 | * makes the holding time of page lock longer. Second, it forces lock | 2096 | * makes the holding time of page lock longer. Second, it forces lock |
@@ -2318,6 +2308,11 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping, | |||
2318 | err = 0; | 2308 | err = 0; |
2319 | 2309 | ||
2320 | balance_dirty_pages_ratelimited(mapping); | 2310 | balance_dirty_pages_ratelimited(mapping); |
2311 | |||
2312 | if (unlikely(fatal_signal_pending(current))) { | ||
2313 | err = -EINTR; | ||
2314 | goto out; | ||
2315 | } | ||
2321 | } | 2316 | } |
2322 | 2317 | ||
2323 | /* page covers the boundary, find the boundary offset */ | 2318 | /* page covers the boundary, find the boundary offset */ |
@@ -2956,7 +2951,7 @@ static void end_bio_bh_io_sync(struct bio *bio, int err) | |||
2956 | 2951 | ||
2957 | /* | 2952 | /* |
2958 | * This allows us to do IO even on the odd last sectors | 2953 | * This allows us to do IO even on the odd last sectors |
2959 | * of a device, even if the bh block size is some multiple | 2954 | * of a device, even if the block size is some multiple |
2960 | * of the physical sector size. | 2955 | * of the physical sector size. |
2961 | * | 2956 | * |
2962 | * We'll just truncate the bio to the size of the device, | 2957 | * We'll just truncate the bio to the size of the device, |
@@ -2966,10 +2961,11 @@ static void end_bio_bh_io_sync(struct bio *bio, int err) | |||
2966 | * errors, this only handles the "we need to be able to | 2961 | * errors, this only handles the "we need to be able to |
2967 | * do IO at the final sector" case. | 2962 | * do IO at the final sector" case. |
2968 | */ | 2963 | */ |
2969 | static void guard_bh_eod(int rw, struct bio *bio, struct buffer_head *bh) | 2964 | void guard_bio_eod(int rw, struct bio *bio) |
2970 | { | 2965 | { |
2971 | sector_t maxsector; | 2966 | sector_t maxsector; |
2972 | unsigned bytes; | 2967 | struct bio_vec *bvec = &bio->bi_io_vec[bio->bi_vcnt - 1]; |
2968 | unsigned truncated_bytes; | ||
2973 | 2969 | ||
2974 | maxsector = i_size_read(bio->bi_bdev->bd_inode) >> 9; | 2970 | maxsector = i_size_read(bio->bi_bdev->bd_inode) >> 9; |
2975 | if (!maxsector) | 2971 | if (!maxsector) |
@@ -2984,23 +2980,20 @@ static void guard_bh_eod(int rw, struct bio *bio, struct buffer_head *bh) | |||
2984 | return; | 2980 | return; |
2985 | 2981 | ||
2986 | maxsector -= bio->bi_iter.bi_sector; | 2982 | maxsector -= bio->bi_iter.bi_sector; |
2987 | bytes = bio->bi_iter.bi_size; | 2983 | if (likely((bio->bi_iter.bi_size >> 9) <= maxsector)) |
2988 | if (likely((bytes >> 9) <= maxsector)) | ||
2989 | return; | 2984 | return; |
2990 | 2985 | ||
2991 | /* Uhhuh. We've got a bh that straddles the device size! */ | 2986 | /* Uhhuh. We've got a bio that straddles the device size! */ |
2992 | bytes = maxsector << 9; | 2987 | truncated_bytes = bio->bi_iter.bi_size - (maxsector << 9); |
2993 | 2988 | ||
2994 | /* Truncate the bio.. */ | 2989 | /* Truncate the bio.. */ |
2995 | bio->bi_iter.bi_size = bytes; | 2990 | bio->bi_iter.bi_size -= truncated_bytes; |
2996 | bio->bi_io_vec[0].bv_len = bytes; | 2991 | bvec->bv_len -= truncated_bytes; |
2997 | 2992 | ||
2998 | /* ..and clear the end of the buffer for reads */ | 2993 | /* ..and clear the end of the buffer for reads */ |
2999 | if ((rw & RW_MASK) == READ) { | 2994 | if ((rw & RW_MASK) == READ) { |
3000 | void *kaddr = kmap_atomic(bh->b_page); | 2995 | zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len, |
3001 | memset(kaddr + bh_offset(bh) + bytes, 0, bh->b_size - bytes); | 2996 | truncated_bytes); |
3002 | kunmap_atomic(kaddr); | ||
3003 | flush_dcache_page(bh->b_page); | ||
3004 | } | 2997 | } |
3005 | } | 2998 | } |
3006 | 2999 | ||
@@ -3041,7 +3034,7 @@ int _submit_bh(int rw, struct buffer_head *bh, unsigned long bio_flags) | |||
3041 | bio->bi_flags |= bio_flags; | 3034 | bio->bi_flags |= bio_flags; |
3042 | 3035 | ||
3043 | /* Take care of bh's that straddle the end of the device */ | 3036 | /* Take care of bh's that straddle the end of the device */ |
3044 | guard_bh_eod(rw, bio, bh); | 3037 | guard_bio_eod(rw, bio); |
3045 | 3038 | ||
3046 | if (buffer_meta(bh)) | 3039 | if (buffer_meta(bh)) |
3047 | rw |= REQ_META; | 3040 | rw |= REQ_META; |