diff options
author | Gu Zheng <guz.fnst@cn.fujitsu.com> | 2013-10-14 06:47:11 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2013-10-17 20:44:13 -0400 |
commit | 9076a75f8e0f23ab64e2f34eb6be144e81f00a3e (patch) | |
tree | 9716694cb187d4e1603cbed53a3ff24e6bebeb28 /fs | |
parent | b1838f8952123842b00d6f8979e0f19a3b680e87 (diff) |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/f2fs/super.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 3b786c85b5cd..692f35fbae1a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -746,30 +746,47 @@ static void init_sb_info(struct f2fs_sb_info *sbi) | |||
746 | atomic_set(&sbi->nr_pages[i], 0); | 746 | atomic_set(&sbi->nr_pages[i], 0); |
747 | } | 747 | } |
748 | 748 | ||
749 | static int validate_superblock(struct super_block *sb, | 749 | /* |
750 | struct f2fs_super_block **raw_super, | 750 | * Read f2fs raw super block. |
751 | struct buffer_head **raw_super_buf, sector_t block) | 751 | * Because we have two copies of super block, so read the first one at first, |
752 | * if the first one is invalid, move to read the second one. | ||
753 | */ | ||
754 | static int read_raw_super_block(struct super_block *sb, | ||
755 | struct f2fs_super_block **raw_super, | ||
756 | struct buffer_head **raw_super_buf) | ||
752 | { | 757 | { |
753 | const char *super = (block == 0 ? "first" : "second"); | 758 | int block = 0; |
754 | 759 | ||
755 | /* read f2fs raw super block */ | 760 | retry: |
756 | *raw_super_buf = sb_bread(sb, block); | 761 | *raw_super_buf = sb_bread(sb, block); |
757 | if (!*raw_super_buf) { | 762 | if (!*raw_super_buf) { |
758 | f2fs_msg(sb, KERN_ERR, "unable to read %s superblock", | 763 | f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock", |
759 | super); | 764 | block + 1); |
760 | return -EIO; | 765 | if (block == 0) { |
766 | block++; | ||
767 | goto retry; | ||
768 | } else { | ||
769 | return -EIO; | ||
770 | } | ||
761 | } | 771 | } |
762 | 772 | ||
763 | *raw_super = (struct f2fs_super_block *) | 773 | *raw_super = (struct f2fs_super_block *) |
764 | ((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET); | 774 | ((char *)(*raw_super_buf)->b_data + F2FS_SUPER_OFFSET); |
765 | 775 | ||
766 | /* sanity checking of raw super */ | 776 | /* sanity checking of raw super */ |
767 | if (!sanity_check_raw_super(sb, *raw_super)) | 777 | if (sanity_check_raw_super(sb, *raw_super)) { |
768 | return 0; | 778 | brelse(*raw_super_buf); |
779 | f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem " | ||
780 | "in %dth superblock", block + 1); | ||
781 | if(block == 0) { | ||
782 | block++; | ||
783 | goto retry; | ||
784 | } else { | ||
785 | return -EINVAL; | ||
786 | } | ||
787 | } | ||
769 | 788 | ||
770 | f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem " | 789 | return 0; |
771 | "in %s superblock", super); | ||
772 | return -EINVAL; | ||
773 | } | 790 | } |
774 | 791 | ||
775 | static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | 792 | 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) | |||
791 | goto free_sbi; | 808 | goto free_sbi; |
792 | } | 809 | } |
793 | 810 | ||
794 | err = validate_superblock(sb, &raw_super, &raw_super_buf, 0); | 811 | err = read_raw_super_block(sb, &raw_super, &raw_super_buf); |
795 | if (err) { | 812 | if (err) |
796 | brelse(raw_super_buf); | 813 | goto free_sbi; |
797 | /* check secondary superblock when primary failed */ | 814 | |
798 | err = validate_superblock(sb, &raw_super, &raw_super_buf, 1); | ||
799 | if (err) | ||
800 | goto free_sb_buf; | ||
801 | } | ||
802 | sb->s_fs_info = sbi; | 815 | sb->s_fs_info = sbi; |
803 | /* init some FS parameters */ | 816 | /* init some FS parameters */ |
804 | sbi->active_logs = NR_CURSEG_TYPE; | 817 | sbi->active_logs = NR_CURSEG_TYPE; |