From: shhuiw@gmail.com
To: chris.mason@fusionio.com, jbacik@fusionio.com
Cc: linux-btrfs@vger.kernel.org
Subject: [PATCH] Btrfs: check crc area early in io_ctl_init
Date: Fri, 30 Nov 2012 14:02:27 +0800 [thread overview]
Message-ID: <50b84c2d.c44d320a.520e.ffffbea6@mx.google.com> (raw)
In-Reply-To: <1354255348-5011-1-git-send-email-y>
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
next prev parent reply other threads:[~2012-11-30 6:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1354255348-5011-1-git-send-email-y>
2012-11-30 6:02 ` [PATCH] Btrfs: remove warning check in io_ctl_map_page shhuiw
2012-11-30 9:02 ` Liu Bo
2012-11-30 11:18 ` Wang Sheng-Hui
2012-11-30 6:02 ` shhuiw [this message]
2012-11-30 6:02 ` [PATCH] Btrfs: cleanup: assign path->nodes[0]to leaf after ret check in __btrfs_write_out_cache shhuiw
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50b84c2d.c44d320a.520e.ffffbea6@mx.google.com \
--to=shhuiw@gmail.com \
--cc=chris.mason@fusionio.com \
--cc=jbacik@fusionio.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).