From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762169AbZC0UK5 (ORCPT ); Fri, 27 Mar 2009 16:10:57 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753430AbZC0UHF (ORCPT ); Fri, 27 Mar 2009 16:07:05 -0400 Received: from mx2.redhat.com ([66.187.237.31]:55358 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760983AbZC0UHC (ORCPT ); Fri, 27 Mar 2009 16:07:02 -0400 From: Eric Paris Subject: [PATCH -V2 11/13] fsnotify: fsnotify marks on inodes pin them in core To: linux-kernel@vger.kernel.org Cc: viro@zeniv.linux.org.uk, hch@infradead.org, alan@lxorguk.ukuu.org.uk, sfr@canb.auug.org.au, john@johnmccutchan.com, rlove@rlove.org, akpm@linux-foundation.org Date: Fri, 27 Mar 2009 16:06:05 -0400 Message-ID: <20090327200605.32007.66600.stgit@paris.rdu.redhat.com> In-Reply-To: <20090327200508.32007.63278.stgit@paris.rdu.redhat.com> References: <20090327200508.32007.63278.stgit@paris.rdu.redhat.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch pins any inodes with an fsnotify mark in core. The idea is that as soon as the mark is removed from the inode->fsnotify_mark_entries list the inode will be iput. In reality is doesn't quite work exactly this way. The igrab will happen when the mark is added to an inode, but the iput will happen when the inode pointer is NULL'd inside the mark. It's possible that 2 racing things will try to remove the mark from different directions. One may try to remove the mark because of an explicit request and one might try to remove it because the inode was deleted. It's possible that the removal because of inode deletion will remove the mark from the inode's list, but the removal by explicit request will actually set entry->inode == NULL; and call the iput. This is safe. Signed-off-by: Eric Paris --- fs/notify/inode_mark.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c index e59a198..e9e89d2 100644 --- a/fs/notify/inode_mark.c +++ b/fs/notify/inode_mark.c @@ -160,6 +160,8 @@ void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry) fsnotify_update_dentry_child_flags(inode); + iput(inode); + if (atomic_dec_and_test(&group->num_marks)) fsnotify_final_destroy_group(group); } @@ -231,11 +233,16 @@ void fsnotify_init_mark(struct fsnotify_mark_entry *entry, void (*free_mark)(str entry->free_mark = free_mark; } -int fsnotify_add_mark(struct fsnotify_mark_entry *entry, struct fsnotify_group *group, struct inode *inode) +int fsnotify_add_mark(struct fsnotify_mark_entry *entry, struct fsnotify_group *group, struct inode *in_inode) { struct fsnotify_mark_entry *lentry; + struct inode *inode; int ret = 0; + inode = igrab(in_inode); + if (unlikely(!inode)) + return -EINVAL; + /* * LOCKING ORDER!!!! * entry->lock