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