Whamcloud - gitweb
New files:
[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 SIM_OBD_DEBUG
7
8
9 #define MIN(a,b) (((a)<(b)) ? (a): (b))
10 #define MAX(a,b) (((a)>(b)) ? (a): (b))
11
12 /*
13  * Debug code
14  */
15 /* global variables */
16 extern int obd_debug_level;
17 extern int obd_print_entry;
18
19 /* debugging masks */
20 #define D_PSDEV       1 /* debug information from psdev.c */
21 #define D_INODE       2
22 #define D_UNUSED2     4
23 #define D_UNUSED3     8
24 #define D_UNUSED4    16
25 #define D_WARNING    32 /* misc warnings */
26 #define D_EXT2       64 /* anything from ext2_debug */
27 #define D_MALLOC    128 /* print malloc, free information */
28 #define D_CACHE     256 /* cache-related items */
29 #define D_INFO      512 /* general information, especially from interface.c */
30 #define D_IOCTL    1024 /* ioctl related information */
31 #define D_BLOCKS   2048 /* ext2 block allocation */
32  
33 #ifdef SIM_OBD_DEBUG
34 #define CDEBUG(mask, format, a...)                                      \
35         do {                                                            \
36         if (obd_debug_level & mask) {                                   \
37                 printk("(%s,l. %d): ",  __FUNCTION__, __LINE__);        \
38                 printk(format, ## a); }                                 \
39         } while (0)
40
41 #define ENTRY                                                                 \
42         if (obd_print_entry)                                                  \
43                 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
44
45 #define EXIT                                                                  \
46         if (obd_print_entry)                                                  \
47                 printk("Process %d leaving %s\n", current->pid, __FUNCTION__)
48
49 #else /* SIM_OBD_DEBUG */
50
51 #       define CDEBUG ;
52 #       define ENTRY ;
53 #       define EXIT ;
54
55 #endif /* SIM_OBD_DEBUG */
56
57
58 #define CMD(cmd) (( cmd == READ ) ? "read" : "write")
59
60 #define PDEBUG(page,cmd)        {if (page){\
61                 char *uptodate = (Page_Uptodate(page)) ? "yes" : "no";\
62                 char *locked = (PageLocked(page)) ? "yes" : "no";\
63                 int count = page->count.counter;\
64                 long ino = (page->inode) ? page->inode->i_ino : -1;\
65                 long offset = page->offset / PAGE_SIZE;\
66                 \
67                 CDEBUG(D_IOCTL, " ** %s, cmd: %s, ino: %ld, off %ld, uptodate: %s, "\
68                        "locked: %s, cnt %d page %p ** \n", __FUNCTION__,\
69                        cmd, ino, offset, uptodate, locked, count, page);\
70         } else { CDEBUG(D_IOCTL, "** %s, no page\n", __FUNCTION__); }}
71
72
73 #define OBD_ALLOC(ptr, cast, size)                                      \
74 do {                                                                    \
75         if (size <= 4096) {                                             \
76                 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
77                 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n",              \
78                        (int) size, (int) ptr);                          \
79         } else {                                                        \
80                 ptr = (cast)vmalloc((unsigned long) size);              \
81                 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n",              \
82                        (int) size, (int) ptr);                          \
83         }                                                               \
84         if (ptr == 0) {                                                 \
85                 printk("kernel malloc returns 0 at %s:%d\n",            \
86                        __FILE__, __LINE__);                             \
87         }                                                               \
88         memset(ptr, 0, size);                                           \
89 } while (0)
90
91 #define OBD_FREE(ptr,size)                              \
92 do {                                                    \
93         if (size <= 4096) {                             \
94                 kfree_s((ptr), (size));                 \
95                 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
96                        (int) size, (int) ptr);          \
97         } else {                                        \
98                 vfree((ptr));                           \
99                 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
100                        (int) size, (int) ptr);          \
101         }                                               \
102 } while (0)
103
104
105
106 static inline void inode_to_iattr(struct inode *inode, struct iattr *tmp)
107 {
108         tmp->ia_mode = inode->i_mode;
109         tmp->ia_uid = inode->i_uid;
110         tmp->ia_gid = inode->i_gid;
111         tmp->ia_size = inode->i_size;
112         tmp->ia_atime = inode->i_atime;
113         tmp->ia_mtime = inode->i_mtime;
114         tmp->ia_ctime = inode->i_ctime;
115         tmp->ia_attr_flags = inode->i_flags;
116
117         tmp->ia_valid = ~0;
118 }
119
120 static inline void inode_cpy(struct inode *dest, struct inode *src)
121 {
122         dest->i_mode = src->i_mode;
123         dest->i_uid = src->i_uid;
124         dest->i_gid = src->i_gid;
125         dest->i_size = src->i_size;
126         dest->i_atime = src->i_atime;
127         dest->i_mtime = src->i_mtime;
128         dest->i_ctime = src->i_ctime;
129         dest->i_attr_flags = src->i_flags;
130         /* allocation of space */
131         dest->i_blocks = src->i_blocks;
132
133         if ( !dest->i_blocks) 
134                 memcpy(&dest->u, &src->u, sizeof(src->u));
135 }
136
137
138
139
140
141
142
143
144
145
146 #endif