ocfs2: Optimize inode group allocation by recording last used group.
[safe/jmp/linux-2.6] / fs / ocfs2 / aops.c
index e7acd28..8e1709a 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/swap.h>
 #include <linux/pipe_fs_i.h>
 #include <linux/mpage.h>
+#include <linux/quotaops.h>
 
 #define MLOG_MASK_PREFIX ML_FILE_IO
 #include <cluster/masklog.h>
@@ -68,22 +69,13 @@ static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
                goto bail;
        }
 
-       status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
-                                 OCFS2_I(inode)->ip_blkno,
-                                 &bh, OCFS2_BH_CACHED, inode);
+       status = ocfs2_read_inode_block(inode, &bh);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
        }
        fe = (struct ocfs2_dinode *) bh->b_data;
 
-       if (!OCFS2_IS_VALID_DINODE(fe)) {
-               mlog(ML_ERROR, "Invalid dinode #%llu: signature = %.*s\n",
-                    (unsigned long long)le64_to_cpu(fe->i_blkno), 7,
-                    fe->i_signature);
-               goto bail;
-       }
-
        if ((u64)iblock >= ocfs2_clusters_to_blocks(inode->i_sb,
                                                    le32_to_cpu(fe->i_clusters))) {
                mlog(ML_ERROR, "block offset is outside the allocated size: "
@@ -128,8 +120,7 @@ static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
        err = 0;
 
 bail:
-       if (bh)
-               brelse(bh);
+       brelse(bh);
 
        mlog_exit(err);
        return err;
@@ -236,7 +227,7 @@ int ocfs2_read_inline_data(struct inode *inode, struct page *page,
        size = i_size_read(inode);
 
        if (size > PAGE_CACHE_SIZE ||
-           size > ocfs2_max_inline_data(inode->i_sb)) {
+           size > ocfs2_max_inline_data_with_xattr(inode->i_sb, di)) {
                ocfs2_error(inode->i_sb,
                            "Inode %llu has with inline data has bad size: %Lu",
                            (unsigned long long)OCFS2_I(inode)->ip_blkno,
@@ -261,13 +252,11 @@ static int ocfs2_readpage_inline(struct inode *inode, struct page *page)
 {
        int ret;
        struct buffer_head *di_bh = NULL;
-       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
 
        BUG_ON(!PageLocked(page));
        BUG_ON(!(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL));
 
-       ret = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, &di_bh,
-                              OCFS2_BH_CACHED, inode);
+       ret = ocfs2_read_inode_block(inode, &di_bh);
        if (ret) {
                mlog_errno(ret);
                goto out;
@@ -485,11 +474,8 @@ handle_t *ocfs2_start_walk_page_trans(struct inode *inode,
        }
 
        if (ocfs2_should_order_data(inode)) {
-               ret = walk_page_buffers(handle,
-                                       page_buffers(page),
-                                       from, to, NULL,
-                                       ocfs2_journal_dirty_data);
-               if (ret < 0) 
+               ret = ocfs2_jbd2_file_inode(handle, inode);
+               if (ret < 0)
                        mlog_errno(ret);
        }
 out:
@@ -669,7 +655,7 @@ static void ocfs2_invalidatepage(struct page *page, unsigned long offset)
 {
        journal_t *journal = OCFS2_SB(page->mapping->host->i_sb)->journal->j_journal;
 
-       journal_invalidatepage(journal, page, offset);
+       jbd2_journal_invalidatepage(journal, page, offset);
 }
 
 static int ocfs2_releasepage(struct page *page, gfp_t wait)
@@ -678,7 +664,7 @@ static int ocfs2_releasepage(struct page *page, gfp_t wait)
 
        if (!page_has_buffers(page))
                return 0;
-       return journal_try_to_free_buffers(journal, page, wait);
+       return jbd2_journal_try_to_free_buffers(journal, page, wait);
 }
 
 static ssize_t ocfs2_direct_IO(int rw,
@@ -1075,10 +1061,7 @@ static void ocfs2_write_failure(struct inode *inode,
 
                if (page_has_buffers(tmppage)) {
                        if (ocfs2_should_order_data(inode))
-                               walk_page_buffers(wc->w_handle,
-                                                 page_buffers(tmppage),
-                                                 from, to, NULL,
-                                                 ocfs2_journal_dirty_data);
+                               ocfs2_jbd2_file_inode(wc->w_handle, inode);
 
                        block_commit_write(tmppage, from, to);
                }
@@ -1242,6 +1225,7 @@ static int ocfs2_write_cluster(struct address_space *mapping,
        int ret, i, new, should_zero = 0;
        u64 v_blkno, p_blkno;
        struct inode *inode = mapping->host;
+       struct ocfs2_extent_tree et;
 
        new = phys == 0 ? 1 : 0;
        if (new || unwritten)
@@ -1276,10 +1260,10 @@ static int ocfs2_write_cluster(struct address_space *mapping,
                        goto out;
                }
        } else if (unwritten) {
-               ret = ocfs2_mark_extent_written(inode, wc->w_di_bh,
+               ocfs2_init_dinode_extent_tree(&et, inode, wc->w_di_bh);
+               ret = ocfs2_mark_extent_written(inode, &et,
                                                wc->w_handle, cpos, 1, phys,
-                                               meta_ac, &wc->w_dealloc,
-                                               OCFS2_DINODE_EXTENT);
+                                               meta_ac, &wc->w_dealloc);
                if (ret < 0) {
                        mlog_errno(ret);
                        goto out;
@@ -1528,8 +1512,8 @@ static int ocfs2_write_begin_inline(struct address_space *mapping,
                goto out;
        }
 
-       ret = ocfs2_journal_access(handle, inode, wc->w_di_bh,
-                                  OCFS2_JOURNAL_ACCESS_WRITE);
+       ret = ocfs2_journal_access_di(handle, inode, wc->w_di_bh,
+                                     OCFS2_JOURNAL_ACCESS_WRITE);
        if (ret) {
                ocfs2_commit_trans(osb, handle);
 
@@ -1571,6 +1555,7 @@ static int ocfs2_try_to_write_inline_data(struct address_space *mapping,
        int ret, written = 0;
        loff_t end = pos + len;
        struct ocfs2_inode_info *oi = OCFS2_I(inode);
+       struct ocfs2_dinode *di = NULL;
 
        mlog(0, "Inode %llu, write of %u bytes at off %llu. features: 0x%x\n",
             (unsigned long long)oi->ip_blkno, len, (unsigned long long)pos,
@@ -1603,7 +1588,9 @@ static int ocfs2_try_to_write_inline_data(struct address_space *mapping,
        /*
         * Check whether the write can fit.
         */
-       if (mmap_page || end > ocfs2_max_inline_data(inode->i_sb))
+       di = (struct ocfs2_dinode *)wc->w_di_bh->b_data;
+       if (mmap_page ||
+           end > ocfs2_max_inline_data_with_xattr(inode->i_sb, di))
                return 0;
 
 do_inline_write:
@@ -1666,6 +1653,7 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
        struct ocfs2_alloc_context *data_ac = NULL;
        struct ocfs2_alloc_context *meta_ac = NULL;
        handle_t *handle;
+       struct ocfs2_extent_tree et;
 
        ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh);
        if (ret) {
@@ -1719,7 +1707,8 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
                     (long long)i_size_read(inode), le32_to_cpu(di->i_clusters),
                     clusters_to_alloc, extents_to_split);
 
-               ret = ocfs2_lock_allocators(inode, wc->w_di_bh, &di->id2.i_list,
+               ocfs2_init_dinode_extent_tree(&et, inode, wc->w_di_bh);
+               ret = ocfs2_lock_allocators(inode, &et,
                                            clusters_to_alloc, extents_to_split,
                                            &data_ac, &meta_ac);
                if (ret) {
@@ -1745,15 +1734,20 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
 
        wc->w_handle = handle;
 
+       if (clusters_to_alloc && vfs_dq_alloc_space_nodirty(inode,
+                       ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc))) {
+               ret = -EDQUOT;
+               goto out_commit;
+       }
        /*
         * We don't want this to fail in ocfs2_write_end(), so do it
         * here.
         */
-       ret = ocfs2_journal_access(handle, inode, wc->w_di_bh,
-                                  OCFS2_JOURNAL_ACCESS_WRITE);
+       ret = ocfs2_journal_access_di(handle, inode, wc->w_di_bh,
+                                     OCFS2_JOURNAL_ACCESS_WRITE);
        if (ret) {
                mlog_errno(ret);
-               goto out_commit;
+               goto out_quota;
        }
 
        /*
@@ -1766,14 +1760,14 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
                                         mmap_page);
        if (ret) {
                mlog_errno(ret);
-               goto out_commit;
+               goto out_quota;
        }
 
        ret = ocfs2_write_cluster_by_desc(mapping, data_ac, meta_ac, wc, pos,
                                          len);
        if (ret) {
                mlog_errno(ret);
-               goto out_commit;
+               goto out_quota;
        }
 
        if (data_ac)
@@ -1785,6 +1779,10 @@ success:
        *pagep = wc->w_target_page;
        *fsdata = wc;
        return 0;
+out_quota:
+       if (clusters_to_alloc)
+               vfs_dq_free_space(inode,
+                         ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc));
 out_commit:
        ocfs2_commit_trans(osb, handle);
 
@@ -1915,10 +1913,7 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
 
                if (page_has_buffers(tmppage)) {
                        if (ocfs2_should_order_data(inode))
-                               walk_page_buffers(wc->w_handle,
-                                                 page_buffers(tmppage),
-                                                 from, to, NULL,
-                                                 ocfs2_journal_dirty_data);
+                               ocfs2_jbd2_file_inode(wc->w_handle, inode);
                        block_commit_write(tmppage, from, to);
                }
        }