aboutsummaryrefslogtreecommitdiffstats
path: root/fs/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/buffer.c')
-rw-r--r--fs/buffer.c133
1 files changed, 45 insertions, 88 deletions
diff --git a/fs/buffer.c b/fs/buffer.c
index c9c266db0624..50efa339e051 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -275,6 +275,7 @@ void invalidate_bdev(struct block_device *bdev)
275 return; 275 return;
276 276
277 invalidate_bh_lrus(); 277 invalidate_bh_lrus();
278 lru_add_drain_all(); /* make sure all lru add caches are flushed */
278 invalidate_mapping_pages(mapping, 0, -1); 279 invalidate_mapping_pages(mapping, 0, -1);
279} 280}
280EXPORT_SYMBOL(invalidate_bdev); 281EXPORT_SYMBOL(invalidate_bdev);
@@ -560,26 +561,17 @@ repeat:
560 return err; 561 return err;
561} 562}
562 563
563static void do_thaw_all(struct work_struct *work) 564static void do_thaw_one(struct super_block *sb, void *unused)
564{ 565{
565 struct super_block *sb;
566 char b[BDEVNAME_SIZE]; 566 char b[BDEVNAME_SIZE];
567 while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
568 printk(KERN_WARNING "Emergency Thaw on %s\n",
569 bdevname(sb->s_bdev, b));
570}
567 571
568 spin_lock(&sb_lock); 572static void do_thaw_all(struct work_struct *work)
569restart: 573{
570 list_for_each_entry(sb, &super_blocks, s_list) { 574 iterate_supers(do_thaw_one, NULL);
571 sb->s_count++;
572 spin_unlock(&sb_lock);
573 down_read(&sb->s_umount);
574 while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
575 printk(KERN_WARNING "Emergency Thaw on %s\n",
576 bdevname(sb->s_bdev, b));
577 up_read(&sb->s_umount);
578 spin_lock(&sb_lock);
579 if (__put_super_and_need_restart(sb))
580 goto restart;
581 }
582 spin_unlock(&sb_lock);
583 kfree(work); 575 kfree(work);
584 printk(KERN_WARNING "Emergency Thaw complete\n"); 576 printk(KERN_WARNING "Emergency Thaw complete\n");
585} 577}
@@ -1841,9 +1833,10 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to)
1841} 1833}
1842EXPORT_SYMBOL(page_zero_new_buffers); 1834EXPORT_SYMBOL(page_zero_new_buffers);
1843 1835
1844static int __block_prepare_write(struct inode *inode, struct page *page, 1836int block_prepare_write(struct page *page, unsigned from, unsigned to,
1845 unsigned from, unsigned to, get_block_t *get_block) 1837 get_block_t *get_block)
1846{ 1838{
1839 struct inode *inode = page->mapping->host;
1847 unsigned block_start, block_end; 1840 unsigned block_start, block_end;
1848 sector_t block; 1841 sector_t block;
1849 int err = 0; 1842 int err = 0;
@@ -1916,10 +1909,13 @@ static int __block_prepare_write(struct inode *inode, struct page *page,
1916 if (!buffer_uptodate(*wait_bh)) 1909 if (!buffer_uptodate(*wait_bh))
1917 err = -EIO; 1910 err = -EIO;
1918 } 1911 }
1919 if (unlikely(err)) 1912 if (unlikely(err)) {
1920 page_zero_new_buffers(page, from, to); 1913 page_zero_new_buffers(page, from, to);
1914 ClearPageUptodate(page);
1915 }
1921 return err; 1916 return err;
1922} 1917}
1918EXPORT_SYMBOL(block_prepare_write);
1923 1919
1924static int __block_commit_write(struct inode *inode, struct page *page, 1920static int __block_commit_write(struct inode *inode, struct page *page,
1925 unsigned from, unsigned to) 1921 unsigned from, unsigned to)
@@ -1956,62 +1952,40 @@ static int __block_commit_write(struct inode *inode, struct page *page,
1956 return 0; 1952 return 0;
1957} 1953}
1958 1954
1955int __block_write_begin(struct page *page, loff_t pos, unsigned len,
1956 get_block_t *get_block)
1957{
1958 unsigned start = pos & (PAGE_CACHE_SIZE - 1);
1959
1960 return block_prepare_write(page, start, start + len, get_block);
1961}
1962EXPORT_SYMBOL(__block_write_begin);
1963
1959/* 1964/*
1960 * block_write_begin takes care of the basic task of block allocation and 1965 * block_write_begin takes care of the basic task of block allocation and
1961 * bringing partial write blocks uptodate first. 1966 * bringing partial write blocks uptodate first.
1962 * 1967 *
1963 * If *pagep is not NULL, then block_write_begin uses the locked page 1968 * The filesystem needs to handle block truncation upon failure.
1964 * at *pagep rather than allocating its own. In this case, the page will
1965 * not be unlocked or deallocated on failure.
1966 */ 1969 */
1967int block_write_begin(struct file *file, struct address_space *mapping, 1970int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len,
1968 loff_t pos, unsigned len, unsigned flags, 1971 unsigned flags, struct page **pagep, get_block_t *get_block)
1969 struct page **pagep, void **fsdata,
1970 get_block_t *get_block)
1971{ 1972{
1972 struct inode *inode = mapping->host; 1973 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1973 int status = 0;
1974 struct page *page; 1974 struct page *page;
1975 pgoff_t index; 1975 int status;
1976 unsigned start, end;
1977 int ownpage = 0;
1978 1976
1979 index = pos >> PAGE_CACHE_SHIFT; 1977 page = grab_cache_page_write_begin(mapping, index, flags);
1980 start = pos & (PAGE_CACHE_SIZE - 1); 1978 if (!page)
1981 end = start + len; 1979 return -ENOMEM;
1982
1983 page = *pagep;
1984 if (page == NULL) {
1985 ownpage = 1;
1986 page = grab_cache_page_write_begin(mapping, index, flags);
1987 if (!page) {
1988 status = -ENOMEM;
1989 goto out;
1990 }
1991 *pagep = page;
1992 } else
1993 BUG_ON(!PageLocked(page));
1994 1980
1995 status = __block_prepare_write(inode, page, start, end, get_block); 1981 status = __block_write_begin(page, pos, len, get_block);
1996 if (unlikely(status)) { 1982 if (unlikely(status)) {
1997 ClearPageUptodate(page); 1983 unlock_page(page);
1998 1984 page_cache_release(page);
1999 if (ownpage) { 1985 page = NULL;
2000 unlock_page(page);
2001 page_cache_release(page);
2002 *pagep = NULL;
2003
2004 /*
2005 * prepare_write() may have instantiated a few blocks
2006 * outside i_size. Trim these off again. Don't need
2007 * i_size_read because we hold i_mutex.
2008 */
2009 if (pos + len > inode->i_size)
2010 vmtruncate(inode, inode->i_size);
2011 }
2012 } 1986 }
2013 1987
2014out: 1988 *pagep = page;
2015 return status; 1989 return status;
2016} 1990}
2017EXPORT_SYMBOL(block_write_begin); 1991EXPORT_SYMBOL(block_write_begin);
@@ -2344,7 +2318,7 @@ int cont_write_begin(struct file *file, struct address_space *mapping,
2344 2318
2345 err = cont_expand_zero(file, mapping, pos, bytes); 2319 err = cont_expand_zero(file, mapping, pos, bytes);
2346 if (err) 2320 if (err)
2347 goto out; 2321 return err;
2348 2322
2349 zerofrom = *bytes & ~PAGE_CACHE_MASK; 2323 zerofrom = *bytes & ~PAGE_CACHE_MASK;
2350 if (pos+len > *bytes && zerofrom & (blocksize-1)) { 2324 if (pos+len > *bytes && zerofrom & (blocksize-1)) {
@@ -2352,25 +2326,10 @@ int cont_write_begin(struct file *file, struct address_space *mapping,
2352 (*bytes)++; 2326 (*bytes)++;
2353 } 2327 }
2354 2328
2355 *pagep = NULL; 2329 return block_write_begin(mapping, pos, len, flags, pagep, get_block);
2356 err = block_write_begin(file, mapping, pos, len,
2357 flags, pagep, fsdata, get_block);
2358out:
2359 return err;
2360} 2330}
2361EXPORT_SYMBOL(cont_write_begin); 2331EXPORT_SYMBOL(cont_write_begin);
2362 2332
2363int block_prepare_write(struct page *page, unsigned from, unsigned to,
2364 get_block_t *get_block)
2365{
2366 struct inode *inode = page->mapping->host;
2367 int err = __block_prepare_write(inode, page, from, to, get_block);
2368 if (err)
2369 ClearPageUptodate(page);
2370 return err;
2371}
2372EXPORT_SYMBOL(block_prepare_write);
2373
2374int block_commit_write(struct page *page, unsigned from, unsigned to) 2333int block_commit_write(struct page *page, unsigned from, unsigned to)
2375{ 2334{
2376 struct inode *inode = page->mapping->host; 2335 struct inode *inode = page->mapping->host;
@@ -2389,7 +2348,7 @@ EXPORT_SYMBOL(block_commit_write);
2389 * 2348 *
2390 * We are not allowed to take the i_mutex here so we have to play games to 2349 * We are not allowed to take the i_mutex here so we have to play games to
2391 * protect against truncate races as the page could now be beyond EOF. Because 2350 * protect against truncate races as the page could now be beyond EOF. Because
2392 * vmtruncate() writes the inode size before removing pages, once we have the 2351 * truncate writes the inode size before removing pages, once we have the
2393 * page lock we can determine safely if the page is beyond EOF. If it is not 2352 * page lock we can determine safely if the page is beyond EOF. If it is not
2394 * beyond EOF, then the page is guaranteed safe against truncation until we 2353 * beyond EOF, then the page is guaranteed safe against truncation until we
2395 * unlock the page. 2354 * unlock the page.
@@ -2474,8 +2433,9 @@ static void attach_nobh_buffers(struct page *page, struct buffer_head *head)
2474/* 2433/*
2475 * On entry, the page is fully not uptodate. 2434 * On entry, the page is fully not uptodate.
2476 * On exit the page is fully uptodate in the areas outside (from,to) 2435 * On exit the page is fully uptodate in the areas outside (from,to)
2436 * The filesystem needs to handle block truncation upon failure.
2477 */ 2437 */
2478int nobh_write_begin(struct file *file, struct address_space *mapping, 2438int nobh_write_begin(struct address_space *mapping,
2479 loff_t pos, unsigned len, unsigned flags, 2439 loff_t pos, unsigned len, unsigned flags,
2480 struct page **pagep, void **fsdata, 2440 struct page **pagep, void **fsdata,
2481 get_block_t *get_block) 2441 get_block_t *get_block)
@@ -2508,8 +2468,8 @@ int nobh_write_begin(struct file *file, struct address_space *mapping,
2508 unlock_page(page); 2468 unlock_page(page);
2509 page_cache_release(page); 2469 page_cache_release(page);
2510 *pagep = NULL; 2470 *pagep = NULL;
2511 return block_write_begin(file, mapping, pos, len, flags, pagep, 2471 return block_write_begin(mapping, pos, len, flags, pagep,
2512 fsdata, get_block); 2472 get_block);
2513 } 2473 }
2514 2474
2515 if (PageMappedToDisk(page)) 2475 if (PageMappedToDisk(page))
@@ -2613,9 +2573,6 @@ out_release:
2613 page_cache_release(page); 2573 page_cache_release(page);
2614 *pagep = NULL; 2574 *pagep = NULL;
2615 2575
2616 if (pos + len > inode->i_size)
2617 vmtruncate(inode, inode->i_size);
2618
2619 return ret; 2576 return ret;
2620} 2577}
2621EXPORT_SYMBOL(nobh_write_begin); 2578EXPORT_SYMBOL(nobh_write_begin);