1. 13 1月, 2012 1 次提交
  2. 11 1月, 2012 1 次提交
    • M
      fix shrink_dcache_parent() livelock · eaf5f907
      Miklos Szeredi 提交于
      Two (or more) concurrent calls of shrink_dcache_parent() on the same dentry may
      cause shrink_dcache_parent() to loop forever.
      
      Here's what appears to happen:
      
      1 - CPU0: select_parent(P) finds C and puts it on dispose list, returns 1
      
      2 - CPU1: select_parent(P) locks P->d_lock
      
      3 - CPU0: shrink_dentry_list() locks C->d_lock
         dentry_kill(C) tries to lock P->d_lock but fails, unlocks C->d_lock
      
      4 - CPU1: select_parent(P) locks C->d_lock,
               moves C from dispose list being processed on CPU0 to the new
      dispose list, returns 1
      
      5 - CPU0: shrink_dentry_list() finds dispose list empty, returns
      
      6 - Goto 2 with CPU0 and CPU1 switched
      
      Basically select_parent() steals the dentry from shrink_dentry_list() and thinks
      it found a new one, causing shrink_dentry_list() to think it's making progress
      and loop over and over.
      
      One way to trigger this is to make udev calls stat() on the sysfs file while it
      is going away.
      
      Having a file in /lib/udev/rules.d/ with only this one rule seems to the trick:
      
      ATTR{vendor}=="0x8086", ATTR{device}=="0x10ca", ENV{PCI_SLOT_NAME}="%k", ENV{MATCHADDR}="$attr{address}", RUN+="/bin/true"
      
      Then execute the following loop:
      
      while true; do
              echo -bond0 > /sys/class/net/bonding_masters
              echo +bond0 > /sys/class/net/bonding_masters
              echo -bond1 > /sys/class/net/bonding_masters
              echo +bond1 > /sys/class/net/bonding_masters
      done
      
      One fix would be to check all callers and prevent concurrent calls to
      shrink_dcache_parent().  But I think a better solution is to stop the
      stealing behavior.
      
      This patch adds a new dentry flag that is set when the dentry is added to the
      dispose list.  The flag is cleared in dentry_lru_del() in case the dentry gets a
      new reference just before being pruned.
      
      If the dentry has this flag, select_parent() will skip it and let
      shrink_dentry_list() retry pruning it.  With select_parent() skipping those
      dentries there will not be the appearance of progress (new dentries found) when
      there is none, hence shrink_dcache_parent() will not loop forever.
      
      Set the flag is also set in prune_dcache_sb() for consistency as suggested by
      Linus.
      Signed-off-by: NMiklos Szeredi <mszeredi@suse.cz>
      CC: stable@vger.kernel.org
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      eaf5f907
  3. 10 1月, 2012 2 次提交
    • A
      vfs: new helper - d_make_root() · adc0e91a
      Al Viro 提交于
      d_alloc_root() with iput() in case of allocation failure...
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      adc0e91a
    • D
      dcache: use a dispose list in select_parent · b48f03b3
      Dave Chinner 提交于
      select_parent currently abuses the dentry cache LRU to provide
      cleanup features for child dentries that need to be freed. It moves
      them to the tail of the LRU, then tells shrink_dcache_parent() to
      calls __shrink_dcache_sb to unconditionally move them to a dispose
      list (as DCACHE_REFERENCED is ignored). __shrink_dcache_sb() has to
      relock the dentries to move them off the LRU onto the dispose list,
      but otherwise does not touch the dentries that select_parent() moved
      to the tail of the LRU. It then passses the dispose list to
      shrink_dentry_list() which tries to free the dentries.
      
      IOWs, the use of __shrink_dcache_sb() is superfluous - we can build
      exactly the same list of dentries for disposal directly in
      select_parent() and call shrink_dentry_list() instead of calling
      __shrink_dcache_sb() to do that. This means that we avoid long holds
      on the lru lock walking the LRU moving dentries to the dispose list
      We also avoid the need to relock each dentry just to move it off the
      LRU, reducing the numebr of times we lock each dentry to dispose of
      them in shrink_dcache_parent() from 3 to 2 times.
      
      Further, we remove one of the two callers of __shrink_dcache_sb().
      This also means that __shrink_dcache_sb can be moved into back into
      prune_dcache_sb() and we no longer have to handle referenced
      dentries conditionally, simplifying the code.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      b48f03b3
  4. 04 1月, 2012 7 次提交
  5. 07 12月, 2011 1 次提交
    • A
      fix apparmor dereferencing potentially freed dentry, sanitize __d_path() API · 02125a82
      Al Viro 提交于
      __d_path() API is asking for trouble and in case of apparmor d_namespace_path()
      getting just that.  The root cause is that when __d_path() misses the root
      it had been told to look for, it stores the location of the most remote ancestor
      in *root.  Without grabbing references.  Sure, at the moment of call it had
      been pinned down by what we have in *path.  And if we raced with umount -l, we
      could have very well stopped at vfsmount/dentry that got freed as soon as
      prepend_path() dropped vfsmount_lock.
      
      It is safe to compare these pointers with pre-existing (and known to be still
      alive) vfsmount and dentry, as long as all we are asking is "is it the same
      address?".  Dereferencing is not safe and apparmor ended up stepping into
      that.  d_namespace_path() really wants to examine the place where we stopped,
      even if it's not connected to our namespace.  As the result, it looked
      at ->d_sb->s_magic of a dentry that might've been already freed by that point.
      All other callers had been careful enough to avoid that, but it's really
      a bad interface - it invites that kind of trouble.
      
      The fix is fairly straightforward, even though it's bigger than I'd like:
      	* prepend_path() root argument becomes const.
      	* __d_path() is never called with NULL/NULL root.  It was a kludge
      to start with.  Instead, we have an explicit function - d_absolute_root().
      Same as __d_path(), except that it doesn't get root passed and stops where
      it stops.  apparmor and tomoyo are using it.
      	* __d_path() returns NULL on path outside of root.  The main
      caller is show_mountinfo() and that's precisely what we pass root for - to
      skip those outside chroot jail.  Those who don't want that can (and do)
      use d_path().
      	* __d_path() root argument becomes const.  Everyone agrees, I hope.
      	* apparmor does *NOT* try to use __d_path() or any of its variants
      when it sees that path->mnt is an internal vfsmount.  In that case it's
      definitely not mounted anywhere and dentry_path() is exactly what we want
      there.  Handling of sysctl()-triggered weirdness is moved to that place.
      	* if apparmor is asked to do pathname relative to chroot jail
      and __d_path() tells it we it's not in that jail, the sucker just calls
      d_absolute_path() instead.  That's the other remaining caller of __d_path(),
      BTW.
              * seq_path_root() does _NOT_ return -ENAMETOOLONG (it's stupid anyway -
      the normal seq_file logics will take care of growing the buffer and redoing
      the call of ->show() just fine).  However, if it gets path not reachable
      from root, it returns SEQ_SKIP.  The only caller adjusted (i.e. stopped
      ignoring the return value as it used to do).
      Reviewed-by: NJohn Johansen <john.johansen@canonical.com>
      ACKed-by: NJohn Johansen <john.johansen@canonical.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      Cc: stable@vger.kernel.org
      02125a82
  6. 21 11月, 2011 1 次提交
    • D
      VFS: Log the fact that we've given ELOOP rather than creating a loop · dd179946
      David Howells 提交于
      To prevent an NFS server from being used to create a directory loop in an NFS
      superblock on the client, the following patch was committed:
      
      	commit 18367501
      	Author: Al Viro <viro@zeniv.linux.org.uk>
      	Date:   Tue Jul 12 21:42:24 2011 -0400
      	Subject: fix loop checks in d_materialise_unique()
      
      This causes ELOOP to be reported to anyone trying to access the dentry that
      would otherwise cause the kernel to complete the loop.
      
      However, no indication is given to the caller as to why an operation that ought
      to work doesn't.  The fault is with the kernel, which doesn't want to try and
      solve the problem as it gets horrendously messy if there's another mountpoint
      somewhere in the trees being spliced that can't be moved[*].
      
      [*] The real problem is that we don't handle the excision of a subtree that
      gets moved _out_ of what we can see.  This can happen on the server where a
      directory is merely moved between two other dirs on the same filesystem, but
      where destination dir is not accessible by the client.
      
      So, given the choice to return ELOOP rather than trying to reconfigure the
      dentry tree, we should give the caller some indication of why they aren't being
      allowed to make what should be a legitimate request and log a message.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NSachin Prabhu <sprabhu@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      dd179946
  7. 08 11月, 2011 1 次提交
  8. 02 11月, 2011 1 次提交
    • S
      vfs: add d_prune dentry operation · f0023bc6
      Sage Weil 提交于
      This adds a d_prune dentry operation that is called by the VFS prior to
      pruning (i.e. unhashing and killing) a hashed dentry from the dcache.
      Wrap dentry_lru_del() and use the new _prune() helper in the cases where we
      are about to unhash and kill the dentry.
      
      This will be used by Ceph to maintain a flag indicating whether the
      complete contents of a directory are contained in the dcache, allowing it
      to satisfy lookups and readdir without addition server communication.
      
      Renumber a few DCACHE_* #defines to group DCACHE_OP_PRUNE with the other
      DCACHE_OP_ bits.
      Signed-off-by: NSage Weil <sage@newdream.net>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      f0023bc6
  9. 07 8月, 2011 1 次提交
    • L
      vfs: renumber DCACHE_xyz flags, remove some stale ones · 830c0f0e
      Linus Torvalds 提交于
      Gcc tends to generate better code with small integers, including the
      DCACHE_xyz flag tests - so move the common ones to be first in the list.
      Also just remove the unused DCACHE_INOTIFY_PARENT_WATCHED and
      DCACHE_AUTOFS_PENDING values, their users no longer exists in the source
      tree.
      
      And add a "unlikely()" to the DCACHE_OP_COMPARE test, since we want the
      common case to be a nice straight-line fall-through.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      830c0f0e
  10. 04 8月, 2011 1 次提交
  11. 01 8月, 2011 3 次提交
    • D
      VFS: Reorganise shrink_dcache_for_umount_subtree() after demise of dcache_lock · 43c1c9cd
      David Howells 提交于
      Reorganise shrink_dcache_for_umount_subtree() in light of the demise of
      dcache_lock.  Without that dcache_lock, there is no need for the batching of
      removal of dentries from the system under it (we wanted to make intensive use
      of the locked data whilst we held it, but didn't want to hold it for long at a
      time).
      
      This works, provided the preceding patch is correct in its removal of locking
      on dentry->d_lock on the basis that no one should be locking these dentries any
      more as the whole superblock is defunct.
      
      With this patch, the calls to dentry_lru_del() and __d_shrink() are placed at
      the point where each dentry is detached handled.
      
      It is possible that, as an alternative, the batching should still be done -
      but only for dentry_lru_del() of all a dentry's children in one go.  In such a
      case, the batching would be done under dcache_lru_lock.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      43c1c9cd
    • D
      VFS: Remove dentry->d_lock locking from shrink_dcache_for_umount_subtree() · c6627c60
      David Howells 提交于
      Locks of the dcache_lock were replaced by locks of dentry->d_lock in commits
      such as:
      
      	23044507
      	2fd6b7f5
      
      as part of the RCU-based pathwalk changes, despite the fact that the caller
      (shrink_dcache_for_umount()) notes in the banner comment the reasons that
      d_lock is not necessary in these functions:
      
      /*
       * destroy the dentries attached to a superblock on unmounting
       * - we don't need to use dentry->d_lock because:
       *   - the superblock is detached from all mountings and open files, so the
       *     dentry trees will not be rearranged by the VFS
       *   - s_umount is write-locked, so the memory pressure shrinker will ignore
       *     any dentries belonging to this superblock that it comes across
       *   - the filesystem itself is no longer permitted to rearrange the dentries
       *     in this superblock
       */
      
      So remove these locks.  If the locks are actually necessary, then this banner
      comment should be altered instead.
      
      The hash table chains are protected by 1-bit locks in the hash table heads, so
      those shouldn't be a problem.
      
      Note that to make this work, __d_drop() has to be split so that the RCUwalk
      barrier can be avoided.  This causes problems otherwise as it has an assertion
      that dentry->d_lock is locked - but there is no need for that as no one else
      can be trying to access this dentry, except to step over it (and that should
      be handled by d_free(), I think).
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Cc: Nick Piggin <npiggin@kernel.dk>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      c6627c60
    • D
      VFS: Remove detached-dentry counter from shrink_dcache_for_umount_subtree() · 35f40ef0
      David Howells 提交于
      Remove the detached-dentry counter from shrink_dcache_for_umount_subtree() as
      the value it computes is no longer used as of commit
      312d3ca8 which made the nr_dentry counters
      summed per-CPU rather than global atomic.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      35f40ef0
  12. 27 7月, 2011 1 次提交
  13. 22 7月, 2011 1 次提交
  14. 21 7月, 2011 3 次提交
    • A
      Remove dead code in dget_parent() · 86c98e8c
      Al Viro 提交于
      ->d_parent is never NULL...
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      86c98e8c
    • A
    • D
      superblock: introduce per-sb cache shrinker infrastructure · b0d40c92
      Dave Chinner 提交于
      With context based shrinkers, we can implement a per-superblock
      shrinker that shrinks the caches attached to the superblock. We
      currently have global shrinkers for the inode and dentry caches that
      split up into per-superblock operations via a coarse proportioning
      method that does not batch very well.  The global shrinkers also
      have a dependency - dentries pin inodes - so we have to be very
      careful about how we register the global shrinkers so that the
      implicit call order is always correct.
      
      With a per-sb shrinker callout, we can encode this dependency
      directly into the per-sb shrinker, hence avoiding the need for
      strictly ordering shrinker registrations. We also have no need for
      any proportioning code for the shrinker subsystem already provides
      this functionality across all shrinkers. Allowing the shrinker to
      operate on a single superblock at a time means that we do less
      superblock list traversals and locking and reclaim should batch more
      effectively. This should result in less CPU overhead for reclaim and
      potentially faster reclaim of items from each filesystem.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      b0d40c92
  15. 20 7月, 2011 3 次提交
    • A
      make d_splice_alias(ERR_PTR(err), dentry) = ERR_PTR(err) · a9049376
      Al Viro 提交于
      ... and simplify the living hell out of callers
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      a9049376
    • A
      Make ->d_sb assign-once and always non-NULL · a4464dbc
      Al Viro 提交于
      New helper (non-exported, fs/internal.h-only): __d_alloc(sb, name).
      Allocates dentry, sets its ->d_sb to given superblock and sets
      ->d_op accordingly.  Old d_alloc(NULL, name) callers are converted
      to that (all of them know what superblock they want).  d_alloc()
      itself is left only for parent != NULl case; uses __d_alloc(),
      inserts result into the list of parent's children.
      
      Note that now ->d_sb is assign-once and never NULL *and*
      ->d_parent is never NULL either.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      a4464dbc
    • J
      fs: add a DCACHE_NEED_LOOKUP flag for d_flags · 44396f4b
      Josef Bacik 提交于
      Btrfs (and I'd venture most other fs's) stores its indexes in nice disk order
      for readdir, but unfortunately in the case of anything that stats the files in
      order that readdir spits back (like oh say ls) that means we still have to do
      the normal lookup of the file, which means looking up our other index and then
      looking up the inode.  What I want is a way to create dummy dentries when we
      find them in readdir so that when ls or anything else subsequently does a
      stat(), we already have the location information in the dentry and can go
      straight to the inode itself.  The lookup stuff just assumes that if it finds a
      dentry it is done, it doesn't perform a lookup.  So add a DCACHE_NEED_LOOKUP
      flag so that the lookup code knows it still needs to run i_op->lookup() on the
      parent to get the inode for the dentry.  I have tested this with btrfs and I
      went from something that looks like this
      
      http://people.redhat.com/jwhiter/ls-noreada.png
      
      To this
      
      http://people.redhat.com/jwhiter/ls-good.png
      
      Thats a savings of 1300 seconds, or 22 minutes.  That is a significant savings.
      Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      44396f4b
  16. 15 7月, 2011 1 次提交
    • A
      fix loop checks in d_materialise_unique() · 18367501
      Al Viro 提交于
      Both __d_unalias() and __d_materialise_dentry() need loop prevention.
      Grab rename_lock in caller, check for loops there...
      
      As a side benefit, we have dentry_lock_for_move() called only under
      rename_lock, which seriously reduces deadlock potential of the
      execrable "locking order" used for ->d_lock.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      18367501
  17. 25 5月, 2011 1 次提交
  18. 21 5月, 2011 1 次提交
    • L
      sanitize <linux/prefetch.h> usage · 268bb0ce
      Linus Torvalds 提交于
      Commit e66eed65 ("list: remove prefetching from regular list
      iterators") removed the include of prefetch.h from list.h, which
      uncovered several cases that had apparently relied on that rather
      obscure header file dependency.
      
      So this fixes things up a bit, using
      
         grep -L linux/prefetch.h $(git grep -l '[^a-z_]prefetchw*(' -- '*.[ch]')
         grep -L 'prefetchw*(' $(git grep -l 'linux/prefetch.h' -- '*.[ch]')
      
      to guide us in finding files that either need <linux/prefetch.h>
      inclusion, or have it despite not needing it.
      
      There are more of them around (mostly network drivers), but this gets
      many core ones.
      Reported-by: NStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      268bb0ce
  19. 26 4月, 2011 1 次提交
  20. 24 4月, 2011 2 次提交
    • L
      vfs: get rid of insane dentry hashing rules · dea3667b
      Linus Torvalds 提交于
      The dentry hashing rules have been really quite complicated for a long
      while, in odd ways.  That made functions like __d_drop() very fragile
      and non-obvious.
      
      In particular, whether a dentry was hashed or not was indicated with an
      explicit DCACHE_UNHASHED bit.  That's despite the fact that the hash
      abstraction that the dentries use actually have a 'is this entry hashed
      or not' model (which is a simple test of the 'pprev' pointer).
      
      The reason that was done is because we used the normal 'is this entry
      unhashed' model to mark whether the dentry had _ever_ been hashed in the
      dentry hash tables, and that logic goes back many years (commit
      b3423415: "dcache: avoid RCU for never-hashed dentries").
      
      That, in turn, meant that __d_drop had totally different unhashing logic
      for the dentry hash table case and for the anonymous dcache case,
      because in order to use the "is this dentry hashed" logic as a flag for
      whether it had ever been on the RCU hash table, we had to unhash such a
      dentry differently so that we'd never think that it wasn't 'unhashed'
      and wouldn't be free'd correctly.
      
      That's just insane.  It made the logic really hard to follow, when there
      were two different kinds of "unhashed" states, and one of them (the one
      that used "list_bl_unhashed()") really had nothing at all to do with
      being unhashed per se, but with a very subtle lifetime rule instead.
      
      So turn all of it around, and make it logical.
      
      Instead of having a DENTRY_UNHASHED bit in d_flags to indicate whether
      the dentry is on the hash chains or not, use the hash chain unhashed
      logic for that.  Suddenly "d_unhashed()" just uses "list_bl_unhashed()",
      and everything makes sense.
      
      And for the lifetime rule, just use an explicit DENTRY_RCUACCEES bit.
      If we ever insert the dentry into the dentry hash table so that it is
      visible to RCU lookup, we mark it DENTRY_RCUACCESS to show that it now
      needs the RCU lifetime rules.  Now suddently that test at dentry free
      time makes sense too.
      
      And because unhashing now is sane and doesn't depend on where the dentry
      got unhashed from (because the dentry hash chain details doesn't have
      some subtle side effects), we can re-unify the __d_drop() logic and use
      common code for the unhashing.
      
      Also fix one more open-coded hash chain bit_spin_lock() that I missed in
      the previous chain locking cleanup commit.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      dea3667b
    • L
      vfs: get rid of 'struct dcache_hash_bucket' abstraction · b07ad996
      Linus Torvalds 提交于
      It's a useless abstraction for 'hlist_bl_head', and it doesn't actually
      help anything - quite the reverse.  All the users end up having to know
      about the hlist_bl_head details anyway, using 'struct hlist_bl_node *'
      etc. So it just makes the code look confusing.
      
      And the cost of it is extra '&b->head' syntactic noise, but more
      importantly it spuriously makes the hash table dentry list look
      different from the per-superblock DCACHE_DISCONNECTED dentry list.
      
      As a result, the code ended up using ad-hoc locking for one case and
      special helper functions for what is really another totally identical
      case in the very same function.
      
      Make it all look and work the same.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      b07ad996
  21. 15 4月, 2011 1 次提交
    • L
      vfs: fix incorrect dentry_update_name_case() BUG_ON() test · 7ebfa57f
      Linus Torvalds 提交于
      The case we should be verifying when updating the dentry name is that
      the _parent_ inode (the directory) semaphore is held, not the semaphore
      for the dentry itself.  It's the directory locking that rename and
      readdir() etc all care about.
      
      The comment just above even says so - but then the BUG_ON() still
      checked the dentry inode itself.
      
      Very few people noticed, because this helper function really isn't used
      for very much, so you had to be using ncpfs to ever hit it.
      
      I think I should just remove the BUG_ON (the function really has just
      one user), but let's run with it fixed for a while before getting rid of
      it entirely.
      Reported-and-tested-by: NBongani Hlope <bonganih@bankservafrica.com>
      Reported-and-tested-by: NBernd Feige <bernd.feige@uniklinik-freiburg.de>
      Cc: Petr Vandrovec <petr@vandrovec.name>,
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Nick Piggin <npiggin@kernel.dk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      7ebfa57f
  22. 18 3月, 2011 1 次提交
    • J
      fs: call security_d_instantiate in d_obtain_alias V2 · 24ff6663
      Josef Bacik 提交于
      While trying to track down some NFS problems with BTRFS, I kept noticing I was
      getting -EACCESS for no apparent reason.  Eric Paris and printk() helped me
      figure out that it was SELinux that was giving me grief, with the following
      denial
      
      type=AVC msg=audit(1290013638.413:95): avc:  denied  { 0x800000 } for  pid=1772
      comm="nfsd" name="" dev=sda1 ino=256 scontext=system_u:system_r:kernel_t:s0
      tcontext=system_u:object_r:unlabeled_t:s0 tclass=file
      
      Turns out this is because in d_obtain_alias if we can't find an alias we create
      one and do all the normal instantiation stuff, but we don't do the
      security_d_instantiate.
      
      Usually we are protected from getting a hashed dentry that hasn't yet run
      security_d_instantiate() by the parent's i_mutex, but obviously this isn't an
      option there, so in order to deal with the case that a second thread comes in
      and finds our new dentry before we get to run security_d_instantiate(), we go
      ahead and call it if we find a dentry already.  Eric assures me that this is ok
      as the code checks to see if the dentry has been initialized already so calling
      security_d_instantiate() against the same dentry multiple times is ok.  With
      this patch I'm no longer getting errant -EACCESS values.
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      24ff6663
  23. 16 3月, 2011 2 次提交
    • T
      VFS: Fix the nfs sillyrename regression in kernel 2.6.38 · c83ce989
      Trond Myklebust 提交于
      The new vfs locking scheme introduced in 2.6.38 breaks NFS sillyrename
      because the latter relies on being able to determine the parent
      directory of the dentry in the ->iput() callback in order to send the
      appropriate unlink rpc call.
      
      Looking at the code that cares about races with dput(), there doesn't
      seem to be anything that specifically uses d_parent as a test for
      whether or not there is a race:
        - __d_lookup_rcu(), __d_lookup() all test for d_hashed() after d_parent
        - shrink_dcache_for_umount() is safe since nothing else can rearrange
          the dentries in that super block.
        - have_submount(), select_parent() and d_genocide() can test for a
          deletion if we set the DCACHE_DISCONNECTED flag when the dentry
          is removed from the parent's d_subdirs list.
      Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
      Cc: stable@kernel.org (2.6.38, needs commit c826cb7d "dcache.c:
      	create helper function for duplicated functionality" )
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c83ce989
    • L
      dcache.c: create helper function for duplicated functionality · c826cb7d
      Linus Torvalds 提交于
      This creates a helper function for he "try to ascend into the parent
      directory" case, which was written out in triplicate before.  With all
      the locking and subtle sequence number stuff, we really don't want to
      duplicate that kind of code.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c826cb7d
  24. 10 3月, 2011 1 次提交
    • J
      fs/dcache: allow d_obtain_alias() to return unhashed dentries · d891eedb
      J. Bruce Fields 提交于
      Without this patch, inodes are not promptly freed on last close of an
      unlinked file by an nfs client:
      
      	client$ mount -tnfs4 server:/export/ /mnt/
      	client$ tail -f /mnt/FOO
      	...
      	server$ df -i /export
      	server$ rm /export/FOO
      	(^C the tail -f)
      	server$ df -i /export
      	server$ echo 2 >/proc/sys/vm/drop_caches
      	server$ df -i /export
      
      the df's will show that the inode is not freed on the filesystem until
      the last step, when it could have been freed after killing the client's
      tail -f. On-disk data won't be deallocated either, leading to possible
      spurious ENOSPC.
      
      This occurs because when the client does the close, it arrives in a
      compound with a putfh and a close, processed like:
      
      	- putfh: look up the filehandle.  The only alias found for the
      	  inode will be DCACHE_UNHASHED alias referenced by the filp
      	  this, so it creates a new DCACHE_DISCONECTED dentry and
      	  returns that instead.
      	- close: closes the existing filp, which is destroyed
      	  immediately by dput() since it's DCACHE_UNHASHED.
      	- end of the compound: release the reference
      	  to the current filehandle, and dput() the new
      	  DCACHE_DISCONECTED dentry, which gets put on the
      	  unused list instead of being destroyed immediately.
      
      Nick Piggin suggested fixing this by allowing d_obtain_alias to return
      the unhashed dentry that is referenced by the filp, instead of making it
      create a new dentry.
      
      Leave __d_find_alias() alone to avoid changing behavior of other
      callers.
      
      Also nfsd doesn't need all the checks of __d_find_alias(); any dentry,
      hashed or unhashed, disconnected or not, should work.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      d891eedb
  25. 17 2月, 2011 1 次提交