ext4_balloc: invalidate buffers which have the blocks freed.
authorngkaho1234 <ngkaho1234@gmail.com>
Sat, 26 Dec 2015 11:09:55 +0000 (11:09 +0000)
committerngkaho1234 <ngkaho1234@gmail.com>
Sat, 26 Dec 2015 11:10:08 +0000 (11:10 +0000)
lwext4/ext4_balloc.c
lwext4/ext4_bcache.c
lwext4/ext4_bcache.h

index 64f1bcf26253100ff0309e0c61dd0bc5b3f63f4c..b840bea8c55651410624e758fdf1da00555630e0 100644 (file)
@@ -211,6 +211,7 @@ int ext4_balloc_free_block(struct ext4_inode_ref *inode_ref, ext4_fsblk_t baddr)
 
        bg_ref.dirty = true;
 
+       ext4_bcache_invalidate_lba(fs->bdev->bc, baddr, 1);
        /* Release block group reference */
        return ext4_fs_put_block_group_ref(&bg_ref);
 }
@@ -317,6 +318,7 @@ int ext4_balloc_free_blocks(struct ext4_inode_ref *inode_ref,
                bg_first++;
        }
 
+       ext4_bcache_invalidate_lba(fs->bdev->bc, first, count);
        /*All blocks should be released*/
        ext4_assert(count == 0);
        return rc;
index 43bca03494cc75bb1fe97bc8ca762b9d81c00c3e..a03f9495c04c7fd7bc2b160701e803b1a4fddc09 100644 (file)
@@ -176,6 +176,21 @@ void ext4_bcache_drop_buf(struct ext4_bcache *bc, struct ext4_buf *buf)
        bc->ref_blocks--;
 }
 
+void ext4_bcache_invalidate_lba(struct ext4_bcache *bc,
+                               uint64_t from,
+                               uint32_t cnt)
+{
+       uint64_t end = from + cnt - 1;
+       struct ext4_buf *tmp = ext4_buf_lookup(bc, from), *buf;
+       RB_FOREACH_FROM(buf, ext4_buf_lba, tmp) {
+               if (buf->lba > end)
+                       break;
+
+               /* Clear both dirty and up-to-date flags. */
+               ext4_bcache_clear_dirty(buf);
+       }
+}
+
 struct ext4_buf *
 ext4_bcache_find_get(struct ext4_bcache *bc, struct ext4_block *b,
                     uint64_t lba)
index 9cb921a69151cea256373509d2c7687aaf2b95b9..f386b753db309efdb7f8a4e30fbcdb4b81680019 100644 (file)
@@ -238,6 +238,15 @@ struct ext4_buf *ext4_buf_lowest_lru(struct ext4_bcache *bc);
  * @param   buf buffer*/
 void ext4_bcache_drop_buf(struct ext4_bcache *bc, struct ext4_buf *buf);
 
+/**@brief   Invalidate a range of buffers.
+ * @param   bc block cache descriptor
+ * @param   from starting lba
+ * @param   cnt block counts
+ * @param   buf buffer*/
+void ext4_bcache_invalidate_lba(struct ext4_bcache *bc,
+                               uint64_t from,
+                               uint32_t cnt);
+
 /**@brief   Find existing buffer from block cache memory.
  *          Unreferenced block allocation is based on LRU
  *          (Last Recently Used) algorithm.