Commit ff01bb4832651c6d25ac509a06a10fcbd75c461c

Authored by Al Viro
1 parent 94ea4158f1

fs: move code out of buffer.c

Move invalidate_bdev, block_sync_page into fs/block_dev.c.  Export
kill_bdev as well, so brd doesn't have to open code it.  Reduce
buffer_head.h requirement accordingly.

Removed a rather large comment from invalidate_bdev, as it looked a bit
obsolete to bother moving.  The small comment replacing it says enough.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 28 changed files with 40 additions and 83 deletions Side-by-side Diff

arch/powerpc/sysdev/axonram.c
... ... @@ -25,7 +25,6 @@
25 25  
26 26 #include <linux/bio.h>
27 27 #include <linux/blkdev.h>
28   -#include <linux/buffer_head.h>
29 28 #include <linux/device.h>
30 29 #include <linux/errno.h>
31 30 #include <linux/fs.h>
... ... @@ -15,7 +15,6 @@
15 15 #include <linux/slab.h>
16 16 #include <linux/kmod.h>
17 17 #include <linux/kobj_map.h>
18   -#include <linux/buffer_head.h>
19 18 #include <linux/mutex.h>
20 19 #include <linux/idr.h>
21 20 #include <linux/log2.h>
... ... @@ -5,7 +5,7 @@
5 5 #include <linux/blkpg.h>
6 6 #include <linux/hdreg.h>
7 7 #include <linux/backing-dev.h>
8   -#include <linux/buffer_head.h>
  8 +#include <linux/fs.h>
9 9 #include <linux/blktrace_api.h>
10 10 #include <asm/uaccess.h>
11 11  
drivers/block/amiflop.c
... ... @@ -63,7 +63,7 @@
63 63 #include <linux/mutex.h>
64 64 #include <linux/amifdreg.h>
65 65 #include <linux/amifd.h>
66   -#include <linux/buffer_head.h>
  66 +#include <linux/fs.h>
67 67 #include <linux/blkdev.h>
68 68 #include <linux/elevator.h>
69 69 #include <linux/interrupt.h>
... ... @@ -17,7 +17,7 @@
17 17 #include <linux/highmem.h>
18 18 #include <linux/mutex.h>
19 19 #include <linux/radix-tree.h>
20   -#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
  20 +#include <linux/fs.h>
21 21 #include <linux/slab.h>
22 22  
23 23 #include <asm/uaccess.h>
24 24  
... ... @@ -402,14 +402,13 @@
402 402 error = -EBUSY;
403 403 if (bdev->bd_openers <= 1) {
404 404 /*
405   - * Invalidate the cache first, so it isn't written
406   - * back to the device.
  405 + * Kill the cache first, so it isn't written back to the
  406 + * device.
407 407 *
408 408 * Another thread might instantiate more buffercache here,
409 409 * but there is not much we can do to close that race.
410 410 */
411   - invalidate_bh_lrus();
412   - truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
  411 + kill_bdev(bdev);
413 412 brd_free_pages(brd);
414 413 error = 0;
415 414 }
drivers/block/floppy.c
... ... @@ -188,7 +188,6 @@
188 188 #include <linux/init.h>
189 189 #include <linux/platform_device.h>
190 190 #include <linux/mod_devicetable.h>
191   -#include <linux/buffer_head.h> /* for invalidate_buffers() */
192 191 #include <linux/mutex.h>
193 192 #include <linux/io.h>
194 193 #include <linux/uaccess.h>
drivers/block/loop.c
... ... @@ -69,7 +69,6 @@
69 69 #include <linux/freezer.h>
70 70 #include <linux/mutex.h>
71 71 #include <linux/writeback.h>
72   -#include <linux/buffer_head.h> /* for invalidate_bdev() */
73 72 #include <linux/completion.h>
74 73 #include <linux/highmem.h>
75 74 #include <linux/kthread.h>
drivers/cdrom/cdrom.c
... ... @@ -267,7 +267,6 @@
267 267  
268 268 #include <linux/module.h>
269 269 #include <linux/fs.h>
270   -#include <linux/buffer_head.h>
271 270 #include <linux/major.h>
272 271 #include <linux/types.h>
273 272 #include <linux/errno.h>
... ... @@ -14,7 +14,6 @@
14 14 #include <linux/moduleparam.h>
15 15 #include <linux/blkpg.h>
16 16 #include <linux/bio.h>
17   -#include <linux/buffer_head.h>
18 17 #include <linux/mempool.h>
19 18 #include <linux/slab.h>
20 19 #include <linux/idr.h>
... ... @@ -36,8 +36,7 @@
36 36 #include <linux/blkdev.h>
37 37 #include <linux/sysctl.h>
38 38 #include <linux/seq_file.h>
39   -#include <linux/mutex.h>
40   -#include <linux/buffer_head.h> /* for invalidate_bdev */
  39 +#include <linux/fs.h>
