Skip to content

Commit aabb8fd

Browse files
Nick PigginAl Viro
authored andcommitted
fs: avoid I_NEW inodes
To be on the safe side, it should be less fragile to exclude I_NEW inodes from inode list scans by default (unless there is an important reason to have them). Normally they will get excluded (eg. by zero refcount or writecount etc), however it is a bit fragile for list walkers to know exactly what parts of the inode state is set up and valid to test when in I_NEW. So along these lines, move I_NEW checks upward as well (sometimes taking I_FREEING etc checks with them too -- this shouldn't be a problem should it?) Signed-off-by: Nick Piggin <npiggin@suse.de> Acked-by: Jan Kara <jack@suse.cz> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 1bd7903 commit aabb8fd

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎fs/dquot.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,12 @@ static void add_dquot_ref(struct super_block *sb, int type)
789789

790790
spin_lock(&inode_lock);
791791
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
792+
if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW))
793+
continue;
792794
if (!atomic_read(&inode->i_writecount))
793795
continue;
794796
if (!dqinit_needed(inode, type))
795797
continue;
796-
if (inode->i_state & (I_FREEING|I_WILL_FREE))
797-
continue;
798798

799799
__iget(inode);
800800
spin_unlock(&inode_lock);
@@ -870,6 +870,12 @@ static void remove_dquot_ref(struct super_block *sb, int type,
870870

871871
spin_lock(&inode_lock);
872872
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
873+
/*
874+
* We have to scan also I_NEW inodes because they can already
875+
* have quota pointer initialized. Luckily, we need to touch
876+
* only quota pointers and these have separate locking
877+
* (dqptr_sem).
878+
*/
873879
if (!IS_NOQUOTA(inode))
874880
remove_inode_dquot_ref(inode, type, tofree_head);
875881
}

‎fs/drop_caches.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void drop_pagecache_sb(struct super_block *sb)
1818

1919
spin_lock(&inode_lock);
2020
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
21-
if (inode->i_state & (I_FREEING|I_WILL_FREE))
21+
if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW))
2222
continue;
2323
if (inode->i_mapping->nrpages == 0)
2424
continue;

‎fs/inode.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
356356
if (tmp == head)
357357
break;
358358
inode = list_entry(tmp, struct inode, i_sb_list);
359+
if (inode->i_state & I_NEW)
360+
continue;
359361
invalidate_inode_buffers(inode);
360362
if (!atomic_read(&inode->i_count)) {
361363
list_move(&inode->i_list, dispose);

‎fs/notify/inotify/inotify.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ void inotify_unmount_inodes(struct list_head *list)
379379
struct inode *need_iput_tmp;
380380
struct list_head *watches;
381381

382+
/*
383+
* We cannot __iget() an inode in state I_CLEAR, I_FREEING,
384+
* I_WILL_FREE, or I_NEW which is fine because by that point
385+
* the inode cannot have any associated watches.
386+
*/
387+
if (inode->i_state & (I_CLEAR|I_FREEING|I_WILL_FREE|I_NEW))
388+
continue;
389+
382390
/*
383391
* If i_count is zero, the inode cannot have any watches and
384392
* doing an __iget/iput with MS_ACTIVE clear would actually
@@ -388,14 +396,6 @@ void inotify_unmount_inodes(struct list_head *list)
388396
if (!atomic_read(&inode->i_count))
389397
continue;
390398

391-
/*
392-
* We cannot __iget() an inode in state I_CLEAR, I_FREEING, or
393-
* I_WILL_FREE which is fine because by that point the inode
394-
* cannot have any associated watches.
395-
*/
396-
if (inode->i_state & (I_CLEAR | I_FREEING | I_WILL_FREE))
397-
continue;
398-
399399
need_iput_tmp = need_iput;
400400
need_iput = NULL;
401401
/* In case inotify_remove_watch_locked() drops a reference. */

0 commit comments

Comments
 (0)