GFS2: Add structure to contain rgrp, bitmap, offset tuple
This patch introduces a new structure, gfs2_rbm, which is a tuple of a resource group, a bitmap within the resource group and an offset within that bitmap. This is designed to make manipulating these sets of variables easier. There is also a new helper function which converts this representation back to a disk block address.
In addition, the rbtree nodes which are used for the reservations were not being correctly initialised, which is now fixed. Also, the tracing was not passing through the inode where it should have been. That is mostly fixed aside from one corner case. This needs to be revisited since there can also be a NULL rgrp in some cases which results in the device being incorrect in the trace.
This is intended to be the first step towards cleaning up some of the allocation code, and some further bug fixes.
fs/gfs2/bmap.c +1 -1
@@ -786,7 +786,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, goto out_rlist;if (gfs2_rs_active (ip->i_res))/* needs to be done with the rgrp glock held */ -gfs2_rs_deltree (ip->i_res); +gfs2_rs_deltree (ip, ip->i_res); error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + RES_INDIRECT + RES_STATFS + RES_QUOTA,
fs/gfs2/incore.h +12 -3
@@ -102,6 +102,17 @@ struct gfs2_rgrpd {u32 rd_rs_cnt;/* count of current reservations */ }; +struct gfs2_rbm { +struct gfs2_rgrpd *rgd; +struct gfs2_bitmap *bi;/* Bitmap must belong to the rgd */ +u32 offset;/* The offset is bitmap relative */ +}; + +static inline u64 gfs2_rbm_to_block (const struct gfs2_rbm *rbm) +{ +return rbm->rgd->rd_data0 + (rbm->bi->bi_start *GFS2_NBBY ) + rbm->offset; +} +enum gfs2_state_bits { BH_Pinned = BH_PrivateStart, BH_Escaped = BH_PrivateStart +1 ,
@@ -251,13 +262,11 @@ struct gfs2_blkreserv {atomic_t rs_sizehint;/* hint of the write size */ /* components used during get_local_rgrp (step 3): */ -struct gfs2_rgrpd *rs_rgd;/* pointer to the gfs2_rgrpd */ +struct gfs2_rbm rs_rbm;struct gfs2_holder rs_rgd_gh;/* Filled in by get_local_rgrp */ struct rb_node rs_node;/* link to other block reservations */ /* components used during block searches and assignments (step 4): */ -struct gfs2_bitmap *rs_bi;/* bitmap for the current allocation */ -u32 rs_biblk;/* start block relative to the bi */ u32 rs_free;/* how many blocks are still free */ /* ancillary quota stuff */
fs/gfs2/rgrp.c +81 -94
391 lines not on this page · raw message
fs/gfs2/rgrp.h +5 -11
@@ -46,7 +46,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n, bool dinode, u64 *generation);extern int gfs2_rs_alloc (struct gfs2_inode *ip); -extern void gfs2_rs_deltree (struct gfs2_blkreserv *rs); +extern void gfs2_rs_deltree (struct gfs2_inode *ip,struct gfs2_blkreserv *rs);extern void gfs2_rs_delete (struct gfs2_inode *ip);extern void __gfs2_free_blocks (struct gfs2_inode *ip,u64 bstart,u32 blen,int meta);extern void gfs2_free_meta (struct gfs2_inode *ip,u64 bstart,u32 blen);
@@ -73,22 +73,16 @@ extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset, const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed);extern int gfs2_fitrim (struct file *filp,void __user *argp); -/* This is how to tell if a multi-block reservation is in the rgrp tree: */ -static inline int gfs2_rs_active (struct gfs2_blkreserv *rs) +/* This is how to tell if a reservation is in the rgrp tree: */ +static inline bool gfs2_rs_active (struct gfs2_blkreserv *rs) { -if (rs && rs->rs_bi) -return 1 ; -return 0 ; +return rs && !RB_EMPTY_NODE (&rs->rs_node); } +static inline u32 gfs2_bi2rgd_blk (const struct gfs2_bitmap *bi,u32 blk) {return (bi->bi_start *GFS2_NBBY ) + blk; } -static inline u64 gfs2_rs_startblk (const struct gfs2_blkreserv *rs) -{ -return gfs2_bi2rgd_blk (rs->rs_bi, rs->rs_biblk) + rs->rs_rgd->rd_data0; -} -#endif /* __RGRP_DOT_H__ */
fs/gfs2/super.c +1 -1
@@ -1557,7 +1557,7 @@ out_truncate: out_unlock:/* Error path for case 1 */ if (gfs2_rs_active (ip->i_res)) -gfs2_rs_deltree (ip->i_res); +gfs2_rs_deltree (ip, ip->i_res);if (test_bit (HIF_HOLDER , &ip->i_iopen_gh.gh_iflags))gfs2_glock_dq (&ip->i_iopen_gh);
fs/gfs2/trace_gfs2.h +5 -5
@@ -526,12 +526,12 @@ TRACE_EVENT(gfs2_rs, ),TP_fast_assign ( - __entry->dev = rs->rs_rgd ? rs->rs_rgd->rd_sbd->sd_vfs->s_dev : 0; - __entry->rd_addr = rs->rs_rgd ? rs->rs_rgd->rd_addr :0 ; - __entry->rd_free_clone = rs->rs_rgd ? rs->rs_rgd->rd_free_clone :0 ; - __entry->rd_reserved = rs->rs_rgd ? rs->rs_rgd->rd_reserved :0 ; + __entry->dev = rs->rs_rbm.rgd ? rs->rs_rbm.rgd->rd_sbd->sd_vfs->s_dev : 0; + __entry->rd_addr = rs->rs_rbm.rgd ? rs->rs_rbm.rgd->rd_addr :0 ; + __entry->rd_free_clone = rs->rs_rbm.rgd ? rs->rs_rbm.rgd->rd_free_clone :0 ; + __entry->rd_reserved = rs->rs_rbm.rgd ? rs->rs_rbm.rgd->rd_reserved :0 ; __entry->inum = ip ? ip->i_no_addr :0 ; - __entry->start =gfs2_rs_startblk (rs); + __entry->start =gfs2_rbm_to_block (&rs->rs_rbm); __entry->free = rs->rs_free; __entry->func = func; ),
----- Original Message -----
| | This patch introduces a new structure, gfs2_rbm, which is a | tuple of a resource group, a bitmap within the resource group | and an offset within that bitmap. This is designed to make | manipulating these sets of variables easier. There is also a | new helper function which converts this representation back | to a disk block address. | | In addition, the rbtree nodes which are used for the reservations | were not being correctly initialised, which is now fixed. Also, | the tracing was not passing through the inode where it should | have been. That is mostly fixed aside from one corner case. This | needs to be revisited since there can also be a NULL rgrp in | some cases which results in the device being incorrect in the | trace. | | This is intended to be the first step towards cleaning up some | of the allocation code, and some further bug fixes. | | Signed-off-by: Steven Whitehouse <[email protected]> (snip) | diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c | index a2b43bb..eaa4188 100644 | --- a/fs/gfs2/rgrp.c | +++ b/fs/gfs2/rgrp.c (snip) | @@ -499,8 +501,8 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs) | { | gfs2_print_dbg(seq, " r: %llu s:%llu b:%u f:%u\n", | - rs->rs_rgd->rd_addr, gfs2_rs_startblk(rs), rs->rs_biblk, | - rs->rs_free); | + rs->rs_rbm.rgd->rd_addr, gfs2_rbm_to_block(&rs->rs_rbm),
Hm, just fyi: When I copied the patch, I see an extra space (resulting in a whitespace warning from git) at the end of this last line. On my reply, I don't see it, so I'm not sure what's going on there.
Regards,
Bob Peterson
Red Hat File Systems
Hi,
Quoted 35 lines · Bob Peterson
----- Original Message -----
| | This patch introduces a new structure, gfs2_rbm, which is a | tuple of a resource group, a bitmap within the resource group | and an offset within that bitmap. This is designed to make | manipulating these sets of variables easier. There is also a | new helper function which converts this representation back | to a disk block address. | | In addition, the rbtree nodes which are used for the reservations | were not being correctly initialised, which is now fixed. Also, | the tracing was not passing through the inode where it should | have been. That is mostly fixed aside from one corner case. This | needs to be revisited since there can also be a NULL rgrp in | some cases which results in the device being incorrect in the | trace. | | This is intended to be the first step towards cleaning up some | of the allocation code, and some further bug fixes. | | Signed-off-by: Steven Whitehouse <[email protected]> (snip) | diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c | index a2b43bb..eaa4188 100644 | --- a/fs/gfs2/rgrp.c | +++ b/fs/gfs2/rgrp.c (snip) | @@ -499,8 +501,8 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs) | { | gfs2_print_dbg(seq, " r: %llu s:%llu b:%u f:%u\n", | - rs->rs_rgd->rd_addr, gfs2_rs_startblk(rs), rs->rs_biblk, | - rs->rs_free); | + rs->rs_rbm.rgd->rd_addr, gfs2_rbm_to_block(&rs->rs_rbm),
Quoted 8 lines
Hm, just fyi: When I copied the patch, I see an extra space (resulting in a whitespace warning from git) at the end of this last line. On my reply, I don't see it, so I'm not sure what's going on there.
Regards,
Bob Peterson
Red Hat File Systems
Looks like there is a space there in my git tree. I'll fix that in the next patch. I wonder why git didn't warn me....
Steve.
Quoted 2 lines · Steven Whitehouse
Looks like there is a space there in my git tree. I'll fix that in the next patch. I wonder why git didn't warn me....
By default git only warns about trailing whitespace when you're applying a patch. If you do:
$ cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
Then it'll warn on commit, too:
$ git commit -a gfs2/mkfs/main_mkfs.c:209: trailing whitespace. + strncpy(sdp->device_name, argv[optind++], PATH_MAX - 1);
Andy