All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] ceph: fix statfs for subdir mounts
@ 2022-04-27 15:57 Luís Henriques
  2022-04-27 16:26 ` Jeff Layton
  2022-04-28  1:08 ` Xiubo Li
  0 siblings, 2 replies; 3+ messages in thread
From: Luís Henriques @ 2022-04-27 15:57 UTC (permalink / raw)
  To: Jeff Layton, Xiubo Li, Ilya Dryomov
  Cc: ceph-devel, linux-kernel, Luís Henriques, Ryan Taylor

When doing a mount using as base a directory that has 'max_bytes' quotas
statfs uses that value as the total; if a subdirectory is used instead,
the same 'max_bytes' too in statfs, unless there is another quota set.

Unfortunately, if this subdirectory only has the 'max_files' quota set,
then statfs uses the filesystem total.  Fix this by making sure we only
lookup realms that contain the 'max_bytes' quota.

Link: https://tracker.ceph.com/issues/55090
Cc: Ryan Taylor <rptaylor@uvic.ca>
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
Changes since v2:
Renamed function __ceph_has_any_quota() to __ceph_has_quota()

Changes since v1:
Moved some more logic into __ceph_has_any_quota() function.

 fs/ceph/inode.c |  2 +-
 fs/ceph/quota.c | 19 +++++++++++--------
 fs/ceph/super.h | 28 ++++++++++++++++++++++++----
 3 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 5de7bb9048b7..1067209cf6f6 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -691,7 +691,7 @@ void ceph_evict_inode(struct inode *inode)
 
 	__ceph_remove_caps(ci);
 
-	if (__ceph_has_any_quota(ci))
+	if (__ceph_has_quota(ci, QUOTA_GET_ANY))
 		ceph_adjust_quota_realms_count(inode, false);
 
 	/*
diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
index a338a3ec0dc4..64592adfe48f 100644
--- a/fs/ceph/quota.c
+++ b/fs/ceph/quota.c
@@ -195,9 +195,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
 
 /*
  * This function walks through the snaprealm for an inode and returns the
- * ceph_snap_realm for the first snaprealm that has quotas set (either max_files
- * or max_bytes).  If the root is reached, return the root ceph_snap_realm
- * instead.
+ * ceph_snap_realm for the first snaprealm that has quotas set (max_files,
+ * max_bytes, or any, depending on the 'which_quota' argument).  If the root is
+ * reached, return the root ceph_snap_realm instead.
  *
  * Note that the caller is responsible for calling ceph_put_snap_realm() on the
  * returned realm.
@@ -209,7 +209,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
  * will be restarted.
  */
 static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
-					       struct inode *inode, bool retry)
+					       struct inode *inode,
+					       enum quota_get_realm which_quota,
+					       bool retry)
 {
 	struct ceph_inode_info *ci = NULL;
 	struct ceph_snap_realm *realm, *next;
@@ -248,7 +250,7 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
 		}
 
 		ci = ceph_inode(in);
-		has_quota = __ceph_has_any_quota(ci);
+		has_quota = __ceph_has_quota(ci, which_quota);
 		iput(in);
 
 		next = realm->parent;
@@ -279,8 +281,8 @@ bool ceph_quota_is_same_realm(struct inode *old, struct inode *new)
 	 * dropped and we can then restart the whole operation.
 	 */
 	down_read(&mdsc->snap_rwsem);
-	old_realm = get_quota_realm(mdsc, old, true);
-	new_realm = get_quota_realm(mdsc, new, false);
+	old_realm = get_quota_realm(mdsc, old, QUOTA_GET_ANY, true);
+	new_realm = get_quota_realm(mdsc, new, QUOTA_GET_ANY, false);
 	if (PTR_ERR(new_realm) == -EAGAIN) {
 		up_read(&mdsc->snap_rwsem);
 		if (old_realm)
@@ -483,7 +485,8 @@ bool ceph_quota_update_statfs(struct ceph_fs_client *fsc, struct kstatfs *buf)
 	bool is_updated = false;
 
 	down_read(&mdsc->snap_rwsem);
-	realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root), true);
+	realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root),
+				QUOTA_GET_MAX_BYTES, true);
 	up_read(&mdsc->snap_rwsem);
 	if (!realm)
 		return false;
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index a2e1c83ab29a..0ecde1c12fee 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -1317,9 +1317,29 @@ extern void ceph_fs_debugfs_init(struct ceph_fs_client *client);
 extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);
 
 /* quota.c */
