Whamcloud - gitweb
abb64d25f06df87fd548a21bb5852e2b3d62c2e4
[fs/lustre-release.git] / lustre / include / linux / obd_support.h
1 #ifndef _OBD_SUPPORT
2 #define _OBD_SUPPORT
3 #include <linux/malloc.h>
4 #include <linux/vmalloc.h>
5
6 #define MIN(a,b) (((a)<(b)) ? (a): (b))
7 #define MAX(a,b) (((a)>(b)) ? (a): (b))
8
9 /*
10  * Debug code
11  */
12 /* global variables */
13 extern int obd_debug_level;
14 extern int obd_print_entry;
15
16 #define EXT2_OBD_DEBUG
17
18 #ifdef EXT2_OBD_DEBUG
19 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
20
21 /* debugging masks */
22 #define D_PSDEV       1 /* debug information from psdev.c */
23 #define D_INODE       2
24 #define D_SUPER       4
25 #define D_SNAP        8
26 #define D_UNUSED     16
27 #define D_WARNING    32 /* misc warnings */
28 #define D_EXT2       64 /* anything from ext2_debug */
29 #define D_MALLOC    128 /* print malloc, free information */
30 #define D_CACHE     256 /* cache-related items */
31 #define D_INFO      512 /* general information, especially from interface.c */
32 #define D_IOCTL    1024 /* ioctl related information */
33 #define D_BLOCKS   2048 /* ext2 block allocation */
34 #define D_RPC      4096 /* rpc communications */
35  
36 #define CDEBUG(mask, format, a...)                                      \
37         do {                                                            \
38         if (obd_debug_level & mask) {                                   \
39                 printk("(%s:%d):", __FUNCTION__, __LINE__);             \
40                 printk(format, ## a); }                                 \
41         } while (0)
42
43 #define ENTRY if (obd_print_entry) \
44                         printk(KERN_INFO "Process %d entered %s\n",\
45                                current->pid, __FUNCTION__)
46
47 #define EXIT if (obd_print_entry) \
48                         printk(KERN_INFO "Process %d leaving %s [%d]\n",\
49                                current->pid, __FUNCTION__, __LINE__)
50
51 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
52 #define ICDEBUG(inode) { \
53         CDEBUG(D_INFO, "]]%s line %d[[ ino %ld, atm %ld, mtm %ld, ctm %ld, "\
54                "size %Ld, blocks %ld\n", __FUNCTION__ , __LINE__,\
55                inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
56                inode->i_size, inode->i_blocks);\
57         CDEBUG(D_INFO,\
58                "]]%s line %d[[ mode %o, uid %d, gid %d, nlnk %d, count %d\n",\
59                __FUNCTION__, __LINE__, inode->i_mode, inode->i_uid,\
60                inode->i_gid, inode->i_nlink, inode->i_count);\
61 }
62
63 /* Ext2 inode information */
64 #define EXDEBUG(inode) { \
65         ICDEBUG(inode);\
66         CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n",\
67                inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1],\
68                inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3],\
69                inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5],\
70                inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]);\
71 }
72
73 /* OBDFS inode information */
74 #define OIDEBUG(inode) { \
75         ICDEBUG(inode);\
76         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
77         /* obdfs_print_plist(inode); */\
78 }
79
80 #define ODEBUG(obdo) { \
81         CDEBUG(D_INFO, "]]%s line %d[[  id %ld, atm %ld, mtm %ld, ctm %ld, "\
82                "size %ld, blocks %ld\n", __FUNCTION__ , __LINE__,\
83                (long)(obdo)->o_id, (long)(obdo)->o_atime,\
84                (long)(obdo)->o_mtime, (long)(obdo)->o_ctime,\
85                (long)(obdo)->o_size, (long)(obdo)->o_blocks);\
86         CDEBUG(D_INFO, "]]%s line %d[[  mode %o, uid %d, gid %d, flg 0x%0x, "\
87                "obdflg 0x%0x, nlnk %d, valid 0x%0x\n", __FUNCTION__ , __LINE__,\
88                (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
89                (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid);\
90 }
91
92
93 #define PDEBUG(page,cmd) { \
94         if (page){\
95                 char *uptodate = (Page_Uptodate(page)) ? "yes" : "no";\
96                 char *locked = (PageLocked(page)) ? "yes" : "no";\
97                 int count = page->count.counter;\
98                 long index = page->index;\
99                 CDEBUG(D_CACHE, " ** %s, cmd: %s, off %ld, uptodate: %s, "\
100                        "locked: %s, cnt %d page %p pages %ld** \n",\
101                        __FUNCTION__, cmd, index, uptodate, locked, count, \
102                        page, (!page->mapping) ? -1 : page->mapping->nrpages);\
103         } else \
104                 CDEBUG(D_CACHE, "** %s, no page\n", __FUNCTION__);\
105 }
106
107 #else /* EXT2_OBD_DEBUG */
108
109 #define CDEBUG(mask, format, a...) {}
110 #define ENTRY {}
111 #define EXIT {}
112 #define ODEBUG(obdo) {}
113 #define EXDEBUG(inode) {}
114 #define OIDEBUG(inode) {}
115 #define PDEBUG(page, cmd) {}
116
117 #endif /* EXT2_OBD_DEBUG */
118
119
120
121 #define OBD_ALLOC(ptr, cast, size)                                      \
122 do {                                                                    \
123         if (size <= 4096) {                                             \
124                 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
125                 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n",              \
126                        (int) size, (int) ptr);                          \
127         } else {                                                        \
128                 ptr = (cast)vmalloc((unsigned long) size);              \
129                 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n",              \
130                        (int) size, (int) ptr);                          \
131         }                                                               \
132         if (ptr == 0) {                                                 \
133                 printk("kernel malloc returns 0 at %s:%d\n",            \
134                        __FILE__, __LINE__);                             \
135         }                                                               \
136         memset(ptr, 0, size);                                           \
137 } while (0)
138
139 #define OBD_FREE(ptr,size)                              \
140 do {                                                    \
141         if (size <= 4096) {                             \
142                 kfree_s((ptr), (size));                 \
143                 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
144                        (int) size, (int) ptr);          \
145         } else {                                        \
146                 vfree((ptr));                           \
147                 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
148                        (int) size, (int) ptr);          \
149         }                                               \
150 } while (0)
151
152
153
154 #endif