public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] simplify xfs_lock_for_rename
@ 2008-04-10 18:44 Christoph Hellwig
  2008-04-11  0:24 ` Barry Naujok
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Christoph Hellwig @ 2008-04-10 18:44 UTC (permalink / raw)
  To: xfs

as with lookup merge what's left of xfs_dir_lookup_int into it, kill
a useless lock roundtrip left over from IRIX and kill a bunch of useless
variables.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: linux-2.6-xfs/fs/xfs/xfs_rename.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_rename.c	2008-04-09 20:30:08.000000000 +0200
+++ linux-2.6-xfs/fs/xfs/xfs_rename.c	2008-04-10 08:58:50.000000000 +0200
@@ -67,10 +67,6 @@ xfs_rename_unlock4(
 	}
 }
 
-#ifdef DEBUG
-int xfs_rename_skip, xfs_rename_nskip;
-#endif
-
 /*
  * The following routine will acquire the locks required for a rename
  * operation. The code understands the semantics of renames and will
@@ -92,47 +88,33 @@ xfs_lock_for_rename(
 	xfs_inode_t	**i_tab,/* out: array of inode returned, sorted */
 	int		*num_inodes)  /* out: number of inodes in array */
 {
-	xfs_inode_t		*ip2 = NULL;
 	xfs_inode_t		*temp;
-	xfs_ino_t		inum1, inum2;
+	xfs_ino_t		inum2;
 	int			error;
 	int			i, j;
 	uint			lock_mode;
-	int			diff_dirs = (dp1 != dp2);
 
-	/*
-	 * First, find out the current inums of the entries so that we
-	 * can determine the initial locking order.  We'll have to
-	 * sanity check stuff after all the locks have been acquired
-	 * to see if we still have the right inodes, directories, etc.
-	 */
-	lock_mode = xfs_ilock_map_shared(dp1);
+	*ipp2 = NULL;
+
 	IHOLD(ip1);
 	xfs_itrace_ref(ip1);
 
-	inum1 = ip1->i_ino;
-
-	/*
-	 * Unlock dp1 and lock dp2 if they are different.
-	 */
-	if (diff_dirs) {
-		xfs_iunlock_map_shared(dp1, lock_mode);
-		lock_mode = xfs_ilock_map_shared(dp2);
+	lock_mode = xfs_ilock_map_shared(dp2);
+	error = xfs_dir_lookup(NULL, dp2, name2, &inum2);
+	if (!error) {
+		xfs_iunlock(dp2, lock_mode);
+		error = xfs_iget(dp2->i_mount, NULL, inum2, 0, 0, ipp2, 0);
+		xfs_ilock(dp2, lock_mode);
 	}
 
-	error = xfs_dir_lookup_int(dp2, lock_mode, name2, &inum2, &ip2);
 	if (error == ENOENT) {		/* target does not need to exist. */
 		inum2 = 0;
 	} else if (error) {
-		/*
-		 * If dp2 and dp1 are the same, the next line unlocks dp1.
-		 * Got it?
-		 */
 		xfs_iunlock_map_shared(dp2, lock_mode);
-		IRELE (ip1);
+		IRELE(ip1);
 		return error;
 	} else {
-		xfs_itrace_ref(ip2);
+		xfs_itrace_ref(*ipp2);
 	}
 
 	/*
@@ -150,9 +132,8 @@ xfs_lock_for_rename(
 		i_tab[3] = NULL;
 	} else {
 		*num_inodes = 4;
-		i_tab[3] = ip2;
+		i_tab[3] = *ipp2;
 	}
-	*ipp2 = i_tab[3];
 
 	/*
 	 * Sort the elements via bubble sort.  (Remember, there are at
@@ -178,14 +159,8 @@ xfs_lock_for_rename(
 	 */
 
 	if (i_tab[0] == dp2 && lock_mode == XFS_ILOCK_SHARED) {
-#ifdef DEBUG
-		xfs_rename_skip++;
-#endif
 		xfs_lock_inodes(i_tab, *num_inodes, 1, XFS_ILOCK_SHARED);
 	} else {
-#ifdef DEBUG
-		xfs_rename_nskip++;
-#endif
 		xfs_iunlock_map_shared(dp2, lock_mode);
 		xfs_lock_inodes(i_tab, *num_inodes, 0, XFS_ILOCK_SHARED);
 	}
Index: linux-2.6-xfs/fs/xfs/xfs_utils.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_utils.c	2008-04-09 20:30:08.000000000 +0200
+++ linux-2.6-xfs/fs/xfs/xfs_utils.c	2008-04-10 08:46:27.000000000 +0200
@@ -41,49 +41,6 @@
 #include "xfs_utils.h"
 
 
-int
-xfs_dir_lookup_int(
-	xfs_inode_t	*dp,
-	uint		lock_mode,
-	struct xfs_name	*name,
-	xfs_ino_t	*inum,
-	xfs_inode_t	**ipp)
-{
-	int		error;
-
-	xfs_itrace_entry(dp);
-
-	error = xfs_dir_lookup(NULL, dp, name, inum);
-	if (!error) {
-		/*
-		 * Unlock the directory. We do this because we can't
-		 * hold the directory lock while doing the vn_get()
-		 * in xfs_iget().  Doing so could cause us to hold
-		 * a lock while waiting for the inode to finish
-		 * being inactive while it's waiting for a log
-		 * reservation in the inactive routine.
-		 */
-		xfs_iunlock(dp, lock_mode);
-		error = xfs_iget(dp->i_mount, NULL, *inum, 0, 0, ipp, 0);
-		xfs_ilock(dp, lock_mode);
-
-		if (error) {
-			*ipp = NULL;
-		} else if ((*ipp)->i_d.di_mode == 0) {
-			/*
-			 * The inode has been freed.  Something is
-			 * wrong so just get out of here.
-			 */
-			xfs_iunlock(dp, lock_mode);
-			xfs_iput_new(*ipp, 0);
-			*ipp = NULL;
-			xfs_ilock(dp, lock_mode);
-			error = XFS_ERROR(ENOENT);
-		}
-	}
-	return error;
-}
-
 /*
  * Allocates a new inode from disk and return a pointer to the
  * incore copy. This routine will internally commit the current
Index: linux-2.6-xfs/fs/xfs/xfs_utils.h
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_utils.h	2008-04-09 20:30:08.000000000 +0200
+++ linux-2.6-xfs/fs/xfs/xfs_utils.h	2008-04-10 08:46:27.000000000 +0200
@@ -21,8 +21,6 @@
 #define IRELE(ip)	VN_RELE(XFS_ITOV(ip))
 #define IHOLD(ip)	VN_HOLD(XFS_ITOV(ip))
 
-extern int xfs_dir_lookup_int(xfs_inode_t *, uint, struct xfs_name *,
-				xfs_ino_t *, xfs_inode_t **);
 extern int xfs_truncate_file(xfs_mount_t *, xfs_inode_t *);
 extern int xfs_dir_ialloc(xfs_trans_t **, xfs_inode_t *, mode_t, xfs_nlink_t,
 				xfs_dev_t, cred_t *, prid_t, int,

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

end of thread, other threads:[~2008-04-11  9:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-10 18:44 [PATCH 2/2] simplify xfs_lock_for_rename Christoph Hellwig
2008-04-11  0:24 ` Barry Naujok
2008-04-11  4:40 ` Barry Naujok
2008-04-11  7:37   ` Christoph Hellwig
2008-04-11  8:40     ` Barry Naujok
2008-04-11  8:46       ` Christoph Hellwig
2008-04-11  9:11 ` [PATCH 2/2] remove manual lookup from xfs_rename and simplify locking Christoph Hellwig

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