Whamcloud - gitweb
* Landed portals:b_port_step as follows...
authoreeb <eeb>
Fri, 4 Feb 2005 18:50:00 +0000 (18:50 +0000)
committereeb <eeb>
Fri, 4 Feb 2005 18:50:00 +0000 (18:50 +0000)
  - removed CFS_DECL_SPIN*
    just use 'spinlock_t' and initialise with spin_lock_init()

  - removed CFS_DECL_MUTEX*
    just use 'struct semaphore' and initialise with init_mutex()

  - removed CFS_DECL_RWSEM*
    just use 'struct rw_semaphore' and initialise with init_rwsem()

  - renamed cfs_sleep_chan -> cfs_waitq
            cfs_sleep_link -> cfs_waitlink

          - fixed race in linux version of arch-independent socknal
       (the ENOMEM/EAGAIN decision).

  - Didn't fix problems in Darwin version of arch-independent socknal
      (resetting socket callbacks, eager ack hack, ENOMEM/EAGAIN decision)

  - removed libcfs types from non-socknal header files (only some types
    in the header files had been changed; the .c files hadn't been
    updated at all).

  - Updated lustre b1_4 to match

169 files changed:
lnet/ChangeLog
lnet/autoMakefile.am
lnet/autoconf/lustre-lnet.m4
lnet/include/Makefile.am
lnet/include/libcfs/.cvsignore [new file with mode: 0644]
lnet/include/libcfs/Makefile.am [new file with mode: 0644]
lnet/include/libcfs/curproc.h [new file with mode: 0644]
lnet/include/libcfs/darwin/.cvsignore [new file with mode: 0644]
lnet/include/libcfs/darwin/Makefile.am [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-fs.h [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-lock.h [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-mem.h [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-prim.h [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-sync.h [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-time.h [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-types.h [new file with mode: 0644]
lnet/include/libcfs/darwin/darwin-utils.h [new file with mode: 0644]
lnet/include/libcfs/darwin/kp30.h [new file with mode: 0644]
lnet/include/libcfs/darwin/libcfs.h [new file with mode: 0644]
lnet/include/libcfs/darwin/lltrace.h [new file with mode: 0644]
lnet/include/libcfs/darwin/portals_lib.h [new file with mode: 0644]
lnet/include/libcfs/darwin/portals_utils.h [new file with mode: 0644]
lnet/include/libcfs/kp30.h [moved from lnet/include/linux/kp30.h with 54% similarity]
lnet/include/libcfs/libcfs.h [moved from lnet/include/linux/libcfs.h with 63% similarity]
lnet/include/libcfs/linux/.cvsignore [new file with mode: 0644]
lnet/include/libcfs/linux/Makefile.am [new file with mode: 0644]
lnet/include/libcfs/linux/kp30.h [new file with mode: 0644]
lnet/include/libcfs/linux/libcfs.h [new file with mode: 0644]
lnet/include/libcfs/linux/linux-fs.h [new file with mode: 0644]
lnet/include/libcfs/linux/linux-lock.h [new file with mode: 0644]
lnet/include/libcfs/linux/linux-mem.h [new file with mode: 0644]
lnet/include/libcfs/linux/linux-prim.h [new file with mode: 0644]
lnet/include/libcfs/linux/linux-time.h [new file with mode: 0644]
lnet/include/libcfs/linux/lltrace.h [new file with mode: 0644]
lnet/include/libcfs/linux/portals_compat25.h [moved from lnet/include/linux/portals_compat25.h with 97% similarity]
lnet/include/libcfs/linux/portals_lib.h [new file with mode: 0644]
lnet/include/libcfs/linux/portals_utils.h [new file with mode: 0644]
lnet/include/libcfs/list.h [moved from lnet/include/linux/lustre_list.h with 87% similarity]
lnet/include/libcfs/lltrace.h [moved from lnet/include/lnet/lltrace.h with 90% similarity]
lnet/include/libcfs/portals_lib.h [moved from lnet/include/linux/portals_lib.h with 91% similarity]
lnet/include/libcfs/portals_utils.h [new file with mode: 0644]
lnet/include/libcfs/user-lock.h [new file with mode: 0644]
lnet/include/libcfs/user-prim.h [new file with mode: 0644]
lnet/include/libcfs/user-time.h [new file with mode: 0644]
lnet/include/linux/Makefile.am [deleted file]
lnet/include/lnet/Makefile.am
lnet/include/lnet/api-support.h
lnet/include/lnet/darwin/.cvsignore [moved from lnet/include/linux/.cvsignore with 100% similarity]
lnet/include/lnet/darwin/Makefile.am [new file with mode: 0644]
lnet/include/lnet/darwin/lib-lnet.h [new file with mode: 0644]
lnet/include/lnet/darwin/lib-p30.h [new file with mode: 0644]
lnet/include/lnet/darwin/lib-types.h [new file with mode: 0644]
lnet/include/lnet/darwin/lnet.h [new file with mode: 0644]
lnet/include/lnet/darwin/p30.h [new file with mode: 0644]
lnet/include/lnet/kpr.h [moved from lnet/include/linux/kpr.h with 99% similarity]
lnet/include/lnet/lib-lnet.h
lnet/include/lnet/lib-p30.h
lnet/include/lnet/lib-types.h
lnet/include/lnet/linux/.cvsignore [new file with mode: 0644]
lnet/include/lnet/linux/Makefile.am [new file with mode: 0644]
lnet/include/lnet/linux/lib-lnet.h [new file with mode: 0644]
lnet/include/lnet/linux/lib-p30.h [new file with mode: 0644]
lnet/include/lnet/linux/lib-types.h [new file with mode: 0644]
lnet/include/lnet/linux/lnet.h [new file with mode: 0644]
lnet/include/lnet/linux/p30.h [new file with mode: 0644]
lnet/include/lnet/list.h [deleted file]
lnet/include/lnet/lnet.h
lnet/include/lnet/lnetctl.h
lnet/include/lnet/p30.h
lnet/include/lnet/ptlctl.h
lnet/include/lnet/types.h
lnet/klnds/gmlnd/gmlnd.h
lnet/klnds/iiblnd/iiblnd.h
lnet/klnds/lolnd/autoMakefile.am
lnet/klnds/lolnd/lolnd.h
lnet/klnds/openiblnd/openiblnd.h
lnet/klnds/qswlnd/qswlnd.h
lnet/klnds/ralnd/ralnd.h
lnet/klnds/socklnd/Info.plist [new file with mode: 0644]
lnet/klnds/socklnd/Makefile.in
lnet/klnds/socklnd/autoMakefile.am
lnet/klnds/socklnd/ksocklnd.xcode/project.pbxproj [new file with mode: 0644]
lnet/klnds/socklnd/socklnd.c
lnet/klnds/socklnd/socklnd.h
lnet/klnds/socklnd/socklnd_cb.c
lnet/klnds/socklnd/socklnd_lib-darwin.c [new file with mode: 0644]
lnet/klnds/socklnd/socklnd_lib-darwin.h [new file with mode: 0644]
lnet/klnds/socklnd/socklnd_lib-linux.c [new file with mode: 0644]
lnet/klnds/socklnd/socklnd_lib-linux.h [new file with mode: 0644]
lnet/klnds/viblnd/viblnd.h
lnet/libcfs/Info.plist [new file with mode: 0644]
lnet/libcfs/Makefile.in
lnet/libcfs/autoMakefile.am
lnet/libcfs/darwin/.cvsignore [new file with mode: 0644]
lnet/libcfs/darwin/Makefile.am [new file with mode: 0644]
lnet/libcfs/darwin/darwin-curproc.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-debug.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-fs.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-mem.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-module.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-prim.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-proc.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-sync.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-tracefile.c [new file with mode: 0644]
lnet/libcfs/darwin/darwin-utils.c [new file with mode: 0644]
lnet/libcfs/debug.c
lnet/libcfs/libcfs.xcode/project.pbxproj [new file with mode: 0644]
lnet/libcfs/linux/.cvsignore [new file with mode: 0644]
lnet/libcfs/linux/Makefile.am [new file with mode: 0644]
lnet/libcfs/linux/linux-curproc.c [new file with mode: 0644]
lnet/libcfs/linux/linux-debug.c [new file with mode: 0644]
lnet/libcfs/linux/linux-fs.c [new file with mode: 0644]
lnet/libcfs/linux/linux-lock.c [new file with mode: 0644]
lnet/libcfs/linux/linux-lwt.c [new file with mode: 0644]
lnet/libcfs/linux/linux-mem.c [new file with mode: 0644]
lnet/libcfs/linux/linux-module.c [new file with mode: 0644]
lnet/libcfs/linux/linux-prim.c [new file with mode: 0644]
lnet/libcfs/linux/linux-proc.c [moved from lnet/libcfs/proc.c with 99% similarity]
lnet/libcfs/linux/linux-sync.c [new file with mode: 0644]
lnet/libcfs/linux/linux-tracefile.c [new file with mode: 0644]
lnet/libcfs/linux/linux-utils.c [new file with mode: 0644]
lnet/libcfs/lwt.c
lnet/libcfs/module.c
lnet/libcfs/tracefile.c
lnet/libcfs/tracefile.h
lnet/libcfs/user-lock.c [new file with mode: 0644]
lnet/libcfs/user-prim.c [new file with mode: 0644]
lnet/libcfs/watchdog.c
lnet/lnet/Info.plist [new file with mode: 0644]
lnet/lnet/api-ni.c
lnet/lnet/api-wrap.c
lnet/lnet/autoMakefile.am
lnet/lnet/lib-eq.c
lnet/lnet/lib-init.c
lnet/lnet/lib-md.c
lnet/lnet/lib-me.c
lnet/lnet/lib-move.c
lnet/lnet/lib-msg.c
lnet/lnet/lib-pid.c
lnet/lnet/module.c
lnet/lnet/portals.xcode/project.pbxproj [new file with mode: 0644]
lnet/router/autoMakefile.am
lnet/router/router.h
lnet/tests/arch-linux/ping.h [new file with mode: 0644]
lnet/tests/arch-xnu/ping.h [new file with mode: 0644]
lnet/tests/autoMakefile.am
lnet/tests/build-osx [new file with mode: 0644]
lnet/tests/build.seq [new file with mode: 0644]
lnet/tests/ping.h
lnet/tests/ping_cli.c
lnet/tests/ping_cli/Info.plist [new file with mode: 0644]
lnet/tests/ping_cli/ping_cli.xcode/project.pbxproj [new file with mode: 0644]
lnet/tests/ping_srv.c
lnet/tests/ping_srv/Info.plist [new file with mode: 0644]
lnet/tests/ping_srv/ping_srv.xcode/project.pbxproj [new file with mode: 0644]
lnet/tests/sping_cli.c
lnet/tests/sping_srv.c
lnet/ulnds/address.c
lnet/ulnds/connection.c
lnet/ulnds/select.c
lnet/ulnds/socklnd/address.c
lnet/ulnds/socklnd/connection.c
lnet/ulnds/socklnd/select.c
lnet/utils/acceptor.c
lnet/utils/debug.c
lnet/utils/gmlndnid.c
lnet/utils/l_ioctl.c
lnet/utils/portals.c
lnet/utils/wirecheck.c

index e69de29..3d7f2b0 100644 (file)
@@ -0,0 +1,25 @@
+2005-02-04  Eric Barton  <eeb@bartonsoftware.com>
+
+       * Landed portals:b_port_step as follows...
+
+         - removed CFS_DECL_SPIN* 
+           just use 'spinlock_t' and initialise with spin_lock_init()
+
+         - removed CFS_DECL_MUTEX*
+           just use 'struct semaphore' and initialise with init_mutex()
+
+         - removed CFS_DECL_RWSEM*
+           just use 'struct rw_semaphore' and initialise with init_rwsem()
+
+         - renamed cfs_sleep_chan -> cfs_waitq
+                   cfs_sleep_link -> cfs_waitlink
+
+          - fixed race in linux version of arch-independent socknal
+           (the ENOMEM/EAGAIN decision).
+
+         - Didn't fix problems in Darwin version of arch-independent socknal
+           (resetting socket callbacks, eager ack hack, ENOMEM/EAGAIN decision)
+
+         - removed libcfs types from non-socknal header files (only some types
+           in the header files had been changed; the .c files hadn't been
+           updated at all).
index f2ba240..50d8298 100644 (file)
@@ -3,7 +3,23 @@
 # This code is issued under the GNU General Public License.
 # See the file COPYING in this distribution
 
-SUBDIRS = portals libcfs knals unals router tests doc utils include    \
+SUBDIRS = libcfs portals knals unals router tests doc utils include    \
        autoconf
 
-sources:
+sources: include/libcfs/arch
+       $(MAKE) sources -C libcfs
+
+all-recursive: include/libcfs/arch
+
+include/libcfs/arch:
+       case `uname` in                                           \
+               Linux)                                            \
+                       ln -s linux include/libcfs/arch           \
+                       ;;                                        \
+               Darwin)                                           \
+                       ln -s darwin include/libcfs/arch          \
+                       ;;                                        \
+               *)                                                \
+                       echo "Platform `uname` is not supported"  \
+                       ;;                                        \
+       esac
index 06bdf39..b2abf0a 100644 (file)
@@ -428,6 +428,15 @@ LP_FUNC_SHOW_TASK
 ])
 
 #
+# LP_PROG_DARWIN
+#
+# Darwin checks
+#
+AC_DEFUN([LP_PROG_DARWIN],
+[LB_DARWIN_CHECK_FUNCS([get_preemption_level])
+])
+
+#
 # LP_PATH_DEFAULTS
 #
 # default paths for installed files
@@ -443,7 +452,7 @@ AC_DEFUN([LP_PATH_DEFAULTS],
 #
 AC_DEFUN([LP_CONFIGURE],
 [# portals/utils/portals.c
-AC_CHECK_HEADERS([netdb.h netinet/tcp.h asm/types.h])
+AC_CHECK_HEADERS([netdb.h netinet/tcp.h asm/types.h endian.h])
 AC_CHECK_FUNCS([gethostbyname socket connect])
 
 # portals/utils/debug.c
@@ -454,22 +463,20 @@ AC_CHECK_TYPE([spinlock_t],
        [],
        [#include <linux/spinlock.h>])
 
+# portals/utils/wirecheck.c
+AC_CHECK_FUNCS([strnlen])
+
 # --------  Check for required packages  --------------
 
-# this doesn't seem to work on older autoconf
-# AC_CHECK_LIB(readline, readline,,)
-AC_MSG_CHECKING([for readline support])
-AC_ARG_ENABLE(readline,
-       AC_HELP_STRING([--disable-readline],
-                       [do not use readline library]),
-       [],[enable_readline='yes'])
-AC_MSG_RESULT([$enable_readline]) 
-if test x$enable_readline = xyes ; then
+LIBS_save="$LIBS"
+LIBS="-lncurses $LIBS"
+AC_CHECK_LIB([readline],[readline],[
        LIBREADLINE="-lreadline -lncurses"
        AC_DEFINE(HAVE_LIBREADLINE, 1, [readline library is available])
-else 
+],[
        LIBREADLINE=""
-fi
+])
+LIBS="$LIBS_save"
 AC_SUBST(LIBREADLINE)
 
 AC_MSG_CHECKING([if efence debugging support is requested])
@@ -573,8 +580,12 @@ portals/autoMakefile
 portals/autoconf/Makefile
 portals/doc/Makefile
 portals/include/Makefile
-portals/include/linux/Makefile
+portals/include/libcfs/Makefile
+portals/include/libcfs/darwin/Makefile
+portals/include/libcfs/linux/Makefile
 portals/include/portals/Makefile
+portals/include/portals/darwin/Makefile
+portals/include/portals/linux/Makefile
 portals/knals/Makefile
 portals/knals/autoMakefile
 portals/knals/gmnal/Makefile
@@ -595,6 +606,8 @@ portals/knals/socknal/Makefile
 portals/knals/socknal/autoMakefile
 portals/libcfs/Makefile
 portals/libcfs/autoMakefile
+portals/libcfs/darwin/Makefile
+portals/libcfs/linux/Makefile
 portals/portals/Makefile
 portals/portals/autoMakefile
 portals/router/Makefile
index 2b3eb8c..dd6db1d 100644 (file)
@@ -1,3 +1,3 @@
-SUBDIRS = linux portals
+SUBDIRS = libcfs portals
 
 EXTRA_DIST = cygwin-ioctl.h
diff --git a/lnet/include/libcfs/.cvsignore b/lnet/include/libcfs/.cvsignore
new file mode 100644 (file)
index 0000000..3dda729
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
diff --git a/lnet/include/libcfs/Makefile.am b/lnet/include/libcfs/Makefile.am
new file mode 100644 (file)
index 0000000..1e928ba
--- /dev/null
@@ -0,0 +1,3 @@
+SUBDIRS := darwin linux
+
+EXTRA_DIST := libcfs.h list.h lltrace.h kp30.h portals_utils.h portals_lib.h
diff --git a/lnet/include/libcfs/curproc.h b/lnet/include/libcfs/curproc.h
new file mode 100644 (file)
index 0000000..630912d
--- /dev/null
@@ -0,0 +1,62 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Lustre curproc API declaration
+ *
+ * Copyright (C) 2004 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of Lustre, http://www.lustre.org.
+ *
+ * Lustre is free software; you can redistribute it and/or modify it under the
+ * terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation. Lustre 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 for more details. You should have received a copy of the GNU
+ * General Public License along with Lustre; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#ifndef __LIBCFS_CURPROC_H__
+#define __LIBCFS_CURPROC_H__
+
+/*
+ * Portable API to access common characteristics of "current" UNIX process.
+ *
+ * Implemented in portals/include/libcfs/<os>/
+ */
+uid_t  cfs_curproc_uid(void);
+gid_t  cfs_curproc_gid(void);
+uid_t  cfs_curproc_fsuid(void);
+gid_t  cfs_curproc_fsgid(void);
+pid_t  cfs_curproc_pid(void);
+int    cfs_curproc_groups_nr(void);
+int    cfs_curproc_is_in_groups(gid_t group);
+void   cfs_curproc_groups_dump(gid_t *array, int size);
+mode_t cfs_curproc_umask(void);
+char  *cfs_curproc_comm(void);
+
+
+/*
+ * Plus, platform-specific constant
+ *
+ * CFS_CURPROC_COMM_MAX,
+ *
+ * and opaque scalar type
+ *
+ * cfs_kernel_cap_t
+ */
+cfs_kernel_cap_t cfs_curproc_cap_get(void);
+void cfs_curproc_cap_set(cfs_kernel_cap_t cap);
+
+/* __LIBCFS_CURPROC_H__ */
+#endif
+/*
+ * Local variables:
+ * c-indentation-style: "K&R"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 80
+ * scroll-step: 1
+ * End:
+ */
diff --git a/lnet/include/libcfs/darwin/.cvsignore b/lnet/include/libcfs/darwin/.cvsignore
new file mode 100644 (file)
index 0000000..3dda729
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
diff --git a/lnet/include/libcfs/darwin/Makefile.am b/lnet/include/libcfs/darwin/Makefile.am
new file mode 100644 (file)
index 0000000..4ff2072
--- /dev/null
@@ -0,0 +1,3 @@
+EXTRA_DIST := darwin-mem.h darwin-types.h libcfs.h portals_utils.h     \
+       darwin-fs.h darwin-prim.h darwin-utils.h lltrace.h              \
+       darwin-lock.h darwin-sync.h kp30.h portals_lib.h
diff --git a/lnet/include/libcfs/darwin/darwin-fs.h b/lnet/include/libcfs/darwin/darwin-fs.h
new file mode 100644 (file)
index 0000000..32244e7
--- /dev/null
@@ -0,0 +1,131 @@
+#ifndef __LIBCFS_DARWIN_CFS_FS_H__
+#define __LIBCFS_DARWIN_CFS_FS_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+
+#include <sys/types.h>
+#include <sys/systm.h>
+/*
+ * __APPLE_API_PRIVATE is defined before include user.h
+ * Doing this way to get the define of uthread, it's not good
+ * but I do need to know what's inside uthread.
+ */
+#ifndef __APPLE_API_PRIVATE
+#define __APPLE_API_PRIVATE
+#include <sys/vnode.h>
+#undef __APPLE_API_PRIVATE
+#else
+#include <sys/vnode.h>
+#endif
+
+#include <sys/kernel.h>
+#include <sys/file.h>
+#include <sys/time.h>
+#include <sys/filedesc.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <sys/sysctl.h>
+#include <sys/ubc.h>
+#include <sys/mbuf.h>
+#include <sys/namei.h>
+#include <sys/fcntl.h>
+#include <sys/lockf.h>
+#include <stdarg.h>
+
+#include <mach/mach_types.h>
+#include <mach/mach_traps.h>
+#include <mach/time_value.h>
+#include <kern/clock.h>
+#include <sys/param.h>
+#include <IOKit/system.h>
+
+#include <libcfs/darwin/darwin-types.h>
+#include <libcfs/darwin/darwin-lock.h>
+#include <libcfs/darwin/darwin-mem.h>
+#include <libcfs/list.h>
+
+/*
+ * File operating APIs in kernel
+ */
+typedef struct file cfs_file_t;
+
+int    filp_node_size(cfs_file_t *fp, off_t    *size);
+#define cfs_filp_size(fp)                      \
+       ({                                      \
+               off_t           __size;         \
+               filp_node_size((fp), &__size);  \
+               __size;                         \
+        })
+#define cfs_filp_poff(fp)               (NULL)
+
+cfs_file_t *filp_open(const char *name, int flags, int mode, int *err);
+int filp_close(cfs_file_t *fp);
+int filp_read(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
+int filp_write(cfs_file_t *fp, void *buf, size_t nbytes, off_t *pos);
+int filp_fsync(cfs_file_t *fp);
+
+#define cfs_filp_open(n, f, m, e)      filp_open(n, f, m, e)
+#define cfs_filp_close(f)              filp_close(f)
+#define cfs_filp_read(f, b, n, p)      filp_read(f, b, n, p)
+#define cfs_filp_write(f, b, n, p)     filp_write(f, b, n, p)
+#define cfs_filp_fsync(f)              filp_fsync(f)
+
+int ref_file(cfs_file_t *fp);
+int rele_file(cfs_file_t *fp);
+int file_count(cfs_file_t *fp);
+#define cfs_get_file(f)                        ref_file(f)
+#define cfs_put_file(f)                        rele_file(f)
+#define cfs_file_count(f)              file_count(f)
+
+#define CFS_INT_LIMIT(x)               (~((x)1 << (sizeof(x)*8 - 1)))
+#define CFS_OFFSET_MAX                 CFS_INT_LIMIT(loff_t)
+
+typedef struct flock                   cfs_flock_t;
+#define CFS_FLOCK_TYPE(fl)             ((fl)->l_type)
+#define CFS_FLOCK_SET_TYPE(fl, type)   do { (fl)->l_type = (type); } while(0)
+#define CFS_FLOCK_PID(fl)              ((fl)->l_pid)
+#define CFS_FLOCK_SET_PID(fl, pid)     do { (fl)->l_pid = (pid); } while(0)
+#define CFS_FLOCK_START(fl)            ((fl)->l_start)
+#define CFS_FLOCK_SET_START(fl, start) do { (fl)->l_start = (start); } while(0)
+#define CFS_FLOCK_END(fl)              ((fl)->l_len == 0? CFS_OFFSET_MAX: ((fl)->l_start + (fl)->l_en))
+#define CFS_FLOCK_SET_END(fl, end)             \
+       do {                                    \
+               if (end == CFS_OFFSET_MAX)      \
+                       (fl)->l_len = 0;        \
+               else                            \
+                       (fl)->l_len = (end) - (fl)->l_start;\
+       } while(0)
+
+typedef struct {
+       void    *d;
+} cfs_dentry_t;
+typedef unsigned short umode_t;
+
+#define ATTR_MODE       0x0001
+#define ATTR_UID        0x0002
+#define ATTR_GID        0x0004
+#define ATTR_SIZE       0x0008
+#define ATTR_ATIME      0x0010
+#define ATTR_MTIME      0x0020
+#define ATTR_CTIME      0x0040
+#define ATTR_ATIME_SET  0x0080
+#define ATTR_MTIME_SET  0x0100
+#define ATTR_FORCE      0x0200  /* Not a change, but a change it */
+#define ATTR_ATTR_FLAG  0x0400
+#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 in_group_p(x)  (0)
+
+#endif
+
+#define O_SYNC                                 0
+#define O_DIRECTORY                            0
+#define O_LARGEFILE                            0
+
+#endif
diff --git a/lnet/include/libcfs/darwin/darwin-lock.h b/lnet/include/libcfs/darwin/darwin-lock.h
new file mode 100644 (file)
index 0000000..da16418
--- /dev/null
@@ -0,0 +1,264 @@
+#ifndef __LIBCFS_DARWIN_CFS_LOCK_H__
+#define __LIBCFS_DARWIN_CFS_LOCK_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+#include <mach/sync_policy.h>
+#include <mach/task.h>
+#include <mach/semaphore.h>
+#include <mach/mach_traps.h>
+
+/* spin lock types and operations */
+#include <kern/simple_lock.h>
+#include <kern/assert.h>
+#include <kern/thread.h>
+
+#include <libcfs/darwin/darwin-types.h>
+#include <libcfs/darwin/darwin-sync.h>
+
+/*
+ * spin_lock (use Linux kernel's primitives)
+ * 
+ * - spin_lock_init(x)
+ * - spin_lock(x)
+ * - spin_unlock(x)
+ * - spin_trylock(x)
+ * 
+ * - spin_lock_irqsave(x, f)
+ * - spin_unlock_irqrestore(x, f)
+ */
+struct spin_lock {
+       struct kspin spin;
+};
+
+typedef struct spin_lock spinlock_t;
+
+static inline void spin_lock_init(spinlock_t *lock)
+{
+       kspin_init(&lock->spin);
+}
+
+static inline void spin_lock(spinlock_t *lock)
+{
+       kspin_lock(&lock->spin);
+}
+
+static inline void spin_unlock(spinlock_t *lock)
+{
+       kspin_unlock(&lock->spin);
+}
+
+static inline int spin_trylock(spinlock_t *lock)
+{
+       return kspin_trylock(&lock->spin);
+}
+
+#define spin_lock_bh(x)                spin_lock(x)
+#define spin_unlock_bh(x)      spin_unlock(x)
+#define spin_lock_bh_init(x)   spin_lock_init(x)
+
+extern boolean_t ml_set_interrupts_enabled(boolean_t enable);
+#define __disable_irq()         (spl_t) ml_set_interrupts_enabled(FALSE)
+#define __enable_irq(x)         (void) ml_set_interrupts_enabled(x)
+
+#define spin_lock_irqsave(s, f)                do{                     \
+                                       f = __disable_irq();    \
+                                       spin_lock(s);   }while(0)
+
+#define spin_unlock_irqrestore(s, f)   do{                     \
+                                       spin_unlock(s);         \
+                                       __enable_irq(f);}while(0)
+
+/* 
+ * Semaphore
+ *
+ * - sema_init(x, v)
+ * - __down(x)
+ * - __up(x)
+ */
+struct semaphore {
+       struct ksem sem;
+};
+
+static inline void sema_init(struct semaphore *s, int val)
+{
+       ksem_init(&s->sem, val);
+}
+
+static inline void __down(struct semaphore *s)
+{
+       ksem_down(&s->sem, 1);
+}
+
+static inline void __up(struct semaphore *s)
+{
+       ksem_up(&s->sem, 1);
+}
+
+/*
+ * Mutex:
+ *
+ * - init_mutex(x)
+ * - init_mutex_locked(x)
+ * - mutex_up(x)
+ * - mutex_down(x)
+ */
+
+#define mutex_up(s)                    __up(s)
+#define mutex_down(s)                  __down(s)
+
+#define init_mutex(x)                  sema_init(x, 1)
+#define init_mutex_locked(x)           sema_init(x, 0)
+
+/*
+ * Completion:
+ *
+ * - init_completion(c)
+ * - complete(c)
+ * - wait_for_completion(c)
+ */
+struct completion {
+       /*
+        * Emulate completion by semaphore for now.
+        *
+        * XXX nikita: this is not safe if completion is used to synchronize
+        * exit from kernel daemon thread and kext unloading. In this case
+        * some core function (a la complete_and_exit()) is needed.
+        */
+       struct ksem sem;
+};
+
+static inline void init_completion(struct completion *c)
+{
+       ksem_init(&c->sem, 0);
+}
+
+static inline void complete(struct completion *c)
+{
+       ksem_up(&c->sem, 1);
+}
+
+static inline void wait_for_completion(struct completion *c)
+{
+       ksem_down(&c->sem, 1);
+}
+
+/*
+ * rw_semaphore:
+ *
+ * - DECLARE_RWSEM(x)
+ * - init_rwsem(x)
+ * - down_read(x)
+ * - up_read(x)
+ * - down_write(x)
+ * - up_write(x)
+ */
+struct rw_semaphore {
+       struct krw_sem s;
+};
+
+static inline void init_rwsem(struct rw_semaphore *s)
+{
+       krw_sem_init(&s->s);
+}
+
+static inline void down_read(struct rw_semaphore *s)
+{
+       krw_sem_down_r(&s->s);
+}
+
+static inline int down_read_trylock(struct rw_semaphore *s)
+{
+       int ret = krw_sem_down_r_try(&s->s);
+       return ret == 0? 1: 0;
+}
+
+static inline void down_write(struct rw_semaphore *s)
+{
+       krw_sem_down_w(&s->s);
+}
+
+static inline int down_write_trylock(struct rw_semaphore *s)
+{
+       int ret = krw_sem_down_w_try(&s->s);
+       return ret == 0? 1: 0;
+}
+
+static inline void up_read(struct rw_semaphore *s)
+{
+       krw_sem_up_r(&s->s);
+}
+
+static inline void up_write(struct rw_semaphore *s)
+{
+       krw_sem_up_w(&s->s);
+}
+
+/* 
+ * read-write lock : Need to be investigated more!!
+ * XXX nikita: for now, let rwlock_t to be identical to rw_semaphore
+ *
+ * - DECLARE_RWLOCK(l)
+ * - rwlock_init(x)
+ * - read_lock(x)
+ * - read_unlock(x)
+ * - write_lock(x)
+ * - write_unlock(x)
+ */
+typedef struct rw_semaphore rwlock_t;
+
+#define rwlock_init(pl)                init_rwsem(pl)
+
+#define read_lock(l)           down_read(l)
+#define read_unlock(l)         up_read(l)
+#define write_lock(l)          down_write(l)
+#define write_unlock(l)                up_write(l)
+
+#define write_lock_irqsave(l, f)       do{                     \
+                                       f = __disable_irq();    \
+                                       write_lock(l);  }while(0)
+
+#define write_unlock_irqrestore(l, f)  do{                     \
+                                       write_unlock(l);        \
+                                       __enable_irq(f);}while(0)
+
+#define read_lock_irqsave(l, f)                do{                     \
+                                       f = __disable_irq();    \
+                                       read_lock(l);   }while(0)
+
+#define read_unlock_irqrestore(l, f)   do{                     \
+                                       read_unlock(l);         \
+                                       __enable_irq(f);}while(0)
+
+/*
+ * Funnel: 
+ *
+ * Safe funnel in/out
+ */
+
+#define CFS_DECL_FUNNEL_DATA                   \
+        boolean_t    __funnel_state = FALSE;   \
+        funnel_t    *__funnel
+#define CFS_DECL_CONE_DATA             CFS_DECL_FUNNEL_DATA
+#define CFS_DECL_NET_DATA              CFS_DECL_FUNNEL_DATA
+
+void lustre_cone_in(boolean_t *state, funnel_t **cone);
+void lustre_cone_ex(boolean_t state, funnel_t *cone);
+
+#define CFS_CONE_IN lustre_cone_in(&__funnel_state, &__funnel)
+#define CFS_CONE_EX lustre_cone_ex(__funnel_state, __funnel)
+
+void lustre_net_in(boolean_t *state, funnel_t **cone);
+void lustre_net_ex(boolean_t state, funnel_t *cone);
+
+#define CFS_NET_IN  lustre_net_in(&__funnel_state, &__funnel)
+#define CFS_NET_EX  lustre_net_ex(__funnel_state, __funnel)
+
+/* __KERNEL__ */
+#endif
+
+/* __XNU_CFS_LOCK_H */
+#endif
diff --git a/lnet/include/libcfs/darwin/darwin-mem.h b/lnet/include/libcfs/darwin/darwin-mem.h
new file mode 100644 (file)
index 0000000..922a1b8
--- /dev/null
@@ -0,0 +1,206 @@
+#ifndef __LIBCFS_DARWIN_CFS_MEM_H__
+#define __LIBCFS_DARWIN_CFS_MEM_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#include <sys/vm.h>
+#include <sys/kernel.h>
+#include <sys/ubc.h>
+#include <sys/uio.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/lockf.h>
+
+#include <mach/mach_types.h>
+#include <mach/vm_types.h>
+#include <vm/pmap.h>
+#include <vm/vm_kern.h>
+#include <mach/machine/vm_param.h>
+#include <kern/thread_call.h>
+#include <sys/param.h>
+#include <sys/vm.h>
+
+#include <libcfs/darwin/darwin-types.h>
+#include <libcfs/darwin/darwin-sync.h>
+#include <libcfs/darwin/darwin-lock.h>
+#include <libcfs/list.h>
+
+/*
+ * Page of OSX
+ *
+ * There is no page in OSX, however, we need page in lustre.
+ */
+#define PAGE_MASK                              (~(PAGE_SIZE-1))
+#define _ALIGN_UP(addr,size)                   (((addr)+((size)-1))&(~((size)-1)))
+#define _ALIGN(addr,size)                      _ALIGN_UP(addr,size)
+#define PAGE_ALIGN(addr)                       _ALIGN(addr, PAGE_SIZE)
+
+/*
+ * Basic xnu_page struct, should be binary compatibility with
+ * all page types in xnu (we have only xnu_raw_page, xll_page now)
+ */
+
+/* Variable sized pages are not supported */
+
+#define CFS_PAGE_SHIFT 12
+#define CFS_PAGE_SIZE  (1 << CFS_PAGE_SHIFT)
+#define PAGE_CACHE_SIZE CFS_PAGE_SIZE
+#define CFS_PAGE_MASK  (~(CFS_PAGE_SIZE - 1))
+
+enum {
+       XNU_PAGE_RAW,
+       XNU_PAGE_XLL,
+       XNU_PAGE_NTYPES
+};
+
+typedef __u32 page_off_t;
+
+/*
+ * For XNU we have our own page cache built on top of underlying BSD/MACH
+ * infrastructure. In particular, we have two disjoint types of pages:
+ *
+ *    - "raw" pages (XNU_PAGE_RAW): these are just buffers mapped into KVM,
+ *    based on UPLs, and
+ *
+ *    - "xll" pages (XNU_PAGE_XLL): these are used by file system to cache
+ *    file data, owned by file system objects, hashed, lrued, etc.
+ *
+ * cfs_page_t has to cover both of them, because core Lustre code is based on
+ * the Linux assumption that page is _both_ memory buffer and file system
+ * caching entity.
+ *
+ * To achieve this, all types of pages supported on XNU has to start from
+ * common header that contains only "page type". Common cfs_page_t operations
+ * dispatch through operation vector based on page type.
+ *
+ */
+typedef struct xnu_page {
+       int type;
+} cfs_page_t;
+
+struct xnu_page_ops {
+       void *(*page_map)        (cfs_page_t *);
+       void  (*page_unmap)      (cfs_page_t *);
+       void *(*page_address)    (cfs_page_t *);
+};
+
+void xnu_page_ops_register(int type, struct xnu_page_ops *ops);
+void xnu_page_ops_unregister(int type);
+
+/*
+ * raw page, no cache object, just like buffer
+ */
+struct xnu_raw_page {
+       struct xnu_page header;
+       vm_address_t    virtual;
+       upl_t           upl;
+       int             order;
+       atomic_t        count;
+       void           *private;
+};
+
+/*
+ * Public interface to lustre
+ *
+ * - cfs_alloc_pages(f, o)
+ * - cfs_alloc_page(f)
+ * - cfs_free_pages(p, o)
+ * - cfs_free_page(p)
+ * - cfs_kmap(p)
+ * - cfs_kunmap(p)
+ * - cfs_page_address(p)
+ */
+
+/*
+ * Of all functions above only cfs_kmap(), cfs_kunmap(), and
+ * cfs_page_address() can be called on file system pages. The rest is for raw
+ * pages only.
+ */
+
+cfs_page_t *cfs_alloc_pages(u_int32_t flags, u_int32_t order);
+cfs_page_t *cfs_alloc_page(u_int32_t flags);
+void cfs_free_pages(cfs_page_t *pages, int order);
+void cfs_free_page(cfs_page_t *page);
+void cfs_get_page(cfs_page_t *page);
+int cfs_put_page_testzero(cfs_page_t *page);
+int cfs_page_count(cfs_page_t *page);
+void cfs_set_page_count(cfs_page_t *page, int v);
+
+void *cfs_page_address(cfs_page_t *pg);
+void *cfs_kmap(cfs_page_t *pg);
+void cfs_kunmap(cfs_page_t *pg);
+
+/*
+ * Memory allocator
+ */
+
+extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
+extern void  cfs_free(void *addr);
+
+extern void *cfs_alloc_large(size_t nr_bytes);
+extern void  cfs_free_large(void *addr);
+
+/*
+ * Slab:
+ *
+ * No slab in OSX, use zone allocator to fake slab
+ */
+#define SLAB_HWCACHE_ALIGN             0
+
+typedef struct cfs_mem_cache {
+       struct list_head        link;
+       zone_t                  zone;
+       int                     size;
+       char                    name [ZONE_NAME_MAX_LEN];
+} cfs_mem_cache_t;
+
+#define KMEM_CACHE_MAX_COUNT   64
+#define KMEM_MAX_ZONE          8192
+
+extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, unsigned long,
+                                              void (*)(void *, cfs_mem_cache_t *, unsigned long),
+                                              void (*)(void *, cfs_mem_cache_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 *);
+
+/*
+ * Misc
+ */
+/* XXX fix me */
+#define num_physpages                  (64 * 1024)
+
+#define CFS_DECL_MMSPACE               
+#define CFS_MMSPACE_OPEN               do {} while(0)
+#define CFS_MMSPACE_CLOSE              do {} while(0)
+
+#define copy_from_user(kaddr, uaddr, size)     copyin((caddr_t)uaddr, (caddr_t)kaddr, size)
+#define copy_to_user(uaddr, kaddr, size)       copyout((caddr_t)kaddr, (caddr_t)uaddr, size)
+
+#if defined (__ppc__)
+#define mb()  __asm__ __volatile__ ("sync" : : : "memory")
+#define rmb()  __asm__ __volatile__ ("sync" : : : "memory")
+#define wmb()  __asm__ __volatile__ ("eieio" : : : "memory")
+#elif defined (__i386__)
+#define mb()    __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
+#define rmb()   mb()
+#define wmb()   __asm__ __volatile__ ("": : :"memory")
+#else
+#error architecture not supported
+#endif
+
+#else  /* !__KERNEL__ */
+
+typedef struct cfs_page{
+       void    *foo;
+} cfs_page_t;
+#endif /* __KERNEL__ */
+
+#endif /* __XNU_CFS_MEM_H__ */
diff --git a/lnet/include/libcfs/darwin/darwin-prim.h b/lnet/include/libcfs/darwin/darwin-prim.h
new file mode 100644 (file)
index 0000000..ce9078d
--- /dev/null
@@ -0,0 +1,554 @@
+#ifndef __LIBCFS_DARWIN_CFS_PRIM_H__
+#define __LIBCFS_DARWIN_CFS_PRIM_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#ifndef __APPLE_API_PRIVATE
+#define __APPLE_API_PRIVATE
+#include <sys/user.h>
+#undef __APPLE_API_PRIVATE
+#else
+#include <sys/user.h>
+#endif
+
+#include <sys/kernel.h>
+
+#include <mach/thread_act.h>
+#include <mach/mach_types.h>
+#include <mach/mach_traps.h>
+#include <mach/thread_switch.h>
+#include <mach/time_value.h>
+#include <kern/sched_prim.h>
+#include <vm/pmap.h>
+#include <vm/vm_kern.h>
+#include <mach/machine/vm_param.h>
+#include <kern/clock.h>
+#include <kern/thread_call.h>
+#include <sys/param.h>
+#include <sys/vm.h>
+
+#include <libcfs/darwin/darwin-types.h>
+#include <libcfs/darwin/darwin-utils.h>
+#include <libcfs/darwin/darwin-lock.h>
+
+/*
+ * Symbol functions for libcfs
+ *
+ * OSX has no facility for use to register symbol.
+ * So we have to implement it.
+ */
+#define CFS_SYMBOL_LEN     64
+
+struct  cfs_symbol {
+       char    name[CFS_SYMBOL_LEN];
+       void    *value;
+       int     ref;
+       struct  list_head sym_list;
+};
+
+extern kern_return_t            cfs_symbol_register(const char *, const void *);
+extern kern_return_t            cfs_symbol_unregister(const char *);
+extern void *                   cfs_symbol_get(const char *);
+extern kern_return_t            cfs_symbol_put(const char *);
+
+/*
+ * sysctl typedef
+ *
+ * User can register/unregister a list of sysctl_oids
+ * sysctl_oid is data struct of osx's sysctl-entry
+ */
+typedef struct sysctl_oid *     cfs_sysctl_table_t;
+typedef cfs_sysctl_table_t      cfs_sysctl_table_header_t;
+cfs_sysctl_table_header_t      *register_cfs_sysctl_table (cfs_sysctl_table_t *table, int arg);
+void unregister_cfs_sysctl_table (cfs_sysctl_table_header_t *table);
+
+/*
+ * Proc file system APIs, no /proc fs support in OSX
+ */
+typedef struct cfs_proc_dir_entry{
+       void            *data;
+}cfs_proc_dir_entry_t;
+
+cfs_proc_dir_entry_t * cfs_create_proc_entry(char *name, int mod,
+                                         cfs_proc_dir_entry_t *parent);
+void cfs_free_proc_entry(cfs_proc_dir_entry_t *de);
+void cfs_remove_proc_entry(char *name, cfs_proc_dir_entry_t *entry);
+
+typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
+                         int count, int *eof, void *data);
+typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
+                          unsigned long count, void *data);
+
+/*
+ * cfs pseudo device
+ *
+ * cfs_psdev_t
+ * cfs_psdev_register:
+ * cfs_psdev_deregister:
+ */
+typedef struct {
+       int             index;
+       void            *handle;
+       const char      *name;
+       struct cdevsw   *devsw;
+       void            *private;
+} cfs_psdev_t;
+
+extern kern_return_t            cfs_psdev_register(cfs_psdev_t *);
+extern kern_return_t            cfs_psdev_deregister(cfs_psdev_t *);
+
+/*
+ * Task struct and ...
+ *
+ * Using BSD current_proc in Darwin
+ */
+extern boolean_t        assert_wait_possible(void);
+extern void             *get_bsdtask_info(task_t);
+
+typedef struct uthread         cfs_task_t;
+#define current_uthread()       ((struct uthread *)get_bsdthread_info(current_act()))
+#define cfs_current()          current_uthread()
+
+#define set_current_state(s)   do {;} while (0)
+#define reparent_to_init()     do {;} while (0)
+
+#define CFS_DECL_JOURNAL_DATA  
+#define CFS_PUSH_JOURNAL       do {;} while(0)
+#define CFS_POP_JOURNAL                do {;} while(0)
+
+#define THREAD_NAME(comm, fmt, a...)
+/*
+ * Kernel thread:
+ *
+ * OSX kernel thread can not be created with args,
+ * so we have to implement new APIs to create thread with args
+ *
+ * All requests to create kernel thread will create a new
+ * thread instance of cfs_thread_agent, one by one.
+ * cfs_thread_agent will call the caller's thread function
+ * with argument supplied by caller.
+ */
+
+typedef int (*cfs_thread_t)(void *);
+
+extern task_t  kernel_task;
+
+struct kernel_thread_arg
+{
+       spinlock_t      lock;
+       atomic_t        inuse;
+       cfs_thread_t    func;
+       void            *arg;
+};
+
+extern struct kernel_thread_arg cfs_thread_arg;
+extern void cfs_thread_agent(void);
+
+#define THREAD_ARG_FREE                        0
+#define THREAD_ARG_HOLD                        1
+#define THREAD_ARG_RECV                        2
+
+#define set_targ_stat(a, v)            atomic_set(&(a)->inuse, v)
+#define get_targ_stat(a)               atomic_read(&(a)->inuse)
+
+/*
+ * Hold the thread argument and set the status of thread_status
+ * to THREAD_ARG_HOLD, if the thread argument is held by other
+ * threads (It's THREAD_ARG_HOLD already), current-thread has to wait.
+ */
+#define thread_arg_hold(pta, _func, _arg)                      \
+       do {                                                    \
+               spin_lock(&(pta)->lock);                        \
+               if (get_targ_stat(pta) == THREAD_ARG_FREE) {    \
+                       set_targ_stat((pta), THREAD_ARG_HOLD);  \
+                       (pta)->arg = (void *)_arg;              \
+                       (pta)->func = _func;                    \
+                       spin_unlock(&(pta)->lock);              \
+                       break;                                  \
+               }                                               \
+               spin_unlock(&(pta)->lock);                      \
+               schedule();                                     \
+       } while(1);                                             \
+
+/*
+ * Release the thread argument if the thread argument has been
+ * received by the child-thread (Status of thread_args is
+ * THREAD_ARG_RECV), otherwise current-thread has to wait.
+ * After release, the thread_args' status will be set to
+ * THREAD_ARG_FREE, and others can re-use the thread_args to
+ * create new kernel_thread.
+ */
+#define thread_arg_release(pta)                                        \
+       do {                                                    \
+               spin_lock(&(pta)->lock);                        \
+               if (get_targ_stat(pta) == THREAD_ARG_RECV) {    \
+                       (pta)->arg = NULL;                      \
+                       (pta)->func = NULL;                     \
+                       set_targ_stat(pta, THREAD_ARG_FREE);    \
+                       spin_unlock(&(pta)->lock);              \
+                       break;                                  \
+               }                                               \
+               spin_unlock(&(pta)->lock);                      \
+               schedule();                                     \
+       } while(1)
+
+/*
+ * Receive thread argument (Used in child thread), set the status
+ * of thread_args to THREAD_ARG_RECV.
+ */
+#define __thread_arg_recv_fin(pta, _func, _arg, fin)           \
+       do {                                                    \
+               spin_lock(&(pta)->lock);                        \
+               if (get_targ_stat(pta) == THREAD_ARG_HOLD) {    \
+                       if (fin)                                \
+                           set_targ_stat(pta, THREAD_ARG_RECV);\
+                       _arg = (pta)->arg;                      \
+                       _func = (pta)->func;                    \
+                       spin_unlock(&(pta)->lock);              \
+                       break;                                  \
+               }                                               \
+               spin_unlock(&(pta)->lock);                      \
+               schedule();                                     \
+       } while (1);                                            \
+
+/*
+ * Just set the thread_args' status to THREAD_ARG_RECV
+ */
+#define thread_arg_fin(pta)                                    \
+       do {                                                    \
+               spin_lock(&(pta)->lock);                        \
+               assert( get_targ_stat(pta) == THREAD_ARG_HOLD); \
+               set_targ_stat(pta, THREAD_ARG_RECV);            \
+               spin_unlock(&(pta)->lock);                      \
+       } while(0)
+
+#define thread_arg_recv(pta, f, a)     __thread_arg_recv_fin(pta, f, a, 1)
+#define thread_arg_keep(pta, f, a)     __thread_arg_recv_fin(pta, f, a, 0)
+
+/*
+ * cloning flags, no use in OSX, just copy them from Linux
+ */
+#define CSIGNAL         0x000000ff      /* signal mask to be sent at exit */
+#define CLONE_VM        0x00000100      /* set if VM shared between processes */
+#define CLONE_FS        0x00000200      /* set if fs info shared between processes */
+#define CLONE_FILES     0x00000400      /* set if open files shared between processes */
+#define CLONE_SIGHAND   0x00000800      /* set if signal handlers and blocked signals shared */
+#define CLONE_PID       0x00001000      /* set if pid shared */
+#define CLONE_PTRACE    0x00002000      /* set if we want to let tracing continue on the child too */
+#define CLONE_VFORK     0x00004000      /* set if the parent wants the child to wake it up on mm_release */
+#define CLONE_PARENT    0x00008000      /* set if we want to have the same parent as the cloner */
+#define CLONE_THREAD    0x00010000      /* Same thread group? */
+#define CLONE_NEWNS     0x00020000      /* New namespace group? */
+
+#define CLONE_SIGNAL    (CLONE_SIGHAND | CLONE_THREAD)
+
+extern int cfs_kernel_thread(cfs_thread_t func, void *arg, int flag);
+
+
+/*
+ * Wait Queue implementation
+ *
+ * Like wait_queue in Linux
+ */
+typedef struct cfs_waitq {
+       struct ksleep_chan wq_ksleep_chan;
+} cfs_waitq_t;
+
+typedef struct cfs_waitlink {
+       struct cfs_waitq   *wl_waitq;
+       struct ksleep_link  wl_ksleep_link;
+} cfs_waitlink_t;
+
+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_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq);
+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_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link, 
+                                  cfs_duration_t timeout);
+
+/*
+ * Thread schedule APIs.
+ */
+#define MAX_SCHEDULE_TIMEOUT    ((long)(~0UL>>12))
+
+static inline int schedule_timeout(int64_t timeout)
+{
+       int          result;
+       
+       AbsoluteTime clock_current;
+       AbsoluteTime clock_delay;
+       result = assert_wait((event_t)current_uthread(), THREAD_UNINT);
+       clock_get_uptime(&clock_current);
+       nanoseconds_to_absolutetime(timeout, &clock_delay);
+       ADD_ABSOLUTETIME(&clock_current, &clock_delay);
+       thread_set_timer_deadline(clock_current);
+       if (result == THREAD_WAITING)
+               result = thread_block(THREAD_CONTINUE_NULL);
+       thread_cancel_timer();
+       if (result == THREAD_TIMED_OUT)
+               result = 0;
+       else
+               result = 1;
+       return result;
+}
+
+#define schedule()                              \
+       do {                                    \
+               if (assert_wait_possible())     \
+                       schedule_timeout(1);    \
+               else                            \
+                       schedule_timeout(0);    \
+       } while (0)
+
+#define __wait_event(wq, condition)            \
+do {                                           \
+       struct cfs_waitlink __wait;             \
+                                               \
+       cfs_waitlink_init(&__wait);             \
+       for (;;) {                              \
+               cfs_waitq_add(&wq, &__wait);    \
+               if (condition)                  \
+                       break;                  \
+               cfs_waitq_wait(&__wait);        \
+               cfs_waitq_del(&wq, &__wait);    \
+       }                                       \
+       cfs_waitq_del(&wq, &__wait);            \
+} while (0)
+
+#define wait_event(wq, condition)                                      \
+do {                                                                   \
+       if (condition)                                                  \
+               break;                                                  \
+       __wait_event(wq, condition);                                    \
+} while (0)
+
+#define wait_event_interruptible(wq, condition)        \
+({                                             \
+       wait_event(wq, condition);              \
+       0;                                      \
+})
+
+extern void    wakeup_one __P((void * chan));
+/* only used in tests */
+#define wake_up_process(p)                     \
+       do {                                    \
+               wakeup_one(p);                  \
+       } while (0)
+       
+/* used in couple of places */
+static inline void sleep_on(cfs_waitq_t *waitq)
+{
+       cfs_waitlink_t link;
+       
+       cfs_waitlink_init(&link);
+       cfs_waitq_add(waitq, &link);
+       cfs_waitq_wait(&link);
+       cfs_waitq_del(waitq, &link);
+}
+
+/*
+ * XXX
+ * Signal
+ */
+#define cfs_sigmask_lock(t, f)         do { f = 0; } while(0)
+#define cfs_sigmask_unlock(t, f)       do { f = 0; } while(0)
+#define cfs_signal_pending(t)          (0)
+
+#define cfs_siginitset(pmask, sigs)                            \
+       do {                                                    \
+               sigset_t __sigs = sigs & (~sigcantmask);        \
+               *(pmask) = __sigs;                              \
+       } while(0)
+
+#define cfs_siginitsetinv(pmask, sigs)                          \
+       do {                                                    \
+               sigset_t __sigs = ~(sigs | sigcantmask);        \
+               *(pmask) = __sigs;                              \
+       } while(0)
+
+#define cfs_recalc_sigpending(ut)                              \
+        do {                                                   \
+               (ut)->uu_siglist = (ut)->uu_siglist & ~(ut)->uu_sigmask;\
+       } while (0)
+#define cfs_sigfillset(s)                                      \
+       do {                                                    \
+               memset((s), -1, sizeof(sigset_t));              \
+       } while(0)
+
+#define cfs_set_sig_blocked(ut, b)             do {(ut)->uu_sigmask = b;} while(0)
+#define cfs_get_sig_blocked(ut)                        (&(ut)->uu_sigmask)
+
+#define SIGNAL_MASK_ASSERT()
+
+/*
+ * Timer
+ */
+
+typedef struct cfs_timer {
+       struct ktimer t;
+} cfs_timer_t;
+
+#define cfs_init_timer(t)      do {} while(0)
+void cfs_timer_init(struct cfs_timer *t, void (*func)(unsigned long), void *arg);
+void cfs_timer_done(struct cfs_timer *t);
+void cfs_timer_arm(struct cfs_timer *t, cfs_time_t deadline);
+void cfs_timer_disarm(struct cfs_timer *t);
+int  cfs_timer_is_armed(struct cfs_timer *t);
+
+cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
+
+/*
+ * Ioctl
+ * We don't need to copy out everything in osx
+ */
+#define cfs_ioctl_data_out(a, d, l)                    \
+       ({                                              \
+               int __size;                             \
+               int __rc = 0;                           \
+               assert((l) >= sizeof(*d));              \
+               __size = (l) - sizeof(*d);              \
+               if (__size > 0)                         \
+                       __rc = copy_to_user((void *)a + __size, \
+                            (void *)d + __size,        \
+                            __size);                   \
+               __rc;                                   \
+       })
+
+/*
+ * CPU
+ */
+#include <machine/cpu_number.h>
+/* Run in PowerG5 who is PPC64 */
+#define SMP_CACHE_BYTES                         128
+#define __cacheline_aligned                     __attribute__((__aligned__(SMP_CACHE_BYTES)))
+/* XXX How to get the value of NCPUS from xnu ? */
+#define NR_CPUS                                        2
+#define smp_processor_id()                     cpu_number()
+#define smp_num_cpus                           NR_CPUS
+/* XXX smp_call_function is not supported in xnu */
+#define smp_call_function(f, a, n, w)          do {} while(0)
+
+/*
+ * Misc
+ */
+#ifndef likely
+#define likely(exp) (exp)
+#endif
+#ifndef unlikely
+#define unlikely(exp) (exp)
+#endif
+
+#define lock_kernel()                          do {} while(0)
+#define unlock_kernel()                                do {} while(0)
+
+#define exit_mm(t)                             do {} while(0)
+#define exit_files(t)                          do {} while(0)
+
+#define CAP_SYS_ADMIN                           0
+#define capable(a)             suser(current_proc()->p_ucred, &(current_proc()->p_acflag))
+
+#define USERMODEHELPER(path, argv, envp)       (0)
+
+#define cfs_module(name, version, init, fini)                          \
+extern kern_return_t _start(kmod_info_t *ki, void *data);              \
+extern kern_return_t _stop(kmod_info_t *ki, void *data);               \
+__private_extern__ kern_return_t name##_start(kmod_info_t *ki, void *data); \
+__private_extern__ kern_return_t name##_stop(kmod_info_t *ki, void *data); \
+                                                                       \
+kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1,               \
+                               { "com.clusterfs.lustre." #name }, { version }, \
+                               -1, 0, 0, 0, 0, name##_start, name##_stop }; \
+                                                                       \
+__private_extern__ kmod_start_func_t *_realmain = name##_start;                \
+__private_extern__ kmod_stop_func_t *_antimain = name##_stop;          \
+__private_extern__ int _kext_apple_cc = __APPLE_CC__ ;                 \
+                                                                       \
+kern_return_t name##_start(kmod_info_t *ki, void *d)                   \
+{                                                                      \
+       return init();                                                  \
+}                                                                      \
+                                                                       \
+kern_return_t name##_stop(kmod_info_t *ki, void *d)                    \
+{                                                                      \
+        fini();                                                                \
+        return KERN_SUCCESS;                                           \
+}                                                                      \
+                                                                       \
+/*                                                                     \
+ * to allow semicolon after cfs_module(...)                            \
+ */                                                                    \
+struct __dummy_ ## name ## _struct {}
+
+#define inter_module_get(n)                    cfs_symbol_get(n)
+#define inter_module_put(n)                    cfs_symbol_put(n)
+
+#ifndef __exit
+#define __exit
+#endif
+#ifndef __init
+#define __init
+#endif
+
+#define EXPORT_SYMBOL(s)
+#define MODULE_AUTHOR(s)
+#define MODULE_DESCRIPTION(s)
+#define MODULE_LICENSE(s)
+#define MODULE_PARM(a, b)
+#define MODULE_PARM_DESC(a, b)
+
+#define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
+#define LINUX_VERSION_CODE (2*200+5*10+0)
+
+#define NR_IRQS                                512
+#define in_interrupt()                 (0)
+
+#define KERN_EMERG      "<0>"   /* system is unusable                   */
+#define KERN_ALERT      "<1>"   /* action must be taken immediately     */
+#define KERN_CRIT       "<2>"   /* critical conditions                  */
+#define KERN_ERR        "<3>"   /* error conditions                     */
+#define KERN_WARNING    "<4>"   /* warning conditions                   */
+#define KERN_NOTICE     "<5>"   /* normal but significant condition     */
+#define KERN_INFO       "<6>"   /* informational                        */
+#define KERN_DEBUG      "<7>"   /* debug-level messages                 */
+
+static inline long PTR_ERR(const void *ptr)
+{
+       return (long) ptr;
+}
+
+#define ERR_PTR(err)   ((void *)err)
+
+/* XXX */
+#define IS_ERR(p)      (0)
+
+/*
+ * Error nubmer
+ */
+#define EBADR          EBADRPC
+#define ERESTARTSYS    ERESTART
+#define EDEADLOCK      EDEADLK
+#define ECOMM          EINVAL
+#define ENODATA                EINVAL
+
+#else
+#define __WORDSIZE     32
+#endif /* __KERNEL__ */
+
+#endif /* __LINUX__ */
diff --git a/lnet/include/libcfs/darwin/darwin-sync.h b/lnet/include/libcfs/darwin/darwin-sync.h
new file mode 100644 (file)
index 0000000..3374f43
--- /dev/null
@@ -0,0 +1,276 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Lustre Light Super operations
+ *
+ *  Copyright (c) 2004 Cluster File Systems, Inc.
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or modify it under
+ *   the terms of version 2 of the GNU General Public License as published by
+ *   the Free Software Foundation. Lustre 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 for more details. You should have received a
+ *   copy of the GNU General Public License along with Lustre; if not, write
+ *   to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
+ *   USA.
+ */
+
+/*
+ * xnu_sync.h
+ *
+ * Created by nikita on Sun Jul 18 2004.
+ *
+ * Prototypes of XNU synchronization primitives.
+ */
+
+#ifndef __LIBCFS_DARWIN_XNU_SYNC_H__
+#define __LIBCFS_DARWIN_XNU_SYNC_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#define XNU_SYNC_DEBUG (0)
+
+#if XNU_SYNC_DEBUG
+#define ON_SYNC_DEBUG(e) e
+#else
+#define ON_SYNC_DEBUG(e)
+#endif
+
+enum {
+        /* "egrep -i '^(o?x)?[abcdeflo]*$' /usr/dict/words" is your friend */
+       KMUT_MAGIC  = 0x0bac0cab, /* [a, [b, c]] = b (a, c) - c (a, b) */
+       KSEM_MAGIC  = 0x1abe11ed,
+       KCOND_MAGIC = 0xb01dface,
+       KRW_MAGIC   = 0xdabb1edd,
+       KSPIN_MAGIC = 0xca11ab1e,
+       KSLEEP_CHAN_MAGIC = 0x0debac1e,
+       KSLEEP_LINK_MAGIC = 0xacc01ade,
+       KTIMER_MAGIC      = 0xbefadd1e
+};
+
+/* ------------------------- spin lock ------------------------- */
+
+/*
+ * XXX nikita: don't use NCPUS it's hardcoded to (1) in cpus.h
+ */
+#define SMP (1)
+
+#include <kern/simple_lock.h>
+
+#include <libcfs/list.h>
+
+struct kspin {
+#if SMP
+       hw_lock_data_t lock;
+#endif
+#if XNU_SYNC_DEBUG
+       unsigned magic;
+       thread_t owner;
+#endif
+};
+
+/*
+ * XXX nikita: we cannot use simple_* functions, because bsd/sys/lock.h
+ * redefines them to nothing. Use low-level hw_lock_* instead.
+ */
+
+void kspin_init(struct kspin *spin);
+void kspin_done(struct kspin *spin);
+void kspin_lock(struct kspin *spin);
+void kspin_unlock(struct kspin *spin);
+int  kspin_trylock(struct kspin *spin);
+
+#if XNU_SYNC_DEBUG
+/*
+ * two functions below are for use in assertions
+ */
+/* true, iff spin-lock is locked by the current thread */
+int kspin_islocked(struct kspin *spin);
+/* true, iff spin-lock is not locked by the current thread */
+int kspin_isnotlocked(struct kspin *spin);
+#else
+#define kspin_islocked(s) (1)
+#define kspin_isnotlocked(s) (1)
+#endif
+
+/* ------------------------- semaphore ------------------------- */
+
+struct ksem {
+        struct kspin      guard;
+        struct wait_queue q;
+        int               value;
+#if XNU_SYNC_DEBUG
+        unsigned          magic;
+#endif
+};
+
+void ksem_init(struct ksem *sem, int value);
+void ksem_done(struct ksem *sem);
+int  ksem_up  (struct ksem *sem, int value);
+void ksem_down(struct ksem *sem, int value);
+int  ksem_trydown(struct ksem *sem, int value);
+
+/* ------------------------- mutex ------------------------- */
+
+struct kmut {
+       struct ksem s;
+#if XNU_SYNC_DEBUG
+        unsigned    magic;
+        thread_t    owner;
+#endif
+};
+
+void kmut_init(struct kmut *mut);
+void kmut_done(struct kmut *mut);
+
+void kmut_lock   (struct kmut *mut);
+void kmut_unlock (struct kmut *mut);
+int  kmut_trylock(struct kmut *mut);
+
+#if XNU_SYNC_DEBUG
+/*
+ * two functions below are for use in assertions
+ */
+/* true, iff mutex is locked by the current thread */
+int kmut_islocked(struct kmut *mut);
+/* true, iff mutex is not locked by the current thread */
+int kmut_isnotlocked(struct kmut *mut);
+#else
+#define kmut_islocked(m) (1)
+#define kmut_isnotlocked(m) (1)
+#endif
+
+/* ------------------------- condition variable ------------------------- */
+
+struct kcond_link {
+       struct kcond_link *next;
+        struct ksem        sem;
+};
+
+struct kcond {
+        struct kspin       guard;
+        struct kcond_link *waiters;
+#if XNU_SYNC_DEBUG
+        unsigned           magic;
+#endif
+};
+
+void kcond_init(struct kcond *cond);
+void kcond_done(struct kcond *cond);
+void kcond_wait(struct kcond *cond, struct kspin *lock);
+void kcond_signal(struct kcond *cond);
+void kcond_broadcast(struct kcond *cond);
+
+void kcond_wait_guard(struct kcond *cond);
+void kcond_signal_guard(struct kcond *cond);
+void kcond_broadcast_guard(struct kcond *cond);
+
+/* ------------------------- read-write semaphore ------------------------- */
+
+struct krw_sem {
+       int          count;
+       struct kcond cond;
+#if XNU_SYNC_DEBUG
+       unsigned     magic;
+#endif
+};
+
+void krw_sem_init(struct krw_sem *sem);
+void krw_sem_done(struct krw_sem *sem);
+void krw_sem_down_r(struct krw_sem *sem);
+int krw_sem_down_r_try(struct krw_sem *sem);
+void krw_sem_down_w(struct krw_sem *sem);
+int krw_sem_down_w_try(struct krw_sem *sem);
+void krw_sem_up_r(struct krw_sem *sem);
+void krw_sem_up_w(struct krw_sem *sem);
+
+/* ------------------------- sleep-channel ------------------------- */
+
+struct ksleep_chan {
+       struct kspin     guard;
+       struct list_head waiters;
+#if XNU_SYNC_DEBUG
+       unsigned     magic;
+#endif
+};
+
+#define KSLEEP_CHAN_INITIALIZER         {{{0}}}
+
+struct ksleep_link {
+       int                 flags;
+       event_t             event;
+       int                 hits;
+       struct ksleep_chan *forward;
+       struct list_head    linkage;
+#if XNU_SYNC_DEBUG
+       unsigned     magic;
+#endif
+};
+
+enum {
+       KSLEEP_EXCLUSIVE = 1
+};
+
+void ksleep_chan_init(struct ksleep_chan *chan);
+void ksleep_chan_done(struct ksleep_chan *chan);
+
+void ksleep_link_init(struct ksleep_link *link);
+void ksleep_link_done(struct ksleep_link *link);
+
+void ksleep_add(struct ksleep_chan *chan, struct ksleep_link *link);
+void ksleep_del(struct ksleep_chan *chan, struct ksleep_link *link);
+
+void ksleep_wait(struct ksleep_chan *chan);
+int64_t  ksleep_timedwait(struct ksleep_chan *chan, uint64_t timeout);
+
+void ksleep_wake(struct ksleep_chan *chan);
+void ksleep_wake_all(struct ksleep_chan *chan);
+void ksleep_wake_nr(struct ksleep_chan *chan, int nr);
+
+#define KSLEEP_LINK_DECLARE(name)                      \
+{                                                      \
+       .flags   = 0,                                   \
+       .event   = 0,                                   \
+       .hits    = 0,                                   \
+       .linkage = PTL_LIST_HEAD_INIT(name.linkage),    \
+       .magic   = KSLEEP_LINK_MAGIC                    \
+}
+
+/* ------------------------- timer ------------------------- */
+
+struct ktimer {
+       struct kspin   guard;
+       void         (*func)(void *);
+       void          *arg;
+       u_int64_t      deadline; /* timer deadline in absolute nanoseconds */
+       int            armed;
+#if XNU_SYNC_DEBUG
+       unsigned     magic;
+#endif
+};
+
+void ktimer_init(struct ktimer *t, void (*func)(void *), void *arg);
+void ktimer_done(struct ktimer *t);
+void ktimer_arm(struct ktimer *t, u_int64_t deadline);
+void ktimer_disarm(struct ktimer *t);
+int  ktimer_is_armed(struct ktimer *t);
+
+u_int64_t ktimer_deadline(struct ktimer *t);
+
+/* __XNU_SYNC_H__ */
+#endif
+
+/*
+ * Local variables:
+ * c-indentation-style: "K&R"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 80
+ * scroll-step: 1
+ * End:
+ */
diff --git a/lnet/include/libcfs/darwin/darwin-time.h b/lnet/include/libcfs/darwin/darwin-time.h
new file mode 100644 (file)
index 0000000..d6230ad
--- /dev/null
@@ -0,0 +1,257 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Copyright (C) 2004 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of Lustre, http://www.lustre.org.
+ *
+ * Lustre is free software; you can redistribute it and/or modify it under the
+ * terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * Lustre 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 for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
+ * Ave, Cambridge, MA 02139, USA.
+ *
+ * Implementation of portable time API for XNU kernel
+ *
+ */
+
+#ifndef __LIBCFS_DARWIN_DARWIN_TIME_H__
+#define __LIBCFS_DARWIN_DARWIN_TIME_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+/* Portable time API */
+
+/*
+ * Platform provides three opaque data-types:
+ *
+ *  cfs_time_t        represents point in time. This is internal kernel
+ *                    time rather than "wall clock". This time bears no
+ *                    relation to gettimeofday().
+ *
+ *  cfs_duration_t    represents time interval with resolution of internal
+ *                    platform clock
+ *
+ *  cfs_fs_time_t     represents instance in world-visible time. This is
+ *                    used in file-system time-stamps
+ *
+ *  cfs_time_t     cfs_time_current(void);
+ *  cfs_time_t     cfs_time_add    (cfs_time_t, cfs_duration_t);
+ *  cfs_duration_t cfs_time_sub    (cfs_time_t, cfs_time_t);
+ *  int            cfs_time_before (cfs_time_t, cfs_time_t);
+ *  int            cfs_time_beforeq(cfs_time_t, cfs_time_t);
+ *
+ *  cfs_duration_t cfs_duration_build(int64_t);
+ *
+ *  time_t         cfs_duration_sec (cfs_duration_t);
+ *  void           cfs_duration_usec(cfs_duration_t, struct timeval *);
+ *  void           cfs_duration_nsec(cfs_duration_t, struct timespec *);
+ *
+ *  void           cfs_fs_time_current(cfs_fs_time_t *);
+ *  time_t         cfs_fs_time_sec    (cfs_fs_time_t *);
+ *  void           cfs_fs_time_usec   (cfs_fs_time_t *, struct timeval *);
+ *  void           cfs_fs_time_nsec   (cfs_fs_time_t *, struct timespec *);
+ *  int            cfs_fs_time_before (cfs_fs_time_t *, cfs_fs_time_t *);
+ *  int            cfs_fs_time_beforeq(cfs_fs_time_t *, cfs_fs_time_t *);
+ *
+ *  cfs_duration_t cfs_time_minimal_timeout(void)
+ *
+ *  CFS_TIME_FORMAT
+ *  CFS_DURATION_FORMAT
+ *
+ */
+
+#define ONE_BILLION ((u_int64_t)1000000000)
+#define ONE_MILLION ((u_int64_t)   1000000)
+
+#ifdef __KERNEL__
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#ifndef __APPLE_API_PRIVATE
+#define __APPLE_API_PRIVATE
+#include <sys/user.h>
+#undef __APPLE_API_PRIVATE
+#else
+#include <sys/user.h>
+#endif
+
+#include <sys/kernel.h>
+
+#include <mach/thread_act.h>
+#include <mach/mach_types.h>
+#include <mach/mach_traps.h>
+#include <mach/thread_switch.h>
+#include <mach/time_value.h>
+#include <kern/sched_prim.h>
+#include <vm/pmap.h>
+#include <vm/vm_kern.h>
+#include <mach/machine/vm_param.h>
+#include <kern/clock.h>
+#include <kern/thread_call.h>
+#include <sys/param.h>
+#include <sys/vm.h>
+
+#include <libcfs/darwin/darwin-types.h>
+#include <libcfs/darwin/darwin-utils.h>
+#include <libcfs/darwin/darwin-lock.h>
+
+typedef u_int64_t cfs_time_t; /* nanoseconds */
+typedef int64_t cfs_duration_t;
+
+#define CFS_TIME_T             "%llu"
+#define CFS_DURATION_T         "%lld"
+
+typedef struct timeval cfs_fs_time_t;
+
+static inline cfs_time_t cfs_time_current(void)
+{
+        struct timespec instant;
+
+        nanotime(&instant);
+        return ((u_int64_t)instant.tv_sec) * ONE_BILLION + instant.tv_nsec;
+}
+
+static inline time_t cfs_time_current_sec(void)
+{
+        struct timespec instant;
+
+        nanotime(&instant);
+       return instant.tv_sec;
+}
+
+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;
+}
+
+static inline void cfs_fs_time_current(cfs_fs_time_t *t)
+{
+        *t = time;
+}
+
+static inline time_t cfs_fs_time_sec(cfs_fs_time_t *t)
+{
+        return t->tv_sec;
+}
+
+static inline cfs_duration_t cfs_duration_build(int64_t nano)
+{
+        return nano;
+}
+
+
+static inline void cfs_fs_time_usec(cfs_fs_time_t *t, struct timeval *v)
+{
+        *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;
+}
+
+static inline cfs_duration_t cfs_time_seconds(int seconds)
+{
+       return cfs_duration_build(ONE_BILLION * (int64_t)seconds);
+}
+
+static inline cfs_time_t cfs_time_shift(int seconds)
+{
+       return cfs_time_add(cfs_time_current(), cfs_time_seconds(seconds));
+}
+
+/*
+ * internal helper function used by cfs_fs_time_before*()
+ */
+static inline int64_t __cfs_fs_time_flat(cfs_fs_time_t *t)
+{
+        return ((int64_t)t->tv_sec) * ONE_BILLION + t->tv_usec;
+}
+
+static inline int cfs_fs_time_before(cfs_fs_time_t *t1, cfs_fs_time_t *t2)
+{
+        return __cfs_fs_time_flat(t1) - __cfs_fs_time_flat(t2) < 0;
+}
+
+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) <= 0;
+}
+
+static inline time_t cfs_duration_sec(cfs_duration_t d)
+{
+        return d / ONE_BILLION;
+}
+
+static inline void cfs_duration_usec(cfs_duration_t d, struct timeval *s)
+{
+        s->tv_sec = d / ONE_BILLION;
+        s->tv_usec = (d - s->tv_sec * ONE_BILLION) / 1000;
+}
+
+static inline void cfs_duration_nsec(cfs_duration_t d, struct timespec *s)
+{
+        s->tv_sec = d / ONE_BILLION;
+        s->tv_nsec = d - ((int64_t)s->tv_sec) * ONE_BILLION;
+}
+
+static inline cfs_duration_t cfs_time_minimal_timeout(void)
+{
+        return ONE_BILLION / (u_int64_t)hz;
+}
+
+/* inline function cfs_time_minimal_timeout() can not be used to
+ * initiallize static variable */
+#define CFS_MIN_DELAY          (ONE_BILLION / (u_int64_t)100)
+
+#define LTIME_S(t)             (t)
+
+/* __KERNEL__ */
+#else
+
+/*
+ * User level
+ */
+#include <libcfs/user-time.h>
+
+/* __KERNEL__ */
+#endif
+
+/* __LIBCFS_DARWIN_DARWIN_TIME_H__ */
+#endif
+/*
+ * Local variables:
+ * c-indentation-style: "K&R"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 80
+ * scroll-step: 1
+ * End:
+ */
diff --git a/lnet/include/libcfs/darwin/darwin-types.h b/lnet/include/libcfs/darwin/darwin-types.h
new file mode 100644 (file)
index 0000000..b2762c0
--- /dev/null
@@ -0,0 +1,82 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic library routines. 
+ *
+ */
+
+#ifndef __LIBCFS_DARWIN_XNU_TYPES_H__
+#define __LIBCFS_DARWIN_XNU_TYPES_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#include <mach/mach_types.h>
+#include <sys/types.h>
+
+typedef u_int8_t  __u8;
+typedef u_int16_t __u16;
+typedef u_int32_t __u32;
+typedef u_int64_t __u64;
+
+#ifdef __KERNEL__
+
+#include <kern/kern_types.h>
+
+#ifndef __s32
+typedef __signed__ int                 __s32;
+#endif
+#ifndef __s64
+typedef __signed__ long long           __s64;
+#endif
+
+typedef struct { int e; }              event_chan_t;
+typedef dev_t                          kdev_t;
+
+/*
+ * Atmoic define
+ */
+#include <libkern/OSAtomic.h>
+
+typedef struct { volatile uint32_t counter; }  atomic_t;
+
+#define ATOMIC_INIT(i)                 { (i) }
+#define atomic_read(a)                 ((a)->counter)
+#define atomic_set(a, v)               (((a)->counter) = (v))
+#define atomic_add(v, a)               hw_atomic_add((uint32_t *)&((a)->counter), v)
+#define atomic_sub(v, a)               hw_atomic_sub((uint32_t *)&((a)->counter), v)
+#define atomic_inc(a)                  atomic_add(1, a)
+#define atomic_dec(a)                  atomic_sub(1, a)
+#define atomic_sub_and_test(v, a)      ( atomic_sub(v, a) == 0 )
+#define atomic_dec_and_test(a)         ( atomic_dec(a) == 0 )
+
+#include <libsa/mach/mach.h>
+typedef uint64_t                       loff_t;
+
+#else  /* !__KERNEL__ */
+
+#include <stdint.h>
+
+typedef uint64_t                       loff_t;
+
+#endif /* __KERNEL END */
+
+#endif  /* __XNU_CFS_TYPES_H__ */
diff --git a/lnet/include/libcfs/darwin/darwin-utils.h b/lnet/include/libcfs/darwin/darwin-utils.h
new file mode 100644 (file)
index 0000000..4e91db9
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef __LIBCFS_DARWIN_XNU_UTILS_H__
+#define __LIBCFS_DARWIN_XNU_UTILS_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#include <sys/random.h> 
+
+#ifdef __KERNEL__
+inline int isspace(char c);
+char *strpbrk(const char *cs, const char *ct);
+char * strsep(char **s, const char *ct);
+size_t strnlen(const char * s, size_t count);
+char * strstr(const char *in, const char *str);
+char * strrchr(const char *p, int ch);
+char * ul2dstr(unsigned long address, char *buf, int len);
+
+#define simple_strtol(a1, a2, a3)               strtol(a1, a2, a3)
+#define simple_strtoul(a1, a2, a3)              strtoul(a1, a2, a3)
+#define simple_strtoll(a1, a2, a3)              strtoq(a1, a2, a3)
+#define simple_strtoull(a1, a2, a3)             strtouq(a1, a2, a3)
+
+#define test_bit(i, a)                          isset(a, i)
+#define set_bit(i, a)                           setbit(a, i)
+#define clear_bit(i, a)                         clrbit(a, i)
+
+#define get_random_bytes(buf, len)              read_random(buf, len)
+
+#endif  /* __KERNEL__ */
+
+#ifndef min_t
+#define min_t(type,x,y) \
+       ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+#endif
+#ifndef max_t
+#define max_t(type,x,y) \
+       ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
+#endif
+
+#define do_div(n,base)                          \
+       ({                                      \
+        __u64 __n = (n);                       \
+        __u32 __base = (base);                 \
+        __u32 __mod;                           \
+                                               \
+        __mod = __n % __base;                  \
+        n = __n / __base;                      \
+        __mod;                                 \
+        })
+
+#define NIPQUAD(addr)                  \
+       ((unsigned char *)&addr)[0],    \
+       ((unsigned char *)&addr)[1],    \
+       ((unsigned char *)&addr)[2],    \
+       ((unsigned char *)&addr)[3]
+
+#define HIPQUAD NIPQUAD
+
+#endif /* __XNU_UTILS_H__ */
diff --git a/lnet/include/libcfs/darwin/kp30.h b/lnet/include/libcfs/darwin/kp30.h
new file mode 100644 (file)
index 0000000..885a78a
--- /dev/null
@@ -0,0 +1,90 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __LIBCFS_DARWIN_KP30__
+#define __LIBCFS_DARWIN_KP30__
+
+#ifndef __LIBCFS_KP30_H__
+#error Do not #include this file directly. #include <libcfs/kp30.h> instead
+#endif
+
+#ifdef __KERNEL__
+
+#include <sys/types.h>
+#include <sys/malloc.h>
+#include <sys/systm.h>
+#include <mach/mach_types.h>
+#include <string.h>
+#include <sys/file.h>
+#include <sys/conf.h>
+#include <miscfs/devfs/devfs.h>
+#include <stdarg.h>
+                                                                                                                                                                            
+#include <libcfs/darwin/darwin-lock.h>
+#include <libcfs/darwin/darwin-prim.h>
+#include <portals/p30.h>
+                                                                                                                                                                            
+#define our_cond_resched()              schedule_timeout(1);
+                                                                                                                                                                            
+#ifdef CONFIG_SMP
+#define LASSERT_SPIN_LOCKED(lock) do {} while(0) /* XXX */
+#else
+#define LASSERT_SPIN_LOCKED(lock) do {} while(0)
+#endif
+                                                                                                                                                                            
+#define LBUG_WITH_LOC(file, func, line)         do {} while(0)
+
+/* --------------------------------------------------------------------- */
+
+#define PORTAL_SYMBOL_REGISTER(x)               cfs_symbol_register(#x, &x)
+#define PORTAL_SYMBOL_UNREGISTER(x)             cfs_symbol_unregister(#x)
+                                                                                                                                                                            
+#define PORTAL_SYMBOL_GET(x)                    ((typeof(&x))cfs_symbol_get(#x))
+#define PORTAL_SYMBOL_PUT(x)                    cfs_symbol_put(#x)
+                                                                                                                                                                            
+#define PORTAL_MODULE_USE                       do{int i = 0; i++;}while(0)
+#define PORTAL_MODULE_UNUSE                     do{int i = 0; i--;}while(0)
+
+#define printk(format, args...)                 printf(format, ## args)
+
+#else  /* !__KERNEL__ */
+# include <stdio.h>
+# include <stdlib.h>
+# include <stdint.h>
+# include <unistd.h>
+# include <time.h>
+# include <machine/limits.h>
+# include <sys/types.h>
+#endif
+
+/******************************************************************************/
+/* Light-weight trace
+ * Support for temporary event tracing with minimal Heisenberg effect. */
+#define LWT_SUPPORT  0
+
+typedef struct { 
+        long long   lwte_when; 
+        char       *lwte_where; 
+        void       *lwte_task; 
+        long        lwte_p1; 
+        long        lwte_p2; 
+        long        lwte_p3; 
+        long        lwte_p4; 
+} lwt_event_t;
+
+# define LWT_EVENT(p1,p2,p3,p4)     /* no lwt implementation yet */
+
+/* -------------------------------------------------------------------------- */
+
+#define IOCTL_PORTAL_TYPE struct portal_ioctl_data
+
+#define LPU64 "%llu"
+#define LPD64 "%lld"
+#define LPX64 "%llx"
+#define LPSZ  "%lu"
+#define LPSSZ "%ld"
+# define LI_POISON ((int)0x5a5a5a5a)
+# define LL_POISON ((long)0x5a5a5a5a)
+# define LP_POISON ((void *)(long)0x5a5a5a5a)
+
+#endif
diff --git a/lnet/include/libcfs/darwin/libcfs.h b/lnet/include/libcfs/darwin/libcfs.h
new file mode 100644 (file)
index 0000000..8e4eb89
--- /dev/null
@@ -0,0 +1,173 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __LIBCFS_DARWIN_LIBCFS_H__
+#define __LIBCFS_DARWIN_LIBCFS_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#include <mach/mach_types.h>
+#include <string.h>
+#include <libcfs/darwin/darwin-types.h>
+#include <libcfs/darwin/darwin-time.h>
+#include <libcfs/darwin/darwin-prim.h>
+#include <libcfs/darwin/darwin-mem.h>
+#include <libcfs/darwin/darwin-lock.h>
+#include <libcfs/darwin/darwin-fs.h>
+
+#ifdef __KERNEL__
+# include <sys/types.h>
+# include <sys/time.h>
+# define do_gettimeofday(tv) microuptime(tv)
+#else
+# include <sys/time.h>
+# define do_gettimeofday(tv) gettimeofday(tv, NULL);
+typedef unsigned long long cycles_t;
+#endif
+
+#define __cpu_to_le64(x)                        OSSwapHostToLittleInt64(x)
+#define __cpu_to_le32(x)                        OSSwapHostToLittleInt32(x)
+#define __cpu_to_le16(x)                        OSSwapHostToLittleInt16(x)
+
+#define __le16_to_cpu(x)                        OSSwapLittleToHostInt16(x)
+#define __le32_to_cpu(x)                        OSSwapLittleToHostInt32(x)
+#define __le64_to_cpu(x)                        OSSwapLittleToHostInt64(x)
+
+#define cpu_to_le64(x)                          __cpu_to_le64(x)
+#define cpu_to_le32(x)                          __cpu_to_le32(x)
+#define cpu_to_le16(x)                          __cpu_to_le16(x)
+
+#define le64_to_cpu(x)                          __le64_to_cpu(x)
+#define le32_to_cpu(x)                          __le32_to_cpu(x)
+#define le16_to_cpu(x)                          __le16_to_cpu(x)
+
+#define __swab16(x)                             OSSwapInt16(x)
+#define __swab32(x)                             OSSwapInt32(x)
+#define __swab64(x)                             OSSwapInt64(x)
+#define __swab16s(x)                            do { *(x) = __swab16(*(x)); } while (0)
+#define __swab32s(x)                            do { *(x) = __swab32(*(x)); } while (0)
+#define __swab64s(x)                            do { *(x) = __swab64(*(x)); } while (0)
+
+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__
+# include <sys/systm.h>
+# include <pexpert/pexpert.h>
+/* Fix me */
+# define THREAD_SIZE 8192
+#else
+# define THREAD_SIZE 8192
+#endif
+#define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
+
+#define CHECK_STACK(stack) do { } while(0)
+#define CDEBUG_STACK (0L)
+
+/* Darwin has defined RETURN, so we have to undef it in lustre */
+#ifdef RETURN
+#undef RETURN
+#endif
+
+/*
+ * When this is enabled debugging messages are indented according to the
+ * current "nesting level". Nesting level in increased when ENTRY macro
+ * is executed, and decreased on EXIT and RETURN.
+ */
+#ifdef __KERNEL__
+#define ENTRY_NESTING_SUPPORT (0)
+#endif
+
+#if ENTRY_NESTING_SUPPORT
+
+/*
+ * Currently ENTRY_NESTING_SUPPORT is only supported for XNU port. Basic
+ * idea is to keep per-thread pointer to small data structure (struct
+ * cfs_debug_data) describing current nesting level. In XNU unused
+ * proc->p_wmegs field in hijacked for this. On Linux
+ * current->journal_info can be used. In user space
+ * pthread_{g,s}etspecific().
+ *
+ * ENTRY macro allocates new cfs_debug_data on stack, and installs it as
+ * a current nesting level, storing old data in cfs_debug_data it just
+ * created.
+ *
+ * EXIT pops old value back.
+ *
+ */
+
+/*
+ * One problem with this approach is that there is a lot of code that
+ * does ENTRY and then escapes scope without doing EXIT/RETURN. In this
+ * case per-thread current nesting level pointer is dangling (it points
+ * to the stack area that is possible already overridden). To detect
+ * such cases, we add two magic fields to the cfs_debug_data and check
+ * them whenever current nesting level pointer is dereferenced. While
+ * looking flaky this works because stack is always consumed
+ * "continously".
+ */
+enum {
+       CDD_MAGIC1 = 0x02128506,
+       CDD_MAGIC2 = 0x42424242
+};
+
+struct cfs_debug_data {
+       unsigned int           magic1;
+       struct cfs_debug_data *parent;
+       int                    nesting_level;
+       unsigned int           magic2;
+};
+
+void __entry_nesting(struct cfs_debug_data *child);
+void __exit_nesting(struct cfs_debug_data *child);
+unsigned int __current_nesting_level(void);
+
+#define ENTRY_NESTING                                          \
+struct cfs_debug_data __cdd = { .magic1        = CDD_MAGIC1,   \
+                               .parent        = NULL,          \
+                                .nesting_level = 0,            \
+                                .magic2        = CDD_MAGIC2 }; \
+__entry_nesting(&__cdd);
+
+#define EXIT_NESTING __exit_nesting(&__cdd)
+
+/* ENTRY_NESTING_SUPPORT */
+#else
+
+#define ENTRY_NESTING   do {;} while (0)
+#define EXIT_NESTING   do {;} while (0)
+#define __current_nesting_level() (0)
+
+/* ENTRY_NESTING_SUPPORT */
+#endif
+
+#define LUSTRE_PTL_PID          12345
+
+#define _XNU_LIBCFS_H
+
+/*
+ * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
+ *
+ * Implementation is in darwin-curproc.c
+ */
+#define CFS_CURPROC_COMM_MAX (sizeof ((struct proc *)0)->p_comm)
+/*
+ * XNU has no capabilities
+ */
+typedef int cfs_kernel_cap_t;
+
+#endif /* _XNU_LIBCFS_H */
diff --git a/lnet/include/libcfs/darwin/lltrace.h b/lnet/include/libcfs/darwin/lltrace.h
new file mode 100644 (file)
index 0000000..bb0dc91
--- /dev/null
@@ -0,0 +1,26 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __LIBCFS_DARWIN_LLTRACE_H__
+#define __LIBCFS_DARWIN_LLTRACE_H__
+
+#ifndef __LIBCFS_LLTRACE_H__
+#error Do not #include this file directly. #include <libcfs/lltrace.h> instead
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <portals/types.h>
+#include <libcfs/kp30.h>
+#include <mach/vm_param.h>
+#include <portals/ptlctl.h>
+
+#endif
diff --git a/lnet/include/libcfs/darwin/portals_lib.h b/lnet/include/libcfs/darwin/portals_lib.h
new file mode 100644 (file)
index 0000000..dde962a
--- /dev/null
@@ -0,0 +1,34 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic library routines. 
+ *
+ */
+
+#ifndef __LIBCFS_DARWIN_PORTALS_LIB_H__
+#define __LIBCFS_DARWIN_PORTALS_LIB_H__
+
+#ifndef __LIBCFS_PORTALS_LIB_H__
+#error Do not #include this file directly. #include <libcfs/portals_lib.h> instead
+#endif
+
+#include <string.h>
+
+#endif
diff --git a/lnet/include/libcfs/darwin/portals_utils.h b/lnet/include/libcfs/darwin/portals_utils.h
new file mode 100644 (file)
index 0000000..4907cb1
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __LIBCFS_DARWIN_PORTALS_UTILS_H__
+#define __LIBCFS_DARWIN_PORTALS_UTILS_H__
+
+#ifndef __LIBCFS_PORTALS_UTILS_H__
+#error Do not #include this file directly. #include <libcfs/portals_utils.h> instead
+#endif
+
+#include <libcfs/list.h>
+#ifdef __KERNEL__
+#include <mach/mach_types.h>
+#include <libcfs/libcfs.h>
+#else /* !__KERNEL__ */
+#include <machine/endian.h>
+#include <netinet/in.h>
+#include <sys/syscall.h>
+#endif /* !__KERNEL__ */
+
+#endif
similarity index 54%
rename from lnet/include/linux/kp30.h
rename to lnet/include/libcfs/kp30.h
index e590514..cdd1bff 100644 (file)
@@ -1,58 +1,19 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
-#ifndef _KP30_INCLUDED
-#define _KP30_INCLUDED
+#ifndef __LIBCFS_KP30_H__
+#define __LIBCFS_KP30_H__
 
