Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
buffer.c File Reference
#include <linux/kernel.h>
#include <linux/syscalls.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/percpu.h>
#include <linux/slab.h>
#include <linux/capability.h>
#include <linux/blkdev.h>
#include <linux/file.h>
#include <linux/quotaops.h>
#include <linux/highmem.h>
#include <linux/export.h>
#include <linux/writeback.h>
#include <linux/hash.h>
#include <linux/suspend.h>
#include <linux/buffer_head.h>
#include <linux/task_io_accounting_ops.h>
#include <linux/bio.h>
#include <linux/notifier.h>
#include <linux/cpu.h>
#include <linux/bitops.h>
#include <linux/mpage.h>
#include <linux/bit_spinlock.h>

Go to the source code of this file.

Data Structures

struct  bh_lru
 
struct  bh_accounting
 

Macros

#define BH_ENTRY(list)   list_entry((list), struct buffer_head, b_assoc_buffers)
 
#define BH_LRU_SIZE   8
 
#define bh_lru_lock()   preempt_disable()
 
#define bh_lru_unlock()   preempt_enable()
 

Functions

void init_buffer (struct buffer_head *bh, bh_end_io_t *handler, void *private)
 
 EXPORT_SYMBOL (init_buffer)
 
void __lock_buffer (struct buffer_head *bh)
 
 EXPORT_SYMBOL (__lock_buffer)
 
void unlock_buffer (struct buffer_head *bh)
 
 EXPORT_SYMBOL (unlock_buffer)
 
void __wait_on_buffer (struct buffer_head *bh)
 
 EXPORT_SYMBOL (__wait_on_buffer)
 
void end_buffer_read_sync (struct buffer_head *bh, int uptodate)
 
 EXPORT_SYMBOL (end_buffer_read_sync)
 
void end_buffer_write_sync (struct buffer_head *bh, int uptodate)
 
 EXPORT_SYMBOL (end_buffer_write_sync)
 
void end_buffer_async_write (struct buffer_head *bh, int uptodate)
 
 EXPORT_SYMBOL (end_buffer_async_write)
 
void mark_buffer_async_write (struct buffer_head *bh)
 
 EXPORT_SYMBOL (mark_buffer_async_write)
 
int inode_has_buffers (struct inode *inode)
 
void emergency_thaw_all (void)
 
int sync_mapping_buffers (struct address_space *mapping)
 
 EXPORT_SYMBOL (sync_mapping_buffers)
 
void write_boundary_block (struct block_device *bdev, sector_t bblock, unsigned blocksize)
 
void mark_buffer_dirty_inode (struct buffer_head *bh, struct inode *inode)
 
 EXPORT_SYMBOL (mark_buffer_dirty_inode)
 
int __set_page_dirty_buffers (struct page *page)
 
 EXPORT_SYMBOL (__set_page_dirty_buffers)
 
void invalidate_inode_buffers (struct inode *inode)
 
 EXPORT_SYMBOL (invalidate_inode_buffers)
 
int remove_inode_buffers (struct inode *inode)
 
struct buffer_head * alloc_page_buffers (struct page *page, unsigned long size, int retry)
 
 EXPORT_SYMBOL_GPL (alloc_page_buffers)
 
void mark_buffer_dirty (struct buffer_head *bh)
 
 EXPORT_SYMBOL (mark_buffer_dirty)
 
void __brelse (struct buffer_head *buf)
 
 EXPORT_SYMBOL (__brelse)
 
void __bforget (struct buffer_head *bh)
 
 EXPORT_SYMBOL (__bforget)
 
struct buffer_head * __find_get_block (struct block_device *bdev, sector_t block, unsigned size)
 
 EXPORT_SYMBOL (__find_get_block)
 
struct buffer_head * __getblk (struct block_device *bdev, sector_t block, unsigned size)
 
 EXPORT_SYMBOL (__getblk)
 
void __breadahead (struct block_device *bdev, sector_t block, unsigned size)
 
 EXPORT_SYMBOL (__breadahead)
 