-static inline bool __ceph_has_any_quota(struct ceph_inode_info *ci)
+
+enum quota_get_realm {
+	QUOTA_GET_MAX_FILES,
+	QUOTA_GET_MAX_BYTES,
+	QUOTA_GET_ANY
+};
+
+static inline bool __ceph_has_quota(struct ceph_inode_info *ci,
+				    enum quota_get_realm which)
 {
-	return ci->i_max_files || ci->i_max_bytes;
+	bool has_quota = false;
+
+	switch (which) {
+	case QUOTA_GET_MAX_BYTES:
+		has_quota = !!ci->i_max_bytes;
+		break;
+	case QUOTA_GET_MAX_FILES:
+		has_quota = !!ci->i_max_files;
+		break;
+	default:
+		has_quota = !!(ci->i_max_files || ci->i_max_bytes);
+	}
+	return has_quota;
 }
 
 extern void ceph_adjust_quota_realms_count(struct inode *inode, bool inc);
@@ -1328,10 +1348,10 @@ static inline void __ceph_update_quota(struct ceph_inode_info *ci,
 				       u64 max_bytes, u64 max_files)
 {
 	bool had_quota, has_quota;
-	had_quota = __ceph_has_any_quota(ci);
+	had_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
 	ci->i_max_bytes = max_bytes;
 	ci->i_max_files = max_files;
-	has_quota = __ceph_has_any_quota(ci);
+	has_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
 
 	if (had_quota != has_quota)
 		ceph_adjust_quota_realms_count(&ci->vfs_inode, has_quota);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] ceph: fix statfs for subdir mounts
  2022-04-27 15:57 [PATCH v3] ceph: fix statfs for subdir mounts Luís Henriques
@ 2022-04-27 16:26 ` Jeff Layton
  2022-04-28  1:08 ` Xiubo Li
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Layton @ 2022-04-27 16:26 UTC (permalink / raw)
  To: Luís Henriques, Xiubo Li, Ilya Dryomov
  Cc: ceph-devel, linux-kernel, Ryan Taylor

