Skip to content

Commit 2f9dbed

Browse files
Alexander Aringteigland
authored andcommitted
dlm: use __le types for rcom messages
This patch changes to use __le types directly in the dlm rcom structure which is casted at the right dlm message buffer positions. The main goal what is reached here is to remove sparse warnings regarding to host to little byte order conversion or vice versa. Leaving those sparse issues ignored and always do it in out/in functionality tends to leave it unknown in which byte order the variable is being handled. Signed-off-by: Alexander Aring <[email protected]> Signed-off-by: David Teigland <[email protected]>
1 parent 3428785 commit 2f9dbed

File tree

7 files changed

+52
-80
lines changed

7 files changed

+52
-80
lines changed

fs/dlm/dlm_internal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,11 @@ struct dlm_message {
451451

452452
struct dlm_rcom {
453453
struct dlm_header rc_header;
454-
uint32_t rc_type; /* DLM_RCOM_ */
455-
int rc_result; /* multi-purpose */
456-
uint64_t rc_id; /* match reply with request */
457-
uint64_t rc_seq; /* sender's ls_recover_seq */
458-
uint64_t rc_seq_reply; /* remote ls_recover_seq */
454+
__le32 rc_type; /* DLM_RCOM_ */
455+
__le32 rc_result; /* multi-purpose */
456+
__le64 rc_id; /* match reply with request */
457+
__le64 rc_seq; /* sender's ls_recover_seq */
458+
__le64 rc_seq_reply; /* remote ls_recover_seq */
459459
char rc_buf[];
460460
};
461461

fs/dlm/lock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5062,8 +5062,7 @@ void dlm_receive_buffer(union dlm_packet *p, int nodeid)
50625062
type = p->message.m_type;
50635063
break;
50645064
case DLM_RCOM:
5065-
dlm_rcom_in(&p->rcom);
5066-
type = p->rcom.rc_type;
5065+
type = le32_to_cpu(p->rcom.rc_type);
50675066
break;
50685067
default:
50695068
log_print("invalid h_cmd %d from %u", hd->h_cmd, nodeid);

fs/dlm/member.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,13 @@ int dlm_slots_copy_in(struct dlm_ls *ls)
120120

121121
ro0 = (struct rcom_slot *)(rc->rc_buf + sizeof(struct rcom_config));
122122

123-
for (i = 0, ro = ro0; i < num_slots; i++, ro++) {
124-
ro->ro_nodeid = le32_to_cpu(ro->ro_nodeid);
125-
ro->ro_slot = le16_to_cpu(ro->ro_slot);
126-
}
127-
128123
log_slots(ls, gen, num_slots, ro0, NULL, 0);
129124

130125
list_for_each_entry(memb, &ls->ls_nodes, list) {
131126
for (i = 0, ro = ro0; i < num_slots; i++, ro++) {
132-
if (ro->ro_nodeid != memb->nodeid)
127+
if (le32_to_cpu(ro->ro_nodeid) != memb->nodeid)
133128
continue;
134-
memb->slot = ro->ro_slot;
129+
memb->slot = le16_to_cpu(ro->ro_slot);
135130
memb->slot_prev = memb->slot;
136131
break;
137132
}

fs/dlm/rcom.c

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ static void _create_rcom(struct dlm_ls *ls, int to_nodeid, int type, int len,
4040
rc->rc_header.h_length = cpu_to_le16(mb_len);
4141
rc->rc_header.h_cmd = DLM_RCOM;
4242

43-
rc->rc_type = type;
43+
rc->rc_type = cpu_to_le32(type);
4444

4545
spin_lock(&ls->ls_recover_lock);
46-
rc->rc_seq = ls->ls_recover_seq;
46+
rc->rc_seq = cpu_to_le64(ls->ls_recover_seq);
4747
spin_unlock(&ls->ls_recover_lock);
4848

4949
*rc_ret = rc;
@@ -91,13 +91,11 @@ static int create_rcom_stateless(struct dlm_ls *ls, int to_nodeid, int type,
9191

9292
static void send_rcom(struct dlm_mhandle *mh, struct dlm_rcom *rc)
9393
{
94-
dlm_rcom_out(rc);
9594
dlm_midcomms_commit_mhandle(mh);
9695
}
9796

9897
static void send_rcom_stateless(struct dlm_msg *msg, struct dlm_rcom *rc)
9998
{
100-
dlm_rcom_out(rc);
10199
dlm_lowcomms_commit_msg(msg);
102100
dlm_lowcomms_put_msg(msg);
103101
}
@@ -145,10 +143,10 @@ static int check_rcom_config(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
145143
return 0;
146144
}
147145

148-
static void allow_sync_reply(struct dlm_ls *ls, uint64_t *new_seq)
146+
static void allow_sync_reply(struct dlm_ls *ls, __le64 *new_seq)
149147
{
150148
spin_lock(&ls->ls_rcom_spin);
151-
*new_seq = ++ls->ls_rcom_seq;
149+
*new_seq = cpu_to_le64(++ls->ls_rcom_seq);
152150
set_bit(LSFL_RCOM_WAIT, &ls->ls_flags);
153151
spin_unlock(&ls->ls_rcom_spin);
154152
}
@@ -182,7 +180,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint32_t status_flags)
182180

183181
if (nodeid == dlm_our_nodeid()) {
184182
rc = ls->ls_recover_buf;
185-
rc->rc_result = dlm_recover_status(ls);
183+
rc->rc_result = cpu_to_le32(dlm_recover_status(ls));
186184
goto out;
187185
}
188186

@@ -208,7 +206,7 @@ int dlm_rcom_status(struct dlm_ls *ls, int nodeid, uint32_t status_flags)
208206

209207
rc = ls->ls_recover_buf;
210208

211-
if (rc->rc_result == -ESRCH) {
209+
if (rc->rc_result == cpu_to_le32(-ESRCH)) {
212210
/* we pretend the remote lockspace exists with 0 status */
213211
log_debug(ls, "remote node %d not ready", nodeid);
214212
rc->rc_result = 0;
@@ -259,7 +257,7 @@ static void receive_rcom_status(struct dlm_ls *ls, struct dlm_rcom *rc_in)
259257

260258
rc->rc_id = rc_in->rc_id;
261259
rc->rc_seq_reply = rc_in->rc_seq;
262-
rc->rc_result = status;
260+
rc->rc_result = cpu_to_le32(status);
263261

264262
set_rcom_config(ls, (struct rcom_config *)rc->rc_buf, num_slots);
265263

@@ -287,11 +285,11 @@ static void receive_sync_reply(struct dlm_ls *ls, struct dlm_rcom *rc_in)
287285
{
288286
spin_lock(&ls->ls_rcom_spin);
289287
if (!test_bit(LSFL_RCOM_WAIT, &ls->ls_flags) ||
290-
rc_in->rc_id != ls->ls_rcom_seq) {
288+
le64_to_cpu(rc_in->rc_id) != ls->ls_rcom_seq) {
291289
log_debug(ls, "reject reply %d from %d seq %llx expect %llx",
292-
rc_in->rc_type,
290+
le32_to_cpu(rc_in->rc_type),
293291
le32_to_cpu(rc_in->rc_header.h_nodeid),
294-
(unsigned long long)rc_in->rc_id,
292+
(unsigned long long)le64_to_cpu(rc_in->rc_id),
295293
(unsigned long long)ls->ls_rcom_seq);
296294
goto out;
297295
}
@@ -367,7 +365,7 @@ int dlm_send_rcom_lookup(struct dlm_rsb *r, int dir_nodeid)
367365
if (error)
368366
goto out;
369367
memcpy(rc->rc_buf, r->res_name, r->res_length);
370-
rc->rc_id = (unsigned long) r->res_id;
368+
rc->rc_id = cpu_to_le64(r->res_id);
371369

372370
send_rcom(mh, rc);
373371
out:
@@ -383,7 +381,7 @@ static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in)
383381
sizeof(struct dlm_rcom);
384382

385383
/* Old code would send this special id to trigger a debug dump. */
386-
if (rc_in->rc_id == 0xFFFFFFFF) {
384+
if (rc_in->rc_id == cpu_to_le64(0xFFFFFFFF)) {
387385
log_error(ls, "receive_rcom_lookup dump from %d", nodeid);
388386
dlm_dump_rsb_name(ls, rc_in->rc_buf, len);
389387
return;
@@ -397,7 +395,7 @@ static void receive_rcom_lookup(struct dlm_ls *ls, struct dlm_rcom *rc_in)
397395
DLM_LU_RECOVER_MASTER, &ret_nodeid, NULL);
398396
if (error)
399397
ret_nodeid = error;
400-
rc->rc_result = ret_nodeid;
398+
rc->rc_result = cpu_to_le32(ret_nodeid);
401399
rc->rc_id = rc_in->rc_id;
402400
rc->rc_seq_reply = rc_in->rc_seq;
403401

@@ -456,7 +454,7 @@ int dlm_send_rcom_lock(struct dlm_rsb *r, struct dlm_lkb *lkb)
456454

457455
rl = (struct rcom_lock *) rc->rc_buf;
458456
pack_rcom_lock(r, lkb, rl);
459-
rc->rc_id = (unsigned long) r;
457+
rc->rc_id = cpu_to_le64(r);
460458

461459
send_rcom(mh, rc);
462460
out:
@@ -510,15 +508,14 @@ int dlm_send_ls_not_ready(int nodeid, struct dlm_rcom *rc_in)
510508
rc->rc_header.h_length = cpu_to_le16(mb_len);
511509
rc->rc_header.h_cmd = DLM_RCOM;
512510

513-
rc->rc_type = DLM_RCOM_STATUS_REPLY;
511+
rc->rc_type = cpu_to_le32(DLM_RCOM_STATUS_REPLY);
514512
rc->rc_id = rc_in->rc_id;
515513
rc->rc_seq_reply = rc_in->rc_seq;
516-
rc->rc_result = -ESRCH;
514+
rc->rc_result = cpu_to_le32(-ESRCH);
517515

518516
rf = (struct rcom_config *) rc->rc_buf;
519517
rf->rf_lvblen = cpu_to_le32(~0U);
520518

521-
dlm_rcom_out(rc);
522519
dlm_midcomms_commit_mhandle(mh);
523520

524521
return 0;
@@ -577,27 +574,27 @@ void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
577574
uint64_t seq;
578575

579576
switch (rc->rc_type) {
580-
case DLM_RCOM_STATUS_REPLY:
577+
case cpu_to_le32(DLM_RCOM_STATUS_REPLY):
581578
reply = 1;
582579
break;
583-
case DLM_RCOM_NAMES:
580+
case cpu_to_le32(DLM_RCOM_NAMES):
584581
names = 1;
585582
break;
586-
case DLM_RCOM_NAMES_REPLY:
583+
case cpu_to_le32(DLM_RCOM_NAMES_REPLY):
587584
names = 1;
588585
reply = 1;
589586
break;
590-
case DLM_RCOM_LOOKUP:
587+
case cpu_to_le32(DLM_RCOM_LOOKUP):
591588
lookup = 1;
592589
break;
593-
case DLM_RCOM_LOOKUP_REPLY:
590+
case cpu_to_le32(DLM_RCOM_LOOKUP_REPLY):
594591
lookup = 1;
595592
reply = 1;
596593
break;
597-
case DLM_RCOM_LOCK:
594+
case cpu_to_le32(DLM_RCOM_LOCK):
598595
lock = 1;
599596
break;
600-
case DLM_RCOM_LOCK_REPLY:
597+
case cpu_to_le32(DLM_RCOM_LOCK_REPLY):
601598
lock = 1;
602599
reply = 1;
603600
break;
@@ -609,10 +606,10 @@ void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
609606
seq = ls->ls_recover_seq;
610607
spin_unlock(&ls->ls_recover_lock);
611608

612-
if (stop && (rc->rc_type != DLM_RCOM_STATUS))
609+
if (stop && (rc->rc_type != cpu_to_le32(DLM_RCOM_STATUS)))
613610
goto ignore;
614611

615-
if (reply && (rc->rc_seq_reply != seq))
612+
if (reply && (le64_to_cpu(rc->rc_seq_reply) != seq))
616613
goto ignore;
617614

618615
if (!(status & DLM_RS_NODES) && (names || lookup || lock))
@@ -622,59 +619,60 @@ void dlm_receive_rcom(struct dlm_ls *ls, struct dlm_rcom *rc, int nodeid)
622619
goto ignore;
623620

624621
switch (rc->rc_type) {
625-
case DLM_RCOM_STATUS:
622+
case cpu_to_le32(DLM_RCOM_STATUS):
626623
receive_rcom_status(ls, rc);
627624
break;
628625

629-
case DLM_RCOM_NAMES:
626+
case cpu_to_le32(DLM_RCOM_NAMES):
630627
receive_rcom_names(ls, rc);
631628
break;
632629

633-
case DLM_RCOM_LOOKUP:
630+
case cpu_to_le32(DLM_RCOM_LOOKUP):
634631
receive_rcom_lookup(ls, rc);
635632
break;
636633

637-
case DLM_RCOM_LOCK:
634+
case cpu_to_le32(DLM_RCOM_LOCK):
638635
if (le16_to_cpu(rc->rc_header.h_length) < lock_size)
639636
goto Eshort;
640637
receive_rcom_lock(ls, rc);
641638
break;
642639

643-
case DLM_RCOM_STATUS_REPLY:
640+
case cpu_to_le32(DLM_RCOM_STATUS_REPLY):
644641
receive_sync_reply(ls, rc);
645642
break;
646643

647-
case DLM_RCOM_NAMES_REPLY:
644+
case cpu_to_le32(DLM_RCOM_NAMES_REPLY):
648645
receive_sync_reply(ls, rc);
649646
break;
650647

651-
case DLM_RCOM_LOOKUP_REPLY:
648+
case cpu_to_le32(DLM_RCOM_LOOKUP_REPLY):
652649
receive_rcom_lookup_reply(ls, rc);
653650
break;
654651

655-
case DLM_RCOM_LOCK_REPLY:
652+
case cpu_to_le32(DLM_RCOM_LOCK_REPLY):
656653
if (le16_to_cpu(rc->rc_header.h_length) < lock_size)
657654
goto Eshort;
658655
dlm_recover_process_copy(ls, rc);
659656
break;
660657

661658
default:
662-
log_error(ls, "receive_rcom bad type %d", rc->rc_type);
659+
log_error(ls, "receive_rcom bad type %d",
660+
le32_to_cpu(rc->rc_type));
663661
}
664662
return;
665663

666664
ignore:
667665
log_limit(ls, "dlm_receive_rcom ignore msg %d "
668666
"from %d %llu %llu recover seq %llu sts %x gen %u",
669-
rc->rc_type,
667+
le32_to_cpu(rc->rc_type),
670668
nodeid,
671-
(unsigned long long)rc->rc_seq,
672-
(unsigned long long)rc->rc_seq_reply,
669+
(unsigned long long)le64_to_cpu(rc->rc_seq),
670+
(unsigned long long)le64_to_cpu(rc->rc_seq_reply),
673671
(unsigned long long)seq,
674672
status, ls->ls_generation);
675673
return;
676674
Eshort:
677675
log_error(ls, "recovery message %d from %d is too short",
678-
rc->rc_type, nodeid);
676+
le32_to_cpu(rc->rc_type), nodeid);
679677
}
680678

fs/dlm/recover.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int wait_status_all(struct dlm_ls *ls, uint32_t wait_status,
114114
if (save_slots)
115115
dlm_slot_save(ls, rc, memb);
116116

117-
if (rc->rc_result & wait_status)
117+
if (le32_to_cpu(rc->rc_result) & wait_status)
118118
break;
119119
if (delay < 1000)
120120
delay += 20;
@@ -141,7 +141,7 @@ static int wait_status_low(struct dlm_ls *ls, uint32_t wait_status,
141141
if (error)
142142
break;
143143

144-
if (rc->rc_result & wait_status)
144+
if (le32_to_cpu(rc->rc_result) & wait_status)
145145
break;
146146
if (delay < 1000)
147147
delay += 20;
@@ -568,14 +568,14 @@ int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc)
568568
struct dlm_rsb *r;
569569
int ret_nodeid, new_master;
570570

571-
r = recover_idr_find(ls, rc->rc_id);
571+
r = recover_idr_find(ls, le64_to_cpu(rc->rc_id));
572572
if (!r) {
573573
log_error(ls, "dlm_recover_master_reply no id %llx",
574-
(unsigned long long)rc->rc_id);
574+
(unsigned long long)le64_to_cpu(rc->rc_id));
575575
goto out;
576576
}
577577

578-
ret_nodeid = rc->rc_result;
578+
ret_nodeid = le32_to_cpu(rc->rc_result);
579579

580580
if (ret_nodeid == dlm_our_nodeid())
581581
new_master = 0;

fs/dlm/util.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,3 @@ void dlm_message_in(struct dlm_message *ms)
108108
ms->m_asts = le32_to_cpu(ms->m_asts);
109109
ms->m_result = from_dlm_errno(le32_to_cpu(ms->m_result));
110110
}
111-
112-
void dlm_rcom_out(struct dlm_rcom *rc)
113-
{
114-
rc->rc_type = cpu_to_le32(rc->rc_type);
115-
rc->rc_result = cpu_to_le32(rc->rc_result);
116-
rc->rc_id = cpu_to_le64(rc->rc_id);
117-
rc->rc_seq = cpu_to_le64(rc->rc_seq);
118-
rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply);
119-
}
120-
121-
void dlm_rcom_in(struct dlm_rcom *rc)
122-
{
123-
rc->rc_type = le32_to_cpu(rc->rc_type);
124-
rc->rc_result = le32_to_cpu(rc->rc_result);
125-
rc->rc_id = le64_to_cpu(rc->rc_id);
126-
rc->rc_seq = le64_to_cpu(rc->rc_seq);
127-
rc->rc_seq_reply = le64_to_cpu(rc->rc_seq_reply);
128-
}

fs/dlm/util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
void dlm_message_out(struct dlm_message *ms);
1515
void dlm_message_in(struct dlm_message *ms);
16-
void dlm_rcom_out(struct dlm_rcom *rc);
17-
void dlm_rcom_in(struct dlm_rcom *rc);
1816

1917
#endif
2018

0 commit comments

Comments
 (0)