]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_vnodeops.c
[XFS] Remove an unhelpful ifdef, the comment above the routine explains
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_vnodeops.c
index 1377c868f3f4929aec4106f187b01c03f480c433..7c1f74531463bb11cac411322a6366420c822921 100644 (file)
@@ -1,40 +1,26 @@
 /*
- * Copyright (c) 2000-2005 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_macros.h"
+#include "xfs_fs.h"
 #include "xfs_types.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_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
-#include "xfs_alloc_btree.h"
+#include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
+#include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_itable.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
-#include "xfs_alloc.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_item.h"
 #include "xfs_inode.h"
+#include "xfs_inode_item.h"
+#include "xfs_dir_leaf.h"
+#include "xfs_itable.h"
+#include "xfs_btree.h"
+#include "xfs_ialloc.h"
+#include "xfs_alloc.h"
 #include "xfs_bmap.h"
-#include "xfs_da_btree.h"
 #include "xfs_attr.h"
 #include "xfs_rw.h"
-#include "xfs_refcache.h"
 #include "xfs_error.h"
-#include "xfs_bit.h"
-#include "xfs_rtalloc.h"
 #include "xfs_quota.h"
 #include "xfs_utils.h"
+#include "xfs_rtalloc.h"
+#include "xfs_refcache.h"
 #include "xfs_trans_space.h"
-#include "xfs_dir_leaf.h"
-#include "xfs_mac.h"
 #include "xfs_log_priv.h"
+#include "xfs_mac.h"
 
 
 /*
@@ -104,7 +89,7 @@ xfs_open(
         * If it's a directory with any blocks, read-ahead block 0
         * as we're almost certain to have the next operation be a read there.
         */