struct buffer_head * __bread (struct block_device *bdev, sector_t block, unsigned size)
 
 EXPORT_SYMBOL (__bread)
 
void invalidate_bh_lrus (void)
 
 EXPORT_SYMBOL_GPL (invalidate_bh_lrus)
 
void set_bh_page (struct buffer_head *bh, struct page *page, unsigned long offset)
 
 EXPORT_SYMBOL (set_bh_page)
 
void block_invalidatepage (struct page *page, unsigned long offset)
 
 EXPORT_SYMBOL (block_invalidatepage)
 
void create_empty_buffers (struct page *page, unsigned long blocksize, unsigned long b_state)
 
 EXPORT_SYMBOL (create_empty_buffers)
 
void unmap_underlying_metadata (struct block_device *bdev, sector_t block)
 
 EXPORT_SYMBOL (unmap_underlying_metadata)
 
void page_zero_new_buffers (struct page *page, unsigned from, unsigned to)
 
 EXPORT_SYMBOL (page_zero_new_buffers)
 
int __block_write_begin (struct page *page, loff_t pos, unsigned len, get_block_t *get_block)
 
 EXPORT_SYMBOL (__block_write_begin)
 
int block_write_begin (struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, get_block_t *get_block)
 
 EXPORT_SYMBOL (block_write_begin)
 
int block_write_end (struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata)
 
 EXPORT_SYMBOL (block_write_end)
 
int generic_write_end (struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata)
 
 EXPORT_SYMBOL (generic_write_end)
 
int block_is_partially_uptodate (struct page *page, read_descriptor_t *desc, unsigned long from)
 
 EXPORT_SYMBOL (block_is_partially_uptodate)
 
int block_read_full_page (struct page *page, get_block_t *get_block)
 
 EXPORT_SYMBOL (block_read_full_page)
 
int generic_cont_expand_simple (struct inode *inode, loff_t size)
 
 EXPORT_SYMBOL (generic_cont_expand_simple)
 
int cont_write_begin (struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata, get_block_t *get_block, loff_t *bytes)
 
 EXPORT_SYMBOL (cont_write_begin)
 
int block_commit_write (struct page *page, unsigned from, unsigned to)
 
 EXPORT_SYMBOL (block_commit_write)
 
int __block_page_mkwrite (struct vm_area_struct *vma, struct vm_fault *vmf, get_block_t get_block)
 
 EXPORT_SYMBOL (__block_page_mkwrite)
 
int block_page_mkwrite (struct vm_area_struct *vma, struct vm_fault *vmf, get_block_t get_block)
 
 EXPORT_SYMBOL (block_page_mkwrite)
 
int nobh_write_begin (struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, struct page **pagep, void **fsdata, get_block_t *get_block)
 
 EXPORT_SYMBOL (nobh_write_begin)
 
int nobh_write_end (struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied, struct page *page, void *fsdata)
 
 EXPORT_SYMBOL (nobh_write_end)
 
int nobh_writepage (struct page *page, get_block_t *get_block, struct writeback_control *wbc)
 
 EXPORT_SYMBOL (nobh_writepage)
 
int nobh_truncate_page (struct address_space *mapping, loff_t from, get_block_t *get_block)
 
 EXPORT_SYMBOL (nobh_truncate_page)
 
int block_truncate_page (struct address_space *mapping, loff_t from, get_block_t *get_block)
 
 EXPORT_SYMBOL (block_truncate_page)
 
int block_write_full_page_endio (struct page *page, get_block_t *get_block, struct writeback_control *wbc, bh_end_io_t *handler)
 
 EXPORT_SYMBOL (block_write_full_page_endio)
 
int block_write_full_page (struct page *page, get_block_t *get_block, struct writeback_control *wbc)
 
 EXPORT_SYMBOL (block_write_full_page)
 
sector_t generic_block_bmap (struct address_space *mapping, sector_t block, get_block_t *get_block)
 
 EXPORT_SYMBOL (generic_block_bmap)
 
int submit_bh (int rw, struct buffer_head *bh)
 
 EXPORT_SYMBOL (submit_bh)
 
