MCPcopy Create free account
hub / github.com/F-Stack/f-stack / zil_commit_waiter_timeout

Function zil_commit_waiter_timeout

freebsd/contrib/openzfs/module/zfs/zil.c:2491–2620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2489}
2490
2491static void
2492zil_commit_waiter_timeout(zilog_t *zilog, zil_commit_waiter_t *zcw)
2493{
2494 ASSERT(!MUTEX_HELD(&zilog->zl_issuer_lock));
2495 ASSERT(MUTEX_HELD(&zcw->zcw_lock));
2496 ASSERT3B(zcw->zcw_done, ==, B_FALSE);
2497
2498 lwb_t *lwb = zcw->zcw_lwb;
2499 ASSERT3P(lwb, !=, NULL);
2500 ASSERT3S(lwb->lwb_state, !=, LWB_STATE_CLOSED);
2501
2502 /*
2503 * If the lwb has already been issued by another thread, we can
2504 * immediately return since there's no work to be done (the
2505 * point of this function is to issue the lwb). Additionally, we
2506 * do this prior to acquiring the zl_issuer_lock, to avoid
2507 * acquiring it when it's not necessary to do so.
2508 */
2509 if (lwb->lwb_state == LWB_STATE_ISSUED ||
2510 lwb->lwb_state == LWB_STATE_WRITE_DONE ||
2511 lwb->lwb_state == LWB_STATE_FLUSH_DONE)
2512 return;
2513
2514 /*
2515 * In order to call zil_lwb_write_issue() we must hold the
2516 * zilog's "zl_issuer_lock". We can't simply acquire that lock,
2517 * since we're already holding the commit waiter's "zcw_lock",
2518 * and those two locks are acquired in the opposite order
2519 * elsewhere.
2520 */
2521 mutex_exit(&zcw->zcw_lock);
2522 mutex_enter(&zilog->zl_issuer_lock);
2523 mutex_enter(&zcw->zcw_lock);
2524
2525 /*
2526 * Since we just dropped and re-acquired the commit waiter's
2527 * lock, we have to re-check to see if the waiter was marked
2528 * "done" during that process. If the waiter was marked "done",
2529 * the "lwb" pointer is no longer valid (it can be free'd after
2530 * the waiter is marked "done"), so without this check we could
2531 * wind up with a use-after-free error below.
2532 */
2533 if (zcw->zcw_done)
2534 goto out;
2535
2536 ASSERT3P(lwb, ==, zcw->zcw_lwb);
2537
2538 /*
2539 * We've already checked this above, but since we hadn't acquired
2540 * the zilog's zl_issuer_lock, we have to perform this check a
2541 * second time while holding the lock.
2542 *
2543 * We don't need to hold the zl_lock since the lwb cannot transition
2544 * from OPENED to ISSUED while we hold the zl_issuer_lock. The lwb
2545 * _can_ transition from ISSUED to DONE, but it's OK to race with
2546 * that transition since we treat the lwb the same, whether it's in
2547 * the ISSUED or DONE states.
2548 *

Callers 1

zil_commit_waiterFunction · 0.85

Calls 4

mutex_exitFunction · 0.85
mutex_enterFunction · 0.85
zil_lwb_write_issueFunction · 0.85
zil_commit_writer_stallFunction · 0.85

Tested by

no test coverage detected