diff options
author | Joel Becker <joel.becker@oracle.com> | 2008-11-13 17:49:15 -0500 |
---|---|---|
committer | Mark Fasheh <mfasheh@suse.com> | 2009-01-05 11:36:53 -0500 |
commit | 4203530613280281868b3ca36c817530bca3825c (patch) | |
tree | 57acc14e07bd97491a3781eb61e8c83c3c6e0151 /fs/ocfs2 | |
parent | 68f64d471be38631d7196b938d9809802dd467fa (diff) |
ocfs2: Morph the haphazard OCFS2_IS_VALID_GROUP_DESC() checks.
Random places in the code would check a group descriptor bh to see if it
was valid. The previous commit unified descriptor block reads,
validating all block reads in the same place. Thus, these 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 descriptor read.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2')
-rw-r--r-- | fs/ocfs2/ocfs2.h | 7 | ||||
-rw-r--r-- | fs/ocfs2/suballoc.c | 39 |
2 files changed, 14 insertions, 32 deletions
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 467bdb6f71e1..82ba887afa0d 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h | |||
@@ -458,13 +458,6 @@ static inline int ocfs2_uses_extended_slot_map(struct ocfs2_super *osb) | |||
458 | #define OCFS2_IS_VALID_GROUP_DESC(ptr) \ | 458 | #define OCFS2_IS_VALID_GROUP_DESC(ptr) \ |
459 | (!strcmp((ptr)->bg_signature, OCFS2_GROUP_DESC_SIGNATURE)) | 459 | (!strcmp((ptr)->bg_signature, OCFS2_GROUP_DESC_SIGNATURE)) |
460 | 460 | ||
461 | #define OCFS2_RO_ON_INVALID_GROUP_DESC(__sb, __gd) do { \ | ||
462 | typeof(__gd) ____gd = (__gd); \ | ||
463 | ocfs2_error((__sb), \ | ||
464 | "Group Descriptor # %llu has bad signature %.*s", \ | ||
465 | (unsigned long long)le64_to_cpu((____gd)->bg_blkno), 7, \ | ||
466 | (____gd)->bg_signature); \ | ||
467 | } while (0) | ||
468 | 461 | ||
469 | #define OCFS2_IS_VALID_XATTR_BLOCK(ptr) \ | 462 | #define OCFS2_IS_VALID_XATTR_BLOCK(ptr) \ |
470 | (!strcmp((ptr)->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE)) | 463 | (!strcmp((ptr)->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE)) |
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index 797f509d7250..766a00b26441 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c | |||
@@ -842,10 +842,9 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb, | |||
842 | int offset, start, found, status = 0; | 842 | int offset, start, found, status = 0; |
843 | struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data; | 843 | struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data; |
844 | 844 | ||
845 | if (!OCFS2_IS_VALID_GROUP_DESC(bg)) { | 845 | /* Callers got this descriptor from |
846 | OCFS2_RO_ON_INVALID_GROUP_DESC(osb->sb, bg); | 846 | * ocfs2_read_group_descriptor(). Any corruption is a code bug. */ |
847 | return -EIO; | 847 | BUG_ON(!OCFS2_IS_VALID_GROUP_DESC(bg)); |
848 | } | ||
849 | 848 | ||
850 | found = start = best_offset = best_size = 0; | 849 | found = start = best_offset = best_size = 0; |
851 | bitmap = bg->bg_bitmap; | 850 | bitmap = bg->bg_bitmap; |
@@ -910,11 +909,9 @@ static inline int ocfs2_block_group_set_bits(handle_t *handle, | |||
910 | 909 | ||
911 | mlog_entry_void(); | 910 | mlog_entry_void(); |
912 | 911 | ||
913 | if (!OCFS2_IS_VALID_GROUP_DESC(bg)) { | 912 | /* All callers get the descriptor via |
914 | OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg); | 913 | * ocfs2_read_group_descriptor(). Any corruption is a code bug. */ |
915 | status = -EIO; | 914 | BUG_ON(!OCFS2_IS_VALID_GROUP_DESC(bg)); |
916 | goto bail; | ||
917 | } | ||
918 | BUG_ON(le16_to_cpu(bg->bg_free_bits_count) < num_bits); | 915 | BUG_ON(le16_to_cpu(bg->bg_free_bits_count) < num_bits); |
919 | 916 | ||
920 | mlog(0, "block_group_set_bits: off = %u, num = %u\n", bit_off, | 917 | mlog(0, "block_group_set_bits: off = %u, num = %u\n", bit_off, |
@@ -983,16 +980,10 @@ static int ocfs2_relink_block_group(handle_t *handle, | |||
983 | struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data; | 980 | struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data; |
984 | struct ocfs2_group_desc *prev_bg = (struct ocfs2_group_desc *) prev_bg_bh->b_data; | 981 | struct ocfs2_group_desc *prev_bg = (struct ocfs2_group_desc *) prev_bg_bh->b_data; |
985 | 982 | ||
986 | if (!OCFS2_IS_VALID_GROUP_DESC(bg)) { | 983 | /* The caller got these descriptors from |
987 | OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg); | 984 | * ocfs2_read_group_descriptor(). Any corruption is a code bug. */ |
988 | status = -EIO; | 985 | BUG_ON(!OCFS2_IS_VALID_GROUP_DESC(bg)); |
989 | goto out; | 986 | BUG_ON(!OCFS2_IS_VALID_GROUP_DESC(prev_bg)); |
990 | } | ||
991 | if (!OCFS2_IS_VALID_GROUP_DESC(prev_bg)) { | ||
992 | OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, prev_bg); | ||
993 | status = -EIO; | ||
994 | goto out; | ||
995 | } | ||
996 | 987 | ||
997 | mlog(0, "Suballoc %llu, chain %u, move group %llu to top, prev = %llu\n", | 988 | mlog(0, "Suballoc %llu, chain %u, move group %llu to top, prev = %llu\n", |
998 | (unsigned long long)le64_to_cpu(fe->i_blkno), chain, | 989 | (unsigned long long)le64_to_cpu(fe->i_blkno), chain, |
@@ -1055,7 +1046,7 @@ out_rollback: | |||
1055 | bg->bg_next_group = cpu_to_le64(bg_ptr); | 1046 | bg->bg_next_group = cpu_to_le64(bg_ptr); |
1056 | prev_bg->bg_next_group = cpu_to_le64(prev_bg_ptr); | 1047 | prev_bg->bg_next_group = cpu_to_le64(prev_bg_ptr); |
1057 | } | 1048 | } |
1058 | out: | 1049 | |
1059 | mlog_exit(status); | 1050 | mlog_exit(status); |
1060 | return status; | 1051 | return status; |
1061 | } | 1052 | } |
@@ -1758,11 +1749,9 @@ static inline int ocfs2_block_group_clear_bits(handle_t *handle, | |||
1758 | 1749 | ||
1759 | mlog_entry_void(); | 1750 | mlog_entry_void(); |
1760 | 1751 | ||
1761 | if (!OCFS2_IS_VALID_GROUP_DESC(bg)) { | 1752 | /* The caller got this descriptor from |
1762 | OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg); | 1753 | * ocfs2_read_group_descriptor(). Any corruption is a code bug. */ |
1763 | status = -EIO; | 1754 | BUG_ON(!OCFS2_IS_VALID_GROUP_DESC(bg)); |
1764 | goto bail; | ||
1765 | } | ||
1766 | 1755 | ||
1767 | mlog(0, "off = %u, num = %u\n", bit_off, num_bits); | 1756 | mlog(0, "off = %u, num = %u\n", bit_off, num_bits); |
1768 | 1757 | ||