Whamcloud - gitweb
b=b=6065
[fs/lustre-release.git] / lnet / include / libcfs / libcfs.h
index 3788b6d..f928fcf 100644 (file)
 
 #include "curproc.h"
 
+#ifndef __KERNEL__
+#include <stdio.h>
+#endif
+
 #define PORTAL_DEBUG
 
 #ifndef offsetof
@@ -66,6 +70,7 @@ extern unsigned int portal_printk;
 #define S_CONFOBD     0x00400000
 #define S_LMV         0x00800000
 #define S_CMOBD       0x01000000
+#define S_SEC         0x02000000
 /* If you change these values, please keep these files up to date...
  *    portals/utils/debug.c
  *    utils/lconf
@@ -97,6 +102,9 @@ extern unsigned int portal_printk;
 #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
 /* If you change these values, please keep these files up to date...
  *    portals/utils/debug.c
  *    utils/lconf
@@ -106,11 +114,12 @@ extern unsigned int portal_printk;
 # define DEBUG_SUBSYSTEM S_UNDEFINED
 #endif
 
+#ifdef __KERNEL__
 #if 1
 #define CDEBUG(mask, format, a...)                                            \
 do {                                                                          \
         CHECK_STACK(CDEBUG_STACK);                                            \
-        if (((mask) & (D_ERROR | D_EMERG | D_WARNING)) ||                     \
+        if (((mask) & (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)) ||         \
             (portal_debug & (mask) &&                                         \
              portal_subsystem_debug & DEBUG_SUBSYSTEM))                       \
                 portals_debug_msg(DEBUG_SUBSYSTEM, mask,                      \
@@ -156,10 +165,16 @@ do {                                                                          \
         }                                                                     \
 } while (0)
 
-#define CWARN(format, a...) CDEBUG_LIMIT(D_WARNING, format, ## a)
-#define CERROR(format, a...) CDEBUG_LIMIT(D_ERROR, format, ## a)
+#define CWARN(format, a...) CDEBUG(D_WARNING, format, ## a)
+#define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
 #define CEMERG(format, a...) CDEBUG(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(format, a...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, format, ## a)
+#define LCONSOLE_EMERG(format, a...) CDEBUG(D_CONSOLE | D_EMERG, format, ## a)
+
 #define GOTO(label, rc)                                                 \
 do {                                                                    \
         long GOTO__ret = (long)(rc);                                    \
@@ -197,28 +212,53 @@ do {                                                                    \
         CDEBUG(D_TRACE, "Process leaving\n");                           \
         EXIT_NESTING;                                                   \
 } while(0)
-#else
+#else /* !CDEBUG_ENTRY_EXIT */
 
 #define RETURN(rc) return (rc)
 #define ENTRY
 #define EXIT
 
-#endif
+#endif /* !CDEBUG_ENTRY_EXIT */
 
-#else
+#else /* !1 */
 #define CDEBUG(mask, format, a...)      do { } while (0)
 #define CWARN(format, a...)             printk(KERN_WARNING format, ## a)
 #define CERROR(format, a...)            printk(KERN_ERR format, ## a)
 #define CEMERG(format, a...)            printk(KERN_EMERG format, ## a)
+#define LCONSOLE(mask, format, a...)    printk(format, ## a)
+#define LCONSOLE_INFO(format, a...)     printk(KERN_INFO format, ## a)
+#define LCONSOLE_WARN(format, a...)     printk(KERN_WARNING format, ## a)
+#define LCONSOLE_ERROR(format, a...)    printk(KERN_ERROR format, ## a)
+#define LCONSOLE_EMERG(format, a...)    printk(KERN_EMERG format, ## a)
 #define GOTO(label, rc)                 do { (void)(rc); goto label; } while (0)
 #define RETURN(rc)                      return (rc)
 #define ENTRY                           do { } while (0)
 #define EXIT                            do { } while (0)
