diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4
index 146f0abda13c7be4456ce69bb263f26fb16dfa63..c0e3a41f7653099cd5ca52760a48bbdb7e3834fc 100644
--- a/lustre/autoconf/lustre-core.m4
+++ b/lustre/autoconf/lustre-core.m4
@@ -1401,7 +1401,7 @@ AC_TRY_RUN([
 #  endif
 # endif
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 
 #include <stdio.h>
 
diff --git a/lustre/cmm/cmm_internal.h b/lustre/cmm/cmm_internal.h
index a71420b4911d4db40dd4ca2ad5a243c709a26bf7..e3b1da21485d5eb82d88ec551d8fdfa67ce70a71 100644
--- a/lustre/cmm/cmm_internal.h
+++ b/lustre/cmm/cmm_internal.h
@@ -48,7 +48,7 @@
 #include <obd.h>
 #include <lustre_fld.h>
 #include <md_object.h>
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 
 
 struct cmm_device {
diff --git a/lustre/include/linux/lustre_acl.h b/lustre/include/linux/lustre_acl.h
index ba7abb16300f4392b5dbe59479bbe0bc53c98444..f5d07a55d6aa087a810437d48d33b25c68a8d4b3 100644
--- a/lustre/include/linux/lustre_acl.h
+++ b/lustre/include/linux/lustre_acl.h
@@ -39,8 +39,12 @@
  * See also lustre_idl.h for wire formats of requests.
  */
 
-#ifndef _LUSTRE_ACL_H
-#define _LUSTRE_ACL_H
+#ifndef _LUSTRE_LINUX_ACL_H
+#define _LUSTRE_LINUX_ACL_H
+
+#ifndef	_LUSTRE_ACL_H
+#error	Shoud not include direectly. use #include <lustre/lustre_acl.h> instead
+#endif
 
 #ifdef __KERNEL__
 # include <linux/fs.h>
@@ -78,4 +82,4 @@
 # define LUSTRE_POSIX_ACL_MAX_SIZE      0
 # endif /* CONFIG_FS_POSIX_ACL */
 
-#endif /* _LUSTRE_ACL_H */
+#endif /* _LUSTRE_LINUX_ACL_H */
diff --git a/lustre/include/lustre_acl.h b/lustre/include/lustre_acl.h
new file mode 100644
index 0000000000000000000000000000000000000000..8204adc70213b3cc9cc47a4801395430a0d901dc
--- /dev/null
+++ b/lustre/include/lustre_acl.h
@@ -0,0 +1,35 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <info@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 _LUSTRE_ACL_H
+#define _LUSTRE_ACL_H
+
+#if defined(__linux__)
+#include <linux/lustre_acl.h>
+#elif defined(__APPLE__)
+#include <darwin/lustre_acl.h>
+#elif defined(__WINNT__)
+#include <winnt/lustre_acl.h>
+#error Unsupported operating system.
+#endif
+
+#endif
diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c
index b54e767cca64194fc3bd42783d3dacdb2fd692b4..5011d59de3a41b9da80257d86c5300bec6c20c1f 100644
--- a/lustre/ldlm/ldlm_request.c
+++ b/lustre/ldlm/ldlm_request.c
@@ -81,8 +81,8 @@ int ldlm_expired_completion_wait(void *data)
 			   CFS_DURATION_T"s ago); not entering recovery in "
                            "server code, just going back to sleep",
 			   lock->l_enqueued_time.tv_sec,
-                           cfs_time_current_sec() -
-                           lock->l_enqueued_time.tv_sec);
+                           cfs_time_sub(cfs_time_current_sec(),
+                           lock->l_enqueued_time.tv_sec));
                 if (cfs_time_after(cfs_time_current(), next_dump)) {
                         last_dump = next_dump;
                         next_dump = cfs_time_shift(300);
@@ -100,7 +100,8 @@ int ldlm_expired_completion_wait(void *data)
         LDLM_ERROR(lock, "lock timed out (enqueued at "CFS_TIME_T", "
                   CFS_DURATION_T"s ago), entering recovery for %s@%s",
                   lock->l_enqueued_time.tv_sec,
-                  cfs_time_current_sec() - lock->l_enqueued_time.tv_sec,
+                  cfs_time_sub(cfs_time_current_sec(),
+                  lock->l_enqueued_time.tv_sec),
                   obd2cli_tgt(obd), imp->imp_connection->c_remote_uuid.uuid);
 
         RETURN(0);
@@ -206,8 +207,10 @@ noreproc:
                 RETURN(rc);
         }
 
-        LDLM_DEBUG(lock, "client-side enqueue waking up: granted after %lds",
-                   cfs_time_current_sec() - lock->l_enqueued_time.tv_sec);
+        LDLM_DEBUG(lock, "client-side enqueue waking up: granted after "
+                   CFS_DURATION_T"s",
+                   cfs_time_sub(cfs_time_current_sec(),
+                   lock->l_enqueued_time.tv_sec));
 
         /* Update our time estimate */
         at_add(&lock->l_resource->lr_namespace->ns_at_estimate,
diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h
index 9f5e7b587a631bcb99af6b948d413921904765a8..c9acb96deb1de14def9df37e742f93deb5fe9565 100644
--- a/lustre/llite/llite_internal.h
+++ b/lustre/llite/llite_internal.h
@@ -37,17 +37,7 @@
 #ifndef LLITE_INTERNAL_H
 #define LLITE_INTERNAL_H
 
-#include <linux/lustre_acl.h>
-
-#ifdef CONFIG_FS_POSIX_ACL
-# include <linux/fs.h>
-#ifdef HAVE_XATTR_ACL
-# include <linux/xattr_acl.h>
-#endif /* HAVE_XATTR_ACL */
-#ifdef HAVE_LINUX_POSIX_ACL_XATTR_H
-# include <linux/posix_acl_xattr.h>
-#endif /* HAVE_LINUX_POSIX_ACL_XATTR_H */
-#endif /* CONFIG_FS_POSIX_ACL */
+#include <lustre_acl.h>
 
 #include <lustre_debug.h>
 #include <lustre_ver.h>
diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c
index b33f051e4439c41c41fbb7e2171ccab0feaaa3fb..28075a9f9cdf4ccf29259d81cd2fd5e879b6c443 100644
--- a/lustre/llite/xattr.c
+++ b/lustre/llite/xattr.c
@@ -46,7 +46,7 @@
 #include <lustre_dlm.h>
 #include <lustre_ver.h>
 //#include <lustre_mdc.h>
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 
 #include "llite_internal.h"
 
diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c
index 6b838e3a907ed41629ae5e59b60db4f418b1dd23..db0116c2d5e02c210c78a75efa502581cac71734 100644
--- a/lustre/lmv/lmv_obd.c
+++ b/lustre/lmv/lmv_obd.c
@@ -63,11 +63,6 @@
 #include <lustre_fid.h>
 #include "lmv_internal.h"
 
-/* not defined for liblustre building */
-#if !defined(ATOMIC_INIT)
-#define ATOMIC_INIT(val) { (val) }
-#endif
-
 /* object cache. */
 cfs_mem_cache_t *obj_cache;
 atomic_t obj_cache_count = ATOMIC_INIT(0);
diff --git a/lustre/mdc/mdc_locks.c b/lustre/mdc/mdc_locks.c
index 8f0f6d6b868be6533c2826d2c1785966980a133b..ea03789001913b42bc4dc6ca46637c391b60fefa 100644
--- a/lustre/mdc/mdc_locks.c
+++ b/lustre/mdc/mdc_locks.c
@@ -48,7 +48,7 @@
 # include <liblustre.h>
 #endif
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <obd_class.h>
 #include <lustre_dlm.h>
 /* fid_res_name_eq() */
diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c
index 10459b39c686c45c659d386b00b910890048d909..19781c463a28eac1b64c4dabcf7bf759a0987ef0 100644
--- a/lustre/mdc/mdc_request.c
+++ b/lustre/mdc/mdc_request.c
@@ -48,7 +48,7 @@
 # include <liblustre.h>
 #endif
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <obd_class.h>
 #include <lustre_dlm.h>
 #include <lustre_fid.h>
diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h
index 6ddc808909044d065f38ce4988bd60afe773c26b..01fb5c7ecf474a42d9ce1d986b7917390d87763e 100644
--- a/lustre/mdd/mdd_internal.h
+++ b/lustre/mdd/mdd_internal.h
@@ -43,7 +43,7 @@
 
 #include <asm/semaphore.h>
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <lustre_eacl.h>
 #include <obd.h>
 #include <md_object.h>
diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c
index 961590d0bb73a8a3c10f980541b7b58d0f50ae06..2c37cc549e00cc6752a851e7f802201873cc8c0c 100644
--- a/lustre/mds/handler.c
+++ b/lustre/mds/handler.c
@@ -54,7 +54,7 @@
 #include <linux/workqueue.h>
 #include <linux/mount.h>
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <obd_class.h>
 #include <lustre_dlm.h>
 #include <obd_lov.h>
diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c
index 749d1e5d0cd06b2acbc5d33f8e58ec28908d27bb..8f060beae68df426f60d3f02c823e121eb6b3a62 100644
--- a/lustre/mdt/mdt_handler.c
+++ b/lustre/mdt/mdt_handler.c
@@ -67,7 +67,7 @@
 #include <lustre_mds.h>
 #include <lustre_mdt.h>
 #include "mdt_internal.h"
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <lustre_param.h>
 
 mdl_mode_t mdt_mdl_lock_modes[] = {
diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c
index a07e0a72f057c1f65c28dea887bd29313f574cee..d197eb647e9f946c232c590b538c8bb1111d319e 100644
--- a/lustre/mdt/mdt_open.c
+++ b/lustre/mdt/mdt_open.c
@@ -45,7 +45,7 @@
 #endif
 #define DEBUG_SUBSYSTEM S_MDS
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <lustre_mds.h>
 #include "mdt_internal.h"
 
diff --git a/lustre/obdclass/acl.c b/lustre/obdclass/acl.c
index 07364bcb60505dce105573b4f3cd2d94077ac785..05b1fb0d15645dbd4a245638854925677c99bd1a 100644
--- a/lustre/obdclass/acl.c
+++ b/lustre/obdclass/acl.c
@@ -46,7 +46,7 @@
 
 #define DEBUG_SUBSYSTEM S_SEC
 
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 #include <lustre_eacl.h>
 #include <obd_support.h>
 
diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c
index aa61ab365c4a571f1a8ca1129947dff197b31f1d..4ea1aebbe444862c9c6a3264ad81ead52918eec7 100644
--- a/lustre/obdclass/genops.c
+++ b/lustre/obdclass/genops.c
@@ -1072,7 +1072,7 @@ static void class_disconnect_export_list(struct list_head *list, int flags)
                 spin_unlock(&fake_exp->exp_lock);
 
                 CDEBUG(D_HA, "%s: disconnecting export at %s (%p), "
-                       "last request at %ld\n",
+                       "last request at "CFS_TIME_T"\n",
                        exp->exp_obd->obd_name, obd_export_nid2str(exp),
                        exp, exp->exp_last_request_time);
                 rc = obd_disconnect(fake_exp);
diff --git a/lustre/ptlrpc/client.c b/lustre/ptlrpc/client.c
index f0b0c985be96dd196fc9653a2c63bcf35352e3b6..b1a3c106f2b8ad24fac569348ff4e0c4df6961f8 100644
--- a/lustre/ptlrpc/client.c
+++ b/lustre/ptlrpc/client.c
@@ -279,8 +279,9 @@ static void ptlrpc_at_adj_net_latency(struct ptlrpc_request *req)
         /* Network latency is total time less server processing time */
         nl = max_t(int, now - req->rq_sent - st, 0) + 1/*st rounding*/;
         if (st > now - req->rq_sent + 2 /* rounding */)
-                CERROR("Reported service time %u > total measured time %ld\n",
-                       st, now - req->rq_sent);
+                CERROR("Reported service time %u > total measured time "
+                       CFS_DURATION_T"\n",
+                       st, cfs_time_sub(now, req->rq_sent));
 
         oldnl = at_add(&at->iat_net_latency, nl);
         if (oldnl != 0)
@@ -347,9 +348,10 @@ static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req) {
                     ptlrpc_at_get_net_latency(req);
 
         DEBUG_REQ(D_ADAPTTO, req,
-                  "Early reply #%d, new deadline in %lds (%+lds)",
-                  req->rq_early_count, req->rq_deadline -
-                  cfs_time_current_sec(), req->rq_deadline - olddl);
+                  "Early reply #%d, new deadline in "CFS_DURATION_T"s ("
+                  CFS_DURATION_T"s)", req->rq_early_count,
+                  cfs_time_sub(req->rq_deadline, cfs_time_current_sec()),
+                  cfs_time_sub(req->rq_deadline, olddl));
 
 out_cleanup:
         sptlrpc_cli_finish_early_reply(req);
@@ -1399,17 +1401,19 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req)
         ENTRY;
 
         DEBUG_REQ(D_ERROR|D_NETERROR, req,
-                  "%s (sent at %lu, "CFS_DURATION_T"s ago)",
+                  "%s (sent at "CFS_TIME_T", "CFS_DURATION_T"s ago)",
                   req->rq_net_err ? "network error" : "timeout",
-                  (long)req->rq_sent, cfs_time_current_sec() - req->rq_sent);
+                  req->rq_sent, cfs_time_sub(cfs_time_current_sec(),
+                  req->rq_sent));
 
         if (imp) {
-                LCONSOLE_WARN("Request x"LPU64" sent from %s to NID %s %lus ago"
-                              " has timed out (limit %lus).\n", req->rq_xid,
+                LCONSOLE_WARN("Request x"LPU64" sent from %s to NID %s "
+                              CFS_DURATION_T"s ago has timed out "
+                              "(limit "CFS_DURATION_T"s).\n", req->rq_xid,
                               req->rq_import->imp_obd->obd_name,
                               libcfs_nid2str(imp->imp_connection->c_peer.nid),
-                              cfs_time_current_sec() - req->rq_sent,
-                              req->rq_deadline - req->rq_sent);
+                              cfs_time_sub(cfs_time_current_sec(), req->rq_sent),
+                              cfs_time_sub(req->rq_deadline, req->rq_sent));
         }
 
         if (imp != NULL && obd_debug_peer_on_timeout)
