1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004-2005 Cluster File Systems, Inc.
5 * Author: jacob berkman <jacob@clusterfs.com>
7 * This file is part of the Lustre file system, http://www.lustre.org
8 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
25 * Swabbing of llog datatypes (from disk or over the wire).
29 #define DEBUG_SUBSYSTEM S_LOG
32 #include <liblustre.h>
35 #include <lustre_log.h>
37 static void print_llogd_body(struct llogd_body *d)
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);
51 void lustre_swab_llogd_body (struct 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);
67 EXPORT_SYMBOL(lustre_swab_llogd_body);
69 void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
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);
78 EXPORT_SYMBOL(lustre_swab_llogd_conn_body);
80 void lustre_swab_ll_fid(struct ll_fid *fid)
83 __swab32s (&fid->generation);
84 __swab32s (&fid->f_type);
86 EXPORT_SYMBOL(lustre_swab_ll_fid);
88 void lustre_swab_llog_rec(struct llog_rec_hdr *rec, struct llog_rec_tail *tail)
90 __swab32s(&rec->lrh_len);
91 __swab32s(&rec->lrh_index);
92 __swab32s(&rec->lrh_type);
94 switch (rec->lrh_type) {
96 struct llog_size_change_rec *lsc =
97 (struct llog_size_change_rec *)rec;
99 lustre_swab_ll_fid(&lsc->lsc_fid);
100 __swab32s(&lsc->lsc_io_epoch);
108 case MDS_UNLINK_REC: {
109 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
111 __swab64s(&lur->lur_oid);
112 __swab32s(&lur->lur_ogen);
117 case MDS_SETATTR_REC: {
118 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
120 __swab64s(&lsr->lsr_oid);
121 __swab32s(&lsr->lsr_ogen);
122 __swab32s(&lsr->lsr_uid);
123 __swab32s(&lsr->lsr_gid);
129 case PTL_CFG_REC: /* obsolete */
130 /* these are swabbed as they are consumed */
133 case LLOG_HDR_MAGIC: {
134 struct llog_log_hdr *llh = (struct llog_log_hdr *)rec;
136 __swab64s(&llh->llh_timestamp);
137 __swab32s(&llh->llh_count);
138 __swab32s(&llh->llh_bitmap_offset);
139 __swab32s(&llh->llh_flags);
140 __swab32s(&llh->llh_size);
141 __swab32s(&llh->llh_cat_idx);
142 if (tail != &llh->llh_tail) {
143 __swab32s(&llh->llh_tail.lrt_index);
144 __swab32s(&llh->llh_tail.lrt_len);
150 case LLOG_LOGID_MAGIC: {
151 struct llog_logid_rec *lid = (struct llog_logid_rec *)rec;
153 __swab64s(&lid->lid_id.lgl_oid);
154 __swab64s(&lid->lid_id.lgl_ogr);
155 __swab32s(&lid->lid_id.lgl_ogen);
160 /* ignore old pad records of type 0 */
165 CERROR("Unknown llog rec type %#x swabbing rec %p\n",
170 __swab32s(&tail->lrt_len);
171 __swab32s(&tail->lrt_index);
174 EXPORT_SYMBOL(lustre_swab_llog_rec);
176 static void print_llog_hdr(struct llog_log_hdr *h)
178 CDEBUG(D_OTHER, "llog header: %p\n", h);
179 CDEBUG(D_OTHER, "\tllh_hdr.lrh_index: %#x\n", h->llh_hdr.lrh_index);
180 CDEBUG(D_OTHER, "\tllh_hdr.lrh_len: %#x\n", h->llh_hdr.lrh_len);
181 CDEBUG(D_OTHER, "\tllh_hdr.lrh_type: %#x\n", h->llh_hdr.lrh_type);
182 CDEBUG(D_OTHER, "\tllh_timestamp: "LPX64"\n", h->llh_timestamp);
183 CDEBUG(D_OTHER, "\tllh_count: %#x\n", h->llh_count);
184 CDEBUG(D_OTHER, "\tllh_bitmap_offset: %#x\n", h->llh_bitmap_offset);
185 CDEBUG(D_OTHER, "\tllh_flags: %#x\n", h->llh_flags);
186 CDEBUG(D_OTHER, "\tllh_size: %#x\n", h->llh_size);
187 CDEBUG(D_OTHER, "\tllh_cat_idx: %#x\n", h->llh_cat_idx);
188 CDEBUG(D_OTHER, "\tllh_tail.lrt_index: %#x\n", h->llh_tail.lrt_index);
189 CDEBUG(D_OTHER, "\tllh_tail.lrt_len: %#x\n", h->llh_tail.lrt_len);
192 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
197 lustre_swab_llog_rec(&h->llh_hdr, &h->llh_tail);
202 EXPORT_SYMBOL(lustre_swab_llog_hdr);
204 static void print_lustre_cfg(struct lustre_cfg *lcfg)
209 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
211 CDEBUG(D_OTHER, "lustre_cfg: %p\n", lcfg);
212 CDEBUG(D_OTHER, "\tlcfg->lcfg_version: %#x\n", lcfg->lcfg_version);
214 CDEBUG(D_OTHER, "\tlcfg->lcfg_command: %#x\n", lcfg->lcfg_command);
215 CDEBUG(D_OTHER, "\tlcfg->lcfg_num: %#x\n", lcfg->lcfg_num);
216 CDEBUG(D_OTHER, "\tlcfg->lcfg_flags: %#x\n", lcfg->lcfg_flags);
217 CDEBUG(D_OTHER, "\tlcfg->lcfg_nid: %s\n", libcfs_nid2str(lcfg->lcfg_nid));
219 CDEBUG(D_OTHER, "\tlcfg->lcfg_bufcount: %d\n", lcfg->lcfg_bufcount);
220 if (lcfg->lcfg_bufcount < LUSTRE_CFG_MAX_BUFCOUNT)
221 for (i = 0; i < lcfg->lcfg_bufcount; i++)
222 CDEBUG(D_OTHER, "\tlcfg->lcfg_buflens[%d]: %d\n",
223 i, lcfg->lcfg_buflens[i]);
227 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg)
232 __swab32s(&lcfg->lcfg_version);
234 if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
235 CERROR("not swabbing lustre_cfg version %#x (expecting %#x)\n",
236 lcfg->lcfg_version, LUSTRE_CFG_VERSION);
241 __swab32s(&lcfg->lcfg_command);
242 __swab32s(&lcfg->lcfg_num);
243 __swab32s(&lcfg->lcfg_flags);
244 __swab64s(&lcfg->lcfg_nid);
245 __swab32s(&lcfg->lcfg_bufcount);
246 for (i = 0; i < lcfg->lcfg_bufcount && i < LUSTRE_CFG_MAX_BUFCOUNT; i++)
247 __swab32s(&lcfg->lcfg_buflens[i]);
249 print_lustre_cfg(lcfg);
253 EXPORT_SYMBOL(lustre_swab_lustre_cfg);