mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: viro@zeniv.linux.org.uk
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	hirofumi@mail.parknet.co.jp
Subject: [PATCH 2/6] vfs: add d_ancestor()
Date: Wed, 15 Oct 2008 22:58:10 +0900	[thread overview]
Message-ID: <e015bca83e848f5f6f2226623.ps@mail.parknet.co.jp> (raw)
In-Reply-To: <fcaad2cb3e848f5f6f1126623.ps@mail.parknet.co.jp>



This adds d_ancestor() instead of d_isparent(), then use it.

If new_dentry == old_dentry, is_subdir() returns 1, looks strange. But
I'm not checking callers for now, so this keeps current behavior.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---

 fs/dcache.c            |   28 ++++++++++------------------
 fs/namei.c             |   22 ++++++++++------------
 include/linux/dcache.h |    1 +
 3 files changed, 21 insertions(+), 30 deletions(-)

diff -puN fs/dcache.c~dcache-cleanup-2 fs/dcache.c
--- linux-2.6/fs/dcache.c~dcache-cleanup-2	2008-10-13 02:26:23.000000000 +0900
+++ linux-2.6-hirofumi/fs/dcache.c	2008-10-13 02:26:55.000000000 +0900
@@ -1719,17 +1719,18 @@ void d_move(struct dentry * dentry, stru
 }
 
 /*
- * Helper that returns 1 if p1 is a parent of p2, else 0
+ * Helper that returns the ancestor dentry of p2 which is a child of
+ * p1, if p1 is an ancestor of p2, else NULL.
  */
-static int d_isparent(struct dentry *p1, struct dentry *p2)
+struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2)
 {
 	struct dentry *p;
 
 	for (p = p2; !IS_ROOT(p); p = p->d_parent) {
 		if (p->d_parent == p1)
-			return 1;
+			return p;
 	}
-	return 0;
+	return NULL;
 }
 
 /*
@@ -1753,7 +1754,7 @@ static struct dentry *__d_unalias(struct
 
 	/* Check for loops */
 	ret = ERR_PTR(-ELOOP);
-	if (d_isparent(alias, dentry))
+	if (d_ancestor(alias, dentry))
 		goto out_err;
 
 	/* See lock_rename() */
@@ -2156,28 +2157,19 @@ out:
 int is_subdir(struct dentry * new_dentry, struct dentry * old_dentry)
 {
 	int result;
-	struct dentry * saved = new_dentry;
 	unsigned long seq;
 
+	if (new_dentry == old_dentry)
+		return 1;
+
 	/* need rcu_readlock to protect against the d_parent trashing due to
 	 * d_move
 	 */
 	rcu_read_lock();
         do {
 		/* for restarting inner loop in case of seq retry */
-		new_dentry = saved;
-		result = 0;
 		seq = read_seqbegin(&rename_lock);
-		for (;;) {
-			if (new_dentry != old_dentry) {
-				if (IS_ROOT(new_dentry))
-					break;
-				new_dentry = new_dentry->d_parent;
-				continue;
-			}
-			result = 1;
-			break;
-		}
+		result = (d_ancestor(old_dentry, new_dentry) != NULL);
 	} while (read_seqretry(&rename_lock, seq));
 	rcu_read_unlock();
 
diff -puN include/linux/dcache.h~dcache-cleanup-2 include/linux/dcache.h
--- linux-2.6/include/linux/dcache.h~dcache-cleanup-2	2008-10-13 02:26:23.000000000 +0900
+++ linux-2.6-hirofumi/include/linux/dcache.h	2008-10-13 02:26:23.000000000 +0900
@@ -287,6 +287,7 @@ static inline struct dentry *d_add_uniqu
 
 /* used for rename() and baskets */
 extern void d_move(struct dentry *, struct dentry *);
+extern struct dentry *d_ancestor(struct dentry *, struct dentry *);
 
 /* appendix may either be NULL or be used for transname suffixes */
 extern struct dentry * d_lookup(struct dentry *, struct qstr *);
diff -puN fs/namei.c~dcache-cleanup-2 fs/namei.c
--- linux-2.6/fs/namei.c~dcache-cleanup-2	2008-10-13 02:26:23.000000000 +0900
+++ linux-2.6-hirofumi/fs/namei.c	2008-10-13 02:26:23.000000000 +0900
@@ -1470,20 +1470,18 @@ struct dentry *lock_rename(struct dentry
 
 	mutex_lock(&p1->d_inode->i_sb->s_vfs_rename_mutex);
 
-	for (p = p1; !IS_ROOT(p); p = p->d_parent) {
-		if (p->d_parent == p2) {
-			mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_PARENT);
-			mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_CHILD);
-			return p;
-		}
+	p = d_ancestor(p2, p1);
+	if (p) {
+		mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_PARENT);
+		mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_CHILD);
+		return p;
 	}
 
-	for (p = p2; !IS_ROOT(p); p = p->d_parent) {
-		if (p->d_parent == p1) {
-			mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);
-			mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_CHILD);
-			return p;
-		}
+	p = d_ancestor(p1, p2);
+	if (p) {
+		mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);
+		mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_CHILD);
+		return p;
 	}
 
 	mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);
_

  reply	other threads:[~2008-10-15 14:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-15 13:58 [PATCH 1/6] vfs: replace parent == dentry->d_parent by IS_ROOT() OGAWA Hirofumi
2008-10-15 13:58 ` OGAWA Hirofumi [this message]
2008-10-15 13:58   ` [PATCH 3/6] vfs: add __d_instantiate() helper OGAWA Hirofumi
2008-10-15 13:58     ` [PATCH 4/6] vfs: remove unnecessary fsnotify_d_instantiate() OGAWA Hirofumi
2008-10-15 13:58       ` [PATCH 5/6] vfs: remove LOOKUP_PARENT from non LOOKUP_PARENT lookup OGAWA Hirofumi
2008-10-15 13:58         ` [PATCH 6/6] vfs: add LOOKUP_RENAME_NEW intent OGAWA Hirofumi
2008-10-15 19:37           ` Christoph Hellwig
2008-10-15 20:13             ` OGAWA Hirofumi
2008-10-15 19:44         ` [PATCH 5/6] vfs: remove LOOKUP_PARENT from non LOOKUP_PARENT lookup Christoph Hellwig
2008-10-15 21:43           ` OGAWA Hirofumi
2008-10-15 19:43       ` [PATCH 4/6] vfs: remove unnecessary fsnotify_d_instantiate() Christoph Hellwig
2008-10-15 20:16         ` OGAWA Hirofumi
2008-10-15 20:20           ` Christoph Hellwig
2008-10-15 19:41     ` [PATCH 3/6] vfs: add __d_instantiate() helper Christoph Hellwig
2008-10-15 20:39       ` OGAWA Hirofumi
2008-10-15 20:47         ` Trond Myklebust
2008-10-15 21:31           ` OGAWA Hirofumi
2008-10-15 19:53   ` [PATCH 2/6] vfs: add d_ancestor() Christoph Hellwig
2008-10-15 21:42     ` OGAWA Hirofumi
2008-10-15 19:45 ` [PATCH 1/6] vfs: replace parent == dentry->d_parent by IS_ROOT() Christoph Hellwig
2008-10-15 20:24   ` OGAWA Hirofumi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e015bca83e848f5f6f2226623.ps@mail.parknet.co.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®