Lines Matching refs:osb
53 static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
60 static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
66 static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
71 static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
75 static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
117 unsigned int ocfs2_la_default_mb(struct ocfs2_super *osb) in ocfs2_la_default_mb() argument
123 struct super_block *sb = osb->sb; in ocfs2_la_default_mb()
125 gd_mb = ocfs2_clusters_to_megabytes(osb->sb, in ocfs2_la_default_mb()
126 8 * ocfs2_group_bitmap_size(sb, 0, osb->s_feature_incompat)); in ocfs2_la_default_mb()
133 if ((sb->s_blocksize == 512 && osb->s_clustersize <= 8192) in ocfs2_la_default_mb()
134 || (sb->s_blocksize == 1024 && osb->s_clustersize == 4096)) in ocfs2_la_default_mb()
180 megs_per_slot = osb->osb_clusters_at_boot / osb->max_slots; in ocfs2_la_default_mb()
181 megs_per_slot = ocfs2_clusters_to_megabytes(osb->sb, megs_per_slot); in ocfs2_la_default_mb()
187 la_max_mb = ocfs2_clusters_to_megabytes(osb->sb, in ocfs2_la_default_mb()
195 void ocfs2_la_set_sizes(struct ocfs2_super *osb, int requested_mb) in ocfs2_la_set_sizes() argument
197 struct super_block *sb = osb->sb; in ocfs2_la_set_sizes()
198 unsigned int la_default_mb = ocfs2_la_default_mb(osb); in ocfs2_la_set_sizes()
208 osb->local_alloc_default_bits = in ocfs2_la_set_sizes()
212 osb->local_alloc_default_bits = in ocfs2_la_set_sizes()
215 osb->local_alloc_default_bits = in ocfs2_la_set_sizes()
219 osb->local_alloc_bits = osb->local_alloc_default_bits; in ocfs2_la_set_sizes()
222 static inline int ocfs2_la_state_enabled(struct ocfs2_super *osb) in ocfs2_la_state_enabled() argument
224 return (osb->local_alloc_state == OCFS2_LA_THROTTLED || in ocfs2_la_state_enabled()
225 osb->local_alloc_state == OCFS2_LA_ENABLED); in ocfs2_la_state_enabled()
228 void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb, in ocfs2_local_alloc_seen_free_bits() argument
231 spin_lock(&osb->osb_lock); in ocfs2_local_alloc_seen_free_bits()
232 if (osb->local_alloc_state == OCFS2_LA_DISABLED || in ocfs2_local_alloc_seen_free_bits()
233 osb->local_alloc_state == OCFS2_LA_THROTTLED) in ocfs2_local_alloc_seen_free_bits()
234 if (num_clusters >= osb->local_alloc_default_bits) { in ocfs2_local_alloc_seen_free_bits()
235 cancel_delayed_work(&osb->la_enable_wq); in ocfs2_local_alloc_seen_free_bits()
236 osb->local_alloc_state = OCFS2_LA_ENABLED; in ocfs2_local_alloc_seen_free_bits()
238 spin_unlock(&osb->osb_lock); in ocfs2_local_alloc_seen_free_bits()
243 struct ocfs2_super *osb = in ocfs2_la_enable_worker() local
246 spin_lock(&osb->osb_lock); in ocfs2_la_enable_worker()
247 osb->local_alloc_state = OCFS2_LA_ENABLED; in ocfs2_la_enable_worker()
248 spin_unlock(&osb->osb_lock); in ocfs2_la_enable_worker()
258 int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits) in ocfs2_alloc_should_use_local() argument
263 spin_lock(&osb->osb_lock); in ocfs2_alloc_should_use_local()
264 la_bits = osb->local_alloc_bits; in ocfs2_alloc_should_use_local()
266 if (!ocfs2_la_state_enabled(osb)) in ocfs2_alloc_should_use_local()
279 (unsigned long long)bits, osb->local_alloc_state, la_bits, ret); in ocfs2_alloc_should_use_local()
280 spin_unlock(&osb->osb_lock); in ocfs2_alloc_should_use_local()
284 int ocfs2_load_local_alloc(struct ocfs2_super *osb) in ocfs2_load_local_alloc() argument
293 if (osb->local_alloc_bits == 0) in ocfs2_load_local_alloc()
296 if (osb->local_alloc_bits >= osb->bitmap_cpg) { in ocfs2_load_local_alloc()
299 osb->local_alloc_bits, (osb->bitmap_cpg - 1)); in ocfs2_load_local_alloc()
300 osb->local_alloc_bits = in ocfs2_load_local_alloc()
301 ocfs2_megabytes_to_clusters(osb->sb, in ocfs2_load_local_alloc()
302 ocfs2_la_default_mb(osb)); in ocfs2_load_local_alloc()
306 inode = ocfs2_get_system_file_inode(osb, LOCAL_ALLOC_SYSTEM_INODE, in ocfs2_load_local_alloc()
307 osb->slot_num); in ocfs2_load_local_alloc()
355 osb->local_alloc_bh = alloc_bh; in ocfs2_load_local_alloc()
356 osb->local_alloc_state = OCFS2_LA_ENABLED; in ocfs2_load_local_alloc()
364 trace_ocfs2_load_local_alloc(osb->local_alloc_bits); in ocfs2_load_local_alloc()
378 void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) in ocfs2_shutdown_local_alloc() argument
389 cancel_delayed_work(&osb->la_enable_wq); in ocfs2_shutdown_local_alloc()
392 if (osb->local_alloc_state == OCFS2_LA_UNUSED) in ocfs2_shutdown_local_alloc()
396 ocfs2_get_system_file_inode(osb, in ocfs2_shutdown_local_alloc()
398 osb->slot_num); in ocfs2_shutdown_local_alloc()
405 osb->local_alloc_state = OCFS2_LA_DISABLED; in ocfs2_shutdown_local_alloc()
407 ocfs2_resmap_uninit(&osb->osb_la_resmap); in ocfs2_shutdown_local_alloc()
409 main_bm_inode = ocfs2_get_system_file_inode(osb, in ocfs2_shutdown_local_alloc()
427 handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS); in ocfs2_shutdown_local_alloc()
434 bh = osb->local_alloc_bh; in ocfs2_shutdown_local_alloc()
455 osb->local_alloc_bh = NULL; in ocfs2_shutdown_local_alloc()
456 osb->local_alloc_state = OCFS2_LA_UNUSED; in ocfs2_shutdown_local_alloc()
458 status = ocfs2_sync_local_to_main(osb, handle, alloc_copy, in ocfs2_shutdown_local_alloc()
464 ocfs2_commit_trans(osb, handle); in ocfs2_shutdown_local_alloc()
489 int ocfs2_begin_local_alloc_recovery(struct ocfs2_super *osb, in ocfs2_begin_local_alloc_recovery() argument
502 inode = ocfs2_get_system_file_inode(osb, in ocfs2_begin_local_alloc_recovery()
530 ocfs2_compute_meta_ecc(osb->sb, alloc_bh->b_data, &alloc->i_check); in ocfs2_begin_local_alloc_recovery()
531 status = ocfs2_write_block(osb, alloc_bh, INODE_CACHE(inode)); in ocfs2_begin_local_alloc_recovery()
559 int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb, in ocfs2_complete_local_alloc_recovery() argument
567 main_bm_inode = ocfs2_get_system_file_inode(osb, in ocfs2_complete_local_alloc_recovery()
584 handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS); in ocfs2_complete_local_alloc_recovery()
595 status = ocfs2_sync_local_to_main(osb, handle, alloc, in ocfs2_complete_local_alloc_recovery()
600 ocfs2_commit_trans(osb, handle); in ocfs2_complete_local_alloc_recovery()
614 ocfs2_init_steal_slots(osb); in ocfs2_complete_local_alloc_recovery()
627 int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb, in ocfs2_reserve_local_alloc_bits() argument
639 ocfs2_get_system_file_inode(osb, in ocfs2_reserve_local_alloc_bits()
641 osb->slot_num); in ocfs2_reserve_local_alloc_bits()
654 spin_lock(&osb->osb_lock); in ocfs2_reserve_local_alloc_bits()
655 if (!ocfs2_la_state_enabled(osb) || in ocfs2_reserve_local_alloc_bits()
656 (bits_wanted > osb->local_alloc_bits)) { in ocfs2_reserve_local_alloc_bits()
657 spin_unlock(&osb->osb_lock); in ocfs2_reserve_local_alloc_bits()
661 spin_unlock(&osb->osb_lock); in ocfs2_reserve_local_alloc_bits()
663 alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; in ocfs2_reserve_local_alloc_bits()
668 ocfs2_error(osb->sb, "local alloc inode %llu says it has %u used bits, but a count shows %u\n", in ocfs2_reserve_local_alloc_bits()
682 ocfs2_local_alloc_slide_window(osb, local_alloc_inode); in ocfs2_reserve_local_alloc_bits()
696 if (!ocfs2_la_state_enabled(osb)) in ocfs2_reserve_local_alloc_bits()
707 ac->ac_alloc_slot = osb->slot_num; in ocfs2_reserve_local_alloc_bits()
709 get_bh(osb->local_alloc_bh); in ocfs2_reserve_local_alloc_bits()
710 ac->ac_bh = osb->local_alloc_bh; in ocfs2_reserve_local_alloc_bits()
720 bits_wanted, osb->slot_num, status); in ocfs2_reserve_local_alloc_bits()
727 int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb, in ocfs2_claim_local_alloc_bits() argument
743 alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; in ocfs2_claim_local_alloc_bits()
746 start = ocfs2_local_alloc_find_clear_bits(osb, alloc, &bits_wanted, in ocfs2_claim_local_alloc_bits()
761 osb->local_alloc_bh, in ocfs2_claim_local_alloc_bits()
768 ocfs2_resmap_claimed_bits(&osb->osb_la_resmap, ac->ac_resv, start, in ocfs2_claim_local_alloc_bits()
775 ocfs2_journal_dirty(handle, osb->local_alloc_bh); in ocfs2_claim_local_alloc_bits()
783 int ocfs2_free_local_alloc_bits(struct ocfs2_super *osb, in ocfs2_free_local_alloc_bits() argument
799 alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; in ocfs2_free_local_alloc_bits()
808 osb->local_alloc_bh, in ocfs2_free_local_alloc_bits()
819 ocfs2_journal_dirty(handle, osb->local_alloc_bh); in ocfs2_free_local_alloc_bits()
836 static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb, in ocfs2_local_alloc_find_clear_bits() argument
845 struct ocfs2_reservation_map *resmap = &osb->osb_la_resmap; in ocfs2_local_alloc_find_clear_bits()
870 BUG_ON(osb->osb_resv_level != 0); in ocfs2_local_alloc_find_clear_bits()
962 static int ocfs2_sync_local_to_main(struct ocfs2_super *osb, in ocfs2_sync_local_to_main() argument
988 la_start_blk = ocfs2_clusters_to_blocks(osb->sb, in ocfs2_sync_local_to_main()
1003 ocfs2_clusters_to_blocks(osb->sb, in ocfs2_sync_local_to_main()
1054 static int ocfs2_recalc_la_window(struct ocfs2_super *osb, in ocfs2_recalc_la_window() argument
1060 spin_lock(&osb->osb_lock); in ocfs2_recalc_la_window()
1061 if (osb->local_alloc_state == OCFS2_LA_DISABLED) { in ocfs2_recalc_la_window()
1062 WARN_ON_ONCE(osb->local_alloc_state == OCFS2_LA_DISABLED); in ocfs2_recalc_la_window()
1076 bits = osb->local_alloc_bits >> 1; in ocfs2_recalc_la_window()
1077 if (bits > ocfs2_megabytes_to_clusters(osb->sb, 1)) { in ocfs2_recalc_la_window()
1085 osb->local_alloc_state = OCFS2_LA_THROTTLED; in ocfs2_recalc_la_window()
1086 osb->local_alloc_bits = bits; in ocfs2_recalc_la_window()
1088 osb->local_alloc_state = OCFS2_LA_DISABLED; in ocfs2_recalc_la_window()
1090 queue_delayed_work(ocfs2_wq, &osb->la_enable_wq, in ocfs2_recalc_la_window()
1101 if (osb->local_alloc_state != OCFS2_LA_THROTTLED) in ocfs2_recalc_la_window()
1102 osb->local_alloc_bits = osb->local_alloc_default_bits; in ocfs2_recalc_la_window()
1105 state = osb->local_alloc_state; in ocfs2_recalc_la_window()
1106 spin_unlock(&osb->osb_lock); in ocfs2_recalc_la_window()
1111 static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, in ocfs2_local_alloc_reserve_for_window() argument
1126 (*ac)->ac_bits_wanted = osb->local_alloc_bits; in ocfs2_local_alloc_reserve_for_window()
1127 status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac); in ocfs2_local_alloc_reserve_for_window()
1129 if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_ENOSPC) == in ocfs2_local_alloc_reserve_for_window()
1161 static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb, in ocfs2_local_alloc_new_window() argument
1170 alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; in ocfs2_local_alloc_new_window()
1175 osb->local_alloc_bits); in ocfs2_local_alloc_new_window()
1180 ac->ac_last_group = osb->la_last_gd; in ocfs2_local_alloc_new_window()
1185 status = ocfs2_claim_clusters(handle, ac, osb->local_alloc_bits, in ocfs2_local_alloc_new_window()
1194 if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_FRAGMENTED) == in ocfs2_local_alloc_new_window()
1198 ac->ac_bits_wanted = osb->local_alloc_bits; in ocfs2_local_alloc_new_window()
1200 osb->local_alloc_bits, in ocfs2_local_alloc_new_window()
1211 spin_lock(&osb->osb_lock); in ocfs2_local_alloc_new_window()
1212 osb->local_alloc_bits = cluster_count; in ocfs2_local_alloc_new_window()
1213 spin_unlock(&osb->osb_lock); in ocfs2_local_alloc_new_window()
1222 osb->la_last_gd = ac->ac_last_group; in ocfs2_local_alloc_new_window()
1234 ocfs2_resmap_restart(&osb->osb_la_resmap, cluster_count, in ocfs2_local_alloc_new_window()
1249 static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, in ocfs2_local_alloc_slide_window() argument
1260 ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_SLIDE); in ocfs2_local_alloc_slide_window()
1263 status = ocfs2_local_alloc_reserve_for_window(osb, in ocfs2_local_alloc_slide_window()
1273 handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS); in ocfs2_local_alloc_slide_window()
1281 alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; in ocfs2_local_alloc_slide_window()
1288 alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_NOFS); in ocfs2_local_alloc_slide_window()
1294 memcpy(alloc_copy, alloc, osb->local_alloc_bh->b_size); in ocfs2_local_alloc_slide_window()
1298 osb->local_alloc_bh, in ocfs2_local_alloc_slide_window()
1306 ocfs2_journal_dirty(handle, osb->local_alloc_bh); in ocfs2_local_alloc_slide_window()
1308 status = ocfs2_sync_local_to_main(osb, handle, alloc_copy, in ocfs2_local_alloc_slide_window()
1315 status = ocfs2_local_alloc_new_window(osb, handle, ac); in ocfs2_local_alloc_slide_window()
1322 atomic_inc(&osb->alloc_stats.moves); in ocfs2_local_alloc_slide_window()
1326 ocfs2_commit_trans(osb, handle); in ocfs2_local_alloc_slide_window()