diff options
author | Theodore Ts'o <tytso@mit.edu> | 2009-05-14 00:54:29 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2009-05-14 00:54:29 -0400 |
commit | b920c75502cb2c48654ef196d647c8eb81ab608a (patch) | |
tree | 73105b8a1212001a3636d83b3f8e9e554e048170 /fs/ext4/inode.c | |
parent | c21770573319922e3f3fcb331cfaa290c49f1c81 (diff) |
ext4: Add documentation to the ext4_*get_block* functions
This adds more documentation to various internal functions in
fs/ext4/inode.c, most notably ext4_ind_get_blocks(),
ext4_da_get_block_write(), ext4_da_get_block_prep(),
ext4_normal_get_block_write().
In addition, the static function ext4_normal_get_block_write() has
been renamed noalloc_get_block_write(), since it is used in many
places far beyond ext4_normal_writepage().
Plenty of warnings have been added to the noalloc_get_block_write()
function, since the way it is used is amazingly fragile.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 8b7564dfacdf..fd5f27a9b81b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -892,6 +892,10 @@ err_out: | |||
892 | } | 892 | } |
893 | 893 | ||
894 | /* | 894 | /* |
895 | * The ext4_ind_get_blocks() function handles non-extents inodes | ||
896 | * (i.e., using the traditional indirect/double-indirect i_blocks | ||
897 | * scheme) for ext4_get_blocks(). | ||
898 | * | ||
895 | * Allocation strategy is simple: if we have to allocate something, we will | 899 | * Allocation strategy is simple: if we have to allocate something, we will |
896 | * have to go the whole way to leaf. So let's do it before attaching anything | 900 | * have to go the whole way to leaf. So let's do it before attaching anything |
897 | * to tree, set linkage between the newborn blocks, write them if sync is | 901 | * to tree, set linkage between the newborn blocks, write them if sync is |
@@ -909,10 +913,11 @@ err_out: | |||
909 | * return = 0, if plain lookup failed. | 913 | * return = 0, if plain lookup failed. |
910 | * return < 0, error case. | 914 | * return < 0, error case. |
911 | * | 915 | * |
912 | * | 916 | * The ext4_ind_get_blocks() function should be called with |
913 | * Need to be called with | 917 | * down_write(&EXT4_I(inode)->i_data_sem) if allocating filesystem |
914 | * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block | 918 | * blocks (i.e., flags has EXT4_GET_BLOCKS_CREATE set) or |
915 | * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) | 919 | * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system |
920 | * blocks. | ||
916 | */ | 921 | */ |
917 | static int ext4_ind_get_blocks(handle_t *handle, struct inode *inode, | 922 | static int ext4_ind_get_blocks(handle_t *handle, struct inode *inode, |
918 | ext4_lblk_t iblock, unsigned int maxblocks, | 923 | ext4_lblk_t iblock, unsigned int maxblocks, |
@@ -1152,8 +1157,8 @@ int ext4_get_blocks(handle_t *handle, struct inode *inode, sector_t block, | |||
1152 | clear_buffer_unwritten(bh); | 1157 | clear_buffer_unwritten(bh); |
1153 | 1158 | ||
1154 | /* | 1159 | /* |
1155 | * Try to see if we can get the block without requesting | 1160 | * Try to see if we can get the block without requesting a new |
1156 | * for new file system block. | 1161 | * file system block. |
1157 | */ | 1162 | */ |
1158 | down_read((&EXT4_I(inode)->i_data_sem)); | 1163 | down_read((&EXT4_I(inode)->i_data_sem)); |
1159 | if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { | 1164 | if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { |
@@ -2000,6 +2005,12 @@ static void ext4_print_free_blocks(struct inode *inode) | |||
2000 | return; | 2005 | return; |
2001 | } | 2006 | } |
2002 | 2007 | ||
2008 | /* | ||
2009 | * This function is used by mpage_da_map_blocks(). We separate it out | ||
2010 | * as a separate function just to make life easier, and because | ||
2011 | * mpage_da_map_blocks() used to be a generic function that took a | ||
2012 | * get_block_t. | ||
2013 | */ | ||
2003 | static int ext4_da_get_block_write(struct inode *inode, sector_t iblock, | 2014 | static int ext4_da_get_block_write(struct inode *inode, sector_t iblock, |
2004 | struct buffer_head *bh_result) | 2015 | struct buffer_head *bh_result) |
2005 | { | 2016 | { |
@@ -2031,8 +2042,8 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock, | |||
2031 | 2042 | ||
2032 | /* | 2043 | /* |
2033 | * Update on-disk size along with block allocation we don't | 2044 | * Update on-disk size along with block allocation we don't |
2034 | * use 'extend_disksize' as size may change within already | 2045 | * use EXT4_GET_BLOCKS_EXTEND_DISKSIZE as size may change |
2035 | * allocated block -bzzz | 2046 | * within already allocated block -bzzz |
2036 | */ | 2047 | */ |
2037 | disksize = ((loff_t) iblock + ret) << inode->i_blkbits; | 2048 | disksize = ((loff_t) iblock + ret) << inode->i_blkbits; |
2038 | if (disksize > i_size_read(inode)) | 2049 | if (disksize > i_size_read(inode)) |
@@ -2338,8 +2349,9 @@ static int __mpage_da_writepage(struct page *page, | |||
2338 | } | 2349 | } |
2339 | 2350 | ||
2340 | /* | 2351 | /* |
2341 | * this is a special callback for ->write_begin() only | 2352 | * This is a special get_blocks_t callback which is used by |
2342 | * it's intention is to return mapped block or reserve space | 2353 | * ext4_da_write_begin(). It will either return mapped block or |
2354 | * reserve space for a single block. | ||
2343 | * | 2355 | * |
2344 | * For delayed buffer_head we have BH_Mapped, BH_New, BH_Delay set. | 2356 | * For delayed buffer_head we have BH_Mapped, BH_New, BH_Delay set. |
2345 | * We also have b_blocknr = -1 and b_bdev initialized properly | 2357 | * We also have b_blocknr = -1 and b_bdev initialized properly |
@@ -2347,7 +2359,6 @@ static int __mpage_da_writepage(struct page *page, | |||
2347 | * For unwritten buffer_head we have BH_Mapped, BH_New, BH_Unwritten set. | 2359 | * For unwritten buffer_head we have BH_Mapped, BH_New, BH_Unwritten set. |
2348 | * We also have b_blocknr = physicalblock mapping unwritten extent and b_bdev | 2360 | * We also have b_blocknr = physicalblock mapping unwritten extent and b_bdev |
2349 | * initialized properly. | 2361 | * initialized properly. |
2350 | * | ||
2351 | */ | 2362 | */ |
2352 | static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, | 2363 | static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, |
2353 | struct buffer_head *bh_result, int create) | 2364 | struct buffer_head *bh_result, int create) |
@@ -2400,7 +2411,23 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, | |||
2400 | return ret; | 2411 | return ret; |
2401 | } | 2412 | } |
2402 | 2413 | ||
2403 | static int ext4_normal_get_block_write(struct inode *inode, sector_t iblock, | 2414 | /* |
2415 | * This function is used as a standard get_block_t calback function | ||
2416 | * when there is no desire to allocate any blocks. It is used as a | ||
2417 | * callback function for block_prepare_write(), nobh_writepage(), and | ||
2418 | * block_write_full_page(). These functions should only try to map a | ||
2419 | * single block at a time. | ||
2420 | * | ||
2421 | * Since this function doesn't do block allocations even if the caller | ||
2422 | * requests it by passing in create=1, it is critically important that | ||
2423 | * any caller checks to make sure that any buffer heads are returned | ||
2424 | * by this function are either all already mapped or marked for | ||
2425 | * delayed allocation before calling nobh_writepage() or | ||
2426 | * block_write_full_page(). Otherwise, b_blocknr could be left | ||
2427 | * unitialized, and the page write functions will be taken by | ||
2428 | * surprise. | ||
2429 | */ | ||
2430 | static int noalloc_get_block_write(struct inode *inode, sector_t iblock, | ||
2404 | struct buffer_head *bh_result, int create) | 2431 | struct buffer_head *bh_result, int create) |
2405 | { | 2432 | { |
2406 | int ret = 0; | 2433 | int ret = 0; |
@@ -2419,10 +2446,11 @@ static int ext4_normal_get_block_write(struct inode *inode, sector_t iblock, | |||
2419 | } | 2446 | } |
2420 | 2447 | ||
2421 | /* | 2448 | /* |
2422 | * get called vi ext4_da_writepages after taking page lock (have journal handle) | 2449 | * This function can get called via... |
2423 | * get called via journal_submit_inode_data_buffers (no journal handle) | 2450 | * - ext4_da_writepages after taking page lock (have journal handle) |
2424 | * get called via shrink_page_list via pdflush (no journal handle) | 2451 | * - journal_submit_inode_data_buffers (no journal handle) |
2425 | * or grab_page_cache when doing write_begin (have journal handle) | 2452 | * - shrink_page_list via pdflush (no journal handle) |
2453 | * - grab_page_cache when doing write_begin (have journal handle) | ||
2426 | */ | 2454 | */ |
2427 | static int ext4_da_writepage(struct page *page, | 2455 | static int ext4_da_writepage(struct page *page, |
2428 | struct writeback_control *wbc) | 2456 | struct writeback_control *wbc) |
@@ -2473,7 +2501,7 @@ static int ext4_da_writepage(struct page *page, | |||
2473 | * do block allocation here. | 2501 | * do block allocation here. |
2474 | */ | 2502 | */ |
2475 | ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, | 2503 | ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, |
2476 | ext4_normal_get_block_write); | 2504 | noalloc_get_block_write); |
2477 | if (!ret) { | 2505 | if (!ret) { |
2478 | page_bufs = page_buffers(page); | 2506 | page_bufs = page_buffers(page); |
2479 | /* check whether all are mapped and non delay */ | 2507 | /* check whether all are mapped and non delay */ |
@@ -2498,11 +2526,10 @@ static int ext4_da_writepage(struct page *page, | |||
2498 | } | 2526 | } |
2499 | 2527 | ||
2500 | if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) | 2528 | if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) |
2501 | ret = nobh_writepage(page, ext4_normal_get_block_write, wbc); | 2529 | ret = nobh_writepage(page, noalloc_get_block_write, wbc); |
2502 | else | 2530 | else |
2503 | ret = block_write_full_page(page, | 2531 | ret = block_write_full_page(page, noalloc_get_block_write, |
2504 | ext4_normal_get_block_write, | 2532 | wbc); |
2505 | wbc); | ||
2506 | 2533 | ||
2507 | return ret; | 2534 | return ret; |
2508 | } | 2535 | } |
@@ -2814,7 +2841,7 @@ retry: | |||
2814 | *pagep = page; | 2841 | *pagep = page; |
2815 | 2842 | ||
2816 | ret = block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, | 2843 | ret = block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, |
2817 | ext4_da_get_block_prep); | 2844 | ext4_da_get_block_prep); |
2818 | if (ret < 0) { | 2845 | if (ret < 0) { |
2819 | unlock_page(page); | 2846 | unlock_page(page); |
2820 | ext4_journal_stop(handle); | 2847 | ext4_journal_stop(handle); |
@@ -3122,12 +3149,10 @@ static int __ext4_normal_writepage(struct page *page, | |||
3122 | struct inode *inode = page->mapping->host; | 3149 | struct inode *inode = page->mapping->host; |
3123 | 3150 | ||
3124 | if (test_opt(inode->i_sb, NOBH)) | 3151 | if (test_opt(inode->i_sb, NOBH)) |
3125 | return nobh_writepage(page, | 3152 | return nobh_writepage(page, noalloc_get_block_write, wbc); |
3126 | ext4_normal_get_block_write, wbc); | ||
3127 | else | 3153 | else |
3128 | return block_write_full_page(page, | 3154 | return block_write_full_page(page, noalloc_get_block_write, |
3129 | ext4_normal_get_block_write, | 3155 | wbc); |
3130 | wbc); | ||
3131 | } | 3156 | } |
3132 | 3157 | ||
3133 | static int ext4_normal_writepage(struct page *page, | 3158 | static int ext4_normal_writepage(struct page *page, |
@@ -3179,7 +3204,7 @@ static int __ext4_journalled_writepage(struct page *page, | |||
3179 | int err; | 3204 | int err; |
3180 | 3205 | ||
3181 | ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, | 3206 | ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, |
3182 | ext4_normal_get_block_write); | 3207 | noalloc_get_block_write); |
3183 | if (ret != 0) | 3208 | if (ret != 0) |
3184 | goto out_unlock; | 3209 | goto out_unlock; |
3185 | 3210 | ||
@@ -3264,9 +3289,8 @@ static int ext4_journalled_writepage(struct page *page, | |||
3264 | * really know unless we go poke around in the buffer_heads. | 3289 | * really know unless we go poke around in the buffer_heads. |
3265 | * But block_write_full_page will do the right thing. | 3290 | * But block_write_full_page will do the right thing. |
3266 | */ | 3291 | */ |
3267 | return block_write_full_page(page, | 3292 | return block_write_full_page(page, noalloc_get_block_write, |
3268 | ext4_normal_get_block_write, | 3293 | wbc); |
3269 | wbc); | ||
3270 | } | 3294 | } |
3271 | no_write: | 3295 | no_write: |
3272 | redirty_page_for_writepage(wbc, page); | 3296 | redirty_page_for_writepage(wbc, page); |