4 #include <linux/malloc.h>
5 #include <linux/vmalloc.h>
10 #define MIN(a,b) (((a)<(b)) ? (a): (b))
11 #define MAX(a,b) (((a)>(b)) ? (a): (b))
16 /* global variables */
17 extern int obd_debug_level;
18 extern int obd_print_entry;
20 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
24 #define D_PSDEV 1 /* debug information from psdev.c */
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 */
38 #define CDEBUG(mask, format, a...) \
40 if (obd_debug_level & mask) { \
41 printk("(%s,l. %d): ", __FUNCTION__, __LINE__); \
42 printk(format, ## a); } \
46 if (obd_print_entry) \
47 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
50 if (obd_print_entry) \
51 printk("Process %d leaving %s [%d]\n", current->pid, __FUNCTION__, __LINE__)
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);\
64 /* Ext2 inode information */
65 #define EXDEBUG(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]);\
74 /* OBDFS inode information */
75 #define OIDEBUG(inode) { \
77 printk("oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
78 /* obdfs_print_plist(inode); */\
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);\
94 #define PDEBUG(page,cmd) { \
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);\
105 CDEBUG(D_IOCTL, "** %s, no page\n", __FUNCTION__);\
108 #else /* EXT2_OBD_DEBUG */
110 #define CDEBUG(mask, format, a...) {}
113 #define ODEBUG(obdo) {}
114 #define EXDEBUG(inode) {}
115 #define OIDEBUG(inode) {}
116 #define PDEBUG(page, cmd) {}
118 #endif /* EXT2_OBD_DEBUG */
122 #define OBD_ALLOC(ptr, cast, size) \
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); \
129 ptr = (cast)vmalloc((unsigned long) size); \
130 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n", \
131 (int) size, (int) ptr); \
134 printk("kernel malloc returns 0 at %s:%d\n", \
135 __FILE__, __LINE__); \
137 memset(ptr, 0, size); \
140 #define OBD_FREE(ptr,size) \
142 if (size <= 4096) { \
143 kfree_s((ptr), (size)); \
144 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
145 (int) size, (int) ptr); \
148 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
149 (int) size, (int) ptr); \