Skip to content

Commit a2351c5

Browse files
Ursula BraunJakub Kicinski
Ursula Braun
authored and
Jakub Kicinski
committed
net/smc: separate SMCD and SMCR link group lists
Currently SMCD and SMCR link groups are maintained in one list. To facilitate abnormal termination handling they are split into a separate list for SMCR link groups and separate lists for SMCD link groups per SMCD device. Signed-off-by: Ursula Braun <[email protected]> Signed-off-by: Karsten Graul <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0ea1671 commit a2351c5

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

include/net/smc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct smcd_dev {
7575
struct workqueue_struct *event_wq;
7676
u8 pnetid[SMC_MAX_PNETID_LEN];
7777
bool pnetid_by_user;
78+
struct list_head lgr_list;
7879
};
7980

8081
struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,

net/smc/smc_core.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ static void smc_lgr_free_work(struct work_struct *work)
198198
static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
199199
{
200200
struct smc_link_group *lgr;
201+
struct list_head *lgr_list;
201202
struct smc_link *lnk;
202203
u8 rndvec[3];
203204
int rc = 0;
@@ -233,6 +234,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
233234
/* SMC-D specific settings */
234235
lgr->peer_gid = ini->ism_gid;
235236
lgr->smcd = ini->ism_dev;
237+
lgr_list = &ini->ism_dev->lgr_list;
236238
} else {
237239
/* SMC-R specific settings */
238240
lgr->role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
@@ -245,6 +247,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
245247
lnk->link_id = SMC_SINGLE_LINK;
246248
lnk->smcibdev = ini->ib_dev;
247249
lnk->ibport = ini->ib_port;
250+
lgr_list = &smc_lgr_list.list;
248251
lnk->path_mtu =
249252
ini->ib_dev->pattr[ini->ib_port - 1].active_mtu;
250253
if (!ini->ib_dev->initialized)
@@ -275,7 +278,7 @@ static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini)
275278
}
276279
smc->conn.lgr = lgr;
277280
spin_lock_bh(&smc_lgr_list.lock);
278-
list_add(&lgr->list, &smc_lgr_list.list);
281+
list_add(&lgr->list, lgr_list);
279282
spin_unlock_bh(&smc_lgr_list.lock);
280283
return 0;
281284

@@ -512,9 +515,8 @@ void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid, unsigned short vlan)
512515

513516
/* run common cleanup function and build free list */
514517
spin_lock_bh(&smc_lgr_list.lock);
515-
list_for_each_entry_safe(lgr, l, &smc_lgr_list.list, list) {
516-
if (lgr->is_smcd && lgr->smcd == dev &&
517-
(!peer_gid || lgr->peer_gid == peer_gid) &&
518+
list_for_each_entry_safe(lgr, l, &dev->lgr_list, list) {
519+
if ((!peer_gid || lgr->peer_gid == peer_gid) &&
518520
(vlan == VLAN_VID_MASK || lgr->vlan_id == vlan)) {
519521
__smc_lgr_terminate(lgr);
520522
list_move(&lgr->list, &lgr_free_list);
@@ -604,10 +606,12 @@ static bool smcd_lgr_match(struct smc_link_group *lgr,
604606
int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
605607
{
606608
struct smc_connection *conn = &smc->conn;
609+
struct list_head *lgr_list;
607610
struct smc_link_group *lgr;
608611
enum smc_lgr_role role;
609612
int rc = 0;
610613

614+
lgr_list = ini->is_smcd ? &ini->ism_dev->lgr_list : &smc_lgr_list.list;
611615
ini->cln_first_contact = SMC_FIRST_CONTACT;
612616
role = smc->listen_smc ? SMC_SERV : SMC_CLNT;
613617
if (role == SMC_CLNT && ini->srv_first_contact)
@@ -616,7 +620,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
616620

617621
/* determine if an existing link group can be reused */
618622
spin_lock_bh(&smc_lgr_list.lock);
619-
list_for_each_entry(lgr, &smc_lgr_list.list, list) {
623+
list_for_each_entry(lgr, lgr_list, list) {
620624
write_lock_bh(&lgr->conns_lock);
621625
if ((ini->is_smcd ?
622626
smcd_lgr_match(lgr, ini->ism_dev, ini->ism_gid) :
@@ -1029,11 +1033,17 @@ void smc_core_exit(void)
10291033
{
10301034
struct smc_link_group *lgr, *lg;
10311035
LIST_HEAD(lgr_freeing_list);
1036+
struct smcd_dev *smcd;
10321037

10331038
spin_lock_bh(&smc_lgr_list.lock);
1034-
if (!list_empty(&smc_lgr_list.list))
1035-
list_splice_init(&smc_lgr_list.list, &lgr_freeing_list);
1039+
list_splice_init(&smc_lgr_list.list, &lgr_freeing_list);
10361040
spin_unlock_bh(&smc_lgr_list.lock);
1041+
1042+
spin_lock(&smcd_dev_list.lock);
1043+
list_for_each_entry(smcd, &smcd_dev_list.list, list)
1044+
list_splice_init(&smcd->lgr_list, &lgr_freeing_list);
1045+
spin_unlock(&smcd_dev_list.lock);
1046+
10371047
list_for_each_entry_safe(lgr, lg, &lgr_freeing_list, list) {
10381048
list_del_init(&lgr->list);
10391049
if (!lgr->is_smcd) {

net/smc/smc_ism.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ struct smcd_dev *smcd_alloc_dev(struct device *parent, const char *name,
287287

288288
spin_lock_init(&smcd->lock);
289289
INIT_LIST_HEAD(&smcd->vlan);
290+
INIT_LIST_HEAD(&smcd->lgr_list);
290291
smcd->event_wq = alloc_ordered_workqueue("ism_evt_wq-%s)",
291292
WQ_MEM_RECLAIM, name);
292293
if (!smcd->event_wq) {

0 commit comments

Comments
 (0)