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