]> git.proxmox.com Git - mirror_spl-debian.git/blobdiff - module/spl/spl-vnode.c
Imported Upstream version 0.6.2
[mirror_spl-debian.git] / module / spl / spl-vnode.c
index 0ecd9addfa06f3d184c0cf60a794be07fdd28289..0784ff2611096304b532901b01b2559c4ae1453b 100644 (file)
@@ -6,7 +6,7 @@
  *  UCRL-CODE-235197
  *
  *  This file is part of the SPL, Solaris Porting Layer.
- *  For details, see <http://github.com/behlendorf/spl/>.
+ *  For details, see <http://zfsonlinux.org/>.
  *
  *  The SPL is free software; you can redistribute it and/or modify it
  *  under the terms of the GNU General Public License as published by the
@@ -24,6 +24,7 @@
  *  Solaris Porting Layer (SPL) Vnode Implementation.
 \*****************************************************************************/
 
+#include <sys/cred.h>
 #include <sys/vnode.h>
 #include <linux/falloc.h>
 #include <spl-debug.h>
@@ -175,7 +176,11 @@ vn_open(const char *path, uio_seg_t seg, int flags, int mode,
        if (IS_ERR(fp))
                SRETURN(-PTR_ERR(fp));
 
-       rc = vfs_getattr(fp->f_vfsmnt, fp->f_dentry, &stat);
+#ifdef HAVE_2ARGS_VFS_GETATTR
+       rc = vfs_getattr(&fp->f_path, &stat);
+#else
+       rc = vfs_getattr(fp->f_path.mnt, fp->f_dentry, &stat);
+#endif
        if (rc) {
                filp_close(fp, 0);
                SRETURN(-rc);
@@ -602,14 +607,18 @@ vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4)
 
        fp = vp->v_file;
 
-        rc = vfs_getattr(fp->f_vfsmnt, fp->f_dentry, &stat);
+#ifdef HAVE_2ARGS_VFS_GETATTR
+       rc = vfs_getattr(&fp->f_path, &stat);
+#else
+       rc = vfs_getattr(fp->f_path.mnt, fp->f_dentry, &stat);
+#endif
        if (rc)
                SRETURN(-rc);
 
        vap->va_type          = vn_mode_to_vtype(stat.mode);
        vap->va_mode          = stat.mode;
-       vap->va_uid           = stat.uid;
-       vap->va_gid           = stat.gid;
+       vap->va_uid           = KUID_TO_SUID(stat.uid);
+       vap->va_gid           = KGID_TO_SGID(stat.gid);
        vap->va_fsid          = 0;
        vap->va_nodeid        = stat.ino;
        vap->va_nlink         = stat.nlink;
@@ -654,13 +663,15 @@ int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag,
        ASSERT(bfp->l_start >= 0 && bfp->l_len > 0);
 
 #ifdef FALLOC_FL_PUNCH_HOLE
-       if (vp->v_file->f_op->fallocate) {
-               error = -vp->v_file->f_op->fallocate(vp->v_file,
-                   FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
-                   bfp->l_start, bfp->l_len);
-               if (!error)
-                       SRETURN(0);
-       }
+       /*
+        * When supported by the underlying file system preferentially
+        * use the fallocate() callback to preallocate the space.
+        */
+       error = -spl_filp_fallocate(vp->v_file,
+           FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
+           bfp->l_start, bfp->l_len);
+       if (error == 0)
+               SRETURN(0);
 #endif
 
 #ifdef HAVE_INODE_TRUNCATE_RANGE
@@ -752,7 +763,12 @@ vn_getf(int fd)
        if (vp == NULL)
                SGOTO(out_fget, rc);
 
-        if (vfs_getattr(lfp->f_vfsmnt, lfp->f_dentry, &stat))
+#ifdef HAVE_2ARGS_VFS_GETATTR
+       rc = vfs_getattr(&lfp->f_path, &stat);
+#else
+       rc = vfs_getattr(lfp->f_path.mnt, lfp->f_dentry, &stat);
+#endif
+        if (rc)
                SGOTO(out_vnode, rc);
 
        mutex_enter(&vp->v_lock);
@@ -822,10 +838,12 @@ vn_releasef(int fd)
 EXPORT_SYMBOL(releasef);
 
 #ifndef HAVE_SET_FS_PWD
-# ifdef HAVE_2ARGS_SET_FS_PWD
-/* Used from 2.6.25 - 2.6.31+ */
 void
+#  ifdef HAVE_SET_FS_PWD_WITH_CONST
+set_fs_pwd(struct fs_struct *fs, const struct path *path)
+#  else
 set_fs_pwd(struct fs_struct *fs, struct path *path)
+#  endif
 {
        struct path old_pwd;
 
@@ -846,37 +864,16 @@ set_fs_pwd(struct fs_struct *fs, struct path *path)
        if (old_pwd.dentry)
                path_put(&old_pwd);
 }
-# else
-/* Used from 2.6.11 - 2.6.24 */
-void
-set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt, struct dentry *dentry)
-{
-        struct dentry *old_pwd;
-        struct vfsmount *old_pwdmnt;
-
-        write_lock(&fs->lock);
-        old_pwd = fs->pwd;
-        old_pwdmnt = fs->pwdmnt;
-        fs->pwdmnt = mntget(mnt);
-        fs->pwd = dget(dentry);
-        write_unlock(&fs->lock);
-
-        if (old_pwd) {
-                dput(old_pwd);
-                mntput(old_pwdmnt);
-        }
-}
-# endif /* HAVE_2ARGS_SET_FS_PWD */
 #endif /* HAVE_SET_FS_PWD */
 
 int
 vn_set_pwd(const char *filename)
 {
-#if defined(HAVE_2ARGS_SET_FS_PWD) && defined(HAVE_USER_PATH_DIR)
+#ifdef HAVE_USER_PATH_DIR
         struct path path;
 #else
         struct nameidata nd;
-#endif /* HAVE_2ARGS_SET_FS_PWD */
+#endif /* HAVE_USER_PATH_DIR */
         mm_segment_t saved_fs;
         int rc;
         SENTRY;
@@ -889,7 +886,6 @@ vn_set_pwd(const char *filename)
         saved_fs = get_fs();
         set_fs(get_ds());
 
-#ifdef HAVE_2ARGS_SET_FS_PWD
 # ifdef HAVE_USER_PATH_DIR
         rc = user_path_dir(filename, &path);
         if (rc)
@@ -918,21 +914,6 @@ dput_and_out:
 dput_and_out:
         path_put(&nd.path);
 # endif /* HAVE_USER_PATH_DIR */
-#else
-        rc = __user_walk(filename,
-                         LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_CHDIR, &nd);
-        if (rc)
-                SGOTO(out, rc);
-
-        rc = vfs_permission(&nd, MAY_EXEC);
-        if (rc)
-                SGOTO(dput_and_out, rc);
-
-        set_fs_pwd(current->fs, nd.nd_mnt, nd.nd_dentry);
-
-dput_and_out:
-        vn_path_release(&nd);
-#endif /* HAVE_2ARGS_SET_FS_PWD */
 out:
        set_fs(saved_fs);