Whamcloud - gitweb
b=2776
[fs/lustre-release.git] / lustre / portals / include / linux / libcfs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #ifndef _LIBCFS_H
5
6
7 #define PORTAL_DEBUG
8
9 #ifndef offsetof
10 # define offsetof(typ,memb)     ((int)((char *)&(((typ *)0)->memb)))
11 #endif
12
13 #define LOWEST_BIT_SET(x)       ((x) & ~((x) - 1))
14
15 /*
16  *  Debugging
17  */
18 extern unsigned int portal_subsystem_debug;
19 extern unsigned int portal_stack;
20 extern unsigned int portal_debug;
21 extern unsigned int portal_printk;
22 extern unsigned int portal_cerror;
23 /* Debugging subsystems (32 bits, non-overlapping) */
24 #define S_UNDEFINED   0x00000001
25 #define S_MDC         0x00000002
26 #define S_MDS         0x00000004
27 #define S_OSC         0x00000008
28 #define S_OST         0x00000010
29 #define S_CLASS       0x00000020
30 #define S_LOG         0x00000040
31 #define S_LLITE       0x00000080
32 #define S_RPC         0x00000100
33 #define S_MGMT        0x00000200
34 #define S_PORTALS     0x00000400
35 #define S_SOCKNAL     0x00000800
36 #define S_QSWNAL      0x00001000
37 #define S_PINGER      0x00002000
38 #define S_FILTER      0x00004000
39 #define S_PTLBD       0x00008000
40 #define S_ECHO        0x00010000
41 #define S_LDLM        0x00020000
42 #define S_LOV         0x00040000
43 #define S_GMNAL       0x00080000
44 #define S_PTLROUTER   0x00100000
45 #define S_COBD        0x00200000
46 #define S_IBNAL       0x00400000
47
48 /* If you change these values, please keep portals/utils/debug.c
49  * up to date! */
50
51 /* Debugging masks (32 bits, non-overlapping) */
52 #define D_TRACE       0x00000001 /* ENTRY/EXIT markers */
53 #define D_INODE       0x00000002
54 #define D_SUPER       0x00000004
55 #define D_EXT2        0x00000008 /* anything from ext2_debug */
56 #define D_MALLOC      0x00000010 /* print malloc, free information */
57 #define D_CACHE       0x00000020 /* cache-related items */
58 #define D_INFO        0x00000040 /* general information */
59 #define D_IOCTL       0x00000080 /* ioctl related information */
60 #define D_BLOCKS      0x00000100 /* ext2 block allocation */
61 #define D_NET         0x00000200 /* network communications */
62 #define D_WARNING     0x00000400 /* CWARN(...) == CDEBUG (D_WARNING, ...) */
63 #define D_BUFFS       0x00000800
64 #define D_OTHER       0x00001000
65 #define D_DENTRY      0x00002000
66 #define D_PORTALS     0x00004000 /* ENTRY/EXIT markers */
67 #define D_PAGE        0x00008000 /* bulk page handling */
68 #define D_DLMTRACE    0x00010000
69 #define D_ERROR       0x00020000 /* CERROR(...) == CDEBUG (D_ERROR, ...) */
70 #define D_EMERG       0x00040000 /* CEMERG(...) == CDEBUG (D_EMERG, ...) */
71 #define D_HA          0x00080000 /* recovery and failover */
72 #define D_RPCTRACE    0x00100000 /* for distributed debugging */
73 #define D_VFSTRACE    0x00200000
74 #define D_READA       0x00400000 /* read-ahead */
75
76 #ifdef __KERNEL__
77 # include <linux/sched.h> /* THREAD_SIZE */
78 #else
79 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
80 #  define THREAD_SIZE 8192
81 # endif
82 #endif
83
84 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
85
86 #ifdef __KERNEL__
87 # ifdef  __ia64__
88 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
89                         ((unsigned long)__builtin_dwarf_cfa() &            \
90                          (THREAD_SIZE - 1)))
91 # else
92 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
93                         ((unsigned long)__builtin_frame_address(0) &       \
94                          (THREAD_SIZE - 1)))
95 # endif
96
97 #define CHECK_STACK(stack)                                                    \
98         do {                                                                  \
99                 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) {    \
100                         portals_debug_msg(DEBUG_SUBSYSTEM, D_WARNING,         \
101                                           __FILE__, __FUNCTION__, __LINE__,   \
102                                           (stack),"maximum lustre stack %u\n",\
103                                           portal_stack = (stack));            \
104                       /*panic("LBUG");*/                                      \
105                 }                                                             \
106         } while (0)
107 #else /* __KERNEL__ */
108 #define CHECK_STACK(stack) do { } while(0)
109 #define CDEBUG_STACK (0L)
110 #endif /* __KERNEL__ */
111
112 #if 1
113 #define CDEBUG(mask, format, a...)                                            \
114 do {                                                                          \
115         if (portal_cerror == 0)                                               \
116                 break;                                                        \
117         CHECK_STACK(CDEBUG_STACK);                                            \
118         if (((mask) & (D_ERROR | D_EMERG | D_WARNING)) ||                     \
119             (portal_debug & (mask) &&                                         \
120              portal_subsystem_debug & DEBUG_SUBSYSTEM))                       \
121                 portals_debug_msg(DEBUG_SUBSYSTEM, mask,                      \
122                                   __FILE__, __FUNCTION__, __LINE__,           \
123                                   CDEBUG_STACK, format, ## a);                \
124 } while (0)
125
126 #define CWARN(format, a...) CDEBUG(D_WARNING, format, ## a)
127 #define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
128 #define CEMERG(format, a...) CDEBUG(D_EMERG, format, ## a)
129
130 #define GOTO(label, rc)                                                 \
131 do {                                                                    \
132         long GOTO__ret = (long)(rc);                                    \
133         CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
134                #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
135                (signed long)GOTO__ret);                                 \
136         goto label;                                                     \
137 } while (0)
138
139 #define RETURN(rc)                                                      \
140 do {                                                                    \
141         typeof(rc) RETURN__ret = (rc);                                  \
142         CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n",       \
143                (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
144         return RETURN__ret;                                             \
145 } while (0)
146
147 #define ENTRY                                                           \
148 do {                                                                    \
149         CDEBUG(D_TRACE, "Process entered\n");                           \
150 } while (0)
151
152 #define EXIT                                                            \
153 do {                                                                    \
154         CDEBUG(D_TRACE, "Process leaving\n");                           \
155 } while(0)
156 #else
157 #define CDEBUG(mask, format, a...)      do { } while (0)
158 #define CWARN(format, a...)             do { } while (0)
159 #define CERROR(format, a...)            printk("<3>" format, ## a)
160 #define CEMERG(format, a...)            printk("<0>" format, ## a)
161 #define GOTO(label, rc)                 do { (void)(rc); goto label; } while (0)
162 #define RETURN(rc)                      return (rc)
163 #define ENTRY                           do { } while (0)
164 #define EXIT                            do { } while (0)
165 #endif
166
167 struct portal_ioctl_data {
168         __u32 ioc_len;
169         __u32 ioc_version;
170         __u64 ioc_nid;
171         __u64 ioc_nid2;
172         __u64 ioc_nid3;
173         __u32 ioc_count;
174         __u32 ioc_nal;
175         __u32 ioc_nal_cmd;
176         __u32 ioc_fd;
177         __u32 ioc_id;
178
179         __u32 ioc_flags;
180         __u32 ioc_size;
181
182         __u32 ioc_wait;
183         __u32 ioc_timeout;
184         __u32 ioc_misc;
185
186         __u32 ioc_inllen1;
187         char *ioc_inlbuf1;
188         __u32 ioc_inllen2;
189         char *ioc_inlbuf2;
190
191         __u32 ioc_plen1; /* buffers in userspace */
192         char *ioc_pbuf1;
193         __u32 ioc_plen2; /* buffers in userspace */
194         char *ioc_pbuf2;
195
196         char ioc_bulk[0];
197 };
198
199 #ifdef __KERNEL__
200
201 #include <linux/list.h>
202
203 struct libcfs_ioctl_handler {
204         struct list_head item;
205         int (*handle_ioctl)(struct portal_ioctl_data *data,
206                             unsigned int cmd, unsigned long args);
207 };
208
209 #define DECLARE_IOCTL_HANDLER(ident, func)              \
210         struct libcfs_ioctl_handler ident = {           \
211                 .item = LIST_HEAD_INIT(ident.item),     \
212                 .handle_ioctl = func                    \
213         }
214
215 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
216 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
217
218 #endif
219
220 #define _LIBCFS_H
221
222 #endif /* _LIBCFS_H */