From: Wang Sheng-Hui <shhuiw@gmail.com>
When use crc area, we should check if it can host the desired num of
crcs. Add the check in init stage.
And the check should be more strict: the first page has sizeof(u64)*2
cannot used for crc.
Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
---
fs/btrfs/free-space-cache.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 4ea66d4..058fc9b 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -286,8 +286,14 @@ static int io_ctl_init(struct io_ctl *io_ctl, struct inode
*inode,
if (!io_ctl->pages)
return -ENOMEM;
io_ctl->root = root;
- if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID)
+ if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID) {
io_ctl->check_crcs = 1;
+ if ((io_ctl.num_pages * sizeof(u32)) >
+ (PAGE_CACHE_SIZE - sizeof(u64) * 2)) {
+ WARN_ON(1);
+ return -1;
+ }
+ }
return 0;
}
@@ -917,7 +923,8 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct
inode *inode,
/* Make sure we can fit our crcs into the first page */
if (io_ctl.check_crcs &&
- (io_ctl.num_pages * sizeof(u32)) >= PAGE_CACHE_SIZE) {
+ (io_ctl.num_pages * sizeof(u32)) >
+ (PAGE_CACHE_SIZE - sizeof(u64) * 2)) {
WARN_ON(1);
goto out_nospc;
}
--
1.6.0.2
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs"
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html