-       if (vp->v_type == VDIR && ip->i_d.di_nextents > 0) {
+       if (VN_ISDIR(vp) && ip->i_d.di_nextents > 0) {
                mode = xfs_ilock_map_shared(ip);
                if (ip->i_d.di_nextents > 0)
                        (void)xfs_da_reada_buf(NULL, ip, 0, XFS_DATA_FORK);
@@ -163,55 +148,25 @@ xfs_getattr(
        /*
         * Copy from in-core inode.
         */
-       vap->va_type = vp->v_type;
-       vap->va_mode = ip->i_d.di_mode & MODEMASK;
+       vap->va_mode = ip->i_d.di_mode;
        vap->va_uid = ip->i_d.di_uid;
        vap->va_gid = ip->i_d.di_gid;
        vap->va_projid = ip->i_d.di_projid;
 
        /*
         * Check vnode type block/char vs. everything else.
-        * Do it with bitmask because that's faster than looking
-        * for multiple values individually.
         */
-       if (((1 << vp->v_type) & ((1<<VBLK) | (1<<VCHR))) == 0) {
+       switch (ip->i_d.di_mode & S_IFMT) {
+       case S_IFBLK:
+       case S_IFCHR:
+               vap->va_rdev = ip->i_df.if_u2.if_rdev;
+               vap->va_blocksize = BLKDEV_IOSIZE;
+               break;
+       default:
                vap->va_rdev = 0;
 
                if (!(ip->i_d.di_flags & XFS_DIFLAG_REALTIME)) {
-
-#if 0
-                       /* Large block sizes confuse various
-                        * user space programs, so letting the
-                        * stripe size through is not a good
-                        * idea for now.
-                        */
-                       vap->va_blocksize = mp->m_swidth ?
-                               /*
-                                * If the underlying volume is a stripe, then
-                                * return the stripe width in bytes as the
-                                * recommended I/O size.
-                                */
-                               (mp->m_swidth << mp->m_sb.sb_blocklog) :
-                               /*
-                                * Return the largest of the preferred buffer
-                                * sizes since doing small I/Os into larger
-                                * buffers causes buffers to be decommissioned.
-                                * The value returned is in bytes.
-                                */
-                               (1 << (int)MAX(mp->m_readio_log,
-                                              mp->m_writeio_log));
-
-#else
-                       vap->va_blocksize =
-                               /*
-                                * Return the largest of the preferred buffer
-                                * sizes since doing small I/Os into larger
-                                * buffers causes buffers to be decommissioned.
-                                * The value returned is in bytes.
-                                */
-                               1 << (int)MAX(mp->m_readio_log,
-                                              mp->m_writeio_log);
-#endif
+                       vap->va_blocksize = xfs_preferred_iosize(mp);
                } else {
 
                        /*
@@ -224,9 +179,7 @@ xfs_getattr(
                                (ip->i_d.di_extsize << mp->m_sb.sb_blocklog) :
                                (mp->m_sb.sb_rextsize << mp->m_sb.sb_blocklog);
                }
-       } else {
-               vap->va_rdev = ip->i_df.if_u2.if_rdev;
-               vap->va_blocksize = BLKDEV_IOSIZE;
+               break;
        }
 
        vap->va_atime.tv_sec = ip->i_d.di_atime.t_sec;
@@ -468,7 +421,7 @@ xfs_setattr(
                                m |= S_ISGID;
 #if 0
                        /* Linux allows this, Irix doesn't. */
-                       if ((vap->va_mode & S_ISVTX) && vp->v_type != VDIR)
+                       if ((vap->va_mode & S_ISVTX) && !VN_ISDIR(vp))
                                m |= S_ISVTX;
 #endif
                        if (m && !capable(CAP_FSETID))
@@ -546,10 +499,10 @@ xfs_setattr(
                        goto error_return;
                }
 
-               if (vp->v_type == VDIR) {
+               if (VN_ISDIR(vp)) {
                        code = XFS_ERROR(EISDIR);
                        goto error_return;
-               } else if (vp->v_type != VREG) {
+               } else if (!VN_ISREG(vp)) {
                        code = XFS_ERROR(EINVAL);
                        goto error_return;
                }
@@ -580,8 +533,7 @@ xfs_setattr(
                /*
                 * Can't change extent size if any extents are allocated.
                 */
-               if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
-                   (mask & XFS_AT_EXTSIZE) &&
+               if (ip->i_d.di_nextents && (mask & XFS_AT_EXTSIZE) &&
                    ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) !=
                     vap->va_extsize) ) {
                        code = XFS_ERROR(EINVAL);       /* EFBIG? */
@@ -609,7 +561,8 @@ xfs_setattr(
                /*
                 * Can't change realtime flag if any extents are allocated.
                 */
-               if (ip->i_d.di_nextents && (mask & XFS_AT_XFLAGS) &&
+               if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
+                   (mask & XFS_AT_XFLAGS) &&
                    (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) !=
                    (vap->va_xflags & XFS_XFLAG_REALTIME)) {
                        code = XFS_ERROR(EINVAL);       /* EFBIG? */
@@ -673,8 +626,10 @@ xfs_setattr(
         */
        if (mask & XFS_AT_SIZE) {
                code = 0;
-               if (vap->va_size > ip->i_d.di_size)
+               if ((vap->va_size > ip->i_d.di_size) && 
+                   (flags & ATTR_NOSIZETOK) == 0) {
                        code = xfs_igrow_start(ip, vap->va_size, credp);
+               }
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
                if (!code)
                        code = xfs_itruncate_data(ip, vap->va_size);
@@ -1117,6 +1072,7 @@ xfs_fsync(
        xfs_inode_t     *ip;
        xfs_trans_t     *tp;
        int             error;
+       int             log_flushed = 0, changed = 1;
 
        vn_trace_entry(BHV_TO_VNODE(bdp),
                        __FUNCTION__, (inst_t *)__return_address);
@@ -1170,10 +1126,18 @@ xfs_fsync(
                xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
                if (xfs_ipincount(ip)) {
-                       xfs_log_force(ip->i_mount, (xfs_lsn_t)0,
+                       _xfs_log_force(ip->i_mount, (xfs_lsn_t)0,
                                      XFS_LOG_FORCE |
                                      ((flag & FSYNC_WAIT)
-                                      ? XFS_LOG_SYNC : 0));
+                                      ? XFS_LOG_SYNC : 0),
+                                     &log_flushed);
+               } else {
+                       /*
+                        * If the inode is not pinned and nothing
+                        * has changed we don't need to flush the
+                        * cache.
+                        */
+                       changed = 0;
                }
                error = 0;
        } else  {
@@ -1209,10 +1173,27 @@ xfs_fsync(
                xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
                if (flag & FSYNC_WAIT)
                        xfs_trans_set_sync(tp);
-               error = xfs_trans_commit(tp, 0, NULL);
+               error = _xfs_trans_commit(tp, 0, NULL, &log_flushed);
 
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
        }
+
+       if ((ip->i_mount->m_flags & XFS_MOUNT_BARRIER) && changed) {
+               /*
+                * If the log write didn't issue an ordered tag we need
+                * to flush the disk cache for the data device now.
+                */
+               if (!log_flushed)
+                       xfs_blkdev_issue_flush(ip->i_mount->m_ddev_targp);
+
+               /*
+                * If this inode is on the RT dev we need to flush that
+                * cache aswell.
+                */
+               if (ip->i_d.di_flags & XFS_DIFLAG_REALTIME)
+                       xfs_blkdev_issue_flush(ip->i_mount->m_rtdev_targp);
+       }
+
        return error;
 }
 
@@ -1567,7 +1548,7 @@ xfs_release(
        vp = BHV_TO_VNODE(bdp);
        ip = XFS_BHVTOI(bdp);
 
-       if ((vp->v_type != VREG) || (ip->i_d.di_mode == 0)) {
+       if (!VN_ISREG(vp) || (ip->i_d.di_mode == 0)) {
                return 0;
        }
 
@@ -1895,7 +1876,7 @@ xfs_create(
        dp = XFS_BHVTOI(dir_bdp);
        mp = dp->i_mount;
 
-       dm_di_mode = vap->va_mode|VTTOIF(vap->va_type);
+       dm_di_mode = vap->va_mode;
        namelen = VNAMELEN(dentry);
 
        if (DM_EVENT_ENABLED(dir_vp->v_vfsp, dp, DM_EVENT_CREATE)) {
@@ -1973,8 +1954,7 @@ xfs_create(
            (error = XFS_DIR_CANENTER(mp, tp, dp, name, namelen)))
                goto error_return;
        rdev = (vap->va_mask & XFS_AT_RDEV) ? vap->va_rdev : 0;
-       error = xfs_dir_ialloc(&tp, dp,
-                       MAKEIMODE(vap->va_type,vap->va_mode), 1,
+       error = xfs_dir_ialloc(&tp, dp, vap->va_mode, 1,
                        rdev, credp, prid, resblks > 0,
                        &ip, &committed);
        if (error) {
@@ -2620,7 +2600,7 @@ xfs_link(
        vn_trace_entry(src_vp, __FUNCTION__, (inst_t *)__return_address);
 
        target_namelen = VNAMELEN(dentry);
-       if (src_vp->v_type == VDIR)
+       if (VN_ISDIR(src_vp))
                return XFS_ERROR(EPERM);
 
        src_bdp = vn_bhv_lookup_unlocked(VN_BHV_HEAD(src_vp), &xfs_vnodeops);
@@ -2805,7 +2785,7 @@ xfs_mkdir(
 
        tp = NULL;
        dp_joined_to_trans = B_FALSE;
-       dm_di_mode = vap->va_mode|VTTOIF(vap->va_type);
+       dm_di_mode = vap->va_mode;
 
        if (DM_EVENT_ENABLED(dir_vp->v_vfsp, dp, DM_EVENT_CREATE)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_CREATE,
@@ -2879,8 +2859,7 @@ xfs_mkdir(
        /*
         * create the directory inode.
         */
-       error = xfs_dir_ialloc(&tp, dp,
-                       MAKEIMODE(vap->va_type,vap->va_mode), 2,
+       error = xfs_dir_ialloc(&tp, dp, vap->va_mode, 2,
                        0, credp, prid, resblks > 0,
                &cdp, NULL);
        if (error) {
@@ -3650,7 +3629,7 @@ xfs_rwlock(
        vnode_t         *vp;
 
        vp = BHV_TO_VNODE(bdp);
-       if (vp->v_type == VDIR)
+       if (VN_ISDIR(vp))
                return 1;
        ip = XFS_BHVTOI(bdp);
        if (locktype == VRWLOCK_WRITE) {
@@ -3681,7 +3660,7 @@ xfs_rwunlock(
        vnode_t         *vp;
 
        vp = BHV_TO_VNODE(bdp);
-       if (vp->v_type == VDIR)
+       if (VN_ISDIR(vp))
                return;
        ip = XFS_BHVTOI(bdp);
        if (locktype == VRWLOCK_WRITE) {
@@ -3847,51 +3826,10 @@ xfs_reclaim(
                return 0;
        }
 
-       if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
-               if (ip->i_d.di_size > 0) {
-                       /*
-                        * Flush and invalidate any data left around that is
-                        * a part of this file.
-                        *
-                        * Get the inode's i/o lock so that buffers are pushed
-                        * out while holding the proper lock.  We can't hold
-                        * the inode lock here since flushing out buffers may
-                        * cause us to try to get the lock in xfs_strategy().
-                        *
-                        * We don't have to call remapf() here, because there
-                        * cannot be any mapped file references to this vnode
-                        * since it is being reclaimed.
-                        */
-                       xfs_ilock(ip, XFS_IOLOCK_EXCL);
+       vn_iowait(vp);
 
-                       /*
-                        * If we hit an IO error, we need to make sure that the
-                        * buffer and page caches of file data for
-                        * the file are tossed away. We don't want to use
-                        * VOP_FLUSHINVAL_PAGES here because we don't want dirty
-                        * pages to stay attached to the vnode, but be
-                        * marked P_BAD. pdflush/vnode_pagebad
-                        * hates that.
-                        */
-                       if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
-                               VOP_FLUSHINVAL_PAGES(vp, 0, -1, FI_NONE);
-                       } else {
-                               VOP_TOSS_PAGES(vp, 0, -1, FI_NONE);
-                       }
-
-                       ASSERT(VN_CACHED(vp) == 0);
-                       ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) ||
-                              ip->i_delayed_blks == 0);
-                       xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-               } else if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
-                       /*
-                        * di_size field may not be quite accurate if we're
-                        * shutting down.
-                        */
-                       VOP_TOSS_PAGES(vp, 0, -1, FI_NONE);
-                       ASSERT(VN_CACHED(vp) == 0);
-               }
-       }
+       ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
+       ASSERT(VN_CACHED(vp) == 0);
 
        /* If we have nothing to flush with this inode then complete the
         * teardown now, otherwise break the link between the xfs inode
@@ -4567,7 +4505,7 @@ xfs_change_file_space(
        /*
         * must be a regular file and have write permission
         */
-       if (vp->v_type != VREG)
+       if (!VN_ISREG(vp))
                return XFS_ERROR(EINVAL);
 
        xfs_ilock(ip, XFS_ILOCK_SHARED);