Skip to content

Commit 84e4008

Browse files
committed
ocfs2: convert inode refcount test to a helper
Replace the open-coded inode refcount flag test with a helper function to reduce the potential for bugs. Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 876bec6 commit 84e4008

File tree

6 files changed

+23
-29
lines changed

6 files changed

+23
-29
lines changed

fs/ocfs2/alloc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -5713,8 +5713,7 @@ int ocfs2_remove_btree_range(struct inode *inode,
57135713
struct ocfs2_refcount_tree *ref_tree = NULL;
57145714

57155715
if ((flags & OCFS2_EXT_REFCOUNTED) && len) {
5716-
BUG_ON(!(OCFS2_I(inode)->ip_dyn_features &
5717-
OCFS2_HAS_REFCOUNT_FL));
5716+
BUG_ON(!ocfs2_is_refcount_inode(inode));
57185717

57195718
if (!refcount_tree_locked) {
57205719
ret = ocfs2_lock_refcount_tree(osb, refcount_loc, 1,

fs/ocfs2/file.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ int ocfs2_extend_no_holes(struct inode *inode, struct buffer_head *di_bh,
10301030
* Only quota files call this without a bh, and they can't be
10311031
* refcounted.
10321032
*/
1033-
BUG_ON(!di_bh && (oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
1033+
BUG_ON(!di_bh && ocfs2_is_refcount_inode(inode));
10341034
BUG_ON(!di_bh && !(oi->ip_flags & OCFS2_INODE_SYSTEM_FILE));
10351035

10361036
clusters_to_add = ocfs2_clusters_for_bytes(inode->i_sb, new_i_size);
@@ -1719,8 +1719,7 @@ static int ocfs2_remove_inode_range(struct inode *inode,
17191719
* within one cluster(means is not exactly aligned to clustersize).
17201720
*/
17211721

1722-
if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) {
1723-
1722+
if (ocfs2_is_refcount_inode(inode)) {
17241723
ret = ocfs2_cow_file_pos(inode, di_bh, byte_start);
17251724
if (ret) {
17261725
mlog_errno(ret);
@@ -2036,7 +2035,7 @@ int ocfs2_check_range_for_refcount(struct inode *inode, loff_t pos,
20362035
struct super_block *sb = inode->i_sb;
20372036

20382037
if (!ocfs2_refcount_tree(OCFS2_SB(inode->i_sb)) ||
2039-
!(OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) ||
2038+
!ocfs2_is_refcount_inode(inode) ||
20402039
OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
20412040
return 0;
20422041

fs/ocfs2/inode.h

+6
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,10 @@ static inline struct ocfs2_inode_info *cache_info_to_inode(struct ocfs2_caching_
181181
return container_of(ci, struct ocfs2_inode_info, ip_metadata_cache);
182182
}
183183

184+
/* Does this inode have the reflink flag set? */
185+
static inline bool ocfs2_is_refcount_inode(struct inode *inode)
186+
{
187+
return (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
188+
}
189+
184190
#endif /* OCFS2_INODE_H */

fs/ocfs2/move_extents.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context,
235235
u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
236236

237237
if ((ext_flags & OCFS2_EXT_REFCOUNTED) && *len) {
238-
239-
BUG_ON(!(OCFS2_I(inode)->ip_dyn_features &
240-
OCFS2_HAS_REFCOUNT_FL));
241-
238+
BUG_ON(!ocfs2_is_refcount_inode(inode));
242239
BUG_ON(!context->refcount_loc);
243240

244241
ret = ocfs2_lock_refcount_tree(osb, context->refcount_loc, 1,
@@ -581,10 +578,7 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
581578
phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
582579

583580
if ((ext_flags & OCFS2_EXT_REFCOUNTED) && len) {
584-
585-
BUG_ON(!(OCFS2_I(inode)->ip_dyn_features &
586-
OCFS2_HAS_REFCOUNT_FL));
587-
581+
BUG_ON(!ocfs2_is_refcount_inode(inode));
588582
BUG_ON(!context->refcount_loc);
589583

590584
ret = ocfs2_lock_refcount_tree(osb, context->refcount_loc, 1,

fs/ocfs2/refcounttree.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static int ocfs2_get_refcount_block(struct inode *inode, u64 *ref_blkno)
410410
goto out;
411411
}
412412

413-
BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
413+
BUG_ON(!ocfs2_is_refcount_inode(inode));
414414

415415
di = (struct ocfs2_dinode *)di_bh->b_data;
416416
*ref_blkno = le64_to_cpu(di->i_refcount_loc);
@@ -570,7 +570,7 @@ static int ocfs2_create_refcount_tree(struct inode *inode,
570570
u32 num_got;
571571
u64 suballoc_loc, first_blkno;
572572

573-
BUG_ON(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
573+
BUG_ON(ocfs2_is_refcount_inode(inode));
574574

575575
trace_ocfs2_create_refcount_tree(
576576
(unsigned long long)OCFS2_I(inode)->ip_blkno);
@@ -708,7 +708,7 @@ static int ocfs2_set_refcount_tree(struct inode *inode,
708708
struct ocfs2_refcount_block *rb;
709709
struct ocfs2_refcount_tree *ref_tree;
710710

711-
BUG_ON(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL);
711+
BUG_ON(ocfs2_is_refcount_inode(inode));
712712

713713
ret = ocfs2_lock_refcount_tree(osb, refcount_loc, 1,
714714
&ref_tree, &ref_root_bh);
@@ -775,7 +775,7 @@ int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh)
775775
u64 blk = 0, bg_blkno = 0, ref_blkno = le64_to_cpu(di->i_refcount_loc);
776776
u16 bit = 0;
777777

778-
if (!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL))
778+
if (!ocfs2_is_refcount_inode(inode))
779779
return 0;
780780

781781
BUG_ON(!ref_blkno);
@@ -2299,11 +2299,10 @@ int ocfs2_decrease_refcount(struct inode *inode,
22992299
{
23002300
int ret;
23012301
u64 ref_blkno;
2302-
struct ocfs2_inode_info *oi = OCFS2_I(inode);
23032302
struct buffer_head *ref_root_bh = NULL;
23042303
struct ocfs2_refcount_tree *tree;
23052304

2306-
BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
2305+
BUG_ON(!ocfs2_is_refcount_inode(inode));
23072306

23082307
ret = ocfs2_get_refcount_block(inode, &ref_blkno);
23092308
if (ret) {
@@ -2533,7 +2532,6 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
25332532
int *ref_blocks)
25342533
{
25352534
int ret;
2536-
struct ocfs2_inode_info *oi = OCFS2_I(inode);
25372535
struct buffer_head *ref_root_bh = NULL;
25382536
struct ocfs2_refcount_tree *tree;
25392537
u64 start_cpos = ocfs2_blocks_to_clusters(inode->i_sb, phys_blkno);
@@ -2544,7 +2542,7 @@ int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
25442542
goto out;
25452543
}
25462544

2547-
BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
2545+
BUG_ON(!ocfs2_is_refcount_inode(inode));
25482546

25492547
ret = ocfs2_get_refcount_tree(OCFS2_SB(inode->i_sb),
25502548
refcount_loc, &tree);
@@ -3412,14 +3410,13 @@ static int ocfs2_refcount_cow_hunk(struct inode *inode,
34123410
{
34133411
int ret;
34143412
u32 cow_start = 0, cow_len = 0;
3415-
struct ocfs2_inode_info *oi = OCFS2_I(inode);
34163413
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
34173414
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
34183415
struct buffer_head *ref_root_bh = NULL;
34193416
struct ocfs2_refcount_tree *ref_tree;
34203417
struct ocfs2_cow_context *context = NULL;
34213418

3422-
BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
3419+
BUG_ON(!ocfs2_is_refcount_inode(inode));
34233420

34243421
ret = ocfs2_refcount_cal_cow_clusters(inode, &di->id2.i_list,
34253422
cpos, write_len, max_cpos,
@@ -3629,11 +3626,10 @@ int ocfs2_refcount_cow_xattr(struct inode *inode,
36293626
{
36303627
int ret;
36313628
struct ocfs2_xattr_value_root *xv = vb->vb_xv;
3632-
struct ocfs2_inode_info *oi = OCFS2_I(inode);
36333629
struct ocfs2_cow_context *context = NULL;
36343630
u32 cow_start, cow_len;
36353631

3636-
BUG_ON(!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL));
3632+
BUG_ON(!ocfs2_is_refcount_inode(inode));
36373633

36383634
ret = ocfs2_refcount_cal_cow_clusters(inode, &xv->xr_list,
36393635
cpos, write_len, UINT_MAX,
@@ -3807,7 +3803,7 @@ static int ocfs2_attach_refcount_tree(struct inode *inode,
38073803

38083804
ocfs2_init_dealloc_ctxt(&dealloc);
38093805

3810-
if (!(oi->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL)) {
3806+
if (!ocfs2_is_refcount_inode(inode)) {
38113807
ret = ocfs2_create_refcount_tree(inode, di_bh);
38123808
if (ret) {
38133809
mlog_errno(ret);

fs/ocfs2/xattr.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh)
25772577
if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
25782578
return 0;
25792579

2580-
if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL) {
2580+
if (ocfs2_is_refcount_inode(inode)) {
25812581
ret = ocfs2_lock_refcount_tree(OCFS2_SB(inode->i_sb),
25822582
le64_to_cpu(di->i_refcount_loc),
25832583
1, &ref_tree, &ref_root_bh);
@@ -3608,7 +3608,7 @@ int ocfs2_xattr_set(struct inode *inode,
36083608
}
36093609

36103610
/* Check whether the value is refcounted and do some preparation. */
3611-
if (OCFS2_I(inode)->ip_dyn_features & OCFS2_HAS_REFCOUNT_FL &&
3611+
if (ocfs2_is_refcount_inode(inode) &&
36123612
(!xis.not_found || !xbs.not_found)) {
36133613
ret = ocfs2_prepare_refcount_xattr(inode, di, &xi,
36143614
&xis, &xbs, &ref_tree,

0 commit comments

Comments
 (0)