Lines Matching refs:journal
68 static int jbd2_descriptor_blocks_per_trans(journal_t *journal) in jbd2_descriptor_blocks_per_trans() argument
70 int tag_space = journal->j_blocksize - sizeof(journal_header_t); in jbd2_descriptor_blocks_per_trans()
75 if (jbd2_journal_has_csum_v2or3(journal)) in jbd2_descriptor_blocks_per_trans()
78 tags_per_block = (tag_space - 16) / journal_tag_bytes(journal); in jbd2_descriptor_blocks_per_trans()
83 return 1 + DIV_ROUND_UP(journal->j_max_transaction_buffers, in jbd2_descriptor_blocks_per_trans()
102 static void jbd2_get_transaction(journal_t *journal, in jbd2_get_transaction() argument
105 transaction->t_journal = journal; in jbd2_get_transaction()
108 transaction->t_tid = journal->j_transaction_sequence++; in jbd2_get_transaction()
109 transaction->t_expires = jiffies + journal->j_commit_interval; in jbd2_get_transaction()
112 jbd2_descriptor_blocks_per_trans(journal) + in jbd2_get_transaction()
113 atomic_read(&journal->j_reserved_credits)); in jbd2_get_transaction()
120 journal->j_commit_timer.expires = round_jiffies_up(transaction->t_expires); in jbd2_get_transaction()
121 add_timer(&journal->j_commit_timer); in jbd2_get_transaction()
123 J_ASSERT(journal->j_running_transaction == NULL); in jbd2_get_transaction()
124 journal->j_running_transaction = transaction; in jbd2_get_transaction()
164 static void wait_transaction_locked(journal_t *journal) in wait_transaction_locked() argument
165 __releases(journal->j_state_lock) in wait_transaction_locked()
169 tid_t tid = journal->j_running_transaction->t_tid; in wait_transaction_locked()
171 prepare_to_wait_exclusive(&journal->j_wait_transaction_locked, &wait, in wait_transaction_locked()
173 need_to_start = !tid_geq(journal->j_commit_request, tid); in wait_transaction_locked()
174 read_unlock(&journal->j_state_lock); in wait_transaction_locked()
176 jbd2_log_start_commit(journal, tid); in wait_transaction_locked()
177 jbd2_might_wait_for_commit(journal); in wait_transaction_locked()
179 finish_wait(&journal->j_wait_transaction_locked, &wait); in wait_transaction_locked()
187 static void wait_transaction_switching(journal_t *journal) in wait_transaction_switching() argument
188 __releases(journal->j_state_lock) in wait_transaction_switching()
192 if (WARN_ON(!journal->j_running_transaction || in wait_transaction_switching()
193 journal->j_running_transaction->t_state != T_SWITCH)) { in wait_transaction_switching()
194 read_unlock(&journal->j_state_lock); in wait_transaction_switching()
197 prepare_to_wait_exclusive(&journal->j_wait_transaction_locked, &wait, in wait_transaction_switching()
199 read_unlock(&journal->j_state_lock); in wait_transaction_switching()
207 finish_wait(&journal->j_wait_transaction_locked, &wait); in wait_transaction_switching()
210 static void sub_reserved_credits(journal_t *journal, int blocks) in sub_reserved_credits() argument
212 atomic_sub(blocks, &journal->j_reserved_credits); in sub_reserved_credits()
213 wake_up(&journal->j_wait_reserved); in sub_reserved_credits()
227 static int add_transaction_credits(journal_t *journal, int blocks, in add_transaction_credits() argument
229 __must_hold(&journal->j_state_lock) in add_transaction_credits()
231 transaction_t *t = journal->j_running_transaction; in add_transaction_credits()
241 wait_transaction_locked(journal); in add_transaction_credits()
242 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
252 if (needed > journal->j_max_transaction_buffers) { in add_transaction_credits()
264 if (atomic_read(&journal->j_reserved_credits) + total > in add_transaction_credits()
265 journal->j_max_transaction_buffers) { in add_transaction_credits()
266 read_unlock(&journal->j_state_lock); in add_transaction_credits()
267 jbd2_might_wait_for_commit(journal); in add_transaction_credits()
268 wait_event(journal->j_wait_reserved, in add_transaction_credits()
269 atomic_read(&journal->j_reserved_credits) + total <= in add_transaction_credits()
270 journal->j_max_transaction_buffers); in add_transaction_credits()
271 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
275 wait_transaction_locked(journal); in add_transaction_credits()
276 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
291 if (jbd2_log_space_left(journal) < journal->j_max_transaction_buffers) { in add_transaction_credits()
293 read_unlock(&journal->j_state_lock); in add_transaction_credits()
294 jbd2_might_wait_for_commit(journal); in add_transaction_credits()
295 write_lock(&journal->j_state_lock); in add_transaction_credits()
296 if (jbd2_log_space_left(journal) < in add_transaction_credits()
297 journal->j_max_transaction_buffers) in add_transaction_credits()
298 __jbd2_log_wait_for_space(journal); in add_transaction_credits()
299 write_unlock(&journal->j_state_lock); in add_transaction_credits()
300 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
308 needed = atomic_add_return(rsv_blocks, &journal->j_reserved_credits); in add_transaction_credits()
310 if (needed > journal->j_max_transaction_buffers / 2) { in add_transaction_credits()
311 sub_reserved_credits(journal, rsv_blocks); in add_transaction_credits()
313 read_unlock(&journal->j_state_lock); in add_transaction_credits()
314 jbd2_might_wait_for_commit(journal); in add_transaction_credits()
315 wait_event(journal->j_wait_reserved, in add_transaction_credits()
316 atomic_read(&journal->j_reserved_credits) + rsv_blocks in add_transaction_credits()
317 <= journal->j_max_transaction_buffers / 2); in add_transaction_credits()
318 __acquire(&journal->j_state_lock); /* fake out sparse */ in add_transaction_credits()
331 static int start_this_handle(journal_t *journal, handle_t *handle, in start_this_handle() argument
347 if ((rsv_blocks > journal->j_max_transaction_buffers / 2) || in start_this_handle()
348 (rsv_blocks + blocks > journal->j_max_transaction_buffers)) { in start_this_handle()
352 journal->j_max_transaction_buffers); in start_this_handle()
363 if (!data_race(journal->j_running_transaction)) { in start_this_handle()
383 read_lock(&journal->j_state_lock); in start_this_handle()
384 BUG_ON(journal->j_flags & JBD2_UNMOUNT); in start_this_handle()
385 if (is_journal_aborted(journal) || in start_this_handle()
386 (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) { in start_this_handle()
387 read_unlock(&journal->j_state_lock); in start_this_handle()
397 if (!handle->h_reserved && journal->j_barrier_count) { in start_this_handle()
398 read_unlock(&journal->j_state_lock); in start_this_handle()
399 wait_event(journal->j_wait_transaction_locked, in start_this_handle()
400 journal->j_barrier_count == 0); in start_this_handle()
404 if (!journal->j_running_transaction) { in start_this_handle()
405 read_unlock(&journal->j_state_lock); in start_this_handle()
408 write_lock(&journal->j_state_lock); in start_this_handle()
409 if (!journal->j_running_transaction && in start_this_handle()
410 (handle->h_reserved || !journal->j_barrier_count)) { in start_this_handle()
411 jbd2_get_transaction(journal, new_transaction); in start_this_handle()
414 write_unlock(&journal->j_state_lock); in start_this_handle()
418 transaction = journal->j_running_transaction; in start_this_handle()
422 if (add_transaction_credits(journal, blocks, rsv_blocks)) { in start_this_handle()
427 __release(&journal->j_state_lock); in start_this_handle()
439 wait_transaction_switching(journal); in start_this_handle()
442 sub_reserved_credits(journal, blocks); in start_this_handle()
459 jbd2_log_space_left(journal)); in start_this_handle()
460 read_unlock(&journal->j_state_lock); in start_this_handle()
463 rwsem_acquire_read(&journal->j_trans_commit_map, 0, 0, _THIS_IP_); in start_this_handle()
485 handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int rsv_blocks, in jbd2__journal_start() argument
492 if (!journal) in jbd2__journal_start()
496 J_ASSERT(handle->h_transaction->t_journal == journal); in jbd2__journal_start()
502 journal->j_revoke_records_per_block); in jbd2__journal_start()
515 rsv_handle->h_journal = journal; in jbd2__journal_start()
520 err = start_this_handle(journal, handle, gfp_mask); in jbd2__journal_start()
529 trace_jbd2_handle_start(journal->j_fs_dev->bd_dev, in jbd2__journal_start()
557 handle_t *jbd2_journal_start(journal_t *journal, int nblocks) in jbd2_journal_start() argument
559 return jbd2__journal_start(journal, nblocks, 0, 0, GFP_NOFS, 0, 0); in jbd2_journal_start()
565 journal_t *journal = handle->h_journal; in __jbd2_journal_unreserve_handle() local
568 sub_reserved_credits(journal, handle->h_total_credits); in __jbd2_journal_unreserve_handle()
575 journal_t *journal = handle->h_journal; in jbd2_journal_free_reserved() local
578 read_lock(&journal->j_state_lock); in jbd2_journal_free_reserved()
579 __jbd2_journal_unreserve_handle(handle, journal->j_running_transaction); in jbd2_journal_free_reserved()
580 read_unlock(&journal->j_state_lock); in jbd2_journal_free_reserved()
602 journal_t *journal = handle->h_journal; in jbd2_journal_start_reserved() local
624 ret = start_this_handle(journal, handle, GFP_NOFS); in jbd2_journal_start_reserved()
626 handle->h_journal = journal; in jbd2_journal_start_reserved()
632 trace_jbd2_handle_start(journal->j_fs_dev->bd_dev, in jbd2_journal_start_reserved()
663 journal_t *journal; in jbd2_journal_extend() local
669 journal = transaction->t_journal; in jbd2_journal_extend()
673 read_lock(&journal->j_state_lock); in jbd2_journal_extend()
684 journal->j_revoke_records_per_block) - in jbd2_journal_extend()
687 journal->j_revoke_records_per_block); in jbd2_journal_extend()
691 if (wanted > journal->j_max_transaction_buffers) { in jbd2_journal_extend()
698 trace_jbd2_handle_extend(journal->j_fs_dev->bd_dev, in jbd2_journal_extend()
712 read_unlock(&journal->j_state_lock); in jbd2_journal_extend()
719 journal_t *journal = transaction->t_journal; in stop_this_handle() local
734 int rr_per_blk = journal->j_revoke_records_per_block; in stop_this_handle()
751 wake_up(&journal->j_wait_updates); in stop_this_handle()
753 rwsem_release(&journal->j_trans_commit_map, _THIS_IP_); in stop_this_handle()
782 journal_t *journal; in jbd2__journal_restart() local
791 journal = transaction->t_journal; in jbd2__journal_restart()
806 read_lock(&journal->j_state_lock); in jbd2__journal_restart()
807 need_to_start = !tid_geq(journal->j_commit_request, tid); in jbd2__journal_restart()
808 read_unlock(&journal->j_state_lock); in jbd2__journal_restart()
810 jbd2_log_start_commit(journal, tid); in jbd2__journal_restart()
813 journal->j_revoke_records_per_block); in jbd2__journal_restart()
815 ret = start_this_handle(journal, handle, gfp_mask); in jbd2__journal_restart()
816 trace_jbd2_handle_restart(journal->j_fs_dev->bd_dev, in jbd2__journal_restart()
835 void jbd2_journal_wait_updates(journal_t *journal) in jbd2_journal_wait_updates() argument
850 transaction_t *transaction = journal->j_running_transaction; in jbd2_journal_wait_updates()
855 prepare_to_wait(&journal->j_wait_updates, &wait, in jbd2_journal_wait_updates()
858 finish_wait(&journal->j_wait_updates, &wait); in jbd2_journal_wait_updates()
861 write_unlock(&journal->j_state_lock); in jbd2_journal_wait_updates()
863 finish_wait(&journal->j_wait_updates, &wait); in jbd2_journal_wait_updates()
864 write_lock(&journal->j_state_lock); in jbd2_journal_wait_updates()
878 void jbd2_journal_lock_updates(journal_t *journal) in jbd2_journal_lock_updates() argument
880 jbd2_might_wait_for_commit(journal); in jbd2_journal_lock_updates()
882 write_lock(&journal->j_state_lock); in jbd2_journal_lock_updates()
883 ++journal->j_barrier_count; in jbd2_journal_lock_updates()
886 if (atomic_read(&journal->j_reserved_credits)) { in jbd2_journal_lock_updates()
887 write_unlock(&journal->j_state_lock); in jbd2_journal_lock_updates()
888 wait_event(journal->j_wait_reserved, in jbd2_journal_lock_updates()
889 atomic_read(&journal->j_reserved_credits) == 0); in jbd2_journal_lock_updates()
890 write_lock(&journal->j_state_lock); in jbd2_journal_lock_updates()
894 jbd2_journal_wait_updates(journal); in jbd2_journal_lock_updates()
896 write_unlock(&journal->j_state_lock); in jbd2_journal_lock_updates()
904 mutex_lock(&journal->j_barrier); in jbd2_journal_lock_updates()
915 void jbd2_journal_unlock_updates (journal_t *journal) in jbd2_journal_unlock_updates() argument
917 J_ASSERT(journal->j_barrier_count != 0); in jbd2_journal_unlock_updates()
919 mutex_unlock(&journal->j_barrier); in jbd2_journal_unlock_updates()
920 write_lock(&journal->j_state_lock); in jbd2_journal_unlock_updates()
921 --journal->j_barrier_count; in jbd2_journal_unlock_updates()
922 write_unlock(&journal->j_state_lock); in jbd2_journal_unlock_updates()
923 wake_up_all(&journal->j_wait_transaction_locked); in jbd2_journal_unlock_updates()
975 journal_t *journal; in do_get_write_access() local
980 journal = transaction->t_journal; in do_get_write_access()
1022 journal->j_committing_transaction); in do_get_write_access()
1076 spin_lock(&journal->j_list_lock); in do_get_write_access()
1078 spin_unlock(&journal->j_list_lock); in do_get_write_access()
1093 J_ASSERT_JH(jh, jh->b_transaction == journal->j_committing_transaction); in do_get_write_access()
1270 journal_t *journal; in jbd2_journal_get_create_access() local
1278 journal = transaction->t_journal; in jbd2_journal_get_create_access()
1292 (jh->b_transaction == journal->j_committing_transaction && in jbd2_journal_get_create_access()
1312 spin_lock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1314 spin_unlock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1315 } else if (jh->b_transaction == journal->j_committing_transaction) { in jbd2_journal_get_create_access()
1320 spin_lock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1322 spin_unlock(&journal->j_list_lock); in jbd2_journal_get_create_access()
1485 journal_t *journal; in jbd2_journal_dirty_metadata() local
1532 journal = transaction->t_journal; in jbd2_journal_dirty_metadata()
1571 journal->j_running_transaction)) { in jbd2_journal_dirty_metadata()
1575 journal->j_devname, in jbd2_journal_dirty_metadata()
1579 journal->j_running_transaction, in jbd2_journal_dirty_metadata()
1580 journal->j_running_transaction ? in jbd2_journal_dirty_metadata()
1581 journal->j_running_transaction->t_tid : 0); in jbd2_journal_dirty_metadata()
1598 journal->j_committing_transaction)) || in jbd2_journal_dirty_metadata()
1605 journal->j_devname, in jbd2_journal_dirty_metadata()
1627 spin_lock(&journal->j_list_lock); in jbd2_journal_dirty_metadata()
1629 spin_unlock(&journal->j_list_lock); in jbd2_journal_dirty_metadata()
1657 journal_t *journal; in jbd2_journal_forget() local
1665 journal = transaction->t_journal; in jbd2_journal_forget()
1724 spin_lock(&journal->j_list_lock); in jbd2_journal_forget()
1732 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1735 journal->j_committing_transaction)); in jbd2_journal_forget()
1749 spin_lock(&journal->j_list_lock); in jbd2_journal_forget()
1751 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1768 spin_lock(&journal->j_list_lock); in jbd2_journal_forget()
1771 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1781 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1793 spin_unlock(&journal->j_list_lock); in jbd2_journal_forget()
1825 journal_t *journal; in jbd2_journal_stop() local
1845 journal = transaction->t_journal; in jbd2_journal_stop()
1852 trace_jbd2_handle_stats(journal->j_fs_dev->bd_dev, in jbd2_journal_stop()
1889 if (handle->h_sync && journal->j_last_sync_writer != pid && in jbd2_journal_stop()
1890 journal->j_max_batch_time) { in jbd2_journal_stop()
1893 journal->j_last_sync_writer = pid; in jbd2_journal_stop()
1895 read_lock(&journal->j_state_lock); in jbd2_journal_stop()
1896 commit_time = journal->j_average_commit_time; in jbd2_journal_stop()
1897 read_unlock(&journal->j_state_lock); in jbd2_journal_stop()
1903 1000*journal->j_min_batch_time); in jbd2_journal_stop()
1905 1000*journal->j_max_batch_time); in jbd2_journal_stop()
1932 jbd2_log_start_commit(journal, tid); in jbd2_journal_stop()
1951 err = jbd2_log_wait_commit(journal, tid); in jbd2_journal_stop()
2080 void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh) in jbd2_journal_unfile_buffer() argument
2087 spin_lock(&journal->j_list_lock); in jbd2_journal_unfile_buffer()
2089 spin_unlock(&journal->j_list_lock); in jbd2_journal_unfile_buffer()
2101 __journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh) in __journal_try_to_free_buffer() argument
2113 spin_lock(&journal->j_list_lock); in __journal_try_to_free_buffer()
2119 spin_unlock(&journal->j_list_lock); in __journal_try_to_free_buffer()
2158 bool jbd2_journal_try_to_free_buffers(journal_t *journal, struct folio *folio) in jbd2_journal_try_to_free_buffers() argument
2181 __journal_try_to_free_buffer(journal, bh); in jbd2_journal_try_to_free_buffers()
2276 static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh, in journal_unmap_buffer() argument
2296 write_lock(&journal->j_state_lock); in journal_unmap_buffer()
2298 spin_lock(&journal->j_list_lock); in journal_unmap_buffer()
2344 if (journal->j_running_transaction) { in journal_unmap_buffer()
2350 journal->j_running_transaction); in journal_unmap_buffer()
2357 if (journal->j_committing_transaction) { in journal_unmap_buffer()
2360 journal->j_committing_transaction); in journal_unmap_buffer()
2370 } else if (transaction == journal->j_committing_transaction) { in journal_unmap_buffer()
2378 spin_unlock(&journal->j_list_lock); in journal_unmap_buffer()
2380 write_unlock(&journal->j_state_lock); in journal_unmap_buffer()
2392 if (journal->j_running_transaction && buffer_jbddirty(bh)) in journal_unmap_buffer()
2393 jh->b_next_transaction = journal->j_running_transaction; in journal_unmap_buffer()
2395 spin_unlock(&journal->j_list_lock); in journal_unmap_buffer()
2397 write_unlock(&journal->j_state_lock); in journal_unmap_buffer()
2407 J_ASSERT_JH(jh, transaction == journal->j_running_transaction); in journal_unmap_buffer()
2422 spin_unlock(&journal->j_list_lock); in journal_unmap_buffer()
2424 write_unlock(&journal->j_state_lock); in journal_unmap_buffer()
2450 int jbd2_journal_invalidate_folio(journal_t *journal, struct folio *folio, in jbd2_journal_invalidate_folio() argument
2483 ret = journal_unmap_buffer(journal, bh, partial_page); in jbd2_journal_invalidate_folio()
2649 void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh) in jbd2_journal_refile_buffer() argument
2654 spin_lock(&journal->j_list_lock); in jbd2_journal_refile_buffer()
2657 spin_unlock(&journal->j_list_lock); in jbd2_journal_refile_buffer()
2669 journal_t *journal; in jbd2_journal_file_inode() local
2673 journal = transaction->t_journal; in jbd2_journal_file_inode()
2678 spin_lock(&journal->j_list_lock); in jbd2_journal_file_inode()
2706 journal->j_committing_transaction); in jbd2_journal_file_inode()
2715 spin_unlock(&journal->j_list_lock); in jbd2_journal_file_inode()
2755 int jbd2_journal_begin_ordered_truncate(journal_t *journal, in jbd2_journal_begin_ordered_truncate() argument
2768 read_lock(&journal->j_state_lock); in jbd2_journal_begin_ordered_truncate()
2769 commit_trans = journal->j_committing_transaction; in jbd2_journal_begin_ordered_truncate()
2770 read_unlock(&journal->j_state_lock); in jbd2_journal_begin_ordered_truncate()
2771 spin_lock(&journal->j_list_lock); in jbd2_journal_begin_ordered_truncate()
2773 spin_unlock(&journal->j_list_lock); in jbd2_journal_begin_ordered_truncate()
2778 jbd2_journal_abort(journal, ret); in jbd2_journal_begin_ordered_truncate()