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