aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
authorEric Whitney <enwlinux@gmail.com>2014-11-23 00:59:39 -0500
committerTheodore Ts'o <tytso@mit.edu>2014-11-23 00:59:39 -0500
commit345ee947482f1c787b31014008586b8f512af1bd (patch)
tree1316cb427103e7e75d9ce63fa37ac43f3926bcad /fs/ext4
parent5bf43760654fa618fb8bb1612ee2d7ae164f7f94 (diff)
ext4: miscellaneous partial cluster cleanups
Add some casts and rearrange a few statements for improved readability. Some code can also be simplified and made more readable if we set partial_cluster to 0 rather than to a negative value when we can tell we've hit the left edge of the punched region. Signed-off-by: Eric Whitney <enwlinux@gmail.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/extents.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 859ab37efa6f..841adf05e287 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2481,7 +2481,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
2481 ext4_lblk_t from, ext4_lblk_t to) 2481 ext4_lblk_t from, ext4_lblk_t to)
2482{ 2482{
2483 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 2483 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
2484 unsigned short ee_len = ext4_ext_get_actual_len(ex); 2484 unsigned short ee_len = ext4_ext_get_actual_len(ex);
2485 ext4_fsblk_t pblk; 2485 ext4_fsblk_t pblk;
2486 int flags = get_default_free_blocks_flags(inode); 2486 int flags = get_default_free_blocks_flags(inode);
2487 2487
@@ -2490,7 +2490,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
2490 * at the beginning of the extent. Instead, we make a note 2490 * at the beginning of the extent. Instead, we make a note
2491 * that we tried freeing the cluster, and check to see if we 2491 * that we tried freeing the cluster, and check to see if we
2492 * need to free it on a subsequent call to ext4_remove_blocks, 2492 * need to free it on a subsequent call to ext4_remove_blocks,
2493 * or at the end of the ext4_truncate() operation. 2493 * or at the end of ext4_ext_rm_leaf or ext4_ext_remove_space.
2494 */ 2494 */
2495 flags |= EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER; 2495 flags |= EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER;
2496 2496
@@ -2501,8 +2501,8 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
2501 * partial cluster here. 2501 * partial cluster here.
2502 */ 2502 */
2503 pblk = ext4_ext_pblock(ex) + ee_len - 1; 2503 pblk = ext4_ext_pblock(ex) + ee_len - 1;
2504 if ((*partial_cluster > 0) && 2504 if (*partial_cluster > 0 &&
2505 (EXT4_B2C(sbi, pblk) != *partial_cluster)) { 2505 *partial_cluster != (long long) EXT4_B2C(sbi, pblk)) {
2506 ext4_free_blocks(handle, inode, NULL, 2506 ext4_free_blocks(handle, inode, NULL,
2507 EXT4_C2B(sbi, *partial_cluster), 2507 EXT4_C2B(sbi, *partial_cluster),
2508 sbi->s_cluster_ratio, flags); 2508 sbi->s_cluster_ratio, flags);
@@ -2528,7 +2528,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
2528 && to == le32_to_cpu(ex->ee_block) + ee_len - 1) { 2528 && to == le32_to_cpu(ex->ee_block) + ee_len - 1) {
2529 /* tail removal */ 2529 /* tail removal */
2530 ext4_lblk_t num; 2530 ext4_lblk_t num;
2531 unsigned int unaligned; 2531 long long first_cluster;
2532 2532
2533 num = le32_to_cpu(ex->ee_block) + ee_len - from; 2533 num = le32_to_cpu(ex->ee_block) + ee_len - from;
2534 pblk = ext4_ext_pblock(ex) + ee_len - num; 2534 pblk = ext4_ext_pblock(ex) + ee_len - num;
@@ -2538,7 +2538,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
2538 * used by any other extent (partial_cluster is negative). 2538 * used by any other extent (partial_cluster is negative).
2539 */ 2539 */
2540 if (*partial_cluster < 0 && 2540 if (*partial_cluster < 0 &&
2541 -(*partial_cluster) == EXT4_B2C(sbi, pblk + num - 1)) 2541 *partial_cluster == -(long long) EXT4_B2C(sbi, pblk+num-1))
2542 flags |= EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER; 2542 flags |= EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER;
2543 2543
2544 ext_debug("free last %u blocks starting %llu partial %lld\n", 2544 ext_debug("free last %u blocks starting %llu partial %lld\n",
@@ -2549,21 +2549,24 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
2549 * beginning of a cluster, and we removed the entire 2549 * beginning of a cluster, and we removed the entire
2550 * extent and the cluster is not used by any other extent, 2550 * extent and the cluster is not used by any other extent,
2551 * save the partial cluster here, since we might need to 2551 * save the partial cluster here, since we might need to
2552 * delete if we determine that the truncate operation has 2552 * delete if we determine that the truncate or punch hole
2553 * removed all of the blocks in the cluster. 2553 * operation has removed all of the blocks in the cluster.
2554 * If that cluster is used by another extent, preserve its
2555 * negative value so it isn't freed later on.
2554 * 2556 *
2555 * On the other hand, if we did not manage to free the whole 2557 * If the whole extent wasn't freed, we've reached the
2556 * extent, we have to mark the cluster as used (store negative 2558 * start of the truncated/punched region and have finished
2557 * cluster number in partial_cluster). 2559 * removing blocks. If there's a partial cluster here it's
2560 * shared with the remainder of the extent and is no longer
2561 * a candidate for removal.
2558 */ 2562 */
2559 unaligned = EXT4_PBLK_COFF(sbi, pblk); 2563 if (EXT4_PBLK_COFF(sbi, pblk) && ee_len == num) {
2560 if (unaligned && (ee_len == num) && 2564 first_cluster = (long long) EXT4_B2C(sbi, pblk);
2561 (*partial_cluster != -((long long)EXT4_B2C(sbi, pblk)))) 2565 if (first_cluster != -*partial_cluster)
2562 *partial_cluster = EXT4_B2C(sbi, pblk); 2566 *partial_cluster = first_cluster;
2563 else if (unaligned) 2567 } else {
2564 *partial_cluster = -((long long)EXT4_B2C(sbi, pblk));
2565 else if (*partial_cluster > 0)
2566 *partial_cluster = 0; 2568 *partial_cluster = 0;
2569 }
2567 } else 2570 } else
2568 ext4_error(sbi->s_sb, "strange request: removal(2) " 2571 ext4_error(sbi->s_sb, "strange request: removal(2) "
2569 "%u-%u from %u:%u\n", 2572 "%u-%u from %u:%u\n",