-#include <linux/libcfs.h>
 #define PORTAL_DEBUG
+#include <libcfs/libcfs.h>
 
-#ifdef __KERNEL__
-# include <linux/vmalloc.h>
-# include <linux/time.h>
-# include <linux/slab.h>
-# include <linux/interrupt.h>
-# include <linux/highmem.h>
-# include <linux/module.h>
-# include <linux/version.h>
-# include <portals/p30.h>
-# include <linux/smp_lock.h>
-# include <asm/atomic.h>
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-#define schedule_work schedule_task
-#define prepare_work(wq,cb,cbdata)                                            \
-do {                                                                          \
-        INIT_TQUEUE((wq), 0, 0);                                              \
-        PREPARE_TQUEUE((wq), (cb), (cbdata));                                 \
-} while (0)
-
-#define PageUptodate Page_Uptodate
-#define our_recalc_sigpending(current) recalc_sigpending(current)
-#define num_online_cpus() smp_num_cpus
-static inline void our_cond_resched(void)
-{
-        if (current->need_resched)
-               schedule ();
-}
-#define work_struct_t       struct tq_struct
+#include <libcfs/arch/kp30.h>
 
-#else
-
-#define prepare_work(wq,cb,cbdata)                                            \
-do {                                                                          \
-        INIT_WORK((wq), (void *)(cb), (void *)(cbdata));                      \
-} while (0)
-#define wait_on_page wait_on_page_locked
-#define our_recalc_sigpending(current) recalc_sigpending()
-#define strtok(a,b) strpbrk(a, b)
-static inline void our_cond_resched(void)
-{
-        cond_resched();
-}
-#define work_struct_t      struct work_struct
+#ifdef __KERNEL__
 
