From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Gruenbacher Date: Thu, 1 Apr 2021 12:12:24 +0200 Subject: [Cluster-devel] [PATCH 2/4] gfs2: Turn gfs2_extent_map into gfs2_{get, alloc}_extent In-Reply-To: <4bdf64ec-835e-6d97-b1d9-b34defacb694@redhat.com> References: <20210401091839.2251916-1-agruenba@redhat.com> <20210401091839.2251916-3-agruenba@redhat.com> <4bdf64ec-835e-6d97-b1d9-b34defacb694@redhat.com> Message-ID: List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Thu, Apr 1, 2021 at 11:46 AM Andrew Price wrote: > On 01/04/2021 10:18, Andreas Gruenbacher wrote: > > Convert gfs2_extent_map to iomap and split it into gfs2_get_extent and > > gfs2_alloc_extent. Instead of hardcoding the extent size, pass it in > > via the extlen parameter. > > > > Signed-off-by: Andreas Gruenbacher > > --- > > fs/gfs2/bmap.c | 59 ++++++++++++++++++++++++++++++---------------- > > fs/gfs2/bmap.h | 6 +++-- > > fs/gfs2/dir.c | 13 +++++----- > > fs/gfs2/quota.c | 4 ++-- > > fs/gfs2/recovery.c | 4 ++-- > > 5 files changed, 53 insertions(+), 33 deletions(-) > > > > diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c > > index cc12dc0d6955..ac959a99ea81 100644 > > --- a/fs/gfs2/bmap.c > > +++ b/fs/gfs2/bmap.c > > @@ -1320,28 +1320,47 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, > > return ret; > > } > > > > -/* > > - * Deprecated: do not use in new code > > - */ > > -int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen) > > +int gfs2_get_extent(struct inode *inode, u64 lblock, u64 *dblock, > > + unsigned int *extlen) > > { > > - struct buffer_head bh = { .b_state = 0, .b_blocknr = 0 }; > > + unsigned int blkbits = inode->i_blkbits; > > + struct iomap iomap = { }; > > + unsigned int len; > > int ret; > > - int create = *new; > > - > > - BUG_ON(!extlen); > > - BUG_ON(!dblock); > > - BUG_ON(!new); > > - > > - bh.b_size = BIT(inode->i_blkbits + (create ? 0 : 5)); > > - ret = gfs2_block_map(inode, lblock, &bh, create); > > - *extlen = bh.b_size >> inode->i_blkbits; > > - *dblock = bh.b_blocknr; > > - if (buffer_new(&bh)) > > - *new = 1; > > - else > > - *new = 0; > > - return ret; > > + > > + ret = gfs2_iomap_get(inode, lblock << blkbits, *extlen << blkbits, > > + &iomap); > > + if (ret) > > + return ret; > > + if (iomap.type != IOMAP_MAPPED) > > + return -EIO; > > + *dblock = iomap.addr >> blkbits; > > + len = iomap.length >> blkbits; > > + if (len < *extlen) > > + *extlen = len; > > + return 0; > > +} > > + > > +int gfs2_alloc_extent(struct inode *inode, u64 lblock, u64 *dblock, > > + unsigned int *extlen, bool *new) > > +{ > > + unsigned int blkbits = inode->i_blkbits; > > + struct iomap iomap = { }; > > + unsigned int len; > > + int ret; > > + > > + ret = gfs2_iomap_alloc(inode, lblock << blkbits, *extlen << blkbits, > > + &iomap); > > + if (ret) > > + return ret; > > + if (iomap.type != IOMAP_MAPPED) > > + return -EIO; > > + *dblock = iomap.addr >> blkbits; > > + len = iomap.length >> blkbits; > > + if (len < *extlen) > > + *extlen = len; > > + *new = iomap.flags & IOMAP_F_NEW; > > As *new is bool, shouldn't this be !!(iomap.flags & IOMAP_F_NEW) or similar? That's implied with type bool (but not with integer types). For example, (bool)(1L << (8 * sizeof(long) - 1)) is always 1. > Otherwise, the set looks good to me. > > Andy > > > + return 0; > > } > > > > /* > > diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h > > index c63efee8aaa4..67ef7cf7fdac 100644 > > --- a/fs/gfs2/bmap.h > > +++ b/fs/gfs2/bmap.h > > @@ -53,8 +53,10 @@ extern int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, > > struct iomap *iomap); > > extern int gfs2_iomap_alloc(struct inode *inode, loff_t pos, loff_t length, > > struct iomap *iomap); > > -extern int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, > > - u64 *dblock, unsigned *extlen); > > +extern int gfs2_get_extent(struct inode *inode, u64 lblock, u64 *dblock, > > + unsigned int *extlen); > > +extern int gfs2_alloc_extent(struct inode *inode, u64 lblock, u64 *dblock, > > + unsigned *extlen, bool *new); > > extern int gfs2_setattr_size(struct inode *inode, u64 size); > > extern void gfs2_trim_blocks(struct inode *inode); > > extern int gfs2_truncatei_resume(struct gfs2_inode *ip); > > diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c > > index c0f2875c946c..4517ffb7c13d 100644 > > --- a/fs/gfs2/dir.c > > +++ b/fs/gfs2/dir.c > > @@ -159,7 +159,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, > > unsigned int o; > > int copied = 0; > > int error = 0; > > - int new = 0; > > + bool new = false; > > > > if (!size) > > return 0; > > @@ -189,9 +189,9 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf, > > amount = sdp->sd_sb.sb_bsize - o; > > > > if (!extlen) { > > - new = 1; > > - error = gfs2_extent_map(&ip->i_inode, lblock, &new, > > - &dblock, &extlen); > > + extlen = 1; > > + error = gfs2_alloc_extent(&ip->i_inode, lblock, &dblock, > > + &extlen, &new); > > if (error) > > goto fail; > > error = -EIO; > > @@ -286,15 +286,14 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, __be64 *buf, > > while (copied < size) { > > unsigned int amount; > > struct buffer_head *bh; > > - int new; > > > > amount = size - copied; > > if (amount > sdp->sd_sb.sb_bsize - o) > > amount = sdp->sd_sb.sb_bsize - o; > > > > if (!extlen) { > > - new = 0; > > - error = gfs2_extent_map(&ip->i_inode, lblock, &new, > > + extlen = 32; > > + error = gfs2_get_extent(&ip->i_inode, lblock, > > &dblock, &extlen); > > if (error || !dblock) > > goto fail; > > diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c > > index 6e173ae378c4..9b1aca7e1264 100644 > > --- a/fs/gfs2/quota.c > > +++ b/fs/gfs2/quota.c > > @@ -1375,8 +1375,8 @@ int gfs2_quota_init(struct gfs2_sbd *sdp) > > unsigned int y; > > > > if (!extlen) { > > - int new = 0; > > - error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen); > > + extlen = 32; > > + error = gfs2_get_extent(&ip->i_inode, x, &dblock, &extlen); > > if (error) > > goto fail; > > } > > diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c > > index 282173774005..4ab4cdbf774a 100644 > > --- a/fs/gfs2/recovery.c > > +++ b/fs/gfs2/recovery.c > > @@ -34,12 +34,12 @@ int gfs2_replay_read_block(struct gfs2_jdesc *jd, unsigned int blk, > > { > > struct gfs2_inode *ip = GFS2_I(jd->jd_inode); > > struct gfs2_glock *gl = ip->i_gl; > > - int new = 0; > > u64 dblock; > > u32 extlen; > > int error; > > > > - error = gfs2_extent_map(&ip->i_inode, blk, &new, &dblock, &extlen); > > + extlen = 32; > > + error = gfs2_get_extent(&ip->i_inode, blk, &dblock, &extlen); > > if (error) > > return error; > > if (!dblock) { > > > Thanks, Andreas