On Wed, 2022-04-27 at 16:57 +0100, Luís Henriques wrote:
> When doing a mount using as base a directory that has 'max_bytes' quotas
> statfs uses that value as the total; if a subdirectory is used instead,
> the same 'max_bytes' too in statfs, unless there is another quota set.
> 
> Unfortunately, if this subdirectory only has the 'max_files' quota set,
> then statfs uses the filesystem total.  Fix this by making sure we only
> lookup realms that contain the 'max_bytes' quota.
> 
> Link: https://tracker.ceph.com/issues/55090
> Cc: Ryan Taylor <rptaylor@uvic.ca>
> Signed-off-by: Luís Henriques <lhenriques@suse.de>
> ---
> Changes since v2:
> Renamed function __ceph_has_any_quota() to __ceph_has_quota()
> 
> Changes since v1:
> Moved some more logic into __ceph_has_any_quota() function.
> 
>  fs/ceph/inode.c |  2 +-
>  fs/ceph/quota.c | 19 +++++++++++--------
>  fs/ceph/super.h | 28 ++++++++++++++++++++++++----
>  3 files changed, 36 insertions(+), 13 deletions(-)
> 
> diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
> index 5de7bb9048b7..1067209cf6f6 100644
> --- a/fs/ceph/inode.c
> +++ b/fs/ceph/inode.c
> @@ -691,7 +691,7 @@ void ceph_evict_inode(struct inode *inode)
>  
>  	__ceph_remove_caps(ci);
>  
> -	if (__ceph_has_any_quota(ci))
> +	if (__ceph_has_quota(ci, QUOTA_GET_ANY))
>  		ceph_adjust_quota_realms_count(inode, false);
>  
>  	/*
> diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
> index a338a3ec0dc4..64592adfe48f 100644
> --- a/fs/ceph/quota.c
> +++ b/fs/ceph/quota.c
> @@ -195,9 +195,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
>  
>  /*
>   * This function walks through the snaprealm for an inode and returns the
> - * ceph_snap_realm for the first snaprealm that has quotas set (either max_files
> - * or max_bytes).  If the root is reached, return the root ceph_snap_realm
> - * instead.
> + * ceph_snap_realm for the first snaprealm that has quotas set (max_files,
> + * max_bytes, or any, depending on the 'which_quota' argument).  If the root is
> + * reached, return the root ceph_snap_realm instead.
>   *
>   * Note that the caller is responsible for calling ceph_put_snap_realm() on the
>   * returned realm.
> @@ -209,7 +209,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
>   * will be restarted.
>   */
>  static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
> -					       struct inode *inode, bool retry)
> +					       struct inode *inode,
> +					       enum quota_get_realm which_quota,
> +					       bool retry)
>  {
>  	struct ceph_inode_info *ci = NULL;
>  	struct ceph_snap_realm *realm, *next;
> @@ -248,7 +250,7 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
>  		}
>  
>  		ci = ceph_inode(in);
> -		has_quota = __ceph_has_any_quota(ci);
> +		has_quota = __ceph_has_quota(ci, which_quota);
>  		iput(in);
>  
>  		next = realm->parent;
> @@ -279,8 +281,8 @@ bool ceph_quota_is_same_realm(struct inode *old, struct inode *new)
>  	 * dropped and we can then restart the whole operation.
>  	 */
>  	down_read(&mdsc->snap_rwsem);
> -	old_realm = get_quota_realm(mdsc, old, true);
> -	new_realm = get_quota_realm(mdsc, new, false);
> +	old_realm = get_quota_realm(mdsc, old, QUOTA_GET_ANY, true);
> +	new_realm = get_quota_realm(mdsc, new, QUOTA_GET_ANY, false);
>  	if (PTR_ERR(new_realm) == -EAGAIN) {
>  		up_read(&mdsc->snap_rwsem);
>  		if (old_realm)
> @@ -483,7 +485,8 @@ bool ceph_quota_update_statfs(struct ceph_fs_client *fsc, struct kstatfs *buf)
>  	bool is_updated = false;
>  
>  	down_read(&mdsc->snap_rwsem);
> -	realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root), true);
> +	realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root),
> +				QUOTA_GET_MAX_BYTES, true);
>  	up_read(&mdsc->snap_rwsem);
>  	if (!realm)
>  		return false;
> diff --git a/fs/ceph/super.h b/fs/ceph/super.h
> index a2e1c83ab29a..0ecde1c12fee 100644
> --- a/fs/ceph/super.h
> +++ b/fs/ceph/super.h
> @@ -1317,9 +1317,29 @@ extern void ceph_fs_debugfs_init(struct ceph_fs_client *client);
>  extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);
>  
>  /* quota.c */
> -static inline bool __ceph_has_any_quota(struct ceph_inode_info *ci)
> +
> +enum quota_get_realm {
> +	QUOTA_GET_MAX_FILES,
> +	QUOTA_GET_MAX_BYTES,
> +	QUOTA_GET_ANY
> +};
> +
> +static inline bool __ceph_has_quota(struct ceph_inode_info *ci,
> +				    enum quota_get_realm which)
>  {
> -	return ci->i_max_files || ci->i_max_bytes;
> +	bool has_quota = false;
> +
> +	switch (which) {
> +	case QUOTA_GET_MAX_BYTES:
> +		has_quota = !!ci->i_max_bytes;
> +		break;
> +	case QUOTA_GET_MAX_FILES:
> +		has_quota = !!ci->i_max_files;
> +		break;
> +	default:
> +		has_quota = !!(ci->i_max_files || ci->i_max_bytes);
> +	}
> +	return has_quota;
>  }
>  
>  extern void ceph_adjust_quota_realms_count(struct inode *inode, bool inc);
> @@ -1328,10 +1348,10 @@ static inline void __ceph_update_quota(struct ceph_inode_info *ci,
>  				       u64 max_bytes, u64 max_files)
>  {
>  	bool had_quota, has_quota;
> -	had_quota = __ceph_has_any_quota(ci);
> +	had_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
>  	ci->i_max_bytes = max_bytes;
>  	ci->i_max_files = max_files;
> -	has_quota = __ceph_has_any_quota(ci);
> +	has_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
>  
>  	if (had_quota != has_quota)
>  		ceph_adjust_quota_realms_count(&ci->vfs_inode, has_quota);

Reviewed-by: Jeff Layton <jlayton@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] ceph: fix statfs for subdir mounts
  2022-04-27 15:57 [PATCH v3] ceph: fix statfs for subdir mounts Luís Henriques
  2022-04-27 16:26 ` Jeff Layton
@ 2022-04-28  1:08 ` Xiubo Li
  1 sibling, 0 replies; 3+ messages in thread