41 40 #include <linux/poll.h>
42 41 #include <linux/ctype.h>
43 42 #include <linux/string.h>
drivers/mtd/devices/block2mtd.c
... ... @@ -14,7 +14,6 @@
14 14 #include <linux/list.h>
15 15 #include <linux/init.h>
16 16 #include <linux/mtd/mtd.h>
17   -#include <linux/buffer_head.h>
18 17 #include <linux/mutex.h>
19 18 #include <linux/mount.h>
20 19 #include <linux/slab.h>
drivers/s390/block/dasd.c
... ... @@ -17,7 +17,6 @@
17 17 #include <linux/ctype.h>
18 18 #include <linux/major.h>
19 19 #include <linux/slab.h>
20   -#include <linux/buffer_head.h>
21 20 #include <linux/hdreg.h>
22 21 #include <linux/async.h>
23 22 #include <linux/mutex.h>
drivers/scsi/scsicam.c
... ... @@ -16,7 +16,6 @@
16 16 #include <linux/genhd.h>
17 17 #include <linux/kernel.h>
18 18 #include <linux/blkdev.h>
19   -#include <linux/buffer_head.h>
20 19 #include <asm/unaligned.h>
21 20  
22 21 #include <scsi/scsicam.h>
... ... @@ -32,7 +32,6 @@
32 32 #include <linux/module.h>
33 33 #include <linux/suspend.h>
34 34 #include <linux/writeback.h>
35   -#include <linux/buffer_head.h> /* for fsync_bdev() */
36 35 #include <linux/swap.h>
37 36 #include <linux/spinlock.h>
38 37 #include <linux/vt_kern.h>
... ... @@ -41,6 +40,7 @@
41 40 #include <linux/oom.h>
42 41 #include <linux/slab.h>
43 42 #include <linux/input.h>
  43 +#include <linux/uaccess.h>
44 44  
45 45 #include <asm/ptrace.h>
46 46 #include <asm/irq_regs.h>
... ... @@ -17,6 +17,7 @@
17 17 #include <linux/module.h>
18 18 #include <linux/blkpg.h>
19 19 #include <linux/buffer_head.h>
  20 +#include <linux/swap.h>
20 21 #include <linux/pagevec.h>
21 22 #include <linux/writeback.h>
22 23 #include <linux/mpage.h>
... ... @@ -25,6 +26,7 @@
25 26 #include <linux/namei.h>
26 27 #include <linux/log2.h>
27 28 #include <linux/kmemleak.h>
  29 +#include <linux/cleancache.h>
28 30 #include <asm/uaccess.h>
29 31 #include "internal.h"
30 32  
31 33  
32 34  
33 35  
34 36  
... ... @@ -82,13 +84,35 @@
82 84 }
83 85  
84 86 /* Kill _all_ buffers and pagecache , dirty or not.. */
85   -static void kill_bdev(struct block_device *bdev)
  87 +void kill_bdev(struct block_device *bdev)
86 88 {
87   - if (bdev->bd_inode->i_mapping->nrpages == 0)
  89 + struct address_space *mapping = bdev->bd_inode->i_mapping;
  90 +
  91 + if (mapping->nrpages == 0)
88 92 return;
  93 +
89 94 invalidate_bh_lrus();
90   - truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
  95 + truncate_inode_pages(mapping, 0);
91 96 }
  97 +EXPORT_SYMBOL(kill_bdev);
  98 +
  99 +/* Invalidate clean unused buffers and pagecache. */
  100 +void invalidate_bdev(struct block_device *bdev)
  101 +{
  102 + struct address_space *mapping = bdev->bd_inode->i_mapping;
  103 +
  104 + if (mapping->nrpages == 0)
  105 + return;
  106 +
  107 + invalidate_bh_lrus();
  108 + lru_add_drain_all(); /* make sure all lru add caches are flushed */
  109 + invalidate_mapping_pages(mapping, 0, -1);
  110 + /* 99% of the time, we don't need to flush the cleancache on the bdev.
  111 + * But, for the strange corners, lets be cautious
  112 + */
  113 + cleancache_flush_inode(mapping);
  114 +}
  115 +EXPORT_SYMBOL(invalidate_bdev);
