Skip to content

Commit 3428785

Browse files
Alexander Aringteigland
authored andcommitted
dlm: use __le types for dlm header
This patch changes to use __le types directly in the dlm header 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 d9efd00 commit 3428785

File tree

9 files changed

+98
-116
lines changed

9 files changed

+98
-116
lines changed

fs/dlm/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int dlm_recover_directory(struct dlm_ls *ls)
101101
*/
102102

103103
b = ls->ls_recover_buf->rc_buf;
104-
left = ls->ls_recover_buf->rc_header.h_length;
104+
left = le16_to_cpu(ls->ls_recover_buf->rc_header.h_length);
105105
left -= sizeof(struct dlm_rcom);
106106

107107
for (;;) {

fs/dlm/dlm_internal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,15 @@ static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)
379379
#define DLM_FIN 5
380380

381381
struct dlm_header {
382-
uint32_t h_version;
382+
__le32 h_version;
383383
union {
384384
/* for DLM_MSG and DLM_RCOM */
385-
uint32_t h_lockspace;
385+
__le32 h_lockspace;
386386
/* for DLM_ACK and DLM_OPTS */
387-
uint32_t h_seq;
387+
__le32 h_seq;
388388
} u;
389-
uint32_t h_nodeid; /* nodeid of sender */
390-
uint16_t h_length;
389+
__le32 h_nodeid; /* nodeid of sender */
390+
__le16 h_length;
391391
uint8_t h_cmd; /* DLM_MSG, DLM_RCOM */
392392
uint8_t h_pad;
393393
};

fs/dlm/lock.c

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,8 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
15711571
}
15721572

15731573
log_error(ls, "remwait error %x remote %d %x msg %d flags %x no wait",
1574-
lkb->lkb_id, ms ? ms->m_header.h_nodeid : 0, lkb->lkb_remid,
1575-
mstype, lkb->lkb_flags);
1574+
lkb->lkb_id, ms ? le32_to_cpu(ms->m_header.h_nodeid) : 0,
1575+
lkb->lkb_remid, mstype, lkb->lkb_flags);
15761576
return -1;
15771577

