From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Gruenbacher Date: Tue, 28 Aug 2018 23:47:30 +0200 Subject: [Cluster-devel] [PATCH 7/8] gfs2: Move gfs2_alloc_size out of gfs2_iomap_get In-Reply-To: <20180828214731.15199-1-agruenba@redhat.com> References: <20180828214731.15199-1-agruenba@redhat.com> Message-ID: <20180828214731.15199-8-agruenba@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Move gfs2_alloc_size out of gfs2_iomap_get and rename it to gfs2_compute_alloc_size. This simplifies gfs2_iomap_get, and will allow to pass additional parameters to gfs2_alloc_size that are not relevant to gfs2_iomap_get later. In addition, gfs2_alloc_size is now no longer called again unnecessarily after unstuffing in gfs2_iomap_begin_write. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/bmap.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 5168e5c39d49..66ecc4439e77 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -624,9 +624,6 @@ enum alloc_state { * ii) Indirect blocks to fill in lower part of the metadata tree * iii) Data blocks * - * This function is called after gfs2_iomap_get, which works out the - * total number of blocks which we need via gfs2_alloc_size. - * * We then do the actual allocation asking for an extent at a time (if * enough contiguous free blocks are available, there will only be one * allocation request per call) and uses the state machine to initialise @@ -792,17 +789,15 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap, #define IOMAP_F_GFS2_BOUNDARY IOMAP_F_PRIVATE /** - * gfs2_alloc_size - Compute the maximum allocation size + * gfs2_compute_alloc_size - Compute the maximum allocation size * @inode: The inode * @mp: The metapath * @iomap: The iomap * * Compute the maximum size of the next allocation at @mp. - * - * Returns: size in blocks */ -static u64 gfs2_alloc_size(struct inode *inode, struct metapath *mp, - struct iomap *iomap) +static void gfs2_compute_alloc_size(struct inode *inode, struct metapath *mp, + struct iomap *iomap) { struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); @@ -832,7 +827,7 @@ static u64 gfs2_alloc_size(struct inode *inode, struct metapath *mp, } len = ptr - first; } - return len; + iomap->length = len << inode->i_blkbits; } /** @@ -956,17 +951,7 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, ret = gfs2_hole_size(inode, lblock, len, mp, iomap); else iomap->length = size - pos; - } else if (flags & IOMAP_WRITE) { - u64 alloc_size; - - if (flags & IOMAP_DIRECT) - goto out; /* (see gfs2_file_direct_write) */ - - len = gfs2_alloc_size(inode, mp, iomap); - alloc_size = len << inode->i_blkbits; - if (alloc_size < iomap->length) - iomap->length = alloc_size; - } else { + } else if (!(flags & IOMAP_WRITE)) { if (pos < size && height == ip->i_height) ret = gfs2_hole_size(inode, lblock, len, mp, iomap); } @@ -1048,6 +1033,9 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, alloc_required = unstuff || iomap->type == IOMAP_HOLE; + if (iomap->type == IOMAP_HOLE) + gfs2_compute_alloc_size(inode, &mp, iomap); + if (alloc_required || gfs2_is_jdata(ip)) gfs2_write_calc_reserv(ip, iomap->length, &data_blocks, &ind_blocks); @@ -1245,9 +1233,11 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, if (create) { ret = gfs2_iomap_get(inode, pos, length, IOMAP_WRITE, &iomap, &mp); - if (!ret && iomap.type == IOMAP_HOLE) + if (!ret && iomap.type == IOMAP_HOLE) { + gfs2_compute_alloc_size(inode, &mp, &iomap); ret = gfs2_iomap_alloc(inode, &iomap, IOMAP_WRITE, &mp, gfs2_inode_contains_data(inode)); + } release_metapath(&mp); } else { ret = gfs2_iomap_get(inode, pos, length, 0, &iomap, &mp); @@ -1476,9 +1466,11 @@ int gfs2_iomap_get_alloc(struct inode *inode, loff_t pos, loff_t length, int ret; ret = gfs2_iomap_get(inode, pos, length, IOMAP_WRITE, iomap, &mp); - if (!ret && iomap->type == IOMAP_HOLE) + if (!ret && iomap->type == IOMAP_HOLE) { + gfs2_compute_alloc_size(inode, &mp, iomap); ret = gfs2_iomap_alloc(inode, iomap, IOMAP_WRITE, &mp, gfs2_inode_contains_data(inode)); + } release_metapath(&mp); return ret; } -- 2.17.1