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