void ll_rw_block (int rw, int nr, struct buffer_head *bhs[])
 
 EXPORT_SYMBOL (ll_rw_block)
 
void write_dirty_buffer (struct buffer_head *bh, int rw)
 
 EXPORT_SYMBOL (write_dirty_buffer)
 
int __sync_dirty_buffer (struct buffer_head *bh, int rw)
 
 EXPORT_SYMBOL (__sync_dirty_buffer)
 
int sync_dirty_buffer (struct buffer_head *bh)
 
 EXPORT_SYMBOL (sync_dirty_buffer)
 
int try_to_free_buffers (struct page *page)
 
 EXPORT_SYMBOL (try_to_free_buffers)
 
 SYSCALL_DEFINE2 (bdflush, int, func, long, data)
 
struct buffer_head * alloc_buffer_head (gfp_t gfp_flags)
 
 EXPORT_SYMBOL (alloc_buffer_head)
 
void free_buffer_head (struct buffer_head *bh)
 
 EXPORT_SYMBOL (free_buffer_head)
 
int bh_uptodate_or_lock (struct buffer_head *bh)
 
 EXPORT_SYMBOL (bh_uptodate_or_lock)
 
int bh_submit_read (struct buffer_head *bh)
 
 EXPORT_SYMBOL (bh_submit_read)
 
void __init buffer_init (void)
 

Variables

int buffer_heads_over_limit
 

Macro Definition Documentation

#define BH_ENTRY (   list)    list_entry((list), struct buffer_head, b_assoc_buffers)

Definition at line 47 of file buffer.c.

#define bh_lru_lock ( )    preempt_disable()

Definition at line 1223 of file buffer.c.

#define BH_LRU_SIZE   8

Definition at line 1211 of file buffer.c.

#define bh_lru_unlock ( )    preempt_enable()

Definition at line 1224 of file buffer.c.

Function Documentation

void __bforget ( struct buffer_head *  bh)

Definition at line 1164 of file buffer.c.

int __block_page_mkwrite ( struct vm_area_struct vma,
struct vm_fault *  vmf,
get_block_t  get_block 
)

Definition at line 2335 of file buffer.c.

int __block_write_begin ( struct page page,
loff_t  pos,
unsigned  len,
get_block_t get_block 
)

Definition at line 1823 of file buffer.c.

struct buffer_head* __bread ( struct block_device bdev,
sector_t  block,
unsigned  size 
)
read

__bread() - reads a specified block and returns the bh : the block_device to read from : number of block : size (in bytes) to read

Reads a specified block, and returns buffer head that contains it. It returns NULL if the block was unreadable.

Definition at line 1372 of file buffer.c.

void __breadahead ( struct block_device bdev,
sector_t  block,
unsigned  size 
)

Definition at line 1352 of file buffer.c.

void __brelse ( struct buffer_head *  buf)

Definition at line 1150 of file buffer.c.

struct buffer_head* __find_get_block ( struct block_device bdev,
sector_t  block,
unsigned  size 
)
read

Definition at line 1314 of file buffer.c.

struct buffer_head* __getblk ( struct block_device bdev,
sector_t  block,
unsigned  size 
)
read

Definition at line 1338 of file buffer.c.

void __lock_buffer ( struct buffer_head *  bh)

Definition at line 63 of file buffer.c.

int __set_page_dirty_buffers ( struct page page)

Definition at line 652 of file buffer.c.

int __sync_dirty_buffer ( struct buffer_head *  bh,
int  rw 
)

Definition at line 3067 of file buffer.c.

void __wait_on_buffer ( struct buffer_head *  bh)

Definition at line 83 of file buffer.c.

struct buffer_head* alloc_buffer_head ( gfp_t  gfp_flags)
read

Definition at line 3257 of file buffer.c.

struct buffer_head* alloc_page_buffers ( struct page page,
unsigned long  size,
int  retry 
)
read

Definition at line 839 of file buffer.c.

int bh_submit_read ( struct buffer_head *  bh)

