• Andrew Morton's avatar
    [PATCH] JBD: journal_release_buffer: handle credits fix · 4b3044b0
    Andrew Morton authored
    There's a bug: a caller tries to journal a buffer and then decides he didn't
    want to after all.  He calls journal_release_buffer().
    
    But journal_release_buffer() is only allowed to give the caller a buffer
    credit back if it was the caller who added the buffer in the first place.
    
    journal_release_buffer() currently looks at the buffer state to work that
    out, but gets it wrong: if the buffer has been moved onto a different list by
    some other part of ext3 the credit is bogusly not returned to the caller and
    the fs can later go BUG due to handle credit exhaustion.
    
    
    The fix:
    
    Change journal_get_undo_access() to return the number of buffers which the
    caller actually added to the journal.  (one or zero).
    
    When the caller later calls journal_release_buffer(), he passes in that
    count, to tell journal_release_buffer() how many credits the caller should
    get back.
    
    For API consistency this change should also be made to
    journal_get_create_access() and journal_get_write_access().  But there is no
    requirement for that in ext3 at this time.
    
    
    The remaining bug:
    
    This logic effectively gives another transaction handle a free buffer credit.
    These could conceivably accumulate and cause a journal overflow.  This is a
    separate problem and needs changes to the t_outstanding_credits accounting
    and the logic in start_this_handle.
    4b3044b0
balloc.c 24.7 KB