]> err.no Git - linux-2.6/blobdiff - fs/xfs/linux-2.6/xfs_aops.c
fs: rename buffer trylock
[linux-2.6] / fs / xfs / linux-2.6 / xfs_aops.c
index 22a40bd0cce29bc66e0370b38dbe658eefd56d1d..fa47e43b8b41a525843c57cb4591ed9ffd334141 100644 (file)
@@ -107,6 +107,18 @@ xfs_page_trace(
 #define xfs_page_trace(tag, inode, page, pgoff)
 #endif
 
+STATIC struct block_device *
+xfs_find_bdev_for_inode(
+       struct xfs_inode        *ip)
+{
+       struct xfs_mount        *mp = ip->i_mount;
+
+       if (XFS_IS_REALTIME_INODE(ip))
+               return mp->m_rtdev_targp->bt_bdev;
+       else
+               return mp->m_ddev_targp->bt_bdev;
+}
+
 /*
  * Schedule IO completion handling on a xfsdatad if this was
  * the final hold on this ioend. If we are asked to wait,
@@ -140,16 +152,18 @@ xfs_destroy_ioend(
                next = bh->b_private;
                bh->b_end_io(bh, !ioend->io_error);
        }
-       if (unlikely(ioend->io_error))
-               vn_ioerror(ioend->io_vnode, ioend->io_error, __FILE__,__LINE__);
-       vn_iowake(ioend->io_vnode);
+       if (unlikely(ioend->io_error)) {
+               vn_ioerror(XFS_I(ioend->io_inode), ioend->io_error,
+                               __FILE__,__LINE__);
+       }
+       vn_iowake(XFS_I(ioend->io_inode));
        mempool_free(ioend, xfs_ioend_pool);
 }
 
 /*
  * Update on-disk file size now that data has been written to disk.
  * The current in-memory file size is i_size.  If a write is beyond
- * eof io_new_size will be the intended file size until i_size is
+ * eof i_new_size will be the intended file size until i_size is
  * updated.  If this write does not extend all the way to the valid
  * file size then restrict this update to the end of the write.
  */
@@ -157,14 +171,10 @@ STATIC void
 xfs_setfilesize(
        xfs_ioend_t             *ioend)
 {
-       xfs_inode_t             *ip;
+       xfs_inode_t             *ip = XFS_I(ioend->io_inode);
        xfs_fsize_t             isize;
        xfs_fsize_t             bsize;
 
-       ip = xfs_vtoi(ioend->io_vnode);
-       if (!ip)
-               return;
-
        ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
        ASSERT(ioend->io_type != IOMAP_READ);
 
@@ -175,14 +185,14 @@ xfs_setfilesize(
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
 
-       isize = MAX(ip->i_size, ip->i_iocore.io_new_size);
+       isize = MAX(ip->i_size, ip->i_new_size);
        isize = MIN(isize, bsize);
 
        if (ip->i_d.di_size < isize) {
                ip->i_d.di_size = isize;
                ip->i_update_core = 1;
                ip->i_update_size = 1;
-               mark_inode_dirty_sync(vn_to_inode(ioend->io_vnode));
+               mark_inode_dirty_sync(ioend->io_inode);
        }
 
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -228,13 +238,17 @@ xfs_end_bio_unwritten(
 {
        xfs_ioend_t             *ioend =
                container_of(work, xfs_ioend_t, io_work);
-       bhv_vnode_t             *vp = ioend->io_vnode;
+       struct xfs_inode        *ip = XFS_I(ioend->io_inode);
        xfs_off_t               offset = ioend->io_offset;
        size_t                  size = ioend->io_size;
 
        if (likely(!ioend->io_error)) {
-               xfs_bmap(xfs_vtoi(vp), offset, size,
-                               BMAPI_UNWRITTEN, NULL, NULL);
+               if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
+                       int error;
+                       error = xfs_iomap_write_unwritten(ip, offset, size);
+                       if (error)
+                               ioend->io_error = error;
+               }
                xfs_setfilesize(ioend);
        }
        xfs_destroy_ioend(ioend);
@@ -277,10 +291,10 @@ xfs_alloc_ioend(
        ioend->io_error = 0;
        ioend->io_list = NULL;
        ioend->io_type = type;
-       ioend->io_vnode = vn_from_inode(inode);
+       ioend->io_inode = inode;
        ioend->io_buffer_head = NULL;
        ioend->io_buffer_tail = NULL;
-       atomic_inc(&ioend->io_vnode->v_iocount);
+       atomic_inc(&XFS_I(ioend->io_inode)->i_iocount);
        ioend->io_offset = 0;
        ioend->io_size = 0;
 
@@ -307,7 +321,7 @@ xfs_map_blocks(
        xfs_inode_t             *ip = XFS_I(inode);
        int                     error, nmaps = 1;
 
-       error = xfs_bmap(ip, offset, count,
+       error = xfs_iomap(ip, offset, count,
                                flags, mapp, &nmaps);
        if (!error && (flags & (BMAPI_WRITE|BMAPI_ALLOCATE)))
                xfs_iflags_set(ip, XFS_IMODIFIED);
@@ -326,17 +340,13 @@ xfs_iomap_valid(
 /*
  * BIO completion handler for buffered IO.
  */
-STATIC int
+STATIC void
 xfs_end_bio(
        struct bio              *bio,
-       unsigned int            bytes_done,
        int                     error)
 {
        xfs_ioend_t             *ioend = bio->bi_private;
 
-       if (bio->bi_size)
-               return 1;
-
        ASSERT(atomic_read(&bio->bi_cnt) >= 1);
        ioend->io_error = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : error;
 
@@ -346,7 +356,6 @@ xfs_end_bio(
        bio_put(bio);
 
        xfs_finish_ioend(ioend, 0);
-       return 0;
 }
 
 STATIC void
@@ -400,7 +409,6 @@ xfs_start_buffer_writeback(
 STATIC void
 xfs_start_page_writeback(
        struct page             *page,
-       struct writeback_control *wbc,
        int                     clear_dirty,
        int                     buffers)
 {
@@ -410,10 +418,9 @@ xfs_start_page_writeback(
                clear_page_dirty_for_io(page);
        set_page_writeback(page);
        unlock_page(page);
-       if (!buffers) {
+       /* If no buffers on the page are to be written, finish it here */
+       if (!buffers)
                end_page_writeback(page);
-               wbc->pages_skipped++;   /* We didn't write this page */
-       }
 }
 
 static inline int bio_add_buffer(struct bio *bio, struct buffer_head *bh)
@@ -506,7 +513,7 @@ xfs_cancel_ioend(
                        unlock_buffer(bh);
                } while ((bh = next_bh) != NULL);
 
-               vn_iowake(ioend->io_vnode);
+               vn_iowake(XFS_I(ioend->io_inode));
                mempool_free(ioend, xfs_ioend_pool);
        } while ((ioend = next) != NULL);
 }
@@ -668,7 +675,7 @@ xfs_probe_cluster(
                        } else
                                pg_offset = PAGE_CACHE_SIZE;
 
-                       if (page->index == tindex && !TestSetPageLocked(page)) {
+                       if (page->index == tindex && trylock_page(page)) {
                                pg_len = xfs_probe_page(page, pg_offset, mapped);
                                unlock_page(page);
                        }
@@ -752,7 +759,7 @@ xfs_convert_page(
 
        if (page->index != tindex)
                goto fail;
-       if (TestSetPageLocked(page))
+       if (!trylock_page(page))
                goto fail;
        if (PageWriteback(page))
                goto fail_unlock_page;
@@ -850,7 +857,7 @@ xfs_convert_page(
                                done = 1;
                        }
                }
-               xfs_start_page_writeback(page, wbc, !page_dirty, count);
+               xfs_start_page_writeback(page, !page_dirty, count);
        }
 
        return done;
@@ -1097,7 +1104,7 @@ xfs_page_state_convert(
                         * that we are writing into for the first time.
                         */
                        type = IOMAP_NEW;
-                       if (!test_and_set_bit(BH_Lock, &bh->b_state)) {
+                       if (trylock_buffer(bh)) {
                                ASSERT(buffer_mapped(bh));
                                if (iomap_valid)
                                        all_bh = 1;
@@ -1122,7 +1129,7 @@ xfs_page_state_convert(
                SetPageUptodate(page);
 
        if (startio)
-               xfs_start_page_writeback(page, wbc, 1, count);
+               xfs_start_page_writeback(page, 1, count);
 
        if (ioend && iomap_valid) {
                offset = (iomap.iomap_offset + iomap.iomap_bsize - 1) >>
@@ -1332,7 +1339,7 @@ __xfs_get_blocks(
        offset = (xfs_off_t)iblock << inode->i_blkbits;
        ASSERT(bh_result->b_size >= (1 << inode->i_blkbits));
        size = bh_result->b_size;
-       error = xfs_bmap(XFS_I(inode), offset, size,
+       error = xfs_iomap(XFS_I(inode), offset, size,
                             create ? flags : BMAPI_READ, &iomap, &niomap);
        if (error)
                return -error;
@@ -1480,28 +1487,21 @@ xfs_vm_direct_IO(
 {
        struct file     *file = iocb->ki_filp;
        struct inode    *inode = file->f_mapping->host;
-       xfs_iomap_t     iomap;
-       int             maps = 1;
-       int             error;
+       struct block_device *bdev;
        ssize_t         ret;
 
-       error = xfs_bmap(XFS_I(inode), offset, 0,
-                               BMAPI_DEVICE, &iomap, &maps);
-       if (error)
-               return -error;
+       bdev = xfs_find_bdev_for_inode(XFS_I(inode));
 
        if (rw == WRITE) {
                iocb->private = xfs_alloc_ioend(inode, IOMAP_UNWRITTEN);
                ret = blockdev_direct_IO_own_locking(rw, iocb, inode,
-                       iomap.iomap_target->bt_bdev,
-                       iov, offset, nr_segs,
+                       bdev, iov, offset, nr_segs,
                        xfs_get_blocks_direct,
                        xfs_end_io_direct);
        } else {
                iocb->private = xfs_alloc_ioend(inode, IOMAP_READ);
                ret = blockdev_direct_IO_no_locking(rw, iocb, inode,
-                       iomap.iomap_target->bt_bdev,
-                       iov, offset, nr_segs,
+                       bdev, iov, offset, nr_segs,
                        xfs_get_blocks_direct,
                        xfs_end_io_direct);
        }
@@ -1512,13 +1512,18 @@ xfs_vm_direct_IO(
 }
 
 STATIC int
-xfs_vm_prepare_write(
+xfs_vm_write_begin(
        struct file             *file,
-       struct page             *page,
-       unsigned int            from,
-       unsigned int            to)
+       struct address_space    *mapping,
+       loff_t                  pos,
+       unsigned                len,
+       unsigned                flags,
+       struct page             **pagep,
+       void                    **fsdata)
 {
-       return block_prepare_write(page, from, to, xfs_get_blocks);
+       *pagep = NULL;
+       return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
+                                                               xfs_get_blocks);
 }
 
 STATIC sector_t
@@ -1529,11 +1534,10 @@ xfs_vm_bmap(
        struct inode            *inode = (struct inode *)mapping->host;
        struct xfs_inode        *ip = XFS_I(inode);
 
-       vn_trace_entry(vn_from_inode(inode), __FUNCTION__,
-                       (inst_t *)__return_address);
-       xfs_rwlock(ip, VRWLOCK_READ);
+       xfs_itrace_entry(XFS_I(inode));
+       xfs_ilock(ip, XFS_IOLOCK_SHARED);
        xfs_flush_pages(ip, (xfs_off_t)0, -1, 0, FI_REMAPF);
-       xfs_rwunlock(ip, VRWLOCK_READ);
+       xfs_iunlock(ip, XFS_IOLOCK_SHARED);
        return generic_block_bmap(mapping, block, xfs_get_blocks);
 }
 
@@ -1573,8 +1577,8 @@ const struct address_space_operations xfs_address_space_operations = {
        .sync_page              = block_sync_page,
        .releasepage            = xfs_vm_releasepage,
        .invalidatepage         = xfs_vm_invalidatepage,
-       .prepare_write          = xfs_vm_prepare_write,
-       .commit_write           = generic_commit_write,
+       .write_begin            = xfs_vm_write_begin,
+       .write_end              = generic_write_end,
        .bmap                   = xfs_vm_bmap,
        .direct_IO              = xfs_vm_direct_IO,
        .migratepage            = buffer_migrate_page,