Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 3 Mar 2013 21:23:02 +0000 (13:23 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 3 Mar 2013 21:23:03 +0000 (13:23 -0800)
Pull  more VFS bits from Al Viro:
 "Unfortunately, it looks like xattr series will have to wait until the
  next cycle ;-/

  This pile contains 9p cleanups and fixes (races in v9fs_fid_add()
  etc), fixup for nommu breakage in shmem.c, several cleanups and a bit
  more file_inode() work"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  constify path_get/path_put and fs_struct.c stuff
  fix nommu breakage in shmem.c
  cache the value of file_inode() in struct file
  9p: if v9fs_fid_lookup() gets to asking server, it'd better have hashed dentry
  9p: make sure ->lookup() adds fid to the right dentry
  9p: untangle ->lookup() a bit
  9p: double iput() in ->lookup() if d_materialise_unique() fails
  9p: v9fs_fid_add() can't fail now
  v9fs: get rid of v9fs_dentry
  9p: turn fid->dlist into hlist
  9p: don't bother with private lock in ->d_fsdata; dentry->d_lock will do just fine
  more file_inode() open-coded instances
  selinux: opened file can't have NULL or negative ->f_path.dentry

(In the meantime, the hlist traversal macros have changed, so this
required a semantic conflict fixup for the newly hlistified fid->dlist)

1  2 
fs/9p/fid.c
fs/open.c
fs/seq_file.c

diff --combined fs/9p/fid.c
   *
   */
  
int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
static inline void __add_fid(struct dentry *dentry, struct p9_fid *fid)
  {
-       struct v9fs_dentry *dent;
-       p9_debug(P9_DEBUG_VFS, "fid %d dentry %s\n",
-                fid->fid, dentry->d_name.name);
-       dent = dentry->d_fsdata;
-       if (!dent) {
-               dent = kmalloc(sizeof(struct v9fs_dentry), GFP_KERNEL);
-               if (!dent)
-                       return -ENOMEM;
-               spin_lock_init(&dent->lock);
-               INIT_LIST_HEAD(&dent->fidlist);
-               dentry->d_fsdata = dent;
-       }
-       spin_lock(&dent->lock);
-       list_add(&fid->dlist, &dent->fidlist);
-       spin_unlock(&dent->lock);
+       hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata);
+ }
  
-       return 0;
+ void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
+ {
+       spin_lock(&dentry->d_lock);
+       __add_fid(dentry, fid);
+       spin_unlock(&dentry->d_lock);
  }
  
  /**
  
  static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any)
  {
-       struct v9fs_dentry *dent;
        struct p9_fid *fid, *ret;
  
        p9_debug(P9_DEBUG_VFS, " dentry: %s (%p) uid %d any %d\n",
                 dentry->d_name.name, dentry, from_kuid(&init_user_ns, uid),
                 any);
-       dent = (struct v9fs_dentry *) dentry->d_fsdata;
        ret = NULL;
-       if (dent) {
-               spin_lock(&dent->lock);
-               list_for_each_entry(fid, &dent->fidlist, dlist) {
+       /* we'll recheck under lock if there's anything to look in */
+       if (dentry->d_fsdata) {
+               struct hlist_head *h = (struct hlist_head *)&dentry->d_fsdata;
 -              struct hlist_node *n;
+               spin_lock(&dentry->d_lock);
 -              hlist_for_each_entry(fid, n, h, dlist) {
++              hlist_for_each_entry(fid, h, dlist) {
                        if (any || uid_eq(fid->uid, uid)) {
                                ret = fid;
                                break;
                        }
                }
-               spin_unlock(&dent->lock);
+               spin_unlock(&dentry->d_lock);
        }
  
        return ret;
@@@ -215,8 -203,17 +202,17 @@@ static struct p9_fid *v9fs_fid_lookup_w
        }
        kfree(wnames);
  fid_out:
-       if (!IS_ERR(fid))
-               v9fs_fid_add(dentry, fid);
+       if (!IS_ERR(fid)) {
+               spin_lock(&dentry->d_lock);
+               if (d_unhashed(dentry)) {
+                       spin_unlock(&dentry->d_lock);
+                       p9_client_clunk(fid);
+                       fid = ERR_PTR(-ENOENT);
+               } else {
+                       __add_fid(dentry, fid);
+                       spin_unlock(&dentry->d_lock);
+               }
+       }
  err_out:
        up_read(&v9ses->rename_sem);
        return fid;
