⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libcfs.h

📁 非常经典的一个分布式系统
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: */#ifndef __LIBCFS_LIBCFS_H__#define __LIBCFS_LIBCFS_H__#if !__GNUC__#define __attribute__(x)#endif#if defined(__linux__)#include <libcfs/linux/libcfs.h>#elif defined(__APPLE__)#include <libcfs/darwin/libcfs.h>#elif defined(__WINNT__)#include <libcfs/winnt/libcfs.h>#else#error Unsupported operating system.#endif#include "curproc.h"#ifndef __KERNEL__#include <stdio.h>#endif/* Controlled via configure key *//* #define LIBCFS_DEBUG */#ifndef offsetof# define offsetof(typ,memb)     ((unsigned long)((char *)&(((typ *)0)->memb)))#endif/* cardinality of array */#define sizeof_array(a) ((sizeof (a)) / (sizeof ((a)[0])))#if !defined(container_of)/* given a pointer @ptr to the field @member embedded into type (usually * struct) @type, return pointer to the embedding instance of @type. */#define container_of(ptr, type, member) \        ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))#endif#define container_of0(ptr, type, member)                        \({                                                              \        typeof(ptr) __ptr = (ptr);                              \        type       *__res;                                      \                                                                \        if (unlikely(IS_ERR(__ptr) || __ptr == NULL))           \                __res = (type *)__ptr;                          \        else                                                    \                __res = container_of(__ptr, type, member);      \        __res;                                                  \})/* * true iff @i is power-of-2 */#define IS_PO2(i)                               \({                                              \        typeof(i) __i;                          \                                                \        __i = (i);                              \        !(__i & (__i - 1));                     \})#define LOWEST_BIT_SET(x)       ((x) & ~((x) - 1))/* *  Debugging */extern unsigned int libcfs_subsystem_debug;extern unsigned int libcfs_stack;extern unsigned int libcfs_debug;extern unsigned int libcfs_printk;extern unsigned int libcfs_console_ratelimit;extern cfs_duration_t libcfs_console_max_delay;extern cfs_duration_t libcfs_console_min_delay;extern unsigned int libcfs_console_backoff;extern unsigned int libcfs_debug_binary;extern char debug_file_path[1024];int libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys);int libcfs_debug_str2mask(int *mask, const char *str, int is_subsys);/* Has there been an LBUG? */extern unsigned int libcfs_catastrophe;extern unsigned int libcfs_panic_on_lbug;/* * struct ptldebug_header is defined in libcfs/<os>/libcfs.h */#define PH_FLAG_FIRST_RECORD 1/* Debugging subsystems (32 bits, non-overlapping) *//* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */#define S_UNDEFINED   0x00000001#define S_MDC         0x00000002#define S_MDS         0x00000004#define S_OSC         0x00000008#define S_OST         0x00000010#define S_CLASS       0x00000020#define S_LOG         0x00000040#define S_LLITE       0x00000080#define S_RPC         0x00000100#define S_MGMT        0x00000200#define S_LNET        0x00000400#define S_LND         0x00000800 /* ALL LNDs */#define S_PINGER      0x00001000#define S_FILTER      0x00002000/* unused */#define S_ECHO        0x00008000#define S_LDLM        0x00010000#define S_LOV         0x00020000/* unused *//* unused *//* unused *//* unused *//* unused */#define S_LMV         0x00800000 /* b_new_cmd *//* unused */#define S_SEC         0x02000000 /* upcall cache */#define S_GSS         0x04000000 /* b_new_cmd *//* unused */#define S_MGC         0x10000000#define S_MGS         0x20000000#define S_FID         0x40000000 /* b_new_cmd */#define S_FLD         0x80000000 /* b_new_cmd *//* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c *//* Debugging masks (32 bits, non-overlapping) *//* keep these in sync with lnet/utils/debug.c and lnet/libcfs/debug.c */#define D_TRACE       0x00000001 /* ENTRY/EXIT markers */#define D_INODE       0x00000002#define D_SUPER       0x00000004#define D_EXT2        0x00000008 /* anything from ext2_debug */#define D_MALLOC      0x00000010 /* print malloc, free information */#define D_CACHE       0x00000020 /* cache-related items */#define D_INFO        0x00000040 /* general information */#define D_IOCTL       0x00000080 /* ioctl related information */#define D_NETERROR    0x00000100 /* network errors */#define D_NET         0x00000200 /* network communications */#define D_WARNING     0x00000400 /* CWARN(...) == CDEBUG (D_WARNING, ...) */#define D_BUFFS       0x00000800#define D_OTHER       0x00001000#define D_DENTRY      0x00002000#define D_NETTRACE    0x00004000#define D_PAGE        0x00008000 /* bulk page handling */#define D_DLMTRACE    0x00010000#define D_ERROR       0x00020000 /* CERROR(...) == CDEBUG (D_ERROR, ...) */#define D_EMERG       0x00040000 /* CEMERG(...) == CDEBUG (D_EMERG, ...) */#define D_HA          0x00080000 /* recovery and failover */#define D_RPCTRACE    0x00100000 /* for distributed debugging */#define D_VFSTRACE    0x00200000#define D_READA       0x00400000 /* read-ahead */#define D_MMAP        0x00800000#define D_CONFIG      0x01000000#define D_CONSOLE     0x02000000#define D_QUOTA       0x04000000#define D_SEC         0x08000000/* keep these in sync with lnet/{utils,libcfs}/debug.c */#define D_CANTMASK   (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)#ifndef DEBUG_SUBSYSTEM# define DEBUG_SUBSYSTEM S_UNDEFINED#endif#define CDEBUG_DEFAULT_MAX_DELAY (cfs_time_seconds(600))         /* jiffies */#define CDEBUG_DEFAULT_MIN_DELAY ((cfs_time_seconds(1) + 1) / 2) /* jiffies */#define CDEBUG_DEFAULT_BACKOFF   2typedef struct {        cfs_time_t      cdls_next;        int             cdls_count;        cfs_duration_t  cdls_delay;} cfs_debug_limit_state_t;/* Controlled via configure key *//* #define CDEBUG_ENABLED */#if defined(__KERNEL__) || (defined(__arch_lib__) && !defined(LUSTRE_UTILS))#ifdef CDEBUG_ENABLED#define __CDEBUG(cdls, mask, format, 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__, __FUNCTION__, __LINE__,      \                                 format, ## a);                         \} while (0)#define CDEBUG(mask, format, a...) __CDEBUG(NULL, mask, format, ## a)#define CDEBUG_LIMIT(mask, format, a...)        \do {                                            \        static cfs_debug_limit_state_t cdls;    \                                                \        __CDEBUG(&cdls, mask, format, ## a);    \} while (0)#else /* CDEBUG_ENABLED */#define CDEBUG(mask, format, a...) (void)(0)#define CDEBUG_LIMIT(mask, format, a...) (void)(0)#warning "CDEBUG IS DISABLED. THIS SHOULD NEVER BE DONE FOR PRODUCTION!"#endif#else#define CDEBUG(mask, format, a...)                                      \do {                                                                    \        if (((mask) & D_CANTMASK) != 0)                                 \                fprintf(stderr, "(%s:%d:%s()) " format,                 \                        __FILE__, __LINE__, __FUNCTION__, ## a);        \} while (0)#define CDEBUG_LIMIT CDEBUG#endif /* !__KERNEL__ *//* * Lustre Error Checksum: calculates checksum * of Hex number by XORing each bit. */#define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \                           ((hexnum) >> 8 & 0xf))#define CWARN(format, a...)          CDEBUG_LIMIT(D_WARNING, format, ## a)#define CERROR(format, a...)         CDEBUG_LIMIT(D_ERROR, format, ## a)#define CEMERG(format, a...)         CDEBUG_LIMIT(D_EMERG, format, ## a)#define LCONSOLE(mask, format, a...) CDEBUG(D_CONSOLE | (mask), format, ## a)#define LCONSOLE_INFO(format, a...)  CDEBUG_LIMIT(D_CONSOLE, format, ## a)#define LCONSOLE_WARN(format, a...)  CDEBUG_LIMIT(D_CONSOLE | D_WARNING, format, ## a)#define LCONSOLE_ERROR_MSG(errnum, format, a...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, \                           "%x-%x: " format, errnum, LERRCHKSUM(errnum),  ## a)#define LCONSOLE_ERROR(format, a...) LCONSOLE_ERROR_MSG(0x00, format, ## a)#define LCONSOLE_EMERG(format, a...) CDEBUG(D_CONSOLE | D_EMERG, format, ## a)#ifdef CDEBUG_ENABLED#define GOTO(label, rc)                                                 \do {                                                                    \        long GOTO__ret = (long)(rc);                                    \        CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \               #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\               (signed long)GOTO__ret);                                 \        goto label;                                                     \} while (0)#else#define GOTO(label, rc) do { ((void)(rc)); goto label; } while (0)#endif/* Controlled via configure key *//* #define CDEBUG_ENTRY_EXIT */#ifdef CDEBUG_ENTRY_EXIT/* * if rc == NULL, we need to code as RETURN((void *)NULL), otherwise * there will be a warning in osx. */#define RETURN(rc)                                                      \do {                                                                    \        typeof(rc) RETURN__ret = (rc);                                  \        CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n",       \               (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\        EXIT_NESTING;                                                   \        return RETURN__ret;                                             \} while (0)#define ENTRY                                                           \ENTRY_NESTING;                                                          \do {                                                                    \        CDEBUG(D_TRACE, "Process entered\n");                           \} while (0)#define EXIT                                                            \do {                                                                    \        CDEBUG(D_TRACE, "Process leaving\n");                           \        EXIT_NESTING;                                                   \} while(0)#else /* !CDEBUG_ENTRY_EXIT */#define RETURN(rc) return (rc)#define ENTRY                           do { } while (0)#define EXIT                            do { } while (0)#endif /* !CDEBUG_ENTRY_EXIT *//* * Some (nomina odiosa sunt) platforms define NULL as naked 0. This confuses * Lustre RETURN(NULL) macro. */#if defined(NULL)#undef NULL#endif#define NULL ((void *)0)#define LUSTRE_SRV_LNET_PID      LUSTRE_LNET_PID#ifdef __KERNEL__#include <libcfs/list.h>struct libcfs_ioctl_data;                       /* forward ref */struct libcfs_ioctl_handler {        struct list_head item;        int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_data *data);};#define DECLARE_IOCTL_HANDLER(ident, func)                      \        struct libcfs_ioctl_handler ident = {                   \                /* .item = */ CFS_LIST_HEAD_INIT(ident.item),   \                /* .handle_ioctl = */ func                      \        }int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -