Whamcloud - gitweb
Pass 1 of debugging and leak cleanup:
[fs/lustre-release.git] / lustre / include / linux / obd_support.h
1 #ifndef _OBD_SUPPORT
2 #define _OBD_SUPPORT
3 /*
4  * Copyright (C) 2001  Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #include <linux/autoconf.h>
11 #include <linux/slab.h>
12
13 #define obd_unlock_page(page)                                           \
14 do {                                                                    \
15         if (PageLocked(page)) {                                         \
16                 UnlockPage(page);                                       \
17         } else {                                                        \
18                 printk("file %s, line %d: expecting locked page\n",     \
19                        __FILE__, __LINE__);                             \
20         }                                                               \
21 } while(0)
22
23 /*
24  * Debug code
25  */
26 /* global variables */
27 extern int obd_debug_level;
28 extern int obd_print_entry;
29 extern int obd_inodes;
30 extern int obd_pages;
31 extern long obd_memory;
32
33 #define EXT2_OBD_DEBUG
34
35 #ifdef EXT2_OBD_DEBUG
36 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
37
38 /* debugging masks */
39 #define D_PSDEV   0x001 /* debug information from psdev.c */
40 #define D_INODE   0x002
41 #define D_SUPER   0x004
42 #define D_SNAP    0x008
43 #define D_UNUSED4 0x010
44 #define D_WARNING 0x020 /* misc warnings */
45 #define D_EXT2    0x040 /* anything from ext2_debug */
46 #define D_MALLOC  0x080 /* print malloc, free information */
47 #define D_CACHE   0x100 /* cache-related items */
48 #define D_INFO    0x200 /* general information, especially from interface.c */
49 #define D_IOCTL   0x400 /* ioctl related information */
50 #define D_BLOCKS  0x800 /* ext2 block allocation */
51 #define D_NET    0x1000 /* network communications */
52 #define D_PUNCH  0x2000
53 #define D_BUFFS  0x4000 /* print network buffers */
54  
55 #define CDEBUG(mask, format, a...)                                      \
56         do {                                                            \
57         if (obd_debug_level & mask) {                                   \
58                 printk("(%s:%d):", __FUNCTION__, __LINE__);             \
59                 printk(format, ## a); }                                 \
60         } while (0)
61
62 #define ENTRY if (obd_print_entry)                                      \
63         printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
64
65 #define EXIT if (obd_print_entry)                                       \
66         printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid,  \
67                __FUNCTION__, __LINE__)
68
69 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
70 #define ICDEBUG(inode) {                                                \
71         CDEBUG(D_INFO,                                                  \
72                "ino %ld, atm %ld, mtm %ld, ctm %ld, size %Ld, blocks %ld\n",\
73                inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
74                inode->i_size, inode->i_blocks);                         \
75         CDEBUG(D_INFO, "mode %o, uid %d, gid %d, nlnk %d, count %d\n",  \
76                inode->i_mode, inode->i_uid, inode->i_gid, inode->i_nlink,\
77                atomic_read(&inode->i_count));                                         \
78 }
79
80 /* Ext2 inode information */
81 #define EXDEBUG(inode) {                                                \
82         ICDEBUG(inode);                                                 \
83         CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n",        \
84                inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1],    \
85                inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3],    \
86                inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5],    \
87                inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]);   \
88 }
89
90 /* OBDFS inode information */
91 #define OIDEBUG(inode) {                                                \
92         ICDEBUG(inode);                                                 \
93         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
94         /* obdfs_print_plist(inode); */                                 \
95 }
96
97 #define ODEBUG(obdo) {                                                  \
98         CDEBUG(D_INFO, "id %ld, atm %ld, mtm %ld, ctm %ld, "            \
99                "size %ld, blocks %ld\n",                                \
100                (long)(obdo)->o_id, (long)(obdo)->o_atime,               \
101                (long)(obdo)->o_mtime, (long)(obdo)->o_ctime,            \
102                (long)(obdo)->o_size, (long)(obdo)->o_blocks);           \
103         CDEBUG(D_INFO, " mode %o, uid %d, gid %d, flg 0x%0x, "          \
104                "obdflg 0x%0x, nlnk %d, valid 0x%0x\n",                  \
105                (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
106                (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid);   \
107 }
108
109
110 #define PDEBUG(page,msg) {                                              \
111         if (page){                                                      \
112                 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
113                 char *locked = (PageLocked(page)) ? "" : "un";          \
114                 char *buffer = page->buffers ? "buffer" : "";           \
115                 int count = page_count(page);                           \
116                 long index = page->index;                               \
117                 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
118                        " cnt %d page 0x%p pages %ld virt %lx %s**\n",   \
119                        msg, index, uptodate, locked, page->flags, count,\
120                        page, page->mapping ? page->mapping->nrpages : -1,\
121                        page->virtual, buffer);                          \
122         } else                                                          \
123                 CDEBUG(D_CACHE, "** %s: no page\n", msg);               \
124 }
125
126 #if 0
127 #define iget(sb, ino) obd_iget(sb, ino)
128 #define iput(sb, ino) obd_iput(sb, ino)
129
130 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
131 {
132         struct inode *inode;
133         
134         if ((inode = iget(sb, ino)) == NULL)
135                 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
136         else
137                 obd_inodes++;
138         return inode;
139 }
140
141 static inline void obd_iput(struct inode *inode)
142 {
143         if (inode == NULL)
144                 CDEBUG(D_INODE, "NULL in iput\n");
145         else
146                 obd_inodes--;
147 }
148 #endif
149
150 #else /* EXT2_OBD_DEBUG */
151
152 #define CDEBUG(mask, format, a...) {}
153 #define ENTRY {}
154 #define EXIT {}
155 #define ODEBUG(obdo) {}
156 #define EXDEBUG(inode) {}
157 #define OIDEBUG(inode) {}
158 #define PDEBUG(page, cmd) {}
159
160 #endif /* EXT2_OBD_DEBUG */
161
162 #define OBD_ALLOC(ptr, size)                                    \
163 do {                                                            \
164         (ptr) = kmalloc((unsigned long)(size), GFP_KERNEL);     \
165         obd_memory += (size);                                   \
166         CDEBUG(D_MALLOC, "kmalloced: %ld at %x (tot %ld).\n",   \
167                (long)(size), (int)(ptr), obd_memory);           \
168         if (ptr == NULL) {                                      \
169                 printk("kernel malloc failed at %s:%d\n",       \
170                        __FILE__, __LINE__);                     \
171         } else {                                                \
172                 memset((ptr), 0, (size));                       \
173         }                                                       \
174 } while (0)
175
176 #define OBD_FREE(ptr, size)                                  \
177 do {                                                         \
178         kfree((ptr));                                        \
179         obd_memory -= (size);                                \
180         CDEBUG(D_MALLOC, "kfreed: %d at %x (tot %ld).\n",    \
181                (int)(size), (int)(ptr), obd_memory);         \
182 } while (0)
183
184 #endif