-#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
+# ifndef DEBUG_SUBSYSTEM
+#  define DEBUG_SUBSYSTEM S_UNDEFINED
+# endif
 
 #ifdef PORTAL_DEBUG
 extern void kportal_assertion_failed(char *expr, char *file, const char *func,
@@ -74,32 +35,7 @@ extern void kportal_assertion_failed(char *expr, char *file, const char *func,
 #define LASSERTF(cond, fmt...) do { } while (0)
 #endif
 
-#ifdef CONFIG_SMP
-#define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
-#else
-#define LASSERT_SPIN_LOCKED(lock) do {} while(0)
-#endif
-
-#ifdef __arch_um__
-#define LBUG_WITH_LOC(file, func, line)                                 \
-do {                                                                    \
-        CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n");       \
-        portals_debug_dumplog();                                        \
-        portals_run_lbug_upcall(file, func, line);                      \
-        panic("LBUG");                                                  \
-} while (0)
-#else
-#define LBUG_WITH_LOC(file, func, line)                                 \
-do {                                                                    \
-        CEMERG("LBUG\n");                                               \
-        portals_debug_dumpstack(NULL);                                  \
-        portals_debug_dumplog();                                        \
-        portals_run_lbug_upcall(file, func, line);                      \
-        set_task_state(current, TASK_UNINTERRUPTIBLE);                  \
-        schedule();                                                     \
-} while (0)
-#endif /* __arch_um__ */
-
+/* LBUG_WITH_LOC defined in portals/<os>/kp30.h */
 #define LBUG() LBUG_WITH_LOC(__FILE__, __FUNCTION__, __LINE__)
 
 /*
@@ -127,11 +63,11 @@ do {                                                                          \
 #define PORTAL_ALLOC_GFP(ptr, size, mask)                                 \
 do {                                                                      \
         LASSERT(!in_interrupt() ||                                        \
-               (size <= PORTAL_VMALLOC_SIZE && mask == GFP_ATOMIC));      \
+               (size <= PORTAL_VMALLOC_SIZE && mask == CFS_ALLOC_ATOMIC));\
         if ((size) > PORTAL_VMALLOC_SIZE)                                 \
-                (ptr) = vmalloc(size);                                    \
+                (ptr) = cfs_alloc_large(size);                            \
         else                                                              \
-                (ptr) = kmalloc((size), (mask));                          \
+                (ptr) = cfs_alloc((size), (mask));                        \
         if ((ptr) == NULL) {                                              \
                 CERROR("PORTALS: out of memory at %s:%d (tried to alloc '"\
                        #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));\
@@ -139,17 +75,18 @@ do {                                                                      \
                        atomic_read(&portal_kmemory));                     \
         } else {                                                          \
                 portal_kmem_inc((ptr), (size));                           \
-                memset((ptr), 0, (size));                                 \
+                if (!((mask) & CFS_ALLOC_ZERO))                           \
+                       memset((ptr), 0, (size));                          \
         }                                                                 \
         CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p (tot %d).\n",    \
                (int)(size), (ptr), atomic_read (&portal_kmemory));        \
 } while (0)
 
 #define PORTAL_ALLOC(ptr, size) \
-        PORTAL_ALLOC_GFP(ptr, size, GFP_NOFS)
+        PORTAL_ALLOC_GFP(ptr, size, CFS_ALLOC_IO)
 
 #define PORTAL_ALLOC_ATOMIC(ptr, size) \
-        PORTAL_ALLOC_GFP(ptr, size, GFP_ATOMIC)
+        PORTAL_ALLOC_GFP(ptr, size, CFS_ALLOC_ATOMIC)
 
 #define PORTAL_FREE(ptr, size)                                          \
 do {                                                                    \
@@ -160,39 +97,14 @@ do {                                                                    \
                 break;                                                  \
         }                                                               \
         if (s > PORTAL_VMALLOC_SIZE)                                    \
-                vfree(ptr);                                             \
+                cfs_free_large(ptr);                                    \
         else                                                            \
-                kfree(ptr);                                             \
+                cfs_free(ptr);                                          \
         portal_kmem_dec((ptr), s);                                      \
         CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n",     \
                s, (ptr), atomic_read(&portal_kmemory));                 \
 } while (0)
 
-/* ------------------------------------------------------------------- */
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-
-#define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
-#define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
-
-#define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
-#define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
-
-#define PORTAL_MODULE_USE       MOD_INC_USE_COUNT
-#define PORTAL_MODULE_UNUSE     MOD_DEC_USE_COUNT
-#else
-
-#define PORTAL_SYMBOL_REGISTER(x)
-#define PORTAL_SYMBOL_UNREGISTER(x)
-
-#define PORTAL_SYMBOL_GET(x) symbol_get(x)
-#define PORTAL_SYMBOL_PUT(x) symbol_put(x)
-
-#define PORTAL_MODULE_USE       try_module_get(THIS_MODULE)
-#define PORTAL_MODULE_UNUSE     module_put(THIS_MODULE)
-
-#endif
-
 /******************************************************************************/
 
 #ifdef PORTALS_PROFILING
@@ -243,7 +155,9 @@ extern struct prof_ent prof_ents[MAX_PROFS];
 #endif /* PORTALS_PROFILING */
 
 /* debug.c */
-void portals_debug_dumpstack(struct task_struct *tsk);
+extern spinlock_t stack_backtrace_lock;
+
+void portals_debug_dumpstack(cfs_task_t *tsk);
 void portals_run_upcall(char **argv);
 void portals_run_lbug_upcall(char * file, const char *fn, const int line);
 void portals_debug_dumplog(void);
@@ -254,44 +168,20 @@ int portals_debug_mark_buffer(char *text);
 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
                              char *file, unsigned int size);
 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
-#if (__GNUC__)
 /* Use the special GNU C __attribute__ hack to have the compiler check the
  * printf style argument string against the actual argument count and
  * types.
  */
-#ifdef printf
-# warning printf has been defined as a macro...
-# undef printf
-#endif
 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
                        const int line, unsigned long stack,
                        char *format, ...)
         __attribute__ ((format (printf, 7, 8)));
-#else
-void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
-                       const int line, unsigned long stack,
-                       const char *format, ...);
-#endif /* __GNUC__ */
 void portals_debug_set_level(unsigned int debug_level);
 