15781578
out_del:
@@ -3564,10 +3564,10 @@ static int _create_message(struct dlm_ls *ls, int mb_len,
35643564

35653565
ms = (struct dlm_message *) mb;
35663566

3567-
ms->m_header.h_version = (DLM_HEADER_MAJOR | DLM_HEADER_MINOR);
3568-
ms->m_header.u.h_lockspace = ls->ls_global_id;
3569-
ms->m_header.h_nodeid = dlm_our_nodeid();
3570-
ms->m_header.h_length = mb_len;
3567+
ms->m_header.h_version = cpu_to_le32(DLM_HEADER_MAJOR | DLM_HEADER_MINOR);
3568+
ms->m_header.u.h_lockspace = cpu_to_le32(ls->ls_global_id);
3569+
ms->m_header.h_nodeid = cpu_to_le32(dlm_our_nodeid());
3570+
ms->m_header.h_length = cpu_to_le16(mb_len);
35713571
ms->m_header.h_cmd = DLM_MSG;
35723572

35733573
ms->m_type = mstype;
@@ -3861,7 +3861,7 @@ static int send_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms_in,
38613861
struct dlm_rsb *r = &ls->ls_stub_rsb;
38623862
struct dlm_message *ms;
38633863
struct dlm_mhandle *mh;
3864-
int error, nodeid = ms_in->m_header.h_nodeid;
3864+
int error, nodeid = le32_to_cpu(ms_in->m_header.h_nodeid);
38653865

38663866
error = create_message(r, NULL, nodeid, DLM_MSG_LOOKUP_REPLY, &ms, &mh);
38673867
if (error)
@@ -3900,7 +3900,8 @@ static void receive_flags_reply(struct dlm_lkb *lkb, struct dlm_message *ms)
39003900

39013901
static int receive_extralen(struct dlm_message *ms)
39023902
{
3903-
return (ms->m_header.h_length - sizeof(struct dlm_message));
3903+
return (le16_to_cpu(ms->m_header.h_length) -
3904+
sizeof(struct dlm_message));
39043905
}
39053906

39063907
static int receive_lvb(struct dlm_ls *ls, struct dlm_lkb *lkb,
@@ -3934,7 +3935,7 @@ static void fake_astfn(void *astparam)
39343935
static int receive_request_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
39353936
struct dlm_message *ms)
39363937
{
3937-
lkb->lkb_nodeid = ms->m_header.h_nodeid;
3938+
lkb->lkb_nodeid = le32_to_cpu(ms->m_header.h_nodeid);
39383939
lkb->lkb_ownpid = ms->m_pid;
39393940
lkb->lkb_remid = ms->m_lkid;
39403941
lkb->lkb_grmode = DLM_LOCK_IV;
@@ -3982,7 +3983,7 @@ static int receive_unlock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
39823983
static void setup_stub_lkb(struct dlm_ls *ls, struct dlm_message *ms)
39833984
{
39843985
struct dlm_lkb *lkb = &ls->ls_stub_lkb;
3985-
lkb->lkb_nodeid = ms->m_header.h_nodeid;
3986+
lkb->lkb_nodeid = le32_to_cpu(ms->m_header.h_nodeid);
39863987
lkb->lkb_remid = ms->m_lkid;
39873988
}
39883989

@@ -3991,7 +3992,7 @@ static void setup_stub_lkb(struct dlm_ls *ls, struct dlm_message *ms)
39913992

39923993
static int validate_message(struct dlm_lkb *lkb, struct dlm_message *ms)
39933994
{
3994-
int from = ms->m_header.h_nodeid;
3995+
int from = le32_to_cpu(ms->m_header.h_nodeid);
39953996
int error = 0;
39963997

39973998
/* currently mixing of user/kernel locks are not supported */
@@ -4105,7 +4106,7 @@ static int receive_request(struct dlm_ls *ls, struct dlm_message *ms)
41054106
int from_nodeid;
41064107
int error, namelen = 0;
41074108

4108-
from_nodeid = ms->m_header.h_nodeid;
4109+
from_nodeid = le32_to_cpu(ms->m_header.h_nodeid);
41094110

41104111
error = create_lkb(ls, &lkb);
41114112
if (error)
@@ -4205,7 +4206,7 @@ static int receive_convert(struct dlm_ls *ls, struct dlm_message *ms)
42054206
log_error(ls, "receive_convert %x remid %x recover_seq %llu "
42064207
"remote %d %x", lkb->lkb_id, lkb->lkb_remid,
42074208
(unsigned long long)lkb->lkb_recover_seq,
4208-
ms->m_header.h_nodeid, ms->m_lkid);
4209+
le32_to_cpu(ms->m_header.h_nodeid), ms->m_lkid);
42094210
error = -ENOENT;
42104211
dlm_put_lkb(lkb);
42114212
goto fail;
@@ -4259,7 +4260,7 @@ static int receive_unlock(struct dlm_ls *ls, struct dlm_message *ms)
42594260
if (lkb->lkb_remid != ms->m_lkid) {
42604261
log_error(ls, "receive_unlock %x remid %x remote %d %x",
42614262
lkb->lkb_id, lkb->lkb_remid,
4262-
ms->m_header.h_nodeid, ms->m_lkid);
4263+
le32_to_cpu(ms->m_header.h_nodeid), ms->m_lkid);
42634264
error = -ENOENT;
42644265
dlm_put_lkb(lkb);
42654266
goto fail;
@@ -4396,7 +4397,7 @@ static void receive_lookup(struct dlm_ls *ls, struct dlm_message *ms)
43964397
{
43974398
int len, error, ret_nodeid, from_nodeid, our_nodeid;
43984399

4399-
from_nodeid = ms->m_header.h_nodeid;
4400+
from_nodeid = le32_to_cpu(ms->m_header.h_nodeid);
44004401
our_nodeid = dlm_our_nodeid();
44014402

44024403
len = receive_extralen(ms);
@@ -4419,7 +4420,7 @@ static void receive_remove(struct dlm_ls *ls, struct dlm_message *ms)
44194420
uint32_t hash, b;
44204421
int rv, len, dir_nodeid, from_nodeid;
44214422

4422-
from_nodeid = ms->m_header.h_nodeid;
4423+
from_nodeid = le32_to_cpu(ms->m_header.h_nodeid);
44234424

44244425
len = receive_extralen(ms);
44254426

@@ -4510,7 +4511,7 @@ static int receive_request_reply(struct dlm_ls *ls, struct dlm_message *ms)
45104511
struct dlm_lkb *lkb;
45114512
struct dlm_rsb *r;
45124513
int error, mstype, result;
4513-
int from_nodeid = ms->m_header.h_nodeid;
4514+
int from_nodeid = le32_to_cpu(ms->m_header.h_nodeid);
45144515

45154516
error = find_lkb(ls, ms->m_remid, &lkb);
45164517
if (error)
@@ -4662,8 +4663,8 @@ static void __receive_convert_reply(struct dlm_rsb *r, struct dlm_lkb *lkb,
46624663

46634664
default:
46644665
log_error(r->res_ls, "receive_convert_reply %x remote %d %x %d",
4665-
lkb->lkb_id, ms->m_header.h_nodeid, ms->m_lkid,
4666-
ms->m_result);
4666+
lkb->lkb_id, le32_to_cpu(ms->m_header.h_nodeid),
4667+
ms->m_lkid, ms->m_result);
46674668
dlm_print_rsb(r);
46684669
dlm_print_lkb(lkb);
46694670
}
@@ -4842,8 +4843,8 @@ static void receive_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms)
48424843
/* This should never happen */
48434844
log_error(ls, "receive_lookup_reply %x from %d ret %d "
48444845
"master %d dir %d our %d first %x %s",
4845-
lkb->lkb_id, ms->m_header.h_nodeid, ret_nodeid,
4846-
r->res_master_nodeid, r->res_dir_nodeid,
4846+
lkb->lkb_id, le32_to_cpu(ms->m_header.h_nodeid),
4847+
ret_nodeid, r->res_master_nodeid, r->res_dir_nodeid,
48474848
dlm_our_nodeid(), r->res_first_lkid, r->res_name);
48484849
}
48494850

