]> err.no Git - linux-2.6/blobdiff - fs/xfs/linux-2.6/xfs_lrw.c
Merge branch 'for-2.6.26' of master.kernel.org:/pub/scm/linux/kernel/git/jwboyer...
[linux-2.6] / fs / xfs / linux-2.6 / xfs_lrw.c
index 1663533884902bb749a371271e7e4943f507a3f7..5e3b57516ec7293fe8bffe42cc995b9025780b8e 100644 (file)
@@ -51,6 +51,7 @@
 #include "xfs_vnodeops.h"
 
 #include <linux/capability.h>
+#include <linux/mount.h>
 #include <linux/writeback.h>
 
 
@@ -176,7 +177,6 @@ xfs_read(
 {
        struct file             *file = iocb->ki_filp;
        struct inode            *inode = file->f_mapping->host;
-       bhv_vnode_t             *vp = XFS_ITOV(ip);
        xfs_mount_t             *mp = ip->i_mount;
        size_t                  size = 0;
        ssize_t                 ret = 0;
@@ -228,11 +228,11 @@ xfs_read(
        xfs_ilock(ip, XFS_IOLOCK_SHARED);
 
        if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
-               bhv_vrwlock_t locktype = VRWLOCK_READ;
                int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
+               int iolock = XFS_IOLOCK_SHARED;
 
-               ret = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp, *offset, size,
-                                       dmflags, &locktype);
+               ret = -XFS_SEND_DATA(mp, DM_EVENT_READ, ip, *offset, size,
+                                       dmflags, &iolock);
                if (ret) {
                        xfs_iunlock(ip, XFS_IOLOCK_SHARED);
                        if (unlikely(ioflags & IO_ISDIRECT))
@@ -242,7 +242,7 @@ xfs_read(
        }
 
        if (unlikely(ioflags & IO_ISDIRECT)) {
-               if (VN_CACHED(vp))
+               if (inode->i_mapping->nrpages)
                        ret = xfs_flushinval_pages(ip, (*offset & PAGE_CACHE_MASK),
                                                    -1, FI_REMAPF_LOCKED);
                mutex_unlock(&inode->i_mutex);
@@ -276,7 +276,6 @@ xfs_splice_read(
        int                     flags,
        int                     ioflags)
 {
-       bhv_vnode_t             *vp = XFS_ITOV(ip);
        xfs_mount_t             *mp = ip->i_mount;
        ssize_t                 ret;
 
@@ -287,11 +286,11 @@ xfs_splice_read(
        xfs_ilock(ip, XFS_IOLOCK_SHARED);
 
        if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
-               bhv_vrwlock_t locktype = VRWLOCK_READ;
+               int iolock = XFS_IOLOCK_SHARED;
                int error;
 
-               error = XFS_SEND_DATA(mp, DM_EVENT_READ, vp, *ppos, count,
-                                       FILP_DELAY_FLAG(infilp), &locktype);
+               error = XFS_SEND_DATA(mp, DM_EVENT_READ, ip, *ppos, count,
+                                       FILP_DELAY_FLAG(infilp), &iolock);
                if (error) {
                        xfs_iunlock(ip, XFS_IOLOCK_SHARED);
                        return -error;
@@ -317,7 +316,6 @@ xfs_splice_write(
        int                     flags,
        int                     ioflags)
 {
-       bhv_vnode_t             *vp = XFS_ITOV(ip);
        xfs_mount_t             *mp = ip->i_mount;
        ssize_t                 ret;
        struct inode            *inode = outfilp->f_mapping->host;
@@ -330,11 +328,11 @@ xfs_splice_write(
        xfs_ilock(ip, XFS_IOLOCK_EXCL);
 
        if (DM_EVENT_ENABLED(ip, DM_EVENT_WRITE) && !(ioflags & IO_INVIS)) {
-               bhv_vrwlock_t locktype = VRWLOCK_WRITE;
+               int iolock = XFS_IOLOCK_EXCL;
                int error;
 
-               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, vp, *ppos, count,
-                                       FILP_DELAY_FLAG(outfilp), &locktype);
+               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip, *ppos, count,
+                                       FILP_DELAY_FLAG(outfilp), &iolock);
                if (error) {
                        xfs_iunlock(ip, XFS_IOLOCK_EXCL);
                        return -error;
@@ -396,7 +394,7 @@ xfs_zero_last_block(
        int             error = 0;
        xfs_bmbt_irec_t imap;
 
-       ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0);
+       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
 
        zero_offset = XFS_B_FSB_OFFSET(mp, isize);
        if (zero_offset == 0) {
@@ -427,14 +425,14 @@ xfs_zero_last_block(
         * out sync.  We need to drop the ilock while we do this so we
         * don't deadlock when the buffer cache calls back to us.
         */
-       xfs_iunlock(ip, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
        zero_len = mp->m_sb.sb_blocksize - zero_offset;
        if (isize + zero_len > offset)
                zero_len = offset - isize;
        error = xfs_iozero(ip, isize, zero_len);
 
-       xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+       xfs_ilock(ip, XFS_ILOCK_EXCL);
        ASSERT(error >= 0);
        return error;
 }
@@ -467,8 +465,7 @@ xfs_zero_eof(
        int             error = 0;
        xfs_bmbt_irec_t imap;
 
-       ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
-       ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
+       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
        ASSERT(offset > isize);
 
        /*
@@ -477,8 +474,7 @@ xfs_zero_eof(
         */
        error = xfs_zero_last_block(ip, offset, isize);
        if (error) {
-               ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
-               ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
+               ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
                return error;
        }
 
@@ -509,8 +505,7 @@ xfs_zero_eof(
                error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb,
                                  0, NULL, 0, &imap, &nimaps, NULL, NULL);
                if (error) {
-                       ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
-                       ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
+                       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
                        return error;
                }
                ASSERT(nimaps > 0);
@@ -534,7 +529,7 @@ xfs_zero_eof(
                 * Drop the inode lock while we're doing the I/O.
                 * We'll still have the iolock to protect us.
                 */
-               xfs_iunlock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+               xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
                zero_off = XFS_FSB_TO_B(mp, start_zero_fsb);
                zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount);
@@ -550,13 +545,13 @@ xfs_zero_eof(
                start_zero_fsb = imap.br_startoff + imap.br_blockcount;
                ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
 
-               xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+               xfs_ilock(ip, XFS_ILOCK_EXCL);
        }
 
        return 0;
 
 out_lock:
-       xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+       xfs_ilock(ip, XFS_ILOCK_EXCL);
        ASSERT(error >= 0);
        return error;
 }
@@ -573,14 +568,12 @@ xfs_write(
        struct file             *file = iocb->ki_filp;
        struct address_space    *mapping = file->f_mapping;
        struct inode            *inode = mapping->host;
-       bhv_vnode_t             *vp = XFS_ITOV(xip);
        unsigned long           segs = nsegs;
        xfs_mount_t             *mp;
        ssize_t                 ret = 0, error = 0;
        xfs_fsize_t             isize, new_size;
        int                     iolock;
        int                     eventsent = 0;
-       bhv_vrwlock_t           locktype;
        size_t                  ocount = 0, count;
        loff_t                  pos;
        int                     need_i_mutex;
@@ -607,11 +600,9 @@ xfs_write(
 relock:
        if (ioflags & IO_ISDIRECT) {
                iolock = XFS_IOLOCK_SHARED;
-               locktype = VRWLOCK_WRITE_DIRECT;
                need_i_mutex = 0;
        } else {
                iolock = XFS_IOLOCK_EXCL;
-               locktype = VRWLOCK_WRITE;
                need_i_mutex = 1;
                mutex_lock(&inode->i_mutex);
        }
@@ -634,9 +625,8 @@ start:
                        dmflags |= DM_FLAGS_IMUX;
 
                xfs_iunlock(xip, XFS_ILOCK_EXCL);
-               error = XFS_SEND_DATA(xip->i_mount, DM_EVENT_WRITE, vp,
-                                     pos, count,
-                                     dmflags, &locktype);
+               error = XFS_SEND_DATA(xip->i_mount, DM_EVENT_WRITE, xip,
+                                     pos, count, dmflags, &iolock);
                if (error) {
                        goto out_unlock_internal;
                }
@@ -664,10 +654,9 @@ start:
                        return XFS_ERROR(-EINVAL);
                }
 
-               if (!need_i_mutex && (VN_CACHED(vp) || pos > xip->i_size)) {
+               if (!need_i_mutex && (mapping->nrpages || pos > xip->i_size)) {
                        xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
                        iolock = XFS_IOLOCK_EXCL;
-                       locktype = VRWLOCK_WRITE;
                        need_i_mutex = 1;
                        mutex_lock(&inode->i_mutex);
                        xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
@@ -679,10 +668,16 @@ start:
        if (new_size > xip->i_size)
                xip->i_new_size = new_size;
 
-       if (likely(!(ioflags & IO_INVIS))) {
+       /*
+        * We're not supposed to change timestamps in readonly-mounted
+        * filesystems.  Throw it away if anyone asks us.
+        */
+       if (likely(!(ioflags & IO_INVIS) &&
+                  !mnt_want_write(file->f_path.mnt))) {
                file_update_time(file);
                xfs_ichgtime_fast(xip, inode,
                                  XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
+               mnt_drop_write(file->f_path.mnt);
        }
 
        /*
@@ -727,7 +722,7 @@ retry:
        current->backing_dev_info = mapping->backing_dev_info;
 
        if ((ioflags & IO_ISDIRECT)) {
-               if (VN_CACHED(vp)) {
+               if (mapping->nrpages) {
                        WARN_ON(need_i_mutex == 0);
                        xfs_inval_cached_trace(xip, pos, -1,
                                        (pos & PAGE_CACHE_MASK), -1);
@@ -744,7 +739,6 @@ retry:
                        mutex_unlock(&inode->i_mutex);
 
                        iolock = XFS_IOLOCK_SHARED;
-                       locktype = VRWLOCK_WRITE_DIRECT;
                        need_i_mutex = 0;
                }
 
@@ -781,15 +775,15 @@ retry:
 
        if (ret == -ENOSPC &&
            DM_EVENT_ENABLED(xip, DM_EVENT_NOSPACE) && !(ioflags & IO_INVIS)) {
-               xfs_rwunlock(xip, locktype);
+               xfs_iunlock(xip, iolock);
                if (need_i_mutex)
                        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,
+               error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, xip,
+                               DM_RIGHT_NULL, xip, DM_RIGHT_NULL, NULL, NULL,
                                0, 0, 0); /* Delay flag intentionally  unused */
                if (need_i_mutex)
                        mutex_lock(&inode->i_mutex);
-               xfs_rwlock(xip, locktype);
+               xfs_ilock(xip, iolock);
                if (error)
                        goto out_unlock_internal;
                pos = xip->i_size;
@@ -817,7 +811,8 @@ retry:
        /* Handle various SYNC-type writes */
        if ((file->f_flags & O_SYNC) || IS_SYNC(inode)) {
                int error2;
-               xfs_rwunlock(xip, locktype);
+
+               xfs_iunlock(xip, iolock);
                if (need_i_mutex)
                        mutex_unlock(&inode->i_mutex);
                error2 = sync_page_range(inode, mapping, pos, ret);
@@ -825,7 +820,7 @@ retry:
                        error = error2;
                if (need_i_mutex)
                        mutex_lock(&inode->i_mutex);
-               xfs_rwlock(xip, locktype);
+               xfs_ilock(xip, iolock);
                error2 = xfs_write_sync_logforce(mp, xip);
                if (!error)
                        error = error2;
@@ -846,7 +841,7 @@ retry:
                        xip->i_d.di_size = xip->i_size;
                xfs_iunlock(xip, XFS_ILOCK_EXCL);
        }
-       xfs_rwunlock(xip, locktype);
+       xfs_iunlock(xip, iolock);
  out_unlock_mutex:
        if (need_i_mutex)
                mutex_unlock(&inode->i_mutex);
@@ -884,28 +879,23 @@ xfs_bdstrat_cb(struct xfs_buf *bp)
 }
 
 /*
- * Wrapper around bdstrat so that we can stop data
- * from going to disk in case we are shutting down the filesystem.
- * Typically user data goes thru this path; one of the exceptions
- * is the superblock.
+ * Wrapper around bdstrat so that we can stop data from going to disk in case
+ * we are shutting down the filesystem.  Typically user data goes thru this
+ * path; one of the exceptions is the superblock.
  */
-int
+void
 xfsbdstrat(
        struct xfs_mount        *mp,
        struct xfs_buf          *bp)
 {
        ASSERT(mp);
        if (!XFS_FORCED_SHUTDOWN(mp)) {
-               /* Grio redirection would go here
-                * if (XFS_BUF_IS_GRIO(bp)) {
-                */
-
                xfs_buf_iorequest(bp);
-               return 0;
+               return;
        }
 
        xfs_buftrace("XFSBDSTRAT IOERROR", bp);
-       return (xfs_bioerror_relse(bp));
+       xfs_bioerror_relse(bp);
 }
 
 /*