| .. | .. |
|---|
| 63 | 63 | } |
|---|
| 64 | 64 | |
|---|
| 65 | 65 | /* |
|---|
| 66 | + * Base amount of descriptor blocks we reserve for each transaction. |
|---|
| 67 | + */ |
|---|
| 68 | +static int jbd2_descriptor_blocks_per_trans(journal_t *journal) |
|---|
| 69 | +{ |
|---|
| 70 | + int tag_space = journal->j_blocksize - sizeof(journal_header_t); |
|---|
| 71 | + int tags_per_block; |
|---|
| 72 | + |
|---|
| 73 | + /* Subtract UUID */ |
|---|
| 74 | + tag_space -= 16; |
|---|
| 75 | + if (jbd2_journal_has_csum_v2or3(journal)) |
|---|
| 76 | + tag_space -= sizeof(struct jbd2_journal_block_tail); |
|---|
| 77 | + /* Commit code leaves a slack space of 16 bytes at the end of block */ |
|---|
| 78 | + tags_per_block = (tag_space - 16) / journal_tag_bytes(journal); |
|---|
| 79 | + /* |
|---|
| 80 | + * Revoke descriptors are accounted separately so we need to reserve |
|---|
| 81 | + * space for commit block and normal transaction descriptor blocks. |
|---|
| 82 | + */ |
|---|
| 83 | + return 1 + DIV_ROUND_UP(journal->j_max_transaction_buffers, |
|---|
| 84 | + tags_per_block); |
|---|
| 85 | +} |
|---|
| 86 | + |
|---|
| 87 | +/* |
|---|
| 66 | 88 | * jbd2_get_transaction: obtain a new transaction_t object. |
|---|
| 67 | 89 | * |
|---|
| 68 | | - * Simply allocate and initialise a new transaction. Create it in |
|---|
| 90 | + * Simply initialise a new transaction. Initialize it in |
|---|
| 69 | 91 | * RUNNING state and add it to the current journal (which should not |
|---|
| 70 | 92 | * have an existing running transaction: we only make a new transaction |
|---|
| 71 | 93 | * once we have started to commit the old one). |
|---|
| .. | .. |
|---|
| 77 | 99 | * |
|---|
| 78 | 100 | */ |
|---|
| 79 | 101 | |
|---|
| 80 | | -static transaction_t * |
|---|
| 81 | | -jbd2_get_transaction(journal_t *journal, transaction_t *transaction) |
|---|
| 102 | +static void jbd2_get_transaction(journal_t *journal, |
|---|
| 103 | + transaction_t *transaction) |
|---|
| 82 | 104 | { |
|---|
| 83 | 105 | transaction->t_journal = journal; |
|---|
| 84 | 106 | transaction->t_state = T_RUNNING; |
|---|
| .. | .. |
|---|
| 88 | 110 | spin_lock_init(&transaction->t_handle_lock); |
|---|
| 89 | 111 | atomic_set(&transaction->t_updates, 0); |
|---|
| 90 | 112 | atomic_set(&transaction->t_outstanding_credits, |
|---|
| 113 | + jbd2_descriptor_blocks_per_trans(journal) + |
|---|
| 91 | 114 | atomic_read(&journal->j_reserved_credits)); |
|---|
| 115 | + atomic_set(&transaction->t_outstanding_revokes, 0); |
|---|
| 92 | 116 | atomic_set(&transaction->t_handle_count, 0); |
|---|
| 93 | 117 | INIT_LIST_HEAD(&transaction->t_inode_list); |
|---|
| 94 | 118 | INIT_LIST_HEAD(&transaction->t_private_list); |
|---|
| .. | .. |
|---|
| 102 | 126 | transaction->t_max_wait = 0; |
|---|
| 103 | 127 | transaction->t_start = jiffies; |
|---|
| 104 | 128 | transaction->t_requested = 0; |
|---|
| 105 | | - |
|---|
| 106 | | - return transaction; |
|---|
| 107 | 129 | } |
|---|
| 108 | 130 | |
|---|
| 109 | 131 | /* |
|---|
| .. | .. |
|---|
| 140 | 162 | } |
|---|
| 141 | 163 | |
|---|
| 142 | 164 | /* |
|---|
| 143 | | - * Wait until running transaction passes T_LOCKED state. Also starts the commit |
|---|
| 144 | | - * if needed. The function expects running transaction to exist and releases |
|---|
| 145 | | - * j_state_lock. |
|---|
| 165 | + * Wait until running transaction passes to T_FLUSH state and new transaction |
|---|
| 166 | + * can thus be started. Also starts the commit if needed. The function expects |
|---|
| 167 | + * running transaction to exist and releases j_state_lock. |
|---|
| 146 | 168 | */ |
|---|
| 147 | 169 | static void wait_transaction_locked(journal_t *journal) |
|---|
| 148 | 170 | __releases(journal->j_state_lock) |
|---|
| .. | .. |
|---|
| 151 | 173 | int need_to_start; |
|---|
| 152 | 174 | tid_t tid = journal->j_running_transaction->t_tid; |
|---|
| 153 | 175 | |
|---|
| 154 | | - prepare_to_wait(&journal->j_wait_transaction_locked, &wait, |
|---|
| 176 | + prepare_to_wait_exclusive(&journal->j_wait_transaction_locked, &wait, |
|---|
| 155 | 177 | TASK_UNINTERRUPTIBLE); |
|---|
| 156 | 178 | need_to_start = !tid_geq(journal->j_commit_request, tid); |
|---|
| 157 | 179 | read_unlock(&journal->j_state_lock); |
|---|
| 158 | 180 | if (need_to_start) |
|---|
| 159 | 181 | jbd2_log_start_commit(journal, tid); |
|---|
| 160 | 182 | jbd2_might_wait_for_commit(journal); |
|---|
| 183 | + schedule(); |
|---|
| 184 | + finish_wait(&journal->j_wait_transaction_locked, &wait); |
|---|
| 185 | +} |
|---|
| 186 | + |
|---|
| 187 | +/* |
|---|
| 188 | + * Wait until running transaction transitions from T_SWITCH to T_FLUSH |
|---|
| 189 | + * state and new transaction can thus be started. The function releases |
|---|
| 190 | + * j_state_lock. |
|---|
| 191 | + */ |
|---|
| 192 | +static void wait_transaction_switching(journal_t *journal) |
|---|
| 193 | + __releases(journal->j_state_lock) |
|---|
| 194 | +{ |
|---|
| 195 | + DEFINE_WAIT(wait); |
|---|
| 196 | + |
|---|
| 197 | + if (WARN_ON(!journal->j_running_transaction || |
|---|
| 198 | + journal->j_running_transaction->t_state != T_SWITCH)) { |
|---|
| 199 | + read_unlock(&journal->j_state_lock); |
|---|
| 200 | + return; |
|---|
| 201 | + } |
|---|
| 202 | + prepare_to_wait_exclusive(&journal->j_wait_transaction_locked, &wait, |
|---|
| 203 | + TASK_UNINTERRUPTIBLE); |
|---|
| 204 | + read_unlock(&journal->j_state_lock); |
|---|
| 205 | + /* |
|---|
| 206 | + * We don't call jbd2_might_wait_for_commit() here as there's no |
|---|
| 207 | + * waiting for outstanding handles happening anymore in T_SWITCH state |
|---|
| 208 | + * and handling of reserved handles actually relies on that for |
|---|
| 209 | + * correctness. |
|---|
| 210 | + */ |
|---|
| 161 | 211 | schedule(); |
|---|
| 162 | 212 | finish_wait(&journal->j_wait_transaction_locked, &wait); |
|---|
| 163 | 213 | } |
|---|
| .. | .. |
|---|
| 185 | 235 | * If the current transaction is locked down for commit, wait |
|---|
| 186 | 236 | * for the lock to be released. |
|---|
| 187 | 237 | */ |
|---|
| 188 | | - if (t->t_state == T_LOCKED) { |
|---|
| 238 | + if (t->t_state != T_RUNNING) { |
|---|
| 239 | + WARN_ON_ONCE(t->t_state >= T_FLUSH); |
|---|
| 189 | 240 | wait_transaction_locked(journal); |
|---|
| 190 | 241 | return 1; |
|---|
| 191 | 242 | } |
|---|
| .. | .. |
|---|
| 233 | 284 | * *before* starting to dirty potentially checkpointed buffers |
|---|
| 234 | 285 | * in the new transaction. |
|---|
| 235 | 286 | */ |
|---|
| 236 | | - if (jbd2_log_space_left(journal) < jbd2_space_needed(journal)) { |
|---|
| 287 | + if (jbd2_log_space_left(journal) < journal->j_max_transaction_buffers) { |
|---|
| 237 | 288 | atomic_sub(total, &t->t_outstanding_credits); |
|---|
| 238 | 289 | read_unlock(&journal->j_state_lock); |
|---|
| 239 | 290 | jbd2_might_wait_for_commit(journal); |
|---|
| 240 | 291 | write_lock(&journal->j_state_lock); |
|---|
| 241 | | - if (jbd2_log_space_left(journal) < jbd2_space_needed(journal)) |
|---|
| 292 | + if (jbd2_log_space_left(journal) < |
|---|
| 293 | + journal->j_max_transaction_buffers) |
|---|
| 242 | 294 | __jbd2_log_wait_for_space(journal); |
|---|
| 243 | 295 | write_unlock(&journal->j_state_lock); |
|---|
| 244 | 296 | return 1; |
|---|
| .. | .. |
|---|
| 274 | 326 | gfp_t gfp_mask) |
|---|
| 275 | 327 | { |
|---|
| 276 | 328 | transaction_t *transaction, *new_transaction = NULL; |
|---|
| 277 | | - int blocks = handle->h_buffer_credits; |
|---|
| 329 | + int blocks = handle->h_total_credits; |
|---|
| 278 | 330 | int rsv_blocks = 0; |
|---|
| 279 | 331 | unsigned long ts = jiffies; |
|---|
| 280 | 332 | |
|---|
| 281 | 333 | if (handle->h_rsv_handle) |
|---|
| 282 | | - rsv_blocks = handle->h_rsv_handle->h_buffer_credits; |
|---|
| 334 | + rsv_blocks = handle->h_rsv_handle->h_total_credits; |
|---|
| 283 | 335 | |
|---|
| 284 | 336 | /* |
|---|
| 285 | 337 | * Limit the number of reserved credits to 1/2 of maximum transaction |
|---|
| .. | .. |
|---|
| 297 | 349 | } |
|---|
| 298 | 350 | |
|---|
| 299 | 351 | alloc_transaction: |
|---|
| 300 | | - if (!journal->j_running_transaction) { |
|---|
| 352 | + /* |
|---|
| 353 | + * This check is racy but it is just an optimization of allocating new |
|---|
| 354 | + * transaction early if there are high chances we'll need it. If we |
|---|
| 355 | + * guess wrong, we'll retry or free unused transaction. |
|---|
| 356 | + */ |
|---|
| 357 | + if (!data_race(journal->j_running_transaction)) { |
|---|
| 301 | 358 | /* |
|---|
| 302 | 359 | * If __GFP_FS is not present, then we may be being called from |
|---|
| 303 | 360 | * inside the fs writeback layer, so we MUST NOT fail. |
|---|
| .. | .. |
|---|
| 362 | 419 | /* |
|---|
| 363 | 420 | * We have handle reserved so we are allowed to join T_LOCKED |
|---|
| 364 | 421 | * transaction and we don't have to check for transaction size |
|---|
| 365 | | - * and journal space. |
|---|
| 422 | + * and journal space. But we still have to wait while running |
|---|
| 423 | + * transaction is being switched to a committing one as it |
|---|
| 424 | + * won't wait for any handles anymore. |
|---|
| 366 | 425 | */ |
|---|
| 426 | + if (transaction->t_state == T_SWITCH) { |
|---|
| 427 | + wait_transaction_switching(journal); |
|---|
| 428 | + goto repeat; |
|---|
| 429 | + } |
|---|
| 367 | 430 | sub_reserved_credits(journal, blocks); |
|---|
| 368 | 431 | handle->h_reserved = 0; |
|---|
| 369 | 432 | } |
|---|
| .. | .. |
|---|
| 374 | 437 | update_t_max_wait(transaction, ts); |
|---|
| 375 | 438 | handle->h_transaction = transaction; |
|---|
| 376 | 439 | handle->h_requested_credits = blocks; |
|---|
| 440 | + handle->h_revoke_credits_requested = handle->h_revoke_credits; |
|---|
| 377 | 441 | handle->h_start_jiffies = jiffies; |
|---|
| 378 | 442 | atomic_inc(&transaction->t_updates); |
|---|
| 379 | 443 | atomic_inc(&transaction->t_handle_count); |
|---|
| .. | .. |
|---|
| 400 | 464 | handle_t *handle = jbd2_alloc_handle(GFP_NOFS); |
|---|
| 401 | 465 | if (!handle) |
|---|
| 402 | 466 | return NULL; |
|---|
| 403 | | - handle->h_buffer_credits = nblocks; |
|---|
| 467 | + handle->h_total_credits = nblocks; |
|---|
| 404 | 468 | handle->h_ref = 1; |
|---|
| 405 | 469 | |
|---|
| 406 | 470 | return handle; |
|---|
| 407 | 471 | } |
|---|
| 408 | 472 | |
|---|
| 409 | 473 | handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int rsv_blocks, |
|---|
| 410 | | - gfp_t gfp_mask, unsigned int type, |
|---|
| 411 | | - unsigned int line_no) |
|---|
| 474 | + int revoke_records, gfp_t gfp_mask, |
|---|
| 475 | + unsigned int type, unsigned int line_no) |
|---|
| 412 | 476 | { |
|---|
| 413 | 477 | handle_t *handle = journal_current_handle(); |
|---|
| 414 | 478 | int err; |
|---|
| .. | .. |
|---|
| 422 | 486 | return handle; |
|---|
| 423 | 487 | } |
|---|
| 424 | 488 | |
|---|
| 489 | + nblocks += DIV_ROUND_UP(revoke_records, |
|---|
| 490 | + journal->j_revoke_records_per_block); |
|---|
| 425 | 491 | handle = new_handle(nblocks); |
|---|
| 426 | 492 | if (!handle) |
|---|
| 427 | 493 | return ERR_PTR(-ENOMEM); |
|---|
| .. | .. |
|---|
| 437 | 503 | rsv_handle->h_journal = journal; |
|---|
| 438 | 504 | handle->h_rsv_handle = rsv_handle; |
|---|
| 439 | 505 | } |
|---|
| 506 | + handle->h_revoke_credits = revoke_records; |
|---|
| 440 | 507 | |
|---|
| 441 | 508 | err = start_this_handle(journal, handle, gfp_mask); |
|---|
| 442 | 509 | if (err < 0) { |
|---|
| .. | .. |
|---|
| 457 | 524 | |
|---|
| 458 | 525 | |
|---|
| 459 | 526 | /** |
|---|
| 460 | | - * handle_t *jbd2_journal_start() - Obtain a new handle. |
|---|
| 527 | + * jbd2_journal_start() - Obtain a new handle. |
|---|
| 461 | 528 | * @journal: Journal to start transaction on. |
|---|
| 462 | 529 | * @nblocks: number of block buffer we might modify |
|---|
| 463 | 530 | * |
|---|
| .. | .. |
|---|
| 465 | 532 | * modified buffers in the log. We block until the log can guarantee |
|---|
| 466 | 533 | * that much space. Additionally, if rsv_blocks > 0, we also create another |
|---|
| 467 | 534 | * handle with rsv_blocks reserved blocks in the journal. This handle is |
|---|
| 468 | | - * is stored in h_rsv_handle. It is not attached to any particular transaction |
|---|
| 535 | + * stored in h_rsv_handle. It is not attached to any particular transaction |
|---|
| 469 | 536 | * and thus doesn't block transaction commit. If the caller uses this reserved |
|---|
| 470 | 537 | * handle, it has to set h_rsv_handle to NULL as otherwise jbd2_journal_stop() |
|---|
| 471 | 538 | * on the parent handle will dispose the reserved one. Reserved handle has to |
|---|
| .. | .. |
|---|
| 477 | 544 | */ |
|---|
| 478 | 545 | handle_t *jbd2_journal_start(journal_t *journal, int nblocks) |
|---|
| 479 | 546 | { |
|---|
| 480 | | - return jbd2__journal_start(journal, nblocks, 0, GFP_NOFS, 0, 0); |
|---|
| 547 | + return jbd2__journal_start(journal, nblocks, 0, 0, GFP_NOFS, 0, 0); |
|---|
| 481 | 548 | } |
|---|
| 482 | 549 | EXPORT_SYMBOL(jbd2_journal_start); |
|---|
| 550 | + |
|---|
| 551 | +static void __jbd2_journal_unreserve_handle(handle_t *handle, transaction_t *t) |
|---|
| 552 | +{ |
|---|
| 553 | + journal_t *journal = handle->h_journal; |
|---|
| 554 | + |
|---|
| 555 | + WARN_ON(!handle->h_reserved); |
|---|
| 556 | + sub_reserved_credits(journal, handle->h_total_credits); |
|---|
| 557 | + if (t) |
|---|
| 558 | + atomic_sub(handle->h_total_credits, &t->t_outstanding_credits); |
|---|
| 559 | +} |
|---|
| 483 | 560 | |
|---|
| 484 | 561 | void jbd2_journal_free_reserved(handle_t *handle) |
|---|
| 485 | 562 | { |
|---|
| 486 | 563 | journal_t *journal = handle->h_journal; |
|---|
| 487 | 564 | |
|---|
| 488 | | - WARN_ON(!handle->h_reserved); |
|---|
| 489 | | - sub_reserved_credits(journal, handle->h_buffer_credits); |
|---|
| 565 | + /* Get j_state_lock to pin running transaction if it exists */ |
|---|
| 566 | + read_lock(&journal->j_state_lock); |
|---|
| 567 | + __jbd2_journal_unreserve_handle(handle, journal->j_running_transaction); |
|---|
| 568 | + read_unlock(&journal->j_state_lock); |
|---|
| 490 | 569 | jbd2_free_handle(handle); |
|---|
| 491 | 570 | } |
|---|
| 492 | 571 | EXPORT_SYMBOL(jbd2_journal_free_reserved); |
|---|
| 493 | 572 | |
|---|
| 494 | 573 | /** |
|---|
| 495 | | - * int jbd2_journal_start_reserved() - start reserved handle |
|---|
| 574 | + * jbd2_journal_start_reserved() - start reserved handle |
|---|
| 496 | 575 | * @handle: handle to start |
|---|
| 497 | 576 | * @type: for handle statistics |
|---|
| 498 | 577 | * @line_no: for handle statistics |
|---|
| .. | .. |
|---|
| 538 | 617 | } |
|---|
| 539 | 618 | handle->h_type = type; |
|---|
| 540 | 619 | handle->h_line_no = line_no; |
|---|
| 620 | + trace_jbd2_handle_start(journal->j_fs_dev->bd_dev, |
|---|
| 621 | + handle->h_transaction->t_tid, type, |
|---|
| 622 | + line_no, handle->h_total_credits); |
|---|
| 541 | 623 | return 0; |
|---|
| 542 | 624 | } |
|---|
| 543 | 625 | EXPORT_SYMBOL(jbd2_journal_start_reserved); |
|---|
| 544 | 626 | |
|---|
| 545 | 627 | /** |
|---|
| 546 | | - * int jbd2_journal_extend() - extend buffer credits. |
|---|
| 628 | + * jbd2_journal_extend() - extend buffer credits. |
|---|
| 547 | 629 | * @handle: handle to 'extend' |
|---|
| 548 | 630 | * @nblocks: nr blocks to try to extend by. |
|---|
| 631 | + * @revoke_records: number of revoke records to try to extend by. |
|---|
| 549 | 632 | * |
|---|
| 550 | 633 | * Some transactions, such as large extends and truncates, can be done |
|---|
| 551 | 634 | * atomically all at once or in several stages. The operation requests |
|---|
| .. | .. |
|---|
| 562 | 645 | * return code < 0 implies an error |
|---|
| 563 | 646 | * return code > 0 implies normal transaction-full status. |
|---|
| 564 | 647 | */ |
|---|
| 565 | | -int jbd2_journal_extend(handle_t *handle, int nblocks) |
|---|
| 648 | +int jbd2_journal_extend(handle_t *handle, int nblocks, int revoke_records) |
|---|
| 566 | 649 | { |
|---|
| 567 | 650 | transaction_t *transaction = handle->h_transaction; |
|---|
| 568 | 651 | journal_t *journal; |
|---|
| .. | .. |
|---|
| 584 | 667 | goto error_out; |
|---|
| 585 | 668 | } |
|---|
| 586 | 669 | |
|---|
| 670 | + nblocks += DIV_ROUND_UP( |
|---|
| 671 | + handle->h_revoke_credits_requested + revoke_records, |
|---|
| 672 | + journal->j_revoke_records_per_block) - |
|---|
| 673 | + DIV_ROUND_UP( |
|---|
| 674 | + handle->h_revoke_credits_requested, |
|---|
| 675 | + journal->j_revoke_records_per_block); |
|---|
| 587 | 676 | spin_lock(&transaction->t_handle_lock); |
|---|
| 588 | 677 | wanted = atomic_add_return(nblocks, |
|---|
| 589 | 678 | &transaction->t_outstanding_credits); |
|---|
| .. | .. |
|---|
| 595 | 684 | goto unlock; |
|---|
| 596 | 685 | } |
|---|
| 597 | 686 | |
|---|
| 598 | | - if (wanted + (wanted >> JBD2_CONTROL_BLOCKS_SHIFT) > |
|---|
| 599 | | - jbd2_log_space_left(journal)) { |
|---|
| 600 | | - jbd_debug(3, "denied handle %p %d blocks: " |
|---|
| 601 | | - "insufficient log space\n", handle, nblocks); |
|---|
| 602 | | - atomic_sub(nblocks, &transaction->t_outstanding_credits); |
|---|
| 603 | | - goto unlock; |
|---|
| 604 | | - } |
|---|
| 605 | | - |
|---|
| 606 | 687 | trace_jbd2_handle_extend(journal->j_fs_dev->bd_dev, |
|---|
| 607 | 688 | transaction->t_tid, |
|---|
| 608 | 689 | handle->h_type, handle->h_line_no, |
|---|
| 609 | | - handle->h_buffer_credits, |
|---|
| 690 | + handle->h_total_credits, |
|---|
| 610 | 691 | nblocks); |
|---|
| 611 | 692 | |
|---|
| 612 | | - handle->h_buffer_credits += nblocks; |
|---|
| 693 | + handle->h_total_credits += nblocks; |
|---|
| 613 | 694 | handle->h_requested_credits += nblocks; |
|---|
| 695 | + handle->h_revoke_credits += revoke_records; |
|---|
| 696 | + handle->h_revoke_credits_requested += revoke_records; |
|---|
| 614 | 697 | result = 0; |
|---|
| 615 | 698 | |
|---|
| 616 | 699 | jbd_debug(3, "extended handle %p by %d\n", handle, nblocks); |
|---|
| .. | .. |
|---|
| 621 | 704 | return result; |
|---|
| 622 | 705 | } |
|---|
| 623 | 706 | |
|---|
| 707 | +static void stop_this_handle(handle_t *handle) |
|---|
| 708 | +{ |
|---|
| 709 | + transaction_t *transaction = handle->h_transaction; |
|---|
| 710 | + journal_t *journal = transaction->t_journal; |
|---|
| 711 | + int revokes; |
|---|
| 712 | + |
|---|
| 713 | + J_ASSERT(journal_current_handle() == handle); |
|---|
| 714 | + J_ASSERT(atomic_read(&transaction->t_updates) > 0); |
|---|
| 715 | + current->journal_info = NULL; |
|---|
| 716 | + /* |
|---|
| 717 | + * Subtract necessary revoke descriptor blocks from handle credits. We |
|---|
| 718 | + * take care to account only for revoke descriptor blocks the |
|---|
| 719 | + * transaction will really need as large sequences of transactions with |
|---|
| 720 | + * small numbers of revokes are relatively common. |
|---|
| 721 | + */ |
|---|
| 722 | + revokes = handle->h_revoke_credits_requested - handle->h_revoke_credits; |
|---|
| 723 | + if (revokes) { |
|---|
| 724 | + int t_revokes, revoke_descriptors; |
|---|
| 725 | + int rr_per_blk = journal->j_revoke_records_per_block; |
|---|
| 726 | + |
|---|
| 727 | + WARN_ON_ONCE(DIV_ROUND_UP(revokes, rr_per_blk) |
|---|
| 728 | + > handle->h_total_credits); |
|---|
| 729 | + t_revokes = atomic_add_return(revokes, |
|---|
| 730 | + &transaction->t_outstanding_revokes); |
|---|
| 731 | + revoke_descriptors = |
|---|
| 732 | + DIV_ROUND_UP(t_revokes, rr_per_blk) - |
|---|
| 733 | + DIV_ROUND_UP(t_revokes - revokes, rr_per_blk); |
|---|
| 734 | + handle->h_total_credits -= revoke_descriptors; |
|---|
| 735 | + } |
|---|
| 736 | + atomic_sub(handle->h_total_credits, |
|---|
| 737 | + &transaction->t_outstanding_credits); |
|---|
| 738 | + if (handle->h_rsv_handle) |
|---|
| 739 | + __jbd2_journal_unreserve_handle(handle->h_rsv_handle, |
|---|
| 740 | + transaction); |
|---|
| 741 | + if (atomic_dec_and_test(&transaction->t_updates)) |
|---|
| 742 | + wake_up(&journal->j_wait_updates); |
|---|
| 743 | + |
|---|
| 744 | + rwsem_release(&journal->j_trans_commit_map, _THIS_IP_); |
|---|
| 745 | + /* |
|---|
| 746 | + * Scope of the GFP_NOFS context is over here and so we can restore the |
|---|
| 747 | + * original alloc context. |
|---|
| 748 | + */ |
|---|
| 749 | + memalloc_nofs_restore(handle->saved_alloc_context); |
|---|
| 750 | +} |
|---|
| 624 | 751 | |
|---|
| 625 | 752 | /** |
|---|
| 626 | | - * int jbd2_journal_restart() - restart a handle . |
|---|
| 753 | + * jbd2__journal_restart() - restart a handle . |
|---|
| 627 | 754 | * @handle: handle to restart |
|---|
| 628 | 755 | * @nblocks: nr credits requested |
|---|
| 756 | + * @revoke_records: number of revoke record credits requested |
|---|
| 629 | 757 | * @gfp_mask: memory allocation flags (for start_this_handle) |
|---|
| 630 | 758 | * |
|---|
| 631 | 759 | * Restart a handle for a multi-transaction filesystem |
|---|
| .. | .. |
|---|
| 638 | 766 | * credits. We preserve reserved handle if there's any attached to the |
|---|
| 639 | 767 | * passed in handle. |
|---|
| 640 | 768 | */ |
|---|
| 641 | | -int jbd2__journal_restart(handle_t *handle, int nblocks, gfp_t gfp_mask) |
|---|
| 769 | +int jbd2__journal_restart(handle_t *handle, int nblocks, int revoke_records, |
|---|
| 770 | + gfp_t gfp_mask) |
|---|
| 642 | 771 | { |
|---|
| 643 | 772 | transaction_t *transaction = handle->h_transaction; |
|---|
| 644 | 773 | journal_t *journal; |
|---|
| 645 | 774 | tid_t tid; |
|---|
| 646 | | - int need_to_start, ret; |
|---|
| 775 | + int need_to_start; |
|---|
| 776 | + int ret; |
|---|
| 647 | 777 | |
|---|
| 648 | 778 | /* If we've had an abort of any type, don't even think about |
|---|
| 649 | 779 | * actually doing the restart! */ |
|---|
| 650 | 780 | if (is_handle_aborted(handle)) |
|---|
| 651 | 781 | return 0; |
|---|
| 652 | 782 | journal = transaction->t_journal; |
|---|
| 783 | + tid = transaction->t_tid; |
|---|
| 653 | 784 | |
|---|
| 654 | 785 | /* |
|---|
| 655 | 786 | * First unlink the handle from its current transaction, and start the |
|---|
| 656 | 787 | * commit on that. |
|---|
| 657 | 788 | */ |
|---|
| 658 | | - J_ASSERT(atomic_read(&transaction->t_updates) > 0); |
|---|
| 659 | | - J_ASSERT(journal_current_handle() == handle); |
|---|
| 660 | | - |
|---|
| 661 | | - read_lock(&journal->j_state_lock); |
|---|
| 662 | | - spin_lock(&transaction->t_handle_lock); |
|---|
| 663 | | - atomic_sub(handle->h_buffer_credits, |
|---|
| 664 | | - &transaction->t_outstanding_credits); |
|---|
| 665 | | - if (handle->h_rsv_handle) { |
|---|
| 666 | | - sub_reserved_credits(journal, |
|---|
| 667 | | - handle->h_rsv_handle->h_buffer_credits); |
|---|
| 668 | | - } |
|---|
| 669 | | - if (atomic_dec_and_test(&transaction->t_updates)) |
|---|
| 670 | | - wake_up(&journal->j_wait_updates); |
|---|
| 671 | | - tid = transaction->t_tid; |
|---|
| 672 | | - spin_unlock(&transaction->t_handle_lock); |
|---|
| 673 | | - handle->h_transaction = NULL; |
|---|
| 674 | | - current->journal_info = NULL; |
|---|
| 675 | | - |
|---|
| 676 | 789 | jbd_debug(2, "restarting handle %p\n", handle); |
|---|
| 790 | + stop_this_handle(handle); |
|---|
| 791 | + handle->h_transaction = NULL; |
|---|
| 792 | + |
|---|
| 793 | + /* |
|---|
| 794 | + * TODO: If we use READ_ONCE / WRITE_ONCE for j_commit_request we can |
|---|
| 795 | + * get rid of pointless j_state_lock traffic like this. |
|---|
| 796 | + */ |
|---|
| 797 | + read_lock(&journal->j_state_lock); |
|---|
| 677 | 798 | need_to_start = !tid_geq(journal->j_commit_request, tid); |
|---|
| 678 | 799 | read_unlock(&journal->j_state_lock); |
|---|
| 679 | 800 | if (need_to_start) |
|---|
| 680 | 801 | jbd2_log_start_commit(journal, tid); |
|---|
| 681 | | - |
|---|
| 682 | | - rwsem_release(&journal->j_trans_commit_map, 1, _THIS_IP_); |
|---|
| 683 | | - handle->h_buffer_credits = nblocks; |
|---|
| 684 | | - /* |
|---|
| 685 | | - * Restore the original nofs context because the journal restart |
|---|
| 686 | | - * is basically the same thing as journal stop and start. |
|---|
| 687 | | - * start_this_handle will start a new nofs context. |
|---|
| 688 | | - */ |
|---|
| 689 | | - memalloc_nofs_restore(handle->saved_alloc_context); |
|---|
| 802 | + handle->h_total_credits = nblocks + |
|---|
| 803 | + DIV_ROUND_UP(revoke_records, |
|---|
| 804 | + journal->j_revoke_records_per_block); |
|---|
| 805 | + handle->h_revoke_credits = revoke_records; |
|---|
| 690 | 806 | ret = start_this_handle(journal, handle, gfp_mask); |
|---|
| 807 | + trace_jbd2_handle_restart(journal->j_fs_dev->bd_dev, |
|---|
| 808 | + ret ? 0 : handle->h_transaction->t_tid, |
|---|
| 809 | + handle->h_type, handle->h_line_no, |
|---|
| 810 | + handle->h_total_credits); |
|---|
| 691 | 811 | return ret; |
|---|
| 692 | 812 | } |
|---|
| 693 | 813 | EXPORT_SYMBOL(jbd2__journal_restart); |
|---|
| .. | .. |
|---|
| 695 | 815 | |
|---|
| 696 | 816 | int jbd2_journal_restart(handle_t *handle, int nblocks) |
|---|
| 697 | 817 | { |
|---|
| 698 | | - return jbd2__journal_restart(handle, nblocks, GFP_NOFS); |
|---|
| 818 | + return jbd2__journal_restart(handle, nblocks, 0, GFP_NOFS); |
|---|
| 699 | 819 | } |
|---|
| 700 | 820 | EXPORT_SYMBOL(jbd2_journal_restart); |
|---|
| 701 | 821 | |
|---|
| 702 | 822 | /** |
|---|
| 703 | | - * void jbd2_journal_lock_updates () - establish a transaction barrier. |
|---|
| 823 | + * jbd2_journal_lock_updates () - establish a transaction barrier. |
|---|
| 704 | 824 | * @journal: Journal to establish a barrier on. |
|---|
| 705 | 825 | * |
|---|
| 706 | 826 | * This locks out any further updates from being started, and blocks |
|---|
| .. | .. |
|---|
| 759 | 879 | } |
|---|
| 760 | 880 | |
|---|
| 761 | 881 | /** |
|---|
| 762 | | - * void jbd2_journal_unlock_updates (journal_t* journal) - release barrier |
|---|
| 882 | + * jbd2_journal_unlock_updates () - release barrier |
|---|
| 763 | 883 | * @journal: Journal to release the barrier on. |
|---|
| 764 | 884 | * |
|---|
| 765 | 885 | * Release a transaction barrier obtained with jbd2_journal_lock_updates(). |
|---|
| .. | .. |
|---|
| 774 | 894 | write_lock(&journal->j_state_lock); |
|---|
| 775 | 895 | --journal->j_barrier_count; |
|---|
| 776 | 896 | write_unlock(&journal->j_state_lock); |
|---|
| 777 | | - wake_up(&journal->j_wait_transaction_locked); |
|---|
| 897 | + wake_up_all(&journal->j_wait_transaction_locked); |
|---|
| 778 | 898 | } |
|---|
| 779 | 899 | |
|---|
| 780 | 900 | static void warn_dirty_buffer(struct buffer_head *bh) |
|---|
| .. | .. |
|---|
| 843 | 963 | |
|---|
| 844 | 964 | start_lock = jiffies; |
|---|
| 845 | 965 | lock_buffer(bh); |
|---|
| 846 | | - jbd_lock_bh_state(bh); |
|---|
| 966 | + spin_lock(&jh->b_state_lock); |
|---|
| 847 | 967 | |
|---|
| 848 | 968 | /* If it takes too long to lock the buffer, trace it */ |
|---|
| 849 | 969 | time_lock = jbd2_time_diff(start_lock, jiffies); |
|---|
| .. | .. |
|---|
| 893 | 1013 | |
|---|
| 894 | 1014 | error = -EROFS; |
|---|
| 895 | 1015 | if (is_handle_aborted(handle)) { |
|---|
| 896 | | - jbd_unlock_bh_state(bh); |
|---|
| 1016 | + spin_unlock(&jh->b_state_lock); |
|---|
| 897 | 1017 | goto out; |
|---|
| 898 | 1018 | } |
|---|
| 899 | 1019 | error = 0; |
|---|
| .. | .. |
|---|
| 910 | 1030 | * this is the first time this transaction is touching this buffer, |
|---|
| 911 | 1031 | * reset the modified flag |
|---|
| 912 | 1032 | */ |
|---|
| 913 | | - jh->b_modified = 0; |
|---|
| 1033 | + jh->b_modified = 0; |
|---|
| 914 | 1034 | |
|---|
| 915 | 1035 | /* |
|---|
| 916 | 1036 | * If the buffer is not journaled right now, we need to make sure it |
|---|
| .. | .. |
|---|
| 957 | 1077 | */ |
|---|
| 958 | 1078 | if (buffer_shadow(bh)) { |
|---|
| 959 | 1079 | JBUFFER_TRACE(jh, "on shadow: sleep"); |
|---|
| 960 | | - jbd_unlock_bh_state(bh); |
|---|
| 1080 | + spin_unlock(&jh->b_state_lock); |
|---|
| 961 | 1081 | wait_on_bit_io(&bh->b_state, BH_Shadow, TASK_UNINTERRUPTIBLE); |
|---|
| 962 | 1082 | goto repeat; |
|---|
| 963 | 1083 | } |
|---|
| .. | .. |
|---|
| 978 | 1098 | JBUFFER_TRACE(jh, "generate frozen data"); |
|---|
| 979 | 1099 | if (!frozen_buffer) { |
|---|
| 980 | 1100 | JBUFFER_TRACE(jh, "allocate memory for buffer"); |
|---|
| 981 | | - jbd_unlock_bh_state(bh); |
|---|
| 1101 | + spin_unlock(&jh->b_state_lock); |
|---|
| 982 | 1102 | frozen_buffer = jbd2_alloc(jh2bh(jh)->b_size, |
|---|
| 983 | 1103 | GFP_NOFS | __GFP_NOFAIL); |
|---|
| 984 | 1104 | goto repeat; |
|---|
| .. | .. |
|---|
| 997 | 1117 | jh->b_next_transaction = transaction; |
|---|
| 998 | 1118 | |
|---|
| 999 | 1119 | done: |
|---|
| 1000 | | - jbd_unlock_bh_state(bh); |
|---|
| 1120 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1001 | 1121 | |
|---|
| 1002 | 1122 | /* |
|---|
| 1003 | 1123 | * If we are about to journal a buffer, then any revoke pending on it is |
|---|
| .. | .. |
|---|
| 1067 | 1187 | } |
|---|
| 1068 | 1188 | |
|---|
| 1069 | 1189 | /** |
|---|
| 1070 | | - * int jbd2_journal_get_write_access() - notify intent to modify a buffer for metadata (not data) update. |
|---|
| 1190 | + * jbd2_journal_get_write_access() - notify intent to modify a buffer |
|---|
| 1191 | + * for metadata (not data) update. |
|---|
| 1071 | 1192 | * @handle: transaction to add buffer modifications to |
|---|
| 1072 | 1193 | * @bh: bh to be used for metadata writes |
|---|
| 1073 | 1194 | * |
|---|
| .. | .. |
|---|
| 1111 | 1232 | * unlocked buffer beforehand. */ |
|---|
| 1112 | 1233 | |
|---|
| 1113 | 1234 | /** |
|---|
| 1114 | | - * int jbd2_journal_get_create_access () - notify intent to use newly created bh |
|---|
| 1235 | + * jbd2_journal_get_create_access () - notify intent to use newly created bh |
|---|
| 1115 | 1236 | * @handle: transaction to new buffer to |
|---|
| 1116 | 1237 | * @bh: new buffer. |
|---|
| 1117 | 1238 | * |
|---|
| .. | .. |
|---|
| 1139 | 1260 | * that case: the transaction must have deleted the buffer for it to be |
|---|
| 1140 | 1261 | * reused here. |
|---|
| 1141 | 1262 | */ |
|---|
| 1142 | | - jbd_lock_bh_state(bh); |
|---|
| 1263 | + spin_lock(&jh->b_state_lock); |
|---|
| 1143 | 1264 | J_ASSERT_JH(jh, (jh->b_transaction == transaction || |
|---|
| 1144 | 1265 | jh->b_transaction == NULL || |
|---|
| 1145 | 1266 | (jh->b_transaction == journal->j_committing_transaction && |
|---|
| .. | .. |
|---|
| 1174 | 1295 | jh->b_next_transaction = transaction; |
|---|
| 1175 | 1296 | spin_unlock(&journal->j_list_lock); |
|---|
| 1176 | 1297 | } |
|---|
| 1177 | | - jbd_unlock_bh_state(bh); |
|---|
| 1298 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1178 | 1299 | |
|---|
| 1179 | 1300 | /* |
|---|
| 1180 | 1301 | * akpm: I added this. ext3_alloc_branch can pick up new indirect |
|---|
| .. | .. |
|---|
| 1191 | 1312 | } |
|---|
| 1192 | 1313 | |
|---|
| 1193 | 1314 | /** |
|---|
| 1194 | | - * int jbd2_journal_get_undo_access() - Notify intent to modify metadata with |
|---|
| 1315 | + * jbd2_journal_get_undo_access() - Notify intent to modify metadata with |
|---|
| 1195 | 1316 | * non-rewindable consequences |
|---|
| 1196 | 1317 | * @handle: transaction |
|---|
| 1197 | 1318 | * @bh: buffer to undo |
|---|
| .. | .. |
|---|
| 1245 | 1366 | committed_data = jbd2_alloc(jh2bh(jh)->b_size, |
|---|
| 1246 | 1367 | GFP_NOFS|__GFP_NOFAIL); |
|---|
| 1247 | 1368 | |
|---|
| 1248 | | - jbd_lock_bh_state(bh); |
|---|
| 1369 | + spin_lock(&jh->b_state_lock); |
|---|
| 1249 | 1370 | if (!jh->b_committed_data) { |
|---|
| 1250 | 1371 | /* Copy out the current buffer contents into the |
|---|
| 1251 | 1372 | * preserved, committed copy. */ |
|---|
| 1252 | 1373 | JBUFFER_TRACE(jh, "generate b_committed data"); |
|---|
| 1253 | 1374 | if (!committed_data) { |
|---|
| 1254 | | - jbd_unlock_bh_state(bh); |
|---|
| 1375 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1255 | 1376 | goto repeat; |
|---|
| 1256 | 1377 | } |
|---|
| 1257 | 1378 | |
|---|
| .. | .. |
|---|
| 1259 | 1380 | committed_data = NULL; |
|---|
| 1260 | 1381 | memcpy(jh->b_committed_data, bh->b_data, bh->b_size); |
|---|
| 1261 | 1382 | } |
|---|
| 1262 | | - jbd_unlock_bh_state(bh); |
|---|
| 1383 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1263 | 1384 | out: |
|---|
| 1264 | 1385 | jbd2_journal_put_journal_head(jh); |
|---|
| 1265 | 1386 | if (unlikely(committed_data)) |
|---|
| .. | .. |
|---|
| 1268 | 1389 | } |
|---|
| 1269 | 1390 | |
|---|
| 1270 | 1391 | /** |
|---|
| 1271 | | - * void jbd2_journal_set_triggers() - Add triggers for commit writeout |
|---|
| 1392 | + * jbd2_journal_set_triggers() - Add triggers for commit writeout |
|---|
| 1272 | 1393 | * @bh: buffer to trigger on |
|---|
| 1273 | 1394 | * @type: struct jbd2_buffer_trigger_type containing the trigger(s). |
|---|
| 1274 | 1395 | * |
|---|
| .. | .. |
|---|
| 1310 | 1431 | } |
|---|
| 1311 | 1432 | |
|---|
| 1312 | 1433 | /** |
|---|
| 1313 | | - * int jbd2_journal_dirty_metadata() - mark a buffer as containing dirty metadata |
|---|
| 1434 | + * jbd2_journal_dirty_metadata() - mark a buffer as containing dirty metadata |
|---|
| 1314 | 1435 | * @handle: transaction to add buffer to. |
|---|
| 1315 | 1436 | * @bh: buffer to mark |
|---|
| 1316 | 1437 | * |
|---|
| .. | .. |
|---|
| 1339 | 1460 | struct journal_head *jh; |
|---|
| 1340 | 1461 | int ret = 0; |
|---|
| 1341 | 1462 | |
|---|
| 1342 | | - if (is_handle_aborted(handle)) |
|---|
| 1343 | | - return -EROFS; |
|---|
| 1344 | 1463 | if (!buffer_jbd(bh)) |
|---|
| 1345 | 1464 | return -EUCLEAN; |
|---|
| 1346 | 1465 | |
|---|
| .. | .. |
|---|
| 1358 | 1477 | * crucial to catch bugs so let's do a reliable check until the |
|---|
| 1359 | 1478 | * lockless handling is fully proven. |
|---|
| 1360 | 1479 | */ |
|---|
| 1361 | | - if (jh->b_transaction != transaction && |
|---|
| 1362 | | - jh->b_next_transaction != transaction) { |
|---|
| 1363 | | - jbd_lock_bh_state(bh); |
|---|
| 1480 | + if (data_race(jh->b_transaction != transaction && |
|---|
| 1481 | + jh->b_next_transaction != transaction)) { |
|---|
| 1482 | + spin_lock(&jh->b_state_lock); |
|---|
| 1364 | 1483 | J_ASSERT_JH(jh, jh->b_transaction == transaction || |
|---|
| 1365 | 1484 | jh->b_next_transaction == transaction); |
|---|
| 1366 | | - jbd_unlock_bh_state(bh); |
|---|
| 1485 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1367 | 1486 | } |
|---|
| 1368 | 1487 | if (jh->b_modified == 1) { |
|---|
| 1369 | 1488 | /* If it's in our transaction it must be in BJ_Metadata list. */ |
|---|
| 1370 | | - if (jh->b_transaction == transaction && |
|---|
| 1371 | | - jh->b_jlist != BJ_Metadata) { |
|---|
| 1372 | | - jbd_lock_bh_state(bh); |
|---|
| 1489 | + if (data_race(jh->b_transaction == transaction && |
|---|
| 1490 | + jh->b_jlist != BJ_Metadata)) { |
|---|
| 1491 | + spin_lock(&jh->b_state_lock); |
|---|
| 1373 | 1492 | if (jh->b_transaction == transaction && |
|---|
| 1374 | 1493 | jh->b_jlist != BJ_Metadata) |
|---|
| 1375 | 1494 | pr_err("JBD2: assertion failure: h_type=%u " |
|---|
| .. | .. |
|---|
| 1379 | 1498 | jh->b_jlist); |
|---|
| 1380 | 1499 | J_ASSERT_JH(jh, jh->b_transaction != transaction || |
|---|
| 1381 | 1500 | jh->b_jlist == BJ_Metadata); |
|---|
| 1382 | | - jbd_unlock_bh_state(bh); |
|---|
| 1501 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1383 | 1502 | } |
|---|
| 1384 | 1503 | goto out; |
|---|
| 1385 | 1504 | } |
|---|
| 1386 | 1505 | |
|---|
| 1387 | 1506 | journal = transaction->t_journal; |
|---|
| 1388 | | - jbd_lock_bh_state(bh); |
|---|
| 1507 | + spin_lock(&jh->b_state_lock); |
|---|
| 1508 | + |
|---|
| 1509 | + if (is_handle_aborted(handle)) { |
|---|
| 1510 | + /* |
|---|
| 1511 | + * Check journal aborting with @jh->b_state_lock locked, |
|---|
| 1512 | + * since 'jh->b_transaction' could be replaced with |
|---|
| 1513 | + * 'jh->b_next_transaction' during old transaction |
|---|
| 1514 | + * committing if journal aborted, which may fail |
|---|
| 1515 | + * assertion on 'jh->b_frozen_data == NULL'. |
|---|
| 1516 | + */ |
|---|
| 1517 | + ret = -EROFS; |
|---|
| 1518 | + goto out_unlock_bh; |
|---|
| 1519 | + } |
|---|
| 1389 | 1520 | |
|---|
| 1390 | 1521 | if (jh->b_modified == 0) { |
|---|
| 1391 | 1522 | /* |
|---|
| .. | .. |
|---|
| 1393 | 1524 | * of the transaction. This needs to be done |
|---|
| 1394 | 1525 | * once a transaction -bzzz |
|---|
| 1395 | 1526 | */ |
|---|
| 1396 | | - if (handle->h_buffer_credits <= 0) { |
|---|
| 1527 | + if (WARN_ON_ONCE(jbd2_handle_buffer_credits(handle) <= 0)) { |
|---|
| 1397 | 1528 | ret = -ENOSPC; |
|---|
| 1398 | 1529 | goto out_unlock_bh; |
|---|
| 1399 | 1530 | } |
|---|
| 1400 | 1531 | jh->b_modified = 1; |
|---|
| 1401 | | - handle->h_buffer_credits--; |
|---|
| 1532 | + handle->h_total_credits--; |
|---|
| 1402 | 1533 | } |
|---|
| 1403 | 1534 | |
|---|
| 1404 | 1535 | /* |
|---|
| .. | .. |
|---|
| 1471 | 1602 | __jbd2_journal_file_buffer(jh, transaction, BJ_Metadata); |
|---|
| 1472 | 1603 | spin_unlock(&journal->j_list_lock); |
|---|
| 1473 | 1604 | out_unlock_bh: |
|---|
| 1474 | | - jbd_unlock_bh_state(bh); |
|---|
| 1605 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1475 | 1606 | out: |
|---|
| 1476 | 1607 | JBUFFER_TRACE(jh, "exit"); |
|---|
| 1477 | 1608 | return ret; |
|---|
| 1478 | 1609 | } |
|---|
| 1479 | 1610 | |
|---|
| 1480 | 1611 | /** |
|---|
| 1481 | | - * void jbd2_journal_forget() - bforget() for potentially-journaled buffers. |
|---|
| 1612 | + * jbd2_journal_forget() - bforget() for potentially-journaled buffers. |
|---|
| 1482 | 1613 | * @handle: transaction handle |
|---|
| 1483 | 1614 | * @bh: bh to 'forget' |
|---|
| 1484 | 1615 | * |
|---|
| .. | .. |
|---|
| 1494 | 1625 | * Allow this call even if the handle has aborted --- it may be part of |
|---|
| 1495 | 1626 | * the caller's cleanup after an abort. |
|---|
| 1496 | 1627 | */ |
|---|
| 1497 | | -int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) |
|---|
| 1628 | +int jbd2_journal_forget(handle_t *handle, struct buffer_head *bh) |
|---|
| 1498 | 1629 | { |
|---|
| 1499 | 1630 | transaction_t *transaction = handle->h_transaction; |
|---|
| 1500 | 1631 | journal_t *journal; |
|---|
| .. | .. |
|---|
| 1509 | 1640 | |
|---|
| 1510 | 1641 | BUFFER_TRACE(bh, "entry"); |
|---|
| 1511 | 1642 | |
|---|
| 1512 | | - jbd_lock_bh_state(bh); |
|---|
| 1643 | + jh = jbd2_journal_grab_journal_head(bh); |
|---|
| 1644 | + if (!jh) { |
|---|
| 1645 | + __bforget(bh); |
|---|
| 1646 | + return 0; |
|---|
| 1647 | + } |
|---|
| 1513 | 1648 | |
|---|
| 1514 | | - if (!buffer_jbd(bh)) |
|---|
| 1515 | | - goto not_jbd; |
|---|
| 1516 | | - jh = bh2jh(bh); |
|---|
| 1649 | + spin_lock(&jh->b_state_lock); |
|---|
| 1517 | 1650 | |
|---|
| 1518 | 1651 | /* Critical error: attempting to delete a bitmap buffer, maybe? |
|---|
| 1519 | 1652 | * Don't do any jbd operations, and return an error. */ |
|---|
| 1520 | 1653 | if (!J_EXPECT_JH(jh, !jh->b_committed_data, |
|---|
| 1521 | 1654 | "inconsistent data on disk")) { |
|---|
| 1522 | 1655 | err = -EIO; |
|---|
| 1523 | | - goto not_jbd; |
|---|
| 1656 | + goto drop; |
|---|
| 1524 | 1657 | } |
|---|
| 1525 | 1658 | |
|---|
| 1526 | 1659 | /* keep track of whether or not this transaction modified us */ |
|---|
| .. | .. |
|---|
| 1568 | 1701 | __jbd2_journal_file_buffer(jh, transaction, BJ_Forget); |
|---|
| 1569 | 1702 | } else { |
|---|
| 1570 | 1703 | __jbd2_journal_unfile_buffer(jh); |
|---|
| 1571 | | - if (!buffer_jbd(bh)) { |
|---|
| 1572 | | - spin_unlock(&journal->j_list_lock); |
|---|
| 1573 | | - jbd_unlock_bh_state(bh); |
|---|
| 1574 | | - __bforget(bh); |
|---|
| 1575 | | - goto drop; |
|---|
| 1576 | | - } |
|---|
| 1704 | + jbd2_journal_put_journal_head(jh); |
|---|
| 1577 | 1705 | } |
|---|
| 1578 | 1706 | spin_unlock(&journal->j_list_lock); |
|---|
| 1579 | 1707 | } else if (jh->b_transaction) { |
|---|
| .. | .. |
|---|
| 1605 | 1733 | if (was_modified) |
|---|
| 1606 | 1734 | drop_reserve = 1; |
|---|
| 1607 | 1735 | } |
|---|
| 1608 | | - } |
|---|
| 1736 | + } else { |
|---|
| 1737 | + /* |
|---|
| 1738 | + * Finally, if the buffer is not belongs to any |
|---|
| 1739 | + * transaction, we can just drop it now if it has no |
|---|
| 1740 | + * checkpoint. |
|---|
| 1741 | + */ |
|---|
| 1742 | + spin_lock(&journal->j_list_lock); |
|---|
| 1743 | + if (!jh->b_cp_transaction) { |
|---|
| 1744 | + JBUFFER_TRACE(jh, "belongs to none transaction"); |
|---|
| 1745 | + spin_unlock(&journal->j_list_lock); |
|---|
| 1746 | + goto drop; |
|---|
| 1747 | + } |
|---|
| 1609 | 1748 | |
|---|
| 1610 | | -not_jbd: |
|---|
| 1611 | | - jbd_unlock_bh_state(bh); |
|---|
| 1612 | | - __brelse(bh); |
|---|
| 1749 | + /* |
|---|
| 1750 | + * Otherwise, if the buffer has been written to disk, |
|---|
| 1751 | + * it is safe to remove the checkpoint and drop it. |
|---|
| 1752 | + */ |
|---|
| 1753 | + if (!buffer_dirty(bh)) { |
|---|
| 1754 | + __jbd2_journal_remove_checkpoint(jh); |
|---|
| 1755 | + spin_unlock(&journal->j_list_lock); |
|---|
| 1756 | + goto drop; |
|---|
| 1757 | + } |
|---|
| 1758 | + |
|---|
| 1759 | + /* |
|---|
| 1760 | + * The buffer is still not written to disk, we should |
|---|
| 1761 | + * attach this buffer to current transaction so that the |
|---|
| 1762 | + * buffer can be checkpointed only after the current |
|---|
| 1763 | + * transaction commits. |
|---|
| 1764 | + */ |
|---|
| 1765 | + clear_buffer_dirty(bh); |
|---|
| 1766 | + __jbd2_journal_file_buffer(jh, transaction, BJ_Forget); |
|---|
| 1767 | + spin_unlock(&journal->j_list_lock); |
|---|
| 1768 | + } |
|---|
| 1613 | 1769 | drop: |
|---|
| 1770 | + __brelse(bh); |
|---|
| 1771 | + spin_unlock(&jh->b_state_lock); |
|---|
| 1772 | + jbd2_journal_put_journal_head(jh); |
|---|
| 1614 | 1773 | if (drop_reserve) { |
|---|
| 1615 | 1774 | /* no need to reserve log space for this block -bzzz */ |
|---|
| 1616 | | - handle->h_buffer_credits++; |
|---|
| 1775 | + handle->h_total_credits++; |
|---|
| 1617 | 1776 | } |
|---|
| 1618 | 1777 | return err; |
|---|
| 1619 | 1778 | } |
|---|
| 1620 | 1779 | |
|---|
| 1621 | 1780 | /** |
|---|
| 1622 | | - * int jbd2_journal_stop() - complete a transaction |
|---|
| 1781 | + * jbd2_journal_stop() - complete a transaction |
|---|
| 1623 | 1782 | * @handle: transaction to complete. |
|---|
| 1624 | 1783 | * |
|---|
| 1625 | 1784 | * All done for a particular handle. |
|---|
| .. | .. |
|---|
| 1642 | 1801 | tid_t tid; |
|---|
| 1643 | 1802 | pid_t pid; |
|---|
| 1644 | 1803 | |
|---|
| 1804 | + if (--handle->h_ref > 0) { |
|---|
| 1805 | + jbd_debug(4, "h_ref %d -> %d\n", handle->h_ref + 1, |
|---|
| 1806 | + handle->h_ref); |
|---|
| 1807 | + if (is_handle_aborted(handle)) |
|---|
| 1808 | + return -EIO; |
|---|
| 1809 | + return 0; |
|---|
| 1810 | + } |
|---|
| 1645 | 1811 | if (!transaction) { |
|---|
| 1646 | 1812 | /* |
|---|
| 1647 | | - * Handle is already detached from the transaction so |
|---|
| 1648 | | - * there is nothing to do other than decrease a refcount, |
|---|
| 1649 | | - * or free the handle if refcount drops to zero |
|---|
| 1813 | + * Handle is already detached from the transaction so there is |
|---|
| 1814 | + * nothing to do other than free the handle. |
|---|
| 1650 | 1815 | */ |
|---|
| 1651 | | - if (--handle->h_ref > 0) { |
|---|
| 1652 | | - jbd_debug(4, "h_ref %d -> %d\n", handle->h_ref + 1, |
|---|
| 1653 | | - handle->h_ref); |
|---|
| 1654 | | - return err; |
|---|
| 1655 | | - } else { |
|---|
| 1656 | | - if (handle->h_rsv_handle) |
|---|
| 1657 | | - jbd2_free_handle(handle->h_rsv_handle); |
|---|
| 1658 | | - goto free_and_exit; |
|---|
| 1659 | | - } |
|---|
| 1816 | + memalloc_nofs_restore(handle->saved_alloc_context); |
|---|
| 1817 | + goto free_and_exit; |
|---|
| 1660 | 1818 | } |
|---|
| 1661 | 1819 | journal = transaction->t_journal; |
|---|
| 1662 | | - |
|---|
| 1663 | | - J_ASSERT(journal_current_handle() == handle); |
|---|
| 1820 | + tid = transaction->t_tid; |
|---|
| 1664 | 1821 | |
|---|
| 1665 | 1822 | if (is_handle_aborted(handle)) |
|---|
| 1666 | 1823 | err = -EIO; |
|---|
| 1667 | | - else |
|---|
| 1668 | | - J_ASSERT(atomic_read(&transaction->t_updates) > 0); |
|---|
| 1669 | | - |
|---|
| 1670 | | - if (--handle->h_ref > 0) { |
|---|
| 1671 | | - jbd_debug(4, "h_ref %d -> %d\n", handle->h_ref + 1, |
|---|
| 1672 | | - handle->h_ref); |
|---|
| 1673 | | - return err; |
|---|
| 1674 | | - } |
|---|
| 1675 | 1824 | |
|---|
| 1676 | 1825 | jbd_debug(4, "Handle %p going down\n", handle); |
|---|
| 1677 | 1826 | trace_jbd2_handle_stats(journal->j_fs_dev->bd_dev, |
|---|
| 1678 | | - transaction->t_tid, |
|---|
| 1679 | | - handle->h_type, handle->h_line_no, |
|---|
| 1827 | + tid, handle->h_type, handle->h_line_no, |
|---|
| 1680 | 1828 | jiffies - handle->h_start_jiffies, |
|---|
| 1681 | 1829 | handle->h_sync, handle->h_requested_credits, |
|---|
| 1682 | 1830 | (handle->h_requested_credits - |
|---|
| 1683 | | - handle->h_buffer_credits)); |
|---|
| 1831 | + handle->h_total_credits)); |
|---|
| 1684 | 1832 | |
|---|
| 1685 | 1833 | /* |
|---|
| 1686 | 1834 | * Implement synchronous transaction batching. If the handle |
|---|
| .. | .. |
|---|
| 1740 | 1888 | |
|---|
| 1741 | 1889 | if (handle->h_sync) |
|---|
| 1742 | 1890 | transaction->t_synchronous_commit = 1; |
|---|
| 1743 | | - current->journal_info = NULL; |
|---|
| 1744 | | - atomic_sub(handle->h_buffer_credits, |
|---|
| 1745 | | - &transaction->t_outstanding_credits); |
|---|
| 1746 | 1891 | |
|---|
| 1747 | 1892 | /* |
|---|
| 1748 | 1893 | * If the handle is marked SYNC, we need to set another commit |
|---|
| 1749 | | - * going! We also want to force a commit if the current |
|---|
| 1750 | | - * transaction is occupying too much of the log, or if the |
|---|
| 1751 | | - * transaction is too old now. |
|---|
| 1894 | + * going! We also want to force a commit if the transaction is too |
|---|
| 1895 | + * old now. |
|---|
| 1752 | 1896 | */ |
|---|
| 1753 | 1897 | if (handle->h_sync || |
|---|
| 1754 | | - (atomic_read(&transaction->t_outstanding_credits) > |
|---|
| 1755 | | - journal->j_max_transaction_buffers) || |
|---|
| 1756 | 1898 | time_after_eq(jiffies, transaction->t_expires)) { |
|---|
| 1757 | 1899 | /* Do this even for aborted journals: an abort still |
|---|
| 1758 | 1900 | * completes the commit thread, it just doesn't write |
|---|
| .. | .. |
|---|
| 1761 | 1903 | jbd_debug(2, "transaction too old, requesting commit for " |
|---|
| 1762 | 1904 | "handle %p\n", handle); |
|---|
| 1763 | 1905 | /* This is non-blocking */ |
|---|
| 1764 | | - jbd2_log_start_commit(journal, transaction->t_tid); |
|---|
| 1906 | + jbd2_log_start_commit(journal, tid); |
|---|
| 1765 | 1907 | |
|---|
| 1766 | 1908 | /* |
|---|
| 1767 | 1909 | * Special case: JBD2_SYNC synchronous updates require us |
|---|
| .. | .. |
|---|
| 1772 | 1914 | } |
|---|
| 1773 | 1915 | |
|---|
| 1774 | 1916 | /* |
|---|
| 1775 | | - * Once we drop t_updates, if it goes to zero the transaction |
|---|
| 1776 | | - * could start committing on us and eventually disappear. So |
|---|
| 1777 | | - * once we do this, we must not dereference transaction |
|---|
| 1778 | | - * pointer again. |
|---|
| 1917 | + * Once stop_this_handle() drops t_updates, the transaction could start |
|---|
| 1918 | + * committing on us and eventually disappear. So we must not |
|---|
| 1919 | + * dereference transaction pointer again after calling |
|---|
| 1920 | + * stop_this_handle(). |
|---|
| 1779 | 1921 | */ |
|---|
| 1780 | | - tid = transaction->t_tid; |
|---|
| 1781 | | - if (atomic_dec_and_test(&transaction->t_updates)) { |
|---|
| 1782 | | - wake_up(&journal->j_wait_updates); |
|---|
| 1783 | | - if (journal->j_barrier_count) |
|---|
| 1784 | | - wake_up(&journal->j_wait_transaction_locked); |
|---|
| 1785 | | - } |
|---|
| 1786 | | - |
|---|
| 1787 | | - rwsem_release(&journal->j_trans_commit_map, 1, _THIS_IP_); |
|---|
| 1922 | + stop_this_handle(handle); |
|---|
| 1788 | 1923 | |
|---|
| 1789 | 1924 | if (wait_for_commit) |
|---|
| 1790 | 1925 | err = jbd2_log_wait_commit(journal, tid); |
|---|
| 1791 | 1926 | |
|---|
| 1792 | | - if (handle->h_rsv_handle) |
|---|
| 1793 | | - jbd2_journal_free_reserved(handle->h_rsv_handle); |
|---|
| 1794 | 1927 | free_and_exit: |
|---|
| 1795 | | - /* |
|---|
| 1796 | | - * Scope of the GFP_NOFS context is over here and so we can restore the |
|---|
| 1797 | | - * original alloc context. |
|---|
| 1798 | | - */ |
|---|
| 1799 | | - memalloc_nofs_restore(handle->saved_alloc_context); |
|---|
| 1928 | + if (handle->h_rsv_handle) |
|---|
| 1929 | + jbd2_free_handle(handle->h_rsv_handle); |
|---|
| 1800 | 1930 | jbd2_free_handle(handle); |
|---|
| 1801 | 1931 | return err; |
|---|
| 1802 | 1932 | } |
|---|
| .. | .. |
|---|
| 1814 | 1944 | * |
|---|
| 1815 | 1945 | * j_list_lock is held. |
|---|
| 1816 | 1946 | * |
|---|
| 1817 | | - * jbd_lock_bh_state(jh2bh(jh)) is held. |
|---|
| 1947 | + * jh->b_state_lock is held. |
|---|
| 1818 | 1948 | */ |
|---|
| 1819 | 1949 | |
|---|
| 1820 | 1950 | static inline void |
|---|
| .. | .. |
|---|
| 1838 | 1968 | * |
|---|
| 1839 | 1969 | * Called with j_list_lock held, and the journal may not be locked. |
|---|
| 1840 | 1970 | * |
|---|
| 1841 | | - * jbd_lock_bh_state(jh2bh(jh)) is held. |
|---|
| 1971 | + * jh->b_state_lock is held. |
|---|
| 1842 | 1972 | */ |
|---|
| 1843 | 1973 | |
|---|
| 1844 | 1974 | static inline void |
|---|
| .. | .. |
|---|
| 1870 | 2000 | transaction_t *transaction; |
|---|
| 1871 | 2001 | struct buffer_head *bh = jh2bh(jh); |
|---|
| 1872 | 2002 | |
|---|
| 1873 | | - J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh)); |
|---|
| 2003 | + lockdep_assert_held(&jh->b_state_lock); |
|---|
| 1874 | 2004 | transaction = jh->b_transaction; |
|---|
| 1875 | 2005 | if (transaction) |
|---|
| 1876 | 2006 | assert_spin_locked(&transaction->t_journal->j_list_lock); |
|---|
| .. | .. |
|---|
| 1907 | 2037 | } |
|---|
| 1908 | 2038 | |
|---|
| 1909 | 2039 | /* |
|---|
| 1910 | | - * Remove buffer from all transactions. |
|---|
| 2040 | + * Remove buffer from all transactions. The caller is responsible for dropping |
|---|
| 2041 | + * the jh reference that belonged to the transaction. |
|---|
| 1911 | 2042 | * |
|---|
| 1912 | 2043 | * Called with bh_state lock and j_list_lock |
|---|
| 1913 | | - * |
|---|
| 1914 | | - * jh and bh may be already freed when this function returns. |
|---|
| 1915 | 2044 | */ |
|---|
| 1916 | 2045 | static void __jbd2_journal_unfile_buffer(struct journal_head *jh) |
|---|
| 1917 | 2046 | { |
|---|
| .. | .. |
|---|
| 1920 | 2049 | |
|---|
| 1921 | 2050 | __jbd2_journal_temp_unlink_buffer(jh); |
|---|
| 1922 | 2051 | jh->b_transaction = NULL; |
|---|
| 1923 | | - jbd2_journal_put_journal_head(jh); |
|---|
| 1924 | 2052 | } |
|---|
| 1925 | 2053 | |
|---|
| 1926 | 2054 | void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh) |
|---|
| .. | .. |
|---|
| 1929 | 2057 | |
|---|
| 1930 | 2058 | /* Get reference so that buffer cannot be freed before we unlock it */ |
|---|
| 1931 | 2059 | get_bh(bh); |
|---|
| 1932 | | - jbd_lock_bh_state(bh); |
|---|
| 2060 | + spin_lock(&jh->b_state_lock); |
|---|
| 1933 | 2061 | spin_lock(&journal->j_list_lock); |
|---|
| 1934 | 2062 | __jbd2_journal_unfile_buffer(jh); |
|---|
| 1935 | 2063 | spin_unlock(&journal->j_list_lock); |
|---|
| 1936 | | - jbd_unlock_bh_state(bh); |
|---|
| 2064 | + spin_unlock(&jh->b_state_lock); |
|---|
| 2065 | + jbd2_journal_put_journal_head(jh); |
|---|
| 1937 | 2066 | __brelse(bh); |
|---|
| 1938 | 2067 | } |
|---|
| 1939 | 2068 | |
|---|
| 1940 | 2069 | /* |
|---|
| 1941 | 2070 | * Called from jbd2_journal_try_to_free_buffers(). |
|---|
| 1942 | 2071 | * |
|---|
| 1943 | | - * Called under jbd_lock_bh_state(bh) |
|---|
| 2072 | + * Called under jh->b_state_lock |
|---|
| 1944 | 2073 | */ |
|---|
| 1945 | 2074 | static void |
|---|
| 1946 | 2075 | __journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh) |
|---|
| .. | .. |
|---|
| 1967 | 2096 | } |
|---|
| 1968 | 2097 | |
|---|
| 1969 | 2098 | /** |
|---|
| 1970 | | - * int jbd2_journal_try_to_free_buffers() - try to free page buffers. |
|---|
| 2099 | + * jbd2_journal_try_to_free_buffers() - try to free page buffers. |
|---|
| 1971 | 2100 | * @journal: journal for operation |
|---|
| 1972 | 2101 | * @page: to try and free |
|---|
| 1973 | | - * @gfp_mask: we use the mask to detect how hard should we try to release |
|---|
| 1974 | | - * buffers. If __GFP_DIRECT_RECLAIM and __GFP_FS is set, we wait for commit |
|---|
| 1975 | | - * code to release the buffers. |
|---|
| 1976 | | - * |
|---|
| 1977 | 2102 | * |
|---|
| 1978 | 2103 | * For all the buffers on this page, |
|---|
| 1979 | 2104 | * if they are fully written out ordered data, move them onto BUF_CLEAN |
|---|
| .. | .. |
|---|
| 2004 | 2129 | * |
|---|
| 2005 | 2130 | * Return 0 on failure, 1 on success |
|---|
| 2006 | 2131 | */ |
|---|
| 2007 | | -int jbd2_journal_try_to_free_buffers(journal_t *journal, |
|---|
| 2008 | | - struct page *page, gfp_t gfp_mask) |
|---|
| 2132 | +int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page) |
|---|
| 2009 | 2133 | { |
|---|
| 2010 | 2134 | struct buffer_head *head; |
|---|
| 2011 | 2135 | struct buffer_head *bh; |
|---|
| .. | .. |
|---|
| 2028 | 2152 | if (!jh) |
|---|
| 2029 | 2153 | continue; |
|---|
| 2030 | 2154 | |
|---|
| 2031 | | - jbd_lock_bh_state(bh); |
|---|
| 2155 | + spin_lock(&jh->b_state_lock); |
|---|
| 2032 | 2156 | __journal_try_to_free_buffer(journal, bh); |
|---|
| 2157 | + spin_unlock(&jh->b_state_lock); |
|---|
| 2033 | 2158 | jbd2_journal_put_journal_head(jh); |
|---|
| 2034 | | - jbd_unlock_bh_state(bh); |
|---|
| 2035 | 2159 | if (buffer_jbd(bh)) |
|---|
| 2036 | 2160 | goto busy; |
|---|
| 2037 | 2161 | |
|---|
| .. | .. |
|---|
| 2067 | 2191 | * |
|---|
| 2068 | 2192 | * Called under j_list_lock. |
|---|
| 2069 | 2193 | * |
|---|
| 2070 | | - * Called under jbd_lock_bh_state(bh). |
|---|
| 2194 | + * Called under jh->b_state_lock. |
|---|
| 2071 | 2195 | */ |
|---|
| 2072 | 2196 | static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction) |
|---|
| 2073 | 2197 | { |
|---|
| .. | .. |
|---|
| 2088 | 2212 | } else { |
|---|
| 2089 | 2213 | JBUFFER_TRACE(jh, "on running transaction"); |
|---|
| 2090 | 2214 | __jbd2_journal_unfile_buffer(jh); |
|---|
| 2215 | + jbd2_journal_put_journal_head(jh); |
|---|
| 2091 | 2216 | } |
|---|
| 2092 | 2217 | return may_free; |
|---|
| 2093 | 2218 | } |
|---|
| .. | .. |
|---|
| 2154 | 2279 | * holding the page lock. --sct |
|---|
| 2155 | 2280 | */ |
|---|
| 2156 | 2281 | |
|---|
| 2157 | | - if (!buffer_jbd(bh)) |
|---|
| 2282 | + jh = jbd2_journal_grab_journal_head(bh); |
|---|
| 2283 | + if (!jh) |
|---|
| 2158 | 2284 | goto zap_buffer_unlocked; |
|---|
| 2159 | 2285 | |
|---|
| 2160 | 2286 | /* OK, we have data buffer in journaled mode */ |
|---|
| 2161 | 2287 | write_lock(&journal->j_state_lock); |
|---|
| 2162 | | - jbd_lock_bh_state(bh); |
|---|
| 2288 | + spin_lock(&jh->b_state_lock); |
|---|
| 2163 | 2289 | spin_lock(&journal->j_list_lock); |
|---|
| 2164 | | - |
|---|
| 2165 | | - jh = jbd2_journal_grab_journal_head(bh); |
|---|
| 2166 | | - if (!jh) |
|---|
| 2167 | | - goto zap_buffer_no_jh; |
|---|
| 2168 | 2290 | |
|---|
| 2169 | 2291 | /* |
|---|
| 2170 | 2292 | * We cannot remove the buffer from checkpoint lists until the |
|---|
| .. | .. |
|---|
| 2244 | 2366 | * for commit and try again. |
|---|
| 2245 | 2367 | */ |
|---|
| 2246 | 2368 | if (partial_page) { |
|---|
| 2247 | | - jbd2_journal_put_journal_head(jh); |
|---|
| 2248 | 2369 | spin_unlock(&journal->j_list_lock); |
|---|
| 2249 | | - jbd_unlock_bh_state(bh); |
|---|
| 2370 | + spin_unlock(&jh->b_state_lock); |
|---|
| 2250 | 2371 | write_unlock(&journal->j_state_lock); |
|---|
| 2372 | + jbd2_journal_put_journal_head(jh); |
|---|
| 2251 | 2373 | return -EBUSY; |
|---|
| 2252 | 2374 | } |
|---|
| 2253 | 2375 | /* |
|---|
| .. | .. |
|---|
| 2261 | 2383 | if (journal->j_running_transaction && buffer_jbddirty(bh)) |
|---|
| 2262 | 2384 | jh->b_next_transaction = journal->j_running_transaction; |
|---|
| 2263 | 2385 | jh->b_modified = 0; |
|---|
| 2264 | | - jbd2_journal_put_journal_head(jh); |
|---|
| 2265 | 2386 | spin_unlock(&journal->j_list_lock); |
|---|
| 2266 | | - jbd_unlock_bh_state(bh); |
|---|
| 2387 | + spin_unlock(&jh->b_state_lock); |
|---|
| 2267 | 2388 | write_unlock(&journal->j_state_lock); |
|---|
| 2389 | + jbd2_journal_put_journal_head(jh); |
|---|
| 2268 | 2390 | return 0; |
|---|
| 2269 | 2391 | } else { |
|---|
| 2270 | 2392 | /* Good, the buffer belongs to the running transaction. |
|---|
| .. | .. |
|---|
| 2288 | 2410 | * here. |
|---|
| 2289 | 2411 | */ |
|---|
| 2290 | 2412 | jh->b_modified = 0; |
|---|
| 2291 | | - jbd2_journal_put_journal_head(jh); |
|---|
| 2292 | | -zap_buffer_no_jh: |
|---|
| 2293 | 2413 | spin_unlock(&journal->j_list_lock); |
|---|
| 2294 | | - jbd_unlock_bh_state(bh); |
|---|
| 2414 | + spin_unlock(&jh->b_state_lock); |
|---|
| 2295 | 2415 | write_unlock(&journal->j_state_lock); |
|---|
| 2416 | + jbd2_journal_put_journal_head(jh); |
|---|
| 2296 | 2417 | zap_buffer_unlocked: |
|---|
| 2297 | 2418 | clear_buffer_dirty(bh); |
|---|
| 2298 | 2419 | J_ASSERT_BH(bh, !buffer_jbddirty(bh)); |
|---|
| .. | .. |
|---|
| 2306 | 2427 | } |
|---|
| 2307 | 2428 | |
|---|
| 2308 | 2429 | /** |
|---|
| 2309 | | - * void jbd2_journal_invalidatepage() |
|---|
| 2430 | + * jbd2_journal_invalidatepage() |
|---|
| 2310 | 2431 | * @journal: journal to use for flush... |
|---|
| 2311 | 2432 | * @page: page to flush |
|---|
| 2312 | 2433 | * @offset: start of the range to invalidate |
|---|
| .. | .. |
|---|
| 2379 | 2500 | int was_dirty = 0; |
|---|
| 2380 | 2501 | struct buffer_head *bh = jh2bh(jh); |
|---|
| 2381 | 2502 | |
|---|
| 2382 | | - J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh)); |
|---|
| 2503 | + lockdep_assert_held(&jh->b_state_lock); |
|---|
| 2383 | 2504 | assert_spin_locked(&transaction->t_journal->j_list_lock); |
|---|
| 2384 | 2505 | |
|---|
| 2385 | 2506 | J_ASSERT_JH(jh, jh->b_jlist < BJ_Types); |
|---|
| .. | .. |
|---|
| 2441 | 2562 | void jbd2_journal_file_buffer(struct journal_head *jh, |
|---|
| 2442 | 2563 | transaction_t *transaction, int jlist) |
|---|
| 2443 | 2564 | { |
|---|
| 2444 | | - jbd_lock_bh_state(jh2bh(jh)); |
|---|
| 2565 | + spin_lock(&jh->b_state_lock); |
|---|
| 2445 | 2566 | spin_lock(&transaction->t_journal->j_list_lock); |
|---|
| 2446 | 2567 | __jbd2_journal_file_buffer(jh, transaction, jlist); |
|---|
| 2447 | 2568 | spin_unlock(&transaction->t_journal->j_list_lock); |
|---|
| 2448 | | - jbd_unlock_bh_state(jh2bh(jh)); |
|---|
| 2569 | + spin_unlock(&jh->b_state_lock); |
|---|
| 2449 | 2570 | } |
|---|
| 2450 | 2571 | |
|---|
| 2451 | 2572 | /* |
|---|
| .. | .. |
|---|
| 2455 | 2576 | * buffer on that transaction's metadata list. |
|---|
| 2456 | 2577 | * |
|---|
| 2457 | 2578 | * Called under j_list_lock |
|---|
| 2458 | | - * Called under jbd_lock_bh_state(jh2bh(jh)) |
|---|
| 2579 | + * Called under jh->b_state_lock |
|---|
| 2459 | 2580 | * |
|---|
| 2460 | | - * jh and bh may be already free when this function returns |
|---|
| 2581 | + * When this function returns true, there's no next transaction to refile to |
|---|
| 2582 | + * and the caller has to drop jh reference through |
|---|
| 2583 | + * jbd2_journal_put_journal_head(). |
|---|
| 2461 | 2584 | */ |
|---|
| 2462 | | -void __jbd2_journal_refile_buffer(struct journal_head *jh) |
|---|
| 2585 | +bool __jbd2_journal_refile_buffer(struct journal_head *jh) |
|---|
| 2463 | 2586 | { |
|---|
| 2464 | 2587 | int was_dirty, jlist; |
|---|
| 2465 | 2588 | struct buffer_head *bh = jh2bh(jh); |
|---|
| 2466 | 2589 | |
|---|
| 2467 | | - J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh)); |
|---|
| 2590 | + lockdep_assert_held(&jh->b_state_lock); |
|---|
| 2468 | 2591 | if (jh->b_transaction) |
|---|
| 2469 | 2592 | assert_spin_locked(&jh->b_transaction->t_journal->j_list_lock); |
|---|
| 2470 | 2593 | |
|---|
| 2471 | 2594 | /* If the buffer is now unused, just drop it. */ |
|---|
| 2472 | 2595 | if (jh->b_next_transaction == NULL) { |
|---|
| 2473 | 2596 | __jbd2_journal_unfile_buffer(jh); |
|---|
| 2474 | | - return; |
|---|
| 2597 | + return true; |
|---|
| 2475 | 2598 | } |
|---|
| 2476 | 2599 | |
|---|
| 2477 | 2600 | /* |
|---|
| .. | .. |
|---|
| 2506 | 2629 | |
|---|
| 2507 | 2630 | if (was_dirty) |
|---|
| 2508 | 2631 | set_buffer_jbddirty(bh); |
|---|
| 2632 | + return false; |
|---|
| 2509 | 2633 | } |
|---|
| 2510 | 2634 | |
|---|
| 2511 | 2635 | /* |
|---|
| .. | .. |
|---|
| 2516 | 2640 | */ |
|---|
| 2517 | 2641 | void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh) |
|---|
| 2518 | 2642 | { |
|---|
| 2519 | | - struct buffer_head *bh = jh2bh(jh); |
|---|
| 2643 | + bool drop; |
|---|
| 2520 | 2644 | |
|---|
| 2521 | | - /* Get reference so that buffer cannot be freed before we unlock it */ |
|---|
| 2522 | | - get_bh(bh); |
|---|
| 2523 | | - jbd_lock_bh_state(bh); |
|---|
| 2645 | + spin_lock(&jh->b_state_lock); |
|---|
| 2524 | 2646 | spin_lock(&journal->j_list_lock); |
|---|
| 2525 | | - __jbd2_journal_refile_buffer(jh); |
|---|
| 2526 | | - jbd_unlock_bh_state(bh); |
|---|
| 2647 | + drop = __jbd2_journal_refile_buffer(jh); |
|---|
| 2648 | + spin_unlock(&jh->b_state_lock); |
|---|
| 2527 | 2649 | spin_unlock(&journal->j_list_lock); |
|---|
| 2528 | | - __brelse(bh); |
|---|
| 2650 | + if (drop) |
|---|
| 2651 | + jbd2_journal_put_journal_head(jh); |
|---|
| 2529 | 2652 | } |
|---|
| 2530 | 2653 | |
|---|
| 2531 | 2654 | /* |
|---|
| .. | .. |
|---|
| 2584 | 2707 | spin_unlock(&journal->j_list_lock); |
|---|
| 2585 | 2708 | |
|---|
| 2586 | 2709 | return 0; |
|---|
| 2587 | | -} |
|---|
| 2588 | | - |
|---|
| 2589 | | -int jbd2_journal_inode_add_write(handle_t *handle, struct jbd2_inode *jinode) |
|---|
| 2590 | | -{ |
|---|
| 2591 | | - return jbd2_journal_file_inode(handle, jinode, |
|---|
| 2592 | | - JI_WRITE_DATA | JI_WAIT_DATA, 0, LLONG_MAX); |
|---|
| 2593 | | -} |
|---|
| 2594 | | - |
|---|
| 2595 | | -int jbd2_journal_inode_add_wait(handle_t *handle, struct jbd2_inode *jinode) |
|---|
| 2596 | | -{ |
|---|
| 2597 | | - return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA, 0, |
|---|
| 2598 | | - LLONG_MAX); |
|---|
| 2599 | 2710 | } |
|---|
| 2600 | 2711 | |
|---|
| 2601 | 2712 | int jbd2_journal_inode_ranged_write(handle_t *handle, |
|---|