@@ -4855,7 +4856,7 @@ static void receive_lookup_reply(struct dlm_ls *ls, struct dlm_message *ms)
48554856
} else if (ret_nodeid == -1) {
48564857
/* the remote node doesn't believe it's the dir node */
48574858
log_error(ls, "receive_lookup_reply %x from %d bad ret_nodeid",
4858-
lkb->lkb_id, ms->m_header.h_nodeid);
4859+
lkb->lkb_id, le32_to_cpu(ms->m_header.h_nodeid));
48594860
r->res_master_nodeid = 0;
48604861
r->res_nodeid = -1;
48614862
lkb->lkb_nodeid = -1;
@@ -4889,10 +4890,10 @@ static void _receive_message(struct dlm_ls *ls, struct dlm_message *ms,
48894890
{
48904891
int error = 0, noent = 0;
48914892

4892-
if (!dlm_is_member(ls, ms->m_header.h_nodeid)) {
4893+
if (!dlm_is_member(ls, le32_to_cpu(ms->m_header.h_nodeid))) {
48934894
log_limit(ls, "receive %d from non-member %d %x %x %d",
4894-
ms->m_type, ms->m_header.h_nodeid, ms->m_lkid,
4895-
ms->m_remid, ms->m_result);
4895+
ms->m_type, le32_to_cpu(ms->m_header.h_nodeid),
4896+
ms->m_lkid, ms->m_remid, ms->m_result);
48964897
return;
48974898
}
48984899

@@ -4986,11 +4987,13 @@ static void _receive_message(struct dlm_ls *ls, struct dlm_message *ms,
49864987

49874988
if (error == -ENOENT && noent) {
49884989
log_debug(ls, "receive %d no %x remote %d %x saved_seq %u",
4989-
ms->m_type, ms->m_remid, ms->m_header.h_nodeid,
4990+
ms->m_type, ms->m_remid,
4991+
le32_to_cpu(ms->m_header.h_nodeid),
49904992
ms->m_lkid, saved_seq);
49914993
} else if (error == -ENOENT) {
49924994
log_error(ls, "receive %d no %x remote %d %x saved_seq %u",
4993-
ms->m_type, ms->m_remid, ms->m_header.h_nodeid,
4995+
ms->m_type, ms->m_remid,
4996+
le32_to_cpu(ms->m_header.h_nodeid),
49944997
ms->m_lkid, saved_seq);
49954998

49964999
if (ms->m_type == DLM_MSG_CONVERT)
@@ -5000,7 +5003,7 @@ static void _receive_message(struct dlm_ls *ls, struct dlm_message *ms,
50005003
if (error == -EINVAL) {
50015004
log_error(ls, "receive %d inval from %d lkid %x remid %x "
50025005
"saved_seq %u",
5003-
ms->m_type, ms->m_header.h_nodeid,
5006+
ms->m_type, le32_to_cpu(ms->m_header.h_nodeid),
50045007
ms->m_lkid, ms->m_remid, saved_seq);
50055008
}
50065009
}
@@ -5067,18 +5070,20 @@ void dlm_receive_buffer(union dlm_packet *p, int nodeid)
50675070
return;
50685071
}
50695072

5070-
if (hd->h_nodeid != nodeid) {
5073+
if (le32_to_cpu(hd->h_nodeid) != nodeid) {
50715074
log_print("invalid h_nodeid %d from %d lockspace %x",
5072-
hd->h_nodeid, nodeid, hd->u.h_lockspace);
5075+
le32_to_cpu(hd->h_nodeid), nodeid,
5076+
le32_to_cpu(hd->u.h_lockspace));
50735077
return;
50745078
}
50755079

5076-
ls = dlm_find_lockspace_global(hd->u.h_lockspace);
5080+
ls = dlm_find_lockspace_global(le32_to_cpu(hd->u.h_lockspace));
50775081
if (!ls) {
50785082
if (dlm_config.ci_log_debug) {
50795083
printk_ratelimited(KERN_DEBUG "dlm: invalid lockspace "
50805084
"%u from %d cmd %d type %d\n",
5081-
hd->u.h_lockspace, nodeid, hd->h_cmd, type);
5085+
le32_to_cpu(hd->u.h_lockspace), nodeid,
5086+
hd->h_cmd, type);
50825087
}
50835088

50845089
if (hd->h_cmd == DLM_RCOM && type == DLM_RCOM_STATUS)
@@ -5108,7 +5113,7 @@ static void recover_convert_waiter(struct dlm_ls *ls, struct dlm_lkb *lkb,
51085113
ms_stub->m_flags = DLM_IFL_STUB_MS;
51095114
ms_stub->m_type = DLM_MSG_CONVERT_REPLY;
51105115
ms_stub->m_result = -EINPROGRESS;
5111-
ms_stub->m_header.h_nodeid = lkb->lkb_nodeid;
5116+
ms_stub->m_header.h_nodeid = cpu_to_le32(lkb->lkb_nodeid);
51125117
_receive_convert_reply(lkb, ms_stub);
51135118

51145119
/* Same special case as in receive_rcom_lock_args() */
@@ -5230,7 +5235,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls)
52305235
ms_stub->m_flags = DLM_IFL_STUB_MS;
52315236
ms_stub->m_type = DLM_MSG_UNLOCK_REPLY;
52325237
ms_stub->m_result = stub_unlock_result;
5233-
ms_stub->m_header.h_nodeid = lkb->lkb_nodeid;
5238+
ms_stub->m_header.h_nodeid = cpu_to_le32(lkb->lkb_nodeid);
52345239
_receive_unlock_reply(lkb, ms_stub);
52355240
dlm_put_lkb(lkb);
52365241
break;
@@ -5241,7 +5246,7 @@ void dlm_recover_waiters_pre(struct dlm_ls *ls)
52415246
ms_stub->m_flags = DLM_IFL_STUB_MS;
52425247
ms_stub->m_type = DLM_MSG_CANCEL_REPLY;
52435248
ms_stub->m_result = stub_cancel_result;
5244-
ms_stub->m_header.h_nodeid = lkb->lkb_nodeid;
5249+
ms_stub->m_header.h_nodeid = cpu_to_le32(lkb->lkb_nodeid);
52455250
_receive_cancel_reply(lkb, ms_stub);
52465251
dlm_put_lkb(lkb);
52475252
break;
@@ -5606,7 +5611,7 @@ static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
56065611
{
56075612
struct rcom_lock *rl = (struct rcom_lock *) rc->rc_buf;
56085613

5609-
lkb->lkb_nodeid = rc->rc_header.h_nodeid;
5614+
lkb->lkb_nodeid = le32_to_cpu(rc->rc_header.h_nodeid);
56105615
lkb->lkb_ownpid = le32_to_cpu(rl->rl_ownpid);
56115616
lkb->lkb_remid = le32_to_cpu(rl->rl_lkid);
56125617
lkb->lkb_exflags = le32_to_cpu(rl->rl_exflags);
@@ -5621,8 +5626,8 @@ static int receive_rcom_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
56215626
lkb->lkb_astfn = (rl->rl_asts & DLM_CB_CAST) ? &fake_astfn : NULL;
56225627

56235628
if (lkb->lkb_exflags & DLM_LKF_VALBLK) {
5624-
int lvblen = rc->rc_header.h_length - sizeof(struct dlm_rcom) -
5625-
sizeof(struct rcom_lock);
5629+
int lvblen = le16_to_cpu(rc->rc_header.h_length) -
5630+
sizeof(struct dlm_rcom) - sizeof(struct rcom_lock);
56265631
if (lvblen > ls->ls_lvblen)
56275632
return -EINVAL;
56285633
lkb->lkb_lvbptr = dlm_allocate_lvb(ls);
@@ -5658,7 +5663,7 @@ int dlm_recover_master_copy(struct dlm_ls *ls, struct dlm_rcom *rc)
56585663
struct dlm_rsb *r;
56595664
struct dlm_lkb *lkb;
56605665
uint32_t remid = 0;
5661-
int from_nodeid = rc->rc_header.h_nodeid;
5666+
int from_nodeid = le32_to_cpu(rc->rc_header.h_nodeid);
56625667
int error;
56635668

56645669
if (rl->rl_parent_lkid) {
@@ -5748,7 +5753,8 @@ int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc)
57485753
error = find_lkb(ls, lkid, &lkb);
57495754
if (error) {
57505755
log_error(ls, "dlm_recover_process_copy no %x remote %d %x %d",
5751-
lkid, rc->rc_header.h_nodeid, remid, result);
5756+
lkid, le32_to_cpu(rc->rc_header.h_nodeid), remid,
5757+
result);
57525758
return error;
57535759
}
57545760

@@ -5758,7 +5764,8 @@ int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc)
57585764

57595765
if (!is_process_copy(lkb)) {
57605766
log_error(ls, "dlm_recover_process_copy bad %x remote %d %x %d",
5761-
lkid, rc->rc_header.h_nodeid, remid, result);
5767+
lkid, le32_to_cpu(rc->rc_header.h_nodeid), remid,
5768+
result);
57625769
dlm_dump_rsb(r);
57635770
unlock_rsb(r);
57645771
put_rsb(r);
@@ -5773,7 +5780,8 @@ int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc)
57735780
a barrier between recover_masters and recover_locks. */
57745781

57755782
log_debug(ls, "dlm_recover_process_copy %x remote %d %x %d",
5776-
lkid, rc->rc_header.h_nodeid, remid, result);
5783+
lkid, le32_to_cpu(rc->rc_header.h_nodeid), remid,
5784+
result);
57775785

57785786
dlm_send_rcom_lock(r, lkb);
57795787
goto out;
@@ -5783,7 +5791,8 @@ int dlm_recover_process_copy(struct dlm_ls *ls, struct dlm_rcom *rc)
57835791
break;
57845792
default:
57855793
log_error(ls, "dlm_recover_process_copy %x remote %d %x %d unk",
5786-
lkid, rc->rc_header.h_nodeid, remid, result);
5794+
lkid, le32_to_cpu(rc->rc_header.h_nodeid), remid,
5795+
result);
57875796
}
57885797

57895798
/* an ack for dlm_recover_locks() which waits for replies from

fs/dlm/member.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
int dlm_slots_version(struct dlm_header *h)
2222
{
23-
if ((h->h_version & 0x0000FFFF) < DLM_HEADER_SLOTS)
23+
if ((le32_to_cpu(h->h_version) & 0x0000FFFF) < DLM_HEADER_SLOTS)
2424
return 0;
2525
return 1;
2626
}

0 commit comments

Comments
 (0)