hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/fs/buffer.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/fs/buffer.c
34 *
....@@ -47,6 +48,8 @@
4748 #include <linux/sched/mm.h>
4849 #include <trace/events/block.h>
4950 #include <linux/fscrypt.h>
51
+
52
+#include "internal.h"
5053
5154 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
5255 static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
....@@ -120,14 +123,6 @@
120123 }
121124 EXPORT_SYMBOL(__wait_on_buffer);
122125
123
-static void
124
-__clear_page_buffers(struct page *page)
125
-{
126
- ClearPagePrivate(page);
127
- set_page_private(page, 0);
128
- put_page(page);
129
-}
130
-
131126 static void buffer_io_error(struct buffer_head *bh, char *msg)
132127 {
133128 if (!test_bit(BH_Quiet, &bh->b_state))
....@@ -178,7 +173,7 @@
178173 unlock_buffer(bh);
179174 put_bh(bh);
180175 }
181
-EXPORT_SYMBOL(end_buffer_write_sync);
176
+EXPORT_SYMBOL_NS(end_buffer_write_sync, ANDROID_GKI_VFS_EXPORT_ONLY);
182177
183178 /*
184179 * Various filesystems appear to want __find_get_block to be non-blocking.
....@@ -246,10 +241,6 @@
246241 return ret;
247242 }
248243
249
-/*
250
- * I/O completion handler for block_read_full_page() - pages
251
- * which come unlocked at the end of I/O.
252
- */
253244 static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
254245 {
255246 unsigned long flags;
....@@ -275,7 +266,7 @@
275266 * decide that the page is now completely done.
276267 */
277268 first = page_buffers(page);
278
- flags = bh_uptodate_lock_irqsave(first);
269
+ spin_lock_irqsave(&first->b_uptodate_lock, flags);
279270 clear_buffer_async_read(bh);
280271 unlock_buffer(bh);
281272 tmp = bh;
....@@ -288,7 +279,7 @@
288279 }
289280 tmp = tmp->b_this_page;
290281 } while (tmp != bh);
291
- bh_uptodate_unlock_irqrestore(first, flags);
282
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
292283
293284 /*
294285 * If none of the buffers had errors and they are all
....@@ -300,7 +291,48 @@
300291 return;
301292
302293 still_busy:
303
- bh_uptodate_unlock_irqrestore(first, flags);
294
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
295
+ return;
296
+}
297
+
298
+struct decrypt_bh_ctx {
299
+ struct work_struct work;
300
+ struct buffer_head *bh;
301
+};
302
+
303
+static void decrypt_bh(struct work_struct *work)
304
+{
305
+ struct decrypt_bh_ctx *ctx =
306
+ container_of(work, struct decrypt_bh_ctx, work);
307
+ struct buffer_head *bh = ctx->bh;
308
+ int err;
309
+
310
+ err = fscrypt_decrypt_pagecache_blocks(bh->b_page, bh->b_size,
311
+ bh_offset(bh));
312
+ end_buffer_async_read(bh, err == 0);
313
+ kfree(ctx);
314
+}
315
+
316
+/*
317
+ * I/O completion handler for block_read_full_page() - pages
318
+ * which come unlocked at the end of I/O.
319
+ */
320
+static void end_buffer_async_read_io(struct buffer_head *bh, int uptodate)
321
+{
322
+ /* Decrypt if needed */
323
+ if (uptodate &&
324
+ fscrypt_inode_uses_fs_layer_crypto(bh->b_page->mapping->host)) {
325
+ struct decrypt_bh_ctx *ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
326
+
327
+ if (ctx) {
328
+ INIT_WORK(&ctx->work, decrypt_bh);
329
+ ctx->bh = bh;
330
+ fscrypt_enqueue_decrypt_work(&ctx->work);
331
+ return;
332
+ }
333
+ uptodate = 0;
334
+ }
335
+ end_buffer_async_read(bh, uptodate);
304336 }
305337
306338 /*
....@@ -327,7 +359,7 @@
327359 }
328360
329361 first = page_buffers(page);
330
- flags = bh_uptodate_lock_irqsave(first);
362
+ spin_lock_irqsave(&first->b_uptodate_lock, flags);
331363
332364 clear_buffer_async_write(bh);
333365 unlock_buffer(bh);
....@@ -339,12 +371,13 @@
339371 }
340372 tmp = tmp->b_this_page;
341373 }
342
- bh_uptodate_unlock_irqrestore(first, flags);
374
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
343375 end_page_writeback(page);
344376 return;
345377
346378 still_busy:
347
- bh_uptodate_unlock_irqrestore(first, flags);
379
+ spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
380
+ return;
348381 }
349382 EXPORT_SYMBOL(end_buffer_async_write);
350383
....@@ -371,7 +404,7 @@
371404 */
372405 static void mark_buffer_async_read(struct buffer_head *bh)
373406 {
374
- bh->b_end_io = end_buffer_async_read;
407
+ bh->b_end_io = end_buffer_async_read_io;
375408 set_buffer_async_read(bh);
376409 }
377410
....@@ -386,7 +419,7 @@
386419 {
387420 mark_buffer_async_write_endio(bh, end_buffer_async_write);
388421 }
389
-EXPORT_SYMBOL(mark_buffer_async_write);
422
+EXPORT_SYMBOL_NS(mark_buffer_async_write, ANDROID_GKI_VFS_EXPORT_ONLY);
390423
391424
392425 /*
....@@ -490,7 +523,7 @@
490523
491524 void emergency_thaw_bdev(struct super_block *sb)
492525 {
493
- while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
526
+ while (sb->s_bdev && !thaw_bdev(sb->s_bdev))
494527 printk(KERN_WARNING "Emergency Thaw on %pg\n", sb->s_bdev);
495528 }
496529
....@@ -556,7 +589,7 @@
556589 EXPORT_SYMBOL(mark_buffer_dirty_inode);
557590
558591 /*
559
- * Mark the page dirty, and set it dirty in the radix tree, and mark the inode
592
+ * Mark the page dirty, and set it dirty in the page cache, and mark the inode
560593 * dirty.
561594 *
562595 * If warn is true, then emit a warning if the page is not uptodate and has
....@@ -573,8 +606,8 @@
573606 if (page->mapping) { /* Race with truncate? */
574607 WARN_ON_ONCE(warn && !PageUptodate(page));
575608 account_page_dirtied(page, mapping);
576
- radix_tree_tag_set(&mapping->i_pages,
577
- page_index(page), PAGECACHE_TAG_DIRTY);
609
+ __xa_set_mark(&mapping->i_pages, page_index(page),
610
+ PAGECACHE_TAG_DIRTY);
578611 }
579612 xa_unlock_irqrestore(&mapping->i_pages, flags);
580613 }
....@@ -641,7 +674,7 @@
641674
642675 return newly_dirty;
643676 }
644
-EXPORT_SYMBOL(__set_page_dirty_buffers);
677
+EXPORT_SYMBOL_NS(__set_page_dirty_buffers, ANDROID_GKI_VFS_EXPORT_ONLY);
645678
646679 /*
647680 * Write out and wait upon a list of buffers.
....@@ -809,13 +842,13 @@
809842 struct buffer_head *bh, *head;
810843 gfp_t gfp = GFP_NOFS | __GFP_ACCOUNT;
811844 long offset;
812
- struct mem_cgroup *memcg;
845
+ struct mem_cgroup *memcg, *old_memcg;
813846
814847 if (retry)
815848 gfp |= __GFP_NOFAIL;
816849
817850 memcg = get_mem_cgroup_from_page(page);
818
- memalloc_use_memcg(memcg);
851
+ old_memcg = set_active_memcg(memcg);
819852
820853 head = NULL;
821854 offset = PAGE_SIZE;
....@@ -834,7 +867,7 @@
834867 set_bh_page(bh, page, offset);
835868 }
836869 out:
837
- memalloc_unuse_memcg();
870
+ set_active_memcg(old_memcg);
838871 mem_cgroup_put(memcg);
839872 return head;
840873 /*
....@@ -864,7 +897,7 @@
864897 bh = bh->b_this_page;
865898 } while (bh);
866899 tail->b_this_page = head;
867
- attach_page_buffers(page, head);
900
+ attach_page_private(page, head);
868901 }
869902
870903 static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size)
....@@ -925,7 +958,7 @@
925958 struct page *page;
926959 struct buffer_head *bh;
927960 sector_t end_block;
928
- int ret = 0; /* Will call free_more_memory() */
961
+ int ret = 0;
929962 gfp_t gfp_mask;
930963
931964 gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp;
....@@ -1044,7 +1077,7 @@
10441077 * The relationship between dirty buffers and dirty pages:
10451078 *
10461079 * Whenever a page has any dirty buffers, the page's dirty bit is set, and
1047
- * the page is tagged dirty in its radix tree.
1080
+ * the page is tagged dirty in the page cache.
10481081 *
10491082 * At all times, the dirtiness of the buffers represents the dirtiness of
10501083 * subsections of the page. If the page has buffers, the page dirty bit is
....@@ -1067,9 +1100,9 @@
10671100 * mark_buffer_dirty - mark a buffer_head as needing writeout
10681101 * @bh: the buffer_head to mark dirty
10691102 *
1070
- * mark_buffer_dirty() will set the dirty bit against the buffer, then set its
1071
- * backing page dirty, then tag the page as dirty in its address_space's radix
1072
- * tree and then attach the address_space's inode to its superblock's dirty
1103
+ * mark_buffer_dirty() will set the dirty bit against the buffer, then set
1104
+ * its backing page dirty, then tag the page as dirty in the page cache
1105
+ * and then attach the address_space's inode to its superblock's dirty
10731106 * inode list.
10741107 *
10751108 * mark_buffer_dirty() is atomic. It takes bh->b_page->mapping->private_lock,
....@@ -1108,18 +1141,25 @@
11081141 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
11091142 }
11101143 }
1111
-EXPORT_SYMBOL(mark_buffer_dirty);
1144
+EXPORT_SYMBOL_NS(mark_buffer_dirty, ANDROID_GKI_VFS_EXPORT_ONLY);
11121145
11131146 void mark_buffer_write_io_error(struct buffer_head *bh)
11141147 {
1148
+ struct super_block *sb;
1149
+
11151150 set_buffer_write_io_error(bh);
11161151 /* FIXME: do we need to set this in both places? */
11171152 if (bh->b_page && bh->b_page->mapping)
11181153 mapping_set_error(bh->b_page->mapping, -EIO);
11191154 if (bh->b_assoc_map)
11201155 mapping_set_error(bh->b_assoc_map, -EIO);
1156
+ rcu_read_lock();
1157
+ sb = READ_ONCE(bh->b_bdev->bd_super);
1158
+ if (sb)
1159
+ errseq_set(&sb->s_wb_err, -EIO);
1160
+ rcu_read_unlock();
11211161 }
1122
-EXPORT_SYMBOL(mark_buffer_write_io_error);
1162
+EXPORT_SYMBOL_NS(mark_buffer_write_io_error, ANDROID_GKI_VFS_EXPORT_ONLY);
11231163
11241164 /*
11251165 * Decrement a buffer_head's reference count. If all buffers against a page
....@@ -1136,7 +1176,7 @@
11361176 }
11371177 WARN(1, KERN_ERR "VFS: brelse: Trying to free free buffer\n");
11381178 }
1139
-EXPORT_SYMBOL(__brelse);
1179
+EXPORT_SYMBOL_NS(__brelse, ANDROID_GKI_VFS_EXPORT_ONLY);
11401180
11411181 /*
11421182 * bforget() is like brelse(), except it discards any
....@@ -1155,7 +1195,7 @@
11551195 }
11561196 __brelse(bh);
11571197 }
1158
-EXPORT_SYMBOL(__bforget);
1198
+EXPORT_SYMBOL_NS(__bforget, ANDROID_GKI_VFS_EXPORT_ONLY);
11591199
11601200 static struct buffer_head *__bread_slow(struct buffer_head *bh)
11611201 {
....@@ -1224,6 +1264,15 @@
12241264 int i;
12251265
12261266 check_irqs_on();
1267
+ /*
1268
+ * the refcount of buffer_head in bh_lru prevents dropping the
1269
+ * attached page(i.e., try_to_free_buffers) so it could cause
1270
+ * failing page migration.
1271
+ * Skip putting upcoming bh into bh_lru until migration is done.
1272
+ */
1273
+ if (lru_cache_disabled())
1274
+ return;
1275
+
12271276 bh_lru_lock();
12281277
12291278 b = this_cpu_ptr(&bh_lrus);
....@@ -1327,7 +1376,7 @@
13271376 brelse(bh);
13281377 }
13291378 }
1330
-EXPORT_SYMBOL(__breadahead);
1379
+EXPORT_SYMBOL_NS(__breadahead, ANDROID_GKI_VFS_EXPORT_ONLY);
13311380
13321381 void __breadahead_gfp(struct block_device *bdev, sector_t block, unsigned size,
13331382 gfp_t gfp)
....@@ -1362,8 +1411,17 @@
13621411 bh = __bread_slow(bh);
13631412 return bh;
13641413 }
1365
-EXPORT_SYMBOL(__bread_gfp);
1414
+EXPORT_SYMBOL_NS(__bread_gfp, ANDROID_GKI_VFS_EXPORT_ONLY);
13661415
1416
+static void __invalidate_bh_lrus(struct bh_lru *b)
1417
+{
1418
+ int i;
1419
+
1420
+ for (i = 0; i < BH_LRU_SIZE; i++) {
1421
+ brelse(b->bhs[i]);
1422
+ b->bhs[i] = NULL;
1423
+ }
1424
+}
13671425 /*
13681426 * invalidate_bh_lrus() is called rarely - but not only at unmount.
13691427 * This doesn't race because it runs in each cpu either in irq
....@@ -1372,33 +1430,43 @@
13721430 static void invalidate_bh_lru(void *arg)
13731431 {
13741432 struct bh_lru *b = &get_cpu_var(bh_lrus);
1375
- int i;
13761433
1377
- for (i = 0; i < BH_LRU_SIZE; i++) {
1378
- brelse(b->bhs[i]);
1379
- b->bhs[i] = NULL;
1380
- }
1434
+ __invalidate_bh_lrus(b);
13811435 put_cpu_var(bh_lrus);
13821436 }
13831437
1384
-static bool has_bh_in_lru(int cpu, void *dummy)
1438
+bool has_bh_in_lru(int cpu, void *dummy)
13851439 {
13861440 struct bh_lru *b = per_cpu_ptr(&bh_lrus, cpu);
13871441 int i;
13881442
13891443 for (i = 0; i < BH_LRU_SIZE; i++) {
13901444 if (b->bhs[i])
1391
- return 1;
1445
+ return true;
13921446 }
13931447
1394
- return 0;
1448
+ return false;
13951449 }
13961450
13971451 void invalidate_bh_lrus(void)
13981452 {
1399
- on_each_cpu_cond(has_bh_in_lru, invalidate_bh_lru, NULL, 1, GFP_KERNEL);
1453
+ on_each_cpu_cond(has_bh_in_lru, invalidate_bh_lru, NULL, 1);
14001454 }
14011455 EXPORT_SYMBOL_GPL(invalidate_bh_lrus);
1456
+
1457
+/*
1458
+ * It's called from workqueue context so we need a bh_lru_lock to close
1459
+ * the race with preemption/irq.
1460
+ */
1461
+void invalidate_bh_lrus_cpu(void)
1462
+{
1463
+ struct bh_lru *b;
1464
+
1465
+ bh_lru_lock();
1466
+ b = this_cpu_ptr(&bh_lrus);
1467
+ __invalidate_bh_lrus(b);
1468
+ bh_lru_unlock();
1469
+}
14021470
14031471 void set_bh_page(struct buffer_head *bh,
14041472 struct page *page, unsigned long offset)
....@@ -1505,7 +1573,7 @@
15051573 out:
15061574 return;
15071575 }
1508
-EXPORT_SYMBOL(block_invalidatepage);
1576
+EXPORT_SYMBOL_NS(block_invalidatepage, ANDROID_GKI_VFS_EXPORT_ONLY);
15091577
15101578
15111579 /*
....@@ -1538,10 +1606,10 @@
15381606 bh = bh->b_this_page;
15391607 } while (bh != head);
15401608 }
1541
- attach_page_buffers(page, head);
1609
+ attach_page_private(page, head);
15421610 spin_unlock(&page->mapping->private_lock);
15431611 }
1544
-EXPORT_SYMBOL(create_empty_buffers);
1612
+EXPORT_SYMBOL_NS(create_empty_buffers, ANDROID_GKI_VFS_EXPORT_ONLY);
15451613
15461614 /**
15471615 * clean_bdev_aliases: clean a range of buffers in block device
....@@ -1615,7 +1683,7 @@
16151683 break;
16161684 }
16171685 }
1618
-EXPORT_SYMBOL(clean_bdev_aliases);
1686
+EXPORT_SYMBOL_NS(clean_bdev_aliases, ANDROID_GKI_VFS_EXPORT_ONLY);
16191687
16201688 /*
16211689 * Size is a power-of-two in the range 512..PAGE_SIZE,
....@@ -1873,7 +1941,7 @@
18731941 bh = bh->b_this_page;
18741942 } while (bh != head);
18751943 }
1876
-EXPORT_SYMBOL(page_zero_new_buffers);
1944
+EXPORT_SYMBOL_NS(page_zero_new_buffers, ANDROID_GKI_VFS_EXPORT_ONLY);
18771945
18781946 static void
18791947 iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,
....@@ -1918,7 +1986,7 @@
19181986 */
19191987 set_buffer_new(bh);
19201988 set_buffer_unwritten(bh);
1921
- /* FALLTHRU */
1989
+ fallthrough;
19221990 case IOMAP_MAPPED:
19231991 if ((iomap->flags & IOMAP_F_NEW) ||
19241992 offset >= i_size_read(inode))
....@@ -2089,40 +2157,6 @@
20892157 }
20902158 EXPORT_SYMBOL(block_write_begin);
20912159
2092
-int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
2093
- struct page *page)
2094
-{
2095
- loff_t old_size = inode->i_size;
2096
- bool i_size_changed = false;
2097
-
2098
- /*
2099
- * No need to use i_size_read() here, the i_size cannot change under us
2100
- * because we hold i_rwsem.
2101
- *
2102
- * But it's important to update i_size while still holding page lock:
2103
- * page writeout could otherwise come in and zero beyond i_size.
2104
- */
2105
- if (pos + copied > inode->i_size) {
2106
- i_size_write(inode, pos + copied);
2107
- i_size_changed = true;
2108
- }
2109
-
2110
- unlock_page(page);
2111
- put_page(page);
2112
-
2113
- if (old_size < pos)
2114
- pagecache_isize_extended(inode, old_size, pos);
2115
- /*
2116
- * Don't mark the inode dirty under page lock. First, it unnecessarily
2117
- * makes the holding time of page lock longer. Second, it forces lock
2118
- * ordering of page lock and transaction start for journaling
2119
- * filesystems.
2120
- */
2121
- if (i_size_changed)
2122
- mark_inode_dirty(inode);
2123
- return copied;
2124
-}
2125
-
21262160 int block_write_end(struct file *file, struct address_space *mapping,
21272161 loff_t pos, unsigned len, unsigned copied,
21282162 struct page *page, void *fsdata)
....@@ -2163,8 +2197,38 @@
21632197 loff_t pos, unsigned len, unsigned copied,
21642198 struct page *page, void *fsdata)
21652199 {
2200
+ struct inode *inode = mapping->host;
2201
+ loff_t old_size = inode->i_size;
2202
+ bool i_size_changed = false;
2203
+
21662204 copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
2167
- return __generic_write_end(mapping->host, pos, copied, page);
2205
+
2206
+ /*
2207
+ * No need to use i_size_read() here, the i_size cannot change under us
2208
+ * because we hold i_rwsem.
2209
+ *
2210
+ * But it's important to update i_size while still holding page lock:
2211
+ * page writeout could otherwise come in and zero beyond i_size.
2212
+ */
2213
+ if (pos + copied > inode->i_size) {
2214
+ i_size_write(inode, pos + copied);
2215
+ i_size_changed = true;
2216
+ }
2217
+
2218
+ unlock_page(page);
2219
+ put_page(page);
2220
+
2221
+ if (old_size < pos)
2222
+ pagecache_isize_extended(inode, old_size, pos);
2223
+ /*
2224
+ * Don't mark the inode dirty under page lock. First, it unnecessarily
2225
+ * makes the holding time of page lock longer. Second, it forces lock
2226
+ * ordering of page lock and transaction start for journaling
2227
+ * filesystems.
2228
+ */
2229
+ if (i_size_changed)
2230
+ mark_inode_dirty(inode);
2231
+ return copied;
21682232 }
21692233 EXPORT_SYMBOL(generic_write_end);
21702234
....@@ -2211,7 +2275,7 @@
22112275
22122276 return ret;
22132277 }
2214
-EXPORT_SYMBOL(block_is_partially_uptodate);
2278
+EXPORT_SYMBOL_NS(block_is_partially_uptodate, ANDROID_GKI_VFS_EXPORT_ONLY);
22152279
22162280 /*
22172281 * Generic "read page" function for block devices that have the normal
....@@ -2314,7 +2378,7 @@
23142378 {
23152379 struct address_space *mapping = inode->i_mapping;
23162380 struct page *page;
2317
- void *fsdata;
2381
+ void *fsdata = NULL;
23182382 int err;
23192383
23202384 err = inode_newsize_ok(inode, size);
....@@ -2340,7 +2404,7 @@
23402404 struct inode *inode = mapping->host;
23412405 unsigned int blocksize = i_blocksize(inode);
23422406 struct page *page;
2343
- void *fsdata;
2407
+ void *fsdata = NULL;
23442408 pgoff_t index, curidx;
23452409 loff_t curpos;
23462410 unsigned zerofrom, offset, len;
....@@ -2371,7 +2435,7 @@
23712435
23722436 balance_dirty_pages_ratelimited(mapping);
23732437
2374
- if (unlikely(fatal_signal_pending(current))) {
2438
+ if (fatal_signal_pending(current)) {
23752439 err = -EINTR;
23762440 goto out;
23772441 }
....@@ -2529,7 +2593,7 @@
25292593 bh->b_this_page = head;
25302594 bh = bh->b_this_page;
25312595 } while (bh != head);
2532
- attach_page_buffers(page, head);
2596
+ attach_page_private(page, head);
25332597 spin_unlock(&page->mapping->private_lock);
25342598 }
25352599
....@@ -2970,69 +3034,6 @@
29703034 bio_put(bio);
29713035 }
29723036
2973
-/*
2974
- * This allows us to do IO even on the odd last sectors
2975
- * of a device, even if the block size is some multiple
2976
- * of the physical sector size.
2977
- *
2978
- * We'll just truncate the bio to the size of the device,
2979
- * and clear the end of the buffer head manually.
2980
- *
2981
- * Truly out-of-range accesses will turn into actual IO
2982
- * errors, this only handles the "we need to be able to
2983
- * do IO at the final sector" case.
2984
- */
2985
-void guard_bio_eod(int op, struct bio *bio)
2986
-{
2987
- sector_t maxsector;
2988
- struct bio_vec *bvec = bio_last_bvec_all(bio);
2989
- unsigned truncated_bytes;
2990
- struct hd_struct *part;
2991
-
2992
- rcu_read_lock();
2993
- part = __disk_get_part(bio->bi_disk, bio->bi_partno);
2994
- if (part)
2995
- maxsector = part_nr_sects_read(part);
2996
- else
2997
- maxsector = get_capacity(bio->bi_disk);
2998
- rcu_read_unlock();
2999
-
3000
- if (!maxsector)
3001
- return;
3002
-
3003
- /*
3004
- * If the *whole* IO is past the end of the device,
3005
- * let it through, and the IO layer will turn it into
3006
- * an EIO.
3007
- */
3008
- if (unlikely(bio->bi_iter.bi_sector >= maxsector))
3009
- return;
3010
-
3011
- maxsector -= bio->bi_iter.bi_sector;
3012
- if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
3013
- return;
3014
-
3015
- /* Uhhuh. We've got a bio that straddles the device size! */
3016
- truncated_bytes = bio->bi_iter.bi_size - (maxsector << 9);
3017
-
3018
- /*
3019
- * The bio contains more than one segment which spans EOD, just return
3020
- * and let IO layer turn it into an EIO
3021
- */
3022
- if (truncated_bytes > bvec->bv_len)
3023
- return;
3024
-
3025
- /* Truncate the bio.. */
3026
- bio->bi_iter.bi_size -= truncated_bytes;
3027
- bvec->bv_len -= truncated_bytes;
3028
-
3029
- /* ..and clear the end of the buffer for reads */
3030
- if (op == REQ_OP_READ) {
3031
- zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len,
3032
- truncated_bytes);
3033
- }
3034
-}
3035
-
30363037 static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
30373038 enum rw_hint write_hint, struct writeback_control *wbc)
30383039 {
....@@ -3050,18 +3051,9 @@
30503051 if (test_set_buffer_req(bh) && (op == REQ_OP_WRITE))
30513052 clear_buffer_write_io_error(bh);
30523053
3053
- /*
3054
- * from here on down, it's all bio -- do the initial mapping,
3055
- * submit_bio -> generic_make_request may further map this bio around
3056
- */
30573054 bio = bio_alloc(GFP_NOIO, 1);
30583055
30593056 fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO);
3060
-
3061
- if (wbc) {
3062
- wbc_init_bio(wbc, bio);
3063
- wbc_account_io(wbc, bh->b_page, bh->b_size);
3064
- }
30653057
30663058 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
30673059 bio_set_dev(bio, bh->b_bdev);
....@@ -3073,14 +3065,19 @@
30733065 bio->bi_end_io = end_bio_bh_io_sync;
30743066 bio->bi_private = bh;
30753067
3076
- /* Take care of bh's that straddle the end of the device */
3077
- guard_bio_eod(op, bio);
3078
-
30793068 if (buffer_meta(bh))
30803069 op_flags |= REQ_META;
30813070 if (buffer_prio(bh))
30823071 op_flags |= REQ_PRIO;
30833072 bio_set_op_attrs(bio, op, op_flags);
3073
+
3074
+ /* Take care of bh's that straddle the end of the device */
3075
+ guard_bio_eod(bio);
3076
+
3077
+ if (wbc) {
3078
+ wbc_init_bio(wbc, bio);
3079
+ wbc_account_cgroup_owner(wbc, bh->b_page, bh->b_size);
3080
+ }
30843081
30853082 submit_bio(bio);
30863083 return 0;
....@@ -3145,7 +3142,7 @@
31453142 unlock_buffer(bh);
31463143 }
31473144 }
3148
-EXPORT_SYMBOL(ll_rw_block);
3145
+EXPORT_SYMBOL_NS(ll_rw_block, ANDROID_GKI_VFS_EXPORT_ONLY);
31493146
31503147 void write_dirty_buffer(struct buffer_head *bh, int op_flags)
31513148 {
....@@ -3198,7 +3195,7 @@
31983195 {
31993196 return __sync_dirty_buffer(bh, REQ_SYNC);
32003197 }
3201
-EXPORT_SYMBOL(sync_dirty_buffer);
3198
+EXPORT_SYMBOL_NS(sync_dirty_buffer, ANDROID_GKI_VFS_EXPORT_ONLY);
32023199
32033200 /*
32043201 * try_to_free_buffers() checks if all the buffers on this particular page
....@@ -3247,7 +3244,7 @@
32473244 bh = next;
32483245 } while (bh != head);
32493246 *buffers_to_free = head;
3250
- __clear_page_buffers(page);
3247
+ detach_page_private(page);
32513248 return 1;
32523249 failed:
32533250 return 0;
....@@ -3367,7 +3364,7 @@
33673364 struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
33683365 if (ret) {
33693366 INIT_LIST_HEAD(&ret->b_assoc_buffers);
3370
- buffer_head_init_locks(ret);
3367
+ spin_lock_init(&ret->b_uptodate_lock);
33713368 preempt_disable();
33723369 __this_cpu_inc(bh_accounting.nr);
33733370 recalc_bh_state();