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 Lustre, http://www.lustre.org.
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.
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.
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.
22 * Swabbing of llog datatypes (from disk or over the wire).
26 #define DEBUG_SUBSYSTEM S_LOG
29 #include <liblustre.h>
32 #include <linux/lustre_log.h>
34 static void print_llogd_body(struct llogd_body *d)
36 CDEBUG(D_OTHER, "llogd body: %p\n", d);
37 CDEBUG(D_OTHER, "\tlgd_logid.lgl_oid: "LPX64"\n", d->lgd_logid.lgl_oid);
38 CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogr: "LPX64"\n", d->lgd_logid.lgl_ogr);
39 CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogen: %#x\n", d->lgd_logid.lgl_ogen);
40 CDEBUG(D_OTHER, "\tlgd_ctxt_idx: %#x\n", d->lgd_ctxt_idx);
41 CDEBUG(D_OTHER, "\tlgd_llh_flags: %#x\n", d->lgd_llh_flags);
42 CDEBUG(D_OTHER, "\tlgd_index: %#x\n", d->lgd_index);
43 CDEBUG(D_OTHER, "\tlgd_saved_index: %#x\n", d->lgd_saved_index);
44 CDEBUG(D_OTHER, "\tlgd_len: %#x\n", d->lgd_len);
45 CDEBUG(D_OTHER, "\tlgd_cur_offset: "LPX64"\n", d->lgd_cur_offset);
48 void lustre_swab_llogd_body (struct llogd_body *d)
52 __swab64s (&d->lgd_logid.lgl_oid);
53 __swab64s (&d->lgd_logid.lgl_ogr);
54 __swab32s (&d->lgd_logid.lgl_ogen);
55 __swab32s (&d->lgd_ctxt_idx);
56 __swab32s (&d->lgd_llh_flags);
57 __swab32s (&d->lgd_index);
58 __swab32s (&d->lgd_saved_index);
59 __swab32s (&d->lgd_len);
60 __swab64s (&d->lgd_cur_offset);
64 EXPORT_SYMBOL(lustre_swab_llogd_body);
66 void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
68 __swab64s (&d->lgdc_gen.mnt_cnt);
69 __swab64s (&d->lgdc_gen.conn_cnt);
70 __swab64s (&d->lgdc_logid.lgl_oid);
71 __swab64s (&d->lgdc_logid.lgl_ogr);
72 __swab32s (&d->lgdc_logid.lgl_ogen);
73 __swab32s (&d->lgdc_ctxt_idx);
75 EXPORT_SYMBOL(lustre_swab_llogd_conn_body);
77 void lustre_swab_ll_fid (struct ll_fid *fid)
80 __swab32s (&fid->generation);
81 __swab32s (&fid->f_type);
83 EXPORT_SYMBOL(lustre_swab_ll_fid);
85 void lustre_swab_llog_rec(struct llog_rec_hdr *rec, struct llog_rec_tail *tail)
87 __swab32s(&rec->lrh_len);
88 __swab32s(&rec->lrh_index);
89 __swab32s(&rec->lrh_type);
91 switch (rec->lrh_type) {
93 struct llog_size_change_rec *lsc =
94 (struct llog_size_change_rec *)rec;
96 lustre_swab_ll_fid(&lsc->lsc_fid);
97 __swab32s(&lsc->lsc_io_epoch);
105 case MDS_UNLINK_REC: {
106 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
108 __swab64s(&lur->lur_oid);
109 __swab32s(&lur->lur_ogen);
114 case MDS_SETATTR_REC: {
115 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
117 __swab64s(&lsr->lsr_oid);
118 __swab32s(&lsr->lsr_ogen);
119 __swab32s(&lsr->lsr_uid);
120 __swab32s(&lsr->lsr_gid);
126 case PTL_CFG_REC: /* obsolete */
127 /* these are swabbed as they are consumed */
130 case LLOG_HDR_MAGIC: {
131 struct llog_log_hdr *llh = (struct llog_log_hdr *)rec;
133 __swab64s(&llh->llh_timestamp);
134 __swab32s(&llh->llh_count);
135 __swab32s(&llh->llh_bitmap_offset);
136 __swab32s(&llh->llh_flags);
137 __swab32s(&llh->llh_size);
138 __swab32s(&llh->llh_cat_idx);
139 if (tail != &llh->llh_tail) {
140 __swab32s(&llh->llh_tail.lrt_index);
141 __swab32s(&llh->llh_tail.lrt_len);
147 case LLOG_LOGID_MAGIC: {
148 struct llog_logid_rec *lid = (struct llog_logid_rec *)rec;
150 __swab64s(&lid->lid_id.lgl_oid);
151 __swab64s(&lid->lid_id.lgl_ogr);
152 __swab32s(&lid->lid_id.lgl_ogen);
157 /* ignore old pad records of type 0 */
162 CERROR("Unknown llog rec type %#x swabbing rec %p\n",
167 __swab32s(&tail->lrt_len);
168 __swab32s(&tail->lrt_index);
171 EXPORT_SYMBOL(lustre_swab_llog_rec);
173 static void print_llog_hdr(struct llog_log_hdr *h)
175 CDEBUG(D_OTHER, "llog header: %p\n", h);
176 CDEBUG(D_OTHER, "\tllh_hdr.lrh_index: %#x\n", h->llh_hdr.lrh_index);
177 CDEBUG(D_OTHER, "\tllh_hdr.lrh_len: %#x\n", h->llh_hdr.lrh_len);
178 CDEBUG(D_OTHER, "\tllh_hdr.lrh_type: %#x\n", h->llh_hdr.lrh_type);
179 CDEBUG(D_OTHER, "\tllh_timestamp: "LPX64"\n", h->llh_timestamp);
180 CDEBUG(D_OTHER, "\tllh_count: %#x\n", h->llh_count);
181 CDEBUG(D_OTHER, "\tllh_bitmap_offset: %#x\n", h->llh_bitmap_offset);
182 CDEBUG(D_OTHER, "\tllh_flags: %#x\n", h->llh_flags);
183 CDEBUG(D_OTHER, "\tllh_size: %#x\n", h->llh_size);
184 CDEBUG(D_OTHER, "\tllh_cat_idx: %#x\n", h->llh_cat_idx);
185 CDEBUG(D_OTHER, "\tllh_tail.lrt_index: %#x\n", h->llh_tail.lrt_index);
186 CDEBUG(D_OTHER, "\tllh_tail.lrt_len: %#x\n", h->llh_tail.lrt_len);
189 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
194 lustre_swab_llog_rec(&h->llh_hdr, &h->llh_tail);
199 EXPORT_SYMBOL(lustre_swab_llog_hdr);
201 static void print_lustre_cfg(struct lustre_cfg *lcfg)
206 if (!(portal_debug & D_OTHER)) /* don't loop on nothing */
208 CDEBUG(D_OTHER, "lustre_cfg: %p\n", lcfg);
209 CDEBUG(D_OTHER, "\tlcfg->lcfg_magic: %#x\n", lcfg->lcfg_magic);
210 CDEBUG(D_OTHER, "\tlcfg->lcfg_version: %#x\n", lcfg->lcfg_version);
212 CDEBUG(D_OTHER, "\tlcfg->lcfg_command: %#x\n", lcfg->lcfg_command);
213 CDEBUG(D_OTHER, "\tlcfg->lcfg_num: %#x\n", lcfg->lcfg_num);
214 CDEBUG(D_OTHER, "\tlcfg->lcfg_flags: %#x\n", lcfg->lcfg_flags);
215 CDEBUG(D_OTHER, "\tlcfg->lcfg_nid: "LPX64"\n", lcfg->lcfg_nid);
217 CDEBUG(D_OTHER, "\tlcfg->lcfg_bufcount: %d\n", lcfg->lcfg_bufcount);
218 if (lcfg->lcfg_bufcount < LUSTRE_CFG_MAX_BUFCOUNT)
219 for (i = 0; i < lcfg->lcfg_bufcount; i++)
220 CDEBUG(D_OTHER, "\tlcfg->lcfg_buflens[%d]: %d\n",
221 i, lcfg->lcfg_buflens[i]);
225 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg)
230 __swab32s(&lcfg->lcfg_magic);
232 if (lcfg->lcfg_magic != LUSTRE_CFG_MAGIC) {
233 CERROR("not swabbing lustre_cfg magic %#x (expecting %#x)\n",
234 lcfg->lcfg_magic, LUSTRE_CFG_MAGIC);
239 __swab32s(&lcfg->lcfg_version);
240 __swab32s(&lcfg->lcfg_command);
242 __swab32s(&lcfg->lcfg_num);
243 __swab32s(&lcfg->lcfg_flags);
244 __swab64s(&lcfg->lcfg_nid);
246 __swab32s(&lcfg->lcfg_bufcount);
247 for (i = 0; i < lcfg->lcfg_bufcount && i < LUSTRE_CFG_MAX_BUFCOUNT; i++)
248 __swab32s(&lcfg->lcfg_buflens[i]);
250 print_lustre_cfg(lcfg);
254 EXPORT_SYMBOL(lustre_swab_lustre_cfg);