3 #include <linux/malloc.h>
4 #include <linux/vmalloc.h>
6 #define MIN(a,b) (((a)<(b)) ? (a): (b))
7 #define MAX(a,b) (((a)>(b)) ? (a): (b))
12 /* global variables */
13 extern int obd_debug_level;
14 extern int obd_print_entry;
16 #define EXT2_OBD_DEBUG
19 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
22 #define D_PSDEV 1 /* debug information from psdev.c */
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 */
36 #define CDEBUG(mask, format, a...) \
38 if (obd_debug_level & mask) { \
39 printk("(%s:%d):", __FUNCTION__, __LINE__); \
40 printk(format, ## a); } \
43 #define ENTRY if (obd_print_entry) \
44 printk(KERN_INFO "Process %d entered %s\n",\
45 current->pid, __FUNCTION__)
47 #define EXIT if (obd_print_entry) \
48 printk(KERN_INFO "Process %d leaving %s [%d]\n",\
49 current->pid, __FUNCTION__, __LINE__)
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);\
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);\
63 /* Ext2 inode information */
64 #define EXDEBUG(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]);\
73 /* OBDFS inode information */
74 #define OIDEBUG(inode) { \
76 CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
77 /* obdfs_print_plist(inode); */\
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);\
93 #define PDEBUG(page,cmd) { \
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);\
104 CDEBUG(D_CACHE, "** %s, no page\n", __FUNCTION__);\
107 #else /* EXT2_OBD_DEBUG */
109 #define CDEBUG(mask, format, a...) {}
112 #define ODEBUG(obdo) {}
113 #define EXDEBUG(inode) {}
114 #define OIDEBUG(inode) {}
115 #define PDEBUG(page, cmd) {}
117 #endif /* EXT2_OBD_DEBUG */
121 #define OBD_ALLOC(ptr, cast, size) \
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); \
128 ptr = (cast)vmalloc((unsigned long) size); \
129 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n", \
130 (int) size, (int) ptr); \
133 printk("kernel malloc returns 0 at %s:%d\n", \
134 __FILE__, __LINE__); \
136 memset(ptr, 0, size); \
139 #define OBD_FREE(ptr,size) \
141 if (size <= 4096) { \
142 kfree_s((ptr), (size)); \
143 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
144 (int) size, (int) ptr); \
147 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
148 (int) size, (int) ptr); \