Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[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 #define EXPORT_SYMTAB
27 #ifndef __KERNEL__
28 # include <liblustre.h>
29 #endif
30
31 #include <linux/obd_ost.h>
32 #include <linux/obd_support.h>
33 #include <linux/lustre_debug.h>
34 #include <linux/lustre_net.h>
35
36 int dump_ioo(struct obd_ioobj *ioo)
37 {
38         CERROR("obd_ioobj: ioo_id="LPD64", ioo_gr="LPD64", ioo_type=%d, "
39                "ioo_bufct=%d\n",
40                ioo->ioo_id, ioo->ioo_gr, ioo->ioo_type, ioo->ioo_bufcnt);
41         return -EINVAL;
42 }
43
44 int dump_lniobuf(struct niobuf_local *nb)
45 {
46         CERROR("niobuf_local: offset="LPD64", len=%d, page=%p, rc=%d\n",
47                nb->offset, nb->len, nb->page, nb->rc);
48         CERROR("nb->page: index = %ld\n", nb->page ? nb->page->index : -1);
49
50         return -EINVAL;
51 }
52
53 int dump_rniobuf(struct niobuf_remote *nb)
54 {
55         CERROR("niobuf_remote: offset="LPU64", len=%d, flags=%x\n",
56                nb->offset, nb->len, nb->flags);
57
58         return -EINVAL;
59 }
60
61 int dump_obdo(struct obdo *oa)
62 {
63         __u32 valid = oa->o_valid;
64
65         CERROR("obdo: o_valid = %08x\n", valid);
66         if (valid & OBD_MD_FLID)
67                 CERROR("obdo: o_id = "LPD64"\n", oa->o_id);
68         if (valid & OBD_MD_FLATIME)
69                 CERROR("obdo: o_atime = "LPD64"\n", oa->o_atime);
70         if (valid & OBD_MD_FLMTIME)
71                 CERROR("obdo: o_mtime = "LPD64"\n", oa->o_mtime);
72         if (valid & OBD_MD_FLCTIME)
73                 CERROR("obdo: o_ctime = "LPD64"\n", oa->o_ctime);
74         if (valid & OBD_MD_FLSIZE)
75                 CERROR("obdo: o_size = "LPD64"\n", oa->o_size);
76         if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
77                 CERROR("obdo: o_blocks = "LPD64"\n", oa->o_blocks);
78         if (valid & OBD_MD_FLBLKSZ)
79                 CERROR("obdo: o_blksize = %d\n", oa->o_blksize);
80         if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
81                 CERROR("obdo: o_mode = %o\n",
82                        oa->o_mode & ((valid & OBD_MD_FLTYPE ?  S_IFMT : 0) |
83                                      (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
84         if (valid & OBD_MD_FLUID)
85                 CERROR("obdo: o_uid = %d\n", oa->o_uid);
86         if (valid & OBD_MD_FLGID)
87                 CERROR("obdo: o_gid = %d\n", oa->o_gid);
88         if (valid & OBD_MD_FLFLAGS)
89                 CERROR("obdo: o_flags = %x\n", oa->o_flags);
90         if (valid & OBD_MD_FLNLINK)
91                 CERROR("obdo: o_nlink = %d\n", oa->o_nlink);
92         if (valid & OBD_MD_FLGENER)
93                 CERROR("obdo: o_generation = %d\n", oa->o_generation);
94
95         return -EINVAL;
96 }
97
98 /* XXX assumes only a single page in request */
99 /*
100 int dump_req(struct ptlrpc_request *req)
101 {
102         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
103         struct obd_ioobj *ioo = lustre_msg_buf(req->rq_reqmsg, 1);
104         //struct niobuf *nb = lustre_msg_buf(req->rq_reqmsg, 2);
105
106         dump_obdo(&body->oa);
107         //dump_niobuf(nb);
108         dump_ioo(ioo);
109
110         return -EINVAL;
111 }
112 */
113
114 #define LPDS sizeof(__u64)
115 int page_debug_setup(void *addr, int len, __u64 off, __u64 id)
116 {
117         LASSERT(addr);
118
119         off = cpu_to_le64 (off);
120         id = cpu_to_le64 (id);
121         memcpy(addr, (char *)&off, LPDS);
122         memcpy(addr + LPDS, (char *)&id, LPDS);
123
124         addr += len - LPDS - LPDS;
125         memcpy(addr, (char *)&off, LPDS);
126         memcpy(addr + LPDS, (char *)&id, LPDS);
127
128         return 0;
129 }
130
131 int page_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
132 {
133         __u64 ne_off;
134         int err = 0;
135
136         LASSERT(addr);
137
138         ne_off = le64_to_cpu (off);
139         id = le64_to_cpu (id);
140         if (memcmp(addr, (char *)&ne_off, LPDS)) {
141                 CERROR("%s: id "LPX64" offset "LPU64" off: "LPX64" != "
142                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
143                 err = -EINVAL;
144         }
145         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
146                 CERROR("%s: id "LPX64" offset "LPU64" id: "LPX64" != "LPX64"\n",
147                        who, id, off, *(__u64 *)(addr + LPDS), id);
148                 err = -EINVAL;
149         }
150
151         addr += end - LPDS - LPDS;
152         if (memcmp(addr, (char *)&ne_off, LPDS)) {
153                 CERROR("%s: id "LPX64" offset "LPU64" end off: "LPX64" != "
154                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
155                 err = -EINVAL;
156         }
157         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
158                 CERROR("%s: id "LPX64" offset "LPU64" end id: "LPX64" != "
159                        LPX64"\n", who, id, off, *(__u64 *)(addr + LPDS), id);
160                 err = -EINVAL;
161         }
162
163         return err;
164 }
165 #undef LPDS
166
167 EXPORT_SYMBOL(dump_lniobuf);
168 EXPORT_SYMBOL(dump_rniobuf);
169 EXPORT_SYMBOL(dump_ioo);
170 //EXPORT_SYMBOL(dump_req);
171 EXPORT_SYMBOL(dump_obdo);
172 EXPORT_SYMBOL(page_debug_setup);
173 EXPORT_SYMBOL(page_debug_check);