Whamcloud - gitweb
LU-2675 llite: remove liblustre includes
[fs/lustre-release.git] / lustre / obdclass / debug.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/obdclass/debug.c
37  *
38  * Helper routines for dumping data structs for debugging.
39  */
40
41 #define DEBUG_SUBSYSTEM D_OTHER
42
43 #ifndef __KERNEL__
44 # include <liblustre.h>
45 #endif
46
47 #include <obd_support.h>
48 #include <lustre_debug.h>
49 #include <lustre_net.h>
50
51 void dump_lniobuf(struct niobuf_local *nb)
52 {
53         CDEBUG(D_RPCTRACE,
54                "niobuf_local: file_offset="LPD64", len=%d, page=%p, rc=%d\n",
55                nb->lnb_file_offset, nb->len, nb->page, nb->rc);
56         CDEBUG(D_RPCTRACE, "nb->page: index = %ld\n",
57                nb->page ? page_index(nb->page) : -1);
58 }
59 EXPORT_SYMBOL(dump_lniobuf);
60
61 #define LPDS sizeof(__u64)
62 int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
63 {
64         LASSERT(addr);
65
66         off = cpu_to_le64 (off);
67         id = cpu_to_le64 (id);
68         memcpy(addr, (char *)&off, LPDS);
69         memcpy(addr + LPDS, (char *)&id, LPDS);
70
71         addr += len - LPDS - LPDS;
72         memcpy(addr, (char *)&off, LPDS);
73         memcpy(addr + LPDS, (char *)&id, LPDS);
74
75         return 0;
76 }
77 EXPORT_SYMBOL(block_debug_setup);
78
79 int block_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
80 {
81         __u64 ne_off;
82         int err = 0;
83
84         LASSERT(addr);
85
86         ne_off = le64_to_cpu (off);
87         id = le64_to_cpu (id);
88         if (memcmp(addr, (char *)&ne_off, LPDS)) {
89                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" off: "LPX64" != "
90                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
91                 err = -EINVAL;
92         }
93         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
94                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" id: "LPX64" != "LPX64"\n",
95                        who, id, off, *(__u64 *)(addr + LPDS), id);
96                 err = -EINVAL;
97         }
98
99         addr += end - LPDS - LPDS;
100         if (memcmp(addr, (char *)&ne_off, LPDS)) {
101                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end off: "LPX64" != "
102                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
103                 err = -EINVAL;
104         }
105         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
106                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end id: "LPX64" != "
107                        LPX64"\n", who, id, off, *(__u64 *)(addr + LPDS), id);
108                 err = -EINVAL;
109         }
110
111         return err;
112 }
113 EXPORT_SYMBOL(block_debug_check);
114 #undef LPDS