aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/file.c
diff options
context:
space:
mode:
authorJoel Becker <joel.becker@oracle.com>2008-11-13 17:49:11 -0500
committerMark Fasheh <mfasheh@suse.com>2009-01-05 11:36:52 -0500
commitb657c95c11088d77fc1bfc9c84d940f778bf9d12 (patch)
tree7e52e73aabbdbc55f644ad26735edc25a652ac32 /fs/ocfs2/file.c
parenta68979b857283daf4acc405e476dcc8812a3ff2b (diff)
ocfs2: Wrap inode block reads in a dedicated function.
The ocfs2 code currently reads inodes off disk with a simple ocfs2_read_block() call. Each place that does this has a different set of sanity checks it performs. Some check only the signature. A couple validate the block number (the block read vs di->i_blkno). A couple others check for VALID_FL. Only one place validates i_fs_generation. A couple check nothing. Even when an error is found, they don't all do the same thing. We wrap inode reading into ocfs2_read_inode_block(). This will validate all the above fields, going readonly if they are invalid (they never should be). ocfs2_read_inode_block_full() is provided for the places that want to pass read_block flags. Every caller is passing a struct inode with a valid ip_blkno, so we don't need a separate blkno argument either. We will remove the validation checks from the rest of the code in a later commit, as they are no longer necessary. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2/file.c')
-rw-r--r--fs/ocfs2/file.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 4636aa6b0117..41001d515fae 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -402,12 +402,9 @@ static int ocfs2_truncate_file(struct inode *inode,
402 (unsigned long long)OCFS2_I(inode)->ip_blkno, 402 (unsigned long long)OCFS2_I(inode)->ip_blkno,
403 (unsigned long long)new_i_size); 403 (unsigned long long)new_i_size);
404 404
405 /* We trust di_bh because it comes from ocfs2_inode_lock(), which
406 * already validated it */
405 fe = (struct ocfs2_dinode *) di_bh->b_data; 407 fe = (struct ocfs2_dinode *) di_bh->b_data;
406 if (!OCFS2_IS_VALID_DINODE(fe)) {
407 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
408 status = -EIO;
409 goto bail;
410 }
411 408
412 mlog_bug_on_msg(le64_to_cpu(fe->i_size) != i_size_read(inode), 409 mlog_bug_on_msg(le64_to_cpu(fe->i_size) != i_size_read(inode),
413 "Inode %llu, inode i_size = %lld != di " 410 "Inode %llu, inode i_size = %lld != di "
@@ -546,18 +543,12 @@ static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
546 */ 543 */
547 BUG_ON(mark_unwritten && !ocfs2_sparse_alloc(osb)); 544 BUG_ON(mark_unwritten && !ocfs2_sparse_alloc(osb));
548 545
549 status = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, &bh); 546 status = ocfs2_read_inode_block(inode, &bh);
550 if (status < 0) { 547 if (status < 0) {
551 mlog_errno(status); 548 mlog_errno(status);
552 goto leave; 549 goto leave;
553 } 550 }
554
555 fe = (struct ocfs2_dinode *) bh->b_data; 551 fe = (struct ocfs2_dinode *) bh->b_data;
556 if (!OCFS2_IS_VALID_DINODE(fe)) {
557 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
558 status = -EIO;
559 goto leave;
560 }
561 552
562restart_all: 553restart_all:
563 BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters); 554 BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters);
@@ -1135,9 +1126,8 @@ static int ocfs2_write_remove_suid(struct inode *inode)
1135{ 1126{
1136 int ret; 1127 int ret;
1137 struct buffer_head *bh = NULL; 1128 struct buffer_head *bh = NULL;
1138 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1139 1129
1140 ret = ocfs2_read_block(inode, oi->ip_blkno, &bh); 1130 ret = ocfs2_read_inode_block(inode, &bh);
1141 if (ret < 0) { 1131 if (ret < 0) {
1142 mlog_errno(ret); 1132 mlog_errno(ret);
1143 goto out; 1133 goto out;
@@ -1163,8 +1153,7 @@ static int ocfs2_allocate_unwritten_extents(struct inode *inode,
1163 struct buffer_head *di_bh = NULL; 1153 struct buffer_head *di_bh = NULL;
1164 1154
1165 if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { 1155 if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
1166 ret = ocfs2_read_block(inode, OCFS2_I(inode)->ip_blkno, 1156 ret = ocfs2_read_inode_block(inode, &di_bh);
1167 &di_bh);
1168 if (ret) { 1157 if (ret) {
1169 mlog_errno(ret); 1158 mlog_errno(ret);
1170 goto out; 1159 goto out;