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_lu_fid(struct lu_fid *fid)
90 __swab64s (&fid->f_seq);
91 __swab32s (&fid->f_oid);
92 __swab32s (&fid->f_ver);
94 EXPORT_SYMBOL(lustre_swab_lu_fid);
96 void lustre_swab_lu_range(struct lu_range *range)
98 __swab64s (&range->lr_start);
99 __swab64s (&range->lr_end);
101 EXPORT_SYMBOL(lustre_swab_lu_range);
103 void lustre_swab_llog_rec(struct llog_rec_hdr *rec, struct llog_rec_tail *tail)
105 __swab32s(&rec->lrh_len);
106 __swab32s(&rec->lrh_index);
107 __swab32s(&rec->lrh_type);
109 switch (rec->lrh_type) {
111 struct llog_size_change_rec *lsc =
112 (struct llog_size_change_rec *)rec;
114 lustre_swab_ll_fid(&lsc->lsc_fid);
115 __swab32s(&lsc->lsc_ioepoch);
123 case MDS_UNLINK_REC: {
124 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
126 __swab64s(&lur->lur_oid);
127 __swab32s(&lur->lur_ogen);
132 case MDS_SETATTR_REC: {
133 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
135 __swab64s(&lsr->lsr_oid);
136 __swab32s(&lsr->lsr_ogen);
137 __swab32s(&lsr->lsr_uid);
138 __swab32s(&lsr->lsr_gid);
144 case PTL_CFG_REC: /* obsolete */
145 /* these are swabbed as they are consumed */
148 case LLOG_HDR_MAGIC: {
149 struct llog_log_hdr *llh = (struct llog_log_hdr *)rec;
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);
165 case LLOG_LOGID_MAGIC: {
166 struct llog_logid_rec *lid = (struct llog_logid_rec *)rec;
168 __swab64s(&lid->lid_id.lgl_oid);
169 __swab64s(&lid->lid_id.lgl_ogr);
170 __swab32s(&lid->lid_id.lgl_ogen);
175 /* ignore old pad records of type 0 */
180 CERROR("Unknown llog rec type %#x swabbing rec %p\n",
185 __swab32s(&tail->lrt_len);
186 __swab32s(&tail->lrt_index);
189 EXPORT_SYMBOL(lustre_swab_llog_rec);
191 static void print_llog_hdr(struct llog_log_hdr *h)
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);
207 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
212 lustre_swab_llog_rec(&h->llh_hdr, &h->llh_tail);
217 EXPORT_SYMBOL(lustre_swab_llog_hdr);
219 static void print_lustre_cfg(struct lustre_cfg *lcfg)
224 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
226 CDEBUG(D_OTHER, "lustre_cfg: %p\n", lcfg);
227 CDEBUG(D_OTHER, "\tlcfg->lcfg_version: %#x\n", lcfg->lcfg_version);
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));
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]);
242 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg)
247 __swab32s(&lcfg->lcfg_version);
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);
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]);
264 print_lustre_cfg(lcfg);
268 EXPORT_SYMBOL(lustre_swab_lustre_cfg);