Lines Matching refs:journal
80 static void jbd2_get_transaction(journal_t *journal, in jbd2_get_transaction() argument
83 transaction->t_journal = journal; in jbd2_get_transaction()
86 transaction->t_tid = journal->j_transaction_sequence++; in jbd2_get_transaction()
87 transaction->t_expires = jiffies + journal->j_commit_interval; in jbd2_get_transaction()
90 journal->j_transaction_overhead_buffers + in jbd2_get_transaction()
91 atomic_read(&journal->j_reserved_credits)); in jbd2_get_transaction()
98 journal->j_commit_timer.expires = round_jiffies_up(transaction->t_expires); in jbd2_get_transaction()
99 add_timer(&journal->j_commit_timer); in jbd2_get_transaction()
101 J_ASSERT(journal->j_running_transaction == NULL); in jbd2_get_transaction()
102 journal->j_running_transaction = transaction; in jbd2_get_transaction()
142 static void wait_transaction_locked(journal_t *journal) in wait_transaction_locked() argument
143 __releases(journal->j_state_lock) in wait_transaction_locked()
147 tid_t tid = journal->j_running_transaction->t_tid; in wait_transaction_locked()
149 prepare_to_wait_exclusive(&journal->j_wait_transaction_locked, &wait, in wait_transaction_locked()
151 need_to_start = !tid_geq(journal->j_commit_request, tid); in wait_transaction_locked()
152 read_unlock(&journal->j_state_lock); in wait_transaction_locked()
154 jbd2_log_start_commit(journal, tid); in wait_transaction_locked()
155 jbd2_might_wait_for_commit(journal); in wait_transaction_locked()
157 finish_wait(&journal->j_wait_transaction_locked, &wait); in wait_transaction_locked()
165 static void wait_transaction_switching(journal_t *journal) in wait_transaction_switching() argument
166 __releases(journal->j_state_lock) in wait_transaction_switching()
170 if (WARN_ON(!journal->j_running_transaction || in wait_transaction_switching()
171 journal->j_running_transaction->t_state != T_SWITCH)) { in wait_transaction_switching()
172 read_unlock(&journal->j_state_lock); in wait_transaction_switching()
175 prepare_to_wait_exclusive(&journal->j_wait_transaction_locked, &wait, in wait_transaction_switching()
177 read_unlock(&journal->j_state_lock); in wait_transaction_switching()
185 finish_wait(&journal->j_wait_transaction_locked, &wait); in wait_transaction_switching()
188 static void sub_reserved_credits(journal_t *journal, int blocks) in sub_reserved_credits() argument
190 atomic_sub(blocks, &journal->j_reserved_credits); in sub_reserved_credits()
191 wake_up(&journal->j_wait_reserved); in sub_reserved_credits()
195 static int jbd2_max_user_trans_buffers(journal_t *journal) in jbd2_max_user_trans_buffers() argument
197 return journal->j_max_transaction_buffers - in jbd2_max_user_trans_buffers()
198 journal->j_transaction_overhead_buffers; in jbd2_max_user_trans_buffers()
212 static int add_transaction_credits(journal_t *journal, int blocks, in add_transaction_credits() argument
214 __must_hold(&journal->j_state_lock) in add_transaction_credits()
216 transaction_t *t = journal->j_running_transaction; in add_transaction_credits()
226 wait_transaction_locked(journal); in add_transaction_credits()
227 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
237 if (needed > journal->j_max_transaction_buffers) { in add_transaction_credits()
249 if (atomic_read(&journal->j_reserved_credits) + total > in add_transaction_credits()
250 jbd2_max_user_trans_buffers(journal)) { in add_transaction_credits()
251 read_unlock(&journal->j_state_lock); in add_transaction_credits()
252 jbd2_might_wait_for_commit(journal); in add_transaction_credits()
253 wait_event(journal->j_wait_reserved, in add_transaction_credits()
254 atomic_read(&journal->j_reserved_credits) + total <= in add_transaction_credits()
255 jbd2_max_user_trans_buffers(journal)); in add_transaction_credits()
256 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
260 wait_transaction_locked(journal); in add_transaction_credits()
261 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
276 if (jbd2_log_space_left(journal) < journal->j_max_transaction_buffers) { in add_transaction_credits()
278 read_unlock(&journal->j_state_lock); in add_transaction_credits()
279 jbd2_might_wait_for_commit(journal); in add_transaction_credits()
280 write_lock(&journal->j_state_lock); in add_transaction_credits()
281 if (jbd2_log_space_left(journal) < in add_transaction_credits()
282 journal->j_max_transaction_buffers) in add_transaction_credits()
283 __jbd2_log_wait_for_space(journal); in add_transaction_credits()
284 write_unlock(&journal->j_state_lock); in add_transaction_credits()
285 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
293 needed = atomic_add_return(rsv_blocks, &journal->j_reserved_credits); in add_transaction_credits()
295 if (needed > jbd2_max_user_trans_buffers(journal) / 2) { in add_transaction_credits()
296 sub_reserved_credits(journal, rsv_blocks); in add_transaction_credits()
298 read_unlock(&journal->j_state_lock); in add_transaction_credits()
299 jbd2_might_wait_for_commit(journal); in add_transaction_credits()
300 wait_event(journal->j_wait_reserved, in add_transaction_credits()
301 atomic_read(&journal->j_reserved_credits) + rsv_blocks in add_transaction_credits()
302 <= jbd2_max_user_trans_buffers(journal) / 2); in add_transaction_credits()
303 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
316 static int start_this_handle(journal_t *journal, handle_t *handle, in start_this_handle() argument
332 if (rsv_blocks > jbd2_max_user_trans_buffers(journal) / 2 || in start_this_handle()
333 rsv_blocks + blocks > jbd2_max_user_trans_buffers(journal)) { in start_this_handle()
337 jbd2_max_user_trans_buffers(journal)); in start_this_handle()
348 if (!data_race(journal->j_running_transaction)) { in start_this_handle()
368 read_lock(&journal->j_state_lock); in start_this_handle()
369 BUG_ON(journal->j_flags & JBD2_UNMOUNT); in start_this_handle()
370 if (is_journal_aborted(journal) || in start_this_handle()
371 (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) { in start_this_handle()
372 read_unlock(&journal->j_state_lock); in start_this_handle()
382 if (!handle->h_reserved && journal->j_barrier_count) { in start_this_handle()
383 read_unlock(&journal->j_state_lock); in start_this_handle()
384 wait_event(journal->j_wait_transaction_locked, in start_this_handle()
385 journal->j_barrier_count == 0); in start_this_handle()
389 if (!journal->j_running_transaction) { in start_this_handle()
390 read_unlock(&journal->j_state_lock); in start_this_handle()
393 write_lock(&journal->j_state_lock); in start_this_handle()
394 if (!journal->j_running_transaction && in start_this_handle()
395 (handle->h_reserved || !journal->j_barrier_count)) { in start_this_handle()
396 jbd2_get_transaction(journal, new_transaction); in start_this_handle()
399 write_unlock(&journal->j_state_lock); in start_this_handle()
403 transaction = journal->j_running_transaction; in start_this_handle()
407 if (add_transaction_credits(journal, blocks, rsv_blocks)) { in start_this_handle()
412 __release(&journal->j_state_lock); in start_this_handle()
424 wait_transaction_switching(journal); in start_this_handle()
427 sub_reserved_credits(journal, blocks); in start_this_handle()
444 jbd2_log_space_left(journal)); in start_this_handle()
445 read_unlock(&journal->j_state_lock); in start_this_handle()
448 rwsem_acquire_read(&journal->j_trans_commit_map, 0, 0, _THIS_IP_); in start_this_handle()
470 handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int rsv_blocks, in jbd2__journal_start() argument
477 if (!journal) in jbd2__journal_start()
481 J_ASSERT(handle->h_transaction->t_journal == journal); in jbd2__journal_start()
487 journal->j_revoke_records_per_block); in jbd2__journal_start()
500 rsv_handle->h_journal = journal; in jbd2__journal_start()
505 err = start_this_handle(journal, handle, gfp_mask); in jbd2__journal_start()
514 trace_jbd2_handle_start(journal->j_fs_dev->bd_dev, in jbd2__journal_start()
542 handle_t *jbd2_journal_start(journal_t *journal, int nblocks) in jbd2_journal_start() argument
544 return jbd2__journal_start(journal, nblocks, 0, 0, GFP_NOFS, 0, 0); in jbd2_journal_start()
550 journal_t *journal = handle->h_journal; in __jbd2_journal_unreserve_handle() local
553 sub_reserved_credits(journal, handle->h_total_credits); in __jbd2_journal_unreserve_handle()
560 journal_t *journal = handle->h_journal; in jbd2_journal_free_reserved() local
563 read_lock(&journal->j_state_lock); in jbd2_journal_free_reserved()
564 __jbd2_journal_unreserve_handle(handle, journal->j_running_transaction); in jbd2_journal_free_reserved()
565 read_unlock(&journal->j_state_lock); in jbd2_journal_free_reserved()
587 journal_t *journal = handle->h_journal; in jbd2_journal_start_reserved() local
609 ret = start_this_handle(journal, handle, GFP_NOFS); in jbd2_journal_start_reserved()
611 handle->h_journal = journal; in jbd2_journal_start_reserved()
617 trace_jbd2_handle_start(journal->j_fs_dev->bd_dev, in jbd2_journal_start_reserved()
648 journal_t *journal; in jbd2_journal_extend() local
654 journal = transaction->t_journal; in jbd2_journal_extend()
658 read_lock(&journal->j_state_lock); in jbd2_journal_extend()
669 journal->j_revoke_records_per_block) - in jbd2_journal_extend()
672 journal->j_revoke_records_per_block); in jbd2_journal_extend()
676 if (wanted > journal->j_max_transaction_buffers) { in jbd2_journal_extend()
683 trace_jbd2_handle_extend(journal->j_fs_dev->bd_dev, in jbd2_journal_extend()
697 read_unlock(&journal->j_state_lock); in jbd2_journal_extend()
704 journal_t *journal = transaction->t_journal; in stop_this_handle() local
719 int rr_per_blk = journal->j_revoke_records_per_block; in stop_this_handle()
736 wake_up(&journal->j_wait_updates); in stop_this_handle()
738 rwsem_release(&journal->j_trans_commit_map, _THIS_IP_); in stop_this_handle()
767 journal_t *journal; in jbd2__journal_restart() local
776 journal = transaction->t_journal; in jbd2__journal_restart()
791 read_lock(&journal->j_state_lock); in jbd2__journal_restart()
792 need_to_start = !tid_geq(journal->j_commit_request, tid); in jbd2__journal_restart()
793 read_unlock(&journal->j_state_lock); in jbd2__journal_restart()
795 jbd2_log_start_commit(journal, tid); in jbd2__journal_restart()
798 journal->j_revoke_records_per_block); in jbd2__journal_restart()
800 ret = start_this_handle(journal, handle, gfp_mask); in jbd2__journal_restart()
801 trace_jbd2_handle_restart(journal->j_fs_dev->bd_dev, in jbd2__journal_restart()
820 void jbd2_journal_wait_updates(journal_t *journal) in jbd2_journal_wait_updates() argument
835 transaction_t *transaction = journal->j_running_transaction; in jbd2_journal_wait_updates()
840 prepare_to_wait(&journal->j_wait_updates, &wait, in jbd2_journal_wait_updates()
843 finish_wait(&journal->j_wait_updates, &wait); in jbd2_journal_wait_updates()
846 write_unlock(&journal->j_state_lock); in jbd2_journal_wait_updates()
848 finish_wait(&journal->j_wait_updates, &wait); in jbd2_journal_wait_updates()
849 write_lock(&journal->j_state_lock); in jbd2_journal_wait_updates()
863 void jbd2_journal_lock_updates(journal_t *journal) in jbd2_journal_lock_updates() argument
865 jbd2_might_wait_for_commit(journal); in jbd2_journal_lock_updates()
867 write_lock(&journal->j_state_lock); in jbd2_journal_lock_updates()
868 ++journal->j_barrier_count; in jbd2_journal_lock_updates()
871 if (atomic_read(&journal->j_reserved_credits)) { in jbd2_journal_lock_updates()
872 write_unlock(&journal->j_state_lock); in jbd2_journal_lock_updates()
873 wait_event(journal->j_wait_reserved, in jbd2_journal_lock_updates()
874 atomic_read(&journal->j_reserved_credits) == 0); in jbd2_journal_lock_updates()
875 write_lock(&journal->j_state_lock); in jbd2_journal_lock_updates()
879 jbd2_journal_wait_updates(journal); in jbd2_journal_lock_updates()
881 write_unlock(&journal->j_state_lock); in jbd2_journal_lock_updates()
889 mutex_lock(&journal->j_barrier); in jbd2_journal_lock_updates()
900 void jbd2_journal_unlock_updates (journal_t *journal) in jbd2_journal_unlock_updates() argument
902 J_ASSERT(journal->j_barrier_count != 0); in jbd2_journal_unlock_updates()
904 mutex_unlock(&journal->j_barrier); in jbd2_journal_unlock_updates()
905 write_lock(&journal->j_state_lock); in jbd2_journal_unlock_updates()
906 --journal->j_barrier_count; in jbd2_journal_unlock_updates()
907 write_unlock(&journal->j_state_lock); in jbd2_journal_unlock_updates()
908 wake_up_all(&journal->j_wait_transaction_locked); in jbd2_journal_unlock_updates()
956 journal_t *journal; in do_get_write_access() local
961 journal = transaction->t_journal; in do_get_write_access()
1051 spin_lock(&journal->j_list_lock); in do_get_write_access()
1064 spin_unlock(&journal->j_list_lock); in do_get_write_access()
1082 J_ASSERT_JH(jh, jh->b_transaction == journal->j_committing_transaction); in do_get_write_access()
1219 journal_t *journal; in jbd2_journal_get_write_access() local
1225 journal = handle->h_transaction->t_journal; in jbd2_journal_get_write_access()
1226 if (jbd2_check_fs_dev_write_error(journal)) { in jbd2_journal_get_write_access()
1234 jbd2_journal_abort(journal, -EIO); in jbd2_journal_get_write_access()
1273 journal_t *journal; in jbd2_journal_get_create_access() local
1281 journal = transaction->t_journal; in jbd2_journal_get_create_access()
1295 (jh->b_transaction == journal->j_committing_transaction && in jbd2_journal_get_create_access()
1315 spin_lock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1317 spin_unlock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1318 } else if (jh->b_transaction == journal->j_committing_transaction) { in jbd2_journal_get_create_access()
1323 spin_lock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1325 spin_unlock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1488 journal_t *journal; in jbd2_journal_dirty_metadata() local
1535 journal = transaction->t_journal; in jbd2_journal_dirty_metadata()
1574 journal->j_running_transaction)) { in jbd2_journal_dirty_metadata()
1578 journal->j_devname, in jbd2_journal_dirty_metadata()
1582 journal->j_running_transaction, in jbd2_journal_dirty_metadata()
1583 journal->j_running_transaction ? in jbd2_journal_dirty_metadata()
1584 journal->j_running_transaction->t_tid : 0); in jbd2_journal_dirty_metadata()
1601 journal->j_committing_transaction)) || in jbd2_journal_dirty_metadata()
1608 journal->j_devname, in jbd2_journal_dirty_metadata()
1630 spin_lock(&journal->j_list_lock); in jbd2_journal_dirty_metadata()
1632 spin_unlock(&journal->j_list_lock); in jbd2_journal_dirty_metadata()
1660 journal_t *journal; in jbd2_journal_forget() local
1668 journal = transaction->t_journal; in jbd2_journal_forget()
1727 spin_lock(&journal->j_list_lock); in jbd2_journal_forget()
1735 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1738 journal->j_committing_transaction)); in jbd2_journal_forget()
1752 spin_lock(&journal->j_list_lock); in jbd2_journal_forget()
1754 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1771 spin_lock(&journal->j_list_lock); in jbd2_journal_forget()
1774 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1783 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1795 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1827 journal_t *journal; in jbd2_journal_stop() local
1847 journal = transaction->t_journal; in jbd2_journal_stop()
1854 trace_jbd2_handle_stats(journal->j_fs_dev->bd_dev, in jbd2_journal_stop()
1891 if (handle->h_sync && journal->j_last_sync_writer != pid && in jbd2_journal_stop()
1892 journal->j_max_batch_time) { in jbd2_journal_stop()
1895 journal->j_last_sync_writer = pid; in jbd2_journal_stop()
1897 read_lock(&journal->j_state_lock); in jbd2_journal_stop()
1898 commit_time = journal->j_average_commit_time; in jbd2_journal_stop()
1899 read_unlock(&journal->j_state_lock); in jbd2_journal_stop()
1905 1000*journal->j_min_batch_time); in jbd2_journal_stop()
1907 1000*journal->j_max_batch_time); in jbd2_journal_stop()
1934 jbd2_log_start_commit(journal, tid); in jbd2_journal_stop()
1953 err = jbd2_log_wait_commit(journal, tid); in jbd2_journal_stop()
2082 void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh) in jbd2_journal_unfile_buffer() argument
2089 spin_lock(&journal->j_list_lock); in jbd2_journal_unfile_buffer()
2091 spin_unlock(&journal->j_list_lock); in jbd2_journal_unfile_buffer()
2131 bool jbd2_journal_try_to_free_buffers(journal_t *journal, struct folio *folio) in jbd2_journal_try_to_free_buffers() argument
2155 spin_lock(&journal->j_list_lock); in jbd2_journal_try_to_free_buffers()
2159 spin_unlock(&journal->j_list_lock); in jbd2_journal_try_to_free_buffers()
2255 static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh, in journal_unmap_buffer() argument
2275 write_lock(&journal->j_state_lock); in journal_unmap_buffer()
2277 spin_lock(&journal->j_list_lock); in journal_unmap_buffer()
2323 if (journal->j_running_transaction) { in journal_unmap_buffer()
2329 journal->j_running_transaction); in journal_unmap_buffer()
2336 if (journal->j_committing_transaction) { in journal_unmap_buffer()
2339 journal->j_committing_transaction); in journal_unmap_buffer()
2349 } else if (transaction == journal->j_committing_transaction) { in journal_unmap_buffer()
2357 spin_unlock(&journal->j_list_lock); in journal_unmap_buffer()
2359 write_unlock(&journal->j_state_lock); in journal_unmap_buffer()
2374 if (journal->j_running_transaction && buffer_jbddirty(bh)) in journal_unmap_buffer()
2375 jh->b_next_transaction = journal->j_running_transaction; in journal_unmap_buffer()
2377 spin_unlock(&journal->j_list_lock); in journal_unmap_buffer()
2379 write_unlock(&journal->j_state_lock); in journal_unmap_buffer()
2389 J_ASSERT_JH(jh, transaction == journal->j_running_transaction); in journal_unmap_buffer()
2404 spin_unlock(&journal->j_list_lock); in journal_unmap_buffer()
2406 write_unlock(&journal->j_state_lock); in journal_unmap_buffer()
2432 int jbd2_journal_invalidate_folio(journal_t *journal, struct folio *folio, in jbd2_journal_invalidate_folio() argument
2465 ret = journal_unmap_buffer(journal, bh, partial_page); in jbd2_journal_invalidate_folio()
2631 void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh) in jbd2_journal_refile_buffer() argument
2636 spin_lock(&journal->j_list_lock); in jbd2_journal_refile_buffer()
2639 spin_unlock(&journal->j_list_lock); in jbd2_journal_refile_buffer()
2651 journal_t *journal; in jbd2_journal_file_inode() local
2655 journal = transaction->t_journal; in jbd2_journal_file_inode()
2660 spin_lock(&journal->j_list_lock); in jbd2_journal_file_inode()
2688 journal->j_committing_transaction); in jbd2_journal_file_inode()
2697 spin_unlock(&journal->j_list_lock); in jbd2_journal_file_inode()
2737 int jbd2_journal_begin_ordered_truncate(journal_t *journal, in jbd2_journal_begin_ordered_truncate() argument
2750 read_lock(&journal->j_state_lock); in jbd2_journal_begin_ordered_truncate()
2751 commit_trans = journal->j_committing_transaction; in jbd2_journal_begin_ordered_truncate()
2752 read_unlock(&journal->j_state_lock); in jbd2_journal_begin_ordered_truncate()
2753 spin_lock(&journal->j_list_lock); in jbd2_journal_begin_ordered_truncate()
2755 spin_unlock(&journal->j_list_lock); in jbd2_journal_begin_ordered_truncate()
2760 jbd2_journal_abort(journal, ret); in jbd2_journal_begin_ordered_truncate()