diff mbox series

[v3,02/10] xattr: add a function to check if a namespace is supported

Message ID 20200623223927.31795-3-fllinden@amazon.com (mailing list archive)
State New, archived
Headers show
Series [v3,01/10] xattr: break delegations in {set,remove}xattr | expand

Commit Message

Frank van der Linden June 23, 2020, 10:39 p.m. UTC
Add a function that checks is an extended attribute namespace is
supported for an inode, meaning that a handler must be present
for either the whole namespace, or at least one synthetic
xattr in the namespace.

To be used by the nfs server code when being queried for extended
attributes support.

Cc: linux-fsdevel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Frank van der Linden <fllinden@amazon.com>
---
 fs/xattr.c            | 27 +++++++++++++++++++++++++++
 include/linux/xattr.h |  2 ++
 2 files changed, 29 insertions(+)

Comments

Frank van der Linden June 25, 2020, 8:41 p.m. UTC | #1
Hi Al,

..and here is the other xattr change that was part of the nfsd user xattr
support series that I mentioned in my previous email.

Full series here:

https://lore.kernel.org/linux-nfs/20200623223927.31795-1-fllinden@amazon.com/

Any comments / concerned about this one?

Thanks,

- Frank

On Tue, Jun 23, 2020 at 10:39:19PM +0000, Frank van der Linden wrote:
> Add a function that checks is an extended attribute namespace is
> supported for an inode, meaning that a handler must be present
> for either the whole namespace, or at least one synthetic
> xattr in the namespace.
> 
> To be used by the nfs server code when being queried for extended
> attributes support.
> 
> Cc: linux-fsdevel@vger.kernel.org
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Frank van der Linden <fllinden@amazon.com>
> ---
>  fs/xattr.c            | 27 +++++++++++++++++++++++++++
>  include/linux/xattr.h |  2 ++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/fs/xattr.c b/fs/xattr.c
> index 95f38f57347f..386b45676d7e 100644
> --- a/fs/xattr.c
> +++ b/fs/xattr.c
> @@ -134,6 +134,33 @@ xattr_permission(struct inode *inode, const char *name, int mask)
>  	return inode_permission(inode, mask);
>  }
>  
> +/*
> + * Look for any handler that deals with the specified namespace.
> + */
> +int
> +xattr_supported_namespace(struct inode *inode, const char *prefix)
> +{
> +	const struct xattr_handler **handlers = inode->i_sb->s_xattr;
> +	const struct xattr_handler *handler;
> +	size_t preflen;
> +
> +	if (!(inode->i_opflags & IOP_XATTR)) {
> +		if (unlikely(is_bad_inode(inode)))
> +			return -EIO;
> +		return -EOPNOTSUPP;
> +	}
> +
> +	preflen = strlen(prefix);
> +
> +	for_each_xattr_handler(handlers, handler) {
> +		if (!strncmp(xattr_prefix(handler), prefix, preflen))
> +			return 0;
> +	}
> +
> +	return -EOPNOTSUPP;
> +}
> +EXPORT_SYMBOL(xattr_supported_namespace);
> +
>  int
>  __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
>  	       const void *value, size_t size, int flags)
> diff --git a/include/linux/xattr.h b/include/linux/xattr.h
> index a2f3cd02653c..fac75810d9d3 100644
> --- a/include/linux/xattr.h
> +++ b/include/linux/xattr.h
> @@ -61,6 +61,8 @@ ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_siz
>  ssize_t vfs_getxattr_alloc(struct dentry *dentry, const char *name,
>  			   char **xattr_value, size_t size, gfp_t flags);
>  
> +int xattr_supported_namespace(struct inode *inode, const char *prefix);
> +
>  static inline const char *xattr_prefix(const struct xattr_handler *handler)
>  {
>  	return handler->prefix ?: handler->name;
> -- 
> 2.17.2
>
Frank van der Linden July 14, 2020, 5:13 p.m. UTC | #2
On Thu, Jun 25, 2020 at 08:41:57PM +0000, Frank van der Linden wrote:
> Hi Al,
> 
> ..and here is the other xattr change that was part of the nfsd user xattr
> support series that I mentioned in my previous email.
> 
> Full series here:
> 
> https://lore.kernel.org/linux-nfs/20200623223927.31795-1-fllinden@amazon.com/
> 
> Any comments / concerned about this one?
> 
> Thanks,
> 
> - Frank

Hi Al,

Here's the other one I'm just sending a quick ping on. It's a simple change -
just add a little new function that enables nfsd to check if the "user."
namespace is at all supported by a filesystem.

Any comments?

Again, Linus - this is a pretty small change, doesn't affect any existing
codepaths, and it's already in the tree Chuck is setting up for 5.9. Could
this go in through that directly?

Thanks,

- Frank
> 
> On Tue, Jun 23, 2020 at 10:39:19PM +0000, Frank van der Linden wrote:
> > Add a function that checks is an extended attribute namespace is
> > supported for an inode, meaning that a handler must be present
> > for either the whole namespace, or at least one synthetic
> > xattr in the namespace.
> > 
> > To be used by the nfs server code when being queried for extended
> > attributes support.
> > 
> > Cc: linux-fsdevel@vger.kernel.org
> > Cc: Al Viro <viro@zeniv.linux.org.uk>
> > Signed-off-by: Frank van der Linden <fllinden@amazon.com>
> > ---
> >  fs/xattr.c            | 27 +++++++++++++++++++++++++++
> >  include/linux/xattr.h |  2 ++
> >  2 files changed, 29 insertions(+)
> > 
> > diff --git a/fs/xattr.c b/fs/xattr.c
> > index 95f38f57347f..386b45676d7e 100644
> > --- a/fs/xattr.c
> > +++ b/fs/xattr.c
> > @@ -134,6 +134,33 @@ xattr_permission(struct inode *inode, const char *name, int mask)
> >  	return inode_permission(inode, mask);
> >  }
> >  
> > +/*
> > + * Look for any handler that deals with the specified namespace.
> > + */
> > +int
> > +xattr_supported_namespace(struct inode *inode, const char *prefix)
> > +{
> > +	const struct xattr_handler **handlers = inode->i_sb->s_xattr;
> > +	const struct xattr_handler *handler;
> > +	size_t preflen;
> > +
> > +	if (!(inode->i_opflags & IOP_XATTR)) {
> > +		if (unlikely(is_bad_inode(inode)))
> > +			return -EIO;
> > +		return -EOPNOTSUPP;
> > +	}
> > +
> > +	preflen = strlen(prefix);
> > +
> > +	for_each_xattr_handler(handlers, handler) {
> > +		if (!strncmp(xattr_prefix(handler), prefix, preflen))
> > +			return 0;
> > +	}
> > +
> > +	return -EOPNOTSUPP;
> > +}
> > +EXPORT_SYMBOL(xattr_supported_namespace);
> > +
> >  int
> >  __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
> >  	       const void *value, size_t size, int flags)
> > diff --git a/include/linux/xattr.h b/include/linux/xattr.h
> > index a2f3cd02653c..fac75810d9d3 100644
> > --- a/include/linux/xattr.h
> > +++ b/include/linux/xattr.h
> > @@ -61,6 +61,8 @@ ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_siz
> >  ssize_t vfs_getxattr_alloc(struct dentry *dentry, const char *name,
> >  			   char **xattr_value, size_t size, gfp_t flags);
> >  
> > +int xattr_supported_namespace(struct inode *inode, const char *prefix);
> > +
> >  static inline const char *xattr_prefix(const struct xattr_handler *handler)
> >  {
> >  	return handler->prefix ?: handler->name;
> > -- 
> > 2.17.2
> >
Linus Torvalds July 14, 2020, 6:46 p.m. UTC | #3
On Tue, Jul 14, 2020 at 10:13 AM Frank van der Linden
<fllinden@amazon.com> wrote:
>
> Again, Linus - this is a pretty small change, doesn't affect any existing
> codepaths, and it's already in the tree Chuck is setting up for 5.9. Could
> this go in through that directly?

Both ok by me, but I'd like to have Al ack them. Al?

               Linus
Chuck Lever July 28, 2020, 2:17 p.m. UTC | #4
Hi Linus-

> On Jul 14, 2020, at 2:46 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> 
> On Tue, Jul 14, 2020 at 10:13 AM Frank van der Linden
> <fllinden@amazon.com> wrote:
>> 
>> Again, Linus - this is a pretty small change, doesn't affect any existing
>> codepaths, and it's already in the tree Chuck is setting up for 5.9. Could
>> this go in through that directly?
> 
> Both ok by me, but I'd like to have Al ack them. Al?

I have the NFSD user xattr patches in the current series waiting to be
merged into v5.9. I'd like to create the nfsd-5.9 merge tag soon, but I
haven't heard any review comments from Al. How would you like me to
proceed?


--
Chuck Lever
Al Viro July 28, 2020, 2:33 p.m. UTC | #5
On Tue, Jul 28, 2020 at 10:17:07AM -0400, Chuck Lever wrote:
> Hi Linus-
> 
> > On Jul 14, 2020, at 2:46 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> > 
> > On Tue, Jul 14, 2020 at 10:13 AM Frank van der Linden
> > <fllinden@amazon.com> wrote:
> >> 
> >> Again, Linus - this is a pretty small change, doesn't affect any existing
> >> codepaths, and it's already in the tree Chuck is setting up for 5.9. Could
> >> this go in through that directly?
> > 
> > Both ok by me, but I'd like to have Al ack them. Al?
> 
> I have the NFSD user xattr patches in the current series waiting to be
> merged into v5.9. I'd like to create the nfsd-5.9 merge tag soon, but I
> haven't heard any review comments from Al. How would you like me to
> proceed?

Looks sane, AFAICS.  Sorry, still digging myself from under the mounds of
mail...
Chuck Lever July 29, 2020, 12:23 p.m. UTC | #6
> On Jul 28, 2020, at 10:33 AM, Al Viro <viro@zeniv.linux.org.uk> wrote:
> 
> On Tue, Jul 28, 2020 at 10:17:07AM -0400, Chuck Lever wrote:
>> Hi Linus-
>> 
>>> On Jul 14, 2020, at 2:46 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>>> 
>>> On Tue, Jul 14, 2020 at 10:13 AM Frank van der Linden
>>> <fllinden@amazon.com> wrote:
>>>> 
>>>> Again, Linus - this is a pretty small change, doesn't affect any existing
>>>> codepaths, and it's already in the tree Chuck is setting up for 5.9. Could
>>>> this go in through that directly?
>>> 
>>> Both ok by me, but I'd like to have Al ack them. Al?
>> 
>> I have the NFSD user xattr patches in the current series waiting to be
>> merged into v5.9. I'd like to create the nfsd-5.9 merge tag soon, but I
>> haven't heard any review comments from Al. How would you like me to
>> proceed?
> 
> Looks sane, AFAICS.  Sorry, still digging myself from under the mounds of
> mail...

No problem at all. Thanks!

--
Chuck Lever
diff mbox series

Patch

diff --git a/fs/xattr.c b/fs/xattr.c
index 95f38f57347f..386b45676d7e 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -134,6 +134,33 @@  xattr_permission(struct inode *inode, const char *name, int mask)
 	return inode_permission(inode, mask);
 }
 
