Commit ff01bb4832651c6d25ac509a06a10fcbd75c461c
1 parent
94ea4158f1
Exists in
master
and in
6 other branches
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
- block/genhd.c
- block/ioctl.c
- drivers/block/amiflop.c
- drivers/block/brd.c
- drivers/block/floppy.c
- drivers/block/loop.c
- drivers/cdrom/cdrom.c
- drivers/md/dm.c
- drivers/md/md.c
- drivers/mtd/devices/block2mtd.c
- drivers/s390/block/dasd.c
- drivers/scsi/scsicam.c
- drivers/tty/sysrq.c
- fs/block_dev.c
- fs/buffer.c
- fs/cachefiles/interface.c
- fs/cramfs/inode.c
- fs/fs-writeback.c
- fs/libfs.c
- fs/quota/dquot.c
- fs/quota/quota.c
- fs/splice.c
- fs/sync.c
- include/linux/fs.h
- kernel/power/swap.c
- mm/page-writeback.c
- mm/swap_state.c
arch/powerpc/sysdev/axonram.c
block/genhd.c
block/ioctl.c
drivers/block/amiflop.c
drivers/block/brd.c
... | ... | @@ -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
drivers/cdrom/cdrom.c
drivers/md/dm.c
drivers/md/md.c
... | ... | @@ -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
drivers/s390/block/dasd.c
drivers/scsi/scsicam.c
drivers/tty/sysrq.c
... | ... | @@ -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> |
fs/block_dev.c
... | ... | @@ -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 | { |
fs/buffer.c
... | ... | @@ -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
fs/cramfs/inode.c
fs/fs-writeback.c
fs/libfs.c
fs/quota/dquot.c
fs/quota/quota.c
fs/splice.c
fs/sync.c
include/linux/fs.h
... | ... | @@ -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 *, |
kernel/power/swap.c
mm/page-writeback.c
... | ... | @@ -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 |
mm/swap_state.c