inode_mark.c 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 *  Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>

26
#include <linux/atomic.h>
27 28 29 30

#include <linux/fsnotify_backend.h>
#include "fsnotify.h"

31 32
#include "../internal.h"

33
/*
34 35
 * given a group and inode, find the mark associated with that combination.
 * if found take a reference to that mark and return it, else return NULL
36
 */
37 38
struct fsnotify_mark *fsnotify_find_inode_mark(struct fsnotify_group *group,
					       struct inode *inode)
39
{
40
	return fsnotify_find_mark(&inode->i_fsnotify_marks, group);
41
}
42

43 44
/**
 * fsnotify_unmount_inodes - an sb is unmounting.  handle any watched inodes.
45
 * @sb: superblock being unmounted.
46
 *
47
 * Called during unmount with no locks held, so needs to be safe against
48
 * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block.
49
 */
50
void fsnotify_unmount_inodes(struct super_block *sb)
51
{
52
	struct inode *inode, *iput_inode = NULL;
53

54
	spin_lock(&sb->s_inode_list_lock);
55
	list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
56
		/*
57
		 * We cannot __iget() an inode in state I_FREEING,
58 59 60
		 * I_WILL_FREE, or I_NEW which is fine because by that point
		 * the inode cannot have any associated watches.
		 */
61 62 63
		spin_lock(&inode->i_lock);
		if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) {
			spin_unlock(&inode->i_lock);
64
			continue;
65
		}
66 67 68 69 70 71 72

		/*
		 * If i_count is zero, the inode cannot have any watches and
		 * doing an __iget/iput with MS_ACTIVE clear would actually
		 * evict all inodes with zero i_count from icache which is
		 * unnecessarily violent and may in fact be illegal to do.
		 */
73 74
		if (!atomic_read(&inode->i_count)) {
			spin_unlock(&inode->i_lock);
75
			continue;
76
		}
77

78
		__iget(inode);
79
		spin_unlock(&inode->i_lock);
80
		spin_unlock(&sb->s_inode_list_lock);
81

82 83
		if (iput_inode)
			iput(iput_inode);
84 85 86 87 88 89

		/* for each watch, send FS_UNMOUNT and then remove it */
		fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0);

		fsnotify_inode_delete(inode);

90
		iput_inode = inode;
91

92
		spin_lock(&sb->s_inode_list_lock);
93
	}
94
	spin_unlock(&sb->s_inode_list_lock);
95 96 97

	if (iput_inode)
		iput(iput_inode);
98
}
新手
引导
客服 返回
顶部