92 116  
93 117 int set_blocksize(struct block_device *bdev, int size)
94 118 {
... ... @@ -41,7 +41,6 @@
41 41 #include <linux/bitops.h>
42 42 #include <linux/mpage.h>
43 43 #include <linux/bit_spinlock.h>
44   -#include <linux/cleancache.h>
45 44  
46 45 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
47 46  
... ... @@ -230,55 +229,6 @@
230 229 out:
231 230 return ret;
232 231 }
233   -
234   -/* If invalidate_buffers() will trash dirty buffers, it means some kind
235   - of fs corruption is going on. Trashing dirty data always imply losing
236   - information that was supposed to be just stored on the physical layer
237   - by the user.
238   -
239   - Thus invalidate_buffers in general usage is not allwowed to trash
240   - dirty buffers. For example ioctl(FLSBLKBUF) expects dirty data to
241   - be preserved. These buffers are simply skipped.
242   -
243   - We also skip buffers which are still in use. For example this can
244   - happen if a userspace program is reading the block device.
245   -
246   - NOTE: In the case where the user removed a removable-media-disk even if
247   - there's still dirty data not synced on disk (due a bug in the device driver
248   - or due an error of the user), by not destroying the dirty buffers we could
249   - generate corruption also on the next media inserted, thus a parameter is
250   - necessary to handle this case in the most safe way possible (trying
251   - to not corrupt also the new disk inserted with the data belonging to
252   - the old now corrupted disk). Also for the ramdisk the natural thing
253   - to do in order to release the ramdisk memory is to destroy dirty buffers.
254   -
255   - These are two special cases. Normal usage imply the device driver
256   - to issue a sync on the device (without waiting I/O completion) and
257   - then an invalidate_buffers call that doesn't trash dirty buffers.
258   -
259   - For handling cache coherency with the blkdev pagecache the 'update' case
260   - is been introduced. It is needed to re-read from disk any pinned
261   - buffer. NOTE: re-reading from disk is destructive so we can do it only
262   - when we assume nobody is changing the buffercache under our I/O and when
263   - we think the disk contains more recent information than the buffercache.
264   - The update == 1 pass marks the buffers we need to update, the update == 2
265   - pass does the actual I/O. */
266   -void invalidate_bdev(struct block_device *bdev)
267   -{
268   - struct address_space *mapping = bdev->bd_inode->i_mapping;
269   -
270   - if (mapping->nrpages == 0)
271   - return;
272   -
273   - invalidate_bh_lrus();
274   - lru_add_drain_all(); /* make sure all lru add caches are flushed */
275   - invalidate_mapping_pages(mapping, 0, -1);
276   - /* 99% of the time, we don't need to flush the cleancache on the bdev.
277   - * But, for the strange corners, lets be cautious
278   - */
279   - cleancache_flush_inode(mapping);
280   -}
281   -EXPORT_SYMBOL(invalidate_bdev);
282 232  
283 233 /*
284 234 * Kick the writeback threads then try to free up some ZONE_NORMAL memory.
fs/cachefiles/interface.c
... ... @@ -11,7 +11,6 @@
11 11  
12 12 #include <linux/slab.h>
13 13 #include <linux/mount.h>
14   -#include <linux/buffer_head.h>
15 14 #include "internal.h"
16 15  
17 16 #define list_to_page(head) (list_entry((head)->prev, struct page, lru))
... ... @@ -20,7 +20,6 @@
20 20 #include <linux/cramfs_fs.h>
21 21 #include <linux/slab.h>
22 22 #include <linux/cramfs_fs_sb.h>
23   -#include <linux/buffer_head.h>
24 23 #include <linux/vfs.h>
25 24 #include <linux/mutex.h>
26 25  
... ... @@ -25,7 +25,6 @@
25 25 #include <linux/writeback.h>
26 26 #include <linux/blkdev.h>
27 27 #include <linux/backing-dev.h>
28   -#include <linux/buffer_head.h>
29 28 #include <linux/tracepoint.h>
30 29 #include "internal.h"
31 30  
... ... @@ -12,7 +12,7 @@
12 12 #include <linux/mutex.h>
13 13 #include <linux/exportfs.h>
14 14 #include <linux/writeback.h>
15   -#include <linux/buffer_head.h>
  15 +#include <linux/buffer_head.h> /* sync_mapping_buffers */
