Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
balloc.c File Reference
#include <linux/quotaops.h>
#include <linux/blkdev.h>
#include "ext3.h"

Go to the source code of this file.

Macros

#define in_range(b, first, len)   ((b) >= (first) && (b) <= (first) + (len) - 1)
 
#define rsv_window_dump(root, verbose)   __rsv_window_dump((root), (verbose), __func__)
 

Functions

struct ext3_group_descext3_get_group_desc (struct super_block *sb, unsigned int block_group, struct buffer_head **bh)
 
void ext3_rsv_window_add (struct super_block *sb, struct ext3_reserve_window_node *rsv)
 
void ext3_init_block_alloc_info (struct inode *inode)
 
void ext3_discard_reservation (struct inode *inode)
 
void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb, ext3_fsblk_t block, unsigned long count, unsigned long *pdquot_freed_blocks)
 
void ext3_free_blocks (handle_t *handle, struct inode *inode, ext3_fsblk_t block, unsigned long count)
 
int ext3_should_retry_alloc (struct super_block *sb, int *retries)
 
ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode, ext3_fsblk_t goal, unsigned long *count, int *errp)
 
ext3_fsblk_t ext3_new_block (handle_t *handle, struct inode *inode, ext3_fsblk_t goal, int *errp)
 
ext3_fsblk_t ext3_count_free_blocks (struct super_block *sb)
 
int ext3_bg_has_super (struct super_block *sb, int group)
 
unsigned long ext3_bg_num_gdb (struct super_block *sb, int group)
 
int ext3_trim_fs (struct super_block *sb, struct fstrim_range *range)
 

Macro Definition Documentation

#define in_range (   b,
  first,
  len 
)    ((b) >= (first) && (b) <= (first) + (len) - 1)

Definition at line 34 of file balloc.c.

#define rsv_window_dump (   root,
  verbose 
)    __rsv_window_dump((root), (verbose), __func__)

Definition at line 249 of file balloc.c.

Function Documentation

int ext3_bg_has_super ( struct super_block sb,
int  group 
)

ext3_bg_has_super - number of blocks used by the superblock in group : superblock for filesystem : group number to check

Return the number of blocks used by the superblock (primary or backup) in this group. Currently this will be only 0 or 1.

Definition at line 1860 of file balloc.c.

unsigned long ext3_bg_num_gdb ( struct super_block sb,
int  group 
)

ext3_bg_num_gdb - number of blocks used by the group table in group : superblock for filesystem : group number to check

Return the number of blocks used by the group descriptor table (primary or backup) in this group. In the future there may be a different number of descriptor blocks in each group.

Definition at line 1894 of file balloc.c.

ext3_fsblk_t ext3_count_free_blocks ( struct super_block sb)

ext3_count_free_blocks() – count filesystem free blocks : superblock

Adds up the number of free blocks from each block group.

Definition at line 1780 of file balloc.c.

void ext3_discard_reservation ( struct inode inode)

ext3_discard_reservation() : inode

Discard(free) block reservation window on last file close, or truncate or at last iput().

It is being called in three cases: ext3_release_file(): last writer close the file ext3_clear_inode(): last iput(), when nobody link to this file. ext3_truncate(): when the block indirect map is about to change.

Definition at line 461 of file balloc.c.

void ext3_free_blocks ( handle_t *  handle,
struct inode inode,
ext3_fsblk_t  block,
unsigned long  count 
)

ext3_free_blocks() – Free given blocks and update quota : handle for this transaction : inode : start physical block to free : number of blocks to count

Definition at line 680 of file balloc.c.

void ext3_free_blocks_sb ( handle_t *  handle,
struct super_block sb,
ext3_fsblk_t  block,
unsigned long  count,
unsigned long pdquot_freed_blocks 
)

ext3_free_blocks_sb() – Free given blocks and update quota : handle to this transaction : super block : start physical block to free : number of blocks to free : pointer to quota

Definition at line 490 of file balloc.c.

struct ext3_group_desc* ext3_get_group_desc ( struct super_block sb,
unsigned int  block_group,
struct buffer_head **  bh 
)
read

ext3_get_group_desc() – load group descriptor from disk : super block : given block group : pointer to the buffer head to store the block group descriptor

Definition at line 58 of file balloc.c.

void ext3_init_block_alloc_info ( struct inode inode)

ext3_init_block_alloc_info() : file inode structure

Allocate and initialize the reservation window structure, and link the window to the ext3 inode structure at last

The reservation window structure is only dynamically allocated and linked to ext3 inode the first time the open file needs a new block. So, before every ext3_new_block(s) call, for regular files, we should check whether the reservation window structure exists or not. In the latter case, this function is called. Fail to do so will result in block reservation being turned off for that open file.

This function is called from ext3_get_blocks_handle(), also called when setting the reservation window size through ioctl before the file is open for write (needs block allocation).

Needs truncate_mutex protection prior to call this function.

Definition at line 419 of file balloc.c.

ext3_fsblk_t ext3_new_block ( handle_t *  handle,
struct inode inode,
ext3_fsblk_t  goal,
int errp 
)

Definition at line 1766 of file balloc.c.

ext3_fsblk_t ext3_new_blocks ( handle_t *  handle,
struct inode inode,
ext3_fsblk_t  goal,
unsigned long count,
int errp 
)

ext3_new_blocks() – core block(s) allocation function : handle to this transaction : file inode : given target block(filesystem wide) : target number of blocks to allocate : error code

ext3_new_blocks uses a goal block to assist allocation. It tries to allocate block(s) from the block group contains the goal block first. If that fails, it will try to allocate block(s) from other block groups without any specific goal block.

Definition at line 1486 of file balloc.c.

void ext3_rsv_window_add ( struct super_block sb,
struct ext3_reserve_window_node rsv 
)

ext3_rsv_window_add() – Insert a window to the block reservation rb tree. : super block : reservation window to add

Must be called with rsv_lock hold.

Definition at line 337 of file balloc.c.

int ext3_should_retry_alloc ( struct super_block sb,
int retries 
)

ext3_should_retry_alloc() : super block number of attemps has been made

ext3_should_retry_alloc() is called when ENOSPC is returned, and if it is profitable to retry the operation, this function will wait for the current or committing transaction to complete, and then return TRUE.

if the total number of retries exceed three times, return FALSE.

Definition at line 1462 of file balloc.c.

int ext3_trim_fs ( struct super_block sb,
struct fstrim_range range 
)

ext3_trim_fs() – trim ioctl handle function : superblock for filesystem : First Byte to trim : number of Bytes to trim from start : minimum extent length in Bytes

ext3_trim_fs goes through all allocation groups containing Bytes from start to start+len. For each such a group ext3_trim_all_free function is invoked to trim all free space.

Definition at line 2088 of file balloc.c.