Lines Matching full:sb
33 static struct inode *mbt_alloc_inode(struct super_block *sb) in mbt_alloc_inode() argument
60 static void mbt_kill_sb(struct super_block *sb) in mbt_kill_sb() argument
62 generic_shutdown_super(sb); in mbt_kill_sb()
70 static int mbt_mb_init(struct super_block *sb) in mbt_mb_init() argument
75 /* needed by ext4_mb_init->bdev_nonrot(sb->s_bdev) */ in mbt_mb_init()
76 sb->s_bdev = kzalloc(sizeof(*sb->s_bdev), GFP_KERNEL); in mbt_mb_init()
77 if (sb->s_bdev == NULL) in mbt_mb_init()
80 sb->s_bdev->bd_queue = kzalloc(sizeof(struct request_queue), GFP_KERNEL); in mbt_mb_init()
81 if (sb->s_bdev->bd_queue == NULL) { in mbt_mb_init()
82 kfree(sb->s_bdev); in mbt_mb_init()
88 * new_inode(sb); in mbt_mb_init()
90 INIT_LIST_HEAD(&sb->s_inodes); in mbt_mb_init()
91 sb->s_op = &mbt_sops; in mbt_mb_init()
93 ret = ext4_mb_init(sb); in mbt_mb_init()
97 block = ext4_count_free_clusters(sb); in mbt_mb_init()
98 ret = percpu_counter_init(&EXT4_SB(sb)->s_freeclusters_counter, block, in mbt_mb_init()
103 ret = percpu_counter_init(&EXT4_SB(sb)->s_dirtyclusters_counter, 0, in mbt_mb_init()
111 percpu_counter_destroy(&EXT4_SB(sb)->s_freeclusters_counter); in mbt_mb_init()
113 ext4_mb_release(sb); in mbt_mb_init()
115 kfree(sb->s_bdev->bd_queue); in mbt_mb_init()
116 kfree(sb->s_bdev); in mbt_mb_init()
120 static void mbt_mb_release(struct super_block *sb) in mbt_mb_release() argument
122 percpu_counter_destroy(&EXT4_SB(sb)->s_dirtyclusters_counter); in mbt_mb_release()
123 percpu_counter_destroy(&EXT4_SB(sb)->s_freeclusters_counter); in mbt_mb_release()
124 ext4_mb_release(sb); in mbt_mb_release()
125 kfree(sb->s_bdev->bd_queue); in mbt_mb_release()
126 kfree(sb->s_bdev); in mbt_mb_release()
129 static int mbt_set(struct super_block *sb, void *data) in mbt_set() argument
137 struct super_block *sb; in mbt_ext4_alloc_super_block() local
144 sb = sget(&mbt_fs_type, NULL, mbt_set, 0, NULL); in mbt_ext4_alloc_super_block()
145 if (IS_ERR(sb)) in mbt_ext4_alloc_super_block()
158 sb->s_fs_info = sbi; in mbt_ext4_alloc_super_block()
160 up_write(&sb->s_umount); in mbt_ext4_alloc_super_block()
161 return sb; in mbt_ext4_alloc_super_block()
164 deactivate_locked_super(sb); in mbt_ext4_alloc_super_block()
170 static void mbt_ext4_free_super_block(struct super_block *sb) in mbt_ext4_free_super_block() argument
172 struct mbt_ext4_super_block *fsb = MBT_SB(sb); in mbt_ext4_free_super_block()
173 struct ext4_sb_info *sbi = EXT4_SB(sb); in mbt_ext4_free_super_block()
176 deactivate_super(sb); in mbt_ext4_free_super_block()
188 static void mbt_init_sb_layout(struct super_block *sb, in mbt_init_sb_layout() argument
191 struct ext4_sb_info *sbi = EXT4_SB(sb); in mbt_init_sb_layout()
194 sb->s_blocksize = 1UL << layout->blocksize_bits; in mbt_init_sb_layout()
195 sb->s_blocksize_bits = layout->blocksize_bits; in mbt_init_sb_layout()
205 sb->s_blocksize_bits - (fls(layout->desc_size) - 1); in mbt_init_sb_layout()
213 static int mbt_grp_ctx_init(struct super_block *sb, in mbt_grp_ctx_init() argument
216 ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb); in mbt_grp_ctx_init()
218 grp_ctx->bitmap_bh.b_data = kzalloc(EXT4_BLOCK_SIZE(sb), GFP_KERNEL); in mbt_grp_ctx_init()
221 mb_set_bits(grp_ctx->bitmap_bh.b_data, max, sb->s_blocksize * 8 - max); in mbt_grp_ctx_init()
222 ext4_free_group_clusters_set(sb, &grp_ctx->desc, max); in mbt_grp_ctx_init()
233 static void mbt_ctx_mark_used(struct super_block *sb, ext4_group_t group, in mbt_ctx_mark_used() argument
236 struct mbt_grp_ctx *grp_ctx = MBT_GRP_CTX(sb, group); in mbt_ctx_mark_used()
241 static void *mbt_ctx_bitmap(struct super_block *sb, ext4_group_t group) in mbt_ctx_bitmap() argument
243 struct mbt_grp_ctx *grp_ctx = MBT_GRP_CTX(sb, group); in mbt_ctx_bitmap()
249 static int mbt_ctx_init(struct super_block *sb) in mbt_ctx_init() argument
251 struct mbt_ctx *ctx = MBT_CTX(sb); in mbt_ctx_init()
252 ext4_group_t i, ngroups = ext4_get_groups_count(sb); in mbt_ctx_init()
260 if (mbt_grp_ctx_init(sb, &ctx->grp_ctx[i])) in mbt_ctx_init()
269 ext4_free_group_clusters_set(sb, &ctx->grp_ctx[0].desc, in mbt_ctx_init()
270 EXT4_CLUSTERS_PER_GROUP(sb) - 1); in mbt_ctx_init()
280 static void mbt_ctx_release(struct super_block *sb) in mbt_ctx_release() argument
282 struct mbt_ctx *ctx = MBT_CTX(sb); in mbt_ctx_release()
283 ext4_group_t i, ngroups = ext4_get_groups_count(sb); in mbt_ctx_release()
291 ext4_read_block_bitmap_nowait_stub(struct super_block *sb, ext4_group_t block_group, in ext4_read_block_bitmap_nowait_stub() argument
294 struct mbt_grp_ctx *grp_ctx = MBT_GRP_CTX(sb, block_group); in ext4_read_block_bitmap_nowait_stub()
301 static int ext4_wait_block_bitmap_stub(struct super_block *sb, in ext4_wait_block_bitmap_stub() argument
316 ext4_get_group_desc_stub(struct super_block *sb, ext4_group_t block_group, in ext4_get_group_desc_stub() argument
319 struct mbt_grp_ctx *grp_ctx = MBT_GRP_CTX(sb, block_group); in ext4_get_group_desc_stub()
328 ext4_mb_mark_context_stub(handle_t *handle, struct super_block *sb, bool state, in ext4_mb_mark_context_stub() argument
333 struct mbt_grp_ctx *grp_ctx = MBT_GRP_CTX(sb, group); in ext4_mb_mark_context_stub()
349 struct super_block *sb; in mbt_kunit_init() local
352 sb = mbt_ext4_alloc_super_block(); in mbt_kunit_init()
353 if (sb == NULL) in mbt_kunit_init()
356 mbt_init_sb_layout(sb, layout); in mbt_kunit_init()
358 ret = mbt_ctx_init(sb); in mbt_kunit_init()
360 mbt_ext4_free_super_block(sb); in mbt_kunit_init()
364 test->priv = sb; in mbt_kunit_init()
379 if (mbt_mb_init(sb) != 0) { in mbt_kunit_init()
380 mbt_ctx_release(sb); in mbt_kunit_init()
381 mbt_ext4_free_super_block(sb); in mbt_kunit_init()
390 struct super_block *sb = (struct super_block *)test->priv; in mbt_kunit_exit() local
392 mbt_mb_release(sb); in mbt_kunit_exit()
393 mbt_ctx_release(sb); in mbt_kunit_exit()
394 mbt_ext4_free_super_block(sb); in mbt_kunit_exit()
399 struct super_block *sb = (struct super_block *)test->priv; in test_new_blocks_simple() local
405 struct ext4_sb_info *sbi = EXT4_SB(sb); in test_new_blocks_simple()
411 inode->i_sb = sb; in test_new_blocks_simple()
415 ar.goal = ext4_group_first_block_no(sb, goal_group); in test_new_blocks_simple()
422 ar.goal = ext4_group_first_block_no(sb, goal_group); in test_new_blocks_simple()
429 mbt_ctx_mark_used(sb, goal_group, 0, EXT4_CLUSTERS_PER_GROUP(sb)); in test_new_blocks_simple()
430 ar.goal = ext4_group_first_block_no(sb, goal_group); in test_new_blocks_simple()
433 ext4_group_first_block_no(sb, goal_group + 1), found, in test_new_blocks_simple()
435 ext4_group_first_block_no(sb, goal_group + 1), found); in test_new_blocks_simple()
438 for (i = goal_group; i < ext4_get_groups_count(sb); i++) in test_new_blocks_simple()
439 mbt_ctx_mark_used(sb, i, 0, EXT4_CLUSTERS_PER_GROUP(sb)); in test_new_blocks_simple()
440 ar.goal = ext4_group_first_block_no(sb, goal_group); in test_new_blocks_simple()
443 ext4_group_first_block_no(sb, 0) + EXT4_C2B(sbi, 1), found, in test_new_blocks_simple()
445 ext4_group_first_block_no(sb, 0 + EXT4_C2B(sbi, 1)), found); in test_new_blocks_simple()
448 for (i = 0; i < ext4_get_groups_count(sb); i++) in test_new_blocks_simple()
449 mbt_ctx_mark_used(sb, i, 0, EXT4_CLUSTERS_PER_GROUP(sb)); in test_new_blocks_simple()
450 ar.goal = ext4_group_first_block_no(sb, goal_group); in test_new_blocks_simple()
464 mbt_generate_test_ranges(struct super_block *sb, struct test_range *ranges, in mbt_generate_test_ranges() argument
470 max = EXT4_CLUSTERS_PER_GROUP(sb) / count; in mbt_generate_test_ranges()
482 validate_free_blocks_simple(struct kunit *test, struct super_block *sb, in validate_free_blocks_simple() argument
487 ext4_grpblk_t bit, max = EXT4_CLUSTERS_PER_GROUP(sb); in validate_free_blocks_simple()
490 for (i = 0; i < ext4_get_groups_count(sb); i++) { in validate_free_blocks_simple()
494 bitmap = mbt_ctx_bitmap(sb, i); in validate_free_blocks_simple()
500 bitmap = mbt_ctx_bitmap(sb, goal_group); in validate_free_blocks_simple()
512 struct super_block *sb = (struct super_block *)test->priv; in test_free_blocks_simple_range() local
513 struct ext4_sb_info *sbi = EXT4_SB(sb); in test_free_blocks_simple_range()
520 inode->i_sb = sb; in test_free_blocks_simple_range()
525 block = ext4_group_first_block_no(sb, goal_group) + in test_free_blocks_simple_range()
528 validate_free_blocks_simple(test, sb, goal_group, start, len); in test_free_blocks_simple_range()
529 mbt_ctx_mark_used(sb, goal_group, 0, EXT4_CLUSTERS_PER_GROUP(sb)); in test_free_blocks_simple_range()
534 struct super_block *sb = (struct super_block *)test->priv; in test_free_blocks_simple() local
535 ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb); in test_free_blocks_simple()
539 for (i = 0; i < ext4_get_groups_count(sb); i++) in test_free_blocks_simple()
540 mbt_ctx_mark_used(sb, i, 0, max); in test_free_blocks_simple()
542 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT); in test_free_blocks_simple()
554 struct super_block *sb = (struct super_block *)test->priv; in test_mark_diskspace_used_range() local
567 bitmap = mbt_ctx_bitmap(sb, TEST_GOAL_GROUP); in test_mark_diskspace_used_range()
568 memset(bitmap, 0, sb->s_blocksize); in test_mark_diskspace_used_range()
572 max = EXT4_CLUSTERS_PER_GROUP(sb); in test_mark_diskspace_used_range()
583 struct super_block *sb = (struct super_block *)test->priv; in test_mark_diskspace_used() local
589 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT); in test_mark_diskspace_used()
594 inode->i_sb = sb; in test_mark_diskspace_used()
597 ac.ac_sb = sb; in test_mark_diskspace_used()
604 static void mbt_generate_buddy(struct super_block *sb, void *buddy, in mbt_generate_buddy() argument
607 struct ext4_sb_info *sbi = EXT4_SB(sb); in mbt_generate_buddy()
612 memset(buddy, 0xff, sb->s_blocksize); in mbt_generate_buddy()
614 bb_counters[MB_NUM_ORDERS(sb)])); in mbt_generate_buddy()
617 max = EXT4_CLUSTERS_PER_GROUP(sb); in mbt_generate_buddy()
638 for (order = 1; order < MB_NUM_ORDERS(sb) - 1; order++) { in mbt_generate_buddy()
658 max = EXT4_CLUSTERS_PER_GROUP(sb); in mbt_generate_buddy()
675 struct super_block *sb = (struct super_block *)test->priv; in mbt_validate_group_info() local
686 for (i = 1; i < MB_NUM_ORDERS(sb); i++) { in mbt_validate_group_info()
696 do_test_generate_buddy(struct kunit *test, struct super_block *sb, void *bitmap, in do_test_generate_buddy() argument
702 mbt_generate_buddy(sb, mbt_buddy, bitmap, mbt_grp); in do_test_generate_buddy()
704 for (i = 0; i < MB_NUM_ORDERS(sb); i++) in do_test_generate_buddy()
708 memset(ext4_buddy, 0xff, sb->s_blocksize); in do_test_generate_buddy()
709 ext4_mb_generate_buddy(sb, ext4_buddy, bitmap, TEST_GOAL_GROUP, in do_test_generate_buddy()
712 KUNIT_ASSERT_EQ(test, memcmp(mbt_buddy, ext4_buddy, sb->s_blocksize), in do_test_generate_buddy()
719 struct super_block *sb = (struct super_block *)test->priv; in test_mb_generate_buddy() local
725 bitmap = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL); in test_mb_generate_buddy()
727 expected_bb = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL); in test_mb_generate_buddy()
729 generate_bb = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL); in test_mb_generate_buddy()
732 bb_counters[MB_NUM_ORDERS(sb)]), GFP_KERNEL); in test_mb_generate_buddy()
734 generate_grp = ext4_get_group_info(sb, TEST_GOAL_GROUP); in test_mb_generate_buddy()
737 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT); in test_mb_generate_buddy()
740 do_test_generate_buddy(test, sb, bitmap, expected_bb, in test_mb_generate_buddy()
750 struct super_block *sb = (struct super_block *)test->priv; in test_mb_mark_used_range() local
762 ext4_lock_group(sb, TEST_GOAL_GROUP); in test_mb_mark_used_range()
764 ext4_unlock_group(sb, TEST_GOAL_GROUP); in test_mb_mark_used_range()
769 memset(buddy, 0xff, sb->s_blocksize); in test_mb_mark_used_range()
770 for (i = 0; i < MB_NUM_ORDERS(sb); i++) in test_mb_mark_used_range()
772 ext4_mb_generate_buddy(sb, buddy, bitmap, 0, grp); in test_mb_mark_used_range()
774 KUNIT_ASSERT_EQ(test, memcmp(buddy, e4b->bd_buddy, sb->s_blocksize), in test_mb_mark_used_range()
782 struct super_block *sb = (struct super_block *)test->priv; in test_mb_mark_used() local
790 if (sb->s_blocksize > PAGE_SIZE) in test_mb_mark_used()
793 bitmap = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL); in test_mb_mark_used()
795 buddy = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL); in test_mb_mark_used()
798 bb_counters[MB_NUM_ORDERS(sb)]), GFP_KERNEL); in test_mb_mark_used()
800 ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b); in test_mb_mark_used()
803 grp->bb_free = EXT4_CLUSTERS_PER_GROUP(sb); in test_mb_mark_used()
804 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT); in test_mb_mark_used()
817 struct super_block *sb = (struct super_block *)test->priv; in test_mb_free_blocks_range() local
824 ext4_lock_group(sb, e4b->bd_group); in test_mb_free_blocks_range()
826 ext4_unlock_group(sb, e4b->bd_group); in test_mb_free_blocks_range()
831 memset(buddy, 0xff, sb->s_blocksize); in test_mb_free_blocks_range()
832 for (i = 0; i < MB_NUM_ORDERS(sb); i++) in test_mb_free_blocks_range()
834 ext4_mb_generate_buddy(sb, buddy, bitmap, 0, grp); in test_mb_free_blocks_range()
836 KUNIT_ASSERT_EQ(test, memcmp(buddy, e4b->bd_buddy, sb->s_blocksize), in test_mb_free_blocks_range()
845 struct super_block *sb = (struct super_block *)test->priv; in test_mb_free_blocks() local
854 if (sb->s_blocksize > PAGE_SIZE) in test_mb_free_blocks()
857 bitmap = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL); in test_mb_free_blocks()
859 buddy = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL); in test_mb_free_blocks()
862 bb_counters[MB_NUM_ORDERS(sb)]), GFP_KERNEL); in test_mb_free_blocks()
864 ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b); in test_mb_free_blocks()
868 ex.fe_len = EXT4_CLUSTERS_PER_GROUP(sb); in test_mb_free_blocks()
871 ext4_lock_group(sb, TEST_GOAL_GROUP); in test_mb_free_blocks()
873 ext4_unlock_group(sb, TEST_GOAL_GROUP); in test_mb_free_blocks()
876 memset(bitmap, 0xff, sb->s_blocksize); in test_mb_free_blocks()
878 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT); in test_mb_free_blocks()
890 struct super_block *sb = (struct super_block *)test->priv; in test_mb_mark_used_cost() local
898 if (sb->s_blocksize > PAGE_SIZE) in test_mb_mark_used_cost()
901 ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b); in test_mb_mark_used_cost()
906 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT); in test_mb_mark_used_cost()
914 ext4_lock_group(sb, TEST_GOAL_GROUP); in test_mb_mark_used_cost()
916 ext4_unlock_group(sb, TEST_GOAL_GROUP); in test_mb_mark_used_cost()
925 ext4_lock_group(sb, TEST_GOAL_GROUP); in test_mb_mark_used_cost()
928 ext4_unlock_group(sb, TEST_GOAL_GROUP); in test_mb_mark_used_cost()