diff --git a/lnet/archdep.m4 b/lnet/archdep.m4
index 3bdaf3220c2cc34e113f6d73e929edeee1f0927b..7801957e6988f36052160374de98e0638e804585 100644
--- a/lnet/archdep.m4
+++ b/lnet/archdep.m4
@@ -133,8 +133,8 @@ case ${host_cpu} in
 
 	powerpc )
 	AC_MSG_RESULT($host_cpu)
-        KCFLAGS='-O2 -Wall -Wstrict-prototypes -Wno-trigraphs -fomit-frame-pointer -fno-strict-aliasing -fno-common -D__powerpc__ -fsigned-char -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring'
-        KCPPFLAGS='-D__KERNEL__'
+        KCFLAGS='-O2 -g -Wall -Wstrict-prototypes -Wno-trigraphs -fomit-frame-pointer -fno-strict-aliasing -fno-common -D__powerpc__ -fsigned-char -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring'
+        KCPPFLAGS='-D__KERNEL__ -DMODULE'
         MOD_LINK=elf32ppclinux
 ;;
 
@@ -338,6 +338,18 @@ AC_SUBST(MOD_LINK)
 AC_SUBST(LINUX25)
 AM_CONDITIONAL(LIBLUSTRE, test x$host_cpu = xlib)
 
+# ---------- Red Hat 2.4.18 has iobuf->dovary --------------
+# But other kernels don't
+
+AC_MSG_CHECKING([if struct kiobuf has a dovary field])
+AC_TRY_COMPILE([#define __KERNEL__
+		#include <linux/iobuf.h>],
+	       [struct kiobuf iobuf;
+		iobuf.dovary = 1;],
+	       [AC_MSG_RESULT([yes])
+                CPPFLAGS="$CPPFLAGS -DHAVE_KIOBUF_DOVARY"],
+	       [AC_MSG_RESULT([no])])
+
 # ---------- Red Hat 2.4.20 backports some 2.5 bits --------
 # This needs to run after we've defined the KCPPFLAGS
 
diff --git a/lnet/include/lnet/types.h b/lnet/include/lnet/types.h
index 7ffe797b1a4119fcc8814e1cf69f37fb66847f6c..ccce5d5c915dd286583f22a0e560ad0c70d54ce5 100644
--- a/lnet/include/lnet/types.h
+++ b/lnet/include/lnet/types.h
@@ -1,21 +1,20 @@
 #ifndef _P30_TYPES_H_
 #define _P30_TYPES_H_
 
-#ifdef __linux__
+#ifdef __KERNEL__
+# include <linux/time.h>
 # include <asm/types.h>
 # include <asm/timex.h>
-#else
+#else /* !__KERNEL__ */
 # include <sys/types.h>
+# include <sys/time.h>
 typedef u_int32_t __u32;
 typedef u_int64_t __u64;
-#endif
-
-#ifdef __KERNEL__
-# include <linux/time.h>
-#else
-# include <sys/time.h>
 # define do_gettimeofday(tv) gettimeofday(tv, NULL)
-#endif
+# ifndef cycles_t
+typedef unsigned long cycles_t;
+# endif
+#endif /* !__KERNEL__ */
 
 #include <portals/errno.h>
 
@@ -129,7 +128,7 @@ typedef struct {
         struct timeval     arrival_time;
 
         volatile ptl_seq_t sequence;
-} ptl_event_t;
+} __attribute__((packed)) ptl_event_t;
 #ifdef __CYGWIN__
 #pragma pop
 #endif
diff --git a/lnet/klnds/socklnd/socklnd.h b/lnet/klnds/socklnd/socklnd.h
index 2767c41311ca9210a5eaf097cf33a979e10b6be1..db8c8428a1328488418de6cb811fcb0dc6b41b01 100644
--- a/lnet/klnds/socklnd/socklnd.h
+++ b/lnet/klnds/socklnd/socklnd.h
@@ -44,6 +44,7 @@
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
+#include <asm/irq.h>
 
 #include <linux/init.h>
 #include <linux/fs.h>
diff --git a/lnet/utils/Makefile.am b/lnet/utils/Makefile.am
index 6c31b3d2a199d6ab801fc64d8a74e2982b7ba1a4..925406f9d2f0e2994407a542bcf4a8d6c30424a6 100644
--- a/lnet/utils/Makefile.am
+++ b/lnet/utils/Makefile.am
@@ -26,11 +26,11 @@ libptlctl_a_SOURCES = portals.c debug.c l_ioctl.c parser.c parser.h
 gmnalnid_SOURCES = gmnalnid.c
 
 ptlctl_SOURCES = ptlctl.c