-# define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
-# define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
-# define time(a) CURRENT_TIME
-
 extern void kportal_daemonize (char *name);
 extern void kportal_blockallsigs (void);
 
 #else  /* !__KERNEL__ */
-# include <stdio.h>
-# include <stdlib.h>
-#ifndef __CYGWIN__
-# include <stdint.h>
-#else
-# include <cygwin-ioctl.h>
-#endif
-# include <unistd.h>
-# include <time.h>
-# include <limits.h>
 # ifndef DEBUG_SUBSYSTEM
 #  define DEBUG_SUBSYSTEM S_UNDEFINED
 # endif
@@ -324,6 +214,22 @@ void portals_debug_dumplog(void);
 #define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
 #endif
 
+/*
+ * compile-time assertions. @cond has to be constant expression.
+ * ISO C Standard:
+ *
+ *        6.8.4.2  The switch statement
+ *
+ *       ....
+ *
+ *       [#3] The expression of each case label shall be  an  integer
+ *       constant   expression  and  no  two  of  the  case  constant
+ *       expressions in the same switch statement shall have the same
+ *       value  after  conversion...
+ *
+ */
+#define CLASSERT(cond) ({ switch(42) { case (cond): case 0: break; } })
+
 /* support decl needed both by kernel and liblustre */
 char *portals_nid2str(int nal, ptl_nid_t nid, char *str);
 char *portals_id2str(int nal, ptl_process_id_t nid, char *str);
@@ -332,119 +238,19 @@ char *portals_id2str(int nal, ptl_process_id_t nid, char *str);
 # define CURRENT_TIME time(0)
 #endif
 
-/******************************************************************************/
-/* Light-weight trace
- * Support for temporary event tracing with minimal Heisenberg effect. */
-#define LWT_SUPPORT  0
-
-#define LWT_MEMORY   (16<<20)
-
-#if !KLWT_SUPPORT
-# if defined(__KERNEL__)
-#  if !defined(BITS_PER_LONG)
-#   error "BITS_PER_LONG not defined"
-#  endif
-# elif !defined(__WORDSIZE)
-#  error "__WORDSIZE not defined"
-# else
-#  define BITS_PER_LONG __WORDSIZE
-# endif
-
-/* kernel hasn't defined this? */
-typedef struct {
-        long long   lwte_when;
-        char       *lwte_where;
-        void       *lwte_task;
-        long        lwte_p1;
-        long        lwte_p2;
-        long        lwte_p3;
-        long        lwte_p4;
-# if BITS_PER_LONG > 32
-        long        lwte_pad;
-# endif
-} lwt_event_t;
-#endif /* !KLWT_SUPPORT */
-
-#if LWT_SUPPORT
-# ifdef __KERNEL__
-#  if !KLWT_SUPPORT
-
-typedef struct _lwt_page {
-        struct list_head     lwtp_list;
-        struct page         *lwtp_page;
-        lwt_event_t         *lwtp_events;
-} lwt_page_t;
-
-typedef struct {
-        int                lwtc_current_index;
-        lwt_page_t        *lwtc_current_page;
-} lwt_cpu_t;
-
-extern int       lwt_enabled;
-extern lwt_cpu_t lwt_cpus[];
-
-/* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
- * This stuff is meant for finding specific problems; it never stays in
- * production code... */
-
-#define LWTSTR(n)       #n
-#define LWTWHERE(f,l)   f ":" LWTSTR(l)
-#define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
-
-#define LWT_EVENT(p1, p2, p3, p4)                                       \
-do {                                                                    \
-        unsigned long    flags;                                         \
-        lwt_cpu_t       *cpu;                                           \
-        lwt_page_t      *p;                                             \
-        lwt_event_t     *e;                                             \
-                                                                        \
-        if (lwt_enabled) {                                              \
-                local_irq_save (flags);                                 \
-                                                                        \
-                cpu = &lwt_cpus[smp_processor_id()];                    \
-                p = cpu->lwtc_current_page;                             \
-                e = &p->lwtp_events[cpu->lwtc_current_index++];         \
-                                                                        \
-                if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) {   \
-                        cpu->lwtc_current_page =                        \
-                                list_entry (p->lwtp_list.next,          \
-                                            lwt_page_t, lwtp_list);     \
-                        cpu->lwtc_current_index = 0;                    \
-                }                                                       \
-                                                                        \
-                e->lwte_when  = get_cycles();                           \
-                e->lwte_where = LWTWHERE(__FILE__,__LINE__);            \
-                e->lwte_task  = current;                                \
-                e->lwte_p1    = (long)(p1);                             \
-                e->lwte_p2    = (long)(p2);                             \
-                e->lwte_p3    = (long)(p3);                             \
-                e->lwte_p4    = (long)(p4);                             \
-                                                                        \
-                local_irq_restore (flags);                              \
-        }                                                               \
-} while (0)
-
-#endif /* !KLWT_SUPPORT */
-
-extern int  lwt_init (void);
-extern void lwt_fini (void);
-extern int  lwt_lookup_string (int *size, char *knlptr,
-                               char *usrptr, int usrsize);
-extern int  lwt_control (int enable, int clear);
-extern int  lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
-                          void *user_ptr, int user_size);
-# else  /* __KERNEL__ */
-#  define LWT_EVENT(p1,p2,p3,p4)     /* no userland implementation yet */
-# endif /* __KERNEL__ */
-#endif /* LWT_SUPPORT */
+/* --------------------------------------------------------------------
+ * Light-weight trace
+ * Support for temporary event tracing with minimal Heisenberg effect.
+ * All stuff about lwt are put in arch/kp30.h
+ * -------------------------------------------------------------------- */
 
 struct portals_device_userstate
 {
         int          pdu_memhog_pages;
-        struct page *pdu_memhog_root_page;
+        cfs_page_t   *pdu_memhog_root_page;
 };
 
-#include <linux/portals_lib.h>
+#include <libcfs/portals_lib.h>
 
 /*
  * USER LEVEL STUFF BELOW
@@ -569,77 +375,30 @@ static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
 
         return 0;
 }
-#else
-#include <asm/uaccess.h>
-
-/* buffer MUST be at least the size of portal_ioctl_hdr */
-static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
-{
-        struct portal_ioctl_hdr *hdr;
-        struct portal_ioctl_data *data;
-        int err;
-        ENTRY;
-
-        hdr = (struct portal_ioctl_hdr *)buf;
-        data = (struct portal_ioctl_data *)buf;
-
-        err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
-        if (err)
-                RETURN(err);
 
-        if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
-                CERROR("PORTALS: version mismatch kernel vs application\n");
-                RETURN(-EINVAL);
-        }
-
-        if (hdr->ioc_len + buf >= end) {
-                CERROR("PORTALS: user buffer exceeds kernel buffer\n");
-                RETURN(-EINVAL);
-        }
-
-
-        if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
-                CERROR("PORTALS: user buffer too small for ioctl\n");
-                RETURN(-EINVAL);
-        }
-
-        err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
-        if (err)
-                RETURN(err);
-
-        if (portal_ioctl_is_invalid(data)) {
-                CERROR("PORTALS: ioctl not correctly formatted\n");
-                RETURN(-EINVAL);
-        }
-
-        if (data->ioc_inllen1)
-                data->ioc_inlbuf1 = &data->ioc_bulk[0];
+#else
 
-        if (data->ioc_inllen2)
-                data->ioc_inlbuf2 = &data->ioc_bulk[0] +
-                        size_round(data->ioc_inllen1);
+extern inline int portal_ioctl_getdata(char *buf, char *end, void *arg);
 
-        RETURN(0);
-}
 #endif
 
 /* ioctls for manipulating snapshots 30- */
 #define IOC_PORTAL_TYPE                   'e'
 #define IOC_PORTAL_MIN_NR                 30
 
-#define IOC_PORTAL_PING                    _IOWR('e', 30, long)
+#define IOC_PORTAL_PING                    _IOWR('e', 30, IOCTL_PORTAL_TYPE)
 
-#define IOC_PORTAL_CLEAR_DEBUG             _IOWR('e', 32, long)
-#define IOC_PORTAL_MARK_DEBUG              _IOWR('e', 33, long)
-#define IOC_PORTAL_PANIC                   _IOWR('e', 34, long)
-#define IOC_PORTAL_NAL_CMD                 _IOWR('e', 35, long)
-#define IOC_PORTAL_GET_NID                 _IOWR('e', 36, long)
-#define IOC_PORTAL_FAIL_NID                _IOWR('e', 37, long)
+#define IOC_PORTAL_CLEAR_DEBUG             _IOWR('e', 32, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_MARK_DEBUG              _IOWR('e', 33, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_PANIC                   _IOWR('e', 34, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_NAL_CMD                 _IOWR('e', 35, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_GET_NID                 _IOWR('e', 36, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_FAIL_NID                _IOWR('e', 37, IOCTL_PORTAL_TYPE)
 
-#define IOC_PORTAL_LWT_CONTROL             _IOWR('e', 39, long)
-#define IOC_PORTAL_LWT_SNAPSHOT            _IOWR('e', 40, long)
-#define IOC_PORTAL_LWT_LOOKUP_STRING       _IOWR('e', 41, long)
-#define IOC_PORTAL_MEMHOG                  _IOWR('e', 42, long)
+#define IOC_PORTAL_LWT_CONTROL             _IOWR('e', 39, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_LWT_SNAPSHOT            _IOWR('e', 40, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_LWT_LOOKUP_STRING       _IOWR('e', 41, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_MEMHOG                  _IOWR('e', 42, IOCTL_PORTAL_TYPE)
 #define IOC_PORTAL_MAX_NR                             42
 
 enum {
@@ -694,49 +453,6 @@ enum cfg_record_type {
 
 typedef int (*cfg_record_cb_t)(enum cfg_record_type, int len, void *data);
 
-#ifdef __CYGWIN__
-# ifndef BITS_PER_LONG
-#  if (~0UL) == 0xffffffffUL
-#   define BITS_PER_LONG 32
-#  else
-#   define BITS_PER_LONG 64
-#  endif
-# endif
-#endif
-
-#if BITS_PER_LONG > 32
-# define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
-#else
-# define LI_POISON ((int)0x5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a)
-#endif
-
-#if defined(__x86_64__)
-# define LPU64 "%Lu"
-# define LPD64 "%Ld"
-# define LPX64 "%#Lx"
-# define LPSZ  "%lu"
-# define LPSSZ "%ld"
-#elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
-# define LPU64 "%Lu"
-# define LPD64 "%Ld"
-# define LPX64 "%#Lx"
-# define LPSZ  "%u"
-# define LPSSZ "%d"
-#elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
-# define LPU64 "%lu"
-# define LPD64 "%ld"
-# define LPX64 "%#lx"
-# define LPSZ  "%lu"
-# define LPSSZ "%ld"
-#endif
-#ifndef LPU64
-# error "No word size defined"
-#endif
-
 /* lustre_id output helper macros */
 #define DLID4   "%lu/%lu/%lu/%lu"
 
@@ -745,5 +461,5 @@ typedef int (*cfg_record_cb_t)(enum cfg_record_type, int len, void *data);
     (unsigned long)(id)->li_fid.lf_group,      \
     (unsigned long)(id)->li_stc.u.e3s.l3s_ino, \
     (unsigned long)(id)->li_stc.u.e3s.l3s_gen
-                
+
 #endif
similarity index 63%
rename from lnet/include/linux/libcfs.h
rename to lnet/include/libcfs/libcfs.h
index d8f5349..2fabeab 100644 (file)
@@ -1,23 +1,15 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
-#ifndef _LIBCFS_H
-#define _LIBCFS_H
+#ifndef __LIBCFS_LIBCFS_H__
+#define __LIBCFS_LIBCFS_H__
 
-#ifdef HAVE_ASM_TYPES_H
-#include <asm/types.h>
-#else
-#include "types.h"
+#if !__GNUC__
+#define __attribute__(x)
 #endif
 
-#ifdef __KERNEL__
-# include <linux/time.h>
-# include <asm/timex.h>
-#else
-# include <sys/time.h>
-# define do_gettimeofday(tv) gettimeofday(tv, NULL);
-typedef unsigned long long cycles_t;
-#endif
+#include <libcfs/arch/libcfs.h>
+#include "curproc.h"
 
 #define PORTAL_DEBUG
 
@@ -27,37 +19,6 @@ typedef unsigned long long cycles_t;
 
 #define LOWEST_BIT_SET(x)       ((x) & ~((x) - 1))
 
-#ifndef __KERNEL__
-/* Userpace byte flipping */
-# include <endian.h>
-# include <byteswap.h>
-# define __swab16(x) bswap_16(x)
-# define __swab32(x) bswap_32(x)
-# define __swab64(x) bswap_64(x)
-# define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
-# define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
-# define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
-# if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define le16_to_cpu(x) (x)
-#  define cpu_to_le16(x) (x)
-#  define le32_to_cpu(x) (x)
-#  define cpu_to_le32(x) (x)
-#  define le64_to_cpu(x) (x)
-#  define cpu_to_le64(x) (x)
-# else
-#  if __BYTE_ORDER == __BIG_ENDIAN
-#   define le16_to_cpu(x) bswap_16(x)
-#   define cpu_to_le16(x) bswap_16(x)
-#   define le32_to_cpu(x) bswap_32(x)
-#   define cpu_to_le32(x) bswap_32(x)
-#   define le64_to_cpu(x) bswap_64(x)
-#   define cpu_to_le64(x) bswap_64(x)
-#  else
-#   error "Unknown byte order"
-#  endif /* __BIG_ENDIAN */
-# endif /* __LITTLE_ENDIAN */
-#endif /* ! __KERNEL__ */
-
 /*
  *  Debugging
  */
@@ -66,19 +27,9 @@ extern unsigned int portal_stack;
 extern unsigned int portal_debug;
 extern unsigned int portal_printk;
 
-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));
+/*
+ * struct ptldebug_header is defined in libcfs/<os>/libcfs.h
+ */
 
 #define PH_FLAG_FIRST_RECORD 1
 
