• Trond Myklebust's avatar
    pNFS: Fix a deadlock when coalescing writes and returning the layout · 61f454e3
    Trond Myklebust authored
    Consider the following deadlock:
    
    Process P1	Process P2		Process P3
    ==========	==========		==========
    					lock_page(page)
    
    		lseg = pnfs_update_layout(inode)
    
    lo = NFS_I(inode)->layout
    pnfs_error_mark_layout_for_return(lo)
    
    		lock_page(page)
    
    					lseg = pnfs_update_layout(inode)
    
    In this scenario,
    - P1 has declared the layout to be in error, but P2 holds a reference to
      a layout segment on that inode, so the layoutreturn is deferred.
    - P2 is waiting for a page lock held by P3.
    - P3 is asking for a new layout segment, but is blocked waiting
      for the layoutreturn.
    
    The fix is to ensure that pnfs_error_mark_layout_for_return() does
    not set the NFS_LAYOUT_RETURN flag, which blocks P3. Instead, we allow
    the latter to call LAYOUTGET so that it can make progress and unblock
    P2.
    Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
    61f454e3
pnfs.c 73 KB