aboutsummaryrefslogtreecommitdiff
path: root/fs/dlm/util.c
blob: 38dcfeb9c4b7a71d1b1fc10436564cff880b05ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/******************************************************************************
*******************************************************************************
**
**  Copyright (C) 2005 Red Hat, Inc.  All rights reserved.
**
**  This copyrighted material is made available to anyone wishing to use,
**  modify, copy, or redistribute it subject to the terms and conditions
**  of the GNU General Public License v.2.
**
*******************************************************************************
******************************************************************************/

#include "dlm_internal.h"
#include "rcom.h"
#include "util.h"

static void header_out(struct dlm_header *hd)
{
	hd->h_version		= cpu_to_le32(hd->h_version);
	hd->h_lockspace		= cpu_to_le32(hd->h_lockspace);
	hd->h_nodeid		= cpu_to_le32(hd->h_nodeid);
	hd->h_length		= cpu_to_le16(hd->h_length);
}

static void header_in(struct dlm_header *hd)
{
	hd->h_version		= le32_to_cpu(hd->h_version);
	hd->h_lockspace		= le32_to_cpu(hd->h_lockspace);
	hd->h_nodeid		= le32_to_cpu(hd->h_nodeid);
	hd->h_length		= le16_to_cpu(hd->h_length);
}

void dlm_message_out(struct dlm_message *ms)
{
	struct dlm_header *hd = (struct dlm_header *) ms;

	header_out(hd);

	ms->m_type		= cpu_to_le32(ms->m_type);
	ms->m_nodeid		= cpu_to_le32(ms->m_nodeid);
	ms->m_pid		= cpu_to_le32(ms->m_pid);
	ms->m_lkid		= cpu_to_le32(ms->m_lkid);
	ms->m_remid		= cpu_to_le32(ms->m_remid);
	ms->m_parent_lkid	= cpu_to_le32(ms->m_parent_lkid);
	ms->m_parent_remid	= cpu_to_le32(ms->m_parent_remid);
	ms->m_exflags		= cpu_to_le32(ms->m_exflags);
	ms->m_sbflags		= cpu_to_le32(ms->m_sbflags);
	ms->m_flags		= cpu_to_le32(ms->m_flags);
	ms->m_lvbseq		= cpu_to_le32(ms->m_lvbseq);
	ms->m_hash		= cpu_to_le32(ms->m_hash);
	ms->m_status		= cpu_to_le32(ms->m_status);
	ms->m_grmode		= cpu_to_le32(ms->m_grmode);
	ms->m_rqmode		= cpu_to_le32(ms->m_rqmode);
	ms->m_bastmode		= cpu_to_le32(ms->m_bastmode);
	ms->m_asts		= cpu_to_le32(ms->m_asts);
	ms->m_result		= cpu_to_le32(ms->m_result);
}

void dlm_message_in(struct dlm_message *ms)
{
	struct dlm_header *hd = (struct dlm_header *) ms;

	header_in(hd);

	ms->m_type		= le32_to_cpu(ms->m_type);
	ms->m_nodeid		= le32_to_cpu(ms->m_nodeid);
	ms->m_pid		= le32_to_cpu(ms->m_pid);
	ms->m_lkid		= le32_to_cpu(ms->m_lkid);
	ms->m_remid		= le32_to_cpu(ms->m_remid);
	ms->m_parent_lkid	= le32_to_cpu(ms->m_parent_lkid);
	ms->m_parent_remid	= le32_to_cpu(ms->m_parent_remid);
	ms->m_exflags		= le32_to_cpu(ms->m_exflags);
	ms->m_sbflags		= le32_to_cpu(ms->m_sbflags);
	ms->m_flags		= le32_to_cpu(ms->m_flags);
	ms->m_lvbseq		= le32_to_cpu(ms->m_lvbseq);
	ms->m_hash		= le32_to_cpu(ms->m_hash);
	ms->m_status		= le32_to_cpu(ms->m_status);
	ms->m_grmode		= le32_to_cpu(ms->m_grmode);
	ms->m_rqmode		= le32_to_cpu(ms->m_rqmode);
	ms->m_bastmode		= le32_to_cpu(ms->m_bastmode);
	ms->m_asts		= le32_to_cpu(ms->m_asts);
	ms->m_result		= le32_to_cpu(ms->m_result);
}