bh_submit_read - Submit a locked buffer for reading : struct buffer_head

Returns zero on success and -EIO on error.

Definition at line 3328 of file buffer.c.

int bh_uptodate_or_lock ( struct buffer_head *  bh)

bh_uptodate_or_lock - Test whether the buffer is uptodate : struct buffer_head

Return true if the buffer is up-to-date and false, with the buffer locked, if not.

Definition at line 3310 of file buffer.c.

int block_commit_write ( struct page page,
unsigned  from,
unsigned  to 
)

Definition at line 2309 of file buffer.c.

void block_invalidatepage ( struct page page,
unsigned long  offset 
)

Definition at line 1464 of file buffer.c.

int block_is_partially_uptodate ( struct page page,
read_descriptor_t desc,
unsigned long  from 
)

Definition at line 2052 of file buffer.c.

int block_page_mkwrite ( struct vm_area_struct vma,
struct vm_fault *  vmf,
get_block_t  get_block 
)

Definition at line 2374 of file buffer.c.

int block_read_full_page ( struct page page,
get_block_t get_block 
)

Definition at line 2097 of file buffer.c.

int block_truncate_page ( struct address_space mapping,
loff_t  from,
get_block_t get_block 
)

Definition at line 2739 of file buffer.c.

int block_write_begin ( struct address_space mapping,
loff_t  pos,
unsigned  len,
unsigned  flags,
struct page **  pagep,
get_block_t get_block 
)

Definition at line 1949 of file buffer.c.

int block_write_end ( struct file file,
struct address_space mapping,
loff_t  pos,
unsigned  len,
unsigned  copied,
struct page page,
void fsdata 
)

Definition at line 1972 of file buffer.c.

int block_write_full_page ( struct page page,
get_block_t get_block,
struct writeback_control wbc 
)

Definition at line 2860 of file buffer.c.

int block_write_full_page_endio ( struct page page,
get_block_t get_block,
struct writeback_control wbc,
bh_end_io_t *  handler 
)

Definition at line 2819 of file buffer.c.

void __init buffer_init ( void  )

Definition at line 3347 of file buffer.c.

int cont_write_begin ( struct file file,
struct address_space mapping,
loff_t  pos,
unsigned  len,
unsigned  flags,
struct page **  pagep,
void **  fsdata,
get_block_t get_block,
loff_t *  bytes 
)

Definition at line 2285 of file buffer.c.

void create_empty_buffers ( struct page page,
unsigned long  blocksize,
unsigned long  b_state 
)

Definition at line 1505 of file buffer.c.

void emergency_thaw_all ( void  )

emergency_thaw_all – forcibly thaw every frozen filesystem

Used for emergency unfreeze of all filesystems via SysRq

Definition at line 534 of file buffer.c.

void end_buffer_async_write ( struct buffer_head *  bh,
int  uptodate 
)

Definition at line 320 of file buffer.c.

void end_buffer_read_sync ( struct buffer_head *  bh,
int  uptodate 
)

Definition at line 137 of file buffer.c.

void end_buffer_write_sync ( struct buffer_head *  bh,
int  uptodate 
)

Definition at line 144 of file buffer.c.

