gfs2: Turn gfs2_extent_map into gfs2_{get,alloc}_extent

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 <agruenba@redhat.com>
This commit is contained in:
Andreas Gruenbacher 2021-03-31 23:17:38 +02:00
parent 54992257fe
commit 9153dac13a
5 changed files with 51 additions and 31 deletions

View File

@ -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);
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;
}
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;
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;
return 0;
}
/*

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {