ocfs2: use jbd2_inode dirty range scoping
authorJoseph Qi <joseph.qi@linux.alibaba.com>
Mon, 23 Sep 2019 22:33:08 +0000 (15:33 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 Sep 2019 22:54:07 +0000 (15:54 -0700)
6ba0e7dc64a5 ("jbd2: introduce jbd2_inode dirty range scoping") allow us
scoping each of the inode dirty ranges associated with a given
transaction, and ext4 already does this way.

Now let's also use the newly introduced jbd2_inode dirty range scoping to
prevent us from waiting forever when trying to complete a journal
transaction in ocfs2.

Link: http://lkml.kernel.org/r/1562977611-8412-1-git-send-email-joseph.qi@linux.alibaba.com
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Ross Zwisler <zwisler@google.com>
Reviewed-by: Changwei Ge <chge@linux.alibaba.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Joseph Qi <jiangqi903@gmail.com>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/alloc.c
fs/ocfs2/aops.c
fs/ocfs2/file.c
fs/ocfs2/journal.h

index 0c335b51043dcf922e7c71d66a532f424131037d..f5d2bd15e0cae0bf4313fd0f1a7811ba7c453bd6 100644 (file)
@@ -6792,6 +6792,8 @@ void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle,
                              struct page *page, int zero, u64 *phys)
 {
        int ret, partial = 0;
+       loff_t start_byte = ((loff_t)page->index << PAGE_SHIFT) + from;
+       loff_t length = to - from;
 
        ret = ocfs2_map_page_blocks(page, phys, inode, from, to, 0);
        if (ret)
@@ -6811,7 +6813,8 @@ void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle,
        if (ret < 0)
                mlog_errno(ret);
        else if (ocfs2_should_order_data(inode)) {
-               ret = ocfs2_jbd2_file_inode(handle, inode);
+               ret = ocfs2_jbd2_inode_add_write(handle, inode,
+                                                start_byte, length);
                if (ret < 0)
                        mlog_errno(ret);
        }
index a4c905d6b5755d81460ff413caf1a6fe6c955bb4..8de1c9d644f62ca203ad33d7b5cda3613309f866 100644 (file)
@@ -942,7 +942,8 @@ static void ocfs2_write_failure(struct inode *inode,
 
                if (tmppage && page_has_buffers(tmppage)) {
                        if (ocfs2_should_order_data(inode))
-                               ocfs2_jbd2_file_inode(wc->w_handle, inode);
+                               ocfs2_jbd2_inode_add_write(wc->w_handle, inode,
+                                                          user_pos, user_len);
 
                        block_commit_write(tmppage, from, to);
                }
@@ -2023,8 +2024,14 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
                }
 
                if (page_has_buffers(tmppage)) {
-                       if (handle && ocfs2_should_order_data(inode))
-                               ocfs2_jbd2_file_inode(handle, inode);
+                       if (handle && ocfs2_should_order_data(inode)) {
+                               loff_t start_byte =
+                                       ((loff_t)tmppage->index << PAGE_SHIFT) +
+                                       from;
+                               loff_t length = to - from;
+                               ocfs2_jbd2_inode_add_write(handle, inode,
+                                                          start_byte, length);
+                       }
                        block_commit_write(tmppage, from, to);
                }
        }
index 4435df3e5adb975fb15042d0c5892e5ff73b4281..efe9988a5be40edc9c1a6ff6b5bae26dbe7c8954 100644 (file)
@@ -706,7 +706,9 @@ leave:
  * Thus, we need to explicitly order the zeroed pages.
  */
 static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode,
-                                               struct buffer_head *di_bh)
+                                                     struct buffer_head *di_bh,
+                                                     loff_t start_byte,
+                                                     loff_t length)
 {
        struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
        handle_t *handle = NULL;
@@ -722,7 +724,7 @@ static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode,
                goto out;
        }
 
-       ret = ocfs2_jbd2_file_inode(handle, inode);
+       ret = ocfs2_jbd2_inode_add_write(handle, inode, start_byte, length);
        if (ret < 0) {
                mlog_errno(ret);
                goto out;
@@ -761,7 +763,9 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
        BUG_ON(abs_to > (((u64)index + 1) << PAGE_SHIFT));
        BUG_ON(abs_from & (inode->i_blkbits - 1));
 
-       handle = ocfs2_zero_start_ordered_transaction(inode, di_bh);
+       handle = ocfs2_zero_start_ordered_transaction(inode, di_bh,
+                                                     abs_from,
+                                                     abs_to - abs_from);
        if (IS_ERR(handle)) {
                ret = PTR_ERR(handle);
                goto out;
index c0fe6ed08ab12dd5715eb2b6f766152943602830..f37473c20a7b8d15b09e6911d96c85aa3f054c5e 100644 (file)
@@ -232,8 +232,8 @@ static inline void ocfs2_checkpoint_inode(struct inode *inode)
  *                          ocfs2_journal_access_*() unless you intend to
  *                          manage the checksum by hand.
  *  ocfs2_journal_dirty    - Mark a journalled buffer as having dirty data.
- *  ocfs2_jbd2_file_inode  - Mark an inode so that its data goes out before
- *                           the current handle commits.
+ *  ocfs2_jbd2_inode_add_write  - Mark an inode with range so that its data goes
+ *                                out before the current handle commits.
  */
 
 /* You must always start_trans with a number of buffs > 0, but it's
@@ -603,9 +603,12 @@ static inline int ocfs2_calc_tree_trunc_credits(struct super_block *sb,
        return credits;
 }
 
-static inline int ocfs2_jbd2_file_inode(handle_t *handle, struct inode *inode)
+static inline int ocfs2_jbd2_inode_add_write(handle_t *handle, struct inode *inode,
+                                            loff_t start_byte, loff_t length)
 {
-       return jbd2_journal_inode_add_write(handle, &OCFS2_I(inode)->ip_jinode);
+       return jbd2_journal_inode_ranged_write(handle,
+                                              &OCFS2_I(inode)->ip_jinode,
+                                              start_byte, length);
 }
 
 static inline int ocfs2_begin_ordered_truncate(struct inode *inode,