From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Piggin Subject: [rfc][patch] fs: introduce iget, mark igrab as must_check Date: Thu, 18 Mar 2010 00:11:12 +1100 Message-ID: <20100317131111.GG2869@laptop> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: linux-fsdevel@vger.kernel.org Return-path: Received: from cantor.suse.de ([195.135.220.2]:42551 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753480Ab0CQNLQ (ORCPT ); Wed, 17 Mar 2010 09:11:16 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 9ACD3457F0 for ; Wed, 17 Mar 2010 14:11:15 +0100 (CET) Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: I thought I would ask for opinions on this because it can come in handy to avoid locking to use an iget() rather than igrab() if we do lazy LRU (like the dcache), then iget() just increments the refcount and doesn't require any more locking. I thought it might be useful anyway to avoid igrab misuse by filesystems? So after this patch we should use igrab for when we don't already have the inode pinned. Introduce iget for when we do. The interfaces don't change, but __must_check will prompt filesystems to use the correct API. Index: linux-2.6/fs/inode.c =================================================================== --- linux-2.6.orig/fs/inode.c +++ linux-2.6/fs/inode.c @@ -296,6 +296,15 @@ void __iget(struct inode *inode) inodes_stat.nr_unused--; } +void iget(struct inode *inode) +{ + spin_lock(&inode_lock); + __iget(inode); + spin_unlock(&inode_lock); + BUG_ON(inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)); +} +EXPORT_SYMBOL(iget); + /** * clear_inode - clear an inode * @inode: inode to clear Index: linux-2.6/include/linux/fs.h =================================================================== --- linux-2.6.orig/include/linux/fs.h +++ linux-2.6/include/linux/fs.h @@ -2146,7 +2146,7 @@ extern int inode_init_always(struct supe extern void inode_init_once(struct inode *); extern void inode_add_to_lists(struct super_block *, struct inode *); extern void iput(struct inode *); -extern struct inode * igrab(struct inode *); +extern struct inode * __must_check igrab(struct inode *); extern ino_t iunique(struct super_block *, ino_t); extern int inode_needs_sync(struct inode *inode); extern void generic_delete_inode(struct inode *inode); @@ -2166,6 +2166,7 @@ extern int insert_inode_locked4(struct i extern int insert_inode_locked(struct inode *); extern void unlock_new_inode(struct inode *); +extern void iget(struct inode * inode); extern void __iget(struct inode * inode); extern void iget_failed(struct inode *); extern void clear_inode(struct inode *);