xref: /linux/fs/dlm/util.c (revision 38aa8b0c59c35d10d15ebf00ceee641f9ed7acba)
1e7fd4179SDavid Teigland /******************************************************************************
2e7fd4179SDavid Teigland *******************************************************************************
3e7fd4179SDavid Teigland **
4e7fd4179SDavid Teigland **  Copyright (C) 2005 Red Hat, Inc.  All rights reserved.
5e7fd4179SDavid Teigland **
6e7fd4179SDavid Teigland **  This copyrighted material is made available to anyone wishing to use,
7e7fd4179SDavid Teigland **  modify, copy, or redistribute it subject to the terms and conditions
8e7fd4179SDavid Teigland **  of the GNU General Public License v.2.
9e7fd4179SDavid Teigland **
10e7fd4179SDavid Teigland *******************************************************************************
11e7fd4179SDavid Teigland ******************************************************************************/
12e7fd4179SDavid Teigland 
13e7fd4179SDavid Teigland #include "dlm_internal.h"
14e7fd4179SDavid Teigland #include "rcom.h"
15e7fd4179SDavid Teigland #include "util.h"
16e7fd4179SDavid Teigland 
17e7fd4179SDavid Teigland static void header_out(struct dlm_header *hd)
18e7fd4179SDavid Teigland {
19e7fd4179SDavid Teigland 	hd->h_version		= cpu_to_le32(hd->h_version);
20e7fd4179SDavid Teigland 	hd->h_lockspace		= cpu_to_le32(hd->h_lockspace);
21e7fd4179SDavid Teigland 	hd->h_nodeid		= cpu_to_le32(hd->h_nodeid);
22e7fd4179SDavid Teigland 	hd->h_length		= cpu_to_le16(hd->h_length);
23e7fd4179SDavid Teigland }
24e7fd4179SDavid Teigland 
25e7fd4179SDavid Teigland static void header_in(struct dlm_header *hd)
26e7fd4179SDavid Teigland {
27e7fd4179SDavid Teigland 	hd->h_version		= le32_to_cpu(hd->h_version);
28e7fd4179SDavid Teigland 	hd->h_lockspace		= le32_to_cpu(hd->h_lockspace);
29e7fd4179SDavid Teigland 	hd->h_nodeid		= le32_to_cpu(hd->h_nodeid);
30e7fd4179SDavid Teigland 	hd->h_length		= le16_to_cpu(hd->h_length);
31e7fd4179SDavid Teigland }
32e7fd4179SDavid Teigland 
33e7fd4179SDavid Teigland void dlm_message_out(struct dlm_message *ms)
34e7fd4179SDavid Teigland {
35e7fd4179SDavid Teigland 	struct dlm_header *hd = (struct dlm_header *) ms;
36e7fd4179SDavid Teigland 
37e7fd4179SDavid Teigland 	header_out(hd);
38e7fd4179SDavid Teigland 
39e7fd4179SDavid Teigland 	ms->m_type		= cpu_to_le32(ms->m_type);
40e7fd4179SDavid Teigland 	ms->m_nodeid		= cpu_to_le32(ms->m_nodeid);
41e7fd4179SDavid Teigland 	ms->m_pid		= cpu_to_le32(ms->m_pid);
42e7fd4179SDavid Teigland 	ms->m_lkid		= cpu_to_le32(ms->m_lkid);
43e7fd4179SDavid Teigland 	ms->m_remid		= cpu_to_le32(ms->m_remid);
44e7fd4179SDavid Teigland 	ms->m_parent_lkid	= cpu_to_le32(ms->m_parent_lkid);
45e7fd4179SDavid Teigland 	ms->m_parent_remid	= cpu_to_le32(ms->m_parent_remid);
46e7fd4179SDavid Teigland 	ms->m_exflags		= cpu_to_le32(ms->m_exflags);
47e7fd4179SDavid Teigland 	ms->m_sbflags		= cpu_to_le32(ms->m_sbflags);
48e7fd4179SDavid Teigland 	ms->m_flags		= cpu_to_le32(ms->m_flags);
49e7fd4179SDavid Teigland 	ms->m_lvbseq		= cpu_to_le32(ms->m_lvbseq);
50e7fd4179SDavid Teigland 	ms->m_hash		= cpu_to_le32(ms->m_hash);
51e7fd4179SDavid Teigland 	ms->m_status		= cpu_to_le32(ms->m_status);
52e7fd4179SDavid Teigland 	ms->m_grmode		= cpu_to_le32(ms->m_grmode);
53e7fd4179SDavid Teigland 	ms->m_rqmode		= cpu_to_le32(ms->m_rqmode);
54e7fd4179SDavid Teigland 	ms->m_bastmode		= cpu_to_le32(ms->m_bastmode);
55e7fd4179SDavid Teigland 	ms->m_asts		= cpu_to_le32(ms->m_asts);
56e7fd4179SDavid Teigland 	ms->m_result		= cpu_to_le32(ms->m_result);
57e7fd4179SDavid Teigland }
58e7fd4179SDavid Teigland 
59e7fd4179SDavid Teigland void dlm_message_in(struct dlm_message *ms)
60e7fd4179SDavid Teigland {
61e7fd4179SDavid Teigland 	struct dlm_header *hd = (struct dlm_header *) ms;
62e7fd4179SDavid Teigland 
63e7fd4179SDavid Teigland 	header_in(hd);
64e7fd4179SDavid Teigland 
65e7fd4179SDavid Teigland 	ms->m_type		= le32_to_cpu(ms->m_type);
66e7fd4179SDavid Teigland 	ms->m_nodeid		= le32_to_cpu(ms->m_nodeid);
67e7fd4179SDavid Teigland 	ms->m_pid		= le32_to_cpu(ms->m_pid);
68e7fd4179SDavid Teigland 	ms->m_lkid		= le32_to_cpu(ms->m_lkid);
69e7fd4179SDavid Teigland 	ms->m_remid		= le32_to_cpu(ms->m_remid);
70e7fd4179SDavid Teigland 	ms->m_parent_lkid	= le32_to_cpu(ms->m_parent_lkid);
71e7fd4179SDavid Teigland 	ms->m_parent_remid	= le32_to_cpu(ms->m_parent_remid);
72e7fd4179SDavid Teigland 	ms->m_exflags		= le32_to_cpu(ms->m_exflags);
73e7fd4179SDavid Teigland 	ms->m_sbflags		= le32_to_cpu(ms->m_sbflags);
74e7fd4179SDavid Teigland 	ms->m_flags		= le32_to_cpu(ms->m_flags);
75e7fd4179SDavid Teigland 	ms->m_lvbseq		= le32_to_cpu(ms->m_lvbseq);
76e7fd4179SDavid Teigland 	ms->m_hash		= le32_to_cpu(ms->m_hash);
77e7fd4179SDavid Teigland 	ms->m_status		= le32_to_cpu(ms->m_status);
78e7fd4179SDavid Teigland 	ms->m_grmode		= le32_to_cpu(ms->m_grmode);
79e7fd4179SDavid Teigland 	ms->m_rqmode		= le32_to_cpu(ms->m_rqmode);
80e7fd4179SDavid Teigland 	ms->m_bastmode		= le32_to_cpu(ms->m_bastmode);
81e7fd4179SDavid Teigland 	ms->m_asts		= le32_to_cpu(ms->m_asts);
82e7fd4179SDavid Teigland 	ms->m_result		= le32_to_cpu(ms->m_result);
83e7fd4179SDavid Teigland }
84e7fd4179SDavid Teigland 
85e7fd4179SDavid Teigland static void rcom_lock_out(struct rcom_lock *rl)
86e7fd4179SDavid Teigland {
87e7fd4179SDavid Teigland 	rl->rl_ownpid		= cpu_to_le32(rl->rl_ownpid);
88e7fd4179SDavid Teigland 	rl->rl_lkid		= cpu_to_le32(rl->rl_lkid);
89e7fd4179SDavid Teigland 	rl->rl_remid		= cpu_to_le32(rl->rl_remid);
90e7fd4179SDavid Teigland 	rl->rl_parent_lkid	= cpu_to_le32(rl->rl_parent_lkid);
91e7fd4179SDavid Teigland 	rl->rl_parent_remid	= cpu_to_le32(rl->rl_parent_remid);
92e7fd4179SDavid Teigland 	rl->rl_exflags		= cpu_to_le32(rl->rl_exflags);
93e7fd4179SDavid Teigland 	rl->rl_flags		= cpu_to_le32(rl->rl_flags);
94e7fd4179SDavid Teigland 	rl->rl_lvbseq		= cpu_to_le32(rl->rl_lvbseq);
95e7fd4179SDavid Teigland 	rl->rl_result		= cpu_to_le32(rl->rl_result);
96e7fd4179SDavid Teigland 	rl->rl_wait_type	= cpu_to_le16(rl->rl_wait_type);
97e7fd4179SDavid Teigland 	rl->rl_namelen		= cpu_to_le16(rl->rl_namelen);
98e7fd4179SDavid Teigland }
99e7fd4179SDavid Teigland 
100e7fd4179SDavid Teigland static void rcom_lock_in(struct rcom_lock *rl)
101e7fd4179SDavid Teigland {
102e7fd4179SDavid Teigland 	rl->rl_ownpid		= le32_to_cpu(rl->rl_ownpid);
103e7fd4179SDavid Teigland 	rl->rl_lkid		= le32_to_cpu(rl->rl_lkid);
104e7fd4179SDavid Teigland 	rl->rl_remid		= le32_to_cpu(rl->rl_remid);
105e7fd4179SDavid Teigland 	rl->rl_parent_lkid	= le32_to_cpu(rl->rl_parent_lkid);
106e7fd4179SDavid Teigland 	rl->rl_parent_remid	= le32_to_cpu(rl->rl_parent_remid);
107e7fd4179SDavid Teigland 	rl->rl_exflags		= le32_to_cpu(rl->rl_exflags);
108e7fd4179SDavid Teigland 	rl->rl_flags		= le32_to_cpu(rl->rl_flags);
109e7fd4179SDavid Teigland 	rl->rl_lvbseq		= le32_to_cpu(rl->rl_lvbseq);
110e7fd4179SDavid Teigland 	rl->rl_result		= le32_to_cpu(rl->rl_result);
111e7fd4179SDavid Teigland 	rl->rl_wait_type	= le16_to_cpu(rl->rl_wait_type);
112e7fd4179SDavid Teigland 	rl->rl_namelen		= le16_to_cpu(rl->rl_namelen);
113e7fd4179SDavid Teigland }
114e7fd4179SDavid Teigland 
115e7fd4179SDavid Teigland static void rcom_config_out(struct rcom_config *rf)
116e7fd4179SDavid Teigland {
117e7fd4179SDavid Teigland 	rf->rf_lvblen		= cpu_to_le32(rf->rf_lvblen);
118e7fd4179SDavid Teigland 	rf->rf_lsflags		= cpu_to_le32(rf->rf_lsflags);
119e7fd4179SDavid Teigland }
120e7fd4179SDavid Teigland 
121e7fd4179SDavid Teigland static void rcom_config_in(struct rcom_config *rf)
122e7fd4179SDavid Teigland {
123e7fd4179SDavid Teigland 	rf->rf_lvblen		= le32_to_cpu(rf->rf_lvblen);
124e7fd4179SDavid Teigland 	rf->rf_lsflags		= le32_to_cpu(rf->rf_lsflags);
125e7fd4179SDavid Teigland }
126e7fd4179SDavid Teigland 
127e7fd4179SDavid Teigland void dlm_rcom_out(struct dlm_rcom *rc)
128e7fd4179SDavid Teigland {
129e7fd4179SDavid Teigland 	struct dlm_header *hd = (struct dlm_header *) rc;
130e7fd4179SDavid Teigland 	int type = rc->rc_type;
131e7fd4179SDavid Teigland 
132e7fd4179SDavid Teigland 	header_out(hd);
133e7fd4179SDavid Teigland 
134e7fd4179SDavid Teigland 	rc->rc_type		= cpu_to_le32(rc->rc_type);
135e7fd4179SDavid Teigland 	rc->rc_result		= cpu_to_le32(rc->rc_result);
136e7fd4179SDavid Teigland 	rc->rc_id		= cpu_to_le64(rc->rc_id);
137*38aa8b0cSDavid Teigland 	rc->rc_seq		= cpu_to_le64(rc->rc_seq);
138*38aa8b0cSDavid Teigland 	rc->rc_seq_reply	= cpu_to_le64(rc->rc_seq_reply);
139e7fd4179SDavid Teigland 
140e7fd4179SDavid Teigland 	if (type == DLM_RCOM_LOCK)
141e7fd4179SDavid Teigland 		rcom_lock_out((struct rcom_lock *) rc->rc_buf);
142e7fd4179SDavid Teigland 
143e7fd4179SDavid Teigland 	else if (type == DLM_RCOM_STATUS_REPLY)
144e7fd4179SDavid Teigland 		rcom_config_out((struct rcom_config *) rc->rc_buf);
145e7fd4179SDavid Teigland }
146e7fd4179SDavid Teigland 
147e7fd4179SDavid Teigland void dlm_rcom_in(struct dlm_rcom *rc)
148e7fd4179SDavid Teigland {
149e7fd4179SDavid Teigland 	struct dlm_header *hd = (struct dlm_header *) rc;
150e7fd4179SDavid Teigland 
151e7fd4179SDavid Teigland 	header_in(hd);
152e7fd4179SDavid Teigland 
153e7fd4179SDavid Teigland 	rc->rc_type		= le32_to_cpu(rc->rc_type);
154e7fd4179SDavid Teigland 	rc->rc_result		= le32_to_cpu(rc->rc_result);
155e7fd4179SDavid Teigland 	rc->rc_id		= le64_to_cpu(rc->rc_id);
156*38aa8b0cSDavid Teigland 	rc->rc_seq		= le64_to_cpu(rc->rc_seq);
157*38aa8b0cSDavid Teigland 	rc->rc_seq_reply	= le64_to_cpu(rc->rc_seq_reply);
158e7fd4179SDavid Teigland 
159e7fd4179SDavid Teigland 	if (rc->rc_type == DLM_RCOM_LOCK)
160e7fd4179SDavid Teigland 		rcom_lock_in((struct rcom_lock *) rc->rc_buf);
161e7fd4179SDavid Teigland 
162e7fd4179SDavid Teigland 	else if (rc->rc_type == DLM_RCOM_STATUS_REPLY)
163e7fd4179SDavid Teigland 		rcom_config_in((struct rcom_config *) rc->rc_buf);
164e7fd4179SDavid Teigland }
165e7fd4179SDavid Teigland 
166