ext3: fix lock inversion in direct IO
ext3: fix lock inversion in direct IO

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.

[5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org: build fix]
Signed-off-by: Jan Kara <596727c8a0ea4db3ba2ceceedccbacd3d7b371b8@suse.cz>
Cc: <1269efedfb983ffa0fcddcd77de5cd0e558a37da@vger.kernel.org>
Cc: Zach Brown <bdd5f2a410e3c75a25da3e38f76d719a18e93cd3@oracle.com>
Cc: Badari Pulavarty <a0471031ec5071754e15184cabeebf7217ef1fd9@us.ibm.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas