Whamcloud - gitweb
Update <linux/malloc.h> to <linux/slab.h>.
[fs/lustre-release.git] / lustre / include / linux / obd_support.h
1 #ifndef _OBD_SUPPORT
2 #define _OBD_SUPPORT
3 #include <linux/autoconf.h>
4 #include <linux/slab.h>
5 #include <linux/vmalloc.h>
6
7 #define MIN(a,b) (((a)<(b)) ? (a): (b))
8 #define MAX(a,b) (((a)>(b)) ? (a): (b))
9
10 #define obd_unlock_page(page)   do {    if (PageLocked(page)) { \
11                         UnlockPage(page);\
12                 } else {\
13                         printk("file %s, line %d: expecting locked page\n",\
14                                __FILE__, __LINE__); \
15                 }                       \
16 } while(0)
17
18 /*
19  * Debug code
20  */
21 /* global variables */
22 extern int obd_debug_level;
23 extern int obd_print_entry;
24 extern int obd_inodes;
25 extern int obd_pages;
26 extern long obd_memory;
27
28 #define EXT2_OBD_DEBUG
29
30 #ifdef EXT2_OBD_DEBUG
31 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
32
33 /* debugging masks */
34 #define D_PSDEV   0x001 /* debug information from psdev.c */
35 #define D_INODE   0x002
36 #define D_SUPER   0x004
37 #define D_SNAP    0x008
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 */
49  
50 #define CDEBUG(mask, format, a...)                                      \
51         do {                                                            \
52         if (obd_debug_level & mask) {                                   \
53                 printk("(%s:%d):", __FUNCTION__, __LINE__);             \
54                 printk(format, ## a); }                                 \
55         } while (0)
56
57 #define ENTRY if (obd_print_entry)                                      \
58         printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
59
60 #define EXIT if (obd_print_entry)                                       \
61         printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid,  \
62                __FUNCTION__, __LINE__)
63
64 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
65 #define ICDEBUG(inode) {                                                \
66         CDEBUG(D_INFO,                                                  \
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));                                         \
73 }
74
75 /* Ext2 inode information */
76 #define EXDEBUG(inode) {                                                \
77         ICDEBUG(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]);   \
83 }
84
85 /* OBDFS inode information */
86 #define OIDEBUG(inode) {                                                \
87         ICDEBUG(inode);                                                 \
88         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
89         /* obdfs_print_plist(inode); */                                 \
90 }
91
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);   \
102 }
103
104
105 #define PDEBUG(page,msg) {                                              \
106         if (page){                                                      \
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);                          \
117         } else                                                          \
118                 CDEBUG(D_CACHE, "** %s: no page\n", msg);               \
119 }
120
121 #if 0
122 #define iget(sb, ino) obd_iget(sb, ino)
123 #define iput(sb, ino) obd_iput(sb, ino)
124
125 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
126 {
127         struct inode *inode;
128         
129         if ((inode = iget(sb, ino)) == NULL)
130                 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
131         else
132                 obd_inodes++;
133         return inode;
134 }
135
136 static inline void obd_iput(struct inode *inode)
137 {
138         if (inode == NULL)
139                 CDEBUG(D_INODE, "NULL in iput\n");
140         else
141                 obd_inodes--;
142 }
143 #endif
144
145 #else /* EXT2_OBD_DEBUG */
146
147 #define CDEBUG(mask, format, a...) {}
148 #define ENTRY {}
149 #define EXIT {}
150 #define ODEBUG(obdo) {}
151 #define EXDEBUG(inode) {}
152 #define OIDEBUG(inode) {}
153 #define PDEBUG(page, cmd) {}
154
155 #endif /* EXT2_OBD_DEBUG */
156
157
158
159 #define OBD_ALLOC(ptr, cast, size)                                      \
160 do {                                                                    \
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);                          \
165         } else {                                                        \
166                 ptr = (cast)vmalloc((unsigned long) size);              \
167                 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n",              \
168                        (int) size, (int) ptr);                          \
169         }                                                               \
170         if (ptr == 0) {                                                 \
171                 printk("kernel malloc returns 0 at %s:%d\n",            \
172                        __FILE__, __LINE__);                             \
173         } else {                                                        \
174                 memset(ptr, 0, size);                                   \
175                 obd_memory += size;                                     \
176         }                                                               \
177 } while (0)
178
179 #define OBD_FREE(ptr,size)                              \
180 do {                                                    \
181         if (size <= 4096) {                             \
182                 kfree((ptr));                   \
183                 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
184                        (int) size, (int) ptr);          \
185         } else {                                        \
186                 vfree((ptr));                           \
187                 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
188                        (int) size, (int) ptr);          \
189         }                                               \
190         obd_memory -= size;                             \
191 } while (0)
192
193
194
195 #endif
196