Whamcloud - gitweb
Update copyright and license information.
[fs/lustre-release.git] / lustre / include / linux / obd_support.h
1 #ifndef _OBD_SUPPORT
2 #define _OBD_SUPPORT
3 /*
4  * Copyright (C) 2001  Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #include <linux/autoconf.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
13
14 #define MIN(a,b) (((a)<(b)) ? (a): (b))
15 #define MAX(a,b) (((a)>(b)) ? (a): (b))
16
17 #define obd_unlock_page(page)   do {    if (PageLocked(page)) { \
18                         UnlockPage(page);\
19                 } else {\
20                         printk("file %s, line %d: expecting locked page\n",\
21                                __FILE__, __LINE__); \
22                 }                       \
23 } while(0)
24
25 /*
26  * Debug code
27  */
28 /* global variables */
29 extern int obd_debug_level;
30 extern int obd_print_entry;
31 extern int obd_inodes;
32 extern int obd_pages;
33 extern long obd_memory;
34
35 #define EXT2_OBD_DEBUG
36
37 #ifdef EXT2_OBD_DEBUG
38 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
39
40 /* debugging masks */
41 #define D_PSDEV   0x001 /* debug information from psdev.c */
42 #define D_INODE   0x002
43 #define D_SUPER   0x004
44 #define D_SNAP    0x008
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 */
56  
57 #define CDEBUG(mask, format, a...)                                      \
58         do {                                                            \
59         if (obd_debug_level & mask) {                                   \
60                 printk("(%s:%d):", __FUNCTION__, __LINE__);             \
61                 printk(format, ## a); }                                 \
62         } while (0)
63
64 #define ENTRY if (obd_print_entry)                                      \
65         printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
66
67 #define EXIT if (obd_print_entry)                                       \
68         printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid,  \
69                __FUNCTION__, __LINE__)
70
71 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
72 #define ICDEBUG(inode) {                                                \
73         CDEBUG(D_INFO,                                                  \
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));                                         \
80 }
81
82 /* Ext2 inode information */
83 #define EXDEBUG(inode) {                                                \
84         ICDEBUG(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]);   \
90 }
91
92 /* OBDFS inode information */
93 #define OIDEBUG(inode) {                                                \
94         ICDEBUG(inode);                                                 \
95         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
96         /* obdfs_print_plist(inode); */                                 \
97 }
98
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);   \
109 }
110
111
112 #define PDEBUG(page,msg) {                                              \
113         if (page){                                                      \
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);                          \
124         } else                                                          \
125                 CDEBUG(D_CACHE, "** %s: no page\n", msg);               \
126 }
127
128 #if 0
129 #define iget(sb, ino) obd_iget(sb, ino)
130 #define iput(sb, ino) obd_iput(sb, ino)
131
132 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
133 {
134         struct inode *inode;
135         
136         if ((inode = iget(sb, ino)) == NULL)
137                 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
138         else
139                 obd_inodes++;
140         return inode;
141 }
142
143 static inline void obd_iput(struct inode *inode)
144 {
145         if (inode == NULL)
146                 CDEBUG(D_INODE, "NULL in iput\n");
147         else
148                 obd_inodes--;
149 }
150 #endif
151
152 #else /* EXT2_OBD_DEBUG */
153
154 #define CDEBUG(mask, format, a...) {}
155 #define ENTRY {}
156 #define EXIT {}
157 #define ODEBUG(obdo) {}
158 #define EXDEBUG(inode) {}
159 #define OIDEBUG(inode) {}
160 #define PDEBUG(page, cmd) {}
161
162 #endif /* EXT2_OBD_DEBUG */
163
164
165
166 #define OBD_ALLOC(ptr, cast, size)                                      \
167 do {                                                                    \
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);                          \
172         } else {                                                        \
173                 ptr = (cast)vmalloc((unsigned long) size);              \
174                 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n",              \
175                        (int) size, (int) ptr);                          \
176         }                                                               \
177         if (ptr == 0) {                                                 \
178                 printk("kernel malloc returns 0 at %s:%d\n",            \
179                        __FILE__, __LINE__);                             \
180         } else {                                                        \
181                 memset(ptr, 0, size);                                   \
182                 obd_memory += size;                                     \
183         }                                                               \
184 } while (0)
185
186 #define OBD_FREE(ptr,size)                              \
187 do {                                                    \
188         if (size <= 4096) {                             \
189                 kfree((ptr));                   \
190                 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
191                        (int) size, (int) ptr);          \
192         } else {                                        \
193                 vfree((ptr));                           \
194                 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
195                        (int) size, (int) ptr);          \
196         }                                               \
197         obd_memory -= size;                             \
198 } while (0)
199
200
201
202 #endif
203