f2fs: introduce function read_raw_super_block()
Introduce function read_raw_super_block() to hide reading raw super block and the retry routine if the first sb is invalid. Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
parent
b1838f8952
commit
9076a75f8e
|
@ -746,30 +746,47 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
|
||||||
atomic_set(&sbi->nr_pages[i], 0);
|
atomic_set(&sbi->nr_pages[i], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int validate_superblock(struct super_block *sb,
|
/*
|
||||||
struct f2fs_super_block **raw_super,
|
* Read f2fs raw super block.
|
||||||
struct buffer_head **raw_super_buf, sector_t block)
|
* Because we have two copies of super block, so read the first one at first,
|
||||||
|
* if the first one is invalid, move to read the second one.
|
||||||
|
*/
|
||||||
|
static int read_raw_super_block(struct super_block *sb,
|
||||||
|
struct f2fs_super_block **raw_super,
|
||||||
|
struct buffer_head **raw_super_buf)
|
||||||
{
|
{
|
||||||
const char *super = (block == 0 ? "first" : "second");
|
int block = 0;
|
||||||
|
|
||||||
/* read f2fs raw super block */
|
retry:
|
||||||
*raw_super_buf = sb_bread(sb, block);
|
*raw_super_buf = sb_bread(sb, block);
|
||||||
if (!*raw_super_buf) {
|
if (!*raw_super_buf) {
|
||||||
f2fs_msg(sb, KERN_ERR, "unable to read %s superblock",
|
f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock",
|
||||||
super);
|
block + 1);
|
||||||
return -EIO;
|
if (block == 0) {
|
||||||
|
block++;
|
||||||
|
goto retry;
|
||||||
|
} else {
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*raw_super = (struct f2fs_super_block *)
|
*raw_super = (struct f2fs_super_block *)
|
||||||
((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET);
|
((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET);
|
||||||
|
|
||||||
/* sanity checking of raw super */
|
/* sanity checking of raw super */
|
||||||
if (!sanity_check_raw_super(sb, *raw_super))
|
if (sanity_check_raw_super(sb, *raw_super)) {
|
||||||
return 0;
|
brelse(*raw_super_buf);
|
||||||
|
f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem "
|
||||||
|
"in %dth superblock", block + 1);
|
||||||
|
if(block == 0) {
|
||||||
|
block++;
|
||||||
|
goto retry;
|
||||||
|
} else {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem "
|
return 0;
|
||||||
"in %s superblock", super);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
|
static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
|
@ -791,14 +808,10 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
goto free_sbi;
|
goto free_sbi;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = validate_superblock(sb, &raw_super, &raw_super_buf, 0);
|
err = read_raw_super_block(sb, &raw_super, &raw_super_buf);
|
||||||
if (err) {
|
if (err)
|
||||||
brelse(raw_super_buf);
|
goto free_sbi;
|
||||||
/* check secondary superblock when primary failed */
|
|
||||||
err = validate_superblock(sb, &raw_super, &raw_super_buf, 1);
|
|
||||||
if (err)
|
|
||||||
goto free_sb_buf;
|
|
||||||
}
|
|
||||||
sb->s_fs_info = sbi;
|
sb->s_fs_info = sbi;
|
||||||
/* init some FS parameters */
|
/* init some FS parameters */
|
||||||
sbi->active_logs = NR_CURSEG_TYPE;
|
sbi->active_logs = NR_CURSEG_TYPE;
|
||||||
|
|
Loading…
Reference in New Issue