From: ebiederm@xmission.com (Eric W. Biederman) Subject: Re: [PATCH 06/20] sysfs: Use dentry_ops instead of directly playing with the dcache Date: Thu, 21 May 2009 00:37:30 -0700 Message-ID: References: <1242865694-2100-1-git-send-email-ebiederm@xmission.com> <1242865694-2100-2-git-send-email-ebiederm@xmission.com> <1242865694-2100-3-git-send-email-ebiederm@xmission.com> <1242865694-2100-4-git-send-email-ebiederm@xmission.com> <1242865694-2100-5-git-send-email-ebiederm@xmission.com> <1242865694-2100-6-git-send-email-ebiederm@xmission.com> <4A14F781.6010103@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Andrew Morton , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Cornelia Huck , linux-fsdevel@vger.kernel.org, "Eric W. Biederman" To: Tejun Heo Return-path: Received: from out02.mta.xmission.com ([166.70.13.232]:56016 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751985AbZEUHhc (ORCPT ); Thu, 21 May 2009 03:37:32 -0400 In-Reply-To: <4A14F781.6010103@kernel.org> (Tejun Heo's message of "Thu\, 21 May 2009 15\:41\:05 +0900") Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Tejun Heo writes: >> +static int sysfs_dentry_revalidate(struct dentry *dentry, struct nameidata *nd) >> +{ >> + struct sysfs_dirent *sd = dentry->d_fsdata; >> + int is_dir; >> + >> + mutex_lock(&sysfs_mutex); >> + >> + /* The sysfs dirent has been deleted */ >> + if (sd->s_flags & SYSFS_FLAG_REMOVED) >> + goto out_bad; >> + >> + mutex_unlock(&sysfs_mutex); >> +out_valid: >> + return 1; >> +out_bad: >> + /* Remove the dentry from the dcache hashes. >> + * If this is a deleted dentry we use d_drop instead of d_delete >> + * so sysfs doesn't need to cope with negative dentries. >> + */ >> + is_dir = (sysfs_type(sd) == SYSFS_DIR); >> + mutex_unlock(&sysfs_mutex); >> + if (is_dir) { >> + /* If we have submounts we must allow the vfs caches >> + * to lie about the state of the filesystem to prevent >> + * leaks and other nasty things. >> + */ >> + if (have_submounts(dentry)) >> + goto out_valid; >> + shrink_dcache_parent(dentry); >> + } >> + d_drop(dentry); >> + return 0; >> +} > > Ummm... what happens if sysfs recreates those identical nodes again > while the old dentries are lingering? The dead ones will linger till > the submounts are gone and then look ups after that will show the new > ones, right? Yep. On the vfs level. The sysfs dirent tree will reflect what is going on with the hardware. This is a vfs misfeature, that I hope someday we will get fixed. But for now it is better not to leak mount points. Especially since no one actually mounts things on sysfs. Eric