Lines Matching defs:handle

217  * Wait until we can add credits for handle to the running transaction.  Called
218 * with j_state_lock held for reading. Returns 0 if handle joined the running
256 * attach this handle to a new transaction.
262 * big to fit this handle? Wait until reserved credits are freed.
325 * start_this_handle: Given a handle, deal with any locking or stalling
326 * needed to make sure that there is enough journal space for the handle
327 * to begin. Attach the handle to a transaction and set up the
331 static int start_this_handle(journal_t *journal, handle_t *handle,
335 int blocks = handle->h_total_credits;
339 if (handle->h_rsv_handle)
340 rsv_blocks = handle->h_rsv_handle->h_total_credits;
376 jbd2_debug(3, "New handle %p going live.\n", handle);
397 if (!handle->h_reserved && journal->j_barrier_count) {
410 (handle->h_reserved || !journal->j_barrier_count)) {
420 if (!handle->h_reserved) {
432 * We have handle reserved so we are allowed to join T_LOCKED
443 handle->h_reserved = 0;
447 * use and add the handle to the running transaction.
450 handle->h_transaction = transaction;
451 handle->h_requested_credits = blocks;
452 handle->h_revoke_credits_requested = handle->h_revoke_credits;
453 handle->h_start_jiffies = jiffies;
457 handle, blocks,
461 current->journal_info = handle;
469 handle->saved_alloc_context = memalloc_nofs_save();
473 /* Allocate a new handle. This should probably be in a slab... */
476 handle_t *handle = jbd2_alloc_handle(GFP_NOFS);
477 if (!handle)
479 handle->h_total_credits = nblocks;
480 handle->h_ref = 1;
482 return handle;
489 handle_t *handle = journal_current_handle();
495 if (handle) {
496 J_ASSERT(handle->h_transaction->t_journal == journal);
497 handle->h_ref++;
498 return handle;
503 handle = new_handle(nblocks);
504 if (!handle)
511 jbd2_free_handle(handle);
516 handle->h_rsv_handle = rsv_handle;
518 handle->h_revoke_credits = revoke_records;
520 err = start_this_handle(journal, handle, gfp_mask);
522 if (handle->h_rsv_handle)
523 jbd2_free_handle(handle->h_rsv_handle);
524 jbd2_free_handle(handle);
527 handle->h_type = type;
528 handle->h_line_no = line_no;
530 handle->h_transaction->t_tid, type,
533 return handle;
539 * jbd2_journal_start() - Obtain a new handle.
546 * handle with rsv_blocks reserved blocks in the journal. This handle is
549 * handle, it has to set h_rsv_handle to NULL as otherwise jbd2_journal_stop()
550 * on the parent handle will dispose the reserved one. Reserved handle has to
551 * be converted to a normal handle using jbd2_journal_start_reserved() before
554 * Return a pointer to a newly allocated handle, or an ERR_PTR() value
563 static void __jbd2_journal_unreserve_handle(handle_t *handle, transaction_t *t)
565 journal_t *journal = handle->h_journal;
567 WARN_ON(!handle->h_reserved);
568 sub_reserved_credits(journal, handle->h_total_credits);
570 atomic_sub(handle->h_total_credits, &t->t_outstanding_credits);
573 void jbd2_journal_free_reserved(handle_t *handle)
575 journal_t *journal = handle->h_journal;
579 __jbd2_journal_unreserve_handle(handle, journal->j_running_transaction);
581 jbd2_free_handle(handle);
586 * jbd2_journal_start_reserved() - start reserved handle
587 * @handle: handle to start
588 * @type: for handle statistics
589 * @line_no: for handle statistics
591 * Start handle that has been previously reserved with jbd2_journal_reserve().
592 * This attaches @handle to the running transaction (or creates one if there's
597 * Return 0 on success, non-zero on error - handle is freed in that case.
599 int jbd2_journal_start_reserved(handle_t *handle, unsigned int type,
602 journal_t *journal = handle->h_journal;
605 if (WARN_ON(!handle->h_reserved)) {
606 /* Someone passed in normal handle? Just stop it. */
607 jbd2_journal_stop(handle);
615 jbd2_journal_free_reserved(handle);
619 handle->h_journal = NULL;
624 ret = start_this_handle(journal, handle, GFP_NOFS);
626 handle->h_journal = journal;
627 jbd2_journal_free_reserved(handle);
630 handle->h_type = type;
631 handle->h_line_no = line_no;
633 handle->h_transaction->t_tid, type,
634 line_no, handle->h_total_credits);
641 * @handle: handle to 'extend'
650 * jbd2_journal_extend tries to give the running handle more buffer credits.
660 int jbd2_journal_extend(handle_t *handle, int nblocks, int revoke_records)
662 transaction_t *transaction = handle->h_transaction;
667 if (is_handle_aborted(handle))
677 jbd2_debug(3, "denied handle %p %d blocks: "
678 "transaction not running\n", handle, nblocks);
683 handle->h_revoke_credits_requested + revoke_records,
686 handle->h_revoke_credits_requested,
692 jbd2_debug(3, "denied handle %p %d blocks: "
693 "transaction too large\n", handle, nblocks);
700 handle->h_type, handle->h_line_no,
701 handle->h_total_credits,
704 handle->h_total_credits += nblocks;
705 handle->h_requested_credits += nblocks;
706 handle->h_revoke_credits += revoke_records;
707 handle->h_revoke_credits_requested += revoke_records;
710 jbd2_debug(3, "extended handle %p by %d\n", handle, nblocks);
716 static void stop_this_handle(handle_t *handle)
718 transaction_t *transaction = handle->h_transaction;
722 J_ASSERT(journal_current_handle() == handle);
726 * Subtract necessary revoke descriptor blocks from handle credits. We
731 revokes = handle->h_revoke_credits_requested - handle->h_revoke_credits;
737 > handle->h_total_credits);
743 handle->h_total_credits -= revoke_descriptors;
745 atomic_sub(handle->h_total_credits,
747 if (handle->h_rsv_handle)
748 __jbd2_journal_unreserve_handle(handle->h_rsv_handle,
758 memalloc_nofs_restore(handle->saved_alloc_context);
762 * jbd2__journal_restart() - restart a handle .
763 * @handle: handle to restart
768 * Restart a handle for a multi-transaction filesystem
772 * to a running handle, a call to jbd2_journal_restart will commit the
773 * handle's transaction so far and reattach the handle to a new
775 * credits. We preserve reserved handle if there's any attached to the
776 * passed in handle.
778 int jbd2__journal_restart(handle_t *handle, int nblocks, int revoke_records,
781 transaction_t *transaction = handle->h_transaction;
789 if (is_handle_aborted(handle))
795 * First unlink the handle from its current transaction, and start the
798 jbd2_debug(2, "restarting handle %p\n", handle);
799 stop_this_handle(handle);
800 handle->h_transaction = NULL;
811 handle->h_total_credits = nblocks +
814 handle->h_revoke_credits = revoke_records;
815 ret = start_this_handle(journal, handle, gfp_mask);
817 ret ? 0 : handle->h_transaction->t_tid,
818 handle->h_type, handle->h_line_no,
819 handle->h_total_credits);
825 int jbd2_journal_restart(handle_t *handle, int nblocks)
827 return jbd2__journal_restart(handle, nblocks, 0, GFP_NOFS);
961 * the handle's metadata buffer credits (unless the buffer is already
966 do_get_write_access(handle_t *handle, struct journal_head *jh,
970 transaction_t *transaction = handle->h_transaction;
1028 if (is_handle_aborted(handle)) {
1156 jbd2_journal_cancel_revoke(handle, jh);
1167 static bool jbd2_write_access_granted(handle_t *handle, struct buffer_head *bh,
1198 if (READ_ONCE(jh->b_transaction) != handle->h_transaction &&
1199 READ_ONCE(jh->b_next_transaction) != handle->h_transaction)
1222 * @handle: transaction to add buffer modifications to
1231 int jbd2_journal_get_write_access(handle_t *handle, struct buffer_head *bh)
1236 if (is_handle_aborted(handle))
1239 if (jbd2_write_access_granted(handle, bh, false))
1246 rc = do_get_write_access(handle, jh, 0);
1266 * @handle: transaction to new buffer to
1271 int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh)
1273 transaction_t *transaction = handle->h_transaction;
1280 if (is_handle_aborted(handle))
1338 jbd2_journal_cancel_revoke(handle, jh);
1347 * @handle: transaction
1370 int jbd2_journal_get_undo_access(handle_t *handle, struct buffer_head *bh)
1376 if (is_handle_aborted(handle))
1379 if (jbd2_write_access_granted(handle, bh, true))
1390 err = do_get_write_access(handle, jh, 1);
1465 * @handle: transaction to add buffer to.
1486 int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh)
1488 transaction_t *transaction = handle->h_transaction;
1526 handle->h_type, handle->h_line_no,
1539 if (is_handle_aborted(handle)) {
1557 if (WARN_ON_ONCE(jbd2_handle_buffer_credits(handle) <= 0)) {
1562 handle->h_total_credits--;
1568 * Nobody can take it off again because there is a handle open.
1643 * @handle: transaction handle
1655 * Allow this call even if the handle has aborted --- it may be part of
1658 int jbd2_journal_forget(handle_t *handle, struct buffer_head *bh)
1660 transaction_t *transaction = handle->h_transaction;
1667 if (is_handle_aborted(handle))
1804 handle->h_total_credits++;
1811 * @handle: transaction to complete.
1813 * All done for a particular handle.
1816 * buffer credits to the transaction and remove the handle. The only
1825 int jbd2_journal_stop(handle_t *handle)
1827 transaction_t *transaction = handle->h_transaction;
1833 if (--handle->h_ref > 0) {
1834 jbd2_debug(4, "h_ref %d -> %d\n", handle->h_ref + 1,
1835 handle->h_ref);
1836 if (is_handle_aborted(handle))
1843 * nothing to do other than free the handle.
1845 memalloc_nofs_restore(handle->saved_alloc_context);
1851 if (is_handle_aborted(handle))
1854 jbd2_debug(4, "Handle %p going down\n", handle);
1856 tid, handle->h_type, handle->h_line_no,
1857 jiffies - handle->h_start_jiffies,
1858 handle->h_sync, handle->h_requested_credits,
1859 (handle->h_requested_credits -
1860 handle->h_total_credits));
1863 * Implement synchronous transaction batching. If the handle
1892 if (handle->h_sync && journal->j_last_sync_writer != pid &&
1918 if (handle->h_sync)
1922 * If the handle is marked SYNC, we need to set another commit
1926 if (handle->h_sync ||
1933 "handle %p\n", handle);
1941 if (handle->h_sync && !(current->flags & PF_MEMALLOC))
1951 stop_this_handle(handle);
1957 if (handle->h_rsv_handle)
1958 jbd2_free_handle(handle->h_rsv_handle);
1959 jbd2_free_handle(handle);
2511 * so we try to gracefully handle that.
2646 * File inode in the inode list of the handle's transaction
2648 static int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode,
2651 transaction_t *transaction = handle->h_transaction;
2654 if (is_handle_aborted(handle))
2703 int jbd2_journal_inode_ranged_write(handle_t *handle,
2706 return jbd2_journal_file_inode(handle, jinode,
2711 int jbd2_journal_inode_ranged_wait(handle_t *handle, struct jbd2_inode *jinode,
2714 return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA,