From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Layton Subject: Re: [RFC][PATCH] ensure i_ino uniqueness in filesystems without permanent inode numbers (via idr) Date: Wed, 15 Nov 2006 11:42:38 -0500 Message-ID: <1163608958.7571.8.camel@tleilax.poochiereds.net> References: <1163535728.15846.21.camel@dantu.rdu.redhat.com> <20061114202625.GY29920@ftp.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.redhat.com ([66.187.233.31]:54698 "EHLO mx1.redhat.com") by vger.kernel.org with ESMTP id S1030669AbWKOQmk (ORCPT ); Wed, 15 Nov 2006 11:42:40 -0500 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id kAFGgdJj028721 for ; Wed, 15 Nov 2006 11:42:39 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id kAFGgdqL027729 for ; Wed, 15 Nov 2006 11:42:39 -0500 Received: from [192.168.1.3] (vpn-14-138.rdu.redhat.com [10.11.14.138]) by pobox.corp.redhat.com (8.13.1/8.12.8) with ESMTP id kAFGgcGc001051 for ; Wed, 15 Nov 2006 11:42:38 -0500 To: linux-fsdevel@vger.kernel.org In-Reply-To: <20061114202625.GY29920@ftp.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Tue, 2006-11-14 at 20:26 +0000, Al Viro wrote: > NAK. All calls of new_inode() are triggered from within fs code; > there's no reason to introduce flags (which should be the last > resort) when you bloody well can have a separate helpers for that > case and have them called. Explicitly. Ok, that sounds reasonable. Here's a respun patch. This adds 2 new functions, an idr_register and idr_unregister. Filesystems can call idr_register at inode creation time, and then at deletion time, we'll automatically unregister them. Again, this contains a conversion of pipefs to this scheme as an example. If this looks good, I'll start on the legwork to clean up the other filesystems that call new_inode. This patch also adds a new s_generation counter to the superblock. Because i_ino's can be reused so quickly, we don't want NFS getting confused when it happens. When iunique_register is called, we'll assign the s_generation value to the i_generation, and then increment it to help ensure that we get different filehandles. I've left the original iunique function in place here, and new_inode still has the static counter, but that stuff can all be ripped out once I convert the filesystems to the new scheme. Again, comments appreciated... -- Jeff diff --git a/fs/inode.c b/fs/inode.c index 26cdb11..b63b473 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -288,6 +288,8 @@ static void dispose_list(struct list_hea list_del_init(&inode->i_sb_list); spin_unlock(&inode_lock); + iunique_unregister(inode); + wake_up_inode(inode); destroy_inode(inode); nr_disposed++; @@ -706,6 +708,34 @@ retry: EXPORT_SYMBOL(iunique); +int iunique_register(struct inode *inode, int max_reserved) +{ + int rv; + + rv = idr_pre_get(&inode->i_sb->s_inode_ids, GFP_KERNEL); + if (! rv) + return -ENOMEM; + + lock_super(inode->i_sb); + rv = idr_get_new_above(&inode->i_sb->s_inode_ids, inode, + max_reserved+1, (int *) &inode->i_ino); + inode->i_generation = inode->i_sb->s_generation++; + unlock_super(inode->i_sb); + return rv; +} + +EXPORT_SYMBOL(iunique_register); + +void iunique_unregister(struct inode *inode) +{ + lock_super(inode->i_sb); + if (idr_find(&inode->i_sb->s_inode_ids, (int) inode->i_ino)) + idr_remove(&inode->i_sb->s_inode_ids, (int) inode->i_ino); + unlock_super(inode->i_sb); +} + +EXPORT_SYMBOL(iunique_unregister); + struct inode *igrab(struct inode *inode) { spin_lock(&inode_lock); @@ -1025,6 +1055,7 @@ void generic_delete_inode(struct inode * spin_lock(&inode_lock); hlist_del_init(&inode->i_hash); spin_unlock(&inode_lock); + iunique_unregister(inode); wake_up_inode(inode); BUG_ON(inode->i_state != I_CLEAR); destroy_inode(inode); @@ -1057,6 +1088,7 @@ static void generic_forget_inode(struct inode->i_state |= I_FREEING; inodes_stat.nr_inodes--; spin_unlock(&inode_lock); + iunique_unregister(inode); if (inode->i_data.nrpages) truncate_inode_pages(&inode->i_data, 0); clear_inode(inode); diff --git a/fs/pipe.c b/fs/pipe.c index b1626f2..d74ae65 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -845,6 +845,9 @@ static struct inode * get_pipe_inode(voi if (!inode) goto fail_inode; + if (iunique_register(inode, 0)) + goto fail_iput; + pipe = alloc_pipe_info(inode); if (!pipe) goto fail_iput; diff --git a/fs/super.c b/fs/super.c index 47e554c..23b662b 100644 --- a/fs/super.c +++ b/fs/super.c @@ -93,6 +93,7 @@ static struct super_block *alloc_super(s s->s_qcop = sb_quotactl_ops; s->s_op = &default_op; s->s_time_gran = 1000000000; + idr_init(&s->s_inode_ids); } out: return s; diff --git a/include/linux/fs.h b/include/linux/fs.h index 2fe6e3f..c05bf23 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -278,6 +278,7 @@ #include #include #include #include +#include #include #include @@ -961,6 +962,11 @@ #endif /* Granularity of c/m/atime in ns. Cannot be worse than a second */ u32 s_time_gran; + + /* for fs's with dynamic i_ino values, track them with idr, and increment + the generation every time we register a new inode */ + __u32 s_generation; + struct idr s_inode_ids; }; extern struct timespec current_fs_time(struct super_block *sb); @@ -1681,6 +1687,8 @@ extern void inode_init_once(struct inode extern void iput(struct inode *); extern struct inode * igrab(struct inode *); extern ino_t iunique(struct super_block *, ino_t); +extern int iunique_register(struct inode *, int); +extern void iunique_unregister(struct inode *); extern int inode_needs_sync(struct inode *inode); extern void generic_delete_inode(struct inode *inode); extern void generic_drop_inode(struct inode *inode); diff --git a/lib/idr.c b/lib/idr.c