~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/buffer.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include <linux/bitops.h>
42
42
#include <linux/mpage.h>
43
43
#include <linux/bit_spinlock.h>
44
 
#include <trace/fs.h>
 
44
#include <linux/cleancache.h>
45
45
 
46
46
static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
47
47
 
48
48
#define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers)
49
49
 
50
 
DEFINE_TRACE(fs_buffer_wait_start);
51
 
DEFINE_TRACE(fs_buffer_wait_end);
52
 
 
53
50
inline void
54
51
init_buffer(struct buffer_head *bh, bh_end_io_t *handler, void *private)
55
52
{
58
55
}
59
56
EXPORT_SYMBOL(init_buffer);
60
57
 
61
 
static int sync_buffer(void *word)
 
58
static int sleep_on_buffer(void *word)
62
59
{
63
 
        struct block_device *bd;
64
 
        struct buffer_head *bh
65
 
                = container_of(word, struct buffer_head, b_state);
66
 
 
67
 
        smp_mb();
68
 
        bd = bh->b_bdev;
69
 
        if (bd)
70
 
                blk_run_address_space(bd->bd_inode->i_mapping);
71
60
        io_schedule();
72
61
        return 0;
73
62
}
74
63
 
75
64
void __lock_buffer(struct buffer_head *bh)
76
65
{
77
 
        wait_on_bit_lock(&bh->b_state, BH_Lock, sync_buffer,
 
66
        wait_on_bit_lock(&bh->b_state, BH_Lock, sleep_on_buffer,
78
67
                                                        TASK_UNINTERRUPTIBLE);
79
68
}
80
69
EXPORT_SYMBOL(__lock_buffer);
94
83
 */
95
84
void __wait_on_buffer(struct buffer_head * bh)
96
85
{
97
 
        trace_fs_buffer_wait_start(bh);
98
 
        wait_on_bit(&bh->b_state, BH_Lock, sync_buffer, TASK_UNINTERRUPTIBLE);
99
 
        trace_fs_buffer_wait_end(bh);
 
86
        wait_on_bit(&bh->b_state, BH_Lock, sleep_on_buffer, TASK_UNINTERRUPTIBLE);
100
87
}
101
88
EXPORT_SYMBOL(__wait_on_buffer);
102
89
 
283
270
        invalidate_bh_lrus();
284
271
        lru_add_drain_all();    /* make sure all lru add caches are flushed */
285
272
        invalidate_mapping_pages(mapping, 0, -1);
 
273
        /* 99% of the time, we don't need to flush the cleancache on the bdev.
 
274
         * But, for the strange corners, lets be cautious
 
275
         */
 
276
        cleancache_flush_inode(mapping);
286
277
}
287
278
EXPORT_SYMBOL(invalidate_bdev);
288
279
 
755
746
{
756
747
        struct buffer_head *bh;
757
748
        struct list_head tmp;
758
 
        struct address_space *mapping, *prev_mapping = NULL;
 
749
        struct address_space *mapping;
759
750
        int err = 0, err2;
 
751
        struct blk_plug plug;
760
752
 
761
753
        INIT_LIST_HEAD(&tmp);
 
754
        blk_start_plug(&plug);
762
755
 
763
756
        spin_lock(lock);
764
757
        while (!list_empty(list)) {
781
774
                                 * still in flight on potentially older
782
775
                                 * contents.
783
776
                                 */
784
 
                                write_dirty_buffer(bh, WRITE_SYNC_PLUG);
 
777
                                write_dirty_buffer(bh, WRITE_SYNC);
785
778
 
786
779
                                /*
787
780
                                 * Kick off IO for the previous mapping. Note
789
782
                                 * wait_on_buffer() will do that for us
790
783
                                 * through sync_buffer().
791
784
                                 */
792
 
                                if (prev_mapping && prev_mapping != mapping)
793
 
                                        blk_run_address_space(prev_mapping);
794
 
                                prev_mapping = mapping;
795
 
 
796
785
                                brelse(bh);
797
786
                                spin_lock(lock);
798
787
                        }
799
788
                }
800
789
        }
801
790
 
 
791
        spin_unlock(lock);
 
792
        blk_finish_plug(&plug);
 
793
        spin_lock(lock);
 
794
 
802
795
        while (!list_empty(&tmp)) {
803
796
                bh = BH_ENTRY(tmp.prev);
804
797
                get_bh(bh);
1150
1143
 * inode list.
1151
1144
 *
1152
1145
 * mark_buffer_dirty() is atomic.  It takes bh->b_page->mapping->private_lock,
1153
 
 * mapping->tree_lock and the global inode_lock.
 
1146
 * mapping->tree_lock and mapping->host->i_lock.
1154
1147
 */
1155
1148
void mark_buffer_dirty(struct buffer_head *bh)
1156
1149
{
1620
1613
 * prevents this contention from occurring.
1621
1614
 *
1622
1615
 * If block_write_full_page() is called with wbc->sync_mode ==
1623
 
 * WB_SYNC_ALL, the writes are posted using WRITE_SYNC_PLUG; this
1624
 
 * causes the writes to be flagged as synchronous writes, but the
1625
 
 * block device queue will NOT be unplugged, since usually many pages
1626
 
 * will be pushed to the out before the higher-level caller actually
1627
 
 * waits for the writes to be completed.  The various wait functions,
1628
 
 * such as wait_on_writeback_range() will ultimately call sync_page()
1629
 
 * which will ultimately call blk_run_backing_dev(), which will end up
1630
 
 * unplugging the device queue.
 
1616
 * WB_SYNC_ALL, the writes are posted using WRITE_SYNC; this
 
1617
 * causes the writes to be flagged as synchronous writes.
1631
1618
 */
1632
1619
static int __block_write_full_page(struct inode *inode, struct page *page,
1633
1620
                        get_block_t *get_block, struct writeback_control *wbc,
1640
1627
        const unsigned blocksize = 1 << inode->i_blkbits;
1641
1628
        int nr_underway = 0;
1642
1629
        int write_op = (wbc->sync_mode == WB_SYNC_ALL ?
1643
 
                        WRITE_SYNC_PLUG : WRITE);
 
1630
                        WRITE_SYNC : WRITE);
1644
1631
 
1645
1632
        BUG_ON(!PageLocked(page));
1646
1633
 
1915
1902
                if (!buffer_uptodate(*wait_bh))
1916
1903
                        err = -EIO;
1917
1904
        }
1918
 
        if (unlikely(err)) {
 
1905
        if (unlikely(err))
1919
1906
                page_zero_new_buffers(page, from, to);
1920
 
                ClearPageUptodate(page);
1921
 
        }
1922
1907
        return err;
1923
1908
}
1924
1909
EXPORT_SYMBOL(__block_write_begin);
2349
2334
 * page lock we can determine safely if the page is beyond EOF. If it is not