@@ -144,42 +95,10 @@ struct ptldebug_header {
  *    utils/lconf
  */
 
-#ifdef __KERNEL__
-# include <linux/sched.h> /* THREAD_SIZE */
-#else
-# ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
-#  define THREAD_SIZE 8192
-# endif
+#ifndef DEBUG_SUBSYSTEM
+# define DEBUG_SUBSYSTEM S_UNDEFINED
 #endif
 
-#define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
-
-#ifdef __KERNEL__
-# ifdef  __ia64__
-#  define CDEBUG_STACK (THREAD_SIZE -                                      \
-                        ((unsigned long)__builtin_dwarf_cfa() &            \
-                         (THREAD_SIZE - 1)))
-# else
-#  define CDEBUG_STACK (THREAD_SIZE -                                      \
-                        ((unsigned long)__builtin_frame_address(0) &       \
-                         (THREAD_SIZE - 1)))
-# endif /* __ia64__ */
-
-#define CHECK_STACK(stack)                                                    \
-        do {                                                                  \
-                if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) {    \
-                        portals_debug_msg(DEBUG_SUBSYSTEM, D_WARNING,         \
-                                          __FILE__, __FUNCTION__, __LINE__,   \
-                                          (stack),"maximum lustre stack %u\n",\
-                                          portal_stack = (stack));            \
-                      /*panic("LBUG");*/                                      \
-                }                                                             \
-        } while (0)
-#else /* !__KERNEL__ */
-#define CHECK_STACK(stack) do { } while(0)
-#define CDEBUG_STACK (0L)
-#endif /* __KERNEL__ */
-
 #if 1
 #define CDEBUG(mask, format, a...)                                            \
 do {                                                                          \
@@ -195,11 +114,12 @@ do {                                                                          \
 #define CDEBUG_MAX_LIMIT 600
 #define CDEBUG_LIMIT(cdebug_mask, cdebug_format, a...)                        \
 do {                                                                          \
-        static unsigned long cdebug_next = 0;                                 \
-        static int cdebug_count = 0, cdebug_delay = 1;                        \
+        static cfs_time_t cdebug_next = 0;                                    \
+        static int cdebug_count = 0;                                          \
+        static cfs_duration_t cdebug_delay = CFS_MIN_DELAY;                   \
                                                                               \
         CHECK_STACK(CDEBUG_STACK);                                            \
-        if (time_after(jiffies, cdebug_next)) {                               \
+        if (cfs_time_after(cfs_time_current(), cdebug_next)) {                \
                 portals_debug_msg(DEBUG_SUBSYSTEM, cdebug_mask, __FILE__,     \
                                   __FUNCTION__, __LINE__, CDEBUG_STACK,       \
                                   cdebug_format, ## a);                       \
@@ -210,12 +130,16 @@ do {                                                                          \
                                           cdebug_count);                      \
                         cdebug_count = 0;                                     \
                 }                                                             \
-                if (time_after(jiffies, cdebug_next+(CDEBUG_MAX_LIMIT+10)*HZ))\
-                        cdebug_delay = cdebug_delay > 8 ? cdebug_delay/8 : 1; \
+                if (cfs_time_after(cfs_time_current(),                        \
+                                   cdebug_next +                              \
+                                   cfs_time_seconds(CDEBUG_MAX_LIMIT+10)))    \
+                        cdebug_delay = cdebug_delay > (8 * CFS_MIN_DELAY)?    \
+                                       cdebug_delay/8 : CFS_MIN_DELAY;        \
                 else                                                          \
-                        cdebug_delay = cdebug_delay*2 >= CDEBUG_MAX_LIMIT*HZ ?\
-                                        CDEBUG_MAX_LIMIT*HZ : cdebug_delay*2; \
-                cdebug_next = jiffies + cdebug_delay;                         \
+                        cdebug_delay = cdebug_delay*2 >= cfs_time_seconds(CDEBUG_MAX_LIMIT)?\
+                                       cfs_time_seconds(CDEBUG_MAX_LIMIT) :   \
+                                       cdebug_delay*2;                        \
+                cdebug_next = cfs_time_current() + cdebug_delay;              \
         } else {                                                              \
                 portals_debug_msg(DEBUG_SUBSYSTEM,                            \
                                   portal_debug & ~(D_EMERG|D_ERROR|D_WARNING),\
@@ -238,15 +162,25 @@ do {                                                                    \
         goto label;                                                     \
 } while (0)
 
+#define CDEBUG_ENTRY_EXIT (0)
+
+#ifdef CDEBUG_ENTRY_EXIT
+
+/*
+ * if rc == NULL, we need to code as RETURN((void *)NULL), otherwise
+ * there will be a warning in osx.
+ */
 #define RETURN(rc)                                                      \
 do {                                                                    \
         typeof(rc) RETURN__ret = (rc);                                  \
         CDEBUG(D_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n",       \
                (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret);\
+        EXIT_NESTING;                                                   \
         return RETURN__ret;                                             \
 } while (0)
 
 #define ENTRY                                                           \
+ENTRY_NESTING;                                                          \
 do {                                                                    \
         CDEBUG(D_TRACE, "Process entered\n");                           \
 } while (0)
@@ -254,8 +188,17 @@ do {                                                                    \
 #define EXIT                                                            \
 do {                                                                    \
         CDEBUG(D_TRACE, "Process leaving\n");                           \
+        EXIT_NESTING;                                                   \
 } while(0)
 #else
+
+#define RETURN(rc) return (rc)
+#define ENTRY
+#define EXIT
+
+#endif
+
+#else
 #define CDEBUG(mask, format, a...)      do { } while (0)
 #define CWARN(format, a...)             printk(KERN_WARNING format, ## a)
 #define CERROR(format, a...)            printk(KERN_ERR format, ## a)
@@ -266,23 +209,7 @@ do {                                                                    \
 #define EXIT                            do { } while (0)
 #endif
 
-/* initial pid  */
-# if CRAY_PORTALS
-/* 
- * 1) ptl_pid_t in cray portals is only 16 bits, not 32 bits, therefore this
- *    is too big.
- *
- * 2) the implementation of ernal in cray portals further restricts the pid
- *    space that may be used to 0 <= pid <= 255 (an 8 bit value).  Returns
- *    an error at nal init time for any pid outside this range.  Other nals
- *    in cray portals don't have this restriction.
- * */
-#define LUSTRE_PTL_PID          9
-# else
-#define LUSTRE_PTL_PID          12345
-# endif
-
-#define LUSTRE_SRV_PTL_PID      LUSTRE_PTL_PID    
+#define LUSTRE_SRV_PTL_PID      LUSTRE_PTL_PID
 
 #define PORTALS_CFG_VERSION 0x00010001;
 
@@ -358,7 +285,7 @@ struct portal_ioctl_data {
 
 #ifdef __KERNEL__
 
-#include <linux/list.h>
+#include <libcfs/list.h>
 
 struct libcfs_ioctl_handler {
         struct list_head item;
@@ -368,16 +295,13 @@ struct libcfs_ioctl_handler {
 
 #define DECLARE_IOCTL_HANDLER(ident, func)              \
         struct libcfs_ioctl_handler ident = {           \
-                .item = LIST_HEAD_INIT(ident.item),     \
+                .item = CFS_LIST_HEAD_INIT(ident.item),     \
                 .handle_ioctl = func                    \
         }
 
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
 
-#endif
-
-#ifdef __KERNEL__
 /* libcfs watchdogs */
 struct lc_watchdog;
 
@@ -386,7 +310,7 @@ struct lc_watchdog;
 
 /* Add a watchdog which fires after "time" milliseconds of delay.  You have to
  * touch it once to enable it. */
-struct lc_watchdog *lc_watchdog_add(int time, 
+struct lc_watchdog *lc_watchdog_add(int time,
                                     void (*cb)(struct lc_watchdog *,
                                                struct task_struct *,
                                                void *),
@@ -405,6 +329,151 @@ void lc_watchdog_delete(struct lc_watchdog *lcw);
 void lc_watchdog_dumplog(struct lc_watchdog *lcw,
                          struct task_struct *tsk,
                          void *data);
-#endif /* !__KERNEL__ */
+
+/* __KERNEL__ */
+#endif
+
+/*
+ * libcfs pseudo device operations
+ *
+ * struct cfs_psdev_t and
+ * cfs_psdev_register() and
+ * cfs_psdev_deregister() are declared in
+ * libcfs/<os>/cfs_prim.h
+ *
+ * It's just draft now.
+ */
+
+struct cfs_psdev_file {
+        unsigned long   off;
+        void            *private_data;
+        unsigned long   reserved1;
+        unsigned long   reserved2;
+};
+
+struct cfs_psdev_ops {
+        int (*p_open)(unsigned long, void *);
+        int (*p_close)(unsigned long, void *);
+        int (*p_read)(struct cfs_psdev_file *, char *, unsigned long);
+        int (*p_write)(struct cfs_psdev_file *, char *, unsigned long);
+        int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void *);
+};
+
+/*
+ * generic time manipulation functions.
+ */
+
+static inline int cfs_time_after(cfs_time_t t1, cfs_time_t t2)
+{
+        return cfs_time_before(t2, t1);
+}
+
+static inline int cfs_time_aftereq(cfs_time_t t1, cfs_time_t t2)
+{
+        return cfs_time_beforeq(t2, t1);
+}
+
+/*
+ * return seconds since UNIX epoch
+ */
+static inline time_t cfs_unix_seconds(void)
+{
+        cfs_fs_time_t t;
+
+        cfs_fs_time_current(&t);
+        return cfs_fs_time_sec(&t);
+}
+
+#define CFS_RATELIMIT(seconds)                                  \
+({                                                              \
+        /*                                                      \
+         * XXX nikita: non-portable initializer                 \
+         */                                                     \
+        static time_t __next_message = 0;                       \
+        int result;                                             \
+                                                                \
+        if (cfs_time_after(cfs_time_current(), __next_message)) \
+                result = 1;                                     \
+        else {                                                  \
+                __next_message = cfs_time_shift(seconds);       \
+                result = 0;                                     \
+        }                                                       \
+        result;                                                 \
+})
+
+extern void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
+                              const int line, unsigned long stack,
+                              char *format, ...)
+            __attribute__ ((format (printf, 7, 8)));
+
+
+static inline void cfs_slow_warning(cfs_time_t now, int seconds, char *msg)
+{
+        if (cfs_time_after(cfs_time_current(),
+                           cfs_time_add(now, cfs_time_seconds(15))))
+                CERROR("slow %s %lu sec\n", msg,
+                       cfs_duration_sec(cfs_time_sub(cfs_time_current(), now)));
+}
+
+/*
+ * helper function similar to do_gettimeofday() of Linux kernel
+ */
+static inline void cfs_fs_timeval(struct timeval *tv)
+{
+       cfs_fs_time_t time;
+
+       cfs_fs_time_current(&time);
+       cfs_fs_time_usec(&time, tv);
+}
+
+/*
+ * return valid time-out based on user supplied one. Currently we only check
+ * that time-out is not shorted than allowed.
+ */
+static inline cfs_duration_t cfs_timeout_cap(cfs_duration_t timeout)
+{
+       if (timeout < cfs_time_minimal_timeout())
+               timeout = cfs_time_minimal_timeout();
+       return timeout;
+}
+
+/*
+ * Portable memory allocator API (draft)
+ */
+enum cfs_alloc_flags {
+        /* allocation is not allowed to block */
+        CFS_ALLOC_ATOMIC = (1 << 0),
+        /* allocation is allowed to block */
+        CFS_ALLOC_WAIT = (1 << 1),
+        /* allocation should return zeroed memory */
+        CFS_ALLOC_ZERO   = (1 << 2),
+        /* allocation is allowed to call file-system code to free/clean
+         * memory */
+        CFS_ALLOC_FS     = (1 << 3),
+        /* allocation is allowed to do io to free/clean memory */
+        CFS_ALLOC_IO     = (1 << 4),
+        /* standard allocator flag combination */
+        CFS_ALLOC_STD    = CFS_ALLOC_FS | CFS_ALLOC_IO,
+        CFS_ALLOC_USER   = CFS_ALLOC_WAIT | CFS_ALLOC_FS | CFS_ALLOC_IO,
+};
+
+#define CFS_SLAB_ATOMIC         CFS_ALLOC_ATOMIC
+#define CFS_SLAB_WAIT           CFS_ALLOC_WAIT
+#define CFS_SLAB_ZERO           CFS_ALLOC_ZERO
+#define CFS_SLAB_FS             CFS_ALLOC_FS
+#define CFS_SLAB_IO             CFS_ALLOC_IO
+#define CFS_SLAB_STD            CFS_ALLOC_STD
+#define CFS_SLAB_USER           CFS_ALLOC_USER
+
+/* flags for cfs_page_alloc() in addition to enum cfs_alloc_flags */
+enum cfs_page_alloc_flags {
+        /* allow to return page beyond KVM. It has to be mapped into KVM by
+         * cfs_page_map(); */
+        CFS_ALLOC_HIGH   = (1 << 5),
+        CFS_ALLOC_HIGHUSER = CFS_ALLOC_WAIT | CFS_ALLOC_FS | CFS_ALLOC_IO | CFS_ALLOC_HIGH,
+};
+
+
+#define _LIBCFS_H
 
 #endif /* _LIBCFS_H */
diff --git a/lnet/include/libcfs/linux/.cvsignore b/lnet/include/libcfs/linux/.cvsignore
new file mode 100644 (file)
index 0000000..3dda729
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
diff --git a/lnet/include/libcfs/linux/Makefile.am b/lnet/include/libcfs/linux/Makefile.am
new file mode 100644 (file)
index 0000000..f340c87
--- /dev/null
@@ -0,0 +1,3 @@
+EXTRA_DIST := linux-fs.h linux-prim.h portals_lib.h kp30.h             \
+       linux-lock.h lltrace.h portals_utils.h libcfs.h linux-mem.h     \
+       portals_compat25.h
diff --git a/lnet/include/libcfs/linux/kp30.h b/lnet/include/libcfs/linux/kp30.h
new file mode 100644 (file)
index 0000000..344264d
--- /dev/null
@@ -0,0 +1,322 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __LIBCFS_LINUX_KP30_H__
+#define __LIBCFS_LINUX_KP30_H__
+
+#ifndef __LIBCFS_KP30_H__
+#error Do not #include this file directly. #include <libcfs/kp30.h> instead
+#endif
+
+#ifdef __KERNEL__
+# include <linux/config.h>
+# include <linux/kernel.h>
+# include <linux/mm.h>
+# include <linux/string.h>
+# include <linux/stat.h>
+# include <linux/init.h>
+# include <linux/errno.h>
+# include <linux/unistd.h>
+# include <asm/system.h>
+# include <linux/kmod.h>
+# include <linux/notifier.h>
+# include <linux/fs.h>
+# include <asm/segment.h>
+# include <linux/miscdevice.h>
+# include <linux/vmalloc.h>
+# include <linux/time.h>
+# include <linux/slab.h>
+# include <linux/interrupt.h>
+# include <linux/highmem.h>
+# include <linux/module.h>
+# include <linux/version.h>
+# include <portals/p30.h>
+# include <linux/smp_lock.h>
+# include <asm/atomic.h>
+# include <asm/uaccess.h>
+# include <linux/rwsem.h>
+# include <linux/proc_fs.h>
+# include <linux/file.h>
+# include <linux/smp.h>
+# include <linux/ctype.h>
+# ifdef HAVE_MM_INLINE
+#  include <linux/mm_inline.h>
+# endif
+# if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
+#  include <linux/kallsyms.h>
+# endif
+
+#include <libcfs/linux/portals_compat25.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+#define schedule_work schedule_task
+#define prepare_work(wq,cb,cbdata)                                            \
+do {                                                                          \
+        INIT_TQUEUE((wq), 0, 0);                                              \
+        PREPARE_TQUEUE((wq), (cb), (cbdata));                                 \
+} while (0)
+
+#define PageUptodate Page_Uptodate
+#define our_recalc_sigpending(current) recalc_sigpending(current)
+#define num_online_cpus() smp_num_cpus
+static inline void our_cond_resched(void)
+{
+        if (current->need_resched)
+               schedule ();
+}
+#define work_struct_t       struct tq_struct
+
+#else
+
+#define prepare_work(wq,cb,cbdata)                                            \
+do {                                                                          \
+        INIT_WORK((wq), (void *)(cb), (void *)(cbdata));                      \
+} while (0)
+#define wait_on_page wait_on_page_locked
+#define our_recalc_sigpending(current) recalc_sigpending()
+#define strtok(a,b) strpbrk(a, b)
+static inline void our_cond_resched(void)
+{
+        cond_resched();
+}
+#define work_struct_t      struct work_struct
+
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
+
+#ifdef CONFIG_SMP
+#define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
+#else
+#define LASSERT_SPIN_LOCKED(lock) do {} while(0)
+#endif
+
+#ifdef __arch_um__
+#define LBUG_WITH_LOC(file, func, line)                                 \
+do {                                                                    \
+        CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n");       \
+        portals_debug_dumplog();                                        \
+        portals_run_lbug_upcall(file, func, line);                      \
+        panic("LBUG");                                                  \
+} while (0)
+#else
+#define LBUG_WITH_LOC(file, func, line)                                 \
+do {                                                                    \
+        CEMERG("LBUG\n");                                               \
+        portals_debug_dumpstack(NULL);                                  \
+        portals_debug_dumplog();                                        \
+        portals_run_lbug_upcall(file, func, line);                      \
+        set_task_state(current, TASK_UNINTERRUPTIBLE);                  \
+        schedule();                                                     \
+} while (0)
+#endif /* __arch_um__ */
+
+/* ------------------------------------------------------------------- */
+                                                                                                                                                                            
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+                                                                                                                                                                            
+#define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
+#define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
+                                                                                                                                                                            
+#define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
+#define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
+                                                                                                                                                                            
+#define PORTAL_MODULE_USE       MOD_INC_USE_COUNT
+#define PORTAL_MODULE_UNUSE     MOD_DEC_USE_COUNT
+#else
+                                                                                                                                                                            
+#define PORTAL_SYMBOL_REGISTER(x)
+#define PORTAL_SYMBOL_UNREGISTER(x)
+                                                                                                                                                                            
+#define PORTAL_SYMBOL_GET(x) symbol_get(x)
+#define PORTAL_SYMBOL_PUT(x) symbol_put(x)
+                                                                                                                                                                            
+#define PORTAL_MODULE_USE       try_module_get(THIS_MODULE)
+#define PORTAL_MODULE_UNUSE     module_put(THIS_MODULE)
+                                                                                                                                                                            
+#endif
+                                                                                                                                                                            
+/******************************************************************************/
+
+#if (__GNUC__)
+/* Use the special GNU C __attribute__ hack to have the compiler check the
+ * printf style argument string against the actual argument count and
+ * types.
+ */
+#ifdef printf
+# warning printf has been defined as a macro...
+# undef printf
+#endif
+
+#endif /* __GNUC__ */
+
+# define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
+# define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
+# define time(a) CURRENT_TIME
+
+#else  /* !__KERNEL__ */
+# include <stdio.h>
+# include <stdlib.h>
+#ifndef __CYGWIN__
+# include <stdint.h>
+#else
+# include <cygwin-ioctl.h>
+#endif
+# include <unistd.h>
+# include <time.h>
+# include <limits.h>
+
+#endif /* End of !__KERNEL__ */
+
+/******************************************************************************/
+/* Light-weight trace
+ * Support for temporary event tracing with minimal Heisenberg effect. */
+#define LWT_SUPPORT  0
+
+#define LWT_MEMORY   (16<<20)
+
+#if !KLWT_SUPPORT
+# if defined(__KERNEL__)
+#  if !defined(BITS_PER_LONG)
+#   error "BITS_PER_LONG not defined"
+#  endif
+# elif !defined(__WORDSIZE)
+#  error "__WORDSIZE not defined"
+# else
+#  define BITS_PER_LONG __WORDSIZE
+# endif
+
+/* kernel hasn't defined this? */
+typedef struct {
+        long long   lwte_when;
+        char       *lwte_where;
+        void       *lwte_task;
+        long        lwte_p1;
+        long        lwte_p2;
+        long        lwte_p3;
+        long        lwte_p4;
+# if BITS_PER_LONG > 32
+        long        lwte_pad;
+# endif
+} lwt_event_t;
+#endif /* !KLWT_SUPPORT */
+
+#if LWT_SUPPORT
+# ifdef __KERNEL__
+#  if !KLWT_SUPPORT
+
+typedef struct _lwt_page {
+        struct list_head     lwtp_list;
+        struct page         *lwtp_page;
+        lwt_event_t         *lwtp_events;
+} lwt_page_t;
+
+typedef struct {
+        int                lwtc_current_index;
+        lwt_page_t        *lwtc_current_page;
+} lwt_cpu_t;
+
+extern int       lwt_enabled;
+extern lwt_cpu_t lwt_cpus[];
+
+/* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
+ * This stuff is meant for finding specific problems; it never stays in
+ * production code... */
+
+#define LWTSTR(n)       #n
+#define LWTWHERE(f,l)   f ":" LWTSTR(l)
+#define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
+
+#define LWT_EVENT(p1, p2, p3, p4)                                       \
+do {                                                                    \
+        unsigned long    flags;                                         \
+        lwt_cpu_t       *cpu;                                           \
+        lwt_page_t      *p;                                             \
+        lwt_event_t     *e;                                             \
+                                                                        \
+        if (lwt_enabled) {                                              \
+                local_irq_save (flags);                                 \
+                                                                        \
+                cpu = &lwt_cpus[smp_processor_id()];                    \
+                p = cpu->lwtc_current_page;                             \
+                e = &p->lwtp_events[cpu->lwtc_current_index++];         \
+                                                                        \
+                if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) {   \
+                        cpu->lwtc_current_page =                        \
+                                list_entry (p->lwtp_list.next,          \
+                                            lwt_page_t, lwtp_list);     \
+                        cpu->lwtc_current_index = 0;                    \
+                }                                                       \
+                                                                        \
+                e->lwte_when  = get_cycles();                           \
+                e->lwte_where = LWTWHERE(__FILE__,__LINE__);            \
+                e->lwte_task  = current;                                \
+                e->lwte_p1    = (long)(p1);                             \
+                e->lwte_p2    = (long)(p2);                             \
+                e->lwte_p3    = (long)(p3);                             \
+                e->lwte_p4    = (long)(p4);                             \
+                                                                        \
+                local_irq_restore (flags);                              \
+        }                                                               \
+} while (0)
+
+#endif /* !KLWT_SUPPORT */
+
+extern int  lwt_init (void);
+extern void lwt_fini (void);
+extern int  lwt_lookup_string (int *size, char *knlptr,
+                               char *usrptr, int usrsize);
+extern int  lwt_control (int enable, int clear);
+extern int  lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
+                          void *user_ptr, int user_size);
+# else  /* __KERNEL__ */
+#  define LWT_EVENT(p1,p2,p3,p4)     /* no userland implementation yet */
+# endif /* __KERNEL__ */
+#endif /* LWT_SUPPORT */
+
+/* ------------------------------------------------------------------ */
+
+#define IOCTL_PORTAL_TYPE long
+
+#ifdef __CYGWIN__
+# ifndef BITS_PER_LONG
+#  if (~0UL) == 0xffffffffUL
+#   define BITS_PER_LONG 32
+#  else
+#   define BITS_PER_LONG 64
+#  endif
+# endif
+#endif
+
+#if BITS_PER_LONG > 32
+# define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
+# define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
+# define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
+#else
+# define LI_POISON ((int)0x5a5a5a5a)
+# define LL_POISON ((long)0x5a5a5a5a)
+# define LP_POISON ((void *)(long)0x5a5a5a5a)
+#endif
+
+#if defined(__x86_64__)
+# define LPU64 "%Lu"
+# define LPD64 "%Ld"
+# define LPX64 "%#Lx"
+# define LPSZ  "%lu"
+# define LPSSZ "%ld"
+#elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
+# define LPU64 "%Lu"
+# define LPD64 "%Ld"
+# define LPX64 "%#Lx"
+# define LPSZ  "%u"
+# define LPSSZ "%d"
+#elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
+# define LPU64 "%lu"
+# define LPD64 "%ld"
+# define LPX64 "%#lx"
+# define LPSZ  "%lu"
+# define LPSSZ "%ld"
+#endif
+#ifndef LPU64
+# error "No word size defined"
+#endif
+
+#endif
diff --git a/lnet/include/libcfs/linux/libcfs.h b/lnet/include/libcfs/linux/libcfs.h
new file mode 100644 (file)
index 0000000..208b89e
--- /dev/null
@@ -0,0 +1,151 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __LIBCFS_LINUX_LIBCFS_H__
+#define __LIBCFS_LINUX_LIBCFS_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#include <libcfs/linux/linux-mem.h>
+#include <libcfs/linux/linux-time.h>
+#include <libcfs/linux/linux-prim.h>
+#include <libcfs/linux/linux-lock.h>
+#include <libcfs/linux/linux-fs.h>
+
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#else
+#include "types.h"
+#endif
+
+
+#ifdef __KERNEL__
+# include <linux/types.h>
+# include <linux/time.h>
+# include <asm/timex.h>
+#else
+# include <sys/types.h>
+# include <sys/time.h>
+# define do_gettimeofday(tv) gettimeofday(tv, NULL);
+typedef unsigned long long cycles_t;
+#endif
+
+#ifndef __KERNEL__
+/* Userpace byte flipping */
+# include <endian.h>
+# include <byteswap.h>
+# define __swab16(x) bswap_16(x)
+# define __swab32(x) bswap_32(x)
+# define __swab64(x) bswap_64(x)
+# define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
+# define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
+# define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define le16_to_cpu(x) (x)
+#  define cpu_to_le16(x) (x)
+#  define le32_to_cpu(x) (x)
+#  define cpu_to_le32(x) (x)
+#  define le64_to_cpu(x) (x)
+#  define cpu_to_le64(x) (x)
+# else
+#  if __BYTE_ORDER == __BIG_ENDIAN
+#   define le16_to_cpu(x) bswap_16(x)
+#   define cpu_to_le16(x) bswap_16(x)
+#   define le32_to_cpu(x) bswap_32(x)
+#   define cpu_to_le32(x) bswap_32(x)
+#   define le64_to_cpu(x) bswap_64(x)
+#   define cpu_to_le64(x) bswap_64(x)
+#  else
+#   error "Unknown byte order"
+#  endif /* __BIG_ENDIAN */
+# endif /* __LITTLE_ENDIAN */
+#endif /* ! __KERNEL__ */
+
+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__
+# include <linux/sched.h> /* THREAD_SIZE */
+#else
+# ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
+#  define THREAD_SIZE 8192
+# endif
+#endif
+
+#define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
+
+#ifdef __KERNEL__
+# ifdef  __ia64__
+#  define CDEBUG_STACK (THREAD_SIZE -                                      \
+                        ((unsigned long)__builtin_dwarf_cfa() &            \
+                         (THREAD_SIZE - 1)))
+# else
+#  define CDEBUG_STACK (THREAD_SIZE -                                      \
+                        ((unsigned long)__builtin_frame_address(0) &       \
+                         (THREAD_SIZE - 1)))
+# endif /* __ia64__ */
+
+#define CHECK_STACK(stack)                                                    \
+        do {                                                                  \
+                if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) {    \
+                        portals_debug_msg(DEBUG_SUBSYSTEM, D_WARNING,         \
+                                          __FILE__, __FUNCTION__, __LINE__,   \
+                                          (stack),"maximum lustre stack %u\n",\
+                                          portal_stack = (stack));            \
+                      /*panic("LBUG");*/                                      \
+                }                                                             \
+        } while (0)
+#else /* !__KERNEL__ */
+#define CHECK_STACK(stack) do { } while(0)
+#define CDEBUG_STACK (0L)
+#endif /* __KERNEL__ */
+
+/* initial pid  */
+# if CRAY_PORTALS
+/*
+ * 1) ptl_pid_t in cray portals is only 16 bits, not 32 bits, therefore this
+ *    is too big.
+ *
+ * 2) the implementation of ernal in cray portals further restricts the pid
+ *    space that may be used to 0 <= pid <= 255 (an 8 bit value).  Returns
+ *    an error at nal init time for any pid outside this range.  Other nals
+ *    in cray portals don't have this restriction.
+ * */
+#define LUSTRE_PTL_PID          9
+# else
+#define LUSTRE_PTL_PID          12345
+# endif
+
+#define ENTRY_NESTING_SUPPORT (0)
+#define ENTRY_NESTING   do {;} while (0)
+#define EXIT_NESTING   do {;} while (0)
+#define __current_nesting_level() (0)
+
+/*
+ * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
+ *
+ * Implementation is in linux-curproc.c
+ */
+#define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
+
+#if defined(__KERNEL__)
+#include <linux/capability.h>
+typedef kernel_cap_t cfs_kernel_cap_t;
+#else
+typedef __u32 cfs_kernel_cap_t;
+#endif
+
+#endif /* _LINUX_LIBCFS_H */
diff --git a/lnet/include/libcfs/linux/linux-fs.h b/lnet/include/libcfs/linux/linux-fs.h
new file mode 100644 (file)
index 0000000..9530360
--- /dev/null
@@ -0,0 +1,70 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic library routines. 
+ *
+ */
+
+#ifndef __LIBCFS_LINUX_CFS_FS_H__
+#define __LIBCFS_LINUX_CFS_FS_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+#include <linux/fs.h>
+#include <linux/stat.h>
+#include <linux/mount.h>
+#endif
+
+typedef struct file cfs_file_t;
+typedef struct dentry cfs_dentry_t;
+
+#ifdef __KERNEL__
+#define cfs_filp_size(f)               ((f)->f_dentry->d_inode->i_size)
+#define cfs_filp_poff(f)                (&(f)->f_pos)
+
+/* 
+ * XXX Do we need to parse flags and mode in cfs_filp_open? 
+ */
+cfs_file_t *cfs_filp_open (const char *name, int flags, int mode, int *err);
+#define cfs_filp_close(f)                   filp_close(f, NULL)
+#define cfs_filp_read(fp, buf, size, pos)   (fp)->f_op->read((fp), (buf), (size), pos)
+#define cfs_filp_write(fp, buf, size, pos)  (fp)->f_op->write((fp), (buf), (size), pos)
+#define cfs_filp_fsync(fp)                  (fp)->f_op->fsync((fp), (fp)->f_dentry, 1)
+
+#define cfs_get_file(f)                     get_file(f)
+#define cfs_put_file(f)                     fput(f)
+#define cfs_file_count(f)                   file_count(f)
+
+typedef struct file_lock cfs_flock_t; 
+#define CFS_FLOCK_TYPE(fl)                  ((fl)->fl_type)
+#define CFS_FLOCK_SET_TYPE(fl, type)        do { (fl)->fl_type = (type); } while(0)
+#define CFS_FLOCK_PID(fl)                   ((fl)->fl_pid)
+#define CFS_FLOCK_SET_PID(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
+#define CFS_FLOCK_START(fl)                 ((fl)->fl_start)
+#define CFS_FLOCK_SET_START(fl, start)      do { (fl)->fl_start = (start); } while(0)
+#define CFS_FLOCK_END(fl)                   ((fl)->fl_end)
+#define CFS_FLOCK_SET_END(fl, end)          do { (fl)->fl_end = (end); } while(0)
+
+#endif
+
+#endif
diff --git a/lnet/include/libcfs/linux/linux-lock.h b/lnet/include/libcfs/linux/linux-lock.h
new file mode 100644 (file)
index 0000000..ce097e9
--- /dev/null
@@ -0,0 +1,118 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic library routines.
+ *
+ */
+
+#ifndef __LIBCFS_LINUX_CFS_LOCK_H__
+#define __LIBCFS_LINUX_CFS_LOCK_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+#include <linux/smp_lock.h>
+
+/*
+ * 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 (use Linux kernel's primitives)
+ *
+ * - spin_lock_init(x)
+ * - spin_lock(x)
+ * - spin_unlock(x)
+ * - spin_trylock(x)
+ *
+ * - spin_lock_irqsave(x, f)
+ * - spin_unlock_irqrestore(x, f)
+ */
+
+/*
+ * rw_semaphore (use Linux kernel's primitives)
+ *
+ * - init_rwsem(x)
+ * - down_read(x)
+ * - up_read(x)
+ * - down_write(x)
+ * - up_write(x)
+ */
+
+/*
+ * rwlock_t (use Linux kernel's primitives)
+ *
+ * - rwlock_init(x)
+ * - read_lock(x)
+ * - read_unlock(x)
+ * - write_lock(x)
+ * - write_unlock(x)
+ */
+
+/*
+ * mutex_t:
+ *
+ * - init_mutex(x)
+ * - init_mutex_locked(x)
+ * - mutex_up(x)
+ * - mutex_down(x)
+ */
+#define init_mutex(x)                   init_MUTEX(x)
+#define init_mutex_locked(x)            init_MUTEX_LOCKED(x)
+#define mutex_up(x)                     up(x)
+#define mutex_down(x)                   down(x)
+
+/*
+ * completion (use Linux kernel's primitives)
+ *
+ * - init_complition(c)
+ * - complete(c)
+ * - wait_for_completion(c)
+ */
+
+/*
+ * OSX funnels:
+ *
+ * No funnels needed in Linux
+ */
+#define CFS_DECL_FUNNEL_DATA
+#define CFS_DECL_CONE_DATA             DECLARE_FUNNEL_DATA
+#define CFS_DECL_NET_DATA               DECLARE_FUNNEL_DATA
+#define CFS_CONE_IN                    do {} while(0)
+#define CFS_CONE_EX                    do {} while(0)
+
+#define CFS_NET_IN                      do {} while(0)
+#define CFS_NET_EX                      do {} while(0)
+
+/* __KERNEL__ */
+#else
+
+//#include "../user-lock.h"
+
+/* __KERNEL__ */
+#endif
+#endif
diff --git a/lnet/include/libcfs/linux/linux-mem.h b/lnet/include/libcfs/linux/linux-mem.h
new file mode 100644 (file)
index 0000000..94b764f
--- /dev/null
@@ -0,0 +1,110 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic library routines.
+ *
+ */
+
+#ifndef __LIBCFS_LINUX_CFS_MEM_H__
+#define __LIBCFS_LINUX_CFS_MEM_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+# include <linux/mm.h>
+# include <linux/vmalloc.h>
+# include <linux/pagemap.h>
+# include <linux/slab.h>
+# ifdef HAVE_MM_INLINE
+#  include <linux/mm_inline.h>
+# endif
+
+typedef struct page                     cfs_page_t;
+#define CFS_PAGE_SIZE                   PAGE_CACHE_SIZE
+#define CFS_PAGE_SHIFT                  PAGE_CACHE_SHIFT
+#define CFS_PAGE_MASK                   PAGE_CACHE_MASK
+
+cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order);
+#define cfs_alloc_page(f)              cfs_alloc_pages(f, 0)
+#define cfs_free_pages(p, o)           __free_pages(p, o)
+#define cfs_free_page(p)               __free_pages(p, 0)
+
+static inline void *cfs_page_address(cfs_page_t *page)
+{
+        return page_address(page);
+}
+
+static inline void *cfs_kmap(cfs_page_t *page)
+{
+        return kmap(page);
+}
+
+static inline void cfs_kunmap(cfs_page_t *page)
+{
+        kunmap(page);
+}
+
+static inline void cfs_get_page(cfs_page_t *page)
+{
+        get_page(page);
+}
+
+static inline int cfs_page_count(cfs_page_t *page)
+{
+        return page_count(page);
+}
+
+static inline void cfs_set_page_count(cfs_page_t *page, int v)
+{
+        set_page_count(page, v);
+}
+
+/*
+ * Memory allocator
+ */
+extern void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
+extern void  cfs_free(void *addr);
+
+extern void *cfs_alloc_large(size_t nr_bytes);
+extern void  cfs_free_large(void *addr);
+
+/*
+ * SLAB allocator
+ */
+typedef kmem_cache_t    cfs_mem_cache_t;
+extern cfs_mem_cache_t * cfs_mem_cache_create (const char *, size_t, size_t, unsigned long,
+                                               void (*)(void *, cfs_mem_cache_t *, unsigned long),
+                                               void (*)(void *, cfs_mem_cache_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 *);
+
+/*
+ */
+#define CFS_DECL_MMSPACE                mm_segment_t __oldfs
+#define CFS_MMSPACE_OPEN                do { __oldfs = get_fs(); set_fs(get_ds());} while(0)
+#define CFS_MMSPACE_CLOSE               set_fs(__oldfs)
+
+/* __KERNEL__ */
+#endif
+
+#endif /* __LINUX_CFS_MEM_H__ */
diff --git a/lnet/include/libcfs/linux/linux-prim.h b/lnet/include/libcfs/linux/linux-prim.h
new file mode 100644 (file)
index 0000000..69bda36
--- /dev/null
@@ -0,0 +1,173 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic library routines.
+ *
+ */
+
+#ifndef __LIBCFS_LINUX_CFS_PRIM_H__
+#define __LIBCFS_LINUX_CFS_PRIM_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+#ifdef __KERNEL__
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/proc_fs.h>
+#include <linux/mm.h>
+#include <linux/timer.h>
+
+#include <linux/miscdevice.h>
+#include <libcfs/linux/portals_compat25.h>
+#include <asm/div64.h>
+
+#include <libcfs/linux/linux-time.h>
+
+/*
+ * Pseudo device register
+ */
+typedef struct miscdevice              cfs_psdev_t;
+#define cfs_psdev_register(dev)                misc_register(dev)
+#define cfs_psdev_deregister(dev)      misc_deregister(dev)
+
+/*
+ * Sysctl register
+ */
+typedef struct ctl_table               cfs_sysctl_table_t;
+typedef struct ctl_table_header                cfs_sysctl_table_header_t;
+
+#define register_cfs_sysctl_table(t, a)        register_sysctl_table(t, a)
+#define unregister_cfs_sysctl_table(t) unregister_sysctl_table(t, a)
+
+/*
+ * Proc file system APIs
+ */
+typedef read_proc_t                     cfs_read_proc_t;
+typedef write_proc_t                    cfs_write_proc_t;
+typedef struct proc_dir_entry           cfs_proc_dir_entry_t;
+#define cfs_create_proc_entry(n, m, p)  create_proc_entry(n, m, p)
+#define cfs_free_proc_entry(e)          free_proc_entry(e)
+#define cfs_remove_proc_entry(n, e)     remove_proc_entry(n, e)
+
+/*
+ * Wait Queue
+ */
+typedef wait_queue_t                   cfs_waitlink_t;
+typedef wait_queue_head_t              cfs_waitq_t;
+
+#define cfs_waitq_init(w)              init_waitqueue_head(w)
+#define cfs_waitlink_init(l)           init_waitqueue_entry(l, current)
+#define cfs_waitq_add(w, l)            add_wait_queue(w, l)
+#define cfs_waitq_add_exclusive(w, l)  add_wait_queue_exclusive(w, l)
+#define cfs_waitq_forward(l, w)         do {} while(0)
+#define cfs_waitq_del(w, l)            remove_wait_queue(w, l)
+#define cfs_waitq_active(w)            waitqueue_active(w)
+#define cfs_waitq_signal(w)            wake_up(w)
+#define cfs_waitq_signal_nr(w,n)       wake_up_nr(w, n)
+#define cfs_waitq_broadcast(w)         wake_up_all(w)
+#define cfs_waitq_wait(l)              schedule()
+#define cfs_waitq_timedwait(l, t)      schedule_timeout(t)
+
+/* Kernel thread */
+typedef int (*cfs_thread_t)(void *);
+#define cfs_kernel_thread(func, a, f)   kernel_thread(func, a, f)
+
+/*
+ * Task struct
+ */
+typedef struct task_struct              cfs_task_t;
+#define cfs_current()                   current
+#define CFS_DECL_JOURNAL_DATA           void *journal_info
+#define CFS_PUSH_JOURNAL                do {    \
+        journal_info = current->journal_info;   \
+        current->journal_info = NULL;           \
+        } while(0)
+#define CFS_POP_JOURNAL                 do {    \
+        current->journal_info = journal_info;   \
+        } while(0)
+
+/* Module interfaces */
+#define cfs_module(name, version, init, fini) \
+module_init(init);                            \
+module_exit(fini)
+
+/*
+ * Signal
+ */
+#define cfs_sigmask_lock(t, f)          SIGNAL_MASK_LOCK(t, f)
+#define cfs_sigmask_unlock(t, f)        SIGNAL_MASK_UNLOCK(t, f)
+#define cfs_recalc_sigpending(t)        RECALC_SIGPENDING
+#define cfs_signal_pending(t)           signal_pending(t)
+#define cfs_sigfillset(s)               sigfillset(s)
+
+#define cfs_set_sig_blocked(t, b)       do { (t)->blocked = b; } while(0)
+#define cfs_get_sig_blocked(t)          (&(t)->blocked)
+
+/*
+ * Timer
+ */
+typedef struct timer_list cfs_timer_t;
+typedef  void (*timer_func_t)(unsigned long);
+
+#define cfs_init_timer(t)       init_timer(t)
+
+static inline void cfs_timer_init(cfs_timer_t *t, void (*func)(unsigned long), void *arg)
+{
+        init_timer(t);
+        t->function = (timer_func_t)func;
+        t->data = (unsigned long)arg;
+}
+
+static inline void cfs_timer_done(cfs_timer_t *t)
+{
+        return;
+}
+
+static inline void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline)
+{
+        mod_timer(t, deadline);
+}
+
+static inline void cfs_timer_disarm(cfs_timer_t *t)
+{
+        del_timer(t);
+}
+
+static inline int  cfs_timer_is_armed(cfs_timer_t *t)
+{
+        return timer_pending(t);
+}
+
+static inline cfs_time_t cfs_timer_deadline(cfs_timer_t *t)
+{
+        return t->expires;
+}
+
+#else   /* !__KERNEL__ */
+
+#include "../user-prim.h"
+
+#endif /* __KERNEL__ */
+
+#endif
diff --git a/lnet/include/libcfs/linux/linux-time.h b/lnet/include/libcfs/linux/linux-time.h
new file mode 100644 (file)
index 0000000..f18e7d9
--- /dev/null
@@ -0,0 +1,292 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Copyright (C) 2004 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of Lustre, http://www.lustre.org.
+ *
+ * Lustre is free software; you can redistribute it and/or modify it under the
+ * terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * Lustre 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 for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
+ * Ave, Cambridge, MA 02139, USA.
+ *
+ * Implementation of portable time API for Linux (kernel and user-level).
+ *
+ */
+
+#ifndef __LIBCFS_LINUX_LINUX_TIME_H__
+#define __LIBCFS_LINUX_LINUX_TIME_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+/* Portable time API */
+
+/*
+ * Platform provides three opaque data-types:
+ *
+ *  cfs_time_t        represents point in time. This is internal kernel
+ *                    time rather than "wall clock". This time bears no
+ *                    relation to gettimeofday().
+ *
+ *  cfs_duration_t    represents time interval with resolution of internal
+ *                    platform clock
+ *
+ *  cfs_fs_time_t     represents instance in world-visible time. This is
+ *                    used in file-system time-stamps
+ *
+ *  cfs_time_t     cfs_time_current(void);
+ *  cfs_time_t     cfs_time_add    (cfs_time_t, cfs_duration_t);
+ *  cfs_duration_t cfs_time_sub    (cfs_time_t, cfs_time_t);
+ *  int            cfs_time_before (cfs_time_t, cfs_time_t);
+ *  int            cfs_time_beforeq(cfs_time_t, cfs_time_t);
+ *
+ *  cfs_duration_t cfs_duration_build(int64_t);
+ *
+ *  time_t         cfs_duration_sec (cfs_duration_t);
+ *  void           cfs_duration_usec(cfs_duration_t, struct timeval *);
+ *  void           cfs_duration_nsec(cfs_duration_t, struct timespec *);
+ *
+ *  void           cfs_fs_time_current(cfs_fs_time_t *);
+ *  time_t         cfs_fs_time_sec    (cfs_fs_time_t *);
+ *  void           cfs_fs_time_usec   (cfs_fs_time_t *, struct timeval *);
+ *  void           cfs_fs_time_nsec   (cfs_fs_time_t *, struct timespec *);
+ *  int            cfs_fs_time_before (cfs_fs_time_t *, cfs_fs_time_t *);
+ *  int            cfs_fs_time_beforeq(cfs_fs_time_t *, cfs_fs_time_t *);
+ *
+ *  cfs_duration_t cfs_time_minimal_timeout(void)
+ *
+ *  CFS_TIME_FORMAT
+ *  CFS_DURATION_FORMAT
+ *
+ */
+
+#define ONE_BILLION ((u_int64_t)1000000000)
+#define ONE_MILLION ((u_int64_t)   1000000)
+
+#ifdef __KERNEL__
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/time.h>
+#include <asm/div64.h>
+
+#include <libcfs/linux/portals_compat25.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+
+/*
+ * old kernels---CURRENT_TIME is struct timeval
+ */
+typedef struct timeval cfs_fs_time_t;
+
+static inline void cfs_fs_time_usec(cfs_fs_time_t *t, struct timeval *v)
+{
+        *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;
+}
+
+/*
+ * internal helper function used by cfs_fs_time_before*()
+ */
+static inline unsigned long __cfs_fs_time_flat(cfs_fs_time_t *t)
+{
+        return ((unsigned long)t->tv_sec) * ONE_MILLION + t->tv_usec * 1000;
+}
+
+#define CURRENT_KERN_TIME        xtime
+
+/* (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) */
+#else
+
+/*
+ * post 2.5 kernels.
+ */
+
+#include <linux/jiffies.h>
+
+typedef struct timespec cfs_fs_time_t;
+
+static inline void cfs_fs_time_usec(cfs_fs_time_t *t, struct timeval *v)
+{
+        v->tv_sec  = t->tv_sec;
+        v->tv_usec = t->tv_nsec / 1000;
+}
+
+static inline void cfs_fs_time_nsec(cfs_fs_time_t *t, struct timespec *s)
+{
+        *s = *t;
+}
+
+/*
+ * internal helper function used by cfs_fs_time_before*()
+ */
+static inline unsigned long __cfs_fs_time_flat(cfs_fs_time_t *t)
+{
+        return ((unsigned long)t->tv_sec) * ONE_BILLION + t->tv_nsec;
+}
+
+#define CURRENT_KERN_TIME        CURRENT_TIME
+
+/* (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) */
+#endif
+
+/*
+ * Generic kernel stuff
+ */
+
+typedef unsigned long cfs_time_t;      /* jiffies */
+typedef long cfs_duration_t;
+
+
+static inline cfs_time_t cfs_time_current(void)
+{
+        return jiffies;
+}
+
+static inline time_t cfs_time_current_sec(void)
+{
+        return CURRENT_SECONDS;
+}
+
+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 time_before(t1, t2);
+}
+
+static inline int cfs_time_beforeq(cfs_time_t t1, cfs_time_t t2)
+{
+        return time_before_eq(t1, t2);
+}
+
+static inline void cfs_fs_time_current(cfs_fs_time_t *t)
+{
+        *t = CURRENT_KERN_TIME;
+}
+
+static inline time_t cfs_fs_time_sec(cfs_fs_time_t *t)
+{
+        return t->tv_sec;
+}
+
+static inline int cfs_fs_time_before(cfs_fs_time_t *t1, cfs_fs_time_t *t2)
+{
+        return time_before(__cfs_fs_time_flat(t1), __cfs_fs_time_flat(t2));
+}
+
+static inline int cfs_fs_time_beforeq(cfs_fs_time_t *t1, cfs_fs_time_t *t2)
+{
+        return time_before_eq(__cfs_fs_time_flat(t1), __cfs_fs_time_flat(t2));
+}
+
+#if 0
+static inline cfs_duration_t cfs_duration_build(int64_t nano)
+{
+#if (BITS_PER_LONG == 32)
+        /* We cannot use do_div(t, ONE_BILLION), do_div can only process
+         * 64 bits n and 32 bits base */
+        int64_t  t = nano * HZ;
+        do_div(t, 1000);
+        do_div(t, 1000000);
+        return (cfs_duration_t)t;
+#else
+        return (nano * HZ / ONE_BILLION);
+#endif
+}
+#endif
+
+static inline cfs_duration_t cfs_time_seconds(int seconds)
+{
+        return seconds * HZ;
+}
+
+static inline cfs_time_t cfs_time_shift(int seconds)
+{
+        return jiffies + seconds * HZ;
+}
+
+static inline time_t cfs_duration_sec(cfs_duration_t d)
+{
+        return d / HZ;
+}
+
+static inline void cfs_duration_usec(cfs_duration_t d, struct timeval *s)
+{
+#if (BITS_PER_LONG == 32)
+        uint64_t t = (d - s->tv_sec * HZ) * ONE_MILLION;
+        s->tv_usec = do_div (t, HZ);
+#else
+        s->tv_usec = (d - s->tv_sec * HZ) * ONE_MILLION / HZ;
+#endif
+        s->tv_sec = d / HZ;
+}
+
+static inline void cfs_duration_nsec(cfs_duration_t d, struct timespec *s)
+{
+#if (BITS_PER_LONG == 32)
+        uint64_t t = (d - s->tv_sec * HZ) * ONE_BILLION;
+        s->tv_nsec = do_div (t, HZ);
+#else
+        s->tv_nsec = (d - s->tv_sec * HZ) * ONE_BILLION / HZ;
+#endif
+        s->tv_sec = d / HZ;
+}
+
+static inline cfs_duration_t cfs_time_minimal_timeout(void)
+{
+        return 1;
+}
+
+/* inline function cfs_time_minimal_timeout() can not be used
+ * to initiallize static variable */
+#define CFS_MIN_DELAY           (1)
+
+#define CFS_TIME_T              "%lu"
+#define CFS_DURATION_T          "%ld"
+
+#else   /* !__KERNEL__ */
+
+/*
+ * Liblustre. time(2) based implementation.
+ */
+#include <libcfs/user-time.h>
+#endif /* __KERNEL__ */
+
+/* __LIBCFS_LINUX_LINUX_TIME_H__ */
+#endif
+/*
+ * Local variables:
+ * c-indentation-style: "K&R"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 80
+ * scroll-step: 1
+ * End:
+ */
diff --git a/lnet/include/libcfs/linux/lltrace.h b/lnet/include/libcfs/linux/lltrace.h
new file mode 100644 (file)
index 0000000..5050abc
--- /dev/null
@@ -0,0 +1,28 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __LIBCFS_LINUX_LLTRACE_H__
+#define __LIBCFS_LINUX_LLTRACE_H__
+
+#ifndef __LIBCFS_LLTRACE_H__
+#error Do not #include this file directly. #include <libcfs/lltrace.h> instead
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <portals/types.h>
+#include <libcfs/kp30.h>
+#include <portals/ptlctl.h>
+#include <linux/limits.h>
+#include <asm/page.h>
+#include <linux/version.h>
+
+#endif
similarity index 97%
rename from lnet/include/linux/portals_compat25.h
rename to lnet/include/libcfs/linux/portals_compat25.h
index fa2709e..148a401 100644 (file)
@@ -1,8 +1,8 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
-#ifndef _PORTALS_COMPAT_H
-#define _PORTALS_COMPAT_H
+#ifndef __LIBCFS_LINUX_PORTALS_COMPAT_H__
+#define __LIBCFS_LINUX_PORTALS_COMPAT_H__
 
 // XXX BUG 1511 -- remove this stanza and all callers when bug 1511 is resolved
 #if SPINLOCK_DEBUG
diff --git a/lnet/include/libcfs/linux/portals_lib.h b/lnet/include/libcfs/linux/portals_lib.h
new file mode 100644 (file)
index 0000000..99fd1bd
--- /dev/null
@@ -0,0 +1,38 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic library routines. 
+ *
+ */
+
+#ifndef __LIBCFS_LINUX_PORTALS_LIB_H__
+#define __LIBCFS_LINUX_PORTALS_LIB_H__
+
+#ifndef __LIBCFS_PORTALS_LIB_H__
+#error Do not #include this file directly. #include <libcfs/portals_lib.h> instead
+#endif
+
+#ifndef __KERNEL__
+# include <string.h>
+#else
+# include <asm/types.h>
+#endif
+
+#endif
diff --git a/lnet/include/libcfs/linux/portals_utils.h b/lnet/include/libcfs/linux/portals_utils.h
new file mode 100644 (file)
index 0000000..0dd6c7e
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef __LIBCFS_LINUX_PORTALS_UTILS_H__
+#define __LIBCFS_LINUX_PORTALS_UTILS_H__
+
+#ifndef __LIBCFS_PORTALS_UTILS_H__
+#error Do not #include this file directly. #include <libcfs/portals_utils.h> instead
+#endif
+
+#ifdef __KERNEL__
+#include <linux/proc_fs.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/wait.h>
+#include <linux/smp_lock.h>
+#include <linux/poll.h>
+#include <linux/random.h>
+                                                                                                                                                                      
+#include <asm/unistd.h>
+#include <asm/semaphore.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+# include <linux/tqueue.h>
+#else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)) */
+# include <linux/workqueue.h>
+#endif
+#include <libcfs/linux/linux-mem.h>
+#include <libcfs/linux/linux-prim.h>
+#else /* !__KERNEL__ */
+
+#include <endian.h>
+#include <libcfs/list.h>
+                                                                                                                                                                      
+#ifdef HAVE_LINUX_VERSION_H
+# include <linux/version.h>
+                                                                                                                                                                      
+# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+#  define BUG()                            /* workaround for module.h includes */
+#  include <linux/module.h>
+# endif
+#endif /* !HAVE_LINUX_VERSION_H */
+                                                                                                                                                                      
+#ifndef __CYGWIN__
+# include <syscall.h>
+#else /* __CYGWIN__ */
+# include <windows.h>
+# include <windef.h>
+# include <netinet/in.h>
+#endif /* __CYGWIN__ */
+
+#endif /* !__KERNEL__ */
+#endif
similarity index 87%
rename from lnet/include/linux/lustre_list.h
rename to lnet/include/libcfs/list.h
index a218f2c..eebb7b6 100644 (file)
@@ -1,9 +1,16 @@
-#ifndef _LUSTRE_LIST_H
-#define _LUSTRE_LIST_H
+#ifndef __LIBCFS_LIST_H__
+#define __LIBCFS_LIST_H__
+
+#if defined (__linux__) && defined(__KERNEL__)
 
-#ifdef __KERNEL__
 #include <linux/list.h>
-#else
+
+#define CFS_LIST_HEAD_INIT(n)          LIST_HEAD_INIT(n)
+#define CFS_LIST_HEAD(n)               LIST_HEAD(n)
+#define CFS_INIT_LIST_HEAD(p)          INIT_LIST_HEAD(p)
+
+#else /* !defined (__linux__) && defined(__KERNEL__) */
+
 /*
  * Simple doubly linked list implementation.
  *
@@ -22,15 +29,22 @@ struct list_head {
 
 typedef struct list_head list_t;
 
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
+#define CFS_LIST_HEAD_INIT(name) { &(name), &(name) }
 
-#define LIST_HEAD(name) \
+#define CFS_LIST_HEAD(name) \
        struct list_head name = LIST_HEAD_INIT(name)
 
-#define INIT_LIST_HEAD(ptr) do { \
+#define CFS_INIT_LIST_HEAD(ptr) do { \
        (ptr)->next = (ptr); (ptr)->prev = (ptr); \
 } while (0)
 
+#ifndef __APPLE__
+#define LIST_HEAD(n)           CFS_LIST_HEAD(n)
+#endif
+
+#define LIST_HEAD_INIT(n)      CFS_LIST_HEAD_INIT(n)
+#define INIT_LIST_HEAD(p)      CFS_INIT_LIST_HEAD(p)
+
 /*
  * Insert a new entry between two known consecutive entries.
  *
@@ -103,7 +117,7 @@ static inline void list_del(struct list_head *entry)
 static inline void list_del_init(struct list_head *entry)
 {
        __list_del(entry->prev, entry->next);
-       INIT_LIST_HEAD(entry);
+       CFS_INIT_LIST_HEAD(entry);
 }
 
 /**
@@ -175,7 +189,7 @@ static inline void list_splice_init(struct list_head *list,
 {
        if (!list_empty(list)) {
                __list_splice(list, head);
-               INIT_LIST_HEAD(list);
+               CFS_INIT_LIST_HEAD(list);
        }
 }
 
@@ -198,15 +212,6 @@ static inline void list_splice_init(struct list_head *list,
                pos = pos->next, prefetch(pos->next))
 
 /**
- * list_for_each_prev  -       iterate over a list in reverse order
- * @pos:       the &struct list_head to use as a loop counter.
- * @head:      the head for your list.
- */
-#define list_for_each_prev(pos, head) \
-       for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
-               pos = pos->prev, prefetch(pos->prev))
-
-/**
  * list_for_each_safe  -       iterate over a list safe against removal of list entry
  * @pos:       the &struct list_head to use as a loop counter.
  * @n:         another &struct list_head to use as temporary storage
@@ -216,6 +221,21 @@ static inline void list_splice_init(struct list_head *list,
        for (pos = (head)->next, n = pos->next; pos != (head); \
                pos = n, n = pos->next)
 
+#endif /* __linux__*/
+
+#ifndef list_for_each_prev
+/**
+ * list_for_each_prev  -       iterate over a list in reverse order
+ * @pos:       the &struct list_head to use as a loop counter.
+ * @head:      the head for your list.
+ */
+#define list_for_each_prev(pos, head) \
+       for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
+               pos = pos->prev, prefetch(pos->prev))
+
+#endif /* list_for_each_prev */
+
+#ifndef list_for_each_entry
 /**
  * list_for_each_entry  -       iterate over list of given type
  * @pos:        the type * to use as a loop counter.
@@ -228,7 +248,9 @@ static inline void list_splice_init(struct list_head *list,
             &pos->member != (head);                                    \
             pos = list_entry(pos->member.next, typeof(*pos), member),  \
             prefetch(pos->member.next))
+#endif /* list_for_each_entry */
 
+#ifndef list_for_each_entry_safe
 /**
  * list_for_each_entry_safe  -       iterate over list of given type safe against removal of list entry
  * @pos:        the type * to use as a loop counter.
@@ -241,6 +263,6 @@ static inline void list_splice_init(struct list_head *list,
                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 */
 
-#endif /* if !__KERNEL__*/
-#endif /* if !_LUSTRE_LIST_H */
+#endif /* __LIBCFS_LUSTRE_LIST_H__ */
similarity index 90%
rename from lnet/include/lnet/lltrace.h
rename to lnet/include/libcfs/lltrace.h
index 3e01df1..4f386c5 100644 (file)
@@ -4,25 +4,16 @@
  * Compile with:
  * cc -I../../portals/include -o fio fio.c -L../../portals/linux/utils -lptlctl
  */
-#ifndef __LTRACE_H_
-#define __LTRACE_H_
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <portals/types.h>
-#include <linux/kp30.h>
-#include <portals/ptlctl.h>
-#include <linux/limits.h>
-#include <asm/page.h>
-#include <linux/version.h>
+#ifndef __LIBCFS_LLTRACE_H__
+#define __LIBCFS_LLTRACE_H__
+
+#if defined(__linux__)
+#include <libcfs/linux/lltrace.h>
+#elif defined(__APPLE__)
+#include <libcfs/darwin/lltrace.h>
+#else
+#error Unsupported Operating System
+#endif
 
 static inline int ltrace_write_file(char* fname)
 {
similarity index 91%
rename from lnet/include/linux/portals_lib.h
rename to lnet/include/libcfs/portals_lib.h
index 8778a52..f6b12c2 100644 (file)
  *
  */
 
-#ifndef _PORTALS_LIB_H
-#define _PORTALS_LIB_H
+#ifndef __LIBCFS_PORTALS_LIB_H__
+#define __LIBCFS_PORTALS_LIB_H__
 
-#ifndef __KERNEL__
-# include <string.h>
-#else 
-# include <asm/types.h>
+#if defined(__linux__)
+#include <libcfs/linux/portals_lib.h>
+#elif defined(__APPLE__)
+#include <libcfs/darwin/portals_lib.h>
+#else
+#error Unsupported Operating System
 #endif
 
 #undef MIN
diff --git a/lnet/include/libcfs/portals_utils.h b/lnet/include/libcfs/portals_utils.h
new file mode 100644 (file)
index 0000000..932caaf
--- /dev/null
@@ -0,0 +1,19 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __LIBCFS_PORTALS_UTILS_H__
+#define __LIBCFS_PORTALS_UTILS_H__
+
+/*
+ * portals_utils.h
+ *
+ */
+#if defined(__linux__)
+#include <libcfs/linux/portals_utils.h>
+#elif defined(__APPLE__)
+#include <libcfs/darwin/portals_utils.h>
+#else
+#error Unsupported Operating System
+#endif
+
+#endif
diff --git a/lnet/include/libcfs/user-lock.h b/lnet/include/libcfs/user-lock.h
new file mode 100644 (file)
index 0000000..e57200f
--- /dev/null
@@ -0,0 +1,171 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Copyright (C) 2004 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of Lustre, http://www.lustre.org.
+ *
+ * Lustre is free software; you can redistribute it and/or modify it under the
+ * terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * Lustre 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 for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
+ * Ave, Cambridge, MA 02139, USA.
+ *
+ * Implementation of portable time API for user-level.
+ *
+ */
+
+#ifndef __LIBCFS_USER_LOCK_H__
+#define __LIBCFS_USER_LOCK_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+/* Implementations of portable synchronization APIs for liblustre */
+
+/*
+ * liblustre is single-threaded, so most "synchronization" APIs are trivial.
+ */
+
+#ifndef __KERNEL__
+
+/*
+ * Optional debugging (magic stamping and checking ownership) can be added.
+ */
+
+/*
+ * spin_lock
+ *
+ * - spin_lock_init(x)
+ * - spin_lock(x)
+ * - spin_unlock(x)
+ * - spin_trylock(x)
+ *
+ * - spin_lock_irqsave(x, f)
+ * - spin_unlock_irqrestore(x, f)
+ *
+ * No-op implementation.
+ */
+struct spin_lock {};
+
+typedef struct spin_lock spinlock_t;
+
+void spin_lock_init(spinlock_t *lock);
+void spin_lock(spinlock_t *lock);
+void spin_unlock(spinlock_t *lock);
+int spin_trylock(spinlock_t *lock);
+void spin_lock_bh_init(spinlock_t *lock);
+void spin_lock_bh(spinlock_t *lock);
+void spin_unlock_bh(spinlock_t *lock);
+
+#define spin_lock_irqsave(l, flags) ({ spin_lock(l); (void)flags; })
+#define spin_unlock_irqrestore(l, flags)  ({ spin_unlock(l); (void)flags; })
+
+/*
+ * Semaphore
+ *
+ * - sema_init(x, v)
+ * - __down(x)
+ * - __up(x)
+ */
+struct semaphore {};
+
+void sema_init(struct semaphore *s, int val);
+void __down(struct semaphore *s);
+void __up(struct semaphore *s);
+
+/*
+ * Mutex:
+ *
+ * - init_mutex(x)
+ * - init_mutex_locked(x)
+ * - mutex_up(x)
+ * - mutex_down(x)
+ */
+#define mutex_up(s)                    __up(s)
+#define mutex_down(s)                  __down(s)
+
+#define init_mutex(x)                  sema_init(x, 1)
+#define init_mutex_locked(x)           sema_init(x, 0)
+
+/*
+ * Completion:
+ *
+ * - init_completion(c)
+ * - complete(c)
+ * - wait_for_completion(c)
+ */
+struct completion {};
+
+void init_completion(struct completion *c);
+void complete(struct completion *c);
+void wait_for_completion(struct completion *c);
+
+/*
+ * rw_semaphore:
+ *
+ * - init_rwsem(x)
+ * - down_read(x)
+ * - up_read(x)
+ * - down_write(x)
+ * - up_write(x)
+ */
+struct rw_semaphore {};
+
+void init_rwsem(struct rw_semaphore *s);
+void down_read(struct rw_semaphore *s);
+int down_read_trylock(struct rw_semaphore *s);
+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);
+
+/*
+ * read-write lock : Need to be investigated more!!
+ * XXX nikita: for now, let rwlock_t to be identical to rw_semaphore
+ *
+ * - DECLARE_RWLOCK(l)
+ * - rwlock_init(x)
+ * - read_lock(x)
+ * - read_unlock(x)
+ * - write_lock(x)
+ * - write_unlock(x)
+ */
+typedef struct rw_semaphore rwlock_t;
+
+#define rwlock_init(pl)                init_rwsem(pl)
+
+#define read_lock(l)           down_read(l)
+#define read_unlock(l)         up_read(l)
+#define write_lock(l)          down_write(l)
+#define write_unlock(l)                up_write(l)
+
+#define write_lock_irqsave(l, f)       write_lock(l)
+#define write_unlock_irqrestore(l, f)  write_unlock(l)
+
+#define read_lock_irqsave(l, f)                read_lock(l)
+#define read_unlock_irqrestore(l, f)   read_unlock(l)
+
+/* !__KERNEL__ */
+#endif
+
+/* __LIBCFS_USER_LOCK_H__ */
+#endif
+/*
+ * Local variables:
+ * c-indentation-style: "K&R"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 80
+ * scroll-step: 1
+ * End:
+ */
diff --git a/lnet/include/libcfs/user-prim.h b/lnet/include/libcfs/user-prim.h
new file mode 100644 (file)
index 0000000..6c3410b
--- /dev/null
@@ -0,0 +1,182 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Copyright (C) 2004 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of Lustre, http://www.lustre.org.
+ *
+ * Lustre is free software; you can redistribute it and/or modify it under the
+ * terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * Lustre 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 for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
+ * Ave, Cambridge, MA 02139, USA.
+ *
+ * Implementation of portable time API for user-level.
+ *
+ */
+
+#ifndef __LIBCFS_USER_PRIM_H__
+#define __LIBCFS_USER_PRIM_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+/* Implementations of portable APIs for liblustre */
+
+/*
+ * liblustre is single-threaded, so most "synchronization" APIs are trivial.
+ */
+
+#ifndef __KERNEL__
+
+#include <libcfs/list.h>
+
+/*
+ * Wait Queue. No-op implementation.
+ */
+
+typedef struct cfs_waitlink {} cfs_waitlink_t;
+typedef struct cfs_waitq {} cfs_waitq_t;
+
+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_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq);
+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);
+int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, int64_t timeout);
+
+/*
+ * Allocator
+ */
+
+/* 2.4 defines */
+
+/* XXX
+ * for this moment, liblusre will not rely OST for non-page-aligned write
+ */
+#define LIBLUSTRE_HANDLE_UNALIGNED_PAGE
+
+struct page {
+        void   *addr;
+        unsigned long index;
+        struct list_head list;
+        unsigned long private;
+
+        /* internally used by liblustre file i/o */
+        int     _offset;
+        int     _count;
+#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
+        int     _managed;
+#endif
+};
+
+typedef struct page cfs_page_t;
+
+#define CFS_PAGE_SIZE                   PAGE_CACHE_SIZE
+#define CFS_PAGE_SHIFT                  PAGE_CACHE_SHIFT
+#define CFS_PAGE_MASK                   PAGE_CACHE_MASK
+
+cfs_page_t *cfs_alloc_pages(unsigned int flags, unsigned int order);
+void cfs_free_pages(struct page *pg, int what);
+
+cfs_page_t *cfs_alloc_page(unsigned int flags);
+void cfs_free_page(cfs_page_t *pg, int what);
+void *cfs_page_address(cfs_page_t *pg);
+void *cfs_kmap(cfs_page_t *pg);
+void cfs_kunmap(cfs_page_t *pg);
+
+#define cfs_get_page(p)                        __I_should_not_be_called__(at_all)
+#define cfs_page_count(p)              __I_should_not_be_called__(at_all)
+#define cfs_set_page_count(p, v)       __I_should_not_be_called__(at_all)
+
+/*
+ * Memory allocator
+ */
+void *cfs_alloc(size_t nr_bytes, u_int32_t flags);
+void cfs_free(void *addr);
+void *cfs_alloc_large(size_t nr_bytes);
+void  cfs_free_large(void *addr);
+
+/*
+ * SLAB allocator
+ */
+typedef struct {
+         int size;
+} cfs_mem_cache_t;
+
+#define SLAB_HWCACHE_ALIGN 0
+
+cfs_mem_cache_t *
+cfs_mem_cache_create(const char *, size_t, size_t, unsigned long,
+                     void (*)(void *, cfs_mem_cache_t *, unsigned long),
+                     void (*)(void *, cfs_mem_cache_t *, unsigned long));
+int cfs_mem_cache_destroy(cfs_mem_cache_t *c);
+void *cfs_mem_cache_alloc(cfs_mem_cache_t *c, int gfp);
+void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr);
+
+typedef int (cfs_read_proc_t)(char *page, char **start, off_t off,
+                          int count, int *eof, void *data);
+
+struct file; /* forward ref */
+typedef int (cfs_write_proc_t)(struct file *file, const char *buffer,
+                               unsigned long count, void *data);
+
+/*
+ * Timer
+ */
+
+typedef struct cfs_timer {} cfs_timer_t;
+
+#if 0
+#define cfs_init_timer(t)      do {} while(0)
+void cfs_timer_init(struct cfs_timer *t, void (*func)(unsigned long), void *arg);
+void cfs_timer_done(struct cfs_timer *t);
+void cfs_timer_arm(struct cfs_timer *t, cfs_time_t deadline);
+void cfs_timer_disarm(struct cfs_timer *t);
+int  cfs_timer_is_armed(struct cfs_timer *t);
+
+cfs_time_t cfs_timer_deadline(struct cfs_timer *t);
+#endif
+
+typedef void cfs_psdev_t;
+
+static inline int cfs_psdev_register(cfs_psdev_t *foo)
+{
+        return 0;
+}
+
+static inline int cfs_psdev_deregister(cfs_psdev_t *foo)
+{
+        return 0;
+}
+
+/* !__KERNEL__ */
+#endif
+
+/* __LIBCFS_USER_PRIM_H__ */
+#endif
+/*
+ * Local variables:
+ * c-indentation-style: "K&R"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 80
+ * scroll-step: 1
+ * End:
+ */
diff --git a/lnet/include/libcfs/user-time.h b/lnet/include/libcfs/user-time.h
new file mode 100644 (file)
index 0000000..7abc9e8
--- /dev/null
@@ -0,0 +1,198 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Copyright (C) 2004 Cluster File Systems, Inc.
+ * Author: Nikita Danilov <nikita@clusterfs.com>
+ *
+ * This file is part of Lustre, http://www.lustre.org.
+ *
+ * Lustre is free software; you can redistribute it and/or modify it under the
+ * terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * Lustre 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 for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
+ * Ave, Cambridge, MA 02139, USA.
+ *
+ * Implementation of portable time API for user-level.
+ *
+ */
+
+#ifndef __LIBCFS_USER_TIME_H__
+#define __LIBCFS_USER_TIME_H__
+
+#ifndef __LIBCFS_LIBCFS_H__
+#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
+#endif
+
+/* Portable time API */
+
+/*
+ * Platform provides three opaque data-types:
+ *
+ *  cfs_time_t        represents point in time. This is internal kernel
+ *                    time rather than "wall clock". This time bears no
+ *                    relation to gettimeofday().
+ *
+ *  cfs_duration_t    represents time interval with resolution of internal
+ *                    platform clock
+ *
+ *  cfs_fs_time_t     represents instance in world-visible time. This is
+ *                    used in file-system time-stamps
+ *
+ *  cfs_time_t     cfs_time_current(void);
+ *  cfs_time_t     cfs_time_add    (cfs_time_t, cfs_duration_t);
+ *  cfs_duration_t cfs_time_sub    (cfs_time_t, cfs_time_t);
+ *  int            cfs_time_before (cfs_time_t, cfs_time_t);
+ *  int            cfs_time_beforeq(cfs_time_t, cfs_time_t);
+ *
+ *  cfs_duration_t cfs_duration_build(int64_t);
+ *
+ *  time_t         cfs_duration_sec (cfs_duration_t);
+ *  void           cfs_duration_usec(cfs_duration_t, struct timeval *);
+ *  void           cfs_duration_nsec(cfs_duration_t, struct timespec *);
+ *
+ *  void           cfs_fs_time_current(cfs_fs_time_t *);
+ *  time_t         cfs_fs_time_sec    (cfs_fs_time_t *);
+ *  void           cfs_fs_time_usec   (cfs_fs_time_t *, struct timeval *);
+ *  void           cfs_fs_time_nsec   (cfs_fs_time_t *, struct timespec *);
+ *  int            cfs_fs_time_before (cfs_fs_time_t *, cfs_fs_time_t *);
+ *  int            cfs_fs_time_beforeq(cfs_fs_time_t *, cfs_fs_time_t *);
+ *
+ *  cfs_duration_t cfs_time_minimal_timeout(void)
+ *
+ *  CFS_TIME_FORMAT
+ *  CFS_DURATION_FORMAT
+ *
+ */
+
+#define ONE_BILLION ((u_int64_t)1000000000)
+#define ONE_MILLION ((u_int64_t)   1000000)
+
+#ifndef __KERNEL__
+
+/*
+ * Liblustre. time(2) based implementation.
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+typedef time_t cfs_fs_time_t;
+typedef time_t cfs_time_t;
+typedef long cfs_duration_t;
+
+static inline cfs_time_t cfs_time_current(void)
+{
+        return time(NULL);
+}
+
+static inline cfs_duration_t cfs_time_seconds(int seconds)
+{
+        return seconds;
+}
+
+static inline int cfs_time_before(cfs_time_t t1, cfs_time_t t2)
+{
+        return t1 < t2;
+}
+
+static inline int cfs_time_beforeq(cfs_time_t t1, cfs_time_t t2)
+{
+        return t1 <= t2;
+}
+
+static inline cfs_duration_t cfs_duration_build(int64_t nano)
+{
+        return nano / ONE_BILLION;
+}
+
+static inline time_t cfs_duration_sec(cfs_duration_t d)
+{
+        return d;
+}
+
+static inline void cfs_duration_usec(cfs_duration_t d, struct timeval *s)
+{
+        s->tv_sec = d;
+        s->tv_usec = 0;
+}
+
+static inline void cfs_duration_nsec(cfs_duration_t d, struct timespec *s)
+{
+        s->tv_sec = d;
+        s->tv_nsec = 0;
+}
+
+static inline void cfs_fs_time_current(cfs_fs_time_t *t)
+{
+        time(t);
+}
+
+static inline time_t cfs_fs_time_sec(cfs_fs_time_t *t)
+{
+        return *t;
+}
+
+static inline void cfs_fs_time_usec(cfs_fs_time_t *t, struct timeval *v)
+{
+        v->tv_sec = *t;
+        v->tv_usec = 0;
+}
+
+static inline void cfs_fs_time_nsec(cfs_fs_time_t *t, struct timespec *s)
+{
+        s->tv_sec = *t;
+        s->tv_nsec = 0;
+}
+
+static inline int cfs_fs_time_before(cfs_fs_time_t *t1, cfs_fs_time_t *t2)
+{
+        return *t1 < *t2;
+}
+
+static inline int cfs_fs_time_beforeq(cfs_fs_time_t *t1, cfs_fs_time_t *t2)
+{
+        return *t1 <= *t2;
+}
+
+static inline cfs_duration_t cfs_time_minimal_timeout(void)
+{
+        return 1;
+}
+
+#define CFS_MIN_DELAY           (1)
+
+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;
+}
+
+#define CFS_TIME_T              "%lu"
+#define CFS_DURATION_T          "%ld"
+
+/* !__KERNEL__ */
+#endif
+
+/* __LIBCFS_USER_TIME_H__ */
+#endif
+/*
+ * Local variables:
+ * c-indentation-style: "K&R"
+ * c-basic-offset: 8
+ * tab-width: 8
+ * fill-column: 80
+ * scroll-step: 1
+ * End:
+ */
diff --git a/lnet/include/linux/Makefile.am b/lnet/include/linux/Makefile.am
deleted file mode 100644 (file)
index 3c28c6e..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-linuxdir = $(includedir)/linux
-
-EXTRA_DIST = kp30.h kpr.h libcfs.h lustre_list.h portals_compat25.h    \
-       portals_lib.h
index 4043f66..55cd240 100644 (file)
@@ -1,10 +1,8 @@
 portalsdir=$(includedir)/portals
 
