Whamcloud - gitweb
r=phil
[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         __u64 valid = oa->o_valid;
66
67         CERROR("obdo: o_valid = "LPX64"\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 = 0x%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 /* XXX assumes only a single page in request */
101 /*
102 int dump_req(struct ptlrpc_request *req)
103 {
104         struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
105         struct obd_ioobj *ioo = lustre_msg_buf(req->rq_reqmsg, 1);
106         //struct niobuf *nb = lustre_msg_buf(req->rq_reqmsg, 2);
107
108         dump_obdo(&body->oa);
109         //dump_niobuf(nb);
110         dump_ioo(ioo);
111
112         return -EINVAL;
113 }
114 */
115
116 #define LPDS sizeof(__u64)
117 int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
118 {
119         LASSERT(addr);
120
121         off = cpu_to_le64 (off);
122         id = cpu_to_le64 (id);
123         memcpy(addr, (char *)&off, LPDS);
124         memcpy(addr + LPDS, (char *)&id, LPDS);
125
126         addr += len - LPDS - LPDS;
127         memcpy(addr, (char *)&off, LPDS);
128         memcpy(addr + LPDS, (char *)&id, LPDS);
129
130         return 0;
131 }
132
133 int block_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
134 {
135         __u64 ne_off;
136         int err = 0;
137
138         LASSERT(addr);
139
140         ne_off = le64_to_cpu (off);
141         id = le64_to_cpu (id);
142         if (memcmp(addr, (char *)&ne_off, LPDS)) {
143                 CERROR("%s: id "LPX64" offset "LPU64" off: "LPX64" != "
144                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
145                 err = -EINVAL;
146         }
147         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
148                 CERROR("%s: id "LPX64" offset "LPU64" id: "LPX64" != "LPX64"\n",
149                        who, id, off, *(__u64 *)(addr + LPDS), id);
150                 err = -EINVAL;
151         }
152
153         addr += end - LPDS - LPDS;
154         if (memcmp(addr, (char *)&ne_off, LPDS)) {
155                 CERROR("%s: id "LPX64" offset "LPU64" end off: "LPX64" != "
156                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
157                 err = -EINVAL;
158         }
159         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
160                 CERROR("%s: id "LPX64" offset "LPU64" end id: "LPX64" != "
161                        LPX64"\n", who, id, off, *(__u64 *)(addr + LPDS), id);
162                 err = -EINVAL;
163         }
164
165         return err;
166 }
167 #undef LPDS
168
169 EXPORT_SYMBOL(dump_lniobuf);
170 EXPORT_SYMBOL(dump_rniobuf);
171 EXPORT_SYMBOL(dump_ioo);
172 //EXPORT_SYMBOL(dump_req);
173 EXPORT_SYMBOL(dump_obdo);
174 EXPORT_SYMBOL(block_debug_setup);
175 EXPORT_SYMBOL(block_debug_check);