4 * Copyright (C) 2001 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
10 #include <linux/autoconf.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
16 #define obd_unlock_page(page) do { if (PageLocked(page)) { \
19 printk("file %s, line %d: expecting locked page\n",\
20 __FILE__, __LINE__); \
27 /* global variables */
28 extern int obd_debug_level;
29 extern int obd_print_entry;
30 extern int obd_inodes;
32 extern long obd_memory;
34 #define EXT2_OBD_DEBUG
37 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
40 #define D_PSDEV 0x001 /* debug information from psdev.c */
44 #define D_UNUSED4 0x010
45 #define D_WARNING 0x020 /* misc warnings */
46 #define D_EXT2 0x040 /* anything from ext2_debug */
47 #define D_MALLOC 0x080 /* print malloc, free information */
48 #define D_CACHE 0x100 /* cache-related items */
49 #define D_INFO 0x200 /* general information, especially from interface.c */
50 #define D_IOCTL 0x400 /* ioctl related information */
51 #define D_BLOCKS 0x800 /* ext2 block allocation */
52 #define D_NET 0x1000 /* network communications */
53 #define D_PUNCH 0x2000
54 #define D_BUFFS 0x4000 /* print network buffers */
56 #define CDEBUG(mask, format, a...) \
58 if (obd_debug_level & mask) { \
59 printk("(%s:%d):", __FUNCTION__, __LINE__); \
60 printk(format, ## a); } \
63 #define ENTRY if (obd_print_entry) \
64 printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
66 #define EXIT if (obd_print_entry) \
67 printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid, \
68 __FUNCTION__, __LINE__)
70 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
71 #define ICDEBUG(inode) { \
73 "ino %ld, atm %ld, mtm %ld, ctm %ld, size %Ld, blocks %ld\n",\
74 inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
75 inode->i_size, inode->i_blocks); \
76 CDEBUG(D_INFO, "mode %o, uid %d, gid %d, nlnk %d, count %d\n", \
77 inode->i_mode, inode->i_uid, inode->i_gid, inode->i_nlink,\
78 atomic_read(&inode->i_count)); \
81 /* Ext2 inode information */
82 #define EXDEBUG(inode) { \
84 CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n", \
85 inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1], \
86 inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3], \
87 inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5], \
88 inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]); \
91 /* OBDFS inode information */
92 #define OIDEBUG(inode) { \
94 CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
95 /* obdfs_print_plist(inode); */ \
98 #define ODEBUG(obdo) { \
99 CDEBUG(D_INFO, "id %ld, atm %ld, mtm %ld, ctm %ld, " \
100 "size %ld, blocks %ld\n", \
101 (long)(obdo)->o_id, (long)(obdo)->o_atime, \
102 (long)(obdo)->o_mtime, (long)(obdo)->o_ctime, \
103 (long)(obdo)->o_size, (long)(obdo)->o_blocks); \
104 CDEBUG(D_INFO, " mode %o, uid %d, gid %d, flg 0x%0x, " \
105 "obdflg 0x%0x, nlnk %d, valid 0x%0x\n", \
106 (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
107 (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid); \
111 #define PDEBUG(page,msg) { \
113 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
114 char *locked = (PageLocked(page)) ? "" : "un"; \
115 char *buffer = page->buffers ? "buffer" : ""; \
116 int count = page_count(page); \
117 long index = page->index; \
118 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
119 " cnt %d page 0x%p pages %ld virt %lx %s**\n", \
120 msg, index, uptodate, locked, page->flags, count,\
121 page, page->mapping ? page->mapping->nrpages : -1,\
122 page->virtual, buffer); \
124 CDEBUG(D_CACHE, "** %s: no page\n", msg); \
128 #define iget(sb, ino) obd_iget(sb, ino)
129 #define iput(sb, ino) obd_iput(sb, ino)
131 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
135 if ((inode = iget(sb, ino)) == NULL)
136 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
142 static inline void obd_iput(struct inode *inode)
145 CDEBUG(D_INODE, "NULL in iput\n");
151 #else /* EXT2_OBD_DEBUG */
153 #define CDEBUG(mask, format, a...) {}
156 #define ODEBUG(obdo) {}
157 #define EXDEBUG(inode) {}
158 #define OIDEBUG(inode) {}
159 #define PDEBUG(page, cmd) {}
161 #endif /* EXT2_OBD_DEBUG */
165 #define OBD_ALLOC(ptr, cast, size) \
167 ptr = kmalloc((unsigned long) size, GFP_KERNEL); \
168 obd_memory += size; \
169 CDEBUG(D_MALLOC, "kmalloced: %d at %x (tot %ld).\n", \
170 (int) size, (int) ptr, obd_memory); \
172 printk("kernel malloc returns 0 at %s:%d\n", \
173 __FILE__, __LINE__); \
175 memset(ptr, 0, size); \
179 #define OBD_FREE(ptr,size) \
182 obd_memory -= size; \
183 CDEBUG(D_MALLOC, "kfreed: %d at %x (tot %ld).\n", \
184 (int) size, (int) ptr, obd_memory); \