Whamcloud - gitweb
b=16150
authormattwu <mattwu>
Tue, 7 Oct 2008 04:14:14 +0000 (04:14 +0000)
committermattwu <mattwu>
Tue, 7 Oct 2008 04:14:14 +0000 (04:14 +0000)
i=adilger
i=robert
i=liang
winnt libcfs cleanup

65 files changed:
libcfs/include/libcfs/Makefile.am
libcfs/include/libcfs/darwin/darwin-types.h
libcfs/include/libcfs/darwin/kp30.h
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/libcfs_debug.h
libcfs/include/libcfs/libcfs_pack.h [new file with mode: 0644]
libcfs/include/libcfs/libcfs_prim.h
libcfs/include/libcfs/libcfs_private.h
libcfs/include/libcfs/libcfs_time.h
libcfs/include/libcfs/libcfs_unpack.h [new file with mode: 0644]
libcfs/include/libcfs/linux/kp30.h
libcfs/include/libcfs/linux/libcfs.h
libcfs/include/libcfs/linux/linux-lock.h
libcfs/include/libcfs/linux/linux-prim.h
libcfs/include/libcfs/linux/portals_compat25.h
libcfs/include/libcfs/list.h
libcfs/include/libcfs/posix/libcfs.h
libcfs/include/libcfs/posix/posix-types.h
libcfs/include/libcfs/posix/posix-wordsize.h
libcfs/include/libcfs/user-lock.h
libcfs/include/libcfs/user-prim.h
libcfs/include/libcfs/user-tcpip.h
libcfs/include/libcfs/user-time.h
libcfs/include/libcfs/util/platform.h
libcfs/include/libcfs/winnt/kp30.h
libcfs/include/libcfs/winnt/libcfs.h
libcfs/include/libcfs/winnt/portals_compat25.h
libcfs/include/libcfs/winnt/portals_utils.h
libcfs/include/libcfs/winnt/winnt-fs.h
libcfs/include/libcfs/winnt/winnt-lock.h
libcfs/include/libcfs/winnt/winnt-mem.h
libcfs/include/libcfs/winnt/winnt-prim.h
libcfs/include/libcfs/winnt/winnt-tcpip.h
libcfs/include/libcfs/winnt/winnt-time.h
libcfs/include/libcfs/winnt/winnt-types.h
libcfs/libcfs/darwin/darwin-tracefile.c
libcfs/libcfs/debug.c
libcfs/libcfs/linux/linux-tracefile.c
libcfs/libcfs/lwt.c
libcfs/libcfs/module.c
libcfs/libcfs/nidstrings.c
libcfs/libcfs/tracefile.c
libcfs/libcfs/tracefile.h
libcfs/libcfs/user-lock.c
libcfs/libcfs/user-mem.c
libcfs/libcfs/user-prim.c
libcfs/libcfs/user-tcpip.c
libcfs/libcfs/util/l_ioctl.c
libcfs/libcfs/util/parser.c
libcfs/libcfs/watchdog.c
libcfs/libcfs/winnt/winnt-curproc.c
libcfs/libcfs/winnt/winnt-debug.c
libcfs/libcfs/winnt/winnt-fs.c
libcfs/libcfs/winnt/winnt-lock.c
libcfs/libcfs/winnt/winnt-mem.c
libcfs/libcfs/winnt/winnt-module.c
libcfs/libcfs/winnt/winnt-native.c [new file with mode: 0644]
libcfs/libcfs/winnt/winnt-prim.c
libcfs/libcfs/winnt/winnt-proc.c
libcfs/libcfs/winnt/winnt-strusup.c [new file with mode: 0644]
libcfs/libcfs/winnt/winnt-sync.c
libcfs/libcfs/winnt/winnt-tcpip.c
libcfs/libcfs/winnt/winnt-tracefile.c
libcfs/libcfs/winnt/winnt-usr.c
libcfs/libcfs/winnt/winnt-utils.c

index dc2b841..c9f9478 100644 (file)
@@ -1,4 +1,3 @@
-
 SUBDIRS := linux posix util
 if DARWIN
 SUBDIRS += darwin
@@ -6,7 +5,8 @@ endif
 DIST_SUBDIRS := $(SUBDIRS)
 
 EXTRA_DIST := curproc.h libcfs_private.h libcfs.h list.h lltrace.h \
-       user-lock.h user-prim.h user-time.h \
-       user-tcpip.h user-bitops.h bitmap.h user-mem.h\
-       libcfs_prim.h libcfs_private.h libcfs_hash.h libcfs_time.h \
-       libcfs_debug.h libcfsutil.h libcfs_ioctl.h
+               user-lock.h user-prim.h user-time.h user-mem.h \
+               user-tcpip.h user-bitops.h bitmap.h \
+               libcfs_prim.h libcfs_time.h libcfs_hash.h \
+               libcfs_debug.h libcfsutil.h libcfs_ioctl.h \
+               libcfs_pack.h libcfs_unpack.h
index 1845ac2..ea9d985 100644 (file)
@@ -61,6 +61,10 @@ typedef int16_t         __s16;
 typedef int32_t         __s32;
 typedef int64_t         __s64;
 
+/* long integer with size equal to pointer */
+typedef unsigned long ulong_ptr_t;
+typedef long long_ptr_t;
+
 #ifdef __KERNEL__
 
 #include <kern/kern_types.h>
index f5e5619..1fc1a1d 100644 (file)
@@ -127,4 +127,16 @@ typedef struct {
 # define LL_POISON ((long)0x5a5a5a5a)
 # define LP_POISON ((void *)(long)0x5a5a5a5a)
 
+/*
+ * long_ptr_t & ulong_ptr_t, same to "long" for gcc
+ */
+# define LPLU "%lu"
+# define LPLD "%ld"
+# define LPLX "%#lx"
+
+/*
+ * pid_t
+ */
+# define LPPID "%d"
+
 #endif
index 5486e0c..08be620 100644 (file)
 #include "curproc.h"
 
 #ifndef offsetof
-# define offsetof(typ,memb)     ((unsigned long)((char *)&(((typ *)0)->memb)))
+# define offsetof(typ,memb) ((long)(long_ptr_t)((char *)&(((typ *)0)->memb)))
 #endif
 
-/* cardinality of array */
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(a) ((sizeof (a)) / (sizeof ((a)[0])))
 #endif
 /* 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)))
+        ((type *)((char *)(ptr)-(char *)(&((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;                                                  \
-})
+static inline int __is_po2(unsigned long long val)
+{
+        return !(val & (val - 1));
+}
 
-/*
- * true iff @i is power-of-2
- */
-#define IS_PO2(i)                               \
-({                                              \
-        typeof(i) __i;                          \
-                                                \
-        __i = (i);                              \
-        !(__i & (__i - 1));                     \
-})
+#define IS_PO2(val) __is_po2((unsigned long long)(val))
 
 #define LOWEST_BIT_SET(x)       ((x) & ~((x) - 1))
 
@@ -301,6 +284,18 @@ int cfs_univ2oflags(int flags);
 #include <libcfs/libcfs_prim.h>
 #include <libcfs/libcfs_time.h>
 
+/* container_of depends on "likely" which is defined in libcfs_private.h */
+static inline void *__container_of(void *ptr, unsigned long shift)
+{
+        if (unlikely(IS_ERR(ptr) || ptr == NULL))
+                return ptr;
+        else
+                return (char *)ptr - shift;
+}
+
+#define container_of0(ptr, type, member) \
+        ((type *)__container_of((void *)(ptr), offsetof(type, member)))
+
 #define _LIBCFS_H
 
 #endif /* _LIBCFS_H */
index 87037f0..379bc9c 100644 (file)
@@ -179,23 +179,23 @@ static inline int cdebug_show(unsigned int mask, unsigned int subsystem)
                 ((libcfs_debug & mask) && (libcfs_subsystem_debug & subsystem));
 }
 
