]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/meta-ti-glsdk.git/blob - recipes-kernel/linux/linux-ti33x-psp-3.2/3.2.14/0109-ext4-fix-race-between-unwritten-extent-conversion-an.patch
linux-ti335x-psp 3.2: update to 3.2.14
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / 3.2.14 / 0109-ext4-fix-race-between-unwritten-extent-conversion-an.patch
1 From 650bb7d911ba40c634964921badb10e175276089 Mon Sep 17 00:00:00 2001
2 From: Jeff Moyer <jmoyer@redhat.com>
3 Date: Mon, 20 Feb 2012 17:59:24 -0500
4 Subject: [PATCH 109/147] ext4: fix race between unwritten extent conversion
5  and truncate
7 commit 266991b13890049ee1a6bb95b9817f06339ee3d7 upstream.
9 The following comment in ext4_end_io_dio caught my attention:
11         /* XXX: probably should move into the real I/O completion handler */
12         inode_dio_done(inode);
14 The truncate code takes i_mutex, then calls inode_dio_wait.  Because the
15 ext4 code path above will end up dropping the mutex before it is
16 reacquired by the worker thread that does the extent conversion, it
17 seems to me that the truncate can happen out of order.  Jan Kara
18 mentioned that this might result in error messages in the system logs,
19 but that should be the extent of the "damage."
21 The fix is pretty straight-forward: don't call inode_dio_done until the
22 extent conversion is complete.
24 Reviewed-by: Jan Kara <jack@suse.cz>
25 Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
26 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 ---
29  fs/ext4/ext4.h    |    1 +
30  fs/ext4/inode.c   |   10 +++++-----
31  fs/ext4/page-io.c |    2 ++
32  3 files changed, 8 insertions(+), 5 deletions(-)
34 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
35 index 5b0e26a..655d942 100644
36 --- a/fs/ext4/ext4.h
37 +++ b/fs/ext4/ext4.h
38 @@ -184,6 +184,7 @@ struct mpage_da_data {
39  #define        EXT4_IO_END_UNWRITTEN   0x0001
40  #define EXT4_IO_END_ERROR      0x0002
41  #define EXT4_IO_END_QUEUED     0x0004
42 +#define EXT4_IO_END_DIRECT     0x0008
43  
44  struct ext4_io_page {
45         struct page     *p_page;
46 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
47 index fbd2ea4..d0dc109 100644
48 --- a/fs/ext4/inode.c
49 +++ b/fs/ext4/inode.c
50 @@ -2794,9 +2794,6 @@ out:
51  
52         /* queue the work to convert unwritten extents to written */
53         queue_work(wq, &io_end->work);
54 -
55 -       /* XXX: probably should move into the real I/O completion handler */
56 -       inode_dio_done(inode);
57  }
58  
59  static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate)
60 @@ -2920,9 +2917,12 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
61                 iocb->private = NULL;
62                 EXT4_I(inode)->cur_aio_dio = NULL;
63                 if (!is_sync_kiocb(iocb)) {
64 -                       iocb->private = ext4_init_io_end(inode, GFP_NOFS);
65 -                       if (!iocb->private)
66 +                       ext4_io_end_t *io_end =
67 +                               ext4_init_io_end(inode, GFP_NOFS);
68 +                       if (!io_end)
69                                 return -ENOMEM;
70 +                       io_end->flag |= EXT4_IO_END_DIRECT;
71 +                       iocb->private = io_end;
72                         /*
73                          * we save the io structure for current async
74                          * direct IO, so that later ext4_map_blocks()
75 diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
76 index 7e106c8..924298a 100644
77 --- a/fs/ext4/page-io.c
78 +++ b/fs/ext4/page-io.c
79 @@ -111,6 +111,8 @@ int ext4_end_io_nolock(ext4_io_end_t *io)
80         if (io->iocb)
81                 aio_complete(io->iocb, io->result, 0);
82  
83 +       if (io->flag & EXT4_IO_END_DIRECT)
84 +               inode_dio_done(inode);
85         /* Wake up anyone waiting on unwritten extent conversion */
86         if (atomic_dec_and_test(&EXT4_I(inode)->i_aiodio_unwritten))
87                 wake_up_all(ext4_ioend_wq(io->inode));
88 -- 
89 1.7.9.4