Whamcloud - gitweb
ed5faa384791d5a8407c9b18f6e685d3fea82d41
[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 pool "POOLNAMEF"\n", lsm,
121                lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
122                lsm->lsm_stripe_size, lsm->lsm_stripe_count,
123                lsm->lsm_pool_name);
124 }
125
126 /* XXX assumes only a single page in request */
127 /*
128 int dump_req(struct ptlrpc_request *req)
129 {
130         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
131         struct obd_ioobj *ioo = lustre_msg_buf(req->rq_reqmsg, 1);
132         //struct niobuf *nb = lustre_msg_buf(req->rq_reqmsg, 2);
133
134         dump_obdo(&body->oa);
135         //dump_niobuf(nb);
136         dump_ioo(ioo);
137
138         return -EINVAL;
139 }
140 */
141
142 #define LPDS sizeof(__u64)
143 int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
144 {
145         LASSERT(addr);
146
147         off = cpu_to_le64 (off);
148         id = cpu_to_le64 (id);
149         memcpy(addr, (char *)&off, LPDS);
150         memcpy(addr + LPDS, (char *)&id, LPDS);
151
152         addr += len - LPDS - LPDS;
153         memcpy(addr, (char *)&off, LPDS);
154         memcpy(addr + LPDS, (char *)&id, LPDS);
155
156         return 0;
157 }
158
159 int block_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
160 {
161         __u64 ne_off;
162         int err = 0;
163
164         LASSERT(addr);
165
166         ne_off = le64_to_cpu (off);
167         id = le64_to_cpu (id);
168         if (memcmp(addr, (char *)&ne_off, LPDS)) {
169                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" off: "LPX64" != "
170                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
171                 err = -EINVAL;
172         }
173         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
174                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" id: "LPX64" != "LPX64"\n",
175                        who, id, off, *(__u64 *)(addr + LPDS), id);
176                 err = -EINVAL;
177         }
178
179         addr += end - LPDS - LPDS;
180         if (memcmp(addr, (char *)&ne_off, LPDS)) {
181                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end off: "LPX64" != "
182                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
183                 err = -EINVAL;
184         }
185         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
186                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end id: "LPX64" != "
187                        LPX64"\n", who, id, off, *(__u64 *)(addr + LPDS), id);
188                 err = -EINVAL;
189         }
190
191         return err;
192 }
193 #undef LPDS
194
195 EXPORT_SYMBOL(dump_lniobuf);
196 EXPORT_SYMBOL(dump_rniobuf);
197 EXPORT_SYMBOL(dump_ioo);
198 //EXPORT_SYMBOL(dump_req);
199 EXPORT_SYMBOL(dump_obdo);
200 EXPORT_SYMBOL(dump_lsm);
201 EXPORT_SYMBOL(block_debug_setup);
202 EXPORT_SYMBOL(block_debug_check);