Skip to content

Commit 342af94

Browse files
Mauricio Faria de Oliveiratytso
authored andcommitted
jbd2, ext4, ocfs2: introduce/use journal callbacks j_submit|finish_inode_data_buffers()
Introduce journal callbacks to allow different behaviors for an inode in journal_submit|finish_inode_data_buffers(). The existing users of the current behavior (ext4, ocfs2) are adapted to use the previously exported functions that implement the current behavior. Users are callers of jbd2_journal_inode_ranged_write|wait(), which adds the inode to the transaction's inode list with the JI_WRITE|WAIT_DATA flags. Only ext4 and ocfs2 in-tree. Both CONFIG_EXT4_FS and CONFIG_OCSFS2_FS select CONFIG_JBD2, which builds fs/jbd2/commit.c and journal.c that define and export the functions, so we can call directly in ext4/ocfs2. Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com> Suggested-by: Jan Kara <jack@suse.cz> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Andreas Dilger <adilger@dilger.ca> Link: https://lore.kernel.org/r/20201006004841.600488-3-mfo@canonical.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent aa3c0c6 commit 342af94

4 files changed

Lines changed: 50 additions & 13 deletions

File tree

‎fs/ext4/super.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,6 +4752,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
47524752
set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
47534753

47544754
sbi->s_journal->j_commit_callback = ext4_journal_commit_callback;
4755+
sbi->s_journal->j_submit_inode_data_buffers =
4756+
jbd2_journal_submit_inode_data_buffers;
4757+
sbi->s_journal->j_finish_inode_data_buffers =
4758+
jbd2_journal_finish_inode_data_buffers;
47554759

47564760
no_journal:
47574761
if (!test_opt(sb, NO_MBCACHE)) {

‎fs/jbd2/commit.c‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ int jbd2_journal_submit_inode_data_buffers(struct jbd2_inode *jinode)
197197
.range_end = jinode->i_dirty_end,
198198
};
199199

200+
/*
201+
* submit the inode data buffers. We use writepage
202+
* instead of writepages. Because writepages can do
203+
* block allocation with delalloc. We need to write
204+
* only allocated blocks here.
205+
*/
200206
return generic_writepages(mapping, &wbc);
201207
}
202208

@@ -220,16 +226,13 @@ static int journal_submit_data_buffers(journal_t *journal,
220226
continue;
221227
jinode->i_flags |= JI_COMMIT_RUNNING;
222228
spin_unlock(&journal->j_list_lock);
223-
/*
224-
* submit the inode data buffers. We use writepage
225-
* instead of writepages. Because writepages can do
226-
* block allocation with delalloc. We need to write
227-
* only allocated blocks here.
228-
*/
229+
/* submit the inode data buffers. */
229230
trace_jbd2_submit_inode_data(jinode->i_vfs_inode);
230-
err = jbd2_journal_submit_inode_data_buffers(jinode);
231-
if (!ret)
232-
ret = err;
231+
if (journal->j_submit_inode_data_buffers) {
232+
err = journal->j_submit_inode_data_buffers(jinode);
233+
if (!ret)
234+
ret = err;
235+
}
233236
spin_lock(&journal->j_list_lock);
234237
J_ASSERT(jinode->i_transaction == commit_transaction);
235238
jinode->i_flags &= ~JI_COMMIT_RUNNING;
@@ -267,9 +270,12 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
267270
continue;
268271
jinode->i_flags |= JI_COMMIT_RUNNING;
269272
spin_unlock(&journal->j_list_lock);
270-
err = jbd2_journal_finish_inode_data_buffers(jinode);
271-
if (!ret)
272-
ret = err;
273+
/* wait for the inode data buffers writeout. */
274+
if (journal->j_finish_inode_data_buffers) {
275+
err = journal->j_finish_inode_data_buffers(jinode);
276+
if (!ret)
277+
ret = err;
278+
}
273279
spin_lock(&journal->j_list_lock);
274280
jinode->i_flags &= ~JI_COMMIT_RUNNING;
275281
smp_mb();

‎fs/ocfs2/journal.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty)
883883
OCFS2_JOURNAL_DIRTY_FL);
884884

885885
journal->j_journal = j_journal;
886+
journal->j_journal->j_submit_inode_data_buffers =
887+
jbd2_journal_submit_inode_data_buffers;
888+
journal->j_journal->j_finish_inode_data_buffers =
889+
jbd2_journal_finish_inode_data_buffers;
886890
journal->j_inode = inode;
887891
journal->j_bh = bh;
888892

‎include/linux/jbd2.h‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,9 @@ struct transaction_s
629629
struct journal_head *t_shadow_list;
630630

631631
/*
632-
* List of inodes whose data we've modified in data=ordered mode.
632+
* List of inodes associated with the transaction; e.g., ext4 uses
633+
* this to track inodes in data=ordered and data=journal mode that
634+
* need special handling on transaction commit; also used by ocfs2.
633635
* [j_list_lock]
634636
*/
635637
struct list_head t_inode_list;
@@ -1111,6 +1113,27 @@ struct journal_s
11111113
void (*j_commit_callback)(journal_t *,
11121114
transaction_t *);
11131115

1116+
/**
1117+
* @j_submit_inode_data_buffers:
1118+
*
1119+
* This function is called for all inodes associated with the
1120+
* committing transaction marked with JI_WRITE_DATA flag
1121+
* before we start to write out the transaction to the journal.
1122+
*/
1123+
int (*j_submit_inode_data_buffers)
1124+
(struct jbd2_inode *);
1125+
1126+
/**
1127+
* @j_finish_inode_data_buffers:
1128+
*
1129+
* This function is called for all inodes associated with the
1130+
* committing transaction marked with JI_WAIT_DATA flag
1131+
* after we have written the transaction to the journal
1132+
* but before we write out the commit block.
1133+
*/
1134+
int (*j_finish_inode_data_buffers)
1135+
(struct jbd2_inode *);
1136+
11141137
/*
11151138
* Journal statistics
11161139
*/

0 commit comments

Comments
 (0)