All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Andreas Gruenbacher
	<agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Alexander Viro
	<viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Cc: Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	Theodore Ts'o <tytso-3s7WtUTddSA@public.gmane.org>,
	Andreas Dilger
	<adilger.kernel-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org>,
	"J. Bruce Fields"
	<bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>,
	Trond Myklebust
	<trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>,
	Anna Schumaker
	<anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org>,
	Dave Chinner <david-FqsqvQoI3Ljby3iVrkZq2A@public.gmane.org>,
	linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	xfs-VZNHf3L845pBDgjK7y7TUQ@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v23 13/22] vfs: Cache richacl in struct inode
Date: Wed, 06 Jul 2016 14:57:05 -0400	[thread overview]
Message-ID: <1467831425.2908.16.camel@redhat.com> (raw)
In-Reply-To: <1467294433-3222-14-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

On Thu, 2016-06-30 at 15:47 +0200, Andreas Gruenbacher wrote:
> Cache richacls in struct inode so that this doesn't have to be done
> individually in each filesystem.  This is similar to POSIX ACLs.
> 
> Signed-off-by: Andreas Gruenbacher <agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
>  fs/inode.c              | 13 +++++---
>  fs/richacl.c            | 81 +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/fs.h      |  5 ++-
>  include/linux/richacl.h | 11 +++++++
>  4 files changed, 105 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 40c03a7..7dbb09c 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -181,8 +181,11 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
>  	inode->i_private = NULL;
>  	inode->i_mapping = mapping;
>  	INIT_HLIST_HEAD(&inode->i_dentry);	/* buggered by rcu freeing */
> -#ifdef CONFIG_FS_POSIX_ACL
> -	inode->i_acl = inode->i_default_acl = ACL_NOT_CACHED;
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
> +	inode->i_acl = ACL_NOT_CACHED;
> +# if defined(CONFIG_FS_POSIX_ACL)
> +	inode->i_default_acl = ACL_NOT_CACHED;
> +# endif
>  #endif
>  
>  #ifdef CONFIG_FSNOTIFY
> @@ -238,17 +241,19 @@ void __destroy_inode(struct inode *inode)
>  		atomic_long_dec(&inode->i_sb->s_remove_count);
>  	}
>  
> -#ifdef CONFIG_FS_POSIX_ACL
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  	if (inode->i_acl && !is_uncached_acl(inode->i_acl))
>  		base_acl_put(inode->i_acl);
> +# if defined(CONFIG_FS_POSIX_ACL)
>  	if (inode->i_default_acl && !is_uncached_acl(inode->i_default_acl))
>  		base_acl_put(inode->i_default_acl);
> +# endif
>  #endif
>  	this_cpu_dec(nr_inodes);
>  }
>  EXPORT_SYMBOL(__destroy_inode);
>  
> -#ifdef CONFIG_FS_POSIX_ACL
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  struct base_acl *__get_cached_acl(struct base_acl **p)
>  {
>  	struct base_acl *base_acl;
> diff --git a/fs/richacl.c b/fs/richacl.c
> index 8971ead..b2a03c1 100644
> --- a/fs/richacl.c
> +++ b/fs/richacl.c
> @@ -20,6 +20,87 @@
>  #include 
>  #include 
>  
> +void set_cached_richacl(struct inode *inode, struct richacl *acl)
> +{
> +	struct base_acl *old;
> +
> +	old = xchg(&inode->i_acl, &richacl_get(acl)->a_base);
> +	if (!is_uncached_acl(old))
> +		base_acl_put(old);
> +}
> +EXPORT_SYMBOL_GPL(set_cached_richacl);
> +
> +void forget_cached_richacl(struct inode *inode)
> +{
> +	__forget_cached_acl(&inode->i_acl);
> +}
> +EXPORT_SYMBOL_GPL(forget_cached_richacl);
> +
> +struct richacl *get_richacl(struct inode *inode)
> +{
> +	struct base_acl *sentinel, *base_acl;
> +	struct richacl *acl;
> +
> +	if (!IS_RICHACL(inode))
> +		return NULL;
> +
> +	/*
> +	 * The sentinel is used to detect when another operation like
> +	 * set_cached_richacl() or forget_cached_richacl() races with
> +	 * get_richacl().
> +	 * It is guaranteed that is_uncached_acl(sentinel) is true.
> +	 */
> +
> +	base_acl = __get_cached_acl(&inode->i_acl);
> +	if (!is_uncached_acl(base_acl))
> +		return richacl(base_acl);
> +
> +	sentinel = uncached_acl_sentinel(current);
> +
> +	/*
> +	 * If the ACL isn't being read yet, set our sentinel.  Otherwise, the
> +	 * current value of the ACL will not be ACL_NOT_CACHED and so our own
> +	 * sentinel will not be set; another task will update the cache.  We
> +	 * could wait for that other task to complete its job, but it's easier
> +	 * to just call ->get_acl to fetch the ACL ourself.  (This is going to
> +	 * be an unlikely race.)
> +	 */
> +	if (cmpxchg(&inode->i_acl, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)
> +		/* fall through */ ;
> +

So you do the same thing regardless of the outcome of the above? Why
bother with the if at all here? Just do the cmpxchg and toss out the
result.

> +	/*
> +	 * Normally, the ACL returned by ->get_richacl will be cached.
> +	 * A filesystem can prevent that by calling
> +	 * forget_cached_richacl(inode) in ->get_richacl.
> +	 *
> +	 * If the filesystem doesn't have a ->get_richacl function at all,
> +	 * we'll just create the negative cache entry.
> +	 */
> +	if (!inode->i_op->get_richacl) {
> +		set_cached_richacl(inode, NULL);
> +		return NULL;
> +	}
> +
> +	acl = inode->i_op->get_richacl(inode);
> +	if (IS_ERR(acl)) {
> +		/*
> +		 * Remove our sentinel so that we don't block future attempts
> +		 * to cache the ACL.
> +		 */
> +		cmpxchg(&inode->i_acl, sentinel, ACL_NOT_CACHED);
> +		return acl;
> +	}
> +

So this is sort of icky: only the task that sets the sentinel can set
the cached acl.

You could have one task set the sentinel, call get_richacl and fail, but then a concurrent task also issues a get_richacl and succeeds. That task will get its acl, but it doesn't end up getting cached and subsequent callers then have to reissue the request. It would be good if the first successful fetch of the acl sets it in the cache.

That said, getting the acl could be pretty expensive with some filesystems. NFS or CIFS are going to have to do an on the wire call to fetch them, for instance. I think it would be better to have concurrent callers wait for the first caller's result instead of issuing parallel get_richacl requests.

> +	/*
> +	 * Cache the result, but only if our sentinel is still in place.
> +	 */
> +	richacl_get(acl);
> +	if (unlikely(cmpxchg(&inode->i_acl, sentinel, &acl->a_base) != sentinel))
> +		richacl_put(acl);
> +	return acl;
> +}
> +EXPORT_SYMBOL_GPL(get_richacl);
> +
>  /**
>   * richacl_alloc  -  allocate a richacl
>   * @count:	number of entries
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index ac96bda..4d72a6d 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -589,6 +589,7 @@ struct base_acl {
>  	};
>  };
>  struct posix_acl;
> +struct richacl;
>  #define ACL_NOT_CACHED ((void *)(-1))
>  
>  static inline struct base_acl *
> @@ -619,9 +620,11 @@ struct inode {
>  	kgid_t			i_gid;
>  	unsigned int		i_flags;
>  
> -#if defined(CONFIG_FS_POSIX_ACL)
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  	struct base_acl		*i_acl;
> +# if defined(CONFIG_FS_POSIX_ACL)
>  	struct base_acl		*i_default_acl;
> +# endif
>  #endif
>  

Oh, so if we compile in richacls and not posix acls, we shrink the
inode by a pointer. Nice!

>  	const struct inode_operations	*i_op;
> diff --git a/include/linux/richacl.h b/include/linux/richacl.h
> index 35a5bcb..3e05c94 100644
> --- a/include/linux/richacl.h
> +++ b/include/linux/richacl.h
> @@ -70,6 +70,17 @@ richacl_put(struct richacl *acl)
>  	base_acl_put(&acl->a_base);
>  }
>  
> +static inline struct richacl *
> +richacl(struct base_acl *base_acl)
> +{
> +	BUILD_BUG_ON(offsetof(struct richacl, a_base) != 0);
> +	return container_of(base_acl, struct richacl, a_base);
> +}
> +
> +extern void set_cached_richacl(struct inode *, struct richacl *);
> +extern void forget_cached_richacl(struct inode *);
> +extern struct richacl *get_richacl(struct inode *);
> +
>  /**
>   * richace_is_owner  -  check if @ace is an OWNER@ entry
>   */

-- 
Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Jeff Layton <jlayton@redhat.com>
To: Andreas Gruenbacher <agruenba@redhat.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	Trond Myklebust <trond.myklebust@primarydata.com>,
	Anna Schumaker <anna.schumaker@netapp.com>,
	Dave Chinner <david@fromorbit.com>,
	linux-ext4@vger.kernel.org, xfs@oss.sgi.com,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org,
	linux-api@vger.kernel.org
Subject: Re: [PATCH v23 13/22] vfs: Cache richacl in struct inode
Date: Wed, 06 Jul 2016 14:57:05 -0400	[thread overview]
Message-ID: <1467831425.2908.16.camel@redhat.com> (raw)
In-Reply-To: <1467294433-3222-14-git-send-email-agruenba@redhat.com>

On Thu, 2016-06-30 at 15:47 +0200, Andreas Gruenbacher wrote:
> Cache richacls in struct inode so that this doesn't have to be done
> individually in each filesystem.  This is similar to POSIX ACLs.
> 
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
>  fs/inode.c              | 13 +++++---
>  fs/richacl.c            | 81 +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/fs.h      |  5 ++-
>  include/linux/richacl.h | 11 +++++++
>  4 files changed, 105 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 40c03a7..7dbb09c 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -181,8 +181,11 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
>  	inode->i_private = NULL;
>  	inode->i_mapping = mapping;
>  	INIT_HLIST_HEAD(&inode->i_dentry);	/* buggered by rcu freeing */
> -#ifdef CONFIG_FS_POSIX_ACL
> -	inode->i_acl = inode->i_default_acl = ACL_NOT_CACHED;
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
> +	inode->i_acl = ACL_NOT_CACHED;
> +# if defined(CONFIG_FS_POSIX_ACL)
> +	inode->i_default_acl = ACL_NOT_CACHED;
> +# endif
>  #endif
>  
>  #ifdef CONFIG_FSNOTIFY
> @@ -238,17 +241,19 @@ void __destroy_inode(struct inode *inode)
>  		atomic_long_dec(&inode->i_sb->s_remove_count);
>  	}
>  
> -#ifdef CONFIG_FS_POSIX_ACL
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  	if (inode->i_acl && !is_uncached_acl(inode->i_acl))
>  		base_acl_put(inode->i_acl);
> +# if defined(CONFIG_FS_POSIX_ACL)
>  	if (inode->i_default_acl && !is_uncached_acl(inode->i_default_acl))
>  		base_acl_put(inode->i_default_acl);
> +# endif
>  #endif
>  	this_cpu_dec(nr_inodes);
>  }
>  EXPORT_SYMBOL(__destroy_inode);
>  
> -#ifdef CONFIG_FS_POSIX_ACL
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  struct base_acl *__get_cached_acl(struct base_acl **p)
>  {
>  	struct base_acl *base_acl;
> diff --git a/fs/richacl.c b/fs/richacl.c
> index 8971ead..b2a03c1 100644
> --- a/fs/richacl.c
> +++ b/fs/richacl.c
> @@ -20,6 +20,87 @@
>  #include 
>  #include 
>  
> +void set_cached_richacl(struct inode *inode, struct richacl *acl)
> +{
> +	struct base_acl *old;
> +
> +	old = xchg(&inode->i_acl, &richacl_get(acl)->a_base);
> +	if (!is_uncached_acl(old))
> +		base_acl_put(old);
> +}
> +EXPORT_SYMBOL_GPL(set_cached_richacl);
> +
> +void forget_cached_richacl(struct inode *inode)
> +{
> +	__forget_cached_acl(&inode->i_acl);
> +}
> +EXPORT_SYMBOL_GPL(forget_cached_richacl);
> +
> +struct richacl *get_richacl(struct inode *inode)
> +{
> +	struct base_acl *sentinel, *base_acl;
> +	struct richacl *acl;
> +
> +	if (!IS_RICHACL(inode))
> +		return NULL;
> +
> +	/*
> +	 * The sentinel is used to detect when another operation like
> +	 * set_cached_richacl() or forget_cached_richacl() races with
> +	 * get_richacl().
> +	 * It is guaranteed that is_uncached_acl(sentinel) is true.
> +	 */
> +
> +	base_acl = __get_cached_acl(&inode->i_acl);
> +	if (!is_uncached_acl(base_acl))
> +		return richacl(base_acl);
> +
> +	sentinel = uncached_acl_sentinel(current);
> +
> +	/*
> +	 * If the ACL isn't being read yet, set our sentinel.  Otherwise, the
> +	 * current value of the ACL will not be ACL_NOT_CACHED and so our own
> +	 * sentinel will not be set; another task will update the cache.  We
> +	 * could wait for that other task to complete its job, but it's easier
> +	 * to just call ->get_acl to fetch the ACL ourself.  (This is going to
> +	 * be an unlikely race.)
> +	 */
> +	if (cmpxchg(&inode->i_acl, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)
> +		/* fall through */ ;
> +

So you do the same thing regardless of the outcome of the above? Why
bother with the if at all here? Just do the cmpxchg and toss out the
result.

> +	/*
> +	 * Normally, the ACL returned by ->get_richacl will be cached.
> +	 * A filesystem can prevent that by calling
> +	 * forget_cached_richacl(inode) in ->get_richacl.
> +	 *
> +	 * If the filesystem doesn't have a ->get_richacl function at all,
> +	 * we'll just create the negative cache entry.
> +	 */
> +	if (!inode->i_op->get_richacl) {
> +		set_cached_richacl(inode, NULL);
> +		return NULL;
> +	}
> +
> +	acl = inode->i_op->get_richacl(inode);
> +	if (IS_ERR(acl)) {
> +		/*
> +		 * Remove our sentinel so that we don't block future attempts
> +		 * to cache the ACL.
> +		 */
> +		cmpxchg(&inode->i_acl, sentinel, ACL_NOT_CACHED);
> +		return acl;
> +	}
> +

So this is sort of icky: only the task that sets the sentinel can set
the cached acl.

You could have one task set the sentinel, call get_richacl and fail, but then a concurrent task also issues a get_richacl and succeeds. That task will get its acl, but it doesn't end up getting cached and subsequent callers then have to reissue the request. It would be good if the first successful fetch of the acl sets it in the cache.

That said, getting the acl could be pretty expensive with some filesystems. NFS or CIFS are going to have to do an on the wire call to fetch them, for instance. I think it would be better to have concurrent callers wait for the first caller's result instead of issuing parallel get_richacl requests.

> +	/*
> +	 * Cache the result, but only if our sentinel is still in place.
> +	 */
> +	richacl_get(acl);
> +	if (unlikely(cmpxchg(&inode->i_acl, sentinel, &acl->a_base) != sentinel))
> +		richacl_put(acl);
> +	return acl;
> +}
> +EXPORT_SYMBOL_GPL(get_richacl);
> +
>  /**
>   * richacl_alloc  -  allocate a richacl
>   * @count:	number of entries
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index ac96bda..4d72a6d 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -589,6 +589,7 @@ struct base_acl {
>  	};
>  };
>  struct posix_acl;
> +struct richacl;
>  #define ACL_NOT_CACHED ((void *)(-1))
>  
>  static inline struct base_acl *
> @@ -619,9 +620,11 @@ struct inode {
>  	kgid_t			i_gid;
>  	unsigned int		i_flags;
>  
> -#if defined(CONFIG_FS_POSIX_ACL)
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  	struct base_acl		*i_acl;
> +# if defined(CONFIG_FS_POSIX_ACL)
>  	struct base_acl		*i_default_acl;
> +# endif
>  #endif
>  

Oh, so if we compile in richacls and not posix acls, we shrink the
inode by a pointer. Nice!

>  	const struct inode_operations	*i_op;
> diff --git a/include/linux/richacl.h b/include/linux/richacl.h
> index 35a5bcb..3e05c94 100644
> --- a/include/linux/richacl.h
> +++ b/include/linux/richacl.h
> @@ -70,6 +70,17 @@ richacl_put(struct richacl *acl)
>  	base_acl_put(&acl->a_base);
>  }
>  
> +static inline struct richacl *
> +richacl(struct base_acl *base_acl)
> +{
> +	BUILD_BUG_ON(offsetof(struct richacl, a_base) != 0);
> +	return container_of(base_acl, struct richacl, a_base);
> +}
> +
> +extern void set_cached_richacl(struct inode *, struct richacl *);
> +extern void forget_cached_richacl(struct inode *);
> +extern struct richacl *get_richacl(struct inode *);
> +
>  /**
>   * richace_is_owner  -  check if @ace is an OWNER@ entry
>   */

-- 
Jeff Layton <jlayton@redhat.com>

WARNING: multiple messages have this Message-ID (diff)
From: Jeff Layton <jlayton@redhat.com>
To: Andreas Gruenbacher <agruenba@redhat.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
	linux-nfs@vger.kernel.org, Theodore Ts'o <tytso@mit.edu>,
	linux-cifs@vger.kernel.org, linux-api@vger.kernel.org,
	Trond Myklebust <trond.myklebust@primarydata.com>,
	linux-kernel@vger.kernel.org, xfs@oss.sgi.com,
	Christoph Hellwig <hch@infradead.org>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,
	Anna Schumaker <anna.schumaker@netapp.com>
Subject: Re: [PATCH v23 13/22] vfs: Cache richacl in struct inode
Date: Wed, 06 Jul 2016 14:57:05 -0400	[thread overview]
Message-ID: <1467831425.2908.16.camel@redhat.com> (raw)
In-Reply-To: <1467294433-3222-14-git-send-email-agruenba@redhat.com>

On Thu, 2016-06-30 at 15:47 +0200, Andreas Gruenbacher wrote:
> Cache richacls in struct inode so that this doesn't have to be done
> individually in each filesystem.  This is similar to POSIX ACLs.
> 
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> ---
>  fs/inode.c              | 13 +++++---
>  fs/richacl.c            | 81 +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/fs.h      |  5 ++-
>  include/linux/richacl.h | 11 +++++++
>  4 files changed, 105 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 40c03a7..7dbb09c 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -181,8 +181,11 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
>  	inode->i_private = NULL;
>  	inode->i_mapping = mapping;
>  	INIT_HLIST_HEAD(&inode->i_dentry);	/* buggered by rcu freeing */
> -#ifdef CONFIG_FS_POSIX_ACL
> -	inode->i_acl = inode->i_default_acl = ACL_NOT_CACHED;
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
> +	inode->i_acl = ACL_NOT_CACHED;
> +# if defined(CONFIG_FS_POSIX_ACL)
> +	inode->i_default_acl = ACL_NOT_CACHED;
> +# endif
>  #endif
>  
>  #ifdef CONFIG_FSNOTIFY
> @@ -238,17 +241,19 @@ void __destroy_inode(struct inode *inode)
>  		atomic_long_dec(&inode->i_sb->s_remove_count);
>  	}
>  
> -#ifdef CONFIG_FS_POSIX_ACL
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  	if (inode->i_acl && !is_uncached_acl(inode->i_acl))
>  		base_acl_put(inode->i_acl);
> +# if defined(CONFIG_FS_POSIX_ACL)
>  	if (inode->i_default_acl && !is_uncached_acl(inode->i_default_acl))
>  		base_acl_put(inode->i_default_acl);
> +# endif
>  #endif
>  	this_cpu_dec(nr_inodes);
>  }
>  EXPORT_SYMBOL(__destroy_inode);
>  
> -#ifdef CONFIG_FS_POSIX_ACL
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  struct base_acl *__get_cached_acl(struct base_acl **p)
>  {
>  	struct base_acl *base_acl;
> diff --git a/fs/richacl.c b/fs/richacl.c
> index 8971ead..b2a03c1 100644
> --- a/fs/richacl.c
> +++ b/fs/richacl.c
> @@ -20,6 +20,87 @@
>  #include 
>  #include 
>  
> +void set_cached_richacl(struct inode *inode, struct richacl *acl)
> +{
> +	struct base_acl *old;
> +
> +	old = xchg(&inode->i_acl, &richacl_get(acl)->a_base);
> +	if (!is_uncached_acl(old))
> +		base_acl_put(old);
> +}
> +EXPORT_SYMBOL_GPL(set_cached_richacl);
> +
> +void forget_cached_richacl(struct inode *inode)
> +{
> +	__forget_cached_acl(&inode->i_acl);
> +}
> +EXPORT_SYMBOL_GPL(forget_cached_richacl);
> +
> +struct richacl *get_richacl(struct inode *inode)
> +{
> +	struct base_acl *sentinel, *base_acl;
> +	struct richacl *acl;
> +
> +	if (!IS_RICHACL(inode))
> +		return NULL;
> +
> +	/*
> +	 * The sentinel is used to detect when another operation like
> +	 * set_cached_richacl() or forget_cached_richacl() races with
> +	 * get_richacl().
> +	 * It is guaranteed that is_uncached_acl(sentinel) is true.
> +	 */
> +
> +	base_acl = __get_cached_acl(&inode->i_acl);
> +	if (!is_uncached_acl(base_acl))
> +		return richacl(base_acl);
> +
> +	sentinel = uncached_acl_sentinel(current);
> +
> +	/*
> +	 * If the ACL isn't being read yet, set our sentinel.  Otherwise, the
> +	 * current value of the ACL will not be ACL_NOT_CACHED and so our own
> +	 * sentinel will not be set; another task will update the cache.  We
> +	 * could wait for that other task to complete its job, but it's easier
> +	 * to just call ->get_acl to fetch the ACL ourself.  (This is going to
> +	 * be an unlikely race.)
> +	 */
> +	if (cmpxchg(&inode->i_acl, ACL_NOT_CACHED, sentinel) != ACL_NOT_CACHED)
> +		/* fall through */ ;
> +

So you do the same thing regardless of the outcome of the above? Why
bother with the if at all here? Just do the cmpxchg and toss out the
result.

> +	/*
> +	 * Normally, the ACL returned by ->get_richacl will be cached.
> +	 * A filesystem can prevent that by calling
> +	 * forget_cached_richacl(inode) in ->get_richacl.
> +	 *
> +	 * If the filesystem doesn't have a ->get_richacl function at all,
> +	 * we'll just create the negative cache entry.
> +	 */
> +	if (!inode->i_op->get_richacl) {
> +		set_cached_richacl(inode, NULL);
> +		return NULL;
> +	}
> +
> +	acl = inode->i_op->get_richacl(inode);
> +	if (IS_ERR(acl)) {
> +		/*
> +		 * Remove our sentinel so that we don't block future attempts
> +		 * to cache the ACL.
> +		 */
> +		cmpxchg(&inode->i_acl, sentinel, ACL_NOT_CACHED);
> +		return acl;
> +	}
> +

So this is sort of icky: only the task that sets the sentinel can set
the cached acl.

You could have one task set the sentinel, call get_richacl and fail, but then a concurrent task also issues a get_richacl and succeeds. That task will get its acl, but it doesn't end up getting cached and subsequent callers then have to reissue the request. It would be good if the first successful fetch of the acl sets it in the cache.

That said, getting the acl could be pretty expensive with some filesystems. NFS or CIFS are going to have to do an on the wire call to fetch them, for instance. I think it would be better to have concurrent callers wait for the first caller's result instead of issuing parallel get_richacl requests.

> +	/*
> +	 * Cache the result, but only if our sentinel is still in place.
> +	 */
> +	richacl_get(acl);
> +	if (unlikely(cmpxchg(&inode->i_acl, sentinel, &acl->a_base) != sentinel))
> +		richacl_put(acl);
> +	return acl;
> +}
> +EXPORT_SYMBOL_GPL(get_richacl);
> +
>  /**
>   * richacl_alloc  -  allocate a richacl
>   * @count:	number of entries
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index ac96bda..4d72a6d 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -589,6 +589,7 @@ struct base_acl {
>  	};
>  };
>  struct posix_acl;
> +struct richacl;
>  #define ACL_NOT_CACHED ((void *)(-1))
>  
>  static inline struct base_acl *
> @@ -619,9 +620,11 @@ struct inode {
>  	kgid_t			i_gid;
>  	unsigned int		i_flags;
>  
> -#if defined(CONFIG_FS_POSIX_ACL)
> +#if defined(CONFIG_FS_POSIX_ACL) || defined(CONFIG_FS_RICHACL)
>  	struct base_acl		*i_acl;
> +# if defined(CONFIG_FS_POSIX_ACL)
>  	struct base_acl		*i_default_acl;
> +# endif
>  #endif
>  

Oh, so if we compile in richacls and not posix acls, we shrink the
inode by a pointer. Nice!

>  	const struct inode_operations	*i_op;
> diff --git a/include/linux/richacl.h b/include/linux/richacl.h
> index 35a5bcb..3e05c94 100644
> --- a/include/linux/richacl.h
> +++ b/include/linux/richacl.h
> @@ -70,6 +70,17 @@ richacl_put(struct richacl *acl)
>  	base_acl_put(&acl->a_base);
>  }
>  
> +static inline struct richacl *
> +richacl(struct base_acl *base_acl)
> +{
> +	BUILD_BUG_ON(offsetof(struct richacl, a_base) != 0);
> +	return container_of(base_acl, struct richacl, a_base);
> +}
> +
> +extern void set_cached_richacl(struct inode *, struct richacl *);
> +extern void forget_cached_richacl(struct inode *);
> +extern struct richacl *get_richacl(struct inode *);
> +
>  /**
>   * richace_is_owner  -  check if @ace is an OWNER@ entry
>   */

-- 
Jeff Layton <jlayton@redhat.com>

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2016-07-06 18:57 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-30 13:46 [PATCH v23 00/22] Richacls (Core and Ext4) Andreas Gruenbacher
2016-06-30 13:46 ` Andreas Gruenbacher
2016-06-30 13:46 ` [PATCH v23 01/22] vfs: Add IS_ACL() and IS_RICHACL() tests Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
2016-07-05 11:00   ` Jeff Layton
2016-07-05 11:00     ` Jeff Layton
2016-06-30 13:46 ` [PATCH v23 02/22] vfs: Add MAY_CREATE_FILE and MAY_CREATE_DIR permission flags Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-3-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-05 11:02     ` Jeff Layton
2016-07-05 11:02       ` Jeff Layton
2016-07-05 11:02       ` Jeff Layton
2016-06-30 13:46 ` [PATCH v23 03/22] vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD " Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-4-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-05 11:07     ` Jeff Layton
2016-07-05 11:07       ` Jeff Layton
2016-07-05 11:07       ` Jeff Layton
2016-06-30 13:46 ` [PATCH v23 04/22] vfs: Make the inode passed to inode_change_ok non-const Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-5-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-05 11:12     ` Jeff Layton
2016-07-05 11:12       ` Jeff Layton
2016-07-05 11:12       ` Jeff Layton
2016-06-30 13:46 ` [PATCH v23 05/22] vfs: Add permission flags for setting file attributes Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
2016-07-05 11:18   ` Jeff Layton
2016-07-05 11:18     ` Jeff Layton
2016-06-30 13:46 ` [PATCH v23 06/22] richacl: In-memory representation and helper functions Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
2016-07-05 11:34   ` Jeff Layton
2016-07-05 11:34     ` Jeff Layton
2016-07-05 11:34     ` Jeff Layton
     [not found]     ` <1467718448.3800.16.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-11 10:11       ` Andreas Gruenbacher
2016-07-11 10:11         ` Andreas Gruenbacher
2016-07-11 10:11         ` Andreas Gruenbacher
2016-06-30 13:46 ` [PATCH v23 07/22] richacl: Permission mapping functions Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
2016-07-05 13:39   ` Jeff Layton
2016-07-05 13:39     ` Jeff Layton
2016-07-05 13:39     ` Jeff Layton
2016-07-11 13:26     ` Andreas Gruenbacher
2016-07-11 13:26       ` Andreas Gruenbacher
2016-06-30 13:46 ` [PATCH v23 08/22] richacl: Compute maximum file masks from an acl Andreas Gruenbacher
2016-06-30 13:46   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-9-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-05 14:22     ` Jeff Layton
2016-07-05 14:22       ` Jeff Layton
2016-07-05 14:22       ` Jeff Layton
2016-07-05 17:08       ` Frank Filz
2016-07-05 17:08         ` Frank Filz
2016-07-05 17:08         ` Frank Filz
2016-07-13 12:34         ` Andreas Gruenbacher
2016-07-13 12:34           ` Andreas Gruenbacher
2016-07-13 19:38           ` Frank Filz
2016-07-13 19:38             ` Frank Filz
2016-07-13 19:38             ` Frank Filz
2016-06-30 13:47 ` [PATCH v23 09/22] richacl: Permission check algorithm Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-07-05 14:59   ` Jeff Layton
2016-07-05 14:59     ` Jeff Layton
2016-07-11 13:28     ` Andreas Gruenbacher
2016-07-11 13:28       ` Andreas Gruenbacher
2016-06-30 13:47 ` [PATCH v23 10/22] posix_acl: Improve xattr fixup code Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-11-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-05 15:38     ` Jeff Layton
2016-07-05 15:38       ` Jeff Layton
2016-07-05 15:38       ` Jeff Layton
2016-06-30 13:47 ` [PATCH v23 11/22] vfs: Cache base_acl objects in inodes Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-12-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-05 15:56     ` Jeff Layton
2016-07-05 15:56       ` Jeff Layton
2016-07-05 15:56       ` Jeff Layton
2016-06-30 13:47 ` [PATCH v23 12/22] vfs: Add get_richacl and set_richacl inode operations Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-13-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-06 18:31     ` Jeff Layton
2016-07-06 18:31       ` Jeff Layton
2016-07-06 18:31       ` Jeff Layton
2016-06-30 13:47 ` [PATCH v23 13/22] vfs: Cache richacl in struct inode Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-14-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-06 18:57     ` Jeff Layton [this message]
2016-07-06 18:57       ` Jeff Layton
2016-07-06 18:57       ` Jeff Layton
2016-07-14 20:02       ` Andreas Gruenbacher
2016-07-14 20:02         ` Andreas Gruenbacher
     [not found]   ` <1467831425.2908.16.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-07 14:14     ` David Howells
2016-07-07 14:14       ` David Howells
2016-07-07 14:14       ` David Howells
2016-06-30 13:47 ` [PATCH v23 14/22] richacl: Update the file masks in chmod() Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
     [not found]   ` <1467294433-3222-15-git-send-email-agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-12 11:36     ` Jeff Layton
2016-07-12 11:36       ` Jeff Layton
2016-07-12 11:36       ` Jeff Layton
2016-06-30 13:47 ` [PATCH v23 15/22] richacl: Check if an acl is equivalent to a file mode Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-07-12 11:39   ` Jeff Layton
2016-07-12 11:39     ` Jeff Layton
2016-07-12 11:39     ` Jeff Layton
2016-06-30 13:47 ` [PATCH v23 16/22] richacl: Create-time inheritance Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-07-12 11:41   ` Jeff Layton
2016-07-12 11:41     ` Jeff Layton
2016-06-30 13:47 ` [PATCH v23 17/22] richacl: Automatic Inheritance Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-07-12 11:56   ` Jeff Layton
2016-07-12 11:56     ` Jeff Layton
2016-07-12 11:56     ` Jeff Layton
     [not found]     ` <1468324560.7798.14.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-12 19:11       ` J. Bruce Fields
2016-07-12 19:11         ` J. Bruce Fields
2016-07-12 19:11         ` J. Bruce Fields
     [not found]         ` <20160712191142.GE449-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org>
2016-07-12 20:28           ` Andreas Gruenbacher
2016-07-12 20:28             ` Andreas Gruenbacher
2016-07-12 20:28             ` Andreas Gruenbacher
2016-06-30 13:47 ` [PATCH v23 18/22] richacl: xattr mapping functions Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-07-12 12:02   ` Jeff Layton
2016-07-12 12:02     ` Jeff Layton
2016-07-14 20:33     ` Andreas Gruenbacher
2016-07-14 20:33       ` Andreas Gruenbacher
2016-06-30 13:47 ` [PATCH v23 19/22] richacl: Add richacl xattr handler Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-07-12 12:13   ` Jeff Layton
2016-07-12 12:13     ` Jeff Layton
2016-06-30 13:47 ` [PATCH v23 20/22] vfs: Add richacl permission checking Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-07-12 12:13   ` Jeff Layton
2016-07-12 12:13     ` Jeff Layton
2016-07-12 12:13     ` Jeff Layton
     [not found]     ` <1468325634.7798.24.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-14 20:59       ` Andreas Gruenbacher
2016-07-14 20:59         ` Andreas Gruenbacher
2016-07-14 20:59         ` Andreas Gruenbacher
2016-06-30 13:47 ` [PATCH v23 21/22] ext4: Add richacl support Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-06-30 13:47 ` [PATCH v23 22/22] ext4: Add richacl feature flag Andreas Gruenbacher
2016-06-30 13:47   ` Andreas Gruenbacher
2016-06-30 14:11 ` [PATCH v23 00/22] Richacls (Core and Ext4) Volker Lendecke
2016-06-30 14:11   ` Volker Lendecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467831425.2908.16.camel@redhat.com \
    --to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=adilger.kernel-m1MBpc4rdrD3fQ9qLvQP4Q@public.gmane.org \
    --cc=agruenba-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=anna.schumaker-HgOvQuBEEgTQT0dZR+AlfA@public.gmane.org \
    --cc=bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org \
    --cc=david-FqsqvQoI3Ljby3iVrkZq2A@public.gmane.org \
    --cc=hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=trond.myklebust-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org \
    --cc=tytso-3s7WtUTddSA@public.gmane.org \
    --cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org \
    --cc=xfs-VZNHf3L845pBDgjK7y7TUQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.