From: Xiubo Li @ 2022-04-28  1:08 UTC (permalink / raw)
  To: Luís Henriques, Jeff Layton, Ilya Dryomov
  Cc: ceph-devel, linux-kernel, Ryan Taylor


On 4/27/22 11:57 PM, Luís Henriques wrote:
> When doing a mount using as base a directory that has 'max_bytes' quotas
> statfs uses that value as the total; if a subdirectory is used instead,
> the same 'max_bytes' too in statfs, unless there is another quota set.
>
> Unfortunately, if this subdirectory only has the 'max_files' quota set,
> then statfs uses the filesystem total.  Fix this by making sure we only
> lookup realms that contain the 'max_bytes' quota.
>
> Link: https://tracker.ceph.com/issues/55090
> Cc: Ryan Taylor <rptaylor@uvic.ca>
> Signed-off-by: Luís Henriques <lhenriques@suse.de>
> ---
> Changes since v2:
> Renamed function __ceph_has_any_quota() to __ceph_has_quota()
>
> Changes since v1:
> Moved some more logic into __ceph_has_any_quota() function.
>
>   fs/ceph/inode.c |  2 +-
>   fs/ceph/quota.c | 19 +++++++++++--------
>   fs/ceph/super.h | 28 ++++++++++++++++++++++++----
>   3 files changed, 36 insertions(+), 13 deletions(-)
>
> diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
> index 5de7bb9048b7..1067209cf6f6 100644
> --- a/fs/ceph/inode.c
> +++ b/fs/ceph/inode.c
> @@ -691,7 +691,7 @@ void ceph_evict_inode(struct inode *inode)
>   
>   	__ceph_remove_caps(ci);
>   
> -	if (__ceph_has_any_quota(ci))
> +	if (__ceph_has_quota(ci, QUOTA_GET_ANY))
>   		ceph_adjust_quota_realms_count(inode, false);
>   
>   	/*
> diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
> index a338a3ec0dc4..64592adfe48f 100644
> --- a/fs/ceph/quota.c
> +++ b/fs/ceph/quota.c
> @@ -195,9 +195,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
>   
>   /*
>    * This function walks through the snaprealm for an inode and returns the
> - * ceph_snap_realm for the first snaprealm that has quotas set (either max_files
> - * or max_bytes).  If the root is reached, return the root ceph_snap_realm
> - * instead.
> + * ceph_snap_realm for the first snaprealm that has quotas set (max_files,
> + * max_bytes, or any, depending on the 'which_quota' argument).  If the root is
> + * reached, return the root ceph_snap_realm instead.
>    *
>    * Note that the caller is responsible for calling ceph_put_snap_realm() on the
>    * returned realm.
> @@ -209,7 +209,9 @@ void ceph_cleanup_quotarealms_inodes(struct ceph_mds_client *mdsc)
>    * will be restarted.
>    */
>   static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
> -					       struct inode *inode, bool retry)
> +					       struct inode *inode,
> +					       enum quota_get_realm which_quota,
> +					       bool retry)
>   {
>   	struct ceph_inode_info *ci = NULL;
>   	struct ceph_snap_realm *realm, *next;
> @@ -248,7 +250,7 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
>   		}
>   
>   		ci = ceph_inode(in);
> -		has_quota = __ceph_has_any_quota(ci);
> +		has_quota = __ceph_has_quota(ci, which_quota);
>   		iput(in);
>   
>   		next = realm->parent;
> @@ -279,8 +281,8 @@ bool ceph_quota_is_same_realm(struct inode *old, struct inode *new)
>   	 * dropped and we can then restart the whole operation.
>   	 */
>   	down_read(&mdsc->snap_rwsem);
> -	old_realm = get_quota_realm(mdsc, old, true);
> -	new_realm = get_quota_realm(mdsc, new, false);
> +	old_realm = get_quota_realm(mdsc, old, QUOTA_GET_ANY, true);
> +	new_realm = get_quota_realm(mdsc, new, QUOTA_GET_ANY, false);
>   	if (PTR_ERR(new_realm) == -EAGAIN) {
>   		up_read(&mdsc->snap_rwsem);
>   		if (old_realm)
> @@ -483,7 +485,8 @@ bool ceph_quota_update_statfs(struct ceph_fs_client *fsc, struct kstatfs *buf)
>   	bool is_updated = false;
>   
>   	down_read(&mdsc->snap_rwsem);
> -	realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root), true);
> +	realm = get_quota_realm(mdsc, d_inode(fsc->sb->s_root),
> +				QUOTA_GET_MAX_BYTES, true);
>   	up_read(&mdsc->snap_rwsem);
>   	if (!realm)
>   		return false;
> diff --git a/fs/ceph/super.h b/fs/ceph/super.h
> index a2e1c83ab29a..0ecde1c12fee 100644
> --- a/fs/ceph/super.h
> +++ b/fs/ceph/super.h
> @@ -1317,9 +1317,29 @@ extern void ceph_fs_debugfs_init(struct ceph_fs_client *client);
>   extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);
>   
>   /* quota.c */
> -static inline bool __ceph_has_any_quota(struct ceph_inode_info *ci)
> +
> +enum quota_get_realm {
> +	QUOTA_GET_MAX_FILES,
> +	QUOTA_GET_MAX_BYTES,
> +	QUOTA_GET_ANY
> +};
> +
> +static inline bool __ceph_has_quota(struct ceph_inode_info *ci,
> +				    enum quota_get_realm which)
>   {
> -	return ci->i_max_files || ci->i_max_bytes;
> +	bool has_quota = false;
> +
> +	switch (which) {
> +	case QUOTA_GET_MAX_BYTES:
> +		has_quota = !!ci->i_max_bytes;
> +		break;
> +	case QUOTA_GET_MAX_FILES:
> +		has_quota = !!ci->i_max_files;
> +		break;
> +	default:
> +		has_quota = !!(ci->i_max_files || ci->i_max_bytes);
> +	}
> +	return has_quota;
>   }
>   
>   extern void ceph_adjust_quota_realms_count(struct inode *inode, bool inc);
> @@ -1328,10 +1348,10 @@ static inline void __ceph_update_quota(struct ceph_inode_info *ci,
>   				       u64 max_bytes, u64 max_files)
>   {
>   	bool had_quota, has_quota;
> -	had_quota = __ceph_has_any_quota(ci);
> +	had_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
>   	ci->i_max_bytes = max_bytes;
>   	ci->i_max_files = max_files;
> -	has_quota = __ceph_has_any_quota(ci);
> +	has_quota = __ceph_has_quota(ci, QUOTA_GET_ANY);
>   
>   	if (had_quota != has_quota)
>   		ceph_adjust_quota_realms_count(&ci->vfs_inode, has_quota);
>
Looks good. Merged into the testing branch.

Thanks Luis.

-- Xiubo



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-28  1:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 15:57 [PATCH v3] ceph: fix statfs for subdir mounts Luís Henriques
2022-04-27 16:26 ` Jeff Layton
2022-04-28  1:08 ` Xiubo Li

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.