public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Dave Jones <davej@redhat.com>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Miklos Szeredi <mszeredi@suse.cz>, Jan Kara <jack@suse.cz>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-fsdevel@vger.kernel.org,
	"J. Bruce Fields" <bfields@redhat.com>,
	Sage Weil <sage@newdream.net>
Subject: Re: processes hung after sys_renameat, and 'missing' processes
Date: Thu, 07 Jun 2012 22:25:46 -0700	[thread overview]
Message-ID: <87bokugysl.fsf@xmission.com> (raw)
In-Reply-To: <20120608005935.GL30000@ZenIV.linux.org.uk> (Al Viro's message of "Fri, 8 Jun 2012 01:59:35 +0100")

Al Viro <viro@ZenIV.linux.org.uk> writes:

> On Fri, Jun 08, 2012 at 01:36:04AM +0100, Al Viro wrote:
>> Eric, how about this - if nothing else, that makes code in there simpler
>> and less dependent on details of VFS guts:
>
> Argh.  No, it's not enough.  Why are you using ->d_iput()?  You are not
> doing anything unusual with inode; the natural place for that is in
> ->d_release() and then it will get simpler rules wrt setting ->d_fsdata.

No good reason.  We do tie inode numbers to the syfs_dirent but the
inode was changed quite a while ago to hold it's own reference
sysfs_dirent.  So using d_iput looks like sysfs historical baggage.

> As it is, you need to do that exactly after the point where you know
> that it dentry won't be dropped without going through d_add().
>
> OK, I've split that in two commits and put into vfs.git#sysfs; take a look
> and comment, please.  Should get to git.kernel.in a few...

The patches on your sysfs branch look reasonable.

I am still learly of d_materialise_unique as it allows to create alias's
on non-directories.  It isn't a functional problem as d_revalidate will
catch the issue and make it look like we have a unlink/link pair instead
of a proper rename.  However since it is possible I would like to aim
for the higher quality of implemntation and use show renames as renames.

What would be ideal for sysfs is the d_add_singleton function below.  It
does what is needed without the weird d_materialise strangeness that is
in d_materialise_unique.  But if a all singing all dancing all
confusing function is preferable I would not mind.

What I would really like is an interface so that a distrubuted/remote
filesystem can provide an inotify like stream of and we can really
implement inotify in a distributed filesystem.  But since I am too lazy
to do that I am reluctant to give up what progress I have actually made
in that direction.

Eric

diff --git a/fs/dcache.c b/fs/dcache.c
index 85c9e2b..2aab524 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2537,6 +2537,74 @@ out_nolock:
 }
 EXPORT_SYMBOL_GPL(d_materialise_unique);
 
+/**
+ * d_add_singleton - add an inode with only a single dentry
+ * @entry: dentry to instantiate
+ * @inode: inode to attach to this dentry
+ *
+ * Fill in inode information in the entry. On success, it returns NULL.
+ * If an alias of "entry" already exists, then we assume that a rename
+ * has occurred and not been reported so the alias is renamed and we
+ * return the aliased dentry and drop one reference to the inode.
+ *
+ * Note that in order to avoid conflicts with rename() etc, the caller
+ * had better be holding the parent directory semaphore.
+ *
+ * This also assumes that the inode count has been incremented
+ * (or otherwise set) by the caller to indicate that it is now
+ * in use by the dcache.
+ */
+struct dentry *d_add_singleton(struct dentry *entry, struct inode *inode)
+{
+       struct dentry *alias, *actual = entry;
+
+       if (!inode) {
+               __d_instantiate(entry, NULL);
+               d_rehash(entry);
+               goto out_nolock;
+       }
+
+       spin_lock(&inode->i_lock);
+
+       /* Does an aliased dentry already exist? */
+       alias = __d_find_alias(inode);
+       if (alias) {
+               write_seqlock(&rename_lock);
+
+               if (d_ancestor(alias, entry)) {
+                       /* Check for loops */
+                       actual = ERR_PTR(-ELOOP);
+                       spin_unlock(&inode->i_lock);
+               } else {
+                       /* Avoid aliases.  This drops inode->i_lock */
+                       actual = __d_unalias(inode, entry, alias);
+               }
+               write_sequnlock(&rename_lock);
+               if (IS_ERR(actual)) {
+                       if (PTR_ERR(actual) == -ELOOP)
+                               pr_warn_ratelimited(
+                                       "VFS: Lookup of '%s' in %s %s"
+                                       " would have caused loop\n",
+                                       entry->d_name.name,
+                                       inode->i_sb->s_type->name,
+                                       inode->i_sb->s_id);
+                       dput(alias);
+               }
+               goto out_nolock;
+       }
+       __d_instantiate(entry, inode);
+       spin_unlock(&inode->i_lock);
+       d_rehash(entry);
+out_nolock:
+       if (actual == entry ) {
+               security_d_instantiate(entry, inode);
+               return NULL;
+       }
+       iput(inode);
+       return actual;
+}
+
+
 static int prepend(char **buffer, int *buflen, const char *str, int namelen)
 {
        *buflen -= namelen;
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 094789f..9613d4c 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -219,6 +219,8 @@ static inline int dname_external(struct dentry *dentry)
 extern void d_instantiate(struct dentry *, struct inode *);
 extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *);
 extern struct dentry * d_materialise_unique(struct dentry *, struct inode *);
