diff options
Diffstat (limited to 'fs/dlm/util.c')
-rw-r--r-- | fs/dlm/util.c | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/fs/dlm/util.c b/fs/dlm/util.c new file mode 100644 index 000000000000..826d122edf55 --- /dev/null +++ b/fs/dlm/util.c | |||
@@ -0,0 +1,173 @@ | |||
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 | |||
17 | static void header_out(struct dlm_header *hd) | ||
18 | { | ||
19 | hd->h_version = cpu_to_le32(hd->h_version); | ||
20 | hd->h_lockspace = cpu_to_le32(hd->h_lockspace); | ||
21 | hd->h_nodeid = cpu_to_le32(hd->h_nodeid); | ||
22 | hd->h_length = cpu_to_le16(hd->h_length); | ||
23 | } | ||
24 | |||
25 | static void header_in(struct dlm_header *hd) | ||
26 | { | ||
27 | hd->h_version = le32_to_cpu(hd->h_version); | ||
28 | hd->h_lockspace = le32_to_cpu(hd->h_lockspace); | ||
29 | hd->h_nodeid = le32_to_cpu(hd->h_nodeid); | ||
30 | hd->h_length = le16_to_cpu(hd->h_length); | ||
31 | } | ||
32 | |||
33 | void dlm_message_out(struct dlm_message *ms) | ||
34 | { | ||
35 | struct dlm_header *hd = (struct dlm_header *) ms; | ||
36 | |||
37 | header_out(hd); | ||
38 | |||
39 | ms->m_type = cpu_to_le32(ms->m_type); | ||
40 | ms->m_nodeid = cpu_to_le32(ms->m_nodeid); | ||
41 | ms->m_pid = cpu_to_le32(ms->m_pid); | ||
42 | ms->m_lkid = cpu_to_le32(ms->m_lkid); | ||
43 | ms->m_remid = cpu_to_le32(ms->m_remid); | ||
44 | ms->m_parent_lkid = cpu_to_le32(ms->m_parent_lkid); | ||
45 | ms->m_parent_remid = cpu_to_le32(ms->m_parent_remid); | ||
46 | ms->m_exflags = cpu_to_le32(ms->m_exflags); | ||
47 | ms->m_sbflags = cpu_to_le32(ms->m_sbflags); | ||
48 | ms->m_flags = cpu_to_le32(ms->m_flags); | ||
49 | ms->m_lvbseq = cpu_to_le32(ms->m_lvbseq); | ||
50 | ms->m_hash = cpu_to_le32(ms->m_hash); | ||
51 | ms->m_status = cpu_to_le32(ms->m_status); | ||
52 | ms->m_grmode = cpu_to_le32(ms->m_grmode); | ||
53 | ms->m_rqmode = cpu_to_le32(ms->m_rqmode); | ||
54 | ms->m_bastmode = cpu_to_le32(ms->m_bastmode); | ||
55 | ms->m_asts = cpu_to_le32(ms->m_asts); | ||
56 | ms->m_result = cpu_to_le32(ms->m_result); | ||
57 | ms->m_range[0] = cpu_to_le64(ms->m_range[0]); | ||
58 | ms->m_range[1] = cpu_to_le64(ms->m_range[1]); | ||
59 | } | ||
60 | |||
61 | void dlm_message_in(struct dlm_message *ms) | ||
62 | { | ||
63 | struct dlm_header *hd = (struct dlm_header *) ms; | ||
64 | |||
65 | header_in(hd); | ||
66 | |||
67 | ms->m_type = le32_to_cpu(ms->m_type); | ||
68 | ms->m_nodeid = le32_to_cpu(ms->m_nodeid); | ||
69 | ms->m_pid = le32_to_cpu(ms->m_pid); | ||
70 | ms->m_lkid = le32_to_cpu(ms->m_lkid); | ||
71 | ms->m_remid = le32_to_cpu(ms->m_remid); | ||
72 | ms->m_parent_lkid = le32_to_cpu(ms->m_parent_lkid); | ||
73 | ms->m_parent_remid = le32_to_cpu(ms->m_parent_remid); | ||
74 | ms->m_exflags = le32_to_cpu(ms->m_exflags); | ||
75 | ms->m_sbflags = le32_to_cpu(ms->m_sbflags); | ||
76 | ms->m_flags = le32_to_cpu(ms->m_flags); | ||
77 | ms->m_lvbseq = le32_to_cpu(ms->m_lvbseq); | ||
78 | ms->m_hash = le32_to_cpu(ms->m_hash); | ||
79 | ms->m_status = le32_to_cpu(ms->m_status); | ||
80 | ms->m_grmode = le32_to_cpu(ms->m_grmode); | ||
81 | ms->m_rqmode = le32_to_cpu(ms->m_rqmode); | ||
82 | ms->m_bastmode = le32_to_cpu(ms->m_bastmode); | ||
83 | ms->m_asts = le32_to_cpu(ms->m_asts); | ||
84 | ms->m_result = le32_to_cpu(ms->m_result); | ||
85 | ms->m_range[0] = le64_to_cpu(ms->m_range[0]); | ||
86 | ms->m_range[1] = le64_to_cpu(ms->m_range[1]); | ||
87 | } | ||
88 | |||
89 | static void rcom_lock_out(struct rcom_lock *rl) | ||
90 | { | ||
91 | rl->rl_ownpid = cpu_to_le32(rl->rl_ownpid); | ||
92 | rl->rl_lkid = cpu_to_le32(rl->rl_lkid); | ||
93 | rl->rl_remid = cpu_to_le32(rl->rl_remid); | ||
94 | rl->rl_parent_lkid = cpu_to_le32(rl->rl_parent_lkid); | ||
95 | rl->rl_parent_remid = cpu_to_le32(rl->rl_parent_remid); | ||
96 | rl->rl_exflags = cpu_to_le32(rl->rl_exflags); | ||
97 | rl->rl_flags = cpu_to_le32(rl->rl_flags); | ||
98 | rl->rl_lvbseq = cpu_to_le32(rl->rl_lvbseq); | ||
99 | rl->rl_result = cpu_to_le32(rl->rl_result); | ||
100 | rl->rl_wait_type = cpu_to_le16(rl->rl_wait_type); | ||
101 | rl->rl_namelen = cpu_to_le16(rl->rl_namelen); | ||
102 | rl->rl_range[0] = cpu_to_le64(rl->rl_range[0]); | ||
103 | rl->rl_range[1] = cpu_to_le64(rl->rl_range[1]); | ||
104 | rl->rl_range[2] = cpu_to_le64(rl->rl_range[2]); | ||
105 | rl->rl_range[3] = cpu_to_le64(rl->rl_range[3]); | ||
106 | } | ||
107 | |||
108 | static void rcom_lock_in(struct rcom_lock *rl) | ||
109 | { | ||
110 | rl->rl_ownpid = le32_to_cpu(rl->rl_ownpid); | ||
111 | rl->rl_lkid = le32_to_cpu(rl->rl_lkid); | ||
112 | rl->rl_remid = le32_to_cpu(rl->rl_remid); | ||
113 | rl->rl_parent_lkid = le32_to_cpu(rl->rl_parent_lkid); | ||
114 | rl->rl_parent_remid = le32_to_cpu(rl->rl_parent_remid); | ||
115 | rl->rl_exflags = le32_to_cpu(rl->rl_exflags); | ||
116 | rl->rl_flags = le32_to_cpu(rl->rl_flags); | ||
117 | rl->rl_lvbseq = le32_to_cpu(rl->rl_lvbseq); | ||
118 | rl->rl_result = le32_to_cpu(rl->rl_result); | ||
119 | rl->rl_wait_type = le16_to_cpu(rl->rl_wait_type); | ||
120 | rl->rl_namelen = le16_to_cpu(rl->rl_namelen); | ||
121 | rl->rl_range[0] = le64_to_cpu(rl->rl_range[0]); | ||
122 | rl->rl_range[1] = le64_to_cpu(rl->rl_range[1]); | ||
123 | rl->rl_range[2] = le64_to_cpu(rl->rl_range[2]); | ||
124 | rl->rl_range[3] = le64_to_cpu(rl->rl_range[3]); | ||
125 | } | ||
126 | |||
127 | static void rcom_config_out(struct rcom_config *rf) | ||
128 | { | ||
129 | rf->rf_lvblen = cpu_to_le32(rf->rf_lvblen); | ||
130 | rf->rf_lsflags = cpu_to_le32(rf->rf_lsflags); | ||
131 | } | ||
132 | |||
133 | static void rcom_config_in(struct rcom_config *rf) | ||
134 | { | ||
135 | rf->rf_lvblen = le32_to_cpu(rf->rf_lvblen); | ||
136 | rf->rf_lsflags = le32_to_cpu(rf->rf_lsflags); | ||
137 | } | ||
138 | |||
139 | void dlm_rcom_out(struct dlm_rcom *rc) | ||
140 | { | ||
141 | struct dlm_header *hd = (struct dlm_header *) rc; | ||
142 | int type = rc->rc_type; | ||
143 | |||
144 | header_out(hd); | ||
145 | |||
146 | rc->rc_type = cpu_to_le32(rc->rc_type); | ||
147 | rc->rc_result = cpu_to_le32(rc->rc_result); | ||
148 | rc->rc_id = cpu_to_le64(rc->rc_id); | ||
149 | |||
150 | if (type == DLM_RCOM_LOCK) | ||
151 | rcom_lock_out((struct rcom_lock *) rc->rc_buf); | ||
152 | |||
153 | else if (type == DLM_RCOM_STATUS_REPLY) | ||
154 | rcom_config_out((struct rcom_config *) rc->rc_buf); | ||
155 | } | ||
156 | |||
157 | void dlm_rcom_in(struct dlm_rcom *rc) | ||
158 | { | ||
159 | struct dlm_header *hd = (struct dlm_header *) rc; | ||
160 | |||
161 | header_in(hd); | ||
162 | |||
163 | rc->rc_type = le32_to_cpu(rc->rc_type); | ||
164 | rc->rc_result = le32_to_cpu(rc->rc_result); | ||
165 | rc->rc_id = le64_to_cpu(rc->rc_id); | ||
166 | |||
167 | if (rc->rc_type == DLM_RCOM_LOCK) | ||
168 | rcom_lock_in((struct rcom_lock *) rc->rc_buf); | ||
169 | |||
170 | else if (rc->rc_type == DLM_RCOM_STATUS_REPLY) | ||
171 | rcom_config_in((struct rcom_config *) rc->rc_buf); | ||
172 | } | ||
173 | |||