Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1647467 > unrolled thread

[PATCH 1/5] kernfs: implement i_generation

Started byShaohua Li <shli@fb.com>
First post2017-05-23 01:00 +0200
Last post2017-05-24 19:50 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 1/5] kernfs: implement i_generation Shaohua Li <shli@fb.com> - 2017-05-23 01:00 +0200
    Re: [PATCH 1/5] kernfs: implement i_generation Christoph Hellwig <hch@infradead.org> - 2017-05-23 09:50 +0200
      Re: [PATCH 1/5] kernfs: implement i_generation Tejun Heo <tj@kernel.org> - 2017-05-23 21:30 +0200
      Re: [PATCH 1/5] kernfs: implement i_generation Christoph Hellwig <hch@infradead.org> - 2017-05-24 19:50 +0200

#1647467 — [PATCH 1/5] kernfs: implement i_generation

FromShaohua Li <shli@fb.com>
Date2017-05-23 01:00 +0200
Subject[PATCH 1/5] kernfs: implement i_generation
Message-ID<tK4sW-3eD-9@gated-at.bofh.it>
Set i_generation for kernfs inod. This is required to implement exportfs
operations.

Signed-off-by: Shaohua Li <shli@fb.com>
---
 fs/kernfs/dir.c        | 2 ++
 fs/kernfs/inode.c      | 1 +
 include/linux/kernfs.h | 2 ++
 3 files changed, 5 insertions(+)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index db5900aaa..09d093e 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -634,6 +634,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
 	if (ret < 0)
 		goto err_out2;
 	kn->ino = ret;
+	kn->generation = atomic_inc_return(&root->next_generation);
 
 	atomic_set(&kn->count, 1);
 	atomic_set(&kn->active, KN_DEACTIVATED_BIAS);
@@ -877,6 +878,7 @@ struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
 
 	ida_init(&root->ino_ida);
 	INIT_LIST_HEAD(&root->supers);
+	atomic_set(&root->next_generation, 0);
 
 	kn = __kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO,
 			       KERNFS_DIR);
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index fb4b4a7..79cdae4 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -220,6 +220,7 @@ static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode)
 	inode->i_private = kn;
 	inode->i_mapping->a_ops = &kernfs_aops;
 	inode->i_op = &kernfs_iops;
+	inode->i_generation = kn->generation;
 
 	set_default_inode_attr(inode, kn->mode);
 	kernfs_refresh_inode(kn, inode);
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index a9b11b8..c5f0fa7 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -135,6 +135,7 @@ struct kernfs_node {
 	umode_t			mode;
 	unsigned int		ino;
 	struct kernfs_iattrs	*iattr;
+	u32			generation;
 };
 
 /*
@@ -170,6 +171,7 @@ struct kernfs_root {
 	struct list_head	supers;
 
 	wait_queue_head_t	deactivate_waitq;
+	atomic_t		next_generation;
 };
 
 struct kernfs_open_file {
-- 
2.9.3

[toc] | [next] | [standalone]


#1647744

FromChristoph Hellwig <hch@infradead.org>
Date2017-05-23 09:50 +0200
Message-ID<tKcJQ-65-17@gated-at.bofh.it>
In reply to#1647467
On Mon, May 22, 2017 at 03:53:05PM -0700, Shaohua Li wrote:
> Set i_generation for kernfs inod. This is required to implement exportfs
> operations.
> 
> Signed-off-by: Shaohua Li <shli@fb.com>
> ---
>  fs/kernfs/dir.c        | 2 ++
>  fs/kernfs/inode.c      | 1 +
>  include/linux/kernfs.h | 2 ++
>  3 files changed, 5 insertions(+)
> 
> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> index db5900aaa..09d093e 100644
> --- a/fs/kernfs/dir.c
> +++ b/fs/kernfs/dir.c
> @@ -634,6 +634,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
>  	if (ret < 0)
>  		goto err_out2;
>  	kn->ino = ret;
> +	kn->generation = atomic_inc_return(&root->next_generation);

i_generation is only supposed to be valid on a per-inode basis, so this
global counter seems really odd.

[toc] | [prev] | [next] | [standalone]


#1648361

FromTejun Heo <tj@kernel.org>
Date2017-05-23 21:30 +0200
Message-ID<tKnFf-7zH-13@gated-at.bofh.it>
In reply to#1647744
Hello,

On Tue, May 23, 2017 at 08:09:48AM -0700, Shaohua Li wrote:
> > i_generation is only supposed to be valid on a per-inode basis, so this
> > global counter seems really odd.
> 
> What's the difference between per-inode or per-super? The i_generation doesn't
> need to be consecutive for an inode. I checked other fs, a lot of filesystems
> implement i_generation in this way, for example, f2fs, ext4.

One worry is that it is reasonably possible to wrap on the generation
number.  Some setups go through cgroups really fast and wrapping 2^32
on the number of files ever created isn't that difficult over time.
This actually showing up as a malfunction would be very low probabilty
but is still nasty.

It'd be nice to give out unique 64bit id for each kn but then we can't
use idr.  rbtree or extensible hash should work, right?

Thanks.

-- 
tejun

[toc] | [prev] | [next] | [standalone]


#1649834

FromChristoph Hellwig <hch@infradead.org>
Date2017-05-24 19:50 +0200
Message-ID<tKIA3-5m6-45@gated-at.bofh.it>
In reply to#1647744
On Tue, May 23, 2017 at 08:09:48AM -0700, Shaohua Li wrote:
> > > diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> > > index db5900aaa..09d093e 100644
> > > --- a/fs/kernfs/dir.c
> > > +++ b/fs/kernfs/dir.c
> > > @@ -634,6 +634,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,
> > >  	if (ret < 0)
> > >  		goto err_out2;
> > >  	kn->ino = ret;
> > > +	kn->generation = atomic_inc_return(&root->next_generation);
> > 
> > i_generation is only supposed to be valid on a per-inode basis, so this
> > global counter seems really odd.
> 
> What's the difference between per-inode or per-super? The i_generation doesn't
> need to be consecutive for an inode. I checked other fs, a lot of filesystems
> implement i_generation in this way, for example, f2fs, ext4.

of course per-sb is a valid implementation, but it seems like
introducing an easily avoidable bottleneck by serializing on a per-sb
cacheline for each file creation.  But then again it seems like kernfs
already has various other per-sb contention points, so maybe it's not
an issue in the end.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web