add patch disallow-all-fallocate-operation-on-active-swapfile
[ext4-patch-queue.git] / update-PF_MEMALLOC-handling-in-ext4_write_inode
blob7529ee4b687f57088af115051fb6e62b769394a7
1 ext4: update PF_MEMALLOC handling in ext4_write_inode()
3 The special handling of PF_MEMALLOC callers in ext4_write_inode()
4 shouldn't be necessary as there shouldn't be any. Warn about it. Also
5 update comment before the function as it seems somewhat outdated.
7 (Changes modeled on an ext3 patch posted by Jan Kara to the linux-ext4
8 mailing list on Februaryt 28, 2014, which apparently never went into
9 the ext3 tree.)
11 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
12 Cc: Jan Kara <jack@suse.cz>
13 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
14 index 93f16c5..7b93df9 100644
15 --- a/fs/ext4/inode.c
16 +++ b/fs/ext4/inode.c
17 @@ -4427,21 +4427,20 @@ out_brelse:
18   *
19   * We are called from a few places:
20   *
21 - * - Within generic_file_write() for O_SYNC files.
22 + * - Within generic_file_aio_write() -> generic_write_sync() for O_SYNC files.
23   *   Here, there will be no transaction running. We wait for any running
24   *   transaction to commit.
25   *
26 - * - Within sys_sync(), kupdate and such.
27 - *   We wait on commit, if tol to.
28 + * - Within flush work (sys_sync(), kupdate and such).
29 + *   We wait on commit, if told to.
30   *
31 - * - Within prune_icache() (PF_MEMALLOC == true)
32 - *   Here we simply return.  We can't afford to block kswapd on the
33 - *   journal commit.
34 + * - Within iput_final() -> write_inode_now()
35 + *   We wait on commit, if told to.
36   *
37   * In all cases it is actually safe for us to return without doing anything,
38   * because the inode has been copied into a raw inode buffer in
39 - * ext4_mark_inode_dirty().  This is a correctness thing for O_SYNC and for
40 - * knfsd.
41 + * ext4_mark_inode_dirty().  This is a correctness thing for WB_SYNC_ALL
42 + * writeback.
43   *
44   * Note that we are absolutely dependent upon all inode dirtiers doing the
45   * right thing: they *must* call mark_inode_dirty() after dirtying info in
46 @@ -4453,15 +4452,15 @@ out_brelse:
47   *     stuff();
48   *     inode->i_size = expr;
49   *
50 - * is in error because a kswapd-driven write_inode() could occur while
51 - * `stuff()' is running, and the new i_size will be lost.  Plus the inode
52 - * will no longer be on the superblock's dirty inode list.
53 + * is in error because write_inode() could occur while `stuff()' is running,
54 + * and the new i_size will be lost.  Plus the inode will no longer be on the
55 + * superblock's dirty inode list.
56   */
57  int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
58  {
59         int err;
61 -       if (current->flags & PF_MEMALLOC)
62 +       if (WARN_ON_ONCE(current->flags & PF_MEMALLOC))
63                 return 0;
65         if (EXT4_SB(inode->i_sb)->s_journal) {