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