linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exportfs: add find_acceptable_alias helper
@ 2006-01-15 17:12 Christoph Hellwig
  2006-01-15 21:41 ` Neil Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2006-01-15 17:12 UTC (permalink / raw)
  To: neilb, akpm; +Cc: linux-fsdevel

find_exported_dentry contains two duplicate loops to find an alias that
the acceptable callback likes.  Split this out to a new helper and
switch from list_for_each to list_for_each_entry to make it more
readable.


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

Index: linux-2.6.15-mm4/fs/exportfs/expfs.c
===================================================================
--- linux-2.6.15-mm4.orig/fs/exportfs/expfs.c	2006-01-15 12:24:06.000000000 +0100
+++ linux-2.6.15-mm4/fs/exportfs/expfs.c	2006-01-15 17:57:08.000000000 +0100
@@ -11,6 +11,33 @@
 
 #define dprintk(fmt, args...) do{}while(0)
 
+static struct dentry *
+find_acceptable_alias(struct dentry *result,
+		int (*acceptable)(void *context, struct dentry *dentry),
+		void *context)
+{
+	struct dentry *dentry, *toput = NULL;
+
+	spin_lock(&dcache_lock);
+	list_for_each_entry(dentry, &result->d_inode->i_dentry, d_alias) {
+		dget_locked(dentry);
+		spin_unlock(&dcache_lock);
+		if (toput)
+			dput(toput);
+		if (dentry != result && acceptable(context, dentry)) {
+			dput(result);
+			return dentry;
+		}
+		spin_lock(&dcache_lock);
+		toput = dentry;
+	}
+	spin_unlock(&dcache_lock);
+
+	if (toput)
+		dput(toput);
+	return NULL;
+}
+
 /**
  * find_exported_dentry - helper routine to implement export_operations->decode_fh
  * @sb:		The &super_block identifying the filesystem
@@ -52,8 +79,7 @@
 	struct dentry *target_dir;
 	int err;
 	struct export_operations *nops = sb->s_export_op;
-	struct list_head *le, *head;
-	struct dentry *toput = NULL;
+	struct dentry *alias;
 	int noprogress;
 	char nbuf[NAME_MAX+1];
 
@@ -79,27 +105,10 @@
 			/* there is no other dentry, so fail */
 			goto err_result;
 		}
-		/* try any other aliases */
-		spin_lock(&dcache_lock);
-		head = &result->d_inode->i_dentry;
-		list_for_each(le, head) {
-			struct dentry *dentry = list_entry(le, struct dentry, d_alias);
-			dget_locked(dentry);
-			spin_unlock(&dcache_lock);
-			if (toput)
-				dput(toput);
-			toput = NULL;
-			if (dentry != result &&
-			    acceptable(context, dentry)) {
-				dput(result);
-				return dentry;
-			}
-			spin_lock(&dcache_lock);
-			toput = dentry;
-		}
-		spin_unlock(&dcache_lock);
-		if (toput)
-			dput(toput);
+
+		alias = find_acceptable_alias(result, acceptable, context);
+		if (alias)
+			return alias;
 	}			
 
 	/* It's a directory, or we are required to confirm the file's
@@ -258,26 +267,10 @@
 	/* now result is properly connected, it is our best bet */
 	if (acceptable(context, result))
 		return result;
-	/* one last try of the aliases.. */
-	spin_lock(&dcache_lock);
-	toput = NULL;
-	head = &result->d_inode->i_dentry;
-	list_for_each(le, head) {
-		struct dentry *dentry = list_entry(le, struct dentry, d_alias);
-		dget_locked(dentry);
-		spin_unlock(&dcache_lock);
-		if (toput) dput(toput);
-		if (dentry != result &&
-		    acceptable(context, dentry)) {
-			dput(result);
-			return dentry;
-		}
-		spin_lock(&dcache_lock);
-		toput = dentry;
-	}
-	spin_unlock(&dcache_lock);
-	if (toput)
-		dput(toput);
+
+	alias = find_acceptable_alias(result, acceptable, context);
+	if (alias)
+		return alias;
 
 	/* drat - I just cannot find anything acceptable */
 	dput(result);

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

* Re: [PATCH] exportfs: add find_acceptable_alias helper
  2006-01-15 17:12 [PATCH] exportfs: add find_acceptable_alias helper Christoph Hellwig
@ 2006-01-15 21:41 ` Neil Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Brown @ 2006-01-15 21:41 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: akpm, linux-fsdevel

On Sunday January 15, hch@lst.de wrote:
> find_exported_dentry contains two duplicate loops to find an alias that
> the acceptable callback likes.  Split this out to a new helper and
> switch from list_for_each to list_for_each_entry to make it more
> readable.
> 
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: NeilBrown <neilb@suse.de>

Thanks.

NeilBrown

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

end of thread, other threads:[~2006-01-15 21:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-15 17:12 [PATCH] exportfs: add find_acceptable_alias helper Christoph Hellwig
2006-01-15 21:41 ` Neil Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).