[bionic:linux][PATCH 2/2] ceph: quota: cache inode pointer in ceph_snap_realm
Marcelo Henrique Cerri
marcelo.cerri at canonical.com
Wed May 13 16:21:49 UTC 2020
From: Luis Henriques <lhenriques at suse.com>
BugLink: https://bugs.launchpad.net/bugs/1875884
Keep a pointer to the inode in struct ceph_snap_realm. This allows to
optimize functions that walk the realms hierarchy (e.g. in quotas).
Signed-off-by: Luis Henriques <lhenriques at suse.com>
Reviewed-by: "Yan, Zheng" <zyan at redhat.com>
Signed-off-by: Ilya Dryomov <idryomov at gmail.com>
(cherry picked from commit e3161f17d92699ce6ca3b7988131b10ad4035cf9)
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri at canonical.com>
---
fs/ceph/caps.c | 4 +++-
fs/ceph/inode.c | 3 +++
fs/ceph/quota.c | 24 ++++++++++--------------
fs/ceph/snap.c | 2 ++
fs/ceph/super.h | 1 +
5 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 0a6dc9b5a530..60a87710193f 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -585,9 +585,11 @@ void ceph_add_cap(struct inode *inode,
realmino);
if (realm) {
spin_lock(&realm->inodes_with_caps_lock);
- ci->i_snap_realm = realm;
list_add(&ci->i_snap_realm_item,
&realm->inodes_with_caps);
+ ci->i_snap_realm = realm;
+ if (realm->ino == ci->i_vino.ino)
+ realm->inode = inode;
spin_unlock(&realm->inodes_with_caps_lock);
} else {
pr_err("ceph_add_cap: couldn't find snap realm %llx\n",
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 7b101a98b812..0d8b039f5805 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -554,6 +554,9 @@ void ceph_evict_inode(struct inode *inode)
dout(" dropping residual ref to snap realm %p\n", realm);
spin_lock(&realm->inodes_with_caps_lock);
list_del_init(&ci->i_snap_realm_item);
+ ci->i_snap_realm = NULL;
+ if (realm->ino == ci->i_vino.ino)
+ realm->inode = NULL;
spin_unlock(&realm->inodes_with_caps_lock);
ceph_put_snap_realm(mdsc, realm);
}
diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c
index e1eb95545feb..2cd727ebb87f 100644
--- a/fs/ceph/quota.c
+++ b/fs/ceph/quota.c
@@ -94,7 +94,6 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
{
struct ceph_inode_info *ci = NULL;
struct ceph_snap_realm *realm, *next;
- struct ceph_vino vino;
struct inode *in;
bool has_quota;
@@ -108,13 +107,12 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc,
pr_err_ratelimited("get_quota_realm: ino (%llx.%llx) "
"null i_snap_realm\n", ceph_vinop(inode));
while (realm) {
- vino.ino = realm->ino;
- vino.snap = CEPH_NOSNAP;
- in = ceph_find_inode(inode->i_sb, vino);
- if (!in) {
- pr_warn("Failed to find inode for %llu\n", vino.ino);
+ spin_lock(&realm->inodes_with_caps_lock);
+ in = realm->inode ? igrab(realm->inode) : NULL;
+ spin_unlock(&realm->inodes_with_caps_lock);
+ if (!in)
break;
- }
+
ci = ceph_inode(in);
has_quota = __ceph_has_any_quota(ci);
/* avoid calling iput_final() while holding mdsc->snap_rwsem */
@@ -173,7 +171,6 @@ static bool check_quota_exceeded(struct inode *inode, enum quota_check_op op,
struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
struct ceph_inode_info *ci;
struct ceph_snap_realm *realm, *next;
- struct ceph_vino vino;
struct inode *in;
u64 max, rvalue;
bool exceeded = false;
@@ -189,13 +186,12 @@ static bool check_quota_exceeded(struct inode *inode, enum quota_check_op op,
pr_err_ratelimited("check_quota_exceeded: ino (%llx.%llx) "
"null i_snap_realm\n", ceph_vinop(inode));
while (realm) {
- vino.ino = realm->ino;
- vino.snap = CEPH_NOSNAP;
- in = ceph_find_inode(inode->i_sb, vino);
- if (!in) {
- pr_warn("Failed to find inode for %llu\n", vino.ino);
+ spin_lock(&realm->inodes_with_caps_lock);
+ in = realm->inode ? igrab(realm->inode) : NULL;
+ spin_unlock(&realm->inodes_with_caps_lock);
+ if (!in)
break;
- }
+
ci = ceph_inode(in);
spin_lock(&ci->i_ceph_lock);
if (op == QUOTA_CHECK_MAX_FILES_OP) {
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index 036d535711c4..fbea7002ad82 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -940,6 +940,8 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
&realm->inodes_with_caps);
oldrealm = ci->i_snap_realm;
ci->i_snap_realm = realm;
+ if (realm->ino == ci->i_vino.ino)
+ realm->inode = inode;
spin_unlock(&realm->inodes_with_caps_lock);
spin_unlock(&ci->i_ceph_lock);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index ede462616680..cf16e0dc2f93 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -761,6 +761,7 @@ struct ceph_readdir_cache_control {
*/
struct ceph_snap_realm {
u64 ino;
+ struct inode *inode;
atomic_t nref;
struct rb_node node;
--
2.25.1
More information about the kernel-team
mailing list