diff --combined fs/open.c
+++ b/fs/open.c
@@@ -30,7 -30,6 +30,7 @@@
  #include <linux/fs_struct.h>
  #include <linux/ima.h>
  #include <linux/dnotify.h>
 +#include <linux/compat.h>
  
  #include "internal.h"
  
@@@ -141,13 -140,6 +141,13 @@@ SYSCALL_DEFINE2(truncate, const char __
        return do_sys_truncate(path, length);
  }
  
 +#ifdef CONFIG_COMPAT
 +COMPAT_SYSCALL_DEFINE2(truncate, const char __user *, path, compat_off_t, length)
 +{
 +      return do_sys_truncate(path, length);
 +}
 +#endif
 +
  static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
  {
        struct inode *inode;
@@@ -203,13 -195,6 +203,13 @@@ SYSCALL_DEFINE2(ftruncate, unsigned int
        return ret;
  }
  
 +#ifdef CONFIG_COMPAT
 +COMPAT_SYSCALL_DEFINE2(ftruncate, unsigned int, fd, compat_ulong_t, length)
 +{
 +      return do_sys_ftruncate(fd, length, 1);
 +}
 +#endif
 +
  /* LFS versions of truncate are only needed on 32 bit machines */
  #if BITS_PER_LONG == 32
  SYSCALL_DEFINE(truncate64)(const char __user * path, loff_t length)
@@@ -704,7 -689,7 +704,7 @@@ static int do_dentry_open(struct file *
                f->f_mode = FMODE_PATH;
  
        path_get(&f->f_path);
-       inode = file_inode(f);
+       inode = f->f_inode = f->f_path.dentry->d_inode;
        if (f->f_mode & FMODE_WRITE) {
                error = __get_file_write_access(inode, f->f_path.mnt);
                if (error)
@@@ -767,6 -752,7 +767,7 @@@ cleanup_file
        path_put(&f->f_path);
        f->f_path.mnt = NULL;
        f->f_path.dentry = NULL;
+       f->f_inode = NULL;
        return error;
  }
  
diff --combined fs/seq_file.c
@@@ -308,27 -308,27 +308,27 @@@ loff_t seq_lseek(struct file *file, lof
        mutex_lock(&m->lock);
        m->version = file->f_version;
        switch (whence) {
 -              case 1:
 -                      offset += file->f_pos;
 -              case 0:
 -                      if (offset < 0)
 -                              break;
 -                      retval = offset;
 -                      if (offset != m->read_pos) {
 -                              while ((retval=traverse(m, offset)) == -EAGAIN)
 -                                      ;
 -                              if (retval) {
 -                                      /* with extreme prejudice... */
 -                                      file->f_pos = 0;
 -                                      m->read_pos = 0;
 -                                      m->version = 0;
 -                                      m->index = 0;
 -                                      m->count = 0;
 -                              } else {
 -                                      m->read_pos = offset;
 -                                      retval = file->f_pos = offset;
 -                              }
 +      case SEEK_CUR:
 +              offset += file->f_pos;
 +      case SEEK_SET:
 +              if (offset < 0)
 +                      break;
 +              retval = offset;
 +              if (offset != m->read_pos) {
 +                      while ((retval = traverse(m, offset)) == -EAGAIN)
 +                              ;
 +                      if (retval) {
 +                              /* with extreme prejudice... */
 +                              file->f_pos = 0;
 +                              m->read_pos = 0;
 +                              m->version = 0;
 +                              m->index = 0;
 +                              m->count = 0;
 +                      } else {
 +                              m->read_pos = offset;
 +                              retval = file->f_pos = offset;
                        }
 +              }
        }
        file->f_version = m->version;
        mutex_unlock(&m->lock);
@@@ -339,7 -339,7 +339,7 @@@ EXPORT_SYMBOL(seq_lseek)
  /**
   *    seq_release -   free the structures associated with sequential file.
   *    @file: file in question
-  *    @inode: file->f_path.dentry->d_inode
+  *    @inode: its inode
   *
   *    Frees the structures associated with sequential file; can be used
   *    as ->f_op->release() if you don't have private data to destroy.