Whamcloud - gitweb
82a3c511559511646b14ec1890696eb55ff92502
[fs/lustre-release.git] / lnet / include / libcfs / libcfs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #ifndef __LIBCFS_LIBCFS_H__
5 #define __LIBCFS_LIBCFS_H__
6
7 #if !__GNUC__
8 #define __attribute__(x)
9 #endif
10
11 #if defined(__linux__)
12 #include <libcfs/linux/libcfs.h>
13 #elif defined(__APPLE__)
14 #include <libcfs/darwin/libcfs.h>
15 #elif defined(__WINNT__)
16 #include <libcfs/winnt/libcfs.h>
17 #else
18 #error Unsupported operating system.
19 #endif
20
21 #include "curproc.h"
22
23 #ifndef __KERNEL__
24 #include <stdio.h>
25 #endif
26
27 /* Controlled via configure key */
28 /* #define LIBCFS_DEBUG */
29
30 #ifndef offsetof
31 # define offsetof(typ,memb)     ((unsigned long)((char *)&(((typ *)0)->memb)))
32 #endif
33
34 /* cardinality of array */
35 #define sizeof_array(a) ((sizeof (a)) / (sizeof ((a)[0])))
36
37 #if !defined(container_of)
38 /* given a pointer @ptr to the field @member embedded into type (usually
39  * struct) @type, return pointer to the embedding instance of @type. */
40 #define container_of(ptr, type, member) \
41         ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
42 #endif
43
44 #define container_of0(ptr, type, member)                        \
45 ({                                                              \
46         typeof(ptr) __ptr = (ptr);                              \
47         __ptr ? container_of(__ptr, type, member) : NULL;       \
48 })
49
50 /*
51  * true iff @i is power-of-2
52  */
53 #define IS_PO2(i)                               \
54 ({                                              \
55         typeof(i) __i;                          \
56                                                 \
57         __i = (i);                              \
58         !(__i & (__i - 1));                     \
59 })
60
61 #define LOWEST_BIT_SET(x)       ((x) & ~((x) - 1))
62
63 /*
64  *  Debugging
65  */
66 extern unsigned int libcfs_subsystem_debug;
67 extern unsigned int libcfs_stack;
68 extern unsigned int libcfs_debug;
69 extern unsigned int libcfs_printk;
70 extern unsigned int libcfs_console_ratelimit;
71 extern unsigned int libcfs_debug_binary;
72 extern char debug_file_path[1024];
73
74 int libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys);
75 int libcfs_debug_str2mask(int *mask, const char *str, int is_subsys);
76
77 /* Has there been an LBUG? */
78 extern unsigned int libcfs_catastrophe;
79
80 /*
81  * struct ptldebug_header is defined in libcfs/<os>/libcfs.h
82  */
83
84 #define PH_FLAG_FIRST_RECORD 1
85
86 /* Debugging subsystems (32 bits, non-overlapping) */
87 /* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */
88 #define S_UNDEFINED   0x00000001
89 #define S_MDC         0x00000002
90 #define S_MDS         0x00000004
91 #define S_OSC         0x00000008
92 #define S_OST         0x00000010
93 #define S_CLASS       0x00000020
94 #define S_LOG         0x00000040
95 #define S_LLITE       0x00000080
96 #define S_RPC         0x00000100
97 #define S_MGMT        0x00000200
98 #define S_LNET        0x00000400
99 #define S_LND         0x00000800 /* ALL LNDs */
100 #define S_PINGER      0x00001000
101 #define S_FILTER      0x00002000
102 /* unused */
103 #define S_ECHO        0x00008000
104 #define S_LDLM        0x00010000
105 #define S_LOV         0x00020000
106 /* unused */
107 /* unused */
108 /* unused */
109 /* unused */
110 /* unused */
111 #define S_LMV         0x00800000 /* b_new_cmd */
112 /* unused */
113 #define S_SEC         0x02000000 /* upcall cache */
114 #define S_GSS         0x04000000 /* b_new_cmd */
115 /* unused */
116 #define S_MGC         0x10000000
117 #define S_MGS         0x20000000
118 #define S_FID         0x40000000 /* b_new_cmd */
119 #define S_FLD         0x80000000 /* b_new_cmd */
120 /* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */
121
122 /* Debugging masks (32 bits, non-overlapping) */
123 /* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */
124 #define D_TRACE       0x00000001 /* ENTRY/EXIT markers */
125 #define D_INODE       0x00000002
126 #define D_SUPER       0x00000004
127 #define D_EXT2        0x00000008 /* anything from ext2_debug */
128 #define D_MALLOC      0x00000010 /* print malloc, free information */
129 #define D_CACHE       0x00000020 /* cache-related items */
130 #define D_INFO        0x00000040 /* general information */
131 #define D_IOCTL       0x00000080 /* ioctl related information */
132 #define D_NETERROR    0x00000100 /* network errors */
133 #define D_NET         0x00000200 /* network communications */
134 #define D_WARNING     0x00000400 /* CWARN(...) == CDEBUG (D_WARNING, ...) */
135 #define D_BUFFS       0x00000800
136 #define D_OTHER       0x00001000
137 #define D_DENTRY      0x00002000
138 #define D_NETTRACE    0x00004000
139 #define D_PAGE        0x00008000 /* bulk page handling */
140 #define D_DLMTRACE    0x00010000
141 #define D_ERROR       0x00020000 /* CERROR(...) == CDEBUG (D_ERROR, ...) */
142 #define D_EMERG       0x00040000 /* CEMERG(...) == CDEBUG (D_EMERG, ...) */
143 #define D_HA          0x00080000 /* recovery and failover */
144 #define D_RPCTRACE    0x00100000 /* for distributed debugging */
145 #define D_VFSTRACE    0x00200000
146 #define D_READA       0x00400000 /* read-ahead */
147 #define D_MMAP        0x00800000
148 #define D_CONFIG      0x01000000
149 #define D_CONSOLE     0x02000000
150 #define D_QUOTA       0x04000000
151 #define D_SEC         0x08000000
152 /* keep these in sync with lnet/{utils,libcfs}/debug.c */
153
154 #define D_CANTMASK   (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)
155
156 #ifndef DEBUG_SUBSYSTEM
157 # define DEBUG_SUBSYSTEM S_UNDEFINED
158 #endif
159
160 #define CDEBUG_MAX_LIMIT 600
161 typedef struct {
162         cfs_time_t      cdls_next;
163         int             cdls_count;
164         cfs_duration_t  cdls_delay;
165 } cfs_debug_limit_state_t;
166
167 /* Controlled via configure key */
168 /* #define CDEBUG_ENABLED */
169
170 #ifdef __KERNEL__
171
172 #ifdef CDEBUG_ENABLED
173 #define __CDEBUG(cdls, mask, format, a...)                              \
174 do {                                                                    \
175         CHECK_STACK();                                                  \
176                                                                         \
177         if (((mask) & D_CANTMASK) != 0 ||                               \
178             ((libcfs_debug & (mask)) != 0 &&                            \
179              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0))          \
180                 libcfs_debug_msg(cdls, DEBUG_SUBSYSTEM, mask,           \
181                                  __FILE__, __FUNCTION__, __LINE__,      \
182                                  format, ## a);                         \
183 } while (0)
184
185 #define CDEBUG(mask, format, a...) __CDEBUG(NULL, mask, format, ## a)
186
187 #define CDEBUG_LIMIT(mask, format, a...)        \
188 do {                                            \
189         static cfs_debug_limit_state_t cdls;    \
190                                                 \
191         __CDEBUG(&cdls, mask, format, ## a);    \
192 } while (0)
193
194 #else /* CDEBUG_ENABLED */
195 #define CDEBUG(mask, format, a...) (void)(0)
196 #define CDEBUG_LIMIT(mask, format, a...) (void)(0)
197 #warning "CDEBUG IS DISABLED. THIS SHOULD NEVER BE DONE FOR PRODUCTION!"
198 #endif
199
200 #elif defined(__arch_lib__) && !defined(LUSTRE_UTILS)
201
202 #define CDEBUG(mask, format, a...)                                      \
203 do {                                                                    \
204         if (((mask) & D_CANTMASK) != 0 ||                               \
205             ((libcfs_debug & (mask)) != 0 &&                            \
206              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0))          \
207                 libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, mask,           \
208                                  __FILE__, __FUNCTION__, __LINE__,      \
209                                  format, ## a);                         \
210 } while (0)
211
212 #define CDEBUG_LIMIT CDEBUG
213
214 #else
215
216 #define CDEBUG(mask, format, a...)                                      \
217 do {                                                                    \
218         if (((mask) & D_CANTMASK) != 0)                                 \
219                 fprintf(stderr, "(%s:%d:%s()) " format,                 \
220                         __FILE__, __LINE__, __FUNCTION__, ## a);        \
221 } while (0)
222
223 #define CDEBUG_LIMIT CDEBUG
224
225 #endif /* !__KERNEL__ */
226
227 #define CWARN(format, a...)          CDEBUG_LIMIT(D_WARNING, format, ## a)
228 #define CERROR(format, a...)         CDEBUG_LIMIT(D_ERROR, format, ## a)
229 #define CEMERG(format, a...)         CDEBUG_LIMIT(D_EMERG, format, ## a)
230
231 #define LCONSOLE(mask, format, a...) CDEBUG(D_CONSOLE | (mask), format, ## a)
232 #define LCONSOLE_INFO(format, a...)  CDEBUG_LIMIT(D_CONSOLE, format, ## a)
233 #define LCONSOLE_WARN(format, a...)  CDEBUG_LIMIT(D_CONSOLE | D_WARNING, format, ## a)
234 #define LCONSOLE_ERROR(format, a...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, format, ## a)
235 #define LCONSOLE_EMERG(format, a...) CDEBUG(D_CONSOLE | D_EMERG, format, ## a)
236
237 #ifdef CDEBUG_ENABLED
238
239 #define GOTO(label, rc)                                                 \
240 do {                                                                    \
241         long GOTO__ret = (long)(rc);                                    \
242         CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
243                #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
244                (signed long)GOTO__ret);                                 \
245         goto label;                                                     \
246 } while (0)
247 #else
248 #define GOTO(label, rc) do { ((void)(rc)); goto label; } while (0)
249 #endif
250
251 /* Controlled via configure key */
252 /* #define CDEBUG_ENTRY_EXIT */
253
254 #ifdef CDEBUG_ENTRY_EXIT
255
256 /*
257  * if rc == NULL, we need to code as RETURN((void *)NULL), otherwise
258  * there will be a warning in osx.
259  */
260 #define RETURN(rc)                                                      \
261 do {                                                                    \
262         typeof(rc) RETURN__ret = (rc);                                  \
263         CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n",       \
264                (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
265         EXIT_NESTING;                                                   \
266         return RETURN__ret;                                             \
267 } while (0)
268
269 #define ENTRY                                                           \
270 ENTRY_NESTING;                                                          \
271 do {                                                                    \
272         CDEBUG(D_TRACE, "Process entered\n");                           \
273 } while (0)
274
275 #define EXIT                                                            \
276 do {                                                                    \
277         CDEBUG(D_TRACE, "Process leaving\n");                           \
278         EXIT_NESTING;                                                   \
279 } while(0)
280 #else /* !CDEBUG_ENTRY_EXIT */
281
282 #define RETURN(rc) return (rc)
283 #define ENTRY                           do { } while (0)
284 #define EXIT                            do { } while (0)
285
286 #endif /* !CDEBUG_ENTRY_EXIT */
287
288 /*
289  * Some (nomina odiosa sunt) platforms define NULL as naked 0. This confuses
290  * Lustre RETURN(NULL) macro.
291  */
292 #if defined(NULL)
293 #undef NULL
294 #endif
295
296 #define NULL ((void *)0)
297
298 #define LUSTRE_SRV_LNET_PID      LUSTRE_LNET_PID
299
300 #ifdef __KERNEL__
301
302 #include <libcfs/list.h>
303
304 struct libcfs_ioctl_data;                       /* forward ref */
305
306 struct libcfs_ioctl_handler {
307         struct list_head item;
308         int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_data *data);
309 };
310
311 #define DECLARE_IOCTL_HANDLER(ident, func)                      \
312         struct libcfs_ioctl_handler ident = {                   \
313                 /* .item = */ CFS_LIST_HEAD_INIT(ident.item),   \
314                 /* .handle_ioctl = */ func                      \
315         }
316
317 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
318 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
319
320 /* libcfs tcpip */
321 #define LNET_ACCEPTOR_MIN_RESERVED_PORT    512
322 #define LNET_ACCEPTOR_MAX_RESERVED_PORT    1023
323
324 int libcfs_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask);
325 int libcfs_ipif_enumerate(char ***names);
326 void libcfs_ipif_free_enumeration(char **names, int n);
327 int libcfs_sock_listen(cfs_socket_t **sockp, __u32 ip, int port, int backlog);
328 int libcfs_sock_accept(cfs_socket_t **newsockp, cfs_socket_t *sock);
329 void libcfs_sock_abort_accept(cfs_socket_t *sock);
330 int libcfs_sock_connect(cfs_socket_t **sockp, int *fatal,
331                         __u32 local_ip, int local_port,
332                         __u32 peer_ip, int peer_port);
333 int libcfs_sock_setbuf(cfs_socket_t *socket, int txbufsize, int rxbufsize);
334 int libcfs_sock_getbuf(cfs_socket_t *socket, int *txbufsize, int *rxbufsize);
335 int libcfs_sock_getaddr(cfs_socket_t *socket, int remote, __u32 *ip, int *port);
336 int libcfs_sock_write(cfs_socket_t *sock, void *buffer, int nob, int timeout);
337 int libcfs_sock_read(cfs_socket_t *sock, void *buffer, int nob, int timeout);
338 void libcfs_sock_release(cfs_socket_t *sock);
339
340 /* libcfs watchdogs */
341 struct lc_watchdog;
342
343 /* Add a watchdog which fires after "time" milliseconds of delay.  You have to
344  * touch it once to enable it. */
345 struct lc_watchdog *lc_watchdog_add(int time,
346                                     void (*cb)(pid_t pid, void *),
347                                     void *data);
348
349 /* Enables a watchdog and resets its timer. */
350 void lc_watchdog_touch(struct lc_watchdog *lcw);
351
352 /* Disable a watchdog; touch it to restart it. */
353 void lc_watchdog_disable(struct lc_watchdog *lcw);
354
355 /* Clean up the watchdog */
356 void lc_watchdog_delete(struct lc_watchdog *lcw);
357
358 /* Dump a debug log */
359 void lc_watchdog_dumplog(pid_t pid, void *data);
360
361 /* __KERNEL__ */
362 #endif
363
364 /*
365  * libcfs pseudo device operations
366  *
367  * struct cfs_psdev_t and
368  * cfs_psdev_register() and
369  * cfs_psdev_deregister() are declared in
370  * libcfs/<os>/cfs_prim.h
371  *
372  * It's just draft now.
373  */
374
375 struct cfs_psdev_file {
376         unsigned long   off;
377         void            *private_data;
378         unsigned long   reserved1;
379         unsigned long   reserved2;
380 };
381
382 struct cfs_psdev_ops {
383         int (*p_open)(unsigned long, void *);
384         int (*p_close)(unsigned long, void *);
385         int (*p_read)(struct cfs_psdev_file *, char *, unsigned long);
386         int (*p_write)(struct cfs_psdev_file *, char *, unsigned long);
387         int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void *);
388 };
389
390 /*
391  * generic time manipulation functions.
392  */
393
394 static inline int cfs_time_after(cfs_time_t t1, cfs_time_t t2)
395 {
396         return cfs_time_before(t2, t1);
397 }
398
399 static inline int cfs_time_aftereq(cfs_time_t t1, cfs_time_t t2)
400 {
401         return cfs_time_beforeq(t2, t1);
402 }
403
404 /*
405  * return seconds since UNIX epoch
406  */
407 static inline time_t cfs_unix_seconds(void)
408 {
409         cfs_fs_time_t t;
410
411         cfs_fs_time_current(&t);
412         return (time_t)cfs_fs_time_sec(&t);
413 }
414
415 static inline cfs_time_t cfs_time_shift(int seconds)
416 {
417         return cfs_time_add(cfs_time_current(), cfs_time_seconds(seconds));
418 }
419
420 static inline long cfs_timeval_sub(struct timeval *large, struct timeval *small,
421                                    struct timeval *result)
422 {
423         long r = (long) (
424                 (large->tv_sec - small->tv_sec) * ONE_MILLION +
425                 (large->tv_usec - small->tv_usec));
426         if (result != NULL) {
427                 result->tv_usec = r % ONE_MILLION;
428                 result->tv_sec = r / ONE_MILLION;
429         }
430         return r;
431 }
432
433 #define CFS_RATELIMIT(seconds)                                  \
434 ({                                                              \
435         /*                                                      \
436          * XXX nikita: non-portable initializer                 \
437          */                                                     \
438         static time_t __next_message = 0;                       \
439         int result;                                             \
440                                                                 \
441         if (cfs_time_after(cfs_time_current(), __next_message)) \
442                 result = 1;                                     \
443         else {                                                  \
444                 __next_message = cfs_time_shift(seconds);       \
445                 result = 0;                                     \
446         }                                                       \
447         result;                                                 \
448 })
449
450 struct libcfs_debug_msg_data {
451         cfs_debug_limit_state_t *msg_cdls;
452         int                      msg_subsys;
453         const char              *msg_file;
454         const char              *msg_fn;
455         int                      msg_line;
456 };
457
458 #define DEBUG_MSG_DATA_INIT(cdls, subsystem, file, func, ln ) { \
459         .msg_cdls           = (cdls),       \
460         .msg_subsys         = (subsystem),  \
461         .msg_file           = (file),       \
462         .msg_fn             = (func),       \
463         .msg_line           = (ln)          \
464     }
465
466
467 extern int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls,
468                               int subsys, int mask,
469                               const char *file, const char *fn, const int line,
470                               const char *format1, va_list args,
471                               const char *format2, ...)
472         __attribute__ ((format (printf, 9, 10)));
473
474 #define libcfs_debug_vmsg(cdls, subsys, mask, file, fn, line, format, args)   \
475     libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,format,args,NULL,NULL)
476
477 #define libcfs_debug_msg(cdls, subsys, mask, file, fn, line, format, a...)    \
478     libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,NULL,NULL,format, ##a)
479
480 #define cdebug_va(cdls, mask, file, func, line, fmt, args)      do {          \
481         CHECK_STACK();                                                        \
482                                                                               \
483         if (((mask) & D_CANTMASK) != 0 ||                                     \
484             ((libcfs_debug & (mask)) != 0 &&                                  \
485              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0))                \
486                 libcfs_debug_vmsg(cdls, DEBUG_SUBSYSTEM, (mask),              \
487                                   (file), (func), (line), fmt, args);         \
488 } while(0);
489
490 #define cdebug(cdls, mask, file, func, line, fmt, a...) do {                  \
491         CHECK_STACK();                                                        \
492                                                                               \
493         if (((mask) & D_CANTMASK) != 0 ||                                     \
494             ((libcfs_debug & (mask)) != 0 &&                                  \
495              (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0))                \
496                 libcfs_debug_msg(cdls, DEBUG_SUBSYSTEM, (mask),               \
497                                  (file), (func), (line), fmt, ## a);          \
498 } while(0);
499
500 extern void libcfs_assertion_failed(const char *expr, const char *file,
501                                     const char *fn, const int line);
502
503 static inline void cfs_slow_warning(cfs_time_t now, int seconds, char *msg)
504 {
505         if (cfs_time_after(cfs_time_current(),
506                            cfs_time_add(now, cfs_time_seconds(15))))
507                 CERROR("slow %s %lu sec\n", msg,
508                        cfs_duration_sec(cfs_time_sub(cfs_time_current(),now)));
509 }
510
511 /*
512  * helper function similar to do_gettimeofday() of Linux kernel
513  */
514 static inline void cfs_fs_timeval(struct timeval *tv)
515 {
516         cfs_fs_time_t time;
517
518         cfs_fs_time_current(&time);
519         cfs_fs_time_usec(&time, tv);
520 }
521
522 /*
523  * return valid time-out based on user supplied one. Currently we only check
524  * that time-out is not shorted than allowed.
525  */
526 static inline cfs_duration_t cfs_timeout_cap(cfs_duration_t timeout)
527 {
528         if (timeout < CFS_TICK)
529                 timeout = CFS_TICK;
530         return timeout;
531 }
532
533 /*
534  * Universal memory allocator API
535  */
536 enum cfs_alloc_flags {
537         /* allocation is not allowed to block */
538         CFS_ALLOC_ATOMIC = (1 << 0),
539         /* allocation is allowed to block */
540         CFS_ALLOC_WAIT = (1 << 1),
541         /* allocation should return zeroed memory */
542         CFS_ALLOC_ZERO   = (1 << 2),
543         /* allocation is allowed to call file-system code to free/clean
544          * memory */
545         CFS_ALLOC_FS     = (1 << 3),
546         /* allocation is allowed to do io to free/clean memory */
547         CFS_ALLOC_IO     = (1 << 4),
548         /* don't report allocation failure to the console */
549         CFS_ALLOC_NOWARN = (1 << 5),
550         /* standard allocator flag combination */
551         CFS_ALLOC_STD    = CFS_ALLOC_FS | CFS_ALLOC_IO,
552         CFS_ALLOC_USER   = CFS_ALLOC_WAIT | CFS_ALLOC_FS | CFS_ALLOC_IO,
553 };
554
555 /* flags for cfs_page_alloc() in addition to enum cfs_alloc_flags */
556 enum cfs_alloc_page_flags {
557         /* allow to return page beyond KVM. It has to be mapped into KVM by
558          * cfs_page_map(); */
559         CFS_ALLOC_HIGH   = (1 << 5),
560         CFS_ALLOC_HIGHUSER = CFS_ALLOC_WAIT | CFS_ALLOC_FS | CFS_ALLOC_IO | CFS_ALLOC_HIGH,
561 };
562
563 /*
564  * portable UNIX device file identification. (This is not _very_
565  * portable. Probably makes no sense for Windows.)
566  */
567 /*
568  * Platform defines
569  *
570  * cfs_rdev_t
571  */
572
573 typedef unsigned int cfs_major_nr_t;
574 typedef unsigned int cfs_minor_nr_t;
575
576 /*
577  * Defined by platform.
578  */
579 cfs_rdev_t     cfs_rdev_build(cfs_major_nr_t major, cfs_minor_nr_t minor);
580 cfs_major_nr_t cfs_rdev_major(cfs_rdev_t rdev);
581 cfs_minor_nr_t cfs_rdev_minor(cfs_rdev_t rdev);
582
583 /*
584  * Generic on-wire rdev format.
585  */
586
587 typedef __u32 cfs_wire_rdev_t;
588
589 cfs_wire_rdev_t cfs_wire_rdev_build(cfs_major_nr_t major, cfs_minor_nr_t minor);
590 cfs_major_nr_t  cfs_wire_rdev_major(cfs_wire_rdev_t rdev);
591 cfs_minor_nr_t  cfs_wire_rdev_minor(cfs_wire_rdev_t rdev);
592
593 /*
594  * Drop into debugger, if possible. Implementation is provided by platform.
595  */
596
597 void cfs_enter_debugger(void);
598
599 /*
600  * Defined by platform
601  */
602 void cfs_daemonize(char *str);
603 int cfs_daemonize_ctxt(char *str);
604 cfs_sigset_t cfs_get_blocked_sigs(void);
605 cfs_sigset_t cfs_block_allsigs(void);
606 cfs_sigset_t cfs_block_sigs(cfs_sigset_t bits);
607 void cfs_restore_sigs(cfs_sigset_t);
608 int cfs_signal_pending(void);
609 void cfs_clear_sigpending(void);
610 /*
611  * XXX Liang:
612  * these macros should be removed in the future,
613  * we keep them just for keeping libcfs compatible
614  * with other branches.
615  */
616 #define libcfs_daemonize(s)     cfs_daemonize(s)
617 #define cfs_sigmask_lock(f)     do { f= 0; } while (0)
618 #define cfs_sigmask_unlock(f)   do { f= 0; } while (0)
619
620 int convert_server_error(__u64 ecode);
621 int convert_client_oflag(int cflag, int *result);
622
623 /*
624  * Stack-tracing filling.
625  */
626
627 /*
628  * Platform-dependent data-type to hold stack frames.
629  */
630 struct cfs_stack_trace;
631
632 /*
633  * Fill @trace with current back-trace.
634  */
635 void cfs_stack_trace_fill(struct cfs_stack_trace *trace);
636
637 /*
638  * Return instruction pointer for frame @frame_no. NULL if @frame_no is
639  * invalid.
640  */
641 void *cfs_stack_trace_frame(struct cfs_stack_trace *trace, int frame_no);
642
643 /*
644  * Universal open flags.
645  */
646 #define CFS_O_ACCMODE           0003
647 #define CFS_O_CREAT             0100
648 #define CFS_O_EXCL              0200
649 #define CFS_O_NOCTTY            0400
650 #define CFS_O_TRUNC             01000
651 #define CFS_O_APPEND            02000
652 #define CFS_O_NONBLOCK          04000
653 #define CFS_O_NDELAY            CFS_O_NONBLOCK
654 #define CFS_O_SYNC              010000
655 #define CFS_O_ASYNC             020000
656 #define CFS_O_DIRECT            040000
657 #define CFS_O_LARGEFILE         0100000
658 #define CFS_O_DIRECTORY         0200000
659 #define CFS_O_NOFOLLOW          0400000
660 #define CFS_O_NOATIME           01000000
661
662 /* convert local open flags to universal open flags */
663 int cfs_oflags2univ(int flags);
664 /* convert universal open flags to local open flags */
665 int cfs_univ2oflags(int flags);
666
667 #define _LIBCFS_H
668
669 #endif /* _LIBCFS_H */