This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / fs / xfs / linux-2.6 / xfs_file.c
index 7321db1..ced4404 100644 (file)
@@ -1,39 +1,26 @@
 /*
- * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-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_inum.h"
+#include "xfs_bit.h"
 #include "xfs_log.h"
+#include "xfs_inum.h"
 #include "xfs_sb.h"
+#include "xfs_ag.h"
 #include "xfs_dir.h"
 #include "xfs_dir2.h"
 #include "xfs_trans.h"
@@ -57,7 +44,9 @@
 #include <linux/smp_lock.h>
 
 static struct vm_operations_struct linvfs_file_vm_ops;
-
+#ifdef CONFIG_XFS_DMAPI
+static struct vm_operations_struct linvfs_dmapi_file_vm_ops;
+#endif
 
 STATIC inline ssize_t
 __linvfs_read(
@@ -309,6 +298,31 @@ linvfs_fsync(
 
 #define nextdp(dp)      ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
 
+#ifdef CONFIG_XFS_DMAPI
+
+STATIC struct page *
+linvfs_filemap_nopage(
+       struct vm_area_struct   *area,
+       unsigned long           address,
+       int                     *type)
+{
+       struct inode    *inode = area->vm_file->f_dentry->d_inode;
+       vnode_t         *vp = LINVFS_GET_VP(inode);
+       xfs_mount_t     *mp = XFS_VFSTOM(vp->v_vfsp);
+       int             error;
+
+       ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
+
+       error = XFS_SEND_MMAP(mp, area, 0);
+       if (error)
+               return NULL;
+
+       return filemap_nopage(area, address, type);
+}
+
+#endif /* CONFIG_XFS_DMAPI */
+
+
 STATIC int
 linvfs_readdir(
        struct file     *filp,
@@ -399,15 +413,13 @@ linvfs_file_mmap(
        vattr_t         va = { .va_mask = XFS_AT_UPDATIME };
        int             error;
 
-       if (vp->v_vfsp->vfs_flag & VFS_DMI) {
-               xfs_mount_t     *mp = XFS_VFSTOM(vp->v_vfsp);
+       vma->vm_ops = &linvfs_file_vm_ops;
 
-               error = -XFS_SEND_MMAP(mp, vma, 0);
-               if (error)
-                       return error;
+#ifdef CONFIG_XFS_DMAPI
+       if (vp->v_vfsp->vfs_flag & VFS_DMI) {
+               vma->vm_ops = &linvfs_dmapi_file_vm_ops;
        }
-
-       vma->vm_ops = &linvfs_file_vm_ops;
+#endif /* CONFIG_XFS_DMAPI */
 
        VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error);
        if (!error)
@@ -461,6 +473,7 @@ linvfs_ioctl_invis(
        return error;
 }
 
+#ifdef CONFIG_XFS_DMAPI
 #ifdef HAVE_VMOP_MPROTECT
 STATIC int
 linvfs_mprotect(
@@ -481,7 +494,38 @@ linvfs_mprotect(
        return error;
 }
 #endif /* HAVE_VMOP_MPROTECT */
+#endif /* CONFIG_XFS_DMAPI */
 
+#ifdef HAVE_FOP_OPEN_EXEC
+/* If the user is attempting to execute a file that is offline then
+ * we have to trigger a DMAPI READ event before the file is marked as busy
+ * otherwise the invisible I/O will not be able to write to the file to bring
+ * it back online.
+ */
+STATIC int
+linvfs_open_exec(
+       struct inode    *inode)
+{
+       vnode_t         *vp = LINVFS_GET_VP(inode);
+       xfs_mount_t     *mp = XFS_VFSTOM(vp->v_vfsp);
+       int             error = 0;
+       xfs_inode_t     *ip;
+
+       if (vp->v_vfsp->vfs_flag & VFS_DMI) {
+               ip = xfs_vtoi(vp);
+               if (!ip) {
+                       error = -EINVAL;
+                       goto open_exec_out;
+               }
+               if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)) {
+                       error = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp,
+                                              0, 0, 0, NULL);
+               }
+       }
+open_exec_out:
+       return error;
+}
+#endif /* HAVE_FOP_OPEN_EXEC */
 
 struct file_operations linvfs_file_operations = {
        .llseek         = generic_file_llseek,
@@ -494,12 +538,15 @@ struct file_operations linvfs_file_operations = {
        .sendfile       = linvfs_sendfile,
        .unlocked_ioctl = linvfs_ioctl,
 #ifdef CONFIG_COMPAT
-       .compat_ioctl   = xfs_compat_ioctl,
+       .compat_ioctl   = linvfs_compat_ioctl,
 #endif
        .mmap           = linvfs_file_mmap,
        .open           = linvfs_open,
        .release        = linvfs_release,
        .fsync          = linvfs_fsync,
+#ifdef HAVE_FOP_OPEN_EXEC
+       .open_exec      = linvfs_open_exec,
+#endif
 };
 
 struct file_operations linvfs_invis_file_operations = {
@@ -513,7 +560,7 @@ struct file_operations linvfs_invis_file_operations = {
        .sendfile       = linvfs_sendfile,
        .unlocked_ioctl = linvfs_ioctl_invis,
 #ifdef CONFIG_COMPAT
-       .compat_ioctl   = xfs_compat_invis_ioctl,
+       .compat_ioctl   = linvfs_compat_invis_ioctl,
 #endif
        .mmap           = linvfs_file_mmap,
        .open           = linvfs_open,
@@ -526,13 +573,23 @@ struct file_operations linvfs_dir_operations = {
        .read           = generic_read_dir,
        .readdir        = linvfs_readdir,
        .unlocked_ioctl = linvfs_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = linvfs_compat_ioctl,
+#endif
        .fsync          = linvfs_fsync,
 };
 
 static struct vm_operations_struct linvfs_file_vm_ops = {
        .nopage         = filemap_nopage,
        .populate       = filemap_populate,
+};
+
+#ifdef CONFIG_XFS_DMAPI
+static struct vm_operations_struct linvfs_dmapi_file_vm_ops = {
+       .nopage         = linvfs_filemap_nopage,
+       .populate       = filemap_populate,
 #ifdef HAVE_VMOP_MPROTECT
        .mprotect       = linvfs_mprotect,
 #endif
 };
+#endif /* CONFIG_XFS_DMAPI */