Whamcloud - gitweb
Numerous changes:
[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
15
16 #define obd_unlock_page(page)   do {    if (PageLocked(page)) { \
17                         UnlockPage(page);\
18                 } else {\
19                         printk("file %s, line %d: expecting locked page\n",\
20                                __FILE__, __LINE__); \
21                 }                       \
22 } while(0)
23
24 /*
25  * Debug code
26  */
27 /* global variables */
28 extern int obd_debug_level;
29 extern int obd_print_entry;
30 extern int obd_inodes;
31 extern int obd_pages;
32 extern long obd_memory;
33
34 #define EXT2_OBD_DEBUG
35
36 #ifdef EXT2_OBD_DEBUG
37 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
38
39 /* debugging masks */
40 #define D_PSDEV   0x001 /* debug information from psdev.c */
41 #define D_INODE   0x002
42 #define D_SUPER   0x004
43 #define D_SNAP    0x008
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 */
55  
56 #define CDEBUG(mask, format, a...)                                      \
57         do {                                                            \
58         if (obd_debug_level & mask) {                                   \
59                 printk("(%s:%d):", __FUNCTION__, __LINE__);             \
60                 printk(format, ## a); }                                 \
61         } while (0)
62
63 #define ENTRY if (obd_print_entry)                                      \
64         printk(KERN_INFO "Process %d entered %s\n", current->pid, __FUNCTION__)
65
66 #define EXIT if (obd_print_entry)                                       \
67         printk(KERN_INFO "Process %d leaving %s [%d]\n", current->pid,  \
68                __FUNCTION__, __LINE__)
69
70 /* Inode common information printed out (used by obdfs and ext2obd inodes) */
71 #define ICDEBUG(inode) {                                                \
72         CDEBUG(D_INFO,                                                  \
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));                                         \
79 }
80
81 /* Ext2 inode information */
82 #define EXDEBUG(inode) {                                                \
83         ICDEBUG(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]);   \
89 }
90
91 /* OBDFS inode information */
92 #define OIDEBUG(inode) {                                                \
93         ICDEBUG(inode);                                                 \
94         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
95         /* obdfs_print_plist(inode); */                                 \
96 }
97
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);   \
108 }
109
110
111 #define PDEBUG(page,msg) {                                              \
112         if (page){                                                      \
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);                          \
123         } else                                                          \
124                 CDEBUG(D_CACHE, "** %s: no page\n", msg);               \
125 }
126
127 #if 0
128 #define iget(sb, ino) obd_iget(sb, ino)
129 #define iput(sb, ino) obd_iput(sb, ino)
130
131 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
132 {
133         struct inode *inode;
134         
135         if ((inode = iget(sb, ino)) == NULL)
136                 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
137         else
138                 obd_inodes++;
139         return inode;
140 }
141
142 static inline void obd_iput(struct inode *inode)
143 {
144         if (inode == NULL)
145                 CDEBUG(D_INODE, "NULL in iput\n");
146         else
147                 obd_inodes--;
148 }
149 #endif
150
151 #else /* EXT2_OBD_DEBUG */
152
153 #define CDEBUG(mask, format, a...) {}
154 #define ENTRY {}
155 #define EXIT {}
156 #define ODEBUG(obdo) {}
157 #define EXDEBUG(inode) {}
158 #define OIDEBUG(inode) {}
159 #define PDEBUG(page, cmd) {}
160
161 #endif /* EXT2_OBD_DEBUG */
162
163
164
165 #define OBD_ALLOC(ptr, cast, size)                                      \
166 do {                                                                    \
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);             \
171         if (ptr == 0) {                                                 \
172                 printk("kernel malloc returns 0 at %s:%d\n",            \
173                        __FILE__, __LINE__);                             \
174         } else {                                                        \
175                 memset(ptr, 0, size);                                   \
176         }                                                               \
177 } while (0)
178
179 #define OBD_FREE(ptr,size)                                   \
180 do {                                                         \
181         kfree((ptr));                                        \
182         obd_memory -= size;                                  \
183         CDEBUG(D_MALLOC, "kfreed: %d at %x (tot %ld).\n",    \
184                (int) size, (int) ptr, obd_memory);           \
185 } while (0)
186
187
188
189 #endif
190