• L
    [XFS] Fix race condition in xfs_write(). · 2a329631
    Lachlan McIlroy 提交于
    This change addresses a race in xfs_write() where, for direct I/O, the
    flags need_i_mutex and need_flush are setup before the iolock is acquired.
    The logic used to setup the flags may change between setting the flags and
    acquiring the iolock resulting in these flags having incorrect values. For
    example, if a file is not currently cached then need_i_mutex is set to
    zero and then if the file is cached before the iolock is acquired we will
    fail to do the flushinval before the direct write.
    
    The flush (and also the call to xfs_zero_eof()) need to be done with the
    iolock held exclusive so we need to acquire the iolock before checking for
    cached data (or if the write begins after eof) to prevent this state from
    changing. For direct I/O I've chosen to always acquire the iolock in
    shared mode initially and if there is a need to promote it then drop it
    and reacquire it.
    
    There's also some other tidy-ups including removing the O_APPEND offset
    adjustment since that work is done in generic_write_checks() (and we don't
    use offset as an input parameter anywhere).
    
    SGI-PV: 962170
    SGI-Modid: xfs-linux-melb:xfs-kern:28319a
    Signed-off-by: NLachlan McIlroy <lachlan@sgi.com>
    Signed-off-by: NDavid Chinner <dgc@sgi.com>
    Signed-off-by: NTim Shimmin <tes@sgi.com>
    2a329631
xfs_lrw.c 25.3 KB