diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2015-08-15 11:30:31 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2015-08-15 11:30:31 -0400 |
commit | 9810446836ab5a4b34a749bb77f3eb5836f982cc (patch) | |
tree | 4bc7c2d3788f2dbd2fb58d185291799f3be9329a | |
parent | c642dc9e1aaed953597e7092d7df329e6234096e (diff) |
ext4: simplify some code in read_mmp_block()
My static check complains because we have:
if (!*bh)
return -ENOMEM;
if (*bh) {
The second check is unnecessary.
I've simplified this code by moving the "if (!*bh)" checks around. Also
Andreas Dilger says we should probably print a warning if sb_getblk()
fails.
[ Restructured the code so that we print a warning message as well if
the mmp block doesn't check out, and to print the error code to
disambiguate between the error cases. - TYT ]
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | fs/ext4/mmp.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 8313ca3324ec..048c52af2fb6 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c | |||
@@ -69,6 +69,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh, | |||
69 | ext4_fsblk_t mmp_block) | 69 | ext4_fsblk_t mmp_block) |
70 | { | 70 | { |
71 | struct mmp_struct *mmp; | 71 | struct mmp_struct *mmp; |
72 | int ret; | ||
72 | 73 | ||
73 | if (*bh) | 74 | if (*bh) |
74 | clear_buffer_uptodate(*bh); | 75 | clear_buffer_uptodate(*bh); |
@@ -76,33 +77,36 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh, | |||
76 | /* This would be sb_bread(sb, mmp_block), except we need to be sure | 77 | /* This would be sb_bread(sb, mmp_block), except we need to be sure |
77 | * that the MD RAID device cache has been bypassed, and that the read | 78 | * that the MD RAID device cache has been bypassed, and that the read |
78 | * is not blocked in the elevator. */ | 79 | * is not blocked in the elevator. */ |
79 | if (!*bh) | 80 | if (!*bh) { |
80 | *bh = sb_getblk(sb, mmp_block); | 81 | *bh = sb_getblk(sb, mmp_block); |
81 | if (!*bh) | 82 | if (!*bh) { |
82 | return -ENOMEM; | 83 | ret = -ENOMEM; |
83 | if (*bh) { | 84 | goto warn_exit; |
84 | get_bh(*bh); | ||
85 | lock_buffer(*bh); | ||
86 | (*bh)->b_end_io = end_buffer_read_sync; | ||
87 | submit_bh(READ_SYNC | REQ_META | REQ_PRIO, *bh); | ||
88 | wait_on_buffer(*bh); | ||
89 | if (!buffer_uptodate(*bh)) { | ||
90 | brelse(*bh); | ||
91 | *bh = NULL; | ||
92 | } | 85 | } |
93 | } | 86 | } |
94 | if (unlikely(!*bh)) { | 87 | |
95 | ext4_warning(sb, "Error while reading MMP block %llu", | 88 | get_bh(*bh); |
96 | mmp_block); | 89 | lock_buffer(*bh); |
97 | return -EIO; | 90 | (*bh)->b_end_io = end_buffer_read_sync; |
91 | submit_bh(READ_SYNC | REQ_META | REQ_PRIO, *bh); | ||
92 | wait_on_buffer(*bh); | ||
93 | if (!buffer_uptodate(*bh)) { | ||
94 | brelse(*bh); | ||
95 | *bh = NULL; | ||
96 | ret = -EIO; | ||
97 | goto warn_exit; | ||
98 | } | 98 | } |
99 | 99 | ||
100 | mmp = (struct mmp_struct *)((*bh)->b_data); | 100 | mmp = (struct mmp_struct *)((*bh)->b_data); |
101 | if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC || | 101 | if (le32_to_cpu(mmp->mmp_magic) == EXT4_MMP_MAGIC && |
102 | !ext4_mmp_csum_verify(sb, mmp)) | 102 | ext4_mmp_csum_verify(sb, mmp)) |
103 | return -EINVAL; | 103 | return 0; |
104 | 104 | ret = -EINVAL; | |
105 | return 0; | 105 | |
106 | warn_exit: | ||
107 | ext4_warning(sb, "Error %d while reading MMP block %llu", | ||
108 | ret, mmp_block); | ||
109 | return ret; | ||
106 | } | 110 | } |
107 | 111 | ||
108 | /* | 112 | /* |