@@ -121,16 +121,59 @@ static void smc_lgr_add_alert_token(struct smc_connection *conn)
121
121
rb_insert_color (& conn -> alert_node , & conn -> lgr -> conns_all );
122
122
}
123
123
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
+
124
161
/* Register connection in link group by assigning an alert token
125
162
* registered in a search tree.
126
163
* Requires @conns_lock
127
164
* Note that '0' is a reserved value and not assigned.
128
165
*/
129
- static int smc_lgr_register_conn (struct smc_connection * conn )
166
+ static int smc_lgr_register_conn (struct smc_connection * conn , bool first )
130
167
{
131
168
struct smc_sock * smc = container_of (conn , struct smc_sock , conn );
132
169
static atomic_t nexttoken = ATOMIC_INIT (0 );
170
+ int rc ;
133
171
172
+ if (!conn -> lgr -> is_smcd ) {
173
+ rc = smcr_lgr_conn_assign_link (conn , first );
174
+ if (rc )
175
+ return rc ;
176
+ }
134
177
/* find a new alert_token_local value not yet used by some connection
135
178
* in this link group
136
179
*/
@@ -141,22 +184,6 @@ static int smc_lgr_register_conn(struct smc_connection *conn)
141
184
conn -> alert_token_local = 0 ;
142
185
}
143
186
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
- }
160
187
conn -> lgr -> conns_num ++ ;
161
188
return 0 ;
162
189
}
@@ -1285,7 +1312,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
1285
1312
/* link group found */
1286
1313
ini -> cln_first_contact = SMC_REUSE_CONTACT ;
1287
1314
conn -> lgr = lgr ;
1288
- rc = smc_lgr_register_conn (conn ); /* add conn to lgr */
1315
+ rc = smc_lgr_register_conn (conn , false);
1289
1316
write_unlock_bh (& lgr -> conns_lock );
1290
1317
if (!rc && delayed_work_pending (& lgr -> free_work ))
1291
1318
cancel_delayed_work (& lgr -> free_work );
@@ -1313,7 +1340,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
1313
1340
goto out ;
1314
1341
lgr = conn -> lgr ;
1315
1342
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);
1317
1344
write_unlock_bh (& lgr -> conns_lock );
1318
1345
if (rc )
1319
1346
goto out ;
0 commit comments