cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 7/8] gfs2: Move gfs2_alloc_size out of gfs2_iomap_get
Date: Tue, 28 Aug 2018 23:47:30 +0200	[thread overview]
Message-ID: <20180828214731.15199-8-agruenba@redhat.com> (raw)
In-Reply-To: <20180828214731.15199-1-agruenba@redhat.com>

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 <agruenba@redhat.com>
---
 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



  parent reply	other threads:[~2018-08-28 21:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 21:47 [Cluster-devel] [PATCH 0/8] Get rid of gfs2_write_calc_reserv in gfs2_iomap_begin_write Andreas Gruenbacher
2018-08-28 21:47 ` [Cluster-devel] [PATCH 1/8] gfs2: Don't depend on mp_aheight in clone_metapath Andreas Gruenbacher
2018-08-28 21:47 ` [Cluster-devel] [PATCH 2/8] gfs2: Split gfs2_indirect_init Andreas Gruenbacher
2018-08-28 21:47 ` [Cluster-devel] [PATCH 3/8] gfs2: Move empty inode check out of gfs2_unstuff_dinode Andreas Gruenbacher
2018-08-28 21:47 ` [Cluster-devel] [PATCH 4/8] gfs2: Don't create unnecessary indirect blocks Andreas Gruenbacher
2018-08-28 21:47 ` [Cluster-devel] [PATCH 5/8] gfs2: Improve gfs2_alloc_size for stuffed files Andreas Gruenbacher
2018-08-28 21:47 ` [Cluster-devel] [PATCH 6/8] gfs2: Rename size to len in gfs2_alloc_size Andreas Gruenbacher
2018-08-28 21:47 ` Andreas Gruenbacher [this message]
2018-08-28 21:47 ` [Cluster-devel] [PATCH 8/8] gfs2: Get rid of gfs2_write_calc_reserv in gfs2_iomap_begin_write Andreas Gruenbacher
2018-08-29 10:12 ` [Cluster-devel] [PATCH 0/8] " Steven Whitehouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180828214731.15199-8-agruenba@redhat.com \
    --to=agruenba@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).