Whamcloud - gitweb
- debug.c was only used by obdclass, so I moved it there
[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 #include <linux/obd_ost.h>
17 #include <linux/lustre_debug.h>
18 #include <linux/lustre_net.h>
19
20 int dump_ioo(struct obd_ioobj *ioo)
21 {
22         CERROR("obd_ioobj: ioo_id=%Ld, ioo_gr=%Ld, ioo_type=%d, ioo_bufct=%d\n",
23                ioo->ioo_id, ioo->ioo_gr, ioo->ioo_type, ioo->ioo_bufcnt);
24         return -EINVAL;
25 }
26
27 int dump_lniobuf(struct niobuf_local *nb)
28 {
29         CERROR("niobuf_local: addr=%p, offset=%Ld, len=%d, xid=%d, page=%p\n",
30                nb->addr, nb->offset, nb->len, nb->xid, nb->page);
31         CERROR("nb->page: index = %ld\n", nb->page ? nb->page->index : -1);
32
33         return -EINVAL;
34 }
35
36 int dump_rniobuf(struct niobuf_remote *nb)
37 {
38         CERROR("niobuf_remote: offset=%Ld, len=%d, flags=%x, xid=%d\n",
39                nb->offset, nb->len, nb->flags, nb->xid);
40
41         return -EINVAL;
42 }
43
44 int dump_obdo(struct obdo *oa)
45 {
46         CERROR("obdo: o_valid = %08x\n", oa->o_valid);
47         if (oa->o_valid & OBD_MD_FLID)
48                 CERROR("obdo: o_id = %Ld\n", oa->o_id);
49         if (oa->o_valid & OBD_MD_FLATIME)
50                 CERROR("obdo: o_atime = %Ld\n", oa->o_atime);
51         if (oa->o_valid & OBD_MD_FLMTIME)
52                 CERROR("obdo: o_mtime = %Ld\n", oa->o_mtime);
53         if (oa->o_valid & OBD_MD_FLCTIME)
54                 CERROR("obdo: o_ctime = %Ld\n", oa->o_ctime);
55         if (oa->o_valid & OBD_MD_FLSIZE)
56                 CERROR("obdo: o_size = %Ld\n", oa->o_size);
57         if (oa->o_valid & OBD_MD_FLBLOCKS)   /* allocation of space */
58                 CERROR("obdo: o_blocks = %Ld\n", oa->o_blocks);
59         if (oa->o_valid & OBD_MD_FLBLKSZ)
60                 CERROR("obdo: o_blksize = %d\n", oa->o_blksize);
61         if (oa->o_valid & OBD_MD_FLMODE)
62                 CERROR("obdo: o_mode = %o\n", oa->o_mode);
63         if (oa->o_valid & OBD_MD_FLUID)
64                 CERROR("obdo: o_uid = %d\n", oa->o_uid);
65         if (oa->o_valid & OBD_MD_FLGID)
66                 CERROR("obdo: o_gid = %d\n", oa->o_gid);
67         if (oa->o_valid & OBD_MD_FLFLAGS)
68                 CERROR("obdo: o_flags = %x\n", oa->o_flags);
69         if (oa->o_valid & OBD_MD_FLNLINK)
70                 CERROR("obdo: o_nlink = %d\n", oa->o_nlink);
71         if (oa->o_valid & OBD_MD_FLGENER)
72                 CERROR("obdo: o_generation = %d\n", oa->o_generation);
73
74         return -EINVAL;
75 }
76
77 /* XXX assumes only a single page in request */
78 /*
79 int dump_req(struct ptlrpc_request *req)
80 {
81         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
82         struct obd_ioobj *ioo = lustre_msg_buf(req->rq_reqmsg, 1);
83         //struct niobuf *nb = lustre_msg_buf(req->rq_reqmsg, 2);
84
85         dump_obdo(&body->oa);
86         //dump_niobuf(nb);
87         dump_ioo(ioo);
88
89         return -EINVAL;
90 }
91 */
92
93 #define LPDS sizeof(__u64)
94 int page_debug_setup(void *addr, int len, __u64 off, __u64 id)
95 {
96         LASSERT(addr);
97
98         off = HTON__u64(off);
99         id = HTON__u64(id);
100         memcpy(addr, (char *)&off, LPDS);
101         memcpy(addr + LPDS, (char *)&id, LPDS);
102
103         addr += len - LPDS - LPDS;
104         memcpy(addr, (char *)&off, LPDS);
105         memcpy(addr + LPDS, (char *)&id, LPDS);
106
107         return 0;
108 }
109
110 int page_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
111 {
112         __u64 ne_off;
113         int err = 0;
114
115         LASSERT(addr);
116
117         ne_off = HTON__u64(off);
118         id = HTON__u64(id);
119         if (memcmp(addr, (char *)&ne_off, LPDS)) {
120                 CERROR("%s: id "LPU64" offset "LPU64" off: "LPX64" != "LPX64"\n",
121                        who, id, off, *(__u64 *)addr, ne_off);
122                 err = -EINVAL;
123         }
124         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
125                 CERROR("%s: id "LPU64" offset "LPU64" id: "LPX64" != "LPX64"\n",
126                        who, id, off, *(__u64 *)(addr + LPDS), id);
127                 err = -EINVAL;
128         }
129
130         addr += end - LPDS - LPDS;
131         if (memcmp(addr, (char *)&ne_off, LPDS)) {
132                 CERROR("%s: id "LPU64" offset "LPU64" end off: "LPX64" != "LPX64"\n",
133                        who, id, off, *(__u64 *)addr, ne_off);
134                 err = -EINVAL;
135         }
136         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
137                 CERROR("%s: id "LPU64" offset "LPU64" end id: "LPX64" != "LPX64"\n",
138                        who, id, off, *(__u64 *)(addr + LPDS), id);
139                 err = -EINVAL;
140         }
141
142         return err;
143 }
144 #undef LPDS
145
146 EXPORT_SYMBOL(dump_lniobuf);
147 EXPORT_SYMBOL(dump_rniobuf);
148 EXPORT_SYMBOL(dump_ioo);
149 //EXPORT_SYMBOL(dump_req);
150 EXPORT_SYMBOL(dump_obdo);
151 EXPORT_SYMBOL(page_debug_setup);
152 EXPORT_SYMBOL(page_debug_check);