[patch 4/6][RFC] Attempt to plug race with truncate

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-fsdevel@...>
Cc: <linux-kernel@...>, Mike Waychison <mikew@...>
Date: Friday, October 26, 2007 - 7:37 pm

Attempt to deal with races with truncate paths.

I'm not really sure on the locking here, but these seem to be taken by the truncate path.  BKL is left as some filesystem may(?) still require it.

Signed-off-by: Mike Waychison <mikew@google.com>
 fs/ioctl.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Index: linux-2.6.23/fs/ioctl.c
===================================================================
--- linux-2.6.23.orig/fs/ioctl.c	2007-10-26 15:27:29.000000000 -0700
+++ linux-2.6.23/fs/ioctl.c	2007-10-26 16:16:28.000000000 -0700
@@ -43,13 +43,21 @@ static long do_ioctl(struct file *filp, 
 static int do_fibmap(struct address_space *mapping, sector_t block,
 		     sector_t *phys_block)
 {
+	struct inode *inode = mapping->host;
+
 	if (!capable(CAP_SYS_RAWIO))
 		return -EPERM;
 	if (!mapping->a_ops->bmap)
 		return -EINVAL;
 
 	lock_kernel();
+	/* Avoid races with truncate */
+	mutex_lock(&inode->i_mutex);
+	/* FIXME: Do we really need i_alloc_sem? */
+	down_read(&inode->i_alloc_sem);
 	*phys_block = mapping->a_ops->bmap(mapping, block);
+	up_read(&inode->i_alloc_sem);
+	mutex_unlock(&inode->i_mutex);
 	unlock_kernel();
 
 	return 0;

--
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 4/6][RFC] Attempt to plug race with truncate, Mike Waychison, (Fri Oct 26, 7:37 pm)