[PATCH] replace inode_update_time with file_update_time
[linux-2.6.git] / fs / xfs / linux-2.6 / xfs_lrw.c
index ff145fd..885dfaf 100644 (file)
@@ -1,44 +1,25 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2003,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
  */
-/*
- *  fs/xfs/linux/xfs_lrw.c (Linux Read Write stuff)
- *
- */
-
 #include "xfs.h"
-
 #include "xfs_fs.h"
-#include "xfs_inum.h"
+#include "xfs_bit.h"
 #include "xfs_log.h"
+#include "xfs_inum.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
-#include "xfs_alloc_btree.h"
 #include "xfs_bmap_btree.h"
+#include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
+#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_bmap.h"
-#include "xfs_bit.h"
+#include "xfs_btree.h"
+#include "xfs_ialloc.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_itable.h"
@@ -209,30 +189,6 @@ unlock:
        return (-status);
 }
 
-/*
- * xfs_inval_cached_pages
- * 
- * This routine is responsible for keeping direct I/O and buffered I/O
- * somewhat coherent.  From here we make sure that we're at least
- * temporarily holding the inode I/O lock exclusively and then call
- * the page cache to flush and invalidate any cached pages.  If there
- * are no cached pages this routine will be very quick.
- */
-void
-xfs_inval_cached_pages(
-       vnode_t         *vp,
-       xfs_iocore_t    *io,
-       xfs_off_t       offset,
-       int             write,
-       int             relock)
-{
-       if (VN_CACHED(vp)) {
-               xfs_inval_cached_trace(io, offset, -1, ctooff(offtoct(offset)), -1);
-               VOP_FLUSHINVAL_PAGES(vp, ctooff(offtoct(offset)), -1, FI_REMAPF_LOCKED);
-       }
-
-}
-
 ssize_t                        /* bytes read, or (-)  error */
 xfs_read(
        bhv_desc_t              *bdp,
@@ -298,16 +254,17 @@ xfs_read(
        }
 
        if (unlikely(ioflags & IO_ISDIRECT))
-               down(&inode->i_sem);
+               mutex_lock(&inode->i_mutex);
        xfs_ilock(ip, XFS_IOLOCK_SHARED);
 
        if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ) &&
            !(ioflags & IO_INVIS)) {
                vrwlock_t locktype = VRWLOCK_READ;
+               int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
 
                ret = -XFS_SEND_DATA(mp, DM_EVENT_READ,
                                        BHV_TO_VNODE(bdp), *offset, size,
-                                       FILP_DELAY_FLAG(file), &locktype);
+                                       dmflags, &locktype);
                if (ret) {
                        xfs_iunlock(ip, XFS_IOLOCK_SHARED);
                        goto unlock_isem;
@@ -325,11 +282,11 @@ xfs_read(
        xfs_iunlock(ip, XFS_IOLOCK_SHARED);
 
        if (likely(!(ioflags & IO_INVIS)))
-               xfs_ichgtime(ip, XFS_ICHGTIME_ACC);
+               xfs_ichgtime_fast(ip, inode, XFS_ICHGTIME_ACC);
 
 unlock_isem:
        if (unlikely(ioflags & IO_ISDIRECT))
-               up(&inode->i_sem);
+               mutex_unlock(&inode->i_mutex);
        return ret;
 }
 
@@ -390,7 +347,7 @@ xfs_sendfile(
                XFS_STATS_ADD(xs_read_bytes, ret);
 
        if (likely(!(ioflags & IO_INVIS)))
-               xfs_ichgtime(ip, XFS_ICHGTIME_ACC);
+               xfs_ichgtime_fast(ip, LINVFS_GET_IP(vp), XFS_ICHGTIME_ACC);
 
        return ret;
 }
@@ -698,7 +655,7 @@ relock:
                iolock = XFS_IOLOCK_EXCL;
                locktype = VRWLOCK_WRITE;
 
-               down(&inode->i_sem);
+               mutex_lock(&inode->i_mutex);
        } else {
                iolock = XFS_IOLOCK_SHARED;
                locktype = VRWLOCK_WRITE_DIRECT;
@@ -729,7 +686,7 @@ start:
                int             dmflags = FILP_DELAY_FLAG(file);
 
                if (need_isem)
-                       dmflags |= DM_FLAGS_ISEM;
+                       dmflags |= DM_FLAGS_IMUX;
 
                xfs_iunlock(xip, XFS_ILOCK_EXCL);
                error = XFS_SEND_DATA(xip->i_mount, DM_EVENT_WRITE, vp,
@@ -755,15 +712,10 @@ start:
                }
        }
 
-       /*
-        * On Linux, generic_file_write updates the times even if
-        * no data is copied in so long as the write had a size.
-        *
-        * We must update xfs' times since revalidate will overcopy xfs.
-        */
-       if (!(ioflags & IO_INVIS)) {
-               xfs_ichgtime(xip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
-               inode_update_time(inode, 1);
+       if (likely(!(ioflags & IO_INVIS))) {
+               file_update_time(file);
+               xfs_ichgtime_fast(xip, inode,
+                                 XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
        }
 
        /*
@@ -820,7 +772,7 @@ retry:
                if (need_isem) {
                        /* demote the lock now the cached pages are gone */
                        XFS_ILOCK_DEMOTE(mp, io, XFS_IOLOCK_EXCL);
-                       up(&inode->i_sem);
+                       mutex_unlock(&inode->i_mutex);
 
                        iolock = XFS_IOLOCK_SHARED;
                        locktype = VRWLOCK_WRITE_DIRECT;
@@ -864,11 +816,15 @@ retry:
            !(ioflags & IO_INVIS)) {
 
                xfs_rwunlock(bdp, locktype);
+               if (need_isem)
+                       mutex_unlock(&inode->i_mutex);
                error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, vp,
                                DM_RIGHT_NULL, vp, DM_RIGHT_NULL, NULL, NULL,
                                0, 0, 0); /* Delay flag intentionally  unused */
                if (error)
-                       goto out_unlock_isem;
+                       goto out_nounlocks;
+               if (need_isem)
+                       mutex_lock(&inode->i_mutex);
                xfs_rwlock(bdp, locktype);
                pos = xip->i_d.di_size;
                ret = 0;
@@ -970,7 +926,7 @@ retry:
        
                xfs_rwunlock(bdp, locktype);
                if (need_isem)
-                       up(&inode->i_sem);
+                       mutex_unlock(&inode->i_mutex);
 
                error = sync_page_range(inode, mapping, pos, ret);
                if (!error)
@@ -982,7 +938,8 @@ retry:
        xfs_rwunlock(bdp, locktype);
  out_unlock_isem:
        if (need_isem)
-               up(&inode->i_sem);
+               mutex_unlock(&inode->i_mutex);
+ out_nounlocks:
        return -error;
 }