From caf9c97ff96a7360bf15c976bbf2f7a406dc65a7 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Thu, 22 Nov 2018 15:55:12 +0800 Subject: [PATCH] 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) --- src/client/Client.cc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 466ed13ad4695..b792f675cfdeb 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -3436,23 +3436,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) << __func__ << " on " << *in -- 2.39.5