Whamcloud - gitweb
9c5df5f28db9155b9d2689bb3d0b0d504ab029cf
[fs/lustre-release.git] / lustre / include / linux / obd_support.h
1
2 #ifndef _OBD_SUPPORT
3 #define _OBD_SUPPORT
4 #include <linux/malloc.h>
5 #include <linux/vmalloc.h>
6
7 #define EXT2_OBD_DEBUG
8
9
10 #define MIN(a,b) (((a)<(b)) ? (a): (b))
11 #define MAX(a,b) (((a)>(b)) ? (a): (b))
12
13 /*
14  * Debug code
15  */
16 /* global variables */
17 extern int obd_debug_level;
18 extern int obd_print_entry;
19
20 /* debugging masks */
21 #define D_PSDEV       1 /* debug information from psdev.c */
22 #define D_INODE       2
23 #define D_SUPER       4
24 #define D_SNAP        8
25 #define D_UNUSED4    16
26 #define D_WARNING    32 /* misc warnings */
27 #define D_EXT2       64 /* anything from ext2_debug */
28 #define D_MALLOC    128 /* print malloc, free information */
29 #define D_CACHE     256 /* cache-related items */
30 #define D_INFO      512 /* general information, especially from interface.c */
31 #define D_IOCTL    1024 /* ioctl related information */
32 #define D_BLOCKS   2048 /* ext2 block allocation */
33 #define D_RPC      4096 /* ext2 block allocation */
34  
35 #ifdef EXT2_OBD_DEBUG
36 #define CDEBUG(mask, format, a...)                                      \
37         do {                                                            \
38         if (obd_debug_level & mask) {                                   \
39                 printk("(%s,l. %d): ",  __FUNCTION__, __LINE__);        \
40                 printk(format, ## a); }                                 \
41         } while (0)
42
43 #define ENTRY                                                                 \
44         if (obd_print_entry)                                                  \
45                 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
46
47 #define EXIT                                                                  \
48         if (obd_print_entry)                                                  \
49                 printk("Process %d leaving %s [%d]\n", current->pid, __FUNCTION__, __LINE__)
50
51 #else /* EXT2_OBD_DEBUG */
52
53 #       define CDEBUG ;
54 #       define ENTRY ;
55 #       define EXIT ;
56
57 #endif /* EXT2_OBD_DEBUG */
58
59
60 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
61
62 /* Inode common information printed out */
63 #define ICDEBUG(inode) { \
64                 printk("]]%s line %d[[  ino %ld, blocks %ld, size %Ld, atm %ld, ctm %ld, mtm %ld, mode %o, uid %d, gid %d\n", \
65                        __FUNCTION__ , __LINE__, \
66                        inode->i_ino, inode->i_blocks, inode->i_size,\
67                        inode->i_atime, inode->i_ctime, inode->i_mtime,\
68                        inode->i_mode, inode->i_uid, inode->i_gid);\
69         }
70
71 /* Ext2 inode information */
72 #define EXDEBUG(inode) { \
73                 ICDEBUG(inode);\
74                 printk("data: 0x%08x 0x%08x 0x%08x 0x%08x\n",\
75                        inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1],\
76                        inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3]);\
77         }
78
79 /* OBDFS inode information */
80 /* Should print these with oi_flags and oi_list.prev, next instead of i_data */
81 #define OIDEBUG(inode) { \
82                 ICDEBUG(inode);\
83                 printk("oinfo: flags 0x%08x next 0x%08x prev 0x%08x\n",\
84                        inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1],\
85                        inode->u.ext2_i.i_data[2]);\
86         }
87
88 #define ODEBUG(obdo) { \
89                 printk("]]%s line %d[[  id %Ld, atm %Ld, mtm %Ld, ctm %Ld, size %Ld, blocks %Ld\n",\
90                        __FUNCTION__ , __LINE__, \
91                        obdo->o_id, obdo->o_atime, obdo->o_mtime,\
92                        obdo->o_ctime, obdo->o_size, obdo->o_blocks);\
93                 printk("]]%s line %d[[  mode %o, uid %d, gid %d, flg 0x%0x, obdflg 0x%0x, nlnk %d, valid 0x%0x\n", \
94                        __FUNCTION__ , __LINE__, \
95                        obdo->o_mode, obdo->o_uid, obdo->o_gid,\
96                        obdo->o_flags, obdo->o_obdflags, obdo->o_nlink,\
97                        obdo->o_valid);\
98         }
99
100
101 #define PDEBUG(page,cmd)        {if (page){\
102                 char *uptodate = (Page_Uptodate(page)) ? "yes" : "no";\
103                 char *locked = (PageLocked(page)) ? "yes" : "no";\
104                 int count = page->count.counter;\
105                 long index = page->index;\
106                 \
107                 CDEBUG(D_IOCTL, " ** %s, cmd: %s, off %ld, uptodate: %s, "\
108                        "locked: %s, cnt %d page %p pages %ld** \n", __FUNCTION__,\
109                        cmd, index, uptodate, locked, count, page, (!page->mapping) ? -1 : page->mapping->nrpages);\
110         } else { CDEBUG(D_IOCTL, "** %s, no page\n", __FUNCTION__); }}
111
112
113 #define OBD_ALLOC(ptr, cast, size)                                      \
114 do {                                                                    \
115         if (size <= 4096) {                                             \
116                 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
117                 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n",              \
118                        (int) size, (int) ptr);                          \
119         } else {                                                        \
120                 ptr = (cast)vmalloc((unsigned long) size);              \
121                 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n",              \
122                        (int) size, (int) ptr);                          \
123         }                                                               \
124         if (ptr == 0) {                                                 \
125                 printk("kernel malloc returns 0 at %s:%d\n",            \
126                        __FILE__, __LINE__);                             \
127         }                                                               \
128         memset(ptr, 0, size);                                           \
129 } while (0)
130
131 #define OBD_FREE(ptr,size)                              \
132 do {                                                    \
133         if (size <= 4096) {                             \
134                 kfree_s((ptr), (size));                 \
135                 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
136                        (int) size, (int) ptr);          \
137         } else {                                        \
138                 vfree((ptr));                           \
139                 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
140                        (int) size, (int) ptr);          \
141         }                                               \
142 } while (0)
143
144
145 static inline struct page *addr_to_page(char *buf)
146 {
147         unsigned long addr = (unsigned long)buf;
148         unsigned long map_nr;
149
150 #ifdef CONFIG_DISCONTIGMEM
151         if (addr == 0) return;
152 #endif
153         map_nr = MAP_NR(addr);
154         if (map_nr < max_mapnr)
155                 return mem_map + map_nr;
156         else 
157                 return 0;
158 }
159
160
161
162 #endif