Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / obdclass / debug.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/obdclass/debug.c
37  *
38  * Helper routines for dumping data structs for debugging.
39  */
40
41 #define DEBUG_SUBSYSTEM D_OTHER
42
43 #ifndef EXPORT_SYMTAB
44 # define EXPORT_SYMTAB
45 #endif
46 #ifndef __KERNEL__
47 # include <liblustre.h>
48 #endif
49
50 #include <obd_ost.h>
51 #include <obd_support.h>
52 #include <lustre_debug.h>
53 #include <lustre_net.h>
54
55 int dump_ioo(struct obd_ioobj *ioo)
56 {
57         CERROR("obd_ioobj: ioo_id="LPD64", ioo_gr="LPD64", ioo_type=%d, "
58                "ioo_bufct=%d\n",
59                ioo->ioo_id, ioo->ioo_gr, ioo->ioo_type, ioo->ioo_bufcnt);
60         return -EINVAL;
61 }
62
63 int dump_lniobuf(struct niobuf_local *nb)
64 {
65         CERROR("niobuf_local: offset="LPD64", len=%d, page=%p, rc=%d\n",
66                nb->offset, nb->len, nb->page, nb->rc);
67         CERROR("nb->page: index = %ld\n", nb->page ? cfs_page_index(nb->page) : -1);
68
69         return -EINVAL;
70 }
71
72 int dump_rniobuf(struct niobuf_remote *nb)
73 {
74         CERROR("niobuf_remote: offset="LPU64", len=%d, flags=%x\n",
75                nb->offset, nb->len, nb->flags);
76
77         return -EINVAL;
78 }
79
80 int dump_obdo(struct obdo *oa)
81 {
82         __u32 valid = oa->o_valid;
83
84         CERROR("obdo: o_valid = %08x\n", valid);
85         if (valid & OBD_MD_FLID)
86                 CERROR("obdo: o_id = "LPD64"\n", oa->o_id);
87         if (valid & OBD_MD_FLATIME)
88                 CERROR("obdo: o_atime = "LPD64"\n", oa->o_atime);
89         if (valid & OBD_MD_FLMTIME)
90                 CERROR("obdo: o_mtime = "LPD64"\n", oa->o_mtime);
91         if (valid & OBD_MD_FLCTIME)
92                 CERROR("obdo: o_ctime = "LPD64"\n", oa->o_ctime);
93         if (valid & OBD_MD_FLSIZE)
94                 CERROR("obdo: o_size = "LPD64"\n", oa->o_size);
95         if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
96                 CERROR("obdo: o_blocks = "LPD64"\n", oa->o_blocks);
97         if (valid & OBD_MD_FLBLKSZ)
98                 CERROR("obdo: o_blksize = %d\n", oa->o_blksize);
99         if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
100                 CERROR("obdo: o_mode = %o\n",
101                        oa->o_mode & ((valid & OBD_MD_FLTYPE ?  S_IFMT : 0) |
102                                      (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
103         if (valid & OBD_MD_FLUID)
104                 CERROR("obdo: o_uid = %u\n", oa->o_uid);
105         if (valid & OBD_MD_FLGID)
106                 CERROR("obdo: o_gid = %u\n", oa->o_gid);
107         if (valid & OBD_MD_FLFLAGS)
108                 CERROR("obdo: o_flags = %x\n", oa->o_flags);
109         if (valid & OBD_MD_FLNLINK)
110                 CERROR("obdo: o_nlink = %u\n", oa->o_nlink);
111         if (valid & OBD_MD_FLGENER)
112                 CERROR("obdo: o_generation = %u\n", oa->o_generation);
113
114         return -EINVAL;
115 }
116
117 void dump_lsm(int level, struct lov_stripe_md *lsm)
118 {
119         CDEBUG(level, "lsm %p, objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
120                "stripe_size %u, stripe_count %u\n", lsm,
121                lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
122                lsm->lsm_stripe_size, lsm->lsm_stripe_count);
123 }
124
125 /* XXX assumes only a single page in request */
126 /*
127 int dump_req(struct ptlrpc_request *req)
128 {
129         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
130         struct obd_ioobj *ioo = lustre_msg_buf(req->rq_reqmsg, 1);
131         //struct niobuf *nb = lustre_msg_buf(req->rq_reqmsg, 2);
132
133         dump_obdo(&body->oa);
134         //dump_niobuf(nb);
135         dump_ioo(ioo);
136
137         return -EINVAL;
138 }
139 */
140
141 #define LPDS sizeof(__u64)
142 int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
143 {
144         LASSERT(addr);
145
146         off = cpu_to_le64 (off);
147         id = cpu_to_le64 (id);
148         memcpy(addr, (char *)&off, LPDS);
149         memcpy(addr + LPDS, (char *)&id, LPDS);
150
151         addr += len - LPDS - LPDS;
152         memcpy(addr, (char *)&off, LPDS);
153         memcpy(addr + LPDS, (char *)&id, LPDS);
154
155         return 0;
156 }
157
158 int block_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
159 {
160         __u64 ne_off;
161         int err = 0;
162
163         LASSERT(addr);
164
165         ne_off = le64_to_cpu (off);
166         id = le64_to_cpu (id);
167         if (memcmp(addr, (char *)&ne_off, LPDS)) {
168                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" off: "LPX64" != "
169                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
170                 err = -EINVAL;
171         }
172         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
173                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" id: "LPX64" != "LPX64"\n",
174                        who, id, off, *(__u64 *)(addr + LPDS), id);
175                 err = -EINVAL;
176         }
177
178         addr += end - LPDS - LPDS;
179         if (memcmp(addr, (char *)&ne_off, LPDS)) {
180                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end off: "LPX64" != "
181                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
182                 err = -EINVAL;
183         }
184         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
185                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end id: "LPX64" != "
186                        LPX64"\n", who, id, off, *(__u64 *)(addr + LPDS), id);
187                 err = -EINVAL;
188         }
189
190         return err;
191 }
192 #undef LPDS
193
194 EXPORT_SYMBOL(dump_lniobuf);
195 EXPORT_SYMBOL(dump_rniobuf);
196 EXPORT_SYMBOL(dump_ioo);
197 //EXPORT_SYMBOL(dump_req);
198 EXPORT_SYMBOL(dump_obdo);
199 EXPORT_SYMBOL(dump_lsm);
200 EXPORT_SYMBOL(block_debug_setup);
201 EXPORT_SYMBOL(block_debug_check);