• Jan Kara's avatar
    ext3: fix lock inversion in direct IO · bd1939de
    Jan Kara authored
    We cannot start transaction in ext3_direct_IO() and just let it last during
    the whole write because dio_get_page() acquires mmap_sem which ranks above
    transaction start (e.g.  because we have dependency chain
    mmap_sem->PageLock->journal_start, or because we update atime while holding
    mmap_sem) and thus deadlocks could happen.  We solve the problem by
    starting a transaction separately for each ext3_get_block() call.
    
    We *could* have a problem that we allocate a block and before its data are
    written out the machine crashes and thus we expose stale data.  But that
    does not happen because for hole-filling generic code falls back to
    buffered writes and for file extension, we add inode to orphan list and
    thus in case of crash, journal replay will truncate inode back to the
    original size.
    
    [akpm@linux-foundation.org: build fix]
    Signed-off-by: default avatarJan Kara <jack@suse.cz>
    Cc: <linux-ext4@vger.kernel.org>
    Cc: Zach Brown <zach.brown@oracle.com>
    Cc: Badari Pulavarty <pbadari@us.ibm.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    bd1939de
inode.c 95.4 KB