ceph: don't skip updating wanted caps when cap is stale
authorYan, Zheng <zyan@redhat.com>
Tue, 10 Mar 2020 11:34:20 +0000 (19:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 2 May 2020 15:23:03 +0000 (17:23 +0200)
[ Upstream commit 0aa971b6fd3f92afef6afe24ef78d9bb14471519 ]

1. try_get_cap_refs() fails to get caps and finds that mds_wanted
   does not include what it wants. It returns -ESTALE.
2. ceph_get_caps() calls ceph_renew_caps(). ceph_renew_caps() finds
   that inode has cap, so it calls ceph_check_caps().
3. ceph_check_caps() finds that issued caps (without checking if it's
   stale) already includes caps wanted by open file, so it skips
   updating wanted caps.

Above events can cause an infinite loop inside ceph_get_caps().

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ceph/caps.c

index f5d9835264aa16f863b2fbd2021e620486f2fcf4..617e9ae67f5067a86f49274158a29ccd3b35a1ee 100644 (file)
@@ -1764,8 +1764,12 @@ retry_locked:
                }
 
                /* want more caps from mds? */
-               if (want & ~(cap->mds_wanted | cap->issued))
-                       goto ack;
+               if (want & ~cap->mds_wanted) {
+                       if (want & ~(cap->mds_wanted | cap->issued))
+                               goto ack;
+                       if (!__cap_is_valid(cap))
+                               goto ack;
+               }
 
                /* things we might delay */
                if ((cap->issued & ~retain) == 0 &&