-#define __CDEBUG(cdls, mask, format, a...)                              \
+#define __CDEBUG(cdls, mask, format, ...)                               \
 do {                                                                    \
         CHECK_STACK();                                                  \
                                                                         \
         if (cdebug_show(mask, DEBUG_SUBSYSTEM))                         \
                 libcfs_debug_msg(cdls, DEBUG_SUBSYSTEM, mask,           \
                                  __FILE__, __FUNCTION__, __LINE__,      \
-                                 format, ## a);                         \
+                                 format, ## __VA_ARGS__);               \
 } while (0)
 
-#define CDEBUG(mask, format, a...) __CDEBUG(NULL, mask, format, ## a)
+#define CDEBUG(mask, format, ...) __CDEBUG(NULL, mask, format, ## __VA_ARGS__)
 
-#define CDEBUG_LIMIT(mask, format, a...)        \
+#define CDEBUG_LIMIT(mask, format, ...)         \
 do {                                            \
         static cfs_debug_limit_state_t cdls;    \
                                                 \
-        __CDEBUG(&cdls, mask, format, ## a);    \
+        __CDEBUG(&cdls, mask, format, ## __VA_ARGS__);\
 } while (0)
 
 #else /* !CDEBUG_ENABLED */
@@ -203,18 +203,18 @@ static inline int cdebug_show(unsigned int mask, unsigned int subsystem)
 {
         return 0;
 }
-#define CDEBUG(mask, format, a...) (void)(0)
-#define CDEBUG_LIMIT(mask, format, a...) (void)(0)
+#define CDEBUG(mask, format, ...) (void)(0)
+#define CDEBUG_LIMIT(mask, format, ...) (void)(0)
 #warning "CDEBUG IS DISABLED. THIS SHOULD NEVER BE DONE FOR PRODUCTION!"
 #endif
 
 #else /* !__KERNEL__ && (!__arch_lib__ || LUSTRE_UTILS) */
 
-#define CDEBUG(mask, format, a...)                                      \
+#define CDEBUG(mask, format, ...)                                       \
 do {                                                                    \
         if (((mask) & D_CANTMASK) != 0)                                 \
                 fprintf(stderr, "(%s:%d:%s()) " format,                 \
-                        __FILE__, __LINE__, __FUNCTION__, ## a);        \
+                        __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__);\
 } while (0)
 
 #define CDEBUG_LIMIT CDEBUG
@@ -222,27 +222,27 @@ do {                                                                    \
 #endif /* !__KERNEL__ ... */
 
 
-#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 CWARN(format, ...)          CDEBUG_LIMIT(D_WARNING, format, ## __VA_ARGS__)
+#define CERROR(format, ...)         CDEBUG_LIMIT(D_ERROR, format, ## __VA_ARGS__)
+#define CEMERG(format, ...)         CDEBUG_LIMIT(D_EMERG, format, ## __VA_ARGS__)
 
-#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(mask, format, ...) CDEBUG(D_CONSOLE | (mask), format, ## __VA_ARGS__)
+#define LCONSOLE_INFO(format, ...)  CDEBUG_LIMIT(D_CONSOLE, format, ## __VA_ARGS__)
+#define LCONSOLE_WARN(format, ...)  CDEBUG_LIMIT(D_CONSOLE | D_WARNING, format, ## __VA_ARGS__)
+#define LCONSOLE_ERROR_MSG(errnum, format, ...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, \
+                           "%x-%x: " format, errnum, LERRCHKSUM(errnum), ## __VA_ARGS__)
+#define LCONSOLE_ERROR(format, ...) LCONSOLE_ERROR_MSG(0x00, format, ## __VA_ARGS__)
 
-#define LCONSOLE_EMERG(format, a...) CDEBUG(D_CONSOLE | D_EMERG, format, ## a)
+#define LCONSOLE_EMERG(format, ...) CDEBUG(D_CONSOLE | D_EMERG, format, ## __VA_ARGS__)
 
 #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);                                 \
+        long_ptr_t GOTO__ret = (long_ptr_t)(rc);                        \
+        CDEBUG(D_TRACE,"Process leaving via %s (rc=" LPLU " : " LPLD    \
+               " : " LPLX ")\n", #label, (ulong_ptr_t)GOTO__ret,        \
+               GOTO__ret, GOTO__ret);                                   \
         goto label;                                                     \
 } while (0)
 #else
@@ -255,6 +255,7 @@ do {                                                                    \
  * if rc == NULL, we need to code as RETURN((void *)NULL), otherwise
  * there will be a warning in osx.
  */
+#if defined(__GNUC__)
 #define RETURN(rc)                                                      \
 do {                                                                    \
         typeof(rc) RETURN__ret = (rc);                                  \
@@ -263,6 +264,16 @@ do {                                                                    \
         EXIT_NESTING;                                                   \
         return RETURN__ret;                                             \
 } while (0)
+#elif defined(_MSC_VER)
+#define RETURN(rc)                                                      \
+do {                                                                    \
+        CDEBUG(D_TRACE, "Process leaving.\n");                          \
+        EXIT_NESTING;                                                   \
+        return (rc);                                                    \
+} while (0)
+#else
+# error "Unkown compiler"
+#endif /* __GNUC__ */
 
 #define ENTRY                                                           \
 ENTRY_NESTING;                                                          \
@@ -293,11 +304,11 @@ struct libcfs_debug_msg_data {
 };
 
 #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)          \
+        /* msg_cdls */          (cdls),       \
+        /* msg_subsys */        (subsystem),  \
+        /* msg_file */          (file),       \
+        /* msg_fn */            (func),       \
+        /* msg_line */          (ln)          \
     }
 
 
@@ -311,8 +322,8 @@ extern int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls,
 #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 libcfs_debug_msg(cdls, subsys, mask, file, fn, line, format, ...)    \
+    libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,NULL,NULL,format, ## __VA_ARGS__)
 
 #define cdebug_va(cdls, mask, file, func, line, fmt, args)      do {          \
         CHECK_STACK();                                                        \
@@ -322,17 +333,26 @@ extern int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls,
                                   (file), (func), (line), fmt, args);         \
 } while(0);
 
-#define cdebug(cdls, mask, file, func, line, fmt, a...) do {                  \
+#define cdebug(cdls, mask, file, func, line, fmt, ...) do {                   \
         CHECK_STACK();                                                        \
                                                                               \
         if (cdebug_show(mask, DEBUG_SUBSYSTEM))                               \
                 libcfs_debug_msg(cdls, DEBUG_SUBSYSTEM, (mask),               \
-                                 (file), (func), (line), fmt, ## a);          \
+                                 (file), (func), (line), fmt, ## __VA_ARGS__);\
 } while(0);
 
 extern void libcfs_assertion_failed(const char *expr, const char *file,
                                     const char *fn, const int line);
 
 
+#if defined(HAVE_BGL_SUPPORT)
+#define DEBUG_FILE_PATH_DEFAULT "/bgl/ion/tmp/lustre-log"
+#elif defined(__arch_um__)
+#define DEBUG_FILE_PATH_DEFAULT "/r/tmp/lustre-log"
+#elif defined(__WINNT__)
+#define DEBUG_FILE_PATH_DEFAULT "\\SystemRoot\\temp\\lustre-log"
+#else
+#define DEBUG_FILE_PATH_DEFAULT "/tmp/lustre-log"
+#endif
 
 #endif /* __LIBCFS_DEBUG_H__ */
diff --git a/libcfs/include/libcfs/libcfs_pack.h b/libcfs/include/libcfs/libcfs_pack.h
new file mode 100644 (file)
index 0000000..74ba33c
--- /dev/null
@@ -0,0 +1,5 @@
+#if !defined(__GNUC__) && defined(_MSC_VER) 
+#pragma warning(disable:4103)
+#pragma pack(push, 1)
+#endif
+
index 3885bb7..64938a5 100644 (file)
@@ -69,7 +69,7 @@ int64_t cfs_waitq_timedwait(cfs_waitlink_t *link, cfs_task_state_t state,
 /*
  * Timer
  */
-typedef  void (cfs_timer_func_t)(unsigned long);
+typedef  void (cfs_timer_func_t)(ulong_ptr_t);
 
 void cfs_init_timer(cfs_timer_t *t);
 void cfs_timer_init(cfs_timer_t *t, cfs_timer_func_t *func, void *arg);
index dd04602..9e3fe71 100644 (file)
  *
  * requires -Wall. Unfortunately this rules out use of likely/unlikely.
  */
-#define LASSERT(cond)                                           \
-({                                                              \
-        if (cond)                                               \
-                ;                                               \
-        else                                                    \
-                libcfs_assertion_failed( #cond , __FILE__,      \
-                        __FUNCTION__, __LINE__);                \
-})
-
-#define LASSERTF(cond, fmt, a...)                                       \
-({                                                                      \
+#define LASSERT(cond)                                                   \
+do {                                                                    \
+        if (cond)                                                       \
+                ;                                                       \
+        else                                                            \
+                libcfs_assertion_failed( #cond , __FILE__,              \
+                        __FUNCTION__, __LINE__);                        \
+} while(0)
+
+#define LASSERTF(cond, fmt, ...)                                        \
+do {                                                                    \
          if (cond)                                                      \
                  ;                                                      \
          else {                                                         \
                  libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG,       \
                                   __FILE__, __FUNCTION__,__LINE__,      \
                                   "ASSERTION(" #cond ") failed: " fmt,  \
-                                  ## a);                                \
+                                  ## __VA_ARGS__);                      \
                  LBUG();                                                \
          }                                                              \
-})
-
+} while(0)
 
 #else /* !LASSERT_CHECKED */
 
-#define LASSERT(cond)                                           \
-({                                                              \
-        if (unlikely(!(cond)))                                  \
-                libcfs_assertion_failed(#cond , __FILE__,       \
-                        __FUNCTION__, __LINE__);                \
-})
+#define LASSERT(cond)                                                   \
+do {                                                                    \
+        if (unlikely(!(cond)))                                          \
+                libcfs_assertion_failed(#cond , __FILE__,               \
+                        __FUNCTION__, __LINE__);                        \
+} while(0)
 
-#define LASSERTF(cond, fmt, a...)                                       \
-({                                                                      \
+#define LASSERTF(cond, fmt, ...)                                        \
+do {                                                                    \
         if (unlikely(!(cond))) {                                        \
                 libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG,        \
                                  __FILE__, __FUNCTION__,__LINE__,       \
                                  "ASSERTION(" #cond ") failed: " fmt,   \
-                                 ## a);                                 \
+                                 ## __VA_ARGS__ );                      \
                 LBUG();                                                 \
         }                                                               \
-})
-
+} while(0)
 
 #endif /* !LASSERT_CHECKED */
 #else /* !LIBCFS_DEBUG */
 /* sizeof is to use expression without evaluating it. */
 # define LASSERT(e) ((void)sizeof!!(e))
-# define LASSERTF(cond, fmt...) ((void)sizeof!!(cond))
+# define LASSERTF(cond, ...) ((void)sizeof!!(cond))
 #endif /* !LIBCFS_DEBUG */
 
 #ifdef INVARIANT_CHECK
@@ -237,10 +235,10 @@ void libcfs_debug_set_level(unsigned int debug_level);
 #  undef NDEBUG
 #  include <assert.h>
 #  define LASSERT(e)     assert(e)
-#  define LASSERTF(cond, args...)                                              \
+#  define LASSERTF(cond, ...)                                                  \
 do {                                                                           \
           if (!(cond))                                                         \
-                CERROR(args);                                                  \
+                CERROR(__VA_ARGS__);                                           \
           assert(cond);                                                        \
 } while (0)
 #  define LBUG()   assert(0)
@@ -251,12 +249,12 @@ do {                                                                           \
 #  endif
 # else
 #  define LASSERT(e) ((void)sizeof!!(e))
-#  define LASSERTF(cond, args...) ((void)sizeof!!(cond))
+#  define LASSERTF(cond, ...) ((void)sizeof!!(cond))
 #  define LBUG()   ((void)(0))
 #  define LINVRNT(exp) ((void)sizeof!!(exp))
 # endif /* LIBCFS_DEBUG */
 # define KLASSERT(e) ((void)0)
-# define printk(format, args...) printf (format, ## args)
+# define printk printf
 # ifdef CRAY_XT3                                /* buggy calloc! */
 #  define LIBCFS_ALLOC(ptr, size)               \
    do {                                         \
@@ -277,10 +275,13 @@ int libcfs_debug_cleanup(void);
  * build go below this comment. Actual compiler/compiler version
  * specific implementations come from the above header files
  */
-
+#ifdef __GNUC__
 #define likely(x)      __builtin_expect(!!(x), 1)
 #define unlikely(x)    __builtin_expect(!!(x), 0)
-
+#else
+#define likely(x)      (!!(x))
+#define unlikely(x)    (!!(x))
+#endif
 /* !__KERNEL__ */
 #endif
 
@@ -298,7 +299,7 @@ int libcfs_debug_cleanup(void);
  *       value  after  conversion...
  *
  */
-#define CLASSERT(cond) ({ switch(42) { case (cond): case 0: break; } })
+#define CLASSERT(cond) do {switch(42) {case (cond): case 0: break;}} while (0)
 
 /* support decl needed both by kernel and liblustre */
 int         libcfs_isknown_lnd(int type);
index 94d6862..946c2be 100644 (file)
 
 static inline cfs_time_t cfs_time_add(cfs_time_t t, cfs_duration_t d)
 {
-        return t + d;
+        return (cfs_time_t)(t + d);
 }
 
 static inline cfs_duration_t cfs_time_sub(cfs_time_t t1, cfs_time_t t2)
 {
-        return t1 - t2;
+        return (cfs_time_t)(t1 - t2);
 }
 
 static inline int cfs_time_before(cfs_time_t t1, cfs_time_t t2)
diff --git a/libcfs/include/libcfs/libcfs_unpack.h b/libcfs/include/libcfs/libcfs_unpack.h
new file mode 100644 (file)
index 0000000..7ea2205
--- /dev/null
@@ -0,0 +1,4 @@
+#if !defined(__GNUC__) && defined(_MSC_VER) 
+#pragma warning(disable:4103)
+#pragma pack(pop)
+#endif
index 378bfc7..02a45e1 100644 (file)
@@ -354,6 +354,18 @@ extern int  lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
 # define LPF64 "l"
 #endif
 
+/*
+ * long_ptr_t & ulong_ptr_t, same to "long" for gcc
+ */
+# define LPLU "%lu"
+# define LPLD "%ld"
+# define LPLX "%#lx"
+
+/*
+ * pid_t
+ */
+# define LPPID "%d"
+
 #ifdef HAVE_SIZE_T_LONG
 # define LPSZ  "%lu"
 #else
index f2b7744..6f0a9e8 100644 (file)
@@ -117,6 +117,10 @@ typedef kernel_cap_t cfs_kernel_cap_t;
 struct cfs_stack_trace {
 };
 
+/* long integer with size equal to pointer */
+typedef unsigned long ulong_ptr_t;
+typedef long long_ptr_t;
+
 #ifndef WITH_WATCHDOG
 #define WITH_WATCHDOG
 #endif
index f294428..f1c442f 100644 (file)
@@ -82,6 +82,7 @@
  * - down_write(x)
  * - up_write(x)
  */
+#define fini_rwsem(s) do {} while(0)
 
 /*
  * rwlock_t (use Linux kernel's primitives)
index 20f3674..3414c9c 100644 (file)
@@ -53,6 +53,7 @@
 #include <linux/config.h>
 #endif
 #include <linux/module.h>
+#include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/version.h>
 #include <linux/proc_fs.h>
@@ -204,15 +205,15 @@ do {                                                             \
    retval == 0; condition met; we're good.
    retval > 0; timed out.
 */
-#define cfs_waitq_wait_event_timeout(wq, condition, timeout)         \
-({                                                                   \
-       int __ret = 0;                                               \
+#define cfs_waitq_wait_event_timeout(wq, condition, timeout, ret)    \
+do {                                                                 \
+       ret = 0;                                                     \
        if (!(condition))                                            \
-               __wait_event_timeout(wq, condition, timeout, __ret); \
-       __ret;                                                       \
-})
+               __wait_event_timeout(wq, condition, timeout, ret);   \
+} while (0)
 #else
-#define cfs_waitq_wait_event_timeout  wait_event_timeout
+#define cfs_waitq_wait_event_timeout(wq, condition, timeout, ret)    \
+        ret = wait_event_timeout(wq, condition, timeout)
 #endif
 
 #ifndef wait_event_interruptible_timeout /* Only for RHEL3 2.4.21 kernel */
@@ -251,16 +252,16 @@ do {                                                           \
    retval < 0; interrupted by signal.
    retval > 0; timed out.
 */
-#define cfs_waitq_wait_event_interruptible_timeout(wq, condition, timeout\
-({                                                                \
-       int __ret = 0;                                            \
+#define cfs_waitq_wait_event_interruptible_timeout(wq, condition, timeout, ret)\
+do {                                                              \
+       ret = 0;                                                  \
        if (!(condition))                                         \
                __wait_event_interruptible_timeout(wq, condition, \
-                                               timeout, __ret);  \
-       __ret;                                                    \
-})
+                                               timeout, ret);     \
+} while (0)
 #else
-#define cfs_waitq_wait_event_interruptible_timeout wait_event_interruptible_timeout
+#define cfs_waitq_wait_event_interruptible_timeout(wq, c, timeout, ret) \
+        ret = wait_event_interruptible_timeout(wq, c, timeout)
 #endif
 
 #endif
index 492fd00..38906e9 100644 (file)
 
 #endif
 
+# define cfs_wait_event_interruptible(wq, condition, ret)               \
+         ret = wait_event_interruptible(wq, condition)
+# define cfs_wait_event_interruptible_exclusive(wq, condition, ret)     \
+         ret = wait_event_interruptible(wq, condition)
+
 #if defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20))
 #define UML_PID(tsk) ((tsk)->thread.extern_pid)
 #elif defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
index ed03bd5..548bdf5 100644 (file)
  * using the generic single-entry routines.
  */
 
-#ifndef __WINNT__
 #define prefetch(a) ((void)a)
-#else
-#define prefetch(a) ((void *)a)
-#endif
 
 struct list_head {
        struct list_head *next, *prev;
@@ -208,7 +204,7 @@ static inline void list_splice_init(struct list_head *list,
  * @member:    the name of the list_struct within the struct.
  */
 #define list_entry(ptr, type, member) \
-       ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+       ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
 
 /**
  * list_for_each       -       iterate over a list
@@ -253,8 +249,8 @@ struct hlist_node {
 #define NULL_P ((void *)0)
 #endif
 
-#define CFS_HLIST_HEAD_INIT { .first = NULL_P }
-#define CFS_HLIST_HEAD(name) struct hlist_head name = {  .first = NULL_P }
+#define CFS_HLIST_HEAD_INIT { NULL_P }
+#define CFS_HLIST_HEAD(name) struct hlist_head name = { NULL_P }
 #define CFS_INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL_P)
 #define CFS_INIT_HLIST_NODE(ptr) ((ptr)->next = NULL_P, (ptr)->pprev = NULL_P)
 
@@ -329,11 +325,11 @@ static inline void hlist_add_after(struct hlist_node *n,
 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
 
 #define hlist_for_each(pos, head) \
-       for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
+       for (pos = (head)->first; pos && (prefetch(pos->next), 1); \
             pos = pos->next)
 
 #define hlist_for_each_safe(pos, n, head) \
-       for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
+       for (pos = (head)->first; pos && (n = pos->next, 1); \
             pos = n)
 
 /**
@@ -395,7 +391,7 @@ static inline void hlist_add_after(struct hlist_node *n,
  * @head:      the head for your list.
  */
 #define list_for_each_prev(pos, head) \
-       for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
+       for (pos = (head)->prev, prefetch(pos->prev); pos != (head);     \
                pos = pos->prev, prefetch(pos->prev))
 
 #endif /* list_for_each_prev */
@@ -441,6 +437,7 @@ static inline void hlist_add_after(struct hlist_node *n,
                n = list_entry(pos->member.next, typeof(*pos), member); \
             &pos->member != (head);                                    \
             pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
 #endif /* list_for_each_entry_safe */
 
 #ifndef list_for_each_entry_safe_from
@@ -454,10 +451,44 @@ static inline void hlist_add_after(struct hlist_node *n,
  * Iterate over list of given type from current point, safe against
  * removal of list entry.
  */
-#define list_for_each_entry_safe_from(pos, n, head, member)                 \
-        for (n = list_entry(pos->member.next, typeof(*pos), member);        \
-             &pos->member != (head);                                        \
+#define list_for_each_entry_safe_from(pos, n, head, member)             \
+        for (n = list_entry(pos->member.next, typeof(*pos), member);    \
+             &pos->member != (head);                                    \
              pos = n, n = list_entry(n->member.next, typeof(*n), member))
 #endif /* list_for_each_entry_safe_from */
 
+#define cfs_list_for_each_entry_typed(pos, head, type, member)         \
+        for (pos = list_entry((head)->next, type, member),             \
+                    prefetch(pos->member.next);                        \
+            &pos->member != (head);                                    \
+            pos = list_entry(pos->member.next, type, member),          \
+            prefetch(pos->member.next))
+
+#define cfs_list_for_each_entry_reverse_typed(pos, head, type, member) \
+       for (pos = list_entry((head)->prev, type, member);              \
+            prefetch(pos->member.prev), &pos->member != (head);        \
+            pos = list_entry(pos->member.prev, type, member))
+
+#define cfs_list_for_each_entry_safe_typed(pos, n, head, type, member) \
+    for (pos = list_entry((head)->next, type, member),                 \
+               n = list_entry(pos->member.next, type, member);         \
+            &pos->member != (head);                                    \
+            pos = n, n = list_entry(n->member.next, type, member))
+
+#define cfs_list_for_each_entry_safe_from_typed(pos, n, head, type, member)   \
+        for (n = list_entry(pos->member.next, type, member);            \
+             &pos->member != (head);                                    \
+             pos = n, n = list_entry(n->member.next, type, member))
+#define cfs_hlist_for_each_entry_typed(tpos, pos, head, type, member)   \
+       for (pos = (head)->first;                                       \
+            pos && (prefetch(pos->next), 1) &&                         \
+               (tpos = hlist_entry(pos, type, member), 1);             \
+            pos = pos->next)
+
+#define cfs_hlist_for_each_entry_safe_typed(tpos, pos, n, head, type, member)\
+       for (pos = (head)->first;                                       \
+            pos && (n = pos->next, 1) &&                               \
+               (tpos = hlist_entry(pos, type, member), 1);             \
+            pos = n)
+
 #endif /* __LIBCFS_LUSTRE_LIST_H__ */
index b50554f..95035d2 100644 (file)
@@ -43,6 +43,7 @@
 #ifndef __LIBCFS_POSIX_LIBCFS_H__
 #define __LIBCFS_POSIX_LIBCFS_H__
 
+#include <errno.h>
 #include <sys/errno.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <assert.h>
+#include <sys/ioctl.h>
 #include <sys/signal.h>
 #include <signal.h>
 #include <sys/time.h>
 #include <time.h>
+#include <getopt.h>
+#include <signal.h>
+#include <pwd.h>
+#include <sys/socket.h>
+#include <sys/utsname.h>
+#include <ctype.h>
+
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 #ifdef HAVE_LIBPTHREAD
 #include <pthread.h>
@@ -331,7 +346,8 @@ static inline struct radix_tree_node *radix_tree_lookup0(struct radix_tree_root
         if (list_empty(&root->list))
                 return NULL;
 
-        list_for_each_entry(node, &root->list, _node)
+        cfs_list_for_each_entry_typed(node, &root->list,
+                                      struct radix_tree_node, _node)
                 if (node->index == idx)
                         return node;
 
index 19ef126..392e70e 100644 (file)
@@ -61,4 +61,8 @@ typedef unsigned int __u32;
 typedef __signed__ long long __s64;
 typedef unsigned long long __u64;
 
+/* long integer with size equal to pointer */
+typedef unsigned long ulong_ptr_t;
+typedef long long_ptr_t;
+
 #endif
index 87eb165..62bd289 100644 (file)
@@ -146,4 +146,16 @@ typedef struct {
 # error "No word size defined"
 #endif
 
+/*
+ * long_ptr_t & ulong_ptr_t, same to "long" for gcc
+ */
+# define LPLU "%lu"
+# define LPLD "%ld"
+# define LPLX "%#lx"
+
+/*
+ * pid_t
+ */
+# define LPPID "%d"
+
 #endif
index 2a38463..01c289b 100644 (file)
@@ -149,6 +149,7 @@ struct completion {
 typedef int (*cfs_wait_handler_t) (int timeout);
 void set_completion_wait_handler(cfs_wait_handler_t *handler);
 void init_completion(struct completion *c);
+void init_completion_module(cfs_wait_handler_t handler);
 void complete(struct completion *c);
 void wait_for_completion(struct completion *c);
 int wait_for_completion_interruptible(struct completion *c);
@@ -182,6 +183,7 @@ void down_write(struct rw_semaphore *s);
 int down_write_trylock(struct rw_semaphore *s);
 void up_read(struct rw_semaphore *s);
 void up_write(struct rw_semaphore *s);
+void fini_rwsem(struct rw_semaphore *s);
 
 /*
  * read-write lock : Need to be investigated more!!
@@ -348,7 +350,7 @@ static inline int mutex_is_locked(struct mutex *lock)
  **************************************************************************/
 
 struct lock_class_key {
-        ;
+        int foo;
 };
 
 static inline void lockdep_set_class(void *lock, struct lock_class_key *key)
index e723182..967cf07 100644 (file)
@@ -112,12 +112,11 @@ typedef sigset_t                        cfs_sigset_t;
 /*
  * Timer
  */
-#include <sys/time.h>
 
 typedef struct {
         struct list_head tl_list;
-        void (*function)(unsigned long unused);
-        unsigned long data;
+        void (*function)(ulong_ptr_t unused);
+        ulong_ptr_t data;
         long expires;
 } cfs_timer_t;
 
@@ -169,6 +168,7 @@ struct cfs_stack_trace {
 /*
  * arithmetic
  */
+#ifndef do_div /* gcc only, platform-specific will override */
 #define do_div(a,b)                     \
         ({                              \
                 unsigned long remainder;\
@@ -176,6 +176,34 @@ struct cfs_stack_trace {
                 (a) = (a) / (b);        \
                 (remainder);            \
         })
+#endif
+
+/* utility libcfs init/fini entries */
+#ifdef __WINNT__
+extern int libcfs_arch_init(void);
+extern void libcfs_arch_cleanup(void);
+#else /* !__WINNT__ */
+static inline int libcfs_arch_init(void) {
+        return 0;
+}
+static inline void libcfs_arch_cleanup(void) {
+}
+/* __WINNT__ */
+#endif
+
+/* proc interface wrappers for non-win OS */
+#ifndef __WINNT__
+#define cfs_proc_open   open
+#define cfs_proc_mknod  mknod
+#define cfs_proc_ioctl  ioctl
+#define cfs_proc_close  close
+#define cfs_proc_read   read
+#define cfs_proc_write  write
+#define cfs_proc_fopen  fopen
+#define cfs_proc_fclose fclose
+#define cfs_proc_fgets  fgets
+/* !__WINNT__ */
+#endif
 
 /* !__KERNEL__ */
 #endif
index 94a75d6..fe0464d 100644 (file)
@@ -73,6 +73,7 @@ int libcfs_fcntl_nonblock(int fd);
 int libcfs_sock_set_nagle(int fd, int nagle);
 int libcfs_sock_set_bufsiz(int fd, int bufsiz);
 int libcfs_sock_create(int *fdp);
+void libcfs_sock_release(int fd);
 int libcfs_sock_bind_to_port(int fd, __u16 port);
 int libcfs_sock_connect(int fd, __u32 ip, __u16 port);
 int libcfs_sock_writev(int fd, const struct iovec *vector, int count);
index 60e466a..5a5cc3e 100644 (file)
@@ -97,7 +97,7 @@
 
 typedef time_t cfs_fs_time_t;
 typedef time_t cfs_time_t;
-typedef long cfs_duration_t;
+typedef time_t cfs_duration_t;
 
 /* looks like linux */
 #define time_after(a, b) ((long)(b) - (long)(a) < 0)
@@ -110,7 +110,7 @@ static inline cfs_time_t cfs_time_current(void)
         return time(NULL);
 }
 
-static inline cfs_duration_t cfs_time_seconds(int seconds)
+static inline cfs_duration_t cfs_time_seconds(cfs_time_t seconds)
 {
         return seconds;
 }
index 43319af..137dabe 100644 (file)
@@ -249,8 +249,10 @@ static inline void l_cond_broadcast(l_cond_t *cond)
 #include <errno.h>
 #include <string.h>
 #if HAVE_LIBPTHREAD
+#ifndef __WINNT__
 #include <sys/ipc.h>
 #include <sys/shm.h>
+#endif
 #include <pthread.h>
 
 typedef pthread_mutex_t        l_mutex_t;
index 49adea2..940bf48 100644 (file)
@@ -37,9 +37,6 @@
 #ifndef __LIBCFS_WINNT_KP30_H__
 #define __LIBCFS_WINNT_KP30_H__
 
-#include <libcfs/winnt/portals_compat25.h>
-#include <lnet/types.h>
-
 #ifdef __KERNEL__
 
 /* Module parameter support */
 
 #define CFS_SYSFS_MODULE_PARM    0 /* no sysfs access to module parameters */
 
+#define cond_resched our_cond_resched
+void our_cond_resched();
 
-static inline void our_cond_resched()
-{
-    schedule_timeout(1i64);
-}
-
-#ifdef CONFIG_SMP
-#define LASSERT_SPIN_LOCKED(lock) do {} while(0) /* XXX */
-#else
 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
-#endif
+#define LASSERT_SEM_LOCKED(sem) LASSERT(down_trylock(sem) != 0)
+
+/* winnt panic */
+void libcfs_panic(char *msg);
+#define LIBCFS_PANIC(msg) libcfs_panic(msg)
+void libcfs_register_panic_notifier();
+void libcfs_unregister_panic_notifier();
 
-#error Need a winnt version of panic()
-#define LIBCFS_PANIC(msg) KeBugCheckEx(msg, (ULONG_PTR)NULL, (ULONG_PTR)NULL, (ULONG_PTR)NULL, (ULONG_PTR)NULL)
-#error libcfs_register_panic_notifier() missing
-#error libcfs_unregister_panic_notifier() missing
 
 #define cfs_work_struct_t WORK_QUEUE_ITEM
 #define cfs_prepare_work(tq, routine, contex)
@@ -82,6 +75,10 @@ static inline void our_cond_resched()
 
 #define printk                                  DbgPrint
 #define ptintf                                  DbgPrint
+#define printk_ratelimit()                      (FALSE)
+#define vprintk(f, a)                           vDbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, f, a)
+                                                /* vDbgPrintEx only available on xp and later OS */
+#define cfs_assert                              ASSERT
 
 #else  /* !__KERNEL__ */
 
@@ -91,6 +88,9 @@ static inline void our_cond_resched()
 # include <cygwin-ioctl.h>
 #endif
 # include <time.h>
+#include <crtdbg.h>
+
+#define cfs_assert     _ASSERT
 
 #endif /* End of !__KERNEL__ */
 
@@ -104,12 +104,12 @@ typedef struct {
         __s64      lwte_when;
         char       *lwte_where;
         void       *lwte_task;
-        long_ptr        lwte_p1;
-        long_ptr        lwte_p2;
-        long_ptr        lwte_p3;
-        long_ptr        lwte_p4;
+        long_ptr_t        lwte_p1;
+        long_ptr_t        lwte_p2;
+        long_ptr_t        lwte_p3;
+        long_ptr_t        lwte_p4;
 # if BITS_PER_LONG > 32
-        long_ptr        lwte_pad;
+        long_ptr_t        lwte_pad;
 # endif
 } lwt_event_t;
 
@@ -119,7 +119,7 @@ typedef struct {
 
 /* ------------------------------------------------------------------ */
 
-#define IOCTL_LIBCFS_TYPE long_ptr
+#define IOCTL_LIBCFS_TYPE long_ptr_t
 
 #ifdef __CYGWIN__
 # ifndef BITS_PER_LONG
@@ -133,35 +133,34 @@ typedef struct {
 
 #if BITS_PER_LONG > 32
 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
-# define LL_POISON ((long_ptr)0x5a5a5a5a5a5a5a5a)
-# define LP_POISON ((char *)(long_ptr)0x5a5a5a5a5a5a5a5a)
+# define LL_POISON ((long_ptr_t)0x5a5a5a5a5a5a5a5a)
+# define LP_POISON ((char *)(long_ptr_t)0x5a5a5a5a5a5a5a5a)
 #else
 # define LI_POISON ((int)0x5a5a5a5a)
-# define LL_POISON ((long_ptr)0x5a5a5a5a)
-# define LP_POISON ((char *)(long_ptr)0x5a5a5a5a)
+# define LL_POISON ((long_ptr_t)0x5a5a5a5a)
+# define LP_POISON ((char *)(long_ptr_t)0x5a5a5a5a)
 #endif
 
-#if defined(__x86_64__)
-# define LPU64 "%I64u"
-# define LPD64 "%I64d"
-# define LPX64 "%I64x"
-# define LPSZ  "%lu"
-# define LPSSZ "%ld"
-#elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
-# define LPU64 "%I64u"
-# define LPD64 "%I64d"
-# define LPX64 "%I64x"
-# define LPSZ  "%u"
-# define LPSSZ "%d"
-#elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
-# define LPU64 "%I64u"
-# define LPD64 "%I64d"
-# define LPX64 "%I64x"
-# define LPSZ  "%u"
-# define LPSSZ "%d"
-#endif
-#ifndef LPU64
-# error "No word size defined"
+#define LPF64 "%I64d"
+#define LPU64 "%I64u"
+#define LPD64 "%I64d"
+#define LPX64 "%#I64x"
+#define LPSZ  "%lu"
+#define LPSSZ "%ld"
+
+/*
+ * long_ptr_t & ulong_ptr_t, same to "long" for linux
+ */
+#if _x86_
+# define LPLU "%u"
+# define LPLD "%d"
+# define LPLX "%#x"
+# define LPPID "%d"
+#else
+# define LPLU "%Ii64u"
+# define LPLD "%I64d"
+# define LPLX "%#I64x"
+# define LPPID "%d"
 #endif
 
 #endif
index aaef666..cfff406 100644 (file)
 #endif
 
 /* workgroud for VC compiler */
-#ifndef __FUNCTION__
-#define __FUNCTION__ "generic"
+#if _MSC_VER <= 1300
+#define __FUNCTION__ ("generic")
 #endif
 
+#include <config.h>
 #include <libcfs/winnt/winnt-types.h>
-#include <libcfs/portals_utils.h>
+#include <libcfs/list.h>
 #include <libcfs/winnt/winnt-time.h>
 #include <libcfs/winnt/winnt-lock.h>
 #include <libcfs/winnt/winnt-mem.h>
 #include <libcfs/winnt/winnt-tcpip.h>
 #include <libcfs/winnt/kp30.h>
 
-struct ptldebug_header {
-        __u32 ph_len;
-        __u32 ph_flags;
-        __u32 ph_subsys;
-        __u32 ph_mask;
-        __u32 ph_cpu_id;
-        __u32 ph_sec;
-        __u64 ph_usec;
-        __u32 ph_stack;
-        __u32 ph_pid;
-        __u32 ph_extern_pid;
-        __u32 ph_line_num;
-} __attribute__((packed));
-
 #ifdef __KERNEL__
 
 enum {
@@ -85,18 +72,25 @@ static inline __u32 query_stack_size()
 {
     ULONG   LowLimit, HighLimit;
 
-    IoGetStackLimits(&LowLimit, &HighLimit);
+    IoGetStackLimits((PULONG_PTR)&LowLimit, (PULONG_PTR)&HighLimit);
     ASSERT(HighLimit > LowLimit);
 
     return (__u32) (HighLimit - LowLimit);
 }
-#else
+
+/* disable watchdog */
+#undef WITH_WATCHDOG
+
+#else /* !__KERNEL__*/
+
+#include <libcfs/user-bitops.h>
+
 static inline __u32 query_stack_size()
 {
-   return 4096;
+   return PAGE_SIZE; /* using one page in default */
 }
-#endif
 
+#endif /* __KERNEL__*/
 
 #ifndef THREAD_SIZE
 # define THREAD_SIZE query_stack_size()
@@ -105,26 +99,8 @@ static inline __u32 query_stack_size()
 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
 
 #ifdef __KERNEL__
-# ifdef  __ia64__
-#  define CDEBUG_STACK() (THREAD_SIZE -                         \
-                          ((ulong_ptr)__builtin_dwarf_cfa() &   \
-                           (THREAD_SIZE - 1)))
-# else
-#  define CDEBUG_STACK (IoGetRemainingStackSize())
-#  error "This doesn't seem right; CDEBUG_STACK should grow with the stack"
-# endif /* __ia64__ */
-
-#define CHECK_STACK()                                                   \
-do {                                                                    \
-        unsigned long _stack = CDEBUG_STACK();                          \
-                                                                        \
-        if (_stack > 3*THREAD_SIZE/4 && _stack > libcfs_stack) {        \
-                libcfs_stack = _stack;                                  \
-                libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_WARNING,      \
-                                 __FILE__, NULL, __LINE__,              \
-                                 "maximum lustre stack %lu\n", _stack); \
-        }                                                               \
-} while (0)
+#define CDEBUG_STACK() (THREAD_SIZE - (__u32)IoGetRemainingStackSize())
+#define CHECK_STACK() do {} while(0)
 #else /* !__KERNEL__ */
 #define CHECK_STACK() do { } while(0)
 #define CDEBUG_STACK() (0L)
@@ -134,8 +110,8 @@ do {                                                                    \
 #define LUSTRE_LNET_PID          12345
 
 #define ENTRY_NESTING_SUPPORT (0)
-#define ENTRY_NESTING   do {;} while (0)
-#define EXIT_NESTING   do {;} while (0)
+#define ENTRY_NESTING   do {} while (0)
+#define EXIT_NESTING   do {} while (0)
 #define __current_nesting_level() (0)
 
 #endif /* _WINNT_LIBCFS_H */
index 17965e6..2353528 100644 (file)
@@ -1,5 +1,5 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=4:tabstop=4:
  *
  * GPL HEADER START
  *
 
 #ifndef __LIBCFS_WINNT_PORTALS_COMPAT_H__
 #define __LIBCFS_WINNT_PORTALS_COMPAT_H__
+#ifdef __KERNEL__
+/*
+ * Signal
+ */
 
+#define SIGNAL_MASK_ASSERT()                    do {} while(0)
+#define SIGNAL_MASK_LOCK(task, flags)           do {} while(0)
+#define SIGNAL_MASK_UNLOCK(task, flags)         do {} while(0)
+#define USERMODEHELPER(path, argv, envp)        do {} while(0)
+#define RECALC_SIGPENDING                       do {} while(0)
+#define CLEAR_SIGPENDING                        do {} while(0)
+#define CURRENT_SECONDS                         get_seconds()
+#endif
 
+#define ll_proc_dointvec(table, write, filp, buffer, lenp, ppos)        \
+        proc_dointvec(table, write, filp, buffer, lenp)
+#define ll_proc_dostring(table, write, filp, buffer, lenp, ppos)        \
+        proc_dostring(table, write, filp, buffer, lenp)
+#define LL_PROC_PROTO(name)                                             \
+        name(cfs_sysctl_table_t *table, int write, struct file *filp,   \
+             void __user *buffer, size_t *lenp)
+#define DECLARE_LL_PROC_PPOS_DECL  loff_t *ppos = &filp->f_pos
 
 #endif /* _PORTALS_COMPAT_H */
index c9ae107..54bb4ee 100644 (file)
@@ -1,5 +1,5 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=4:tabstop=4
  *
  * GPL HEADER START
  *
 #define cfs_clear_flag(x,f)  ((x) &= ~(f))
 #endif
 
-
-static inline __u32 __do_div(__u32 * n, __u32 b) 
+static inline __u32 do_div64(__u64 * n, __u64 b) 
 {
-    __u32   mod;
+    __u64   mod;
 
     mod = *n % b;
     *n  = *n / b;
-    return mod;
+    return (__u32)mod;
 } 
 
-#define do_div(n,base)  __do_div((__u32 *)&(n), (__u32) (base))
-
+#define do_div(n, b) do_div64(&(n), (__u64)b)
 #ifdef __KERNEL__
 
 #include <stdlib.h>
 #include <libcfs/winnt/winnt-types.h>
 
 char * strsep(char **s, const char *ct);
-static inline size_t strnlen(const char * s, size_t count) {
-    size_t len = 0;
-    while(len < count && s[len++]);
-    return len;
-}
-char * ul2dstr(ulong_ptr address, char *buf, int len);
+char * ul2dstr(ulong_ptr_t address, char *buf, int len);
 
 #define simple_strtol(a1, a2, a3)               strtol(a1, a2, a3)
 #define simple_strtoll(a1, a2, a3)              (__s64)strtoull(a1, a2, a3)
@@ -84,25 +77,154 @@ char * ul2dstr(ulong_ptr address, char *buf, int len);
 
 unsigned long simple_strtoul(const char *cp,char **endp, unsigned int base);
 
+static inline int set_bit(int nr, void * addr)
+{
+    (((volatile ULONG *) addr)[nr >> 5]) |= (1UL << (nr & 31));
+    return *((int *) addr);
+}
+
 static inline int test_bit(int nr, void * addr)
 {
-    return ((1UL << (nr & 31)) & (((volatile ULONG *) addr)[nr >> 5])) != 0;
+    return (int)(((1UL << (nr & 31)) & (((volatile ULONG *) addr)[nr >> 5])) != 0);
 }
 
-static inline void clear_bit(int nr, void * addr)
+static inline int clear_bit(int nr, void * addr)
 {
     (((volatile ULONG *) addr)[nr >> 5]) &= (~(1UL << (nr & 31)));
+    return *((int *) addr);
 }
 
+static inline int test_and_set_bit(int nr, volatile void *addr)
+{
+    int rc;
+    unsigned char  mask;
+    volatile unsigned char *ADDR = addr;
 
-static inline void set_bit(int nr, void * addr)
+    ADDR += nr >> 3;
+    mask = 1 << (nr & 0x07);
+    rc = ((mask & *ADDR) != 0);
+    *ADDR |= mask;
+
+    return rc;
+}
+
+#define ext2_set_bit(nr,addr)   (set_bit(nr, addr), 0)
+#define ext2_clear_bit(nr,addr)        (clear_bit(nr, addr), 0)
+#define ext2_test_bit(nr,addr)  test_bit(nr, addr)
+
+static inline int ffs(int x)
 {
-    (((volatile ULONG *) addr)[nr >> 5]) |= (1UL << (nr & 31));
+        int r = 1;
+
+        if (!x)
+                return 0;
+        if (!(x & 0xffff)) {
+                x >>= 16;
+                r += 16;
+        }
+        if (!(x & 0xff)) {
+                x >>= 8;
+                r += 8;
+        }
+        if (!(x & 0xf)) {
+                x >>= 4;
+                r += 4;
+        }
+        if (!(x & 3)) {
+                x >>= 2;
+                r += 2;
+        }
+        if (!(x & 1)) {
+                x >>= 1;
+                r += 1;
+        }
+        return r;
+}
+
+static inline unsigned long __ffs(unsigned long word)
+{
+        int num = 0;
+
+#if BITS_PER_LONG == 64
+        if ((word & 0xffffffff) == 0) {
+                num += 32;
+                word >>= 32;
+        }
+#endif
+        if ((word & 0xffff) == 0) {
+                num += 16;
+                word >>= 16;
+        }
+        if ((word & 0xff) == 0) {
+                num += 8;
+                word >>= 8;
+        }
+        if ((word & 0xf) == 0) {
+                num += 4;
+                word >>= 4;
+        }
+        if ((word & 0x3) == 0) {
+                num += 2;
+                word >>= 2;
+        }
+        if ((word & 0x1) == 0)
+                num += 1;
+        return num;
+}
+
+/**
+ * fls - find last (most-significant) bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs.
+ * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
+ */
+static inline
+int fls(int x)
+{
+        int r = 32;
+
+        if (!x)
+                return 0;
+        if (!(x & 0xffff0000u)) {
+                x <<= 16;
+                r -= 16;
+        }
+        if (!(x & 0xff000000u)) {
+                x <<= 8;
+                r -= 8;
+        }
+        if (!(x & 0xf0000000u)) {
+                x <<= 4;
+                r -= 4;
+        }
+        if (!(x & 0xc0000000u)) {
+                x <<= 2;
+                r -= 2;
+        }
+        if (!(x & 0x80000000u)) {
+                x <<= 1;
+                r -= 1;
+        }
+        return r;
+}
+
+static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
+{
+        unsigned x = 0;
+
+        while (x < size) {
+                unsigned long val = *addr++;
+                if (val)
+                        return __ffs(val) + x;
+                x += (sizeof(*addr)<<3);
+        }
+        return x;
 }
 
 static inline void read_random(char *buf, int len)
 {
-    ULONG   Seed = (ULONG) buf;
+    ULONG   Seed = (ULONG)(ULONG_PTR) buf;
     Seed = RtlRandom(&Seed);
     while (len >0) {
         if (len > sizeof(ULONG)) {
@@ -116,6 +238,7 @@ static inline void read_random(char *buf, int len)
         } 
     }
 }
+
 #define get_random_bytes(buf, len)  read_random(buf, len)
 
 /* do NOT use function or expression as parameters ... */
@@ -147,12 +270,18 @@ static int copy_from_user(void *to, void *from, int c)
     return 0;
 }
 
-static int copy_to_user(void *to, void *from, int c) 
+static int copy_to_user(void *to, const void *from, int c) 
 {
     memcpy(to, from, c);
     return 0;
 }
 
+static unsigned long
+clear_user(void __user *to, unsigned long n)
+{
+    memset(to, 0, n);
+       return n;
+}
 
 #define put_user(x, ptr)        \
 (                               \
@@ -169,12 +298,46 @@ static int copy_to_user(void *to, void *from, int c)
 
 #define num_physpages                  (64 * 1024)
 
-#define snprintf  _snprintf
-#define vsnprintf _vsnprintf
+#else
 
+#define unlink _unlink 
+#define close  _close
+#define open   _open
+#define fdopen _fdopen
+#define strdup _strdup
+#define fileno _fileno
+#define isattry _isattry
+#define stat    _stat
 
 #endif /* !__KERNEL__ */
 
 int cfs_error_code(NTSTATUS);
 
+static inline int vsnprintf(char *buf, size_t cnt,
+                            const char *fmt, va_list va)
+{
+    int rc;
+
+#ifdef TRUE /* using msvcrt from windkk 3790 */
+    rc = _vsnprintf(buf, cnt, fmt, va);
+#else
+    rc = _vsnprintf_s(buf, cnt, cnt, fmt, va);
+#endif
+    if (rc == -1)
+        return cnt;
+    return rc;
+}
+
+static inline int snprintf(char *buf, size_t cnt, 
+                           const char *fmt, ...)
+{
+    int         rc;
+    va_list     va;
+
+    va_start(va, fmt);
+    rc = vsnprintf(buf, cnt, fmt, va);
+    va_end(va);
+    return rc;
+}
+
 #endif
index 7e0c939..e3d52c0 100644 (file)
 #define NODEV          0
 #define MKDEV(ma,mi)   (((ma) << MINORBITS) | (mi))
 
+#define PATH_MAX (260)
 
 #ifdef __KERNEL__
 
+/* linux/fs.h */
+
+#define MAY_EXEC 1
+#define MAY_WRITE 2
+#define MAY_READ 4
+#define MAY_APPEND 8
+
+#define FMODE_READ 1
+#define FMODE_WRITE 2
+
+/* Internal kernel extensions */
+#define FMODE_LSEEK    4
+#define FMODE_PREAD    8
+#define FMODE_PWRITE   FMODE_PREAD     /* These go hand in hand */
+
+/* File is being opened for execution. Primary users of this flag are
+   distributed filesystems that can use it to achieve correct ETXTBUSY
+   behavior for cross-node execution/opening_for_writing of files */
+#define FMODE_EXEC     16
+
+#define RW_MASK         1
+#define RWA_MASK        2
+#define READ 0
+#define WRITE 1
+#define READA 2         /* read-ahead  - don't block if no resources */
+#define SWRITE 3        /* for ll_rw_block() - wait for buffer lock */
+#define SPECIAL 4       /* For non-blockdevice requests in request queue */
+#define READ_SYNC       (READ | (1 << BIO_RW_SYNC))
+#define WRITE_SYNC      (WRITE | (1 << BIO_RW_SYNC))
+#define WRITE_BARRIER   ((1 << BIO_RW) | (1 << BIO_RW_BARRIER))
+
 struct file_operations
 {
-    loff_t (*lseek)(struct file * file, loff_t offset, int origin);
+    struct module *owner;
+    loff_t (*llseek)(struct file * file, loff_t offset, int origin);
     ssize_t (*read) (struct file * file, char * buf, size_t nbytes, loff_t *ppos);
     ssize_t (*write)(struct file * file, const char * buffer,
         size_t count, loff_t *ppos);
-    int (*ioctl) (struct file *, unsigned int, ulong_ptr);
-    int (*open) (struct file *);
-    int (*release) (struct file *);
+    int (*ioctl) (struct file *, unsigned int, ulong_ptr_t);
+    int (*open) (struct inode*, struct file *);
+    int (*release) (struct inode*, struct file *);
 };
 
 struct file {
@@ -73,23 +106,23 @@ struct file {
     cfs_handle_t            f_handle;
     unsigned int            f_flags;
     mode_t                  f_mode;
-    ulong_ptr           f_count;
-
-    //struct list_head      f_list;
-    //struct dentry *       f_dentry;
-
-    cfs_proc_entry_t *      proc_dentry;
-    cfs_file_operations_t * f_op;
+    __u32                   f_count;
 
     size_t                  f_size;
     loff_t                  f_pos;
     unsigned int            f_uid, f_gid;
     int                     f_error;
 
-    ulong_ptr           f_version;
+    __u32                   f_version;
 
-    void *                  private_data;
+    //struct list_head      f_list;
+    struct dentry *         f_dentry;
+
+    cfs_proc_entry_t *      proc_dentry;
+    cfs_file_operations_t * f_op;
 
+    void *                  private_data;
+    struct inode *          f_inode;
     char                    f_name[1];
 
 };
@@ -105,9 +138,7 @@ int cfs_filp_fsync(cfs_file_t *fp);
 int cfs_get_file(cfs_file_t *fp);
 int cfs_put_file(cfs_file_t *fp);
 int cfs_file_count(cfs_file_t *fp);
-
-
-
+#define cfs_filp_unlink(x, y) (KdBreakPoint(),0) 
 /*
  * CFS_FLOCK routines
  */
@@ -146,41 +177,212 @@ typedef struct file_lock{
 #define ATTR_RAW        0x0800  /* file system, not vfs will massage attrs */
 #define ATTR_FROM_OPEN  0x1000  /* called from open path, ie O_TRUNC */
 //#define ATTR_CTIME_SET  0x2000
-#define ATTR_BLOCKS     0x4000
+
+/*
+ * set ATTR_BLOCKS to a high value to avoid any risk of collision with other
+ * ATTR_* attributes (see bug 13828): lustre/include/winnt/lustre_compat25.h
+ */
+/* #define ATTR_BLOCKS     0x4000 */
+#define ATTR_BLOCKS    (1 << 27)
+
 #define ATTR_KILL_SUID  0
 #define ATTR_KILL_SGID  0
 
+
+
 #define in_group_p(x)  (0)
 
-/*
- * proc fs routines
+
+/* VFS structures for windows */
+
+/* 
+ * inode formats
  */
 
-int proc_init_fs();
-void proc_destroy_fs();
+#define S_IFMT   00170000
+#define S_IFSOCK 0140000
+#define S_IFLNK         0120000
+#define S_IFREG  0100000
+#define S_IFBLK  0060000
+#define S_IFDIR  0040000
+#define S_IFCHR  0020000
+#define S_IFIFO  0010000
+#define S_ISUID  0004000
+#define S_ISGID  0002000
+#define S_ISVTX  0001000
+
+/* Inode flags - they have nothing to superblock flags now */
+
+#define S_SYNC         1       /* Writes are synced at once */
+#define S_NOATIME      2       /* Do not update access times */
+#define S_APPEND       4       /* Append-only file */
+#define S_IMMUTABLE    8       /* Immutable file */
+#define S_DEAD         16      /* removed, but still open directory */
+#define S_NOQUOTA      32      /* Inode is not counted to quota */
+#define S_DIRSYNC      64      /* Directory modifications are synchronous */
+#define S_NOCMTIME     128     /* Do not update file c/mtime */
+#define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
+#define S_PRIVATE      512     /* Inode is fs-internal */
+
+
+struct inode {
+        __u32           i_mode;
+        __u64           i_size;
+        __u64           i_blocks;
+        struct timespec i_atime;
+        struct timespec i_ctime;
+        struct timespec i_mtime;
+        struct timespec i_dtime;
+        __u32           i_ino;
+        __u32           i_generation;
+        __u32           i_state;
+        __u32           i_blkbits;
+        int             i_uid;
+        int             i_gid;
+        __u32           i_flags;
+        mutex_t         i_sem;
+        void *          i_priv;
+};
 
+#define I_FREEING       0x0001
 
-/*
- *  misc
- */
+struct dentry {
+        atomic_t        d_count;
+        struct {
+            int         len;
+            char *      name;
+        } d_name;
+        struct inode *  d_inode;
+        struct dentry*  d_parent;
+};
 
-static inline void *ERR_PTR(long_ptr error)
+extern struct dentry *dget(struct dentry *de);
+extern void dput(struct dentry *de);
+static __inline struct dentry *lookup_one_len(const char *name, struct dentry *de, int len)
 {
-       return (void *) error;
+    cfs_enter_debugger();
+    return NULL;
 }
 
-static inline long_ptr PTR_ERR(const void *ptr)
+static inline loff_t i_size_read(const struct inode *inode)
 {
-       return (long_ptr) ptr;
+    cfs_enter_debugger();
+    return inode->i_size;
 }
 
-static inline long_ptr IS_ERR(const void *ptr)
+static inline void i_size_write(struct inode *inode, loff_t i_size)
 {
-       return (ulong_ptr)ptr > (ulong_ptr)-1000L;
+    cfs_enter_debugger();
+    inode->i_size = i_size;
 }
 
+struct kstatfs {
+        u64     f_type;
+        long    f_bsize;
+        u64     f_blocks;
+        u64     f_bfree;
+        u64     f_bavail;
+        u64     f_files;
+        u64     f_ffree;
+        __u32   f_fsid;
+        long    f_namelen;
+        long    f_frsize;
+        long    f_spare[5];
+};
+
+struct super_block {
+        void *  s_fs_info;
+};
+
+struct vfsmount {
+        struct dentry * pwd;
+        struct dentry * mnt_root;
+        struct super_block *mnt_sb;
+};
+
+
+/*
+ * quota definitions (linux/quota.h)
+ */
+
+#define MAXQUOTAS 2
+#define USRQUOTA  0            /* element used for user quotas */
+#define GRPQUOTA  1            /* element used for group quotas */
+
+
+/*
+ * proc fs routines
+ */
+
+typedef int (read_proc_t)(char *page, char **start, off_t off,
+                          int count, int *eof, void *data);
+
+struct file; /* forward ref */
+typedef int (write_proc_t)(struct file *file, const char *buffer,
+                           unsigned long count, void *data);
+
+void proc_destory_subtree(cfs_proc_entry_t *entry);
+
+int proc_init_fs();
+void proc_destroy_fs();
+
+/*
+ *  thread affinity
+ */
+
+HANDLE cfs_open_current_thread();
+void cfs_close_thread_handle(HANDLE handle);
+KAFFINITY cfs_query_thread_affinity();
+int cfs_set_thread_affinity(KAFFINITY affinity);
+int cfs_tie_thread_to_cpu(int cpu);
+typedef PVOID mm_segment_t;
+
+/*
+ * thread priority
+ */
+int cfs_set_thread_priority(KPRIORITY priority);
+
+#define MAKE_MM_SEG(s) ((mm_segment_t)(ulong_ptr_t)(s))
+#define KERNEL_DS       MAKE_MM_SEG(0xFFFFFFFFUL)
+#define USER_DS         MAKE_MM_SEG(PAGE_OFFSET)
+
+#define get_ds()        (KERNEL_DS)
+#define set_fs(x) do {} while(0)
+#define get_fs() (NULL)
+
+/*
+ * radix tree (linux/radix_tree.h)
+ */
+
+/* radix tree root structure */
+struct radix_tree_root {
+    RTL_GENERIC_TABLE   table;
+};
+
+/* #define RADIX_TREE_INIT(mask) {0}
+
+#define RADIX_TREE(name, mask) \
+       struct radix_tree_root name RADIX_TREE_INIT(mask) */
+
+VOID RadixInitTable(IN PRTL_GENERIC_TABLE Table);
+#define INIT_RADIX_TREE(root, mask)    RadixInitTable(&((root)->table))
+
+/* all radix tree routines should be protected by external locks */
+unsigned int
+radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
+                       unsigned long first_index, unsigned int max_items);
+void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index);
+int radix_tree_insert(struct radix_tree_root *root,unsigned long index, void *item);
+void *radix_tree_delete(struct radix_tree_root *root, unsigned long index);
+
+struct rcu_head {
+    int     foo;
+};
+
 #else  /* !__KERNEL__ */
 
+#if !defined(_WINDOWS_)
+
 #define CREATE_NEW          1
 #define CREATE_ALWAYS       2
 #define OPEN_EXISTING       3
@@ -222,6 +424,13 @@ CloseHandle(
     );
 
 NTSYSAPI
+DWORD
+NTAPI
+GetLastError(
+   VOID
+   );
+
+NTSYSAPI
 HANDLE
 NTAPI
 CreateFileMappingA(
@@ -259,6 +468,7 @@ NTAPI
 UnmapViewOfFile(
     IN PVOID lpBaseAddress
     );
+#endif
 
 #endif /* __KERNEL__ */
 
@@ -266,5 +476,12 @@ typedef struct {
        void    *d;
 } cfs_dentry_t;
 
+/*
+ *  misc
+ */
+
+#define ERR_PTR(error) ((void *)(long_ptr_t)(error))
+#define PTR_ERR(ptr)   ((long)(long_ptr_t) (ptr))
+#define IS_ERR(ptr)    ((long)(((ulong_ptr_t) (ptr)) > (ulong_ptr_t)(-1000L)))
 
 #endif /* __LIBCFS_WINNT_CFS_FS_H__*/
index e9b1b57..0b6bac5 100644 (file)
 
 
 /*
- *  nt specific part ...
+ * IMPORTANT !!!!!!!!
+ *
+ * All locks' declaration are not guaranteed to be initialized,
+ * Althought some of they are initialized in Linux. All locks
+ * declared by CFS_DECL_* should be initialized explicitly.
+ */
+
+/*
+ *  spinlock & event definitions
  */
 
+typedef struct spin_lock spinlock_t;
 
 /* atomic */
 
@@ -73,6 +82,13 @@ void FASTCALL atomic_dec(atomic_t *v);
 int FASTCALL atomic_dec_and_test(atomic_t *v);
 int FASTCALL atomic_inc_and_test(atomic_t *v);
 
+int FASTCALL atomic_add_return(int i, atomic_t *v);
+int FASTCALL atomic_sub_return(int i, atomic_t *v);
+
+#define atomic_inc_return(v)  atomic_add_return(1, v)
+#define atomic_dec_return(v)  atomic_sub_return(1, v)
+
+int FASTCALL atomic_dec_and_lock(atomic_t *v, spinlock_t *lock);
 
 /* event */
 
@@ -107,7 +123,7 @@ static inline void
 }
 
 /*
- * cfs_wait_event
+ * cfs_wait_event_internal
  *   To wait on an event to syncrhonize the process
  *
  * Arguments:
@@ -123,7 +139,7 @@ static inline void
  */
 
 static inline int64_t
-cfs_wait_event(event_t * event, int64_t timeout)
+cfs_wait_event_internal(event_t * event, int64_t timeout)
 {
     NTSTATUS        Status;
     LARGE_INTEGER   TimeOut;
@@ -185,16 +201,6 @@ cfs_clear_event(event_t * event)
     KeResetEvent(event);
 }
 
-
-/*
- * IMPORTANT !!!!!!!!
- *
- * All locks' declaration are not guaranteed to be initialized,
- * Althought some of they are initialized in Linux. All locks
- * declared by CFS_DECL_* should be initialized explicitly.
- */
-
-
 /*
  * spin lock defintions / routines
  */
@@ -209,29 +215,31 @@ cfs_clear_event(event_t * event)
  *
  */
 
-typedef struct spin_lock {
-
+struct spin_lock {
     KSPIN_LOCK lock;
     KIRQL      irql;
-
-} spinlock_t;
-
+};
 
 #define CFS_DECL_SPIN(name)  spinlock_t name;
 #define CFS_DECL_SPIN_EXTERN(name)  extern spinlock_t name;
 
+#define SPIN_LOCK_UNLOCKED {0}
 
 static inline void spin_lock_init(spinlock_t *lock)
 {
     KeInitializeSpinLock(&(lock->lock));
 }
 
-
 static inline void spin_lock(spinlock_t *lock)
 {
     KeAcquireSpinLock(&(lock->lock), &(lock->irql));
 }
 
+static inline void spin_lock_nested(spinlock_t *lock, unsigned subclass)
+{
+    KeAcquireSpinLock(&(lock->lock), &(lock->irql));
+}
+
 static inline void spin_unlock(spinlock_t *lock)
 {
     KIRQL       irql = lock->irql;
@@ -248,7 +256,7 @@ static inline void spin_unlock(spinlock_t *lock)
    no way to identify the system is MP build or UP build
    on the runtime. We just uses a workaround for it. */
 
-extern int MPSystem;
+extern int libcfs_mp_system;
 
 static int spin_trylock(spinlock_t *lock)
 {
@@ -259,8 +267,8 @@ static int spin_trylock(spinlock_t *lock)
 
     KeRaiseIrql(DISPATCH_LEVEL, &Irql);
 
-    if (MPSystem) {
-        if (0 == (ulong_ptr)lock->lock) {
+    if (libcfs_mp_system) {
+        if (0 == (ulong_ptr_t)lock->lock) {
 #if _X86_
             __asm {
                 mov  edx, dword ptr [ebp + 8]
@@ -287,6 +295,16 @@ static int spin_trylock(spinlock_t *lock)
     return rc;
 }
 
+static int spin_is_locked(spinlock_t *lock)
+{
+#if _WIN32_WINNT >= 0x502
+    /* KeTestSpinLock only avalilable on 2k3 server or later */
+    return (!KeTestSpinLock(&lock->lock));
+#else
+    return (int) (lock->lock);
+#endif
+}
+
 /* synchronization between cpus: it will disable all DPCs
    kernel task scheduler on the CPU */
 #define spin_lock_bh(x)                    spin_lock(x)
@@ -305,7 +323,7 @@ typedef struct rw_semaphore {
 
 #define CFS_DECL_RWSEM(name) rw_semaphore_t name
 #define CFS_DECL_RWSEM_EXTERN(name) extern rw_semaphore_t name
-
+#define DECLARE_RWSEM CFS_DECL_RWSEM
 
 /*
  * init_rwsem
@@ -325,7 +343,7 @@ static inline void init_rwsem(rw_semaphore_t *s)
 {
        ExInitializeResourceLite(&s->rwsem);
 }
-
+#define rwsem_init init_rwsem
 
 /*
  * fini_rwsem
@@ -346,6 +364,7 @@ static inline void fini_rwsem(rw_semaphore_t *s)
 {
     ExDeleteResourceLite(&s->rwsem);
 }
+#define rwsem_fini fini_rwsem
 
 /*
  * down_read
@@ -365,6 +384,7 @@ static inline void down_read(struct rw_semaphore *s)
 {
        ExAcquireResourceSharedLite(&s->rwsem, TRUE);
 }
+#define down_read_nested down_read
 
 
 /*
@@ -406,7 +426,7 @@ static inline void down_write(struct rw_semaphore *s)
 {
        ExAcquireResourceExclusiveLite(&(s->rwsem), TRUE);
 }
-
+#define down_write_nested down_write
 
 /*
  * down_write_trylock
@@ -500,6 +520,11 @@ void write_unlock(rwlock_t * rwlock);
 #define read_lock_irqsave(l, f)                do {f=0; read_lock(l);} while(0)
 #define read_unlock_irqrestore(l, f)    do {read_unlock(l);} while(0)
 
+#define write_lock_bh   write_lock
+#define write_unlock_bh write_unlock
+
+struct lock_class_key {int foo;};
+#define lockdep_set_class(lock, class) do {} while(0)
 
 /*
  * Semaphore
@@ -509,9 +534,9 @@ void write_unlock(rwlock_t * rwlock);
  * - __up(x)
  */
 
-typedef struct semaphore {
+struct semaphore{
        KSEMAPHORE sem;
-} mutex_t;
+};
 
 static inline void sema_init(struct semaphore *s, int val)
 {
@@ -524,12 +549,25 @@ static inline void __down(struct semaphore *s)
                           KernelMode, FALSE, NULL );
 
 }
-
 static inline void __up(struct semaphore *s)
 {
        KeReleaseSemaphore(&s->sem, 0, 1, FALSE);
 }
 
+static inline int down_trylock(struct semaphore * s)
+{
+    LARGE_INTEGER  timeout = {0};
+    NTSTATUS status =
+        KeWaitForSingleObject( &(s->sem), Executive,
+                               KernelMode, FALSE, &timeout);
+
+    if (status == STATUS_SUCCESS) {
+        return 0;
+    }
+
+    return 1;
+}
+
 /*
  * mutex_t:
  *
@@ -539,6 +577,10 @@ static inline void __up(struct semaphore *s)
  * - mutex_down(x)
  */
 
+#define mutex semaphore
+typedef struct semaphore mutex_t;
+
+#define DECLARE_MUTEX(x) mutex_t x
 
 /*
  * init_mutex
@@ -553,13 +595,13 @@ static inline void __up(struct semaphore *s)
  * Notes: 
  *   N/A
  */
-
+#define mutex_init init_mutex
 static inline void init_mutex(mutex_t *mutex)
 {
     sema_init(mutex, 1);
 }
 
-
+#define init_MUTEX init_mutex
 /*
  * mutex_down
  *   To acquire the mutex lock
@@ -579,6 +621,10 @@ static inline void mutex_down(mutex_t *mutex)
     __down(mutex);
 }
 
+#define mutex_lock(m) mutex_down(m)
+#define mutex_trylock(s) down_trylock(s)
+#define mutex_lock_nested(m) mutex_down(m)
+#define down(m)       mutex_down(m)
 
 /*
  * mutex_up
@@ -599,6 +645,8 @@ static inline void mutex_up(mutex_t *mutex)
     __up(mutex);
 }
 
+#define mutex_unlock(m) mutex_up(m)
+#define up(m)           mutex_up(m)
 
 /*
  * init_mutex_locked
@@ -614,12 +662,18 @@ static inline void mutex_up(mutex_t *mutex)
  *   N/A
  */
 
-static inline init_mutex_locked(mutex_t *mutex)
+static inline void init_mutex_locked(mutex_t *mutex)
 {
     init_mutex(mutex);
     mutex_down(mutex);
 }
 
+#define init_MUTEX_LOCKED init_mutex_locked
+
+static inline void mutex_destroy(mutex_t *mutex)
+{
+}
+
 /*
  * completion
  *
@@ -689,14 +743,15 @@ static inline void complete(struct completion *c)
 
 static inline void wait_for_completion(struct completion *c)
 {
-    cfs_wait_event(&(c->event), 0);
+    cfs_wait_event_internal(&(c->event), 0);
 }
 
-/* __KERNEL__ */
-#else
-
-#include "../user-lock.h"
+static inline int wait_for_completion_interruptible(struct completion *c)
+{
+    cfs_wait_event_internal(&(c->event), 0);
+    return 0;
+}
 
-/* __KERNEL__ */
-#endif
+#else  /* !__KERNEL__ */
+#endif /* !__KERNEL__ */
 #endif
index c5cbfa0..211ffef 100644 (file)
 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
 #endif
 
+#include <libcfs/winnt/portals_utils.h>
+
 #ifdef __KERNEL__
 
+typedef struct cfs_mem_cache cfs_mem_cache_t;
+
+/*
+ * page definitions
+ */
+
 #define CFS_PAGE_SIZE                   PAGE_SIZE
 #define CFS_PAGE_SHIFT                  PAGE_SHIFT
 #define CFS_PAGE_MASK                   (~(PAGE_SIZE - 1))
 typedef struct cfs_page {
     void *      addr;
     atomic_t    count;
+    void *      private;
+    void *      mapping;
+    __u32       index;
+    __u32       flags;
 } cfs_page_t;
 
+#define page cfs_page
+
+#ifndef page_private
+#define page_private(page) ((page)->private)
+#define set_page_private(page, v) ((page)->private = (v))
+#endif
+
+#define page_count(page) (0)
+
+#define PG_locked               0      /* Page is locked. Don't touch. */
+#define PG_error                1
+#define PG_referenced           2
+#define PG_uptodate             3
+
+#define PG_dirty                4
+#define PG_lru                  5
+#define PG_active               6
+#define PG_slab                         7      /* slab debug (Suparna wants this) */
+
+#define PG_owner_priv_1                 8      /* Owner use. If pagecache, fs may use*/
+#define PG_arch_1               9
+#define PG_reserved            10
+#define PG_private             11      /* If pagecache, has fs-private data */
+
+#define PG_writeback           12      /* Page is under writeback */
+#define PG_compound            14      /* Part of a compound page */
+#define PG_swapcache           15      /* Swap page: swp_entry_t in private */
+
+#define PG_mappedtodisk                16      /* Has blocks allocated on-disk */
+#define PG_reclaim             17      /* To be reclaimed asap */
+#define PG_buddy               19      /* Page is free, on buddy lists */
+
+#define PG_virt         31  /* addr is not */
+
+#ifndef arch_set_page_uptodate
+#define arch_set_page_uptodate(page)
+#endif
+
+/* Make it prettier to test the above... */
+#define UnlockPage(page)        unlock_page(page)
+#define Page_Uptodate(page)     test_bit(PG_uptodate, &(page)->flags)
+#define SetPageUptodate(page) \
+       do {                                                            \
+               arch_set_page_uptodate(page);                           \
+               set_bit(PG_uptodate, &(page)->flags);                   \
+       } while (0)
+#define ClearPageUptodate(page) clear_bit(PG_uptodate, &(page)->flags)
+#define PageDirty(page)         test_bit(PG_dirty, &(page)->flags)
+#define SetPageDirty(page)      set_bit(PG_dirty, &(page)->flags)
+#define ClearPageDirty(page)    clear_bit(PG_dirty, &(page)->flags)
+#define PageLocked(page)        test_bit(PG_locked, &(page)->flags)
+#define LockPage(page)          set_bit(PG_locked, &(page)->flags)
+#define TryLockPage(page)       test_and_set_bit(PG_locked, &(page)->flags)
+#define PageChecked(page)       test_bit(PG_checked, &(page)->flags)
+#define SetPageChecked(page)    set_bit(PG_checked, &(page)->flags)
+#define ClearPageChecked(page)  clear_bit(PG_checked, &(page)->flags)
+#define PageLaunder(page)       test_bit(PG_launder, &(page)->flags)
+#define SetPageLaunder(page)    set_bit(PG_launder, &(page)->flags)
+#define ClearPageLaunder(page)  clear_bit(PG_launder, &(page)->flags)
+#define ClearPageArch1(page)    clear_bit(PG_arch_1, &(page)->flags)
+
+#define PageError(page)                test_bit(PG_error, &(page)->flags)
+#define SetPageError(page)     set_bit(PG_error, &(page)->flags)
+#define ClearPageError(page)   clear_bit(PG_error, &(page)->flags)
+#define PageReferenced(page)    test_bit(PG_referenced, &(page)->flags)
+#define SetPageReferenced(page) set_bit(PG_referenced, &(page)->flags)
+#define ClearPageReferenced(page)       clear_bit(PG_referenced, &(page)->flags)
+
+#define PageActive(page)        test_bit(PG_active, &(page)->flags)
+#define SetPageActive(page)     set_bit(PG_active, &(page)->flags)
+#define ClearPageActive(page)   clear_bit(PG_active, &(page)->flags)
+
+#define PageWriteback(page)    test_bit(PG_writeback, &(page)->flags)
+#define TestSetPageWriteback(page) test_and_set_bit(PG_writeback,      \
+                                                       &(page)->flags)
+#define TestClearPageWriteback(page) test_and_clear_bit(PG_writeback,  \
+                                                       &(page)->flags)
+
+#define __GFP_FS    (1)
+#define GFP_KERNEL  (2)
+#define GFP_ATOMIC  (4)
 
 cfs_page_t *cfs_alloc_page(int flags);
 void cfs_free_page(cfs_page_t *pg);
+void cfs_release_page(cfs_page_t *pg);
+cfs_page_t * virt_to_page(void * addr);
+cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order);
+void __cfs_free_pages(cfs_page_t *page, unsigned int order);
+int cfs_mem_is_in_cache(const void *addr, const cfs_mem_cache_t *kmem);
+
+#define page_cache_get(a) do {} while (0)
+#define page_cache_release(a) do {} while (0)
 
 static inline void *cfs_page_address(cfs_page_t *page)
 {
@@ -90,15 +191,18 @@ static inline int cfs_page_count(cfs_page_t *page)
     return atomic_read(&page->count);
 }
 
+#define cfs_page_index(p)       ((p)->index)
+
 /*
  * Memory allocator
  */
 
 #define CFS_ALLOC_ATOMIC_TRY   (0)
-
 extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
 extern void  cfs_free(void *addr);
 
+#define kmalloc cfs_alloc
+
 extern void *cfs_alloc_large(size_t nr_bytes);
 extern void  cfs_free_large(void *addr);
 
@@ -110,20 +214,36 @@ extern void  cfs_free_large(void *addr);
 
 /* The cache name is limited to 20 chars */
 
-typedef struct cfs_mem_cache {
-
+struct cfs_mem_cache {
     char                    name[20];
-    ulong_ptr           flags;
+    ulong_ptr_t             flags;
     NPAGED_LOOKASIDE_LIST   npll;
-
-} cfs_mem_cache_t;
+};
 
 
-extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, ulong_ptr);
+extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, unsigned long);
 extern int cfs_mem_cache_destroy ( cfs_mem_cache_t * );
 extern void *cfs_mem_cache_alloc ( cfs_mem_cache_t *, int);
 extern void cfs_mem_cache_free ( cfs_mem_cache_t *, void *);
 
+/*
+ * shrinker 
+ */
+typedef int (*shrink_callback)(int nr_to_scan, gfp_t gfp_mask);
+struct shrinker {
+    shrink_callback cb;
+       int seeks;      /* seeks to recreate an obj */
+
+       /* These are for internal use */
+       struct list_head list;
+       long nr;        /* objs pending delete */
+};
+
+struct shrinker * set_shrinker(int seeks, shrink_callback cb);
+void remove_shrinker(struct shrinker *s);
+
+int start_shrinker_timer();
+void stop_shrinker_timer();
 
 /*
  * Page allocator slabs 
@@ -142,8 +262,20 @@ extern cfs_mem_cache_t *cfs_page_p_slab;
 #define rmb()   mb()
 #define wmb()   mb()
 
+/*
+ * MM defintions from (linux/mm.h)
+ */
 
-/* __KERNEL__ */
-#endif
+#define DEFAULT_SEEKS 2 /* shrink seek */
+
+#else  /* !__KERNEL__ */
+
+#include "../user-mem.h"
+
+/* page alignmed buffer allocation */
+void* pgalloc(size_t factor);
+void  pgfree(void * page);
+
+#endif /* __KERNEL__ */
 
 #endif /* __WINNT_CFS_MEM_H__ */
index 87f905b..6bef4c1 100644 (file)
 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
 #endif
 
-
 /*
  * libcfs proc device object
  */
 
 
-#define LUSTRE_PROC_DEVICE  L"\\Device\\lproc"      /* proc fs emulator device object */
-#define LUSTRE_PROC_SYMLNK  L"\\DosDevices\\lproc"  /* proc fs user-visible device */
+#define LUSTRE_PROC_DEVICE  L"\\Device\\LNetProcFS"      /* proc fs emulator device object */
+#define LUSTRE_PROC_SYMLNK  L"\\DosDevices\\LNetProcFS"  /* proc fs user-visible device */
 
 
 /*
@@ -61,8 +60,6 @@
 
 #define FILE_DEVICE_LIBCFS      ('LC')
 
-#define FILE_DEVICE_LIBCFS      ('LC')
-
 #define FUNC_LIBCFS_VERSION     0x101  // get version of current libcfs
 #define FUNC_LIBCFS_IOCTL       0x102  // Device i/o control to proc fs
 
      CTL_CODE(FILE_DEVICE_LIBCFS, FUNC_LIBCFS_IOCTL,   METHOD_BUFFERED, FILE_ANY_ACCESS)
 
 #pragma pack(4)
-
 typedef struct _CFS_PROC_IOCTL {
 
     ULONG           cmd;    // ioctl command identifier
     ULONG           len;    // length of data
+    int             rc;     // return code
+    ULONG           usused; // unused 
 
     // UCHAR        data[]; // content of the real ioctl
 
 } CFS_PROC_IOCTL, *PCFS_PROC_IOCTL;
-
 #pragma pack()
 
 #ifdef __KERNEL__
 
-#include <libcfs/list.h>
+void cfs_enter_debugger(void);
+#define __builtin_return_address(x) (0)
 
 /*
  * Symbol functions for libcfs
@@ -110,8 +108,6 @@ extern void *   cfs_symbol_get(const char *);
 extern void     cfs_symbol_put(const char *);
 extern void     cfs_symbol_clean();
 
-
-
 typedef struct file_operations cfs_file_operations_t;
 typedef struct file cfs_file_t;
 
@@ -135,9 +131,9 @@ int cfs_psdev_deregister(cfs_psdev_t * psdev);
  */
 
 typedef int cfs_read_proc_t(char *page, char **start, off_t off,
-                         int count, int *eof, void *data);
+                            int count, int *eof, void *data);
 typedef int cfs_write_proc_t(struct file *file, const char *buffer,
-                          ulong_ptr count, void *data);
+                             unsigned long count, void *data);
 
 #define CFS_PROC_ENTRY_MAGIC 'CPEM'
 
@@ -154,6 +150,8 @@ typedef struct cfs_proc_entry
         PRTL_SPLAY_LINKS    root;
     };
 
+    struct cfs_proc_entry  *parent;
+
     struct _file_entry {                // proc file / leaf entry
            cfs_read_proc_t  *  read_proc;
            cfs_write_proc_t *  write_proc;
@@ -161,10 +159,11 @@ typedef struct cfs_proc_entry
 
     mode_t                  mode;
     unsigned short          nlink;
+    BOOLEAN                 deleted;
 
        
-    struct file_operations * proc_fops;
-       void * data;
+    struct file_operations *proc_fops;
+    void                   *data;
 
     // proc_dir_entry ended.
 
@@ -179,28 +178,32 @@ typedef struct cfs_proc_entry
 } cfs_proc_entry_t, cfs_proc_dir_entry_t;
 
 typedef cfs_proc_entry_t cfs_proc_dir_entry_t;
+#define proc_dir_entry cfs_proc_entry
 
 #define PROC_BLOCK_SIZE    PAGE_SIZE
 
+struct proc_dir_entry *PDE(const struct inode *inode);
+
+
 /*
  * Sysctl register
  */
 
-typedef struct ctl_table                   cfs_sysctl_table_t;
-typedef struct ctl_table_header                cfs_sysctl_table_header_t;
+typedef struct ctl_table                cfs_sysctl_table_t;
+typedef struct ctl_table_header         cfs_sysctl_table_header_t;
 
 
 typedef int ctl_handler (
             cfs_sysctl_table_t *table,
-            int *name,    int nlen,
-                       void *oldval, size_t *oldlenp,
-                       void *newval, size_t newlen, 
-                       void **context );
+            int *name,  int nlen,
+            void *oldval, size_t *oldlenp,
+            void *newval, size_t newlen, 
+            void **context );
 
 typedef int proc_handler (
             cfs_sysctl_table_t *ctl,
             int write, struct file * filp,
-                       void *buffer, size_t *lenp );
+            void *buffer, size_t *lenp );
 
 
 int proc_dointvec(cfs_sysctl_table_t *table, int write, struct file *filp,
@@ -213,7 +216,6 @@ int sysctl_string(cfs_sysctl_table_t *table, int *name, int nlen,
                  void *oldval, size_t *oldlenp,
                  void *newval, size_t newlen, void **context);
 
-
 /*
  *  System io control definitions
  */
@@ -261,21 +263,107 @@ struct ctl_table_header
        struct list_head        ctl_entry;
 };
 
+/* proc root entries, support routines */
+extern cfs_proc_entry_t *  cfs_proc_root;   /* / */
+extern cfs_proc_entry_t *  cfs_proc_proc;   /* /proc */
+extern cfs_proc_entry_t *  cfs_proc_fs;     /* /proc/fs */
+extern cfs_proc_entry_t *  cfs_proc_sys;    /* /proc/sys */
+extern cfs_proc_entry_t *  cfs_proc_dev;    /* /dev */
 
-cfs_proc_entry_t * create_proc_entry(char *name, mode_t mod,
+cfs_proc_entry_t * create_proc_entry(const char *name, mode_t mod,
                                          cfs_proc_entry_t *parent);
 void proc_free_entry(cfs_proc_entry_t *de);
-void remove_proc_entry(char *name, cfs_proc_entry_t *entry);
-cfs_proc_entry_t * search_proc_entry(char * name,
+void remove_proc_entry(const char *name, cfs_proc_entry_t *entry);
+cfs_proc_entry_t * search_proc_entry(const char * name,
                         cfs_proc_entry_t *  root );
+cfs_proc_entry_t *proc_symlink(const char *name,
+                                      cfs_proc_entry_t *parent,
+                               const char *dest);
+cfs_proc_entry_t *proc_mkdir(const char *name,
+                                    cfs_proc_entry_t *parent);
 
 #define cfs_create_proc_entry create_proc_entry
 #define cfs_free_proc_entry   proc_free_entry
 #define cfs_remove_proc_entry remove_proc_entry
 
-#define register_cfs_sysctl_table(t, a)        register_sysctl_table(t, a)
-#define unregister_cfs_sysctl_table(t) unregister_sysctl_table(t, a)
+struct ctl_table_header *register_sysctl_table(cfs_sysctl_table_t * table,
+                                               int insert_at_head);
+void unregister_sysctl_table(struct ctl_table_header * header);
+
+#define cfs_register_sysctl_table(t, a)   register_sysctl_table(t, a)
+#define cfs_unregister_sysctl_table(t)    unregister_sysctl_table(t)
+
+/*
+ * seq device (linux/seq_file.h)
+ */
+
+
+/*
+ * seq file definitions
+ */
+
+struct dentry;
+struct vfsmount;
+
+struct path {
+        struct vfsmount *mnt;
+        struct dentry *dentry;
+};
+
+struct seq_operations;
+struct file;
+struct inode;
+
+struct seq_file {
+       char *buf;
+       size_t size;
+       size_t from;
+       size_t count;
+       loff_t index;
+       u32    version;
+       mutex_t lock;
+       const struct seq_operations *op;
+       void *private;
+};
+
+struct seq_operations {
+       void * (*start) (struct seq_file *m, loff_t *pos);
+       void (*stop) (struct seq_file *m, void *v);
+       void * (*next) (struct seq_file *m, void *v, loff_t *pos);
+       int (*show) (struct seq_file *m, void *v);
+};
+
+int seq_open(struct file *, const struct seq_operations *);
+ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
+loff_t seq_lseek(struct file *, loff_t, int);
+int seq_release(struct inode *, struct file *);
+int seq_escape(struct seq_file *, const char *, const char *);
+int seq_putc(struct seq_file *m, char c);
+int seq_puts(struct seq_file *m, const char *s);
+
+int seq_printf(struct seq_file *, const char *, ...)
+       __attribute__ ((format (printf,2,3)));
 
+int seq_path(struct seq_file *, struct path *, char *);
+
+int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
+int single_release(struct inode *, struct file *);
+void *__seq_open_private(struct file *, const struct seq_operations *, int);
+int seq_open_private(struct file *, const struct seq_operations *, int);
+int seq_release_private(struct inode *, struct file *);
+
+#define SEQ_START_TOKEN ((void *)1)
+
+/*
+ * Helpers for iteration over list_head-s in seq_files
+ */
+
+extern struct list_head *seq_list_start(struct list_head *head,
+               loff_t pos);
+extern struct list_head *seq_list_start_head(struct list_head *head,
+               loff_t pos);
+extern struct list_head *seq_list_next(void *v, struct list_head *head,
+               loff_t *ppos);
 
 /*
  *  declaration of proc kernel process routines
@@ -290,7 +378,7 @@ lustre_close_file(cfs_file_t * fh);
 int
 lustre_do_ioctl( cfs_file_t * fh,
                  unsigned long cmd,
-                 ulong_ptr arg );
+                 ulong_ptr_t arg );
 
 int
 lustre_ioctl_file( cfs_file_t * fh,
@@ -298,7 +386,7 @@ lustre_ioctl_file( cfs_file_t * fh,
 
 size_t
 lustre_read_file( cfs_file_t *    fh,
-                  loff_t          off,
+                  loff_t          offl,
                   size_t          size,
                   char *          buf
                   );
@@ -320,7 +408,7 @@ typedef int cfs_task_state_t;
 #define CFS_TASK_INTERRUPTIBLE 0x00000001
 #define CFS_TASK_UNINT         0x00000002
 #define CFS_TASK_RUNNING        0x00000003
-
+#define CFS_TASK_UNINTERRUPTIBLE CFS_TASK_UNINT
 
 #define CFS_WAITQ_MAGIC     'CWQM'
 #define CFS_WAITLINK_MAGIC  'CWLM'
@@ -367,26 +455,6 @@ enum {
 
 #define CFS_DECL_WAITQ(name) cfs_waitq_t name
 
-
-void cfs_waitq_init(struct cfs_waitq *waitq);
-void cfs_waitlink_init(struct cfs_waitlink *link);
-
-void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link);
-void cfs_waitq_add_exclusive(struct cfs_waitq *waitq, 
-                            struct cfs_waitlink *link);
-void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
-int  cfs_waitq_active(struct cfs_waitq *waitq);
-
-void cfs_waitq_signal(struct cfs_waitq *waitq);
-void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr);
-void cfs_waitq_broadcast(struct cfs_waitq *waitq);
-
-void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state);
-cfs_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link, 
-                                  cfs_task_state_t state, cfs_duration_t timeout);
-
-
-
 /* Kernel thread */
 
 typedef int (*cfs_thread_t) (void *arg);
@@ -397,6 +465,7 @@ typedef struct _cfs_thread_context {
 } cfs_thread_context_t;
 
 int cfs_kernel_thread(int (*func)(void *), void *arg, int flag);
+#define kernel_thread cfs_kernel_thread
 
 /*
  * thread creation flags from Linux, not used in winnt
@@ -417,39 +486,121 @@ int cfs_kernel_thread(int (*func)(void *), void *arg, int flag);
 
 
 /*
- * sigset ...
+ * group_info: linux/sched.h
  */
+#define NGROUPS_SMALL           32
+#define NGROUPS_PER_BLOCK       ((int)(PAGE_SIZE / sizeof(gid_t)))
+struct group_info {
+        int ngroups;
+        atomic_t usage;
+        gid_t small_block[NGROUPS_SMALL];
+        int nblocks;
+        gid_t *blocks[0];
+};
 
-typedef sigset_t cfs_sigset_t;
+#define get_group_info(group_info) do { \
+        atomic_inc(&(group_info)->usage); \
+} while (0)
+
+#define put_group_info(group_info) do { \
+        if (atomic_dec_and_test(&(group_info)->usage)) \
+                groups_free(group_info); \
+} while (0)
+
+static __inline struct group_info *groups_alloc(int gidsetsize)
+{
+    struct group_info * groupinfo;
+    KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, __FUNCTION__));
+    groupinfo = (struct group_info *)cfs_alloc(sizeof(struct group_info), 0);
+    if (groupinfo) {
+        memset(groupinfo, 0, sizeof(struct group_info));
+    }
+    return groupinfo;
+}
+static __inline void groups_free(struct group_info *group_info)
+{
+    KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, __FUNCTION__));
+    cfs_free(group_info);
+}
+static __inline int set_current_groups(struct group_info *group_info) {
+    KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, __FUNCTION__));
+    return 0;
+}
+static __inline int groups_search(struct group_info *group_info, gid_t grp) {
+    KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, __FUNCTION__));
+    return 0;
+}
 
 /*
- * Task struct
+ *   capability issue (linux/capability.h)
  */
 
-#define MAX_SCHEDULE_TIMEOUT    ((long_ptr)(~0UL>>12))
+/* Override resource limits. Set resource limits. */
+/* Override quota limits. */
+/* Override reserved space on ext2 filesystem */
+/* Modify data journaling mode on ext3 filesystem (uses journaling
+   resources) */
+/* NOTE: ext2 honors fsuid when checking for resource overrides, so
+   you can override using fsuid too */
+/* Override size restrictions on IPC message queues */
+/* Allow more than 64hz interrupts from the real-time clock */
+/* Override max number of consoles on console allocation */
+/* Override max number of keymaps */
 
+#define CAP_SYS_RESOURCE     24
 
-#define NGROUPS 1
-#define CFS_CURPROC_COMM_MAX (16)
-typedef struct task_sruct{
-    mode_t umask;
+/*
+ *  capabilities support 
+ */
+
+typedef __u32 cfs_kernel_cap_t;
+
+#define cap_raise(c, flag)  do {} while(0)
+#define cap_lower(c, flag)  do {} while(0)
+#define cap_raised(c, flag) do {} while(0)
 
-       pid_t pid;
-       pid_t pgrp;
 
-       uid_t uid,euid,suid,fsuid;
-       gid_t gid,egid,sgid,fsgid;
+/*
+ * Task struct
+ */
+
+#define MAX_SCHEDULE_TIMEOUT    ((long_ptr_t)(~0UL>>12))
+#define schedule_timeout(t)     cfs_schedule_timeout(0, t)
 
-       int ngroups;
-       gid_t   groups[NGROUPS];
-       cfs_kernel_cap_t   cap_effective,
-                       cap_inheritable,
-                       cap_permitted;
+struct vfsmount;
 
-       char comm[CFS_CURPROC_COMM_MAX];
-    void * journal_info;
+#define NGROUPS 1
+#define CFS_CURPROC_COMM_MAX (16)
+typedef struct task_sruct{
+    mode_t           umask;
+    sigset_t         blocked;
+
+    pid_t            pid;
+    pid_t            pgrp;
+
+    uid_t            uid,euid,suid,fsuid;
+    gid_t            gid,egid,sgid,fsgid;
+
+    int              ngroups;
+    int              cgroups;
+    gid_t            groups[NGROUPS];
+    struct group_info *group_info;
+    cfs_kernel_cap_t cap_effective,
+                     cap_inheritable,
+                     cap_permitted;
+
+    char             comm[CFS_CURPROC_COMM_MAX];
+    void            *journal_info;
+    struct vfsmount *fs;
 }  cfs_task_t;
 
+static inline void task_lock(cfs_task_t *t)
+{
+}
+
+static inline void task_unlock(cfs_task_t *t)
+{
+}
 
 /*
  *  linux task struct emulator ...
@@ -498,49 +649,80 @@ typedef struct _TASK_SLOT {
 #define current                 cfs_current()
 #define set_current_state(s)   do {;} while (0)
 
-#define wait_event(wq, condition)                           \
-do {                                                        \
-    cfs_waitlink_t __wait;                                     \
-                                                            \
-    cfs_waitlink_init(&__wait);                                    \
-       while (TRUE) {                                          \
-               cfs_waitq_add(&wq, &__wait);                        \
-               if (condition)  {                                           \
-                       break;                                                  \
-        }                                                   \
-               cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE);        \
-               cfs_waitq_del(&wq, &__wait);                        \
-       }                                                                           \
-       cfs_waitq_del(&wq, &__wait);                                \
+#define wait_event(wq, condition)                               \
+do {                                                            \
+        cfs_waitlink_t __wait;                                  \
+                                                                \
+        cfs_waitlink_init(&__wait);                             \
+        while (TRUE) {                                          \
+            cfs_waitq_add(&wq, &__wait);                        \
+            if (condition) {                                    \
+                break;                                          \
+            }                                                   \
+            cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE);    \
+            cfs_waitq_del(&wq, &__wait);                       \
+        }                                                      \
+        cfs_waitq_del(&wq, &__wait);                           \
 } while(0)
 
-#define wait_event_interruptible(wq, condition, __ret)      \
-do {                                                        \
-    cfs_waitlink_t __wait;                                     \
-                                                            \
-    __ret = 0;                                              \
-    cfs_waitlink_init(&__wait);                                    \
-       while (TRUE) {                                          \
-               cfs_waitq_add(&wq, &__wait);                        \
-               if (condition)  {                                           \
-                       break;                                                  \
-        }                                                   \
-               cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE);    \
-               cfs_waitq_del(&wq, &__wait);                        \
-       }                                                                           \
-       cfs_waitq_del(&wq, &__wait);                                \
+#define cfs_wait_event_interruptible(wq, condition, __ret)      \
+do {                                                            \
+        cfs_waitlink_t __wait;                                 \
+                                                                \
+        __ret = 0;                                              \
+        cfs_waitlink_init(&__wait);                             \
+        while (TRUE) {                                          \
+            cfs_waitq_add(&wq, &__wait);                       \
+            if (condition) {                                    \
+                break;                                          \
+            }                                                   \
+            cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE);    \
+            cfs_waitq_del(&wq, &__wait);                       \
+        }                                                       \
+        cfs_waitq_del(&wq, &__wait);                            \
 } while(0)
 
+# define cfs_wait_event_interruptible_exclusive(wq, condition, rc)  \
+         cfs_wait_event_interruptible(wq, condition, rc)
+
+/*
+   retval == 0; condition met; we're good.
+   retval < 0; interrupted by signal.
+   retval > 0; timed out.
+*/
+
+#define cfs_waitq_wait_event_interruptible_timeout(             \
+                        wq, condition, timeout, rc)             \
+do {                                                            \
+        cfs_waitlink_t __wait;                                  \
+                                                                \
+        rc = 0;                                                 \
+        cfs_waitlink_init(&__wait);                            \
+        while (TRUE) {                                          \
+            cfs_waitq_add(&wq, &__wait);                        \
+            if (condition) {                                    \
+                break;                                          \
+            }                                                   \
+            if (cfs_waitq_timedwait(&__wait,                    \
+                CFS_TASK_INTERRUPTIBLE, timeout) == 0) {        \
+                rc = TRUE;                                      \
+                break;                                          \
+            }                                                   \
+            cfs_waitq_del(&wq, &__wait);                       \
+        }                                                      \
+        cfs_waitq_del(&wq, &__wait);                           \
+} while(0)
+
+
+#define cfs_waitq_wait_event_timeout                            \
+        cfs_waitq_wait_event_interruptible_timeout
 
 int     init_task_manager();
 void    cleanup_task_manager();
 cfs_task_t * cfs_current();
-int     schedule_timeout(int64_t time);
-int     schedule();
 int     wake_up_process(cfs_task_t * task);
-#define cfs_schedule_timeout(state, time)  schedule_timeout(time)
 void sleep_on(cfs_waitq_t *waitq);
-
+#define might_sleep() do {} while(0)
 #define CFS_DECL_JOURNAL_DATA  
 #define CFS_PUSH_JOURNAL           do {;} while(0)
 #define CFS_POP_JOURNAL                    do {;} while(0)
@@ -555,8 +737,14 @@ void sleep_on(cfs_waitq_t *waitq);
 #define __init
 #endif
 
-#define request_module(x) (0)
+struct module {
+    const char *name;
+};
+
+extern struct module libcfs_global_module;
+#define THIS_MODULE  &libcfs_global_module
 
+#define request_module(x) (0)
 #define EXPORT_SYMBOL(s)
 #define MODULE_AUTHOR(s)
 #define MODULE_DESCRIPTION(s)
@@ -581,20 +769,42 @@ void sleep_on(cfs_waitq_t *waitq);
 #define cfs_module(name, version, init, fini) \
 module_init(init);                            \
 module_exit(fini)
+#define module_refcount(x) (1)
 
+/*
+ * typecheck
+ */
+
+#define typecheck(a, b) do {} while(0)
 
 /*
- *  Linux kernel version definition
+ * linux/crypto.h
  */
 
-#define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
-#define LINUX_VERSION_CODE (2*100+6*10+7)
+#define CRYPTO_MAX_ALG_NAME            64
 
+#define CRYPTO_TFM_MODE_ECB            0x00000001
+#define CRYPTO_TFM_MODE_CBC            0x00000002
+#define CRYPTO_TFM_MODE_CFB            0x00000004
+#define CRYPTO_TFM_MODE_CTR            0x00000008
+#define CRYPTO_TFM_MODE_EME            0x00000010
 
 /*
- * Signal
+ * hash
  */
-#define SIGNAL_MASK_ASSERT()
+/* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
+#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
+
+#if 0 /* defined in libcfs/libcfs_hash.h */
+static inline u32 hash_long(u32 val, unsigned int bits)
+{
+       /* On some cpus multiply is faster, on others gcc will do shifts */
+       u32 hash = val * GOLDEN_RATIO_PRIME_32;
+
+       /* High bits are more random, so use them. */
+       return hash >> (32 - bits);
+}
+#endif
 
 /*
  * Timer
@@ -614,40 +824,11 @@ typedef struct cfs_timer {
 
     cfs_time_t      deadline;
 
-    void (*proc)(ulong_ptr);
+    void (*proc)(ulong_ptr_t);
     void *          arg;
 
 } cfs_timer_t;
 
-
-typedef  void (*timer_func_t)(ulong_ptr);
-
-#define cfs_init_timer(t)
-
-void cfs_timer_init(cfs_timer_t *timer, void (*func)(ulong_ptr), void *arg);
-void cfs_timer_done(cfs_timer_t *t);
-void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline);
-void cfs_timer_disarm(cfs_timer_t *t);
-int  cfs_timer_is_armed(cfs_timer_t *t);
-cfs_time_t cfs_timer_deadline(cfs_timer_t *t);
-
-
-/* deschedule for a bit... */
-static inline void cfs_pause(cfs_duration_t ticks)
-{
-    cfs_schedule_timeout(TASK_UNINTERRUPTIBLE, ticks);
-}
-
-
-static inline void cfs_enter_debugger(void)
-{
-#if _X86_
-    __asm int 3;
-#else
-    KdBreakPoint();
-#endif
-}
-
 /*
  *  libcfs globals initialization/cleanup
  */
@@ -659,23 +840,33 @@ void
 libcfs_arch_cleanup(void);
 
 /*
+ *  cache alignment size
+ */
+
+#define L1_CACHE_ALIGN(x) (x)
+
+#define __cacheline_aligned
+
+/*
  * SMP ...
  */
 
+
 #define SMP_CACHE_BYTES             128
-#define __cacheline_aligned
-#define NR_CPUS                                            (2)
-#define smp_processor_id()                 KeGetCurrentProcessorNumber()
-#define smp_num_cpus                NR_CPUS
-#define num_online_cpus() smp_num_cpus
+#define NR_CPUS                     (32)
+#define smp_num_cpus                ((CCHAR)KeNumberProcessors)
+#define num_possible_cpus()         smp_num_cpus
+#define num_online_cpus()           smp_num_cpus
+#define smp_processor_id()                 ((USHORT)KeGetCurrentProcessorNumber())
 #define smp_call_function(f, a, n, w)          do {} while(0)
+#define smp_rmb()                   do {} while(0)
 
 /*
  *  Irp related
  */
 
-#define NR_IRQS                                    512
-#define in_interrupt()                 (0)
+#define NR_IRQS                                        512
+#define in_interrupt()                     (0)
 
 /*
  *  printk flags
@@ -694,7 +885,6 @@ libcfs_arch_cleanup(void);
  * Misc
  */
 
-
 #define inter_module_get(n)                    cfs_symbol_get(n)
 #define inter_module_put(n)                    cfs_symbol_put(n)
 
@@ -708,65 +898,79 @@ libcfs_arch_cleanup(void);
 #define lock_kernel()               do {} while(0)
 #define unlock_kernel()             do {} while(0)
 
-#define USERMODEHELPER(path, argv, envp)       (0)
-
-
 #define local_irq_save(x)
 #define local_irq_restore(x)
 
-#define cfs_assert                      ASSERT
-
 #define THREAD_NAME
 
-#else   /* !__KERNEL__ */
+#define va_copy(_d, _s)                 (_d = _s)
 
-#define PAGE_CACHE_SIZE PAGE_SIZE
-#define PAGE_CACHE_MASK PAGE_MASK
+char *strnchr(const char *s, size_t count, int c);
 
-#define getpagesize()   (PAGE_SIZE)
+#define adler32(a,b,l) zlib_adler32(a,b,l)
+ULONG zlib_adler32(ULONG adler, const BYTE *buf, UINT len);
 
+typedef ssize_t (*read_actor_t)();
 
-typedef struct {
-    int foo;
-} pthread_mutex_t;
+#if DBG
+/*
+ *  winnt debug routines
+ */
 
-typedef struct {
-    int foo;
-} pthread_cond_t;
+VOID
+KsPrintf(
+    LONG  DebugPrintLevel,
+    PCHAR DebugMessage,
+    ...
+    );
 
-#define pthread_mutex_init(x, y)    do {} while(0)
-#define pthread_cond_init(x, y)     do {} while(0)
+PUCHAR
+KsNtStatusToString (IN NTSTATUS Status);
+#endif
 
-#define pthread_mutex_lock(x)       do {} while(0)
-#define pthread_mutex_unlock(x)     do {} while(0)
+#else   /* !__KERNEL__ */
 
-#define pthread_cond_wait(x,y)      do {} while(0)
-#define pthread_cond_broadcast(x)   do {} while(0)
+void cfs_enter_debugger();
 
-typedef struct file {
-    int foo;
-} cfs_file_t;
+/*
+ *  PAGE_SIZE ...
+ */
 
-typedef struct cfs_proc_dir_entry{
-       void            *data;
-}cfs_proc_dir_entry_t;
+#ifndef PAGE_SIZE
+#define PAGE_SIZE       (4096)
+#endif
 
+#define getpagesize()   (4096)
 
+#define PAGE_CACHE_SIZE PAGE_SIZE
+#define PAGE_CACHE_MASK PAGE_MASK
 
-#include "../user-prim.h"
+#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
+#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)
+#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)
 
+typedef struct file {
+    int foo;
+} cfs_file_t;
+
+#include "../user-prim.h"
+#include "../user-lock.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 
 #define strcasecmp  strcmp
 #define strncasecmp strncmp
-#define snprintf   _snprintf
 #define getpid()   (0)
 
-
-#define getpwuid(x) (NULL)
+#define getuid()    (0)
 #define getgrgid(x) (NULL)
 
+struct passwd {
+        uid_t pw_uid;
+        char  pw_name[64];
+};
+struct passwd * getpwuid(uid_t uid);
+
 int cfs_proc_mknod(const char *path, mode_t mode, dev_t dev);
 
 int gethostname(char * name, int namelen);
@@ -774,195 +978,191 @@ int gethostname(char * name, int namelen);
 #define setlinebuf(x) do {} while(0)
 
 
-NTSYSAPI VOID NTAPI DebugBreak();
+/* Maximum EA Information Length */
+#define EA_MAX_LENGTH  (sizeof(FILE_FULL_EA_INFORMATION) + 15)
 
+/*
+ *  proc user mode routines
+ */
 
-static inline void cfs_enter_debugger(void)
-{
-#if _X86_
-    __asm int 3;
+int cfs_proc_open (char * filename, int oflag);
+int cfs_proc_close(int fd);
+int cfs_proc_read(int fd, void *buffer, unsigned int count);
+int cfs_proc_write(int fd, void *buffer, unsigned int count);
+int cfs_proc_ioctl(int fd, int cmd, void *buffer);
+FILE *cfs_proc_fopen(char *path, char * mode);
+char *cfs_proc_fgets(char * buf, int len, FILE *fp);
+int cfs_proc_fclose(FILE *fp);
+
+/* Bits set in the FLAGS argument to `glob'.  */
+#define        GLOB_ERR        (1 << 0)/* Return on read errors.  */
+#define        GLOB_MARK       (1 << 1)/* Append a slash to each name.  */
+#define        GLOB_NOSORT     (1 << 2)/* Don't sort the names.  */
+#define        GLOB_DOOFFS     (1 << 3)/* Insert PGLOB->gl_offs NULLs.  */
+#define        GLOB_NOCHECK    (1 << 4)/* If nothing matches, return the pattern.  */
+#define        GLOB_APPEND     (1 << 5)/* Append to results of a previous call.  */
+#define        GLOB_NOESCAPE   (1 << 6)/* Backslashes don't quote metacharacters.  */
+#define        GLOB_PERIOD     (1 << 7)/* Leading `.' can be matched by metachars.  */
+
+#if !defined __USE_POSIX2 || defined __USE_BSD || defined __USE_GNU
+# define GLOB_MAGCHAR   (1 << 8)/* Set in gl_flags if any metachars seen.  */
+# define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions.  */
+# define GLOB_BRACE     (1 << 10)/* Expand "{a,b}" to "a" "b".  */
+# define GLOB_NOMAGIC   (1 << 11)/* If no magic chars, return the pattern.  */
+# define GLOB_TILDE     (1 << 12)/* Expand ~user and ~ to home directories. */
+# define GLOB_ONLYDIR   (1 << 13)/* Match only directories.  */
+# define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
+                                     if the user name is not available.  */
+# define __GLOB_FLAGS  (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
+                        GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
+                        GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE|     \
+                        GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
 #else
-    DebugBreak();
+# define __GLOB_FLAGS  (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
+                        GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND|     \
+                        GLOB_PERIOD)
 #endif
-}
 
-/* Maximum EA Information Length */
-#define EA_MAX_LENGTH  (sizeof(FILE_FULL_EA_INFORMATION) + 15)
+/* Error returns from `glob'.  */
+#define        GLOB_NOSPACE    1       /* Ran out of memory.  */
+#define        GLOB_ABORTED    2       /* Read error.  */
+#define        GLOB_NOMATCH    3       /* No matches found.  */
+#define GLOB_NOSYS     4       /* Not implemented.  */
+#ifdef __USE_GNU
+/* Previous versions of this file defined GLOB_ABEND instead of
+   GLOB_ABORTED.  Provide a compatibility definition here.  */
+# define GLOB_ABEND GLOB_ABORTED
+#endif
+
+/* Structure describing a globbing run.  */
+#ifdef __USE_GNU
+struct stat;
+#endif
+typedef struct
+  {
+    size_t gl_pathc;           /* Count of paths matched by the pattern.  */
+    char **gl_pathv;           /* List of matched pathnames.  */
+    size_t gl_offs;            /* Slots to reserve in `gl_pathv'.  */
+    int gl_flags;              /* Set to FLAGS, maybe | GLOB_MAGCHAR.  */
+
+    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
+       are used instead of the normal file access functions.  */
+    void (*gl_closedir) (void *);
+#ifdef __USE_GNU
+    struct dirent *(*gl_readdir) (void *);
+#else
+    void *(*gl_readdir) (void *);
+#endif
+    void *(*gl_opendir) (const char *);
+#ifdef __USE_GNU
+    int (*gl_lstat) (const char *__restrict, struct stat *__restrict);
+    int (*gl_stat) (const char *__restrict, struct stat *__restrict);
+#else
+    int (*gl_lstat) (const char *__restrict, void *__restrict);
+    int (*gl_stat) (const char *__restrict, void *__restrict);
+#endif
+  } glob_t;
+
+#ifdef __USE_LARGEFILE64
+# ifdef __USE_GNU
+struct stat64;
+# endif
+typedef struct
+  {
+    __size_t gl_pathc;
+    char **gl_pathv;
+    __size_t gl_offs;
+    int gl_flags;
+
+    /* If the GLOB_ALTDIRFUNC flag is set, the following functions
+       are used instead of the normal file access functions.  */
+    void (*gl_closedir) (void *);
+# ifdef __USE_GNU
+    struct dirent64 *(*gl_readdir) (void *);
+# else
+    void *(*gl_readdir) (void *);
+# endif
+    void *(*gl_opendir) (__const char *);
+# ifdef __USE_GNU
+    int (*gl_lstat) (__const char *__restrict, struct stat64 *__restrict);
+    int (*gl_stat) (__const char *__restrict, struct stat64 *__restrict);
+# else
+    int (*gl_lstat) (__const char *__restrict, void *__restrict);
+    int (*gl_stat) (__const char *__restrict, void *__restrict);
+# endif
+  } glob64_t;
+#endif
+
+int glob (const char * __pattern, int __flags,
+                int (*__errfunc) (const char *, int),
+                glob_t * __pglob);
+void globfree(glob_t *__pglog);
 
+#endif /* !__KERNEL__ */
 
 /*
- *  proc user mode routines
+ *  module routines
  */
 
-HANDLE cfs_proc_open (char * filename, int oflag);
-int cfs_proc_close(HANDLE handle);
-int cfs_proc_read(HANDLE handle, void *buffer, unsigned int count);
-int cfs_proc_write(HANDLE handle, void *buffer, unsigned int count);
-int cfs_proc_ioctl(HANDLE handle, int cmd, void *buffer);
+static inline void __module_get(struct module *module)
+{
+}
 
+static inline int try_module_get(struct module *module)
+{
+    return 1;
+}
+
+static inline void module_put(struct module *module)
+{
+}
 
 /*
- * Native API definitions
+ *  sigset_t routines 
  */
 
-//
-//  Disk I/O Routines
-//
-
-NTSYSAPI
-NTSTATUS
-NTAPI
-NtReadFile(HANDLE FileHandle,
-    HANDLE Event OPTIONAL,
-    PIO_APC_ROUTINE ApcRoutine OPTIONAL,
-    PVOID ApcContext OPTIONAL,
-    PIO_STATUS_BLOCK IoStatusBlock,
-    PVOID Buffer,
-    ULONG Length,
-    PLARGE_INTEGER ByteOffset OPTIONAL,
-    PULONG Key OPTIONAL);
-
-NTSYSAPI
-NTSTATUS
-NTAPI
-NtWriteFile(HANDLE FileHandle,
-    HANDLE Event OPTIONAL,
-    PIO_APC_ROUTINE ApcRoutine OPTIONAL,
-    PVOID ApcContext OPTIONAL,
-    PIO_STATUS_BLOCK IoStatusBlock,
-    PVOID Buffer,
-    ULONG Length,
-    PLARGE_INTEGER ByteOffset OPTIONAL,
-    PULONG Key OPTIONAL);
-
-NTSYSAPI
-NTSTATUS
-NTAPI
-NtClose(HANDLE Handle);
-
-NTSYSAPI
-NTSTATUS
-NTAPI
-NtCreateFile(PHANDLE FileHandle,
-    ACCESS_MASK DesiredAccess,
-    POBJECT_ATTRIBUTES ObjectAttributes,
-    PIO_STATUS_BLOCK IoStatusBlock,
-    PLARGE_INTEGER AllocationSize OPTIONAL,
-    ULONG FileAttributes,
-    ULONG ShareAccess,
-    ULONG CreateDisposition,
-    ULONG CreateOptions,
-    PVOID EaBuffer OPTIONAL,
-    ULONG EaLength);
-
-
-NTSYSAPI
-NTSTATUS
-NTAPI
-NtDeviceIoControlFile(
-    IN HANDLE  FileHandle,
-    IN HANDLE  Event,
-    IN PIO_APC_ROUTINE  ApcRoutine,
-    IN PVOID  ApcContext,
-    OUT PIO_STATUS_BLOCK  IoStatusBlock,
-    IN ULONG  IoControlCode,
-    IN PVOID  InputBuffer,
-    IN ULONG  InputBufferLength,
-    OUT PVOID  OutputBuffer,
-    OUT ULONG  OutputBufferLength
-    ); 
-
-NTSYSAPI
-NTSTATUS
-NTAPI
-NtFsControlFile(
-    IN HANDLE FileHandle,
-    IN HANDLE Event OPTIONAL,
-    IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
-    IN PVOID ApcContext OPTIONAL,
-    OUT PIO_STATUS_BLOCK IoStatusBlock,
-    IN ULONG FsControlCode,
-    IN PVOID InputBuffer OPTIONAL,
-    IN ULONG InputBufferLength,
-    OUT PVOID OutputBuffer OPTIONAL,
-    IN ULONG OutputBufferLength
-);
-
-
-NTSYSAPI
-NTSTATUS
-NTAPI
-NtQueryInformationFile(
-    IN HANDLE  FileHandle,
-    OUT PIO_STATUS_BLOCK  IoStatusBlock,
-    OUT PVOID  FileInformation,
-    IN ULONG  Length,
-    IN FILE_INFORMATION_CLASS  FileInformationClass
-    );
+typedef sigset_t cfs_sigset_t;
+#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
+#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
+#define sigemptyset(what)   (*(what) = 0, 0)
+#define sigfillset(what)    (*(what) = ~(0), 0)
+#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
+
+static __inline int
+sigprocmask(int sig, cfs_sigset_t *w1, cfs_sigset_t *w2) {
+    return 0;
+}
+static __inline int
+sigpending(cfs_sigset_t *what) {
+    return 0;
+}
+
+/*
+ * common inode flags (user & kernel)
+ */
 
-//
-// Random routines ...
-//
-
-NTSYSAPI
-ULONG
-NTAPI
-RtlRandom(
-    IN OUT PULONG  Seed
-    ); 
-
-#endif /* __KERNEL__ */
-
-
-//
-// Inode flags (Linux uses octad number, but why ? strange!!!)
-//
-
-#undef S_IFMT
-#undef S_IFDIR
-#undef S_IFCHR
-#undef S_IFREG
-#undef S_IREAD
-#undef S_IWRITE
-#undef S_IEXEC
-
-#define S_IFMT   0x0F000            /* 017 0000 */
-#define S_IFSOCK 0x0C000            /* 014 0000 */
-#define S_IFLNK  0x0A000            /* 012 0000 */
-#define S_IFREG  0x08000            /* 010 0000 */
-#define S_IFBLK  0x06000            /* 006 0000 */
-#define S_IFDIR  0x04000            /* 004 0000 */
-#define S_IFCHR  0x02000            /* 002 0000 */
-#define S_IFIFO  0x01000            /* 001 0000 */
-#define S_ISUID  0x00800            /* 000 4000 */
-#define S_ISGID  0x00400            /* 000 2000 */
-#define S_ISVTX  0x00200            /* 000 1000 */
-
-#define S_ISREG(m)      (((m) & S_IFMT) == S_IFREG)
-#define S_ISSOCK(m)     (((m) & S_IFMT) == S_IFSOCK)
-#define S_ISLNK(m)      (((m) & S_IFMT) == S_IFLNK)
-#define S_ISFIL(m)      (((m) & S_IFMT) == S_IFFIL)
-#define S_ISBLK(m)      (((m) & S_IFMT) == S_IFBLK)
-#define S_ISDIR(m)      (((m) & S_IFMT) == S_IFDIR)
-#define S_ISCHR(m)      (((m) & S_IFMT) == S_IFCHR)
-#define S_ISFIFO(m)     (((m) & S_IFMT) == S_IFIFO)
-
-#define S_IPERMISSION_MASK 0x1FF /*  */
-
-#define S_IRWXU  0x1C0              /* 0 0700 */
-#define S_IRUSR  0x100              /* 0 0400 */
-#define S_IWUSR  0x080              /* 0 0200 */
-#define S_IXUSR  0x040              /* 0 0100 */
-
-#define S_IRWXG  0x038              /* 0 0070 */
-#define S_IRGRP  0x020              /* 0 0040 */
-#define S_IWGRP  0x010              /* 0 0020 */
-#define S_IXGRP  0x008              /* 0 0010 */
-
-#define S_IRWXO  0x007              /* 0 0007 */
-#define S_IROTH  0x004              /* 0 0004 */
-#define S_IWOTH  0x002              /* 0 0002 */
-#define S_IXOTH  0x001              /* 0 0001 */
+#define S_ISLNK(m)     (((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m)     (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m)     (((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m)     (((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m)     (((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m)    (((m) & S_IFMT) == S_IFIFO)
+#define S_ISSOCK(m)    (((m) & S_IFMT) == S_IFSOCK)
+
+#define S_IRWXU 00700
+#define S_IRUSR 00400
+#define S_IWUSR 00200
+#define S_IXUSR 00100
+
+#define S_IRWXG 00070
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+
+#define S_IRWXO 00007
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
 
 #define S_IRWXUGO   (S_IRWXU|S_IRWXG|S_IRWXO)
 #define S_IALLUGO   (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
@@ -970,6 +1170,13 @@ RtlRandom(
 #define S_IWUGO     (S_IWUSR|S_IWGRP|S_IWOTH)
 #define S_IXUGO     (S_IXUSR|S_IXGRP|S_IXOTH)
 
+
+/*
+ *  Linux kernel version definition
+ */
+
+#define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
+
 /*
  *  linux ioctl coding definitions
  */
@@ -979,7 +1186,7 @@ RtlRandom(
 #define _IOC_SIZEBITS   14
 #define _IOC_DIRBITS    2
 
-#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
+#define _IOC_NRMASK     ((1 << _IOC_NRBITS)-1)
 #define _IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
 #define _IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
 #define _IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
@@ -1014,16 +1221,26 @@ RtlRandom(
 #define _IOC_NR(nr)         (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
 #define _IOC_SIZE(nr)       (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
 
-/*
- * Io vector ...  
- */
-
-struct iovec
-{
+/* i/o vector sgructure ... */
+struct iovec {
     void *iov_base;
     size_t iov_len;
 };
 
+/* idr support routines */
+struct idr_context *cfs_idr_init();
+int cfs_idr_remove(struct idr_context *idp, int id);
+int cfs_idr_get_new(struct idr_context *idp, void *ptr);
+int cfs_idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id);
+void *cfs_idr_find(struct idr_context *idp, int id);
+void cfs_idr_exit(struct idr_context *idp);
+
+/* runtime time routines for both kenrel and user mode */
+extern int cfs_isalpha(int);
+extern int cfs_isspace(int);
+extern int cfs_isupper(int);
+extern int cfs_isdigit(int);
+extern int cfs_isxdigit(int);
 
 #define ULONG_LONG_MAX ((__u64)(0xFFFFFFFFFFFFFFFF))
 /*
@@ -1032,61 +1249,86 @@ struct iovec
  * Ignores `locale' stuff.  Assumes that the upper and lower case
  * alphabets and digits are each contiguous.
  */
-static inline __u64
-strtoull(
-       char *nptr,
-       char **endptr,
-       int base)
+__u64 strtoull(char *nptr, char **endptr,int base);
+
+/*
+ *  getopt routines
+ */
+
+/* For communication from `getopt' to the caller.
+   When `getopt' finds an option that takes an argument,
+   the argument value is returned here.
+   Also, when `ordering' is RETURN_IN_ORDER,
+   each non-option ARGV-element is returned here.  */
+
+extern char *optarg;
+
+/* Index in ARGV of the next element to be scanned.
+   This is used for communication to and from the caller
+   and for communication between successive calls to `getopt'.
+
+   On entry to `getopt', zero means this is the first call; initialize.
+
+   When `getopt' returns -1, this is the index of the first of the
+   non-option elements that the caller should itself scan.
+
+   Otherwise, `optind' communicates from one call to the next
+   how much of ARGV has been scanned so far.  */
+
+extern int optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+   for unrecognized options.  */
+
+extern int opterr;
+
+/* Set to an option character which was unrecognized.  */
+
+extern int optopt;
+
+
+struct option
 {
-       char *s = nptr;
-       __u64 acc, cutoff;
-       int c, neg = 0, any, cutlim;
-
-       /*
-        * See strtol for comments as to the logic used.
-        */
-       do {
-               c = *s++;
-       } while (isspace(c));
-       if (c == '-') {
-               neg = 1;
-               c = *s++;
-       } else if (c == '+')
-               c = *s++;
-       if ((base == 0 || base == 16) &&
-           c == '0' && (*s == 'x' || *s == 'X')) {
-               c = s[1];
-               s += 2;
-               base = 16;
-       }
-       if (base == 0)
-               base = c == '0' ? 8 : 10;
-       cutoff = (__u64)ULONG_LONG_MAX / (__u64)base;
-       cutlim = (int)((__u64)ULONG_LONG_MAX % (__u64)base);
-       for (acc = 0, any = 0;; c = *s++) {
-               if (isdigit(c))
-                       c -= '0';
-               else if (isalpha(c))
-                       c -= isupper(c) ? 'A' - 10 : 'a' - 10;
-               else
-                       break;
-               if (c >= base)
-                       break;
-               if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
-                       any = -1;
-               else {
-                       any = 1;
-                       acc *= base;
-                       acc += c;
-               }
-       }
-       if (any < 0) {
-               acc = ULONG_LONG_MAX;
-       } else if (neg)
-               acc = 0 - acc;
-       if (endptr != 0)
-               *endptr = (char *) (any ? s - 1 : nptr);
-       return (acc);
-}
+  const char *name;
+  /* has_arg can't be an enum because some compilers complain about
+     type mismatches in all the code that assumes it is an int.  */
+  int has_arg;
+  int *flag;
+  int val;
+};
+
+/* Names for the values of the `has_arg' field of `struct option'.  */
+# define no_argument           0
+# define required_argument     1
+# define optional_argument     2
+
+extern int getopt(int ___argc, char *const *___argv, const char *__shortopts);
+extern int getopt_long (int ___argc, char *const *___argv,
+                       const char *__shortopts,
+                       const struct option *__longopts, int *__longind);
+extern int getopt_long_only (int ___argc, char *const *___argv,
+                            const char *__shortopts,
+                            const struct option *__longopts, int *__longind);
+
+extern char *strcasestr (const char *phaystack, const char *pneedle);
+
+/*
+ * global environment runtime routine
+ */
+
+static __inline char * __cdecl cfs_getenv(const char *ENV) {return NULL;}
+static __inline void   __cdecl set_getenv(const char *ENV, const char *value, int overwrite) {}
+
+int setenv(const char *envname, const char *envval, int overwrite);
+
+struct utsname {
+         char sysname[64];
+         char nodename[64];
+         char release[128];
+         char version[128];
+         char machine[64];
+};
+
+int uname(struct utsname *uts);
 
 #endif
index 179b36b..ebaa4f9 100644 (file)
@@ -1,5 +1,5 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=4:tabstop=4:
  *
  * GPL HEADER START
  *
 // iovec is defined in libcfs: winnt_prim.h 
 // lnetkiov_t is defined in lnet/types.h
 
-typedef struct socket ksock_tconn_t;
-typedef struct socket cfs_socket_t;
+typedef struct socket ks_tconn_t, cfs_socket_t;
 
 // completion notification callback routine
 
-typedef VOID (*ksock_schedule_cb)(struct socket*, int, void *, ulong_ptr);
+typedef VOID (*ks_schedule_cb)(struct socket*, int);
 
-/* completion routine to update tx structure for async sending */
-typedef PVOID (*ksock_update_tx)(struct socket*, PVOID tx, ulong_ptr);
+#define SOCK_ERROR(s)          ((s->kstc_state >= ksts_disconnected) ? ECONNRESET : 0)
+#define SOCK_TEST_NOSPACE(s)   (1)
 
 //
 // tdinal definitions
 //
 
 
-#if TDI_LIBCFS_DBG
+#if DBG
 #define KsPrint(X)     KsPrintf X
 #else
 #define KsPrint(X)
@@ -77,17 +76,17 @@ typedef PVOID (*ksock_update_tx)(struct socket*, PVOID tx, ulong_ptr);
 // Socket Addresses Related ...
 //
 
-#define            INADDR_ANY              (ULONG)0x00000000
+#define     INADDR_ANY          (ULONG)0x00000000
 #define     INADDR_LOOPBACK     (ULONG)0x7f000001
-#define            INADDR_BROADCAST    (ULONG)0xffffffff
-#define            INADDR_NONE             (ULONG)0xffffffff
+#define     INADDR_BROADCAST    (ULONG)0xffffffff
+#define     INADDR_NONE         (ULONG)0xffffffff
 
 /*
  *  TCP / IP options
  */
 
 #define     SOL_TCP             6
-#define     SOL_UDP                    17
+#define     SOL_UD              17
 
 
 #define TL_INSTANCE             0
@@ -104,7 +103,7 @@ typedef PVOID (*ksock_update_tx)(struct socket*, PVOID tx, ulong_ptr);
    Added those for 1003.1g not all are supported yet
  */
  
-#define MSG_OOB            1
+#define MSG_OOB         1
 #define MSG_PEEK        2
 #define MSG_DONTROUTE   4
 #define MSG_TRYHARD     4       /* Synonym for MSG_DONTROUTE for DECnet */
@@ -168,15 +167,14 @@ typedef PVOID (*ksock_update_tx)(struct socket*, PVOID tx, ulong_ptr);
 
 typedef struct _KS_TSDU {
 
-    ULONG               Magic;
-    ULONG               Flags;
+    ULONG               Magic;          /* magic */
+    ULONG               Flags;          /* flags */
 
-    struct list_head    Link;
+    struct list_head    Link;           /* link list */
 
-    ULONG               TotalLength;    // Total size of KS_TSDU
-
-    ULONG               StartOffset;    // Start offset of the first Tsdu unit
-    ULONG               LastOffset;     // End offset of the last Tsdu unit
+    ULONG               TotalLength;    /* total size of KS_TSDU */
+    ULONG               StartOffset;    /* offset of the first Tsdu unit */
+    ULONG               LastOffset;     /* end offset of the last Tsdu unit */
 
 /*
     union {
@@ -192,7 +190,8 @@ typedef struct _KS_TSDU {
 #define TSDU_TYPE_DAT   ((USHORT)0x5402)
 #define TSDU_TYPE_MDL   ((USHORT)0x5403)
 
-#define KS_TSDU_BUF_RECEIVING       0x0001
+#define KS_TSDU_COMM_PARTIAL         0x0001
+
 typedef struct _KS_TSDU_BUF {
 
     USHORT              TsduType;
@@ -202,11 +201,9 @@ typedef struct _KS_TSDU_BUF {
     ULONG               StartOffset;
 
     PVOID               UserBuffer;
-
+    PMDL                Mdl;         /* mdl */
 } KS_TSDU_BUF, *PKS_TSDU_BUF;
 
-#define KS_TSDU_DAT_RECEIVING       0x0001
-
 typedef struct _KS_TSDU_DAT {
 
     USHORT              TsduType;
@@ -216,48 +213,65 @@ typedef struct _KS_TSDU_DAT {
     ULONG               StartOffset;
 
     ULONG               TotalLength;
+    PMDL                Mdl;        /* mdl */
 
-    UCHAR               Data[1];
+    UCHAR               Data[0];
 
 } KS_TSDU_DAT, *PKS_TSDU_DAT;
 
-#define KS_DWORD_ALIGN(x)      (((x) + 0x03) & (~(0x03)))
-#define KS_TSDU_STRU_SIZE(Len) (KS_DWORD_ALIGN((Len) + FIELD_OFFSET(KS_TSDU_DAT, Data)))
+#define KS_QWORD_ALIGN(x)      (((x) + 0x07) & 0xFFFFFFF8)
+#define KS_TSDU_STRU_SIZE(Len) (KS_QWORD_ALIGN((Len) + FIELD_OFFSET(KS_TSDU_DAT, Data[0])))
 
 typedef struct _KS_TSDU_MDL {
+    USHORT              TsduType;      /* TSDU_TYPE_MDL */
+    USHORT              TsduFlags;     /* */
 
-    USHORT              TsduType;
-    USHORT              TsduFlags;
-
-    ULONG               DataLength;
-    ULONG               StartOffset;    
+    ULONG               DataLength;    /* total valid data length */
+    ULONG               BaseOffset;    /* payload offset in Tsdu */
+    ULONG               StartOffset;   /* offset in payload */
 
+    PVOID               Descriptor;    /* tdi descriptor for receiving */
     PMDL                Mdl;
-    PVOID               Descriptor;
-
 } KS_TSDU_MDL, *PKS_TSDU_MDL;
 
+typedef struct ks_engine_mgr {
+    spinlock_t              lock;
+    int                     stop;
+    event_t                 exit;
+    event_t                 start;
+    struct list_head        list;
+} ks_engine_mgr_t;
+
+typedef struct ks_engine_slot {
+    ks_tconn_t *            tconn;
+    void *                  tsdumgr;
+    struct list_head        link;
+    int                     queued;
+    ks_engine_mgr_t *       emgr;
+} ks_engine_slot_t;
 
 typedef struct _KS_TSDUMGR {
-
-    struct list_head    TsduList;
-    ULONG               NumOfTsdu;
-    ULONG               TotalBytes;
-    KEVENT              Event;
-
+    struct list_head        TsduList;
+    ULONG                   NumOfTsdu;
+    ULONG                   TotalBytes;
+    KEVENT                  Event;
+    spinlock_t              Lock;
+    ks_engine_slot_t        Slot;
+    ULONG                   Payload;
+    int                     Busy:1;
+    int                     OOB:1;
 } KS_TSDUMGR, *PKS_TSDUMGR;
 
+#define ks_lock_tsdumgr(mgr)   spin_lock(&((mgr)->Lock))
+#define ks_unlock_tsdumgr(mgr) spin_unlock(&((mgr)->Lock))
 
 typedef struct _KS_CHAIN {
-
-    KS_TSDUMGR          Normal;
-    KS_TSDUMGR          Expedited;
-
+    KS_TSDUMGR          Normal;      /* normal queue */
+    KS_TSDUMGR          Expedited;   /* OOB/expedited queue */
 } KS_CHAIN, *PKS_CHAIN;
 
 
-#define TDINAL_SCHED_FACTOR (1)
-#define CAN_BE_SCHED(Len, Limit) (Len >= ((Limit) >> TDINAL_SCHED_FACTOR))
+#define KS_CAN_SCHED(TM) ((TM)->TotalBytes >= ((TM)->Payload >> 2))
 
 //
 // Handler Settings Indictor 
@@ -299,7 +313,7 @@ typedef struct _KS_ADDRESS {
 typedef struct _KS_DISCONNECT_WORKITEM {
 
     WORK_QUEUE_ITEM         WorkItem;       // Workitem to perform disconnection
-    ksock_tconn_t *         tconn;          // tdi connecton
+    ks_tconn_t *            tconn;          // tdi connecton
     ULONG                   Flags;          // connection broken/discnnection flags
     KEVENT                  Event;          // sync event
 
@@ -323,45 +337,38 @@ typedef struct _KS_CONNECTION {
 // type definitions
 //
 
-typedef MDL                         ksock_mdl_t;
-typedef UNICODE_STRING              ksock_unicode_name_t;
-typedef WORK_QUEUE_ITEM             ksock_workitem_t;
+typedef MDL                         ks_mdl_t;
+typedef UNICODE_STRING              ks_unicode_name_t;
+typedef WORK_QUEUE_ITEM             ks_workitem_t;
 
 
-typedef KS_CHAIN                    ksock_chain_t;
-typedef KS_ADDRESS                  ksock_tdi_addr_t;
-typedef KS_CONNECTION               ksock_tconn_info_t;
-typedef KS_DISCONNECT_WORKITEM      ksock_disconnect_workitem_t;
+typedef KS_CHAIN                    ks_chain_t;
+typedef KS_ADDRESS                  ks_tdi_addr_t;
+typedef KS_CONNECTION               ks_tconn_info_t;
+typedef KS_DISCONNECT_WORKITEM      ks_disconnect_t;
 
 
 //
 // Structures for transmission done Workitem
 //
 
-typedef struct _KS_TCPX_FINILIZE {
-    ksock_workitem_t        item;
-    void *                  tx;
-} ksock_tcpx_fini_t;
-
-
-typedef struct ksock_backlogs {
+typedef struct ks_backlogs {
 
         struct list_head    list;   /* list to link the backlog connections */
         int                 num;    /* number of backlogs in the list */
 
-} ksock_backlogs_t;
+} ks_backlogs_t;
 
 
-typedef struct ksock_daemon {
+typedef struct ks_daemon {
 
-    ksock_tconn_t *         tconn;         /* the listener connection object */
+    ks_tconn_t *            tconn;         /* the listener connection object */
     unsigned short          nbacklogs;     /* number of listening backlog conns */
     unsigned short          port;          /* listening port number */ 
     int                     shutdown;      /* daemon threads is to exit */
-    struct list_head        list;          /* to be attached into ksock_nal_data_t*/
-
-} ksock_daemon_t ;
+    struct list_head        list;          /* to be attached into ks_nal_data_t */
 
+} ks_daemon_t;
 
 typedef enum {
 
@@ -373,8 +380,10 @@ typedef enum {
                         // or refuse the connecting request from remote peers.
 
     kstt_child,         // accepted child connection type, it's parent must be Listener
+
     kstt_lasttype
-} ksock_tconn_type;
+
+} ks_tconn_type_t;
 
 typedef enum {
 
@@ -401,7 +410,8 @@ typedef enum {
     ksts_aborted,       // un-exptected broken status
 
     ksts_last           // total number of tconn statuses
-} ksock_tconn_state;
+
+} ks_tconn_state_t;
 
 #define KS_TCONN_MAGIC              'KSTM'
 
@@ -411,23 +421,22 @@ typedef enum {
 
 #define KS_TCONN_DAEMON_STARTED     0x00100000  // indict the daemon is started,
                                                 // only valid for listener
-
 struct socket {
 
-        ulong_ptr                   kstc_magic;      /* Magic & Flags */
-        ulong_ptr                   kstc_flags;
+        ulong                       kstc_magic;      /* Magic & Flags */
+        ulong                       kstc_flags;
 
         spinlock_t                  kstc_lock;       /* serialise lock*/
-        void *                      kstc_conn;       /* ksock_conn_t */
+        void *                      kstc_conn;       /* ks_conn_t */
 
-        ksock_tconn_type            kstc_type;          /* tdi connection Type */
-        ksock_tconn_state           kstc_state;      /* tdi connection state flag */
+        ks_tconn_type_t             kstc_type;          /* tdi connection Type */
+        ks_tconn_state_t            kstc_state;      /* tdi connection state flag */
 
-        ksock_unicode_name_t        kstc_dev;        /* tcp transport device name */
+        ks_unicode_name_t           kstc_dev;        /* tcp transport device name */
 
-        ksock_tdi_addr_t            kstc_addr;       /* local address handlers / Objects */
+        ks_tdi_addr_t               kstc_addr;       /* local address handlers / Objects */
 
-        atomic_t                    kstc_refcount;   /* reference count of ksock_tconn */
+        atomic_t                    kstc_refcount;   /* reference count of ks_tconn_t */
 
         struct list_head            kstc_list;       /* linked to global ksocknal_data */
 
@@ -435,17 +444,17 @@ struct socket {
 
             struct {
                 int                 nbacklog;         /* total number of backlog tdi connections */
-                ksock_backlogs_t    kstc_listening;   /* listeing backlog child connections */
-                ksock_backlogs_t    kstc_accepted;    /* connected backlog child connections */
+                ks_backlogs_t       kstc_listening;   /* listeing backlog child connections */
+                ks_backlogs_t       kstc_accepted;    /* connected backlog child connections */
                 event_t             kstc_accept_event;   /* Signaled by AcceptedHander, 
                                                             ksocknal_wait_accpeted_conns waits on */
                 event_t             kstc_destroy_event;  /* Signaled when accepted child is released */
             } listener; 
 
             struct  {
-                ksock_tconn_info_t  kstc_info;      /* Connection Info if Connected */
-                ksock_chain_t       kstc_recv;      /* tsdu engine for data receiving */
-                ksock_chain_t       kstc_send;      /* tsdu engine for data sending */
+                ks_tconn_info_t     kstc_info;      /* Connection Info if Connected */
+                ks_chain_t          kstc_recv;      /* tsdu engine for data receiving */
+                ks_chain_t          kstc_send;      /* tsdu engine for data sending */
 
                 int                 kstc_queued;    /* Attached to Parent->ChildList ... */
                 int                 kstc_queueno;   /* 0: Attached to Listening list 
@@ -455,30 +464,28 @@ struct socket {
                 int                 kstc_accepted;  /* the connection is built ready ? */
 
                 struct list_head    kstc_link;      /* linked to parent tdi connection */
-                ksock_tconn_t   *   kstc_parent;    /* pointers to it's listener parent */
+                ks_tconn_t   *      kstc_parent;    /* pointers to it's listener parent */
             } child;
 
             struct {
-                ksock_tconn_info_t  kstc_info;      /* Connection Info if Connected */
-                ksock_chain_t       kstc_recv;      /* tsdu engine for data receiving */
-                ksock_chain_t       kstc_send;      /* tsdu engine for data sending */
+                ks_tconn_info_t     kstc_info;      /* Connection Info if Connected */
+                ks_chain_t          kstc_recv;      /* tsdu engine for data receiving */
+                ks_chain_t          kstc_send;      /* tsdu engine for data sending */
             } sender; 
         };
 
-        ulong_ptr                   kstc_snd_wnd;   /* Sending window size */
-        ulong_ptr                   kstc_rcv_wnd;   /* Recving window size */
+        ulong                       kstc_snd_wnd;   /* Sending window size */
+        ulong                       kstc_rcv_wnd;   /* Recving window size */
 
-        ksock_workitem_t            kstc_destroy;    /* tconn destruction workitem */
-        ksock_disconnect_workitem_t kstc_disconnect; /* connection disconnect workitem */
+        ks_workitem_t               kstc_destroy;    /* tconn destruction workitem */
+        ks_disconnect_t             kstc_disconnect; /* connection disconnect workitem */
 
-        ksock_schedule_cb           kstc_sched_cb;   /* notification callback routine of completion */
-        ksock_update_tx             kstc_update_tx;  /* aync sending callback to update tx */
+        ks_schedule_cb              kstc_sched_cb;   /* notification callback routine of completion */
 };
 
 #define SOCK_WMEM_QUEUED(sock) (0)
-
 #define TDINAL_WINDOW_DEFAULT_SIZE  (0x100000)
-
+#define TDINAL_MAX_TSDU_QUEUE_SIZE  (0x200000)
 
 struct _KS_UDP_COMPLETION_CONTEXT;
 struct _KS_TCP_COMPLETION_CONTEXT;
@@ -510,7 +517,7 @@ typedef struct _KS_UDP_COMPLETION_CONTEXT {
     PKEVENT                             Event;
     union {
         PFILE_OBJECT                    AddressObject;
-        ksock_tconn_t *                 tconn;
+        ks_tconn_t *                    tconn;
     };
 
     PKS_UDP_COMPLETION_ROUTINE          CompletionRoutine;
@@ -523,29 +530,20 @@ typedef struct _KS_UDP_COMPLETION_CONTEXT {
 // Tcp Irp Completion Context (used by tcp data recv/send)
 //
 
-typedef struct _KS_TCP_COMPLETION_CONTEXT {
+#define KS_TCP_CONTEXT_MAGIC 'CCTK'
 
+typedef struct _KS_TCP_COMPLETION_CONTEXT {
     PKEVENT                             Event;      // Event to be waited on by Irp caller ...
-
-    ksock_tconn_t *                     tconn;      // the tdi connection
-
+    ks_tconn_t *                        tconn;      // the tdi connection
     PKS_TCP_COMPLETION_ROUTINE          CompletionRoutine;
     PVOID                               CompletionContext;
-    PVOID                               CompletionContext2;
-
-    PKS_TSDUMGR                         KsTsduMgr;  // Tsdu buffer manager
-
-    //
-    // These tow new members are for NON_BLOCKING transmission
-    //
-
-    BOOLEAN                                                        bCounted;    // To indict needing refcount to
-                                                     // execute CompetionRoutine
-    ULONG                               ReferCount;  // Refer count of this structure
-
+    PKS_TSDUMGR                         TsduMgr;    // Tsdu buffer manager
+    ULONG                               Length;     // Payload length in KsTsdu queue
+    PCHAR                               Buffer;     // User allocated buffer
+    ULONG                               Magic;      // Magic key
 } KS_TCP_COMPLETION_CONTEXT, *PKS_TCP_COMPLETION_CONTEXT;
 
-typedef KS_TCP_COMPLETION_CONTEXT  ksock_tdi_tx_t, ksock_tdi_rx_t;
+typedef KS_TCP_COMPLETION_CONTEXT  ks_tdi_tx_t, ks_tdi_rx_t;
 
 
 /*
@@ -596,7 +594,6 @@ typedef KS_TCP_COMPLETION_CONTEXT  ksock_tdi_tx_t, ksock_tdi_rx_t;
         Irp->UserBuffer = OutBuffer;                            \
     }
 
-
 typedef struct ks_addr_slot {
     LIST_ENTRY      link;
     int             up;
@@ -626,30 +623,28 @@ typedef struct {
 
     int               ksnd_init;            /* initialisation state */
 
-    TDI_PROVIDER_INFO ksnd_provider;    /* tdi tcp/ip provider's information */
+    TDI_PROVIDER_INFO ksnd_provider;        /* tdi tcp/ip provider's information */
 
     spinlock_t        ksnd_tconn_lock;      /* tdi connections access serialise */
 
     int               ksnd_ntconns;         /* number of tconns attached in list */
     struct list_head  ksnd_tconns;          /* tdi connections list */
-    cfs_mem_cache_t * ksnd_tconn_slab;      /* slabs for ksock_tconn_t allocations */
+    cfs_mem_cache_t * ksnd_tconn_slab;      /* slabs for ks_tconn_t allocations */
     event_t           ksnd_tconn_exit;      /* exit event to be signaled by the last tconn */
 
     spinlock_t        ksnd_tsdu_lock;       /* tsdu access serialise */
         
     int               ksnd_ntsdus;          /* number of tsdu buffers allocated */
-    ulong_ptr     ksnd_tsdu_size;       /* the size of a signel tsdu buffer */
+    ulong             ksnd_tsdu_size;       /* the size of a signel tsdu buffer */
     cfs_mem_cache_t * ksnd_tsdu_slab;       /* slab cache for tsdu buffer allocation */
 
     int               ksnd_nfreetsdus;      /* number of tsdu buffers in the freed list */
-    struct list_head  ksnd_freetsdus;          /* List of the freed Tsdu buffer. */
+    struct list_head  ksnd_freetsdus;       /* List of the freed Tsdu buffer. */
 
-    spinlock_t        ksnd_daemon_lock;     /* stabilize daemon ops */
-    int               ksnd_ndaemons;        /* number of listening daemons */
-    struct list_head  ksnd_daemons;         /* listening daemon list */
-    event_t           ksnd_daemon_exit;     /* the last daemon quiting should singal it */
+    int               ksnd_engine_nums;     /* number of tcp sending engine threads */
+    ks_engine_mgr_t * ksnd_engine_mgr;      /* tcp sending engine structure */
 
-} ks_data_t;
+} ks_tdi_data_t;
 
 int
 ks_init_tdi_data();
@@ -658,6 +653,71 @@ void
 ks_fini_tdi_data();
 
 
+int
+ks_query_local_ipaddr(
+    ks_tconn_t *     tconn
+    );
+
+void
+ks_get_tconn(
+    ks_tconn_t * tconn
+    );
+
+void
+ks_put_tconn(
+    ks_tconn_t * tconn
+    );
+
+void
+ks_abort_tconn(
+  ks_tconn_t *     tconn
+    );
+int
+ks_disconnect_tconn(
+    ks_tconn_t *    tconn,
+    ulong           flags
+    );
+
+void
+ks_destroy_tconn(
+    ks_tconn_t *     tconn
+    );
+
+NTSTATUS
+KsLockUserBuffer (
+    IN PVOID            UserBuffer,
+    IN BOOLEAN          bPaged,
+    IN ULONG            Length,
+    IN LOCK_OPERATION   Operation,
+    OUT PMDL *          pMdl
+    );
+
+VOID
+KsReleaseMdl (IN PMDL   Mdl,
+              IN int    Paged );
+
+void
+KsQueueTdiEngine(ks_tconn_t * tconn, PKS_TSDUMGR);
+
+void
+KsRemoveTdiEngine(PKS_TSDUMGR);
+
+NTSTATUS
+ks_set_tcp_option (
+    ks_tconn_t *    tconn,
+    ULONG           ID,
+    PVOID           OptionValue,
+    ULONG           Length
+    );
+
+int
+ks_get_tcp_option (
+    ks_tconn_t *        tconn,
+    ULONG               ID,
+    PVOID               OptionValue,
+    PULONG              Length
+    );
+
 #endif /* __KERNEL__ */
 #endif /* __LIBCFS_WINNT_TCPIP_H__ */
 
index 35c6526..3c46828 100644 (file)
  *
  */
 
-#define ONE_BILLION ((u_int64_t)1000000000)
-#define ONE_MILLION ((u_int64_t)   1000000)
-
-#define HZ (100)
-
 struct timeval {
-       time_t          tv_sec;         /* seconds */
-       suseconds_t     tv_usec;        /* microseconds */
+    time_t      tv_sec;   /* seconds */
+    suseconds_t tv_usec;  /* microseconds */
 };
 
-struct timespec {
-    ulong_ptr tv_sec;
-    ulong_ptr tv_nsec;
-};
+typedef time_t cfs_time_t;
+typedef time_t cfs_duration_t;
 
 #ifdef __KERNEL__
 
 #include <libcfs/winnt/portals_compat25.h>
 
+#define HZ (100)
+
+struct timespec {
+    __u32   tv_sec;
+    __u32   tv_nsec;
+};
+typedef struct timeval cfs_fs_time_t;
+
+
+#define ONE_BILLION ((u_int64_t)1000000000)
+#define ONE_MILLION ((u_int64_t)   1000000)
+
 /*
  * Generic kernel stuff
  */
 
-typedef struct timeval cfs_fs_time_t;
-
-typedef u_int64_t cfs_time_t;
-typedef int64_t cfs_duration_t;
+#define jiffies     (ULONG_PTR)JIFFIES()
+#define cfs_jiffies (ULONG_PTR)JIFFIES()
 
 static inline void do_gettimeofday(struct timeval *tv)
 {
@@ -118,11 +121,11 @@ static inline void do_gettimeofday(struct timeval *tv)
 
     KeQuerySystemTime(&Time);
 
-    tv->tv_sec  = (long_ptr) (Time.QuadPart / 10000000);
-    tv->tv_usec = (long_ptr) (Time.QuadPart % 10000000) / 10;
+    tv->tv_sec  = (time_t) (Time.QuadPart / 10000000);
+    tv->tv_usec = (suseconds_t) (Time.QuadPart % 10000000) / 10;
 }
 
-static inline cfs_time_t JIFFIES()
+static inline LONGLONG JIFFIES()
 {
     LARGE_INTEGER Tick;
     LARGE_INTEGER Elapse;
@@ -137,33 +140,16 @@ static inline cfs_time_t JIFFIES()
 
 static inline cfs_time_t cfs_time_current(void)
 {
-    return JIFFIES();
+    return (cfs_time_t)JIFFIES();
 }
 
-static inline cfs_time_t cfs_time_current_sec(void)
+static inline time_t cfs_time_current_sec(void)
 {
-    return (JIFFIES() / HZ);
+    return (time_t)(JIFFIES() / HZ);
 }
 
-static inline cfs_time_t cfs_time_add(cfs_time_t t, cfs_duration_t d)
-{
-    return (t + d);
-}
-
-static inline cfs_duration_t cfs_time_sub(cfs_time_t t1, cfs_time_t t2)
-{
-    return (t1 - t2);
-}
-
-static inline int cfs_time_before(cfs_time_t t1, cfs_time_t t2)
-{
-    return ((int64_t)t1 - (int64_t)t2) < 0; 
-}
-
-static inline int cfs_time_beforeq(cfs_time_t t1, cfs_time_t t2)
-{
-    return ((int64_t)t1 - (int64_t)t2) <= 0;
-}
+#define time_before(t1, t2) (((signed)(t1) - (signed)(t2)) < 0) 
+#define time_before_eq(t1, t2) (((signed)(t1) - (signed)(t2)) <= 0) 
 
 static inline void cfs_fs_time_current(cfs_fs_time_t *t)
 {
@@ -178,14 +164,21 @@ static inline void cfs_fs_time_current(cfs_fs_time_t *t)
     t->tv_usec = (Sys.LowPart % 10000000) / 10;
 }
 
+static inline unsigned long get_seconds(void)
+{
+    cfs_fs_time_t t;
+    cfs_fs_time_current(&t);
+    return (unsigned long) t.tv_sec;
+}
+
 static inline cfs_time_t cfs_fs_time_sec(cfs_fs_time_t *t)
 {
-    return t->tv_sec;
+    return (cfs_time_t)t->tv_sec;
 }
 
-static inline u_int64_t __cfs_fs_time_flat(cfs_fs_time_t *t)
+static inline unsigned long __cfs_fs_time_flat(cfs_fs_time_t *t)
 {
-    return ((u_int64_t)t->tv_sec) * ONE_MILLION + t->tv_usec;
+    return (unsigned long)(t->tv_sec) * ONE_MILLION + t->tv_usec;
 }
 
 static inline int cfs_fs_time_before(cfs_fs_time_t *t1, cfs_fs_time_t *t2)
@@ -198,126 +191,95 @@ static inline int cfs_fs_time_beforeq(cfs_fs_time_t *t1, cfs_fs_time_t *t2)
     return (__cfs_fs_time_flat(t1) <= __cfs_fs_time_flat(t2));
 }
 
-static inline cfs_duration_t cfs_time_seconds(int seconds)
+static inline cfs_duration_t cfs_time_seconds(cfs_duration_t seconds)
 {
-    return (cfs_duration_t)seconds * HZ;
+    return  (cfs_duration_t)(seconds * HZ);
 }
 
-static inline cfs_time_t cfs_duration_sec(cfs_duration_t d)
+static inline time_t cfs_duration_sec(cfs_duration_t d)
 {
-        return d / HZ;
+    return (time_t)(d / HZ);
 }
 
 static inline void cfs_duration_usec(cfs_duration_t d, struct timeval *s)
 {
-        s->tv_sec = (suseconds_t) (d / HZ);
-        s->tv_usec = (time_t)((d - (cfs_duration_t)s->tv_sec * HZ) *
+    s->tv_sec = (__u32)(d / HZ);
+    s->tv_usec = (__u32)((d - (cfs_duration_t)s->tv_sec * HZ) *
                               ONE_MILLION / HZ);
 }
 
 static inline void cfs_duration_nsec(cfs_duration_t d, struct timespec *s)
 {
-        s->tv_sec = (suseconds_t) (d / HZ);
-        s->tv_nsec = (time_t)((d - (cfs_duration_t)s->tv_sec * HZ) *
-                              ONE_BILLION / HZ);
+    s->tv_sec = (__u32) (d / HZ);
+    s->tv_nsec = (__u32)((d - (cfs_duration_t)s->tv_sec * HZ) *
+                           ONE_BILLION / HZ);
 }
 
 static inline void cfs_fs_time_usec(cfs_fs_time_t *t, struct timeval *v)
 {
-        *v = *t;
+    *v = *t;
 }
 
 static inline void cfs_fs_time_nsec(cfs_fs_time_t *t, struct timespec *s)
 {
-        s->tv_sec  = t->tv_sec;
-        s->tv_nsec = t->tv_usec * 1000;
+    s->tv_sec  = (__u32) t->tv_sec;
+    s->tv_nsec = (__u32) t->tv_usec * 1000;
 }
 
-#define cfs_time_current_64 cfs_time_current
-#define cfs_time_add_64     cfs_time_add
-#define cfs_time_shift_64   cfs_time_shift
-#define cfs_time_before_64  cfs_time_before
-#define cfs_time_beforeq_64 cfs_time_beforeq
-
-/*
- * One jiffy
- */
-#define CFS_TICK                (1)
-
-#define LTIME_S(t)                     (t)
-
-#define CFS_TIME_T              "%I64u"
-#define CFS_DURATION_T          "%I64d"
-
-#else   /* !__KERNEL__ */
-
-/*
- * Liblustre. time(2) based implementation.
- */
-#include <libcfs/user-time.h>
-
-
-//
-// Time routines ...
-//
-
-NTSYSAPI
-CCHAR
-NTAPI
-NtQuerySystemTime(
-    OUT PLARGE_INTEGER  CurrentTime
-    );
-
 
-NTSYSAPI
-BOOLEAN
-NTAPI
-RtlTimeToSecondsSince1970(
-    IN PLARGE_INTEGER  Time,
-    OUT PULONG  ElapsedSeconds
-    );
+#define cfs_time_current_64 JIFFIES
 
+static inline __u64 cfs_time_add_64(__u64 t, __u64 d)
+{
+    return t + d;
+}
 
-NTSYSAPI
-VOID
-NTAPI
-RtlSecondsSince1970ToTime(
-    IN ULONG  ElapsedSeconds,
-    OUT PLARGE_INTEGER  Time
-    );
-
-NTSYSAPI
-VOID
-NTAPI
-Sleep(
-  DWORD dwMilliseconds   // sleep time in milliseconds
-);
+static inline __u64 cfs_time_shift_64(cfs_duration_t seconds)
+{
+    return cfs_time_add_64(cfs_time_current_64(),
+                           cfs_time_seconds(seconds));
+}
 
+static inline int cfs_time_before_64(__u64 t1, __u64 t2)
+{
+    return (__s64)t2 - (__s64)t1 > 0;
+}
 
-static inline void sleep(int time)
+static inline int cfs_time_beforeq_64(__u64 t1, __u64 t2)
 {
-    DWORD Time = 1000 * time;
-    Sleep(Time);
+    return (__s64)t2 - (__s64)t1 >= 0;
 }
 
+/*
+ * One jiffy
+ */
+#define CFS_TICK                (1)
+#define LTIME_S(t)                     *((__u64 *)&(t))
 
-static inline void do_gettimeofday(struct timeval *tv)
-{
-    LARGE_INTEGER Time;
+#define CFS_TIME_T              "%u"
+#define CFS_DURATION_T          "%d"
 
-    NtQuerySystemTime(&Time);
+#else   /* !__KERNEL__ */
 
-    tv->tv_sec  = (long_ptr) (Time.QuadPart / 10000000);
-    tv->tv_usec = (long_ptr) (Time.QuadPart % 10000000) / 10;
-}
+#include <time.h>
+#ifdef HAVE_LIBPTHREAD
+#include <pthread.h>
+#else
+struct timespec {
+    unsigned long tv_sec;
+    unsigned long tv_nsec;
+};
+#endif /* HAVE_LIBPTHREAD */
 
-static inline int gettimeofday(struct timeval *tv, void * tz)
-{
-    do_gettimeofday(tv);
-    return 0;
-}
+#include "../user-time.h"
+
+/* liblustre. time(2) based implementation. */
+int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
+void sleep(int time);
+void do_gettimeofday(struct timeval *tv);
+int gettimeofday(struct timeval *tv, void * tz);
 
-#endif /* __KERNEL__ */
+#endif /* !__KERNEL__ */
 
 /* __LIBCFS_LINUX_LINUX_TIME_H__ */
 #endif
index a87ec81..95660e1 100644 (file)
 #ifdef __KERNEL__
 
 #include <ntifs.h>
+#include <basetsd.h>
 #include <windef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
-
 #include <tdi.h>
 #include <tdikrnl.h>
 #include <tdiinfo.h>
 
 #else
 
-#include <ntddk.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <ntddk.h>
 #include <stdarg.h>
-#include <time.h>
 #include <io.h>
+#include <time.h>
 #include <string.h>
 #include <assert.h>
-
 #endif
 
 
 #define __LITTLE_ENDIAN
+#define __user
 
 #define inline     __inline
 #define __inline__ __inline
 
-typedef unsigned __int8     __u8;
-typedef signed   __int8     __s8;
-
-typedef signed   __int64    __s64;
-typedef unsigned __int64    __u64;
+typedef unsigned __int8         __u8;
+typedef signed   __int8         __s8;
 
 typedef        signed   __int16        __s16;
 typedef        unsigned __int16        __u16;
@@ -87,19 +84,7 @@ typedef      unsigned __int32        __u32;
 typedef        signed   __int64        __s64;
 typedef        unsigned __int64        __u64;
 
-typedef unsigned long       ULONG;
-
-
-#if defined(_WIN64)
-    #define long_ptr        __int64
-    #define ulong_ptr       unsigned __int64
-    #define BITS_PER_LONG   (64)
-#else
-    #define long_ptr        long
-    #define ulong_ptr       unsigned long
-    #define BITS_PER_LONG   (32)
-
-#endif
+typedef unsigned long           ULONG;
 
 /* bsd */
 typedef unsigned char          u_char;
@@ -123,6 +108,11 @@ typedef            __s16           int16_t;
 typedef                __u32           u_int32_t;
 typedef                __s32           int32_t;
 
+#define    u8           __u8
+#define    u16          __u16
+#define    u32          __u32
+#define    u64          __u64
+
 #endif /* !(__BIT_TYPES_DEFINED__) */
 
 typedef                __u8            uint8_t;
@@ -133,72 +123,99 @@ typedef           __u64           uint64_t;
 typedef                __u64           u_int64_t;
 typedef                __s64           int64_t;
 
-typedef long            ssize_t;
+typedef     long        ssize_t;
 
-typedef __u32           suseconds_t;
+typedef     __u32       suseconds_t;
 
-typedef __u32           pid_t, tid_t;
+typedef     __u16       uid_t, gid_t;
 
-typedef __u16           uid_t, gid_t;
+typedef     __u16       mode_t;
+typedef     __u16       umode_t;
 
-typedef __u16           mode_t;
-typedef __u16           umode_t;
+typedef     __u32       sigset_t;
 
-typedef ulong_ptr       sigset_t;
-
-typedef uint64_t        loff_t;
-typedef HANDLE          cfs_handle_t;
+typedef int64_t         loff_t;
+typedef void *          cfs_handle_t;
 typedef uint64_t        cycles_t;
 
 #ifndef INVALID_HANDLE_VALUE
 #define INVALID_HANDLE_VALUE ((HANDLE)-1)
 #endif
 
+# define BITS_PER_LONG   (32)
+
+#if defined(_WIN64)
+typedef  __int64  long_ptr_t;
+typedef  unsigned __int64 ulong_ptr_t;
+#else
+typedef long long_ptr_t;
+typedef unsigned long ulong_ptr_t;
+#endif
 
 #ifdef __KERNEL__ /* kernel */
 
 typedef __u32           off_t;
-typedef __u32           time_t;
 
 typedef unsigned short  kdev_t;
 
-#else  /* !__KERNEL__ */
+typedef __u32           pid_t;
+typedef __u32           tid_t;
 
-typedef int             BOOL;
-typedef __u8            BYTE;
-typedef __u16           WORD;
-typedef __u32           DWORD;
+typedef __u32           ino_t;
 
-#endif /* __KERNEL__ */
+#define dma_addr_t      PVOID
+#define gfp_t           __u32
 
 /*
- * Conastants suffix
+ *  Bytes order 
  */
 
-#define ULL i64
-#define ull i64
+//
+// Byte order swapping routines
+//
 
-/*
- * Winnt kernel has no capabilities.
- */
+#if 0 && NTDDI_VERSION < 0x06000000
+
+USHORT
+FASTCALL
+RtlUshortByteSwap(
+    IN USHORT Source
+    );
+
+ULONG
+FASTCALL
+RtlUlongByteSwap(
+    IN ULONG Source
+    );
+
+ULONGLONG
+FASTCALL
+RtlUlonglongByteSwap(
+    IN ULONGLONG Source
+    );
+#endif
 
-typedef __u32 cfs_kernel_cap_t;
+#else  /* !__KERNEL__ */
 
-#define INT_MAX         ((int)(~0U>>1))
-#define INT_MIN         (-INT_MAX - 1)
-#define UINT_MAX        (~0U)
+typedef int             BOOL;
 
-#endif /* _WINNT_TYPES_H */
+#ifndef _WINDOWS_
+typedef __u8            BYTE;
+typedef __u16           WORD;
+typedef __u32           DWORD;
+#endif
+
+#define __WORDSIZE 32
+typedef long            off_t;
 
+#endif /* __KERNEL__ */
 
 /*
- *  Bytes order 
+ * Conastants suffix
  */
 
-//
-// Byte order swapping routines
-//
-
+#define ULL i64
+#define ull i64
 
 #define ___swab16(x) RtlUshortByteSwap(x)
 #define ___swab32(x) RtlUlongByteSwap(x)
@@ -218,14 +235,14 @@ typedef __u32 cfs_kernel_cap_t;
 
 #define ___constant_swab64(x) \
        ((__u64)( \
-               (__u64)(((__u64)(x) & (__u64)0x00000000000000ffUL) << 56) | \
-               (__u64)(((__u64)(x) & (__u64)0x000000000000ff00UL) << 40) | \
-               (__u64)(((__u64)(x) & (__u64)0x0000000000ff0000UL) << 24) | \
-               (__u64)(((__u64)(x) & (__u64)0x00000000ff000000UL) <<  8) | \
-               (__u64)(((__u64)(x) & (__u64)0x000000ff00000000UL) >>  8) | \
-               (__u64)(((__u64)(x) & (__u64)0x0000ff0000000000UL) >> 24) | \
-               (__u64)(((__u64)(x) & (__u64)0x00ff000000000000UL) >> 40) | \
-               (__u64)(((__u64)(x) & (__u64)0xff00000000000000UL) >> 56) ))
+               (__u64)(((__u64)(x) & (__u64)0x00000000000000ffUi64) << 56) | \
+               (__u64)(((__u64)(x) & (__u64)0x000000000000ff00Ui64) << 40) | \
+               (__u64)(((__u64)(x) & (__u64)0x0000000000ff0000Ui64) << 24) | \
+               (__u64)(((__u64)(x) & (__u64)0x00000000ff000000Ui64) <<  8) | \
+               (__u64)(((__u64)(x) & (__u64)0x000000ff00000000Ui64) >>  8) | \
+               (__u64)(((__u64)(x) & (__u64)0x0000ff0000000000Ui64) >> 24) | \
+               (__u64)(((__u64)(x) & (__u64)0x00ff000000000000Ui64) >> 40) | \
+               (__u64)(((__u64)(x) & (__u64)0xff00000000000000Ui64) >> 56) ))
 
 
 #define __swab16(x)  ___constant_swab16(x)
@@ -347,15 +364,23 @@ typedef __u32 cfs_kernel_cap_t;
 #define htons(x)           ntohs(x)
 
 
+/*
+ *  array must be used for array not pointer
+ */
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+#endif /* _WINNT_TYPES_H */
 
 #ifndef _I386_ERRNO_H
 #define _I386_ERRNO_H
 
+#include <errno.h>
+
 #define        EPERM            1      /* Operation not permitted */
 #define        ENOENT           2      /* No such file or directory */
 #define        ESRCH            3      /* No such process */
 #define        EINTR            4      /* Interrupted system call */
-#define        EIO                  5  /* I/O error */
+#define        EIO                      5      /* I/O error */
 #define        ENXIO            6      /* No such device or address */
 #define        E2BIG            7      /* Arg list too long */
 #define        ENOEXEC          8      /* Exec format error */
@@ -385,16 +410,6 @@ typedef __u32 cfs_kernel_cap_t;
 #define        EPIPE           32      /* Broken pipe */
 #define        EDOM            33      /* Math argument out of domain of func */
 #define        ERANGE          34      /* Math result not representable */
-#undef EDEADLK
-#define        EDEADLK         35      /* Resource deadlock would occur */
-#undef ENAMETOOLONG
-#define        ENAMETOOLONG    36      /* File name too long */
-#undef ENOLCK
-#define        ENOLCK          37      /* No record locks available */
-#undef ENOSYS
-#define        ENOSYS          38      /* Function not implemented */
-#undef ENOTEMPTY
-#define        ENOTEMPTY       39      /* Directory not empty */
 #define        ELOOP           40      /* Too many symbolic links encountered */
 #define        EWOULDBLOCK     EAGAIN  /* Operation would block */
 #define        ENOMSG          42      /* No message of desired type */
@@ -441,8 +456,6 @@ typedef __u32 cfs_kernel_cap_t;
 #define        ELIBSCN         81      /* .lib section in a.out corrupted */
 #define        ELIBMAX         82      /* Attempting to link in too many shared libraries */
 #define        ELIBEXEC        83      /* Cannot exec a shared library directly */
-#undef EILSEQ
-#define        EILSEQ          84      /* Illegal byte sequence */
 #define        ERESTART        85      /* Interrupted system call should be restarted */
 #define        ESTRPIPE        86      /* Streams pipe error */
 #define        EUSERS          87      /* Too many users */
@@ -501,8 +514,6 @@ typedef __u32 cfs_kernel_cap_t;
 #define EBADTYPE       527     /* Type not supported by server */
 #define EJUKEBOX       528     /* Request initiated, but will not complete before timeout */
 
-
-
 /* open/fcntl - O_SYNC is only implemented on blocks devices and on files
    located on an ext2 file system */
 #define O_ACCMODE         0003
@@ -578,6 +589,7 @@ typedef __u32 cfs_kernel_cap_t;
  *  signal values ...
  */
 
+#ifdef __KERNEL__
 #define SIGHUP          1
 #define SIGINT          2
 #define SIGQUIT                 3
@@ -620,6 +632,8 @@ typedef __u32 cfs_kernel_cap_t;
 #define SIGRTMIN       32
 #define SIGRTMAX       (_NSIG-1)
 
+#endif
+
 /*
  * SA_FLAGS values:
  *
index 7c0095d..8cf3c80 100644 (file)
@@ -68,6 +68,7 @@ int tracefile_init_arch() {
 }
 
 void tracefile_fini_arch() {
+    fini_rwsem(&tracefile_sem);
 }
 
 void tracefile_read_lock() {
index 12ec7a9..23b1b78 100644 (file)
@@ -112,13 +112,8 @@ EXPORT_SYMBOL(libcfs_kmemory);
 
 static cfs_waitq_t debug_ctlwq;
 
-#ifdef HAVE_BGL_SUPPORT
-char debug_file_path_arr[1024] = "/bgl/ion/tmp/lustre-log";
-#elif defined(__arch_um__)
-char debug_file_path_arr[1024] = "/r/tmp/lustre-log";
-#else
-char debug_file_path_arr[1024] = "/tmp/lustre-log";
-#endif
+char debug_file_path_arr[1024] = DEBUG_FILE_PATH_DEFAULT;
+
 /* We need to pass a pointer here, but elsewhere this must be a const */
 static char *debug_file_path = &debug_file_path_arr[0];
 CFS_MODULE_PARM(debug_file_path, "s", charp, 0644,
@@ -429,8 +424,8 @@ void libcfs_debug_dumplog_internal(void *arg)
 
         if (strncmp(debug_file_path_arr, "NONE", 4) != 0) {
                 snprintf(debug_file_name, sizeof(debug_file_name) - 1,
-                         "%s.%ld.%ld", debug_file_path_arr,
-                         cfs_time_current_sec(), (long)arg);
+                         "%s.%ld." LPLD, debug_file_path_arr,
+                         cfs_time_current_sec(), (long_ptr_t)arg);
                 printk(KERN_ALERT "LustreError: dumping log to %s\n",
                        debug_file_name);
                 tracefile_dump_all_pages(debug_file_name);
@@ -461,7 +456,7 @@ void libcfs_debug_dumplog(void)
         cfs_waitq_add(&debug_ctlwq, &wait);
 
         rc = cfs_kernel_thread(libcfs_debug_dumplog_thread,
-                               (void *)(long)cfs_curproc_pid(),
+                               (void *)(long_ptr_t)cfs_curproc_pid(),
                                CLONE_VM | CLONE_FS | CLONE_FILES);
         if (rc < 0)
                 printk(KERN_ERR "LustreError: cannot start log dump thread: "
index 6029352..6111060 100644 (file)
@@ -124,6 +124,8 @@ void tracefile_fini_arch()
                kfree(trace_data[i]);
                trace_data[i] = NULL;
        }
+
+       fini_rwsem(&tracefile_sem);
 }
 
 void tracefile_read_lock()
index 325785b..c8ca37b 100644 (file)
 # define EXPORT_SYMTAB
 #endif
 
-#ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
-#endif
-#include <linux/module.h>
-#include <linux/kmod.h>
-#include <linux/kernel.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/string.h>
-#include <linux/stat.h>
-#include <linux/errno.h>
-#include <linux/smp_lock.h>
-#include <linux/unistd.h>
-#include <linux/interrupt.h>
-#include <asm/system.h>
-#include <asm/uaccess.h>
-
 #define DEBUG_SUBSYSTEM S_LNET
 
 #include <libcfs/libcfs.h>
index 5918560..2fff7fb 100644 (file)
@@ -319,7 +319,8 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *a
                 struct libcfs_ioctl_handler *hand;
                 err = -EINVAL;
                 down_read(&ioctl_list_sem);
-                list_for_each_entry(hand, &ioctl_list, item) {
+                cfs_list_for_each_entry_typed(hand, &ioctl_list,
+                        struct libcfs_ioctl_handler, item) {
                         err = hand->handle_ioctl(cmd, data);
                         if (err != -EINVAL) {
                                 if (err == 0)
@@ -432,6 +433,10 @@ static void exit_libcfs_module(void)
         rc = libcfs_debug_cleanup();
         if (rc)
                 printk(KERN_ERR "LustreError: libcfs_debug_cleanup: %d\n", rc);
+
+        fini_rwsem(&ioctl_list_sem);
+        fini_rwsem(&tracefile_sem);
+
         libcfs_arch_cleanup();
 }
 
index 9cf58b4..df02584 100644 (file)
@@ -479,7 +479,7 @@ libcfs_str2nid(const char *str)
                 LASSERT (nf != NULL);
         }
 
-        if (!nf->nf_str2addr(str, sep - str, &addr))
+        if (!nf->nf_str2addr(str, (int)(sep - str), &addr))
                 return LNET_NID_ANY;
 
         return LNET_MKNID(net, addr);
index 15f70de..5b9543e 100644 (file)
@@ -195,7 +195,8 @@ static void tcd_shrink(struct trace_cpu_data *tcd)
         CFS_INIT_LIST_HEAD(&pc.pc_pages);
         spin_lock_init(&pc.pc_lock);
 
-        list_for_each_entry_safe(tage, tmp, &tcd->tcd_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &tcd->tcd_pages, 
+                                           struct trace_page, linkage) {
                 if (pgcount-- == 0)
                         break;
 
@@ -537,7 +538,8 @@ static void put_pages_back_on_cpu(void *info)
         tcd_for_each_type_lock(tcd, i) {
                 cur_head = tcd->tcd_pages.next;
 
-                list_for_each_entry_safe(tage, tmp, &pc->pc_pages, linkage) {
+                cfs_list_for_each_entry_safe_typed(tage, tmp, &pc->pc_pages,
+                                                   struct trace_page, linkage) {
 
                         __LASSERT_TAGE_INVARIANT(tage);
 
@@ -568,7 +570,8 @@ static void put_pages_on_tcd_daemon_list(struct page_collection *pc,
         struct trace_page *tmp;
 
         spin_lock(&pc->pc_lock);
-        list_for_each_entry_safe(tage, tmp, &pc->pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc->pc_pages,
+                                           struct trace_page, linkage) {
 
                 __LASSERT_TAGE_INVARIANT(tage);
 
@@ -619,7 +622,8 @@ void trace_debug_print(void)
 
         pc.pc_want_daemon_pages = 1;
         collect_pages(&pc);
-        list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                           struct trace_page, linkage) {
                 char *p, *file, *fn;
                 cfs_page_t *page;
 
@@ -636,7 +640,7 @@ void trace_debug_print(void)
                         p += strlen(file) + 1;
                         fn = p;
                         p += strlen(fn) + 1;
-                        len = hdr->ph_len - (p - (char *)hdr);
+                        len = hdr->ph_len - (int)(p - (char *)hdr);
 
                         print_to_console(hdr, D_EMERG, p, len, file, fn);
 
@@ -680,7 +684,8 @@ int tracefile_dump_all_pages(char *filename)
         /* ok, for now, just write the pages.  in the future we'll be building
          * iobufs with the pages and calling generic_direct_IO */
         CFS_MMSPACE_OPEN;
-        list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                           struct trace_page, linkage) {
 
                 __LASSERT_TAGE_INVARIANT(tage);
 
@@ -717,7 +722,8 @@ void trace_flush_pages(void)
 
         pc.pc_want_daemon_pages = 1;
         collect_pages(&pc);
-        list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+        cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                           struct trace_page, linkage) {
 
                 __LASSERT_TAGE_INVARIANT(tage);
 
@@ -997,14 +1003,15 @@ static int tracefiled(void *arg)
                 hdr = cfs_page_address(tage->page);
                 hdr->ph_flags |= PH_FLAG_FIRST_RECORD;
 
-                list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+                cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
+                                                   struct trace_page, linkage) {
                         static loff_t f_pos;
 
                         __LASSERT_TAGE_INVARIANT(tage);
 
                         if (f_pos >= (off_t)tracefile_size)
                                 f_pos = 0;
-                        else if (f_pos > cfs_filp_size(filp))
+                        else if (f_pos > (off_t)cfs_filp_size(filp))
                                 f_pos = cfs_filp_size(filp);
 
                         rc = cfs_filp_write(filp, cfs_page_address(tage->page),
@@ -1105,7 +1112,8 @@ static void trace_cleanup_on_cpu(void *info)
         tcd_for_each_type_lock(tcd, i) {
                 tcd->tcd_shutting_down = 1;
 
-                list_for_each_entry_safe(tage, tmp, &tcd->tcd_pages, linkage) {
+                cfs_list_for_each_entry_safe_typed(tage, tmp, &tcd->tcd_pages,
+                                                   struct trace_page, linkage) {
                         __LASSERT_TAGE_INVARIANT(tage);
 
                         list_del(&tage->linkage);
index dd25327..7faf803 100644 (file)
@@ -265,21 +265,21 @@ extern void trace_assertion_failed(const char *str, const char *fn,
                                   const char *file, int line);
 
 /* ASSERTION that is safe to use within the debug system */
-#define __LASSERT(cond)                                                                \
-({                                                                             \
-       if (unlikely(!(cond))) {                                                \
-                trace_assertion_failed("ASSERTION("#cond") failed",            \
-                                      __FUNCTION__, __FILE__, __LINE__);       \
-       }                                                                       \
-})
-
-#define __LASSERT_TAGE_INVARIANT(tage)                 \
-({                                                     \
-        __LASSERT(tage != NULL);                       \
-        __LASSERT(tage->page != NULL);                 \
-        __LASSERT(tage->used <= CFS_PAGE_SIZE);                \
-        __LASSERT(cfs_page_count(tage->page) > 0);     \
-})
+#define __LASSERT(cond)                                                 \
+    do {                                                                \
+        if (unlikely(!(cond))) {                                        \
+                trace_assertion_failed("ASSERTION("#cond") failed",     \
+                                 __FUNCTION__, __FILE__, __LINE__);     \
+        }                                                               \
+    } while (0)
+
+#define __LASSERT_TAGE_INVARIANT(tage)                                  \
+    do {                                                                \
+        __LASSERT(tage != NULL);                                        \
+        __LASSERT(tage->page != NULL);                                  \
+        __LASSERT(tage->used <= CFS_PAGE_SIZE);                         \
+        __LASSERT(cfs_page_count(tage->page) > 0);                      \
+    } while (0)
 
 #endif /* LUSTRE_TRACEFILE_PRIVATE */
 
index 53ab2c4..cee36d7 100644 (file)
@@ -246,6 +246,12 @@ void up_write(struct rw_semaphore *s)
         (void)s;
 }
 
+void fini_rwsem(struct rw_semaphore *s)
+{
+        LASSERT(s != NULL);
+        (void)s;
+}
+
 #ifdef HAVE_LIBPTHREAD
 
 /*
index 7c2cc4d..1140159 100644 (file)
@@ -63,6 +63,8 @@ cfs_page_t *cfs_alloc_pages(int mask, unsigned long order)
         pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
 #elif defined (__DARWIN__)
         pg->addr = valloc(CFS_PAGE_SIZE << order);
+#elif defined (__WINNT__)
+        pg->addr = pgalloc(order);
 #else
         pg->addr = memalign(CFS_PAGE_SIZE, CFS_PAGE_SIZE << order);
 #endif
@@ -78,6 +80,8 @@ void cfs_free_pages(cfs_page_t *pg, int what)
 {
 #if 0 //#ifdef MAP_ANONYMOUS
         munmap(pg->addr, PAGE_SIZE);
+#elif defined (__WINNT__)
+        pgfree(pg->addr);
 #else
         free(pg->addr);
 #endif
index 07678e0..ee381d6 100644 (file)
@@ -156,22 +156,13 @@ void cfs_timer_init(cfs_timer_t *l, cfs_timer_func_t *func, void *arg)
 {
         CFS_INIT_LIST_HEAD(&l->tl_list);
         l->function = func;
-        l->data = (unsigned long)arg;
+        l->data = (ulong_ptr_t)arg;
         return;
 }
 
-#define cfs_jiffies                             \
-({                                              \
-        unsigned long _ret = 0;                 \
-        struct timeval tv;                      \
-        if (gettimeofday(&tv, NULL) == 0)       \
-                _ret = tv.tv_sec;               \
-        _ret;                                   \
-})
-
 int cfs_timer_is_armed(cfs_timer_t *l)
 {
-        if (cfs_time_before(cfs_jiffies, l->expires))
+        if (cfs_time_before(cfs_time_current(), l->expires))
                 return 1;
         else
                 return 0;
@@ -185,8 +176,7 @@ void cfs_timer_arm(cfs_timer_t *l, cfs_time_t deadline)
 void cfs_timer_disarm(cfs_timer_t *l)
 {
 }
-
-long cfs_timer_deadline(cfs_timer_t *l)
+cfs_time_t cfs_timer_deadline(cfs_timer_t *l)
 {
         return l->expires;
 }
@@ -247,7 +237,7 @@ int cfs_parse_int_tunable(int *value, char *name)
         if (env == NULL)
                 return 0;
 
-        *value = strtoull(env, &end, 0);
+        *value = (int)strtoull(env, &end, 0);
         if (*end == 0)
                 return 0;
 
index a78ddde..9dcf4b5 100644 (file)
@@ -528,6 +528,11 @@ libcfs_sock_create(int *fdp)
         return 0;
 }
 
+void libcfs_sock_release(int fd)
+{
+        close(fd);
+}
+
 int
 libcfs_sock_bind_to_port(int fd, __u16 port)
 {
index 59dc6d8..bc7e6a1 100644 (file)
@@ -23,7 +23,6 @@
 #define __USE_FILE_OFFSET64
 
 #include <libcfs/libcfsutil.h>
-
 #include <lnet/api-support.h>
 #include <lnet/lnetctl.h>
 
@@ -77,15 +76,15 @@ open_ioc_dev(int dev_id)
         }
 
         if (ioc_dev_list[dev_id].dev_fd < 0) {
-                int fd = open(dev_name, O_RDWR);
+                int fd = cfs_proc_open((char *)dev_name, O_RDWR);
 
                 /* Make the /dev/ node if we need to */
                 if (fd < 0 && errno == ENOENT) {
-                        if (mknod(dev_name, 
+                        if (cfs_proc_mknod(dev_name, 
                                   S_IFCHR|S_IWUSR|S_IRUSR,
                                   MKDEV(ioc_dev_list[dev_id].dev_major,
                                         ioc_dev_list[dev_id].dev_minor)) == 0)
-                                fd = open(dev_name, O_RDWR);
+                                fd = cfs_proc_open((char *)dev_name, O_RDWR);
                         else
                                 fprintf(stderr, "mknod %s failed: %s\n",
                                         dev_name, strerror(errno));
@@ -113,7 +112,7 @@ do_ioctl(int dev_id, unsigned int opc, void *buf)
         if (fd < 0) 
                 return fd;
 
-        rc = ioctl(fd, opc, buf);
+        rc = cfs_proc_ioctl(fd, opc, buf);
         return rc;
         
 }
@@ -197,7 +196,7 @@ unregister_ioc_dev(int dev_id)
                 return;
         if (ioc_dev_list[dev_id].dev_name != NULL &&
             ioc_dev_list[dev_id].dev_fd >= 0) 
-                close(ioc_dev_list[dev_id].dev_fd);
+                cfs_proc_close(ioc_dev_list[dev_id].dev_fd);
 
         ioc_dev_list[dev_id].dev_name = NULL;
         ioc_dev_list[dev_id].dev_fd = -1;
@@ -237,16 +236,53 @@ int
 parse_dump(char * dump_file, ioc_handler_t ioc_func)
 {
         int line =0;
-        struct stat st;
         char *start, *buf, *end;
-#ifndef __CYGWIN__
-        int fd;
-#else
+
+#if defined(__CYGWIN__) || defined(__WINNT__)
+
         HANDLE fd, hmap;
         DWORD size;
-#endif
-        
-#ifndef __CYGWIN__
+
+        fd = CreateFile(dump_file, GENERIC_READ, FILE_SHARE_READ, NULL,
+                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+        if (fd == INVALID_HANDLE_VALUE) {
+                fprintf(stderr, "couldn't open %s (error code: %u)\n",
+                                dump_file, GetLastError());
+                exit(1);
+        }
+        size = GetFileSize(fd, NULL);
+        if (size < 1 || size == 0xFFFFFFFF) {
+                fprintf(stderr, "KML is empty\n");
+                CloseHandle(fd);
+                exit(1);
+        }
+
+        hmap = CreateFileMapping(fd, NULL, PAGE_READONLY, 0,0, NULL);
+        if (hmap == NULL) {
+                fprintf(stderr, "can't create file mapping\n");
+                CloseHandle(fd);
+                exit(1);
+        }
+        start = buf = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0);
+        if (start == NULL) {
+                fprintf(stderr, "can't map file content\n");
+                CloseHandle(hmap);
+                CloseHandle(fd);
+                exit(1);
+        }
+        end = buf + size;
+        CloseHandle(fd);
+        if (start == NULL) {
+                fprintf(stderr, "can't create file mapping\n");
+                UnmapViewOfFile(start);
+                CloseHandle(hmap);
+                exit(1);
+        }
+#else
+
+        struct stat st;
+        int fd;
+
         fd = open(dump_file, O_RDONLY);
         if (fd < 0) {
                 fprintf(stderr, "couldn't open %s: %s\n", dump_file, 
@@ -271,24 +307,7 @@ parse_dump(char * dump_file, ioc_handler_t ioc_func)
                 fprintf(stderr, "can't create file mapping\n");
                 exit(1);
         }
-#else
-        fd = CreateFile(dump_file, GENERIC_READ, FILE_SHARE_READ, NULL,
-                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-        size = GetFileSize(fd, NULL);
-        if (size < 1) {
-                fprintf(stderr, "KML is empty\n");
-                exit(1);
-        }
-
-        hmap = CreateFileMapping(fd, NULL, PAGE_READONLY, 0,0, NULL);
-        start = buf = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0);
-        end = buf + size;
-        CloseHandle(fd);
-        if (start == NULL) {
-                fprintf(stderr, "can't create file mapping\n");
-                exit(1);
-        }
-#endif /* __CYGWIN__ */
+#endif
 
         while (buf < end) {
                 struct dump_hdr *dump_hdr = (struct dump_hdr *) buf;
@@ -323,11 +342,11 @@ parse_dump(char * dump_file, ioc_handler_t ioc_func)
                 buf += data->ioc_len + sizeof(*dump_hdr);
         }
 
-#ifndef __CYGWIN__
-        munmap(start, end - start);
-#else
+#if defined(__CYGWIN__) || defined(__WINNT__)
         UnmapViewOfFile(start);
         CloseHandle(hmap);
+#else
+        munmap(start, end - start);
 #endif
 
         return 0;
index ce2a99e..dbb3e92 100644 (file)
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <sys/param.h>
-#include <assert.h>
 
 #include <libcfs/libcfsutil.h>
 
@@ -137,7 +129,7 @@ static command_t * find_cmd(char * name, command_t cmds[], char ** next)
            this with strtok*/
         name = skipwhitespace(name);
         *next = skiptowhitespace(name);
-        len = *next - name;
+        len = (int)(*next - name);
         if (len == 0)
                 return NULL;
 
@@ -343,7 +335,7 @@ char * readline(char * prompt)
                 if ((c = fgetc(stdin)) != EOF) {
                         if (c == '\n')
                                 goto out;
-                        *ptr++ = c;
+                        *ptr++ = (char)c;
 
                         if (ptr - line >= size - 1) {
                                 char *tmp;
index 7cfbe1e..6c90188 100644 (file)
@@ -70,7 +70,7 @@ struct lc_watchdog {
  */
 static struct completion lcw_start_completion;
 static struct completion lcw_stop_completion;
-static wait_queue_head_t lcw_event_waitq;
+static cfs_waitq_t lcw_event_waitq;
 
 /*
  * Set this and wake lcw_event_waitq to stop the dispatcher.
@@ -94,7 +94,7 @@ static DECLARE_MUTEX(lcw_refcount_sem);
  */
 static spinlock_t lcw_pending_timers_lock = SPIN_LOCK_UNLOCKED; /* BH lock! */
 static struct list_head lcw_pending_timers = \
-        LIST_HEAD_INIT(lcw_pending_timers);
+        CFS_LIST_HEAD_INIT(lcw_pending_timers);
 
 #ifdef HAVE_TASKLIST_LOCK
 static void
@@ -107,11 +107,11 @@ lcw_dump(struct lc_watchdog *lcw)
         tsk = find_task_by_pid(lcw->lcw_pid);
 
         if (tsk == NULL) {
-                CWARN("Process %d was not found in the task list; "
-                      "watchdog callback may be incomplete\n", (int)lcw->lcw_pid);
+                CWARN("Process " LPPID " was not found in the task list; "
+                      "watchdog callback may be incomplete\n", lcw->lcw_pid);
         } else if (tsk != lcw->lcw_task) {
-                CWARN("The current process %d did not set the watchdog; "
-                      "watchdog callback may be incomplete\n", (int)lcw->lcw_pid);
+                CWARN("The current process " LPPID " did not set the watchdog; "
+                      "watchdog callback may be incomplete\n", lcw->lcw_pid);
         } else {
                 libcfs_debug_dumpstack(tsk);
         }
@@ -127,7 +127,7 @@ lcw_dump(struct lc_watchdog *lcw)
 }
 #endif
 
-static void lcw_cb(unsigned long data)
+static void lcw_cb(ulong_ptr_t data)
 {
         struct lc_watchdog *lcw = (struct lc_watchdog *)data;
 
@@ -143,15 +143,15 @@ static void lcw_cb(unsigned long data)
         /* NB this warning should appear on the console, but may not get into
          * the logs since we're running in a softirq handler */
 
-        CWARN("Watchdog triggered for pid %d: it was inactive for %lds\n",
-              (int)lcw->lcw_pid, cfs_duration_sec(lcw->lcw_time));
+        CWARN("Watchdog triggered for pid: " LPPID " it was inactive for %lds\n",
+              lcw->lcw_pid, cfs_duration_sec(lcw->lcw_time));
         lcw_dump(lcw);
 
         spin_lock_bh(&lcw_pending_timers_lock);
 
         if (list_empty(&lcw->lcw_list)) {
                 list_add(&lcw->lcw_list, &lcw_pending_timers);
-                wake_up(&lcw_event_waitq);
+                cfs_waitq_signal(&lcw_event_waitq);
         }
 
         spin_unlock_bh(&lcw_pending_timers_lock);
@@ -190,7 +190,7 @@ static int lcw_dispatch_main(void *data)
         complete(&lcw_start_completion);
 
         while (1) {
-                wait_event_interruptible(lcw_event_waitq, is_watchdog_fired());
+                cfs_wait_event_interruptible(lcw_event_waitq, is_watchdog_fired(), rc);
                 CDEBUG(D_INFO, "Watchdog got woken up...\n");
                 if (test_bit(LCW_FLAG_STOP, &lcw_flags)) {
                         CDEBUG(D_INFO, "LCW_FLAG_STOP was set, shutting down...\n");
@@ -214,9 +214,8 @@ static int lcw_dispatch_main(void *data)
                         list_del_init(&lcw->lcw_list);
                         spin_unlock_bh(&lcw_pending_timers_lock);
 
-                        CDEBUG(D_INFO, "found lcw for pid %d: inactive for "
-                               "%lds\n", (int)lcw->lcw_pid,
-                               cfs_duration_sec(lcw->lcw_time));
+                        CDEBUG(D_INFO, "found lcw for pid " LPPID ": inactive for "
+                               "%lds\n", lcw->lcw_pid, cfs_duration_sec(lcw->lcw_time));
 
                         if (lcw->lcw_state != LC_WATCHDOG_DISABLED)
                                 lcw->lcw_callback(lcw->lcw_pid, lcw->lcw_data);
@@ -240,7 +239,7 @@ static void lcw_dispatch_start(void)
 
         init_completion(&lcw_stop_completion);
         init_completion(&lcw_start_completion);
-        init_waitqueue_head(&lcw_event_waitq);
+        cfs_waitq_init(&lcw_event_waitq);
 
         CDEBUG(D_INFO, "starting dispatch thread\n");
         rc = kernel_thread(lcw_dispatch_main, NULL, 0);
@@ -263,7 +262,7 @@ static void lcw_dispatch_stop(void)
         CDEBUG(D_INFO, "trying to stop watchdog dispatcher.\n");
 
         set_bit(LCW_FLAG_STOP, &lcw_flags);
-        wake_up(&lcw_event_waitq);
+        cfs_waitq_signal(&lcw_event_waitq);
 
         wait_for_completion(&lcw_stop_completion);
 
@@ -292,12 +291,8 @@ struct lc_watchdog *lc_watchdog_add(int timeout_ms,
         lcw->lcw_data     = data;
         lcw->lcw_state    = LC_WATCHDOG_DISABLED;
 
-        INIT_LIST_HEAD(&lcw->lcw_list);
-
-        lcw->lcw_timer.function = lcw_cb;
-        lcw->lcw_timer.data = (unsigned long)lcw;
-        lcw->lcw_timer.expires = jiffies + lcw->lcw_time;
-        init_timer(&lcw->lcw_timer);
+        CFS_INIT_LIST_HEAD(&lcw->lcw_list);
+        cfs_timer_init(&lcw->lcw_timer, lcw_cb, lcw);
 
         down(&lcw_refcount_sem);
         if (++lcw_refcount == 1)
@@ -307,7 +302,8 @@ struct lc_watchdog *lc_watchdog_add(int timeout_ms,
         /* Keep this working in case we enable them by default */
         if (lcw->lcw_state == LC_WATCHDOG_ENABLED) {
                 do_gettimeofday(&lcw->lcw_last_touched);
-                add_timer(&lcw->lcw_timer);
+                cfs_timer_arm(&lcw->lcw_timer, lcw->lcw_time + 
+                              cfs_time_current());
         }
 
         RETURN(lcw);
@@ -322,7 +318,7 @@ static void lcw_update_time(struct lc_watchdog *lcw, const char *message)
         do_gettimeofday(&newtime);
         if (lcw->lcw_state == LC_WATCHDOG_EXPIRED) {
                 cfs_timeval_sub(&newtime, &lcw->lcw_last_touched, &timediff);
-                CWARN("Expired watchdog for pid %d %s after %lu.%.4lus\n",
+                CWARN("Expired watchdog for pid " LPPID " %s after %lu.%.4lus\n",
                       lcw->lcw_pid,
                       message,
                       timediff.tv_sec,
@@ -343,8 +339,8 @@ void lc_watchdog_touch_ms(struct lc_watchdog *lcw, int timeout_ms)
         lcw_update_time(lcw, "touched");
         lcw->lcw_state = LC_WATCHDOG_ENABLED;
 
-        mod_timer(&lcw->lcw_timer, jiffies +
-                  cfs_time_seconds(timeout_ms) / 1000);
+        cfs_timer_arm(&lcw->lcw_timer, cfs_time_current() +
+                      cfs_time_seconds(timeout_ms) / 1000);
 
         EXIT;
 }
@@ -353,7 +349,7 @@ EXPORT_SYMBOL(lc_watchdog_touch_ms);
 /* deprecated - use above instead */
 void lc_watchdog_touch(struct lc_watchdog *lcw)
 {
-        lc_watchdog_touch_ms(lcw, cfs_duration_sec(lcw->lcw_time) * 1000);
+        lc_watchdog_touch_ms(lcw, (int)cfs_duration_sec(lcw->lcw_time) * 1000);
 }
 EXPORT_SYMBOL(lc_watchdog_touch);
 
@@ -379,7 +375,7 @@ void lc_watchdog_delete(struct lc_watchdog *lcw)
         ENTRY;
         LASSERT(lcw != NULL);
 
-        del_timer(&lcw->lcw_timer);
+        cfs_timer_disarm(&lcw->lcw_timer);
 
         lcw_update_time(lcw, "deleted");
 
@@ -405,7 +401,7 @@ EXPORT_SYMBOL(lc_watchdog_delete);
 
 void lc_watchdog_dumplog(pid_t pid, void *data)
 {
-        libcfs_debug_dumplog_internal((void *)((unsigned long)pid));
+        libcfs_debug_dumplog_internal((void *)((long_ptr_t)pid));
 }
 EXPORT_SYMBOL(lc_watchdog_dumplog);
 
index 7e6f394..93d3af6 100644 (file)
 
 #include <libcfs/libcfs.h>
 
-
 /*
  * Implementation of cfs_curproc API (see portals/include/libcfs/curproc.h)
  * for Linux kernel.
  */
 
-cfs_task_t this_task = 
-    { 0, 0, 0, 0, 0, 0, 0, 
-      0, 0, 0, 0,  1, 0,  0, 0, 0,
-      "sysetm\0" };
+cfs_task_t this_task =
+    { /* umask */ 0,/* blocked*/0, /* pid */ 0, /* pgrp */ 0,
+      /* uid,euid,suid,fsuid */  0, 0, 0, 0, 
+      /* gid_t gid,egid,sgid,fsgid */ 0, 0, 0, 0,
+      /* ngroups*/ 1, /*cgroups*/ 0, /*groups*/ 0,
+      /* group_info */ NULL,
+      /* cap_effective, cap_inheritable, cap_permitted */  0, 0, 0,
+      /* comm */"sysetm\0",
+      /* journal_info */ NULL
+    };
 
 
 uid_t  cfs_curproc_uid(void)
@@ -141,8 +146,10 @@ int cfs_capable(cfs_cap_t cap)
 
 /* global of the task manager structure */
 
-TASK_MAN TaskMan;
+TASK_MAN cfs_win_task_manger;
 
+/* global idr context */
+struct idr_context * cfs_win_task_slot_idp = NULL;
 
 /*
  *  task slot routiens
@@ -153,8 +160,8 @@ alloc_task_slot()
 {
     PTASK_SLOT task = NULL;
 
-    if (TaskMan.slab) {
-        task = cfs_mem_cache_alloc(TaskMan.slab, 0);
+    if (cfs_win_task_manger.slab) {
+        task = cfs_mem_cache_alloc(cfs_win_task_manger.slab, 0);
     } else {
         task = cfs_alloc(sizeof(TASK_SLOT), 0);
     }
@@ -168,16 +175,18 @@ init_task_slot(PTASK_SLOT task)
     memset(task, 0, sizeof(TASK_SLOT));
     task->Magic = TASKSLT_MAGIC;
     task->task  = this_task;
-    task->task.pid = (pid_t)PsGetCurrentThreadId();
     cfs_init_event(&task->Event, TRUE, FALSE);
 }
 
-
 void
 cleanup_task_slot(PTASK_SLOT task)
 {
-    if (TaskMan.slab) {
-        cfs_mem_cache_free(TaskMan.slab, task);
+    if (task->task.pid) {
+        cfs_idr_remove(cfs_win_task_slot_idp, task->task.pid);
+    }
+
+    if (cfs_win_task_manger.slab) {
+        cfs_mem_cache_free(cfs_win_task_manger.slab, task);
     } else {
         cfs_free(task);
     }
@@ -197,25 +206,19 @@ task_manager_notify(
     PLIST_ENTRY ListEntry = NULL; 
     PTASK_SLOT  TaskSlot  = NULL;
 
-    spin_lock(&(TaskMan.Lock));
+    spin_lock(&(cfs_win_task_manger.Lock));
 
-    ListEntry = TaskMan.TaskList.Flink;
-
-    while (ListEntry != (&(TaskMan.TaskList))) {
+    ListEntry = cfs_win_task_manger.TaskList.Flink;
+    while (ListEntry != (&(cfs_win_task_manger.TaskList))) {
 
         TaskSlot = CONTAINING_RECORD(ListEntry, TASK_SLOT, Link);
 
         if (TaskSlot->Pid == ProcessId && TaskSlot->Tid == ThreadId) {
 
-            if (Create) {
-/*
-                DbgPrint("task_manager_notify: Pid=%xh Tid %xh resued (TaskSlot->Tet = %xh)...\n",
-                         ProcessId, ThreadId, TaskSlot->Tet);
-*/
-            } else {
+            if (!Create) {
                 /* remove the taskslot */
                 RemoveEntryList(&(TaskSlot->Link));
-                TaskMan.NumOfTasks--;
+                cfs_win_task_manger.NumOfTasks--;
 
                 /* now free the task slot */
                 cleanup_task_slot(TaskSlot);
@@ -225,7 +228,7 @@ task_manager_notify(
         ListEntry = ListEntry->Flink;
     }
 
-    spin_unlock(&(TaskMan.Lock));
+    spin_unlock(&(cfs_win_task_manger.Lock));
 }
 
 int
@@ -234,24 +237,35 @@ init_task_manager()
     NTSTATUS    status;
 
     /* initialize the content and magic */
-    memset(&TaskMan, 0, sizeof(TASK_MAN));
-    TaskMan.Magic = TASKMAN_MAGIC;
+    memset(&cfs_win_task_manger, 0, sizeof(TASK_MAN));
+    cfs_win_task_manger.Magic = TASKMAN_MAGIC;
 
     /* initialize the spinlock protection */
-    spin_lock_init(&TaskMan.Lock);
+    spin_lock_init(&cfs_win_task_manger.Lock);
 
     /* create slab memory cache */
-    TaskMan.slab = cfs_mem_cache_create(
+    cfs_win_task_manger.slab = cfs_mem_cache_create(
         "TSLT", sizeof(TASK_SLOT), 0, 0);
 
     /* intialize the list header */
-    InitializeListHead(&(TaskMan.TaskList));
+    InitializeListHead(&(cfs_win_task_manger.TaskList));
+
+    cfs_win_task_slot_idp = cfs_idr_init();
+    if (!cfs_win_task_slot_idp) {
+        return -ENOMEM;
+    }
 
     /* set the thread creation/destruction notify routine */
     status = PsSetCreateThreadNotifyRoutine(task_manager_notify);
 
     if (!NT_SUCCESS(status)) {
         cfs_enter_debugger();
+        /* remove idr context */
+        if (cfs_win_task_slot_idp) {
+            cfs_idr_exit(cfs_win_task_slot_idp);
+            cfs_win_task_slot_idp = NULL;
+        }
+        return cfs_error_code(status);
     }
 
     return 0;
@@ -263,28 +277,32 @@ cleanup_task_manager()
     PLIST_ENTRY ListEntry = NULL; 
     PTASK_SLOT  TaskSlot  = NULL;
 
-    /* we must stay in system since we succeed to register the
-       CreateThreadNotifyRoutine: task_manager_notify */
-    cfs_enter_debugger();
+    /* remove ThreadNotifyRoutine: task_manager_notify */
+    PsRemoveCreateThreadNotifyRoutine(task_manager_notify);
 
+    /* remove idr context */
+    if (cfs_win_task_slot_idp) {
+        cfs_idr_exit(cfs_win_task_slot_idp);
+        cfs_win_task_slot_idp = NULL;
+    }
 
     /* cleanup all the taskslots attached to the list */
-    spin_lock(&(TaskMan.Lock));
+    spin_lock(&(cfs_win_task_manger.Lock));
 
-    while (!IsListEmpty(&(TaskMan.TaskList))) {
+    while (!IsListEmpty(&(cfs_win_task_manger.TaskList))) {
 
-        ListEntry = TaskMan.TaskList.Flink;
+        ListEntry = cfs_win_task_manger.TaskList.Flink;
         TaskSlot = CONTAINING_RECORD(ListEntry, TASK_SLOT, Link);
 
         RemoveEntryList(ListEntry);
         cleanup_task_slot(TaskSlot);
     }
 
-    spin_unlock(&TaskMan.Lock);
+    spin_unlock(&cfs_win_task_manger.Lock);
 
     /* destroy the taskslot cache slab */
-    cfs_mem_cache_destroy(TaskMan.slab);
-    memset(&TaskMan, 0, sizeof(TASK_MAN));
+    cfs_mem_cache_destroy(cfs_win_task_manger.slab);
+    memset(&cfs_win_task_manger, 0, sizeof(TASK_MAN));
 }
 
 
@@ -303,21 +321,15 @@ cfs_current()
     PLIST_ENTRY ListEntry = NULL; 
     PTASK_SLOT  TaskSlot  = NULL;
 
-    spin_lock(&(TaskMan.Lock));
+    spin_lock(&(cfs_win_task_manger.Lock));
 
-    ListEntry = TaskMan.TaskList.Flink;
-
-    while (ListEntry != (&(TaskMan.TaskList))) {
+    ListEntry = cfs_win_task_manger.TaskList.Flink;
+    while (ListEntry != (&(cfs_win_task_manger.TaskList))) {
 
         TaskSlot = CONTAINING_RECORD(ListEntry, TASK_SLOT, Link);
-
         if (TaskSlot->Pid == Pid && TaskSlot->Tid == Tid) {
             if (TaskSlot->Tet != Tet) {
 
-/*
-                DbgPrint("cfs_current: Pid=%xh Tid %xh Tet = %xh resued (TaskSlot->Tet = %xh)...\n",
-                         Pid, Tid, Tet, TaskSlot->Tet);
-*/
                 //
                 // The old thread was already exit. This must be a
                 // new thread which get the same Tid to the previous.
@@ -329,16 +341,15 @@ cfs_current()
 
         } else {
 
-            if ((ULONG)TaskSlot->Pid > (ULONG)Pid) {
+            if (TaskSlot->Pid > Pid) {
                 TaskSlot = NULL;
                 break;
-            } else if ((ULONG)TaskSlot->Pid == (ULONG)Pid) {
-                if ((ULONG)TaskSlot->Tid > (ULONG)Tid) {
+            } else if (TaskSlot->Pid == Pid) {
+                if (TaskSlot->Tid > Tid) {
                     TaskSlot = NULL;
                     break;
                 }
             }
-
             TaskSlot =  NULL;
         }
 
@@ -347,24 +358,25 @@ cfs_current()
 
     if (!TaskSlot) {
 
+        /* allocate new task slot */
         TaskSlot = alloc_task_slot();
-
         if (!TaskSlot) {
             cfs_enter_debugger();
             goto errorout;
         }
 
+        /* set task slot IDs */
         init_task_slot(TaskSlot);
-
         TaskSlot->Pid = Pid;
         TaskSlot->Tid = Tid;
         TaskSlot->Tet = Tet;
+        TaskSlot->task.pid = (pid_t)cfs_idr_get_new(cfs_win_task_slot_idp, Tet);
 
-        if (ListEntry == (&(TaskMan.TaskList))) {
+        if (ListEntry == (&(cfs_win_task_manger.TaskList))) {
             //
             // Empty case or the biggest case, put it to the tail.
             //
-            InsertTailList(&(TaskMan.TaskList), &(TaskSlot->Link));
+            InsertTailList(&(cfs_win_task_manger.TaskList), &(TaskSlot->Link));
         } else {
             //
             // Get a slot and smaller than it's tid, put it just before.
@@ -372,7 +384,7 @@ cfs_current()
             InsertHeadList(ListEntry->Blink, &(TaskSlot->Link));
         }
 
-        TaskMan.NumOfTasks++;
+        cfs_win_task_manger.NumOfTasks++;
     }
 
     //
@@ -382,18 +394,18 @@ cfs_current()
     {
         PTASK_SLOT  Prev = NULL, Curr = NULL;
         
-        ListEntry = TaskMan.TaskList.Flink;
+        ListEntry = cfs_win_task_manger.TaskList.Flink;
 
-        while (ListEntry != (&(TaskMan.TaskList))) {
+        while (ListEntry != (&(cfs_win_task_manger.TaskList))) {
 
             Curr = CONTAINING_RECORD(ListEntry, TASK_SLOT, Link);
             ListEntry = ListEntry->Flink;
 
             if (Prev) {
-                if ((ULONG)Prev->Pid > (ULONG)Curr->Pid) {
+                if (Prev->Pid > Curr->Pid) {
                     cfs_enter_debugger();
-                } else if ((ULONG)Prev->Pid == (ULONG)Curr->Pid) {
-                    if ((ULONG)Prev->Tid > (ULONG)Curr->Tid) {
+                } else if (Prev->Pid == Curr->Pid) {
+                    if (Prev->Tid > Curr->Tid) {
                         cfs_enter_debugger();
                     }
                 }
@@ -405,7 +417,7 @@ cfs_current()
 
 errorout:
 
-    spin_unlock(&(TaskMan.Lock));
+    spin_unlock(&(cfs_win_task_manger.Lock));
 
     if (!TaskSlot) {
         cfs_enter_debugger();
@@ -415,15 +427,28 @@ errorout:
     return (&(TaskSlot->task));
 }
 
-int
-schedule_timeout(int64_t time)
+/* deschedule for a bit... */
+void
+cfs_pause(cfs_duration_t ticks)
+{
+    cfs_schedule_timeout(CFS_TASK_UNINTERRUPTIBLE, ticks);
+}
+
+void
+our_cond_resched()
+{
+    cfs_schedule_timeout(CFS_TASK_UNINTERRUPTIBLE, 1i64);
+}
+
+void
+cfs_schedule_timeout(cfs_task_state_t state, int64_t time)
 {
     cfs_task_t * task = cfs_current();
     PTASK_SLOT   slot = NULL;
 
     if (!task) {
         cfs_enter_debugger();
-        return 0;
+        return;
     }
 
     slot = CONTAINING_RECORD(task, TASK_SLOT, task);
@@ -433,13 +458,13 @@ schedule_timeout(int64_t time)
         time = 0;
     }
 
-    return (cfs_wait_event(&(slot->Event), time) != 0);
+    cfs_wait_event_internal(&(slot->Event), time);
 }
 
-int
-schedule()
+void
+cfs_schedule()
 {
-    return schedule_timeout(0);
+    cfs_schedule_timeout(CFS_TASK_UNINTERRUPTIBLE, 0);
 }
 
 int
@@ -463,9 +488,7 @@ wake_up_process(
 }
 
 void
-sleep_on(
-    cfs_waitq_t *waitq
-    )
+sleep_on(cfs_waitq_t *waitq)
 {
        cfs_waitlink_t link;
        
index e226608..16657c8 100644 (file)
 #include <libcfs/libcfs.h>
 #include "tracefile.h"
 
-void lnet_debug_dumpstack(cfs_task_t *tsk)
+void libcfs_debug_dumpstack(cfs_task_t *tsk)
 {
        return;
 }
 
-cfs_task_t *lnet_current(void)
+void libcfs_run_debug_log_upcall(char *file)
 {
-       return cfs_current();
 }
 
-int lnet_arch_debug_init(unsigned long bufsize)
+cfs_task_t *libcfs_current(void)
 {
-       return 0;
-}
-
-int lnet_arch_debug_cleanup(void)
-{
-       return 0;
+       return cfs_current();
 }
 
 void libcfs_run_lbug_upcall(const char *file, const char *fn, const int line)
 {
 }
 
-void libcfs_debug_dumplog(void)
-{
-}
-
 void lbug_with_loc(const char *file, const char *func, const int line)
 {
         libcfs_catastrophe = 1;
         CEMERG("LBUG: pid: %u thread: %#x\n",
-               (unsigned)cfs_curproc_pid(), (unsigned)PsGetCurrentThread());
+               cfs_curproc_pid(), PsGetCurrentThread());
+        cfs_enter_debugger();
         libcfs_debug_dumplog();
         libcfs_run_lbug_upcall(file, func, line);
 }
 
-#if TDI_LIBCFS_DBG
+void cfs_enter_debugger(void)
+{
+# if _X86_
+    __asm int 3;
+# else
+    KdBreakPoint();
+# endif
+}
+
+#if DBG
 
 /*
  * Definitions
  */
 
-LONG  KsDebugLevel = 0x5;
+LONG  KsDebugLevel = 1;
 
 
 /*
@@ -1058,21 +1058,66 @@ KsPrintf(
     ...
     )
 {
-    va_list  ap;
+    LARGE_INTEGER tick;
+    va_list       ap;
 
     va_start(ap, DebugMessage);
-
-    if (DebugPrintLevel <= KsDebugLevel)
-    {
+    if (DebugPrintLevel <= KsDebugLevel) {
         CHAR buffer[0x200];
-
+        KeQueryTickCount(&tick);
         vsprintf(buffer, DebugMessage, ap);
-
-        KdPrint(("TID:%8.8x: %s", PsGetCurrentThread(), buffer));
+        KdPrint(("%8.8X cpu:%d:%d tid:%p %s",
+                 tick.LowPart,
+                 KeGetCurrentProcessorNumber(),
+                 KeGetCurrentIrql(), 
+                 PsGetCurrentThread(), buffer));
     }
-
     va_end(ap);
 
 } // KsPrint()
 
 #endif
+
+
+void libcfs_panic(char *msg)
+{
+    DbgPrint("%s", msg);
+    cfs_enter_debugger();
+}
+
+/* BUGCHECK callback record */
+static int libcfs_bugcheck_inited = 0;
+KBUGCHECK_CALLBACK_RECORD libcfs_bugcheck_record;
+
+void
+libcfs_bugcheck_callback(
+    IN PVOID Buffer, 
+    IN ULONG Length 
+    )
+{
+    cfs_enter_debugger();
+}
+
+
+void libcfs_register_panic_notifier(void)
+{
+    if (libcfs_bugcheck_inited) {
+        return;
+    }
+
+    KeInitializeCallbackRecord(&libcfs_bugcheck_record);
+    KeRegisterBugCheckCallback(&libcfs_bugcheck_record,
+                                libcfs_bugcheck_callback,
+                               &libcfs_bugcheck_record,
+                                sizeof(KBUGCHECK_CALLBACK_RECORD),
+                                "Lustre");
+}
+
+void libcfs_unregister_panic_notifier(void)
+{
+    if (!libcfs_bugcheck_inited) {
+        return;
+    }
+
+    KeDeregisterBugCheckCallback(&libcfs_bugcheck_record);
+}
index 2270771..515eee5 100644 (file)
@@ -38,7 +38,9 @@
 
 #include <libcfs/libcfs.h>
 
-const CHAR *dos_file_prefix = "\\??\\";
+const CHAR *dos_file_prefix[] = {
+            "\\??\\", "\\DosDevices\\",
+            "\\SystemRoot\\", NULL};
 
 /*
  * cfs_filp_open
@@ -57,6 +59,9 @@ const CHAR *dos_file_prefix = "\\??\\";
  *   N/A
  */
 
+#define is_drv_letter_valid(x) (((x) >= 0 && (x) <= 9) || \
+                ( ((x)|0x20) <= 'z' && ((x)|0x20) >= 'a'))
+
 cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
 {
     cfs_file_t *        fp = NULL;
@@ -81,7 +86,6 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
     PUCHAR              AnsiString = NULL;
 
     /* Analyze the flags settings */
-
     if (cfs_is_flag_set(flags, O_WRONLY)) {
         DesiredAccess = (GENERIC_WRITE | SYNCHRONIZE);
         ShareAccess = 0;
@@ -126,11 +130,28 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
     }
 
     /* Initialize the unicode path name for the specified file */
-
     NameLength = (USHORT)strlen(name);
 
+    /* Check file & path name */
     if (name[0] != '\\') {
-        PrefixLength = (USHORT)strlen(dos_file_prefix);
+        if (NameLength < 1 || name[1] != ':' || !is_drv_letter_valid(name[0])) {
+            /* invalid file path name */
+            if (err) *err = -EINVAL;
+            return NULL;
+        }
+        PrefixLength = (USHORT)strlen(dos_file_prefix[0]);
+    } else {
+        int i, j;
+        for (i=0; i < 3 && dos_file_prefix[i] != NULL; i++) {
+            j = strlen(dos_file_prefix[i]);
+            if (NameLength > j && _strnicmp(dos_file_prefix[i], name, j) == 0) {
+                break;
+            }
+        }
+        if (i >= 3) {
+            if (err) *err = -EINVAL;
+            return NULL;
+        }
     }
 
     AnsiString = cfs_alloc( sizeof(CHAR) * (NameLength + PrefixLength + 1),
@@ -142,7 +163,6 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
 
     UnicodeString = cfs_alloc( sizeof(WCHAR) * (NameLength + PrefixLength + 1),
                                CFS_ALLOC_ZERO);
-
     if (NULL == UnicodeString) {
         if (err) *err = -ENOMEM;
         cfs_free(AnsiString);
@@ -150,7 +170,7 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
     }
 
     if (PrefixLength) {
-        RtlCopyMemory(&AnsiString[0], dos_file_prefix , PrefixLength);
+        RtlCopyMemory(&AnsiString[0], dos_file_prefix[0], PrefixLength);
     }
 
     RtlCopyMemory(&AnsiString[PrefixLength], name, NameLength);
@@ -167,7 +187,6 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
     RtlAnsiStringToUnicodeString(&UnicodeName, &AnsiName, FALSE);
 
     /* Setup the object attributes structure for the file. */
-
     InitializeObjectAttributes(
             &ObjectAttributes,
             &UnicodeName,
@@ -177,7 +196,6 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
             NULL );
 
     /* Now to open or create the file now */
-
     Status = ZwCreateFile(
             &FileHandle,
             DesiredAccess,
@@ -192,22 +210,24 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
             0 );
 
     /* Check the returned status of IoStatus... */
-
     if (!NT_SUCCESS(IoStatus.Status)) {
-        *err = cfs_error_code(IoStatus.Status);
+        if (err) {
+            *err = cfs_error_code(IoStatus.Status);
+        }
         cfs_free(UnicodeString);
         cfs_free(AnsiString);
         return NULL;
     }
 
     /* Allocate the cfs_file_t: libcfs file object */
-
     fp = cfs_alloc(sizeof(cfs_file_t) + NameLength, CFS_ALLOC_ZERO);
 
     if (NULL == fp) {
         Status = ZwClose(FileHandle);
         ASSERT(NT_SUCCESS(Status));
-        *err = -ENOMEM;
+        if (err) {
+            *err = -ENOMEM;
+        }
         cfs_free(UnicodeString);
         cfs_free(AnsiString);
         return NULL;
@@ -218,7 +238,9 @@ cfs_file_t *cfs_filp_open(const char *name, int flags, int mode, int *err)
     fp->f_flags = flags;
     fp->f_mode  = (mode_t)mode;
     fp->f_count = 1;
-    *err = 0;
+    if (err) {
+        *err = 0;
+    }
 
     /* free the memory of temporary name strings */
     cfs_free(UnicodeString);
@@ -260,6 +282,164 @@ int cfs_filp_close(cfs_file_t *fp)
 }
 
 
+NTSTATUS CompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
+{
+    /* copy the IoStatus result */
+    if (Irp->UserIosb)
+        *Irp->UserIosb = Irp->IoStatus;
+    
+    /* singal the event we set */
+    KeSetEvent((PKEVENT) Context, 0, FALSE);
+   
+    /* free the Irp we allocated */
+    IoFreeIrp(Irp);
+    
+    return STATUS_MORE_PROCESSING_REQUIRED;
+}
+
+
+NTSTATUS cfs_nt_filp_io(HANDLE Handle, BOOLEAN Writing, PLARGE_INTEGER Offset,
+                        ULONG Length,  PUCHAR Buffer,   PULONG Bytes)
+{
+    NTSTATUS                status;
+    IO_STATUS_BLOCK         iosb;
+
+    PIRP                    irp = NULL;
+    PIO_STACK_LOCATION      irpSp = NULL;
+
+    PFILE_OBJECT            fileObject = NULL;
+    PDEVICE_OBJECT          deviceObject;
+
+    KEVENT                  event;
+
+    KeInitializeEvent(&event, SynchronizationEvent, FALSE);
+
+    status = ObReferenceObjectByHandle( Handle,
+                                        Writing ? FILE_WRITE_DATA : 
+                                                  FILE_READ_DATA,
+                                        *IoFileObjectType,
+                                        KernelMode,
+                                        (PVOID *) &fileObject,
+                                        NULL );
+    if (!NT_SUCCESS(status)) {
+        goto errorout;
+    }
+
+    /* query the DeviceObject in case no input */
+    deviceObject = IoGetBaseFileSystemDeviceObject(fileObject);
+
+
+    /* allocate our own irp */
+    irp = IoAllocateIrp(deviceObject->StackSize, FALSE);
+    if (NULL == irp) {
+        status = STATUS_INSUFFICIENT_RESOURCES;
+        goto errorout;
+    }
+
+    irp->Tail.Overlay.OriginalFileObject = fileObject;
+    irp->Tail.Overlay.Thread = PsGetCurrentThread();
+    irp->Tail.Overlay.AuxiliaryBuffer = (PVOID) NULL;
+    irp->PendingReturned = FALSE;
+    irp->Cancel = FALSE;
+    irp->CancelRoutine = (PDRIVER_CANCEL) NULL;
+    irp->RequestorMode = KernelMode;
+    irp->UserIosb = &iosb;
+
+    /* set up the next I/O stack location. */
+    irpSp = (PIO_STACK_LOCATION)IoGetNextIrpStackLocation(irp);
+    irpSp->MajorFunction = Writing ? IRP_MJ_WRITE : IRP_MJ_READ;
+    irpSp->FileObject = fileObject;
+    irpSp->DeviceObject = deviceObject;
+
+    if (deviceObject->Flags & DO_BUFFERED_IO) {
+        irp->AssociatedIrp.SystemBuffer = Buffer;
+        irp->UserBuffer = Buffer;
+        irp->Flags |= (ULONG) (IRP_BUFFERED_IO |
+                               IRP_INPUT_OPERATION);
+    } else if (deviceObject->Flags & DO_DIRECT_IO) {
+
+        PMDL mdl = NULL;
+
+        mdl = IoAllocateMdl(Buffer, Length, FALSE, TRUE, irp);
+        if (mdl == NULL) {
+            KsPrint((0, "cfs_nt_filp_io: failed to allocate MDL for %wZ .\n",
+                        &fileObject->FileName));
+            status = STATUS_INSUFFICIENT_RESOURCES;
+            goto errorout;
+        }
+
+        __try {
+            MmProbeAndLockPages(mdl, KernelMode, Writing ? IoReadAccess : IoWriteAccess );
+        } __except(EXCEPTION_EXECUTE_HANDLER) {
+            KsPrint((0, "cfs_nt_filp_io: failed to lock buffer %p for %wZ .\n",
+                        Buffer, &fileObject->FileName));
+            IoFreeMdl(irp->MdlAddress);
+            irp->MdlAddress = NULL;
+            status = STATUS_INSUFFICIENT_RESOURCES;
+        }
+    } else {
+        irp->UserBuffer = Buffer;
+        irp->Flags = 0;
+    }
+
+    if (Writing) {
+        irp->Flags |= IRP_WRITE_OPERATION | IRP_DEFER_IO_COMPLETION;
+        irpSp->Parameters.Write.Length = Length;
+        irpSp->Parameters.Write.ByteOffset = *Offset;
+    } else {
+        irp->Flags |= IRP_READ_OPERATION | IRP_DEFER_IO_COMPLETION;
+        irpSp->Parameters.Read.Length = Length;
+        irpSp->Parameters.Read.ByteOffset = *Offset;
+    }
+
+    /* set the Irp completion routine */
+    IoSetCompletionRoutine( irp, CompletionRoutine, 
+                            &event, TRUE, TRUE, TRUE);
+
+
+    /* issue the irp to the lower layer device */
+    status = IoCallDriver(deviceObject, irp);
+
+    /* Irp is to be cleaned up in the compleiton routine */
+    irp = NULL;
+
+    if (status == STATUS_PENDING) {
+
+        /* we need wait until operation is completed, then we can
+           get the returned status and information length */
+
+        status = KeWaitForSingleObject(
+                    &event,
+                    Executive,
+                    KernelMode,
+                    FALSE,
+                    NULL
+                    );
+        if (NT_SUCCESS(status)) {
+            status = iosb.Status;
+        }
+    }
+
+    if (NT_SUCCESS(status)) {
+        *Bytes = (ULONG)iosb.Information;
+    } else {
+        *Bytes = 0;
+    }
+
+errorout:
+
+    if (fileObject) {
+        ObDereferenceObject(fileObject);
+    }
+
+    /* free the Irp in error case */
+    if (irp) {
+        IoFreeIrp(irp);
+    }
+
+    return status;
+}
+
 /*
  * cfs_filp_read
  *     To read data from the opened file
@@ -281,45 +461,33 @@ int cfs_filp_close(cfs_file_t *fp)
 
 int cfs_filp_read(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos)
 {
-    LARGE_INTEGER   address;
-    NTSTATUS        Status;
-    IO_STATUS_BLOCK IoStatus;
-
+    LARGE_INTEGER   offset;
+    NTSTATUS        status;
     int             rc = 0;
 
     /* Read data from the file into the specified buffer */
-
     if (pos != NULL) {
-        address.QuadPart = *pos;
+        offset.QuadPart = *pos;
     } else {
-        address.QuadPart = fp->f_pos;
+        offset.QuadPart = fp->f_pos;
     }
 
-    Status = ZwReadFile( fp->f_handle,
-                         0,
-                         NULL,
-                         NULL,
-                         &IoStatus,
-                         buf,
-                         nbytes,
-                         &address,
-                         NULL );
+    status = cfs_nt_filp_io(fp->f_handle, 0, &offset,
+                            nbytes, buf, &rc);
 
-    if (!NT_SUCCESS(IoStatus.Status)) {
-        rc = cfs_error_code(IoStatus.Status);
-    } else {
-        rc = (int)IoStatus.Information;
-        fp->f_pos = address.QuadPart + rc;
-        if (pos != NULL) {
+    if (!NT_SUCCESS(status)) {
+        rc = cfs_error_code(status);
+    }
+
+    if (rc > 0) {
+        fp->f_pos = offset.QuadPart + rc;
+        if (pos != NULL)
             *pos = fp->f_pos;
-        }   
     }
 
-    return rc;     
+    return rc;
 }
 
-
 /*
  * cfs_filp_wrtie
  *     To write specified data to the opened file
@@ -341,63 +509,33 @@ int cfs_filp_read(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos)
 
 int cfs_filp_write(cfs_file_t *fp, void *buf, size_t nbytes, loff_t *pos)
 {
-    LARGE_INTEGER   address;
-    NTSTATUS        Status;
-    IO_STATUS_BLOCK IoStatus;
+    LARGE_INTEGER   offset;
+    NTSTATUS        status;
     int             rc = 0;
 
-    /* Write user specified data into the file */
-
+    /* Read data from the file into the specified buffer */
     if (pos != NULL) {
-        address.QuadPart = *pos;
+        offset.QuadPart = *pos;
     } else {
-        address.QuadPart = fp->f_pos;
+        offset.QuadPart = fp->f_pos;
     }
 
-    Status = ZwWriteFile( fp->f_handle,
-                         0,
-                         NULL,
-                         NULL,
-                         &IoStatus,
-                         buf,
-                         nbytes,
-                         &address,
-                         NULL );
+    status = cfs_nt_filp_io(fp->f_handle, 1, &offset,
+                            nbytes, buf, &rc);
 
-    if (!NT_SUCCESS(Status)) {
-        rc =  cfs_error_code(Status);
-    } else {
-        rc = (int)IoStatus.Information;
-        fp->f_pos = address.QuadPart + rc;
-        if (pos != NULL) {
+    if (!NT_SUCCESS(status)) {
+        rc = cfs_error_code(status);
+    }
+
+    if (rc > 0) {
+        fp->f_pos = offset.QuadPart + rc;
+        if (pos != NULL)
             *pos = fp->f_pos;
-        }   
     }
 
     return rc;
 }
 
-
-NTSTATUS
-CompletionRoutine(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp,
-    PVOID Context)
-{
-    /* copy the IoStatus result */
-    *Irp->UserIosb = Irp->IoStatus;
-    
-    /* singal the event we set */
-    KeSetEvent(Irp->UserEvent, 0, FALSE);
-   
-    /* free the Irp we allocated */
-    IoFreeIrp(Irp);
-    
-    return STATUS_MORE_PROCESSING_REQUIRED;
-}
-
-
 /*
  * cfs_filp_fsync
  *     To sync the dirty data of the file to disk
@@ -428,7 +566,6 @@ int cfs_filp_fsync(cfs_file_t *fp)
     PIO_STACK_LOCATION      IrpSp;
 
     /* get the FileObject and the DeviceObject */
-
     Status = ObReferenceObjectByHandle(
                 fp->f_handle,
                 FILE_WRITE_DATA,
@@ -444,11 +581,8 @@ int cfs_filp_fsync(cfs_file_t *fp)
     DeviceObject = IoGetRelatedDeviceObject(FileObject);
 
     /* allocate a new Irp */
-
     Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
-
     if (!Irp) {
-
         ObDereferenceObject(FileObject);
         return -ENOMEM;
     }
@@ -457,7 +591,6 @@ int cfs_filp_fsync(cfs_file_t *fp)
     KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
 
     /* setup the Irp */
-    Irp->UserEvent = &Event;
     Irp->UserIosb = &IoSb;
     Irp->RequestorMode = KernelMode;
 
@@ -471,7 +604,8 @@ int cfs_filp_fsync(cfs_file_t *fp)
     IrpSp->DeviceObject = DeviceObject;
     IrpSp->FileObject = FileObject;
 
-    IoSetCompletionRoutine(Irp, CompletionRoutine, 0, TRUE, TRUE, TRUE);
+    IoSetCompletionRoutine( Irp, CompletionRoutine,
+                            &Event, TRUE, TRUE, TRUE);
 
 
     /* issue the Irp to the underlying file system driver */
@@ -553,3 +687,21 @@ int cfs_file_count(cfs_file_t *fp)
 {
     return (int)(fp->f_count);
 }
+
+struct dentry *dget(struct dentry *de)
+{
+    if (de) {
+        atomic_inc(&de->d_count);
+    }
+    return de;
+}
+
+void dput(struct dentry *de)
+{
+    if (!de || atomic_read(&de->d_count) == 0) {
+        return;
+    }
+    if (atomic_dec_and_test(&de->d_count)) {
+        cfs_free(de);
+    }
+}
index 2b57e7f..7b20b53 100644 (file)
@@ -40,7 +40,7 @@
 #include <libcfs/libcfs.h>
 
 
-#if _X86_
+#if defined(_X86_)
 
 void __declspec (naked) FASTCALL
 atomic_add(
@@ -148,7 +148,7 @@ atomic_dec_and_test(
     }
 }
 
-#else
+#elif defined(_AMD64_)
 
 void FASTCALL
 atomic_add(
@@ -235,7 +235,7 @@ atomic_dec_and_test(
     do {
 
         counter = v->counter;
-        result = counter + 1;
+        result = counter - 1;
 
     } while ( InterlockedCompareExchange(
                 &(v->counter),
@@ -245,8 +245,62 @@ atomic_dec_and_test(
     return (result == 0);
 }
 
+#else
+
+#error CPU arch type isn't specified.
+
 #endif
 
+/**
+ * atomic_add_return - add integer and return
+ * @v: pointer of type atomic_t
+ * @i: integer value to add
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+int FASTCALL atomic_add_return(int i, atomic_t *v)
+{
+    int counter, result;
+
+    do {
+
+        counter = v->counter;
+        result = counter + i;
+
+    } while ( InterlockedCompareExchange(
+                &(v->counter),
+                result,
+                counter) !=  counter);
+
+    return result;
+
+}
+
+/**
+ * atomic_sub_return - subtract integer and return
+ * @v: pointer of type atomic_t
+ * @i: integer value to subtract
+ *
+ * Atomically subtracts @i from @v and returns @v - @i
+ */
+int FASTCALL atomic_sub_return(int i, atomic_t *v)
+{
+       return atomic_add_return(-i, v);
+}
+
+int FASTCALL atomic_dec_and_lock(atomic_t *v, spinlock_t *lock)
+{
+    if (atomic_read(v) != 1) {
+        return 0;
+    } 
+
+       spin_lock(lock);
+       if (atomic_dec_and_test(v))
+               return 1;
+       spin_unlock(lock);
+       return 0;
+}
+
 
 /*
  * rw spinlock
index 782d6d7..6a8689e 100644 (file)
 cfs_mem_cache_t *cfs_page_t_slab = NULL;
 cfs_mem_cache_t *cfs_page_p_slab = NULL;
 
+cfs_page_t * virt_to_page(void * addr)
+{
+    cfs_page_t *pg;
+    pg = cfs_mem_cache_alloc(cfs_page_t_slab, 0);
+    
+    if (NULL == pg) {
+        cfs_enter_debugger();
+        return NULL;
+    }
+
+    memset(pg, 0, sizeof(cfs_page_t));
+    pg->addr = (void *)((__u64)addr & (~((__u64)PAGE_SIZE-1)));
+    pg->mapping = addr;
+    atomic_set(&pg->count, 1);
+    set_bit(PG_virt, &(pg->flags));
+    cfs_enter_debugger();
+    return pg;
+}
+
 /*
  * cfs_alloc_page
  *   To allocate the cfs_page_t and also 1 page of memory
@@ -57,6 +76,8 @@ cfs_mem_cache_t *cfs_page_p_slab = NULL;
  *   N/A
  */
 
+atomic_t libcfs_total_pages;
+
 cfs_page_t * cfs_alloc_page(int flags)
 {
     cfs_page_t *pg;
@@ -75,6 +96,7 @@ cfs_page_t * cfs_alloc_page(int flags)
         if (cfs_is_flag_set(flags, CFS_ALLOC_ZERO)) {
             memset(pg->addr, 0, CFS_PAGE_SIZE);
         }
+        atomic_inc(&libcfs_total_pages);
     } else {
         cfs_enter_debugger();
         cfs_mem_cache_free(cfs_page_t_slab, pg);
@@ -103,10 +125,60 @@ void cfs_free_page(cfs_page_t *pg)
     ASSERT(pg->addr  != NULL);
     ASSERT(atomic_read(&pg->count) <= 1);
 
-    cfs_mem_cache_free(cfs_page_p_slab, pg->addr);
+    if (!test_bit(PG_virt, &pg->flags)) {
+        cfs_mem_cache_free(cfs_page_p_slab, pg->addr);
+        atomic_dec(&libcfs_total_pages);
+    } else {
+        cfs_enter_debugger();
+    }
     cfs_mem_cache_free(cfs_page_t_slab, pg);
 }
 
+cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order)
+{
+    cfs_page_t *pg;
+    pg = cfs_mem_cache_alloc(cfs_page_t_slab, 0);
+    
+    if (NULL == pg) {
+        cfs_enter_debugger();
+        return NULL;
+    }
+
+    memset(pg, 0, sizeof(cfs_page_t));
+    pg->addr = cfs_alloc((CFS_PAGE_SIZE << order),0);
+    atomic_set(&pg->count, 1);
+
+    if (pg->addr) {
+        if (cfs_is_flag_set(flags, CFS_ALLOC_ZERO)) {
+            memset(pg->addr, 0, CFS_PAGE_SIZE << order);
+        }
+        atomic_add(1 << order, &libcfs_total_pages);
+    } else {
+        cfs_enter_debugger();
+        cfs_mem_cache_free(cfs_page_t_slab, pg);
+        pg = NULL;
+    }
+
+    return pg;
+}
+
+void __cfs_free_pages(cfs_page_t *pg, unsigned int order)
+{
+    ASSERT(pg != NULL);
+    ASSERT(pg->addr  != NULL);
+    ASSERT(atomic_read(&pg->count) <= 1);
+
+    atomic_sub(1 << order, &libcfs_total_pages);
+    cfs_free(pg->addr);
+    cfs_mem_cache_free(cfs_page_t_slab, pg);
+}
+
+int cfs_mem_is_in_cache(const void *addr, const cfs_mem_cache_t *kmem)
+{
+    KdPrint(("cfs_mem_is_in_cache: not implemented. (should maintain a"
+              "chain to keep all allocations traced.)\n"));
+    return 1;
+}
 
 /*
  * cfs_alloc
@@ -127,21 +199,19 @@ void cfs_free_page(cfs_page_t *pg)
 void *
 cfs_alloc(size_t nr_bytes, u_int32_t flags)
 {
-       void *ptr;
+    void *ptr;
 
     /* Ignore the flags: always allcoate from NonPagedPool */
-
-       ptr = ExAllocatePoolWithTag(NonPagedPool, nr_bytes, 'Lufs');
-
-       if (ptr != NULL && (flags & CFS_ALLOC_ZERO)) {
-               memset(ptr, 0, nr_bytes);
+    ptr = ExAllocatePoolWithTag(NonPagedPool, nr_bytes, 'Lufs');
+    if (ptr != NULL && (flags & CFS_ALLOC_ZERO)) {
+        memset(ptr, 0, nr_bytes);
     }
 
     if (!ptr) {
         cfs_enter_debugger();
     }
 
-       return ptr;
+    return ptr;
 }
 
 /*
@@ -161,7 +231,7 @@ cfs_alloc(size_t nr_bytes, u_int32_t flags)
 void
 cfs_free(void *addr)
 {
-       ExFreePool(addr);
+    ExFreePool(addr);
 }
 
 /*
@@ -182,7 +252,7 @@ cfs_free(void *addr)
 void *
 cfs_alloc_large(size_t nr_bytes)
 {
-       return cfs_alloc(nr_bytes, 0);
+    return cfs_alloc(nr_bytes, 0);
 }
 
 /*
@@ -202,7 +272,7 @@ cfs_alloc_large(size_t nr_bytes)
 void
 cfs_free_large(void *addr)
 {
-       cfs_free(addr);
+    cfs_free(addr);
 }
 
 
@@ -252,7 +322,6 @@ cfs_mem_cache_create(
     }
 
     memset(kmc, 0, sizeof(cfs_mem_cache_t));
-
     kmc->flags = flags;
 
     if (name) {
@@ -345,3 +414,74 @@ void cfs_mem_cache_free(cfs_mem_cache_t * kmc, void * buf)
 {
     ExFreeToNPagedLookasideList(&(kmc->npll), buf);
 }
+
+spinlock_t  shrinker_guard = {0};
+CFS_LIST_HEAD(shrinker_hdr);
+cfs_timer_t shrinker_timer = {0};
+
+struct shrinker * set_shrinker(int seeks, shrink_callback cb)
+{
+    struct shrinker * s = (struct shrinker *)
+        cfs_alloc(sizeof(struct shrinker), CFS_ALLOC_ZERO);
+    if (s) {
+        s->cb = cb;
+        s->seeks = seeks;
+        s->nr = 2;
+        spin_lock(&shrinker_guard);
+        list_add(&s->list, &shrinker_hdr); 
+        spin_unlock(&shrinker_guard);
+    }
+
+    return s;
+}
+
+void remove_shrinker(struct shrinker *s)
+{
+    struct shrinker *tmp;
+    spin_lock(&shrinker_guard);
+#if TRUE
+    cfs_list_for_each_entry_typed(tmp, &shrinker_hdr,
+                            struct shrinker, list) {
+        if (tmp == s) {
+            list_del(&tmp->list);
+            break;
+        } 
+    }
+#else
+    list_del(&s->list);
+#endif
+    spin_unlock(&shrinker_guard);
+    cfs_free(s);
+}
+
+/* time ut test proc */
+void shrinker_timer_proc(ulong_ptr_t arg)
+{
+    struct shrinker *s;
+    spin_lock(&shrinker_guard);
+
+    cfs_list_for_each_entry_typed(s, &shrinker_hdr,
+                            struct shrinker, list) {
+        s->cb(s->nr, __GFP_FS);
+    }
+    spin_unlock(&shrinker_guard);
+    cfs_timer_arm(&shrinker_timer, 300);
+}
+
+int start_shrinker_timer()
+{
+    /* initialize shriner timer */
+    cfs_timer_init(&shrinker_timer, shrinker_timer_proc, NULL);
+
+    /* start the timer to trigger in 5 minutes */
+    cfs_timer_arm(&shrinker_timer, 300);
+
+    return 0;
+}
+
+void stop_shrinker_timer()
+{
+    /* cancel the timer */
+    cfs_timer_disarm(&shrinker_timer);
+    cfs_timer_done(&shrinker_timer);
+}
index ac255ba..3febc7f 100644 (file)
@@ -35,7 +35,7 @@
  */
 
 
-#define DEBUG_SUBSYSTEM S_LIBCFS
+#define DEBUG_SUBSYSTEM S_LNET
 
 #include <libcfs/libcfs.h>
 
@@ -56,17 +56,17 @@ int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
                 RETURN(err);
 
         if (hdr->ioc_version != LIBCFS_IOCTL_VERSION) {
-                CERROR(("LIBCFS: version mismatch kernel vs application\n"));
+                CERROR("LIBCFS: version mismatch kernel vs application\n");
                 RETURN(-EINVAL);
         }
 
         if (hdr->ioc_len + buf >= end) {
-                CERROR(("LIBCFS: user buffer exceeds kernel buffer\n"));
+                CERROR("LIBCFS: user buffer exceeds kernel buffer\n");
                 RETURN(-EINVAL);
         }
 
         if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) {
-                CERROR(("LIBCFS: user buffer too small for ioctl\n"));
+                CERROR("LIBCFS: user buffer too small for ioctl\n");
                 RETURN(-EINVAL);
         }
 
@@ -75,7 +75,7 @@ int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
                 RETURN(err);
 
         if (libcfs_ioctl_is_invalid(data)) {
-                CERROR(("LIBCFS: ioctl not correctly formatted\n"));
+                CERROR("LIBCFS: ioctl not correctly formatted\n");
                 RETURN(-EINVAL);
         }
 
@@ -88,11 +88,18 @@ int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
 
         RETURN(0);
 }
-                                                                                                                                                                        
+
+int libcfs_ioctl_popdata(void *arg, void *data, int size)
+{
+       if (copy_to_user((char *)arg, data, size))
+               return -EFAULT;
+       return 0;
+}
+                                                                                                                                                                       
 extern struct cfs_psdev_ops          libcfs_psdev_ops;
 
 static int 
-libcfs_psdev_open(cfs_file_t * file)
+libcfs_psdev_open(struct inode *in, cfs_file_t * file)
 { 
        struct libcfs_device_userstate **pdu = NULL;
        int    rc = 0;
@@ -107,7 +114,7 @@ libcfs_psdev_open(cfs_file_t * file)
 
 /* called when closing /dev/device */
 static int 
-libcfs_psdev_release(cfs_file_t * file)
+libcfs_psdev_release(struct inode *in, cfs_file_t * file)
 {
        struct libcfss_device_userstate *pdu;
        int    rc = 0;
@@ -121,7 +128,7 @@ libcfs_psdev_release(cfs_file_t * file)
 }
 
 static int 
-libcfs_ioctl(cfs_file_t * file, unsigned int cmd, ulong_ptr arg)
+libcfs_ioctl(cfs_file_t * file, unsigned int cmd, ulong_ptr_t arg)
 { 
        struct cfs_psdev_file    pfile;
        int    rc = 0;
@@ -129,8 +136,8 @@ libcfs_ioctl(cfs_file_t * file, unsigned int cmd, ulong_ptr arg)
        if ( _IOC_TYPE(cmd) != IOC_LIBCFS_TYPE || 
             _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR  || 
             _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR ) { 
-               CDEBUG(D_IOCTL, ("invalid ioctl ( type %d, nr %d, size %d )\n", 
-                      _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd)))
+               CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n", 
+                      _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd)); 
                return (-EINVAL); 
        } 
        
@@ -139,8 +146,8 @@ libcfs_ioctl(cfs_file_t * file, unsigned int cmd, ulong_ptr arg)
        case IOC_LIBCFS_PANIC: 
                if (!cfs_capable(CFS_CAP_SYS_BOOT)) 
                        return (-EPERM); 
-               CERROR(("debugctl-invoked panic"));
-        KeBugCheckEx('LUFS', (ULONG_PTR)libcfs_ioctl, (ULONG_PTR)NULL, (ULONG_PTR)NULL, (ULONG_PTR)NULL);
+               CERROR("debugctl-invoked panic");
+               KeBugCheckEx('LUFS', (ULONG_PTR)libcfs_ioctl, (ULONG_PTR)NULL, (ULONG_PTR)NULL, (ULONG_PTR)NULL);
 
                return (0);
        case IOC_LIBCFS_MEMHOG:
@@ -160,6 +167,7 @@ libcfs_ioctl(cfs_file_t * file, unsigned int cmd, ulong_ptr arg)
 }
 
 static struct file_operations libcfs_fops = {
+    /* owner */   THIS_MODULE,
     /* lseek: */  NULL,
     /* read: */   NULL,
     /* write: */  NULL,
diff --git a/libcfs/libcfs/winnt/winnt-native.c b/libcfs/libcfs/winnt/winnt-native.c
new file mode 100644 (file)
index 0000000..634024a
--- /dev/null
@@ -0,0 +1,709 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=4:tabstop=4:
+ *
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+# define DEBUG_SUBSYSTEM S_LNET
+
+#ifndef __KERNEL__
+
+#include <ntddk.h>
+#include <libcfs/libcfs.h>
+#include <libcfs/user-bitops.h>
+#include <lustre_lib.h>
+
+/*
+ * Native API definitions
+ */
+
+//
+//  Disk I/O Routines
+//
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+NtReadFile(HANDLE FileHandle,
+    HANDLE Event OPTIONAL,
+    PIO_APC_ROUTINE ApcRoutine OPTIONAL,
+    PVOID ApcContext OPTIONAL,
+    PIO_STATUS_BLOCK IoStatusBlock,
+    PVOID Buffer,
+    ULONG Length,
+    PLARGE_INTEGER ByteOffset OPTIONAL,
+    PULONG Key OPTIONAL);
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+NtWriteFile(HANDLE FileHandle,
+    HANDLE Event OPTIONAL,
+    PIO_APC_ROUTINE ApcRoutine OPTIONAL,
+    PVOID ApcContext OPTIONAL,
+    PIO_STATUS_BLOCK IoStatusBlock,
+    PVOID Buffer,
+    ULONG Length,
+    PLARGE_INTEGER ByteOffset OPTIONAL,
+    PULONG Key OPTIONAL);
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+NtClose(HANDLE Handle);
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+NtCreateFile(PHANDLE FileHandle,
+    ACCESS_MASK DesiredAccess,
+    POBJECT_ATTRIBUTES ObjectAttributes,
+    PIO_STATUS_BLOCK IoStatusBlock,
+    PLARGE_INTEGER AllocationSize OPTIONAL,
+    ULONG FileAttributes,
+    ULONG ShareAccess,
+    ULONG CreateDisposition,
+    ULONG CreateOptions,
+    PVOID EaBuffer OPTIONAL,
+    ULONG EaLength);
+
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+NtDeviceIoControlFile(
+    IN HANDLE  FileHandle,
+    IN HANDLE  Event,
+    IN PIO_APC_ROUTINE  ApcRoutine,
+    IN PVOID  ApcContext,
+    OUT PIO_STATUS_BLOCK  IoStatusBlock,
+    IN ULONG  IoControlCode,
+    IN PVOID  InputBuffer,
+    IN ULONG  InputBufferLength,
+    OUT PVOID  OutputBuffer,
+    OUT ULONG  OutputBufferLength
+    ); 
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+NtFsControlFile(
+    IN HANDLE FileHandle,
+    IN HANDLE Event OPTIONAL,
+    IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
+    IN PVOID ApcContext OPTIONAL,
+    OUT PIO_STATUS_BLOCK IoStatusBlock,
+    IN ULONG FsControlCode,
+    IN PVOID InputBuffer OPTIONAL,
+    IN ULONG InputBufferLength,
+    OUT PVOID OutputBuffer OPTIONAL,
+    IN ULONG OutputBufferLength
+);
+
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+NtQueryInformationFile(
+    IN HANDLE  FileHandle,
+    OUT PIO_STATUS_BLOCK  IoStatusBlock,
+    OUT PVOID  FileInformation,
+    IN ULONG  Length,
+    IN FILE_INFORMATION_CLASS  FileInformationClass
+    );
+
+//
+// Random routines ...
+//
+
+NTSYSAPI
+ULONG
+NTAPI
+RtlRandom(
+    IN OUT PULONG  Seed
+    ); 
+
+/*
+ * Time routines ...
+ */
+
+NTSYSAPI
+CCHAR
+NTAPI
+NtQuerySystemTime(
+    OUT PLARGE_INTEGER  CurrentTime
+    );
+
+
+NTSYSAPI
+BOOLEAN
+NTAPI
+RtlTimeToSecondsSince1970(
+    IN PLARGE_INTEGER  Time,
+    OUT PULONG  ElapsedSeconds
+    );
+
+
+NTSYSAPI
+VOID
+NTAPI
+RtlSecondsSince1970ToTime(
+    IN ULONG  ElapsedSeconds,
+    OUT PLARGE_INTEGER  Time
+    );
+
+NTSYSAPI
+NTSTATUS
+NTAPI
+ZwDelayExecution(
+    IN BOOLEAN Alertable,
+    IN PLARGE_INTEGER Interval
+);
+
+
+int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
+{
+    NTSTATUS status;
+    LARGE_INTEGER Interval;
+    Interval.QuadPart = rqtp->tv_sec * 10000000 + rqtp->tv_nsec / 100;
+    status = ZwDelayExecution(TRUE, &Interval);
+    if (rmtp) {
+        rmtp->tv_sec = 0;
+        rmtp->tv_nsec = 0;
+    }
+    if (status == STATUS_ALERTED || status == STATUS_USER_APC) {
+       return -1;
+    }
+    return 0;
+}
+
+
+void do_gettimeofday(struct timeval *tv)
+{
+    LARGE_INTEGER Time;
+
+    NtQuerySystemTime(&Time);
+
+    tv->tv_sec  = (long_ptr_t)  (Time.QuadPart / 10000000);
+    tv->tv_usec = (suseconds_t) (Time.QuadPart % 10000000) / 10;
+}
+
+int gettimeofday(struct timeval *tv, void * tz)
+{
+    do_gettimeofday(tv);
+    return 0;
+}
+
+/*
+ * proc process routines of user space
+ */
+
+struct idr_context *cfs_proc_idp = NULL;
+
+int cfs_proc_open (char * filename, int oflag)
+{
+    NTSTATUS            status;
+    IO_STATUS_BLOCK     iosb;
+    int                 rc = 0;
+
+    HANDLE              Handle = INVALID_HANDLE_VALUE;
+    OBJECT_ATTRIBUTES   ObjectAttributes;
+    ACCESS_MASK         DesiredAccess;
+    ULONG               CreateDisposition;
+    ULONG               ShareAccess;
+    ULONG               CreateOptions;
+    UNICODE_STRING      UnicodeName;
+    USHORT              NameLength;
+
+    PFILE_FULL_EA_INFORMATION Ea = NULL;
+    ULONG               EaLength;
+    PUCHAR              EaBuffer = NULL;
+
+    /* Check the filename: should start with "/proc" or "/dev" */
+    NameLength = (USHORT)strlen(filename);
+    if (NameLength > 0x05) {
+        if (_strnicmp(filename, "/proc/", 6) == 0) {
+            if (NameLength <= 6) {
+                rc = -EINVAL;
+                goto errorout;
+            }
+        } else if (_strnicmp(filename, "/dev/", 5) == 0) {
+        } else {
+            rc = -EINVAL;
+            goto errorout;
+        }
+    } else {
+        rc = -EINVAL;
+        goto errorout;
+    }
+
+    /* Analyze the flags settings */
+
+    if (cfs_is_flag_set(oflag, O_WRONLY)) {
+        DesiredAccess = (GENERIC_WRITE | SYNCHRONIZE);
+        ShareAccess = 0;
+    }  else if (cfs_is_flag_set(oflag, O_RDWR)) {
+        DesiredAccess = (GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE);
+        ShareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE;
+    } else {
+        DesiredAccess = (GENERIC_READ | SYNCHRONIZE);
+        ShareAccess = FILE_SHARE_READ;
+    }
+
+    if (cfs_is_flag_set(oflag, O_CREAT)) {
+        if (cfs_is_flag_set(oflag, O_EXCL)) {
+            CreateDisposition = FILE_CREATE;
+            rc = -EINVAL;
+            goto errorout;
+        } else {
+            CreateDisposition = FILE_OPEN_IF;
+        }
+    } else {
+        CreateDisposition = FILE_OPEN;
+    }
+
+    if (cfs_is_flag_set(oflag, O_TRUNC)) {
+        if (cfs_is_flag_set(oflag, O_EXCL)) {
+            CreateDisposition = FILE_OVERWRITE;
+        } else {
+            CreateDisposition = FILE_OVERWRITE_IF;
+        }
+    }
+
+    CreateOptions = 0;
+
+    if (cfs_is_flag_set(oflag, O_DIRECTORY)) {
+        cfs_set_flag(CreateOptions,  FILE_DIRECTORY_FILE);
+    }
+
+    if (cfs_is_flag_set(oflag, O_SYNC)) {
+         cfs_set_flag(CreateOptions, FILE_WRITE_THROUGH);
+    }
+
+    if (cfs_is_flag_set(oflag, O_DIRECT)) {
+         cfs_set_flag(CreateOptions, FILE_NO_INTERMEDIATE_BUFFERING);
+    }
+
+    /* Initialize the unicode path name for the specified file */
+    RtlInitUnicodeString(&UnicodeName, LUSTRE_PROC_SYMLNK);
+
+    /* Setup the object attributes structure for the file. */
+    InitializeObjectAttributes(
+            &ObjectAttributes,
+            &UnicodeName,
+            OBJ_CASE_INSENSITIVE,
+            NULL,
+            NULL );
+
+    /* building EA for the proc entry ...  */
+    EaBuffer = malloc(NameLength + sizeof(FILE_FULL_EA_INFORMATION));
+    if (!EaBuffer) {
+        rc = -ENOMEM;
+        goto errorout;
+    }
+    memset(EaBuffer, 0, NameLength + sizeof(FILE_FULL_EA_INFORMATION));
+    Ea = (PFILE_FULL_EA_INFORMATION)EaBuffer;
+    Ea->NextEntryOffset = 0;
+    Ea->Flags = 0;
+    Ea->EaNameLength = (UCHAR)NameLength;
+    Ea->EaValueLength = 0;
+    RtlCopyMemory(
+        &(Ea->EaName),
+        filename,
+        NameLength + 1
+        );
+    EaLength = sizeof(FILE_FULL_EA_INFORMATION) - 1 +
+                               Ea->EaNameLength + 1;
+
+    /* Now to open or create the file now */
+    status = NtCreateFile(
+                &Handle,
+                DesiredAccess,
+                &ObjectAttributes,
+                &iosb,
+                0,
+                FILE_ATTRIBUTE_NORMAL,
+                ShareAccess,
+                CreateDisposition,
+                CreateOptions,
+                Ea,
+                EaLength );
+
+    /* Check the returned status of Iosb ... */
+
+    if (!NT_SUCCESS(status)) {
+        rc = cfs_error_code(status);
+        goto errorout;
+    }
+
+errorout:
+
+    if (Handle) {
+        rc = cfs_idr_get_new(cfs_proc_idp, Handle);
+        if (rc < 0) {
+            NtClose(Handle);
+        }
+    }
+
+    if (EaBuffer) {
+        free(EaBuffer);
+    }
+
+    return rc;
+}
+
+int cfs_proc_close(int fd)
+{
+    HANDLE handle = cfs_idr_find(cfs_proc_idp, fd);
+
+    if (handle) {
+        NtClose(handle);
+    }
+
+    cfs_idr_remove(cfs_proc_idp, fd);
+
+    return 0;
+}
+
+int cfs_proc_read_internal(
+    int fd, void *buffer,
+    unsigned int count,
+    unsigned int offlow,
+    unsigned int offhigh
+    )
+{
+    NTSTATUS            status;
+    IO_STATUS_BLOCK     iosb;
+    LARGE_INTEGER       offset;
+
+    HANDLE handle = cfs_idr_find(cfs_proc_idp, fd);
+    offset.HighPart = offhigh;
+    offset.LowPart  = offlow;
+
+    /* read file data */
+    status = NtReadFile(
+                handle,
+                0,
+                NULL,
+                NULL,
+                &iosb,
+                buffer,
+                count,
+                &offset,
+                NULL);                     
+
+    /* check the return status */
+    if (!NT_SUCCESS(status)) {
+        printf("NtReadFile request failed with status: 0x%0x\n", status);
+        goto errorout;
+    }
+
+errorout:
+
+    if (NT_SUCCESS(status)) {
+        return (int)(iosb.Information);
+    }
+
+    return cfs_error_code(status);
+}
+
+int cfs_proc_read(
+    int fd, void *buffer,
+    unsigned int count
+    )
+{
+    return cfs_proc_read_internal(fd, buffer, count, 0, 0);
+}
+
+int cfs_proc_write_internal(
+    int fd, void *buffer,
+    unsigned int count,
+    unsigned int offlow,
+    unsigned int offhigh
+    )
+{
+    NTSTATUS            status;
+    IO_STATUS_BLOCK     iosb;
+    LARGE_INTEGER       offset;
+
+    HANDLE handle = cfs_idr_find(cfs_proc_idp, fd);
+    offset.HighPart = offhigh;
+    offset.LowPart = offlow;
+
+    /* write buffer to the opened file */
+    status = NtWriteFile(
+                handle,
+                0,
+                NULL,
+                NULL,
+                &iosb,
+                buffer,
+                count,
+                &offset,
+                NULL);                     
+
+    /* check the return status */
+    if (!NT_SUCCESS(status)) {
+        printf("NtWriteFile request failed 0x%0x\n", status);
+        goto errorout;
+    }
+
+errorout:
+
+    if (NT_SUCCESS(status)) {
+        return (int)(iosb.Information);
+    }
+
+    return cfs_error_code(status);
+}
+
+int cfs_proc_write(
+    int fd, void *buffer,
+    unsigned int count
+    )
+{
+    return cfs_proc_write_internal(fd, buffer, count, 0, 0);
+}
+
+int cfs_proc_ioctl(int fd, int cmd, void *buffer)
+{
+    PUCHAR          procdat = NULL;
+    CFS_PROC_IOCTL  procctl;
+    ULONG           length = 0;
+    ULONG           extra = 0;
+    int             rc = 0;
+
+    NTSTATUS        status = STATUS_UNSUCCESSFUL;
+    IO_STATUS_BLOCK iosb;
+
+    struct libcfs_ioctl_data * portal = buffer;
+    struct obd_ioctl_data * obd = buffer;
+    struct obd_ioctl_data * data;
+
+    HANDLE handle = cfs_idr_find(cfs_proc_idp, fd);
+#if defined(_X86_)
+    CLASSERT(sizeof(struct obd_ioctl_data) == 528);
+#else
+    CLASSERT(sizeof(struct obd_ioctl_data) == 576);
+#endif
+    memset(&procctl, 0, sizeof(CFS_PROC_IOCTL));
+    procctl.cmd = cmd;
+
+    if(_IOC_TYPE(cmd) == IOC_LIBCFS_TYPE) {
+        length = portal->ioc_len;
+    } else if (_IOC_TYPE(cmd) == 'f') {
+        length = obd->ioc_len;
+        extra = size_round(obd->ioc_plen1) + size_round(obd->ioc_plen2);
+    } else if(_IOC_TYPE(cmd) == 'u') {
+        length = 4;
+        extra  = 0;
+    } else if(_IOC_TYPE(cmd) == 'i') {
+        length = obd->ioc_len;
+        extra  = 0;
+    } else {
+        printf("cfs_proc_ioctl: un-supported ioctl type ...\n");
+        cfs_enter_debugger();
+        status = STATUS_INVALID_PARAMETER;
+        goto errorout;
+    }
+
+    procctl.len = length + extra;
+    procdat = malloc(length + extra + sizeof(CFS_PROC_IOCTL));
+
+    if (NULL == procdat) {
+        printf("user:winnt-proc:cfs_proc_ioctl: no enough memory ...\n");
+        status = STATUS_INSUFFICIENT_RESOURCES;
+        cfs_enter_debugger();
+        goto errorout;
+    }
+    memset(procdat, 0, length + extra + sizeof(CFS_PROC_IOCTL));
+    memcpy(procdat, &procctl, sizeof(CFS_PROC_IOCTL));
+    memcpy(&procdat[sizeof(CFS_PROC_IOCTL)], buffer, length);
+    length += sizeof(CFS_PROC_IOCTL);
+
+    if (_IOC_TYPE(cmd) == 'f') {
+
+        data  = (struct obd_ioctl_data *) (procdat + sizeof(CFS_PROC_IOCTL));
+        if ( cmd != (ULONG)OBD_IOC_BRW_WRITE  &&
+             cmd != (ULONG)OBD_IOC_BRW_READ ) {
+
+            if (obd->ioc_pbuf1 && data->ioc_plen1) {
+                data->ioc_pbuf1 = &procdat[length];
+                memcpy(data->ioc_pbuf1, obd->ioc_pbuf1, obd->ioc_plen1); 
+                length += size_round(obd->ioc_plen1);
+            } else {
+                data->ioc_plen1 = 0;
+                data->ioc_pbuf1 = NULL;
+            }
+
+            if (obd->ioc_pbuf2 && obd->ioc_plen2) {
+                data->ioc_pbuf2 = &procdat[length];
+                memcpy(data->ioc_pbuf2, obd->ioc_pbuf2, obd->ioc_plen2);
+                length += size_round(obd->ioc_plen2);
+            } else {
+                data->ioc_plen2 = 0;
+                data->ioc_pbuf2 = NULL;
+            }
+               } else {
+             extra = 0;
+        }
+
+        ASSERT(length == extra + sizeof(CFS_PROC_IOCTL) + data->ioc_len);
+        if (obd_ioctl_is_invalid(obd)) {
+            cfs_enter_debugger();
+        }