diff --git a/lustre/ptlrpc/layout.c b/lustre/ptlrpc/layout.c
index c522df020dc7db9436f958b5435a096ca5fe9250..c11e836fed9f1af741d6a8feb8a4f19b6111fb48 100644
--- a/lustre/ptlrpc/layout.c
+++ b/lustre/ptlrpc/layout.c
@@ -66,7 +66,7 @@
 #endif
 /* struct ptlrpc_request, lustre_msg* */
 #include <lustre_req_layout.h>
-#include <linux/lustre_acl.h>
+#include <lustre_acl.h>
 
 /*
  * empty set of fields... for suitable definition of emptiness.
diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c
index 564a6c2064b24d70e9335becef0b2a65e3daa18e..a60acbc29f1d8d566d5a164a4fceaf7eed5b5ac4 100644
--- a/lustre/ptlrpc/pack_generic.c
+++ b/lustre/ptlrpc/pack_generic.c
@@ -2190,7 +2190,7 @@ void _debug_req(struct ptlrpc_request *req, __u32 mask,
         libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
                            data->msg_fn, data->msg_line, fmt, args,
                            " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
-                           " lens %d/%d e %d to %d dl %ld ref %d "
+                           " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
                            "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
                            req, req->rq_xid, req->rq_transno,
                            req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c
index fa23b912af732583df6039a2690b168ad388a2d8..9c96628b74eaa77d96893a014875815784d32110 100644
--- a/lustre/ptlrpc/service.c
+++ b/lustre/ptlrpc/service.c
@@ -670,8 +670,8 @@ static int ptlrpc_at_add_timed(struct ptlrpc_request *req)
         if ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT) == 0)
                 return(-ENOSYS);
 
-        DEBUG_REQ(D_ADAPTTO, req, "add timed %lds",
-                  req->rq_deadline - cfs_time_current_sec());
+        DEBUG_REQ(D_ADAPTTO, req, "add timed "CFS_DURATION_T"s",
+                  cfs_time_sub(req->rq_deadline, cfs_time_current_sec()));
 
         spin_lock(&svc->srv_at_lock);
 
@@ -711,7 +711,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req,
         struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service;
         struct ptlrpc_request *reqcopy;
         struct lustre_msg *reqmsg;
-        long olddl = req->rq_deadline - cfs_time_current_sec();
+        cfs_duration_t olddl = req->rq_deadline - cfs_time_current_sec();
         time_t newdl;
         int rc;
         ENTRY;
@@ -753,9 +753,10 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req,
         if (req->rq_deadline >= newdl) {
                 /* We're not adding any time, no need to send an early reply
                    (e.g. maybe at adaptive_max) */
