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

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>

Al Viro ff01bb48 94ea4158

+40 -83
-1
arch/powerpc/sysdev/axonram.c
··· 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>
-1
block/genhd.c
··· 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>
+1 -1
block/ioctl.c
··· 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
+1 -1
drivers/block/amiflop.c
··· 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>
+4 -5
drivers/block/brd.c
··· 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> ··· 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 }
-1
drivers/block/floppy.c
··· 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>
-1
drivers/block/loop.c
··· 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>
-1
drivers/cdrom/cdrom.c
··· 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>
-1
drivers/md/dm.c
··· 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>
+1 -2
drivers/md/md.c
··· 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>
-1
drivers/mtd/devices/block2mtd.c
··· 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>
-1
drivers/s390/block/dasd.c
··· 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>
-1
drivers/scsi/scsicam.c
··· 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>
+1 -1
drivers/tty/sysrq.c
··· 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> ··· 40 41 #include <linux/oom.h> 41 42 #include <linux/slab.h> 42 43 #include <linux/input.h> 44 + #include <linux/uaccess.h> 43 45 44 46 #include <asm/ptrace.h> 45 47 #include <asm/irq_regs.h>
+27 -3
fs/block_dev.c
··· 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> ··· 26 25 #include <linux/namei.h> 27 26 #include <linux/log2.h> 28 27 #include <linux/kmemleak.h> 28 + #include <linux/cleancache.h> 29 29 #include <asm/uaccess.h> 30 30 #include "internal.h" 31 31 ··· 84 82 } 85 83 86 84 /* Kill _all_ buffers and pagecache , dirty or not.. */ 87 - static void kill_bdev(struct block_device *bdev) 85 + void kill_bdev(struct block_device *bdev) 88 86 { 89 - if (bdev->bd_inode->i_mapping->nrpages == 0) 87 + struct address_space *mapping = bdev->bd_inode->i_mapping; 88 + 89 + if (mapping->nrpages == 0) 90 90 return; 91 + 91 92 invalidate_bh_lrus(); 92 - truncate_inode_pages(bdev->bd_inode->i_mapping, 0); 93 + truncate_inode_pages(mapping, 0); 93 94 } 95 + EXPORT_SYMBOL(kill_bdev); 96 + 97 + /* Invalidate clean unused buffers and pagecache. */ 98 + void invalidate_bdev(struct block_device *bdev) 99 + { 100 + struct address_space *mapping = bdev->bd_inode->i_mapping; 101 + 102 + if (mapping->nrpages == 0) 103 + return; 104 + 105 + invalidate_bh_lrus(); 106 + lru_add_drain_all(); /* make sure all lru add caches are flushed */ 107 + invalidate_mapping_pages(mapping, 0, -1); 108 + /* 99% of the time, we don't need to flush the cleancache on the bdev. 109 + * But, for the strange corners, lets be cautious 110 + */ 111 + cleancache_flush_inode(mapping); 112 + } 113 + EXPORT_SYMBOL(invalidate_bdev); 94 114 95 115 int set_blocksize(struct block_device *bdev, int size) 96 116 {
-50
fs/buffer.c
··· 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 ··· 229 230 out: 230 231 return ret; 231 232 } 232 - 233 - /* If invalidate_buffers() will trash dirty buffers, it means some kind 234 - of fs corruption is going on. Trashing dirty data always imply losing 235 - information that was supposed to be just stored on the physical layer 236 - by the user. 237 - 238 - Thus invalidate_buffers in general usage is not allwowed to trash 239 - dirty buffers. For example ioctl(FLSBLKBUF) expects dirty data to 240 - be preserved. These buffers are simply skipped. 241 - 242 - We also skip buffers which are still in use. For example this can 243 - happen if a userspace program is reading the block device. 244 - 245 - NOTE: In the case where the user removed a removable-media-disk even if 246 - there's still dirty data not synced on disk (due a bug in the device driver 247 - or due an error of the user), by not destroying the dirty buffers we could 248 - generate corruption also on the next media inserted, thus a parameter is 249 - necessary to handle this case in the most safe way possible (trying 250 - to not corrupt also the new disk inserted with the data belonging to 251 - the old now corrupted disk). Also for the ramdisk the natural thing 252 - to do in order to release the ramdisk memory is to destroy dirty buffers. 253 - 254 - These are two special cases. Normal usage imply the device driver 255 - to issue a sync on the device (without waiting I/O completion) and 256 - then an invalidate_buffers call that doesn't trash dirty buffers. 257 - 258 - For handling cache coherency with the blkdev pagecache the 'update' case 259 - is been introduced. It is needed to re-read from disk any pinned 260 - buffer. NOTE: re-reading from disk is destructive so we can do it only 261 - when we assume nobody is changing the buffercache under our I/O and when 262 - we think the disk contains more recent information than the buffercache. 263 - The update == 1 pass marks the buffers we need to update, the update == 2 264 - pass does the actual I/O. */ 265 - void invalidate_bdev(struct block_device *bdev) 266 - { 267 - struct address_space *mapping = bdev->bd_inode->i_mapping; 268 - 269 - if (mapping->nrpages == 0) 270 - return; 271 - 272 - invalidate_bh_lrus(); 273 - lru_add_drain_all(); /* make sure all lru add caches are flushed */ 274 - invalidate_mapping_pages(mapping, 0, -1); 275 - /* 99% of the time, we don't need to flush the cleancache on the bdev. 276 - * But, for the strange corners, lets be cautious 277 - */ 278 - cleancache_flush_inode(mapping); 279 - } 280 - EXPORT_SYMBOL(invalidate_bdev); 281 233 282 234 /* 283 235 * Kick the writeback threads then try to free up some ZONE_NORMAL memory.
-1
fs/cachefiles/interface.c
··· 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))
-1
fs/cramfs/inode.c
··· 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
-1
fs/fs-writeback.c
··· 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
+1 -1
fs/libfs.c
··· 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
-1
fs/quota/dquot.c
··· 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 */
-1
fs/quota/quota.c
··· 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>
-1
fs/splice.c
··· 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>
-1
fs/sync.c
··· 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
+3
include/linux/fs.h
··· 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); ··· 2100 2099 #else 2101 2100 static inline void bd_forget(struct inode *inode) {} 2102 2101 static inline int sync_blockdev(struct block_device *bdev) { return 0; } 2102 + static inline void kill_bdev(struct block_device *bdev) {} 2103 2103 static inline void invalidate_bdev(struct block_device *bdev) {} 2104 2104 2105 2105 static inline struct super_block *freeze_bdev(struct block_device *sb) ··· 2417 2415 unsigned long nr_segs, loff_t pos); 2418 2416 extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end, 2419 2417 int datasync); 2418 + extern void block_sync_page(struct page *page); 2420 2419 2421 2420 /* fs/splice.c */ 2422 2421 extern ssize_t generic_file_splice_read(struct file *, loff_t *,
-1
kernel/power/swap.c
··· 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>
+1 -1
mm/page-writeback.c
··· 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
-1
mm/swap_state.c
··· 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>