super.c (404c3bc30cb1361e1b3533643326ab472d24a618) super.c (952fc18ef9ec707ebdc16c0786ec360295e5ff15)
1/*
2 * linux/fs/ext4/super.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *

--- 3071 unchanged lines hidden (view full) ---

3080 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
3081 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT |
3082 JBD2_FEATURE_INCOMPAT_CSUM_V2);
3083 }
3084
3085 return ret;
3086}
3087
1/*
2 * linux/fs/ext4/super.c
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *

--- 3071 unchanged lines hidden (view full) ---

3080 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
3081 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT |
3082 JBD2_FEATURE_INCOMPAT_CSUM_V2);
3083 }
3084
3085 return ret;
3086}
3087
3088/*
3089 * Note: calculating the overhead so we can be compatible with
3090 * historical BSD practice is quite difficult in the face of
3091 * clusters/bigalloc. This is because multiple metadata blocks from
3092 * different block group can end up in the same allocation cluster.
3093 * Calculating the exact overhead in the face of clustered allocation
3094 * requires either O(all block bitmaps) in memory or O(number of block
3095 * groups**2) in time. We will still calculate the superblock for
3096 * older file systems --- and if we come across with a bigalloc file
3097 * system with zero in s_overhead_clusters the estimate will be close to
3098 * correct especially for very large cluster sizes --- but for newer
3099 * file systems, it's better to calculate this figure once at mkfs
3100 * time, and store it in the superblock. If the superblock value is
3101 * present (even for non-bigalloc file systems), we will use it.
3102 */
3103static int count_overhead(struct super_block *sb, ext4_group_t grp,
3104 char *buf)
3105{
3106 struct ext4_sb_info *sbi = EXT4_SB(sb);
3107 struct ext4_group_desc *gdp;
3108 ext4_fsblk_t first_block, last_block, b;
3109 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
3110 int s, j, count = 0;
3111
3112 first_block = le32_to_cpu(sbi->s_es->s_first_data_block) +
3113 (grp * EXT4_BLOCKS_PER_GROUP(sb));
3114 last_block = first_block + EXT4_BLOCKS_PER_GROUP(sb) - 1;
3115 for (i = 0; i < ngroups; i++) {
3116 gdp = ext4_get_group_desc(sb, i, NULL);
3117 b = ext4_block_bitmap(sb, gdp);
3118 if (b >= first_block && b <= last_block) {
3119 ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf);
3120 count++;
3121 }
3122 b = ext4_inode_bitmap(sb, gdp);
3123 if (b >= first_block && b <= last_block) {
3124 ext4_set_bit(EXT4_B2C(sbi, b - first_block), buf);
3125 count++;
3126 }
3127 b = ext4_inode_table(sb, gdp);
3128 if (b >= first_block && b + sbi->s_itb_per_group <= last_block)
3129 for (j = 0; j < sbi->s_itb_per_group; j++, b++) {
3130 int c = EXT4_B2C(sbi, b - first_block);
3131 ext4_set_bit(c, buf);
3132 count++;
3133 }
3134 if (i != grp)
3135 continue;
3136 s = 0;
3137 if (ext4_bg_has_super(sb, grp)) {
3138 ext4_set_bit(s++, buf);
3139 count++;
3140 }
3141 for (j = ext4_bg_num_gdb(sb, grp); j > 0; j--) {
3142 ext4_set_bit(EXT4_B2C(sbi, s++), buf);
3143 count++;
3144 }
3145 }
3146 if (!count)
3147 return 0;
3148 return EXT4_CLUSTERS_PER_GROUP(sb) -
3149 ext4_count_free(buf, EXT4_CLUSTERS_PER_GROUP(sb) / 8);
3150}
3151
3152/*
3153 * Compute the overhead and stash it in sbi->s_overhead
3154 */
3155int ext4_calculate_overhead(struct super_block *sb)
3156{
3157 struct ext4_sb_info *sbi = EXT4_SB(sb);
3158 struct ext4_super_block *es = sbi->s_es;
3159 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
3160 ext4_fsblk_t overhead = 0;
3161 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
3162
3163 memset(buf, 0, PAGE_SIZE);
3164 if (!buf)
3165 return -ENOMEM;
3166
3167 /*
3168 * Compute the overhead (FS structures). This is constant
3169 * for a given filesystem unless the number of block groups
3170 * changes so we cache the previous value until it does.
3171 */
3172
3173 /*
3174 * All of the blocks before first_data_block are overhead
3175 */
3176 overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block));
3177
3178 /*
3179 * Add the overhead found in each block group
3180 */
3181 for (i = 0; i < ngroups; i++) {
3182 int blks;
3183
3184 blks = count_overhead(sb, i, buf);
3185 overhead += blks;
3186 if (blks)
3187 memset(buf, 0, PAGE_SIZE);
3188 cond_resched();
3189 }
3190 sbi->s_overhead = overhead;
3191 smp_wmb();
3192 free_page((unsigned long) buf);
3193 return 0;
3194}
3195
3088static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3089{
3090 char *orig_data = kstrdup(data, GFP_KERNEL);
3091 struct buffer_head *bh;
3092 struct ext4_super_block *es = NULL;
3093 struct ext4_sb_info *sbi;
3094 ext4_fsblk_t block;
3095 ext4_fsblk_t sb_block = get_sb_block(&data);

--- 634 unchanged lines hidden (view full) ---

3730 percpu_counter_set(&sbi->s_freeinodes_counter,
3731 ext4_count_free_inodes(sb));
3732 percpu_counter_set(&sbi->s_dirs_counter,
3733 ext4_count_dirs(sb));
3734 percpu_counter_set(&sbi->s_dirtyclusters_counter, 0);
3735
3736no_journal:
3737 /*
3196static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3197{
3198 char *orig_data = kstrdup(data, GFP_KERNEL);
3199 struct buffer_head *bh;
3200 struct ext4_super_block *es = NULL;
3201 struct ext4_sb_info *sbi;
3202 ext4_fsblk_t block;
3203 ext4_fsblk_t sb_block = get_sb_block(&data);

--- 634 unchanged lines hidden (view full) ---

3838 percpu_counter_set(&sbi->s_freeinodes_counter,
3839 ext4_count_free_inodes(sb));
3840 percpu_counter_set(&sbi->s_dirs_counter,
3841 ext4_count_dirs(sb));
3842 percpu_counter_set(&sbi->s_dirtyclusters_counter, 0);
3843
3844no_journal:
3845 /*
3846 * Get the # of file system overhead blocks from the
3847 * superblock if present.
3848 */
3849 if (es->s_overhead_clusters)
3850 sbi->s_overhead = le32_to_cpu(es->s_overhead_clusters);
3851 else {
3852 ret = ext4_calculate_overhead(sb);
3853 if (ret)
3854 goto failed_mount_wq;
3855 }
3856
3857 /*
3738 * The maximum number of concurrent works can be high and
3739 * concurrency isn't really necessary. Limit it to 1.
3740 */
3741 EXT4_SB(sb)->dio_unwritten_wq =
3742 alloc_workqueue("ext4-dio-unwritten", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
3743 if (!EXT4_SB(sb)->dio_unwritten_wq) {
3744 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n");
3745 goto failed_mount_wq;

--- 849 unchanged lines hidden (view full) ---

4595 sbi->s_qf_names[i] = old_opts.s_qf_names[i];
4596 }
4597#endif
4598 unlock_super(sb);
4599 kfree(orig_data);
4600 return err;
4601}
4602
3858 * The maximum number of concurrent works can be high and
3859 * concurrency isn't really necessary. Limit it to 1.
3860 */
3861 EXT4_SB(sb)->dio_unwritten_wq =
3862 alloc_workqueue("ext4-dio-unwritten", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
3863 if (!EXT4_SB(sb)->dio_unwritten_wq) {
3864 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n");
3865 goto failed_mount_wq;

--- 849 unchanged lines hidden (view full) ---

4715 sbi->s_qf_names[i] = old_opts.s_qf_names[i];
4716 }
4717#endif
4718 unlock_super(sb);
4719 kfree(orig_data);
4720 return err;
4721}
4722
4603/*
4604 * Note: calculating the overhead so we can be compatible with
4605 * historical BSD practice is quite difficult in the face of
4606 * clusters/bigalloc. This is because multiple metadata blocks from
4607 * different block group can end up in the same allocation cluster.
4608 * Calculating the exact overhead in the face of clustered allocation
4609 * requires either O(all block bitmaps) in memory or O(number of block
4610 * groups**2) in time. We will still calculate the superblock for
4611 * older file systems --- and if we come across with a bigalloc file
4612 * system with zero in s_overhead_clusters the estimate will be close to
4613 * correct especially for very large cluster sizes --- but for newer
4614 * file systems, it's better to calculate this figure once at mkfs
4615 * time, and store it in the superblock. If the superblock value is
4616 * present (even for non-bigalloc file systems), we will use it.
4617 */
4618static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
4619{
4620 struct super_block *sb = dentry->d_sb;
4621 struct ext4_sb_info *sbi = EXT4_SB(sb);
4622 struct ext4_super_block *es = sbi->s_es;
4723static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
4724{
4725 struct super_block *sb = dentry->d_sb;
4726 struct ext4_sb_info *sbi = EXT4_SB(sb);
4727 struct ext4_super_block *es = sbi->s_es;
4623 struct ext4_group_desc *gdp;
4728 ext4_fsblk_t overhead = 0;
4624 u64 fsid;
4625 s64 bfree;
4626
4729 u64 fsid;
4730 s64 bfree;
4731
4627 if (test_opt(sb, MINIX_DF)) {
4628 sbi->s_overhead_last = 0;
4629 } else if (es->s_overhead_clusters) {
4630 sbi->s_overhead_last = le32_to_cpu(es->s_overhead_clusters);
4631 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
4632 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
4633 ext4_fsblk_t overhead = 0;
4732 if (!test_opt(sb, MINIX_DF))
4733 overhead = sbi->s_overhead;
4634
4734
4635 /*
4636 * Compute the overhead (FS structures). This is constant
4637 * for a given filesystem unless the number of block groups
4638 * changes so we cache the previous value until it does.
4639 */
4640
4641 /*
4642 * All of the blocks before first_data_block are
4643 * overhead
4644 */
4645 overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block));
4646
4647 /*
4648 * Add the overhead found in each block group
4649 */
4650 for (i = 0; i < ngroups; i++) {
4651 gdp = ext4_get_group_desc(sb, i, NULL);
4652 overhead += ext4_num_overhead_clusters(sb, i, gdp);
4653 cond_resched();
4654 }
4655 sbi->s_overhead_last = overhead;
4656 smp_wmb();
4657 sbi->s_blocks_last = ext4_blocks_count(es);
4658 }
4659
4660 buf->f_type = EXT4_SUPER_MAGIC;
4661 buf->f_bsize = sb->s_blocksize;
4735 buf->f_type = EXT4_SUPER_MAGIC;
4736 buf->f_bsize = sb->s_blocksize;
4662 buf->f_blocks = (ext4_blocks_count(es) -
4663 EXT4_C2B(sbi, sbi->s_overhead_last));
4737 buf->f_blocks = ext4_blocks_count(es) - EXT4_C2B(sbi, sbi->s_overhead);
4664 bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) -
4665 percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter);
4666 /* prevent underflow in case that few free space is available */
4667 buf->f_bfree = EXT4_C2B(sbi, max_t(s64, bfree, 0));
4668 buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es);
4669 if (buf->f_bfree < ext4_r_blocks_count(es))
4670 buf->f_bavail = 0;
4671 buf->f_files = le32_to_cpu(es->s_inodes_count);

--- 484 unchanged lines hidden ---
4738 bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) -
4739 percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter);
4740 /* prevent underflow in case that few free space is available */
4741 buf->f_bfree = EXT4_C2B(sbi, max_t(s64, bfree, 0));
4742 buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es);
4743 if (buf->f_bfree < ext4_r_blocks_count(es))
4744 buf->f_bavail = 0;
4745 buf->f_files = le32_to_cpu(es->s_inodes_count);

--- 484 unchanged lines hidden ---