Commit cb24405e authored by Andy Grover's avatar Andy Grover Committed by David S. Miller

RDS: Refactor end of __conn_create for readability

Add a comment for what's going on. Remove negative logic.
I find this much easier to understand quickly, although
there are a few lines duplicated.
Signed-off-by: default avatarAndy Grover <andy.grover@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ed9e352a
...@@ -126,7 +126,7 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr, ...@@ -126,7 +126,7 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
struct rds_transport *trans, gfp_t gfp, struct rds_transport *trans, gfp_t gfp,
int is_outgoing) int is_outgoing)
{ {
struct rds_connection *conn, *tmp, *parent = NULL; struct rds_connection *conn, *parent = NULL;
struct hlist_head *head = rds_conn_bucket(laddr, faddr); struct hlist_head *head = rds_conn_bucket(laddr, faddr);
unsigned long flags; unsigned long flags;
int ret; int ret;
...@@ -210,26 +210,40 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr, ...@@ -210,26 +210,40 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
trans->t_name ? trans->t_name : "[unknown]", trans->t_name ? trans->t_name : "[unknown]",
is_outgoing ? "(outgoing)" : ""); is_outgoing ? "(outgoing)" : "");
/*
* Since we ran without holding the conn lock, someone could
* have created the same conn (either normal or passive) in the
* interim. We check while holding the lock. If we won, we complete
* init and return our conn. If we lost, we rollback and return the
* other one.
*/
spin_lock_irqsave(&rds_conn_lock, flags); spin_lock_irqsave(&rds_conn_lock, flags);
if (parent == NULL) { if (parent) {
tmp = rds_conn_lookup(head, laddr, faddr, trans); /* Creating passive conn */
if (tmp == NULL) if (parent->c_passive) {
hlist_add_head(&conn->c_hash_node, head); trans->conn_free(conn->c_transport_data);
} else { kmem_cache_free(rds_conn_slab, conn);
tmp = parent->c_passive; conn = parent->c_passive;
if (!tmp) } else {
parent->c_passive = conn; parent->c_passive = conn;
} rds_cong_add_conn(conn);
rds_conn_count++;
if (tmp) { }
trans->conn_free(conn->c_transport_data);
kmem_cache_free(rds_conn_slab, conn);
conn = tmp;
} else { } else {
rds_cong_add_conn(conn); /* Creating normal conn */
rds_conn_count++; struct rds_connection *found;
found = rds_conn_lookup(head, laddr, faddr, trans);
if (found) {
trans->conn_free(conn->c_transport_data);
kmem_cache_free(rds_conn_slab, conn);
conn = found;
} else {
hlist_add_head(&conn->c_hash_node, head);
rds_cong_add_conn(conn);
rds_conn_count++;
}
} }
spin_unlock_irqrestore(&rds_conn_lock, flags); spin_unlock_irqrestore(&rds_conn_lock, flags);
out: out:
......
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