📄 libcfs.h
字号:
int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);/* libcfs tcpip */int libcfs_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask);int libcfs_ipif_enumerate(char ***names);void libcfs_ipif_free_enumeration(char **names, int n);int libcfs_sock_listen(cfs_socket_t **sockp, __u32 ip, int port, int backlog);int libcfs_sock_accept(cfs_socket_t **newsockp, cfs_socket_t *sock);void libcfs_sock_abort_accept(cfs_socket_t *sock);int libcfs_sock_connect(cfs_socket_t **sockp, int *fatal, __u32 local_ip, int local_port, __u32 peer_ip, int peer_port);int libcfs_sock_setbuf(cfs_socket_t *socket, int txbufsize, int rxbufsize);int libcfs_sock_getbuf(cfs_socket_t *socket, int *txbufsize, int *rxbufsize);int libcfs_sock_getaddr(cfs_socket_t *socket, int remote, __u32 *ip, int *port);int libcfs_sock_write(cfs_socket_t *sock, void *buffer, int nob, int timeout);int libcfs_sock_read(cfs_socket_t *sock, void *buffer, int nob, int timeout);void libcfs_sock_release(cfs_socket_t *sock);/* libcfs watchdogs */struct lc_watchdog;/* Add a watchdog which fires after "time" milliseconds of delay. You have to * touch it once to enable it. */struct lc_watchdog *lc_watchdog_add(int time, void (*cb)(pid_t pid, void *), void *data);/* Enables a watchdog and resets its timer. */void lc_watchdog_touch_ms(struct lc_watchdog *lcw, int timeout_ms);void lc_watchdog_touch(struct lc_watchdog *lcw);/* Disable a watchdog; touch it to restart it. */void lc_watchdog_disable(struct lc_watchdog *lcw);/* Clean up the watchdog */void lc_watchdog_delete(struct lc_watchdog *lcw);/* Dump a debug log */void lc_watchdog_dumplog(pid_t pid, void *data);/* __KERNEL__ */#endif/* need both kernel and user-land acceptor */#define LNET_ACCEPTOR_MIN_RESERVED_PORT 512#define LNET_ACCEPTOR_MAX_RESERVED_PORT 1023/* * libcfs pseudo device operations * * struct cfs_psdev_t and * cfs_psdev_register() and * cfs_psdev_deregister() are declared in * libcfs/<os>/cfs_prim.h * * It's just draft now. */struct cfs_psdev_file { unsigned long off; void *private_data; unsigned long reserved1; unsigned long reserved2;};struct cfs_psdev_ops { int (*p_open)(unsigned long, void *); int (*p_close)(unsigned long, void *); int (*p_read)(struct cfs_psdev_file *, char *, unsigned long); int (*p_write)(struct cfs_psdev_file *, char *, unsigned long); int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void *);};/* * generic time manipulation functions. */static inline int cfs_time_after(cfs_time_t t1, cfs_time_t t2){ return cfs_time_before(t2, t1);}static inline int cfs_time_aftereq(cfs_time_t t1, cfs_time_t t2){ return cfs_time_beforeq(t2, t1);}/* * return seconds since UNIX epoch */static inline time_t cfs_unix_seconds(void){ cfs_fs_time_t t; cfs_fs_time_current(&t); return (time_t)cfs_fs_time_sec(&t);}static inline cfs_time_t cfs_time_shift(int seconds){ return cfs_time_add(cfs_time_current(), cfs_time_seconds(seconds));}static inline long cfs_timeval_sub(struct timeval *large, struct timeval *small, struct timeval *result){ long r = (long) ( (large->tv_sec - small->tv_sec) * ONE_MILLION + (large->tv_usec - small->tv_usec)); if (result != NULL) { result->tv_usec = r % ONE_MILLION; result->tv_sec = r / ONE_MILLION; } return r;}#define CFS_RATELIMIT(seconds) \({ \ /* \ * XXX nikita: non-portable initializer \ */ \ static time_t __next_message = 0; \ int result; \ \ if (cfs_time_after(cfs_time_current(), __next_message)) \ result = 1; \ else { \ __next_message = cfs_time_shift(seconds); \ result = 0; \ } \ result; \})struct libcfs_debug_msg_data { cfs_debug_limit_state_t *msg_cdls; int msg_subsys; const char *msg_file; const char *msg_fn; int msg_line;};#define DEBUG_MSG_DATA_INIT(cdls, subsystem, file, func, ln ) { \ .msg_cdls = (cdls), \ .msg_subsys = (subsystem), \ .msg_file = (file), \ .msg_fn = (func), \ .msg_line = (ln) \ }extern int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls, int subsys, int mask, const char *file, const char *fn, const int line, const char *format1, va_list args, const char *format2, ...) __attribute__ ((format (printf, 9, 10)));#define libcfs_debug_vmsg(cdls, subsys, mask, file, fn, line, format, args) \ libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,format,args,NULL,NULL)#define libcfs_debug_msg(cdls, subsys, mask, file, fn, line, format, a...) \ libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,NULL,NULL,format, ##a)#define cdebug_va(cdls, mask, file, func, line, fmt, args) do { \ CHECK_STACK(); \ \ if (((mask) & D_CANTMASK) != 0 || \ ((libcfs_debug & (mask)) != 0 && \ (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) \ libcfs_debug_vmsg(cdls, DEBUG_SUBSYSTEM, (mask), \ (file), (func), (line), fmt, args); \} while(0);#define cdebug(cdls, mask, file, func, line, fmt, a...) do { \ CHECK_STACK(); \ \ if (((mask) & D_CANTMASK) != 0 || \ ((libcfs_debug & (mask)) != 0 && \ (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) \ libcfs_debug_msg(cdls, DEBUG_SUBSYSTEM, (mask), \ (file), (func), (line), fmt, ## a); \} while(0);extern void libcfs_assertion_failed(const char *expr, const char *file, const char *fn, const int line);static inline void cfs_slow_warning(cfs_time_t now, int seconds, char *msg){ if (cfs_time_after(cfs_time_current(), cfs_time_add(now, cfs_time_seconds(15)))) CERROR("slow %s %lu sec\n", msg, cfs_duration_sec(cfs_time_sub(cfs_time_current(),now)));}/* * helper function similar to do_gettimeofday() of Linux kernel */static inline void cfs_fs_timeval(struct timeval *tv){ cfs_fs_time_t time; cfs_fs_time_current(&time); cfs_fs_time_usec(&time, tv);}/* * return valid time-out based on user supplied one. Currently we only check * that time-out is not shorted than allowed. */static inline cfs_duration_t cfs_timeout_cap(cfs_duration_t timeout){ if (timeout < CFS_TICK) timeout = CFS_TICK; return timeout;}/* * Universal memory allocator API */enum cfs_alloc_flags { /* allocation is not allowed to block */ CFS_ALLOC_ATOMIC = 0x1, /* allocation is allowed to block */ CFS_ALLOC_WAIT = 0x2, /* allocation should return zeroed memory */ CFS_ALLOC_ZERO = 0x4, /* allocation is allowed to call file-system code to free/clean * memory */ CFS_ALLOC_FS = 0x8, /* allocation is allowed to do io to free/clean memory */ CFS_ALLOC_IO = 0x10, /* don't report allocation failure to the console */ CFS_ALLOC_NOWARN = 0x20, /* standard allocator flag combination */ CFS_ALLOC_STD = CFS_ALLOC_FS | CFS_ALLOC_IO, CFS_ALLOC_USER = CFS_ALLOC_WAIT | CFS_ALLOC_FS | CFS_ALLOC_IO,};/* flags for cfs_page_alloc() in addition to enum cfs_alloc_flags */enum cfs_alloc_page_flags { /* allow to return page beyond KVM. It has to be mapped into KVM by * cfs_page_map(); */ CFS_ALLOC_HIGH = 0x40, CFS_ALLOC_HIGHUSER = CFS_ALLOC_WAIT | CFS_ALLOC_FS | CFS_ALLOC_IO | CFS_ALLOC_HIGH,};/* * Drop into debugger, if possible. Implementation is provided by platform. */void cfs_enter_debugger(void);/* * Defined by platform */void cfs_daemonize(char *str);int cfs_daemonize_ctxt(char *str);cfs_sigset_t cfs_get_blocked_sigs(void);cfs_sigset_t cfs_block_allsigs(void);cfs_sigset_t cfs_block_sigs(cfs_sigset_t bits);void cfs_restore_sigs(cfs_sigset_t);int cfs_signal_pending(void);void cfs_clear_sigpending(void);/* * XXX Liang: * these macros should be removed in the future, * we keep them just for keeping libcfs compatible * with other branches. */#define libcfs_daemonize(s) cfs_daemonize(s)#define cfs_sigmask_lock(f) do { f= 0; } while (0)#define cfs_sigmask_unlock(f) do { f= 0; } while (0)int convert_server_error(__u64 ecode);int convert_client_oflag(int cflag, int *result);/* * Stack-tracing filling. *//* * Platform-dependent data-type to hold stack frames. */struct cfs_stack_trace;/* * Fill @trace with current back-trace. */void cfs_stack_trace_fill(struct cfs_stack_trace *trace);/* * Return instruction pointer for frame @frame_no. NULL if @frame_no is * invalid. */void *cfs_stack_trace_frame(struct cfs_stack_trace *trace, int frame_no);/* * Universal open flags. */#define CFS_O_ACCMODE 0003#define CFS_O_CREAT 0100#define CFS_O_EXCL 0200#define CFS_O_NOCTTY 0400#define CFS_O_TRUNC 01000#define CFS_O_APPEND 02000#define CFS_O_NONBLOCK 04000#define CFS_O_NDELAY CFS_O_NONBLOCK#define CFS_O_SYNC 010000#define CFS_O_ASYNC 020000#define CFS_O_DIRECT 040000#define CFS_O_LARGEFILE 0100000#define CFS_O_DIRECTORY 0200000#define CFS_O_NOFOLLOW 0400000#define CFS_O_NOATIME 01000000/* convert local open flags to universal open flags */int cfs_oflags2univ(int flags);/* convert universal open flags to local open flags */int cfs_univ2oflags(int flags);#define _LIBCFS_H#endif /* _LIBCFS_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -