Skip to content

Commit 46fcb2e

Browse files
Eric Sandeenswhiteho
authored andcommitted
GFS2: combine duplicated block freeing routines
__gfs2_free_data and __gfs2_free_meta are almost identical, and can be trivially combined. [This is as per Eric's original patch minus gfs2_free_data() which had no callers left and plus the conversion of the bmap.c calls to these functions. All in all, a nice clean up] Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 9964afb commit 46fcb2e

3 files changed

Lines changed: 8 additions & 60 deletions

File tree

‎fs/gfs2/bmap.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
854854
blen++;
855855
else {
856856
if (bstart) {
857-
if (metadata)
858-
__gfs2_free_meta(ip, bstart, blen);
859-
else
860-
__gfs2_free_data(ip, bstart, blen);
861-
857+
__gfs2_free_blocks(ip, bstart, blen, metadata);
862858
btotal += blen;
863859
}
864860

@@ -870,11 +866,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
870866
gfs2_add_inode_blocks(&ip->i_inode, -1);
871867
}
872868
if (bstart) {
873-
if (metadata)
874-
__gfs2_free_meta(ip, bstart, blen);
875-
else
876-
__gfs2_free_data(ip, bstart, blen);
877-
869+
__gfs2_free_blocks(ip, bstart, blen, metadata);
878870
btotal += blen;
879871
}
880872

‎fs/gfs2/rgrp.c‎

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,14 +1607,15 @@ int gfs2_alloc_di(struct gfs2_inode *dip, u64 *bn, u64 *generation)
16071607
}
16081608

16091609
/**
1610-
* gfs2_free_data - free a contiguous run of data block(s)
1610+
* __gfs2_free_blocks - free a contiguous run of block(s)
16111611
* @ip: the inode these blocks are being freed from
16121612
* @bstart: first block of a run of contiguous blocks
16131613
* @blen: the length of the block run
1614+
* @meta: 1 if the blocks represent metadata
16141615
*
16151616
*/
16161617

1617-
void __gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
1618+
void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta)
16181619
{
16191620
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
16201621
struct gfs2_rgrpd *rgd;
@@ -1631,53 +1632,10 @@ void __gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
16311632
gfs2_trans_add_rg(rgd);
16321633

16331634
/* Directories keep their data in the metadata address space */
1634-
if (ip->i_depth)
1635+
if (meta || ip->i_depth)
16351636
gfs2_meta_wipe(ip, bstart, blen);
16361637
}
16371638

1638-
/**
1639-
* gfs2_free_data - free a contiguous run of data block(s)
1640-
* @ip: the inode these blocks are being freed from
1641-
* @bstart: first block of a run of contiguous blocks
1642-
* @blen: the length of the block run
1643-
*
1644-
*/
1645-
1646-
void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
1647-
{
1648-
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1649-
1650-
__gfs2_free_data(ip, bstart, blen);
1651-
gfs2_statfs_change(sdp, 0, +blen, 0);
1652-
gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid);
1653-
}
1654-
1655-
/**
1656-
* gfs2_free_meta - free a contiguous run of data block(s)
1657-
* @ip: the inode these blocks are being freed from
1658-
* @bstart: first block of a run of contiguous blocks
1659-
* @blen: the length of the block run
1660-
*
1661-
*/
1662-
1663-
void __gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen)
1664-
{
1665-
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1666-
struct gfs2_rgrpd *rgd;
1667-
1668-
rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
1669-
if (!rgd)
1670-
return;
1671-
trace_gfs2_block_alloc(ip, bstart, blen, GFS2_BLKST_FREE);
1672-
rgd->rd_free += blen;
1673-
1674-
gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
1675-
gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
1676-
1677-
gfs2_trans_add_rg(rgd);
1678-
gfs2_meta_wipe(ip, bstart, blen);
1679-
}
1680-
16811639
/**
16821640
* gfs2_free_meta - free a contiguous run of data block(s)
16831641
* @ip: the inode these blocks are being freed from
@@ -1690,7 +1648,7 @@ void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen)
16901648
{
16911649
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
16921650

1693-
__gfs2_free_meta(ip, bstart, blen);
1651+
__gfs2_free_blocks(ip, bstart, blen, 1);
16941652
gfs2_statfs_change(sdp, 0, +blen, 0);
16951653
gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid);
16961654
}

‎fs/gfs2/rgrp.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ extern int gfs2_ri_update(struct gfs2_inode *ip);
5252
extern int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n);
5353
extern int gfs2_alloc_di(struct gfs2_inode *ip, u64 *bn, u64 *generation);
5454

55-
extern void __gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen);
56-
extern void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen);
57-
extern void __gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
55+
extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta);
5856
extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
5957
extern void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip);
6058
extern void gfs2_unlink_di(struct inode *inode);

0 commit comments

Comments
 (0)