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