Skip to content

Commit bbd2be3

Browse files
jankaratytso
authored andcommitted
jbd2: Add function jbd2_trans_will_send_data_barrier()
Provide a function which returns whether a transaction with given tid will send a flush to the filesystem device. The function will be used by ext4 to detect whether fsync needs to send a separate flush or not. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 81be12c commit bbd2be3

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

‎fs/jbd2/commit.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)
677677
err = 0;
678678
}
679679

680+
write_lock(&journal->j_state_lock);
681+
J_ASSERT(commit_transaction->t_state == T_COMMIT);
682+
commit_transaction->t_state = T_COMMIT_DFLUSH;
683+
write_unlock(&journal->j_state_lock);
680684
/*
681685
* If the journal is not located on the file system device,
682686
* then we must flush the file system device before we issue
@@ -804,6 +808,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)
804808
jbd2_journal_abort(journal, err);
805809

806810
jbd_debug(3, "JBD: commit phase 5\n");
811+
write_lock(&journal->j_state_lock);
812+
J_ASSERT(commit_transaction->t_state == T_COMMIT_DFLUSH);
813+
commit_transaction->t_state = T_COMMIT_JFLUSH;
814+
write_unlock(&journal->j_state_lock);
807815

808816
if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
809817
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
@@ -959,7 +967,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
959967

960968
jbd_debug(3, "JBD: commit phase 7\n");
961969

962-
J_ASSERT(commit_transaction->t_state == T_COMMIT);
970+
J_ASSERT(commit_transaction->t_state == T_COMMIT_JFLUSH);
963971

964972
commit_transaction->t_start = jiffies;
965973
stats.run.rs_logging = jbd2_time_diff(stats.run.rs_logging,

‎fs/jbd2/journal.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,47 @@ int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
587587
return ret;
588588
}
589589

590+
/*
591+
* Return 1 if a given transaction has not yet sent barrier request
592+
* connected with a transaction commit. If 0 is returned, transaction
593+
* may or may not have sent the barrier. Used to avoid sending barrier
594+
* twice in common cases.
595+
*/
596+
int jbd2_trans_will_send_data_barrier(journal_t *journal, tid_t tid)
597+
{
598+
int ret = 0;
599+
transaction_t *commit_trans;
600+
601+
if (!(journal->j_flags & JBD2_BARRIER))
602+
return 0;
603+
read_lock(&journal->j_state_lock);
604+
/* Transaction already committed? */
605+
if (tid_geq(journal->j_commit_sequence, tid))
606+
goto out;
607+
commit_trans = journal->j_committing_transaction;
608+
if (!commit_trans || commit_trans->t_tid != tid) {
609+
ret = 1;
610+
goto out;
611+
}
612+
/*
613+
* Transaction is being committed and we already proceeded to
614+
* submitting a flush to fs partition?
615+
*/
616+
if (journal->j_fs_dev != journal->j_dev) {
617+
if (!commit_trans->t_need_data_flush ||
618+
commit_trans->t_state >= T_COMMIT_DFLUSH)
619+
goto out;
620+
} else {
621+
if (commit_trans->t_state >= T_COMMIT_JFLUSH)
622+
goto out;
623+
}
624+
ret = 1;
625+
out:
626+
read_unlock(&journal->j_state_lock);
627+
return ret;
628+
}
629+
EXPORT_SYMBOL(jbd2_trans_will_send_data_barrier);
630+
590631
/*
591632
* Wait for a specified commit to complete.
592633
* The caller may not hold the journal lock.

‎include/linux/jbd2.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,10 @@ struct transaction_s
529529
enum {
530530
T_RUNNING,
531531
T_LOCKED,
532-
T_RUNDOWN,
533532
T_FLUSH,
534533
T_COMMIT,
534+
T_COMMIT_DFLUSH,
535+
T_COMMIT_JFLUSH,
535536
T_FINISHED
536537
} t_state;
537538

@@ -1230,6 +1231,7 @@ int jbd2_journal_start_commit(journal_t *journal, tid_t *tid);
12301231
int jbd2_journal_force_commit_nested(journal_t *journal);
12311232
int jbd2_log_wait_commit(journal_t *journal, tid_t tid);
12321233
int jbd2_log_do_checkpoint(journal_t *journal);
1234+
int jbd2_trans_will_send_data_barrier(journal_t *journal, tid_t tid);
12331235

12341236
void __jbd2_log_wait_for_space(journal_t *journal);
12351237
extern void __jbd2_journal_drop_transaction(journal_t *, transaction_t *);

0 commit comments

Comments
 (0)