Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753225AbXLAJVv (ORCPT ); Sat, 1 Dec 2007 04:21:51 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752546AbXLAJVj (ORCPT ); Sat, 1 Dec 2007 04:21:39 -0500 Received: from ebiederm.dsl.xmission.com ([166.70.28.69]:47544 "EHLO ebiederm.dsl.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751282AbXLAJVh (ORCPT ); Sat, 1 Dec 2007 04:21:37 -0500 From: ebiederm@xmission.com (Eric W. Biederman) To: Greg Kroah-Hartman , Greg KH Cc: Tejun Heo , Linux Containers , , cornelia.huck@de.ibm.com, stern@rowland.harvard.edu, kay.sievers@vrfy.org, , Andrew Morton , Herbert Xu , David Miller Subject: [PATCH 04/10] sysfs: Implement __sysfs_get_dentry References: Date: Sat, 01 Dec 2007 02:18:55 -0700 In-Reply-To: (Eric W. Biederman's message of "Sat, 01 Dec 2007 02:16:47 -0700") Message-ID: User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1947 Lines: 69 This function is similar but much simpler to sysfs_get_dentry returns a sysfs dentry if one curently exists. This requires less locking the sysfs_get_dentry and which makes it preferable in some contexts. Signed-off-by: Eric W. Biederman --- fs/sysfs/dir.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-) diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index cff2b12..3ec9040 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -764,6 +764,44 @@ void sysfs_remove_dir(struct kobject * kobj) __sysfs_remove_dir(sd); } +/** + * __sysfs_get_dentry - get dentry for the given sysfs_dirent + * @sb: superblock of the dentry to return + * @sd: sysfs_dirent of interest + * + * Get dentry for @sd. Only return a dentry if one currently + * exists. + * + * LOCKING: + * Kernel thread context (may sleep) + * + * RETURNS: + * Pointer to found dentry on success, NULL on failure. + */ +static struct dentry *__sysfs_get_dentry(struct super_block *sb, struct sysfs_dirent *sd) +{ + struct inode *inode; + struct dentry *dentry = NULL; + + inode = ilookup5_nowait(sysfs_sb, sd->s_ino, sysfs_ilookup_test, sd); + if (inode && !(inode->i_state & I_NEW)) { + struct dentry *alias; + spin_lock(&dcache_lock); + list_for_each_entry(alias, &inode->i_dentry, d_alias) { + if (!IS_ROOT(alias) && d_unhashed(alias)) + continue; + if (alias->d_sb != sb) + continue; + dentry = alias; + dget_locked(dentry); + break; + } + spin_unlock(&dcache_lock); + } + iput(inode); + return dentry; +} + int sysfs_rename_dir(struct kobject * kobj, const char *new_name) { struct sysfs_dirent *sd = kobj->sd; -- 1.5.3.rc6.17.g1911 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/