-#endif
+#endif /* !1 */
+#else /* !__KERNEL__ */
+#define CDEBUG(mask, format, a...)      do { } while (0)
+#define LCONSOLE(mask, format, a...)    fprintf(stderr, format, ## a)
+#define CWARN(format, a...)             fprintf(stderr, format, ## a)
+#define CERROR(format, a...)            fprintf(stderr, format, ## a)
+#define CEMERG(format, a...)            fprintf(stderr, format, ## a)
+#define LCONSOLE_INFO(format, a...)     fprintf(stderr, format, ## a)
+#define LCONSOLE_WARN(format, a...)     fprintf(stderr, format, ## a)
+#define LCONSOLE_ERROR(format, a...)    fprintf(stderr, format, ## a)
+#define LCONSOLE_EMERG(format, a...)    fprintf(stderr, format, ## a)
+#define GOTO(label, rc)                 do { (void)(rc); goto label; } while (0)
+#define RETURN(rc)                      return (rc)
+#define ENTRY                           do { } while (0)
+#define EXIT                            do { } while (0)
+#endif /* !__KERNEL__ */
 
 #define LUSTRE_SRV_PTL_PID      LUSTRE_PTL_PID
 
-#define PORTALS_CFG_VERSION 0x00010001;
+/*
+ * eeb cfg
+ * ecf6
+ * ecfG
+ */
+#define PORTALS_CFG_VERSION 0xecf60001
 
 struct portals_cfg {
         __u32 pcfg_version;
@@ -228,6 +268,8 @@ struct portals_cfg {
         __u32 pcfg_flags;
 
         __u32 pcfg_gw_nal;
+        __u32 pcfg_padding1;
+
         __u64 pcfg_nid;
         __u64 pcfg_nid2;
         __u64 pcfg_nid3;
@@ -239,19 +281,43 @@ struct portals_cfg {
         __u32 pcfg_wait;
 
         __u32 pcfg_plen1; /* buffers in userspace */
-        char *pcfg_pbuf1;
         __u32 pcfg_plen2; /* buffers in userspace */
-        char *pcfg_pbuf2;
+        __u32 pcfg_alloc_size;  /* size of this allocated portals_cfg */
+        char  pcfg_pbuf[0];
 };
 
 #define PCFG_INIT(pcfg, cmd)                            \
 do {                                                    \
-        memset(&pcfg, 0, sizeof(pcfg));                 \
-        pcfg.pcfg_version = PORTALS_CFG_VERSION;        \
-        pcfg.pcfg_command = (cmd);                      \
+        memset(&(pcfg), 0, sizeof((pcfg)));             \
+        (pcfg).pcfg_version = PORTALS_CFG_VERSION;      \
+        (pcfg).pcfg_command = (cmd);                    \
                                                         \
 } while (0)
 
+#define PCFG_INIT_PBUF(pcfg, cmd, plen1, plen2)                         \
+        do {                                                            \
+                int bufsize = size_round(sizeof(*(pcfg)));              \
+                bufsize += size_round(plen1) + size_round(plen2);       \
+                PORTAL_ALLOC((pcfg), bufsize);                          \
+                if ((pcfg)) {                                           \
+                        memset((pcfg), 0, bufsize);                     \
+                        (pcfg)->pcfg_version = PORTALS_CFG_VERSION;     \
+                        (pcfg)->pcfg_command = (cmd);                   \
+                        (pcfg)->pcfg_plen1 = (plen1);                   \
+                        (pcfg)->pcfg_plen2 = (plen2);                   \
+                        (pcfg)->pcfg_alloc_size = bufsize;              \
+                }                                                       \
+        } while (0)
+
+#define PCFG_FREE_PBUF(pcfg) PORTAL_FREE((pcfg), (pcfg)->pcfg_alloc_size)
+
+#define PCFG_PBUF(pcfg, idx)                                            \
+        (0 == (idx)                                                     \
+         ? ((char *)(pcfg) + size_round(sizeof(*(pcfg))))               \
+         : (1 == (idx)                                                  \
+            ? ((char *)(pcfg) + size_round(sizeof(*(pcfg))) + size_round(pcfg->pcfg_plen1)) \
+            : (NULL)))
+
 typedef int (nal_cmd_handler_fn)(struct portals_cfg *, void *);
 int libcfs_nal_cmd_register(int nal, nal_cmd_handler_fn *handler, void *arg);
 int libcfs_nal_cmd(struct portals_cfg *pcfg);
@@ -413,7 +479,6 @@ extern void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
                               char *format, ...)
             __attribute__ ((format (printf, 7, 8)));
 
-
 static inline void cfs_slow_warning(cfs_time_t now, int seconds, char *msg)
 {
         if (cfs_time_after(cfs_time_current(),