Commit | Line | Data |
---|---|---|
e7fd4179 DT |
1 | /****************************************************************************** |
2 | ******************************************************************************* | |
3 | ** | |
4 | ** Copyright (C) 2005 Red Hat, Inc. All rights reserved. | |
5 | ** | |
6 | ** This copyrighted material is made available to anyone wishing to use, | |
7 | ** modify, copy, or redistribute it subject to the terms and conditions | |
8 | ** of the GNU General Public License v.2. | |
9 | ** | |
10 | ******************************************************************************* | |
11 | ******************************************************************************/ | |
12 | ||
13 | #include "dlm_internal.h" | |
14 | #include "rcom.h" | |
15 | #include "util.h" | |
16 | ||
861e2369 DT |
17 | #define DLM_ERRNO_EDEADLK 35 |
18 | #define DLM_ERRNO_EBADR 53 | |
19 | #define DLM_ERRNO_EBADSLT 57 | |
20 | #define DLM_ERRNO_EPROTO 71 | |
21 | #define DLM_ERRNO_EOPNOTSUPP 95 | |
22 | #define DLM_ERRNO_ETIMEDOUT 110 | |
23 | #define DLM_ERRNO_EINPROGRESS 115 | |
24 | ||
e7fd4179 DT |
25 | static void header_out(struct dlm_header *hd) |
26 | { | |
27 | hd->h_version = cpu_to_le32(hd->h_version); | |
28 | hd->h_lockspace = cpu_to_le32(hd->h_lockspace); | |
29 | hd->h_nodeid = cpu_to_le32(hd->h_nodeid); | |
30 | hd->h_length = cpu_to_le16(hd->h_length); | |
31 | } | |
32 | ||
33 | static void header_in(struct dlm_header *hd) | |
34 | { | |
35 | hd->h_version = le32_to_cpu(hd->h_version); | |
36 | hd->h_lockspace = le32_to_cpu(hd->h_lockspace); | |
37 | hd->h_nodeid = le32_to_cpu(hd->h_nodeid); | |
38 | hd->h_length = le16_to_cpu(hd->h_length); | |
39 | } | |
40 | ||
861e2369 DT |
41 | /* higher errno values are inconsistent across architectures, so select |
42 | one set of values for on the wire */ | |
43 | ||
44 | static 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 | ||
65 | static 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 | ||
e7fd4179 DT |
86 | void dlm_message_out(struct dlm_message *ms) |
87 | { | |
88 | struct dlm_header *hd = (struct dlm_header *) ms; | |
89 | ||
90 | header_out(hd); | |
91 | ||
92 | ms->m_type = cpu_to_le32(ms->m_type); | |
93 | ms->m_nodeid = cpu_to_le32(ms->m_nodeid); | |
94 | ms->m_pid = cpu_to_le32(ms->m_pid); | |
95 | ms->m_lkid = cpu_to_le32(ms->m_lkid); | |
96 | ms->m_remid = cpu_to_le32(ms->m_remid); | |
97 | ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid); | |
98 | ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid); | |
99 | ms->m_exflags = cpu_to_le32(ms->m_exflags); | |
100 | ms->m_sbflags = cpu_to_le32(ms->m_sbflags); | |
101 | ms->m_flags = cpu_to_le32(ms->m_flags); | |
102 | ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq); | |
103 | ms->m_hash = cpu_to_le32(ms->m_hash); | |
104 | ms->m_status = cpu_to_le32(ms->m_status); | |
105 | ms->m_grmode = cpu_to_le32(ms->m_grmode); | |
106 | ms->m_rqmode = cpu_to_le32(ms->m_rqmode); | |
107 | ms->m_bastmode = cpu_to_le32(ms->m_bastmode); | |
108 | ms->m_asts = cpu_to_le32(ms->m_asts); | |
861e2369 | 109 | ms->m_result = cpu_to_le32(to_dlm_errno(ms->m_result)); |
e7fd4179 DT |
110 | } |
111 | ||
112 | void dlm_message_in(struct dlm_message *ms) | |
113 | { | |
114 | struct dlm_header *hd = (struct dlm_header *) ms; | |
115 | ||
116 | header_in(hd); | |
117 | ||
118 | ms->m_type = le32_to_cpu(ms->m_type); | |
119 | ms->m_nodeid = le32_to_cpu(ms->m_nodeid); | |
120 | ms->m_pid = le32_to_cpu(ms->m_pid); | |
121 | ms->m_lkid = le32_to_cpu(ms->m_lkid); | |
122 | ms->m_remid = le32_to_cpu(ms->m_remid); | |
123 | ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid); | |
124 | ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid); | |
125 | ms->m_exflags = le32_to_cpu(ms->m_exflags); | |
126 | ms->m_sbflags = le32_to_cpu(ms->m_sbflags); | |
127 | ms->m_flags = le32_to_cpu(ms->m_flags); | |
128 | ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq); | |
129 | ms->m_hash = le32_to_cpu(ms->m_hash); | |
130 | ms->m_status = le32_to_cpu(ms->m_status); | |
131 | ms->m_grmode = le32_to_cpu(ms->m_grmode); | |
132 | ms->m_rqmode = le32_to_cpu(ms->m_rqmode); | |
133 | ms->m_bastmode = le32_to_cpu(ms->m_bastmode); | |
134 | ms->m_asts = le32_to_cpu(ms->m_asts); | |
861e2369 | 135 | ms->m_result = from_dlm_errno(le32_to_cpu(ms->m_result)); |
e7fd4179 DT |
136 | } |
137 | ||
138 | static void rcom_lock_out(struct rcom_lock *rl) | |
139 | { | |
140 | rl->rl_ownpid = cpu_to_le32(rl->rl_ownpid); | |
141 | rl->rl_lkid = cpu_to_le32(rl->rl_lkid); | |
142 | rl->rl_remid = cpu_to_le32(rl->rl_remid); | |
143 | rl->rl_parent_lkid = cpu_to_le32(rl->rl_parent_lkid); | |
144 | rl->rl_parent_remid = cpu_to_le32(rl->rl_parent_remid); | |
145 | rl->rl_exflags = cpu_to_le32(rl->rl_exflags); | |
146 | rl->rl_flags = cpu_to_le32(rl->rl_flags); | |
147 | rl->rl_lvbseq = cpu_to_le32(rl->rl_lvbseq); | |
148 | rl->rl_result = cpu_to_le32(rl->rl_result); | |
149 | rl->rl_wait_type = cpu_to_le16(rl->rl_wait_type); | |
150 | rl->rl_namelen = cpu_to_le16(rl->rl_namelen); | |
e7fd4179 DT |
151 | } |
152 | ||
153 | static void rcom_lock_in(struct rcom_lock *rl) | |
154 | { | |
155 | rl->rl_ownpid = le32_to_cpu(rl->rl_ownpid); | |
156 | rl->rl_lkid = le32_to_cpu(rl->rl_lkid); | |
157 | rl->rl_remid = le32_to_cpu(rl->rl_remid); | |
158 | rl->rl_parent_lkid = le32_to_cpu(rl->rl_parent_lkid); | |
159 | rl->rl_parent_remid = le32_to_cpu(rl->rl_parent_remid); | |
160 | rl->rl_exflags = le32_to_cpu(rl->rl_exflags); | |
161 | rl->rl_flags = le32_to_cpu(rl->rl_flags); | |
162 | rl->rl_lvbseq = le32_to_cpu(rl->rl_lvbseq); | |
163 | rl->rl_result = le32_to_cpu(rl->rl_result); | |
164 | rl->rl_wait_type = le16_to_cpu(rl->rl_wait_type); | |
165 | rl->rl_namelen = le16_to_cpu(rl->rl_namelen); | |
e7fd4179 DT |
166 | } |
167 | ||
168 | static void rcom_config_out(struct rcom_config *rf) | |
169 | { | |
170 | rf->rf_lvblen = cpu_to_le32(rf->rf_lvblen); | |
171 | rf->rf_lsflags = cpu_to_le32(rf->rf_lsflags); | |
172 | } | |
173 | ||
174 | static void rcom_config_in(struct rcom_config *rf) | |
175 | { | |
176 | rf->rf_lvblen = le32_to_cpu(rf->rf_lvblen); | |
177 | rf->rf_lsflags = le32_to_cpu(rf->rf_lsflags); | |
178 | } | |
179 | ||
180 | void dlm_rcom_out(struct dlm_rcom *rc) | |
181 | { | |
182 | struct dlm_header *hd = (struct dlm_header *) rc; | |
183 | int type = rc->rc_type; | |
184 | ||
185 | header_out(hd); | |
186 | ||
187 | rc->rc_type = cpu_to_le32(rc->rc_type); | |
188 | rc->rc_result = cpu_to_le32(rc->rc_result); | |
189 | rc->rc_id = cpu_to_le64(rc->rc_id); | |
38aa8b0c DT |
190 | rc->rc_seq = cpu_to_le64(rc->rc_seq); |
191 | rc->rc_seq_reply = cpu_to_le64(rc->rc_seq_reply); | |
e7fd4179 | 192 | |
550283e3 | 193 | if ((type == DLM_RCOM_LOCK) || (type == DLM_RCOM_LOCK_REPLY)) |
e7fd4179 DT |
194 | rcom_lock_out((struct rcom_lock *) rc->rc_buf); |
195 | ||
196 | else if (type == DLM_RCOM_STATUS_REPLY) | |
197 | rcom_config_out((struct rcom_config *) rc->rc_buf); | |
198 | } | |
199 | ||
200 | void dlm_rcom_in(struct dlm_rcom *rc) | |
201 | { | |
202 | struct dlm_header *hd = (struct dlm_header *) rc; | |
550283e3 | 203 | int type; |
e7fd4179 DT |
204 | |
205 | header_in(hd); | |
206 | ||
207 | rc->rc_type = le32_to_cpu(rc->rc_type); | |
208 | rc->rc_result = le32_to_cpu(rc->rc_result); | |
209 | rc->rc_id = le64_to_cpu(rc->rc_id); | |
38aa8b0c DT |
210 | rc->rc_seq = le64_to_cpu(rc->rc_seq); |
211 | rc->rc_seq_reply = le64_to_cpu(rc->rc_seq_reply); | |
e7fd4179 | 212 | |
550283e3 FDN |
213 | type = rc->rc_type; |
214 | ||
215 | if ((type == DLM_RCOM_LOCK) || (type == DLM_RCOM_LOCK_REPLY)) | |
e7fd4179 DT |
216 | rcom_lock_in((struct rcom_lock *) rc->rc_buf); |
217 | ||
550283e3 | 218 | else if (type == DLM_RCOM_STATUS_REPLY) |
e7fd4179 DT |
219 | rcom_config_in((struct rcom_config *) rc->rc_buf); |
220 | } | |
221 |