2350
2335
 * beyond EOF, then the page is guaranteed safe against truncation until we
2351
2336
 * unlock the page.
 
2337
 *
 
2338
 * Direct callers of this function should call vfs_check_frozen() so that page
 
2339
 * fault does not busyloop until the fs is thawed.
2352
2340
 */
2353
 
int
2354
 
block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
2355
 
                   get_block_t get_block)
 
2341
int __block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
 
2342
                         get_block_t get_block)
2356
2343
{
2357
2344
        struct page *page = vmf->page;
2358
2345
        struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
2359
2346
        unsigned long end;
2360
2347
        loff_t size;
2361
 
        int ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */
 
2348
        int ret;
2362
2349
 
2363
2350
        lock_page(page);
2364
2351
        size = i_size_read(inode);
2365
2352
        if ((page->mapping != inode->i_mapping) ||
2366
2353
            (page_offset(page) > size)) {
2367
 
                /* page got truncated out from underneath us */
2368
 
                unlock_page(page);
2369
 
                goto out;
 
2354
                /* We overload EFAULT to mean page got truncated */
 
2355
                ret = -EFAULT;
 
2356
                goto out_unlock;
2370
2357
        }
2371
2358
 
2372
2359
        /* page is wholly or partially inside EOF */
2379
2366
        if (!ret)
2380
2367
                ret = block_commit_write(page, 0, end);
2381
2368
 
2382
 
        if (unlikely(ret)) {
2383
 
                unlock_page(page);
2384
 
                if (ret == -ENOMEM)
2385
 
                        ret = VM_FAULT_OOM;
2386
 
                else /* -ENOSPC, -EIO, etc */
2387
 
                        ret = VM_FAULT_SIGBUS;
2388
 
        } else
2389
 
                ret = VM_FAULT_LOCKED;
2390
 
 
2391
 
out:
 
2369
        if (unlikely(ret < 0))
 
2370
                goto out_unlock;
 
2371
        /*
 
2372
         * Freezing in progress? We check after the page is marked dirty and
 
2373
         * with page lock held so if the test here fails, we are sure freezing
 
2374
         * code will wait during syncing until the page fault is done - at that
 
2375
         * point page will be dirty and unlocked so freezing code will write it
 
2376
         * and writeprotect it again.
 
2377
         */
 
2378
        set_page_dirty(page);
 
2379
        if (inode->i_sb->s_frozen != SB_UNFROZEN) {
 
2380
                ret = -EAGAIN;
 
2381
                goto out_unlock;
 
2382
        }
 
2383
        wait_on_page_writeback(page);
 
2384
        return 0;
 
2385
out_unlock:
 
2386
        unlock_page(page);
2392
2387
        return ret;
2393
2388
}
 
2389
EXPORT_SYMBOL(__block_page_mkwrite);
 
2390
 
 
2391
int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
 
2392
                   get_block_t get_block)
 
2393
{
 
2394
        int ret;
 
2395
        struct super_block *sb = vma->vm_file->f_path.dentry->d_inode->i_sb;
 
2396
 
 
2397
        /*
 
2398
         * This check is racy but catches the common case. The check in
 
2399
         * __block_page_mkwrite() is reliable.
 
2400
         */
 
2401
        vfs_check_frozen(sb, SB_FREEZE_WRITE);
 
2402
        ret = __block_page_mkwrite(vma, vmf, get_block);
 
2403
        return block_page_mkwrite_return(ret);
 
2404
}
2394
2405
EXPORT_SYMBOL(block_page_mkwrite);
2395
2406
 
2396
2407
/*
3144
3155
}
3145
3156
EXPORT_SYMBOL(try_to_free_buffers);
3146
3157
 
3147
 
void block_sync_page(struct page *page)
3148
 
{
3149
 
        struct address_space *mapping;
3150
 
 
3151
 
        smp_mb();
3152
 
        mapping = page_mapping(page);
3153
 
        if (mapping)
3154
 
                blk_run_backing_dev(mapping->backing_dev_info, page);
3155
 
}
3156
 
EXPORT_SYMBOL(block_sync_page);
3157
 
 
3158
3158
/*
3159
3159
 * There are no bdflush tunables left.  But distributions are
3160
3160
 * still running obsolete flush daemons, so we terminate them here.