-if UTILS
-portals_HEADERS = list.h
-endif
+SUBDIRS := darwin linux
 
-EXTRA_DIST = api.h api-support.h build_check.h errno.h \
-       internal.h lib-p30.h lib-types.h list.h                  \
-       lltrace.h myrnal.h nal.h nalids.h p30.h ptlctl.h         \
+EXTRA_DIST = api.h api-support.h build_check.h errno.h         \
+       internal.h kpr.h lib-p30.h lib-types.h                  \
+       myrnal.h nal.h nalids.h p30.h ptlctl.h  \
        socknal.h stringtab.h types.h
index c5994c6..848cf40 100644 (file)
@@ -1,4 +1,5 @@
-
+#ifndef __API_SUPPORT_H__
+#define __API_SUPPORT_H__
 #include "build_check.h"
 
 #ifndef __KERNEL__
 #endif
 
 #include <portals/types.h>
-#include <linux/kp30.h>
+#include <libcfs/kp30.h>
 #include <portals/p30.h>
 
 #include <portals/internal.h>
 #include <portals/nal.h>
 
+#endif
diff --git a/lnet/include/lnet/darwin/Makefile.am b/lnet/include/lnet/darwin/Makefile.am
new file mode 100644 (file)
index 0000000..b6e7daf
--- /dev/null
@@ -0,0 +1 @@
+EXTRA_DIST := lib-p30.h  lib-types.h  p30.h
diff --git a/lnet/include/lnet/darwin/lib-lnet.h b/lnet/include/lnet/darwin/lib-lnet.h
new file mode 100644 (file)
index 0000000..d3b1ba9
--- /dev/null
@@ -0,0 +1,14 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_DARWIN_LIB_P30_H__
+#define __PORTALS_DARWIN_LIB_P30_H__
+
+#ifndef __PORTALS_LIB_P30_H__
+#error Do not #include this file directly. #include <portals/lib-p30.h> instead
+#endif
+
+#include <string.h>
+#include <libcfs/libcfs.h>
+
+#endif
diff --git a/lnet/include/lnet/darwin/lib-p30.h b/lnet/include/lnet/darwin/lib-p30.h
new file mode 100644 (file)
index 0000000..d3b1ba9
--- /dev/null
@@ -0,0 +1,14 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_DARWIN_LIB_P30_H__
+#define __PORTALS_DARWIN_LIB_P30_H__
+
+#ifndef __PORTALS_LIB_P30_H__
+#error Do not #include this file directly. #include <portals/lib-p30.h> instead
+#endif
+
+#include <string.h>
+#include <libcfs/libcfs.h>
+
+#endif
diff --git a/lnet/include/lnet/darwin/lib-types.h b/lnet/include/lnet/darwin/lib-types.h
new file mode 100644 (file)
index 0000000..744e566
--- /dev/null
@@ -0,0 +1,15 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_DARWIN_LIB_TYPES_H__
+#define __PORTALS_DARWIN_LIB_TYPES_H__
+
+#ifndef __PORTALS_LIB_TYPES_H__
+#error Do not #include this file directly. #include <portals/lib-types.h> instead
+#endif
+
+#include <sys/types.h>
+#include <libcfs/libcfs.h>
+#include <libcfs/list.h>
+
+#endif
diff --git a/lnet/include/lnet/darwin/lnet.h b/lnet/include/lnet/darwin/lnet.h
new file mode 100644 (file)
index 0000000..e619fa7
--- /dev/null
@@ -0,0 +1,20 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef _PORTALS_DARWIN_P30_H_
+#define _PORTALS_DARWIN_P30_H_
+
+#ifndef __PORTALS_P30_H__
+#error Do not #include this file directly. #include <portals/p30.h> instead
+#endif
+
+/*
+ * p30.h
+ *
+ * User application interface file
+ */
+
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#endif
diff --git a/lnet/include/lnet/darwin/p30.h b/lnet/include/lnet/darwin/p30.h
new file mode 100644 (file)
index 0000000..e619fa7
--- /dev/null
@@ -0,0 +1,20 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef _PORTALS_DARWIN_P30_H_
+#define _PORTALS_DARWIN_P30_H_
+
+#ifndef __PORTALS_P30_H__
+#error Do not #include this file directly. #include <portals/p30.h> instead
+#endif
+
+/*
+ * p30.h
+ *
+ * User application interface file
+ */
+
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#endif
similarity index 99%
rename from lnet/include/linux/kpr.h
rename to lnet/include/lnet/kpr.h
index 1127698..23d6e7c 100644 (file)
@@ -1,8 +1,8 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
-#ifndef _KPR_H
-#define _KPR_H
+#ifndef __PORTALS_KPR_H__
+#define __PORTALS_KPR_H__
 
 # include <portals/lib-types.h> /* for ptl_hdr_t */
 
