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