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 the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
10  *   You may have signed or agreed to another license before downloading
11  *   this software.  If so, you are bound by the terms and conditions
12  *   of that agreement, and the following does not apply to you.  See the
13  *   LICENSE file included with this distribution for more information.
14  *
15  *   If you did not agree to a different license, then this copy of Lustre
16  *   is open source software; you can redistribute it and/or modify it
17  *   under the terms of version 2 of the GNU General Public License as
18  *   published by the Free Software Foundation.
19  *
20  *   In either case, Lustre is distributed in the hope that it will be
21  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
22  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *   license text for more details.
24  *
25  * Swabbing of llog datatypes (from disk or over the wire).
26  *
27  */
28
29 #define DEBUG_SUBSYSTEM S_LOG
30
31 #ifndef __KERNEL__
32 #include <liblustre.h>
33 #endif
34
35 #include <lustre_log.h>
36
37 static void print_llogd_body(struct llogd_body *d)
38 {
39         CDEBUG(D_OTHER, "llogd body: %p\n", d);
40         CDEBUG(D_OTHER, "\tlgd_logid.lgl_oid: "LPX64"\n", d->lgd_logid.lgl_oid);
41         CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogr: "LPX64"\n", d->lgd_logid.lgl_ogr);
42         CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogen: %#x\n", d->lgd_logid.lgl_ogen);
43         CDEBUG(D_OTHER, "\tlgd_ctxt_idx: %#x\n", d->lgd_ctxt_idx);
44         CDEBUG(D_OTHER, "\tlgd_llh_flags: %#x\n", d->lgd_llh_flags);
45         CDEBUG(D_OTHER, "\tlgd_index: %#x\n", d->lgd_index);
46         CDEBUG(D_OTHER, "\tlgd_saved_index: %#x\n", d->lgd_saved_index);
47         CDEBUG(D_OTHER, "\tlgd_len: %#x\n", d->lgd_len);
48         CDEBUG(D_OTHER, "\tlgd_cur_offset: "LPX64"\n", d->lgd_cur_offset);
49 }
50
51 void lustre_swab_llogd_body (struct llogd_body *d)
52 {
53         ENTRY;
54         print_llogd_body(d);
55         __swab64s (&d->lgd_logid.lgl_oid);
56         __swab64s (&d->lgd_logid.lgl_ogr);
57         __swab32s (&d->lgd_logid.lgl_ogen);
58         __swab32s (&d->lgd_ctxt_idx);
59         __swab32s (&d->lgd_llh_flags);
60         __swab32s (&d->lgd_index);
61         __swab32s (&d->lgd_saved_index);
62         __swab32s (&d->lgd_len);
63         __swab64s (&d->lgd_cur_offset);
64         print_llogd_body(d);
65         EXIT;
66 }
67 EXPORT_SYMBOL(lustre_swab_llogd_body);
68
69 void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
70 {
71         __swab64s (&d->lgdc_gen.mnt_cnt);
72         __swab64s (&d->lgdc_gen.conn_cnt);
73         __swab64s (&d->lgdc_logid.lgl_oid);
74         __swab64s (&d->lgdc_logid.lgl_ogr);
75         __swab32s (&d->lgdc_logid.lgl_ogen);
76         __swab32s (&d->lgdc_ctxt_idx);
77 }
78 EXPORT_SYMBOL(lustre_swab_llogd_conn_body);
79
80 void lustre_swab_ll_fid(struct ll_fid *fid)
81 {
82         __swab64s (&fid->id);
83         __swab32s (&fid->generation);
84         __swab32s (&fid->f_type);
85 }
86 EXPORT_SYMBOL(lustre_swab_ll_fid);
87
88 void lustre_swab_lu_fid(struct lu_fid *fid)
89 {
90         __swab64s (&fid->f_seq);
91         __swab32s (&fid->f_oid);
92         __swab32s (&fid->f_ver);
93 }
94 EXPORT_SYMBOL(lustre_swab_lu_fid);
95
96 void lustre_swab_lu_range(struct lu_range *range)
97 {
98         __swab64s (&range->lr_start);
99         __swab64s (&range->lr_end);
100 }
101 EXPORT_SYMBOL(lustre_swab_lu_range);
102
103 void lustre_swab_llog_rec(struct llog_rec_hdr *rec, struct llog_rec_tail *tail)
104 {
105         __swab32s(&rec->lrh_len);
106         __swab32s(&rec->lrh_index);
107         __swab32s(&rec->lrh_type);
108
109         switch (rec->lrh_type) {
110         case OST_SZ_REC: {
111                 struct llog_size_change_rec *lsc =
112                         (struct llog_size_change_rec *)rec;
113
114                 lustre_swab_ll_fid(&lsc->lsc_fid);
115                 __swab32s(&lsc->lsc_ioepoch);
116
117                 break;
118         }
119
120         case OST_RAID1_REC:
121                 break;
122
123         case MDS_UNLINK_REC: {
124                 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
125
126                 __swab64s(&lur->lur_oid);
127                 __swab32s(&lur->lur_ogen);
128
129                 break;
130         }
131
132         case MDS_SETATTR_REC: {
133                 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
134
135                 __swab64s(&lsr->lsr_oid);
136                 __swab32s(&lsr->lsr_ogen);
137                 __swab32s(&lsr->lsr_uid);
138                 __swab32s(&lsr->lsr_gid);
139
140                 break;
141         }
142
143         case OBD_CFG_REC:
144         case PTL_CFG_REC:                       /* obsolete */
145                 /* these are swabbed as they are consumed */
146                 break;
147
148         case LLOG_HDR_MAGIC: {
149                 struct llog_log_hdr *llh = (struct llog_log_hdr *)rec;
150
151                 __swab64s(&llh->llh_timestamp);
152                 __swab32s(&llh->llh_count);
153                 __swab32s(&llh->llh_bitmap_offset);
154                 __swab32s(&llh->llh_flags);
155                 __swab32s(&llh->llh_size);
156                 __swab32s(&llh->llh_cat_idx);
157                 if (tail != &llh->llh_tail) {
158                         __swab32s(&llh->llh_tail.lrt_index);
159                         __swab32s(&llh->llh_tail.lrt_len);
160                 }
161
162                 break;
163         }
164
165         case LLOG_LOGID_MAGIC: {
166                 struct llog_logid_rec *lid = (struct llog_logid_rec *)rec;
167
168                 __swab64s(&lid->lid_id.lgl_oid);
169                 __swab64s(&lid->lid_id.lgl_ogr);
170                 __swab32s(&lid->lid_id.lgl_ogen);
171                 break;
172         }
173
174         case LLOG_PAD_MAGIC:
175         /* ignore old pad records of type 0 */
176         case 0:
177                 break;
178
179         default:
180                 CERROR("Unknown llog rec type %#x swabbing rec %p\n",
181                        rec->lrh_type, rec);
182         }
183
184         if (tail) {
185                 __swab32s(&tail->lrt_len);
186                 __swab32s(&tail->lrt_index);
187         }
188 }
189 EXPORT_SYMBOL(lustre_swab_llog_rec);
190
191 static void print_llog_hdr(struct llog_log_hdr *h)
192 {
193         CDEBUG(D_OTHER, "llog header: %p\n", h);
194         CDEBUG(D_OTHER, "\tllh_hdr.lrh_index: %#x\n", h->llh_hdr.lrh_index);
195         CDEBUG(D_OTHER, "\tllh_hdr.lrh_len: %#x\n", h->llh_hdr.lrh_len);
196         CDEBUG(D_OTHER, "\tllh_hdr.lrh_type: %#x\n", h->llh_hdr.lrh_type);
197         CDEBUG(D_OTHER, "\tllh_timestamp: "LPX64"\n", h->llh_timestamp);
198         CDEBUG(D_OTHER, "\tllh_count: %#x\n", h->llh_count);
199         CDEBUG(D_OTHER, "\tllh_bitmap_offset: %#x\n", h->llh_bitmap_offset);
200         CDEBUG(D_OTHER, "\tllh_flags: %#x\n", h->llh_flags);
201         CDEBUG(D_OTHER, "\tllh_size: %#x\n", h->llh_size);
202         CDEBUG(D_OTHER, "\tllh_cat_idx: %#x\n", h->llh_cat_idx);
203         CDEBUG(D_OTHER, "\tllh_tail.lrt_index: %#x\n", h->llh_tail.lrt_index);
204         CDEBUG(D_OTHER, "\tllh_tail.lrt_len: %#x\n", h->llh_tail.lrt_len);
205 }
206
207 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
208 {
209         ENTRY;
210         print_llog_hdr(h);
211
212         lustre_swab_llog_rec(&h->llh_hdr, &h->llh_tail);
213
214         print_llog_hdr(h);
215         EXIT;
216 }
217 EXPORT_SYMBOL(lustre_swab_llog_hdr);
218
219 static void print_lustre_cfg(struct lustre_cfg *lcfg)
220 {
221         int i;
222         ENTRY;
223
224         if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
225                 return;
226         CDEBUG(D_OTHER, "lustre_cfg: %p\n", lcfg);
227         CDEBUG(D_OTHER, "\tlcfg->lcfg_version: %#x\n", lcfg->lcfg_version);
228
229         CDEBUG(D_OTHER, "\tlcfg->lcfg_command: %#x\n", lcfg->lcfg_command);
230         CDEBUG(D_OTHER, "\tlcfg->lcfg_num: %#x\n", lcfg->lcfg_num);
231         CDEBUG(D_OTHER, "\tlcfg->lcfg_flags: %#x\n", lcfg->lcfg_flags);
232         CDEBUG(D_OTHER, "\tlcfg->lcfg_nid: %s\n", libcfs_nid2str(lcfg->lcfg_nid));
233
234         CDEBUG(D_OTHER, "\tlcfg->lcfg_bufcount: %d\n", lcfg->lcfg_bufcount);
235         if (lcfg->lcfg_bufcount < LUSTRE_CFG_MAX_BUFCOUNT)
236                 for (i = 0; i < lcfg->lcfg_bufcount; i++)
237                         CDEBUG(D_OTHER, "\tlcfg->lcfg_buflens[%d]: %d\n",
238                                i, lcfg->lcfg_buflens[i]);
239         EXIT;
240 }
241
242 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg)
243 {
244         int i;
245         ENTRY;
246
247         __swab32s(&lcfg->lcfg_version);
248
249         if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
250                 CERROR("not swabbing lustre_cfg version %#x (expecting %#x)\n",
251                        lcfg->lcfg_version, LUSTRE_CFG_VERSION);
252                 EXIT;
253                 return;
254         }
255
256         __swab32s(&lcfg->lcfg_command);
257         __swab32s(&lcfg->lcfg_num);
258         __swab32s(&lcfg->lcfg_flags);
259         __swab64s(&lcfg->lcfg_nid);
260         __swab32s(&lcfg->lcfg_bufcount);
261         for (i = 0; i < lcfg->lcfg_bufcount && i < LUSTRE_CFG_MAX_BUFCOUNT; i++)
262                 __swab32s(&lcfg->lcfg_buflens[i]);
263
264         print_lustre_cfg(lcfg);
265         EXIT;
266         return;
267 }
268 EXPORT_SYMBOL(lustre_swab_lustre_cfg);