blob: 58acbcc2081ad5328729ce9706bdad2fd3e57f8b [file] [log] [blame]
Thomas Gleixner2522fe42019-05-28 09:57:20 -07001// SPDX-License-Identifier: GPL-2.0-only
David Teiglande7fd4172006-01-18 09:30:29 +00002/******************************************************************************
3*******************************************************************************
4**
David Teiglanddbcfc342008-01-29 14:52:10 -06005** Copyright (C) 2005-2008 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00006**
David Teiglande7fd4172006-01-18 09:30:29 +00007**
8*******************************************************************************
9******************************************************************************/
10
11#include "dlm_internal.h"
12#include "rcom.h"
13#include "util.h"
14
David Teigland861e23692008-01-15 15:43:24 -060015#define DLM_ERRNO_EDEADLK 35
16#define DLM_ERRNO_EBADR 53
17#define DLM_ERRNO_EBADSLT 57
18#define DLM_ERRNO_EPROTO 71
19#define DLM_ERRNO_EOPNOTSUPP 95
20#define DLM_ERRNO_ETIMEDOUT 110
21#define DLM_ERRNO_EINPROGRESS 115
22
Alexander Aring6fb5cf92021-05-21 15:08:40 -040023void header_out(struct dlm_header *hd)
David Teiglande7fd4172006-01-18 09:30:29 +000024{
25 hd->h_version = cpu_to_le32(hd->h_version);
Alexander Aring8e2e4082021-05-21 15:08:45 -040026 /* does it for others u32 in union as well */
27 hd->u.h_lockspace = cpu_to_le32(hd->u.h_lockspace);
David Teiglande7fd4172006-01-18 09:30:29 +000028 hd->h_nodeid = cpu_to_le32(hd->h_nodeid);
29 hd->h_length = cpu_to_le16(hd->h_length);
30}
31
Alexander Aring6fb5cf92021-05-21 15:08:40 -040032void header_in(struct dlm_header *hd)
David Teiglande7fd4172006-01-18 09:30:29 +000033{
34 hd->h_version = le32_to_cpu(hd->h_version);
Alexander Aring8e2e4082021-05-21 15:08:45 -040035 /* does it for others u32 in union as well */
36 hd->u.h_lockspace = le32_to_cpu(hd->u.h_lockspace);
David Teiglande7fd4172006-01-18 09:30:29 +000037 hd->h_nodeid = le32_to_cpu(hd->h_nodeid);
38 hd->h_length = le16_to_cpu(hd->h_length);
39}
40
David Teigland861e23692008-01-15 15:43:24 -060041/* higher errno values are inconsistent across architectures, so select
42 one set of values for on the wire */
43
44static int to_dlm_errno(int err)
45{
46 switch (err) {
47 case -EDEADLK:
48 return -DLM_ERRNO_EDEADLK;
49 case -EBADR:
50 return -DLM_ERRNO_EBADR;
51 case -EBADSLT:
52 return -DLM_ERRNO_EBADSLT;
53 case -EPROTO:
54 return -DLM_ERRNO_EPROTO;
55 case -EOPNOTSUPP:
56 return -DLM_ERRNO_EOPNOTSUPP;
57 case -ETIMEDOUT:
58 return -DLM_ERRNO_ETIMEDOUT;
59 case -EINPROGRESS:
60 return -DLM_ERRNO_EINPROGRESS;
61 }
62 return err;
63}
64
65static int from_dlm_errno(int err)
66{
67 switch (err) {
68 case -DLM_ERRNO_EDEADLK:
69 return -EDEADLK;
70 case -DLM_ERRNO_EBADR:
71 return -EBADR;
72 case -DLM_ERRNO_EBADSLT:
73 return -EBADSLT;
74 case -DLM_ERRNO_EPROTO:
75 return -EPROTO;
76 case -DLM_ERRNO_EOPNOTSUPP:
77 return -EOPNOTSUPP;
78 case -DLM_ERRNO_ETIMEDOUT:
79 return -ETIMEDOUT;
80 case -DLM_ERRNO_EINPROGRESS:
81 return -EINPROGRESS;
82 }
83 return err;
84}
85
David Teiglande7fd4172006-01-18 09:30:29 +000086void dlm_message_out(struct dlm_message *ms)
87{
David Teiglanddbcfc342008-01-29 14:52:10 -060088 header_out(&ms->m_header);
David Teiglande7fd4172006-01-18 09:30:29 +000089
90 ms->m_type = cpu_to_le32(ms->m_type);
91 ms->m_nodeid = cpu_to_le32(ms->m_nodeid);
92 ms->m_pid = cpu_to_le32(ms->m_pid);
93 ms->m_lkid = cpu_to_le32(ms->m_lkid);
94 ms->m_remid = cpu_to_le32(ms->m_remid);
95 ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid);
96 ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid);
97 ms->m_exflags = cpu_to_le32(ms->m_exflags);
98 ms->m_sbflags = cpu_to_le32(ms->m_sbflags);
99 ms->m_flags = cpu_to_le32(ms->m_flags);
100 ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq);
101 ms->m_hash = cpu_to_le32(ms->m_hash);
102 ms->m_status = cpu_to_le32(ms->m_status);
103 ms->m_grmode = cpu_to_le32(ms->m_grmode);
104 ms->m_rqmode = cpu_to_le32(ms->m_rqmode);
105 ms->m_bastmode = cpu_to_le32(ms->m_bastmode);
106 ms->m_asts = cpu_to_le32(ms->m_asts);
David Teigland861e23692008-01-15 15:43:24 -0600107 ms->m_result = cpu_to_le32(to_dlm_errno(ms->m_result));
David Teiglande7fd4172006-01-18 09:30:29 +0000108}
109
110void dlm_message_in(struct dlm_message *ms)
111{
David Teiglanddbcfc342008-01-29 14:52:10 -0600112 header_in(&ms->m_header);
David Teiglande7fd4172006-01-18 09:30:29 +0000113
114 ms->m_type = le32_to_cpu(ms->m_type);
115 ms->m_nodeid = le32_to_cpu(ms->m_nodeid);
116 ms->m_pid = le32_to_cpu(ms->m_pid);
117 ms->m_lkid = le32_to_cpu(ms->m_lkid);
118 ms->m_remid = le32_to_cpu(ms->m_remid);
119 ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid);
120 ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid);
121 ms->m_exflags = le32_to_cpu(ms->m_exflags);
122 ms->m_sbflags = le32_to_cpu(ms->m_sbflags);
123 ms->m_flags = le32_to_cpu(ms->m_flags);
124 ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq);
125 ms->m_hash = le32_to_cpu(ms->m_hash);
126 ms->m_status = le32_to_cpu(ms->m_status);
127 ms->m_grmode = le32_to_cpu(ms->m_grmode);
128 ms->m_rqmode = le32_to_cpu(ms->m_rqmode);
129 ms->m_bastmode = le32_to_cpu(ms->m_bastmode);
130 ms->m_asts = le32_to_cpu(ms->m_asts);
David Teigland861e23692008-01-15 15:43:24 -0600131 ms->m_result = from_dlm_errno(le32_to_cpu(ms->m_result));
David Teiglande7fd4172006-01-18 09:30:29 +0000132}
133
David Teiglande7fd4172006-01-18 09:30:29 +0000134void dlm_rcom_out(struct dlm_rcom *rc)
135{
David Teiglanddbcfc342008-01-29 14:52:10 -0600136 header_out(&rc->rc_header);
David Teiglande7fd4172006-01-18 09:30:29 +0000137
138 rc->rc_type = cpu_to_le32(rc->rc_type);
139 rc->rc_result = cpu_to_le32(rc->rc_result);
140 rc->rc_id = cpu_to_le64(rc->rc_id);
David Teigland38aa8b02006-12-13 10:37:16 -0600141 rc->rc_seq = cpu_to_le64(rc->rc_seq);
142 rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply);
David Teiglande7fd4172006-01-18 09:30:29 +0000143}
144
145void dlm_rcom_in(struct dlm_rcom *rc)
146{
David Teiglanddbcfc342008-01-29 14:52:10 -0600147 header_in(&rc->rc_header);
David Teiglande7fd4172006-01-18 09:30:29 +0000148
149 rc->rc_type = le32_to_cpu(rc->rc_type);
150 rc->rc_result = le32_to_cpu(rc->rc_result);
151 rc->rc_id = le64_to_cpu(rc->rc_id);
David Teigland38aa8b02006-12-13 10:37:16 -0600152 rc->rc_seq = le64_to_cpu(rc->rc_seq);
153 rc->rc_seq_reply = le64_to_cpu(rc->rc_seq_reply);
David Teiglande7fd4172006-01-18 09:30:29 +0000154}