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 1/2] gfs2: gfs2_iomap_begin cleanup
Date: Sat,  6 Jul 2019 01:56:21 +0200	[thread overview]
Message-ID: <20190705235622.22368-2-agruenba@redhat.com> (raw)
In-Reply-To: <20190705235622.22368-1-agruenba@redhat.com>

Turn function gfs2_iomap_begin_write into something all iomap functions
will go through (and rename it to __gfs2_iomap_begin).  This will
simplify adding support for IOMAP_ZERO.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/gfs2/bmap.c | 53 +++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 3b761a0ba6ab..e2c58c6a1276 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -1016,10 +1016,9 @@ static const struct iomap_page_ops gfs2_iomap_page_ops = {
 	.page_done = gfs2_iomap_page_done,
 };
 
-static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
-				  loff_t length, unsigned flags,
-				  struct iomap *iomap,
-				  struct metapath *mp)
+static int __gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
+			      unsigned flags, struct iomap *iomap,
+			      struct metapath *mp)
 {
 	struct gfs2_inode *ip = GFS2_I(inode);
 	struct gfs2_sbd *sdp = GFS2_SB(inode);
@@ -1027,17 +1026,23 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
 	bool unstuff, alloc_required;
 	int ret;
 
-	ret = gfs2_write_lock(inode);
-	if (ret)
+	iomap->flags |= IOMAP_F_BUFFER_HEAD;
+
+	ret = gfs2_iomap_get(inode, pos, length, flags, iomap, mp);
+	if (ret || !(flags & IOMAP_WRITE))
 		return ret;
+	if (flags & IOMAP_DIRECT) {
+		/*
+		 * Silently fall back to buffered I/O for stuffed files or if
+		 * we've got a hole (see gfs2_file_direct_write).
+		 */
+		if (iomap->type != IOMAP_MAPPED)
+			return -ENOTBLK;
+		return 0;
+	}
 
 	unstuff = gfs2_is_stuffed(ip) &&
 		  pos + length > gfs2_max_stuffed_size(ip);
-
-	ret = gfs2_iomap_get(inode, pos, length, flags, iomap, mp);
-	if (ret)
-		goto out_unlock;
-
 	alloc_required = unstuff || iomap->type == IOMAP_HOLE;
 
 	if (alloc_required || gfs2_is_jdata(ip))
@@ -1051,7 +1056,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
 
 		ret = gfs2_quota_lock_check(ip, &ap);
 		if (ret)
-			goto out_unlock;
+			return ret;
 
 		ret = gfs2_inplace_reserve(ip, &ap);
 		if (ret)
@@ -1118,8 +1123,6 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
 out_qunlock:
 	if (alloc_required)
 		gfs2_quota_unlock(ip);
-out_unlock:
-	gfs2_write_unlock(inode);
 	return ret;
 }
 
@@ -1130,23 +1133,19 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
 	struct metapath mp = { .mp_aheight = 1, };
 	int ret;
 
-	iomap->flags |= IOMAP_F_BUFFER_HEAD;
-
 	trace_gfs2_iomap_start(ip, pos, length, flags);
 	if ((flags & IOMAP_WRITE) && !(flags & IOMAP_DIRECT)) {
-		ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap, &mp);
+		ret = gfs2_write_lock(inode);
+		if (ret)
+			goto out;
+		ret = __gfs2_iomap_begin(inode, pos, length, flags, iomap, &mp);
+		if (ret)
+			gfs2_write_unlock(inode);
 	} else {
-		ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
-
-		/*
-		 * Silently fall back to buffered I/O for stuffed files or if
-		 * we've hot a hole (see gfs2_file_direct_write).
-		 */
-		if ((flags & IOMAP_WRITE) && (flags & IOMAP_DIRECT) &&
-		    iomap->type != IOMAP_MAPPED)
-			ret = -ENOTBLK;
+		ret = __gfs2_iomap_begin(inode, pos, length, flags, iomap, &mp);
 	}
 	release_metapath(&mp);
+out:
 	trace_gfs2_iomap_end(ip, iomap, ret);
 	return ret;
 }
@@ -1157,7 +1156,7 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
 	struct gfs2_inode *ip = GFS2_I(inode);
 	struct gfs2_sbd *sdp = GFS2_SB(inode);
 
-	if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE)
+	if (!(flags & IOMAP_WRITE) || (flags & IOMAP_DIRECT))
 		goto out;
 
 	if (!gfs2_is_stuffed(ip))
-- 
2.20.1



  reply	other threads:[~2019-07-05 23:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-05 23:56 [Cluster-devel] Make "gfs2: implement gfs2_block_zero_range using iomap_zero_range" work properly Andreas Gruenbacher
2019-07-05 23:56 ` Andreas Gruenbacher [this message]
2019-07-05 23:56 ` [Cluster-devel] [PATCH 2/2] gfs2: Add support for IOMAP_ZERO Andreas Gruenbacher
2019-07-08 17:06   ` Christoph Hellwig
2019-07-08 18:07     ` Andreas Gruenbacher

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=20190705235622.22368-2-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).