fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / xfs / xfs_iomap.c
index 788917f..1965512 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2005 Silicon Graphics, Inc.
+ * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  * All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or
@@ -23,7 +23,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir.h"
 #include "xfs_dir2.h"
 #include "xfs_alloc.h"
 #include "xfs_dmapi.h"
@@ -32,7 +31,6 @@
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
@@ -76,7 +74,7 @@ xfs_iomap_enter_trace(
                (void *)((unsigned long)count),
                (void *)((unsigned long)((io->io_new_size >> 32) & 0xffffffff)),
                (void *)((unsigned long)(io->io_new_size & 0xffffffff)),
-               (void *)NULL,
+               (void *)((unsigned long)current_pid()),
                (void *)NULL,
                (void *)NULL,
                (void *)NULL,
@@ -252,7 +250,7 @@ xfs_iomap(
        error = XFS_BMAPI(mp, NULL, io, offset_fsb,
                        (xfs_filblks_t)(end_fsb - offset_fsb),
                        bmapi_flags,  NULL, 0, &imap,
-                       &nimaps, NULL);
+                       &nimaps, NULL, NULL);
 
        if (error)
                goto out;
@@ -400,6 +398,23 @@ xfs_flush_space(
        return 1;
 }
 
+STATIC int
+xfs_cmn_err_fsblock_zero(
+       xfs_inode_t     *ip,
+       xfs_bmbt_irec_t *imap)
+{
+       xfs_cmn_err(XFS_PTAG_FSBLOCK_ZERO, CE_ALERT, ip->i_mount,
+                       "Access to block zero in inode %llu "
+                       "start_block: %llx start_off: %llx "
+                       "blkcnt: %llx extent-state: %x\n",
+               (unsigned long long)ip->i_ino,
+               (unsigned long long)imap->br_startblock,
+               (unsigned long long)imap->br_startoff,
+               (unsigned long long)imap->br_blockcount,
+               imap->br_state);
+       return EFSCORRUPTED;
+}
+
 int
 xfs_iomap_write_direct(
        xfs_inode_t     *ip,
@@ -519,8 +534,8 @@ xfs_iomap_write_direct(
         */
        XFS_BMAP_INIT(&free_list, &firstfsb);
        nimaps = 1;
-       error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
-               bmapi_flag, &firstfsb, 0, &imap, &nimaps, &free_list);
+       error = XFS_BMAPI(mp, tp, io, offset_fsb, count_fsb, bmapi_flag,
+               &firstfsb, 0, &imap, &nimaps, &free_list, NULL);
        if (error)
                goto error0;
 
@@ -538,23 +553,17 @@ xfs_iomap_write_direct(
         * Copy any maps to caller's array and return any error.
         */
        if (nimaps == 0) {
-               error = (ENOSPC);
+               error = ENOSPC;
+               goto error_out;
+       }
+
+       if (unlikely(!imap.br_startblock && !(io->io_flags & XFS_IOCORE_RT))) {
+               error = xfs_cmn_err_fsblock_zero(ip, &imap);
                goto error_out;
        }
 
        *ret_imap = imap;
        *nmaps = 1;
-       if ( !(io->io_flags & XFS_IOCORE_RT)  && !ret_imap->br_startblock) {
-                cmn_err(CE_PANIC,"Access to block zero:  fs <%s> inode: %lld "
-                        "start_block : %llx start_off : %llx blkcnt : %llx "
-                        "extent-state : %x \n",
-                        (ip->i_mount)->m_fsname,
-                        (long long)ip->i_ino,
-                        (unsigned long long)ret_imap->br_startblock,
-                       (unsigned long long)ret_imap->br_startoff,
-                        (unsigned long long)ret_imap->br_blockcount,
-                       ret_imap->br_state);
-        }
        return 0;
 
 error0:        /* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
@@ -610,8 +619,8 @@ xfs_iomap_eof_want_preallocate(
        while (count_fsb > 0) {
                imaps = nimaps;
                firstblock = NULLFSBLOCK;
-               error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb,
-                                 0, &firstblock, 0, imap, &imaps, NULL);
+               error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb, 0,
+                                 &firstblock, 0, imap, &imaps, NULL, NULL);
                if (error)
                        return error;
                for (n = 0; n < imaps; n++) {
@@ -695,11 +704,11 @@ retry:
 
        nimaps = XFS_WRITE_IMAPS;
        firstblock = NULLFSBLOCK;
-       error = xfs_bmapi(NULL, ip, offset_fsb,
+       error = XFS_BMAPI(mp, NULL, io, offset_fsb,
                          (xfs_filblks_t)(last_fsb - offset_fsb),
                          XFS_BMAPI_DELAY | XFS_BMAPI_WRITE |
                          XFS_BMAPI_ENTIRE, &firstblock, 1, imap,
-                         &nimaps, NULL);
+                         &nimaps, NULL, NULL);
        if (error && (error != ENOSPC))
                return XFS_ERROR(error);
 
@@ -717,17 +726,8 @@ retry:
                goto retry;
        }
 
-       if (!(io->io_flags & XFS_IOCORE_RT)  && !ret_imap->br_startblock) {
-               cmn_err(CE_PANIC,"Access to block zero:  fs <%s> inode: %lld "
-                        "start_block : %llx start_off : %llx blkcnt : %llx "
-                        "extent-state : %x \n",
-                        (ip->i_mount)->m_fsname,
-                        (long long)ip->i_ino,
-                        (unsigned long long)ret_imap->br_startblock,
-                       (unsigned long long)ret_imap->br_startoff,
-                        (unsigned long long)ret_imap->br_blockcount,
-                       ret_imap->br_state);
-       }
+       if (unlikely(!imap[0].br_startblock && !(io->io_flags & XFS_IOCORE_RT)))
+               return xfs_cmn_err_fsblock_zero(ip, &imap[0]);
 
        *ret_imap = imap[0];
        *nmaps = 1;
@@ -832,9 +832,9 @@ xfs_iomap_write_allocate(
                        }
 
                        /* Go get the actual blocks */
-                       error = xfs_bmapi(tp, ip, map_start_fsb, count_fsb,
+                       error = XFS_BMAPI(mp, tp, io, map_start_fsb, count_fsb,
                                        XFS_BMAPI_WRITE, &first_block, 1,
-                                       imap, &nimaps, &free_list);
+                                       imap, &nimaps, &free_list, NULL);
                        if (error)
                                goto trans_cancel;
 
@@ -855,24 +855,10 @@ xfs_iomap_write_allocate(
                 * See if we were able to allocate an extent that
                 * covers at least part of the callers request
                 */
-
                for (i = 0; i < nimaps; i++) {
-                       if (!(io->io_flags & XFS_IOCORE_RT)  &&
-                           !imap[i].br_startblock) {
-                               cmn_err(CE_PANIC,"Access to block zero:  "
-                                       "fs <%s> inode: %lld "
-                                       "start_block : %llx start_off : %llx "
-                                       "blkcnt : %llx extent-state : %x \n",
-                                       (ip->i_mount)->m_fsname,
-                                       (long long)ip->i_ino,
-                                       (unsigned long long)
-                                               imap[i].br_startblock,
-                                       (unsigned long long)
-                                               imap[i].br_startoff,
-                                       (unsigned long long)
-                                               imap[i].br_blockcount,
-                                       imap[i].br_state);
-                        }
+                       if (unlikely(!imap[i].br_startblock &&
+                                    !(io->io_flags & XFS_IOCORE_RT)))
+                               return xfs_cmn_err_fsblock_zero(ip, &imap[i]);
                        if ((offset_fsb >= imap[i].br_startoff) &&
                            (offset_fsb < (imap[i].br_startoff +
                                           imap[i].br_blockcount))) {
@@ -943,7 +929,7 @@ xfs_iomap_write_unwritten(
                                XFS_WRITE_LOG_COUNT);
                if (error) {
                        xfs_trans_cancel(tp, 0);
-                       goto error0;
+                       return XFS_ERROR(error);
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -955,9 +941,9 @@ xfs_iomap_write_unwritten(
                 */
                XFS_BMAP_INIT(&free_list, &firstfsb);
                nimaps = 1;
-               error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
+               error = XFS_BMAPI(mp, tp, io, offset_fsb, count_fsb,
                                  XFS_BMAPI_WRITE|XFS_BMAPI_CONVERT, &firstfsb,
-                                 1, &imap, &nimaps, &free_list);
+                                 1, &imap, &nimaps, &free_list, NULL);
                if (error)
                        goto error_on_bmapi_transaction;
 
@@ -969,19 +955,11 @@ xfs_iomap_write_unwritten(
                error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
                if (error)
-                       goto error0;
-
-               if ( !(io->io_flags & XFS_IOCORE_RT)  && !imap.br_startblock) {
-                       cmn_err(CE_PANIC,"Access to block zero:  fs <%s> "
-                               "inode: %lld start_block : %llx start_off : "
-                               "%llx blkcnt : %llx extent-state : %x \n",
-                               (ip->i_mount)->m_fsname,
-                               (long long)ip->i_ino,
-                               (unsigned long long)imap.br_startblock,
-                               (unsigned long long)imap.br_startoff,
-                               (unsigned long long)imap.br_blockcount,
-                               imap.br_state);
-               }
+                       return XFS_ERROR(error);
+
+               if (unlikely(!imap.br_startblock &&
+                            !(io->io_flags & XFS_IOCORE_RT)))
+                       return xfs_cmn_err_fsblock_zero(ip, &imap);
 
                if ((numblks_fsb = imap.br_blockcount) == 0) {
                        /*
@@ -1001,6 +979,5 @@ error_on_bmapi_transaction:
        xfs_bmap_cancel(&free_list);
        xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT));
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
-error0:
        return XFS_ERROR(error);
 }