Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[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, Whamcloud, Inc.
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 EXPORT_SYMTAB
44 # define EXPORT_SYMTAB
45 #endif
46 #ifndef __KERNEL__
47 # include <liblustre.h>
48 #endif
49
50 #include <obd_ost.h>
51 #include <obd_support.h>
52 #include <lustre_debug.h>
53 #include <lustre_net.h>
54
55 void dump_lniobuf(struct niobuf_local *nb)
56 {
57         CDEBUG(D_RPCTRACE,
58                "niobuf_local: offset="LPD64", len=%d, page=%p, rc=%d\n",
59                nb->offset, nb->len, nb->page, nb->rc);
60         CDEBUG(D_RPCTRACE, "nb->page: index = %ld\n",
61                nb->page ? cfs_page_index(nb->page) : -1);
62 }
63 EXPORT_SYMBOL(dump_lniobuf);
64
65 void dump_lsm(int level, struct lov_stripe_md *lsm)
66 {
67         CDEBUG(level, "lsm %p, objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
68                "stripe_size %u, stripe_count %u, "
69                "layout_gen %u, pool ["LOV_POOLNAMEF"]\n", lsm,
70                lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
71                lsm->lsm_stripe_size, lsm->lsm_stripe_count,
72                lsm->lsm_layout_gen, lsm->lsm_pool_name);
73 }
74
75 #define LPDS sizeof(__u64)
76 int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
77 {
78         LASSERT(addr);
79
80         off = cpu_to_le64 (off);
81         id = cpu_to_le64 (id);
82         memcpy(addr, (char *)&off, LPDS);
83         memcpy(addr + LPDS, (char *)&id, LPDS);
84
85         addr += len - LPDS - LPDS;
86         memcpy(addr, (char *)&off, LPDS);
87         memcpy(addr + LPDS, (char *)&id, LPDS);
88
89         return 0;
90 }
91
92 int block_debug_check(char *who, void *addr, int end, __u64 off, __u64 id)
93 {
94         __u64 ne_off;
95         int err = 0;
96
97         LASSERT(addr);
98
99         ne_off = le64_to_cpu (off);
100         id = le64_to_cpu (id);
101         if (memcmp(addr, (char *)&ne_off, LPDS)) {
102                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" off: "LPX64" != "
103                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
104                 err = -EINVAL;
105         }
106         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
107                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" id: "LPX64" != "LPX64"\n",
108                        who, id, off, *(__u64 *)(addr + LPDS), id);
109                 err = -EINVAL;
110         }
111
112         addr += end - LPDS - LPDS;
113         if (memcmp(addr, (char *)&ne_off, LPDS)) {
114                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end off: "LPX64" != "
115                        LPX64"\n", who, id, off, *(__u64 *)addr, ne_off);
116                 err = -EINVAL;
117         }
118         if (memcmp(addr + LPDS, (char *)&id, LPDS)) {
119                 CDEBUG(D_ERROR, "%s: id "LPX64" offset "LPU64" end id: "LPX64" != "
120                        LPX64"\n", who, id, off, *(__u64 *)(addr + LPDS), id);
121                 err = -EINVAL;
122         }
123
124         return err;
125 }
126 #undef LPDS
127
128 //EXPORT_SYMBOL(dump_req);
129 EXPORT_SYMBOL(dump_lsm);
130 EXPORT_SYMBOL(block_debug_setup);
131 EXPORT_SYMBOL(block_debug_check);