Merge to kernel-2.6.20-1.2949.fc6.vs2.2.0.1
[linux-2.6.git] / fs / xfs / linux-2.6 / xfs_export.c
index 772d216..5fb75d9 100644 (file)
@@ -1,40 +1,44 @@
 /*
- * Copyright (c) 2004-2005 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2004-2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation.
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
-
 #include "xfs.h"
+#include "xfs_types.h"
+#include "xfs_dmapi.h"
+#include "xfs_log.h"
+#include "xfs_trans.h"
+#include "xfs_sb.h"
+#include "xfs_mount.h"
+#include "xfs_export.h"
+
+STATIC struct dentry dotdot = { .d_name.name = "..", .d_name.len = 2, };
 
+/*
+ * XFS encodes and decodes the fileid portion of NFS filehandles
+ * itself instead of letting the generic NFS code do it.  This
+ * allows filesystems with 64 bit inode numbers to be exported.
+ *
+ * Note that a side effect is that xfs_vget() won't be passed a
+ * zero inode/generation pair under normal circumstances.  As
+ * however a malicious client could send us such data, the check
+ * remains in that code.
+ */
 
 STATIC struct dentry *
-linvfs_decode_fh(
+xfs_fs_decode_fh(
        struct super_block      *sb,
        __u32                   *fh,
        int                     fh_len,
@@ -44,50 +48,104 @@ linvfs_decode_fh(
                struct dentry   *de),
        void                    *context)
 {
-       __u32 parent[2];
-       parent[0] = parent[1] = 0;
-       
-       if (fh_len < 2 || fileid_type > 2)
+       xfs_fid2_t              ifid;
+       xfs_fid2_t              pfid;
+       void                    *parent = NULL;
+       int                     is64 = 0;
+       __u32                   *p = fh;
+
+#if XFS_BIG_INUMS
+       is64 = (fileid_type & XFS_FILEID_TYPE_64FLAG);
+       fileid_type &= ~XFS_FILEID_TYPE_64FLAG;
+#endif
+
+       /*
+        * Note that we only accept fileids which are long enough
+        * rather than allow the parent generation number to default
+        * to zero.  XFS considers zero a valid generation number not
+        * an invalid/wildcard value.  There's little point printk'ing
+        * a warning here as we don't have the client information
+        * which would make such a warning useful.
+        */
+       if (fileid_type > 2 ||
+           fh_len < xfs_fileid_length((fileid_type == 2), is64))
                return NULL;
-       
-       if (fileid_type == 2 && fh_len > 2) {
-               if (fh_len == 3) {
-                       printk(KERN_WARNING
-                              "XFS: detected filehandle without "
-                              "parent inode generation information.");
-                       return ERR_PTR(-ESTALE);
-               }
-                       
-               parent[0] = fh[2];
-               parent[1] = fh[3];
+
+       p = xfs_fileid_decode_fid2(p, &ifid, is64);
+
+       if (fileid_type == 2) {
+               p = xfs_fileid_decode_fid2(p, &pfid, is64);
+               parent = &pfid;
        }
-       
-       return find_exported_dentry(sb, fh, parent, acceptable, context);
 
+       fh = (__u32 *)&ifid;
+       return sb->s_export_op->find_exported_dentry(sb, fh, parent, acceptable, context);
+}
+
+
+STATIC int
+xfs_fs_encode_fh(
+       struct dentry           *dentry,
+       __u32                   *fh,
+       int                     *max_len,
+       int                     connectable)
+{
+       struct inode            *inode = dentry->d_inode;
+       int                     type = 1;
+       __u32                   *p = fh;
+       int                     len;
+       int                     is64 = 0;
+#if XFS_BIG_INUMS
+       bhv_vfs_t               *vfs = vfs_from_sb(inode->i_sb);
+
+       if (!(vfs->vfs_flag & VFS_32BITINODES)) {
+               /* filesystem may contain 64bit inode numbers */
+               is64 = XFS_FILEID_TYPE_64FLAG;
+       }
+#endif
+
+       /* Directories don't need their parent encoded, they have ".." */
+       if (S_ISDIR(inode->i_mode))
+           connectable = 0;
+
+       /*
+        * Only encode if there is enough space given.  In practice
+        * this means we can't export a filesystem with 64bit inodes
+        * over NFSv2 with the subtree_check export option; the other
+        * seven combinations work.  The real answer is "don't use v2".
+        */
+       len = xfs_fileid_length(connectable, is64);
+       if (*max_len < len)
+               return 255;
+       *max_len = len;
+
+       p = xfs_fileid_encode_inode(p, inode, is64);
+       if (connectable) {
+               spin_lock(&dentry->d_lock);
+               p = xfs_fileid_encode_inode(p, dentry->d_parent->d_inode, is64);
+               spin_unlock(&dentry->d_lock);
+               type = 2;
+       }
+       BUG_ON((p - fh) != len);
+       return type | is64;
 }
 
 STATIC struct dentry *
-linvfs_get_dentry(
+xfs_fs_get_dentry(
        struct super_block      *sb,
        void                    *data)
 {
-       vnode_t                 *vp;
+       bhv_vnode_t             *vp;
        struct inode            *inode;
        struct dentry           *result;
-       xfs_fid2_t              xfid;
-       vfs_t                   *vfsp = LINVFS_GET_VFS(sb);
+       bhv_vfs_t               *vfsp = vfs_from_sb(sb);
        int                     error;
 
-       xfid.fid_len = sizeof(xfs_fid2_t) - sizeof(xfid.fid_len);
-       xfid.fid_pad = 0;
-       xfid.fid_gen = ((__u32 *)data)[1];
-       xfid.fid_ino = ((__u32 *)data)[0];
-
-       VFS_VGET(vfsp, &vp, (fid_t *)&xfid, error);
+       error = bhv_vfs_vget(vfsp, &vp, (fid_t *)data);
        if (error || vp == NULL)
                return ERR_PTR(-ESTALE) ;
 
-       inode = LINVFS_GET_IP(vp);
+       inode = vn_to_inode(vp);
        result = d_alloc_anon(inode);
         if (!result) {
                iput(inode);
@@ -97,25 +155,20 @@ linvfs_get_dentry(
 }
 
 STATIC struct dentry *
-linvfs_get_parent(
+xfs_fs_get_parent(
        struct dentry           *child)
 {
        int                     error;
-       vnode_t                 *vp, *cvp;
+       bhv_vnode_t             *vp, *cvp;
        struct dentry           *parent;
-       struct dentry           dotdot;
-
-       dotdot.d_name.name = "..";
-       dotdot.d_name.len = 2;
-       dotdot.d_inode = NULL;
 
        cvp = NULL;
-       vp = LINVFS_GET_VP(child->d_inode);
-       VOP_LOOKUP(vp, &dotdot, &cvp, 0, NULL, NULL, error);
+       vp = vn_from_inode(child->d_inode);
+       error = bhv_vop_lookup(vp, &dotdot, &cvp, 0, NULL, NULL);
        if (unlikely(error))
                return ERR_PTR(-error);
 
-       parent = d_alloc_anon(LINVFS_GET_IP(cvp));
+       parent = d_alloc_anon(vn_to_inode(cvp));
        if (unlikely(!parent)) {
                VN_RELE(cvp);
                return ERR_PTR(-ENOMEM);
@@ -123,8 +176,9 @@ linvfs_get_parent(
        return parent;
 }
 
-struct export_operations linvfs_export_ops = {
-       .decode_fh              = linvfs_decode_fh,
-       .get_parent             = linvfs_get_parent,
-       .get_dentry             = linvfs_get_dentry,
+struct export_operations xfs_export_operations = {
+       .decode_fh              = xfs_fs_decode_fh,
+       .encode_fh              = xfs_fs_encode_fh,
+       .get_parent             = xfs_fs_get_parent,
+       .get_dentry             = xfs_fs_get_dentry,
 };