public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] make xfs_idestroy() wait for log I/O to complete
@ 2007-12-12  7:20 Lachlan McIlroy
  2007-12-14 20:33 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Lachlan McIlroy @ 2007-12-12  7:20 UTC (permalink / raw)
  To: xfs-dev, xfs-oss

[-- Attachment #1: Type: text/plain, Size: 349 bytes --]

An xfs inode can be destroyed before log I/O involving that inode
is complete.  We need to wait for the inode to be unpinned before
tearing it down.  The patch looks big but the only real change is
adding a call to xfs_iunpin_wait() to the start of xfs_idestroy().
The rest of the patch is moving xfs_idestroy() after the pinning
routines.

Lachlan

[-- Attachment #2: xfs_idestroy.diff --]
[-- Type: text/x-patch, Size: 3714 bytes --]

--- fs/xfs/xfs_inode.c_1.489	2007-12-12 17:14:54.000000000 +1100
+++ fs/xfs/xfs_inode.c	2007-12-12 17:15:42.000000000 +1100
@@ -2733,71 +2733,6 @@ xfs_idestroy_fork(
 }
 
 /*
- * This is called free all the memory associated with an inode.
- * It must free the inode itself and any buffers allocated for
- * if_extents/if_data and if_broot.  It must also free the lock
- * associated with the inode.
- */
-void
-xfs_idestroy(
-	xfs_inode_t	*ip)
-{
-	switch (ip->i_d.di_mode & S_IFMT) {
-	case S_IFREG:
-	case S_IFDIR:
-	case S_IFLNK:
-		xfs_idestroy_fork(ip, XFS_DATA_FORK);
-		break;
-	}
-	if (ip->i_afp)
-		xfs_idestroy_fork(ip, XFS_ATTR_FORK);
-	mrfree(&ip->i_lock);
-	mrfree(&ip->i_iolock);
-	freesema(&ip->i_flock);
-
-#ifdef XFS_INODE_TRACE
-	ktrace_free(ip->i_trace);
-#endif
-#ifdef XFS_BMAP_TRACE
-	ktrace_free(ip->i_xtrace);
-#endif
-#ifdef XFS_BMBT_TRACE
-	ktrace_free(ip->i_btrace);
-#endif
-#ifdef XFS_RW_TRACE
-	ktrace_free(ip->i_rwtrace);
-#endif
-#ifdef XFS_ILOCK_TRACE
-	ktrace_free(ip->i_lock_trace);
-#endif
-#ifdef XFS_DIR2_TRACE
-	ktrace_free(ip->i_dir_trace);
-#endif
-	if (ip->i_itemp) {
-		/*
-		 * Only if we are shutting down the fs will we see an
-		 * inode still in the AIL. If it is there, we should remove
-		 * it to prevent a use-after-free from occurring.
-		 */
-		xfs_mount_t	*mp = ip->i_mount;
-		xfs_log_item_t	*lip = &ip->i_itemp->ili_item;
-
-		ASSERT(((lip->li_flags & XFS_LI_IN_AIL) == 0) ||
-				       XFS_FORCED_SHUTDOWN(ip->i_mount));
-		if (lip->li_flags & XFS_LI_IN_AIL) {
-			spin_lock(&mp->m_ail_lock);
-			if (lip->li_flags & XFS_LI_IN_AIL)
-				xfs_trans_delete_ail(mp, lip);
-			else
-				spin_unlock(&mp->m_ail_lock);
-		}
-		xfs_inode_item_destroy(ip);
-	}
-	kmem_zone_free(xfs_inode_zone, ip);
-}
-
-
-/*
  * Increment the pin count of the given buffer.
  * This value is protected by ipinlock spinlock in the mount structure.
  */
@@ -2860,6 +2795,74 @@ xfs_iunpin_wait(
 	wait_event(ip->i_ipin_wait, (atomic_read(&ip->i_pincount) == 0));
 }
 
+/*
+ * This is called free all the memory associated with an inode.
+ * It must free the inode itself and any buffers allocated for
+ * if_extents/if_data and if_broot.  It must also free the lock
+ * associated with the inode.
+ */
+void
+xfs_idestroy(
+	xfs_inode_t	*ip)
+{
+	/*
+	 * Wait for any log writes referencing this inode to complete.
+	 */
+	xfs_iunpin_wait(ip);
+
+	switch (ip->i_d.di_mode & S_IFMT) {
+	case S_IFREG:
+	case S_IFDIR:
+	case S_IFLNK:
+		xfs_idestroy_fork(ip, XFS_DATA_FORK);
+		break;
+	}
+	if (ip->i_afp)
+		xfs_idestroy_fork(ip, XFS_ATTR_FORK);
+	mrfree(&ip->i_lock);
+	mrfree(&ip->i_iolock);
+	freesema(&ip->i_flock);
+
+#ifdef XFS_INODE_TRACE
+	ktrace_free(ip->i_trace);
+#endif
+#ifdef XFS_BMAP_TRACE
+	ktrace_free(ip->i_xtrace);
+#endif
+#ifdef XFS_BMBT_TRACE
+	ktrace_free(ip->i_btrace);
+#endif
+#ifdef XFS_RW_TRACE
+	ktrace_free(ip->i_rwtrace);
+#endif
+#ifdef XFS_ILOCK_TRACE
+	ktrace_free(ip->i_lock_trace);
+#endif
+#ifdef XFS_DIR2_TRACE
+	ktrace_free(ip->i_dir_trace);
+#endif
+	if (ip->i_itemp) {
+		/*
+		 * Only if we are shutting down the fs will we see an
+		 * inode still in the AIL. If it is there, we should remove
+		 * it to prevent a use-after-free from occurring.
+		 */
+		xfs_mount_t	*mp = ip->i_mount;
+		xfs_log_item_t	*lip = &ip->i_itemp->ili_item;
+
+		ASSERT(((lip->li_flags & XFS_LI_IN_AIL) == 0) ||
+				       XFS_FORCED_SHUTDOWN(ip->i_mount));
+		if (lip->li_flags & XFS_LI_IN_AIL) {
+			spin_lock(&mp->m_ail_lock);
+			if (lip->li_flags & XFS_LI_IN_AIL)
+				xfs_trans_delete_ail(mp, lip);
+			else
+				spin_unlock(&mp->m_ail_lock);
+		}
+		xfs_inode_item_destroy(ip);
+	}
+	kmem_zone_free(xfs_inode_zone, ip);
+}
 
 /*
  * xfs_iextents_copy()

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] make xfs_idestroy() wait for log I/O to complete
  2007-12-12  7:20 [PATCH] make xfs_idestroy() wait for log I/O to complete Lachlan McIlroy
@ 2007-12-14 20:33 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2007-12-14 20:33 UTC (permalink / raw)
  To: Lachlan McIlroy; +Cc: xfs-dev, xfs-oss

On Wed, Dec 12, 2007 at 06:20:35PM +1100, Lachlan McIlroy wrote:
> An xfs inode can be destroyed before log I/O involving that inode
> is complete.  We need to wait for the inode to be unpinned before
> tearing it down.  The patch looks big but the only real change is
> adding a call to xfs_iunpin_wait() to the start of xfs_idestroy().
> The rest of the patch is moving xfs_idestroy() after the pinning
> routines.

Making sure the inode is unpinned before it's destroyed definitvely
sounds useful.  I can't think of any harm this might cause either.

I'd prefer to have to commits, one to move the function around and one
to add the call to xfs_iunpin_wait, though.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-12-14 20:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-12  7:20 [PATCH] make xfs_idestroy() wait for log I/O to complete Lachlan McIlroy
2007-12-14 20:33 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox