Whamcloud - gitweb
obdfs,ext2_obd,class/*.c: added truncate/punch method/ioctl
[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, "]]%s line %d[[ ino %ld, atm %ld, mtm %ld, ctm %ld, "\
57                "size %Ld, blocks %ld\n", __FUNCTION__ , __LINE__,\
58                inode->i_ino, inode->i_atime, inode->i_mtime, inode->i_ctime,\
59                inode->i_size, inode->i_blocks);\
60         CDEBUG(D_INFO,\
61                "]]%s line %d[[ mode %o, uid %d, gid %d, nlnk %d, count %d\n",\
62                __FUNCTION__, __LINE__, inode->i_mode, inode->i_uid,\
63                inode->i_gid, inode->i_nlink, inode->i_count);\
64 }
65
66 /* Ext2 inode information */
67 #define EXDEBUG(inode) { \
68         ICDEBUG(inode);\
69         CDEBUG(D_INFO, "ext2 blocks: %d %d %d %d %d %d %d %d\n",\
70                inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1],\
71                inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3],\
72                inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5],\
73                inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7]);\
74 }
75
76 /* OBDFS inode information */
77 #define OIDEBUG(inode) { \
78         ICDEBUG(inode);\
79         CDEBUG(D_INFO,"oinfo: flags 0x%08x\n", obdfs_i2info(inode)->oi_flags);\
80         /* obdfs_print_plist(inode); */\
81 }
82
83 #define ODEBUG(obdo) { \
84         CDEBUG(D_INFO, "]]%s line %d[[  id %ld, atm %ld, mtm %ld, ctm %ld, "\
85                "size %ld, blocks %ld\n", __FUNCTION__ , __LINE__,\
86                (long)(obdo)->o_id, (long)(obdo)->o_atime,\
87                (long)(obdo)->o_mtime, (long)(obdo)->o_ctime,\
88                (long)(obdo)->o_size, (long)(obdo)->o_blocks);\
89         CDEBUG(D_INFO, "]]%s line %d[[  mode %o, uid %d, gid %d, flg 0x%0x, "\
90                "obdflg 0x%0x, nlnk %d, valid 0x%0x\n", __FUNCTION__ , __LINE__,\
91                (obdo)->o_mode, (obdo)->o_uid, (obdo)->o_gid, (obdo)->o_flags,\
92                (obdo)->o_obdflags, (obdo)->o_nlink, (obdo)->o_valid);\
93 }
94
95
96 #define PDEBUG(page,msg) { \
97         if (page){\
98                 char *uptodate = (Page_Uptodate(page)) ? "upto" : "outof";\
99                 char *locked = (PageLocked(page)) ? "" : "un";\
100                 char *buffer = page->buffers ? "buffer" : "";\
101                 int count = page_count(page);\
102                 long index = page->index;\
103                 CDEBUG(D_CACHE, "%s: ** off %ld, %sdate, %slocked, flag %ld,"\
104                        " cnt %d page 0x%p pages %ld virt %lx %s**\n",\
105                        msg, index, uptodate, locked, page->flags, count,\
106                        page, page->mapping ? page->mapping->nrpages : -1,\
107                        page->virtual, buffer);\
108         } else \
109                 CDEBUG(D_CACHE, "** %s: no page\n", msg);\
110 }
111
112 #if 0
113 #define iget(sb, ino) obd_iget(sb, ino)
114 #define iput(sb, ino) obd_iput(sb, ino)
115
116 static inline struct inode *obd_iget(struct super_block *sb, unsigned long ino)
117 {
118         struct inode *inode;
119         
120         if ((inode = iget(sb, ino)) == NULL)
121                 CDEBUG(D_INODE, "NULL in iget for %ld\n", ino);
122         else
123                 obd_inodes++;
124         return inode;
125 }
126
127 static inline void obd_iput(struct inode *inode)
128 {
129         if (inode == NULL)
130                 CDEBUG(D_INODE, "NULL in iput\n");
131         else
132                 obd_inodes--;
133 }
134 #endif
135
136 #else /* EXT2_OBD_DEBUG */
137
138 #define CDEBUG(mask, format, a...) {}
139 #define ENTRY {}
140 #define EXIT {}
141 #define ODEBUG(obdo) {}
142 #define EXDEBUG(inode) {}
143 #define OIDEBUG(inode) {}
144 #define PDEBUG(page, cmd) {}
145
146 #endif /* EXT2_OBD_DEBUG */
147
148
149
150 #define OBD_ALLOC(ptr, cast, size)                                      \
151 do {                                                                    \
152         if (size <= 4096) {                                             \
153                 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL);  \
154                 CDEBUG(D_MALLOC, "kmalloced: %d at %x.\n",              \
155                        (int) size, (int) ptr);                          \
156         } else {                                                        \
157                 ptr = (cast)vmalloc((unsigned long) size);              \
158                 CDEBUG(D_MALLOC, "vmalloced: %d at %x.\n",              \
159                        (int) size, (int) ptr);                          \
160         }                                                               \
161         if (ptr == 0) {                                                 \
162                 printk("kernel malloc returns 0 at %s:%d\n",            \
163                        __FILE__, __LINE__);                             \
164         } else {                                                        \
165                 memset(ptr, 0, size);                                   \
166                 obd_memory += size;                                     \
167         }                                                               \
168 } while (0)
169
170 #define OBD_FREE(ptr,size)                              \
171 do {                                                    \
172         if (size <= 4096) {                             \
173                 kfree_s((ptr), (size));                 \
174                 CDEBUG(D_MALLOC, "kfreed: %d at %x.\n", \
175                        (int) size, (int) ptr);          \
176         } else {                                        \
177                 vfree((ptr));                           \
178                 CDEBUG(D_MALLOC, "vfreed: %d at %x.\n", \
179                        (int) size, (int) ptr);          \
180         }                                               \
181         obd_memory -= size;                             \
182 } while (0)
183
184
185
186 #endif