aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/super.c
diff options
context:
space:
mode:
authorShawn Lin <shawn.lin@rock-chips.com>2016-02-16 19:59:01 -0500
committerJaegeuk Kim <jaegeuk@kernel.org>2016-02-23 00:39:56 -0500
commit2b39e9072d79ab2525100413f3f7a0b8a3e15873 (patch)
treeb12f5a30c0b1d11f823c544bb9571693bae1b1c8 /fs/f2fs/super.c
parent1515aef0130845c6a5c72a3710df362f79eb9fb1 (diff)
f2fs: slightly reorganize read_raw_super_block
read_raw_super_block was introduced to help find the first valid superblock. Commit da554e48caab ("f2fs: recovering broken superblock during mount") changed the behaviour to read both of them and check whether need the recovery flag or not. So the comment before this function isn't consistent with what it actually does. Also, the origin code use two tags to round the err cases, which isn't so readable. So this patch amend the comment and slightly reorganize it. Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/super.c')
-rw-r--r--fs/f2fs/super.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index ecee9ef74266..9e9493999bf3 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1166,14 +1166,15 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
1166 1166
1167/* 1167/*
1168 * Read f2fs raw super block. 1168 * Read f2fs raw super block.
1169 * Because we have two copies of super block, so read the first one at first, 1169 * Because we have two copies of super block, so read both of them
1170 * if the first one is invalid, move to read the second one. 1170 * to get the first valid one. If any one of them is broken, we pass
1171 * them recovery flag back to the caller.
1171 */ 1172 */
1172static int read_raw_super_block(struct super_block *sb, 1173static int read_raw_super_block(struct super_block *sb,
1173 struct f2fs_super_block **raw_super, 1174 struct f2fs_super_block **raw_super,
1174 int *valid_super_block, int *recovery) 1175 int *valid_super_block, int *recovery)
1175{ 1176{
1176 int block = 0; 1177 int block;
1177 struct buffer_head *bh; 1178 struct buffer_head *bh;
1178 struct f2fs_super_block *super, *buf; 1179 struct f2fs_super_block *super, *buf;
1179 int err = 0; 1180 int err = 0;
@@ -1181,50 +1182,48 @@ static int read_raw_super_block(struct super_block *sb,
1181 super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL); 1182 super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
1182 if (!super) 1183 if (!super)
1183 return -ENOMEM; 1184 return -ENOMEM;
1184retry: 1185
1185 bh = sb_bread(sb, block); 1186 for (block = 0; block < 2; block++) {
1186 if (!bh) { 1187 bh = sb_bread(sb, block);
1187 *recovery = 1; 1188 if (!bh) {
1188 f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock", 1189 f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock",
1189 block + 1); 1190 block + 1);
1190 err = -EIO; 1191 err = -EIO;
1191 goto next; 1192 continue;
1192 } 1193 }
1193 1194
1194 buf = (struct f2fs_super_block *)(bh->b_data + F2FS_SUPER_OFFSET); 1195 buf = (struct f2fs_super_block *)
1196 (bh->b_data + F2FS_SUPER_OFFSET);
1195 1197
1196 /* sanity checking of raw super */ 1198 /* sanity checking of raw super */
1197 if (sanity_check_raw_super(sb, buf)) { 1199 if (sanity_check_raw_super(sb, buf)) {
1198 brelse(bh); 1200 f2fs_msg(sb, KERN_ERR,
1199 *recovery = 1; 1201 "Can't find valid F2FS filesystem in %dth superblock",
1200 f2fs_msg(sb, KERN_ERR, 1202 block + 1);
1201 "Can't find valid F2FS filesystem in %dth superblock", 1203 err = -EINVAL;
1202 block + 1); 1204 brelse(bh);
1203 err = -EINVAL; 1205 continue;
1204 goto next; 1206 }
1205 }
1206 1207
1207 if (!*raw_super) { 1208 if (!*raw_super) {
1208 memcpy(super, buf, sizeof(*super)); 1209 memcpy(super, buf, sizeof(*super));
1209 *valid_super_block = block; 1210 *valid_super_block = block;
1210 *raw_super = super; 1211 *raw_super = super;
1212 }
1213 brelse(bh);
1211 } 1214 }
1212 brelse(bh);
1213 1215
1214next: 1216 /* Fail to read any one of the superblocks*/
1215 /* check the validity of the second superblock */ 1217 if (err < 0)
1216 if (block == 0) { 1218 *recovery = 1;
1217 block++;
1218 goto retry;
1219 }
1220 1219
1221 /* No valid superblock */ 1220 /* No valid superblock */
1222 if (!*raw_super) { 1221 if (!*raw_super)
1223 kfree(super); 1222 kfree(super);
1224 return err; 1223 else
1225 } 1224 err = 0;
1226 1225
1227 return 0; 1226 return err;
1228} 1227}
1229 1228
1230static int __f2fs_commit_super(struct f2fs_sb_info *sbi, int block) 1229static int __f2fs_commit_super(struct f2fs_sb_info *sbi, int block)