]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - fs/notify/inode_mark.c
5cc317bad08248444ba067bdbd0f026c2ce40622
[karo-tx-linux.git] / fs / notify / inode_mark.c
1 /*
2  *  Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2, or (at your option)
7  *  any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; see the file COPYING.  If not, write to
16  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <linux/fs.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/mutex.h>
24 #include <linux/spinlock.h>
25
26 #include <linux/atomic.h>
27
28 #include <linux/fsnotify_backend.h>
29 #include "fsnotify.h"
30
31 #include "../internal.h"
32
33 /**
34  * fsnotify_unmount_inodes - an sb is unmounting.  handle any watched inodes.
35  * @sb: superblock being unmounted.
36  *
37  * Called during unmount with no locks held, so needs to be safe against
38  * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block.
39  */
40 void fsnotify_unmount_inodes(struct super_block *sb)
41 {
42         struct inode *inode, *iput_inode = NULL;
43
44         spin_lock(&sb->s_inode_list_lock);
45         list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
46                 /*
47                  * We cannot __iget() an inode in state I_FREEING,
48                  * I_WILL_FREE, or I_NEW which is fine because by that point
49                  * the inode cannot have any associated watches.
50                  */
51                 spin_lock(&inode->i_lock);
52                 if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) {
53                         spin_unlock(&inode->i_lock);
54                         continue;
55                 }
56
57                 /*
58                  * If i_count is zero, the inode cannot have any watches and
59                  * doing an __iget/iput with MS_ACTIVE clear would actually
60                  * evict all inodes with zero i_count from icache which is
61                  * unnecessarily violent and may in fact be illegal to do.
62                  */
63                 if (!atomic_read(&inode->i_count)) {
64                         spin_unlock(&inode->i_lock);
65                         continue;
66                 }
67
68                 __iget(inode);
69                 spin_unlock(&inode->i_lock);
70                 spin_unlock(&sb->s_inode_list_lock);
71
72                 if (iput_inode)
73                         iput(iput_inode);
74
75                 /* for each watch, send FS_UNMOUNT and then remove it */
76                 fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
77
78                 fsnotify_inode_delete(inode);
79
80                 iput_inode = inode;
81
82                 spin_lock(&sb->s_inode_list_lock);
83         }
84         spin_unlock(&sb->s_inode_list_lock);
85
86         if (iput_inode)
87                 iput(iput_inode);
88 }