diff options
Diffstat (limited to 'fs/ext3/inode.c')
| -rw-r--r-- | fs/ext3/inode.c | 170 |
1 files changed, 86 insertions, 84 deletions
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index 2edd7eec88fd..dcf4f1dd108b 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
| @@ -13,11 +13,11 @@ | |||
| 13 | * Copyright (C) 1991, 1992 Linus Torvalds | 13 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 14 | * | 14 | * |
| 15 | * Goal-directed block allocation by Stephen Tweedie | 15 | * Goal-directed block allocation by Stephen Tweedie |
| 16 | * (sct@redhat.com), 1993, 1998 | 16 | * (sct@redhat.com), 1993, 1998 |
| 17 | * Big-endian to little-endian byte-swapping/bitmaps by | 17 | * Big-endian to little-endian byte-swapping/bitmaps by |
| 18 | * David S. Miller (davem@caip.rutgers.edu), 1995 | 18 | * David S. Miller (davem@caip.rutgers.edu), 1995 |
| 19 | * 64-bit file support on 64-bit platforms by Jakub Jelinek | 19 | * 64-bit file support on 64-bit platforms by Jakub Jelinek |
| 20 | * (jj@sunsite.ms.mff.cuni.cz) | 20 | * (jj@sunsite.ms.mff.cuni.cz) |
| 21 | * | 21 | * |
| 22 | * Assorted race fixes, rewrite of ext3_get_block() by Al Viro, 2000 | 22 | * Assorted race fixes, rewrite of ext3_get_block() by Al Viro, 2000 |
| 23 | */ | 23 | */ |
| @@ -55,14 +55,14 @@ static int ext3_inode_is_fast_symlink(struct inode *inode) | |||
| 55 | /* | 55 | /* |
| 56 | * The ext3 forget function must perform a revoke if we are freeing data | 56 | * The ext3 forget function must perform a revoke if we are freeing data |
| 57 | * which has been journaled. Metadata (eg. indirect blocks) must be | 57 | * which has been journaled. Metadata (eg. indirect blocks) must be |
| 58 | * revoked in all cases. | 58 | * revoked in all cases. |
| 59 | * | 59 | * |
| 60 | * "bh" may be NULL: a metadata block may have been freed from memory | 60 | * "bh" may be NULL: a metadata block may have been freed from memory |
| 61 | * but there may still be a record of it in the journal, and that record | 61 | * but there may still be a record of it in the journal, and that record |
| 62 | * still needs to be revoked. | 62 | * still needs to be revoked. |
| 63 | */ | 63 | */ |
| 64 | int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, | 64 | int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, |
| 65 | struct buffer_head *bh, int blocknr) | 65 | struct buffer_head *bh, ext3_fsblk_t blocknr) |
| 66 | { | 66 | { |
| 67 | int err; | 67 | int err; |
| 68 | 68 | ||
| @@ -105,7 +105,7 @@ int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, | |||
| 105 | * Work out how many blocks we need to proceed with the next chunk of a | 105 | * Work out how many blocks we need to proceed with the next chunk of a |
| 106 | * truncate transaction. | 106 | * truncate transaction. |
| 107 | */ | 107 | */ |
| 108 | static unsigned long blocks_for_truncate(struct inode *inode) | 108 | static unsigned long blocks_for_truncate(struct inode *inode) |
| 109 | { | 109 | { |
| 110 | unsigned long needed; | 110 | unsigned long needed; |
| 111 | 111 | ||
| @@ -122,13 +122,13 @@ static unsigned long blocks_for_truncate(struct inode *inode) | |||
| 122 | 122 | ||
| 123 | /* But we need to bound the transaction so we don't overflow the | 123 | /* But we need to bound the transaction so we don't overflow the |
| 124 | * journal. */ | 124 | * journal. */ |
| 125 | if (needed > EXT3_MAX_TRANS_DATA) | 125 | if (needed > EXT3_MAX_TRANS_DATA) |
| 126 | needed = EXT3_MAX_TRANS_DATA; | 126 | needed = EXT3_MAX_TRANS_DATA; |
| 127 | 127 | ||
| 128 | return EXT3_DATA_TRANS_BLOCKS(inode->i_sb) + needed; | 128 | return EXT3_DATA_TRANS_BLOCKS(inode->i_sb) + needed; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | /* | 131 | /* |
| 132 | * Truncate transactions can be complex and absolutely huge. So we need to | 132 | * Truncate transactions can be complex and absolutely huge. So we need to |
| 133 | * be able to restart the transaction at a conventient checkpoint to make | 133 | * be able to restart the transaction at a conventient checkpoint to make |
| 134 | * sure we don't overflow the journal. | 134 | * sure we don't overflow the journal. |
| @@ -136,9 +136,9 @@ static unsigned long blocks_for_truncate(struct inode *inode) | |||
| 136 | * start_transaction gets us a new handle for a truncate transaction, | 136 | * start_transaction gets us a new handle for a truncate transaction, |
| 137 | * and extend_transaction tries to extend the existing one a bit. If | 137 | * and extend_transaction tries to extend the existing one a bit. If |
| 138 | * extend fails, we need to propagate the failure up and restart the | 138 | * extend fails, we need to propagate the failure up and restart the |
| 139 | * transaction in the top-level truncate loop. --sct | 139 | * transaction in the top-level truncate loop. --sct |
| 140 | */ | 140 | */ |
| 141 | static handle_t *start_transaction(struct inode *inode) | 141 | static handle_t *start_transaction(struct inode *inode) |
| 142 | { | 142 | { |
| 143 | handle_t *result; | 143 | handle_t *result; |
| 144 | 144 | ||
| @@ -215,12 +215,12 @@ void ext3_delete_inode (struct inode * inode) | |||
| 215 | ext3_orphan_del(handle, inode); | 215 | ext3_orphan_del(handle, inode); |
| 216 | EXT3_I(inode)->i_dtime = get_seconds(); | 216 | EXT3_I(inode)->i_dtime = get_seconds(); |
| 217 | 217 | ||
| 218 | /* | 218 | /* |
| 219 | * One subtle ordering requirement: if anything has gone wrong | 219 | * One subtle ordering requirement: if anything has gone wrong |
| 220 | * (transaction abort, IO errors, whatever), then we can still | 220 | * (transaction abort, IO errors, whatever), then we can still |
| 221 | * do these next steps (the fs will already have been marked as | 221 | * do these next steps (the fs will already have been marked as |
| 222 | * having errors), but we can't free the inode if the mark_dirty | 222 | * having errors), but we can't free the inode if the mark_dirty |
| 223 | * fails. | 223 | * fails. |
| 224 | */ | 224 | */ |
| 225 | if (ext3_mark_inode_dirty(handle, inode)) | 225 | if (ext3_mark_inode_dirty(handle, inode)) |
| 226 | /* If that failed, just do the required in-core inode clear. */ | 226 | /* If that failed, just do the required in-core inode clear. */ |
| @@ -398,7 +398,7 @@ no_block: | |||
| 398 | * + if there is a block to the left of our position - allocate near it. | 398 | * + if there is a block to the left of our position - allocate near it. |
| 399 | * + if pointer will live in indirect block - allocate near that block. | 399 | * + if pointer will live in indirect block - allocate near that block. |
| 400 | * + if pointer will live in inode - allocate in the same | 400 | * + if pointer will live in inode - allocate in the same |
| 401 | * cylinder group. | 401 | * cylinder group. |
| 402 | * | 402 | * |
| 403 | * In the latter case we colour the starting block by the callers PID to | 403 | * In the latter case we colour the starting block by the callers PID to |
| 404 | * prevent it from clashing with concurrent allocations for a different inode | 404 | * prevent it from clashing with concurrent allocations for a different inode |
| @@ -407,13 +407,13 @@ no_block: | |||
| 407 | * | 407 | * |
| 408 | * Caller must make sure that @ind is valid and will stay that way. | 408 | * Caller must make sure that @ind is valid and will stay that way. |
| 409 | */ | 409 | */ |
| 410 | static unsigned long ext3_find_near(struct inode *inode, Indirect *ind) | 410 | static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind) |
| 411 | { | 411 | { |
| 412 | struct ext3_inode_info *ei = EXT3_I(inode); | 412 | struct ext3_inode_info *ei = EXT3_I(inode); |
| 413 | __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data; | 413 | __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data; |
| 414 | __le32 *p; | 414 | __le32 *p; |
| 415 | unsigned long bg_start; | 415 | ext3_fsblk_t bg_start; |
| 416 | unsigned long colour; | 416 | ext3_grpblk_t colour; |
| 417 | 417 | ||
| 418 | /* Try to find previous block */ | 418 | /* Try to find previous block */ |
| 419 | for (p = ind->p - 1; p >= start; p--) { | 419 | for (p = ind->p - 1; p >= start; p--) { |
| @@ -429,8 +429,7 @@ static unsigned long ext3_find_near(struct inode *inode, Indirect *ind) | |||
| 429 | * It is going to be referred to from the inode itself? OK, just put it | 429 | * It is going to be referred to from the inode itself? OK, just put it |
| 430 | * into the same cylinder group then. | 430 | * into the same cylinder group then. |
| 431 | */ | 431 | */ |
| 432 | bg_start = (ei->i_block_group * EXT3_BLOCKS_PER_GROUP(inode->i_sb)) + | 432 | bg_start = ext3_group_first_block_no(inode->i_sb, ei->i_block_group); |
| 433 | le32_to_cpu(EXT3_SB(inode->i_sb)->s_es->s_first_data_block); | ||
| 434 | colour = (current->pid % 16) * | 433 | colour = (current->pid % 16) * |
| 435 | (EXT3_BLOCKS_PER_GROUP(inode->i_sb) / 16); | 434 | (EXT3_BLOCKS_PER_GROUP(inode->i_sb) / 16); |
| 436 | return bg_start + colour; | 435 | return bg_start + colour; |
| @@ -448,7 +447,7 @@ static unsigned long ext3_find_near(struct inode *inode, Indirect *ind) | |||
| 448 | * stores it in *@goal and returns zero. | 447 | * stores it in *@goal and returns zero. |
| 449 | */ | 448 | */ |
| 450 | 449 | ||
| 451 | static unsigned long ext3_find_goal(struct inode *inode, long block, | 450 | static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block, |
| 452 | Indirect chain[4], Indirect *partial) | 451 | Indirect chain[4], Indirect *partial) |
| 453 | { | 452 | { |
| 454 | struct ext3_block_alloc_info *block_i; | 453 | struct ext3_block_alloc_info *block_i; |
| @@ -471,7 +470,7 @@ static unsigned long ext3_find_goal(struct inode *inode, long block, | |||
| 471 | * ext3_blks_to_allocate: Look up the block map and count the number | 470 | * ext3_blks_to_allocate: Look up the block map and count the number |
| 472 | * of direct blocks need to be allocated for the given branch. | 471 | * of direct blocks need to be allocated for the given branch. |
| 473 | * | 472 | * |
| 474 | * @branch: chain of indirect blocks | 473 | * @branch: chain of indirect blocks |
| 475 | * @k: number of blocks need for indirect blocks | 474 | * @k: number of blocks need for indirect blocks |
| 476 | * @blks: number of data blocks to be mapped. | 475 | * @blks: number of data blocks to be mapped. |
| 477 | * @blocks_to_boundary: the offset in the indirect block | 476 | * @blocks_to_boundary: the offset in the indirect block |
| @@ -516,13 +515,13 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks, | |||
| 516 | * direct blocks | 515 | * direct blocks |
| 517 | */ | 516 | */ |
| 518 | static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, | 517 | static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, |
| 519 | unsigned long goal, int indirect_blks, int blks, | 518 | ext3_fsblk_t goal, int indirect_blks, int blks, |
| 520 | unsigned long long new_blocks[4], int *err) | 519 | ext3_fsblk_t new_blocks[4], int *err) |
| 521 | { | 520 | { |
| 522 | int target, i; | 521 | int target, i; |
| 523 | unsigned long count = 0; | 522 | unsigned long count = 0; |
| 524 | int index = 0; | 523 | int index = 0; |
| 525 | unsigned long current_block = 0; | 524 | ext3_fsblk_t current_block = 0; |
| 526 | int ret = 0; | 525 | int ret = 0; |
| 527 | 526 | ||
| 528 | /* | 527 | /* |
| @@ -592,7 +591,7 @@ failed_out: | |||
| 592 | * as described above and return 0. | 591 | * as described above and return 0. |
| 593 | */ | 592 | */ |
| 594 | static int ext3_alloc_branch(handle_t *handle, struct inode *inode, | 593 | static int ext3_alloc_branch(handle_t *handle, struct inode *inode, |
| 595 | int indirect_blks, int *blks, unsigned long goal, | 594 | int indirect_blks, int *blks, ext3_fsblk_t goal, |
| 596 | int *offsets, Indirect *branch) | 595 | int *offsets, Indirect *branch) |
| 597 | { | 596 | { |
| 598 | int blocksize = inode->i_sb->s_blocksize; | 597 | int blocksize = inode->i_sb->s_blocksize; |
| @@ -600,8 +599,8 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode, | |||
| 600 | int err = 0; | 599 | int err = 0; |
| 601 | struct buffer_head *bh; | 600 | struct buffer_head *bh; |
| 602 | int num; | 601 | int num; |
| 603 | unsigned long long new_blocks[4]; | 602 | ext3_fsblk_t new_blocks[4]; |
| 604 | unsigned long long current_block; | 603 | ext3_fsblk_t current_block; |
| 605 | 604 | ||
| 606 | num = ext3_alloc_blocks(handle, inode, goal, indirect_blks, | 605 | num = ext3_alloc_blocks(handle, inode, goal, indirect_blks, |
| 607 | *blks, new_blocks, &err); | 606 | *blks, new_blocks, &err); |
| @@ -688,7 +687,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, | |||
| 688 | int i; | 687 | int i; |
| 689 | int err = 0; | 688 | int err = 0; |
| 690 | struct ext3_block_alloc_info *block_i; | 689 | struct ext3_block_alloc_info *block_i; |
| 691 | unsigned long current_block; | 690 | ext3_fsblk_t current_block; |
| 692 | 691 | ||
| 693 | block_i = EXT3_I(inode)->i_block_alloc_info; | 692 | block_i = EXT3_I(inode)->i_block_alloc_info; |
| 694 | /* | 693 | /* |
| @@ -745,7 +744,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, | |||
| 745 | jbd_debug(5, "splicing indirect only\n"); | 744 | jbd_debug(5, "splicing indirect only\n"); |
| 746 | BUFFER_TRACE(where->bh, "call ext3_journal_dirty_metadata"); | 745 | BUFFER_TRACE(where->bh, "call ext3_journal_dirty_metadata"); |
| 747 | err = ext3_journal_dirty_metadata(handle, where->bh); | 746 | err = ext3_journal_dirty_metadata(handle, where->bh); |
| 748 | if (err) | 747 | if (err) |
| 749 | goto err_out; | 748 | goto err_out; |
| 750 | } else { | 749 | } else { |
| 751 | /* | 750 | /* |
| @@ -795,13 +794,13 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, | |||
| 795 | int offsets[4]; | 794 | int offsets[4]; |
| 796 | Indirect chain[4]; | 795 | Indirect chain[4]; |
| 797 | Indirect *partial; | 796 | Indirect *partial; |
| 798 | unsigned long goal; | 797 | ext3_fsblk_t goal; |
| 799 | int indirect_blks; | 798 | int indirect_blks; |
| 800 | int blocks_to_boundary = 0; | 799 | int blocks_to_boundary = 0; |
| 801 | int depth; | 800 | int depth; |
| 802 | struct ext3_inode_info *ei = EXT3_I(inode); | 801 | struct ext3_inode_info *ei = EXT3_I(inode); |
| 803 | int count = 0; | 802 | int count = 0; |
| 804 | unsigned long first_block = 0; | 803 | ext3_fsblk_t first_block = 0; |
| 805 | 804 | ||
| 806 | 805 | ||
| 807 | J_ASSERT(handle != NULL || create == 0); | 806 | J_ASSERT(handle != NULL || create == 0); |
| @@ -819,7 +818,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, | |||
| 819 | count++; | 818 | count++; |
| 820 | /*map more blocks*/ | 819 | /*map more blocks*/ |
| 821 | while (count < maxblocks && count <= blocks_to_boundary) { | 820 | while (count < maxblocks && count <= blocks_to_boundary) { |
| 822 | unsigned long blk; | 821 | ext3_fsblk_t blk; |
| 823 | 822 | ||
| 824 | if (!verify_chain(chain, partial)) { | 823 | if (!verify_chain(chain, partial)) { |
| 825 | /* | 824 | /* |
| @@ -926,7 +925,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, | |||
| 926 | set_buffer_new(bh_result); | 925 | set_buffer_new(bh_result); |
| 927 | got_it: | 926 | got_it: |
| 928 | map_bh(bh_result, inode->i_sb, le32_to_cpu(chain[depth-1].key)); | 927 | map_bh(bh_result, inode->i_sb, le32_to_cpu(chain[depth-1].key)); |
| 929 | if (blocks_to_boundary == 0) | 928 | if (count > blocks_to_boundary) |
| 930 | set_buffer_boundary(bh_result); | 929 | set_buffer_boundary(bh_result); |
| 931 | err = count; | 930 | err = count; |
| 932 | /* Clean up and exit */ | 931 | /* Clean up and exit */ |
| @@ -1010,11 +1009,14 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode, | |||
| 1010 | buffer_trace_init(&dummy.b_history); | 1009 | buffer_trace_init(&dummy.b_history); |
| 1011 | err = ext3_get_blocks_handle(handle, inode, block, 1, | 1010 | err = ext3_get_blocks_handle(handle, inode, block, 1, |
| 1012 | &dummy, create, 1); | 1011 | &dummy, create, 1); |
| 1013 | if (err == 1) { | 1012 | /* |
| 1013 | * ext3_get_blocks_handle() returns number of blocks | ||
| 1014 | * mapped. 0 in case of a HOLE. | ||
| 1015 | */ | ||
| 1016 | if (err > 0) { | ||
| 1017 | if (err > 1) | ||
| 1018 | WARN_ON(1); | ||
| 1014 | err = 0; | 1019 | err = 0; |
| 1015 | } else if (err >= 0) { | ||
| 1016 | WARN_ON(1); | ||
| 1017 | err = -EIO; | ||
| 1018 | } | 1020 | } |
| 1019 | *errp = err; | 1021 | *errp = err; |
| 1020 | if (!err && buffer_mapped(&dummy)) { | 1022 | if (!err && buffer_mapped(&dummy)) { |
| @@ -1096,7 +1098,7 @@ static int walk_page_buffers( handle_t *handle, | |||
| 1096 | 1098 | ||
| 1097 | for ( bh = head, block_start = 0; | 1099 | for ( bh = head, block_start = 0; |
| 1098 | ret == 0 && (bh != head || !block_start); | 1100 | ret == 0 && (bh != head || !block_start); |
| 1099 | block_start = block_end, bh = next) | 1101 | block_start = block_end, bh = next) |
| 1100 | { | 1102 | { |
| 1101 | next = bh->b_this_page; | 1103 | next = bh->b_this_page; |
| 1102 | block_end = block_start + blocksize; | 1104 | block_end = block_start + blocksize; |
| @@ -1135,7 +1137,7 @@ static int walk_page_buffers( handle_t *handle, | |||
| 1135 | * So what we do is to rely on the fact that journal_stop/journal_start | 1137 | * So what we do is to rely on the fact that journal_stop/journal_start |
| 1136 | * will _not_ run commit under these circumstances because handle->h_ref | 1138 | * will _not_ run commit under these circumstances because handle->h_ref |
| 1137 | * is elevated. We'll still have enough credits for the tiny quotafile | 1139 | * is elevated. We'll still have enough credits for the tiny quotafile |
| 1138 | * write. | 1140 | * write. |
| 1139 | */ | 1141 | */ |
| 1140 | static int do_journal_get_write_access(handle_t *handle, | 1142 | static int do_journal_get_write_access(handle_t *handle, |
| 1141 | struct buffer_head *bh) | 1143 | struct buffer_head *bh) |
| @@ -1159,7 +1161,7 @@ retry: | |||
| 1159 | ret = PTR_ERR(handle); | 1161 | ret = PTR_ERR(handle); |
| 1160 | goto out; | 1162 | goto out; |
| 1161 | } | 1163 | } |
| 1162 | if (test_opt(inode->i_sb, NOBH)) | 1164 | if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) |
| 1163 | ret = nobh_prepare_write(page, from, to, ext3_get_block); | 1165 | ret = nobh_prepare_write(page, from, to, ext3_get_block); |
| 1164 | else | 1166 | else |
| 1165 | ret = block_prepare_write(page, from, to, ext3_get_block); | 1167 | ret = block_prepare_write(page, from, to, ext3_get_block); |
| @@ -1245,7 +1247,7 @@ static int ext3_writeback_commit_write(struct file *file, struct page *page, | |||
| 1245 | if (new_i_size > EXT3_I(inode)->i_disksize) | 1247 | if (new_i_size > EXT3_I(inode)->i_disksize) |
| 1246 | EXT3_I(inode)->i_disksize = new_i_size; | 1248 | EXT3_I(inode)->i_disksize = new_i_size; |
| 1247 | 1249 | ||
| 1248 | if (test_opt(inode->i_sb, NOBH)) | 1250 | if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) |
| 1249 | ret = nobh_commit_write(file, page, from, to); | 1251 | ret = nobh_commit_write(file, page, from, to); |
| 1250 | else | 1252 | else |
| 1251 | ret = generic_commit_write(file, page, from, to); | 1253 | ret = generic_commit_write(file, page, from, to); |
| @@ -1280,7 +1282,7 @@ static int ext3_journalled_commit_write(struct file *file, | |||
| 1280 | if (inode->i_size > EXT3_I(inode)->i_disksize) { | 1282 | if (inode->i_size > EXT3_I(inode)->i_disksize) { |
| 1281 | EXT3_I(inode)->i_disksize = inode->i_size; | 1283 | EXT3_I(inode)->i_disksize = inode->i_size; |
| 1282 | ret2 = ext3_mark_inode_dirty(handle, inode); | 1284 | ret2 = ext3_mark_inode_dirty(handle, inode); |
| 1283 | if (!ret) | 1285 | if (!ret) |
| 1284 | ret = ret2; | 1286 | ret = ret2; |
| 1285 | } | 1287 | } |
| 1286 | ret2 = ext3_journal_stop(handle); | 1288 | ret2 = ext3_journal_stop(handle); |
| @@ -1289,7 +1291,7 @@ static int ext3_journalled_commit_write(struct file *file, | |||
| 1289 | return ret; | 1291 | return ret; |
| 1290 | } | 1292 | } |
| 1291 | 1293 | ||
| 1292 | /* | 1294 | /* |
| 1293 | * bmap() is special. It gets used by applications such as lilo and by | 1295 | * bmap() is special. It gets used by applications such as lilo and by |
| 1294 | * the swapper to find the on-disk block of a specific piece of data. | 1296 | * the swapper to find the on-disk block of a specific piece of data. |
| 1295 | * | 1297 | * |
| @@ -1298,10 +1300,10 @@ static int ext3_journalled_commit_write(struct file *file, | |||
| 1298 | * filesystem and enables swap, then they may get a nasty shock when the | 1300 | * filesystem and enables swap, then they may get a nasty shock when the |
| 1299 | * data getting swapped to that swapfile suddenly gets overwritten by | 1301 | * data getting swapped to that swapfile suddenly gets overwritten by |
| 1300 | * the original zero's written out previously to the journal and | 1302 | * the original zero's written out previously to the journal and |
| 1301 | * awaiting writeback in the kernel's buffer cache. | 1303 | * awaiting writeback in the kernel's buffer cache. |
| 1302 | * | 1304 | * |
| 1303 | * So, if we see any bmap calls here on a modified, data-journaled file, | 1305 | * So, if we see any bmap calls here on a modified, data-journaled file, |
| 1304 | * take extra steps to flush any blocks which might be in the cache. | 1306 | * take extra steps to flush any blocks which might be in the cache. |
| 1305 | */ | 1307 | */ |
| 1306 | static sector_t ext3_bmap(struct address_space *mapping, sector_t block) | 1308 | static sector_t ext3_bmap(struct address_space *mapping, sector_t block) |
| 1307 | { | 1309 | { |
| @@ -1310,16 +1312,16 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block) | |||
| 1310 | int err; | 1312 | int err; |
| 1311 | 1313 | ||
| 1312 | if (EXT3_I(inode)->i_state & EXT3_STATE_JDATA) { | 1314 | if (EXT3_I(inode)->i_state & EXT3_STATE_JDATA) { |
| 1313 | /* | 1315 | /* |
| 1314 | * This is a REALLY heavyweight approach, but the use of | 1316 | * This is a REALLY heavyweight approach, but the use of |
| 1315 | * bmap on dirty files is expected to be extremely rare: | 1317 | * bmap on dirty files is expected to be extremely rare: |
| 1316 | * only if we run lilo or swapon on a freshly made file | 1318 | * only if we run lilo or swapon on a freshly made file |
| 1317 | * do we expect this to happen. | 1319 | * do we expect this to happen. |
| 1318 | * | 1320 | * |
| 1319 | * (bmap requires CAP_SYS_RAWIO so this does not | 1321 | * (bmap requires CAP_SYS_RAWIO so this does not |
| 1320 | * represent an unprivileged user DOS attack --- we'd be | 1322 | * represent an unprivileged user DOS attack --- we'd be |
| 1321 | * in trouble if mortal users could trigger this path at | 1323 | * in trouble if mortal users could trigger this path at |
| 1322 | * will.) | 1324 | * will.) |
| 1323 | * | 1325 | * |
| 1324 | * NB. EXT3_STATE_JDATA is not set on files other than | 1326 | * NB. EXT3_STATE_JDATA is not set on files other than |
| 1325 | * regular files. If somebody wants to bmap a directory | 1327 | * regular files. If somebody wants to bmap a directory |
| @@ -1455,7 +1457,7 @@ static int ext3_ordered_writepage(struct page *page, | |||
| 1455 | */ | 1457 | */ |
| 1456 | 1458 | ||
| 1457 | /* | 1459 | /* |
| 1458 | * And attach them to the current transaction. But only if | 1460 | * And attach them to the current transaction. But only if |
| 1459 | * block_write_full_page() succeeded. Otherwise they are unmapped, | 1461 | * block_write_full_page() succeeded. Otherwise they are unmapped, |
| 1460 | * and generally junk. | 1462 | * and generally junk. |
| 1461 | */ | 1463 | */ |
| @@ -1495,7 +1497,7 @@ static int ext3_writeback_writepage(struct page *page, | |||
| 1495 | goto out_fail; | 1497 | goto out_fail; |
| 1496 | } | 1498 | } |
| 1497 | 1499 | ||
| 1498 | if (test_opt(inode->i_sb, NOBH)) | 1500 | if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) |
| 1499 | ret = nobh_writepage(page, ext3_get_block, wbc); | 1501 | ret = nobh_writepage(page, ext3_get_block, wbc); |
| 1500 | else | 1502 | else |
| 1501 | ret = block_write_full_page(page, ext3_get_block, wbc); | 1503 | ret = block_write_full_page(page, ext3_get_block, wbc); |
| @@ -1642,7 +1644,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, | |||
| 1642 | } | 1644 | } |
| 1643 | } | 1645 | } |
| 1644 | 1646 | ||
| 1645 | ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, | 1647 | ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, |
| 1646 | offset, nr_segs, | 1648 | offset, nr_segs, |
| 1647 | ext3_get_block, NULL); | 1649 | ext3_get_block, NULL); |
| 1648 | 1650 | ||
| @@ -1699,7 +1701,7 @@ static int ext3_journalled_set_page_dirty(struct page *page) | |||
| 1699 | return __set_page_dirty_nobuffers(page); | 1701 | return __set_page_dirty_nobuffers(page); |
| 1700 | } | 1702 | } |
| 1701 | 1703 | ||
| 1702 | static struct address_space_operations ext3_ordered_aops = { | 1704 | static const struct address_space_operations ext3_ordered_aops = { |
| 1703 | .readpage = ext3_readpage, | 1705 | .readpage = ext3_readpage, |
| 1704 | .readpages = ext3_readpages, | 1706 | .readpages = ext3_readpages, |
| 1705 | .writepage = ext3_ordered_writepage, | 1707 | .writepage = ext3_ordered_writepage, |
| @@ -1713,7 +1715,7 @@ static struct address_space_operations ext3_ordered_aops = { | |||
| 1713 | .migratepage = buffer_migrate_page, | 1715 | .migratepage = buffer_migrate_page, |
| 1714 | }; | 1716 | }; |
| 1715 | 1717 | ||
| 1716 | static struct address_space_operations ext3_writeback_aops = { | 1718 | static const struct address_space_operations ext3_writeback_aops = { |
| 1717 | .readpage = ext3_readpage, | 1719 | .readpage = ext3_readpage, |
| 1718 | .readpages = ext3_readpages, | 1720 | .readpages = ext3_readpages, |
| 1719 | .writepage = ext3_writeback_writepage, | 1721 | .writepage = ext3_writeback_writepage, |
| @@ -1727,7 +1729,7 @@ static struct address_space_operations ext3_writeback_aops = { | |||
| 1727 | .migratepage = buffer_migrate_page, | 1729 | .migratepage = buffer_migrate_page, |
| 1728 | }; | 1730 | }; |
| 1729 | 1731 | ||
| 1730 | static struct address_space_operations ext3_journalled_aops = { | 1732 | static const struct address_space_operations ext3_journalled_aops = { |
| 1731 | .readpage = ext3_readpage, | 1733 | .readpage = ext3_readpage, |
| 1732 | .readpages = ext3_readpages, | 1734 | .readpages = ext3_readpages, |
| 1733 | .writepage = ext3_journalled_writepage, | 1735 | .writepage = ext3_journalled_writepage, |
| @@ -1759,7 +1761,7 @@ void ext3_set_aops(struct inode *inode) | |||
| 1759 | static int ext3_block_truncate_page(handle_t *handle, struct page *page, | 1761 | static int ext3_block_truncate_page(handle_t *handle, struct page *page, |
| 1760 | struct address_space *mapping, loff_t from) | 1762 | struct address_space *mapping, loff_t from) |
| 1761 | { | 1763 | { |
| 1762 | unsigned long index = from >> PAGE_CACHE_SHIFT; | 1764 | ext3_fsblk_t index = from >> PAGE_CACHE_SHIFT; |
| 1763 | unsigned offset = from & (PAGE_CACHE_SIZE-1); | 1765 | unsigned offset = from & (PAGE_CACHE_SIZE-1); |
| 1764 | unsigned blocksize, iblock, length, pos; | 1766 | unsigned blocksize, iblock, length, pos; |
| 1765 | struct inode *inode = mapping->host; | 1767 | struct inode *inode = mapping->host; |
| @@ -1960,7 +1962,7 @@ no_top: | |||
| 1960 | * than `count' because there can be holes in there. | 1962 | * than `count' because there can be holes in there. |
| 1961 | */ | 1963 | */ |
| 1962 | static void ext3_clear_blocks(handle_t *handle, struct inode *inode, | 1964 | static void ext3_clear_blocks(handle_t *handle, struct inode *inode, |
| 1963 | struct buffer_head *bh, unsigned long block_to_free, | 1965 | struct buffer_head *bh, ext3_fsblk_t block_to_free, |
| 1964 | unsigned long count, __le32 *first, __le32 *last) | 1966 | unsigned long count, __le32 *first, __le32 *last) |
| 1965 | { | 1967 | { |
| 1966 | __le32 *p; | 1968 | __le32 *p; |
| @@ -2022,12 +2024,12 @@ static void ext3_free_data(handle_t *handle, struct inode *inode, | |||
| 2022 | struct buffer_head *this_bh, | 2024 | struct buffer_head *this_bh, |
| 2023 | __le32 *first, __le32 *last) | 2025 | __le32 *first, __le32 *last) |
| 2024 | { | 2026 | { |
| 2025 | unsigned long block_to_free = 0; /* Starting block # of a run */ | 2027 | ext3_fsblk_t block_to_free = 0; /* Starting block # of a run */ |
| 2026 | unsigned long count = 0; /* Number of blocks in the run */ | 2028 | unsigned long count = 0; /* Number of blocks in the run */ |
| 2027 | __le32 *block_to_free_p = NULL; /* Pointer into inode/ind | 2029 | __le32 *block_to_free_p = NULL; /* Pointer into inode/ind |
| 2028 | corresponding to | 2030 | corresponding to |
| 2029 | block_to_free */ | 2031 | block_to_free */ |
| 2030 | unsigned long nr; /* Current block # */ | 2032 | ext3_fsblk_t nr; /* Current block # */ |
| 2031 | __le32 *p; /* Pointer into inode/ind | 2033 | __le32 *p; /* Pointer into inode/ind |
| 2032 | for current block */ | 2034 | for current block */ |
| 2033 | int err; | 2035 | int err; |
| @@ -2052,7 +2054,7 @@ static void ext3_free_data(handle_t *handle, struct inode *inode, | |||
| 2052 | } else if (nr == block_to_free + count) { | 2054 | } else if (nr == block_to_free + count) { |
| 2053 | count++; | 2055 | count++; |
| 2054 | } else { | 2056 | } else { |
| 2055 | ext3_clear_blocks(handle, inode, this_bh, | 2057 | ext3_clear_blocks(handle, inode, this_bh, |
| 2056 | block_to_free, | 2058 | block_to_free, |
| 2057 | count, block_to_free_p, p); | 2059 | count, block_to_free_p, p); |
| 2058 | block_to_free = nr; | 2060 | block_to_free = nr; |
| @@ -2089,7 +2091,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, | |||
| 2089 | struct buffer_head *parent_bh, | 2091 | struct buffer_head *parent_bh, |
| 2090 | __le32 *first, __le32 *last, int depth) | 2092 | __le32 *first, __le32 *last, int depth) |
| 2091 | { | 2093 | { |
| 2092 | unsigned long nr; | 2094 | ext3_fsblk_t nr; |
| 2093 | __le32 *p; | 2095 | __le32 *p; |
| 2094 | 2096 | ||
| 2095 | if (is_handle_aborted(handle)) | 2097 | if (is_handle_aborted(handle)) |
| @@ -2113,7 +2115,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, | |||
| 2113 | */ | 2115 | */ |
| 2114 | if (!bh) { | 2116 | if (!bh) { |
| 2115 | ext3_error(inode->i_sb, "ext3_free_branches", | 2117 | ext3_error(inode->i_sb, "ext3_free_branches", |
| 2116 | "Read failure, inode=%ld, block=%ld", | 2118 | "Read failure, inode=%lu, block="E3FSBLK, |
| 2117 | inode->i_ino, nr); | 2119 | inode->i_ino, nr); |
| 2118 | continue; | 2120 | continue; |
| 2119 | } | 2121 | } |
| @@ -2182,7 +2184,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, | |||
| 2182 | *p = 0; | 2184 | *p = 0; |
| 2183 | BUFFER_TRACE(parent_bh, | 2185 | BUFFER_TRACE(parent_bh, |
| 2184 | "call ext3_journal_dirty_metadata"); | 2186 | "call ext3_journal_dirty_metadata"); |
| 2185 | ext3_journal_dirty_metadata(handle, | 2187 | ext3_journal_dirty_metadata(handle, |
| 2186 | parent_bh); | 2188 | parent_bh); |
| 2187 | } | 2189 | } |
| 2188 | } | 2190 | } |
| @@ -2394,22 +2396,24 @@ out_stop: | |||
| 2394 | ext3_journal_stop(handle); | 2396 | ext3_journal_stop(handle); |
| 2395 | } | 2397 | } |
| 2396 | 2398 | ||
| 2397 | static unsigned long ext3_get_inode_block(struct super_block *sb, | 2399 | static ext3_fsblk_t ext3_get_inode_block(struct super_block *sb, |
| 2398 | unsigned long ino, struct ext3_iloc *iloc) | 2400 | unsigned long ino, struct ext3_iloc *iloc) |
| 2399 | { | 2401 | { |
| 2400 | unsigned long desc, group_desc, block_group; | 2402 | unsigned long desc, group_desc, block_group; |
| 2401 | unsigned long offset, block; | 2403 | unsigned long offset; |
| 2404 | ext3_fsblk_t block; | ||
| 2402 | struct buffer_head *bh; | 2405 | struct buffer_head *bh; |
| 2403 | struct ext3_group_desc * gdp; | 2406 | struct ext3_group_desc * gdp; |
| 2404 | 2407 | ||
| 2405 | 2408 | if (!ext3_valid_inum(sb, ino)) { | |
| 2406 | if ((ino != EXT3_ROOT_INO && ino != EXT3_JOURNAL_INO && | 2409 | /* |
| 2407 | ino != EXT3_RESIZE_INO && ino < EXT3_FIRST_INO(sb)) || | 2410 | * This error is already checked for in namei.c unless we are |
| 2408 | ino > le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)) { | 2411 | * looking at an NFS filehandle, in which case no error |
| 2409 | ext3_error(sb, "ext3_get_inode_block", | 2412 | * report is needed |
| 2410 | "bad inode number: %lu", ino); | 2413 | */ |
| 2411 | return 0; | 2414 | return 0; |
| 2412 | } | 2415 | } |
| 2416 | |||
| 2413 | block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); | 2417 | block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); |
| 2414 | if (block_group >= EXT3_SB(sb)->s_groups_count) { | 2418 | if (block_group >= EXT3_SB(sb)->s_groups_count) { |
| 2415 | ext3_error(sb,"ext3_get_inode_block","group >= groups count"); | 2419 | ext3_error(sb,"ext3_get_inode_block","group >= groups count"); |
| @@ -2448,7 +2452,7 @@ static unsigned long ext3_get_inode_block(struct super_block *sb, | |||
| 2448 | static int __ext3_get_inode_loc(struct inode *inode, | 2452 | static int __ext3_get_inode_loc(struct inode *inode, |
| 2449 | struct ext3_iloc *iloc, int in_mem) | 2453 | struct ext3_iloc *iloc, int in_mem) |
| 2450 | { | 2454 | { |
| 2451 | unsigned long block; | 2455 | ext3_fsblk_t block; |
| 2452 | struct buffer_head *bh; | 2456 | struct buffer_head *bh; |
| 2453 | 2457 | ||
| 2454 | block = ext3_get_inode_block(inode->i_sb, inode->i_ino, iloc); | 2458 | block = ext3_get_inode_block(inode->i_sb, inode->i_ino, iloc); |
| @@ -2459,7 +2463,8 @@ static int __ext3_get_inode_loc(struct inode *inode, | |||
| 2459 | if (!bh) { | 2463 | if (!bh) { |
| 2460 | ext3_error (inode->i_sb, "ext3_get_inode_loc", | 2464 | ext3_error (inode->i_sb, "ext3_get_inode_loc", |
| 2461 | "unable to read inode block - " | 2465 | "unable to read inode block - " |
| 2462 | "inode=%lu, block=%lu", inode->i_ino, block); | 2466 | "inode=%lu, block="E3FSBLK, |
| 2467 | inode->i_ino, block); | ||
| 2463 | return -EIO; | 2468 | return -EIO; |
| 2464 | } | 2469 | } |
| 2465 | if (!buffer_uptodate(bh)) { | 2470 | if (!buffer_uptodate(bh)) { |
| @@ -2540,7 +2545,7 @@ make_io: | |||
| 2540 | if (!buffer_uptodate(bh)) { | 2545 | if (!buffer_uptodate(bh)) { |
| 2541 | ext3_error(inode->i_sb, "ext3_get_inode_loc", | 2546 | ext3_error(inode->i_sb, "ext3_get_inode_loc", |
| 2542 | "unable to read inode block - " | 2547 | "unable to read inode block - " |
| 2543 | "inode=%lu, block=%lu", | 2548 | "inode=%lu, block="E3FSBLK, |
| 2544 | inode->i_ino, block); | 2549 | inode->i_ino, block); |
| 2545 | brelse(bh); | 2550 | brelse(bh); |
| 2546 | return -EIO; | 2551 | return -EIO; |
| @@ -2627,9 +2632,6 @@ void ext3_read_inode(struct inode * inode) | |||
| 2627 | * recovery code: that's fine, we're about to complete | 2632 | * recovery code: that's fine, we're about to complete |
| 2628 | * the process of deleting those. */ | 2633 | * the process of deleting those. */ |
| 2629 | } | 2634 | } |
| 2630 | inode->i_blksize = PAGE_SIZE; /* This is the optimal IO size | ||
| 2631 | * (for stat), not the fs block | ||
| 2632 | * size */ | ||
| 2633 | inode->i_blocks = le32_to_cpu(raw_inode->i_blocks); | 2635 | inode->i_blocks = le32_to_cpu(raw_inode->i_blocks); |
| 2634 | ei->i_flags = le32_to_cpu(raw_inode->i_flags); | 2636 | ei->i_flags = le32_to_cpu(raw_inode->i_flags); |
| 2635 | #ifdef EXT3_FRAGMENTS | 2637 | #ifdef EXT3_FRAGMENTS |
| @@ -2699,7 +2701,7 @@ void ext3_read_inode(struct inode * inode) | |||
| 2699 | if (raw_inode->i_block[0]) | 2701 | if (raw_inode->i_block[0]) |
| 2700 | init_special_inode(inode, inode->i_mode, | 2702 | init_special_inode(inode, inode->i_mode, |
| 2701 | old_decode_dev(le32_to_cpu(raw_inode->i_block[0]))); | 2703 | old_decode_dev(le32_to_cpu(raw_inode->i_block[0]))); |
| 2702 | else | 2704 | else |
| 2703 | init_special_inode(inode, inode->i_mode, | 2705 | init_special_inode(inode, inode->i_mode, |
| 2704 | new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); | 2706 | new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); |
| 2705 | } | 2707 | } |
| @@ -2719,8 +2721,8 @@ bad_inode: | |||
| 2719 | * | 2721 | * |
| 2720 | * The caller must have write access to iloc->bh. | 2722 | * The caller must have write access to iloc->bh. |
| 2721 | */ | 2723 | */ |
| 2722 | static int ext3_do_update_inode(handle_t *handle, | 2724 | static int ext3_do_update_inode(handle_t *handle, |
| 2723 | struct inode *inode, | 2725 | struct inode *inode, |
| 2724 | struct ext3_iloc *iloc) | 2726 | struct ext3_iloc *iloc) |
| 2725 | { | 2727 | { |
| 2726 | struct ext3_inode *raw_inode = ext3_raw_inode(iloc); | 2728 | struct ext3_inode *raw_inode = ext3_raw_inode(iloc); |
| @@ -2895,7 +2897,7 @@ int ext3_write_inode(struct inode *inode, int wait) | |||
| 2895 | * commit will leave the blocks being flushed in an unused state on | 2897 | * commit will leave the blocks being flushed in an unused state on |
| 2896 | * disk. (On recovery, the inode will get truncated and the blocks will | 2898 | * disk. (On recovery, the inode will get truncated and the blocks will |
| 2897 | * be freed, so we have a strong guarantee that no future commit will | 2899 | * be freed, so we have a strong guarantee that no future commit will |
| 2898 | * leave these blocks visible to the user.) | 2900 | * leave these blocks visible to the user.) |
| 2899 | * | 2901 | * |
| 2900 | * Called with inode->sem down. | 2902 | * Called with inode->sem down. |
| 2901 | */ | 2903 | */ |
| @@ -3038,13 +3040,13 @@ int ext3_mark_iloc_dirty(handle_t *handle, | |||
| 3038 | return err; | 3040 | return err; |
| 3039 | } | 3041 | } |
| 3040 | 3042 | ||
| 3041 | /* | 3043 | /* |
| 3042 | * On success, We end up with an outstanding reference count against | 3044 | * On success, We end up with an outstanding reference count against |
| 3043 | * iloc->bh. This _must_ be cleaned up later. | 3045 | * iloc->bh. This _must_ be cleaned up later. |
| 3044 | */ | 3046 | */ |
| 3045 | 3047 | ||
| 3046 | int | 3048 | int |
| 3047 | ext3_reserve_inode_write(handle_t *handle, struct inode *inode, | 3049 | ext3_reserve_inode_write(handle_t *handle, struct inode *inode, |
| 3048 | struct ext3_iloc *iloc) | 3050 | struct ext3_iloc *iloc) |
| 3049 | { | 3051 | { |
| 3050 | int err = 0; | 3052 | int err = 0; |
| @@ -3134,7 +3136,7 @@ out: | |||
| 3134 | } | 3136 | } |
| 3135 | 3137 | ||
| 3136 | #if 0 | 3138 | #if 0 |
| 3137 | /* | 3139 | /* |
| 3138 | * Bind an inode's backing buffer_head into this transaction, to prevent | 3140 | * Bind an inode's backing buffer_head into this transaction, to prevent |
| 3139 | * it from being flushed to disk early. Unlike | 3141 | * it from being flushed to disk early. Unlike |
| 3140 | * ext3_reserve_inode_write, this leaves behind no bh reference and | 3142 | * ext3_reserve_inode_write, this leaves behind no bh reference and |
| @@ -3152,7 +3154,7 @@ static int ext3_pin_inode(handle_t *handle, struct inode *inode) | |||
| 3152 | BUFFER_TRACE(iloc.bh, "get_write_access"); | 3154 | BUFFER_TRACE(iloc.bh, "get_write_access"); |
| 3153 | err = journal_get_write_access(handle, iloc.bh); | 3155 | err = journal_get_write_access(handle, iloc.bh); |
| 3154 | if (!err) | 3156 | if (!err) |
| 3155 | err = ext3_journal_dirty_metadata(handle, | 3157 | err = ext3_journal_dirty_metadata(handle, |
| 3156 | iloc.bh); | 3158 | iloc.bh); |
| 3157 | brelse(iloc.bh); | 3159 | brelse(iloc.bh); |
| 3158 | } | 3160 | } |
