aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/suballoc.c
diff options
context:
space:
mode:
authorJoel Becker <joel.becker@oracle.com>2008-11-13 17:49:12 -0500
committerMark Fasheh <mfasheh@suse.com>2009-01-05 11:36:52 -0500
commit10995aa2451afa20b721cc7de856cae1a13dba57 (patch)
tree63129e7d752fb018dc76aa42de136baa4a8a4232 /fs/ocfs2/suballoc.c
parentb657c95c11088d77fc1bfc9c84d940f778bf9d12 (diff)
ocfs2: Morph the haphazard OCFS2_IS_VALID_DINODE() checks.
Random places in the code would check a dinode bh to see if it was valid. Not only did they do different levels of validation, they handled errors in different ways. The previous commit unified inode block reads, validating all block reads in the same place. Thus, these haphazard checks are no longer necessary. Rather than eliminate them, however, we change them to BUG_ON() checks. This ensures the assumptions remain true. All of the code paths to these checks have been audited to ensure they come from a validated inode read. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2/suballoc.c')
-rw-r--r--fs/ocfs2/suballoc.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index c5ff18b46b57..95d432b694e4 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -441,11 +441,11 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
441 ac->ac_alloc_slot = slot; 441 ac->ac_alloc_slot = slot;
442 442
443 fe = (struct ocfs2_dinode *) bh->b_data; 443 fe = (struct ocfs2_dinode *) bh->b_data;
444 if (!OCFS2_IS_VALID_DINODE(fe)) { 444
445 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe); 445 /* The bh was validated by the inode read inside
446 status = -EIO; 446 * ocfs2_inode_lock(). Any corruption is a code bug. */
447 goto bail; 447 BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
448 } 448
449 if (!(fe->i_flags & cpu_to_le32(OCFS2_CHAIN_FL))) { 449 if (!(fe->i_flags & cpu_to_le32(OCFS2_CHAIN_FL))) {
450 ocfs2_error(alloc_inode->i_sb, "Invalid chain allocator %llu", 450 ocfs2_error(alloc_inode->i_sb, "Invalid chain allocator %llu",
451 (unsigned long long)le64_to_cpu(fe->i_blkno)); 451 (unsigned long long)le64_to_cpu(fe->i_blkno));
@@ -931,11 +931,6 @@ static int ocfs2_relink_block_group(handle_t *handle,
931 struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data; 931 struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
932 struct ocfs2_group_desc *prev_bg = (struct ocfs2_group_desc *) prev_bg_bh->b_data; 932 struct ocfs2_group_desc *prev_bg = (struct ocfs2_group_desc *) prev_bg_bh->b_data;
933 933
934 if (!OCFS2_IS_VALID_DINODE(fe)) {
935 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
936 status = -EIO;
937 goto out;
938 }
939 if (!OCFS2_IS_VALID_GROUP_DESC(bg)) { 934 if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
940 OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg); 935 OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
941 status = -EIO; 936 status = -EIO;
@@ -1392,11 +1387,11 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
1392 BUG_ON(!ac->ac_bh); 1387 BUG_ON(!ac->ac_bh);
1393 1388
1394 fe = (struct ocfs2_dinode *) ac->ac_bh->b_data; 1389 fe = (struct ocfs2_dinode *) ac->ac_bh->b_data;
1395 if (!OCFS2_IS_VALID_DINODE(fe)) { 1390
1396 OCFS2_RO_ON_INVALID_DINODE(osb->sb, fe); 1391 /* The bh was validated by the inode read during
1397 status = -EIO; 1392 * ocfs2_reserve_suballoc_bits(). Any corruption is a code bug. */
1398 goto bail; 1393 BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
1399 } 1394
1400 if (le32_to_cpu(fe->id1.bitmap1.i_used) >= 1395 if (le32_to_cpu(fe->id1.bitmap1.i_used) >=
1401 le32_to_cpu(fe->id1.bitmap1.i_total)) { 1396 le32_to_cpu(fe->id1.bitmap1.i_total)) {
1402 ocfs2_error(osb->sb, "Chain allocator dinode %llu has %u used " 1397 ocfs2_error(osb->sb, "Chain allocator dinode %llu has %u used "
@@ -1782,11 +1777,12 @@ int ocfs2_free_suballoc_bits(handle_t *handle,
1782 1777
1783 mlog_entry_void(); 1778 mlog_entry_void();
1784 1779
1785 if (!OCFS2_IS_VALID_DINODE(fe)) { 1780 /* The alloc_bh comes from ocfs2_free_dinode() or
1786 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe); 1781 * ocfs2_free_clusters(). The callers have all locked the
1787 status = -EIO; 1782 * allocator and gotten alloc_bh from the lock call. This
1788 goto bail; 1783 * validates the dinode buffer. Any corruption that has happended
1789 } 1784 * is a code bug. */
1785 BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
1790 BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl)); 1786 BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl));
1791 1787
1792 mlog(0, "%llu: freeing %u bits from group %llu, starting at %u\n", 1788 mlog(0, "%llu: freeing %u bits from group %llu, starting at %u\n",