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>
14 #define MIN(a,b) (((a)<(b)) ? (a): (b))
15 #define MAX(a,b) (((a)>(b)) ? (a): (b))
17 #define obd_unlock_page(page) do { if (PageLocked(page)) { \
20 printk("file %s, line %d: expecting locked page\n",\
21 __FILE__, __LINE__); \
28 /* global variables */
29 extern int obd_debug_level;
30 extern int obd_print_entry;
31 extern int obd_inodes;
33 extern long obd_memory;
35 #define EXT2_OBD_DEBUG
38 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
41 #define D_PSDEV 0x001 /* debug information from psdev.c */
45 #define D_UNUSED4 0x010
46 #define D_WARNING 0x020 /* misc warnings */
47 #define D_EXT2 0x040 /* anything from ext2_debug */
48 #define D_MALLOC 0x080 /* print malloc, free information */
49 #define D_CACHE 0x100 /* cache-related items */
50 #define D_INFO 0x200 /* general information, especially from interface.c */
51 #define D_IOCTL 0x400 /* ioctl related information */
52 #define D_BLOCKS 0x800 /* ext2 block allocation */
53 #define D_NET 0x1000 /* network communications */
54 #define D_PUNCH 0x2000
55 #define D_BUFFS 0x4000 /* print network buffers */
57 #define CDEBUG(mask, format, a...) \
59 if (obd_debug_level & mask) { \
60 printk("(%s:%d):", __FUNCTION__, __LINE__); \
61 printk(format, ## a); } \
64 #define ENTRY if (obd_print_entry) \
65 printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
67 #define EXIT if (obd_print_entry) \
68 printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid, \
69 __FUNCTION__, __LINE__)
71 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
72 #define ICDEBUG(inode) { \
74 "ino %ld, atm %ld, mtm %ld, ctm %ld, size %Ld, blocks %ld\n",\
75 inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
76 inode->i_size, inode->i_blocks); \
77 CDEBUG(D_INFO, "mode %o, uid %d, gid %d, nlnk %d, count %d\n", \
78 inode->i_mode, inode->i_uid, inode->i_gid, inode->i_nlink,\
79 atomic_read(&inode->i_count)); \
82 /* Ext2 inode information */
83 #define EXDEBUG(inode) { \
85 CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n", \
86 inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1], \
87 inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3], \
88 inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5], \
89 inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]); \
92 /* OBDFS inode information */
93 #define OIDEBUG(inode) { \
95 CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
96 /* obdfs_print_plist(inode); */ \
99 #define ODEBUG(obdo) { \
100 CDEBUG(D_INFO, "id %ld, atm %ld, mtm %ld, ctm %ld, " \
101 "size %ld, blocks %ld\n", \
102 (long)(obdo)->o_id, (long)(obdo)->o_atime, \
103 (long)(obdo)->o_mtime, (long)(obdo)->o_ctime, \
104 (long)(obdo)->o_size, (long)(obdo)->o_blocks); \
105 CDEBUG(D_INFO, " mode %o, uid %d, gid %d, flg 0x%0x, " \
106 "obdflg 0x%0x, nlnk %d, valid 0x%0x\n", \
107 (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
108 (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid); \
112 #define PDEBUG(page,msg) { \
114 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
115 char *locked = (PageLocked(page)) ? "" : "un"; \
116 char *buffer = page->buffers ? "buffer" : ""; \
117 int count = page_count(page); \
118 long index = page->index; \
119 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
120 " cnt %d page 0x%p pages %ld virt %lx %s**\n", \
121 msg, index, uptodate, locked, page->flags, count,\
122 page, page->mapping ? page->mapping->nrpages : -1,\
123 page->virtual, buffer); \
125 CDEBUG(D_CACHE, "** %s: no page\n", msg); \
129 #define iget(sb, ino) obd_iget(sb, ino)
130 #define iput(sb, ino) obd_iput(sb, ino)
132 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
136 if ((inode = iget(sb, ino)) == NULL)
137 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
143 static inline void obd_iput(struct inode *inode)
146 CDEBUG(D_INODE, "NULL in iput\n");
152 #else /* EXT2_OBD_DEBUG */
154 #define CDEBUG(mask, format, a...) {}
157 #define ODEBUG(obdo) {}
158 #define EXDEBUG(inode) {}
159 #define OIDEBUG(inode) {}
160 #define PDEBUG(page, cmd) {}
162 #endif /* EXT2_OBD_DEBUG */
166 #define OBD_ALLOC(ptr, cast, size) \
168 if (size <= 4096) { \
169 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
170 CDEBUG(D_MALLOC, "kmalloced: %d at %x.\n", \
171 (int) size, (int) ptr); \
173 ptr = (cast)vmalloc((unsigned long) size); \
174 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n", \
175 (int) size, (int) ptr); \
178 printk("kernel malloc returns 0 at %s:%d\n", \
179 __FILE__, __LINE__); \
181 memset(ptr, 0, size); \
182 obd_memory += size; \
186 #define OBD_FREE(ptr,size) \
188 if (size <= 4096) { \
190 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
191 (int) size, (int) ptr); \
194 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
195 (int) size, (int) ptr); \
197 obd_memory -= size; \