-                CDEBUG(D_ADAPTTO, "x"LPU64": Couldn't add any time (%ld/%ld), "
+                CDEBUG(D_ADAPTTO, "x"LPU64": Couldn't add any time ("
+                       CFS_DURATION_T"/"CFS_DURATION_T"), "
                        "not sending early reply\n", req->rq_xid, olddl,
-                       newdl - cfs_time_current_sec());
+                       cfs_time_sub(newdl, cfs_time_current_sec()));
                 RETURN(-ETIMEDOUT);
         }
 
@@ -1000,8 +1001,9 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service *svc)
 
         /* req_in handling should/must be fast */
         if (cfs_time_current_sec() - req->rq_arrival_time.tv_sec > 5)
-                DEBUG_REQ(D_WARNING, req, "Slow req_in handling %lus",
-                          cfs_time_current_sec() - req->rq_arrival_time.tv_sec);
+                DEBUG_REQ(D_WARNING, req, "Slow req_in handling "CFS_DURATION_T"s",
+                          cfs_time_sub(cfs_time_current_sec(),
+                                       req->rq_arrival_time.tv_sec));
 
         /* Set rpc server deadline and add it to the timed list */
         deadline = (lustre_msghdr_get_flags(req->rq_reqmsg) &
@@ -1112,11 +1114,12 @@ ptlrpc_server_handle_request(struct ptlrpc_service *svc,
            The deadline is increased if we send an early reply. */
         if (cfs_time_current_sec() > request->rq_deadline) {
                 DEBUG_REQ(D_ERROR, request, "Dropping timed-out request from %s"
-                          ": deadline %ld%+lds ago\n",
+                          ": deadline "CFS_DURATION_T":"CFS_DURATION_T"s ago\n",
                           libcfs_id2str(request->rq_peer),
-                          request->rq_deadline -
-                          request->rq_arrival_time.tv_sec,
-                          cfs_time_current_sec() - request->rq_deadline);
+                          cfs_time_sub(request->rq_deadline,
+                          request->rq_arrival_time.tv_sec),
+                          cfs_time_sub(cfs_time_current_sec(),
+                          request->rq_deadline));
                 goto put_rpc_export;
         }
 
@@ -1160,10 +1163,12 @@ put_conn:
 
         if (unlikely(cfs_time_current_sec() > request->rq_deadline)) {
                 DEBUG_REQ(D_WARNING, request, "Request x"LPU64" took longer "
-                          "than estimated (%ld%+lds); client may timeout.",
-                          request->rq_xid, request->rq_deadline -
-                          request->rq_arrival_time.tv_sec,
-                          cfs_time_current_sec() - request->rq_deadline);
+                          "than estimated ("CFS_DURATION_T":"CFS_DURATION_T"s);"
+                          " client may timeout.",
+                          request->rq_xid, cfs_time_sub(request->rq_deadline,
+                          request->rq_arrival_time.tv_sec),
+                          cfs_time_sub(cfs_time_current_sec(),
+                          request->rq_deadline));
         }
 
         do_gettimeofday(&work_end);
@@ -1189,9 +1194,11 @@ put_conn:
         }
         if (unlikely(request->rq_early_count)) {
                 DEBUG_REQ(D_ADAPTTO, request,
-                          "sent %d early replies before finishing in %lds",
+                          "sent %d early replies before finishing in "
+                          CFS_DURATION_T"s",
                           request->rq_early_count,
-                          work_end.tv_sec - request->rq_arrival_time.tv_sec);
+                          cfs_time_sub(work_end.tv_sec,
+                          request->rq_arrival_time.tv_sec));
         }
 
 out_req: