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