+extern struct dentry * d_materialise_unalias(struct dentry *, struct inode *);
+extern struct dentry *d_add_singleton(struct dentry *, struct inode *);
 extern void __d_drop(struct dentry *dentry);
 extern void d_drop(struct dentry *dentry);
 extern void d_delete(struct dentry *);

  reply	other threads:[~2012-06-08  5:26 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-03 22:36 processes hung after sys_renameat, and 'missing' processes Dave Jones
2012-06-03 22:51 ` Dave Jones
2012-06-03 23:07 ` Linus Torvalds
2012-06-03 23:17   ` Al Viro
2012-06-03 23:28     ` Al Viro
2012-06-03 23:40       ` Al Viro
2012-06-03 23:59         ` Al Viro
2012-06-04  0:07       ` Dave Jones
2012-06-06 19:42       ` Dave Jones
2012-06-06 22:38         ` Linus Torvalds
2012-06-06 23:00           ` Dave Jones
2012-06-06 23:31             ` Linus Torvalds
2012-06-06 23:54               ` Al Viro
2012-06-07  0:29                 ` Dave Jones
2012-06-07  0:40                   ` Al Viro
2012-06-07  0:42                   ` Linus Torvalds
2012-06-07  1:19                     ` Dave Jones
2012-06-07  1:29                       ` Al Viro
2012-06-07  1:31                         ` Dave Jones
2012-06-07  1:31                         ` Al Viro
2012-06-07  1:42                           ` Dave Jones
2012-06-07  1:45                           ` Linus Torvalds
2012-06-07  1:54                             ` Al Viro
2012-06-07  2:08                               ` Dave Jones
2012-06-07 19:36                         ` Al Viro
2012-06-07 20:43                           ` Sage Weil
2012-06-07 23:12                           ` Eric W. Biederman
2012-06-07 23:39                             ` Al Viro
2012-06-07 23:57                             ` Linus Torvalds
2012-06-08  0:36                               ` Al Viro
2012-06-08  0:42                                 ` Linus Torvalds
2012-06-08  0:59                                 ` Al Viro
2012-06-08  5:25                                   ` Eric W. Biederman [this message]
2012-06-08  5:48                                     ` Al Viro
2012-06-08  7:54                                       ` Eric W. Biederman
2012-06-08 20:20                                         ` Al Viro
2012-06-08  2:08                                 ` Eric W. Biederman
2012-06-08  2:37                                   ` Al Viro
2012-06-08  2:18                           ` Al Viro
2012-06-08 16:22                           ` J. Bruce Fields
2012-06-08 17:44                             ` Linus Torvalds
2012-06-11 12:17                               ` J. Bruce Fields
2012-06-07  1:40                       ` Linus Torvalds
2012-06-07  0:35                 ` Linus Torvalds
2012-06-07 10:26               ` Peter Zijlstra
2012-06-07 15:30                 ` Linus Torvalds
2012-06-08  7:31                   ` Peter Zijlstra
2012-06-08 14:38                     ` Dave Jones
2012-06-08 14:51                       ` Peter Zijlstra
2012-06-08 15:01                         ` Dave Jones
2012-06-08 15:11                           ` Peter Zijlstra
2012-06-08 15:21                             ` Dave Jones
2012-06-08 14:46                     ` J. Bruce Fields
2012-06-08 15:08                       ` Peter Zijlstra
2012-06-11 12:17                         ` J. Bruce Fields
2012-06-04  0:00   ` Dave Jones
2012-06-04  0:16     ` Linus Torvalds
2012-06-04  0:20       ` Al Viro
2012-06-04  9:35         ` Peter Zijlstra
2012-06-04  9:29       ` Peter Zijlstra
2012-06-04 10:49         ` Peter Zijlstra
2012-06-07  0:13           ` Dave Jones
  -- strict thread matches above, loose matches on Subject: below --
2012-06-07  7:07 Miklos Szeredi
2012-06-07 15:44 ` Linus Torvalds
2012-06-11 16:02   ` Miklos Szeredi

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=87bokugysl.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=bfields@redhat.com \
    --cc=davej@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mszeredi@suse.cz \
    --cc=peterz@infradead.org \
    --cc=sage@newdream.net \
    --cc=torvalds@linux-foundation.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