ocfs2: Optimize inode group allocation by recording last used group.
[safe/jmp/linux-2.6] / fs / ocfs2 / aops.c
index e219f8b..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>
@@ -226,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,
@@ -474,12 +475,6 @@ handle_t *ocfs2_start_walk_page_trans(struct inode *inode,
 
        if (ocfs2_should_order_data(inode)) {
                ret = ocfs2_jbd2_file_inode(handle, inode);
-#ifdef CONFIG_OCFS2_COMPAT_JBD
-               ret = walk_page_buffers(handle,
-                                       page_buffers(page),
-                                       from, to, NULL,
-                                       ocfs2_journal_dirty_data);
-#endif
                if (ret < 0)
                        mlog_errno(ret);
        }
@@ -1065,15 +1060,8 @@ static void ocfs2_write_failure(struct inode *inode,
                tmppage = wc->w_pages[i];
 
                if (page_has_buffers(tmppage)) {
-                       if (ocfs2_should_order_data(inode)) {
+                       if (ocfs2_should_order_data(inode))
                                ocfs2_jbd2_file_inode(wc->w_handle, inode);
-#ifdef CONFIG_OCFS2_COMPAT_JBD
-                               walk_page_buffers(wc->w_handle,
-                                                 page_buffers(tmppage),
-                                                 from, to, NULL,
-                                                 ocfs2_journal_dirty_data);
-#endif
-                       }
 
                        block_commit_write(tmppage, from, to);
                }
@@ -1524,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);
 
@@ -1567,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,
@@ -1599,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:
@@ -1743,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;
        }
 
        /*
@@ -1764,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)
@@ -1783,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);
 
@@ -1912,15 +1912,8 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
                }
 
                if (page_has_buffers(tmppage)) {
-                       if (ocfs2_should_order_data(inode)) {
+                       if (ocfs2_should_order_data(inode))
                                ocfs2_jbd2_file_inode(wc->w_handle, inode);
-#ifdef CONFIG_OCFS2_COMPAT_JBD
-                               walk_page_buffers(wc->w_handle,
-                                                 page_buffers(tmppage),
-                                                 from, to, NULL,
-                                                 ocfs2_journal_dirty_data);
-#endif
-                       }
                        block_commit_write(tmppage, from, to);
                }
        }