16 16  
17 17 #include <asm/uaccess.h>
18 18  
... ... @@ -73,7 +73,6 @@
73 73 #include <linux/security.h>
74 74 #include <linux/kmod.h>
75 75 #include <linux/namei.h>
76   -#include <linux/buffer_head.h>
77 76 #include <linux/capability.h>
78 77 #include <linux/quotaops.h>
79 78 #include "../internal.h" /* ugh */
... ... @@ -13,7 +13,6 @@
13 13 #include <linux/kernel.h>
14 14 #include <linux/security.h>
15 15 #include <linux/syscalls.h>
16   -#include <linux/buffer_head.h>
17 16 #include <linux/capability.h>
18 17 #include <linux/quotaops.h>
19 18 #include <linux/types.h>
... ... @@ -25,7 +25,6 @@
25 25 #include <linux/mm_inline.h>
26 26 #include <linux/swap.h>
27 27 #include <linux/writeback.h>
28   -#include <linux/buffer_head.h>
29 28 #include <linux/module.h>
30 29 #include <linux/syscalls.h>
31 30 #include <linux/uio.h>
... ... @@ -14,7 +14,6 @@
14 14 #include <linux/linkage.h>
15 15 #include <linux/pagemap.h>
16 16 #include <linux/quotaops.h>
17   -#include <linux/buffer_head.h>
18 17 #include <linux/backing-dev.h>
19 18 #include "internal.h"
20 19  
... ... @@ -2092,6 +2092,7 @@
2092 2092 extern void bdput(struct block_device *);
2093 2093 extern void invalidate_bdev(struct block_device *);
2094 2094 extern int sync_blockdev(struct block_device *bdev);
  2095 +extern void kill_bdev(struct block_device *);
2095 2096 extern struct super_block *freeze_bdev(struct block_device *);
2096 2097 extern void emergency_thaw_all(void);
2097 2098 extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
... ... @@ -2099,6 +2100,7 @@
2099 2100 #else
2100 2101 static inline void bd_forget(struct inode *inode) {}
2101 2102 static inline int sync_blockdev(struct block_device *bdev) { return 0; }
  2103 +static inline void kill_bdev(struct block_device *bdev) {}
2102 2104 static inline void invalidate_bdev(struct block_device *bdev) {}
2103 2105  
2104 2106 static inline struct super_block *freeze_bdev(struct block_device *sb)
... ... @@ -2415,6 +2417,7 @@
2415 2417 unsigned long nr_segs, loff_t pos);
2416 2418 extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
2417 2419 int datasync);
  2420 +extern void block_sync_page(struct page *page);
2418 2421  
2419 2422 /* fs/splice.c */
2420 2423 extern ssize_t generic_file_splice_read(struct file *, loff_t *,
... ... @@ -18,7 +18,6 @@
18 18 #include <linux/bitops.h>
19 19 #include <linux/genhd.h>
20 20 #include <linux/device.h>
21   -#include <linux/buffer_head.h>
22 21 #include <linux/bio.h>
23 22 #include <linux/blkdev.h>
24 23 #include <linux/swap.h>
... ... @@ -32,7 +32,7 @@
32 32 #include <linux/sysctl.h>
33 33 #include <linux/cpu.h>
34 34 #include <linux/syscalls.h>
35   -#include <linux/buffer_head.h>
  35 +#include <linux/buffer_head.h> /* __set_page_dirty_buffers */
36 36 #include <linux/pagevec.h>
37 37 #include <trace/events/writeback.h>
38 38  
... ... @@ -13,7 +13,6 @@
13 13 #include <linux/swapops.h>
14 14 #include <linux/init.h>
15 15 #include <linux/pagemap.h>
16   -#include <linux/buffer_head.h>
17 16 #include <linux/backing-dev.h>
18 17 #include <linux/pagevec.h>
19 18 #include <linux/migrate.h>