Skip to content

Commit 4cbe424

Browse files
Joel BeckerTao Ma
authored andcommitted
ocfs2: Define data structures for discontiguous block groups.
Defines the OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG feature bit and modifies struct ocfs2_group_desc for the feature. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Tao Ma <tao.ma@oracle.com>
1 parent 0467ae9 commit 4cbe424

5 files changed

Lines changed: 51 additions & 12 deletions

File tree

‎fs/ocfs2/localalloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ unsigned int ocfs2_la_default_mb(struct ocfs2_super *osb)
122122
struct super_block *sb = osb->sb;
123123

124124
gd_mb = ocfs2_clusters_to_megabytes(osb->sb,
125-
8 * ocfs2_group_bitmap_size(sb));
125+
8 * ocfs2_group_bitmap_size(sb, 0));
126126

127127
/*
128128
* This takes care of files systems with very small group

‎fs/ocfs2/ocfs2_fs.h‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@
165165
/* Refcount tree support */
166166
#define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
167167

168+
/* Discontigous block groups */
169+
#define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
170+
168171
/*
169172
* backup superblock flag is used to indicate that this volume
170173
* has backup superblocks.
@@ -831,6 +834,13 @@ struct ocfs2_dx_leaf {
831834
struct ocfs2_dx_entry_list dl_list;
832835
};
833836

837+
/*
838+
* Largest bitmap for a block (suballocator) group in bytes. This limit
839+
* does not affect cluster groups (global allocator). Cluster group
840+
* bitmaps run to the end of the block.
841+
*/
842+
#define OCFS2_MAX_BG_BITMAP_SIZE 256
843+
834844
/*
835845
* On disk allocator group structure for OCFS2
836846
*/
@@ -852,7 +862,29 @@ struct ocfs2_group_desc
852862
__le64 bg_blkno; /* Offset on disk, in blocks */
853863
/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
854864
__le64 bg_reserved2;
855-
/*40*/ __u8 bg_bitmap[0];
865+
/*40*/ union {
866+
__u8 bg_bitmap[0];
867+
struct {
868+
/*
869+
* Block groups may be discontiguous when
870+
* OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
871+
* The extents of a discontigous block group are
872+
* stored in bg_list. It is a flat list.
873+
* l_tree_depth must always be zero. A
874+
* discontiguous group is signified by a non-zero
875+
* bg_list->l_next_free_rec. Only block groups
876+
* can be discontiguous; Cluster groups cannot.
877+
* We've never made a block group with more than
878+
* 2048 blocks (256 bytes of bg_bitmap). This
879+
* codifies that limit so that we can fit bg_list.
880+
* bg_size of a discontiguous block group will
881+
* be 256 to match bg_bitmap_filler.
882+
*/
883+
__u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
884+
/*140*/ struct ocfs2_extent_list bg_list;
885+
};
886+
};
887+
/* Actual on-disk size is one block */
856888
};
857889

858890
struct ocfs2_refcount_rec {
@@ -1276,12 +1308,16 @@ static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
12761308
return size;
12771309
}
12781310

1279-
static inline int ocfs2_group_bitmap_size(struct super_block *sb)
1311+
static inline int ocfs2_group_bitmap_size(struct super_block *sb,
1312+
int suballocator)
12801313
{
12811314
int size;
12821315

1283-
size = sb->s_blocksize -
1284-
offsetof(struct ocfs2_group_desc, bg_bitmap);
1316+
if (suballocator)
1317+
size = OCFS2_MAX_BG_BITMAP_SIZE;
1318+
else
1319+
size = sb->s_blocksize -
1320+
offsetof(struct ocfs2_group_desc, bg_bitmap);
12851321

12861322
return size;
12871323
}
@@ -1404,12 +1440,15 @@ static inline int ocfs2_local_alloc_size(int blocksize)
14041440
return size;
14051441
}
14061442

1407-
static inline int ocfs2_group_bitmap_size(int blocksize)
1443+
static inline int ocfs2_group_bitmap_size(int blocksize, int suballocator)
14081444
{
14091445
int size;
14101446

1411-
size = blocksize -
1412-
offsetof(struct ocfs2_group_desc, bg_bitmap);
1447+
if (suballocator)
1448+
size = OCFS2_MAX_BG_BITMAP_SIZE;
1449+
else
1450+
size = blocksize -
1451+
offsetof(struct ocfs2_group_desc, bg_bitmap);
14131452

14141453
return size;
14151454
}

‎fs/ocfs2/resize.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ int ocfs2_group_extend(struct inode * inode, int new_clusters)
315315
BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
316316

317317
if (le16_to_cpu(fe->id2.i_chain.cl_cpg) !=
318-
ocfs2_group_bitmap_size(osb->sb) * 8) {
318+
ocfs2_group_bitmap_size(osb->sb, 0) * 8) {
319319
mlog(ML_ERROR, "The disk is too old and small. "
320320
"Force to do offline resize.");
321321
ret = -EINVAL;
@@ -496,7 +496,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
496496
fe = (struct ocfs2_dinode *)main_bm_bh->b_data;
497497

498498
if (le16_to_cpu(fe->id2.i_chain.cl_cpg) !=
499-
ocfs2_group_bitmap_size(osb->sb) * 8) {
499+
ocfs2_group_bitmap_size(osb->sb, 0) * 8) {
500500
mlog(ML_ERROR, "The disk is too old and small."
501501
" Force to do offline resize.");
502502
ret = -EINVAL;

‎fs/ocfs2/suballoc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static int ocfs2_block_group_fill(handle_t *handle,
360360
memset(bg, 0, sb->s_blocksize);
361361
strcpy(bg->bg_signature, OCFS2_GROUP_DESC_SIGNATURE);
362362
bg->bg_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation);
363-
bg->bg_size = cpu_to_le16(ocfs2_group_bitmap_size(sb));
363+
bg->bg_size = cpu_to_le16(ocfs2_group_bitmap_size(sb, 1));
364364
bg->bg_bits = cpu_to_le16(ocfs2_bits_per_group(cl));
365365
bg->bg_chain = cpu_to_le16(my_chain);
366366
bg->bg_next_group = cl->cl_recs[my_chain].c_blkno;

‎fs/ocfs2/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
22772277
osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
22782278
iput(inode);
22792279

2280-
osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
2280+
osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0) * 8;
22812281

22822282
status = ocfs2_init_slot_info(osb);
22832283
if (status < 0) {

0 commit comments

Comments
 (0)