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;
15 extern int obd_inodes;
17 extern long obd_memory;
19 #define EXT2_OBD_DEBUG
22 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
25 #define D_PSDEV 0x001 /* debug information from psdev.c */
29 #define D_UNUSED4 0x010
30 #define D_WARNING 0x020 /* misc warnings */
31 #define D_EXT2 0x040 /* anything from ext2_debug */
32 #define D_MALLOC 0x080 /* print malloc, free information */
33 #define D_CACHE 0x100 /* cache-related items */
34 #define D_INFO 0x200 /* general information, especially from interface.c */
35 #define D_IOCTL 0x400 /* ioctl related information */
36 #define D_BLOCKS 0x800 /* ext2 block allocation */
37 #define D_RPC 0x1000 /* rpc communications */
38 #define D_PUNCH 0x2000
40 #define CDEBUG(mask, format, a...) \
42 if (obd_debug_level & mask) { \
43 printk("(%s:%d):", __FUNCTION__, __LINE__); \
44 printk(format, ## a); } \
47 #define ENTRY if (obd_print_entry) \
48 printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
50 #define EXIT if (obd_print_entry) \
51 printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid, \
52 __FUNCTION__, __LINE__)
54 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
55 #define ICDEBUG(inode) { \
57 "ino %ld, atm %ld, mtm %ld, ctm %ld, size %Ld, blocks %ld\n",\
58 inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
59 inode->i_size, inode->i_blocks); \
60 CDEBUG(D_INFO, "mode %o, uid %d, gid %d, nlnk %d, count %d\n", \
61 inode->i_mode, inode->i_uid, inode->i_gid, inode->i_nlink,\
62 atomic_read(&inode->i_count)); \
65 /* Ext2 inode information */
66 #define EXDEBUG(inode) { \
68 CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n", \
69 inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1], \
70 inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3], \
71 inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5], \
72 inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]); \
75 /* OBDFS inode information */
76 #define OIDEBUG(inode) { \
78 CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
79 /* obdfs_print_plist(inode); */ \
82 #define ODEBUG(obdo) { \
83 CDEBUG(D_INFO, "id %ld, atm %ld, mtm %ld, ctm %ld, " \
84 "size %ld, blocks %ld\n", \
85 (long)(obdo)->o_id, (long)(obdo)->o_atime, \
86 (long)(obdo)->o_mtime, (long)(obdo)->o_ctime, \
87 (long)(obdo)->o_size, (long)(obdo)->o_blocks); \
88 CDEBUG(D_INFO, " mode %o, uid %d, gid %d, flg 0x%0x, " \
89 "obdflg 0x%0x, nlnk %d, valid 0x%0x\n", \
90 (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
91 (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid); \
95 #define PDEBUG(page,msg) { \
97 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
98 char *locked = (PageLocked(page)) ? "" : "un"; \
99 char *buffer = page->buffers ? "buffer" : ""; \
100 int count = page_count(page); \
101 long index = page->index; \
102 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
103 " cnt %d page 0x%p pages %ld virt %lx %s**\n", \
104 msg, index, uptodate, locked, page->flags, count,\
105 page, page->mapping ? page->mapping->nrpages : -1,\
106 page->virtual, buffer); \
108 CDEBUG(D_CACHE, "** %s: no page\n", msg); \
112 #define iget(sb, ino) obd_iget(sb, ino)
113 #define iput(sb, ino) obd_iput(sb, ino)
115 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
119 if ((inode = iget(sb, ino)) == NULL)
120 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
126 static inline void obd_iput(struct inode *inode)
129 CDEBUG(D_INODE, "NULL in iput\n");
135 #else /* EXT2_OBD_DEBUG */
137 #define CDEBUG(mask, format, a...) {}
140 #define ODEBUG(obdo) {}
141 #define EXDEBUG(inode) {}
142 #define OIDEBUG(inode) {}
143 #define PDEBUG(page, cmd) {}
145 #endif /* EXT2_OBD_DEBUG */
149 #define OBD_ALLOC(ptr, cast, size) \
151 if (size <= 4096) { \
152 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
153 CDEBUG(D_MALLOC, "kmalloced: %d at %x.\n", \
154 (int) size, (int) ptr); \
156 ptr = (cast)vmalloc((unsigned long) size); \
157 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n", \
158 (int) size, (int) ptr); \
161 printk("kernel malloc returns 0 at %s:%d\n", \
162 __FILE__, __LINE__); \
164 memset(ptr, 0, size); \
165 obd_memory += size; \
169 #define OBD_FREE(ptr,size) \
171 if (size <= 4096) { \
173 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
174 (int) size, (int) ptr); \
177 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
178 (int) size, (int) ptr); \
180 obd_memory -= size; \