Whamcloud - gitweb
landing smfs.
[fs/lustre-release.git] / lnet / 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 /* I think this beast is just trying to get cycles_t and get_cycles().
10  * this should be in its own header. */
11 #ifdef __linux__
12 # include <asm/types.h>
13 # if defined(__powerpc__) && !defined(__KERNEL__)
14 #  define __KERNEL__
15 #  include <asm/timex.h>
16 #  undef __KERNEL__
17 # else
18 #  if defined(__KERNEL__)
19 #   include <asm/timex.h>
20 #  else
21 #   include <sys/time.h>
22 #   define cycles_t unsigned long
23 static inline cycles_t get_cycles(void) 
24 {
25         struct timeval tv;
26         gettimeofday(&tv, NULL);
27         return (tv.tv_sec * 100000) + tv.tv_usec;
28 }
29 #  endif
30 # endif
31 #else
32 # include <sys/types.h>
33 typedef u_int32_t __u32;
34 typedef u_int64_t __u64;
35 #endif
36
37 #ifdef __KERNEL__
38 # include <linux/time.h>
39 #else
40 # include <sys/time.h>
41 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
42 #endif
43
44 #ifndef offsetof
45 # define offsetof(typ,memb)     ((unsigned long)((char *)&(((typ *)0)->memb)))
46 #endif
47
48 #define LOWEST_BIT_SET(x)       ((x) & ~((x) - 1))
49
50 /*
51  *  Debugging
52  */
53 extern unsigned int portal_subsystem_debug;
54 extern unsigned int portal_stack;
55 extern unsigned int portal_debug;
56 extern unsigned int portal_printk;
57 extern unsigned int portal_cerror;
58 /* Debugging subsystems (32 bits, non-overlapping) */
59 #define S_UNDEFINED   0x00000001
60 #define S_MDC         0x00000002
61 #define S_MDS         0x00000004
62 #define S_OSC         0x00000008
63 #define S_OST         0x00000010
64 #define S_CLASS       0x00000020
65 #define S_LOG         0x00000040
66 #define S_LLITE       0x00000080
67 #define S_RPC         0x00000100
68 #define S_MGMT        0x00000200
69 #define S_PORTALS     0x00000400
70 #define S_SOCKNAL     0x00000800
71 #define S_QSWNAL      0x00001000
72 #define S_PINGER      0x00002000
73 #define S_FILTER      0x00004000
74 #define S_PTLBD       0x00008000
75 #define S_ECHO        0x00010000
76 #define S_LDLM        0x00020000
77 #define S_LOV         0x00040000
78 #define S_GMNAL       0x00080000
79 #define S_PTLROUTER   0x00100000
80 #define S_COBD        0x00200000
81 #define S_IBNAL       0x00400000
82 #define S_SM          0x00800000
83
84 /* If you change these values, please keep portals/utils/debug.c
85  * up to date! */
86
87 /* Debugging masks (32 bits, non-overlapping) */
88 #define D_TRACE       0x00000001 /* ENTRY/EXIT markers */
89 #define D_INODE       0x00000002
90 #define D_SUPER       0x00000004
91 #define D_EXT2        0x00000008 /* anything from ext2_debug */
92 #define D_MALLOC      0x00000010 /* print malloc, free information */
93 #define D_CACHE       0x00000020 /* cache-related items */
94 #define D_INFO        0x00000040 /* general information */
95 #define D_IOCTL       0x00000080 /* ioctl related information */
96 #define D_BLOCKS      0x00000100 /* ext2 block allocation */
97 #define D_NET         0x00000200 /* network communications */
98 #define D_WARNING     0x00000400 /* CWARN(...) == CDEBUG (D_WARNING, ...) */
99 #define D_BUFFS       0x00000800
100 #define D_OTHER       0x00001000
101 #define D_DENTRY      0x00002000
102 #define D_PORTALS     0x00004000 /* ENTRY/EXIT markers */
103 #define D_PAGE        0x00008000 /* bulk page handling */
104 #define D_DLMTRACE    0x00010000
105 #define D_ERROR       0x00020000 /* CERROR(...) == CDEBUG (D_ERROR, ...) */
106 #define D_EMERG       0x00040000 /* CEMERG(...) == CDEBUG (D_EMERG, ...) */
107 #define D_HA          0x00080000 /* recovery and failover */
108 #define D_RPCTRACE    0x00100000 /* for distributed debugging */
109 #define D_VFSTRACE    0x00200000
110 #define D_READA       0x00400000 /* read-ahead */
111
112 #ifdef __KERNEL__
113 # include <linux/sched.h> /* THREAD_SIZE */
114 #else
115 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
116 #  define THREAD_SIZE 8192
117 # endif
118 #endif
119
120 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
121
122 #ifdef __KERNEL__
123 # ifdef  __ia64__
124 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
125                         ((unsigned long)__builtin_dwarf_cfa() &            \
126                          (THREAD_SIZE - 1)))
127 # else
128 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
129                         ((unsigned long)__builtin_frame_address(0) &       \
130                          (THREAD_SIZE - 1)))
131 # endif
132
133 #define CHECK_STACK(stack)                                                    \
134         do {                                                                  \
135                 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) {    \
136                         portals_debug_msg(DEBUG_SUBSYSTEM, D_WARNING,         \
137                                           __FILE__, __FUNCTION__, __LINE__,   \
138                                           (stack),"maximum lustre stack %u\n",\
139                                           portal_stack = (stack));            \
140                       /*panic("LBUG");*/                                      \
141                 }                                                             \
142         } while (0)
143 #else /* __KERNEL__ */
144 #define CHECK_STACK(stack) do { } while(0)
145 #define CDEBUG_STACK (0L)
146 #endif /* __KERNEL__ */
147
148 #if 1
149 #define CDEBUG(mask, format, a...)                                            \
150 do {                                                                          \
151         if (portal_cerror == 0)                                               \
152                 break;                                                        \
153         CHECK_STACK(CDEBUG_STACK);                                            \
154         if (((mask) & (D_ERROR | D_EMERG | D_WARNING)) ||                     \
155             (portal_debug & (mask) &&                                         \
156              portal_subsystem_debug & DEBUG_SUBSYSTEM))                       \
157                 portals_debug_msg(DEBUG_SUBSYSTEM, mask,                      \
158                                   __FILE__, __FUNCTION__, __LINE__,           \
159                                   CDEBUG_STACK, format, ## a);                \
160 } while (0)
161
162 #define CWARN(format, a...) CDEBUG(D_WARNING, format, ## a)
163 #define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
164 #define CEMERG(format, a...) CDEBUG(D_EMERG, format, ## a)
165
166 #define GOTO(label, rc)                                                 \
167 do {                                                                    \
168         long GOTO__ret = (long)(rc);                                    \
169         CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
170                #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
171                (signed long)GOTO__ret);                                 \
172         goto label;                                                     \
173 } while (0)
174
175 #define RETURN(rc)                                                      \
176 do {                                                                    \
177         typeof(rc) RETURN__ret = (rc);                                  \
178         CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n",       \
179                (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
180         return RETURN__ret;                                             \
181 } while (0)
182
183 #define ENTRY                                                           \
184 do {                                                                    \
185         CDEBUG(D_TRACE, "Process entered\n");                           \
186 } while (0)
187
188 #define EXIT                                                            \
189 do {                                                                    \
190         CDEBUG(D_TRACE, "Process leaving\n");                           \
191 } while(0)
192 #else
193 #define CDEBUG(mask, format, a...)      do { } while (0)
194 #define CWARN(format, a...)             do { } while (0)
195 #define CERROR(format, a...)            printk("<3>" format, ## a)
196 #define CEMERG(format, a...)            printk("<0>" format, ## a)
197 #define GOTO(label, rc)                 do { (void)(rc); goto label; } while (0)
198 #define RETURN(rc)                      return (rc)
199 #define ENTRY                           do { } while (0)
200 #define EXIT                            do { } while (0)
201 #endif
202
203 #define PORTALS_CFG_VERSION 0x00010001;
204
205 struct portals_cfg {
206         __u32 pcfg_version;
207         __u32 pcfg_command;
208
209         __u32 pcfg_nal;
210         __u32 pcfg_flags;
211
212         __u32 pcfg_gw_nal;
213         __u64 pcfg_nid;
214         __u64 pcfg_nid2;
215         __u64 pcfg_nid3;
216         __u32 pcfg_id;
217         __u32 pcfg_misc;
218         __u32 pcfg_fd;
219         __u32 pcfg_count;
220         __u32 pcfg_size;
221         __u32 pcfg_wait;
222
223         __u32 pcfg_plen1; /* buffers in userspace */
224         char *pcfg_pbuf1;
225         __u32 pcfg_plen2; /* buffers in userspace */
226         char *pcfg_pbuf2;
227 };
228
229 #define PCFG_INIT(pcfg, cmd)                            \
230 do {                                                    \
231         memset(&pcfg, 0, sizeof(pcfg));                 \
232         pcfg.pcfg_version = PORTALS_CFG_VERSION;        \
233         pcfg.pcfg_command = (cmd);                      \
234                                                         \
235 } while (0)
236
237 typedef int (nal_cmd_handler_fn)(struct portals_cfg *, void *);
238 int libcfs_nal_cmd_register(int nal, nal_cmd_handler_fn *handler, void *arg);
239 int libcfs_nal_cmd(struct portals_cfg *pcfg);
240 void libcfs_nal_cmd_unregister(int nal);
241
242 struct portal_ioctl_data {
243         __u32 ioc_len;
244         __u32 ioc_version;
245         __u64 ioc_nid;
246         __u64 ioc_nid2;
247         __u64 ioc_nid3;
248         __u32 ioc_count;
249         __u32 ioc_nal;
250         __u32 ioc_nal_cmd;
251         __u32 ioc_fd;
252         __u32 ioc_id;
253
254         __u32 ioc_flags;
255         __u32 ioc_size;
256
257         __u32 ioc_wait;
258         __u32 ioc_timeout;
259         __u32 ioc_misc;
260
261         __u32 ioc_inllen1;
262         char *ioc_inlbuf1;
263         __u32 ioc_inllen2;
264         char *ioc_inlbuf2;
265
266         __u32 ioc_plen1; /* buffers in userspace */
267         char *ioc_pbuf1;
268         __u32 ioc_plen2; /* buffers in userspace */
269         char *ioc_pbuf2;
270
271         char ioc_bulk[0];
272 };
273
274
275 #ifdef __KERNEL__
276
277 #include <linux/list.h>
278
279 struct libcfs_ioctl_handler {
280         struct list_head item;
281         int (*handle_ioctl)(struct portal_ioctl_data *data,
282                             unsigned int cmd, unsigned long args);
283 };
284
285 #define DECLARE_IOCTL_HANDLER(ident, func)              \
286         struct libcfs_ioctl_handler ident = {           \
287                 .item = LIST_HEAD_INIT(ident.item),     \
288                 .handle_ioctl = func                    \
289         }
290
291 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
292 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
293
294 #endif
295
296 #define _LIBCFS_H
297
298 #endif /* _LIBCFS_H */