[3/3] ceph: fix infinite loop in get_quota_realm()
diff mbox series

Message ID 20190531122802.12814-3-zyan@redhat.com
State New
Headers show
Series
  • [1/3] libceph: add function that reset client's entity addr
Related show

Commit Message

Yan, Zheng May 31, 2019, 12:28 p.m. UTC
get_quota_realm() enters infinite loop if quota inode has no caps.
This can happen after client gets evicted.

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
---
 fs/ceph/quota.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Luis Henriques May 31, 2019, 3:13 p.m. UTC | #1
On Fri, May 31, 2019 at 08:28:02PM +0800, Yan, Zheng wrote:
> get_quota_realm() enters infinite loop if quota inode has no caps.
> This can happen after client gets evicted.
> 
> Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
> ---
>  fs/ceph/quota.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
> index d629fc857450..de56dee60540 100644
> --- a/fs/ceph/quota.c
> +++ b/fs/ceph/quota.c
> @@ -135,7 +135,7 @@ static struct inode *lookup_quotarealm_inode(struct ceph_mds_client *mdsc,
>  		return NULL;
>  
>  	mutex_lock(&qri->mutex);
> -	if (qri->inode) {
> +	if (qri->inode && ceph_is_any_caps(qri->inode)) {
>  		/* A request has already returned the inode */
>  		mutex_unlock(&qri->mutex);
>  		return qri->inode;
> @@ -146,7 +146,18 @@ static struct inode *lookup_quotarealm_inode(struct ceph_mds_client *mdsc,
>  		mutex_unlock(&qri->mutex);
>  		return NULL;
>  	}
> -	in = ceph_lookup_inode(sb, realm->ino);
> +	if (qri->inode) {
> +		/* get caps */
> +		int ret = __ceph_do_getattr(qri->inode, NULL,
> +					    CEPH_STAT_CAP_INODE, true);
> +		if (ret >= 0)
> +			in = qri->inode;
> +		else
> +			in = ERR_PTR(ret);
> +	}  else {
> +		in = ceph_lookup_inode(sb, realm->ino);
> +	}
> +
>  	if (IS_ERR(in)) {
>  		pr_warn("Can't lookup inode %llx (err: %ld)\n",
>  			realm->ino, PTR_ERR(in));
> -- 
> 2.17.2
> 
> 

Nice catch, thanks!  Feel free to add my

Reviewed-by: Luis Henriques <lhenriques@suse.com>

Cheers,
--
Luís

Patch
diff mbox series

diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
index d629fc857450..de56dee60540 100644
--- a/fs/ceph/quota.c
+++ b/fs/ceph/quota.c
@@ -135,7 +135,7 @@  static struct inode *lookup_quotarealm_inode(struct ceph_mds_client *mdsc,
 		return NULL;
 
 	mutex_lock(&qri->mutex);
-	if (qri->inode) {
+	if (qri->inode && ceph_is_any_caps(qri->inode)) {
 		/* A request has already returned the inode */
 		mutex_unlock(&qri->mutex);
 		return qri->inode;
@@ -146,7 +146,18 @@  static struct inode *lookup_quotarealm_inode(struct ceph_mds_client *mdsc,
 		mutex_unlock(&qri->mutex);
 		return NULL;
 	}
-	in = ceph_lookup_inode(sb, realm->ino);
+	if (qri->inode) {
+		/* get caps */
+		int ret = __ceph_do_getattr(qri->inode, NULL,
+					    CEPH_STAT_CAP_INODE, true);
+		if (ret >= 0)
+			in = qri->inode;
+		else
+			in = ERR_PTR(ret);
+	}  else {
+		in = ceph_lookup_inode(sb, realm->ino);
+	}
+
 	if (IS_ERR(in)) {
 		pr_warn("Can't lookup inode %llx (err: %ld)\n",
 			realm->ino, PTR_ERR(in));