Whamcloud - gitweb
things are starting to work for Linux 2.4.2!!
[fs/lustre-release.git] / lustre / include / linux / obd_support.h
1 #ifndef _OBD_SUPPORT
2 #define _OBD_SUPPORT
3 #include <linux/malloc.h>
4 #include <linux/vmalloc.h>
5
6 #define MIN(a,b) (((a)<(b)) ? (a): (b))
7 #define MAX(a,b) (((a)>(b)) ? (a): (b))
8
9 /*
10  * Debug code
11  */
12 /* global variables */
13 extern int obd_debug_level;
14 extern int obd_print_entry;
15 extern int obd_inodes;
16 extern int obd_pages;
17 extern long obd_memory;
18
19 #define EXT2_OBD_DEBUG
20
21 #ifdef EXT2_OBD_DEBUG
22 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
23
24 /* debugging masks */
25 #define D_PSDEV   0x001 /* debug information from psdev.c */
26 #define D_INODE   0x002
27 #define D_SUPER   0x004
28 #define D_SNAP    0x008
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
39  
40 #define CDEBUG(mask, format, a...)                                      \
41         do {                                                            \
42         if (obd_debug_level & mask) {                                   \
43                 printk("(%s:%d):", __FUNCTION__, __LINE__);             \
44                 printk(format, ## a); }                                 \
45         } while (0)
46
47 #define ENTRY if (obd_print_entry)                                      \
48         printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
49
50 #define EXIT if (obd_print_entry)                                       \
51         printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid,  \
52                __FUNCTION__, __LINE__)
53
54 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
55 #define ICDEBUG(inode) {                                                \
56         CDEBUG(D_INFO,                                                  \
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));                                         \
63 }
64
65 /* Ext2 inode information */
66 #define EXDEBUG(inode) {                                                \
67         ICDEBUG(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]);   \
73 }
74
75 /* OBDFS inode information */
76 #define OIDEBUG(inode) {                                                \
77         ICDEBUG(inode);                                                 \
78         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
79         /* obdfs_print_plist(inode); */                                 \
80 }
81
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);   \
92 }
93
94
95 #define PDEBUG(page,msg) {                                              \
96         if (page){                                                      \
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);                          \
107         } else                                                          \
108                 CDEBUG(D_CACHE, "** %s: no page\n", msg);               \
109 }
110
111 #if 0
112 #define iget(sb, ino) obd_iget(sb, ino)
113 #define iput(sb, ino) obd_iput(sb, ino)
114
115 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
116 {
117         struct inode *inode;
118         
119         if ((inode = iget(sb, ino)) == NULL)
120                 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
121         else
122                 obd_inodes++;
123         return inode;
124 }
125
126 static inline void obd_iput(struct inode *inode)
127 {
128         if (inode == NULL)
129                 CDEBUG(D_INODE, "NULL in iput\n");
130         else
131                 obd_inodes--;
132 }
133 #endif
134
135 #else /* EXT2_OBD_DEBUG */
136
137 #define CDEBUG(mask, format, a...) {}
138 #define ENTRY {}
139 #define EXIT {}
140 #define ODEBUG(obdo) {}
141 #define EXDEBUG(inode) {}
142 #define OIDEBUG(inode) {}
143 #define PDEBUG(page, cmd) {}
144
145 #endif /* EXT2_OBD_DEBUG */
146
147
148
149 #define OBD_ALLOC(ptr, cast, size)                                      \
150 do {                                                                    \
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);                          \
155         } else {                                                        \
156                 ptr = (cast)vmalloc((unsigned long) size);              \
157                 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n",              \
158                        (int) size, (int) ptr);                          \
159         }                                                               \
160         if (ptr == 0) {                                                 \
161                 printk("kernel malloc returns 0 at %s:%d\n",            \
162                        __FILE__, __LINE__);                             \
163         } else {                                                        \
164                 memset(ptr, 0, size);                                   \
165                 obd_memory += size;                                     \
166         }                                                               \
167 } while (0)
168
169 #define OBD_FREE(ptr,size)                              \
170 do {                                                    \
171         if (size <= 4096) {                             \
172                 kfree((ptr));                   \
173                 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
174                        (int) size, (int) ptr);          \
175         } else {                                        \
176                 vfree((ptr));                           \
177                 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
178                        (int) size, (int) ptr);          \
179         }                                               \
180         obd_memory -= size;                             \
181 } while (0)
182
183
184
185 #endif