super.c (f5a53edcf01eae21dc3ef1845515229e8459e5cc) | super.c (d41003513e61dd9d4974cb441d30b63650b85654) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * fs/f2fs/super.c 4 * 5 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 6 * http://www.samsung.com/ 7 */ 8#include <linux/module.h> --- 2590 unchanged lines hidden (view full) --- 2599 } 2600 2601 if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) { 2602 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", 2603 segment_count, le64_to_cpu(raw_super->block_count)); 2604 return -EFSCORRUPTED; 2605 } 2606 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * fs/f2fs/super.c 4 * 5 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 6 * http://www.samsung.com/ 7 */ 8#include <linux/module.h> --- 2590 unchanged lines hidden (view full) --- 2599 } 2600 2601 if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) { 2602 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", 2603 segment_count, le64_to_cpu(raw_super->block_count)); 2604 return -EFSCORRUPTED; 2605 } 2606 |
2607 if (RDEV(0).path[0]) { 2608 block_t dev_seg_count = le32_to_cpu(RDEV(0).total_segments); 2609 int i = 1; 2610 2611 while (i < MAX_DEVICES && RDEV(i).path[0]) { 2612 dev_seg_count += le32_to_cpu(RDEV(i).total_segments); 2613 i++; 2614 } 2615 if (segment_count != dev_seg_count) { 2616 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)", 2617 segment_count, dev_seg_count); 2618 return -EFSCORRUPTED; 2619 } 2620 } 2621 | |
2622 if (secs_per_zone > total_sections || !secs_per_zone) { 2623 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", 2624 secs_per_zone, total_sections); 2625 return -EFSCORRUPTED; 2626 } 2627 if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION || 2628 raw_super->hot_ext_count > F2FS_MAX_EXTENSION || 2629 (le32_to_cpu(raw_super->extension_count) + --- 218 unchanged lines hidden (view full) --- 2848 mutex_init(&sbi->umount_mutex); 2849 init_rwsem(&sbi->io_order_lock); 2850 spin_lock_init(&sbi->cp_lock); 2851 2852 sbi->dirty_device = 0; 2853 spin_lock_init(&sbi->dev_lock); 2854 2855 init_rwsem(&sbi->sb_lock); | 2607 if (secs_per_zone > total_sections || !secs_per_zone) { 2608 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", 2609 secs_per_zone, total_sections); 2610 return -EFSCORRUPTED; 2611 } 2612 if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION || 2613 raw_super->hot_ext_count > F2FS_MAX_EXTENSION || 2614 (le32_to_cpu(raw_super->extension_count) + --- 218 unchanged lines hidden (view full) --- 2833 mutex_init(&sbi->umount_mutex); 2834 init_rwsem(&sbi->io_order_lock); 2835 spin_lock_init(&sbi->cp_lock); 2836 2837 sbi->dirty_device = 0; 2838 spin_lock_init(&sbi->dev_lock); 2839 2840 init_rwsem(&sbi->sb_lock); |
2856 init_rwsem(&sbi->pin_sem); | |
2857} 2858 2859static int init_percpu_info(struct f2fs_sb_info *sbi) 2860{ 2861 int err; 2862 2863 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); 2864 if (err) 2865 return err; 2866 2867 err = percpu_counter_init(&sbi->total_valid_inode_count, 0, 2868 GFP_KERNEL); 2869 if (err) 2870 percpu_counter_destroy(&sbi->alloc_valid_block_count); 2871 2872 return err; 2873} 2874 2875#ifdef CONFIG_BLK_DEV_ZONED | 2841} 2842 2843static int init_percpu_info(struct f2fs_sb_info *sbi) 2844{ 2845 int err; 2846 2847 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); 2848 if (err) 2849 return err; 2850 2851 err = percpu_counter_init(&sbi->total_valid_inode_count, 0, 2852 GFP_KERNEL); 2853 if (err) 2854 percpu_counter_destroy(&sbi->alloc_valid_block_count); 2855 2856 return err; 2857} 2858 2859#ifdef CONFIG_BLK_DEV_ZONED |
2860static int f2fs_report_zone_cb(struct blk_zone *zone, unsigned int idx, 2861 void *data) 2862{ 2863 struct f2fs_dev_info *dev = data; 2864 2865 if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) 2866 set_bit(idx, dev->blkz_seq); 2867 return 0; 2868} 2869 |
|
2876static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) 2877{ 2878 struct block_device *bdev = FDEV(devi).bdev; 2879 sector_t nr_sectors = bdev->bd_part->nr_sects; | 2870static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) 2871{ 2872 struct block_device *bdev = FDEV(devi).bdev; 2873 sector_t nr_sectors = bdev->bd_part->nr_sects; |
2880 sector_t sector = 0; 2881 struct blk_zone *zones; 2882 unsigned int i, nr_zones; 2883 unsigned int n = 0; 2884 int err = -EIO; | 2874 int ret; |
2885 2886 if (!f2fs_sb_has_blkzoned(sbi)) 2887 return 0; 2888 2889 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != 2890 SECTOR_TO_BLOCK(bdev_zone_sectors(bdev))) 2891 return -EINVAL; 2892 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)); --- 8 unchanged lines hidden (view full) --- 2901 2902 FDEV(devi).blkz_seq = f2fs_kzalloc(sbi, 2903 BITS_TO_LONGS(FDEV(devi).nr_blkz) 2904 * sizeof(unsigned long), 2905 GFP_KERNEL); 2906 if (!FDEV(devi).blkz_seq) 2907 return -ENOMEM; 2908 | 2875 2876 if (!f2fs_sb_has_blkzoned(sbi)) 2877 return 0; 2878 2879 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != 2880 SECTOR_TO_BLOCK(bdev_zone_sectors(bdev))) 2881 return -EINVAL; 2882 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)); --- 8 unchanged lines hidden (view full) --- 2891 2892 FDEV(devi).blkz_seq = f2fs_kzalloc(sbi, 2893 BITS_TO_LONGS(FDEV(devi).nr_blkz) 2894 * sizeof(unsigned long), 2895 GFP_KERNEL); 2896 if (!FDEV(devi).blkz_seq) 2897 return -ENOMEM; 2898 |
2909#define F2FS_REPORT_NR_ZONES 4096 2910 2911 zones = f2fs_kzalloc(sbi, 2912 array_size(F2FS_REPORT_NR_ZONES, 2913 sizeof(struct blk_zone)), 2914 GFP_KERNEL); 2915 if (!zones) 2916 return -ENOMEM; 2917 | |
2918 /* Get block zones type */ | 2899 /* Get block zones type */ |
2919 while (zones && sector < nr_sectors) { | 2900 ret = blkdev_report_zones(bdev, 0, BLK_ALL_ZONES, f2fs_report_zone_cb, 2901 &FDEV(devi)); 2902 if (ret < 0) 2903 return ret; |
2920 | 2904 |
2921 nr_zones = F2FS_REPORT_NR_ZONES; 2922 err = blkdev_report_zones(bdev, sector, zones, &nr_zones); 2923 if (err) 2924 break; 2925 if (!nr_zones) { 2926 err = -EIO; 2927 break; 2928 } 2929 2930 for (i = 0; i < nr_zones; i++) { 2931 if (zones[i].type != BLK_ZONE_TYPE_CONVENTIONAL) 2932 set_bit(n, FDEV(devi).blkz_seq); 2933 sector += zones[i].len; 2934 n++; 2935 } 2936 } 2937 2938 kvfree(zones); 2939 2940 return err; | 2905 return 0; |
2941} 2942#endif 2943 2944/* 2945 * Read f2fs raw super block. 2946 * Because we have two copies of super block, so read both of them 2947 * to get the first valid one. If any one of them is broken, we pass 2948 * them recovery flag back to the caller. --- 13 unchanged lines hidden (view full) --- 2962 return -ENOMEM; 2963 2964 for (block = 0; block < 2; block++) { 2965 bh = sb_bread(sb, block); 2966 if (!bh) { 2967 f2fs_err(sbi, "Unable to read %dth superblock", 2968 block + 1); 2969 err = -EIO; | 2906} 2907#endif 2908 2909/* 2910 * Read f2fs raw super block. 2911 * Because we have two copies of super block, so read both of them 2912 * to get the first valid one. If any one of them is broken, we pass 2913 * them recovery flag back to the caller. --- 13 unchanged lines hidden (view full) --- 2927 return -ENOMEM; 2928 2929 for (block = 0; block < 2; block++) { 2930 bh = sb_bread(sb, block); 2931 if (!bh) { 2932 f2fs_err(sbi, "Unable to read %dth superblock", 2933 block + 1); 2934 err = -EIO; |
2970 *recovery = 1; | |
2971 continue; 2972 } 2973 2974 /* sanity checking of raw super */ 2975 err = sanity_check_raw_super(sbi, bh); 2976 if (err) { 2977 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", 2978 block + 1); 2979 brelse(bh); | 2935 continue; 2936 } 2937 2938 /* sanity checking of raw super */ 2939 err = sanity_check_raw_super(sbi, bh); 2940 if (err) { 2941 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", 2942 block + 1); 2943 brelse(bh); |
2980 *recovery = 1; | |
2981 continue; 2982 } 2983 2984 if (!*raw_super) { 2985 memcpy(super, bh->b_data + F2FS_SUPER_OFFSET, 2986 sizeof(*super)); 2987 *valid_super_block = block; 2988 *raw_super = super; 2989 } 2990 brelse(bh); 2991 } 2992 | 2944 continue; 2945 } 2946 2947 if (!*raw_super) { 2948 memcpy(super, bh->b_data + F2FS_SUPER_OFFSET, 2949 sizeof(*super)); 2950 *valid_super_block = block; 2951 *raw_super = super; 2952 } 2953 brelse(bh); 2954 } 2955 |
2956 /* Fail to read any one of the superblocks*/ 2957 if (err < 0) 2958 *recovery = 1; 2959 |
|
2993 /* No valid superblock */ 2994 if (!*raw_super) 2995 kvfree(super); 2996 else 2997 err = 0; 2998 2999 return err; 3000} --- 337 unchanged lines hidden (view full) --- 3338 } 3339 3340 for (j = HOT; j < n; j++) { 3341 init_rwsem(&sbi->write_io[i][j].io_rwsem); 3342 sbi->write_io[i][j].sbi = sbi; 3343 sbi->write_io[i][j].bio = NULL; 3344 spin_lock_init(&sbi->write_io[i][j].io_lock); 3345 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); | 2960 /* No valid superblock */ 2961 if (!*raw_super) 2962 kvfree(super); 2963 else 2964 err = 0; 2965 2966 return err; 2967} --- 337 unchanged lines hidden (view full) --- 3305 } 3306 3307 for (j = HOT; j < n; j++) { 3308 init_rwsem(&sbi->write_io[i][j].io_rwsem); 3309 sbi->write_io[i][j].sbi = sbi; 3310 sbi->write_io[i][j].bio = NULL; 3311 spin_lock_init(&sbi->write_io[i][j].io_lock); 3312 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); |
3346 INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list); 3347 init_rwsem(&sbi->write_io[i][j].bio_list_lock); | |
3348 } 3349 } 3350 3351 init_rwsem(&sbi->cp_rwsem); 3352 init_rwsem(&sbi->quota_sem); 3353 init_waitqueue_head(&sbi->cp_wait); 3354 init_sb_info(sbi); 3355 --- 395 unchanged lines hidden (view full) --- 3751 goto free_sysfs; 3752 err = register_filesystem(&f2fs_fs_type); 3753 if (err) 3754 goto free_shrinker; 3755 f2fs_create_root_stats(); 3756 err = f2fs_init_post_read_processing(); 3757 if (err) 3758 goto free_root_stats; | 3313 } 3314 } 3315 3316 init_rwsem(&sbi->cp_rwsem); 3317 init_rwsem(&sbi->quota_sem); 3318 init_waitqueue_head(&sbi->cp_wait); 3319 init_sb_info(sbi); 3320 --- 395 unchanged lines hidden (view full) --- 3716 goto free_sysfs; 3717 err = register_filesystem(&f2fs_fs_type); 3718 if (err) 3719 goto free_shrinker; 3720 f2fs_create_root_stats(); 3721 err = f2fs_init_post_read_processing(); 3722 if (err) 3723 goto free_root_stats; |
3759 err = f2fs_init_bio_entry_cache(); 3760 if (err) 3761 goto free_post_read; | |
3762 return 0; 3763 | 3724 return 0; 3725 |
3764free_post_read: 3765 f2fs_destroy_post_read_processing(); | |
3766free_root_stats: 3767 f2fs_destroy_root_stats(); 3768 unregister_filesystem(&f2fs_fs_type); 3769free_shrinker: 3770 unregister_shrinker(&f2fs_shrinker_info); 3771free_sysfs: 3772 f2fs_exit_sysfs(); 3773free_extent_cache: --- 7 unchanged lines hidden (view full) --- 3781free_inodecache: 3782 destroy_inodecache(); 3783fail: 3784 return err; 3785} 3786 3787static void __exit exit_f2fs_fs(void) 3788{ | 3726free_root_stats: 3727 f2fs_destroy_root_stats(); 3728 unregister_filesystem(&f2fs_fs_type); 3729free_shrinker: 3730 unregister_shrinker(&f2fs_shrinker_info); 3731free_sysfs: 3732 f2fs_exit_sysfs(); 3733free_extent_cache: --- 7 unchanged lines hidden (view full) --- 3741free_inodecache: 3742 destroy_inodecache(); 3743fail: 3744 return err; 3745} 3746 3747static void __exit exit_f2fs_fs(void) 3748{ |
3789 f2fs_destroy_bio_entry_cache(); | |
3790 f2fs_destroy_post_read_processing(); 3791 f2fs_destroy_root_stats(); 3792 unregister_filesystem(&f2fs_fs_type); 3793 unregister_shrinker(&f2fs_shrinker_info); 3794 f2fs_exit_sysfs(); 3795 f2fs_destroy_extent_cache(); 3796 f2fs_destroy_checkpoint_caches(); 3797 f2fs_destroy_segment_manager_caches(); --- 12 unchanged lines hidden --- | 3749 f2fs_destroy_post_read_processing(); 3750 f2fs_destroy_root_stats(); 3751 unregister_filesystem(&f2fs_fs_type); 3752 unregister_shrinker(&f2fs_shrinker_info); 3753 f2fs_exit_sysfs(); 3754 f2fs_destroy_extent_cache(); 3755 f2fs_destroy_checkpoint_caches(); 3756 f2fs_destroy_segment_manager_caches(); --- 12 unchanged lines hidden --- |