linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Goldwyn Rodrigues <rgoldwyn@suse.de>
To: linux-btrfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, hch@infradead.org,
	darrick.wong@oracle.com, fdmanana@kernel.org,
	Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: [PATCH 4/5] btrfs: Wait for extent bits to release page
Date: Mon, 25 Nov 2019 21:14:55 -0600	[thread overview]
Message-ID: <20191126031456.12150-5-rgoldwyn@suse.de> (raw)
In-Reply-To: <20191126031456.12150-1-rgoldwyn@suse.de>

From: Goldwyn Rodrigues <rgoldwyn@suse.com>

While trying to release a page, the extent containing the page may be locked
which would stop the page from being released. Wait for the
extent lock to be cleared, if blocking is allowed and then clear
the bits.

While we are at it, clean the code of try_release_extent_state() to make
it simpler.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/extent_io.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index cceaf05aada2..a7c32276702d 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4367,28 +4367,23 @@ static int try_release_extent_state(struct extent_io_tree *tree,
 {
 	u64 start = page_offset(page);
 	u64 end = start + PAGE_SIZE - 1;
-	int ret = 1;
 
 	if (test_range_bit(tree, start, end, EXTENT_LOCKED, 0, NULL)) {
-		ret = 0;
-	} else {
-		/*
-		 * at this point we can safely clear everything except the
-		 * locked bit and the nodatasum bit
-		 */
-		ret = __clear_extent_bit(tree, start, end,
-				 ~(EXTENT_LOCKED | EXTENT_NODATASUM),
-				 0, 0, NULL, mask, NULL);
-
-		/* if clear_extent_bit failed for enomem reasons,
-		 * we can't allow the release to continue.
-		 */
-		if (ret < 0)
-			ret = 0;
-		else
-			ret = 1;
+		if (!gfpflags_allow_blocking(mask))
+			return 0;
+		wait_extent_bit(tree, start, end, EXTENT_LOCKED);
 	}
-	return ret;
+	/*
+	 * At this point we can safely clear everything except the locked and
+	 * nodatasum bits. If clear_extent_bit failed due to -ENOMEM,
+	 * don't allow release.
+	 */
+	if (__clear_extent_bit(tree, start, end,
+				~(EXTENT_LOCKED | EXTENT_NODATASUM), 0, 0,
+				NULL, mask, NULL) < 0)
+		return 0;
+
+	return 1;
 }
 
 /*
-- 
2.16.4


  parent reply	other threads:[~2019-11-26  3:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26  3:14 [PATCH 0/5 v2] btrfs direct-io using iomap Goldwyn Rodrigues
2019-11-26  3:14 ` [PATCH 1/5] fs: Export generic_file_buffered_read() Goldwyn Rodrigues
2019-11-26  3:43   ` Matthew Wilcox
2019-11-26 10:10   ` Johannes Thumshirn
2019-11-26 10:43     ` Johannes Thumshirn
2019-11-26  3:14 ` [PATCH 2/5] iomap: add a filesystem hook for direct I/O bio submission Goldwyn Rodrigues
2019-11-26 10:53   ` Nikolay Borisov
2019-11-26 11:51   ` Johannes Thumshirn
2019-11-26  3:14 ` [PATCH 3/5] btrfs: Switch to iomap_dio_rw() for dio Goldwyn Rodrigues
2019-11-26 11:54   ` Nikolay Borisov
2019-11-26 12:13   ` Nikolay Borisov
2019-11-26  3:14 ` Goldwyn Rodrigues [this message]
2019-11-26 12:38   ` [PATCH 4/5] btrfs: Wait for extent bits to release page Nikolay Borisov
2019-11-26 12:42   ` Johannes Thumshirn
2019-11-26  3:14 ` [PATCH 5/5] fs: Remove dio_end_io() Goldwyn Rodrigues
2019-11-26 12:39   ` Nikolay Borisov
2019-11-26 12:50   ` Johannes Thumshirn
2019-11-27 15:51 ` [PATCH 0/5 v2] btrfs direct-io using iomap David Sterba

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=20191126031456.12150-5-rgoldwyn@suse.de \
    --to=rgoldwyn@suse.de \
    --cc=darrick.wong@oracle.com \
    --cc=fdmanana@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=rgoldwyn@suse.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).