index b710569..a407379 100644 (file)
@@ -6,21 +6,21 @@
  * Top level include for library side routines
  */
 
-#ifndef _LIB_P30_H_
-#define _LIB_P30_H_
+#ifndef __PORTALS_LIB_P30_H__
+#define __PORTALS_LIB_P30_H__
 
 #include "build_check.h"
 
-#ifdef __KERNEL__
-# include <asm/page.h>
-# include <linux/string.h>
+#if defined(__linux__)
+#include <portals/linux/lib-p30.h>
+#elif defined(__APPLE__)
+#include <portals/darwin/lib-p30.h>
 #else
-# include <portals/list.h>
-# include <string.h>
-# include <pthread.h>
+#error Unsupported Operating System
 #endif
+
 #include <portals/types.h>
-#include <linux/kp30.h>
+#include <libcfs/kp30.h>
 #include <portals/p30.h>
 #include <portals/nal.h>
 #include <portals/lib-types.h>
index b710569..a407379 100644 (file)
@@ -6,21 +6,21 @@
  * Top level include for library side routines
  */
 
-#ifndef _LIB_P30_H_
-#define _LIB_P30_H_
+#ifndef __PORTALS_LIB_P30_H__
+#define __PORTALS_LIB_P30_H__
 
 #include "build_check.h"
 
-#ifdef __KERNEL__
-# include <asm/page.h>
-# include <linux/string.h>
+#if defined(__linux__)
+#include <portals/linux/lib-p30.h>
+#elif defined(__APPLE__)
+#include <portals/darwin/lib-p30.h>
 #else
-# include <portals/list.h>
-# include <string.h>
-# include <pthread.h>
+#error Unsupported Operating System
 #endif
+
 #include <portals/types.h>
-#include <linux/kp30.h>
+#include <libcfs/kp30.h>
 #include <portals/p30.h>
 #include <portals/nal.h>
 #include <portals/lib-types.h>
index cfcef2b..1ac2c56 100644 (file)
@@ -7,22 +7,24 @@
  * exposed to the user application
  */
 
-#ifndef _LIB_TYPES_H_
-#define _LIB_TYPES_H_
+#ifndef __PORTALS_LIB_TYPES_H__
+#define __PORTALS_LIB_TYPES_H__
 
 #include "build_check.h"
 
-#include <portals/types.h>
-#include <portals/nal.h>
-#ifdef __KERNEL__
-# include <linux/uio.h>
-# include <linux/smp_lock.h>
-# include <linux/types.h>
+#if defined(__linux__)
+#include <portals/linux/lib-types.h>
+#elif defined(__APPLE__)
+#include <portals/darwin/lib-types.h>
 #else
-# define PTL_USE_LIB_FREELIST
-# include <sys/types.h>
+#error Unsupported Operating System
 #endif
 
+#include <libcfs/libcfs.h>
+#include <libcfs/list.h>
+#include <portals/types.h>
+#include <portals/nal.h>
+
 typedef char *user_ptr;
 typedef struct lib_msg_t lib_msg_t;
 typedef struct lib_ptl_t lib_ptl_t;
@@ -271,7 +273,7 @@ typedef struct lib_ni
 
 #ifdef __KERNEL__
         spinlock_t        ni_lock;
-        wait_queue_head_t ni_waitq;
+        cfs_waitq_t       ni_waitq;
 #else
         pthread_mutex_t   ni_mutex;
         pthread_cond_t    ni_cond;
