Merge remote-tracking branch 'lsk/v3.10/topic/gator' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.git] / fs / ext4 / extents.c
index 141d0fce318ddf2655e948a18772199837387487..84d817b842a8f0cf01525f7508b4e078472bed03 100644 (file)
@@ -2511,6 +2511,27 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
        ex_ee_block = le32_to_cpu(ex->ee_block);
        ex_ee_len = ext4_ext_get_actual_len(ex);
 
+       /*
+        * If we're starting with an extent other than the last one in the
+        * node, we need to see if it shares a cluster with the extent to
+        * the right (towards the end of the file). If its leftmost cluster
+        * is this extent's rightmost cluster and it is not cluster aligned,
+        * we'll mark it as a partial that is not to be deallocated.
+        */
+
+       if (ex != EXT_LAST_EXTENT(eh)) {
+               ext4_fsblk_t current_pblk, right_pblk;
+               long long current_cluster, right_cluster;
+
+               current_pblk = ext4_ext_pblock(ex) + ex_ee_len - 1;
+               current_cluster = (long long)EXT4_B2C(sbi, current_pblk);
+               right_pblk = ext4_ext_pblock(ex + 1);
+               right_cluster = (long long)EXT4_B2C(sbi, right_pblk);
+               if (current_cluster == right_cluster &&
+                       EXT4_PBLK_COFF(sbi, right_pblk))
+                       *partial_cluster = -right_cluster;
+       }
+
        trace_ext4_ext_rm_leaf(inode, start, ex, *partial_cluster);
 
        while (ex >= EXT_FIRST_EXTENT(eh) &&