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


Groups > linux.kernel > #1361521 > unrolled thread

Re: [PATCH 1/4] vfs: add file_dentry()

Started byTheodore Ts'o <tytso@mit.edu>
First post2016-03-21 06:10 +0100
Last post2016-03-22 07:30 +0100
Articles 3 — 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

  Re: [PATCH 1/4] vfs: add file_dentry() Theodore Ts'o <tytso@mit.edu> - 2016-03-21 06:10 +0100
    Re: [PATCH 1/4] vfs: add file_dentry() Al Viro <viro@ZenIV.linux.org.uk> - 2016-03-21 06:30 +0100
    Re: [PATCH 1/4] vfs: add file_dentry() Daniel Axtens <dja@axtens.net> - 2016-03-22 07:30 +0100

#1361521 — Re: [PATCH 1/4] vfs: add file_dentry()

FromTheodore Ts'o <tytso@mit.edu>
Date2016-03-21 06:10 +0100
SubjectRe: [PATCH 1/4] vfs: add file_dentry()
Message-ID<rf0gh-TE-9@gated-at.bofh.it>
On Thu, Mar 17, 2016 at 10:02:00AM +0100, Miklos Szeredi wrote:
> From: Miklos Szeredi <mszeredi@redhat.com>
> 
> This series fixes bugs in nfs and ext4 due to 4bacc9c9234c ("overlayfs: Make
> f_path always point to the overlay and f_inode to the underlay").
> 
> Regular files opened on overlayfs will result in the file being opened on
> the underlying filesystem, while f_path points to the overlayfs
> mount/dentry.
> 
> This confuses filesystems which get the dentry from struct file and assume
> it's theirs.
> 
> Add a new helper, file_dentry() [*], to get the filesystem's own dentry
> from the file.  This simply compares file_inode(file->f_path.dentry) to
> file_inode(file) and if they are equal returns file->f_path.dentry (this is
> the common, non-overlayfs case).
> 
> In the uncommon case (regular file on overlayfs) it will call into
> overlayfs's ->d_native_dentry() to get the underlying dentry matching
> file_inode(file).
> 
> [*] If possible, it's better simply to use file_inode() instead.
> 
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> Reviewed-by: Trond Myklebust <trond.myklebust@primarydata.com>
> Cc: <stable@vger.kernel.org> # v4.2
> Cc: David Howells <dhowells@redhat.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Theodore Ts'o <tytso@mit.edu>
> Cc: Daniel Axtens <dja@axtens.net>
> ---
>  fs/open.c              | 11 +++++++++++
>  fs/overlayfs/super.c   | 16 ++++++++++++++++
>  include/linux/dcache.h |  1 +
>  include/linux/fs.h     |  2 ++
>  4 files changed, 30 insertions(+)

I have this patch in the ext4.git tree, but I'd like to get an
Acked-by from Al before I send a pull request to Linus.

Al?  Any objections to my sending in this change via the ext4 tree?

						- Ted

> 
> diff --git a/fs/open.c b/fs/open.c
> index 55bdc75e2172..6326c11eda78 100644
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -831,6 +831,17 @@ char *file_path(struct file *filp, char *buf, int buflen)
>  }
>  EXPORT_SYMBOL(file_path);
>  
> +struct dentry *file_dentry(const struct file *file)
> +{
> +	struct dentry *dentry = file->f_path.dentry;
> +
> +	if (likely(d_inode(dentry) == file_inode(file)))
> +		return dentry;
> +	else
> +		return dentry->d_op->d_native_dentry(dentry, file_inode(file));
> +}
> +EXPORT_SYMBOL(file_dentry);
> +
>  /**
>   * vfs_open - open the file at the given path
>   * @path: path to open
> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> index 619ad4b016d2..5142aa2034c4 100644
> --- a/fs/overlayfs/super.c
> +++ b/fs/overlayfs/super.c
> @@ -336,14 +336,30 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
>  	return ret;
>  }
>  
> +static struct dentry *ovl_d_native_dentry(struct dentry *dentry,
> +					 struct inode *inode)
> +{
> +	struct ovl_entry *oe = dentry->d_fsdata;
> +	struct dentry *realentry = ovl_upperdentry_dereference(oe);
> +
> +	if (realentry && inode == d_inode(realentry))
> +		return realentry;
> +	realentry = __ovl_dentry_lower(oe);
> +	if (realentry && inode == d_inode(realentry))
> +		return realentry;
> +	BUG();
> +}
> +
>  static const struct dentry_operations ovl_dentry_operations = {
>  	.d_release = ovl_dentry_release,
>  	.d_select_inode = ovl_d_select_inode,
> +	.d_native_dentry = ovl_d_native_dentry,
>  };
>  
>  static const struct dentry_operations ovl_reval_dentry_operations = {
>  	.d_release = ovl_dentry_release,
>  	.d_select_inode = ovl_d_select_inode,
> +	.d_native_dentry = ovl_d_native_dentry,
>  	.d_revalidate = ovl_dentry_revalidate,
>  	.d_weak_revalidate = ovl_dentry_weak_revalidate,
>  };
> diff --git a/include/linux/dcache.h b/include/linux/dcache.h
> index c4b5f4b3f8f8..99ecb6de636c 100644
> --- a/include/linux/dcache.h
> +++ b/include/linux/dcache.h
> @@ -161,6 +161,7 @@ struct dentry_operations {
>  	struct vfsmount *(*d_automount)(struct path *);
>  	int (*d_manage)(struct dentry *, bool);
>  	struct inode *(*d_select_inode)(struct dentry *, unsigned);
> +	struct dentry *(*d_native_dentry)(struct dentry *, struct inode *);
>  } ____cacheline_aligned;
>  
>  /*
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index ae681002100a..1091d9f43271 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1234,6 +1234,8 @@ static inline struct inode *file_inode(const struct file *f)
>  	return f->f_inode;
>  }
>  
> +extern struct dentry *file_dentry(const struct file *file);
> +
>  static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
>  {
>  	return locks_lock_inode_wait(file_inode(filp), fl);
> -- 
> 2.1.4
> 

[toc] | [next] | [standalone]


#1361524

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2016-03-21 06:30 +0100
Message-ID<rf0zE-15e-5@gated-at.bofh.it>
In reply to#1361521
On Mon, Mar 21, 2016 at 01:02:15AM -0400, Theodore Ts'o wrote:

> I have this patch in the ext4.git tree, but I'd like to get an
> Acked-by from Al before I send a pull request to Linus.
> 
> Al?  Any objections to my sending in this change via the ext4 tree?
> 						- Ted

FWIW, I would rather add DCACHE_OP_REAL (set at d_set_d_op()
time) and turned that into

static inline struct dentry *d_real(const struct dentry *dentry)
{
	if (unlikely(dentry->d_flags & DCACHE_OP_NATIVE_DENTRY))
		returd dentry->d_op->d_real(dentry);
	else
		return dentry;
}
static inline struct dentry *file_dentry(const struct file *file)
{
	return d_real(file->f_path.dentry);
}

and used ovl_dentry_real as ->d_real for overlayfs.  Miklos, do you
see any problems with that variant?

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


#1362347

FromDaniel Axtens <dja@axtens.net>
Date2016-03-22 07:30 +0100
Message-ID<rfnZg-uA-1@gated-at.bofh.it>
In reply to#1361521
>> From: Miklos Szeredi <mszeredi@redhat.com>
>> 
>> This series fixes bugs in nfs and ext4 due to 4bacc9c9234c ("overlayfs: Make
>> f_path always point to the overlay and f_inode to the underlay").
>> 
>> Regular files opened on overlayfs will result in the file being opened on
>> the underlying filesystem, while f_path points to the overlayfs
>> mount/dentry.
>> 
>> This confuses filesystems which get the dentry from struct file and assume
>> it's theirs.
>> 
>> Add a new helper, file_dentry() [*], to get the filesystem's own dentry
>> from the file.  This simply compares file_inode(file->f_path.dentry) to
>> file_inode(file) and if they are equal returns file->f_path.dentry (this is
>> the common, non-overlayfs case).
>> 
>> In the uncommon case (regular file on overlayfs) it will call into
>> overlayfs's ->d_native_dentry() to get the underlying dentry matching
>> file_inode(file).
>> 
>> [*] If possible, it's better simply to use file_inode() instead.

Hopefully this is not so late as to be useless!
For this entire series:
Tested-by: Daniel Axtens <dja@axtens.net>

Regards,
Daniel

>> 
>> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
>> Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
>> Reviewed-by: Trond Myklebust <trond.myklebust@primarydata.com>
>> Cc: <stable@vger.kernel.org> # v4.2
>> Cc: David Howells <dhowells@redhat.com>
>> Cc: Al Viro <viro@zeniv.linux.org.uk>
>> Cc: Theodore Ts'o <tytso@mit.edu>
>> Cc: Daniel Axtens <dja@axtens.net>
>> ---
>>  fs/open.c              | 11 +++++++++++
>>  fs/overlayfs/super.c   | 16 ++++++++++++++++
>>  include/linux/dcache.h |  1 +
>>  include/linux/fs.h     |  2 ++
>>  4 files changed, 30 insertions(+)
>
> I have this patch in the ext4.git tree, but I'd like to get an
> Acked-by from Al before I send a pull request to Linus.
>
> Al?  Any objections to my sending in this change via the ext4 tree?
>
> 						- Ted
>
>> 
>> diff --git a/fs/open.c b/fs/open.c
>> index 55bdc75e2172..6326c11eda78 100644
>> --- a/fs/open.c
>> +++ b/fs/open.c
>> @@ -831,6 +831,17 @@ char *file_path(struct file *filp, char *buf, int buflen)
>>  }
>>  EXPORT_SYMBOL(file_path);
>>  
>> +struct dentry *file_dentry(const struct file *file)
>> +{
>> +	struct dentry *dentry = file->f_path.dentry;
>> +
>> +	if (likely(d_inode(dentry) == file_inode(file)))
>> +		return dentry;
>> +	else
>> +		return dentry->d_op->d_native_dentry(dentry, file_inode(file));
>> +}
>> +EXPORT_SYMBOL(file_dentry);
>> +
>>  /**
>>   * vfs_open - open the file at the given path
>>   * @path: path to open
>> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
>> index 619ad4b016d2..5142aa2034c4 100644
>> --- a/fs/overlayfs/super.c
>> +++ b/fs/overlayfs/super.c
>> @@ -336,14 +336,30 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
>>  	return ret;
>>  }
>>  
>> +static struct dentry *ovl_d_native_dentry(struct dentry *dentry,
>> +					 struct inode *inode)
>> +{
>> +	struct ovl_entry *oe = dentry->d_fsdata;
>> +	struct dentry *realentry = ovl_upperdentry_dereference(oe);
>> +
>> +	if (realentry && inode == d_inode(realentry))
>> +		return realentry;
>> +	realentry = __ovl_dentry_lower(oe);
>> +	if (realentry && inode == d_inode(realentry))
>> +		return realentry;
>> +	BUG();
>> +}
>> +
>>  static const struct dentry_operations ovl_dentry_operations = {
>>  	.d_release = ovl_dentry_release,
>>  	.d_select_inode = ovl_d_select_inode,
>> +	.d_native_dentry = ovl_d_native_dentry,
>>  };
>>  
>>  static const struct dentry_operations ovl_reval_dentry_operations = {
>>  	.d_release = ovl_dentry_release,
>>  	.d_select_inode = ovl_d_select_inode,
>> +	.d_native_dentry = ovl_d_native_dentry,
>>  	.d_revalidate = ovl_dentry_revalidate,
>>  	.d_weak_revalidate = ovl_dentry_weak_revalidate,
>>  };
>> diff --git a/include/linux/dcache.h b/include/linux/dcache.h
>> index c4b5f4b3f8f8..99ecb6de636c 100644
>> --- a/include/linux/dcache.h
>> +++ b/include/linux/dcache.h
>> @@ -161,6 +161,7 @@ struct dentry_operations {
>>  	struct vfsmount *(*d_automount)(struct path *);
>>  	int (*d_manage)(struct dentry *, bool);
>>  	struct inode *(*d_select_inode)(struct dentry *, unsigned);
>> +	struct dentry *(*d_native_dentry)(struct dentry *, struct inode *);
>>  } ____cacheline_aligned;
>>  
>>  /*
>> diff --git a/include/linux/fs.h b/include/linux/fs.h
>> index ae681002100a..1091d9f43271 100644
>> --- a/include/linux/fs.h
>> +++ b/include/linux/fs.h
>> @@ -1234,6 +1234,8 @@ static inline struct inode *file_inode(const struct file *f)
>>  	return f->f_inode;
>>  }
>>  
>> +extern struct dentry *file_dentry(const struct file *file);
>> +
>>  static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
>>  {
>>  	return locks_lock_inode_wait(file_inode(filp), fl);
>> -- 
>> 2.1.4
>> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web