Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[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  * Helper routines for dumping data structs for debugging.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * Copryright (C) 2002 Cluster File Systems, Inc.
10  *
11  */
12
13 #define DEBUG_SUBSYSTEM D_OTHER
14
15 #define EXPORT_SYMTAB
16 #ifndef __KERNEL__
17 #include <liblustre.h>
18 #endif
19
20 #include <linux/obd_ost.h>
21 #include <linux/obd_support.h>
22 #include <linux/lustre_debug.h>
23 #include <linux/lustre_net.h>
24
25 int dump_ioo(struct obd_ioobj *ioo)
26 {
27         CERROR("obd_ioobj: ioo_id="LPD64", ioo_gr="LPD64", ioo_type=%d, ioo_bufct=%d\n",
28                ioo->ioo_id, ioo->ioo_gr, ioo->ioo_type, ioo->ioo_bufcnt);
29         return -EINVAL;
30 }
31
32 int dump_lniobuf(struct niobuf_local *nb)
33 {
34         CERROR("niobuf_local: addr=%p, offset="LPD64", len=%d, xid=%d, page=%p\n",
35                nb->addr, nb->offset, nb->len, nb->xid, nb->page);
36         CERROR("nb->page: index = %ld\n", nb->page ? nb->page->index : -1);
37
38         return -EINVAL;
39 }
40
41 int dump_rniobuf(struct niobuf_remote *nb)
42 {
43         CERROR("niobuf_remote: offset="LPD64", len=%d, flags=%x, xid=%d\n",
44                nb->offset, nb->len, nb->flags, nb->xid);
45
46         return -EINVAL;
47 }
48
49 int dump_obdo(struct obdo *oa)
50 {
51         __u32 valid = oa->o_valid;
52
53         CERROR("obdo: o_valid = %08x\n", valid);
54         if (valid & OBD_MD_FLID)
55                 CERROR("obdo: o_id = "LPD64"\n", oa->o_id);
56         if (valid & OBD_MD_FLATIME)
57                 CERROR("obdo: o_atime = "LPD64"\n", oa->o_atime);
58         if (valid & OBD_MD_FLMTIME)
59                 CERROR("obdo: o_mtime = "LPD64"\n", oa->o_mtime);
60         if (valid & OBD_MD_FLCTIME)
61                 CERROR("obdo: o_ctime = "LPD64"\n", oa->o_ctime);
62         if (valid & OBD_MD_FLSIZE)
63                 CERROR("obdo: o_size = "LPD64"\n", oa->o_size);
64         if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
65                 CERROR("obdo: o_blocks = "LPD64"\n", oa->o_blocks);
66         if (valid & OBD_MD_FLBLKSZ)
67                 CERROR("obdo: o_blksize = %d\n", oa->o_blksize);
68         if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
69                 CERROR("obdo: o_mode = %o\n",
70                        oa->o_mode & ((valid & OBD_MD_FLTYPE ?  S_IFMT : 0) |
71                                      (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
72         if (valid & OBD_MD_FLUID)
73                 CERROR("obdo: o_uid = %d\n", oa->o_uid);
74         if (valid & OBD_MD_FLGID)
75                 CERROR("obdo: o_gid = %d\n", oa->o_gid);
76         if (valid & OBD_MD_FLFLAGS)
77                 CERROR("obdo: o_flags = %x\n", oa->o_flags);
78         if (valid & OBD_MD_FLNLINK)
79                 CERROR("obdo: o_nlink = %d\n", oa->o_nlink);
80         if (valid & OBD_MD_FLGENER)
81                 CERROR("obdo: o_generation = %d\n", oa->o_generation);
82
83         return -EINVAL;
84 }
85
86 /* XXX assumes only a single page in request */
87 /*
88 int dump_req(struct ptlrpc_request *req)
89 {
90         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
91         struct obd_ioobj *ioo = lustre_msg_buf(req->rq_reqmsg, 1);
92         //struct niobuf *nb = lustre_msg_buf(req->rq_reqmsg, 2);
93
94         dump_obdo(&body->oa);
95         //dump_niobuf(nb);
96         dump_ioo(ioo);
97
98         return -EINVAL;
99 }
100 */
101
102 #define LPDS sizeof(__u64)
103 int page_debug_setup(void *addr, int len, __u64 off, __u64 id)
104 {
105         LASSERT(addr);
106
107         off = HTON__u64(off);
108         id = HTON__u64(id);
109         memcpy(addr, (char *)&off, LPDS);
110         memcpy(addr + LPDS, (char *)&id, LPDS);
111
112         addr += len - LPDS - LPDS;
113         memcpy(addr, (char *)&off, LPDS);
114         memcpy(addr + LPDS, (char *)&id, LPDS);
115
116         return 0;
117 }
118
119 int page_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
120 {
121         __u64 ne_off;
122         int err = 0;
123
124         LASSERT(addr);
125
126         ne_off = HTON__u64(off);
127         id = HTON__u64(id);
128         if (memcmp(addr, (char *)&ne_off, LPDS)) {
129                 CERROR("%s: id "LPU64" offset "LPU64" off: "LPX64" != "LPX64"\n",
130                        who, id, off, *(__u64 *)addr, ne_off);
131                 err = -EINVAL;
132         }
133         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
134                 CERROR("%s: id "LPU64" offset "LPU64" id: "LPX64" != "LPX64"\n",
135                        who, id, off, *(__u64 *)(addr + LPDS), id);
136                 err = -EINVAL;
137         }
138
139         addr += end - LPDS - LPDS;
140         if (memcmp(addr, (char *)&ne_off, LPDS)) {
141                 CERROR("%s: id "LPU64" offset "LPU64" end off: "LPX64" != "LPX64"\n",
142                        who, id, off, *(__u64 *)addr, ne_off);
143                 err = -EINVAL;
144         }
145         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
146                 CERROR("%s: id "LPU64" offset "LPU64" end id: "LPX64" != "LPX64"\n",
147                        who, id, off, *(__u64 *)(addr + LPDS), id);
148                 err = -EINVAL;
149         }
150
151         return err;
152 }
153 #undef LPDS
154
155 EXPORT_SYMBOL(dump_lniobuf);
156 EXPORT_SYMBOL(dump_rniobuf);
157 EXPORT_SYMBOL(dump_ioo);
158 //EXPORT_SYMBOL(dump_req);
159 EXPORT_SYMBOL(dump_obdo);
160 EXPORT_SYMBOL(page_debug_setup);
161 EXPORT_SYMBOL(page_debug_check);