Whamcloud - gitweb
b=4889,5773
[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  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Helper routines for dumping data structs for debugging.
22  */
23
24 #define DEBUG_SUBSYSTEM D_OTHER
25
26 #ifndef EXPORT_SYMTAB
27 # define EXPORT_SYMTAB
28 #endif
29 #ifndef __KERNEL__
30 # include <liblustre.h>
31 #endif
32
33 #include <linux/obd_ost.h>
34 #include <linux/obd_support.h>
35 #include <linux/lustre_debug.h>
36 #include <linux/lustre_net.h>
37
38 int dump_ioo(struct obd_ioobj *ioo)
39 {
40         CERROR("obd_ioobj: ioo_id="LPD64", ioo_gr="LPD64", ioo_type=%d, "
41                "ioo_bufct=%d\n",
42                ioo->ioo_id, ioo->ioo_gr, ioo->ioo_type, ioo->ioo_bufcnt);
43         return -EINVAL;
44 }
45
46 int dump_lniobuf(struct niobuf_local *nb)
47 {
48         CERROR("niobuf_local: offset="LPD64", len=%d, page=%p, rc=%d\n",
49                nb->offset, nb->len, nb->page, nb->rc);
50         CERROR("nb->page: index = %ld\n", nb->page ? nb->page->index : -1);
51
52         return -EINVAL;
53 }
54
55 int dump_rniobuf(struct niobuf_remote *nb)
56 {
57         CERROR("niobuf_remote: offset="LPU64", len=%d, flags=%x\n",
58                nb->offset, nb->len, nb->flags);
59
60         return -EINVAL;
61 }
62
63 int dump_obdo(struct obdo *oa)
64 {
65         __u32 valid = oa->o_valid;
66
67         CERROR("obdo: o_valid = %08x\n", valid);
68         if (valid & OBD_MD_FLID)
69                 CERROR("obdo: o_id = "LPD64"\n", oa->o_id);
70         if (valid & OBD_MD_FLATIME)
71                 CERROR("obdo: o_atime = "LPD64"\n", oa->o_atime);
72         if (valid & OBD_MD_FLMTIME)
73                 CERROR("obdo: o_mtime = "LPD64"\n", oa->o_mtime);
74         if (valid & OBD_MD_FLCTIME)
75                 CERROR("obdo: o_ctime = "LPD64"\n", oa->o_ctime);
76         if (valid & OBD_MD_FLSIZE)
77                 CERROR("obdo: o_size = "LPD64"\n", oa->o_size);
78         if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
79                 CERROR("obdo: o_blocks = "LPD64"\n", oa->o_blocks);
80         if (valid & OBD_MD_FLBLKSZ)
81                 CERROR("obdo: o_blksize = %d\n", oa->o_blksize);
82         if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
83                 CERROR("obdo: o_mode = %o\n",
84                        oa->o_mode & ((valid & OBD_MD_FLTYPE ?  S_IFMT : 0) |
85                                      (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
86         if (valid & OBD_MD_FLUID)
87                 CERROR("obdo: o_uid = %u\n", oa->o_uid);
88         if (valid & OBD_MD_FLGID)
89                 CERROR("obdo: o_gid = %u\n", oa->o_gid);
90         if (valid & OBD_MD_FLFLAGS)
91                 CERROR("obdo: o_flags = %x\n", oa->o_flags);
92         if (valid & OBD_MD_FLNLINK)
93                 CERROR("obdo: o_nlink = %u\n", oa->o_nlink);
94         if (valid & OBD_MD_FLGENER)
95                 CERROR("obdo: o_generation = %u\n", oa->o_generation);
96
97         return -EINVAL;
98 }
99
100 void dump_lsm(int level, struct lov_stripe_md *lsm)
101 {
102         CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
103                "stripe_size %u, stripe_count %u\n",
104                lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
105                lsm->lsm_stripe_size, lsm->lsm_stripe_count);
106 }
107
108 /* XXX assumes only a single page in request */
109 /*
110 int dump_req(struct ptlrpc_request *req)
111 {
112         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
113         struct obd_ioobj *ioo = lustre_msg_buf(req->rq_reqmsg, 1);
114         //struct niobuf *nb = lustre_msg_buf(req->rq_reqmsg, 2);
115
116         dump_obdo(&body->oa);
117         //dump_niobuf(nb);
118         dump_ioo(ioo);
119
120         return -EINVAL;
121 }
122 */
123
124 #define LPDS sizeof(__u64)
125 int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
126 {
127         LASSERT(addr);
128
129         off = cpu_to_le64 (off);
130         id = cpu_to_le64 (id);
131         memcpy(addr, (char *)&off, LPDS);
132         memcpy(addr + LPDS, (char *)&id, LPDS);
133
134         addr += len - LPDS - LPDS;
135         memcpy(addr, (char *)&off, LPDS);
136         memcpy(addr + LPDS, (char *)&id, LPDS);
137
138         return 0;
139 }
140
141 int block_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
142 {
143         __u64 ne_off;
144         int err = 0;
145
146         LASSERT(addr);
147
148         ne_off = le64_to_cpu (off);
149         id = le64_to_cpu (id);
150         if (memcmp(addr, (char *)&ne_off, LPDS)) {
151                 CERROR("%s: id "LPX64" offset "LPU64" off: "LPX64" != "
152                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
153                 err = -EINVAL;
154         }
155         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
156                 CERROR("%s: id "LPX64" offset "LPU64" id: "LPX64" != "LPX64"\n",
157                        who, id, off, *(__u64 *)(addr + LPDS), id);
158                 err = -EINVAL;
159         }
160
161         addr += end - LPDS - LPDS;
162         if (memcmp(addr, (char *)&ne_off, LPDS)) {
163                 CERROR("%s: id "LPX64" offset "LPU64" end off: "LPX64" != "
164                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
165                 err = -EINVAL;
166         }
167         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
168                 CERROR("%s: id "LPX64" offset "LPU64" end id: "LPX64" != "
169                        LPX64"\n", who, id, off, *(__u64 *)(addr + LPDS), id);
170                 err = -EINVAL;
171         }
172
173         return err;
174 }
175 #undef LPDS
176
177 EXPORT_SYMBOL(dump_lniobuf);
178 EXPORT_SYMBOL(dump_rniobuf);
179 EXPORT_SYMBOL(dump_ioo);
180 //EXPORT_SYMBOL(dump_req);
181 EXPORT_SYMBOL(dump_obdo);
182 EXPORT_SYMBOL(dump_lsm);
183 EXPORT_SYMBOL(block_debug_setup);
184 EXPORT_SYMBOL(block_debug_check);