All of lore.kernel.org
 help / color / mirror / Atom feed
From: Allison Henderson <achender@linux.vnet.ibm.com>
To: linux-ext4@vger.kernel.org
Cc: Allison Henderson <achender@linux.vnet.ibm.com>
Subject: [PATCH 4/6 v7] ext4: Lock i_mutex for punch hole
Date: Tue, 30 Aug 2011 17:28:31 -0700	[thread overview]
Message-ID: <1314750513-10045-5-git-send-email-achender@linux.vnet.ibm.com> (raw)
In-Reply-To: <1314750513-10045-1-git-send-email-achender@linux.vnet.ibm.com>

This patch modifies the fallocate routine to lock i_mutex during
the punch hole operation.

Yongqiang noticed that the vfs layer locks i_mutex for truncate,
but not fallocate, so the fallocate routine will need to take
care of locking i_mutex.  Otherwise a page may be mapped after
punch hole has released the pages, but before i_data_sem is
locked to release the blocks in the extent tree.

Signed-off-by: Allison Henderson <achender@linux.vnet.ibm.com>
---
:100644 100644 9124cd2... 007fb08... M	fs/ext4/extents.c
 fs/ext4/extents.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 9124cd2..007fb08 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3774,8 +3774,13 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
 		return -EOPNOTSUPP;
 
-	if (mode & FALLOC_FL_PUNCH_HOLE)
-		return ext4_punch_hole(file, offset, len);
+	mutex_lock(&inode->i_mutex);
+
+	if (mode & FALLOC_FL_PUNCH_HOLE) {
+		ret = ext4_punch_hole(file, offset, len);
+		mutex_unlock(&inode->i_mutex);
+		return ret;	
+	}
 
 	trace_ext4_fallocate_enter(inode, offset, len, mode);
 	map.m_lblk = offset >> blkbits;
@@ -3789,7 +3794,6 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	 * credits to insert 1 extent into extent tree
 	 */
 	credits = ext4_chunk_trans_blocks(inode, max_blocks);
-	mutex_lock(&inode->i_mutex);
 	ret = inode_newsize_ok(inode, (len + offset));
 	if (ret) {
 		mutex_unlock(&inode->i_mutex);
-- 
1.7.1


  parent reply	other threads:[~2011-08-31  0:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-31  0:28 [PATCH 0/6 v7] ext4: fix 1k block bugs Allison Henderson
2011-08-31  0:28 ` [PATCH 1/6 v7] ext4: Add new ext4_discard_partial_page_buffers routines Allison Henderson
2011-08-31  0:28 ` [PATCH 2/6 v7] ext4: fix xfstests 75, 112, 127 punch hole failure Allison Henderson
2011-08-31  0:28 ` [PATCH 3/6 v7] ext4: fix 2nd xfstests " Allison Henderson
2011-08-31  0:28 ` Allison Henderson [this message]
2011-08-31  0:31   ` [PATCH 4/6 v7] ext4: Lock i_mutex for punch hole Andreas Dilger
2011-08-31 18:49     ` Allison Henderson
2011-08-31 19:44       ` Andreas Dilger
2011-08-31  0:28 ` [PATCH 5/6 v7] ext4: fix fsx truncate failure Allison Henderson
2011-08-31  0:28 ` [PATCH 6/6 v7] ext4: fix partial page writes Allison Henderson
2011-09-06  4:59 ` [PATCH 0/6 v7] ext4: fix 1k block bugs Ted Ts'o
2011-09-06 16:38   ` Allison Henderson
2011-09-07 18:41     ` Allison Henderson

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=1314750513-10045-5-git-send-email-achender@linux.vnet.ibm.com \
    --to=achender@linux.vnet.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.