static void rcom_lock_out(struct rcom_lock *rl)
{
	rl->rl_ownpid		= cpu_to_le32(rl->rl_ownpid);
	rl->rl_lkid		= cpu_to_le32(rl->rl_lkid);
	rl->rl_remid		= cpu_to_le32(rl->rl_remid);
	rl->rl_parent_lkid	= cpu_to_le32(rl->rl_parent_lkid);
	rl->rl_parent_remid	= cpu_to_le32(rl->rl_parent_remid);
	rl->rl_exflags		= cpu_to_le32(rl->rl_exflags);
	rl->rl_flags		= cpu_to_le32(rl->rl_flags);
	rl->rl_lvbseq		= cpu_to_le32(rl->rl_lvbseq);
	rl->rl_result		= cpu_to_le32(rl->rl_result);
	rl->rl_wait_type	= cpu_to_le16(rl->rl_wait_type);
	rl->rl_namelen		= cpu_to_le16(rl->rl_namelen);
}

static void rcom_lock_in(struct rcom_lock *rl)
{
	rl->rl_ownpid		= le32_to_cpu(rl->rl_ownpid);
	rl->rl_lkid		= le32_to_cpu(rl->rl_lkid);
	rl->rl_remid		= le32_to_cpu(rl->rl_remid);
	rl->rl_parent_lkid	= le32_to_cpu(rl->rl_parent_lkid);
	rl->rl_parent_remid	= le32_to_cpu(rl->rl_parent_remid);
	rl->rl_exflags		= le32_to_cpu(rl->rl_exflags);
	rl->rl_flags		= le32_to_cpu(rl->rl_flags);
	rl->rl_lvbseq		= le32_to_cpu(rl->rl_lvbseq);
	rl->rl_result		= le32_to_cpu(rl->rl_result);
	rl->rl_wait_type	= le16_to_cpu(rl->rl_wait_type);
	rl->rl_namelen		= le16_to_cpu(rl->rl_namelen);
}

static void rcom_config_out(struct rcom_config *rf)
{
	rf->rf_lvblen		= cpu_to_le32(rf->rf_lvblen);
	rf->rf_lsflags		= cpu_to_le32(rf->rf_lsflags);
}

static void rcom_config_in(struct rcom_config *rf)
{
	rf->rf_lvblen		= le32_to_cpu(rf->rf_lvblen);
	rf->rf_lsflags		= le32_to_cpu(rf->rf_lsflags);
}

void dlm_rcom_out(struct dlm_rcom *rc)
{
	struct dlm_header *hd = (struct dlm_header *) rc;
	int type = rc->rc_type;

	header_out(hd);

	rc->rc_type		= cpu_to_le32(rc->rc_type);
	rc->rc_result		= cpu_to_le32(rc->rc_result);
	rc->rc_id		= cpu_to_le64(rc->rc_id);
	rc->rc_seq		= cpu_to_le64(rc->rc_seq);
	rc->rc_seq_reply	= cpu_to_le64(rc->rc_seq_reply);

	if ((type == DLM_RCOM_LOCK) || (type == DLM_RCOM_LOCK_REPLY))
		rcom_lock_out((struct rcom_lock *) rc->rc_buf);

	else if (type == DLM_RCOM_STATUS_REPLY)
		rcom_config_out((struct rcom_config *) rc->rc_buf);
}

void dlm_rcom_in(struct dlm_rcom *rc)
{
	struct dlm_header *hd = (struct dlm_header *) rc;
	int type;

	header_in(hd);

	rc->rc_type		= le32_to_cpu(rc->rc_type);
	rc->rc_result		= le32_to_cpu(rc->rc_result);
	rc->rc_id		= le64_to_cpu(rc->rc_id);
	rc->rc_seq		= le64_to_cpu(rc->rc_seq);
	rc->rc_seq_reply	= le64_to_cpu(rc->rc_seq_reply);

	type = rc->rc_type;

	if ((type == DLM_RCOM_LOCK) || (type == DLM_RCOM_LOCK_REPLY))
		rcom_lock_in((struct rcom_lock *) rc->rc_buf);

	else if (type == DLM_RCOM_STATUS_REPLY)
		rcom_config_in((struct rcom_config *) rc->rc_buf);
}