Whamcloud - gitweb
* demos/snaprest.sh: ensure client is disconnected after snaprestore
[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 #define IDEBUG(inode) { \
63                 printk("]]%s line %d[[  ino %ld, blocks %ld, size %Ld, atm %ld, ctim %ld, mtm %ld, mode %o, uid %d, gid %d\n", \
64                        __FUNCTION__ , __LINE__, \
65                        inode->i_ino, inode->i_blocks, inode->i_size,\
66                        inode->i_atime, inode->i_ctime, inode->i_mtime,\
67                        inode->i_mode, inode->i_uid, inode->i_gid);\
68                 printk("blk: %d %d %d %d %d %d %d %d %d %d\n",\
69                        inode->u.ext2_i.i_data[0], inode->u.ext2_i.i_data[1],\
70                        inode->u.ext2_i.i_data[2], inode->u.ext2_i.i_data[3],\
71                        inode->u.ext2_i.i_data[4], inode->u.ext2_i.i_data[5],\
72                        inode->u.ext2_i.i_data[6], inode->u.ext2_i.i_data[7],\
73                        inode->u.ext2_i.i_data[8], inode->u.ext2_i.i_data[9]);\
74         }
75
76
77 #define PDEBUG(page,cmd)        {if (page){\
78                 char *uptodate = (Page_Uptodate(page)) ? "yes" : "no";\
79                 char *locked = (PageLocked(page)) ? "yes" : "no";\
80                 int count = page->count.counter;\
81                 long index = page->index;\
82                 \
83                 CDEBUG(D_IOCTL, " ** %s, cmd: %s, off %ld, uptodate: %s, "\
84                        "locked: %s, cnt %d page %p pages %ld** \n", __FUNCTION__,\
85                        cmd, index, uptodate, locked, count, page, (!page->mapping) ? -1 : page->mapping->nrpages);\
86         } else { CDEBUG(D_IOCTL, "** %s, no page\n", __FUNCTION__); }}
87
88
89 #define OBD_ALLOC(ptr, cast, size)                                      \
90 do {                                                                    \
91         if (size <= 4096) {                                             \
92                 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
93                 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n",              \
94                        (int) size, (int) ptr);                          \
95         } else {                                                        \
96                 ptr = (cast)vmalloc((unsigned long) size);              \
97                 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n",              \
98                        (int) size, (int) ptr);                          \
99         }                                                               \
100         if (ptr == 0) {                                                 \
101                 printk("kernel malloc returns 0 at %s:%d\n",            \
102                        __FILE__, __LINE__);                             \
103         }                                                               \
104         memset(ptr, 0, size);                                           \
105 } while (0)
106
107 #define OBD_FREE(ptr,size)                              \
108 do {                                                    \
109         if (size <= 4096) {                             \
110                 kfree_s((ptr), (size));                 \
111                 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
112                        (int) size, (int) ptr);          \
113         } else {                                        \
114                 vfree((ptr));                           \
115                 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
116                        (int) size, (int) ptr);          \
117         }                                               \
118 } while (0)
119
120
121
122 static inline void inode_to_iattr(struct inode *inode, struct iattr *tmp)
123 {
124         tmp->ia_mode = inode->i_mode;
125         tmp->ia_uid = inode->i_uid;
126         tmp->ia_gid = inode->i_gid;
127         tmp->ia_size = inode->i_size;
128         tmp->ia_atime = inode->i_atime;
129         tmp->ia_mtime = inode->i_mtime;
130         tmp->ia_ctime = inode->i_ctime;
131         /*      tmp->ia_flags = inode->i_flags; */
132
133         tmp->ia_valid = ~0;
134 }
135
136
137 #define OBD_MAGIC_INL 0x77777770
138
139
140 static inline void inode_cpy(struct inode *dest, struct inode *src)
141 {
142         dest->i_mode = src->i_mode;
143         dest->i_uid = src->i_uid;
144         dest->i_gid = src->i_gid;
145         dest->i_size = src->i_size;
146         dest->i_atime = src->i_atime;
147         dest->i_mtime = src->i_mtime;
148         dest->i_ctime = src->i_ctime;
149         dest->i_flags = src->i_flags;
150         /* allocation of space */
151         dest->i_blocks = src->i_blocks;
152         if ( !src->i_blocks || 
153              OBD_MAGIC_INL == (OBD_MAGIC_INL & src->u.ext2_i.i_data[0])) {
154                 CDEBUG(D_IOCTL, "copying inline data: ino %ld\n", dest->i_ino);
155                 memcpy(&dest->u.ext2_i.i_data, &src->u.ext2_i.i_data, 
156                        sizeof(src->u.ext2_i.i_data));
157         }
158 }
159
160
161
162 #endif