Skip to content

Commit 1180347

Browse files
author
Mete Durlu
committed
net/smc: unify the structs of accept or confirm message for v1 and v2
JIRA: https://issues.redhat.com/browse/RHEL-73484 commit 9505450 Author: Wen Gu <guwen@linux.alibaba.com> Date: Tue Dec 19 22:26:09 2023 +0800 net/smc: unify the structs of accept or confirm message for v1 and v2 The structs of CLC accept and confirm messages for SMCv1 and SMCv2 are separately defined and often casted to each other in the code, which may increase the risk of errors caused by future divergence of them. So unify them into one struct for better maintainability. Suggested-by: Alexandra Winter <wintera@linux.ibm.com> Signed-off-by: Wen Gu <guwen@linux.alibaba.com> Reviewed-by: Alexandra Winter <wintera@linux.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Mete Durlu <mdurlu@redhat.com>
1 parent c0db56c commit 1180347

File tree

3 files changed

+62
-97
lines changed

3 files changed

+62
-97
lines changed

net/smc/af_smc.c

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,6 @@ static bool smc_isascii(char *hostname)
646646
static void smc_conn_save_peer_info_fce(struct smc_sock *smc,
647647
struct smc_clc_msg_accept_confirm *clc)
648648
{
649-
struct smc_clc_msg_accept_confirm_v2 *clc_v2 =
650-
(struct smc_clc_msg_accept_confirm_v2 *)clc;
651649
struct smc_clc_first_contact_ext *fce;
652650
int clc_v2_len;
653651

@@ -656,17 +654,15 @@ static void smc_conn_save_peer_info_fce(struct smc_sock *smc,
656654
return;
657655

658656
if (smc->conn.lgr->is_smcd) {
659-
memcpy(smc->conn.lgr->negotiated_eid, clc_v2->d1.eid,
657+
memcpy(smc->conn.lgr->negotiated_eid, clc->d1.eid,
660658
SMC_MAX_EID_LEN);
661-
clc_v2_len = offsetofend(struct smc_clc_msg_accept_confirm_v2,
662-
d1);
659+
clc_v2_len = offsetofend(struct smc_clc_msg_accept_confirm, d1);
663660
} else {
664-
memcpy(smc->conn.lgr->negotiated_eid, clc_v2->r1.eid,
661+
memcpy(smc->conn.lgr->negotiated_eid, clc->r1.eid,
665662
SMC_MAX_EID_LEN);
666-
clc_v2_len = offsetofend(struct smc_clc_msg_accept_confirm_v2,
667-
r1);
663+
clc_v2_len = offsetofend(struct smc_clc_msg_accept_confirm, r1);
668664
}
669-
fce = (struct smc_clc_first_contact_ext *)(((u8 *)clc_v2) + clc_v2_len);
665+
fce = (struct smc_clc_first_contact_ext *)(((u8 *)clc) + clc_v2_len);
670666
smc->conn.lgr->peer_os = fce->os_type;
671667
smc->conn.lgr->peer_smc_release = fce->release;
672668
if (smc_isascii(fce->hostname))
@@ -1122,13 +1118,13 @@ static int smc_connect_ism_vlan_cleanup(struct smc_sock *smc,
11221118
}
11231119

11241120
#define SMC_CLC_MAX_ACCEPT_LEN \
1125-
(sizeof(struct smc_clc_msg_accept_confirm_v2) + \
1121+
(sizeof(struct smc_clc_msg_accept_confirm) + \
11261122
sizeof(struct smc_clc_first_contact_ext_v2x) + \
11271123
sizeof(struct smc_clc_msg_trail))
11281124

11291125
/* CLC handshake during connect */
11301126
static int smc_connect_clc(struct smc_sock *smc,
1131-
struct smc_clc_msg_accept_confirm_v2 *aclc2,
1127+
struct smc_clc_msg_accept_confirm *aclc,
11321128
struct smc_init_info *ini)
11331129
{
11341130
int rc = 0;
@@ -1138,7 +1134,7 @@ static int smc_connect_clc(struct smc_sock *smc,
11381134
if (rc)
11391135
return rc;
11401136
/* receive SMC Accept CLC message */
1141-
return smc_clc_wait_msg(smc, aclc2, SMC_CLC_MAX_ACCEPT_LEN,
1137+
return smc_clc_wait_msg(smc, aclc, SMC_CLC_MAX_ACCEPT_LEN,
11421138
SMC_CLC_ACCEPT, CLC_WAIT_TIME);
11431139
}
11441140

@@ -1174,10 +1170,8 @@ static int smc_connect_rdma_v2_prepare(struct smc_sock *smc,
11741170
struct smc_clc_msg_accept_confirm *aclc,
11751171
struct smc_init_info *ini)
11761172
{
1177-
struct smc_clc_msg_accept_confirm_v2 *clc_v2 =
1178-
(struct smc_clc_msg_accept_confirm_v2 *)aclc;
11791173
struct smc_clc_first_contact_ext *fce =
1180-
smc_get_clc_first_contact_ext(clc_v2, false);
1174+
smc_get_clc_first_contact_ext(aclc, false);
11811175
struct net *net = sock_net(&smc->sk);
11821176
int rc;
11831177

@@ -1300,10 +1294,7 @@ static int smc_connect_rdma(struct smc_sock *smc,
13001294
}
13011295

13021296
if (aclc->hdr.version > SMC_V1) {
1303-
struct smc_clc_msg_accept_confirm_v2 *clc_v2 =
1304-
(struct smc_clc_msg_accept_confirm_v2 *)aclc;
1305-
1306-
eid = clc_v2->r1.eid;
1297+
eid = aclc->r1.eid;
13071298
if (ini->first_contact_local)
13081299
smc_fill_gid_list(link->lgr, &ini->smcrv2.gidlist,
13091300
link->smcibdev, link->gid);
@@ -1344,7 +1335,7 @@ static int smc_connect_rdma(struct smc_sock *smc,
13441335
* Determine from the CHID of the received CLC ACCEPT the ISM device chosen.
13451336
*/
13461337
static int
1347-
smc_v2_determine_accepted_chid(struct smc_clc_msg_accept_confirm_v2 *aclc,
1338+
smc_v2_determine_accepted_chid(struct smc_clc_msg_accept_confirm *aclc,
13481339
struct smc_init_info *ini)
13491340
{
13501341
int i;
@@ -1371,20 +1362,17 @@ static int smc_connect_ism(struct smc_sock *smc,
13711362
ini->first_contact_peer = aclc->hdr.typev2 & SMC_FIRST_CONTACT_MASK;
13721363

13731364
if (aclc->hdr.version == SMC_V2) {
1374-
struct smc_clc_msg_accept_confirm_v2 *aclc_v2 =
1375-
(struct smc_clc_msg_accept_confirm_v2 *)aclc;
1376-
13771365
if (ini->first_contact_peer) {
13781366
struct smc_clc_first_contact_ext *fce =
1379-
smc_get_clc_first_contact_ext(aclc_v2, true);
1367+
smc_get_clc_first_contact_ext(aclc, true);
13801368

13811369
ini->release_nr = fce->release;
13821370
rc = smc_clc_clnt_v2x_features_validate(fce, ini);
13831371
if (rc)
13841372
return rc;
13851373
}
13861374

1387-
rc = smc_v2_determine_accepted_chid(aclc_v2, ini);
1375+
rc = smc_v2_determine_accepted_chid(aclc, ini);
13881376
if (rc)
13891377
return rc;
13901378
}
@@ -1410,12 +1398,8 @@ static int smc_connect_ism(struct smc_sock *smc,
14101398
smc_rx_init(smc);
14111399
smc_tx_init(smc);
14121400

1413-
if (aclc->hdr.version > SMC_V1) {
1414-
struct smc_clc_msg_accept_confirm_v2 *clc_v2 =
1415-
(struct smc_clc_msg_accept_confirm_v2 *)aclc;
1416-
1417-
eid = clc_v2->d1.eid;
1418-
}
1401+
if (aclc->hdr.version > SMC_V1)
1402+
eid = aclc->d1.eid;
14191403

14201404
rc = smc_clc_send_confirm(smc, ini->first_contact_local,
14211405
aclc->hdr.version, eid, ini);
@@ -1466,7 +1450,6 @@ static int smc_connect_check_aclc(struct smc_init_info *ini,
14661450
static int __smc_connect(struct smc_sock *smc)
14671451
{
14681452
u8 version = smc_ism_is_v2_capable() ? SMC_V2 : SMC_V1;
1469-
struct smc_clc_msg_accept_confirm_v2 *aclc2;
14701453
struct smc_clc_msg_accept_confirm *aclc;
14711454
struct smc_init_info *ini = NULL;
14721455
u8 *buf = NULL;
@@ -1514,11 +1497,10 @@ static int __smc_connect(struct smc_sock *smc)
15141497
rc = SMC_CLC_DECL_MEM;
15151498
goto fallback;
15161499
}
1517-
aclc2 = (struct smc_clc_msg_accept_confirm_v2 *)buf;
1518-
aclc = (struct smc_clc_msg_accept_confirm *)aclc2;
1500+
aclc = (struct smc_clc_msg_accept_confirm *)buf;
15191501

15201502
/* perform CLC handshake */
1521-
rc = smc_connect_clc(smc, aclc2, ini);
1503+
rc = smc_connect_clc(smc, aclc, ini);
15221504
if (rc) {
15231505
/* -EAGAIN on timeout, see tcp_recvmsg() */
15241506
if (rc == -EAGAIN) {

net/smc/smc_clc.c

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ static bool smc_clc_msg_prop_valid(struct smc_clc_msg_proposal *pclc)
377377

378378
/* check arriving CLC accept or confirm */
379379
static bool
380-
smc_clc_msg_acc_conf_valid(struct smc_clc_msg_accept_confirm_v2 *clc_v2)
380+
smc_clc_msg_acc_conf_valid(struct smc_clc_msg_accept_confirm *clc)
381381
{
382-
struct smc_clc_msg_hdr *hdr = &clc_v2->hdr;
382+
struct smc_clc_msg_hdr *hdr = &clc->hdr;
383383

384384
if (hdr->typev1 != SMC_TYPE_R && hdr->typev1 != SMC_TYPE_D)
385385
return false;
@@ -449,7 +449,7 @@ static int smc_clc_fill_fce_v2x(struct smc_clc_first_contact_ext_v2x *fce_v2x,
449449
*/
450450
static bool smc_clc_msg_hdr_valid(struct smc_clc_msg_hdr *clcm, bool check_trl)
451451
{
452-
struct smc_clc_msg_accept_confirm_v2 *clc_v2;
452+
struct smc_clc_msg_accept_confirm *clc;
453453
struct smc_clc_msg_proposal *pclc;
454454
struct smc_clc_msg_decline *dclc;
455455
struct smc_clc_msg_trail *trl;
@@ -467,12 +467,11 @@ static bool smc_clc_msg_hdr_valid(struct smc_clc_msg_hdr *clcm, bool check_trl)
467467
break;
468468
case SMC_CLC_ACCEPT:
469469
case SMC_CLC_CONFIRM:
470-
clc_v2 = (struct smc_clc_msg_accept_confirm_v2 *)clcm;
471-
if (!smc_clc_msg_acc_conf_valid(clc_v2))
470+
clc = (struct smc_clc_msg_accept_confirm *)clcm;
471+
if (!smc_clc_msg_acc_conf_valid(clc))
472472
return false;
473473
trl = (struct smc_clc_msg_trail *)
474-
((u8 *)clc_v2 + ntohs(clc_v2->hdr.length) -
475-
sizeof(*trl));
474+
((u8 *)clc + ntohs(clc->hdr.length) - sizeof(*trl));
476475
break;
477476
case SMC_CLC_DECLINE:
478477
dclc = (struct smc_clc_msg_decline *)clcm;
@@ -1000,19 +999,17 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
1000999

10011000
static void
10021001
smcd_clc_prep_confirm_accept(struct smc_connection *conn,
1003-
struct smc_clc_msg_accept_confirm_v2 *clc_v2,
1002+
struct smc_clc_msg_accept_confirm *clc,
10041003
int first_contact, u8 version,
10051004
u8 *eid, struct smc_init_info *ini,
10061005
int *fce_len,
10071006
struct smc_clc_first_contact_ext_v2x *fce_v2x,
10081007
struct smc_clc_msg_trail *trl)
10091008
{
10101009
struct smcd_dev *smcd = conn->lgr->smcd;
1011-
struct smc_clc_msg_accept_confirm *clc;
10121010
int len;
10131011

10141012
/* SMC-D specific settings */
1015-
clc = (struct smc_clc_msg_accept_confirm *)clc_v2;
10161013
memcpy(clc->hdr.eyecatcher, SMCD_EYECATCHER,
10171014
sizeof(SMCD_EYECATCHER));
10181015
clc->hdr.typev1 = SMC_TYPE_D;
@@ -1024,36 +1021,34 @@ smcd_clc_prep_confirm_accept(struct smc_connection *conn,
10241021
if (version == SMC_V1) {
10251022
clc->hdr.length = htons(SMCD_CLC_ACCEPT_CONFIRM_LEN);
10261023
} else {
1027-
clc_v2->d1.chid = htons(smc_ism_get_chid(smcd));
1024+
clc->d1.chid = htons(smc_ism_get_chid(smcd));
10281025
if (eid && eid[0])
1029-
memcpy(clc_v2->d1.eid, eid, SMC_MAX_EID_LEN);
1026+
memcpy(clc->d1.eid, eid, SMC_MAX_EID_LEN);
10301027
len = SMCD_CLC_ACCEPT_CONFIRM_LEN_V2;
10311028
if (first_contact) {
10321029
*fce_len = smc_clc_fill_fce_v2x(fce_v2x, ini);
10331030
len += *fce_len;
10341031
}
1035-
clc_v2->hdr.length = htons(len);
1032+
clc->hdr.length = htons(len);
10361033
}
10371034
memcpy(trl->eyecatcher, SMCD_EYECATCHER,
10381035
sizeof(SMCD_EYECATCHER));
10391036
}
10401037

10411038
static void
10421039
smcr_clc_prep_confirm_accept(struct smc_connection *conn,
1043-
struct smc_clc_msg_accept_confirm_v2 *clc_v2,
1040+
struct smc_clc_msg_accept_confirm *clc,
10441041
int first_contact, u8 version,
10451042
u8 *eid, struct smc_init_info *ini,
10461043
int *fce_len,
10471044
struct smc_clc_first_contact_ext_v2x *fce_v2x,
10481045
struct smc_clc_fce_gid_ext *gle,
10491046
struct smc_clc_msg_trail *trl)
10501047
{
1051-
struct smc_clc_msg_accept_confirm *clc;
10521048
struct smc_link *link = conn->lnk;
10531049
int len;
10541050

10551051
/* SMC-R specific settings */
1056-
clc = (struct smc_clc_msg_accept_confirm *)clc_v2;
10571052
memcpy(clc->hdr.eyecatcher, SMC_EYECATCHER,
10581053
sizeof(SMC_EYECATCHER));
10591054
clc->hdr.typev1 = SMC_TYPE_R;
@@ -1085,7 +1080,7 @@ smcr_clc_prep_confirm_accept(struct smc_connection *conn,
10851080
clc->hdr.length = htons(SMCR_CLC_ACCEPT_CONFIRM_LEN);
10861081
} else {
10871082
if (eid && eid[0])
1088-
memcpy(clc_v2->r1.eid, eid, SMC_MAX_EID_LEN);
1083+
memcpy(clc->r1.eid, eid, SMC_MAX_EID_LEN);
10891084
len = SMCR_CLC_ACCEPT_CONFIRM_LEN_V2;
10901085
if (first_contact) {
10911086
*fce_len = smc_clc_fill_fce_v2x(fce_v2x, ini);
@@ -1099,42 +1094,40 @@ smcr_clc_prep_confirm_accept(struct smc_connection *conn,
10991094
len += gle->gid_cnt * sizeof(gle->gid[0]);
11001095
}
11011096
}
1102-
clc_v2->hdr.length = htons(len);
1097+
clc->hdr.length = htons(len);
11031098
}
11041099
memcpy(trl->eyecatcher, SMC_EYECATCHER, sizeof(SMC_EYECATCHER));
11051100
}
11061101

11071102
/* build and send CLC CONFIRM / ACCEPT message */
11081103
static int smc_clc_send_confirm_accept(struct smc_sock *smc,
1109-
struct smc_clc_msg_accept_confirm_v2 *clc_v2,
1104+
struct smc_clc_msg_accept_confirm *clc,
11101105
int first_contact, u8 version,
11111106
u8 *eid, struct smc_init_info *ini)
11121107
{
11131108
struct smc_clc_first_contact_ext_v2x fce_v2x;
11141109
struct smc_connection *conn = &smc->conn;
1115-
struct smc_clc_msg_accept_confirm *clc;
11161110
struct smc_clc_fce_gid_ext gle;
11171111
struct smc_clc_msg_trail trl;
11181112
int i, fce_len;
11191113
struct kvec vec[5];
11201114
struct msghdr msg;
11211115

11221116
/* send SMC Confirm CLC msg */
1123-
clc = (struct smc_clc_msg_accept_confirm *)clc_v2;
11241117
clc->hdr.version = version; /* SMC version */
11251118
if (first_contact)
11261119
clc->hdr.typev2 |= SMC_FIRST_CONTACT_MASK;
11271120
if (conn->lgr->is_smcd)
1128-
smcd_clc_prep_confirm_accept(conn, clc_v2, first_contact,
1121+
smcd_clc_prep_confirm_accept(conn, clc, first_contact,
11291122
version, eid, ini, &fce_len,
11301123
&fce_v2x, &trl);
11311124
else
1132-
smcr_clc_prep_confirm_accept(conn, clc_v2, first_contact,
1125+
smcr_clc_prep_confirm_accept(conn, clc, first_contact,
11331126
version, eid, ini, &fce_len,
11341127
&fce_v2x, &gle, &trl);
11351128
memset(&msg, 0, sizeof(msg));
11361129
i = 0;
1137-
vec[i].iov_base = clc_v2;
1130+
vec[i].iov_base = clc;
11381131
if (version > SMC_V1)
11391132
vec[i++].iov_len = (clc->hdr.typev1 == SMC_TYPE_D ?
11401133
SMCD_CLC_ACCEPT_CONFIRM_LEN_V2 :
@@ -1168,16 +1161,16 @@ static int smc_clc_send_confirm_accept(struct smc_sock *smc,
11681161
int smc_clc_send_confirm(struct smc_sock *smc, bool clnt_first_contact,
11691162
u8 version, u8 *eid, struct smc_init_info *ini)
11701163
{
1171-
struct smc_clc_msg_accept_confirm_v2 cclc_v2;
1164+
struct smc_clc_msg_accept_confirm cclc;
11721165
int reason_code = 0;
11731166
int len;
11741167

11751168
/* send SMC Confirm CLC msg */
1176-
memset(&cclc_v2, 0, sizeof(cclc_v2));
1177-
cclc_v2.hdr.type = SMC_CLC_CONFIRM;
1178-
len = smc_clc_send_confirm_accept(smc, &cclc_v2, clnt_first_contact,
1169+
memset(&cclc, 0, sizeof(cclc));
1170+
cclc.hdr.type = SMC_CLC_CONFIRM;
1171+
len = smc_clc_send_confirm_accept(smc, &cclc, clnt_first_contact,
11791172
version, eid, ini);
1180-
if (len < ntohs(cclc_v2.hdr.length)) {
1173+
if (len < ntohs(cclc.hdr.length)) {
11811174
if (len >= 0) {
11821175
reason_code = -ENETUNREACH;
11831176
smc->sk.sk_err = -reason_code;
@@ -1193,14 +1186,14 @@ int smc_clc_send_confirm(struct smc_sock *smc, bool clnt_first_contact,
11931186
int smc_clc_send_accept(struct smc_sock *new_smc, bool srv_first_contact,
11941187
u8 version, u8 *negotiated_eid, struct smc_init_info *ini)
11951188
{
1196-
struct smc_clc_msg_accept_confirm_v2 aclc_v2;
1189+
struct smc_clc_msg_accept_confirm aclc;
11971190
int len;
11981191

1199-
memset(&aclc_v2, 0, sizeof(aclc_v2));
1200-
aclc_v2.hdr.type = SMC_CLC_ACCEPT;
1201-
len = smc_clc_send_confirm_accept(new_smc, &aclc_v2, srv_first_contact,
1192+
memset(&aclc, 0, sizeof(aclc));
1193+
aclc.hdr.type = SMC_CLC_ACCEPT;
1194+
len = smc_clc_send_confirm_accept(new_smc, &aclc, srv_first_contact,
12021195
version, negotiated_eid, ini);
1203-
if (len < ntohs(aclc_v2.hdr.length))
1196+
if (len < ntohs(aclc.hdr.length))
12041197
len = len >= 0 ? -EPROTO : -new_smc->clcsock->sk->sk_err;
12051198

12061199
return len > 0 ? 0 : len;
@@ -1265,10 +1258,8 @@ int smc_clc_clnt_v2x_features_validate(struct smc_clc_first_contact_ext *fce,
12651258
int smc_clc_v2x_features_confirm_check(struct smc_clc_msg_accept_confirm *cclc,
12661259
struct smc_init_info *ini)
12671260
{
1268-
struct smc_clc_msg_accept_confirm_v2 *clc_v2 =
1269-
(struct smc_clc_msg_accept_confirm_v2 *)cclc;
12701261
struct smc_clc_first_contact_ext *fce =
1271-
smc_get_clc_first_contact_ext(clc_v2, ini->is_smcd);
1262+
smc_get_clc_first_contact_ext(cclc, ini->is_smcd);
12721263
struct smc_clc_first_contact_ext_v2x *fce_v2x =
12731264
(struct smc_clc_first_contact_ext_v2x *)fce;
12741265

0 commit comments

Comments
 (0)