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