// while holding the lock — readers must do the same to avoid a
// torn optional<> read. m_bytenr/m_phys_size are immutable
// post-construction; m_refs uses atomic_load by contract.
- // Snapshot then release before streaming so a slow ostream sink
- // can't block concurrent fetches on the same node.
+ //
+ // try_lock, never block: print() runs from the status callbacks in
+ // BeesNote::get_status(), which hold BeesNote::s_mutex, while a fetching
+ // thread holds this node's m_lazy_mutex and then takes s_mutex via the
+ // BEESNOTE inside refs_fetch — the opposite order. Blocking here on a node
+ // a fetcher holds would deadlock the reporter against that fetcher. If the
+ // lock is held, leave the lazy fields unknown; a best-effort status line is
+ // worth more than a hang.
optional<int> ct;
optional<uint64_t> gen;
optional<bool> dc;
{
- unique_lock<recursive_mutex> lock(m_lazy_mutex);
- ct = m_compress_type;
- gen = m_generation;
- dc = m_datacow;
+ unique_lock<recursive_mutex> lock(m_lazy_mutex, try_to_lock);
+ if (lock.owns_lock()) {
+ ct = m_compress_type;
+ gen = m_generation;
+ dc = m_datacow;
+ }
}
os << "BtrfsExtent { bytenr " << to_hex(m_bytenr)
<< ", size " << pretty(m_phys_size)