diff options
| author | James Morris <jmorris@namei.org> | 2011-04-19 07:32:41 -0400 |
|---|---|---|
| committer | James Morris <jmorris@namei.org> | 2011-04-19 07:32:41 -0400 |
| commit | d4ab4e6a23f805abb8fc3cc34525eec3788aeca1 (patch) | |
| tree | eefd82c155bc27469a85667d759cd90facf4a6e3 /fs/ext4 | |
| parent | c0fa797ae6cd02ff87c0bfe0d509368a3b45640e (diff) | |
| parent | 96fd2d57b8252e16dfacf8941f7a74a6119197f5 (diff) | |
Merge branch 'master'; commit 'v2.6.39-rc3' into next
Diffstat (limited to 'fs/ext4')
| -rw-r--r-- | fs/ext4/balloc.c | 2 | ||||
| -rw-r--r-- | fs/ext4/ext4_jbd2.h | 4 | ||||
| -rw-r--r-- | fs/ext4/extents.c | 10 | ||||
| -rw-r--r-- | fs/ext4/fsync.c | 19 | ||||
| -rw-r--r-- | fs/ext4/inode.c | 55 | ||||
| -rw-r--r-- | fs/ext4/mballoc.c | 2 | ||||
| -rw-r--r-- | fs/ext4/migrate.c | 2 | ||||
| -rw-r--r-- | fs/ext4/super.c | 78 |
8 files changed, 118 insertions, 54 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index 97b970e7dd13..1c67139ad4b4 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
| @@ -547,7 +547,7 @@ int ext4_claim_free_blocks(struct ext4_sb_info *sbi, | |||
| 547 | * | 547 | * |
| 548 | * ext4_should_retry_alloc() is called when ENOSPC is returned, and if | 548 | * ext4_should_retry_alloc() is called when ENOSPC is returned, and if |
| 549 | * it is profitable to retry the operation, this function will wait | 549 | * it is profitable to retry the operation, this function will wait |
| 550 | * for the current or commiting transaction to complete, and then | 550 | * for the current or committing transaction to complete, and then |
| 551 | * return TRUE. | 551 | * return TRUE. |
| 552 | * | 552 | * |
| 553 | * if the total number of retries exceed three times, return FALSE. | 553 | * if the total number of retries exceed three times, return FALSE. |
diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index e25e99bf7ee1..d0f53538a57f 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h | |||
| @@ -86,8 +86,8 @@ | |||
| 86 | 86 | ||
| 87 | #ifdef CONFIG_QUOTA | 87 | #ifdef CONFIG_QUOTA |
| 88 | /* Amount of blocks needed for quota update - we know that the structure was | 88 | /* Amount of blocks needed for quota update - we know that the structure was |
| 89 | * allocated so we need to update only inode+data */ | 89 | * allocated so we need to update only data block */ |
| 90 | #define EXT4_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0) | 90 | #define EXT4_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 1 : 0) |
| 91 | /* Amount of blocks needed for quota insert/delete - we do some block writes | 91 | /* Amount of blocks needed for quota insert/delete - we do some block writes |
| 92 | * but inode, sb and group updates are done only once */ | 92 | * but inode, sb and group updates are done only once */ |
| 93 | #define EXT4_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\ | 93 | #define EXT4_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\ |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index dd2cb5076ff9..4890d6f3ad15 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
| @@ -1729,7 +1729,7 @@ repeat: | |||
| 1729 | BUG_ON(npath->p_depth != path->p_depth); | 1729 | BUG_ON(npath->p_depth != path->p_depth); |
| 1730 | eh = npath[depth].p_hdr; | 1730 | eh = npath[depth].p_hdr; |
| 1731 | if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max)) { | 1731 | if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max)) { |
| 1732 | ext_debug("next leaf isnt full(%d)\n", | 1732 | ext_debug("next leaf isn't full(%d)\n", |
| 1733 | le16_to_cpu(eh->eh_entries)); | 1733 | le16_to_cpu(eh->eh_entries)); |
| 1734 | path = npath; | 1734 | path = npath; |
| 1735 | goto repeat; | 1735 | goto repeat; |
| @@ -2533,7 +2533,7 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) | |||
| 2533 | /* | 2533 | /* |
| 2534 | * This function is called by ext4_ext_map_blocks() if someone tries to write | 2534 | * This function is called by ext4_ext_map_blocks() if someone tries to write |
| 2535 | * to an uninitialized extent. It may result in splitting the uninitialized | 2535 | * to an uninitialized extent. It may result in splitting the uninitialized |
| 2536 | * extent into multiple extents (upto three - one initialized and two | 2536 | * extent into multiple extents (up to three - one initialized and two |
| 2537 | * uninitialized). | 2537 | * uninitialized). |
| 2538 | * There are three possibilities: | 2538 | * There are three possibilities: |
| 2539 | * a> There is no split required: Entire extent should be initialized | 2539 | * a> There is no split required: Entire extent should be initialized |
| @@ -3174,7 +3174,7 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | |||
| 3174 | path, flags); | 3174 | path, flags); |
| 3175 | /* | 3175 | /* |
| 3176 | * Flag the inode(non aio case) or end_io struct (aio case) | 3176 | * Flag the inode(non aio case) or end_io struct (aio case) |
| 3177 | * that this IO needs to convertion to written when IO is | 3177 | * that this IO needs to conversion to written when IO is |
| 3178 | * completed | 3178 | * completed |
| 3179 | */ | 3179 | */ |
| 3180 | if (io && !(io->flag & EXT4_IO_END_UNWRITTEN)) { | 3180 | if (io && !(io->flag & EXT4_IO_END_UNWRITTEN)) { |
| @@ -3460,10 +3460,10 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, | |||
| 3460 | ext4_ext_mark_uninitialized(&newex); | 3460 | ext4_ext_mark_uninitialized(&newex); |
| 3461 | /* | 3461 | /* |
| 3462 | * io_end structure was created for every IO write to an | 3462 | * io_end structure was created for every IO write to an |
| 3463 | * uninitialized extent. To avoid unecessary conversion, | 3463 | * uninitialized extent. To avoid unnecessary conversion, |
| 3464 | * here we flag the IO that really needs the conversion. | 3464 | * here we flag the IO that really needs the conversion. |
| 3465 | * For non asycn direct IO case, flag the inode state | 3465 | * For non asycn direct IO case, flag the inode state |
| 3466 | * that we need to perform convertion when IO is done. | 3466 | * that we need to perform conversion when IO is done. |
| 3467 | */ | 3467 | */ |
| 3468 | if ((flags & EXT4_GET_BLOCKS_PRE_IO)) { | 3468 | if ((flags & EXT4_GET_BLOCKS_PRE_IO)) { |
| 3469 | if (io && !(io->flag & EXT4_IO_END_UNWRITTEN)) { | 3469 | if (io && !(io->flag & EXT4_IO_END_UNWRITTEN)) { |
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index 7f74019d6d77..e9473cbe80df 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c | |||
| @@ -101,7 +101,7 @@ extern int ext4_flush_completed_IO(struct inode *inode) | |||
| 101 | * to the work-to-be schedule is freed. | 101 | * to the work-to-be schedule is freed. |
| 102 | * | 102 | * |
| 103 | * Thus we need to keep the io structure still valid here after | 103 | * Thus we need to keep the io structure still valid here after |
| 104 | * convertion finished. The io structure has a flag to | 104 | * conversion finished. The io structure has a flag to |
| 105 | * avoid double converting from both fsync and background work | 105 | * avoid double converting from both fsync and background work |
| 106 | * queue work. | 106 | * queue work. |
| 107 | */ | 107 | */ |
| @@ -125,9 +125,11 @@ extern int ext4_flush_completed_IO(struct inode *inode) | |||
| 125 | * the parent directory's parent as well, and so on recursively, if | 125 | * the parent directory's parent as well, and so on recursively, if |
| 126 | * they are also freshly created. | 126 | * they are also freshly created. |
| 127 | */ | 127 | */ |
| 128 | static void ext4_sync_parent(struct inode *inode) | 128 | static int ext4_sync_parent(struct inode *inode) |
| 129 | { | 129 | { |
| 130 | struct writeback_control wbc; | ||
| 130 | struct dentry *dentry = NULL; | 131 | struct dentry *dentry = NULL; |
| 132 | int ret = 0; | ||
| 131 | 133 | ||
| 132 | while (inode && ext4_test_inode_state(inode, EXT4_STATE_NEWENTRY)) { | 134 | while (inode && ext4_test_inode_state(inode, EXT4_STATE_NEWENTRY)) { |
| 133 | ext4_clear_inode_state(inode, EXT4_STATE_NEWENTRY); | 135 | ext4_clear_inode_state(inode, EXT4_STATE_NEWENTRY); |
| @@ -136,8 +138,17 @@ static void ext4_sync_parent(struct inode *inode) | |||
| 136 | if (!dentry || !dentry->d_parent || !dentry->d_parent->d_inode) | 138 | if (!dentry || !dentry->d_parent || !dentry->d_parent->d_inode) |
| 137 | break; | 139 | break; |
| 138 | inode = dentry->d_parent->d_inode; | 140 | inode = dentry->d_parent->d_inode; |
| 139 | sync_mapping_buffers(inode->i_mapping); | 141 | ret = sync_mapping_buffers(inode->i_mapping); |
| 142 | if (ret) | ||
| 143 | break; | ||
| 144 | memset(&wbc, 0, sizeof(wbc)); | ||
| 145 | wbc.sync_mode = WB_SYNC_ALL; | ||
| 146 | wbc.nr_to_write = 0; /* only write out the inode */ | ||
| 147 | ret = sync_inode(inode, &wbc); | ||
| 148 | if (ret) | ||
| 149 | break; | ||
| 140 | } | 150 | } |
| 151 | return ret; | ||
| 141 | } | 152 | } |
| 142 | 153 | ||
| 143 | /* | 154 | /* |
| @@ -176,7 +187,7 @@ int ext4_sync_file(struct file *file, int datasync) | |||
| 176 | if (!journal) { | 187 | if (!journal) { |
| 177 | ret = generic_file_fsync(file, datasync); | 188 | ret = generic_file_fsync(file, datasync); |
| 178 | if (!ret && !list_empty(&inode->i_dentry)) | 189 | if (!ret && !list_empty(&inode->i_dentry)) |
| 179 | ext4_sync_parent(inode); | 190 | ret = ext4_sync_parent(inode); |
| 180 | goto out; | 191 | goto out; |
| 181 | } | 192 | } |
| 182 | 193 | ||
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1a86282b9024..f2fa5e8a582c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
| @@ -2502,6 +2502,7 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, | |||
| 2502 | * for partial write. | 2502 | * for partial write. |
| 2503 | */ | 2503 | */ |
| 2504 | set_buffer_new(bh); | 2504 | set_buffer_new(bh); |
| 2505 | set_buffer_mapped(bh); | ||
| 2505 | } | 2506 | } |
| 2506 | return 0; | 2507 | return 0; |
| 2507 | } | 2508 | } |
| @@ -2588,7 +2589,7 @@ static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate); | |||
| 2588 | * because we should have holes filled from ext4_page_mkwrite(). We even don't | 2589 | * because we should have holes filled from ext4_page_mkwrite(). We even don't |
| 2589 | * need to file the inode to the transaction's list in ordered mode because if | 2590 | * need to file the inode to the transaction's list in ordered mode because if |
| 2590 | * we are writing back data added by write(), the inode is already there and if | 2591 | * we are writing back data added by write(), the inode is already there and if |
| 2591 | * we are writing back data modified via mmap(), noone guarantees in which | 2592 | * we are writing back data modified via mmap(), no one guarantees in which |
| 2592 | * transaction the data will hit the disk. In case we are journaling data, we | 2593 | * transaction the data will hit the disk. In case we are journaling data, we |
| 2593 | * cannot start transaction directly because transaction start ranks above page | 2594 | * cannot start transaction directly because transaction start ranks above page |
| 2594 | * lock so we have to do some magic. | 2595 | * lock so we have to do some magic. |
| @@ -2690,7 +2691,7 @@ static int ext4_writepage(struct page *page, | |||
| 2690 | 2691 | ||
| 2691 | /* | 2692 | /* |
| 2692 | * This is called via ext4_da_writepages() to | 2693 | * This is called via ext4_da_writepages() to |
| 2693 | * calulate the total number of credits to reserve to fit | 2694 | * calculate the total number of credits to reserve to fit |
| 2694 | * a single extent allocation into a single transaction, | 2695 | * a single extent allocation into a single transaction, |
| 2695 | * ext4_da_writpeages() will loop calling this before | 2696 | * ext4_da_writpeages() will loop calling this before |
| 2696 | * the block allocation. | 2697 | * the block allocation. |
| @@ -3304,7 +3305,7 @@ int ext4_alloc_da_blocks(struct inode *inode) | |||
| 3304 | * the pages by calling redirty_page_for_writepage() but that | 3305 | * the pages by calling redirty_page_for_writepage() but that |
| 3305 | * would be ugly in the extreme. So instead we would need to | 3306 | * would be ugly in the extreme. So instead we would need to |
| 3306 | * replicate parts of the code in the above functions, | 3307 | * replicate parts of the code in the above functions, |
| 3307 | * simplifying them becuase we wouldn't actually intend to | 3308 | * simplifying them because we wouldn't actually intend to |
| 3308 | * write out the pages, but rather only collect contiguous | 3309 | * write out the pages, but rather only collect contiguous |
| 3309 | * logical block extents, call the multi-block allocator, and | 3310 | * logical block extents, call the multi-block allocator, and |
| 3310 | * then update the buffer heads with the block allocations. | 3311 | * then update the buffer heads with the block allocations. |
| @@ -3694,7 +3695,7 @@ retry: | |||
| 3694 | * | 3695 | * |
| 3695 | * The unwrritten extents will be converted to written when DIO is completed. | 3696 | * The unwrritten extents will be converted to written when DIO is completed. |
| 3696 | * For async direct IO, since the IO may still pending when return, we | 3697 | * For async direct IO, since the IO may still pending when return, we |
| 3697 | * set up an end_io call back function, which will do the convertion | 3698 | * set up an end_io call back function, which will do the conversion |
| 3698 | * when async direct IO completed. | 3699 | * when async direct IO completed. |
| 3699 | * | 3700 | * |
| 3700 | * If the O_DIRECT write will extend the file then add this inode to the | 3701 | * If the O_DIRECT write will extend the file then add this inode to the |
| @@ -3717,7 +3718,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
| 3717 | * We could direct write to holes and fallocate. | 3718 | * We could direct write to holes and fallocate. |
| 3718 | * | 3719 | * |
| 3719 | * Allocated blocks to fill the hole are marked as uninitialized | 3720 | * Allocated blocks to fill the hole are marked as uninitialized |
| 3720 | * to prevent paralel buffered read to expose the stale data | 3721 | * to prevent parallel buffered read to expose the stale data |
| 3721 | * before DIO complete the data IO. | 3722 | * before DIO complete the data IO. |
| 3722 | * | 3723 | * |
| 3723 | * As to previously fallocated extents, ext4 get_block | 3724 | * As to previously fallocated extents, ext4 get_block |
| @@ -3778,7 +3779,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, | |||
| 3778 | int err; | 3779 | int err; |
| 3779 | /* | 3780 | /* |
| 3780 | * for non AIO case, since the IO is already | 3781 | * for non AIO case, since the IO is already |
| 3781 | * completed, we could do the convertion right here | 3782 | * completed, we could do the conversion right here |
| 3782 | */ | 3783 | */ |
| 3783 | err = ext4_convert_unwritten_extents(inode, | 3784 | err = ext4_convert_unwritten_extents(inode, |
| 3784 | offset, ret); | 3785 | offset, ret); |
| @@ -4025,7 +4026,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q) | |||
| 4025 | * | 4026 | * |
| 4026 | * When we do truncate() we may have to clean the ends of several | 4027 | * When we do truncate() we may have to clean the ends of several |
| 4027 | * indirect blocks but leave the blocks themselves alive. Block is | 4028 | * indirect blocks but leave the blocks themselves alive. Block is |
| 4028 | * partially truncated if some data below the new i_size is refered | 4029 | * partially truncated if some data below the new i_size is referred |
| 4029 | * from it (and it is on the path to the first completely truncated | 4030 | * from it (and it is on the path to the first completely truncated |
| 4030 | * data block, indeed). We have to free the top of that path along | 4031 | * data block, indeed). We have to free the top of that path along |
| 4031 | * with everything to the right of the path. Since no allocation | 4032 | * with everything to the right of the path. Since no allocation |
| @@ -4169,7 +4170,7 @@ out_err: | |||
| 4169 | * @first: array of block numbers | 4170 | * @first: array of block numbers |
| 4170 | * @last: points immediately past the end of array | 4171 | * @last: points immediately past the end of array |
| 4171 | * | 4172 | * |
| 4172 | * We are freeing all blocks refered from that array (numbers are stored as | 4173 | * We are freeing all blocks referred from that array (numbers are stored as |
| 4173 | * little-endian 32-bit) and updating @inode->i_blocks appropriately. | 4174 | * little-endian 32-bit) and updating @inode->i_blocks appropriately. |
| 4174 | * | 4175 | * |
| 4175 | * We accumulate contiguous runs of blocks to free. Conveniently, if these | 4176 | * We accumulate contiguous runs of blocks to free. Conveniently, if these |
| @@ -4261,7 +4262,7 @@ static void ext4_free_data(handle_t *handle, struct inode *inode, | |||
| 4261 | * @last: pointer immediately past the end of array | 4262 | * @last: pointer immediately past the end of array |
| 4262 | * @depth: depth of the branches to free | 4263 | * @depth: depth of the branches to free |
| 4263 | * | 4264 | * |
| 4264 | * We are freeing all blocks refered from these branches (numbers are | 4265 | * We are freeing all blocks referred from these branches (numbers are |
| 4265 | * stored as little-endian 32-bit) and updating @inode->i_blocks | 4266 | * stored as little-endian 32-bit) and updating @inode->i_blocks |
| 4266 | * appropriately. | 4267 | * appropriately. |
| 4267 | */ | 4268 | */ |
| @@ -4429,8 +4430,8 @@ void ext4_truncate(struct inode *inode) | |||
| 4429 | Indirect chain[4]; | 4430 | Indirect chain[4]; |
| 4430 | Indirect *partial; | 4431 | Indirect *partial; |
| 4431 | __le32 nr = 0; | 4432 | __le32 nr = 0; |
| 4432 | int n; | 4433 | int n = 0; |
| 4433 | ext4_lblk_t last_block; | 4434 | ext4_lblk_t last_block, max_block; |
| 4434 | unsigned blocksize = inode->i_sb->s_blocksize; | 4435 | unsigned blocksize = inode->i_sb->s_blocksize; |
| 4435 | 4436 | ||
| 4436 | trace_ext4_truncate_enter(inode); | 4437 | trace_ext4_truncate_enter(inode); |
| @@ -4455,14 +4456,18 @@ void ext4_truncate(struct inode *inode) | |||
| 4455 | 4456 | ||
| 4456 | last_block = (inode->i_size + blocksize-1) | 4457 | last_block = (inode->i_size + blocksize-1) |
| 4457 | >> EXT4_BLOCK_SIZE_BITS(inode->i_sb); | 4458 | >> EXT4_BLOCK_SIZE_BITS(inode->i_sb); |
| 4459 | max_block = (EXT4_SB(inode->i_sb)->s_bitmap_maxbytes + blocksize-1) | ||
| 4460 | >> EXT4_BLOCK_SIZE_BITS(inode->i_sb); | ||
| 4458 | 4461 | ||
| 4459 | if (inode->i_size & (blocksize - 1)) | 4462 | if (inode->i_size & (blocksize - 1)) |
| 4460 | if (ext4_block_truncate_page(handle, mapping, inode->i_size)) | 4463 | if (ext4_block_truncate_page(handle, mapping, inode->i_size)) |
| 4461 | goto out_stop; | 4464 | goto out_stop; |
| 4462 | 4465 | ||
| 4463 | n = ext4_block_to_path(inode, last_block, offsets, NULL); | 4466 | if (last_block != max_block) { |
| 4464 | if (n == 0) | 4467 | n = ext4_block_to_path(inode, last_block, offsets, NULL); |
| 4465 | goto out_stop; /* error */ | 4468 | if (n == 0) |
| 4469 | goto out_stop; /* error */ | ||
| 4470 | } | ||
| 4466 | 4471 | ||
| 4467 | /* | 4472 | /* |
| 4468 | * OK. This truncate is going to happen. We add the inode to the | 4473 | * OK. This truncate is going to happen. We add the inode to the |
| @@ -4493,7 +4498,13 @@ void ext4_truncate(struct inode *inode) | |||
| 4493 | */ | 4498 | */ |
| 4494 | ei->i_disksize = inode->i_size; | 4499 | ei->i_disksize = inode->i_size; |
| 4495 | 4500 | ||
| 4496 | if (n == 1) { /* direct blocks */ | 4501 | if (last_block == max_block) { |
| 4502 | /* | ||
| 4503 | * It is unnecessary to free any data blocks if last_block is | ||
| 4504 | * equal to the indirect block limit. | ||
| 4505 | */ | ||
| 4506 | goto out_unlock; | ||
| 4507 | } else if (n == 1) { /* direct blocks */ | ||
| 4497 | ext4_free_data(handle, inode, NULL, i_data+offsets[0], | 4508 | ext4_free_data(handle, inode, NULL, i_data+offsets[0], |
| 4498 | i_data + EXT4_NDIR_BLOCKS); | 4509 | i_data + EXT4_NDIR_BLOCKS); |
| 4499 | goto do_indirects; | 4510 | goto do_indirects; |
| @@ -4553,6 +4564,7 @@ do_indirects: | |||
| 4553 | ; | 4564 | ; |
| 4554 | } | 4565 | } |
| 4555 | 4566 | ||
| 4567 | out_unlock: | ||
| 4556 | up_write(&ei->i_data_sem); | 4568 | up_write(&ei->i_data_sem); |
| 4557 | inode->i_mtime = inode->i_ctime = ext4_current_time(inode); | 4569 | inode->i_mtime = inode->i_ctime = ext4_current_time(inode); |
| 4558 | ext4_mark_inode_dirty(handle, inode); | 4570 | ext4_mark_inode_dirty(handle, inode); |
| @@ -5398,13 +5410,12 @@ static int ext4_indirect_trans_blocks(struct inode *inode, int nrblocks, | |||
| 5398 | /* if nrblocks are contiguous */ | 5410 | /* if nrblocks are contiguous */ |
| 5399 | if (chunk) { | 5411 | if (chunk) { |
| 5400 | /* | 5412 | /* |
| 5401 | * With N contiguous data blocks, it need at most | 5413 | * With N contiguous data blocks, we need at most |
| 5402 | * N/EXT4_ADDR_PER_BLOCK(inode->i_sb) indirect blocks | 5414 | * N/EXT4_ADDR_PER_BLOCK(inode->i_sb) + 1 indirect blocks, |
| 5403 | * 2 dindirect blocks | 5415 | * 2 dindirect blocks, and 1 tindirect block |
| 5404 | * 1 tindirect block | ||
| 5405 | */ | 5416 | */ |
| 5406 | indirects = nrblocks / EXT4_ADDR_PER_BLOCK(inode->i_sb); | 5417 | return DIV_ROUND_UP(nrblocks, |
| 5407 | return indirects + 3; | 5418 | EXT4_ADDR_PER_BLOCK(inode->i_sb)) + 4; |
| 5408 | } | 5419 | } |
| 5409 | /* | 5420 | /* |
| 5410 | * if nrblocks are not contiguous, worse case, each block touch | 5421 | * if nrblocks are not contiguous, worse case, each block touch |
| @@ -5478,7 +5489,7 @@ static int ext4_meta_trans_blocks(struct inode *inode, int nrblocks, int chunk) | |||
| 5478 | } | 5489 | } |
| 5479 | 5490 | ||
| 5480 | /* | 5491 | /* |
| 5481 | * Calulate the total number of credits to reserve to fit | 5492 | * Calculate the total number of credits to reserve to fit |
| 5482 | * the modification of a single pages into a single transaction, | 5493 | * the modification of a single pages into a single transaction, |
| 5483 | * which may include multiple chunks of block allocations. | 5494 | * which may include multiple chunks of block allocations. |
| 5484 | * | 5495 | * |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index a5837a837a8b..d8a16eecf1d5 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
| @@ -92,7 +92,7 @@ | |||
| 92 | * between CPUs. It is possible to get scheduled at this point. | 92 | * between CPUs. It is possible to get scheduled at this point. |
| 93 | * | 93 | * |
| 94 | * The locality group prealloc space is used looking at whether we have | 94 | * The locality group prealloc space is used looking at whether we have |
| 95 | * enough free space (pa_free) withing the prealloc space. | 95 | * enough free space (pa_free) within the prealloc space. |
| 96 | * | 96 | * |
| 97 | * If we can't allocate blocks via inode prealloc or/and locality group | 97 | * If we can't allocate blocks via inode prealloc or/and locality group |
| 98 | * prealloc then we look at the buddy cache. The buddy cache is represented | 98 | * prealloc then we look at the buddy cache. The buddy cache is represented |
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index d1bafa57f483..92816b4e0f16 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c | |||
| @@ -517,7 +517,7 @@ int ext4_ext_migrate(struct inode *inode) | |||
| 517 | * start with one credit accounted for | 517 | * start with one credit accounted for |
| 518 | * superblock modification. | 518 | * superblock modification. |
| 519 | * | 519 | * |
| 520 | * For the tmp_inode we already have commited the | 520 | * For the tmp_inode we already have committed the |
| 521 | * trascation that created the inode. Later as and | 521 | * trascation that created the inode. Later as and |
| 522 | * when we add extents we extent the journal | 522 | * when we add extents we extent the journal |
| 523 | */ | 523 | */ |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 22546ad7f0ae..8553dfb310af 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
| @@ -242,27 +242,44 @@ static void ext4_put_nojournal(handle_t *handle) | |||
| 242 | * journal_end calls result in the superblock being marked dirty, so | 242 | * journal_end calls result in the superblock being marked dirty, so |
| 243 | * that sync() will call the filesystem's write_super callback if | 243 | * that sync() will call the filesystem's write_super callback if |
| 244 | * appropriate. | 244 | * appropriate. |
| 245 | * | ||
| 246 | * To avoid j_barrier hold in userspace when a user calls freeze(), | ||
| 247 | * ext4 prevents a new handle from being started by s_frozen, which | ||
| 248 | * is in an upper layer. | ||
| 245 | */ | 249 | */ |
| 246 | handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) | 250 | handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) |
| 247 | { | 251 | { |
| 248 | journal_t *journal; | 252 | journal_t *journal; |
| 253 | handle_t *handle; | ||
| 249 | 254 | ||
| 250 | if (sb->s_flags & MS_RDONLY) | 255 | if (sb->s_flags & MS_RDONLY) |
| 251 | return ERR_PTR(-EROFS); | 256 | return ERR_PTR(-EROFS); |
| 252 | 257 | ||
| 253 | vfs_check_frozen(sb, SB_FREEZE_TRANS); | ||
| 254 | /* Special case here: if the journal has aborted behind our | ||
| 255 | * backs (eg. EIO in the commit thread), then we still need to | ||
| 256 | * take the FS itself readonly cleanly. */ | ||
| 257 | journal = EXT4_SB(sb)->s_journal; | 258 | journal = EXT4_SB(sb)->s_journal; |
| 258 | if (journal) { | 259 | handle = ext4_journal_current_handle(); |
| 259 | if (is_journal_aborted(journal)) { | 260 | |
| 260 | ext4_abort(sb, "Detected aborted journal"); | 261 | /* |
| 261 | return ERR_PTR(-EROFS); | 262 | * If a handle has been started, it should be allowed to |
| 262 | } | 263 | * finish, otherwise deadlock could happen between freeze |
| 263 | return jbd2_journal_start(journal, nblocks); | 264 | * and others(e.g. truncate) due to the restart of the |
| 265 | * journal handle if the filesystem is forzen and active | ||
| 266 | * handles are not stopped. | ||
| 267 | */ | ||
| 268 | if (!handle) | ||
| 269 | vfs_check_frozen(sb, SB_FREEZE_TRANS); | ||
| 270 | |||
| 271 | if (!journal) | ||
| 272 | return ext4_get_nojournal(); | ||
| 273 | /* | ||
| 274 | * Special case here: if the journal has aborted behind our | ||
| 275 | * backs (eg. EIO in the commit thread), then we still need to | ||
| 276 | * take the FS itself readonly cleanly. | ||
| 277 | */ | ||
| 278 | if (is_journal_aborted(journal)) { | ||
| 279 | ext4_abort(sb, "Detected aborted journal"); | ||
| 280 | return ERR_PTR(-EROFS); | ||
| 264 | } | 281 | } |
| 265 | return ext4_get_nojournal(); | 282 | return jbd2_journal_start(journal, nblocks); |
| 266 | } | 283 | } |
| 267 | 284 | ||
| 268 | /* | 285 | /* |
| @@ -617,7 +634,7 @@ __acquires(bitlock) | |||
| 617 | * filesystem will have already been marked read/only and the | 634 | * filesystem will have already been marked read/only and the |
| 618 | * journal has been aborted. We return 1 as a hint to callers | 635 | * journal has been aborted. We return 1 as a hint to callers |
| 619 | * who might what to use the return value from | 636 | * who might what to use the return value from |
| 620 | * ext4_grp_locked_error() to distinguish beween the | 637 | * ext4_grp_locked_error() to distinguish between the |
| 621 | * ERRORS_CONT and ERRORS_RO case, and perhaps return more | 638 | * ERRORS_CONT and ERRORS_RO case, and perhaps return more |
| 622 | * aggressively from the ext4 function in question, with a | 639 | * aggressively from the ext4 function in question, with a |
| 623 | * more appropriate error code. | 640 | * more appropriate error code. |
| @@ -2975,6 +2992,12 @@ static int ext4_register_li_request(struct super_block *sb, | |||
| 2975 | mutex_unlock(&ext4_li_info->li_list_mtx); | 2992 | mutex_unlock(&ext4_li_info->li_list_mtx); |
| 2976 | 2993 | ||
| 2977 | sbi->s_li_request = elr; | 2994 | sbi->s_li_request = elr; |
| 2995 | /* | ||
| 2996 | * set elr to NULL here since it has been inserted to | ||
| 2997 | * the request_list and the removal and free of it is | ||
| 2998 | * handled by ext4_clear_request_list from now on. | ||
| 2999 | */ | ||
| 3000 | elr = NULL; | ||
| 2978 | 3001 | ||
| 2979 | if (!(ext4_li_info->li_state & EXT4_LAZYINIT_RUNNING)) { | 3002 | if (!(ext4_li_info->li_state & EXT4_LAZYINIT_RUNNING)) { |
| 2980 | ret = ext4_run_lazyinit_thread(); | 3003 | ret = ext4_run_lazyinit_thread(); |
| @@ -3385,6 +3408,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
| 3385 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); | 3408 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
| 3386 | spin_lock_init(&sbi->s_next_gen_lock); | 3409 | spin_lock_init(&sbi->s_next_gen_lock); |
| 3387 | 3410 | ||
| 3411 | init_timer(&sbi->s_err_report); | ||
| 3412 | sbi->s_err_report.function = print_daily_error_info; | ||
| 3413 | sbi->s_err_report.data = (unsigned long) sb; | ||
| 3414 | |||
| 3388 | err = percpu_counter_init(&sbi->s_freeblocks_counter, | 3415 | err = percpu_counter_init(&sbi->s_freeblocks_counter, |
| 3389 | ext4_count_free_blocks(sb)); | 3416 | ext4_count_free_blocks(sb)); |
| 3390 | if (!err) { | 3417 | if (!err) { |
| @@ -3646,9 +3673,6 @@ no_journal: | |||
| 3646 | "Opts: %s%s%s", descr, sbi->s_es->s_mount_opts, | 3673 | "Opts: %s%s%s", descr, sbi->s_es->s_mount_opts, |
| 3647 | *sbi->s_es->s_mount_opts ? "; " : "", orig_data); | 3674 | *sbi->s_es->s_mount_opts ? "; " : "", orig_data); |
| 3648 | 3675 | ||
| 3649 | init_timer(&sbi->s_err_report); | ||
| 3650 | sbi->s_err_report.function = print_daily_error_info; | ||
| 3651 | sbi->s_err_report.data = (unsigned long) sb; | ||
| 3652 | if (es->s_error_count) | 3676 | if (es->s_error_count) |
| 3653 | mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */ | 3677 | mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */ |
| 3654 | 3678 | ||
| @@ -3672,6 +3696,7 @@ failed_mount_wq: | |||
| 3672 | sbi->s_journal = NULL; | 3696 | sbi->s_journal = NULL; |
| 3673 | } | 3697 | } |
| 3674 | failed_mount3: | 3698 | failed_mount3: |
| 3699 | del_timer(&sbi->s_err_report); | ||
| 3675 | if (sbi->s_flex_groups) { | 3700 | if (sbi->s_flex_groups) { |
| 3676 | if (is_vmalloc_addr(sbi->s_flex_groups)) | 3701 | if (is_vmalloc_addr(sbi->s_flex_groups)) |
| 3677 | vfree(sbi->s_flex_groups); | 3702 | vfree(sbi->s_flex_groups); |
| @@ -4138,6 +4163,11 @@ static int ext4_sync_fs(struct super_block *sb, int wait) | |||
| 4138 | /* | 4163 | /* |
| 4139 | * LVM calls this function before a (read-only) snapshot is created. This | 4164 | * LVM calls this function before a (read-only) snapshot is created. This |
| 4140 | * gives us a chance to flush the journal completely and mark the fs clean. | 4165 | * gives us a chance to flush the journal completely and mark the fs clean. |
| 4166 | * | ||
| 4167 | * Note that only this function cannot bring a filesystem to be in a clean | ||
| 4168 | * state independently, because ext4 prevents a new handle from being started | ||
| 4169 | * by @sb->s_frozen, which stays in an upper layer. It thus needs help from | ||
| 4170 | * the upper layer. | ||
| 4141 | */ | 4171 | */ |
| 4142 | static int ext4_freeze(struct super_block *sb) | 4172 | static int ext4_freeze(struct super_block *sb) |
| 4143 | { | 4173 | { |
| @@ -4614,17 +4644,30 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id, | |||
| 4614 | 4644 | ||
| 4615 | static int ext4_quota_off(struct super_block *sb, int type) | 4645 | static int ext4_quota_off(struct super_block *sb, int type) |
| 4616 | { | 4646 | { |
| 4647 | struct inode *inode = sb_dqopt(sb)->files[type]; | ||
| 4648 | handle_t *handle; | ||
| 4649 | |||
| 4617 | /* Force all delayed allocation blocks to be allocated. | 4650 | /* Force all delayed allocation blocks to be allocated. |
| 4618 | * Caller already holds s_umount sem */ | 4651 | * Caller already holds s_umount sem */ |
| 4619 | if (test_opt(sb, DELALLOC)) | 4652 | if (test_opt(sb, DELALLOC)) |
| 4620 | sync_filesystem(sb); | 4653 | sync_filesystem(sb); |
| 4621 | 4654 | ||
| 4655 | /* Update modification times of quota files when userspace can | ||
| 4656 | * start looking at them */ | ||
| 4657 | handle = ext4_journal_start(inode, 1); | ||
| 4658 | if (IS_ERR(handle)) | ||
| 4659 | goto out; | ||
| 4660 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
| 4661 | ext4_mark_inode_dirty(handle, inode); | ||
| 4662 | ext4_journal_stop(handle); | ||
| 4663 | |||
| 4664 | out: | ||
| 4622 | return dquot_quota_off(sb, type); | 4665 | return dquot_quota_off(sb, type); |
| 4623 | } | 4666 | } |
| 4624 | 4667 | ||
| 4625 | /* Read data from quotafile - avoid pagecache and such because we cannot afford | 4668 | /* Read data from quotafile - avoid pagecache and such because we cannot afford |
| 4626 | * acquiring the locks... As quota files are never truncated and quota code | 4669 | * acquiring the locks... As quota files are never truncated and quota code |
| 4627 | * itself serializes the operations (and noone else should touch the files) | 4670 | * itself serializes the operations (and no one else should touch the files) |
| 4628 | * we don't have to be afraid of races */ | 4671 | * we don't have to be afraid of races */ |
| 4629 | static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, | 4672 | static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, |
| 4630 | size_t len, loff_t off) | 4673 | size_t len, loff_t off) |
| @@ -4714,9 +4757,8 @@ out: | |||
| 4714 | if (inode->i_size < off + len) { | 4757 | if (inode->i_size < off + len) { |
| 4715 | i_size_write(inode, off + len); | 4758 | i_size_write(inode, off + len); |
| 4716 | EXT4_I(inode)->i_disksize = inode->i_size; | 4759 | EXT4_I(inode)->i_disksize = inode->i_size; |
| 4760 | ext4_mark_inode_dirty(handle, inode); | ||
| 4717 | } | 4761 | } |
| 4718 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
| 4719 | ext4_mark_inode_dirty(handle, inode); | ||
| 4720 | mutex_unlock(&inode->i_mutex); | 4762 | mutex_unlock(&inode->i_mutex); |
| 4721 | return len; | 4763 | return len; |
| 4722 | } | 4764 | } |
