Whamcloud - gitweb
Branch: HEAD
[fs/lustre-release.git] / lustre / obdclass / llog_swab.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2004-2005 Cluster File Systems, Inc.
5  *   Author: jacob berkman  <jacob@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * Swabbing of llog datatypes (from disk or over the wire).
23  *
24  */
25
26 #define DEBUG_SUBSYSTEM S_LOG
27
28 #include <linux/lustre_log.h>
29
30 static void print_llogd_body(struct llogd_body *d)
31 {
32         CDEBUG(D_OTHER, "llogd body: %p\n", d);
33         CDEBUG(D_OTHER, "\tlgd_logid.lgl_oid: "LPX64"\n", d->lgd_logid.lgl_oid);
34         CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogr: "LPX64"\n", d->lgd_logid.lgl_ogr);
35         CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogen: %#x\n", d->lgd_logid.lgl_ogen);
36         CDEBUG(D_OTHER, "\tlgd_ctxt_idx: %#x\n", d->lgd_ctxt_idx);
37         CDEBUG(D_OTHER, "\tlgd_llh_flags: %#x\n", d->lgd_llh_flags);
38         CDEBUG(D_OTHER, "\tlgd_index: %#x\n", d->lgd_index);
39         CDEBUG(D_OTHER, "\tlgd_saved_index: %#x\n", d->lgd_saved_index);
40         CDEBUG(D_OTHER, "\tlgd_len: %#x\n", d->lgd_len);
41         CDEBUG(D_OTHER, "\tlgd_cur_offset: "LPX64"\n", d->lgd_cur_offset);
42 }
43
44 void lustre_swab_llogd_body (struct llogd_body *d)
45 {
46         ENTRY;
47         print_llogd_body(d);
48         __swab64s (&d->lgd_logid.lgl_oid);
49         __swab64s (&d->lgd_logid.lgl_ogr);
50         __swab32s (&d->lgd_logid.lgl_ogen);
51         __swab32s (&d->lgd_ctxt_idx);
52         __swab32s (&d->lgd_llh_flags);
53         __swab32s (&d->lgd_index);
54         __swab32s (&d->lgd_saved_index);
55         __swab32s (&d->lgd_len);
56         __swab64s (&d->lgd_cur_offset);
57         print_llogd_body(d);
58         EXIT;
59 }
60 EXPORT_SYMBOL(lustre_swab_llogd_body);
61
62 void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
63 {
64         __swab64s (&d->lgdc_gen.mnt_cnt);
65         __swab64s (&d->lgdc_gen.conn_cnt);
66         __swab64s (&d->lgdc_logid.lgl_oid);
67         __swab64s (&d->lgdc_logid.lgl_ogr);
68         __swab32s (&d->lgdc_logid.lgl_ogen);
69         __swab32s (&d->lgdc_ctxt_idx);
70 }
71 EXPORT_SYMBOL(lustre_swab_llogd_conn_body);
72
73 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
74 {
75         __swab32s (&h->llh_hdr.lrh_index);
76         __swab32s (&h->llh_hdr.lrh_len);
77         __swab32s (&h->llh_hdr.lrh_type);
78         __swab64s (&h->llh_timestamp);
79         __swab32s (&h->llh_count);
80         __swab32s (&h->llh_bitmap_offset);
81         __swab32s (&h->llh_flags);
82         __swab32s (&h->llh_tail.lrt_index);
83         __swab32s (&h->llh_tail.lrt_len);
84 }
85 EXPORT_SYMBOL(lustre_swab_llog_hdr);
86
87 #define PRINT_PCFG32(x) CDEBUG(D_OTHER, "\tpcfg->pcfg_"#x": %#x\n", pcfg->pcfg_##x)
88 #define PRINT_PCFG64(x) CDEBUG(D_OTHER, "\tpcfg->pcfg_"#x": "LPX64"\n", pcfg->pcfg_##x)
89
90 static void print_portals_cfg(struct portals_cfg *pcfg)
91 {
92         ENTRY;
93
94         if (!(portal_debug & D_OTHER)) /* don't loop on nothing */
95                 return;
96         CDEBUG(D_OTHER, "portals_cfg: %p\n", pcfg);
97         PRINT_PCFG32(version);
98         PRINT_PCFG32(command);
99
100         PRINT_PCFG32(nal);
101         PRINT_PCFG32(flags);
102
103         PRINT_PCFG32(gw_nal);
104         PRINT_PCFG64(nid);
105         PRINT_PCFG64(nid2);
106         PRINT_PCFG64(nid3);
107         PRINT_PCFG32(id);
108         PRINT_PCFG32(misc);
109         PRINT_PCFG32(fd);
110         PRINT_PCFG32(count);
111         PRINT_PCFG32(size);
112         PRINT_PCFG32(wait);
113
114         PRINT_PCFG32(plen1);
115         PRINT_PCFG32(plen2);
116
117         EXIT;
118 }
119
120 void lustre_swab_portals_cfg(struct portals_cfg *pcfg)
121 {
122         ENTRY;
123
124         __swab32s(&pcfg->pcfg_version);
125         __swab32s(&pcfg->pcfg_command);
126
127         __swab32s(&pcfg->pcfg_nal);
128         __swab32s(&pcfg->pcfg_flags);
129
130         __swab32s(&pcfg->pcfg_gw_nal);
131         __swab64s(&pcfg->pcfg_nid);
132         __swab64s(&pcfg->pcfg_nid2);
133         __swab64s(&pcfg->pcfg_nid3);
134         __swab32s(&pcfg->pcfg_id);
135         __swab32s(&pcfg->pcfg_misc);
136         __swab32s(&pcfg->pcfg_fd);
137         __swab32s(&pcfg->pcfg_count);
138         __swab32s(&pcfg->pcfg_size);
139         __swab32s(&pcfg->pcfg_wait);
140
141         __swab32s(&pcfg->pcfg_plen1);
142         __swab32s(&pcfg->pcfg_plen2);
143
144         print_portals_cfg(pcfg);
145         EXIT;
146 }
147 EXPORT_SYMBOL(lustre_swab_portals_cfg);
148
149 static void print_lustre_cfg(struct lustre_cfg *lcfg)
150 {
151         int i;
152         ENTRY;
153
154         if (!(portal_debug & D_OTHER)) /* don't loop on nothing */
155                 return;
156         CDEBUG(D_OTHER, "lustre_cfg: %p\n", lcfg);
157         CDEBUG(D_OTHER, "\tlcfg->lcfg_version: %#x\n", lcfg->lcfg_version);
158
159         CDEBUG(D_OTHER, "\tlcfg->lcfg_command: %#x\n", lcfg->lcfg_command);
160         CDEBUG(D_OTHER, "\tlcfg->lcfg_num: %#x\n", lcfg->lcfg_num);
161         CDEBUG(D_OTHER, "\tlcfg->lcfg_flags: %#x\n", lcfg->lcfg_flags);
162         CDEBUG(D_OTHER, "\tlcfg->lcfg_nid: "LPX64"\n", lcfg->lcfg_nid);
163         CDEBUG(D_OTHER, "\tlcfg->lcfg_nal: %#x\n", lcfg->lcfg_nal);
164
165         CDEBUG(D_OTHER, "\tlcfg->lcfg_bufcount: %d\n", lcfg->lcfg_bufcount);
166         if (lcfg->lcfg_bufcount < LUSTRE_CFG_MAX_BUFCOUNT)
167                 for (i = 0; i < lcfg->lcfg_bufcount; i++)
168                         CDEBUG(D_OTHER, "\tlcfg->lcfg_buflens[%d]: %d\n",
169                                i, lcfg->lcfg_buflens[i]);
170         EXIT;
171 }
172
173 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg)
174 {
175         int i;
176         ENTRY;
177
178         __swab32s(&lcfg->lcfg_version);
179
180         if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
181                 CERROR("not swabbing lustre_cfg version %#x (expecting %#x)\n",
182                        lcfg->lcfg_version, LUSTRE_CFG_VERSION);
183                 EXIT;
184                 return;
185         }
186
187         __swab32s(&lcfg->lcfg_command);
188
189         __swab32s(&lcfg->lcfg_num);
190         __swab32s(&lcfg->lcfg_flags);
191         __swab64s(&lcfg->lcfg_nid);
192         __swab32s(&lcfg->lcfg_nal);
193
194         __swab32s(&lcfg->lcfg_bufcount);
195         for (i = 0; i < lcfg->lcfg_bufcount && i < LUSTRE_CFG_MAX_BUFCOUNT; i++)
196                 __swab32s(&lcfg->lcfg_buflens[i]);
197
198         print_lustre_cfg(lcfg);
199         EXIT;
200         return;
201 }
202 EXPORT_SYMBOL(lustre_swab_lustre_cfg);