ext4: fix a race in the ext4 shutdown path
commit abbc3f9395
upstream.
This patch fixes a race between the shutdown path and bio completion
handling. In the ext4 direct io path with async io, after submitting a
bio to the block layer, if journal starting fails,
ext4_direct_IO_write() would bail out pretending that the IO
failed. The caller would have had no way of knowing whether or not the
IO was successfully submitted. So instead, we return -EIOCBQUEUED in
this case. Now, the caller knows that the IO was submitted. The bio
completion handler takes care of the error.
Tested: Ran the shutdown xfstest test 461 in loop for over 2 hours across
4 machines resulting in over 400 runs. Verified that the race didn't
occur. Usually the race was seen in about 20-30 iterations.
Signed-off-by: Harshad Shirwadkar <harshads@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
879bcbe091
commit
4d4d103a1b
@ -3724,10 +3724,18 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
|
|||||||
/* Credits for sb + inode write */
|
/* Credits for sb + inode write */
|
||||||
handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
|
handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
|
||||||
if (IS_ERR(handle)) {
|
if (IS_ERR(handle)) {
|
||||||
/* This is really bad luck. We've written the data
|
/*
|
||||||
* but cannot extend i_size. Bail out and pretend
|
* We wrote the data but cannot extend
|
||||||
* the write failed... */
|
* i_size. Bail out. In async io case, we do
|
||||||
ret = PTR_ERR(handle);
|
* not return error here because we have
|
||||||
|
* already submmitted the corresponding
|
||||||
|
* bio. Returning error here makes the caller
|
||||||
|
* think that this IO is done and failed
|
||||||
|
* resulting in race with bio's completion
|
||||||
|
* handler.
|
||||||
|
*/
|
||||||
|
if (!ret)
|
||||||
|
ret = PTR_ERR(handle);
|
||||||
if (inode->i_nlink)
|
if (inode->i_nlink)
|
||||||
ext4_orphan_del(NULL, inode);
|
ext4_orphan_del(NULL, inode);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user