28 #include <linux/types.h>
29 #include <linux/slab.h>
50 #define NOT_ALLOC_NEW_GROUP 0
51 #define ALLOC_NEW_GROUP 0x1
52 #define ALLOC_GROUPS_FROM_GLOBAL 0x2
54 #define OCFS2_MAX_TO_STEAL 1024
83 static inline void ocfs2_debug_suballoc_inode(
struct ocfs2_dinode *fe);
85 static int ocfs2_block_group_fill(handle_t *
handle,
86 struct inode *alloc_inode,
87 struct buffer_head *bg_bh,
89 unsigned int group_clusters,
92 static int ocfs2_block_group_alloc(
struct ocfs2_super *osb,
93 struct inode *alloc_inode,
94 struct buffer_head *bh,
96 u64 *last_alloc_group,
99 static int ocfs2_cluster_group_search(
struct inode *
inode,
100 struct buffer_head *group_bh,
101 u32 bits_wanted,
u32 min_bits,
104 static int ocfs2_block_group_search(
struct inode *
inode,
105 struct buffer_head *group_bh,
106 u32 bits_wanted,
u32 min_bits,
114 static int ocfs2_test_bg_bit_allocatable(
struct buffer_head *bg_bh,
116 static inline int ocfs2_block_group_set_bits(handle_t *
handle,
117 struct inode *alloc_inode,
119 struct buffer_head *group_bh,
120 unsigned int bit_off,
121 unsigned int num_bits);
122 static int ocfs2_relink_block_group(handle_t *
handle,
123 struct inode *alloc_inode,
124 struct buffer_head *fe_bh,
125 struct buffer_head *bg_bh,
126 struct buffer_head *prev_bg_bh,
130 static inline u32 ocfs2_desc_bitmap_to_cluster_off(
struct inode *
inode,
133 static inline void ocfs2_block_to_cluster_group(
struct inode *
inode,
137 static int ocfs2_reserve_clusters_with_limit(
struct ocfs2_super *osb,
138 u32 bits_wanted,
u64 max_block,
175 #define do_error(fmt, ...) \
178 mlog(ML_ERROR, fmt "\n", ##__VA_ARGS__); \
180 ocfs2_error(sb, fmt, ##__VA_ARGS__); \
184 struct buffer_head *bh,
190 do_error(
"Group descriptor #%llu has bad signature %.*s",
191 (
unsigned long long)bh->b_blocknr, 7,
197 do_error(
"Group descriptor #%llu has an invalid bg_blkno "
199 (
unsigned long long)bh->b_blocknr,
205 do_error(
"Group descriptor #%llu has an invalid "
206 "fs_generation of #%u",
207 (
unsigned long long)bh->b_blocknr,
213 do_error(
"Group descriptor #%llu has bit count %u but "
214 "claims that %u are free",
215 (
unsigned long long)bh->b_blocknr,
222 do_error(
"Group descriptor #%llu has bit count %u but "
223 "max bitmap bits of %u",
224 (
unsigned long long)bh->b_blocknr,
235 struct buffer_head *bh,
242 do_error(
"Group descriptor #%llu has bad parent "
243 "pointer (%llu, expected %llu)",
244 (
unsigned long long)bh->b_blocknr,
252 do_error(
"Group descriptor #%llu has bit count of %u",
253 (
unsigned long long)bh->b_blocknr,
263 do_error(
"Group descriptor #%llu has bad chain %u",
264 (
unsigned long long)bh->b_blocknr,
280 struct buffer_head *bh)
285 BUG_ON(!buffer_uptodate(bh));
295 "Checksum failed for group descriptor %llu\n",
296 (
unsigned long long)bh->b_blocknr);
298 rc = ocfs2_validate_gd_self(sb, bh, 1);
300 rc = ocfs2_validate_gd_parent(sb, di, bh, 1);
305 static int ocfs2_validate_group_descriptor(
struct super_block *sb,
306 struct buffer_head *bh)
311 trace_ocfs2_validate_group_descriptor(
312 (
unsigned long long)bh->b_blocknr);
314 BUG_ON(!buffer_uptodate(bh));
329 return ocfs2_validate_gd_self(sb, bh, 0);
333 u64 gd_blkno,
struct buffer_head **bh)
336 struct buffer_head *
tmp = *bh;
338 rc = ocfs2_read_block(INODE_CACHE(inode), gd_blkno, &tmp,
339 ocfs2_validate_group_descriptor);
343 rc = ocfs2_validate_gd_parent(inode->
i_sb, di, tmp, 0);
357 static void ocfs2_bg_discontig_add_extent(
struct ocfs2_super *osb,
360 u64 p_blkno,
unsigned int clusters)
365 BUG_ON(!ocfs2_supports_discontig_bg(osb));
379 static int ocfs2_block_group_fill(handle_t *
handle,
380 struct inode *alloc_inode,
381 struct buffer_head *bg_bh,
383 unsigned int group_clusters,
392 if (((
unsigned long long) bg_bh->b_blocknr) != group_blkno) {
395 (
unsigned long long)group_blkno,
396 (
unsigned long long) bg_bh->b_blocknr);
402 INODE_CACHE(alloc_inode),
422 ocfs2_bg_discontig_add_extent(osb, bg, cl, group_blkno,
456 static struct buffer_head *
457 ocfs2_block_group_alloc_contig(
struct ocfs2_super *osb, handle_t *handle,
458 struct inode *alloc_inode,
463 u32 bit_off, num_bits;
465 struct buffer_head *bg_bh;
466 unsigned int alloc_rec = ocfs2_find_smallest_chain(cl);
478 bg_blkno = ocfs2_clusters_to_blocks(osb->
sb, bit_off);
479 trace_ocfs2_block_group_alloc_contig(
480 (
unsigned long long)bg_blkno, alloc_rec);
482 bg_bh = sb_getblk(osb->
sb, bg_blkno);
490 status = ocfs2_block_group_fill(handle, alloc_inode, bg_bh,
491 bg_blkno, num_bits, alloc_rec, cl);
498 return status ? ERR_PTR(status) : bg_bh;
501 static int ocfs2_block_group_claim_bits(
struct ocfs2_super *osb,
504 unsigned int min_bits,
505 u32 *bit_off,
u32 *num_bits)
521 static int ocfs2_block_group_grow_discontig(handle_t *handle,
522 struct inode *alloc_inode,
523 struct buffer_head *bg_bh,
526 unsigned int min_bits)
534 u32 p_cpos, clusters;
539 INODE_CACHE(alloc_inode),
549 if (min_bits > needed)
551 status = ocfs2_block_group_claim_bits(osb, handle, ac,
559 p_blkno = ocfs2_clusters_to_blocks(osb->
sb, p_cpos);
560 ocfs2_bg_discontig_add_extent(osb, bg, cl, p_blkno,
583 static void ocfs2_bg_alloc_cleanup(handle_t *handle,
585 struct inode *alloc_inode,
586 struct buffer_head *bg_bh)
613 static struct buffer_head *
614 ocfs2_block_group_alloc_discontig(handle_t *handle,
615 struct inode *alloc_inode,
620 u32 bit_off, num_bits;
623 struct buffer_head *bg_bh =
NULL;
624 unsigned int alloc_rec = ocfs2_find_smallest_chain(cl);
627 if (!ocfs2_supports_discontig_bg(osb)) {
633 ocfs2_calc_bg_discontig_credits(osb->
sb));
648 status = ocfs2_block_group_claim_bits(osb, handle, ac, min_bits,
649 &bit_off, &num_bits);
658 bg_blkno = ocfs2_clusters_to_blocks(osb->
sb, bit_off);
659 trace_ocfs2_block_group_alloc_discontig(
660 (
unsigned long long)bg_blkno, alloc_rec);
662 bg_bh = sb_getblk(osb->
sb, bg_blkno);
670 status = ocfs2_block_group_fill(handle, alloc_inode, bg_bh,
671 bg_blkno, num_bits, alloc_rec, cl);
677 status = ocfs2_block_group_grow_discontig(handle, alloc_inode,
678 bg_bh, ac, cl, min_bits);
684 ocfs2_bg_alloc_cleanup(handle, ac, alloc_inode, bg_bh);
685 return status ? ERR_PTR(status) : bg_bh;
691 static int ocfs2_block_group_alloc(
struct ocfs2_super *osb,
692 struct inode *alloc_inode,
693 struct buffer_head *bh,
695 u64 *last_alloc_group,
702 handle_t *handle =
NULL;
704 struct buffer_head *bg_bh =
NULL;
707 BUG_ON(ocfs2_is_cluster_bitmap(alloc_inode));
710 status = ocfs2_reserve_clusters_with_limit(osb,
712 max_block, flags, &ac);
719 credits = ocfs2_calc_group_alloc_credits(osb->
sb,
722 if (IS_ERR(handle)) {
723 status = PTR_ERR(handle);
729 if (last_alloc_group && *last_alloc_group != 0) {
730 trace_ocfs2_block_group_alloc(
731 (
unsigned long long)*last_alloc_group);
735 bg_bh = ocfs2_block_group_alloc_contig(osb, handle, alloc_inode,
737 if (IS_ERR(bg_bh) && (PTR_ERR(bg_bh) == -
ENOSPC))
738 bg_bh = ocfs2_block_group_alloc_discontig(handle,
742 status = PTR_ERR(bg_bh);
758 le32_add_cpu(&cl->
cl_recs[alloc_rec].c_free,
760 le32_add_cpu(&cl->
cl_recs[alloc_rec].c_total,
773 spin_lock(&OCFS2_I(alloc_inode)->ip_lock);
777 spin_unlock(&OCFS2_I(alloc_inode)->ip_lock);
779 alloc_inode->
i_blocks = ocfs2_inode_sector_count(alloc_inode);
784 if (last_alloc_group)
801 static int ocfs2_reserve_suballoc_bits(
struct ocfs2_super *osb,
805 u64 *last_alloc_group,
810 struct inode *alloc_inode;
811 struct buffer_head *bh =
NULL;
851 if (bits_wanted > free_bits) {
853 if (ocfs2_is_cluster_bitmap(alloc_inode)) {
854 trace_ocfs2_reserve_suballoc_bits_nospc(bits_wanted,
861 trace_ocfs2_reserve_suballoc_bits_no_new_group(
862 slot, bits_wanted, free_bits);
867 status = ocfs2_block_group_alloc(osb, alloc_inode, bh,
869 last_alloc_group, flags);
893 static void ocfs2_init_inode_steal_slot(
struct ocfs2_super *osb)
901 static void ocfs2_init_meta_steal_slot(
struct ocfs2_super *osb)
911 ocfs2_init_inode_steal_slot(osb);
912 ocfs2_init_meta_steal_slot(osb);
915 static void __ocfs2_set_steal_slot(
struct ocfs2_super *osb,
int slot,
int type)
925 static int __ocfs2_get_steal_slot(
struct ocfs2_super *osb,
int type)
939 static int ocfs2_get_inode_steal_slot(
struct ocfs2_super *osb)
944 static int ocfs2_get_meta_steal_slot(
struct ocfs2_super *osb)
949 static int ocfs2_steal_resource(
struct ocfs2_super *osb,
954 int slot = __ocfs2_get_steal_slot(osb, type);
960 for (i = 0; i < osb->
max_slots; i++, slot++) {
967 status = ocfs2_reserve_suballoc_bits(osb, ac,
972 __ocfs2_set_steal_slot(osb, slot, type);
982 static int ocfs2_steal_inode(
struct ocfs2_super *osb,
988 static int ocfs2_steal_meta(
struct ocfs2_super *osb,
999 int slot = ocfs2_get_meta_steal_slot(osb);
1008 (*ac)->ac_bits_wanted = blocks;
1010 (*ac)->ac_group_search = ocfs2_block_group_search;
1017 status = ocfs2_reserve_suballoc_bits(osb, (*ac),
1026 ocfs2_init_meta_steal_slot(osb);
1028 }
else if (status < 0 && status != -
ENOSPC) {
1036 status = ocfs2_steal_meta(osb, *ac);
1046 if ((status < 0) && *ac) {
1061 ocfs2_extend_meta_needed(root_el),
1069 int slot = ocfs2_get_inode_steal_slot(osb);
1079 (*ac)->ac_bits_wanted = 1;
1082 (*ac)->ac_group_search = ocfs2_block_group_search;
1090 (*ac)->ac_max_block = (
u32)~0
U;
1107 status = ocfs2_reserve_suballoc_bits(osb, *ac,
1119 trace_ocfs2_reserve_new_inode_new_group(
1120 (
unsigned long long)alloc_group);
1127 ocfs2_init_inode_steal_slot(osb);
1129 }
else if (status < 0 && status != -
ENOSPC) {
1137 status = ocfs2_steal_inode(osb, *ac);
1147 if ((status < 0) && *ac) {
1167 status = ocfs2_reserve_suballoc_bits(osb, ac,
1171 if (status < 0 && status != -
ENOSPC) {
1183 static int ocfs2_reserve_clusters_with_limit(
struct ocfs2_super *osb,
1184 u32 bits_wanted,
u64 max_block,
1197 (*ac)->ac_bits_wanted = bits_wanted;
1198 (*ac)->ac_max_block = max_block;
1206 if ((status < 0) && (status != -
ENOSPC)) {
1223 if ((status < 0) && *ac) {
1237 return ocfs2_reserve_clusters_with_limit(osb, bits_wanted, 0,
1238 ALLOC_NEW_GROUP, ac);
1263 static int ocfs2_test_bg_bit_allocatable(
struct buffer_head *bg_bh,
1272 if (!buffer_jbd(bg_bh))
1275 jbd_lock_bh_state(bg_bh);
1281 jbd_unlock_bh_state(bg_bh);
1286 static int ocfs2_block_group_find_clear_bits(
struct ocfs2_super *osb,
1287 struct buffer_head *bg_bh,
1288 unsigned int bits_wanted,
1289 unsigned int total_bits,
1293 u16 best_offset, best_size;
1301 found = start = best_offset = best_size = 0;
1305 if (offset == total_bits)
1308 if (!ocfs2_test_bg_bit_allocatable(bg_bh, offset)) {
1313 }
else if (offset == start) {
1323 if (found > best_size) {
1325 best_offset = start - found;
1328 if (found == bits_wanted) {
1346 static inline int ocfs2_block_group_set_bits(handle_t *handle,
1347 struct inode *alloc_inode,
1349 struct buffer_head *group_bh,
1350 unsigned int bit_off,
1351 unsigned int num_bits)
1362 trace_ocfs2_block_group_set_bits(bit_off, num_bits);
1364 if (ocfs2_is_cluster_bitmap(alloc_inode))
1368 INODE_CACHE(alloc_inode),
1379 " count %u but claims %u are freed. num_bits %d",
1415 static int ocfs2_relink_block_group(handle_t *handle,
1416 struct inode *alloc_inode,
1417 struct buffer_head *fe_bh,
1418 struct buffer_head *bg_bh,
1419 struct buffer_head *prev_bg_bh,
1425 u64 fe_ptr, bg_ptr, prev_bg_ptr;
1435 trace_ocfs2_relink_block_group(
1487 static inline int ocfs2_block_group_reasonably_empty(
struct ocfs2_group_desc *bg,
1495 static int ocfs2_cluster_group_search(
struct inode *
inode,
1496 struct buffer_head *group_bh,
1497 u32 bits_wanted,
u32 min_bits,
1506 unsigned int max_bits, gd_cluster_off;
1508 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
1519 gd_cluster_off = ocfs2_blocks_to_clusters(inode->
i_sb,
1521 if ((gd_cluster_off + max_bits) >
1522 OCFS2_I(inode)->ip_clusters) {
1523 max_bits = OCFS2_I(inode)->ip_clusters - gd_cluster_off;
1524 trace_ocfs2_cluster_group_search_wrong_max_bits(
1527 OCFS2_I(inode)->ip_clusters, max_bits);
1530 ret = ocfs2_block_group_find_clear_bits(
OCFS2_SB(inode->
i_sb),
1531 group_bh, bits_wanted,
1537 blkoff = ocfs2_clusters_to_blocks(inode->
i_sb,
1541 trace_ocfs2_cluster_group_search_max_block(
1542 (
unsigned long long)blkoff,
1543 (
unsigned long long)max_block);
1544 if (blkoff > max_block)
1552 if (min_bits <= res->sr_bits)
1566 static int ocfs2_block_group_search(
struct inode *inode,
1567 struct buffer_head *group_bh,
1568 u32 bits_wanted,
u32 min_bits,
1577 BUG_ON(ocfs2_is_cluster_bitmap(inode));
1580 ret = ocfs2_block_group_find_clear_bits(
OCFS2_SB(inode->
i_sb),
1581 group_bh, bits_wanted,
1584 if (!ret && max_block) {
1587 trace_ocfs2_block_group_search_max_block(
1588 (
unsigned long long)blkoff,
1589 (
unsigned long long)max_block);
1590 if (blkoff > max_block)
1598 static int ocfs2_alloc_dinode_update_counts(
struct inode *inode,
1600 struct buffer_head *di_bh,
1618 le32_add_cpu(&cl->
cl_recs[chain].c_free, -num_bits);
1667 if (ocfs2_bg_discontig_fix_by_rec(res, rec, cl)) {
1682 struct buffer_head *group_bh =
NULL;
1685 struct inode *alloc_inode = ac->
ac_inode;
1695 ret = ac->
ac_group_search(alloc_inode, group_bh, bits_wanted, min_bits,
1704 ocfs2_bg_discontig_fix_result(ac, gd, res);
1715 ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->
ac_bh,
1723 ret = ocfs2_block_group_set_bits(handle, alloc_inode, gd, group_bh,
1747 struct inode *alloc_inode = ac->
ac_inode;
1748 struct buffer_head *group_bh =
NULL;
1749 struct buffer_head *prev_group_bh =
NULL;
1755 trace_ocfs2_search_chain_begin(
1756 (
unsigned long long)OCFS2_I(alloc_inode)->ip_blkno,
1757 bits_wanted, chain);
1772 bits_wanted, min_bits,
1778 brelse(prev_group_bh);
1779 prev_group_bh =
NULL;
1782 prev_group_bh = group_bh;
1785 next_group, &group_bh);
1798 trace_ocfs2_search_chain_succ(
1805 ocfs2_bg_discontig_fix_result(ac, bg, res);
1828 (ocfs2_block_group_reasonably_empty(bg, res->
sr_bits))) {
1829 status = ocfs2_relink_block_group(handle, alloc_inode,
1830 ac->
ac_bh, group_bh,
1831 prev_group_bh, chain);
1841 status = ocfs2_alloc_dinode_update_counts(alloc_inode, handle,
1849 status = ocfs2_block_group_set_bits(handle,
1860 trace_ocfs2_search_chain_end(
1868 brelse(prev_group_bh);
1902 "Chain allocator dinode %llu has %u used "
1903 "bits but only %u total.",
1917 status = ocfs2_search_one_group(ac, handle, bits_wanted,
1918 min_bits, res, &bits_left);
1921 if (status < 0 && status != -
ENOSPC) {
1929 victim = ocfs2_find_victim_chain(cl);
1933 status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits,
1936 hint = ocfs2_group_from_res(res);
1939 if (status < 0 && status != -
ENOSPC) {
1944 trace_ocfs2_claim_suballoc_bits(victim);
1958 status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits,
1961 hint = ocfs2_group_from_res(res);
1964 if (status < 0 && status != -
ENOSPC) {
1975 if (bits_left < min_bits)
1991 u16 *suballoc_bit_start,
1992 unsigned int *num_bits,
2002 status = ocfs2_claim_suballoc_bits(ac,
2025 static void ocfs2_init_inode_ac_group(
struct inode *dir,
2026 struct buffer_head *parent_di_bh,
2040 if (OCFS2_I(dir)->ip_last_used_group &&
2053 static inline void ocfs2_save_inode_ac_group(
struct inode *dir,
2061 struct buffer_head *parent_fe_bh,
2066 handle_t *handle =
NULL;
2074 res = kzalloc(
sizeof(*res),
GFP_NOFS);
2081 ocfs2_init_inode_ac_group(dir, parent_fe_bh, ac);
2088 if (IS_ERR(handle)) {
2089 ret = PTR_ERR(handle);
2102 ret = ocfs2_claim_suballoc_bits(ac, handle, 1, 1, res);
2131 struct buffer_head *bg_bh =
NULL;
2153 ret = ocfs2_alloc_dinode_update_counts(ac->
ac_inode, handle,
2161 ret = ocfs2_block_group_set_bits(handle,
2172 trace_ocfs2_claim_new_inode_at_loc((
unsigned long long)di_blkno,
2182 ocfs2_save_inode_ac_group(dir, ac);
2192 struct buffer_head *parent_fe_bh,
2206 ocfs2_init_inode_ac_group(dir, parent_fe_bh, ac);
2208 status = ocfs2_claim_suballoc_bits(ac,
2225 ocfs2_save_inode_ac_group(dir, ac);
2235 static inline u32 ocfs2_desc_bitmap_to_cluster_off(
struct inode *inode,
2242 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
2245 cluster = ocfs2_blocks_to_clusters(inode->
i_sb, bg_blkno);
2246 cluster += (
u32) bg_bit_off;
2257 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
2262 return ocfs2_clusters_to_blocks(inode->
i_sb,
2268 static inline void ocfs2_block_to_cluster_group(
struct inode *inode,
2274 u32 data_cluster = ocfs2_blocks_to_clusters(osb->
sb, data_blkno);
2276 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
2282 *bg_bit_off = (
u16) data_cluster;
2284 *bg_bit_off = (
u16) ocfs2_blocks_to_clusters(osb->
sb,
2285 data_blkno - *bg_blkno);
2302 unsigned int bits_wanted = max_clusters;
2326 mlog(
ML_ERROR,
"minimum allocation requested %u exceeds "
2327 "group bitmap size %u!\n", min_clusters,
2336 status = ocfs2_claim_suballoc_bits(ac,
2344 ocfs2_desc_bitmap_to_cluster_off(ac->
ac_inode,
2374 bits_wanted, cluster_start, num_clusters);
2377 static int ocfs2_block_group_clear_bits(handle_t *handle,
2378 struct inode *alloc_inode,
2380 struct buffer_head *group_bh,
2381 unsigned int bit_off,
2382 unsigned int num_bits,
2383 void (*undo_fn)(
unsigned int bit,
2384 unsigned long *
bmap))
2394 trace_ocfs2_block_group_clear_bits(bit_off, num_bits);
2396 BUG_ON(undo_fn && !ocfs2_is_cluster_bitmap(alloc_inode));
2408 jbd_lock_bh_state(group_bh);
2410 bh2jh(group_bh)->b_committed_data;
2419 undo_fn(bit_off + tmp,
2425 " count %u but claims %u are freed. num_bits %d",
2433 jbd_unlock_bh_state(group_bh);
2443 static int _ocfs2_free_suballoc_bits(handle_t *handle,
2444 struct inode *alloc_inode,
2445 struct buffer_head *alloc_bh,
2449 void (*undo_fn)(
unsigned int bit,
2450 unsigned long *bitmap))
2456 struct buffer_head *group_bh =
NULL;
2465 BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl));
2467 trace_ocfs2_free_suballoc_bits(
2468 (
unsigned long long)OCFS2_I(alloc_inode)->ip_blkno,
2469 (
unsigned long long)bg_blkno,
2482 status = ocfs2_block_group_clear_bits(handle, alloc_inode,
2484 start_bit, count, undo_fn);
2512 struct inode *alloc_inode,
2513 struct buffer_head *alloc_bh,
2514 unsigned int start_bit,
2518 return _ocfs2_free_suballoc_bits(handle, alloc_inode, alloc_bh,
2519 start_bit, bg_blkno, count,
NULL);
2523 struct inode *inode_alloc_inode,
2524 struct buffer_head *inode_alloc_bh,
2529 u64 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
2534 inode_alloc_bh, bit, bg_blkno, 1);
2537 static int _ocfs2_free_clusters(handle_t *handle,
2538 struct inode *bitmap_inode,
2539 struct buffer_head *bitmap_bh,
2541 unsigned int num_clusters,
2542 void (*undo_fn)(
unsigned int bit,
2543 unsigned long *bitmap))
2555 BUG_ON(start_blk != ocfs2_clusters_to_blocks(bitmap_inode->
i_sb, ocfs2_blocks_to_clusters(bitmap_inode->
i_sb, start_blk)));
2559 ocfs2_block_to_cluster_group(bitmap_inode, start_blk, &bg_blkno,
2562 trace_ocfs2_free_clusters((
unsigned long long)bg_blkno,
2563 (
unsigned long long)start_blk,
2564 bg_start_bit, num_clusters);
2566 status = _ocfs2_free_suballoc_bits(handle, bitmap_inode, bitmap_bh,
2567 bg_start_bit, bg_blkno,
2568 num_clusters, undo_fn);
2584 struct inode *bitmap_inode,
2585 struct buffer_head *bitmap_bh,
2587 unsigned int num_clusters)
2589 return _ocfs2_free_clusters(handle, bitmap_inode, bitmap_bh,
2590 start_blk, num_clusters,
2599 struct inode *bitmap_inode,
2600 struct buffer_head *bitmap_bh,
2602 unsigned int num_clusters)
2604 return _ocfs2_free_clusters(handle, bitmap_inode, bitmap_bh,
2605 start_blk, num_clusters,
2611 printk(
"Block Group:\n");
2618 printk(
"bg_next_group: %llu\n",
2620 printk(
"bg_parent_dinode: %llu\n",
2622 printk(
"bg_blkno: %llu\n",
2626 static inline void ocfs2_debug_suballoc_inode(
struct ocfs2_dinode *fe)
2630 printk(
"Suballoc Inode %llu:\n", (
unsigned long long)fe->
i_blkno);
2633 (
unsigned long long)fe->
i_size);
2635 printk(
"i_generation: %u\n",
2637 printk(
"id1.bitmap1.i_used: %u\n",
2639 printk(
"id1.bitmap1.i_total: %u\n",
2644 printk(
"id2.i_chain.cl_next_free_rec: %u\n",
2646 for(i = 0; i < fe->
id2.
i_chain.cl_next_free_rec; i++) {
2647 printk(
"fe->id2.i_chain.cl_recs[%d].c_free: %u\n", i,
2649 printk(
"fe->id2.i_chain.cl_recs[%d].c_total: %u\n", i,
2651 printk(
"fe->id2.i_chain.cl_recs[%d].c_blkno: %llu\n", i,
2652 (
unsigned long long)fe->
id2.
i_chain.cl_recs[i].c_blkno);
2668 u32 clusters_to_add,
u32 extents_to_split,
2672 int ret = 0, num_free_extents;
2673 unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split;
2680 BUG_ON(clusters_to_add != 0 && data_ac ==
NULL);
2683 if (num_free_extents < 0) {
2684 ret = num_free_extents;
2702 if (!num_free_extents ||
2703 (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) {
2712 if (clusters_to_add == 0)
2741 static int ocfs2_get_suballoc_slot_bit(
struct ocfs2_super *osb,
u64 blkno,
2742 u16 *suballoc_slot,
u64 *group_blkno,
2746 struct buffer_head *inode_bh =
NULL;
2749 trace_ocfs2_get_suballoc_slot_bit((
unsigned long long)blkno);
2755 (
unsigned long long)blkno, status);
2762 (
unsigned long long)blkno);
2769 mlog(
ML_ERROR,
"inode %llu has invalid suballoc slot %u\n",
2770 (
unsigned long long)blkno,
2798 static int ocfs2_test_suballoc_bit(
struct ocfs2_super *osb,
2799 struct inode *suballoc,
2800 struct buffer_head *alloc_bh,
2801 u64 group_blkno,
u64 blkno,
2806 struct buffer_head *group_bh =
NULL;
2810 trace_ocfs2_test_suballoc_bit((
unsigned long long)blkno,
2814 if ((bit + 1) > ocfs2_bits_per_group(&alloc_di->
id2.
i_chain)) {
2817 ocfs2_bits_per_group(&alloc_di->
id2.
i_chain));
2822 bg_blkno = group_blkno ? group_blkno :
2823 ocfs2_which_suballoc_group(blkno, bit);
2828 (
unsigned long long)bg_blkno, status);
2859 u64 group_blkno = 0;
2860 u16 suballoc_bit = 0, suballoc_slot = 0;
2861 struct inode *inode_alloc_inode;
2862 struct buffer_head *alloc_bh =
NULL;
2864 trace_ocfs2_test_inode_bit((
unsigned long long)blkno);
2866 status = ocfs2_get_suballoc_slot_bit(osb, blkno, &suballoc_slot,
2867 &group_blkno, &suballoc_bit);
2869 mlog(
ML_ERROR,
"get alloc slot and bit failed %d\n", status);
2876 if (!inode_alloc_inode) {
2880 mlog(
ML_ERROR,
"unable to get alloc inode in slot %u\n",
2881 (
u32)suballoc_slot);
2889 mlog(
ML_ERROR,
"lock on alloc inode on slot %u failed %d\n",
2890 (
u32)suballoc_slot, status);
2894 status = ocfs2_test_suballoc_bit(osb, inode_alloc_inode, alloc_bh,
2895 group_blkno, blkno, suballoc_bit, res);
2897 mlog(
ML_ERROR,
"test suballoc bit failed %d\n", status);
2902 iput(inode_alloc_inode);