Whamcloud - gitweb
- Converted lots of debugging printks to CDEBUGs
[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 #include <linux/kp30.h>
13
14 #define obd_unlock_page(page)                                           \
15 do {                                                                    \
16         if (PageLocked(page)) {                                         \
17                 UnlockPage(page);                                       \
18         } else {                                                        \
19                 printk("file %s, line %d: expecting locked page\n",     \
20                        __FILE__, __LINE__);                             \
21         }                                                               \
22 } while(0)
23
24 /*
25  * Debug code
26  */
27 /* global variables */
28 extern int obd_debug_level;
29 extern int obd_print_entry;
30 extern int obd_inodes;
31 extern int obd_pages;
32 extern long obd_memory;
33
34 #define EXT2_OBD_DEBUG
35
36 #ifdef EXT2_OBD_DEBUG
37 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
38
39 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
40 #define ICDEBUG(inode) {                                                \
41         CDEBUG(D_INFO, "ino %ld, atm %ld, mtm %ld, ctm %ld, size %Ld, " \
42                "blocks %ld\n", inode->i_ino, inode->i_atime,            \
43                inode->i_mtime, inode->i_ctime, inode->i_size,           \
44                inode->i_blocks);                                        \
45         CDEBUG(D_INFO, "mode %o, uid %d, gid %d, nlnk %d, count %d\n",  \
46                inode->i_mode, inode->i_uid, inode->i_gid,               \
47                inode->i_nlink, atomic_read(&inode->i_count));           \
48 }
49
50 /* Ext2 inode information */
51 #define EXDEBUG(inode) {                                                \
52         ICDEBUG(inode);                                                 \
53         CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n",        \
54                inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1],    \
55                inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3],    \
56                inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5],    \
57                inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]);   \
58 }
59
60 /* OBDFS inode information */
61 #define OIDEBUG(inode) {                                                \
62         ICDEBUG(inode);                                                 \
63         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
64         /* obdfs_print_plist(inode); */                                 \
65 }
66
67 #define ODEBUG(obdo) {                                                  \
68         CDEBUG(D_INFO, "id %ld, atm %ld, mtm %ld, ctm %ld, "            \
69                "size %ld, blocks %ld\n",                                \
70                (long)(obdo)->o_id, (long)(obdo)->o_atime,               \
71                (long)(obdo)->o_mtime, (long)(obdo)->o_ctime,            \
72                (long)(obdo)->o_size, (long)(obdo)->o_blocks);           \
73         CDEBUG(D_INFO, " mode %o, uid %d, gid %d, flg 0x%0x, "          \
74                "obdflg 0x%0x, nlnk %d, valid 0x%0x\n",                  \
75                (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
76                (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid);   \
77 }
78
79 #define PDEBUG(page,msg) {                                              \
80         if (page){                                                      \
81                 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
82                 char *locked = (PageLocked(page)) ? "" : "un";          \
83                 char *buffer = page->buffers ? "buffer" : "";           \
84                 int count = page_count(page);                           \
85                 long index = page->index;                               \
86                 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
87                        " cnt %d page 0x%p pages %ld virt %lx %s**\n",   \
88                        msg, index, uptodate, locked, page->flags, count,\
89                        page, page->mapping ? page->mapping->nrpages : -1,\
90                        page->virtual, buffer);                          \
91         } else                                                          \
92                 CDEBUG(D_CACHE, "** %s: no page\n", msg);               \
93 }
94
95 #if 0
96 #define iget(sb, ino) obd_iget(sb, ino)
97 #define iput(sb, ino) obd_iput(sb, ino)
98
99 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
100 {
101         struct inode *inode;
102         
103         if ((inode = iget(sb, ino)) == NULL)
104                 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
105         else
106                 obd_inodes++;
107         return inode;
108 }
109
110 static inline void obd_iput(struct inode *inode)
111 {
112         if (inode == NULL)
113                 CDEBUG(D_INODE, "NULL in iput\n");
114         else
115                 obd_inodes--;
116 }
117 #endif
118
119 #else /* EXT2_OBD_DEBUG */
120
121 #define CDEBUG(mask, format, a...) {}
122 #define ENTRY {}
123 #define EXIT {}
124 #define ODEBUG(obdo) {}
125 #define EXDEBUG(inode) {}
126 #define OIDEBUG(inode) {}
127 #define PDEBUG(page, cmd) {}
128
129 #endif /* EXT2_OBD_DEBUG */
130
131 #define OBD_ALLOC(ptr, size)                                    \
132 do {                                                            \
133         (ptr) = kmalloc((unsigned long)(size), GFP_KERNEL);     \
134         obd_memory += (size);                                   \
135         CDEBUG(D_MALLOC, "kmalloced: %ld at %x (tot %ld).\n",   \
136                (long)(size), (int)(ptr), obd_memory);           \
137         if (ptr == NULL) {                                      \
138                 printk("kernel malloc failed at %s:%d\n",       \
139                        __FILE__, __LINE__);                     \
140         } else {                                                \
141                 memset((ptr), 0, (size));                       \
142         }                                                       \
143 } while (0)
144
145 #define OBD_FREE(ptr, size)                                  \
146 do {                                                         \
147         kfree((ptr));                                        \
148         obd_memory -= (size);                                \
149         CDEBUG(D_MALLOC, "kfreed: %d at %x (tot %ld).\n",    \
150                (int)(size), (int)(ptr), obd_memory);         \
151 } while (0)
152
153 #endif