-ptlctl_LDADD =  -L. -lptlctl -lncurses # -lefence
+ptlctl_LDADD =  -L. -lptlctl $(LIBREADLINE) $(LIBEFENCE)
 ptlctl_DEPENDENCIES = libptlctl.a
 
 debugctl_SOURCES = debugctl.c
-debugctl_LDADD = -L. -lptlctl -lncurses # -lefence
+debugctl_LDADD = -L. -lptlctl $(LIBREADLINE) $(LIBEFENCE)
 debugctl_DEPENDENCIES = libptlctl.a
 
 routerstat_SOURCES = routerstat.c
diff --git a/lustre/include/linux/lustre_cfg.h b/lustre/include/linux/lustre_cfg.h
index d8c84be157efb29286a4c5be85c0e05762fafc11..4f230d2cbcafda344ae5097b0a0d03bb942a6145 100644
--- a/lustre/include/linux/lustre_cfg.h
+++ b/lustre/include/linux/lustre_cfg.h
@@ -119,8 +119,6 @@ static inline int lustre_cfg_pack(struct lustre_cfg *data, char **pbuf,
                 LOGL(data->lcfg_inlbuf3, data->lcfg_inllen3, ptr);
         if (data->lcfg_inlbuf4)
                 LOGL(data->lcfg_inlbuf4, data->lcfg_inllen4, ptr);
-//        if (lustre_cfg_is_invalid(overlay))
-//                return 1;
 
 	*plen = len;
 
@@ -200,14 +198,11 @@ static inline int lustre_cfg_getdata(char **buf, int len, void *arg, int kernel)
         lcfg = (struct lustre_cfg *)*buf;
 
         if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) {
-                CERROR("Version mismatch kernel vs application\n");
+                CERROR("Version mismatch kernel: %#x application: %#x\n",
+                       LUSTRE_CFG_VERSION, lcfg->lcfg_version);
                 return -EINVAL;
         }
 
