Skip to content

Commit 56bc3b2

Browse files
karstengrdavem330
authored andcommitted
net/smc: assign link to a new connection
For new connections, assign a link from the link group, using some simple load balancing. Signed-off-by: Karsten Graul <[email protected]> Reviewed-by: Ursula Braun <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f3811fd commit 56bc3b2

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

net/smc/smc_core.c

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,59 @@ static void smc_lgr_add_alert_token(struct smc_connection *conn)
121121
rb_insert_color(&conn->alert_node, &conn->lgr->conns_all);
122122
}
123123

124+
/* assign an SMC-R link to the connection */
125+
static int smcr_lgr_conn_assign_link(struct smc_connection *conn, bool first)
126+
{
127+
enum smc_link_state expected = first ? SMC_LNK_ACTIVATING :
128+
SMC_LNK_ACTIVE;
129+
int i, j;
130+
131+
/* do link balancing */
132+
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
133+
struct smc_link *lnk = &conn->lgr->lnk[i];
134+
135+
if (lnk->state != expected)
136+
continue;
137+
if (conn->lgr->role == SMC_CLNT) {
138+
conn->lnk = lnk; /* temporary, SMC server assigns link*/
139+
break;
140+
}
141+
if (conn->lgr->conns_num % 2) {
142+
for (j = i + 1; j < SMC_LINKS_PER_LGR_MAX; j++) {
143+
struct smc_link *lnk2;
144+
145+
lnk2 = &conn->lgr->lnk[j];
146+
if (lnk2->state == expected) {
147+
conn->lnk = lnk2;
148+
break;
149+
}
150+
}
151+
}
152+
if (!conn->lnk)
153+
conn->lnk = lnk;
154+
break;
155+
}
156+
if (!conn->lnk)
157+
return SMC_CLC_DECL_NOACTLINK;
158+
return 0;
159+
}
160+
124161
/* Register connection in link group by assigning an alert token
125162
* registered in a search tree.
126163
* Requires @conns_lock
127164
* Note that '0' is a reserved value and not assigned.
128165
*/
129-
static int smc_lgr_register_conn(struct smc_connection *conn)
166+
static int smc_lgr_register_conn(struct smc_connection *conn, bool first)
130167
{
131168
struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
132169
static atomic_t nexttoken = ATOMIC_INIT(0);
170+
int rc;
133171

172+
if (!conn->lgr->is_smcd) {
173+
rc = smcr_lgr_conn_assign_link(conn, first);
174+
if (rc)
175+
return rc;
176+
}
134177
/* find a new alert_token_local value not yet used by some connection
135178
* in this link group
136179
*/
@@ -141,22 +184,6 @@ static int smc_lgr_register_conn(struct smc_connection *conn)
141184
conn->alert_token_local = 0;
142185
}
143186
smc_lgr_add_alert_token(conn);
144-
145-
/* assign the new connection to a link */
146-
if (!conn->lgr->is_smcd) {
147-
struct smc_link *lnk;
148-
int i;
149-
150-
/* tbd - link balancing */
151-
for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) {
152-
lnk = &conn->lgr->lnk[i];
153-
if (lnk->state == SMC_LNK_ACTIVATING ||
154-
lnk->state == SMC_LNK_ACTIVE)
155-
conn->lnk = lnk;
156-
}
157-
if (!conn->lnk)
158-
return SMC_CLC_DECL_NOACTLINK;
159-
}
160187
conn->lgr->conns_num++;
161188
return 0;
162189
}
@@ -1285,7 +1312,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
12851312
/* link group found */
12861313
ini->cln_first_contact = SMC_REUSE_CONTACT;
12871314
conn->lgr = lgr;
1288-
rc = smc_lgr_register_conn(conn); /* add conn to lgr */
1315+
rc = smc_lgr_register_conn(conn, false);
12891316
write_unlock_bh(&lgr->conns_lock);
12901317
if (!rc && delayed_work_pending(&lgr->free_work))
12911318
cancel_delayed_work(&lgr->free_work);
@@ -1313,7 +1340,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
13131340
goto out;
13141341
lgr = conn->lgr;
13151342
write_lock_bh(&lgr->conns_lock);
1316-
rc = smc_lgr_register_conn(conn); /* add smc conn to lgr */
1343+
rc = smc_lgr_register_conn(conn, true);
13171344
write_unlock_bh(&lgr->conns_lock);
13181345
if (rc)
13191346
goto out;

0 commit comments

Comments
 (0)