Commit 9153dac1 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher
Browse files

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: default avatarAndreas Gruenbacher <agruenba@redhat.com>
parent 54992257
Loading
Loading
Loading
Loading
+39 −20
Original line number Original line Diff line number Diff line
@@ -1320,28 +1320,47 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
	return ret;
	return ret;
}
}


/*
int gfs2_get_extent(struct inode *inode, u64 lblock, u64 *dblock,
 * Deprecated: do not use in new code
		    unsigned int *extlen)
 */
int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *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 ret;
	int create = *new;


	ret = gfs2_iomap_get(inode, lblock << blkbits, *extlen << blkbits,
	BUG_ON(!extlen);
			     &iomap);
	BUG_ON(!dblock);
	if (ret)
	BUG_ON(!new);
		return ret;

	if (iomap.type != IOMAP_MAPPED)
	bh.b_size = BIT(inode->i_blkbits + (create ? 0 : 5));
		return -EIO;
	ret = gfs2_block_map(inode, lblock, &bh, create);
	*dblock = iomap.addr >> blkbits;
	*extlen = bh.b_size >> inode->i_blkbits;
	len = iomap.length >> blkbits;
	*dblock = bh.b_blocknr;
	if (len < *extlen)
	if (buffer_new(&bh))
		*extlen = len;
		*new = 1;
	return 0;
	else
}
		*new = 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;
		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;
}
}


/*
/*
+4 −2
Original line number Original line Diff line number Diff line
@@ -53,8 +53,10 @@ extern int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
			  struct iomap *iomap);
			  struct iomap *iomap);
extern int gfs2_iomap_alloc(struct inode *inode, loff_t pos, loff_t length,
extern int gfs2_iomap_alloc(struct inode *inode, loff_t pos, loff_t length,
			    struct iomap *iomap);
			    struct iomap *iomap);
extern int gfs2_extent_map(struct inode *inode, u64 lblock, int *new,
extern int gfs2_get_extent(struct inode *inode, u64 lblock, u64 *dblock,
			   u64 *dblock, unsigned *extlen);
			   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 int gfs2_setattr_size(struct inode *inode, u64 size);
extern void gfs2_trim_blocks(struct inode *inode);
extern void gfs2_trim_blocks(struct inode *inode);
extern int gfs2_truncatei_resume(struct gfs2_inode *ip);
extern int gfs2_truncatei_resume(struct gfs2_inode *ip);
+6 −7
Original line number Original line Diff line number Diff line
@@ -159,7 +159,7 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
	unsigned int o;
	unsigned int o;
	int copied = 0;
	int copied = 0;
	int error = 0;
	int error = 0;
	int new = 0;
	bool new = false;


	if (!size)
	if (!size)
		return 0;
		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;
			amount = sdp->sd_sb.sb_bsize - o;


		if (!extlen) {
		if (!extlen) {
			new = 1;
			extlen = 1;
			error = gfs2_extent_map(&ip->i_inode, lblock, &new,
			error = gfs2_alloc_extent(&ip->i_inode, lblock, &dblock,
						&dblock, &extlen);
						  &extlen, &new);
			if (error)
			if (error)
				goto fail;
				goto fail;
			error = -EIO;
			error = -EIO;
@@ -286,15 +286,14 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, __be64 *buf,
	while (copied < size) {
	while (copied < size) {
		unsigned int amount;
		unsigned int amount;
		struct buffer_head *bh;
		struct buffer_head *bh;
		int new;


		amount = size - copied;
		amount = size - copied;
		if (amount > sdp->sd_sb.sb_bsize - o)
		if (amount > sdp->sd_sb.sb_bsize - o)
			amount = sdp->sd_sb.sb_bsize - o;
			amount = sdp->sd_sb.sb_bsize - o;


		if (!extlen) {
		if (!extlen) {
			new = 0;
			extlen = 32;
			error = gfs2_extent_map(&ip->i_inode, lblock, &new,
			error = gfs2_get_extent(&ip->i_inode, lblock,
						&dblock, &extlen);
						&dblock, &extlen);
			if (error || !dblock)
			if (error || !dblock)
				goto fail;
				goto fail;
+2 −2
Original line number Original line Diff line number Diff line
@@ -1375,8 +1375,8 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
		unsigned int y;
		unsigned int y;


		if (!extlen) {
		if (!extlen) {
			int new = 0;
			extlen = 32;
			error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen);
			error = gfs2_get_extent(&ip->i_inode, x, &dblock, &extlen);
			if (error)
			if (error)
				goto fail;
				goto fail;
		}
		}
+2 −2
Original line number Original line Diff line number Diff line
@@ -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_inode *ip = GFS2_I(jd->jd_inode);
	struct gfs2_glock *gl = ip->i_gl;
	struct gfs2_glock *gl = ip->i_gl;
	int new = 0;
	u64 dblock;
	u64 dblock;
	u32 extlen;
	u32 extlen;
	int error;
	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)
	if (error)
		return error;
		return error;
	if (!dblock) {
	if (!dblock) {