EXPORT_SYMBOL ( init_buffer  )
EXPORT_SYMBOL ( __lock_buffer  )
EXPORT_SYMBOL ( unlock_buffer  )
EXPORT_SYMBOL ( __wait_on_buffer  )
EXPORT_SYMBOL ( end_buffer_read_sync  )
EXPORT_SYMBOL ( end_buffer_write_sync  )
EXPORT_SYMBOL ( end_buffer_async_write  )
EXPORT_SYMBOL ( mark_buffer_async_write  )
EXPORT_SYMBOL ( sync_mapping_buffers  )
EXPORT_SYMBOL ( mark_buffer_dirty_inode  )
EXPORT_SYMBOL ( __set_page_dirty_buffers  )
EXPORT_SYMBOL ( invalidate_inode_buffers  )
EXPORT_SYMBOL ( mark_buffer_dirty  )
EXPORT_SYMBOL ( __brelse  )
EXPORT_SYMBOL ( __bforget  )
EXPORT_SYMBOL ( __find_get_block  )
EXPORT_SYMBOL ( __getblk  )
EXPORT_SYMBOL ( __breadahead  )
EXPORT_SYMBOL ( __bread  )
EXPORT_SYMBOL ( set_bh_page  )
EXPORT_SYMBOL ( block_invalidatepage  )
EXPORT_SYMBOL ( create_empty_buffers  )
EXPORT_SYMBOL ( unmap_underlying_metadata  )
EXPORT_SYMBOL ( page_zero_new_buffers  )
EXPORT_SYMBOL ( __block_write_begin  )
EXPORT_SYMBOL ( block_write_begin  )
EXPORT_SYMBOL ( block_write_end  )
EXPORT_SYMBOL ( generic_write_end  )
EXPORT_SYMBOL ( block_is_partially_uptodate  )
EXPORT_SYMBOL ( block_read_full_page  )
EXPORT_SYMBOL ( generic_cont_expand_simple  )
EXPORT_SYMBOL ( cont_write_begin  )
EXPORT_SYMBOL ( block_commit_write  )
EXPORT_SYMBOL ( __block_page_mkwrite  )
EXPORT_SYMBOL ( block_page_mkwrite  )
EXPORT_SYMBOL ( nobh_write_begin  )
EXPORT_SYMBOL ( nobh_write_end  )
EXPORT_SYMBOL ( nobh_writepage  )
EXPORT_SYMBOL ( nobh_truncate_page  )
EXPORT_SYMBOL ( block_truncate_page  )
EXPORT_SYMBOL ( block_write_full_page_endio  )
EXPORT_SYMBOL ( block_write_full_page  )
EXPORT_SYMBOL ( generic_block_bmap  )
EXPORT_SYMBOL ( submit_bh  )
EXPORT_SYMBOL ( ll_rw_block  )
EXPORT_SYMBOL ( write_dirty_buffer  )
EXPORT_SYMBOL ( __sync_dirty_buffer  )
EXPORT_SYMBOL ( sync_dirty_buffer  )
EXPORT_SYMBOL ( try_to_free_buffers  )
EXPORT_SYMBOL ( alloc_buffer_head  )
EXPORT_SYMBOL ( free_buffer_head  )
EXPORT_SYMBOL ( bh_uptodate_or_lock  )
EXPORT_SYMBOL ( bh_submit_read  )
EXPORT_SYMBOL_GPL ( alloc_page_buffers  )
EXPORT_SYMBOL_GPL ( invalidate_bh_lrus  )
void free_buffer_head ( struct buffer_head *  bh)

Definition at line 3271 of file buffer.c.

sector_t generic_block_bmap ( struct address_space mapping,
sector_t  block,
get_block_t get_block 
)

Definition at line 2868 of file buffer.c.

int generic_cont_expand_simple ( struct inode inode,
loff_t  size 
)

Definition at line 2187 of file buffer.c.

int generic_write_end ( struct file file,
struct address_space mapping,
loff_t  pos,
unsigned  len,
unsigned  copied,
struct page page,
void fsdata 
)

Definition at line 2008 of file buffer.c.

void init_buffer ( struct buffer_head *  bh,
bh_end_io_t *  handler,
void private 
)
inline

Definition at line 50 of file buffer.c.

int inode_has_buffers ( struct inode inode)

Definition at line 474 of file buffer.c.

void invalidate_bh_lrus ( void  )

Definition at line 1412 of file buffer.c.

void invalidate_inode_buffers ( struct inode inode)

Definition at line 786 of file buffer.c.

void ll_rw_block ( int  rw,
int  nr,
struct buffer_head *  bhs[] 
)

ll_rw_block: low-level access to block devices (DEPRECATED) : whether to READ or WRITE or maybe READA (readahead) : number of &struct buffer_heads in the array : array of pointers to &struct buffer_head

ll_rw_block() takes an array of pointers to &struct buffer_heads, and requests an I/O operation on them, either a READ or a WRITE. The third READA option is described in the documentation for generic_make_request() which ll_rw_block() calls.

