From: Yan, Zheng Date: Thu, 22 Nov 2018 07:55:12 +0000 (+0800) Subject: client: sync 'retain caps' logical from kernel client X-Git-Tag: v12.2.12~111^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ecd0a5ac43634f6cfd0476879d36ae487ba43cb5;p=ceph.git client: sync 'retain caps' logical from kernel client The main change is keeping CEPH_CAP_ANY_RD for unused file inodes Signed-off-by: "Yan, Zheng" (cherry picked from commit 29034396398b1706db625e1abf2e6682be7130a5) --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 9f78b24a5f8..324c468edef 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -3424,23 +3424,30 @@ void Client::check_caps(Inode *in, unsigned flags) unsigned used = get_caps_used(in); unsigned cap_used; - if (in->is_dir() && (in->flags & I_COMPLETE)) { - // we do this here because we don't want to drop to Fs (and then - // drop the Fs if we do a create!) if that alone makes us send lookups - // to the MDS. Doing it in in->caps_wanted() has knock-on effects elsewhere - wanted |= CEPH_CAP_FILE_EXCL; - } - int implemented; int issued = in->caps_issued(&implemented); int revoking = implemented & ~issued; int retain = wanted | used | CEPH_CAP_PIN; - if (!unmounting) { - if (wanted) + if (!unmounting && in->nlink > 0) { + if (wanted) { retain |= CEPH_CAP_ANY; - else + } else if (in->is_dir() && + (issued & CEPH_CAP_FILE_SHARED) && + (in->flags & I_COMPLETE)) { + // we do this here because we don't want to drop to Fs (and then + // drop the Fs if we do a create!) if that alone makes us send lookups + // to the MDS. Doing it in in->caps_wanted() has knock-on effects elsewhere + wanted = CEPH_CAP_ANY_SHARED | CEPH_CAP_FILE_EXCL; + retain |= wanted; + } else { retain |= CEPH_CAP_ANY_SHARED; + // keep RD only if we didn't have the file open RW, + // because then the mds would revoke it anyway to + // journal max_size=0. + if (in->max_size == 0) + retain |= CEPH_CAP_ANY_RD; + } } ldout(cct, 10) << "check_caps on " << *in