1. 04 Aug, 2022 6 commits
    • NeilBrown's avatar
      NFSD: use explicit lock/unlock for directory ops · debf16f0
      NeilBrown authored
      When creating or unlinking a name in a directory use explicit
      inode_lock_nested() instead of fh_lock(), and explicit calls to
      fh_fill_pre_attrs() and fh_fill_post_attrs().  This is already done
      for renames, with lock_rename() as the explicit locking.
      
      Also move the 'fill' calls closer to the operation that might change the
      attributes.  This way they are avoided on some error paths.
      
      For the v2-only code in nfsproc.c, the fill calls are not replaced as
      they aren't needed.
      
      Making the locking explicit will simplify proposed future changes to
      locking for directories.  It also makes it easily visible exactly where
      pre/post attributes are used - not all callers of fh_lock() actually
      need the pre/post attributes.
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      debf16f0
    • NeilBrown's avatar
      NFSD: reduce locking in nfsd_lookup() · 19d008b4
      NeilBrown authored
      nfsd_lookup() takes an exclusive lock on the parent inode, but no
      callers want the lock and it may not be needed at all if the
      result is in the dcache.
      
      Change nfsd_lookup_dentry() to not take the lock, and call
      lookup_one_len_locked() which takes lock only if needed.
      
      nfsd4_open() currently expects the lock to still be held, but that isn't
      necessary as nfsd_validate_delegated_dentry() provides required
      guarantees without the lock.
      
      NOTE: NFSv4 requires directory changeinfo for OPEN even when a create
        wasn't requested and no change happened.  Now that nfsd_lookup()
        doesn't use fh_lock(), we need to explicitly fill the attributes
        when no create happens.  A new fh_fill_both_attrs() is provided
        for that task.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      19d008b4
    • NeilBrown's avatar
      NFSD: only call fh_unlock() once in nfsd_link() · e18bcb33
      NeilBrown authored
      On non-error paths, nfsd_link() calls fh_unlock() twice.  This is safe
      because fh_unlock() records that the unlock has been done and doesn't
      repeat it.
      However it makes the code a little confusing and interferes with changes
      that are planned for directory locking.
      
      So rearrange the code to ensure fh_unlock() is called exactly once if
      fh_lock() was called.
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      e18bcb33
    • NeilBrown's avatar
      NFSD: always drop directory lock in nfsd_unlink() · b677c0c6
      NeilBrown authored
      Some error paths in nfsd_unlink() allow it to exit without unlocking the
      directory.  This is not a problem in practice as the directory will be
      locked with an fh_put(), but it is untidy and potentially confusing.
      
      This allows us to remove all the fh_unlock() calls that are immediately
      after nfsd_unlink() calls.
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      b677c0c6
    • NeilBrown's avatar
      NFSD: change nfsd_create()/nfsd_symlink() to unlock directory before returning. · 927bfc56
      NeilBrown authored
      nfsd_create() usually returns with the directory still locked.
      nfsd_symlink() usually returns with it unlocked.  This is clumsy.
      
      Until recently nfsd_create() needed to keep the directory locked until
      ACLs and security label had been set.  These are now set inside
      nfsd_create() (in nfsd_setattr()) so this need is gone.
      
      So change nfsd_create() and nfsd_symlink() to always unlock, and remove
      any fh_unlock() calls that follow calls to these functions.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      927bfc56
    • NeilBrown's avatar
      NFSD: add posix ACLs to struct nfsd_attrs · c0cbe707
      NeilBrown authored
      pacl and dpacl pointers are added to struct nfsd_attrs, which requires
      that we have an nfsd_attrs_free() function to free them.
      Those nfsv4 functions that can set ACLs now set up these pointers
      based on the passed in NFSv4 ACL.
      
      nfsd_setattr() sets the acls as appropriate.
      
      Errors are handled as with security labels.
      Signed-off-by: default avatarNeilBrown <neilb@suse.de>
      Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
      c0cbe707
  2. 30 Jul, 2022 34 commits