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))
9 #define obd_unlock_page(page) do { if (PageLocked(page)) { \
12 printk("file %s, line %d: expecting locked page\n",\
13 __FILE__, __LINE__); \
20 /* global variables */
21 extern int obd_debug_level;
22 extern int obd_print_entry;
23 extern int obd_inodes;
25 extern long obd_memory;
27 #define EXT2_OBD_DEBUG
30 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
33 #define D_PSDEV 0x001 /* debug information from psdev.c */
37 #define D_UNUSED4 0x010
38 #define D_WARNING 0x020 /* misc warnings */
39 #define D_EXT2 0x040 /* anything from ext2_debug */
40 #define D_MALLOC 0x080 /* print malloc, free information */
41 #define D_CACHE 0x100 /* cache-related items */
42 #define D_INFO 0x200 /* general information, especially from interface.c */
43 #define D_IOCTL 0x400 /* ioctl related information */
44 #define D_BLOCKS 0x800 /* ext2 block allocation */
45 #define D_RPC 0x1000 /* rpc communications */
46 #define D_PUNCH 0x2000
48 #define CDEBUG(mask, format, a...) \
50 if (obd_debug_level & mask) { \
51 printk("(%s:%d):", __FUNCTION__, __LINE__); \
52 printk(format, ## a); } \
55 #define ENTRY if (obd_print_entry) \
56 printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
58 #define EXIT if (obd_print_entry) \
59 printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid, \
60 __FUNCTION__, __LINE__)
62 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
63 #define ICDEBUG(inode) { \
65 "ino %ld, atm %ld, mtm %ld, ctm %ld, size %Ld, blocks %ld\n",\
66 inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
67 inode->i_size, inode->i_blocks); \
68 CDEBUG(D_INFO, "mode %o, uid %d, gid %d, nlnk %d, count %d\n", \
69 inode->i_mode, inode->i_uid, inode->i_gid, inode->i_nlink,\
70 atomic_read(&inode->i_count)); \
73 /* Ext2 inode information */
74 #define EXDEBUG(inode) { \
76 CDEBUG(D_INFO, "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]); \
83 /* OBDFS inode information */
84 #define OIDEBUG(inode) { \
86 CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
87 /* obdfs_print_plist(inode); */ \
90 #define ODEBUG(obdo) { \
91 CDEBUG(D_INFO, "id %ld, atm %ld, mtm %ld, ctm %ld, " \
92 "size %ld, blocks %ld\n", \
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 CDEBUG(D_INFO, " mode %o, uid %d, gid %d, flg 0x%0x, " \
97 "obdflg 0x%0x, nlnk %d, valid 0x%0x\n", \
98 (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
99 (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid); \
103 #define PDEBUG(page,msg) { \
105 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
106 char *locked = (PageLocked(page)) ? "" : "un"; \
107 char *buffer = page->buffers ? "buffer" : ""; \
108 int count = page_count(page); \
109 long index = page->index; \
110 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
111 " cnt %d page 0x%p pages %ld virt %lx %s**\n", \
112 msg, index, uptodate, locked, page->flags, count,\
113 page, page->mapping ? page->mapping->nrpages : -1,\
114 page->virtual, buffer); \
116 CDEBUG(D_CACHE, "** %s: no page\n", msg); \
120 #define iget(sb, ino) obd_iget(sb, ino)
121 #define iput(sb, ino) obd_iput(sb, ino)
123 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
127 if ((inode = iget(sb, ino)) == NULL)
128 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
134 static inline void obd_iput(struct inode *inode)
137 CDEBUG(D_INODE, "NULL in iput\n");
143 #else /* EXT2_OBD_DEBUG */
145 #define CDEBUG(mask, format, a...) {}
148 #define ODEBUG(obdo) {}
149 #define EXDEBUG(inode) {}
150 #define OIDEBUG(inode) {}
151 #define PDEBUG(page, cmd) {}
153 #endif /* EXT2_OBD_DEBUG */
157 #define OBD_ALLOC(ptr, cast, size) \
159 if (size <= 4096) { \
160 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
161 CDEBUG(D_MALLOC, "kmalloced: %d at %x.\n", \
162 (int) size, (int) ptr); \
164 ptr = (cast)vmalloc((unsigned long) size); \
165 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n", \
166 (int) size, (int) ptr); \
169 printk("kernel malloc returns 0 at %s:%d\n", \
170 __FILE__, __LINE__); \
172 memset(ptr, 0, size); \
173 obd_memory += size; \
177 #define OBD_FREE(ptr,size) \
179 if (size <= 4096) { \
181 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
182 (int) size, (int) ptr); \
185 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
186 (int) size, (int) ptr); \
188 obd_memory -= size; \