[PATCH] Btrfs: check crc area early in io_ctl_init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Wang Sheng-Hui <shhuiw@xxxxxxxxx>

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@xxxxxxxxx>
---
 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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux