Whamcloud - gitweb
new llog open mechanism
[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 #ifndef __KERNEL__
29 #include <liblustre.h>
30 #endif
31
32 #include <linux/lustre_log.h>
33
34 static void print_llogd_body(struct llogd_body *d)
35 {
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);
46 }
47
48 void lustre_swab_llogd_body (struct llogd_body *d)
49 {
50         ENTRY;
51         print_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);
61         print_llogd_body(d);
62         EXIT;
63 }
64 EXPORT_SYMBOL(lustre_swab_llogd_body);
65
66 void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
67 {
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);
74 }
75 EXPORT_SYMBOL(lustre_swab_llogd_conn_body);
76
77 void lustre_swab_ll_fid (struct ll_fid *fid)
78 {
79         __swab64s (&fid->id);
80         __swab32s (&fid->generation);
81         __swab32s (&fid->f_type);
82 }
83 EXPORT_SYMBOL(lustre_swab_ll_fid);
84
85 void lustre_swab_llog_rec(struct llog_rec_hdr *rec, struct llog_rec_tail *tail)
86 {
87         __swab32s(&rec->lrh_len);
88         __swab32s(&rec->lrh_index);
89         __swab32s(&rec->lrh_type);
90
91         switch (rec->lrh_type) {
92         case OST_SZ_REC: {
93                 struct llog_size_change_rec *lsc =
94                         (struct llog_size_change_rec *)rec;
95
96                 lustre_swab_ll_fid(&lsc->lsc_fid);
97                 __swab32s(&lsc->lsc_io_epoch);
98
99                 break;
100         }
101
102         case OST_RAID1_REC:
103                 break;
104
105         case MDS_UNLINK_REC: {
106                 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
107
108                 __swab64s(&lur->lur_oid);
109                 __swab32s(&lur->lur_ogen);
110
111                 break;
112         }
113
114         case MDS_SETATTR_REC: {
115                 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
116
117                 __swab64s(&lsr->lsr_oid);
118                 __swab32s(&lsr->lsr_ogen);
119                 __swab32s(&lsr->lsr_uid);
120                 __swab32s(&lsr->lsr_gid);
121
122                 break;
123         }
124
125         case OBD_CFG_REC:
126         case PTL_CFG_REC:                       /* obsolete */
127                 /* these are swabbed as they are consumed */
128                 break;
129
130         case LLOG_HDR_MAGIC: {
131                 struct llog_log_hdr *llh = (struct llog_log_hdr *)rec;
132
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);
142                 }
143
144                 break;
145         }
146
147         case LLOG_LOGID_MAGIC: {
148                 struct llog_logid_rec *lid = (struct llog_logid_rec *)rec;
149
150                 __swab64s(&lid->lid_id.lgl_oid);
151                 __swab64s(&lid->lid_id.lgl_ogr);
152                 __swab32s(&lid->lid_id.lgl_ogen);
153                 break;
154         }
155
156         case LLOG_PAD_MAGIC:
157         /* ignore old pad records of type 0 */
158         case 0:
159                 break;
160
161         default:
162                 CERROR("Unknown llog rec type %#x swabbing rec %p\n",
163                        rec->lrh_type, rec);
164         }
165
166         if (tail) {
167                 __swab32s(&tail->lrt_len);
168                 __swab32s(&tail->lrt_index);
169         }
170 }
171 EXPORT_SYMBOL(lustre_swab_llog_rec);
172
173 static void print_llog_hdr(struct llog_log_hdr *h)
174 {
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);
187 }
188
189 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
190 {
191         ENTRY;
192         print_llog_hdr(h);
193
194         lustre_swab_llog_rec(&h->llh_hdr, &h->llh_tail);
195
196         print_llog_hdr(h);
197         EXIT;
198 }
199 EXPORT_SYMBOL(lustre_swab_llog_hdr);
200
201 static void print_lustre_cfg(struct lustre_cfg *lcfg)
202 {
203         int i;
204         ENTRY;
205
206         if (!(portal_debug & D_OTHER)) /* don't loop on nothing */
207                 return;
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);
211
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);
216
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]);
222         EXIT;
223 }
224
225 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg)
226 {
227         int i;
228         ENTRY;
229
230         __swab32s(&lcfg->lcfg_magic);
231
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);
235                 EXIT;
236                 return;
237         }
238
239         __swab32s(&lcfg->lcfg_version);
240         __swab32s(&lcfg->lcfg_command);
241
242         __swab32s(&lcfg->lcfg_num);
243         __swab32s(&lcfg->lcfg_flags);
244         __swab64s(&lcfg->lcfg_nid);
245
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]);
249
250         print_lustre_cfg(lcfg);
251         EXIT;
252         return;
253 }
254 EXPORT_SYMBOL(lustre_swab_lustre_cfg);