This function drops any buffer that it cannot get a lock on (with the BH_Lock state bit), any buffer that appears to be clean when doing a write request, and any buffer that appears to be up-to-date when doing read request. Further it marks as clean buffers that are processed for writing (the buffer cache won't assume that they are actually clean until the buffer gets unlocked).

ll_rw_block sets b_end_io to simple completion handler that marks the buffer up-to-date (if approriate), unlocks the buffer and wakes any waiters.

All of the buffers must be for the same device, and must also be a multiple of the current approved size for the device.

Definition at line 3020 of file buffer.c.

void mark_buffer_async_write ( struct buffer_head *  bh)

Definition at line 406 of file buffer.c.

void mark_buffer_dirty ( struct buffer_head *  bh)

mark_buffer_dirty - mark a buffer_head as needing writeout : the buffer_head to mark dirty

mark_buffer_dirty() will set the dirty bit against the buffer, then set its backing page dirty, then tag the page as dirty in its address_space's radix tree and then attach the address_space's inode to its superblock's dirty inode list.

mark_buffer_dirty() is atomic. It takes bh->b_page->mapping->private_lock, mapping->tree_lock and mapping->host->i_lock.

Definition at line 1116 of file buffer.c.

void mark_buffer_dirty_inode ( struct buffer_head *  bh,
struct inode inode 
)

Definition at line 585 of file buffer.c.

int nobh_truncate_page ( struct address_space mapping,
loff_t  from,
get_block_t get_block 
)

Definition at line 2661 of file buffer.c.

int nobh_write_begin ( struct address_space mapping,
loff_t  pos,
unsigned  len,
unsigned  flags,
struct page **  pagep,
void **  fsdata,
get_block_t get_block 
)

Definition at line 2433 of file buffer.c.

int nobh_write_end ( struct file file,
struct address_space mapping,
loff_t  pos,
unsigned  len,
unsigned  copied,
struct page page,
void fsdata 
)

Definition at line 2574 of file buffer.c.

int nobh_writepage ( struct page page,
get_block_t get_block,
struct writeback_control wbc 
)

Definition at line 2614 of file buffer.c.

void page_zero_new_buffers ( struct page page,
unsigned  from,
unsigned  to 
)

Definition at line 1786 of file buffer.c.

int remove_inode_buffers ( struct inode inode)

Definition at line 807 of file buffer.c.

void set_bh_page ( struct buffer_head *  bh,
struct page page,
unsigned long  offset 
)

Definition at line 1418 of file buffer.c.

int submit_bh ( int  rw,
struct buffer_head *  bh 
)

Definition at line 2945 of file buffer.c.

int sync_dirty_buffer ( struct buffer_head *  bh)

Definition at line 3087 of file buffer.c.

int sync_mapping_buffers ( struct address_space mapping)

sync_mapping_buffers - write out & wait upon a mapping's "associated" buffers : the mapping which wants those buffers written

Starts I/O against the buffers at mapping->private_list, and waits upon that I/O.

Basically, this is a convenience function for fsync(). is a file or directory which needs those buffers to be written for a successful fsync().

Definition at line 556 of file buffer.c.

SYSCALL_DEFINE2 ( bdflush  ,
int  ,
func  ,
long  ,
data   
)

Definition at line 3204 of file buffer.c.

int try_to_free_buffers ( struct page page)

Definition at line 3148 of file buffer.c.

void unlock_buffer ( struct buffer_head *  bh)

Definition at line 70 of file buffer.c.

void unmap_underlying_metadata ( struct block_device bdev,
sector_t  block 
)

Definition at line 1551 of file buffer.c.

void write_boundary_block ( struct block_device bdev,
sector_t  bblock,
unsigned  blocksize 
)

Definition at line 574 of file buffer.c.

void write_dirty_buffer ( struct buffer_head *  bh,
int  rw 
)

Definition at line 3049 of file buffer.c.

Variable Documentation

int buffer_heads_over_limit

Definition at line 3235 of file buffer.c.