Lines Matching full:handle
108 * Handle management.
198 * Wait until we can add credits for handle to the running transaction. Called
199 * with j_state_lock held for reading. Returns 0 if handle joined the running
237 * attach this handle to a new transaction. in add_transaction_credits()
243 * big to fit this handle? Wait until reserved credits are freed. in add_transaction_credits()
306 * start_this_handle: Given a handle, deal with any locking or stalling
307 * needed to make sure that there is enough journal space for the handle
308 * to begin. Attach the handle to a transaction and set up the
312 static int start_this_handle(journal_t *journal, handle_t *handle, in start_this_handle() argument
316 int blocks = handle->h_total_credits; in start_this_handle()
320 if (handle->h_rsv_handle) in start_this_handle()
321 rsv_blocks = handle->h_rsv_handle->h_total_credits; in start_this_handle()
357 jbd2_debug(3, "New handle %p going live.\n", handle); in start_this_handle()
378 if (!handle->h_reserved && journal->j_barrier_count) { in start_this_handle()
391 (handle->h_reserved || !journal->j_barrier_count)) { in start_this_handle()
401 if (!handle->h_reserved) { in start_this_handle()
413 * We have handle reserved so we are allowed to join T_LOCKED in start_this_handle()
424 handle->h_reserved = 0; in start_this_handle()
428 * use and add the handle to the running transaction. in start_this_handle()
431 handle->h_transaction = transaction; in start_this_handle()
432 handle->h_requested_credits = blocks; in start_this_handle()
433 handle->h_revoke_credits_requested = handle->h_revoke_credits; in start_this_handle()
434 handle->h_start_jiffies = jiffies; in start_this_handle()
437 jbd2_debug(4, "Handle %p given %d credits (total %d, free %lu)\n", in start_this_handle()
438 handle, blocks, in start_this_handle()
442 current->journal_info = handle; in start_this_handle()
450 handle->saved_alloc_context = memalloc_nofs_save(); in start_this_handle()
454 /* Allocate a new handle. This should probably be in a slab... */
457 handle_t *handle = jbd2_alloc_handle(GFP_NOFS); in new_handle() local
458 if (!handle) in new_handle()
460 handle->h_total_credits = nblocks; in new_handle()
461 handle->h_ref = 1; in new_handle()
463 return handle; in new_handle()
470 handle_t *handle = journal_current_handle(); in jbd2__journal_start() local
476 if (handle) { in jbd2__journal_start()
477 J_ASSERT(handle->h_transaction->t_journal == journal); in jbd2__journal_start()
478 handle->h_ref++; in jbd2__journal_start()
479 return handle; in jbd2__journal_start()
484 handle = new_handle(nblocks); in jbd2__journal_start()
485 if (!handle) in jbd2__journal_start()
492 jbd2_free_handle(handle); in jbd2__journal_start()
497 handle->h_rsv_handle = rsv_handle; in jbd2__journal_start()
499 handle->h_revoke_credits = revoke_records; in jbd2__journal_start()
501 err = start_this_handle(journal, handle, gfp_mask); in jbd2__journal_start()
503 if (handle->h_rsv_handle) in jbd2__journal_start()
504 jbd2_free_handle(handle->h_rsv_handle); in jbd2__journal_start()
505 jbd2_free_handle(handle); in jbd2__journal_start()
508 handle->h_type = type; in jbd2__journal_start()
509 handle->h_line_no = line_no; in jbd2__journal_start()
511 handle->h_transaction->t_tid, type, in jbd2__journal_start()
514 return handle; in jbd2__journal_start()
520 * jbd2_journal_start() - Obtain a new handle.
527 * handle with rsv_blocks reserved blocks in the journal. This handle is
530 * handle, it has to set h_rsv_handle to NULL as otherwise jbd2_journal_stop()
531 * on the parent handle will dispose the reserved one. Reserved handle has to
532 * be converted to a normal handle using jbd2_journal_start_reserved() before
535 * Return a pointer to a newly allocated handle, or an ERR_PTR() value
544 static void __jbd2_journal_unreserve_handle(handle_t *handle, transaction_t *t) in __jbd2_journal_unreserve_handle() argument
546 journal_t *journal = handle->h_journal; in __jbd2_journal_unreserve_handle()
548 WARN_ON(!handle->h_reserved); in __jbd2_journal_unreserve_handle()
549 sub_reserved_credits(journal, handle->h_total_credits); in __jbd2_journal_unreserve_handle()
551 atomic_sub(handle->h_total_credits, &t->t_outstanding_credits); in __jbd2_journal_unreserve_handle()
554 void jbd2_journal_free_reserved(handle_t *handle) in jbd2_journal_free_reserved() argument
556 journal_t *journal = handle->h_journal; in jbd2_journal_free_reserved()
560 __jbd2_journal_unreserve_handle(handle, journal->j_running_transaction); in jbd2_journal_free_reserved()
562 jbd2_free_handle(handle); in jbd2_journal_free_reserved()
567 * jbd2_journal_start_reserved() - start reserved handle
568 * @handle: handle to start
569 * @type: for handle statistics
570 * @line_no: for handle statistics
572 * Start handle that has been previously reserved with jbd2_journal_reserve().
573 * This attaches @handle to the running transaction (or creates one if there's
578 * Return 0 on success, non-zero on error - handle is freed in that case.
580 int jbd2_journal_start_reserved(handle_t *handle, unsigned int type, in jbd2_journal_start_reserved() argument
583 journal_t *journal = handle->h_journal; in jbd2_journal_start_reserved()
586 if (WARN_ON(!handle->h_reserved)) { in jbd2_journal_start_reserved()
587 /* Someone passed in normal handle? Just stop it. */ in jbd2_journal_start_reserved()
588 jbd2_journal_stop(handle); in jbd2_journal_start_reserved()
596 jbd2_journal_free_reserved(handle); in jbd2_journal_start_reserved()
600 handle->h_journal = NULL; in jbd2_journal_start_reserved()
605 ret = start_this_handle(journal, handle, GFP_NOFS); in jbd2_journal_start_reserved()
607 handle->h_journal = journal; in jbd2_journal_start_reserved()
608 jbd2_journal_free_reserved(handle); in jbd2_journal_start_reserved()
611 handle->h_type = type; in jbd2_journal_start_reserved()
612 handle->h_line_no = line_no; in jbd2_journal_start_reserved()
614 handle->h_transaction->t_tid, type, in jbd2_journal_start_reserved()
615 line_no, handle->h_total_credits); in jbd2_journal_start_reserved()
622 * @handle: handle to 'extend'
631 * jbd2_journal_extend tries to give the running handle more buffer credits.
641 int jbd2_journal_extend(handle_t *handle, int nblocks, int revoke_records) in jbd2_journal_extend() argument
643 transaction_t *transaction = handle->h_transaction; in jbd2_journal_extend()
648 if (is_handle_aborted(handle)) in jbd2_journal_extend()
658 jbd2_debug(3, "denied handle %p %d blocks: " in jbd2_journal_extend()
659 "transaction not running\n", handle, nblocks); in jbd2_journal_extend()
664 handle->h_revoke_credits_requested + revoke_records, in jbd2_journal_extend()
667 handle->h_revoke_credits_requested, in jbd2_journal_extend()
673 jbd2_debug(3, "denied handle %p %d blocks: " in jbd2_journal_extend()
674 "transaction too large\n", handle, nblocks); in jbd2_journal_extend()
681 handle->h_type, handle->h_line_no, in jbd2_journal_extend()
682 handle->h_total_credits, in jbd2_journal_extend()
685 handle->h_total_credits += nblocks; in jbd2_journal_extend()
686 handle->h_requested_credits += nblocks; in jbd2_journal_extend()
687 handle->h_revoke_credits += revoke_records; in jbd2_journal_extend()
688 handle->h_revoke_credits_requested += revoke_records; in jbd2_journal_extend()
691 jbd2_debug(3, "extended handle %p by %d\n", handle, nblocks); in jbd2_journal_extend()
697 static void stop_this_handle(handle_t *handle) in stop_this_handle() argument
699 transaction_t *transaction = handle->h_transaction; in stop_this_handle()
703 J_ASSERT(journal_current_handle() == handle); in stop_this_handle()
707 * Subtract necessary revoke descriptor blocks from handle credits. We in stop_this_handle()
712 revokes = handle->h_revoke_credits_requested - handle->h_revoke_credits; in stop_this_handle()
718 > handle->h_total_credits); in stop_this_handle()
724 handle->h_total_credits -= revoke_descriptors; in stop_this_handle()
726 atomic_sub(handle->h_total_credits, in stop_this_handle()
728 if (handle->h_rsv_handle) in stop_this_handle()
729 __jbd2_journal_unreserve_handle(handle->h_rsv_handle, in stop_this_handle()
739 memalloc_nofs_restore(handle->saved_alloc_context); in stop_this_handle()
743 * jbd2__journal_restart() - restart a handle .
744 * @handle: handle to restart
749 * Restart a handle for a multi-transaction filesystem
753 * to a running handle, a call to jbd2_journal_restart will commit the
754 * handle's transaction so far and reattach the handle to a new
756 * credits. We preserve reserved handle if there's any attached to the
757 * passed in handle.
759 int jbd2__journal_restart(handle_t *handle, int nblocks, int revoke_records, in jbd2__journal_restart() argument
762 transaction_t *transaction = handle->h_transaction; in jbd2__journal_restart()
770 if (is_handle_aborted(handle)) in jbd2__journal_restart()
776 * First unlink the handle from its current transaction, and start the in jbd2__journal_restart()
779 jbd2_debug(2, "restarting handle %p\n", handle); in jbd2__journal_restart()
780 stop_this_handle(handle); in jbd2__journal_restart()
781 handle->h_transaction = NULL; in jbd2__journal_restart()
792 handle->h_total_credits = nblocks + in jbd2__journal_restart()
795 handle->h_revoke_credits = revoke_records; in jbd2__journal_restart()
796 ret = start_this_handle(journal, handle, gfp_mask); in jbd2__journal_restart()
798 ret ? 0 : handle->h_transaction->t_tid, in jbd2__journal_restart()
799 handle->h_type, handle->h_line_no, in jbd2__journal_restart()
800 handle->h_total_credits); in jbd2__journal_restart()
806 int jbd2_journal_restart(handle_t *handle, int nblocks) in jbd2_journal_restart() argument
808 return jbd2__journal_restart(handle, nblocks, 0, GFP_NOFS); in jbd2_journal_restart()
942 * the handle's metadata buffer credits (unless the buffer is already
947 do_get_write_access(handle_t *handle, struct journal_head *jh, in do_get_write_access() argument
951 transaction_t *transaction = handle->h_transaction; in do_get_write_access()
1009 if (is_handle_aborted(handle)) { in do_get_write_access()
1137 jbd2_journal_cancel_revoke(handle, jh); in do_get_write_access()
1148 static bool jbd2_write_access_granted(handle_t *handle, struct buffer_head *bh, in jbd2_write_access_granted() argument
1179 if (READ_ONCE(jh->b_transaction) != handle->h_transaction && in jbd2_write_access_granted()
1180 READ_ONCE(jh->b_next_transaction) != handle->h_transaction) in jbd2_write_access_granted()
1203 * @handle: transaction to add buffer modifications to
1212 int jbd2_journal_get_write_access(handle_t *handle, struct buffer_head *bh) in jbd2_journal_get_write_access() argument
1218 if (is_handle_aborted(handle)) in jbd2_journal_get_write_access()
1221 journal = handle->h_transaction->t_journal; in jbd2_journal_get_write_access()
1234 if (jbd2_write_access_granted(handle, bh, false)) in jbd2_journal_get_write_access()
1241 rc = do_get_write_access(handle, jh, 0); in jbd2_journal_get_write_access()
1261 * @handle: transaction to new buffer to
1266 int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh) in jbd2_journal_get_create_access() argument
1268 transaction_t *transaction = handle->h_transaction; in jbd2_journal_get_create_access()
1275 if (is_handle_aborted(handle)) in jbd2_journal_get_create_access()
1333 jbd2_journal_cancel_revoke(handle, jh); in jbd2_journal_get_create_access()
1342 * @handle: transaction
1365 int jbd2_journal_get_undo_access(handle_t *handle, struct buffer_head *bh) in jbd2_journal_get_undo_access() argument
1371 if (is_handle_aborted(handle)) in jbd2_journal_get_undo_access()
1374 if (jbd2_write_access_granted(handle, bh, true)) in jbd2_journal_get_undo_access()
1385 err = do_get_write_access(handle, jh, 1); in jbd2_journal_get_undo_access()
1460 * @handle: transaction to add buffer to.
1481 int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh) in jbd2_journal_dirty_metadata() argument
1483 transaction_t *transaction = handle->h_transaction; in jbd2_journal_dirty_metadata()
1521 handle->h_type, handle->h_line_no, in jbd2_journal_dirty_metadata()
1533 if (is_handle_aborted(handle)) { in jbd2_journal_dirty_metadata()
1553 if (WARN_ON_ONCE(jbd2_handle_buffer_credits(handle) <= 0)) { in jbd2_journal_dirty_metadata()
1558 handle->h_total_credits--; in jbd2_journal_dirty_metadata()
1564 * Nobody can take it off again because there is a handle open. in jbd2_journal_dirty_metadata()
1639 * @handle: transaction handle
1651 * Allow this call even if the handle has aborted --- it may be part of
1654 int jbd2_journal_forget(handle_t *handle, struct buffer_head *bh) in jbd2_journal_forget() argument
1656 transaction_t *transaction = handle->h_transaction; in jbd2_journal_forget()
1664 if (is_handle_aborted(handle)) in jbd2_journal_forget()
1805 handle->h_total_credits++; in jbd2_journal_forget()
1812 * @handle: transaction to complete.
1814 * All done for a particular handle.
1817 * buffer credits to the transaction and remove the handle. The only
1826 int jbd2_journal_stop(handle_t *handle) in jbd2_journal_stop() argument
1828 transaction_t *transaction = handle->h_transaction; in jbd2_journal_stop()
1834 if (--handle->h_ref > 0) { in jbd2_journal_stop()
1835 jbd2_debug(4, "h_ref %d -> %d\n", handle->h_ref + 1, in jbd2_journal_stop()
1836 handle->h_ref); in jbd2_journal_stop()
1837 if (is_handle_aborted(handle)) in jbd2_journal_stop()
1843 * Handle is already detached from the transaction so there is in jbd2_journal_stop()
1844 * nothing to do other than free the handle. in jbd2_journal_stop()
1846 memalloc_nofs_restore(handle->saved_alloc_context); in jbd2_journal_stop()
1852 if (is_handle_aborted(handle)) in jbd2_journal_stop()
1855 jbd2_debug(4, "Handle %p going down\n", handle); in jbd2_journal_stop()
1857 tid, handle->h_type, handle->h_line_no, in jbd2_journal_stop()
1858 jiffies - handle->h_start_jiffies, in jbd2_journal_stop()
1859 handle->h_sync, handle->h_requested_credits, in jbd2_journal_stop()
1860 (handle->h_requested_credits - in jbd2_journal_stop()
1861 handle->h_total_credits)); in jbd2_journal_stop()
1864 * Implement synchronous transaction batching. If the handle in jbd2_journal_stop()
1893 if (handle->h_sync && journal->j_last_sync_writer != pid && in jbd2_journal_stop()
1919 if (handle->h_sync) in jbd2_journal_stop()
1923 * If the handle is marked SYNC, we need to set another commit in jbd2_journal_stop()
1927 if (handle->h_sync || in jbd2_journal_stop()
1934 "handle %p\n", handle); in jbd2_journal_stop()
1942 if (handle->h_sync && !(current->flags & PF_MEMALLOC)) in jbd2_journal_stop()
1952 stop_this_handle(handle); in jbd2_journal_stop()
1958 if (handle->h_rsv_handle) in jbd2_journal_stop()
1959 jbd2_free_handle(handle->h_rsv_handle); in jbd2_journal_stop()
1960 jbd2_free_handle(handle); in jbd2_journal_stop()
2497 * so we try to gracefully handle that. in __jbd2_journal_file_buffer()
2632 * File inode in the inode list of the handle's transaction
2634 static int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode, in jbd2_journal_file_inode() argument
2637 transaction_t *transaction = handle->h_transaction; in jbd2_journal_file_inode()
2640 if (is_handle_aborted(handle)) in jbd2_journal_file_inode()
2689 int jbd2_journal_inode_ranged_write(handle_t *handle, in jbd2_journal_inode_ranged_write() argument
2692 return jbd2_journal_file_inode(handle, jinode, in jbd2_journal_inode_ranged_write()
2697 int jbd2_journal_inode_ranged_wait(handle_t *handle, struct jbd2_inode *jinode, in jbd2_journal_inode_ranged_wait() argument
2700 return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA, in jbd2_journal_inode_ranged_wait()