+/*
+ * Look for any handler that deals with the specified namespace.
+ */
+int
+xattr_supported_namespace(struct inode *inode, const char *prefix)
+{
+	const struct xattr_handler **handlers = inode->i_sb->s_xattr;
+	const struct xattr_handler *handler;
+	size_t preflen;
+
+	if (!(inode->i_opflags & IOP_XATTR)) {
+		if (unlikely(is_bad_inode(inode)))
+			return -EIO;
+		return -EOPNOTSUPP;
+	}
+
+	preflen = strlen(prefix);
+
+	for_each_xattr_handler(handlers, handler) {
+		if (!strncmp(xattr_prefix(handler), prefix, preflen))
+			return 0;
+	}
+
+	return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(xattr_supported_namespace);
+
 int
 __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
 	       const void *value, size_t size, int flags)
diff --git a/include/linux/xattr.h b/include/linux/xattr.h
index a2f3cd02653c..fac75810d9d3 100644
--- a/include/linux/xattr.h
+++ b/include/linux/xattr.h
@@ -61,6 +61,8 @@  ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_siz
 ssize_t vfs_getxattr_alloc(struct dentry *dentry, const char *name,
 			   char **xattr_value, size_t size, gfp_t flags);
 
+int xattr_supported_namespace(struct inode *inode, const char *prefix);
+
 static inline const char *xattr_prefix(const struct xattr_handler *handler)
 {
 	return handler->prefix ?: handler->name;