1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * metadata alloc and free
7 * Inspired by ext3 block groups.
9 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public
22 * License along with this program; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 021110-1307, USA.
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
32 #define MLOG_MASK_PREFIX ML_DISK_ALLOC
33 #include <cluster/masklog.h>
41 #include "localalloc.h"
47 #include "buffer_head_io.h"
49 static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg);
50 static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe);
51 static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl);
52 static int ocfs2_block_group_fill(handle_t *handle,
53 struct inode *alloc_inode,
54 struct buffer_head *bg_bh,
57 struct ocfs2_chain_list *cl);
58 static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
59 struct inode *alloc_inode,
60 struct buffer_head *bh);
62 static int ocfs2_cluster_group_search(struct inode *inode,
63 struct buffer_head *group_bh,
64 u32 bits_wanted, u32 min_bits,
65 u16 *bit_off, u16 *bits_found);
66 static int ocfs2_block_group_search(struct inode *inode,
67 struct buffer_head *group_bh,
68 u32 bits_wanted, u32 min_bits,
69 u16 *bit_off, u16 *bits_found);
70 static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
71 struct ocfs2_alloc_context *ac,
76 unsigned int *num_bits,
78 static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
80 static inline int ocfs2_block_group_set_bits(handle_t *handle,
81 struct inode *alloc_inode,
82 struct ocfs2_group_desc *bg,
83 struct buffer_head *group_bh,
85 unsigned int num_bits);
86 static inline int ocfs2_block_group_clear_bits(handle_t *handle,
87 struct inode *alloc_inode,
88 struct ocfs2_group_desc *bg,
89 struct buffer_head *group_bh,
91 unsigned int num_bits);
93 static int ocfs2_relink_block_group(handle_t *handle,
94 struct inode *alloc_inode,
95 struct buffer_head *fe_bh,
96 struct buffer_head *bg_bh,
97 struct buffer_head *prev_bg_bh,
99 static inline int ocfs2_block_group_reasonably_empty(struct ocfs2_group_desc *bg,
101 static int ocfs2_free_suballoc_bits(handle_t *handle,
102 struct inode *alloc_inode,
103 struct buffer_head *alloc_bh,
104 unsigned int start_bit,
107 static inline u64 ocfs2_which_suballoc_group(u64 block,
109 static inline u32 ocfs2_desc_bitmap_to_cluster_off(struct inode *inode,
112 static inline u64 ocfs2_which_cluster_group(struct inode *inode,
114 static inline void ocfs2_block_to_cluster_group(struct inode *inode,
119 void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
121 struct inode *inode = ac->ac_inode;
124 if (ac->ac_which != OCFS2_AC_USE_LOCAL)
125 ocfs2_meta_unlock(inode, 1);
127 mutex_unlock(&inode->i_mutex);
136 static u32 ocfs2_bits_per_group(struct ocfs2_chain_list *cl)
138 return (u32)le16_to_cpu(cl->cl_cpg) * (u32)le16_to_cpu(cl->cl_bpc);
141 /* somewhat more expensive than our other checks, so use sparingly. */
142 static int ocfs2_check_group_descriptor(struct super_block *sb,
143 struct ocfs2_dinode *di,
144 struct ocfs2_group_desc *gd)
146 unsigned int max_bits;
148 if (!OCFS2_IS_VALID_GROUP_DESC(gd)) {
149 OCFS2_RO_ON_INVALID_GROUP_DESC(sb, gd);
153 if (di->i_blkno != gd->bg_parent_dinode) {
154 ocfs2_error(sb, "Group descriptor # %llu has bad parent "
155 "pointer (%llu, expected %llu)",
156 (unsigned long long)le64_to_cpu(gd->bg_blkno),
157 (unsigned long long)le64_to_cpu(gd->bg_parent_dinode),
158 (unsigned long long)le64_to_cpu(di->i_blkno));
162 max_bits = le16_to_cpu(di->id2.i_chain.cl_cpg) * le16_to_cpu(di->id2.i_chain.cl_bpc);
163 if (le16_to_cpu(gd->bg_bits) > max_bits) {
164 ocfs2_error(sb, "Group descriptor # %llu has bit count of %u",
165 (unsigned long long)le64_to_cpu(gd->bg_blkno),
166 le16_to_cpu(gd->bg_bits));
170 if (le16_to_cpu(gd->bg_chain) >=
171 le16_to_cpu(di->id2.i_chain.cl_next_free_rec)) {
172 ocfs2_error(sb, "Group descriptor # %llu has bad chain %u",
173 (unsigned long long)le64_to_cpu(gd->bg_blkno),
174 le16_to_cpu(gd->bg_chain));
178 if (le16_to_cpu(gd->bg_free_bits_count) > le16_to_cpu(gd->bg_bits)) {
179 ocfs2_error(sb, "Group descriptor # %llu has bit count %u but "
180 "claims that %u are free",
181 (unsigned long long)le64_to_cpu(gd->bg_blkno),
182 le16_to_cpu(gd->bg_bits),
183 le16_to_cpu(gd->bg_free_bits_count));
187 if (le16_to_cpu(gd->bg_bits) > (8 * le16_to_cpu(gd->bg_size))) {
188 ocfs2_error(sb, "Group descriptor # %llu has bit count %u but "
189 "max bitmap bits of %u",
190 (unsigned long long)le64_to_cpu(gd->bg_blkno),
191 le16_to_cpu(gd->bg_bits),
192 8 * le16_to_cpu(gd->bg_size));
199 static int ocfs2_block_group_fill(handle_t *handle,
200 struct inode *alloc_inode,
201 struct buffer_head *bg_bh,
204 struct ocfs2_chain_list *cl)
207 struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
208 struct super_block * sb = alloc_inode->i_sb;
212 if (((unsigned long long) bg_bh->b_blocknr) != group_blkno) {
213 ocfs2_error(alloc_inode->i_sb, "group block (%llu) != "
215 (unsigned long long)group_blkno,
216 (unsigned long long) bg_bh->b_blocknr);
221 status = ocfs2_journal_access(handle,
224 OCFS2_JOURNAL_ACCESS_CREATE);
230 memset(bg, 0, sb->s_blocksize);
231 strcpy(bg->bg_signature, OCFS2_GROUP_DESC_SIGNATURE);
232 bg->bg_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation);
233 bg->bg_size = cpu_to_le16(ocfs2_group_bitmap_size(sb));
234 bg->bg_bits = cpu_to_le16(ocfs2_bits_per_group(cl));
235 bg->bg_chain = cpu_to_le16(my_chain);
236 bg->bg_next_group = cl->cl_recs[my_chain].c_blkno;
237 bg->bg_parent_dinode = cpu_to_le64(OCFS2_I(alloc_inode)->ip_blkno);
238 bg->bg_blkno = cpu_to_le64(group_blkno);
239 /* set the 1st bit in the bitmap to account for the descriptor block */
240 ocfs2_set_bit(0, (unsigned long *)bg->bg_bitmap);
241 bg->bg_free_bits_count = cpu_to_le16(le16_to_cpu(bg->bg_bits) - 1);
243 status = ocfs2_journal_dirty(handle, bg_bh);
247 /* There is no need to zero out or otherwise initialize the
248 * other blocks in a group - All valid FS metadata in a block
249 * group stores the superblock fs_generation value at
250 * allocation time. */
257 static inline u16 ocfs2_find_smallest_chain(struct ocfs2_chain_list *cl)
262 while (curr < le16_to_cpu(cl->cl_count)) {
263 if (le32_to_cpu(cl->cl_recs[best].c_total) >
264 le32_to_cpu(cl->cl_recs[curr].c_total))
272 * We expect the block group allocator to already be locked.
274 static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
275 struct inode *alloc_inode,
276 struct buffer_head *bh)
279 struct ocfs2_dinode *fe = (struct ocfs2_dinode *) bh->b_data;
280 struct ocfs2_chain_list *cl;
281 struct ocfs2_alloc_context *ac = NULL;
282 handle_t *handle = NULL;
283 u32 bit_off, num_bits;
286 struct buffer_head *bg_bh = NULL;
287 struct ocfs2_group_desc *bg;
289 BUG_ON(ocfs2_is_cluster_bitmap(alloc_inode));
293 cl = &fe->id2.i_chain;
294 status = ocfs2_reserve_clusters(osb,
295 le16_to_cpu(cl->cl_cpg),
298 if (status != -ENOSPC)
303 credits = ocfs2_calc_group_alloc_credits(osb->sb,
304 le16_to_cpu(cl->cl_cpg));
305 handle = ocfs2_start_trans(osb, credits);
306 if (IS_ERR(handle)) {
307 status = PTR_ERR(handle);
313 status = ocfs2_claim_clusters(osb,
316 le16_to_cpu(cl->cl_cpg),
320 if (status != -ENOSPC)
325 alloc_rec = ocfs2_find_smallest_chain(cl);
327 /* setup the group */
328 bg_blkno = ocfs2_clusters_to_blocks(osb->sb, bit_off);
329 mlog(0, "new descriptor, record %u, at block %llu\n",
330 alloc_rec, (unsigned long long)bg_blkno);
332 bg_bh = sb_getblk(osb->sb, bg_blkno);
338 ocfs2_set_new_buffer_uptodate(alloc_inode, bg_bh);
340 status = ocfs2_block_group_fill(handle,
351 bg = (struct ocfs2_group_desc *) bg_bh->b_data;
353 status = ocfs2_journal_access(handle, alloc_inode,
354 bh, OCFS2_JOURNAL_ACCESS_WRITE);
360 le32_add_cpu(&cl->cl_recs[alloc_rec].c_free,
361 le16_to_cpu(bg->bg_free_bits_count));
362 le32_add_cpu(&cl->cl_recs[alloc_rec].c_total, le16_to_cpu(bg->bg_bits));
363 cl->cl_recs[alloc_rec].c_blkno = cpu_to_le64(bg_blkno);
364 if (le16_to_cpu(cl->cl_next_free_rec) < le16_to_cpu(cl->cl_count))
365 le16_add_cpu(&cl->cl_next_free_rec, 1);
367 le32_add_cpu(&fe->id1.bitmap1.i_used, le16_to_cpu(bg->bg_bits) -
368 le16_to_cpu(bg->bg_free_bits_count));
369 le32_add_cpu(&fe->id1.bitmap1.i_total, le16_to_cpu(bg->bg_bits));
370 le32_add_cpu(&fe->i_clusters, le16_to_cpu(cl->cl_cpg));
372 status = ocfs2_journal_dirty(handle, bh);
378 spin_lock(&OCFS2_I(alloc_inode)->ip_lock);
379 OCFS2_I(alloc_inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
380 fe->i_size = cpu_to_le64(ocfs2_clusters_to_bytes(alloc_inode->i_sb,
381 le32_to_cpu(fe->i_clusters)));
382 spin_unlock(&OCFS2_I(alloc_inode)->ip_lock);
383 i_size_write(alloc_inode, le64_to_cpu(fe->i_size));
384 alloc_inode->i_blocks = ocfs2_inode_sector_count(alloc_inode);
389 ocfs2_commit_trans(osb, handle);
392 ocfs2_free_alloc_context(ac);
401 static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
402 struct ocfs2_alloc_context *ac,
407 u32 bits_wanted = ac->ac_bits_wanted;
408 struct inode *alloc_inode;
409 struct buffer_head *bh = NULL;
410 struct ocfs2_dinode *fe;
415 alloc_inode = ocfs2_get_system_file_inode(osb, type, slot);
421 mutex_lock(&alloc_inode->i_mutex);
423 status = ocfs2_meta_lock(alloc_inode, &bh, 1);
425 mutex_unlock(&alloc_inode->i_mutex);
432 ac->ac_inode = alloc_inode;
434 fe = (struct ocfs2_dinode *) bh->b_data;
435 if (!OCFS2_IS_VALID_DINODE(fe)) {
436 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
440 if (!(fe->i_flags & cpu_to_le32(OCFS2_CHAIN_FL))) {
441 ocfs2_error(alloc_inode->i_sb, "Invalid chain allocator %llu",
442 (unsigned long long)le64_to_cpu(fe->i_blkno));
447 free_bits = le32_to_cpu(fe->id1.bitmap1.i_total) -
448 le32_to_cpu(fe->id1.bitmap1.i_used);
450 if (bits_wanted > free_bits) {
451 /* cluster bitmap never grows */
452 if (ocfs2_is_cluster_bitmap(alloc_inode)) {
453 mlog(0, "Disk Full: wanted=%u, free_bits=%u\n",
454 bits_wanted, free_bits);
459 status = ocfs2_block_group_alloc(osb, alloc_inode, bh);
461 if (status != -ENOSPC)
465 atomic_inc(&osb->alloc_stats.bg_extends);
467 /* You should never ask for this much metadata */
469 (le32_to_cpu(fe->id1.bitmap1.i_total)
470 - le32_to_cpu(fe->id1.bitmap1.i_used)));
483 int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
484 struct ocfs2_dinode *fe,
485 struct ocfs2_alloc_context **ac)
490 *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
497 (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(fe);
498 (*ac)->ac_which = OCFS2_AC_USE_META;
500 #ifndef OCFS2_USE_ALL_METADATA_SUBALLOCATORS
503 slot = osb->slot_num;
506 (*ac)->ac_group_search = ocfs2_block_group_search;
508 status = ocfs2_reserve_suballoc_bits(osb, (*ac),
509 EXTENT_ALLOC_SYSTEM_INODE, slot);
511 if (status != -ENOSPC)
518 if ((status < 0) && *ac) {
519 ocfs2_free_alloc_context(*ac);
527 int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
528 struct ocfs2_alloc_context **ac)
532 *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
539 (*ac)->ac_bits_wanted = 1;
540 (*ac)->ac_which = OCFS2_AC_USE_INODE;
542 (*ac)->ac_group_search = ocfs2_block_group_search;
544 status = ocfs2_reserve_suballoc_bits(osb, *ac,
545 INODE_ALLOC_SYSTEM_INODE,
548 if (status != -ENOSPC)
555 if ((status < 0) && *ac) {
556 ocfs2_free_alloc_context(*ac);
564 /* local alloc code has to do the same thing, so rather than do this
566 int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb,
567 struct ocfs2_alloc_context *ac)
571 ac->ac_which = OCFS2_AC_USE_MAIN;
572 ac->ac_group_search = ocfs2_cluster_group_search;
574 status = ocfs2_reserve_suballoc_bits(osb, ac,
575 GLOBAL_BITMAP_SYSTEM_INODE,
577 if (status < 0 && status != -ENOSPC) {
586 /* Callers don't need to care which bitmap (local alloc or main) to
587 * use so we figure it out for them, but unfortunately this clutters
589 int ocfs2_reserve_clusters(struct ocfs2_super *osb,
591 struct ocfs2_alloc_context **ac)
597 *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
604 (*ac)->ac_bits_wanted = bits_wanted;
607 if (ocfs2_alloc_should_use_local(osb, bits_wanted)) {
608 status = ocfs2_reserve_local_alloc_bits(osb,
611 if ((status < 0) && (status != -ENOSPC)) {
614 } else if (status == -ENOSPC) {
615 /* reserve_local_bits will return enospc with
616 * the local alloc inode still locked, so we
617 * can change this safely here. */
618 mlog(0, "Disabling local alloc\n");
619 /* We set to OCFS2_LA_DISABLED so that umount
620 * can clean up what's left of the local
622 osb->local_alloc_state = OCFS2_LA_DISABLED;
626 if (status == -ENOSPC) {
627 status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
629 if (status != -ENOSPC)
637 if ((status < 0) && *ac) {
638 ocfs2_free_alloc_context(*ac);
647 * More or less lifted from ext3. I'll leave their description below:
649 * "For ext3 allocations, we must not reuse any blocks which are
650 * allocated in the bitmap buffer's "last committed data" copy. This
651 * prevents deletes from freeing up the page for reuse until we have
652 * committed the delete transaction.
654 * If we didn't do this, then deleting something and reallocating it as
655 * data would allow the old block to be overwritten before the
656 * transaction committed (because we force data to disk before commit).
657 * This would lead to corruption if we crashed between overwriting the
658 * data and committing the delete.
660 * @@@ We may want to make this allocation behaviour conditional on
661 * data-writes at some point, and disable it for metadata allocations or
664 * Note: OCFS2 already does this differently for metadata vs data
665 * allocations, as those bitmaps are seperate and undo access is never
666 * called on a metadata group descriptor.
668 static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,
671 struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
673 if (ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap))
675 if (!buffer_jbd(bg_bh) || !bh2jh(bg_bh)->b_committed_data)
678 bg = (struct ocfs2_group_desc *) bh2jh(bg_bh)->b_committed_data;
679 return !ocfs2_test_bit(nr, (unsigned long *)bg->bg_bitmap);
682 static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb,
683 struct buffer_head *bg_bh,
684 unsigned int bits_wanted,
685 unsigned int total_bits,
690 u16 best_offset, best_size;
691 int offset, start, found, status = 0;
692 struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
694 if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
695 OCFS2_RO_ON_INVALID_GROUP_DESC(osb->sb, bg);
699 found = start = best_offset = best_size = 0;
700 bitmap = bg->bg_bitmap;
702 while((offset = ocfs2_find_next_zero_bit(bitmap, total_bits, start)) != -1) {
703 if (offset == total_bits)
706 if (!ocfs2_test_bg_bit_allocatable(bg_bh, offset)) {
707 /* We found a zero, but we can't use it as it
708 * hasn't been put to disk yet! */
711 } else if (offset == start) {
712 /* we found a zero */
714 /* move start to the next bit to test */
717 /* got a zero after some ones */
721 if (found > best_size) {
723 best_offset = start - found;
725 /* we got everything we needed */
726 if (found == bits_wanted) {
727 /* mlog(0, "Found it all!\n"); */
732 /* XXX: I think the first clause is equivalent to the second
734 if (found == bits_wanted) {
735 *bit_off = start - found;
737 } else if (best_size) {
738 *bit_off = best_offset;
739 *bits_found = best_size;
742 /* No error log here -- see the comment above
743 * ocfs2_test_bg_bit_allocatable */
749 static inline int ocfs2_block_group_set_bits(handle_t *handle,
750 struct inode *alloc_inode,
751 struct ocfs2_group_desc *bg,
752 struct buffer_head *group_bh,
753 unsigned int bit_off,
754 unsigned int num_bits)
757 void *bitmap = bg->bg_bitmap;
758 int journal_type = OCFS2_JOURNAL_ACCESS_WRITE;
762 if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
763 OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
767 BUG_ON(le16_to_cpu(bg->bg_free_bits_count) < num_bits);
769 mlog(0, "block_group_set_bits: off = %u, num = %u\n", bit_off,
772 if (ocfs2_is_cluster_bitmap(alloc_inode))
773 journal_type = OCFS2_JOURNAL_ACCESS_UNDO;
775 status = ocfs2_journal_access(handle,
784 le16_add_cpu(&bg->bg_free_bits_count, -num_bits);
787 ocfs2_set_bit(bit_off++, bitmap);
789 status = ocfs2_journal_dirty(handle,
801 /* find the one with the most empty bits */
802 static inline u16 ocfs2_find_victim_chain(struct ocfs2_chain_list *cl)
806 BUG_ON(!cl->cl_next_free_rec);
809 while (curr < le16_to_cpu(cl->cl_next_free_rec)) {
810 if (le32_to_cpu(cl->cl_recs[curr].c_free) >
811 le32_to_cpu(cl->cl_recs[best].c_free))
816 BUG_ON(best >= le16_to_cpu(cl->cl_next_free_rec));
820 static int ocfs2_relink_block_group(handle_t *handle,
821 struct inode *alloc_inode,
822 struct buffer_head *fe_bh,
823 struct buffer_head *bg_bh,
824 struct buffer_head *prev_bg_bh,
828 /* there is a really tiny chance the journal calls could fail,
829 * but we wouldn't want inconsistent blocks in *any* case. */
830 u64 fe_ptr, bg_ptr, prev_bg_ptr;
831 struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
832 struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data;
833 struct ocfs2_group_desc *prev_bg = (struct ocfs2_group_desc *) prev_bg_bh->b_data;
835 if (!OCFS2_IS_VALID_DINODE(fe)) {
836 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
840 if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
841 OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
845 if (!OCFS2_IS_VALID_GROUP_DESC(prev_bg)) {
846 OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, prev_bg);
851 mlog(0, "Suballoc %llu, chain %u, move group %llu to top, prev = %llu\n",
852 (unsigned long long)le64_to_cpu(fe->i_blkno), chain,
853 (unsigned long long)le64_to_cpu(bg->bg_blkno),
854 (unsigned long long)le64_to_cpu(prev_bg->bg_blkno));
856 fe_ptr = le64_to_cpu(fe->id2.i_chain.cl_recs[chain].c_blkno);
857 bg_ptr = le64_to_cpu(bg->bg_next_group);
858 prev_bg_ptr = le64_to_cpu(prev_bg->bg_next_group);
860 status = ocfs2_journal_access(handle, alloc_inode, prev_bg_bh,
861 OCFS2_JOURNAL_ACCESS_WRITE);
867 prev_bg->bg_next_group = bg->bg_next_group;
869 status = ocfs2_journal_dirty(handle, prev_bg_bh);
875 status = ocfs2_journal_access(handle, alloc_inode, bg_bh,
876 OCFS2_JOURNAL_ACCESS_WRITE);
882 bg->bg_next_group = fe->id2.i_chain.cl_recs[chain].c_blkno;
884 status = ocfs2_journal_dirty(handle, bg_bh);
890 status = ocfs2_journal_access(handle, alloc_inode, fe_bh,
891 OCFS2_JOURNAL_ACCESS_WRITE);
897 fe->id2.i_chain.cl_recs[chain].c_blkno = bg->bg_blkno;
899 status = ocfs2_journal_dirty(handle, fe_bh);
908 fe->id2.i_chain.cl_recs[chain].c_blkno = cpu_to_le64(fe_ptr);
909 bg->bg_next_group = cpu_to_le64(bg_ptr);
910 prev_bg->bg_next_group = cpu_to_le64(prev_bg_ptr);
917 static inline int ocfs2_block_group_reasonably_empty(struct ocfs2_group_desc *bg,
920 return le16_to_cpu(bg->bg_free_bits_count) > wanted;
923 /* return 0 on success, -ENOSPC to keep searching and any other < 0
925 static int ocfs2_cluster_group_search(struct inode *inode,
926 struct buffer_head *group_bh,
927 u32 bits_wanted, u32 min_bits,
928 u16 *bit_off, u16 *bits_found)
930 int search = -ENOSPC;
932 struct ocfs2_group_desc *gd = (struct ocfs2_group_desc *) group_bh->b_data;
933 u16 tmp_off, tmp_found;
934 unsigned int max_bits, gd_cluster_off;
936 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
938 if (gd->bg_free_bits_count) {
939 max_bits = le16_to_cpu(gd->bg_bits);
941 /* Tail groups in cluster bitmaps which aren't cpg
942 * aligned are prone to partial extention by a failed
943 * fs resize. If the file system resize never got to
944 * update the dinode cluster count, then we don't want
945 * to trust any clusters past it, regardless of what
946 * the group descriptor says. */
947 gd_cluster_off = ocfs2_blocks_to_clusters(inode->i_sb,
948 le64_to_cpu(gd->bg_blkno));
949 if ((gd_cluster_off + max_bits) >
950 OCFS2_I(inode)->ip_clusters) {
951 max_bits = OCFS2_I(inode)->ip_clusters - gd_cluster_off;
952 mlog(0, "Desc %llu, bg_bits %u, clusters %u, use %u\n",
953 (unsigned long long)le64_to_cpu(gd->bg_blkno),
954 le16_to_cpu(gd->bg_bits),
955 OCFS2_I(inode)->ip_clusters, max_bits);
958 ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb),
959 group_bh, bits_wanted,
961 &tmp_off, &tmp_found);
965 /* ocfs2_block_group_find_clear_bits() might
966 * return success, but we still want to return
967 * -ENOSPC unless it found the minimum number
969 if (min_bits <= tmp_found) {
971 *bits_found = tmp_found;
972 search = 0; /* success */
979 static int ocfs2_block_group_search(struct inode *inode,
980 struct buffer_head *group_bh,
981 u32 bits_wanted, u32 min_bits,
982 u16 *bit_off, u16 *bits_found)
985 struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) group_bh->b_data;
987 BUG_ON(min_bits != 1);
988 BUG_ON(ocfs2_is_cluster_bitmap(inode));
990 if (bg->bg_free_bits_count)
991 ret = ocfs2_block_group_find_clear_bits(OCFS2_SB(inode->i_sb),
992 group_bh, bits_wanted,
993 le16_to_cpu(bg->bg_bits),
994 bit_off, bits_found);
999 static int ocfs2_alloc_dinode_update_counts(struct inode *inode,
1001 struct buffer_head *di_bh,
1007 struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
1008 struct ocfs2_chain_list *cl = (struct ocfs2_chain_list *) &di->id2.i_chain;
1010 ret = ocfs2_journal_access(handle, inode, di_bh,
1011 OCFS2_JOURNAL_ACCESS_WRITE);
1017 tmp_used = le32_to_cpu(di->id1.bitmap1.i_used);
1018 di->id1.bitmap1.i_used = cpu_to_le32(num_bits + tmp_used);
1019 le32_add_cpu(&cl->cl_recs[chain].c_free, -num_bits);
1021 ret = ocfs2_journal_dirty(handle, di_bh);
1029 static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac,
1034 unsigned int *num_bits,
1040 struct buffer_head *group_bh = NULL;
1041 struct ocfs2_group_desc *gd;
1042 struct inode *alloc_inode = ac->ac_inode;
1044 ret = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb), gd_blkno,
1045 &group_bh, OCFS2_BH_CACHED, alloc_inode);
1051 gd = (struct ocfs2_group_desc *) group_bh->b_data;
1052 if (!OCFS2_IS_VALID_GROUP_DESC(gd)) {
1053 OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, gd);
1058 ret = ac->ac_group_search(alloc_inode, group_bh, bits_wanted, min_bits,
1068 ret = ocfs2_alloc_dinode_update_counts(alloc_inode, handle, ac->ac_bh,
1070 le16_to_cpu(gd->bg_chain));
1076 ret = ocfs2_block_group_set_bits(handle, alloc_inode, gd, group_bh,
1077 *bit_off, *num_bits);
1081 *bits_left = le16_to_cpu(gd->bg_free_bits_count);
1089 static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
1094 unsigned int *num_bits,
1099 u16 chain, tmp_bits;
1102 struct inode *alloc_inode = ac->ac_inode;
1103 struct buffer_head *group_bh = NULL;
1104 struct buffer_head *prev_group_bh = NULL;
1105 struct ocfs2_dinode *fe = (struct ocfs2_dinode *) ac->ac_bh->b_data;
1106 struct ocfs2_chain_list *cl = (struct ocfs2_chain_list *) &fe->id2.i_chain;
1107 struct ocfs2_group_desc *bg;
1109 chain = ac->ac_chain;
1110 mlog(0, "trying to alloc %u bits from chain %u, inode %llu\n",
1112 (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno);
1114 status = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb),
1115 le64_to_cpu(cl->cl_recs[chain].c_blkno),
1116 &group_bh, OCFS2_BH_CACHED, alloc_inode);
1121 bg = (struct ocfs2_group_desc *) group_bh->b_data;
1122 status = ocfs2_check_group_descriptor(alloc_inode->i_sb, fe, bg);
1129 /* for now, the chain search is a bit simplistic. We just use
1130 * the 1st group with any empty bits. */
1131 while ((status = ac->ac_group_search(alloc_inode, group_bh,
1132 bits_wanted, min_bits, bit_off,
1133 &tmp_bits)) == -ENOSPC) {
1134 if (!bg->bg_next_group)
1137 if (prev_group_bh) {
1138 brelse(prev_group_bh);
1139 prev_group_bh = NULL;
1141 next_group = le64_to_cpu(bg->bg_next_group);
1142 prev_group_bh = group_bh;
1144 status = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb),
1145 next_group, &group_bh,
1146 OCFS2_BH_CACHED, alloc_inode);
1151 bg = (struct ocfs2_group_desc *) group_bh->b_data;
1152 status = ocfs2_check_group_descriptor(alloc_inode->i_sb, fe, bg);
1159 if (status != -ENOSPC)
1164 mlog(0, "alloc succeeds: we give %u bits from block group %llu\n",
1165 tmp_bits, (unsigned long long)le64_to_cpu(bg->bg_blkno));
1167 *num_bits = tmp_bits;
1169 BUG_ON(*num_bits == 0);
1172 * Keep track of previous block descriptor read. When
1173 * we find a target, if we have read more than X
1174 * number of descriptors, and the target is reasonably
1175 * empty, relink him to top of his chain.
1177 * We've read 0 extra blocks and only send one more to
1178 * the transaction, yet the next guy to search has a
1181 * Do this *after* figuring out how many bits we're taking out
1182 * of our target group.
1184 if (ac->ac_allow_chain_relink &&
1186 (ocfs2_block_group_reasonably_empty(bg, *num_bits))) {
1187 status = ocfs2_relink_block_group(handle, alloc_inode,
1188 ac->ac_bh, group_bh,
1189 prev_group_bh, chain);
1196 /* Ok, claim our bits now: set the info on dinode, chainlist
1197 * and then the group */
1198 status = ocfs2_journal_access(handle,
1201 OCFS2_JOURNAL_ACCESS_WRITE);
1207 tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
1208 fe->id1.bitmap1.i_used = cpu_to_le32(*num_bits + tmp_used);
1209 le32_add_cpu(&cl->cl_recs[chain].c_free, -(*num_bits));
1211 status = ocfs2_journal_dirty(handle,
1218 status = ocfs2_block_group_set_bits(handle,
1229 mlog(0, "Allocated %u bits from suballocator %llu\n", *num_bits,
1230 (unsigned long long)le64_to_cpu(fe->i_blkno));
1232 *bg_blkno = le64_to_cpu(bg->bg_blkno);
1233 *bits_left = le16_to_cpu(bg->bg_free_bits_count);
1238 brelse(prev_group_bh);
1244 /* will give out up to bits_wanted contiguous bits. */
1245 static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
1246 struct ocfs2_alloc_context *ac,
1251 unsigned int *num_bits,
1257 u64 hint_blkno = ac->ac_last_group;
1258 struct ocfs2_chain_list *cl;
1259 struct ocfs2_dinode *fe;
1263 BUG_ON(ac->ac_bits_given >= ac->ac_bits_wanted);
1264 BUG_ON(bits_wanted > (ac->ac_bits_wanted - ac->ac_bits_given));
1267 fe = (struct ocfs2_dinode *) ac->ac_bh->b_data;
1268 if (!OCFS2_IS_VALID_DINODE(fe)) {
1269 OCFS2_RO_ON_INVALID_DINODE(osb->sb, fe);
1273 if (le32_to_cpu(fe->id1.bitmap1.i_used) >=
1274 le32_to_cpu(fe->id1.bitmap1.i_total)) {
1275 ocfs2_error(osb->sb, "Chain allocator dinode %llu has %u used "
1276 "bits but only %u total.",
1277 (unsigned long long)le64_to_cpu(fe->i_blkno),
1278 le32_to_cpu(fe->id1.bitmap1.i_used),
1279 le32_to_cpu(fe->id1.bitmap1.i_total));
1285 /* Attempt to short-circuit the usual search mechanism
1286 * by jumping straight to the most recently used
1287 * allocation group. This helps us mantain some
1288 * contiguousness across allocations. */
1289 status = ocfs2_search_one_group(ac, handle, bits_wanted,
1290 min_bits, bit_off, num_bits,
1291 hint_blkno, &bits_left);
1293 /* Be careful to update *bg_blkno here as the
1294 * caller is expecting it to be filled in, and
1295 * ocfs2_search_one_group() won't do that for
1297 *bg_blkno = hint_blkno;
1300 if (status < 0 && status != -ENOSPC) {
1306 cl = (struct ocfs2_chain_list *) &fe->id2.i_chain;
1308 victim = ocfs2_find_victim_chain(cl);
1309 ac->ac_chain = victim;
1310 ac->ac_allow_chain_relink = 1;
1312 status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits, bit_off,
1313 num_bits, bg_blkno, &bits_left);
1316 if (status < 0 && status != -ENOSPC) {
1321 mlog(0, "Search of victim chain %u came up with nothing, "
1322 "trying all chains now.\n", victim);
1324 /* If we didn't pick a good victim, then just default to
1325 * searching each chain in order. Don't allow chain relinking
1326 * because we only calculate enough journal credits for one
1327 * relink per alloc. */
1328 ac->ac_allow_chain_relink = 0;
1329 for (i = 0; i < le16_to_cpu(cl->cl_next_free_rec); i ++) {
1332 if (!cl->cl_recs[i].c_free)
1336 status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits,
1337 bit_off, num_bits, bg_blkno,
1341 if (status < 0 && status != -ENOSPC) {
1348 if (status != -ENOSPC) {
1349 /* If the next search of this group is not likely to
1350 * yield a suitable extent, then we reset the last
1351 * group hint so as to not waste a disk read */
1352 if (bits_left < min_bits)
1353 ac->ac_last_group = 0;
1355 ac->ac_last_group = *bg_blkno;
1363 int ocfs2_claim_metadata(struct ocfs2_super *osb,
1365 struct ocfs2_alloc_context *ac,
1367 u16 *suballoc_bit_start,
1368 unsigned int *num_bits,
1375 BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted));
1376 BUG_ON(ac->ac_which != OCFS2_AC_USE_META);
1378 status = ocfs2_claim_suballoc_bits(osb,
1390 atomic_inc(&osb->alloc_stats.bg_allocs);
1392 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
1393 ac->ac_bits_given += (*num_bits);
1400 int ocfs2_claim_new_inode(struct ocfs2_super *osb,
1402 struct ocfs2_alloc_context *ac,
1407 unsigned int num_bits;
1413 BUG_ON(ac->ac_bits_given != 0);
1414 BUG_ON(ac->ac_bits_wanted != 1);
1415 BUG_ON(ac->ac_which != OCFS2_AC_USE_INODE);
1417 status = ocfs2_claim_suballoc_bits(osb,
1429 atomic_inc(&osb->alloc_stats.bg_allocs);
1431 BUG_ON(num_bits != 1);
1433 *fe_blkno = bg_blkno + (u64) (*suballoc_bit);
1434 ac->ac_bits_given++;
1441 /* translate a group desc. blkno and it's bitmap offset into
1442 * disk cluster offset. */
1443 static inline u32 ocfs2_desc_bitmap_to_cluster_off(struct inode *inode,
1447 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1450 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
1452 if (bg_blkno != osb->first_cluster_group_blkno)
1453 cluster = ocfs2_blocks_to_clusters(inode->i_sb, bg_blkno);
1454 cluster += (u32) bg_bit_off;
1458 /* given a cluster offset, calculate which block group it belongs to
1459 * and return that block offset. */
1460 static inline u64 ocfs2_which_cluster_group(struct inode *inode,
1463 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1466 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
1468 group_no = cluster / osb->bitmap_cpg;
1470 return osb->first_cluster_group_blkno;
1471 return ocfs2_clusters_to_blocks(inode->i_sb,
1472 group_no * osb->bitmap_cpg);
1475 /* given the block number of a cluster start, calculate which cluster
1476 * group and descriptor bitmap offset that corresponds to. */
1477 static inline void ocfs2_block_to_cluster_group(struct inode *inode,
1482 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1483 u32 data_cluster = ocfs2_blocks_to_clusters(osb->sb, data_blkno);
1485 BUG_ON(!ocfs2_is_cluster_bitmap(inode));
1487 *bg_blkno = ocfs2_which_cluster_group(inode,
1490 if (*bg_blkno == osb->first_cluster_group_blkno)
1491 *bg_bit_off = (u16) data_cluster;
1493 *bg_bit_off = (u16) ocfs2_blocks_to_clusters(osb->sb,
1494 data_blkno - *bg_blkno);
1498 * min_bits - minimum contiguous chunk from this total allocation we
1499 * can handle. set to what we asked for originally for a full
1500 * contig. allocation, set to '1' to indicate we can deal with extents
1503 int ocfs2_claim_clusters(struct ocfs2_super *osb,
1505 struct ocfs2_alloc_context *ac,
1511 unsigned int bits_wanted = ac->ac_bits_wanted - ac->ac_bits_given;
1518 BUG_ON(ac->ac_bits_given >= ac->ac_bits_wanted);
1520 BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL
1521 && ac->ac_which != OCFS2_AC_USE_MAIN);
1523 if (ac->ac_which == OCFS2_AC_USE_LOCAL) {
1524 status = ocfs2_claim_local_alloc_bits(osb,
1531 atomic_inc(&osb->alloc_stats.local_data);
1533 if (min_clusters > (osb->bitmap_cpg - 1)) {
1534 /* The only paths asking for contiguousness
1535 * should know about this already. */
1536 mlog(ML_ERROR, "minimum allocation requested exceeds "
1537 "group bitmap size!");
1541 /* clamp the current request down to a realistic size. */
1542 if (bits_wanted > (osb->bitmap_cpg - 1))
1543 bits_wanted = osb->bitmap_cpg - 1;
1545 status = ocfs2_claim_suballoc_bits(osb,
1555 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
1558 atomic_inc(&osb->alloc_stats.bitmap_data);
1562 if (status != -ENOSPC)
1567 ac->ac_bits_given += *num_clusters;
1574 static inline int ocfs2_block_group_clear_bits(handle_t *handle,
1575 struct inode *alloc_inode,
1576 struct ocfs2_group_desc *bg,
1577 struct buffer_head *group_bh,
1578 unsigned int bit_off,
1579 unsigned int num_bits)
1583 int journal_type = OCFS2_JOURNAL_ACCESS_WRITE;
1584 struct ocfs2_group_desc *undo_bg = NULL;
1588 if (!OCFS2_IS_VALID_GROUP_DESC(bg)) {
1589 OCFS2_RO_ON_INVALID_GROUP_DESC(alloc_inode->i_sb, bg);
1594 mlog(0, "off = %u, num = %u\n", bit_off, num_bits);
1596 if (ocfs2_is_cluster_bitmap(alloc_inode))
1597 journal_type = OCFS2_JOURNAL_ACCESS_UNDO;
1599 status = ocfs2_journal_access(handle, alloc_inode, group_bh,
1606 if (ocfs2_is_cluster_bitmap(alloc_inode))
1607 undo_bg = (struct ocfs2_group_desc *) bh2jh(group_bh)->b_committed_data;
1611 ocfs2_clear_bit((bit_off + tmp),
1612 (unsigned long *) bg->bg_bitmap);
1613 if (ocfs2_is_cluster_bitmap(alloc_inode))
1614 ocfs2_set_bit(bit_off + tmp,
1615 (unsigned long *) undo_bg->bg_bitmap);
1617 le16_add_cpu(&bg->bg_free_bits_count, num_bits);
1619 status = ocfs2_journal_dirty(handle, group_bh);
1627 * expects the suballoc inode to already be locked.
1629 static int ocfs2_free_suballoc_bits(handle_t *handle,
1630 struct inode *alloc_inode,
1631 struct buffer_head *alloc_bh,
1632 unsigned int start_bit,
1638 struct ocfs2_super *osb = OCFS2_SB(alloc_inode->i_sb);
1639 struct ocfs2_dinode *fe = (struct ocfs2_dinode *) alloc_bh->b_data;
1640 struct ocfs2_chain_list *cl = &fe->id2.i_chain;
1641 struct buffer_head *group_bh = NULL;
1642 struct ocfs2_group_desc *group;
1646 if (!OCFS2_IS_VALID_DINODE(fe)) {
1647 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
1651 BUG_ON((count + start_bit) > ocfs2_bits_per_group(cl));
1653 mlog(0, "%llu: freeing %u bits from group %llu, starting at %u\n",
1654 (unsigned long long)OCFS2_I(alloc_inode)->ip_blkno, count,
1655 (unsigned long long)bg_blkno, start_bit);
1657 status = ocfs2_read_block(osb, bg_blkno, &group_bh, OCFS2_BH_CACHED,
1664 group = (struct ocfs2_group_desc *) group_bh->b_data;
1665 status = ocfs2_check_group_descriptor(alloc_inode->i_sb, fe, group);
1670 BUG_ON((count + start_bit) > le16_to_cpu(group->bg_bits));
1672 status = ocfs2_block_group_clear_bits(handle, alloc_inode,
1680 status = ocfs2_journal_access(handle, alloc_inode, alloc_bh,
1681 OCFS2_JOURNAL_ACCESS_WRITE);
1687 le32_add_cpu(&cl->cl_recs[le16_to_cpu(group->bg_chain)].c_free,
1689 tmp_used = le32_to_cpu(fe->id1.bitmap1.i_used);
1690 fe->id1.bitmap1.i_used = cpu_to_le32(tmp_used - count);
1692 status = ocfs2_journal_dirty(handle, alloc_bh);
1706 static inline u64 ocfs2_which_suballoc_group(u64 block, unsigned int bit)
1708 u64 group = block - (u64) bit;
1713 int ocfs2_free_dinode(handle_t *handle,
1714 struct inode *inode_alloc_inode,
1715 struct buffer_head *inode_alloc_bh,
1716 struct ocfs2_dinode *di)
1718 u64 blk = le64_to_cpu(di->i_blkno);
1719 u16 bit = le16_to_cpu(di->i_suballoc_bit);
1720 u64 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
1722 return ocfs2_free_suballoc_bits(handle, inode_alloc_inode,
1723 inode_alloc_bh, bit, bg_blkno, 1);
1726 int ocfs2_free_extent_block(handle_t *handle,
1727 struct inode *eb_alloc_inode,
1728 struct buffer_head *eb_alloc_bh,
1729 struct ocfs2_extent_block *eb)
1731 u64 blk = le64_to_cpu(eb->h_blkno);
1732 u16 bit = le16_to_cpu(eb->h_suballoc_bit);
1733 u64 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
1735 return ocfs2_free_suballoc_bits(handle, eb_alloc_inode, eb_alloc_bh,
1739 int ocfs2_free_clusters(handle_t *handle,
1740 struct inode *bitmap_inode,
1741 struct buffer_head *bitmap_bh,
1743 unsigned int num_clusters)
1748 struct ocfs2_dinode *fe;
1750 /* You can't ever have a contiguous set of clusters
1751 * bigger than a block group bitmap so we never have to worry
1752 * about looping on them. */
1756 /* This is expensive. We can safely remove once this stuff has
1757 * gotten tested really well. */
1758 BUG_ON(start_blk != ocfs2_clusters_to_blocks(bitmap_inode->i_sb, ocfs2_blocks_to_clusters(bitmap_inode->i_sb, start_blk)));
1760 fe = (struct ocfs2_dinode *) bitmap_bh->b_data;
1762 ocfs2_block_to_cluster_group(bitmap_inode, start_blk, &bg_blkno,
1765 mlog(0, "want to free %u clusters starting at block %llu\n",
1766 num_clusters, (unsigned long long)start_blk);
1767 mlog(0, "bg_blkno = %llu, bg_start_bit = %u\n",
1768 (unsigned long long)bg_blkno, bg_start_bit);
1770 status = ocfs2_free_suballoc_bits(handle, bitmap_inode, bitmap_bh,
1771 bg_start_bit, bg_blkno,
1780 static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg)
1782 printk("Block Group:\n");
1783 printk("bg_signature: %s\n", bg->bg_signature);
1784 printk("bg_size: %u\n", bg->bg_size);
1785 printk("bg_bits: %u\n", bg->bg_bits);
1786 printk("bg_free_bits_count: %u\n", bg->bg_free_bits_count);
1787 printk("bg_chain: %u\n", bg->bg_chain);
1788 printk("bg_generation: %u\n", le32_to_cpu(bg->bg_generation));
1789 printk("bg_next_group: %llu\n",
1790 (unsigned long long)bg->bg_next_group);
1791 printk("bg_parent_dinode: %llu\n",
1792 (unsigned long long)bg->bg_parent_dinode);
1793 printk("bg_blkno: %llu\n",
1794 (unsigned long long)bg->bg_blkno);
1797 static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe)
1801 printk("Suballoc Inode %llu:\n", (unsigned long long)fe->i_blkno);
1802 printk("i_signature: %s\n", fe->i_signature);
1803 printk("i_size: %llu\n",
1804 (unsigned long long)fe->i_size);
1805 printk("i_clusters: %u\n", fe->i_clusters);
1806 printk("i_generation: %u\n",
1807 le32_to_cpu(fe->i_generation));
1808 printk("id1.bitmap1.i_used: %u\n",
1809 le32_to_cpu(fe->id1.bitmap1.i_used));
1810 printk("id1.bitmap1.i_total: %u\n",
1811 le32_to_cpu(fe->id1.bitmap1.i_total));
1812 printk("id2.i_chain.cl_cpg: %u\n", fe->id2.i_chain.cl_cpg);
1813 printk("id2.i_chain.cl_bpc: %u\n", fe->id2.i_chain.cl_bpc);
1814 printk("id2.i_chain.cl_count: %u\n", fe->id2.i_chain.cl_count);
1815 printk("id2.i_chain.cl_next_free_rec: %u\n",
1816 fe->id2.i_chain.cl_next_free_rec);
1817 for(i = 0; i < fe->id2.i_chain.cl_next_free_rec; i++) {
1818 printk("fe->id2.i_chain.cl_recs[%d].c_free: %u\n", i,
1819 fe->id2.i_chain.cl_recs[i].c_free);
1820 printk("fe->id2.i_chain.cl_recs[%d].c_total: %u\n", i,
1821 fe->id2.i_chain.cl_recs[i].c_total);
1822 printk("fe->id2.i_chain.cl_recs[%d].c_blkno: %llu\n", i,
1823 (unsigned long long)fe->id2.i_chain.cl_recs[i].c_blkno);