-//        if (lustre_cfg_is_invalid(data)) {
-//                CERROR("ioctl not correctly formatted\n");
-//                return -EINVAL;
-//        }
 
         if (lcfg->lcfg_dev_name) {
                 lcfg->lcfg_dev_name = &lcfg->lcfg_bulk[0];
diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c
index 886097f46df4911b4a53943c513e6bbb438194de..660271326eccbc3e423a2639e3c6a4d5c433bdd5 100644
--- a/lustre/ldlm/ldlm_lockd.c
+++ b/lustre/ldlm/ldlm_lockd.c
@@ -37,6 +37,7 @@
 
 #include <linux/lustre_dlm.h>
 #include <linux/obd_class.h>
+#include <portals/list.h>
 #include "ldlm_internal.h"
 
 extern kmem_cache_t *ldlm_resource_slab;
diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c
index c17ad638be6cf9a6c201beffa3a03fb79f7bcbe3..c9cf11918f95feb2e320649db6b0734f6809559a 100644
--- a/lustre/llite/llite_lib.c
+++ b/lustre/llite/llite_lib.c
@@ -462,7 +462,14 @@ int lustre_process_log(struct lustre_mount_data *lmd, char * profile,
         exp = class_conn2export(&mdc_conn);
 
         ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
+#if 1
         rc = class_config_parse_llog(ctxt, profile, cfg);
+#else
+        /*
+         * For debugging, it's useful to just dump the log
+         */
+        rc = class_config_dump_llog(ctxt, profile, cfg);
+#endif
         if (rc) {
                 CERROR("class_config_parse_llog failed: rc = %d\n", rc);
         }
diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c
index c692defa1d2799b14796aca063a40ce2e2479311..e1c3fedc21ad1adfb2df4e79398ab8cf3a21407d 100644
--- a/lustre/mdc/mdc_request.c
+++ b/lustre/mdc/mdc_request.c
@@ -507,6 +507,11 @@ int mdc_close(struct obd_export *exp, struct obdo *obdo,
                         CERROR("Unexpected: can't find mdc_open_data, but the "
                                "close succeeded.  Please tell CFS.\n");
                 }
+                if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
+                                        lustre_swab_mds_body)) {
+                        CERROR("Error unpacking mds_body\n");
+                        rc = -EPROTO;
+                }
         }
         if (req->rq_async_args.pointer_arg[0] != NULL) {
                 CERROR("returned without dropping rpc_lock: rc %d\n", rc);
diff --git a/lustre/mds/mds_open.c b/lustre/mds/mds_open.c
index 8d49420737d6d6546b4d15bd78097dbaa34563ce..e959402a94dab511d160a24bd7fc033c8a14dcb9 100644
--- a/lustre/mds/mds_open.c
+++ b/lustre/mds/mds_open.c
@@ -28,6 +28,7 @@
 #endif
 #define DEBUG_SUBSYSTEM S_MDS
 
+#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/version.h>
diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c
index 9156dc8be6a53b3ee436d3fa577b3489ed5341af..41f2258d75b88210c015dc4a3b4ac69fcc5c0112 100644
--- a/lustre/obdclass/obd_config.c
+++ b/lustre/obdclass/obd_config.c
@@ -545,7 +545,7 @@ static int class_config_llog_handler(struct llog_handle * handle,
         int cfg_len = rec->lrh_len;
         char *cfg_buf = (char*) (rec + 1);
         int rc = 0;
-
+        ENTRY;
         if (rec->lrh_type == OBD_CFG_REC) {
                 char *buf;
                 struct lustre_cfg *lcfg;
@@ -641,7 +641,7 @@ static int class_config_dump_handler(struct llog_handle * handle,
         int cfg_len = rec->lrh_len;
         char *cfg_buf = (char*) (rec + 1);
         int rc = 0;
-
+        ENTRY;
         if (rec->lrh_type == OBD_CFG_REC) {
                 char *buf;
                 struct lustre_cfg *lcfg;
@@ -702,6 +702,9 @@ static int class_config_dump_handler(struct llog_handle * handle,
                 if (pcfg->pcfg_flags)
                         CDEBUG(D_INFO, "       flags: %x\n",
                                pcfg->pcfg_flags);
+        } else {
+                CERROR("unhandled lrh_type: %#x\n", rec->lrh_type);
+                rc = -EINVAL;
         }
 out:
         RETURN(rc);
diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c
index 5d9b641a93eef0e2676ab5e9290425cf5dd26902..e90fb45772cb72a564d5d9b8b5b609a8abd7a4df 100644
--- a/lustre/obdfilter/filter.c
+++ b/lustre/obdfilter/filter.c
@@ -53,6 +53,7 @@
 #include <linux/lprocfs_status.h>
 #include <linux/lustre_log.h>
 #include <linux/lustre_commit_confd.h>
+#include <portals/list.h>
 
 #include "filter_internal.h"
 
diff --git a/lustre/obdfilter/filter_io_24.c b/lustre/obdfilter/filter_io_24.c
index 6ab28dbe7e3a8c3adc3342bb163a6e8116b43bf9..15ac8e9d15389f996c54a5dc044293e9b9f10a49 100644
--- a/lustre/obdfilter/filter_io_24.c
+++ b/lustre/obdfilter/filter_io_24.c
@@ -251,7 +251,7 @@ int filter_commitrw_write(struct obd_export *exp, struct obdo *oa, int objcount,
                 GOTO(cleanup, rc);
         cleanup_phase = 1;
 
-#if (LINUX_VERSION_CODE == KERNEL_VERSION(2,4,18))
+#ifdef HAVE_KIOBUF_DOVARY
         iobuf->dovary = 0; /* this prevents corruption, not present in 2.4.20 */
 #endif
         rc = expand_kiobuf(iobuf, obj->ioo_bufcnt);
diff --git a/lustre/portals/archdep.m4 b/lustre/portals/archdep.m4
index 3bdaf3220c2cc34e113f6d73e929edeee1f0927b..7801957e6988f36052160374de98e0638e804585 100644
--- a/lustre/portals/archdep.m4
+++ b/lustre/portals/archdep.m4
@@ -133,8 +133,8 @@ case ${host_cpu} in
 
 	powerpc )
 	AC_MSG_RESULT($host_cpu)
-        KCFLAGS='-O2 -Wall -Wstrict-prototypes -Wno-trigraphs -fomit-frame-pointer -fno-strict-aliasing -fno-common -D__powerpc__ -fsigned-char -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring'
-        KCPPFLAGS='-D__KERNEL__'
+        KCFLAGS='-O2 -g -Wall -Wstrict-prototypes -Wno-trigraphs -fomit-frame-pointer -fno-strict-aliasing -fno-common -D__powerpc__ -fsigned-char -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring'
+        KCPPFLAGS='-D__KERNEL__ -DMODULE'
         MOD_LINK=elf32ppclinux
 ;;
 
@@ -338,6 +338,18 @@ AC_SUBST(MOD_LINK)
 AC_SUBST(LINUX25)
 AM_CONDITIONAL(LIBLUSTRE, test x$host_cpu = xlib)
 
+# ---------- Red Hat 2.4.18 has iobuf->dovary --------------
+# But other kernels don't
+
+AC_MSG_CHECKING([if struct kiobuf has a dovary field])
+AC_TRY_COMPILE([#define __KERNEL__
+		#include <linux/iobuf.h>],
+	       [struct kiobuf iobuf;
+		iobuf.dovary = 1;],
+	       [AC_MSG_RESULT([yes])
+                CPPFLAGS="$CPPFLAGS -DHAVE_KIOBUF_DOVARY"],
+	       [AC_MSG_RESULT([no])])
+
 # ---------- Red Hat 2.4.20 backports some 2.5 bits --------
 # This needs to run after we've defined the KCPPFLAGS
 
diff --git a/lustre/portals/include/portals/types.h b/lustre/portals/include/portals/types.h
index 7ffe797b1a4119fcc8814e1cf69f37fb66847f6c..ccce5d5c915dd286583f22a0e560ad0c70d54ce5 100644
--- a/lustre/portals/include/portals/types.h
+++ b/lustre/portals/include/portals/types.h
@@ -1,21 +1,20 @@
 #ifndef _P30_TYPES_H_
 #define _P30_TYPES_H_
 
-#ifdef __linux__
+#ifdef __KERNEL__
+# include <linux/time.h>
 # include <asm/types.h>
 # include <asm/timex.h>
-#else
+#else /* !__KERNEL__ */
 # include <sys/types.h>
+# include <sys/time.h>
 typedef u_int32_t __u32;
 typedef u_int64_t __u64;
-#endif
-
-#ifdef __KERNEL__
-# include <linux/time.h>
-#else
-# include <sys/time.h>
 # define do_gettimeofday(tv) gettimeofday(tv, NULL)
-#endif
+# ifndef cycles_t
+typedef unsigned long cycles_t;
+# endif
+#endif /* !__KERNEL__ */
 
 #include <portals/errno.h>
 
@@ -129,7 +128,7 @@ typedef struct {
         struct timeval     arrival_time;
 
         volatile ptl_seq_t sequence;
-} ptl_event_t;
+} __attribute__((packed)) ptl_event_t;
 #ifdef __CYGWIN__
 #pragma pop
 #endif
diff --git a/lustre/portals/knals/socknal/socknal.h b/lustre/portals/knals/socknal/socknal.h
index 2767c41311ca9210a5eaf097cf33a979e10b6be1..db8c8428a1328488418de6cb811fcb0dc6b41b01 100644
--- a/lustre/portals/knals/socknal/socknal.h
+++ b/lustre/portals/knals/socknal/socknal.h
@@ -44,6 +44,7 @@
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
+#include <asm/irq.h>
 
 #include <linux/init.h>
 #include <linux/fs.h>
diff --git a/lustre/portals/utils/Makefile.am b/lustre/portals/utils/Makefile.am
index 6c31b3d2a199d6ab801fc64d8a74e2982b7ba1a4..925406f9d2f0e2994407a542bcf4a8d6c30424a6 100644
--- a/lustre/portals/utils/Makefile.am
+++ b/lustre/portals/utils/Makefile.am
@@ -26,11 +26,11 @@ libptlctl_a_SOURCES = portals.c debug.c l_ioctl.c parser.c parser.h
 gmnalnid_SOURCES = gmnalnid.c
 
 ptlctl_SOURCES = ptlctl.c
-ptlctl_LDADD =  -L. -lptlctl -lncurses # -lefence
+ptlctl_LDADD =  -L. -lptlctl $(LIBREADLINE) $(LIBEFENCE)
 ptlctl_DEPENDENCIES = libptlctl.a
 
 debugctl_SOURCES = debugctl.c
-debugctl_LDADD = -L. -lptlctl -lncurses # -lefence
+debugctl_LDADD = -L. -lptlctl $(LIBREADLINE) $(LIBEFENCE)
 debugctl_DEPENDENCIES = libptlctl.a
 
 routerstat_SOURCES = routerstat.c