Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1460609ybm; Thu, 23 May 2019 01:10:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzRM8tfpZiKGktIDqnseFh917u0Plc9PQyQ6R/JILzHzxVohdSl0iUV/6yeOtKO6KL3DbA X-Received: by 2002:a65:4283:: with SMTP id j3mr46851389pgp.88.1558599030119; Thu, 23 May 2019 01:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558599030; cv=none; d=google.com; s=arc-20160816; b=RABdRunOrDsQVZt/9PiIF6Tt5dhlkEATvaZUMcNTaXFqkZxVwq2igyb9VosLhqqRh7 Jt/tEIP7ULY/dPXxrjkAb+lTqRoXdzopCqw6jD+kGaT6562RA2NXQcdkhQAcpuGkRWXD ckd9Z5xOBw25d6b7J5ZWaxQIW50sZpgg3lNs6F3JW/PO2xMuaGiP5UKwyJu2d8RX6K9z UOnHsAr8GLvCo0B6W70fTY+NsQLoEPlhZpOnnKQLNli2+xr6vRuVZSqV1Xh8xOmU05p7 3l585O2CsE9wFPV9KOEESm4IJ+RSTzjEufhuDgIIrhM9+hZo72ssA6mlvMWndWavedmY I+Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dfcp1J2hURlRZ6ZoL55kX3kYlVgmUsi41pcEPcPR0qQ=; b=ByYfPUxIX3k123YOM2IzDgKkuOvENDoac76vwbZCvLbyfhoX02BnkO5xMJcqirjh/k ndUkbbl2+iP4hraxTmyWhvRz6ZeLdUybEgZ58qAPrC6wPgttpCm/rZyrXT4/jdtck27z HyTMV6aaTrPsPjwBAXYJFw7QZd6RMXV6NSrK1aTQkOyQFOUkFkMsMHZQbrkNowbTd/1Z n1hRV4xr1tEVLmBrFcHsexTvxeLmGCHQD75wGvZXzQ9pKxvR7j7CxRsA+4VxtzG4qOlc aG4ky9uqtHkQCOC3kGDqj5j9WwEXW7s/gIKHg04OF1LI0EXrup+1ApmWhBlOjoRvKQiV upBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si2326620pgc.157.2019.05.23.01.10.15; Thu, 23 May 2019 01:10:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730028AbfEWIHC (ORCPT + 99 others); Thu, 23 May 2019 04:07:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36628 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbfEWIHB (ORCPT ); Thu, 23 May 2019 04:07:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 974FE81106 for ; Thu, 23 May 2019 08:07:01 +0000 (UTC) Received: from zhyan-laptop.redhat.com (ovpn-12-163.pek2.redhat.com [10.72.12.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95B745D9C6; Thu, 23 May 2019 08:06:59 +0000 (UTC) From: "Yan, Zheng" To: linux-kernel@vger.kernel.org Cc: idryomov@redhat.com, jlayton@redhat.com Subject: [PATCH 5/8] ceph: fix dir_lease_is_valid() Date: Thu, 23 May 2019 16:06:43 +0800 Message-Id: <20190523080646.19632-5-zyan@redhat.com> In-Reply-To: <20190523080646.19632-1-zyan@redhat.com> References: <20190523080646.19632-1-zyan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 23 May 2019 08:07:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It should call __ceph_dentry_dir_lease_touch() under dentry->d_lock. Besides, ceph_dentry(dentry) can be NULL when called by LOOKUP_RCU d_revalidate() Cc: stable@vger.kernel.org # v5.1+ Signed-off-by: "Yan, Zheng" --- fs/ceph/dir.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 0637149fb9f9..1271024a3797 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -1512,18 +1512,26 @@ static int __dir_lease_try_check(const struct dentry *dentry) static int dir_lease_is_valid(struct inode *dir, struct dentry *dentry) { struct ceph_inode_info *ci = ceph_inode(dir); - struct ceph_dentry_info *di = ceph_dentry(dentry); - int valid = 0; + int valid; + int shared_gen; spin_lock(&ci->i_ceph_lock); - if (atomic_read(&ci->i_shared_gen) == di->lease_shared_gen) - valid = __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1); + valid = __ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1); + shared_gen = atomic_read(&ci->i_shared_gen); spin_unlock(&ci->i_ceph_lock); - if (valid) - __ceph_dentry_dir_lease_touch(di); - dout("dir_lease_is_valid dir %p v%u dentry %p v%u = %d\n", - dir, (unsigned)atomic_read(&ci->i_shared_gen), - dentry, (unsigned)di->lease_shared_gen, valid); + if (valid) { + struct ceph_dentry_info *di; + spin_lock(&dentry->d_lock); + di = ceph_dentry(dentry); + if (dir == d_inode(dentry->d_parent) && + di && di->lease_shared_gen == shared_gen) + __ceph_dentry_dir_lease_touch(di); + else + valid = 0; + spin_unlock(&dentry->d_lock); + } + dout("dir_lease_is_valid dir %p v%u dentry %p = %d\n", + dir, (unsigned)atomic_read(&ci->i_shared_gen), dentry, valid); return valid; } -- 2.17.2