diff --git a/lnet/include/lnet/linux/.cvsignore b/lnet/include/lnet/linux/.cvsignore
new file mode 100644 (file)
index 0000000..3dda729
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
diff --git a/lnet/include/lnet/linux/Makefile.am b/lnet/include/lnet/linux/Makefile.am
new file mode 100644 (file)
index 0000000..b6e7daf
--- /dev/null
@@ -0,0 +1 @@
+EXTRA_DIST := lib-p30.h  lib-types.h  p30.h
diff --git a/lnet/include/lnet/linux/lib-lnet.h b/lnet/include/lnet/linux/lib-lnet.h
new file mode 100644 (file)
index 0000000..1c88080
--- /dev/null
@@ -0,0 +1,20 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_LINUX_LIB_P30_H__
+#define __PORTALS_LINUX_LIB_P30_H__
+
+#ifndef __PORTALS_LIB_P30_H__
+#error Do not #include this file directly. #include <portals/lib-p30.h> instead
+#endif
+
+#ifdef __KERNEL__
+# include <asm/page.h>
+# include <linux/string.h>
+#else
+# include <libcfs/list.h>
+# include <string.h>
+# include <pthread.h>
+#endif
+
+#endif
diff --git a/lnet/include/lnet/linux/lib-p30.h b/lnet/include/lnet/linux/lib-p30.h
new file mode 100644 (file)
index 0000000..1c88080
--- /dev/null
@@ -0,0 +1,20 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_LINUX_LIB_P30_H__
+#define __PORTALS_LINUX_LIB_P30_H__
+
+#ifndef __PORTALS_LIB_P30_H__
+#error Do not #include this file directly. #include <portals/lib-p30.h> instead
+#endif
+
+#ifdef __KERNEL__
+# include <asm/page.h>
+# include <linux/string.h>
+#else
+# include <libcfs/list.h>
+# include <string.h>
+# include <pthread.h>
+#endif
+
+#endif
diff --git a/lnet/include/lnet/linux/lib-types.h b/lnet/include/lnet/linux/lib-types.h
new file mode 100644 (file)
index 0000000..f896b4b
--- /dev/null
@@ -0,0 +1,20 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_LINUX_LIB_TYPES_H__
+#define __PORTALS_LINUX_LIB_TYPES_H__
+
+#ifndef __PORTALS_LIB_TYPES_H__
+#error Do not #include this file directly. #include <portals/lib-types.h> instead
+#endif
+
+#ifdef __KERNEL__
+# include <linux/uio.h>
+# include <linux/smp_lock.h>
+# include <linux/types.h>
+#else
+# define PTL_USE_LIB_FREELIST
+# include <sys/types.h>
+#endif
+
+#endif
diff --git a/lnet/include/lnet/linux/lnet.h b/lnet/include/lnet/linux/lnet.h
new file mode 100644 (file)
index 0000000..b074837
--- /dev/null
@@ -0,0 +1,25 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_LINUX_P30_H__
+#define __PORTALS_LINUX_P30_H__
+
+#ifndef __PORTALS_P30_H__
+#error Do not #include this file directly. #include <portals/p30.h> instead
+#endif
+
+/*
+ * p30.h
+ *
+ * User application interface file
+ */
+
+#if defined (__KERNEL__)
+#include <linux/uio.h>
+#include <linux/types.h>
+#else
+#include <sys/types.h>
+#include <sys/uio.h>
+#endif
+
+#endif
diff --git a/lnet/include/lnet/linux/p30.h b/lnet/include/lnet/linux/p30.h
new file mode 100644 (file)
index 0000000..b074837
--- /dev/null
@@ -0,0 +1,25 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+#ifndef __PORTALS_LINUX_P30_H__
+#define __PORTALS_LINUX_P30_H__
+
+#ifndef __PORTALS_P30_H__
+#error Do not #include this file directly. #include <portals/p30.h> instead
+#endif
+
+/*
+ * p30.h
+ *
+ * User application interface file
+ */
+
+#if defined (__KERNEL__)
+#include <linux/uio.h>
+#include <linux/types.h>
+#else
+#include <sys/types.h>
+#include <sys/uio.h>
+#endif
+
+#endif
diff --git a/lnet/include/lnet/list.h b/lnet/include/lnet/list.h
deleted file mode 100644 (file)
index 37d9952..0000000
+++ /dev/null
@@ -1,243 +0,0 @@
-#ifndef _LINUX_LIST_H
-/*
- * Simple doubly linked list implementation.
- *
- * Some of the internal functions ("__xxx") are useful when
- * manipulating whole lists rather than single entries, as
- * sometimes we already know the next/prev entries and we can
- * generate better code by using them directly rather than
- * using the generic single-entry routines.
- */
-
-struct list_head {
-       struct list_head *next, *prev;
-};
-
-typedef struct list_head list_t;
-
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
-
-#define LIST_HEAD(name) \
-       struct list_head name = LIST_HEAD_INIT(name)
-
-#define INIT_LIST_HEAD(ptr) do { \
-       (ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
-
-/*
- * Insert a new entry between two known consecutive entries.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_add(struct list_head * new,
-                             struct list_head * prev,
-                             struct list_head * next)
-{
-       next->prev = new;
-       new->next = next;
-       new->prev = prev;
-       prev->next = new;
-}
-
-/**
- * list_add - add a new entry
- * @new: new entry to be added
- * @head: list head to add it after
- *
- * Insert a new entry after the specified head.
- * This is good for implementing stacks.
- */
-static inline void list_add(struct list_head *new, struct list_head *head)
-{
-       __list_add(new, head, head->next);
-}
-
-/**
- * list_add_tail - add a new entry
- * @new: new entry to be added
- * @head: list head to add it before
- *
- * Insert a new entry before the specified head.
- * This is useful for implementing queues.
- */
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
-{
-       __list_add(new, head->prev, head);
-}
-
-/*
- * Delete a list entry by making the prev/next entries
- * point to each other.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_del(struct list_head * prev, struct list_head * next)
-{
-       next->prev = prev;
-       prev->next = next;
-}
-
-/**
- * list_del - deletes entry from list.
- * @entry: the element to delete from the list.
- * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
- */
-static inline void list_del(struct list_head *entry)
-{
-       __list_del(entry->prev, entry->next);
-}
-
-/**
- * list_del_init - deletes entry from list and reinitialize it.
- * @entry: the element to delete from the list.
- */
-static inline void list_del_init(struct list_head *entry)
-{
-       __list_del(entry->prev, entry->next);
-       INIT_LIST_HEAD(entry);
-}
-#endif
-
-#ifndef list_for_each_entry
-/**
- * list_move - delete from one list and add as another's head
- * @list: the entry to move
- * @head: the head that will precede our entry
- */
-static inline void list_move(struct list_head *list, struct list_head *head)
-{
-       __list_del(list->prev, list->next);
-       list_add(list, head);
-}
-
-/**
- * list_move_tail - delete from one list and add as another's tail
- * @list: the entry to move
- * @head: the head that will follow our entry
- */
-static inline void list_move_tail(struct list_head *list,
-                                 struct list_head *head)
-{
-       __list_del(list->prev, list->next);
-       list_add_tail(list, head);
-}
-#endif
-
-#ifndef _LINUX_LIST_H
-#define _LINUX_LIST_H
-/**
- * list_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static inline int list_empty(struct list_head *head)
-{
-       return head->next == head;
-}
-
-static inline void __list_splice(struct list_head *list,
-                                struct list_head *head)
-{
-       struct list_head *first = list->next;
-       struct list_head *last = list->prev;
-       struct list_head *at = head->next;
-
-       first->prev = head;
-       head->next = first;
-
-       last->next = at;
-       at->prev = last;
-}
-
-/**
- * list_splice - join two lists
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- */
-static inline void list_splice(struct list_head *list, struct list_head *head)
-{
-       if (!list_empty(list))
-               __list_splice(list, head);
-}
-
-/**
- * list_splice_init - join two lists and reinitialise the emptied list.
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- *
- * The list at @list is reinitialised
- */
-static inline void list_splice_init(struct list_head *list,
-                                   struct list_head *head)
-{
-       if (!list_empty(list)) {
-               __list_splice(list, head);
-               INIT_LIST_HEAD(list);
-       }
-}
-
-/**
- * list_entry - get the struct for this entry
- * @ptr:       the &struct list_head pointer.
- * @type:      the type of the struct this is embedded in.
- * @member:    the name of the list_struct within the struct.
- */
-#define list_entry(ptr, type, member) \
-       ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
-
-/**
- * list_for_each       -       iterate over a list
- * @pos:       the &struct list_head to use as a loop counter.
- * @head:      the head for your list.
- */
-#define list_for_each(pos, head) \
-       for (pos = (head)->next ; pos != (head); pos = pos->next )
-
-/**
- * list_for_each_prev  -       iterate over a list in reverse order
- * @pos:       the &struct list_head to use as a loop counter.
- * @head:      the head for your list.
- */
-#define list_for_each_prev(pos, head) \
-       for (pos = (head)->prev ; pos != (head); pos = pos->prev)
-
-/**
- * list_for_each_safe  -       iterate over a list safe against removal of list entry
- * @pos:       the &struct list_head to use as a loop counter.
- * @n:         another &struct list_head to use as temporary storage
- * @head:      the head for your list.
- */
-#define list_for_each_safe(pos, n, head) \
-       for (pos = (head)->next, n = pos->next; pos != (head); \
-               pos = n, n = pos->next)
-
-#endif
-
-#ifndef list_for_each_entry
-/**
- * list_for_each_entry  -       iterate over list of given type
- * @pos:        the type * to use as a loop counter.
- * @head:       the head for your list.
- * @member:     the name of the list_struct within the struct.
- */
-#define list_for_each_entry(pos, head, member)                         \
-        for (pos = list_entry((head)->next, typeof(*pos), member);     \
-            &pos->member != (head);                                    \
-            pos = list_entry(pos->member.next, typeof(*pos), member))
-#endif
-
-#ifndef list_for_each_entry_safe
-/**
- * list_for_each_entry_safe  -       iterate over list of given type safe against removal of list entry
- * @pos:        the type * to use as a loop counter.
- * @n:          another type * to use as temporary storage
- * @head:       the head for your list.
- * @member:     the name of the list_struct within the struct.
- */
-#define list_for_each_entry_safe(pos, n, head, member)                 \
-        for (pos = list_entry((head)->next, typeof(*pos), member),     \
-               n = list_entry(pos->member.next, typeof(*pos), member); \
-            &pos->member != (head);                                    \
-            pos = n, n = list_entry(n->member.next, typeof(*n), member))
-#endif
index 4b8631d..9be79b8 100644 (file)
@@ -1,8 +1,8 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
-#ifndef _P30_H_
-#define _P30_H_
+#ifndef __PORTALS_P30_H__
+#define __PORTALS_P30_H__
 
 #include "build_check.h"
 
  *
  * User application interface file
  */
-
-#if defined (__KERNEL__)
-#include <linux/uio.h>
-#include <linux/types.h>
+#if defined(__linux__)
+#include <portals/linux/p30.h>
+#elif defined(__APPLE__)
+#include <portals/darwin/p30.h>
 #else
-#include <sys/types.h>
-#include <sys/uio.h>
+#error Unsupported Operating System
 #endif
 
 #include <portals/types.h>
index 6a7df9a..99da747 100644 (file)
@@ -22,8 +22,8 @@
 #define _PTLCTL_H_
 
 #include <portals/types.h>
-#include <linux/kp30.h>
-#include <linux/libcfs.h>
+#include <libcfs/kp30.h>
+#include <libcfs/libcfs.h>
 
 #define PORTALS_DEV_ID 0
 #define PORTALS_DEV_PATH "/dev/portals"
index 4b8631d..9be79b8 100644 (file)
@@ -1,8 +1,8 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
-#ifndef _P30_H_
-#define _P30_H_
+#ifndef __PORTALS_P30_H__
+#define __PORTALS_P30_H__
 
 #include "build_check.h"
 
  *
  * User application interface file
  */
-
-#if defined (__KERNEL__)
-#include <linux/uio.h>
-#include <linux/types.h>
+#if defined(__linux__)
+#include <portals/linux/p30.h>
+#elif defined(__APPLE__)
+#include <portals/darwin/p30.h>
 #else
-#include <sys/types.h>
-#include <sys/uio.h>
+#error Unsupported Operating System
 #endif
 
 #include <portals/types.h>
index 6a7df9a..99da747 100644 (file)
@@ -22,8 +22,8 @@
 #define _PTLCTL_H_
 
 #include <portals/types.h>
-#include <linux/kp30.h>
-#include <linux/libcfs.h>
+#include <libcfs/kp30.h>
+#include <libcfs/libcfs.h>
 
 #define PORTALS_DEV_ID 0
 #define PORTALS_DEV_PATH "/dev/portals"
index 0bada40..6b31187 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "build_check.h"
 
-#include <linux/libcfs.h>
+#include <libcfs/libcfs.h>
 #include <portals/errno.h>
 
 /* This implementation uses the same type for API function return codes and
@@ -95,7 +95,7 @@ typedef struct {
 typedef struct iovec ptl_md_iovec_t;
 
 typedef struct {
-       struct page     *kiov_page;
+       cfs_page_t      *kiov_page;
        unsigned int     kiov_len;
        unsigned int     kiov_offset;
 } ptl_kiov_t;
index f45eab7..a3492f4 100644 (file)
@@ -52,7 +52,7 @@
 #include "portals/nal.h"
 #include "portals/api.h"
 #include "portals/errno.h"
-#include "linux/kp30.h"
+#include "libcfs/kp30.h"
 #include "portals/p30.h"
 
 #include "portals/nal.h"
index 4f04542..82cdd3c 100644 (file)
@@ -50,7 +50,7 @@
 
 #define DEBUG_SUBSYSTEM S_NAL
 
-#include <linux/kp30.h>
+#include <libcfs/kp30.h>
 #include <portals/p30.h>
 #include <portals/lib-p30.h>
 #include <portals/nal.h>
 /* XXX I have no idea. */
 #define IBNAL_STARTING_PSN 1
 
-typedef struct 
+typedef struct
 {
         int               kib_io_timeout;       /* comms timeout (seconds) */
         struct ctl_table_header *kib_sysctl;    /* sysctl interface */
@@ -163,8 +163,8 @@ typedef struct
         __u32             md_rkey;
         __u64             md_addr;
 } kib_md_t __attribute__((packed));
-        
-typedef struct 
+
+typedef struct
 {
         int               kib_init;             /* initialisation state */
         __u64             kib_incarnation;      /* which one am I */
@@ -196,7 +196,7 @@ typedef struct
         struct list_head  kib_sched_txq;        /* tx requiring attention */
         struct list_head  kib_sched_rxq;        /* rx requiring attention */
         spinlock_t        kib_sched_lock;       /* serialise */
-        
+
         struct kib_tx    *kib_tx_descs;         /* all the tx descriptors */
         kib_pages_t      *kib_tx_pages;         /* premapped tx msg pages */
 
@@ -205,7 +205,7 @@ typedef struct
         wait_queue_head_t kib_idle_tx_waitq;    /* block here for tx descriptor */
         __u64             kib_next_tx_cookie;   /* RDMA completion cookie */
         spinlock_t        kib_tx_lock;          /* serialise */
-        
+
         IB_HANDLE         kib_hca;              /* The HCA */
         int               kib_port;             /* port on the device */
         IB_HANDLE         kib_pd;               /* protection domain */
@@ -232,9 +232,9 @@ typedef struct
 #define IBNAL_INIT_PD              7
 #define IBNAL_INIT_FMR             8
 #define IBNAL_INIT_MR              9
-#define IBNAL_INIT_TXD             10 
-#define IBNAL_INIT_CQ              11 
-#define IBNAL_INIT_ALL             12 
+#define IBNAL_INIT_TXD             10
+#define IBNAL_INIT_CQ              11
+#define IBNAL_INIT_ALL             12
 
 /************************************************************************
  * Wire message structs.
@@ -259,7 +259,7 @@ typedef struct
 
 /* these arrays serve two purposes during rdma.  they are built on the passive
  * side and sent to the active side as remote arguments.  On the active side
- * the descs are used as a data structure on the way to local gather items. 
+ * the descs are used as a data structure on the way to local gather items.
  * the different roles result in split local/remote meaning of desc->rd_key */
 typedef struct
 {
@@ -373,7 +373,7 @@ typedef struct kib_connreq
 } kib_connreq_t;
 
 typedef struct kib_conn
-{ 
+{
         struct kib_peer    *ibc_peer;           /* owning peer */
         struct list_head    ibc_list;           /* stash on peer's conn list */
         __u64               ibc_incarnation;    /* which instance of the peer */
@@ -445,7 +445,7 @@ iibt_get_hca_guids(uint32 *hca_count, EUI64 *hca_guid_list)
 }
 
 static inline FSTATUS
-iibt_open_hca(EUI64                    hca_guid, 
+iibt_open_hca(EUI64                    hca_guid,
              IB_COMPLETION_CALLBACK   completion_callback,
              IB_ASYNC_EVENT_CALLBACK  async_event_callback,
              void                    *arg,
@@ -480,55 +480,55 @@ iibt_pd_free(IB_HANDLE pd_handle)
 }
 
 static inline FSTATUS
-iibt_register_physical_memory(IB_HANDLE hca_handle, 
+iibt_register_physical_memory(IB_HANDLE hca_handle,
                               IB_VIRT_ADDR requested_io_va,
                               void *phys_buffers, uint64 nphys_buffers,
                               uint32 io_va_offset, IB_HANDLE pd_handle,
                               IB_ACCESS_CONTROL access,
-                              IB_HANDLE *mem_handle, 
+                              IB_HANDLE *mem_handle,
                               IB_VIRT_ADDR *actual_io_va,
                               IB_L_KEY *lkey, IB_R_KEY *rkey)
 {
         return IIBT_IF.Vpi.RegisterPhysMemRegion(hca_handle, requested_io_va,
                                                  phys_buffers, nphys_buffers,
-                                                 io_va_offset, pd_handle, 
+                                                 io_va_offset, pd_handle,
                                                  access,
                                                  mem_handle, actual_io_va,
                                                  lkey, rkey);
 }
 
 static inline FSTATUS
-iibt_register_contig_physical_memory(IB_HANDLE hca_handle, 
+iibt_register_contig_physical_memory(IB_HANDLE hca_handle,
                                      IB_VIRT_ADDR requested_io_va,
-                                     IB_MR_PHYS_BUFFER *phys_buffers, 
+                                     IB_MR_PHYS_BUFFER *phys_buffers,
                                      uint64 nphys_buffers,
                                      uint32 io_va_offset, IB_HANDLE pd_handle,
                                      IB_ACCESS_CONTROL access,
-                                     IB_HANDLE *mem_handle, 
+                                     IB_HANDLE *mem_handle,
                                      IB_VIRT_ADDR *actual_io_va,
                                      IB_L_KEY *lkey, IB_R_KEY *rkey)
 {
-        return IIBT_IF.Vpi.RegisterContigPhysMemRegion(hca_handle, 
+        return IIBT_IF.Vpi.RegisterContigPhysMemRegion(hca_handle,
                                                        requested_io_va,
-                                                       phys_buffers, 
+                                                       phys_buffers,
                                                        nphys_buffers,
-                                                       io_va_offset, pd_handle, 
+                                                       io_va_offset, pd_handle,
                                                        access,
                                                        mem_handle, actual_io_va,
                                                        lkey, rkey);
 }
 
 static inline FSTATUS
-iibt_register_memory(IB_HANDLE hca_handle, 
+iibt_register_memory(IB_HANDLE hca_handle,
                      void *virt_addr, unsigned int length,
                      IB_HANDLE pd_handle,
                      IB_ACCESS_CONTROL access,
-                     IB_HANDLE *mem_handle, 
+                     IB_HANDLE *mem_handle,
                      IB_L_KEY *lkey, IB_R_KEY *rkey)
 {
-        return IIBT_IF.Vpi.RegisterMemRegion(hca_handle, 
+        return IIBT_IF.Vpi.RegisterMemRegion(hca_handle,
                                              virt_addr, length,
-                                             pd_handle, 
+                                             pd_handle,
                                              access,
                                              mem_handle,
                                              lkey, rkey);
@@ -568,10 +568,10 @@ iibt_cq_destroy(IB_HANDLE cq_handle)
 
 static inline FSTATUS
 iibt_qp_create(IB_HANDLE hca_handle, IB_QP_ATTRIBUTES_CREATE *create_attr,
-              void *arg, IB_HANDLE *cq_handle, 
+              void *arg, IB_HANDLE *cq_handle,
               IB_QP_ATTRIBUTES_QUERY *query_attr)
 {
-        return IIBT_IF.Vpi.CreateQP(hca_handle, create_attr, arg, cq_handle, 
+        return IIBT_IF.Vpi.CreateQP(hca_handle, create_attr, arg, cq_handle,
                                     query_attr);
 }
 
@@ -672,7 +672,7 @@ iibt_cm_cancel(IB_HANDLE cep)
 }
 
 static inline FSTATUS
-iibt_cm_accept(IB_HANDLE cep, 
+iibt_cm_accept(IB_HANDLE cep,
                CM_CONN_INFO *send_info, CM_CONN_INFO *recv_info,
                PFN_CM_CALLBACK callback, void *arg,
                IB_HANDLE *new_cep)
@@ -736,10 +736,10 @@ static inline int wrq_signals_completion(IB_WORK_REQ *wrq)
 /******************************************************************************/
 
 static inline struct list_head *
-kibnal_nid2peerlist (ptl_nid_t nid) 
+kibnal_nid2peerlist (ptl_nid_t nid)
 {
         unsigned int hash = ((unsigned int)nid) % kibnal_data.kib_peer_hash_size;
-        
+
         return (&kibnal_data.kib_peers [hash]);
 }
 
@@ -797,14 +797,14 @@ kibnal_show_rdma_attr (kib_conn_t *conn)
 {
         struct ib_qp_attribute qp_attr;
         int                    rc;
-        
+
         memset (&qp_attr, 0, sizeof(qp_attr));
         rc = ib_qp_query(conn->ibc_qp, &qp_attr);
         if (rc != 0) {
                 CERROR ("Can't get qp attrs: %d\n", rc);
                 return;
         }
-        
+
         CWARN ("RDMA CAPABILITY: write %s read %s\n",
                (qp_attr.valid_fields & TS_IB_QP_ATTRIBUTE_RDMA_ATOMIC_ENABLE) ?
                (qp_attr.enable_rdma_write ? "enabled" : "disabled") : "invalid",
@@ -818,7 +818,7 @@ static inline __u64
 kibnal_page2phys (struct page *p)
 {
         __u64 page_number = p - mem_map;
-        
+
         return (page_number << PAGE_SHIFT);
 }
 #else
@@ -863,7 +863,7 @@ extern void kibnal_destroy_peer (kib_peer_t *peer);
 extern int kibnal_del_peer (ptl_nid_t nid, int single_share);
 extern kib_peer_t *kibnal_find_peer_locked (ptl_nid_t nid);
 extern void kibnal_unlink_peer_locked (kib_peer_t *peer);
-extern int  kibnal_close_stale_conns_locked (kib_peer_t *peer, 
+extern int  kibnal_close_stale_conns_locked (kib_peer_t *peer,
                                               __u64 incarnation);
 extern kib_conn_t *kibnal_create_conn (void);
 extern void kibnal_put_conn (kib_conn_t *conn);
@@ -881,9 +881,9 @@ extern int  kibnal_scheduler(void *arg);
 extern int  kibnal_connd (void *arg);
 extern void kibnal_init_tx_msg (kib_tx_t *tx, int type, int body_nob);
 extern void kibnal_close_conn (kib_conn_t *conn, int why);
-extern void kibnal_start_active_rdma (int type, int status, 
-                                      kib_rx_t *rx, lib_msg_t *libmsg, 
-                                      unsigned int niov, 
+extern void kibnal_start_active_rdma (int type, int status,
+                                      kib_rx_t *rx, lib_msg_t *libmsg,
+                                      unsigned int niov,
                                       struct iovec *iov, ptl_kiov_t *kiov,
                                       size_t offset, size_t nob);
 
index d8f2639..ee6aa98 100644 (file)
@@ -5,9 +5,11 @@
 
 if MODULES
 if !CRAY_PORTALS
+if LINUX
 modulenet_DATA = klonal$(KMODEXT)
 endif
 endif
+endif
 
 MOSTLYCLEANFILES = *.o *.ko *.mod.c
 DIST_SOURCES = $(klonal-objs:%.o=%.c) lonal.h
index 2beb40d..6d8d77d 100644 (file)
@@ -35,7 +35,7 @@
 
 #define DEBUG_SUBSYSTEM S_NAL
 
-#include <linux/kp30.h>
+#include <libcfs/kp30.h>
 #include <portals/p30.h>
 #include <portals/lib-p30.h>
 #include <portals/nal.h>
index c3e9837..3170c63 100644 (file)
@@ -53,7 +53,7 @@
 
 #define DEBUG_SUBSYSTEM S_NAL
 
-#include <linux/kp30.h>
+#include <libcfs/kp30.h>
 #include <portals/p30.h>
 #include <portals/lib-p30.h>
 #include <portals/nal.h>
 //#define IBNAL_CALLBACK_CTXT  IB_CQ_CALLBACK_PROCESS
 #define IBNAL_CALLBACK_CTXT  IB_CQ_CALLBACK_INTERRUPT
 
-typedef struct 
+typedef struct
 {
         int               kib_io_timeout;       /* comms timeout (seconds) */
         int               kib_listener_timeout; /* listener's timeout */
@@ -140,8 +140,8 @@ typedef struct
         struct ib_mr     *ibp_handle;           /* mapped region handle */
         struct page      *ibp_pages[0];
 } kib_pages_t;
-        
-typedef struct 
+
+typedef struct
 {
         int               kib_init;             /* initialisation state */
         __u64             kib_incarnation;      /* which one am I */
@@ -180,7 +180,7 @@ typedef struct
         struct list_head  kib_sched_txq;        /* tx requiring attention */
         struct list_head  kib_sched_rxq;        /* rx requiring attention */
         spinlock_t        kib_sched_lock;       /* serialise */
-        
+
         struct kib_tx    *kib_tx_descs;         /* all the tx descriptors */
         kib_pages_t      *kib_tx_pages;         /* premapped tx msg pages */
 
@@ -189,7 +189,7 @@ typedef struct
         wait_queue_head_t kib_idle_tx_waitq;    /* block here for tx descriptor */
         __u64             kib_next_tx_cookie;   /* RDMA completion cookie */
         spinlock_t        kib_tx_lock;          /* serialise */
-        
+
         struct ib_device *kib_device;           /* "the" device */
         struct ib_device_properties kib_device_props; /* its properties */
         int               kib_port;             /* port on the device */
@@ -199,7 +199,7 @@ typedef struct
         struct ib_fmr_pool *kib_fmr_pool;       /* fast memory region pool */
 #endif
         struct ib_cq     *kib_cq;               /* completion queue */
-        
+
 } kib_data_t;
 
 #define IBNAL_INIT_NOTHING         0
@@ -362,7 +362,7 @@ typedef struct kib_connreq
 } kib_connreq_t;
 
 typedef struct kib_conn
-{ 
+{
         struct kib_peer    *ibc_peer;           /* owning peer */
         struct list_head    ibc_list;           /* stash on peer's conn list */
         __u64               ibc_incarnation;    /* which instance of the peer */
@@ -412,10 +412,10 @@ extern kib_data_t      kibnal_data;
 extern kib_tunables_t  kibnal_tunables;
 
 static inline struct list_head *
-kibnal_nid2peerlist (ptl_nid_t nid) 
+kibnal_nid2peerlist (ptl_nid_t nid)
 {
         unsigned int hash = ((unsigned int)nid) % kibnal_data.kib_peer_hash_size;
-        
+
         return (&kibnal_data.kib_peers [hash]);
 }
 
@@ -445,14 +445,14 @@ kibnal_show_rdma_attr (kib_conn_t *conn)
 {
         struct ib_qp_attribute qp_attr;
         int                    rc;
-        
+
         memset (&qp_attr, 0, sizeof(qp_attr));
         rc = ib_qp_query(conn->ibc_qp, &qp_attr);
         if (rc != 0) {
                 CERROR ("Can't get qp attrs: %d\n", rc);
                 return;
         }
-        
+
         CWARN ("RDMA CAPABILITY: write %s read %s\n",
                (qp_attr.valid_fields & TS_IB_QP_ATTRIBUTE_RDMA_ATOMIC_ENABLE) ?
                (qp_attr.enable_rdma_write ? "enabled" : "disabled") : "invalid",
@@ -522,7 +522,7 @@ extern void kibnal_put_peer (kib_peer_t *peer);
 extern int kibnal_del_peer (ptl_nid_t nid, int single_share);
 extern kib_peer_t *kibnal_find_peer_locked (ptl_nid_t nid);
 extern void kibnal_unlink_peer_locked (kib_peer_t *peer);
-extern int  kibnal_close_stale_conns_locked (kib_peer_t *peer, 
+extern int  kibnal_close_stale_conns_locked (kib_peer_t *peer,
                                               __u64 incarnation);
 extern kib_conn_t *kibnal_create_conn (void);
 extern void kibnal_put_conn (kib_conn_t *conn);
@@ -535,7 +535,7 @@ extern void kibnal_check_sends (kib_conn_t *conn);
 extern tTS_IB_CM_CALLBACK_RETURN
 kibnal_conn_callback (tTS_IB_CM_EVENT event, tTS_IB_CM_COMM_ID cid,
                        void *param, void *arg);
-extern tTS_IB_CM_CALLBACK_RETURN 
+extern tTS_IB_CM_CALLBACK_RETURN
 kibnal_passive_conn_callback (tTS_IB_CM_EVENT event, tTS_IB_CM_COMM_ID cid,
                                void *param, void *arg);
 
@@ -548,9 +548,9 @@ extern int  kibnal_reaper (void *arg);
 extern void kibnal_callback (struct ib_cq *cq, struct ib_cq_entry *e, void *arg);
 extern void kibnal_init_tx_msg (kib_tx_t *tx, int type, int body_nob);
 extern int  kibnal_close_conn (kib_conn_t *conn, int why);
-extern void kibnal_start_active_rdma (int type, int status, 
-                                      kib_rx_t *rx, lib_msg_t *libmsg, 
-                                      unsigned int niov, 
+extern void kibnal_start_active_rdma (int type, int status,
+                                      kib_rx_t *rx, lib_msg_t *libmsg,
+                                      unsigned int niov,
                                       struct iovec *iov, ptl_kiov_t *kiov,
                                       int offset, int nob);
 
index 6e04752..c138be4 100644 (file)
@@ -18,7 +18,7 @@
  *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * Basic library routines. 
+ * Basic library routines.
  *
  */
 
@@ -74,8 +74,8 @@
 
 #define DEBUG_SUBSYSTEM S_NAL
 
-#include <linux/kp30.h>
-#include <linux/kpr.h>
+#include <libcfs/kp30.h>
+#include <portals/kpr.h>
 #include <portals/p30.h>
 #include <portals/lib-p30.h>
 #include <portals/nal.h>
@@ -215,7 +215,7 @@ typedef struct
         int                      kqn_optimized_gets;  /* optimized GETs? */
 #if CONFIG_SYSCTL
         struct ctl_table_header *kqn_sysctl;          /* sysctl interface */
-#endif        
+#endif
 } kqswnal_tunables_t;
 
 typedef struct
@@ -234,7 +234,7 @@ typedef struct
         wait_queue_head_t  kqn_idletxd_waitq;   /* sender blocks here waiting for idle txd */
         struct list_head   kqn_idletxd_fwdq;    /* forwarded packets block here waiting for idle txd */
         atomic_t           kqn_pending_txs;     /* # transmits being prepped */
-        
+
         spinlock_t         kqn_sched_lock;      /* serialise packet schedulers */
         wait_queue_head_t  kqn_sched_waitq;     /* scheduler blocks here */
 
@@ -282,24 +282,24 @@ extern void kqswnal_fwd_packet (void *arg, kpr_fwd_desc_t *fwd);
 extern void kqswnal_rx_done (kqswnal_rx_t *krx);
 
 static inline ptl_nid_t
-kqswnal_elanid2nid (int elanid) 
+kqswnal_elanid2nid (int elanid)
 {
         return (kqswnal_data.kqn_nid_offset + elanid);
 }
 
 static inline int
-kqswnal_nid2elanid (ptl_nid_t nid) 
+kqswnal_nid2elanid (ptl_nid_t nid)
 {
         /* not in this cluster? */
         if (nid < kqswnal_data.kqn_nid_offset ||
             nid >= kqswnal_data.kqn_nid_offset + kqswnal_data.kqn_nnodes)
                 return (-1);
-        
+
         return (nid - kqswnal_data.kqn_nid_offset);
 }
 
 static inline ptl_nid_t
-kqswnal_rx_nid(kqswnal_rx_t *krx) 
+kqswnal_rx_nid(kqswnal_rx_t *krx)
 {
         return (kqswnal_elanid2nid(ep_rxd_node(krx->krx_rxd)));
 }
@@ -318,10 +318,10 @@ kqswnal_pages_spanned (void *base, int nob)
 static inline kqsw_csum_t kqsw_csum (kqsw_csum_t sum, void *base, int nob)
 {
         unsigned char *ptr = (unsigned char *)base;
-        
+
         while (nob-- > 0)
                 sum += *ptr++;
-        
+
         return (sum);
 }
 #endif
@@ -349,7 +349,7 @@ static inline void kqswnal_rx_decref (kqswnal_rx_t *krx)
 #define EP_ENOMEM      ENOMEM
 
 static inline EP_XMTR *
-ep_alloc_xmtr(EP_DEV *e) 
+ep_alloc_xmtr(EP_DEV *e)
 {
         return (ep_alloc_large_xmtr(e));
 }
@@ -361,7 +361,7 @@ ep_alloc_rcvr(EP_DEV *e, int svc, int nenv)
 }
 
 static inline void
-ep_free_xmtr(EP_XMTR *x) 
+ep_free_xmtr(EP_XMTR *x)
 {
         ep_free_large_xmtr(x);
 }
index e6602dd..0843058 100644 (file)
@@ -53,8 +53,7 @@
 
 #define DEBUG_SUBSYSTEM S_NAL
 
-#include <linux/kp30.h>
-#include <linux/portals_compat25.h>
+#include <libcfs/kp30.h>
 #include <portals/p30.h>
 #include <portals/lib-p30.h>
 #include <portals/nal.h>
diff --git a/lnet/klnds/socklnd/Info.plist b/lnet/klnds/socklnd/Info.plist
new file mode 100644 (file)
index 0000000..11be93d
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>CFBundleDevelopmentRegion</key>
+       <string>English</string>
+       <key>CFBundleExecutable</key>
+       <string>ksocknal</string>
+       <key>CFBundleIconFile</key>
+       <string></string>
+       <key>CFBundleIdentifier</key>
+       <string>com.clusterfs.lustre.ksocknal</string>
+       <key>CFBundleInfoDictionaryVersion</key>
+       <string>6.0</string>
+       <key>CFBundlePackageType</key>
+       <string>KEXT</string>
+       <key>CFBundleSignature</key>
+       <string>????</string>
+       <key>CFBundleVersion</key>
+       <string>1.0.1</string> 
+       <key>OSBundleCompatibleVersion</key> 
+       <string>1.0.0</string>
+       <key>OSBundleLibraries</key>
+       <dict> 
+               <key>com.apple.kernel.bsd</key> 
+               <string>1.1</string> 
+               <key>com.apple.kernel.iokit</key> 
+               <string>1.0.0b1</string> 
+               <key>com.apple.kernel.mach</key> 
+               <string>1.0.0b1</string> 
+               <key>com.clusterfs.lustre.libcfs</key> 
+               <string>1.0.0</string>
+               <key>com.clusterfs.lustre.portals</key> 
+               <string>1.0.0</string>
+       </dict>
+</dict>
+</plist>
index 633b455..7fe9638 100644 (file)
@@ -1,5 +1,6 @@
 MODULES := ksocknal
-ksocknal-objs := socknal.o socknal_cb.o
+
+ksocknal-objs := socknal.o socknal_cb.o socknal_lib-linux.o
 
 # If you don't build with -O2, your modules won't insert, becahse htonl is
 # just special that way.
index 070b649..63c095d 100644 (file)
@@ -5,9 +5,31 @@
 
 if MODULES
 if !CRAY_PORTALS
+
+if LINUX
 modulenet_DATA = ksocknal$(KMODEXT)
 endif
+
+if DARWIN
+macos_PROGRAMS := ksocknal
+
+ksocknal_SOURCES := socknal.c socknal_cb.c socknal_lib-darwin.c
+
+ksocknal_CFLAGS := $(EXTRA_KCFLAGS)
+ksocknal_LDFLAGS := $(EXTRA_KLDFLAGS)
+ksocknal_LDADD := $(EXTRA_KLIBS)
+
+plist_DATA := Info.plist
+
+install-data-hook: fix-kext-ownership
+
+endif
+
 endif
+endif
+
+EXTRA_DIST := Info.plist
 
-MOSTLYCLEANFILES = *.o *.ko *.mod.c
-DIST_SOURCES = $(ksocknal-objs:%.o=%.c) socknal.h
+MOSTLYCLEANFILES = *.o *.ko *.mod.c socknal_lib.c
+DIST_SOURCES = $(ksocknal-objs:%.o=%.c) socknal_lib-darwin.c   \
+       socknal_lib-darwin.h socknal_lib-linux.h socknal.h
diff --git a/lnet/klnds/socklnd/ksocklnd.xcode/project.pbxproj b/lnet/klnds/socklnd/ksocklnd.xcode/project.pbxproj
new file mode 100644 (file)
index 0000000..cab8b43
--- /dev/null
@@ -0,0 +1,287 @@
+// !$*UTF8*$!
+{
+       archiveVersion = 1;
+       classes = {
+       };
+       objectVersion = 39;
+       objects = {
+               06AA1262FFB20DD611CA28AA = {
+                       buildRules = (
+                       );
+                       buildSettings = {
+                               COPY_PHASE_STRIP = NO;
+                               GCC_DYNAMIC_NO_PIC = NO;
+                               GCC_ENABLE_FIX_AND_CONTINUE = YES;
+                               GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+                               GCC_OPTIMIZATION_LEVEL = 0;
+                               OPTIMIZATION_CFLAGS = "-O0";
+                               ZERO_LINK = YES;
+                       };
+                       isa = PBXBuildStyle;
+                       name = Development;
+               };
+               06AA1263FFB20DD611CA28AA = {
+                       buildRules = (
+                       );
+                       buildSettings = {
+                               COPY_PHASE_STRIP = YES;
+                               GCC_ENABLE_FIX_AND_CONTINUE = NO;
+                               ZERO_LINK = NO;
+                       };
+                       isa = PBXBuildStyle;
+                       name = Deployment;
+               };
+//060
+//061
+//062
+//063
+//064
+//080
+//081
+//082
+//083
+//084
+               089C1669FE841209C02AAC07 = {
+                       buildSettings = {
+                       };
+                       buildStyles = (
+                               06AA1262FFB20DD611CA28AA,
+                               06AA1263FFB20DD611CA28AA,
+                       );
+                       hasScannedForEncodings = 1;
+                       isa = PBXProject;
+                       mainGroup = 089C166AFE841209C02AAC07;
+                       projectDirPath = "";
+                       targets = (
+                               32A4FEB80562C75700D090E7,
+                       );
+               };
+               089C166AFE841209C02AAC07 = {
+                       children = (
+                               247142CAFF3F8F9811CA285C,
+                               089C167CFE841241C02AAC07,
+                               19C28FB6FE9D52B211CA2CBB,
+                       );
+                       isa = PBXGroup;
+                       name = ksocknal;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               089C167CFE841241C02AAC07 = {
+                       children = (
+                               32A4FEC30562C75700D090E7,
+                       );
+                       isa = PBXGroup;
+                       name = Resources;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+//080
+//081
+//082
+//083
+//084
+//190
+//191
+//192
+//193
+//194
+               1957C5680737C71F00425049 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.c;
+                       path = socknal.c;
+                       refType = 2;
+                       sourceTree = SOURCE_ROOT;
+               };
+               1957C5690737C71F00425049 = {
+                       fileRef = 1957C5680737C71F00425049;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               1957C56A0737C72F00425049 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.c;
+                       path = socknal_cb.c;
+                       refType = 2;
+                       sourceTree = SOURCE_ROOT;
+               };
+               1957C56B0737C72F00425049 = {
+                       fileRef = 1957C56A0737C72F00425049;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               1957C5B20737C78E00425049 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.c;
+                       name = socknal_lib.c;
+                       path = arch/xnu/socknal_lib.c;
+                       refType = 2;
+                       sourceTree = SOURCE_ROOT;
+               };
+               1957C5B30737C78E00425049 = {
+                       fileRef = 1957C5B20737C78E00425049;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               19C28FB6FE9D52B211CA2CBB = {
+                       children = (
+                               32A4FEC40562C75800D090E7,
+                       );
+                       isa = PBXGroup;
+                       name = Products;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+//190
+//191
+//192
+//193
+//194
+//240
+//241
+//242
+//243
+//244
+               247142CAFF3F8F9811CA285C = {
+                       children = (
+                               1957C5B20737C78E00425049,
+                               1957C56A0737C72F00425049,
+                               1957C5680737C71F00425049,
+                       );
+                       isa = PBXGroup;
+                       name = Source;
+                       path = "";
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+//240
+//241
+//242
+//243
+//244
+//320
+//321
+//322
+//323
+//324
+               32A4FEB80562C75700D090E7 = {
+                       buildPhases = (
+                               32A4FEB90562C75700D090E7,
+                               32A4FEBA0562C75700D090E7,
+                               32A4FEBB0562C75700D090E7,
+                               32A4FEBD0562C75700D090E7,
+                               32A4FEBF0562C75700D090E7,
+                               32A4FEC00562C75700D090E7,
+                               32A4FEC10562C75700D090E7,
+                       );
+                       buildRules = (
+                       );
+                       buildSettings = {
+                               FRAMEWORK_SEARCH_PATHS = "";
+                               GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
+                               GCC_WARN_UNKNOWN_PRAGMAS = NO;
+                               HEADER_SEARCH_PATHS = "../../include ./arch/xnu";
+                               INFOPLIST_FILE = Info.plist;
+                               INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Extensions";
+                               LIBRARY_SEARCH_PATHS = "";
+                               MODULE_NAME = com.clusterfs.lustre.portals.knals.ksocknal;
+                               MODULE_START = ksocknal_start;
+                               MODULE_STOP = ksocknal_stop;
+                               MODULE_VERSION = 1.0.1;
+                               OTHER_CFLAGS = "-D__KERNEL__";
+                               OTHER_LDFLAGS = "";
+                               OTHER_REZFLAGS = "";
+                               PRODUCT_NAME = ksocknal;
+                               SECTORDER_FLAGS = "";
+                               WARNING_CFLAGS = "-Wmost";
+                               WRAPPER_EXTENSION = kext;
+                       };
+                       dependencies = (
+                       );
+                       isa = PBXNativeTarget;
+                       name = ksocknal;
+                       productInstallPath = "$(SYSTEM_LIBRARY_DIR)/Extensions";
+                       productName = ksocknal;
+                       productReference = 32A4FEC40562C75800D090E7;
+                       productType = "com.apple.product-type.kernel-extension";
+               };
+               32A4FEB90562C75700D090E7 = {
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       isa = PBXShellScriptBuildPhase;
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "script=\"${SYSTEM_DEVELOPER_DIR}/ProjectBuilder Extras/Kernel Extension Support/KEXTPreprocess\";\nif [ -x \"$script\" ]; then\n    . \"$script\"\nfi";
+               };
+               32A4FEBA0562C75700D090E7 = {
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       isa = PBXHeadersBuildPhase;
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+               32A4FEBB0562C75700D090E7 = {
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       isa = PBXResourcesBuildPhase;
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+               32A4FEBD0562C75700D090E7 = {
+                       buildActionMask = 2147483647;
+                       files = (
+                               1957C5690737C71F00425049,
+                               1957C56B0737C72F00425049,
+                               1957C5B30737C78E00425049,
+                       );
+                       isa = PBXSourcesBuildPhase;
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+               32A4FEBF0562C75700D090E7 = {
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       isa = PBXFrameworksBuildPhase;
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+               32A4FEC00562C75700D090E7 = {
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       isa = PBXRezBuildPhase;
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+               32A4FEC10562C75700D090E7 = {
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       isa = PBXShellScriptBuildPhase;
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "script=\"${SYSTEM_DEVELOPER_DIR}/ProjectBuilder Extras/Kernel Extension Support/KEXTPostprocess\";\nif [ -x \"$script\" ]; then\n    . \"$script\"\nfi";
+               };
+               32A4FEC30562C75700D090E7 = {
+                       isa = PBXFileReference;
+                       lastKnownFileType = text.plist.xml;
+                       path = Info.plist;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               32A4FEC40562C75800D090E7 = {
+                       explicitFileType = wrapper.cfbundle;
+                       includeInIndex = 0;
+                       isa = PBXFileReference;
+                       path = ksocknal.kext;
+                       refType = 3;
+                       sourceTree = BUILT_PRODUCTS_DIR;
+               };
+       };
+       rootObject = 089C1669FE841209C02AAC07;
+}
index 7642770..07078ca 100644 (file)
@@ -37,68 +37,6 @@ kpr_nal_interface_t ksocknal_router_interface = {
         kprni_notify:     ksocknal_notify,
 };
 
-#ifdef CONFIG_SYSCTL
-#define SOCKNAL_SYSCTL 200
-
-#define SOCKNAL_SYSCTL_TIMEOUT          1
-#define SOCKNAL_SYSCTL_EAGER_ACK        2
-#define SOCKNAL_SYSCTL_ZERO_COPY        3
-#define SOCKNAL_SYSCTL_TYPED            4
-#define SOCKNAL_SYSCTL_MIN_BULK         5
-#define SOCKNAL_SYSCTL_BUFFER_SIZE      6
-#define SOCKNAL_SYSCTL_NAGLE            7
-#define SOCKNAL_SYSCTL_IRQ_AFFINITY     8
-#define SOCKNAL_SYSCTL_KEEPALIVE_IDLE   9
-#define SOCKNAL_SYSCTL_KEEPALIVE_COUNT 10
-#define SOCKNAL_SYSCTL_KEEPALIVE_INTVL 11
-
-static ctl_table ksocknal_ctl_table[] = {
-        {SOCKNAL_SYSCTL_TIMEOUT, "timeout", 
-         &ksocknal_tunables.ksnd_io_timeout, sizeof (int),
-         0644, NULL, &proc_dointvec},
-        {SOCKNAL_SYSCTL_EAGER_ACK, "eager_ack", 
-         &ksocknal_tunables.ksnd_eager_ack, sizeof (int),
-         0644, NULL, &proc_dointvec},
-#if SOCKNAL_ZC
-        {SOCKNAL_SYSCTL_ZERO_COPY, "zero_copy", 
-         &ksocknal_tunables.ksnd_zc_min_frag, sizeof (int),
-         0644, NULL, &proc_dointvec},
-#endif
-        {SOCKNAL_SYSCTL_TYPED, "typed", 
-         &ksocknal_tunables.ksnd_typed_conns, sizeof (int),
-         0644, NULL, &proc_dointvec},
-        {SOCKNAL_SYSCTL_MIN_BULK, "min_bulk", 
-         &ksocknal_tunables.ksnd_min_bulk, sizeof (int),
-         0644, NULL, &proc_dointvec},
-        {SOCKNAL_SYSCTL_BUFFER_SIZE, "buffer_size",
-         &ksocknal_tunables.ksnd_buffer_size, sizeof(int),
-         0644, NULL, &proc_dointvec},
-        {SOCKNAL_SYSCTL_NAGLE, "nagle",
-         &ksocknal_tunables.ksnd_nagle, sizeof(int),
-         0644, NULL, &proc_dointvec},
-#if CPU_AFFINITY
-        {SOCKNAL_SYSCTL_IRQ_AFFINITY, "irq_affinity",
-         &ksocknal_tunables.ksnd_irq_affinity, sizeof(int),
-         0644, NULL, &proc_dointvec},
-#endif
-        {SOCKNAL_SYSCTL_KEEPALIVE_IDLE, "keepalive_idle",
-         &ksocknal_tunables.ksnd_keepalive_idle, sizeof(int),
-         0644, NULL, &proc_dointvec},
-        {SOCKNAL_SYSCTL_KEEPALIVE_COUNT, "keepalive_count",
-         &ksocknal_tunables.ksnd_keepalive_count, sizeof(int),
-         0644, NULL, &proc_dointvec},
-        {SOCKNAL_SYSCTL_KEEPALIVE_INTVL, "keepalive_intvl",
-         &ksocknal_tunables.ksnd_keepalive_intvl, sizeof(int),
-         0644, NULL, &proc_dointvec},
-        { 0 }
-};
-
-static ctl_table ksocknal_top_ctl_table[] = {
-        {SOCKNAL_SYSCTL, "socknal", NULL, 0, 0555, ksocknal_ctl_table},
-        { 0 }
-};
-#endif
-
 int
 ksocknal_set_mynid(ptl_nid_t nid)
 {
@@ -117,54 +55,6 @@ ksocknal_set_mynid(ptl_nid_t nid)
         return (0);
 }
 
-void
-ksocknal_bind_irq (unsigned int irq)
-{
-#if (defined(CONFIG_SMP) && CPU_AFFINITY)
-        int              bind;
-        int              cpu;
-        unsigned long    flags;
-        char             cmdline[64];
-        ksock_irqinfo_t *info;
-        char            *argv[] = {"/bin/sh",
-                                   "-c",
-                                   cmdline,
-                                   NULL};
-        char            *envp[] = {"HOME=/",
-                                   "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
-                                   NULL};
-
-        LASSERT (irq < NR_IRQS);
-        if (irq == 0)              /* software NIC or affinity disabled */
-                return;
-
-        info = &ksocknal_data.ksnd_irqinfo[irq];
-
-        write_lock_irqsave (&ksocknal_data.ksnd_global_lock, flags);
-
-        LASSERT (info->ksni_valid);
-        bind = !info->ksni_bound;
-        info->ksni_bound = 1;
-
-        write_unlock_irqrestore (&ksocknal_data.ksnd_global_lock, flags);
-
-        if (!bind)                              /* bound already */
-                return;
-
-        cpu = ksocknal_irqsched2cpu(info->ksni_sched);
-        snprintf (cmdline, sizeof (cmdline),
-                  "echo %d > /proc/irq/%u/smp_affinity", 1 << cpu, irq);
-
-        printk (KERN_INFO "Lustre: Binding irq %u to CPU %d with cmd: %s\n",
-                irq, cpu, cmdline);
-
-        /* FIXME: Find a better method of setting IRQ affinity...
-         */
-
-        USERMODEHELPER(argv[0], argv, envp);
-#endif
-}
-
 ksock_interface_t *
 ksocknal_ip2iface(__u32 ip)
 {
@@ -174,11 +64,11 @@ ksocknal_ip2iface(__u32 ip)
         for (i = 0; i < ksocknal_data.ksnd_ninterfaces; i++) {
                 LASSERT(i < SOCKNAL_MAX_INTERFACES);
                 iface = &ksocknal_data.ksnd_interfaces[i];
-                
+
                 if (iface->ksni_ipaddr == ip)
                         return (iface);
         }
-        
+
         return (NULL);
 }
 
@@ -193,7 +83,7 @@ ksocknal_create_route (__u32 ipaddr, int port)
 
         atomic_set (&route->ksnr_refcount, 1);
         route->ksnr_peer = NULL;
-        route->ksnr_timeout = jiffies;
+        route->ksnr_timeout = cfs_time_current();
         route->ksnr_retry_interval = SOCKNAL_MIN_RECONNECT_INTERVAL;
         route->ksnr_ipaddr = ipaddr;
         route->ksnr_port = port;
@@ -244,9 +134,9 @@ ksocknal_create_peer (ptl_nid_t nid)
         peer->ksnp_nid = nid;
         atomic_set (&peer->ksnp_refcount, 1);   /* 1 ref for caller */
         peer->ksnp_closing = 0;
-        INIT_LIST_HEAD (&peer->ksnp_conns);
-        INIT_LIST_HEAD (&peer->ksnp_routes);
-        INIT_LIST_HEAD (&peer->ksnp_tx_queue);
+        CFS_INIT_LIST_HEAD (&peer->ksnp_conns);
+        CFS_INIT_LIST_HEAD (&peer->ksnp_routes);
+        CFS_INIT_LIST_HEAD (&peer->ksnp_tx_queue);
 
         atomic_inc (&ksocknal_data.ksnd_npeers);
         return (peer);
@@ -346,7 +236,7 @@ ksocknal_unlink_peer_locked (ksock_peer_t *peer)
 
 int
 ksocknal_get_peer_info (int index, ptl_nid_t *nid,
-                        __u32 *myip, __u32 *peer_ip, int *port, 
+                        __u32 *myip, __u32 *peer_ip, int *port,
                         int *conn_count, int *share_count)
 {
         ksock_peer_t      *peer;
@@ -360,7 +250,7 @@ ksocknal_get_peer_info (int index, ptl_nid_t *nid,
         read_lock (&ksocknal_data.ksnd_global_lock);
 
         for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-                
+
                 list_for_each (ptmp, &ksocknal_data.ksnd_peers[i]) {
                         peer = list_entry (ptmp, ksock_peer_t, ksnp_list);
 
@@ -368,7 +258,7 @@ ksocknal_get_peer_info (int index, ptl_nid_t *nid,
                             list_empty(&peer->ksnp_routes)) {
                                 if (index-- > 0)
                                         continue;
-                                
+
                                 *nid = peer->ksnp_nid;
                                 *myip = 0;
                                 *peer_ip = 0;