3 #include <linux/autoconf.h>
4 #include <linux/malloc.h>
5 #include <linux/vmalloc.h>
7 #define MIN(a,b) (((a)<(b)) ? (a): (b))
8 #define MAX(a,b) (((a)>(b)) ? (a): (b))
10 #define obd_unlock_page(page) do { if (PageLocked(page)) { \
13 printk("file %s, line %d: expecting locked page\n",\
14 __FILE__, __LINE__); \
21 /* global variables */
22 extern int obd_debug_level;
23 extern int obd_print_entry;
24 extern int obd_inodes;
26 extern long obd_memory;
28 #define EXT2_OBD_DEBUG
31 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
34 #define D_PSDEV 0x001 /* debug information from psdev.c */
38 #define D_UNUSED4 0x010
39 #define D_WARNING 0x020 /* misc warnings */
40 #define D_EXT2 0x040 /* anything from ext2_debug */
41 #define D_MALLOC 0x080 /* print malloc, free information */
42 #define D_CACHE 0x100 /* cache-related items */
43 #define D_INFO 0x200 /* general information, especially from interface.c */
44 #define D_IOCTL 0x400 /* ioctl related information */
45 #define D_BLOCKS 0x800 /* ext2 block allocation */
46 #define D_NET 0x1000 /* network communications */
47 #define D_PUNCH 0x2000
48 #define D_BUFFS 0x4000 /* print network buffers */
50 #define CDEBUG(mask, format, a...) \
52 if (obd_debug_level & mask) { \
53 printk("(%s:%d):", __FUNCTION__, __LINE__); \
54 printk(format, ## a); } \
57 #define ENTRY if (obd_print_entry) \
58 printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
60 #define EXIT if (obd_print_entry) \
61 printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid, \
62 __FUNCTION__, __LINE__)
64 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
65 #define ICDEBUG(inode) { \
67 "ino %ld, atm %ld, mtm %ld, ctm %ld, size %Ld, blocks %ld\n",\
68 inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
69 inode->i_size, inode->i_blocks); \
70 CDEBUG(D_INFO, "mode %o, uid %d, gid %d, nlnk %d, count %d\n", \
71 inode->i_mode, inode->i_uid, inode->i_gid, inode->i_nlink,\
72 atomic_read(&inode->i_count)); \
75 /* Ext2 inode information */
76 #define EXDEBUG(inode) { \
78 CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n", \
79 inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1], \
80 inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3], \
81 inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5], \
82 inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]); \
85 /* OBDFS inode information */
86 #define OIDEBUG(inode) { \
88 CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
89 /* obdfs_print_plist(inode); */ \
92 #define ODEBUG(obdo) { \
93 CDEBUG(D_INFO, "id %ld, atm %ld, mtm %ld, ctm %ld, " \
94 "size %ld, blocks %ld\n", \
95 (long)(obdo)->o_id, (long)(obdo)->o_atime, \
96 (long)(obdo)->o_mtime, (long)(obdo)->o_ctime, \
97 (long)(obdo)->o_size, (long)(obdo)->o_blocks); \
98 CDEBUG(D_INFO, " mode %o, uid %d, gid %d, flg 0x%0x, " \
99 "obdflg 0x%0x, nlnk %d, valid 0x%0x\n", \
100 (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
101 (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid); \
105 #define PDEBUG(page,msg) { \
107 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
108 char *locked = (PageLocked(page)) ? "" : "un"; \
109 char *buffer = page->buffers ? "buffer" : ""; \
110 int count = page_count(page); \
111 long index = page->index; \
112 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
113 " cnt %d page 0x%p pages %ld virt %lx %s**\n", \
114 msg, index, uptodate, locked, page->flags, count,\
115 page, page->mapping ? page->mapping->nrpages : -1,\
116 page->virtual, buffer); \
118 CDEBUG(D_CACHE, "** %s: no page\n", msg); \
122 #define iget(sb, ino) obd_iget(sb, ino)
123 #define iput(sb, ino) obd_iput(sb, ino)
125 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
129 if ((inode = iget(sb, ino)) == NULL)
130 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
136 static inline void obd_iput(struct inode *inode)
139 CDEBUG(D_INODE, "NULL in iput\n");
145 #else /* EXT2_OBD_DEBUG */
147 #define CDEBUG(mask, format, a...) {}
150 #define ODEBUG(obdo) {}
151 #define EXDEBUG(inode) {}
152 #define OIDEBUG(inode) {}
153 #define PDEBUG(page, cmd) {}
155 #endif /* EXT2_OBD_DEBUG */
159 #define OBD_ALLOC(ptr, cast, size) \
161 if (size <= 4096) { \
162 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
163 CDEBUG(D_MALLOC, "kmalloced: %d at %x.\n", \
164 (int) size, (int) ptr); \
166 ptr = (cast)vmalloc((unsigned long) size); \
167 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n", \
168 (int) size, (int) ptr); \
171 printk("kernel malloc returns 0 at %s:%d\n", \
172 __FILE__, __LINE__); \
174 memset(ptr, 0, size); \
175 obd_memory += size; \
179 #define OBD_FREE(ptr,size) \
181 if (size <= 4096) { \
183 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
184 (int) size, (int) ptr); \
187 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
188 (int) size, (int) ptr); \
190 obd_memory -= size; \