]> err.no Git - linux-2.6/blobdiff - fs/xfs/xfs_inode.c
Merge branch 'from-linus' into upstream
[linux-2.6] / fs / xfs / xfs_inode.c
index 86a8451d10fc51d0ab2cb4caecfbdb30dbf1b897..94b60dd03801ba4ef4638ab0ffe50219a0170338 100644 (file)
@@ -160,7 +160,7 @@ xfs_inotobp(
        xfs_dinode_t    *dip;
 
        /*
-        * Call the space managment code to find the location of the
+        * Call the space management code to find the location of the
         * inode on disk.
         */
        imap.im_blkno = 0;
@@ -253,7 +253,8 @@ xfs_itobp(
        xfs_inode_t     *ip,
        xfs_dinode_t    **dipp,
        xfs_buf_t       **bpp,
-       xfs_daddr_t     bno)
+       xfs_daddr_t     bno,
+       uint            imap_flags)
 {
        xfs_buf_t       *bp;
        int             error;
@@ -269,10 +270,9 @@ xfs_itobp(
                 * inode on disk.
                 */
                imap.im_blkno = bno;
-               error = xfs_imap(mp, tp, ip->i_ino, &imap, XFS_IMAP_LOOKUP);
-               if (error != 0) {
+               if ((error = xfs_imap(mp, tp, ip->i_ino, &imap,
+                                       XFS_IMAP_LOOKUP | imap_flags)))
                        return error;
-               }
 
                /*
                 * If the inode number maps to a block outside the bounds
@@ -336,9 +336,10 @@ xfs_itobp(
         * (if DEBUG kernel) or the first inode in the buffer, otherwise.
         */
 #ifdef DEBUG
-       ni = BBTOB(imap.im_len) >> mp->m_sb.sb_inodelog;
+       ni = (imap_flags & XFS_IMAP_BULKSTAT) ? 0 :
+               (BBTOB(imap.im_len) >> mp->m_sb.sb_inodelog);
 #else
-       ni = 1;
+       ni = (imap_flags & XFS_IMAP_BULKSTAT) ? 0 : 1;
 #endif
        for (i = 0; i < ni; i++) {
                int             di_ok;
@@ -505,7 +506,7 @@ xfs_iformat(
        switch (INT_GET(dip->di_core.di_aformat, ARCH_CONVERT)) {
        case XFS_DINODE_FMT_LOCAL:
                atp = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip);
-               size = (int)INT_GET(atp->hdr.totsize, ARCH_CONVERT);
+               size = be16_to_cpu(atp->hdr.totsize);
                error = xfs_iformat_local(ip, dip, XFS_ATTR_FORK, size);
                break;
        case XFS_DINODE_FMT_EXTENTS:
@@ -836,7 +837,7 @@ xfs_dic2xflags(
 
 /*
  * Given a mount structure and an inode number, return a pointer
- * to a newly allocated in-core inode coresponding to the given
+ * to a newly allocated in-core inode corresponding to the given
  * inode number.
  *
  * Initialize the inode's attributes and extent pointers if it
@@ -868,9 +869,8 @@ xfs_iread(
         * return NULL as well.  Set i_blkno to 0 so that xfs_itobp() will
         * know that this is a new incore inode.
         */
-       error = xfs_itobp(mp, tp, ip, &dip, &bp, bno);
-
-       if (error != 0) {
+       error = xfs_itobp(mp, tp, ip, &dip, &bp, bno, 0);
+       if (error) {
                kmem_zone_free(xfs_inode_zone, ip);
                return error;
        }
@@ -1372,10 +1372,10 @@ xfs_itrunc_trace(
                     (void*)(unsigned long)((toss_finish >> 32) & 0xffffffff),
                     (void*)(unsigned long)(toss_finish & 0xffffffff),
                     (void*)(unsigned long)current_cpu(),
-                    (void*)0,
-                    (void*)0,
-                    (void*)0,
-                    (void*)0);
+                    (void*)(unsigned long)current_pid(),
+                    (void*)NULL,
+                    (void*)NULL,
+                    (void*)NULL);
 }
 #else
 #define        xfs_itrunc_trace(tag, ip, flag, new_size, toss_start, toss_finish)
@@ -1393,6 +1393,16 @@ xfs_itrunc_trace(
  * calling into the buffer/page cache code and we can't hold the
  * inode lock when we do so.
  *
+ * We need to wait for any direct I/Os in flight to complete before we
+ * proceed with the truncate. This is needed to prevent the extents
+ * being read or written by the direct I/Os from being removed while the
+ * I/O is in flight as there is no other method of synchronising
+ * direct I/O with the truncate operation.  Also, because we hold
+ * the IOLOCK in exclusive mode, we prevent new direct I/Os from being
+ * started until the truncate completes and drops the lock. Essentially,
+ * the vn_iowait() call forms an I/O barrier that provides strict ordering
+ * between direct I/Os and the truncate operation.
+ *
  * The flags parameter can have either the value XFS_ITRUNC_DEFINITE
  * or XFS_ITRUNC_MAYBE.  The XFS_ITRUNC_MAYBE value should be used
  * in the case that the caller is locking things out of order and
@@ -1420,6 +1430,9 @@ xfs_itruncate_start(
 
        mp = ip->i_mount;
        vp = XFS_ITOV(ip);
+
+       vn_iowait(vp);  /* wait for the completion of any pending DIOs */
+       
        /*
         * Call VOP_TOSS_PAGES() or VOP_FLUSHINVAL_PAGES() to get rid of pages and buffers
         * overlapping the region being removed.  We have to use
@@ -1895,7 +1908,7 @@ xfs_iunlink(
                 * Here we put the head pointer into our next pointer,
                 * and then we fall through to point the head at us.
                 */
-               error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0);
+               error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0, 0);
                if (error) {
                        return error;
                }
@@ -2004,7 +2017,7 @@ xfs_iunlink_remove(
                 * of dealing with the buffer when there is no need to
                 * change it.
                 */
-               error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0);
+               error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0, 0);
                if (error) {
                        cmn_err(CE_WARN,
                                "xfs_iunlink_remove: xfs_itobp()  returned an error %d on %s.  Returning error.",
@@ -2066,7 +2079,7 @@ xfs_iunlink_remove(
                 * Now last_ibp points to the buffer previous to us on
                 * the unlinked list.  Pull us from the list.
                 */
-               error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0);
+               error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0, 0);
                if (error) {
                        cmn_err(CE_WARN,
                                "xfs_iunlink_remove: xfs_itobp()  returned an error %d on %s.  Returning error.",
@@ -2710,7 +2723,7 @@ xfs_ipin(
 /*
  * Decrement the pin count of the given inode, and wake up
  * anyone in xfs_iwait_unpin() if the count goes to 0.  The
- * inode must have been previoulsy pinned with a call to xfs_ipin().
+ * inode must have been previously pinned with a call to xfs_ipin().
  */
 void
 xfs_iunpin(
@@ -2719,16 +2732,29 @@ xfs_iunpin(
        ASSERT(atomic_read(&ip->i_pincount) > 0);
 
        if (atomic_dec_and_test(&ip->i_pincount)) {
-               vnode_t *vp = XFS_ITOV_NULL(ip);
+               /*
+                * If the inode is currently being reclaimed, the
+                * linux inode _and_ the xfs vnode may have been
+                * freed so we cannot reference either of them safely.
+                * Hence we should not try to do anything to them
+                * if the xfs inode is currently in the reclaim
+                * path.
+                *
+                * However, we still need to issue the unpin wakeup
+                * call as the inode reclaim may be blocked waiting for
+                * the inode to become unpinned.
+                */
+               if (!(ip->i_flags & (XFS_IRECLAIM|XFS_IRECLAIMABLE))) {
+                       vnode_t *vp = XFS_ITOV_NULL(ip);
 
-               /* make sync come back and flush this inode */
-               if (vp) {
-                       struct inode    *inode = vn_to_inode(vp);
+                       /* make sync come back and flush this inode */
+                       if (vp) {
+                               struct inode    *inode = vn_to_inode(vp);
 
-                       if (!(inode->i_state & I_NEW))
-                               mark_inode_dirty_sync(inode);
+                               if (!(inode->i_state & I_NEW))
+                                       mark_inode_dirty_sync(inode);
+                       }
                }
-
                wake_up(&ip->i_ipin_wait);
        }
 }
@@ -3023,8 +3049,8 @@ xfs_iflush(
        /*
         * Get the buffer containing the on-disk inode.
         */
-       error = xfs_itobp(mp, NULL, ip, &dip, &bp, 0);
-       if (error != 0) {
+       error = xfs_itobp(mp, NULL, ip, &dip, &bp, 0, 0);
+       if (error) {
                xfs_ifunlock(ip);
                return error;
        }
@@ -3677,7 +3703,7 @@ void
 xfs_iext_add(
        xfs_ifork_t     *ifp,           /* inode fork pointer */
        xfs_extnum_t    idx,            /* index to begin adding exts */
-       int             ext_diff)       /* nubmer of extents to add */
+       int             ext_diff)       /* number of extents to add */
 {
        int             byte_diff;      /* new bytes being added */
        int             new_size;       /* size of extents after adding */
@@ -4025,7 +4051,7 @@ xfs_iext_remove_indirect(
        xfs_extnum_t    ext_diff;       /* extents to remove in current list */
        xfs_extnum_t    nex1;           /* number of extents before idx */
        xfs_extnum_t    nex2;           /* extents after idx + count */
-       int             nlists;         /* entries in indirecton array */
+       int             nlists;         /* entries in indirection array */
        int             page_idx = idx; /* index in target extent list */
 
        ASSERT(ifp->if_flags & XFS_IFEXTIREC);
@@ -4278,9 +4304,9 @@ xfs_iext_bno_to_ext(
        xfs_filblks_t   blockcount = 0; /* number of blocks in extent */
        xfs_bmbt_rec_t  *ep = NULL;     /* pointer to target extent */
        xfs_ext_irec_t  *erp = NULL;    /* indirection array pointer */
-       int             high;           /* upper boundry in search */
+       int             high;           /* upper boundary in search */
        xfs_extnum_t    idx = 0;        /* index of target extent */
-       int             low;            /* lower boundry in search */
+       int             low;            /* lower boundary in search */
        xfs_extnum_t    nextents;       /* number of file extents */
        xfs_fileoff_t   startoff = 0;   /* start offset of extent */