[PATCH] PMFS: Fix race with inode allocation/eviction

Ross Zwisler ross.zwisler at linux.intel.com
Fri Jul 26 13:47:47 EDT 2013


This change fixes a race that existed between inode allocation and eviction.
Prior to this change we could get into a situation where we were trying to free
an old inode's data blocks based on information that had changed since the
inode was reallocated.

With this change we calculate and save everything we need to free the
data blocks before we release the inode.

Signed-off-by: Ross Zwisler <ross.zwisler at linux.intel.com>
Reviewed-by: Sanjay Kumar <sanjay.k.kumar at intel.com>
---
 fs/pmfs/inode.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/fs/pmfs/inode.c b/fs/pmfs/inode.c
index 4de4238..16e19f7 100644
--- a/fs/pmfs/inode.c
+++ b/fs/pmfs/inode.c
@@ -1023,11 +1023,6 @@ void pmfs_evict_inode(struct inode *inode)
 		height = pi->height;
 		btype = pi->i_blk_type;
 
-		/* first free the inode */
-		err = pmfs_free_inode(inode);
-		if (err)
-			goto out;
-		/* then free the blocks from the inode's b-tree */
 		if (pi->i_flags & cpu_to_le32(PMFS_EOFBLOCKS_FL)) {
 			last_blocknr = (1UL << (pi->height * META_BLK_SHIFT))
 			    - 1;
@@ -1040,6 +1035,14 @@ void pmfs_evict_inode(struct inode *inode)
 			last_blocknr = pmfs_sparse_last_blocknr(pi->height,
 				last_blocknr);
 		}
+
+		/* first free the inode */
+		err = pmfs_free_inode(inode);
+		if (err)
+			goto out;
+		pi = NULL; /* we no longer own the pmfs_inode */
+
+		/* then free the blocks from the inode's b-tree */
 		pmfs_free_inode_subtree(sb, root, height, btype, last_blocknr);
 		inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
 		inode->i_size = 0;
-- 
1.8.2.GIT




More information about the Linux-pmfs mailing list