Commit e228a5d0 authored by Ka-Cheong Poon's avatar Ka-Cheong Poon Committed by David S. Miller

net/rds: Replace struct rds_mr's r_refcount with struct kref

And removed rds_mr_put().
Signed-off-by: default avatarKa-Cheong Poon <ka-cheong.poon@oracle.com>
Acked-by: default avatarSantosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 022e9d60
/* /*
* Copyright (c) 2006 Oracle. All rights reserved. * Copyright (c) 2006, 2020 Oracle and/or its affiliates.
* *
* This software is available to you under a choice of one of two * This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU * licenses. You may choose to be licensed under the terms of the GNU
...@@ -162,12 +162,12 @@ static void rds_message_purge(struct rds_message *rm) ...@@ -162,12 +162,12 @@ static void rds_message_purge(struct rds_message *rm)
if (rm->rdma.op_active) if (rm->rdma.op_active)
rds_rdma_free_op(&rm->rdma); rds_rdma_free_op(&rm->rdma);
if (rm->rdma.op_rdma_mr) if (rm->rdma.op_rdma_mr)
rds_mr_put(rm->rdma.op_rdma_mr); kref_put(&rm->rdma.op_rdma_mr->r_kref, __rds_put_mr_final);
if (rm->atomic.op_active) if (rm->atomic.op_active)
rds_atomic_free_op(&rm->atomic); rds_atomic_free_op(&rm->atomic);
if (rm->atomic.op_rdma_mr) if (rm->atomic.op_rdma_mr)
rds_mr_put(rm->atomic.op_rdma_mr); kref_put(&rm->atomic.op_rdma_mr->r_kref, __rds_put_mr_final);
} }
void rds_message_put(struct rds_message *rm) void rds_message_put(struct rds_message *rm)
......
/* /*
* Copyright (c) 2007, 2017 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2020 Oracle and/or its affiliates.
* *
* This software is available to you under a choice of one of two * This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU * licenses. You may choose to be licensed under the terms of the GNU
...@@ -84,7 +84,7 @@ static struct rds_mr *rds_mr_tree_walk(struct rb_root *root, u64 key, ...@@ -84,7 +84,7 @@ static struct rds_mr *rds_mr_tree_walk(struct rb_root *root, u64 key,
if (insert) { if (insert) {
rb_link_node(&insert->r_rb_node, parent, p); rb_link_node(&insert->r_rb_node, parent, p);
rb_insert_color(&insert->r_rb_node, root); rb_insert_color(&insert->r_rb_node, root);
refcount_inc(&insert->r_refcount); kref_get(&insert->r_kref);
} }
return NULL; return NULL;
} }
...@@ -99,7 +99,7 @@ static void rds_destroy_mr(struct rds_mr *mr) ...@@ -99,7 +99,7 @@ static void rds_destroy_mr(struct rds_mr *mr)
unsigned long flags; unsigned long flags;
rdsdebug("RDS: destroy mr key is %x refcnt %u\n", rdsdebug("RDS: destroy mr key is %x refcnt %u\n",
mr->r_key, refcount_read(&mr->r_refcount)); mr->r_key, kref_read(&mr->r_kref));
if (test_and_set_bit(RDS_MR_DEAD, &mr->r_state)) if (test_and_set_bit(RDS_MR_DEAD, &mr->r_state))
return; return;
...@@ -115,8 +115,10 @@ static void rds_destroy_mr(struct rds_mr *mr) ...@@ -115,8 +115,10 @@ static void rds_destroy_mr(struct rds_mr *mr)
mr->r_trans->free_mr(trans_private, mr->r_invalidate); mr->r_trans->free_mr(trans_private, mr->r_invalidate);
} }
void __rds_put_mr_final(struct rds_mr *mr) void __rds_put_mr_final(struct kref *kref)
{ {
struct rds_mr *mr = container_of(kref, struct rds_mr, r_kref);
rds_destroy_mr(mr); rds_destroy_mr(mr);
kfree(mr); kfree(mr);
} }
...@@ -141,7 +143,7 @@ void rds_rdma_drop_keys(struct rds_sock *rs) ...@@ -141,7 +143,7 @@ void rds_rdma_drop_keys(struct rds_sock *rs)
RB_CLEAR_NODE(&mr->r_rb_node); RB_CLEAR_NODE(&mr->r_rb_node);
spin_unlock_irqrestore(&rs->rs_rdma_lock, flags); spin_unlock_irqrestore(&rs->rs_rdma_lock, flags);
rds_destroy_mr(mr); rds_destroy_mr(mr);
rds_mr_put(mr); kref_put(&mr->r_kref, __rds_put_mr_final);
spin_lock_irqsave(&rs->rs_rdma_lock, flags); spin_lock_irqsave(&rs->rs_rdma_lock, flags);
} }
spin_unlock_irqrestore(&rs->rs_rdma_lock, flags); spin_unlock_irqrestore(&rs->rs_rdma_lock, flags);
...@@ -242,7 +244,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args, ...@@ -242,7 +244,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args,
goto out; goto out;
} }
refcount_set(&mr->r_refcount, 1); kref_init(&mr->r_kref);
RB_CLEAR_NODE(&mr->r_rb_node); RB_CLEAR_NODE(&mr->r_rb_node);
mr->r_trans = rs->rs_transport; mr->r_trans = rs->rs_transport;
mr->r_sock = rs; mr->r_sock = rs;
...@@ -343,7 +345,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args, ...@@ -343,7 +345,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args,
rdsdebug("RDS: get_mr key is %x\n", mr->r_key); rdsdebug("RDS: get_mr key is %x\n", mr->r_key);
if (mr_ret) { if (mr_ret) {
refcount_inc(&mr->r_refcount); kref_get(&mr->r_kref);
*mr_ret = mr; *mr_ret = mr;
} }
...@@ -351,7 +353,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args, ...@@ -351,7 +353,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args,
out: out:
kfree(pages); kfree(pages);
if (mr) if (mr)
rds_mr_put(mr); kref_put(&mr->r_kref, __rds_put_mr_final);
return ret; return ret;
} }
...@@ -440,7 +442,7 @@ int rds_free_mr(struct rds_sock *rs, char __user *optval, int optlen) ...@@ -440,7 +442,7 @@ int rds_free_mr(struct rds_sock *rs, char __user *optval, int optlen)
* someone else drops their ref. * someone else drops their ref.
*/ */
rds_destroy_mr(mr); rds_destroy_mr(mr);
rds_mr_put(mr); kref_put(&mr->r_kref, __rds_put_mr_final);
return 0; return 0;
} }
...@@ -481,7 +483,7 @@ void rds_rdma_unuse(struct rds_sock *rs, u32 r_key, int force) ...@@ -481,7 +483,7 @@ void rds_rdma_unuse(struct rds_sock *rs, u32 r_key, int force)
* trigger an async flush. */ * trigger an async flush. */
if (zot_me) { if (zot_me) {
rds_destroy_mr(mr); rds_destroy_mr(mr);
rds_mr_put(mr); kref_put(&mr->r_kref, __rds_put_mr_final);
} }
} }
...@@ -490,7 +492,7 @@ void rds_rdma_free_op(struct rm_rdma_op *ro) ...@@ -490,7 +492,7 @@ void rds_rdma_free_op(struct rm_rdma_op *ro)
unsigned int i; unsigned int i;
if (ro->op_odp_mr) { if (ro->op_odp_mr) {
rds_mr_put(ro->op_odp_mr); kref_put(&ro->op_odp_mr->r_kref, __rds_put_mr_final);
} else { } else {
for (i = 0; i < ro->op_nents; i++) { for (i = 0; i < ro->op_nents; i++) {
struct page *page = sg_page(&ro->op_sg[i]); struct page *page = sg_page(&ro->op_sg[i]);
...@@ -730,7 +732,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm, ...@@ -730,7 +732,7 @@ int rds_cmsg_rdma_args(struct rds_sock *rs, struct rds_message *rm,
goto out_pages; goto out_pages;
} }
RB_CLEAR_NODE(&local_odp_mr->r_rb_node); RB_CLEAR_NODE(&local_odp_mr->r_rb_node);
refcount_set(&local_odp_mr->r_refcount, 1); kref_init(&local_odp_mr->r_kref);
local_odp_mr->r_trans = rs->rs_transport; local_odp_mr->r_trans = rs->rs_transport;
local_odp_mr->r_sock = rs; local_odp_mr->r_sock = rs;
local_odp_mr->r_trans_private = local_odp_mr->r_trans_private =
...@@ -827,7 +829,7 @@ int rds_cmsg_rdma_dest(struct rds_sock *rs, struct rds_message *rm, ...@@ -827,7 +829,7 @@ int rds_cmsg_rdma_dest(struct rds_sock *rs, struct rds_message *rm,
if (!mr) if (!mr)
err = -EINVAL; /* invalid r_key */ err = -EINVAL; /* invalid r_key */
else else
refcount_inc(&mr->r_refcount); kref_get(&mr->r_kref);
spin_unlock_irqrestore(&rs->rs_rdma_lock, flags); spin_unlock_irqrestore(&rs->rs_rdma_lock, flags);
if (mr) { if (mr) {
......
...@@ -291,7 +291,7 @@ struct rds_incoming { ...@@ -291,7 +291,7 @@ struct rds_incoming {
struct rds_mr { struct rds_mr {
struct rb_node r_rb_node; struct rb_node r_rb_node;
refcount_t r_refcount; struct kref r_kref;
u32 r_key; u32 r_key;
/* A copy of the creation flags */ /* A copy of the creation flags */
...@@ -946,12 +946,7 @@ void rds_atomic_send_complete(struct rds_message *rm, int wc_status); ...@@ -946,12 +946,7 @@ void rds_atomic_send_complete(struct rds_message *rm, int wc_status);
int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm, int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm,
struct cmsghdr *cmsg); struct cmsghdr *cmsg);
void __rds_put_mr_final(struct rds_mr *mr); void __rds_put_mr_final(struct kref *kref);
static inline void rds_mr_put(struct rds_mr *mr)
{
if (refcount_dec_and_test(&mr->r_refcount))
__rds_put_mr_final(mr);
}
static inline bool rds_destroy_pending(struct rds_connection *conn) static inline bool rds_destroy_pending(struct rds_connection *conn)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment