Skip to content

Commit

Permalink
ceph: quota: cache inode pointer in ceph_snap_realm
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: "Yan, Zheng" <[email protected]>
Signed-off-by: Ilya Dryomov <[email protected]>
  • Loading branch information
Luis Henriques authored and idryomov committed Apr 2, 2018
1 parent 0eb6bbe commit e3161f1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
4 changes: 3 additions & 1 deletion fs/ceph/caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,11 @@ void ceph_add_cap(struct inode *inode,
}

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);

if (oldrealm)
Expand Down
3 changes: 3 additions & 0 deletions fs/ceph/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ void ceph_destroy_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);
}
Expand Down
24 changes: 10 additions & 14 deletions fs/ceph/quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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;

Expand All @@ -97,13 +96,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_quota(ci);
iput(in);
Expand Down Expand Up @@ -161,7 +159,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;
Expand All @@ -177,13 +174,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) {
Expand Down
2 changes: 2 additions & 0 deletions fs/ceph/snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,8 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc,
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);

spin_unlock(&ci->i_ceph_lock);
Expand Down
1 change: 1 addition & 0 deletions fs/ceph/super.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ struct ceph_readdir_cache_control {
*/
struct ceph_snap_realm {
u64 ino;
struct inode *inode;
atomic_t nref;
struct rb_node node;

Expand Down

0 comments on commit e3161f1

Please sign in to comment.