aboutsummaryrefslogtreecommitdiffstats
path: root/fs/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/buffer.c')
-rw-r--r--fs/buffer.c84
1 files changed, 18 insertions, 66 deletions
diff --git a/fs/buffer.c b/fs/buffer.c
index 1d0852fa728b..aecd057cd0e0 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -24,7 +24,6 @@
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <linux/percpu.h> 25#include <linux/percpu.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/smp_lock.h>
28#include <linux/capability.h> 27#include <linux/capability.h>
29#include <linux/blkdev.h> 28#include <linux/blkdev.h>
30#include <linux/file.h> 29#include <linux/file.h>
@@ -44,7 +43,6 @@
44#include <linux/bit_spinlock.h> 43#include <linux/bit_spinlock.h>
45 44
46static int fsync_buffers_list(spinlock_t *lock, struct list_head *list); 45static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
47static void invalidate_bh_lrus(void);
48 46
49#define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers) 47#define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers)
50 48
@@ -333,7 +331,7 @@ out:
333 we think the disk contains more recent information than the buffercache. 331 we think the disk contains more recent information than the buffercache.
334 The update == 1 pass marks the buffers we need to update, the update == 2 332 The update == 1 pass marks the buffers we need to update, the update == 2
335 pass does the actual I/O. */ 333 pass does the actual I/O. */
336void invalidate_bdev(struct block_device *bdev, int destroy_dirty_buffers) 334void invalidate_bdev(struct block_device *bdev)
337{ 335{
338 struct address_space *mapping = bdev->bd_inode->i_mapping; 336 struct address_space *mapping = bdev->bd_inode->i_mapping;
339 337
@@ -341,11 +339,6 @@ void invalidate_bdev(struct block_device *bdev, int destroy_dirty_buffers)
341 return; 339 return;
342 340
343 invalidate_bh_lrus(); 341 invalidate_bh_lrus();
344 /*
345 * FIXME: what about destroy_dirty_buffers?
346 * We really want to use invalidate_inode_pages2() for
347 * that, but not until that's cleaned up.
348 */
349 invalidate_mapping_pages(mapping, 0, -1); 342 invalidate_mapping_pages(mapping, 0, -1);
350} 343}
351 344
@@ -1408,7 +1401,7 @@ static void invalidate_bh_lru(void *arg)
1408 put_cpu_var(bh_lrus); 1401 put_cpu_var(bh_lrus);
1409} 1402}
1410 1403
1411static void invalidate_bh_lrus(void) 1404void invalidate_bh_lrus(void)
1412{ 1405{
1413 on_each_cpu(invalidate_bh_lru, NULL, 1, 1); 1406 on_each_cpu(invalidate_bh_lru, NULL, 1, 1);
1414} 1407}
@@ -1700,17 +1693,8 @@ done:
1700 * clean. Someone wrote them back by hand with 1693 * clean. Someone wrote them back by hand with
1701 * ll_rw_block/submit_bh. A rare case. 1694 * ll_rw_block/submit_bh. A rare case.
1702 */ 1695 */
1703 int uptodate = 1;
1704 do {
1705 if (!buffer_uptodate(bh)) {
1706 uptodate = 0;
1707 break;
1708 }
1709 bh = bh->b_this_page;
1710 } while (bh != head);
1711 if (uptodate)
1712 SetPageUptodate(page);
1713 end_page_writeback(page); 1696 end_page_writeback(page);
1697
1714 /* 1698 /*
1715 * The page and buffer_heads can be released at any time from 1699 * The page and buffer_heads can be released at any time from
1716 * here on. 1700 * here on.
@@ -1742,6 +1726,7 @@ recover:
1742 } while ((bh = bh->b_this_page) != head); 1726 } while ((bh = bh->b_this_page) != head);
1743 SetPageError(page); 1727 SetPageError(page);
1744 BUG_ON(PageWriteback(page)); 1728 BUG_ON(PageWriteback(page));
1729 mapping_set_error(page->mapping, err);
1745 set_page_writeback(page); 1730 set_page_writeback(page);
1746 do { 1731 do {
1747 struct buffer_head *next = bh->b_this_page; 1732 struct buffer_head *next = bh->b_this_page;
@@ -1861,13 +1846,8 @@ static int __block_prepare_write(struct inode *inode, struct page *page,
1861 if (block_start >= to) 1846 if (block_start >= to)
1862 break; 1847 break;
1863 if (buffer_new(bh)) { 1848 if (buffer_new(bh)) {
1864 void *kaddr;
1865
1866 clear_buffer_new(bh); 1849 clear_buffer_new(bh);
1867 kaddr = kmap_atomic(page, KM_USER0); 1850 zero_user_page(page, block_start, bh->b_size, KM_USER0);
1868 memset(kaddr+block_start, 0, bh->b_size);
1869 flush_dcache_page(page);
1870 kunmap_atomic(kaddr, KM_USER0);
1871 set_buffer_uptodate(bh); 1851 set_buffer_uptodate(bh);
1872 mark_buffer_dirty(bh); 1852 mark_buffer_dirty(bh);
1873 } 1853 }
@@ -1955,10 +1935,8 @@ int block_read_full_page(struct page *page, get_block_t *get_block)
1955 SetPageError(page); 1935 SetPageError(page);
1956 } 1936 }
1957 if (!buffer_mapped(bh)) { 1937 if (!buffer_mapped(bh)) {
1958 void *kaddr = kmap_atomic(page, KM_USER0); 1938 zero_user_page(page, i * blocksize, blocksize,
1959 memset(kaddr + i * blocksize, 0, blocksize); 1939 KM_USER0);
1960 flush_dcache_page(page);
1961 kunmap_atomic(kaddr, KM_USER0);
1962 if (!err) 1940 if (!err)
1963 set_buffer_uptodate(bh); 1941 set_buffer_uptodate(bh);
1964 continue; 1942 continue;
@@ -2101,7 +2079,6 @@ int cont_prepare_write(struct page *page, unsigned offset,
2101 long status; 2079 long status;
2102 unsigned zerofrom; 2080 unsigned zerofrom;
2103 unsigned blocksize = 1 << inode->i_blkbits; 2081 unsigned blocksize = 1 << inode->i_blkbits;
2104 void *kaddr;
2105 2082
2106 while(page->index > (pgpos = *bytes>>PAGE_CACHE_SHIFT)) { 2083 while(page->index > (pgpos = *bytes>>PAGE_CACHE_SHIFT)) {
2107 status = -ENOMEM; 2084 status = -ENOMEM;
@@ -2123,10 +2100,8 @@ int cont_prepare_write(struct page *page, unsigned offset,
2123 PAGE_CACHE_SIZE, get_block); 2100 PAGE_CACHE_SIZE, get_block);
2124 if (status) 2101 if (status)
2125 goto out_unmap; 2102 goto out_unmap;
2126 kaddr = kmap_atomic(new_page, KM_USER0); 2103 zero_user_page(page, zerofrom, PAGE_CACHE_SIZE - zerofrom,
2127 memset(kaddr+zerofrom, 0, PAGE_CACHE_SIZE-zerofrom); 2104 KM_USER0);
2128 flush_dcache_page(new_page);
2129 kunmap_atomic(kaddr, KM_USER0);
2130 generic_commit_write(NULL, new_page, zerofrom, PAGE_CACHE_SIZE); 2105 generic_commit_write(NULL, new_page, zerofrom, PAGE_CACHE_SIZE);
2131 unlock_page(new_page); 2106 unlock_page(new_page);
2132 page_cache_release(new_page); 2107 page_cache_release(new_page);
@@ -2153,10 +2128,7 @@ int cont_prepare_write(struct page *page, unsigned offset,
2153 if (status) 2128 if (status)
2154 goto out1; 2129 goto out1;
2155 if (zerofrom < offset) { 2130 if (zerofrom < offset) {
2156 kaddr = kmap_atomic(page, KM_USER0); 2131 zero_user_page(page, zerofrom, offset - zerofrom, KM_USER0);
2157 memset(kaddr+zerofrom, 0, offset-zerofrom);
2158 flush_dcache_page(page);
2159 kunmap_atomic(kaddr, KM_USER0);
2160 __block_commit_write(inode, page, zerofrom, offset); 2132 __block_commit_write(inode, page, zerofrom, offset);
2161 } 2133 }
2162 return 0; 2134 return 0;
@@ -2355,10 +2327,7 @@ failed:
2355 * Error recovery is pretty slack. Clear the page and mark it dirty 2327 * Error recovery is pretty slack. Clear the page and mark it dirty
2356 * so we'll later zero out any blocks which _were_ allocated. 2328 * so we'll later zero out any blocks which _were_ allocated.
2357 */ 2329 */
2358 kaddr = kmap_atomic(page, KM_USER0); 2330 zero_user_page(page, 0, PAGE_CACHE_SIZE, KM_USER0);
2359 memset(kaddr, 0, PAGE_CACHE_SIZE);
2360 flush_dcache_page(page);
2361 kunmap_atomic(kaddr, KM_USER0);
2362 SetPageUptodate(page); 2331 SetPageUptodate(page);
2363 set_page_dirty(page); 2332 set_page_dirty(page);
2364 return ret; 2333 return ret;
@@ -2397,7 +2366,6 @@ int nobh_writepage(struct page *page, get_block_t *get_block,
2397 loff_t i_size = i_size_read(inode); 2366 loff_t i_size = i_size_read(inode);
2398 const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; 2367 const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
2399 unsigned offset; 2368 unsigned offset;
2400 void *kaddr;
2401 int ret; 2369 int ret;
2402 2370
2403 /* Is the page fully inside i_size? */ 2371 /* Is the page fully inside i_size? */
@@ -2428,10 +2396,7 @@ int nobh_writepage(struct page *page, get_block_t *get_block,
2428 * the page size, the remaining memory is zeroed when mapped, and 2396 * the page size, the remaining memory is zeroed when mapped, and
2429 * writes to that region are not written out to the file." 2397 * writes to that region are not written out to the file."
2430 */ 2398 */
2431 kaddr = kmap_atomic(page, KM_USER0); 2399 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0);
2432 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
2433 flush_dcache_page(page);
2434 kunmap_atomic(kaddr, KM_USER0);
2435out: 2400out:
2436 ret = mpage_writepage(page, get_block, wbc); 2401 ret = mpage_writepage(page, get_block, wbc);
2437 if (ret == -EAGAIN) 2402 if (ret == -EAGAIN)
@@ -2452,7 +2417,6 @@ int nobh_truncate_page(struct address_space *mapping, loff_t from)
2452 unsigned to; 2417 unsigned to;
2453 struct page *page; 2418 struct page *page;
2454 const struct address_space_operations *a_ops = mapping->a_ops; 2419 const struct address_space_operations *a_ops = mapping->a_ops;
2455 char *kaddr;
2456 int ret = 0; 2420 int ret = 0;
2457 2421
2458 if ((offset & (blocksize - 1)) == 0) 2422 if ((offset & (blocksize - 1)) == 0)
@@ -2466,10 +2430,8 @@ int nobh_truncate_page(struct address_space *mapping, loff_t from)
2466 to = (offset + blocksize) & ~(blocksize - 1); 2430 to = (offset + blocksize) & ~(blocksize - 1);
2467 ret = a_ops->prepare_write(NULL, page, offset, to); 2431 ret = a_ops->prepare_write(NULL, page, offset, to);
2468 if (ret == 0) { 2432 if (ret == 0) {
2469 kaddr = kmap_atomic(page, KM_USER0); 2433 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset,
2470 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset); 2434 KM_USER0);
2471 flush_dcache_page(page);
2472 kunmap_atomic(kaddr, KM_USER0);
2473 /* 2435 /*
2474 * It would be more correct to call aops->commit_write() 2436 * It would be more correct to call aops->commit_write()
2475 * here, but this is more efficient. 2437 * here, but this is more efficient.
@@ -2495,7 +2457,6 @@ int block_truncate_page(struct address_space *mapping,
2495 struct inode *inode = mapping->host; 2457 struct inode *inode = mapping->host;
2496 struct page *page; 2458 struct page *page;
2497 struct buffer_head *bh; 2459 struct buffer_head *bh;
2498 void *kaddr;
2499 int err; 2460 int err;
2500 2461
2501 blocksize = 1 << inode->i_blkbits; 2462 blocksize = 1 << inode->i_blkbits;
@@ -2549,11 +2510,7 @@ int block_truncate_page(struct address_space *mapping,
2549 goto unlock; 2510 goto unlock;
2550 } 2511 }
2551 2512
2552 kaddr = kmap_atomic(page, KM_USER0); 2513 zero_user_page(page, offset, length, KM_USER0);
2553 memset(kaddr + offset, 0, length);
2554 flush_dcache_page(page);
2555 kunmap_atomic(kaddr, KM_USER0);
2556
2557 mark_buffer_dirty(bh); 2514 mark_buffer_dirty(bh);
2558 err = 0; 2515 err = 0;
2559 2516
@@ -2574,7 +2531,6 @@ int block_write_full_page(struct page *page, get_block_t *get_block,
2574 loff_t i_size = i_size_read(inode); 2531 loff_t i_size = i_size_read(inode);
2575 const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; 2532 const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
2576 unsigned offset; 2533 unsigned offset;
2577 void *kaddr;
2578 2534
2579 /* Is the page fully inside i_size? */ 2535 /* Is the page fully inside i_size? */
2580 if (page->index < end_index) 2536 if (page->index < end_index)
@@ -2600,10 +2556,7 @@ int block_write_full_page(struct page *page, get_block_t *get_block,
2600 * the page size, the remaining memory is zeroed when mapped, and 2556 * the page size, the remaining memory is zeroed when mapped, and
2601 * writes to that region are not written out to the file." 2557 * writes to that region are not written out to the file."
2602 */ 2558 */
2603 kaddr = kmap_atomic(page, KM_USER0); 2559 zero_user_page(page, offset, PAGE_CACHE_SIZE - offset, KM_USER0);
2604 memset(kaddr + offset, 0, PAGE_CACHE_SIZE - offset);
2605 flush_dcache_page(page);
2606 kunmap_atomic(kaddr, KM_USER0);
2607 return __block_write_full_page(inode, page, get_block, wbc); 2560 return __block_write_full_page(inode, page, get_block, wbc);
2608} 2561}
2609 2562
@@ -2968,8 +2921,7 @@ EXPORT_SYMBOL(free_buffer_head);
2968static void 2921static void
2969init_buffer_head(void *data, struct kmem_cache *cachep, unsigned long flags) 2922init_buffer_head(void *data, struct kmem_cache *cachep, unsigned long flags)
2970{ 2923{
2971 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == 2924 if (flags & SLAB_CTOR_CONSTRUCTOR) {
2972 SLAB_CTOR_CONSTRUCTOR) {
2973 struct buffer_head * bh = (struct buffer_head *)data; 2925 struct buffer_head * bh = (struct buffer_head *)data;
2974 2926
2975 memset(bh, 0, sizeof(*bh)); 2927 memset(bh, 0, sizeof(*bh));
@@ -2994,7 +2946,7 @@ static void buffer_exit_cpu(int cpu)
2994static int buffer_cpu_notify(struct notifier_block *self, 2946static int buffer_cpu_notify(struct notifier_block *self,
2995 unsigned long action, void *hcpu) 2947 unsigned long action, void *hcpu)
2996{ 2948{
2997 if (action == CPU_DEAD) 2949 if (action == CPU_DEAD || action == CPU_DEAD_FROZEN)
2998 buffer_exit_cpu((unsigned long)hcpu); 2950 buffer_exit_cpu((unsigned long)hcpu);
2999 return NOTIFY_OK; 2951 return NOTIFY_OK;
3000} 2952}