diff --git a/lustre/include/linux/lustre_idl.h b/lustre/include/linux/lustre_idl.h
index 75de35d3276b1b25a4c26fed1011f0148cd0f5df..9e4d842554f1ea6ab5dc38cb99b2b5deb2c0d575 100644
--- a/lustre/include/linux/lustre_idl.h
+++ b/lustre/include/linux/lustre_idl.h
@@ -28,41 +28,21 @@
 #include <asm/types.h>
 
 #include <linux/types.h>
-#else 
+#else
 #define __KERNEL__
 #include <linux/list.h>
 #undef __KERNEL__
 #include <stdint.h>
 #endif
-/* 
+/*
  * this file contains all data structures used in Lustre interfaces:
  * - obdo and obd_request records
  * - mds_request records
  * - ldlm data
  * - ioctl's
- */ 
-
-struct lustre_msg { 
-        __u32 opc;
-        __u32 xid;
-        __u32 status;
-        __u32 type;
-        __u32   connid;
-        __u32   bufcount;
-        __u32   buflens[0];
-};
-
-struct ptlreq_hdr { 
-        __u32 opc;
-        __u32 xid;
-        __u32 status;
-        __u32 type;
-        __u32   connid;
-        __u32   bufcount;
-        __u32   buflens[0];
-};
+ */
 
-struct ptlrep_hdr { 
+struct lustre_msg {
         __u32 opc;
         __u32 xid;
         __u32 status;
@@ -72,7 +52,7 @@ struct ptlrep_hdr {
         __u32   buflens[0];
 };
 
-/* 
+/*
  *   OST requests: OBDO & OBD request records
  */
 
@@ -104,7 +84,7 @@ typedef uint32_t        obd_rdev;
 typedef uint32_t        obd_flag;
 typedef uint32_t        obd_count;
 
-#define OBD_FL_INLINEDATA       (0x00000001UL)  
+#define OBD_FL_INLINEDATA       (0x00000001UL)
 #define OBD_FL_OBDMDEXISTS      (0x00000002UL)
 
 #define OBD_INLINESZ    60
@@ -158,31 +138,20 @@ struct obdo {
 
 #define OST_REQ_HAS_OA1  0x1
 
-struct ost_req { 
+struct ost_body {
         __u32   connid;
-        __u32   cmd; 
+        __u32   data;
         struct  obdo oa;
-        __u32   buflen1;
-        __u32   buflen2;
 };
 
-struct ost_rep {
-        __u32   result;
-        __u32   connid;
-        struct  obdo oa;
-        __u32   buflen1;
-        __u32   buflen2;
-};
-
-struct obd_ioobj { 
+struct obd_ioobj {
         obd_id    ioo_id;
         obd_gr    ioo_gr;
         __u32     ioo_type;
         __u32     ioo_bufcnt;
 };
 
-
-/* 
+/*
  *   MDS REQ RECORDS
  */
 
@@ -192,81 +161,54 @@ struct obd_ioobj {
 #define MDS_REINT     4
 #define MDS_READPAGE  5
 
-#define REINT_SETATTR 0
-#define REINT_CREATE  1
-#define REINT_LINK    2
-#define REINT_UNLINK  3
-#define REINT_RENAME  4
-#define REINT_MAX     4
+#define REINT_SETATTR 1
+#define REINT_CREATE  2
+#define REINT_LINK    3
+#define REINT_UNLINK  4
+#define REINT_RENAME  5
+#define REINT_MAX     5
 
-struct ll_fid { 
+struct ll_fid {
         __u64 id;
         __u32 generation;
         __u32 f_type;
 };
 
-struct niobuf { 
+struct niobuf {
         __u64 addr;
-        __u64 offset; 
+        __u64 offset;
         __u32 len;
         __u32 flags;
         __u32 xid;
         void *page;
 };
 
-struct mds_req {
-        struct ll_fid        fid1;
-        struct ll_fid        fid2;
-        __u32                       namelen;
-        __u32                       tgtlen;
-        __u32                       opcode;
-        __u32                       valid;
-        __u32                       mode;
-        __u32                       uid;
-        __u32                       gid;
-        __u64                       objid;
-        __u64                       size;
-        __u32                       mtime;
-        __u32                       ctime;
-        __u32                       atime;
-        __u32                       flags;
-        __u32                       major;
-        __u32                       minor;
-        __u32                       ino;
-        __u32                       nlink;
-        __u32                       generation;
+struct mds_body {
+        struct ll_fid  fid1;
+        struct ll_fid  fid2;
+        __u64          objid;
+        __u64          size;
+        __u32          valid;
+        __u32          mode;
+        __u32          uid;
+        __u32          gid;
+        __u32          mtime;
+        __u32          ctime;
+        __u32          atime;
+        __u32          flags;
+        __u32          major;
+        __u32          minor;
+        __u32          ino;
+        __u32          nlink;
+        __u32          generation;
 };
 
-struct mds_rep {
-        struct ll_fid               fid1;
-        struct ll_fid               fid2;
-        __u32                       namelen;
-        __u32                       tgtlen;
-        __u32                       valid;
-        __u32                       mode;
-        __u32                       uid;
-        __u32                       gid;
-        __u64                       objid;
-        __u64                       size;
-        __u32                       mtime;
-        __u32                       ctime;
-        __u32                       atime;
-        __u32                       flags;
-        __u32                       major;
-        __u32                       minor;
-        __u32                       ino;
-        __u32                       nlink;
-        __u32                       generation;
-};
-
-/* MDS update records */ 
-struct mds_update_record_hdr { 
-        __u32 ur_reclen;
+/* MDS update records */
+struct mds_update_record_hdr {
         __u32 ur_opcode;
 };
 
-struct mds_rec_setattr { 
-        __u32           sa_reclen;
+struct mds_rec_setattr {
         __u32           sa_opcode;
         struct ll_fid   sa_fid;
         __u32           sa_valid;
@@ -280,48 +222,36 @@ struct mds_rec_setattr {
         __u32           sa_attr_flags;
 };
 
-struct mds_rec_create { 
-        __u32           cr_reclen;
+struct mds_rec_create {
         __u32           cr_opcode;
         struct ll_fid   cr_fid;
         __u32           cr_uid;
         __u32           cr_gid;
         __u64           cr_time;
         __u32           cr_mode;
-        /* overloaded: id for create, tgtlen for symlink, rdev for mknod */ 
-        __u64           cr_id; 
-        __u32           cr_namelen;
-        __u32           cr_tgtlen;
-        /* name here */
-        /* symlink target here */ 
+        /* overloaded: id for create, tgtlen for symlink, rdev for mknod */
+        __u64           cr_id;
 };
 
-struct mds_rec_link { 
-        __u32           lk_reclen;
+struct mds_rec_link {
         __u32           lk_opcode;
         struct ll_fid   lk_fid1;
         struct ll_fid   lk_fid2;
-        __u32           lk_namelen;
 };
 
-struct mds_rec_unlink { 
-        __u32           ul_reclen;
+struct mds_rec_unlink {
         __u32           ul_opcode;
         struct ll_fid   ul_fid1;
         struct ll_fid   ul_fid2;
-        __u32           ul_namelen;
 };
 
-struct mds_rec_rename { 
-        __u32           rn_reclen;
+struct mds_rec_rename {
         __u32           rn_opcode;
         struct ll_fid   rn_fid1;
         struct ll_fid   rn_fid2;
-        __u32           rn_namelen;
-        __u32           rn_tgtlen;
 };
 
-#ifdef __KERNEL__ 
+#ifdef __KERNEL__
 
 static inline void ll_ino2fid(struct ll_fid *fid, ino_t ino, __u32 generation,
                               int type)
@@ -337,9 +267,9 @@ static inline void ll_inode2fid(struct ll_fid *fid, struct inode *inode)
                    inode->i_mode & S_IFMT);
 }
 
-#endif 
+#endif
 
-/* 
+/*
  *   LDLM requests:
  */
 
@@ -387,14 +317,14 @@ struct ldlm_reply {
         struct ldlm_handle lock_handle;
 };
 
-/* 
+/*
  *   OBD IOCTLS
  */
 
 
 #define OBD_IOCTL_VERSION 0x00010001
 
-struct obd_ioctl_data { 
+struct obd_ioctl_data {
         uint32_t ioc_len;
         uint32_t ioc_version;
         uint32_t ioc_conn1;
@@ -420,7 +350,7 @@ struct obd_ioctl_data {
         char    ioc_bulk[0];
 };
 
-struct obd_ioctl_hdr { 
+struct obd_ioctl_hdr {
         uint32_t ioc_len;
         uint32_t ioc_version;
 };
@@ -435,15 +365,15 @@ static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
 
 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
 {
-        if (data->ioc_len > (1<<30)) { 
+        if (data->ioc_len > (1<<30)) {
                 printk("OBD ioctl: ioc_len larger than 1<<30\n");
                 return 1;
         }
-        if (data->ioc_inllen1 > (1<<30)) { 
+        if (data->ioc_inllen1 > (1<<30)) {
                 printk("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
                 return 1;
         }
-        if (data->ioc_inllen2 > (1<<30)) { 
+        if (data->ioc_inllen2 > (1<<30)) {
                 printk("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
                 return 1;
         }
@@ -485,13 +415,13 @@ static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
                 printk("OBD ioctl: packlen exceeds ioc_len\n");
                 return 1;
         }
-        if (data->ioc_inllen1 && 
-            data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') { 
+        if (data->ioc_inllen1 &&
+            data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
                 printk("OBD ioctl: inlbuf1 not 0 terminated\n");
                 return 1;
         }
-        if (data->ioc_inllen2 && 
-            data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') { 
+        if (data->ioc_inllen2 &&
+            data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2 - 1] != '\0') {
                 printk("OBD ioctl: inlbuf2 not 0 terminated\n");
                 return 1;
         }
@@ -507,9 +437,9 @@ static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf,
         data->ioc_len = obd_ioctl_packlen(data);
         data->ioc_version = OBD_IOCTL_VERSION;
 
-        if (*pbuf && obd_ioctl_packlen(data) > max) 
+        if (*pbuf && obd_ioctl_packlen(data) > max)
                 return 1;
-        if (*pbuf == NULL) { 
+        if (*pbuf == NULL) {
                 *pbuf = malloc(data->ioc_len);
         }
         if (!*pbuf)
@@ -547,18 +477,18 @@ static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
                 return err;
         }
 
-        if (hdr->ioc_version != OBD_IOCTL_VERSION) { 
+        if (hdr->ioc_version != OBD_IOCTL_VERSION) {
                 printk("OBD: version mismatch kernel vs application\n");
                 return -EINVAL;
         }
 
-        if (hdr->ioc_len + buf >= end) { 
+        if (hdr->ioc_len + buf >= end) {
                 printk("OBD: user buffer exceeds kernel buffer\n");
                 return -EINVAL;
         }
 
 
-        if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) { 
+        if (hdr->ioc_len < sizeof(struct obd_ioctl_data)) {
                 printk("OBD: user buffer too small for ioctl\n");
                 return -EINVAL;
         }
@@ -569,16 +499,16 @@ static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
                 return err;
         }
 
-        if (obd_ioctl_is_invalid(data)) { 
+        if (obd_ioctl_is_invalid(data)) {
                 printk("OBD: ioctl not correctly formatted\n");
                 return -EINVAL;
         }
 
-        if (data->ioc_inllen1) { 
+        if (data->ioc_inllen1) {
                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
         }
 
-        if (data->ioc_inllen2) { 
+        if (data->ioc_inllen2) {
                 data->ioc_inlbuf2 = &data->ioc_bulk[0] + size_round(data->ioc_inllen1);
         }
 
@@ -617,18 +547,4 @@ static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
 
 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
 
-
-/* GENERAL THINGS */
-union ptl_rep { 
-        struct mds_rep *mds;
-        struct ost_rep *ost;
-        struct lustre_msg *lustre;
-};
-
-union ptl_req { 
-        struct mds_req *mds;
-        struct ost_req *ost;
-        struct lustre_msg *lustre;
-};
-
 #endif
diff --git a/lustre/include/linux/lustre_mds.h b/lustre/include/linux/lustre_mds.h
index 692aebc704cd922fbbff7adbbca17c960f2e0289..f158be2cff1f7643bab7428d08689a35260d8f79 100644
--- a/lustre/include/linux/lustre_mds.h
+++ b/lustre/include/linux/lustre_mds.h
@@ -43,7 +43,6 @@ static inline void l_dput(struct dentry *de)
 #define LUSTRE_MDS_NAME "mds"
 
 struct mds_update_record { 
-        __u32 ur_reclen;
         __u32 ur_opcode;
         struct ll_fid *ur_fid1;
         struct ll_fid *ur_fid2;
@@ -59,24 +58,22 @@ struct mds_update_record {
         __u64 ur_time;
 }; 
 
-/* mds/mds_pack.c */
-void *mds_req_tgt(struct mds_req *req);
-int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen, struct ptlreq_hdr **hdr, union ptl_req *req, int *len, char **buf);
-int mds_unpack_req(char *buf, int len, struct ptlreq_hdr **hdr, union ptl_req *);
-int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen, struct ptlrep_hdr **hdr, union ptl_rep *rep, int *len, char **buf);
-int mds_unpack_rep(char *buf, int len, struct ptlrep_hdr **hdr, union ptl_rep *rep);
-
 /* mds/mds_reint.c  */
 int mds_reint_rec(struct mds_update_record *r, struct ptlrpc_request *req); 
 
 /* lib/mds_updates.c */
-int mds_update_unpack(char *buf, int len, struct mds_update_record *r); 
-
-void mds_setattr_pack(struct mds_rec_setattr *rec, struct inode *inode, struct iattr *iattr);
-void mds_create_pack(struct mds_rec_create *rec, struct inode *inode, const char *name, int namelen, __u32 mode, __u64 id, __u32 uid, __u32 gid, __u64 time, const char *tgt, int tgtlen);
-void mds_unlink_pack(struct mds_rec_unlink *rec, struct inode *inode, struct inode *child, const char *name, int namelen);
-void mds_link_pack(struct mds_rec_link *rec, struct inode *inode, struct inode *dir, const char *name, int namelen);
-void mds_rename_pack(struct mds_rec_rename *rec, struct inode *srcdir, struct inode *tgtdir, const char *name, int namelen, const char *tgt, int tgtlen);
+void mds_pack_body(struct ptlrpc_request *);
+void mds_unpack_body(struct ptlrpc_request *);
+int mds_update_unpack(struct ptlrpc_request *, struct mds_update_record *);
+
+void mds_setattr_pack(struct mds_rec_setattr *, struct inode *, struct iattr *);
+void mds_create_pack(struct mds_rec_create *, struct inode *,  __u32 mode,
+                     __u64 id, __u32 uid, __u32 gid, __u64 time);
+void mds_unlink_pack(struct mds_rec_unlink *, struct inode *inode,
+                     struct inode *child);
+void mds_link_pack(struct mds_rec_link *, struct inode *ino, struct inode *dir);
+void mds_rename_pack(struct mds_rec_rename *, struct inode *srcdir,
+                     struct inode *tgtdir);
 
 /* mds/handler.c */
 struct dentry *mds_fid2dentry(struct mds_obd *mds, struct ll_fid *fid, struct vfsmount **mnt);
diff --git a/lustre/include/linux/lustre_net.h b/lustre/include/linux/lustre_net.h
index cf2d56985f7bde710192e041a729d0ce3605bf17..238468571da387fb3d169112d94f3d77ebeba18b 100644
--- a/lustre/include/linux/lustre_net.h
+++ b/lustre/include/linux/lustre_net.h
@@ -64,23 +64,11 @@
 #define SVC_LIST   32
 #define SVC_SIGNAL 64
 
-typedef int (*rep_unpack_t)(char *, int, struct ptlrep_hdr **, union ptl_rep *);
-typedef int (*req_pack_t)(char *, int, char *, int, struct ptlreq_hdr **,
-                          union ptl_req*, int *, char **); 
-
-typedef int (*req_unpack_t)(char *buf, int len, struct ptlreq_hdr **, 
-                            union ptl_req *);
-typedef int (*rep_pack_t)(char *buf1, int len1, char *buf2, int len2,
-                          struct ptlrep_hdr **, union ptl_rep*, 
-                          int *replen, char **repbuf); 
-
 struct ptlrpc_client {
         struct lustre_peer cli_server;
         struct obd_device *cli_obd;
         __u32 cli_request_portal;
         __u32 cli_reply_portal;
-        rep_unpack_t cli_rep_unpack;
-        req_pack_t cli_req_pack;
 
         spinlock_t cli_lock;
         __u32 cli_xid;
@@ -107,15 +95,13 @@ struct ptlrpc_request {
         __u32 rq_connid;
         __u32 rq_xid;
 
-        char *rq_reqbuf;
         int rq_reqlen;
-        struct ptlreq_hdr *rq_reqhdr;
-        union ptl_req rq_req;
+        char *rq_reqbuf;
+        struct lustre_msg *rq_reqmsg;
 
-        char *rq_repbuf;
         int rq_replen;
-        struct ptlrep_hdr *rq_rephdr;
-        union ptl_rep rq_rep;
+        char *rq_repbuf;
+        struct lustre_msg *rq_repmsg;
 
         char *rq_bulkbuf;
         int rq_bulklen;
@@ -183,8 +169,6 @@ struct ptlrpc_service {
         spinlock_t srv_lock;
         struct list_head srv_reqs;
         ptl_event_t  srv_ev;
-        req_unpack_t      srv_req_unpack;
-        rep_pack_t        srv_rep_pack;
         int (*srv_handler)(struct obd_device *obddev, 
                            struct ptlrpc_service *svc,
                            struct ptlrpc_request *req);
@@ -210,14 +194,12 @@ int ptl_send_rpc(struct ptlrpc_request *request, struct ptlrpc_client *cl);
 void ptlrpc_link_svc_me(struct ptlrpc_service *service, int i);
 
 /* rpc/client.c */
-int ptlrpc_connect_client(int dev, char *uuid, int req_portal, int rep_portal, 
-                          req_pack_t req_pack, rep_unpack_t rep_unpack,
+int ptlrpc_connect_client(int dev, char *uuid, int req_portal, int rep_portal,
                           struct ptlrpc_client *cl);
 int ptlrpc_queue_wait(struct ptlrpc_client *cl, struct ptlrpc_request *req);
 int ptlrpc_queue_req(struct ptlrpc_client *peer, struct ptlrpc_request *req);
-struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl, 
-                                       int opcode, int namelen, char *name,
-                                       int tgtlen, char *tgt);
+struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl, int opcode,
+                                       int count, int *lengths, char **bufs);
 void ptlrpc_free_req(struct ptlrpc_request *request);
 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct lustre_peer *);
 int ptlrpc_check_status(struct ptlrpc_request *req, int err);
@@ -237,4 +219,10 @@ struct ptlrpc_svc_data {
         struct obd_device *dev;
 }; 
 
+/* rpc/pack_generic.c */
+int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf);
+int lustre_msg_size(int count, int *lengths);
+int lustre_unpack_msg(char *buf, int len);
+void *lustre_msg_buf(struct lustre_msg *m, int n);
+
 #endif
diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h
index 04c8b5bc397f1870fdc5b405e9d863031647ed2d..d97bdba5c0079197e2fd8a2a14dba29e1cd0f3b6 100644
--- a/lustre/include/linux/obd.h
+++ b/lustre/include/linux/obd.h
@@ -1,7 +1,6 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *
  * Copyright (C) 2001  Cluster File Systems, Inc.
  *
  * This code is issued under the GNU General Public License.
@@ -27,10 +26,10 @@ struct obd_type {
         int  typ_refcnt;
 };
 
-struct obd_run_ctxt { 
-	struct vfsmount *pwdmnt;
-	struct dentry   *pwd;
-	mm_segment_t     fs;
+struct obd_run_ctxt {
+        struct vfsmount *pwdmnt;
+        struct dentry   *pwd;
+        mm_segment_t     fs;
 };
 
 struct obd_conn {
@@ -39,42 +38,42 @@ struct obd_conn {
 };
 
 struct obd_devicename {
-	uint32_t len;
-	char *   name;
+        uint32_t len;
+        char *name;
         struct dentry *dentry;   /* file system obd device names */
-        __u8           _uuid[16]; /* uuid obd device names */
+        __u8 _uuid[16];          /* uuid obd device names */
 };
 
 
 /* Individual type definitions */
 
 struct ext2_obd {
-        struct super_block * e2_sb;
-	struct vfsmount *e2_vfsmnt;
+        struct super_block *e2_sb;
+        struct vfsmount *e2_vfsmnt;
 };
 
 struct filter_obd {
-	char *fo_fstype;
-        struct super_block * fo_sb;
-	struct vfsmount *fo_vfsmnt;
-	struct obd_run_ctxt fo_ctxt;
-	spinlock_t fo_lock;
-	__u64 fo_lastino;
-	struct file_operations *fo_fop; 
-	struct inode_operations *fo_iop;
-	struct address_space_operations *fo_aops;
+        char *fo_fstype;
+        struct super_block *fo_sb;
+        struct vfsmount *fo_vfsmnt;
+        struct obd_run_ctxt fo_ctxt;
+        spinlock_t fo_lock;
+        __u64 fo_lastino;
+        struct file_operations *fo_fop;
+        struct inode_operations *fo_iop;
+        struct address_space_operations *fo_aops;
 };
 
 struct mds_obd {
         struct ptlrpc_service *mds_service;
 
-	char *mds_fstype;
-        struct super_block * mds_sb;
-	struct vfsmount *mds_vfsmnt;
-	struct obd_run_ctxt mds_ctxt;
-	struct file_operations *mds_fop; 
-	struct inode_operations *mds_iop;
-	struct address_space_operations *mds_aops;
+        char *mds_fstype;
+        struct super_block *mds_sb;
+        struct vfsmount *mds_vfsmnt;
+        struct obd_run_ctxt mds_ctxt;
+        struct file_operations *mds_fop;
+        struct inode_operations *mds_iop;
+        struct address_space_operations *mds_aops;
         struct mds_fs_operations *mds_fsops;
 };
 
@@ -86,15 +85,15 @@ struct ldlm_obd {
 };
 
 struct echo_obd {
-	char *eo_fstype;
+        char *eo_fstype;
         struct super_block *eo_sb;
-	struct vfsmount *eo_vfsmnt;
-	struct obd_run_ctxt eo_ctxt;
-	spinlock_t eo_lock;
-	__u64 eo_lastino;
-	struct file_operations *eo_fop; 
-	struct inode_operations *eo_iop;
-	struct address_space_operations *eo_aops;
+        struct vfsmount *eo_vfsmnt;
+        struct obd_run_ctxt eo_ctxt;
+        spinlock_t eo_lock;
+        __u64 eo_lastino;
+        struct file_operations *eo_fop;
+        struct inode_operations *eo_iop;
+        struct address_space_operations *eo_aops;
 };
 
 struct trace_obd {
@@ -103,8 +102,8 @@ struct trace_obd {
 
 #if 0
 struct snap_obd {
-	unsigned int snap_index;  /* which snapshot index are we accessing */
-	int snap_tableno;
+        unsigned int snap_index;  /* which snapshot index are we accessing */
+        int snap_tableno;
 };
 
 struct raid1_obd {
@@ -120,13 +119,13 @@ struct raid1_obd {
 struct ost_obd {
         struct ptlrpc_service *ost_service;
 
-	struct obd_device *ost_tgt;
-	struct obd_conn ost_conn;
+        struct obd_device *ost_tgt;
+        struct obd_conn ost_conn;
 };
 
 struct osc_obd {
-	struct obd_device *osc_tgt;
-        struct ptlrpc_client *osc_peer;
+        struct obd_device *osc_tgt;
+        struct ptlrpc_client *osc_client;
 };
 
 /* corresponds to one of the obd's */
@@ -135,9 +134,9 @@ struct obd_device {
         struct obd_type *obd_type;
         int obd_minor;
         int obd_flags;
-        int obd_refcnt; 
-        struct obd_devicename obd_fsname; 
-	struct proc_dir_entry *obd_proc_entry;
+        int obd_refcnt;
+        struct obd_devicename obd_fsname;
+        struct proc_dir_entry *obd_proc_entry;
         int obd_multi_count;
         struct obd_conn obd_multi_conn[MAX_MULTI];
         unsigned int obd_gen_last_id;
@@ -153,7 +152,7 @@ struct obd_device {
                 struct osc_obd osc;
                 struct ldlm_obd ldlm;
                 struct echo_obd echo;
-	        struct trace_obd trace;
+                struct trace_obd trace;
 #if 0
                 struct raid1_obd raid1;
                 struct snap_obd snap;
@@ -200,13 +199,13 @@ struct obd_ops {
                       obd_size count, obd_off offset);
         int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
                          obd_id *startid, obd_gr group, void *data);
-	int (*o_preprw)(int cmd, struct obd_conn *conn, 
-			int objcount, struct obd_ioobj *obj, 
-			int niocount, struct niobuf *nb, 
-			struct niobuf *res);
-	int (*o_commitrw)(int cmd, struct obd_conn *conn, 
-			  int objcount, struct obd_ioobj *obj, 
-			  int niocount, struct niobuf *res);
+        int (*o_preprw)(int cmd, struct obd_conn *conn,
+                        int objcount, struct obd_ioobj *obj,
+                        int niocount, struct niobuf *nb,
+                        struct niobuf *res);
+        int (*o_commitrw)(int cmd, struct obd_conn *conn,
+                          int objcount, struct obd_ioobj *obj,
+                          int niocount, struct niobuf *res);
 };
 
 #endif
diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h
index bf360184419c43f63cde1821f3d3c319cf978d85..5e47065a8bf4ff3ccf9e0bb9afdb4a0f4d96a6da 100644
--- a/lustre/include/linux/obd_class.h
+++ b/lustre/include/linux/obd_class.h
@@ -109,8 +109,8 @@ static inline int obd_check_conn(struct obd_conn *conn)
         return 0;
 }
 
-#define OBT(dev)        dev->obd_type
-#define OBP(dev,op)     dev->obd_type->typ_ops->o_ ## op
+#define OBT(dev)        (dev)->obd_type
+#define OBP(dev,op)     (dev)->obd_type->typ_ops->o_ ## op
 
 #define OBD_CHECK_SETUP(conn)                                   \
 do {                                                            \
@@ -699,9 +699,4 @@ int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
 extern void obd_sysctl_init (void);
 extern void obd_sysctl_clean (void);
 
-/* pack_generic.c */
-int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf);
-int lustre_unpack_msg(char *buf, int len);
-void *lustre_msg_buf(int n, struct lustre_msg *m);
-
 #endif /* __LINUX_CLASS_OBD_H */
diff --git a/lustre/include/linux/obd_ost.h b/lustre/include/linux/obd_ost.h
index ddfc4b7d5b9f8cad66604dddd4606995036173ac..e1c8f92bf5e7a7a9fb035c27a67ee0d2d470c4bb 100644
--- a/lustre/include/linux/obd_ost.h
+++ b/lustre/include/linux/obd_ost.h
@@ -33,21 +33,10 @@
 #define LUSTRE_OSC_NAME "osc"
 
 /* ost/ost_pack.c */
-int ost_pack_req(char *buf1, int buflen1, char *buf2, int buflen2, struct ptlreq_hdr **hdr, union ptl_req *req, int *len, char **buf);
-int ost_unpack_req(char *buf, int len, struct ptlreq_hdr **hdr, union ptl_req *req);
-int ost_pack_rep(char *buf1, int buflen1, char *buf2, int buflen2,
-		 struct ptlrep_hdr **hdr, union ptl_rep *r,
-		 int *len, char **buf);
-int ost_unpack_rep(char *buf, int len, struct ptlrep_hdr **hdr, union ptl_rep *rep);
-
 void ost_pack_niobuf(void **tmp, void *addr, __u64 offset, __u32 len, 
                      __u32 flags, __u32 xid);
 void ost_unpack_niobuf(void **tmp, struct niobuf **nbp);
 void ost_pack_ioo(void **tmp, struct obdo *oa, int bufcnt);
 void ost_unpack_ioo(void **tmp, struct obd_ioobj **ioop);
-void *ost_req_buf2(struct ost_req *req);
-void *ost_req_buf1(struct ost_req *req);
-void *ost_rep_buf2(struct ost_rep *rep);
-void *ost_rep_buf1(struct ost_rep *rep);
 
 #endif
diff --git a/lustre/ldlm/Makefile.am b/lustre/ldlm/Makefile.am
index c060a2bd1c6bf17e3bc5bf04e0d06c89a0162343..925775b2bb30e0d6c5c2f1bd32d7052275394d74 100644
--- a/lustre/ldlm/Makefile.am
+++ b/lustre/ldlm/Makefile.am
@@ -8,10 +8,8 @@ MODULE = ldlm
 modulefs_DATA = ldlm.o
 EXTRA_PROGRAMS = ldlm
 
-pack_generic.c:
-	ln -s ../lib/pack_generic.c
 ldlm_SOURCES = ldlm_lock.c ldlm_resource.c ldlm_test.c ldlm_lockd.c \
-ldlm_extent.c pack_generic.c
+ldlm_extent.c
 
 include $(top_srcdir)/Rules
 
diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c
index 5dd68e92e9bf20848a8826e8275940a3d7ec046f..b2359eb62187b80b62b703fe465aba513e9db510 100644
--- a/lustre/ldlm/ldlm_lockd.c
+++ b/lustre/ldlm/ldlm_lockd.c
@@ -36,10 +36,8 @@ static int ldlm_enqueue(struct ptlrpc_request *req)
 {
         struct ldlm_reply *dlm_rep;
         struct ldlm_request *dlm_req;
-        struct lustre_msg *msg, *req_msg;
         ldlm_error_t err;
-        int rc;
-        int bufsize = sizeof(*dlm_rep);
+        int rc, bufsize = sizeof(*dlm_rep);
         
         rc = lustre_pack_msg(1, &bufsize, NULL, &req->rq_replen,
                              &req->rq_repbuf);
@@ -48,12 +46,9 @@ static int ldlm_enqueue(struct ptlrpc_request *req)
                 req->rq_status = -ENOMEM;
                 RETURN(0);
         }
-        msg = (struct lustre_msg *)req->rq_repbuf;
-        req_msg = req->rq_req.lustre;
-        dlm_rep = lustre_msg_buf(0, msg);
-        dlm_req = lustre_msg_buf(0, req_msg);
-
-        msg->xid = req_msg->xid;
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        dlm_rep = lustre_msg_buf(req->rq_repmsg, 0);
+        dlm_req = lustre_msg_buf(req->rq_reqmsg, 0);
 
         err = ldlm_local_lock_enqueue(req->rq_obd,
                                       dlm_req->ns_id,
@@ -65,40 +60,36 @@ static int ldlm_enqueue(struct ptlrpc_request *req)
                                       &dlm_req->flags,
                                       ldlm_client_callback,
                                       ldlm_client_callback,
-                                      lustre_msg_buf(1, req_msg),
-                                      req_msg->buflens[1],
+                                      lustre_msg_buf(req->rq_reqmsg, 1),
+                                      req->rq_reqmsg->buflens[1],
                                       &dlm_rep->lock_handle);
-        msg->status = HTON__u32(err);
+        req->rq_status = err;
 
-        /* XXX unfinished */
-        return 0;
+        CERROR("local_lock_enqueue: %d\n", err);
+
+        RETURN(0);
 }
 
 static int ldlm_handle(struct obd_device *dev, struct ptlrpc_service *svc,
                        struct ptlrpc_request *req)
 {
         int rc;
-        struct ptlreq_hdr *hdr;
-
         ENTRY;
 
-        hdr = (struct ptlreq_hdr *)req->rq_reqbuf;
-
-        if (NTOH__u32(hdr->type) != PTL_RPC_REQUEST) {
-                CERROR("lustre_ldlm: wrong packet type sent %d\n",
-                       NTOH__u32(hdr->type));
-                rc = -EINVAL;
-                GOTO(out, rc);
-        }
-
         rc = lustre_unpack_msg(req->rq_reqbuf, req->rq_reqlen);
-        req->rq_reqhdr = (void *)req->rq_reqbuf;
+        req->rq_reqmsg = (struct lustre_msg *)req->rq_reqbuf;
         if (rc) {
                 CERROR("lustre_ldlm: Invalid request\n");
                 GOTO(out, rc);
         }
 
-        switch (req->rq_reqhdr->opc) {
+        if (req->rq_reqmsg->type != PTL_RPC_REQUEST) {
+                CERROR("lustre_ldlm: wrong packet type sent %d\n",
+                       req->rq_reqmsg->type);
+                GOTO(out, rc = -EINVAL);
+        }
+
+        switch (req->rq_reqmsg->opc) {
         case LDLM_ENQUEUE:
                 CDEBUG(D_INODE, "enqueue\n");
                 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
@@ -146,12 +137,11 @@ out:
         return 0;
 }
 
-
-
 static int ldlm_iocontrol(int cmd, struct obd_conn *conn, int len, void *karg,
                           void *uarg)
 {
         struct obd_device *obddev = conn->oc_dev;
+        struct ptlrpc_client cl;
         int err;
 
         ENTRY;
@@ -165,6 +155,14 @@ static int ldlm_iocontrol(int cmd, struct obd_conn *conn, int len, void *karg,
                 return -EINVAL;
         }
 
+        err = ptlrpc_connect_client(-1, "ldlm",
+                                    LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
+                                    &cl);
+        if (err) {
+                CERROR("cannot create client\n");
+                RETURN(-EINVAL);
+        }
+
         switch (cmd) {
         case IOC_LDLM_TEST: {
                 err = ldlm_test(obddev);
diff --git a/lustre/lib/Makefile.am b/lustre/lib/Makefile.am
index 2e999b8a0e173121e031463d58afac8f7c2ce506..ce88106b580ba0c9fac65efc4336ac4f178444ba 100644
--- a/lustre/lib/Makefile.am
+++ b/lustre/lib/Makefile.am
@@ -1,3 +1,3 @@
-EXTRA_DIST = mds_pack.c  mds_updates.c  obd_pack.c  page.c pack_generic.c
+EXTRA_DIST = mds_updates.c obd_pack.c page.c
 
 include $(top_srcdir)/Rules
diff --git a/lustre/lib/mds_pack.c b/lustre/lib/mds_pack.c
deleted file mode 100644
index 773ef712e85b07244d6f47f43a3a03117d55cde5..0000000000000000000000000000000000000000
--- a/lustre/lib/mds_pack.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/* -*- 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.
- *
- * (Un)packing of MDS and OST request records
- *
- */
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/major.h>
-#include <linux/sched.h>
-#include <linux/lp.h>
-#include <linux/slab.h>
-#include <linux/ioport.h>
-#include <linux/fcntl.h>
-#include <linux/delay.h>
-#include <linux/skbuff.h>
-#include <linux/proc_fs.h>
-#include <linux/fs.h>
-#include <linux/poll.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <asm/io.h>
-#include <asm/segment.h>
-#include <asm/system.h>
-#include <asm/poll.h>
-#include <asm/uaccess.h>
-
-#define DEBUG_SUBSYSTEM S_MDS
-
-#include <linux/lustre_mds.h>
-#include <linux/lustre_lib.h>
-
-int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen, 
-		 struct ptlreq_hdr **hdr, union ptl_req *r,
-		 int *len, char **buf)
-{
-        struct mds_req *req;
-	char *ptr;
-
-	*len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) + 
-		sizeof(*req); 
-
-	OBD_ALLOC(*buf, *len);
-	if (!*buf) {
-		RETURN(-ENOMEM);
-	}
-
-	memset(*buf, 0, *len); 
-	*hdr = (struct ptlreq_hdr *)(*buf);
-	req = (struct mds_req *)(*buf + sizeof(**hdr));
-        r->mds = req;
-
-	ptr = *buf + sizeof(**hdr) + sizeof(*req);
-
-	(*hdr)->type =  PTL_RPC_REQUEST;
-
-	req->namelen = NTOH__u32(namelen);
-        LOGL(name, namelen, ptr); 
-
-	req->tgtlen = NTOH__u32(tgtlen);
-        LOGL(tgt, tgtlen, ptr);
-
-	RETURN(0);
-}
-
-
-int mds_unpack_req(char *buf, int len, 
-		   struct ptlreq_hdr **hdr, union ptl_req *r)
-{
-        struct mds_req *req;
-        char *name, *tgt;
-
-	if (len < sizeof(**hdr) + sizeof(*req)) { 
-		RETURN(-EINVAL);
-	}
-
-	*hdr = (struct ptlreq_hdr *) (buf);
-        req = (struct mds_req *) (buf + sizeof(**hdr));
-        r->mds = req;
-
-	req->namelen = NTOH__u32(req->namelen); 
-	req->tgtlen = NTOH__u32(req->tgtlen); 
-
-	if (len < sizeof(**hdr) + sizeof(*req) +
-            size_round(req->namelen) + size_round(req->tgtlen) ) { 
-		RETURN(-EINVAL);
-	}
-
-	if (req->namelen) { 
-		name = buf + sizeof(**hdr) + sizeof(*req);
-	} else { 
-		name = NULL;
-	}
-
-	if (req->tgtlen) { 
-		tgt = buf + sizeof(**hdr) + sizeof(*req) + 
-                        size_round(req->namelen);
-	} else { 
-		tgt = NULL;
-	}
-
-	RETURN(0);
-}
-
-void *mds_req_tgt(struct mds_req *req)
-{
-        if (!req->tgtlen) 
-                return NULL;
-        return (void *)((char *)req + sizeof(*req) + 
-                        size_round(req->namelen)); 
-}
-
-void *mds_req_name(struct mds_req *req)
-{
-        if (!req->namelen) 
-                return NULL;
-        return (void *)((char *)req + sizeof(*req));
-}
-
-int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen, 
-		 struct ptlrep_hdr **hdr, union ptl_rep *r,
-		 int *len, char **buf)
-{
-        struct mds_rep *rep;
-	char *ptr;
-
-	*len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) + 
-		sizeof(*rep); 
-
-	OBD_ALLOC(*buf, *len);
-	if (!*buf) {
-		EXIT;
-		return -ENOMEM;
-	}
-
-	memset(*buf, 0, *len); 
-	*hdr = (struct ptlrep_hdr *)(*buf);
-        rep = (struct mds_rep *)(*buf + sizeof(**hdr));
-        r->mds = rep;
-
-	ptr = *buf + sizeof(**hdr) + sizeof(*rep);
-
-	(*hdr)->type =  PTL_RPC_REPLY;
-
-	rep->namelen = NTOH__u32(namelen);
-	if (name) { 
-		LOGL(name, namelen, ptr); 
-	} 
-
-        rep->tgtlen = NTOH__u32(tgtlen);
-	if (tgt) { 
-		LOGL(tgt, tgtlen, ptr);
-	}
-	return 0;
-}
-
-int mds_unpack_rep(char *buf, int len, 
-		   struct ptlrep_hdr **hdr, union ptl_rep *r)
-{
-        struct mds_rep *rep;
-	if (len < sizeof(**hdr)) { 
-		EXIT;
-		return -EINVAL;
-	}
-	*hdr = (struct ptlrep_hdr *) (buf);
-
-	if (len < sizeof(**hdr) + sizeof(*rep)) { 
-		EXIT;
-		return -EINVAL;
-	}
-
-        rep = (struct mds_rep *) (buf + sizeof(**hdr));
-        r->mds = rep;
-	rep->namelen = NTOH__u32(rep->namelen); 
-	rep->tgtlen = NTOH__u32(rep->namelen); 
-
-	if (len < sizeof(**hdr) + sizeof(*rep) 
-            + size_round(rep->namelen) + size_round(rep->tgtlen) ) { 
-		EXIT;
-		return -EINVAL;
-	}
-
-	EXIT;
-	return 0;
-}
-
-void *mds_rep_name(struct mds_rep *rep)
-{
-        if (!rep->namelen) 
-                return NULL;
-        return (void *)((char *)rep + sizeof(*rep));
-}
-
-void *mds_rep_tgt(struct mds_rep *rep)
-{
-        if (!rep->tgtlen) 
-                return NULL;
-        return (void *)((char *)rep + sizeof(*rep) + size_round(rep->namelen)); 
-}
-
diff --git a/lustre/lib/mds_updates.c b/lustre/lib/mds_updates.c
index e33d43241f3689f2381092d9a358afe55ac5847e..35803708aacd3c1840be7d3136eb7d71d2cd594d 100644
--- a/lustre/lib/mds_updates.c
+++ b/lustre/lib/mds_updates.c
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
  * Lustre Light Update Records
  *
  * This code is issued under the GNU General Public License.
@@ -33,40 +35,49 @@
 #include <linux/lustre_lib.h>
 #include <linux/lustre_mds.h>
 
+void mds_pack_body(struct ptlrpc_request *req)
+{
+        struct mds_body *b = lustre_msg_buf(req->rq_reqmsg, 0);
+        if (b == NULL)
+                LBUG();
+
+        /* fid1/fid2 are already packed by another function */
+        b->objid = HTON__u64(b->objid);
+        b->size = HTON__u64(b->size);
+        b->valid = HTON__u32(b->valid);
+        b->mode = HTON__u32(b->mode);
+        b->uid = HTON__u32(b->uid);
+        b->gid = HTON__u32(b->gid);
+        b->mtime = HTON__u32(b->mtime);
+        b->ctime = HTON__u32(b->ctime);
+        b->atime = HTON__u32(b->atime);
+        b->flags = HTON__u32(b->flags);
+        b->major = HTON__u32(b->major);
+        b->minor = HTON__u32(b->minor);
+        b->ino = HTON__u32(b->ino);
+        b->nlink = HTON__u32(b->nlink);
+        b->generation = HTON__u32(b->generation);
+}
+
 /* packing of MDS records */
 void mds_create_pack(struct mds_rec_create *rec, struct inode *inode,
-                     const char *name, int namelen, __u32 mode, __u64 id,
-                     __u32 uid, __u32 gid, __u64 time, const char *tgt,
-                     int tgtlen)
+                     __u32 mode, __u64 id, __u32 uid, __u32 gid, __u64 time)
 {
-        char *tmp = (char *)rec + sizeof(*rec); 
         /* XXX do something about time, uid, gid */
-        rec->cr_reclen = 
-                HTON__u32(sizeof(*rec) + size_round0(namelen) + 
-                          size_round0(tgtlen));
         rec->cr_opcode = HTON__u32(REINT_CREATE);
-
-        ll_inode2fid(&rec->cr_fid, inode); 
+        ll_inode2fid(&rec->cr_fid, inode);
         rec->cr_mode = HTON__u32(mode);
         rec->cr_id = HTON__u64(id);
         rec->cr_uid = HTON__u32(uid);
         rec->cr_gid = HTON__u32(gid);
         rec->cr_time = HTON__u64(time);
-        rec->cr_namelen = HTON__u32(namelen + 1); /* for terminating \0 */ 
-        LOGL0(name, namelen, tmp); 
-        if (tgt) { 
-                rec->cr_tgtlen = HTON__u32(tgtlen + 1); 
-                LOGL0(tgt, tgtlen, tmp); 
-        }
 }
 
 void mds_setattr_pack(struct mds_rec_setattr *rec, struct inode *inode,
                       struct iattr *iattr)
 {
-        rec->sa_reclen = HTON__u32(sizeof(*rec));
         rec->sa_opcode = HTON__u32(REINT_SETATTR);
-
-        ll_inode2fid(&rec->sa_fid, inode); 
+        ll_inode2fid(&rec->sa_fid, inode);
         rec->sa_valid = HTON__u32(iattr->ia_valid);
         rec->sa_mode = HTON__u32(iattr->ia_mode);
         rec->sa_uid = HTON__u32(iattr->ia_uid);
@@ -79,80 +90,66 @@ void mds_setattr_pack(struct mds_rec_setattr *rec, struct inode *inode,
 }
 
 void mds_unlink_pack(struct mds_rec_unlink *rec, struct inode *inode,
-                     struct inode *child, const char *name, int namelen)
+                     struct inode *child)
 {
-        char *tmp = (char *)rec + sizeof(*rec); 
-
-        rec->ul_reclen = HTON__u32(sizeof(*rec)) + size_round0(namelen);
         rec->ul_opcode = HTON__u32(REINT_UNLINK);
-
         ll_inode2fid(&rec->ul_fid1, inode);
         ll_inode2fid(&rec->ul_fid2, child);
-        rec->ul_namelen = HTON__u32(namelen + 1); /* for terminating \0 */ 
-        LOGL0(name, namelen, tmp); 
 }
 
-void mds_link_pack(struct mds_rec_link *rec, 
-                     struct inode *inode, struct inode *dir,
-                     const char *name, int namelen)
+void mds_link_pack(struct mds_rec_link *rec,
+                   struct inode *inode, struct inode *dir)
 {
-        char *tmp = (char *)rec + sizeof(*rec); 
-        rec->lk_reclen = HTON__u32(sizeof(*rec)) + size_round0(namelen);
         rec->lk_opcode = HTON__u32(REINT_LINK);
-
-        ll_inode2fid(&rec->lk_fid1, inode); 
-        ll_inode2fid(&rec->lk_fid2, dir); 
-        rec->lk_namelen = HTON__u32(namelen + 1); /* for terminating \0 */ 
-        LOGL0(name, namelen, tmp); 
+        ll_inode2fid(&rec->lk_fid1, inode);
+        ll_inode2fid(&rec->lk_fid2, dir);
 }
 
-void mds_rename_pack(struct mds_rec_rename *rec, struct inode *srcdir, struct inode *tgtdir, const char *name, int namelen, const char *tgt, int tgtlen)
+void mds_rename_pack(struct mds_rec_rename *rec, struct inode *srcdir,
+                     struct inode *tgtdir)
 {
-        char *tmp = (char *)rec + sizeof(*rec); 
         /* XXX do something about time, uid, gid */
-        rec->rn_reclen = 
-                HTON__u32(sizeof(*rec) + size_round0(namelen) + 
-                          size_round0(tgtlen));
         rec->rn_opcode = HTON__u32(REINT_RENAME);
-
-        ll_inode2fid(&rec->rn_fid1, srcdir); 
-        ll_inode2fid(&rec->rn_fid2, tgtdir); 
-        rec->rn_namelen = HTON__u32(namelen + 1); /* for terminating \0 */ 
-        LOGL0(name, namelen, tmp); 
-        if (tgt) { 
-                rec->rn_tgtlen = HTON__u32(tgtlen + 1); 
-                LOGL0(tgt, tgtlen, tmp); 
-        }
+        ll_inode2fid(&rec->rn_fid1, srcdir);
+        ll_inode2fid(&rec->rn_fid2, tgtdir);
 }
 
 /* unpacking */
-
-static int mds_update_hdr_unpack(char *buf, int len,
-                                 struct mds_update_record *r)
+void mds_unpack_body(struct ptlrpc_request *req)
 {
-        struct mds_update_record_hdr *hdr = (struct mds_update_record_hdr *)buf;
-        
-        r->ur_reclen = NTOH__u32(hdr->ur_reclen);
-        if (len < sizeof(*hdr) || len != r->ur_reclen) { 
-                CERROR("invalid buffer length\n"); 
-                return -EFAULT;
-        }
-        r->ur_opcode = NTOH__u32(hdr->ur_opcode); 
-        return 0;
+        struct mds_body *b = lustre_msg_buf(req->rq_repmsg, 0);
+        if (b == NULL)
+                LBUG();
+
+        b->objid = NTOH__u64(b->objid);
+        b->size = NTOH__u64(b->size);
+        b->valid = NTOH__u32(b->valid);
+        b->mode = NTOH__u32(b->mode);
+        b->uid = NTOH__u32(b->uid);
+        b->gid = NTOH__u32(b->gid);
+        b->mtime = NTOH__u32(b->mtime);
+        b->ctime = NTOH__u32(b->ctime);
+        b->atime = NTOH__u32(b->atime);
+        b->flags = NTOH__u32(b->flags);
+        b->major = NTOH__u32(b->major);
+        b->minor = NTOH__u32(b->minor);
+        b->ino = NTOH__u32(b->ino);
+        b->nlink = NTOH__u32(b->nlink);
+        b->generation = NTOH__u32(b->generation);
 }
 
-static int mds_setattr_unpack(char *buf, int len, struct mds_update_record *r)
+static int mds_setattr_unpack(struct ptlrpc_request *req,
+                              struct mds_update_record *r)
 {
-
         struct iattr *attr = &r->ur_iattr;
-        struct mds_rec_setattr *rec = (struct mds_rec_setattr *)buf; 
+        struct mds_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        ENTRY;
 
-        if (len < sizeof(*rec)) { 
-                CERROR("invalid buffer length\n"); 
-                return -EFAULT;
-        }
+        if (req->rq_reqmsg->bufcount != 1 ||
+            req->rq_reqmsg->buflens[0] != sizeof(*rec))
+                RETURN(-EFAULT);
 
-        r->ur_fid1 = &rec->sa_fid; 
+        r->ur_fid1 = &rec->sa_fid;
         attr->ia_valid = NTOH__u32(rec->sa_valid);
         attr->ia_mode = NTOH__u32(rec->sa_mode);
         attr->ia_uid = NTOH__u32(rec->sa_uid);
@@ -162,129 +159,116 @@ static int mds_setattr_unpack(char *buf, int len, struct mds_update_record *r)
         attr->ia_mtime = NTOH__u64(rec->sa_mtime);
         attr->ia_ctime = NTOH__u64(rec->sa_ctime);
         attr->ia_attr_flags = NTOH__u32(rec->sa_attr_flags);
-        return 0; 
+        RETURN(0);
 }
 
-static int mds_create_unpack(char *buf, int len, struct mds_update_record *r)
+static int mds_create_unpack(struct ptlrpc_request *req,
+                             struct mds_update_record *r)
 {
-        struct mds_rec_create *rec = (struct mds_rec_create *)buf; 
-        char *ptr, *end;
-
-        if (len < sizeof(*rec)) { 
-                CERROR("invalid buffer length\n"); 
-                return -EFAULT;
-        }
-        
-        ptr = (char *)rec + sizeof(*rec); 
-        end = ptr + len - sizeof(*rec); 
-        
+        struct mds_rec_create *rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        ENTRY;
+
+        if (req->rq_reqmsg->bufcount != 3 ||
+            req->rq_reqmsg->buflens[0] != sizeof(*rec))
+                RETURN(-EFAULT);
+
         r->ur_fid1 = &rec->cr_fid;
         r->ur_mode = NTOH__u32(rec->cr_mode);
         r->ur_id = NTOH__u64(rec->cr_id);
         r->ur_uid = NTOH__u32(rec->cr_uid);
         r->ur_gid = NTOH__u32(rec->cr_gid);
         r->ur_time = NTOH__u64(rec->cr_time);
-        r->ur_namelen = NTOH__u32(rec->cr_namelen);
-        r->ur_tgtlen = NTOH__u32(rec->cr_tgtlen);
 
-        UNLOGL0(r->ur_name, char, r->ur_namelen, ptr, end); 
-        UNLOGL0(r->ur_tgt, char, r->ur_tgtlen, ptr, end);
-        return 0;
+        r->ur_name = lustre_msg_buf(req->rq_reqmsg, 1);
+        r->ur_namelen = req->rq_reqmsg->buflens[1];
+
+        r->ur_tgt = lustre_msg_buf(req->rq_reqmsg, 2);
+        r->ur_tgtlen = req->rq_reqmsg->buflens[2];
+        RETURN(0);
 }
 
-static int mds_link_unpack(char *buf, int len, struct mds_update_record *r)
+static int mds_link_unpack(struct ptlrpc_request *req,
+                           struct mds_update_record *r)
 {
-        struct mds_rec_link *rec = (struct mds_rec_link *)buf; 
-        char *ptr, *end;
-
-        if (len < sizeof(*rec)) { 
-                CERROR("invalid buffer length\n"); 
-                return -EFAULT;
-        }
-        
-        ptr = (char *)rec + sizeof(*rec); 
-        end = ptr + len - sizeof(*rec); 
-        
+        struct mds_rec_link *rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        ENTRY;
+
+        if (req->rq_reqmsg->bufcount != 2 ||
+            req->rq_reqmsg->buflens[0] != sizeof(*rec))
+                RETURN(-EFAULT);
+
         r->ur_fid1 = &rec->lk_fid1;
         r->ur_fid2 = &rec->lk_fid2;
-        r->ur_namelen = NTOH__u32(rec->lk_namelen);
-        UNLOGL0(r->ur_name, char, r->ur_namelen, ptr, end); 
-        return 0;
+
+        r->ur_name = lustre_msg_buf(req->rq_reqmsg, 1);
+        r->ur_namelen = req->rq_reqmsg->buflens[1];
+        RETURN(0);
 }
 
-static int mds_unlink_unpack(char *buf, int len, struct mds_update_record *r)
+static int mds_unlink_unpack(struct ptlrpc_request *req,
+                             struct mds_update_record *r)
 {
-        struct mds_rec_unlink *rec = (struct mds_rec_unlink *)buf; 
-        char *ptr, *end;
+        struct mds_rec_unlink *rec = lustre_msg_buf(req->rq_reqmsg, 0);
         ENTRY;
 
-        if (len < sizeof(*rec)) { 
-                CERROR("invalid buffer length\n"); 
-                return -EFAULT;
-        }
-        
-        ptr = (char *)rec + sizeof(*rec); 
-        end = ptr + len - sizeof(*rec); 
-        
+        if (req->rq_reqmsg->bufcount != 2 ||
+            req->rq_reqmsg->buflens[0] != sizeof(*rec))
+                RETURN(-EFAULT);
+
         r->ur_fid1 = &rec->ul_fid1;
         r->ur_fid2 = &rec->ul_fid2;
-        r->ur_namelen = NTOH__u32(rec->ul_namelen);
-        UNLOGL0(r->ur_name, char, r->ur_namelen, ptr, end); 
-        EXIT;
-        return 0;
+
+        r->ur_name = lustre_msg_buf(req->rq_reqmsg, 1);
+        r->ur_namelen = req->rq_reqmsg->buflens[1];
+        RETURN(0);
 }
 
-static int mds_rename_unpack(char *buf, int len, struct mds_update_record *r)
+static int mds_rename_unpack(struct ptlrpc_request *req,
+                             struct mds_update_record *r)
 {
-        struct mds_rec_rename *rec = (struct mds_rec_rename *)buf; 
-        char *ptr, *end;
-
-        if (len < sizeof(*rec)) { 
-                CERROR("invalid buffer length\n"); 
-                return -EFAULT;
-        }
-        
-        ptr = (char *)rec + sizeof(*rec); 
-        end = ptr + len - sizeof(*rec); 
-        
+        struct mds_rec_rename *rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        ENTRY;
+
+        if (req->rq_reqmsg->bufcount != 3 ||
+            req->rq_reqmsg->buflens[0] != sizeof(*rec))
+                RETURN(-EFAULT);
+
         r->ur_fid1 = &rec->rn_fid1;
         r->ur_fid2 = &rec->rn_fid2;
-        r->ur_namelen = NTOH__u32(rec->rn_namelen);
-        r->ur_tgtlen = NTOH__u32(rec->rn_tgtlen);
 
-        UNLOGL0(r->ur_name, char, r->ur_namelen, ptr, end); 
-        UNLOGL0(r->ur_tgt, char, r->ur_tgtlen, ptr, end);
-        return 0;
+        r->ur_name = lustre_msg_buf(req->rq_reqmsg, 1);
+        r->ur_namelen = req->rq_reqmsg->buflens[1];
+
+        r->ur_tgt = lustre_msg_buf(req->rq_reqmsg, 2);
+        r->ur_tgtlen = req->rq_reqmsg->buflens[2];
+        RETURN(0);
 }
 
-typedef int (*update_unpacker)(char *, int , struct mds_update_record *); 
+typedef int (*update_unpacker)(struct ptlrpc_request *req,
+                               struct mds_update_record *r);
 
 static update_unpacker mds_unpackers[REINT_MAX + 1] = {
-        [REINT_SETATTR] mds_setattr_unpack,     
+        [REINT_SETATTR] mds_setattr_unpack,
         [REINT_CREATE] mds_create_unpack,
         [REINT_LINK] mds_link_unpack,
         [REINT_UNLINK] mds_unlink_unpack,
         [REINT_RENAME] mds_rename_unpack,
 };
 
-int mds_update_unpack(char *buf, int len, struct mds_update_record *r)
+int mds_update_unpack(struct ptlrpc_request *req, struct mds_update_record *rec)
 {
-        int rc; 
+        struct mds_update_record_hdr *hdr = lustre_msg_buf(req->rq_reqmsg, 0);
+        int rc;
         ENTRY;
 
-        rc = mds_update_hdr_unpack(buf, len, r);
-
-        if (rc) { 
-                EXIT;
-                return -EFAULT;
-        }
-
-        if ( r->ur_opcode<0 || r->ur_opcode > REINT_MAX) { 
-                EXIT;
-                return EFAULT; 
-        }
-        
-        rc = mds_unpackers[r->ur_opcode](buf, len, r);
-        EXIT;
-        return rc;
+        if (!hdr || req->rq_reqmsg->buflens[0] < sizeof(__u32))
+                RETURN(-EFAULT);
+
+        rec->ur_opcode = NTOH__u32(hdr->ur_opcode);
+
+        if (rec->ur_opcode < 0 || rec->ur_opcode > REINT_MAX)
+                RETURN(-EFAULT);
+
+        rc = mds_unpackers[rec->ur_opcode](req, rec);
+        RETURN(rc);
 }
diff --git a/lustre/lib/obd_pack.c b/lustre/lib/obd_pack.c
index 05e08d8c01c0dfdaf3621d8ff82e951bcf4818d7..cb492dc72ca6148ed4ae099541307e6bceefaf57 100644
--- a/lustre/lib/obd_pack.c
+++ b/lustre/lib/obd_pack.c
@@ -22,187 +22,11 @@
  *
  */
 
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/major.h>
-#include <linux/sched.h>
-#include <linux/lp.h>
-#include <linux/slab.h>
-#include <linux/ioport.h>
-#include <linux/fcntl.h>
-#include <linux/delay.h>
-#include <linux/skbuff.h>
-#include <linux/proc_fs.h>
-#include <linux/fs.h>
-#include <linux/poll.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <asm/io.h>
-#include <asm/segment.h>
-#include <asm/system.h>
-#include <asm/poll.h>
-#include <asm/uaccess.h>
-
 #define DEBUG_SUBSYSTEM S_OST
 
-#include <linux/obd_class.h>
 #include <linux/obd_ost.h>
 #include <linux/lustre_net.h>
 
-int ost_pack_req(char *buf1, int buflen1, char *buf2, int buflen2, 
-		 struct ptlreq_hdr **hdr, union ptl_req *r,
-		 int *len, char **buf)
-{
-        struct ost_req *req;
-	char *ptr;
-
-	*len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) + 
-		sizeof(*req); 
-
-	OBD_ALLOC(*buf, *len);
-	if (!*buf) {
-		RETURN(-ENOMEM);
-	}
-
-	memset(*buf, 0, *len); 
-	*hdr = (struct ptlreq_hdr *)(*buf);
-	req = (struct ost_req *)((*buf) + sizeof(**hdr));
-        r->ost = req;
-
-	ptr = *buf + sizeof(**hdr) + sizeof(*req);
-
-	(*hdr)->type =  PTL_RPC_REQUEST;
-
-        req->buflen1 = HTON__u32(buflen1);
-        LOGL(buf1, buflen1, ptr); 
-
-        req->buflen2 = HTON__u32(buflen2);
-        LOGL(buf2, buflen2, ptr);
-
-	RETURN(0);
-}
-
-int ost_unpack_req(char *buf, int len, 
-		   struct ptlreq_hdr **hdr,  union ptl_req *r)
-{
-        struct ost_req *req;
-
-	if (len < sizeof(**hdr) + sizeof(*req)) { 
-		RETURN(-EINVAL);
-	}
-
-	*hdr = (struct ptlreq_hdr *) (buf);
-	req = (struct ost_req *) (buf + sizeof(**hdr));
-        r->ost = req;
-
-	req->buflen1 = NTOH__u32(req->buflen1); 
-	req->buflen2 = NTOH__u32(req->buflen2); 
-
-	if (len < sizeof(**hdr) + sizeof(*req) + 
-            size_round(req->buflen1) + size_round(req->buflen2) ) { 
-		RETURN(-EINVAL);
-	}
-
-	RETURN(0);
-}
-
-
-void *ost_req_buf1(struct ost_req *req)
-{
-        if (!req->buflen1) 
-                return NULL;
-        return (void *)((char *)req + sizeof(*req));
-}
-
-void *ost_req_buf2(struct ost_req *req)
-{
-        if (!req->buflen2) 
-                return NULL;
-        return (void *)((char *)req + sizeof(*req) + 
-                        size_round(req->buflen1)); 
-}
-
-int ost_pack_rep(char *buf1, int buflen1, char *buf2, int buflen2,
-		 struct ptlrep_hdr **hdr, union ptl_rep *r,
-		 int *len, char **buf)
-{
-	char *ptr;
-        struct ost_rep *rep;
-
-	*len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) + 
-		sizeof(*rep); 
-
-	OBD_ALLOC(*buf, *len);
-	if (!*buf) {
-		EXIT;
-		return -ENOMEM;
-	}
-
-	memset(*buf, 0, *len); 
-	*hdr = (struct ptlrep_hdr *)(*buf);
-	rep = (struct ost_rep *)(*buf + sizeof(**hdr));
-        r->ost = rep;
-
-	ptr = *buf + sizeof(**hdr) + sizeof(*rep);
-
-        rep->buflen1 = HTON__u32(buflen1);
-	if (buf1) { 
-		LOGL(buf1, buflen1, ptr); 
-	} else {
-                ptr += size_round(buflen1);
-        }
-
-        rep->buflen2 = HTON__u32(buflen2);
-	if (buf2) { 
-		LOGL(buf2, buflen2, ptr);
-	}
-	return 0;
-}
-
-
-int ost_unpack_rep(char *buf, int len, 
-		   struct ptlrep_hdr **hdr, union ptl_rep *r)
-{
-        struct ost_rep *rep;
-
-	if (len < sizeof(**hdr) + sizeof(*rep)) { 
-		EXIT;
-		return -EINVAL;
-	}
-
-	*hdr = (struct ptlrep_hdr *) (buf);
-	rep = (struct ost_rep *) (buf + sizeof(**hdr));
-        r->ost = rep;
-
-	rep->buflen1 = NTOH__u32(rep->buflen1); 
-	rep->buflen2 = NTOH__u32(rep->buflen2); 
-
-	if (len < sizeof(**hdr) + sizeof(*rep) + 
-            size_round(rep->buflen1) + size_round(rep->buflen2) ) { 
-		EXIT;
-		return -EINVAL;
-	}
-
-	EXIT;
-	return 0;
-}
-
-void *ost_rep_buf1(struct ost_rep *rep)
-{
-        if (!rep->buflen1) 
-                return NULL;
-        return (void *)((char *)rep + sizeof(*rep));
-}
-
-void *ost_rep_buf2(struct ost_rep *rep)
-{
-        if (!rep->buflen2) 
-                return NULL;
-        return (void *)((char *)rep + sizeof(*rep) + 
-                        size_round(rep->buflen1)); 
-}
-
 void ost_pack_ioo(void **tmp, struct obdo *oa, int bufcnt)
 {
         struct obd_ioobj *ioo = *tmp;
diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c
index f7b9462c967c912857f8d5635ef69d041656ad8f..00c62bde6b52df1b41afa74f66244f4384b1f914 100644
--- a/lustre/llite/namei.c
+++ b/lustre/llite/namei.c
@@ -82,9 +82,9 @@ static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
 /* methods */
 static int ll_find_inode(struct inode *inode, unsigned long ino, void *opaque)
 {
-        struct mds_rep *rep = (struct mds_rep *)opaque;
+        struct mds_body *body = (struct mds_body *)opaque;
 
-        if (inode->i_generation != rep->generation)
+        if (inode->i_generation != body->generation)
                 return 0;
 
         return 1;
@@ -109,14 +109,15 @@ static struct dentry *ll_lookup(struct inode * dir, struct dentry *dentry)
 
         err = mdc_getattr(&sbi->ll_mds_client, ino, type,
                           OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, &request);
-        if ( err ) {
+        if (err) {
                 CERROR("failure %d inode %ld\n", err, ino);
                 ptlrpc_free_req(request);
                 EXIT;
                 return ERR_PTR(-abs(err)); 
         }
 
-        inode = iget4(dir->i_sb, ino, ll_find_inode, request->rq_rep.mds);
+        inode = iget4(dir->i_sb, ino, ll_find_inode,
+                      lustre_msg_buf(request->rq_repmsg, 0));
 
         ptlrpc_free_req(request);
         if (!inode) 
@@ -133,7 +134,7 @@ static struct inode *ll_create_node(struct inode *dir, const char *name,
 {
         struct inode *inode;
         struct ptlrpc_request *request;
-        struct mds_rep *rep;
+        struct mds_body *body;
         int err;
         time_t time = CURRENT_TIME;
         struct ll_sb_info *sbi = ll_i2sbi(dir);
@@ -144,37 +145,34 @@ static struct inode *ll_create_node(struct inode *dir, const char *name,
                          mode, id,  current->uid, current->gid, time, &request);
         if (err) { 
                 inode = ERR_PTR(err);
-                EXIT;
-                goto out;
+                GOTO(out, err);
         }
-        rep = request->rq_rep.mds;
-        rep->valid = OBD_MD_FLNOTOBD;
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        body->valid = OBD_MD_FLNOTOBD;
 
-        rep->objid = id; 
-        rep->nlink = 1;
-        rep->atime = rep->ctime = rep->mtime = time;
-        rep->mode = mode;
+        body->objid = id; 
+        body->nlink = 1;
+        body->atime = body->ctime = body->mtime = time;
+        body->mode = mode;
         CDEBUG(D_INODE, "-- new_inode: objid %lld, ino %d, mode %o\n",
-               rep->objid, rep->ino, rep->mode); 
+               body->objid, body->ino, body->mode); 
 
-        inode = iget4(dir->i_sb, rep->ino, ll_find_inode, rep);
+        inode = iget4(dir->i_sb, body->ino, ll_find_inode, body);
         if (IS_ERR(inode)) {
                 CERROR("new_inode -fatal:  %ld\n", PTR_ERR(inode));
                 inode = ERR_PTR(-EIO);
                 LBUG();
-                EXIT;
-                goto out;
+                GOTO(out, -EIO);
         }
 
         if (!list_empty(&inode->i_dentry)) {
                 CERROR("new_inode -fatal: inode %d, ct %d lnk %d\n", 
-                       rep->ino, atomic_read(&inode->i_count), 
+                       body->ino, atomic_read(&inode->i_count), 
                        inode->i_nlink);
                 iput(inode);
                 LBUG();
                 inode = ERR_PTR(-EIO);
-                EXIT;
-                goto out;
+                GOTO(out, -EIO);
         }
 
         EXIT;
diff --git a/lustre/llite/super.c b/lustre/llite/super.c
index ecd6cf13f7e46eac06e753f958aabc4a653a3223..3bf4d37e1d84503572801aba8033dc18c522bdbe 100644
--- a/lustre/llite/super.c
+++ b/lustre/llite/super.c
@@ -111,7 +111,6 @@ static struct super_block * ll_read_super(struct super_block *sb,
                 RETURN(NULL);
         }
 
-        memset(sbi, 0, sizeof(*sbi));
         sb->u.generic_sbp = sbi;
 
         ll_options(data, &device, &version);
@@ -136,10 +135,7 @@ static struct super_block * ll_read_super(struct super_block *sb,
 
         /* the first parameter should become an mds device no */
         err = ptlrpc_connect_client(-1, "mds",
-                                    MDS_REQUEST_PORTAL,
-                                    MDC_REPLY_PORTAL,
-                                    mds_pack_req,
-                                    mds_unpack_rep,
+                                    MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
                                     &sbi->ll_mds_client);
 
         if (err) {
@@ -163,7 +159,8 @@ static struct super_block * ll_read_super(struct super_block *sb,
                 GOTO(out_req, sb = NULL);
         }
 
-        root = iget4(sb, sbi->ll_rootino, NULL, request->rq_rep.mds);
+        root = iget4(sb, sbi->ll_rootino, NULL,
+                     lustre_msg_buf(request->rq_repmsg, 0));
         if (root) {
                 sb->s_root = d_alloc_root(root);
         } else {
@@ -295,38 +292,38 @@ static int ll_statfs(struct super_block *sb, struct statfs *buf)
         return err; 
 }
 
-static void inline ll_to_inode(struct inode *dst, struct mds_rep *rep)
+static void inline ll_to_inode(struct inode *dst, struct mds_body *body)
 {
         struct ll_inode_info *ii = 
                 (struct ll_inode_info *) &dst->u.generic_ip;
 
         /* core attributes first */
-        if ( rep->valid & OBD_MD_FLID )
-                dst->i_ino = rep->ino;
-        if ( rep->valid & OBD_MD_FLATIME ) 
-                dst->i_atime = rep->atime;
-        if ( rep->valid & OBD_MD_FLMTIME ) 
-                dst->i_mtime = rep->mtime;
-        if ( rep->valid & OBD_MD_FLCTIME ) 
-                dst->i_ctime = rep->ctime;
-        if ( rep->valid & OBD_MD_FLSIZE ) 
-                dst->i_size = rep->size;
-        if ( rep->valid & OBD_MD_FLMODE ) 
-                dst->i_mode = rep->mode;
-        if ( rep->valid & OBD_MD_FLUID ) 
-                dst->i_uid = rep->uid;
-        if ( rep->valid & OBD_MD_FLGID ) 
-                dst->i_gid = rep->gid;
-        if ( rep->valid & OBD_MD_FLFLAGS ) 
-                dst->i_flags = rep->flags;
-        if ( rep->valid & OBD_MD_FLNLINK )
-                dst->i_nlink = rep->nlink;
-        if ( rep->valid & OBD_MD_FLGENER )
-                dst->i_generation = rep->generation;
+        if ( body->valid & OBD_MD_FLID )
+                dst->i_ino = body->ino;
+        if ( body->valid & OBD_MD_FLATIME ) 
+                dst->i_atime = body->atime;
+        if ( body->valid & OBD_MD_FLMTIME ) 
+                dst->i_mtime = body->mtime;
+        if ( body->valid & OBD_MD_FLCTIME ) 
+                dst->i_ctime = body->ctime;
+        if ( body->valid & OBD_MD_FLSIZE ) 
+                dst->i_size = body->size;
+        if ( body->valid & OBD_MD_FLMODE ) 
+                dst->i_mode = body->mode;
+        if ( body->valid & OBD_MD_FLUID ) 
+                dst->i_uid = body->uid;
+        if ( body->valid & OBD_MD_FLGID ) 
+                dst->i_gid = body->gid;
+        if ( body->valid & OBD_MD_FLFLAGS ) 
+                dst->i_flags = body->flags;
+        if ( body->valid & OBD_MD_FLNLINK )
+                dst->i_nlink = body->nlink;
+        if ( body->valid & OBD_MD_FLGENER )
+                dst->i_generation = body->generation;
 
         /* this will become more elaborate for striping etc */ 
-        if (rep->valid & OBD_MD_FLOBJID) 
-                ii->lli_objid = rep->objid;
+        if (body->valid & OBD_MD_FLOBJID) 
+                ii->lli_objid = body->objid;
 #if 0
 
         if (obdo_has_inline(oa)) {
@@ -347,10 +344,10 @@ static void inline ll_to_inode(struct inode *dst, struct mds_rep *rep)
 
 static inline void ll_read_inode2(struct inode *inode, void *opaque)
 {
-        struct mds_rep *rep = opaque; 
+        struct mds_body *body = opaque; 
         
         ENTRY;
-        ll_to_inode(inode, rep); 
+        ll_to_inode(inode, body); 
 
         /* OIDEBUG(inode); */
 
diff --git a/lustre/mdc/Makefile.am b/lustre/mdc/Makefile.am
index c2d03218026d226dd0c838af84b368d4a514e1b0..1595d3d2725c48bdaf0c0bf1fce7821e7b324186 100644
--- a/lustre/mdc/Makefile.am
+++ b/lustre/mdc/Makefile.am
@@ -9,12 +9,9 @@ MODULE = mdc
 modulefs_DATA = mdc.o
 EXTRA_PROGRAMS = mdc
 
-
-LINX=mds_pack.c mds_updates.c
+LINX=mds_updates.c
 mdc_SOURCES =  mdc_request.c mdc_reint.c $(LINX)
 
-mds_pack.c: 
-	ln -s ../lib/mds_pack.c .
 mds_updates.c: 
 	ln -s ../lib/mds_updates.c .
 
diff --git a/lustre/mdc/mdc_reint.c b/lustre/mdc/mdc_reint.c
index da630b4c51fb19efb8dc8c9392f7aeb5f0dbdfaf..e2e062e3747eafc5811d47017650f5fa7fed8500 100644
--- a/lustre/mdc/mdc_reint.c
+++ b/lustre/mdc/mdc_reint.c
@@ -33,151 +33,162 @@
 
 static int mdc_reint(struct ptlrpc_client *cl, struct ptlrpc_request *request)
 {
-        int rc; 
+        int rc;
 
         rc = ptlrpc_queue_wait(cl, request);
+        rc = ptlrpc_check_status(request, rc);
         if (rc)
-                CERROR("error in handling %d\n", rc); 
+                CERROR("error in handling %d\n", rc);
 
         return rc;
 }
 
-int mdc_setattr(struct ptlrpc_client *peer, 
-                struct inode *inode, struct iattr *iattr,
-                struct ptlrpc_request **request)
+int mdc_setattr(struct ptlrpc_client *cl, struct inode *inode,
+                struct iattr *iattr, struct ptlrpc_request **request)
 {
-        int rc; 
         struct mds_rec_setattr *rec;
+        struct ptlrpc_request *req;
+        int rc, size = sizeof(*rec);
         ENTRY;
 
-        *request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL,
-                                   sizeof(*rec), NULL);
-        if (!(*request)) { 
-                CERROR("cannot pack\n");
-                EXIT;
-                return -ENOMEM;
-        }
+        req = ptlrpc_prep_req(cl, MDS_REINT, 1, &size, NULL);
+        if (!req)
+                RETURN(-ENOMEM);
 
-        rec = mds_req_tgt((*request)->rq_req.mds);
-        mds_setattr_pack(rec, inode, iattr); 
-        (*request)->rq_req.mds->opcode = HTON__u32(REINT_SETATTR);
-        (*request)->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        mds_setattr_pack(rec, inode, iattr);
 
-        rc = mdc_reint(peer, *request);
+        size = sizeof(struct mds_body);
+        req->rq_replen = lustre_msg_size(1, &size);
 
-        EXIT;
-        return rc;
+        rc = mdc_reint(cl, req);
+        *request = req;
+
+        RETURN(rc);
 }
 
-int mdc_create(struct ptlrpc_client *peer, 
-               struct inode *dir, const char *name, int namelen, 
-               const char *tgt, int tgtlen, 
-               int mode, __u64 id, __u32 uid, __u32 gid, __u64 time, 
+int mdc_create(struct ptlrpc_client *cl, struct inode *dir, const char *name,
+               int namelen, const char *tgt, int tgtlen, int mode, __u64 id,
+               __u32 uid, __u32 gid, __u64 time,
                struct ptlrpc_request **request)
 {
-        int rc; 
         struct mds_rec_create *rec;
+        struct ptlrpc_request *req;
+        int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
+        char *tmp;
         ENTRY;
 
-        (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
-                               sizeof(*rec) + size_round0(namelen) + 
-                               size_round0(tgtlen), NULL);
-        if (!(*request)) { 
-                CERROR("cannot pack\n");
-                return -ENOMEM;
-        }
+        req = ptlrpc_prep_req(cl, MDS_REINT, 3, size, NULL);
+        if (!req)
+                RETURN(-ENOMEM);
 
-        (*request)->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        mds_create_pack(rec, dir, mode, id, uid, gid, time);
 
-        rec = mds_req_tgt((*request)->rq_req.mds);
-        mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time, 
-                        tgt, tgtlen); 
+        tmp = lustre_msg_buf(req->rq_reqmsg, 1);
+        LOGL0(name, namelen, tmp);
 
-        rc = mdc_reint(peer, (*request));
+        if (tgt) {
+                tmp = lustre_msg_buf(req->rq_reqmsg, 2);
+                LOGL0(tgt, tgtlen, tmp);
+        }
 
-        EXIT;
-        return rc;
+        size[0] = sizeof(struct mds_body);
+        req->rq_replen = lustre_msg_size(1, size);
+
+        rc = mdc_reint(cl, req);
+        *request = req;
+
+        RETURN(rc);
 }
 
-int mdc_unlink(struct ptlrpc_client *peer,  struct inode *dir,
-               struct inode *child, const char *name, int namelen, 
+int mdc_unlink(struct ptlrpc_client *cl,  struct inode *dir,
+               struct inode *child, const char *name, int namelen,
                struct ptlrpc_request **request)
 {
-        int rc; 
         struct mds_rec_unlink *rec;
+        struct ptlrpc_request *req;
+        int rc, size[2] = {sizeof(*rec), namelen + 1};
+        char *tmp;
+        ENTRY;
 
-        (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
-                                     sizeof(*rec) + size_round0(namelen), NULL);
-        if (!(*request)) { 
-                CERROR("cannot pack\n");
-                return -ENOMEM;
-        }
+        req = ptlrpc_prep_req(cl, MDS_REINT, 2, size, NULL);
+        if (!req)
+                RETURN(-ENOMEM);
 
-        (*request)->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        mds_unlink_pack(rec, dir, child);
 
-        rec = mds_req_tgt((*request)->rq_req.mds);
-        mds_unlink_pack(rec, dir, child, name, namelen);
+        tmp = lustre_msg_buf(req->rq_reqmsg, 1);
+        LOGL0(name, namelen, tmp);
 
-        rc = mdc_reint(peer, (*request));
+        size[0] = sizeof(struct mds_body);
+        req->rq_replen = lustre_msg_size(1, size);
 
-        EXIT;
-        return rc;
+        rc = mdc_reint(cl, req);
+        *request = req;
+
+        RETURN(rc);
 }
 
-int mdc_link(struct ptlrpc_client *peer, struct dentry *src, 
-             struct inode *dir, const char *name, int namelen, 
-             struct ptlrpc_request **request)
+int mdc_link(struct ptlrpc_client *cl, struct dentry *src, struct inode *dir,
+             const char *name, int namelen, struct ptlrpc_request **request)
 {
-        int rc; 
         struct mds_rec_link *rec;
+        struct ptlrpc_request *req;
+        int rc, size[2] = {sizeof(*rec), namelen + 1};
+        char *tmp;
         ENTRY;
 
-        (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
-                               sizeof(*rec) + size_round0(namelen), NULL);
-        if (!(*request)) { 
-                CERROR("cannot pack\n");
-                return -ENOMEM;
-        }
+        req = ptlrpc_prep_req(cl, MDS_REINT, 2, size, NULL);
+        if (!req)
+                RETURN(-ENOMEM);
 
-        (*request)->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        mds_link_pack(rec, src->d_inode, dir);
 
-        rec = mds_req_tgt((*request)->rq_req.mds);
-        mds_link_pack(rec, src->d_inode, dir, name, namelen);
+        tmp = lustre_msg_buf(req->rq_reqmsg, 1);
+        LOGL0(name, namelen, tmp);
 
-        rc = mdc_reint(peer, (*request));
-        EXIT;
-        return rc;
+        size[0] = sizeof(struct mds_body);
+        req->rq_replen = lustre_msg_size(1, size);
+
+        rc = mdc_reint(cl, req);
+        *request = req;
+
+        RETURN(rc);
 }
 
-int mdc_rename(struct ptlrpc_client *peer, struct inode *src, 
-               struct inode *tgt, const char *old, int oldlen, 
-               const char *new, int newlen, 
+int mdc_rename(struct ptlrpc_client *cl, struct inode *src, struct inode *tgt,
+               const char *old, int oldlen, const char *new, int newlen,
                struct ptlrpc_request **request)
 {
-        int rc; 
         struct mds_rec_rename *rec;
+        struct ptlrpc_request *req;
+        int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
+        char *tmp;
         ENTRY;
 
-        (*request) = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
-                               sizeof(*rec) + size_round0(oldlen)
-                               + size_round0(newlen), NULL);
-        if (!(*request)) { 
-                CERROR("cannot pack\n");
-                return -ENOMEM;
-        }
+        req = ptlrpc_prep_req(cl, MDS_REINT, 3, size, NULL);
+        if (!req)
+                RETURN(-ENOMEM);
 
-        (*request)->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        rec = lustre_msg_buf(req->rq_reqmsg, 0);
+        mds_rename_pack(rec, src, tgt);
 
-        rec = mds_req_tgt((*request)->rq_req.mds);
-        mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
+        tmp = lustre_msg_buf(req->rq_reqmsg, 1);
+        LOGL0(old, oldlen, tmp);
 
-        rc = mdc_reint(peer, (*request));
+        if (tgt) {
+                tmp = lustre_msg_buf(req->rq_reqmsg, 2);
+                LOGL0(new, newlen, tmp);
+        }
 
-        EXIT;
-        return rc;
+        size[0] = sizeof(struct mds_body);
+        req->rq_replen = lustre_msg_size(1, size);
+
+        rc = mdc_reint(cl, req);
+        *request = req;
+
+        RETURN(rc);
 }
diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c
index bf8b4026f02fbf3ac3b33afa835a64f9c1632f06..4a04ffeb4ade1417afd2e1edc111db2547780f6b 100644
--- a/lustre/mdc/mdc_request.c
+++ b/lustre/mdc/mdc_request.c
@@ -54,110 +54,106 @@
 
 extern int mds_queue_req(struct ptlrpc_request *);
 
-
 int mdc_getattr(struct ptlrpc_client *cl, ino_t ino, int type, int valid,
-                struct ptlrpc_request **req)
+                struct ptlrpc_request **request)
 {
-        int rc;
-        struct ptlrpc_request *request;
-
+        struct ptlrpc_request *req;
+        struct mds_body *body;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        request = ptlrpc_prep_req(cl, MDS_GETATTR, 0, NULL, 0, NULL);
-        if (!request) {
-                CERROR("llight request: cannot pack\n");
+        req = ptlrpc_prep_req(cl, MDS_GETATTR, 1, &size, NULL);
+        if (!req)
                 GOTO(out, rc = -ENOMEM);
-        }
 
-        ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        ll_ino2fid(&body->fid1, ino, 0, type);
+        body->valid = valid;
 
-        request->rq_req.mds->valid = valid;
-        request->rq_replen =
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        req->rq_replen = lustre_msg_size(1, &size);
 
-        rc = ptlrpc_queue_wait(cl, request);
-        rc = ptlrpc_check_status(request, rc);
+        rc = ptlrpc_queue_wait(cl, req);
+        rc = ptlrpc_check_status(req, rc);
 
-        if (!rc)
-                CDEBUG(D_NET, "mode: %o\n", request->rq_rep.mds->mode);
+        if (!rc) {
+                mds_unpack_body(req);
+                body = lustre_msg_buf(req->rq_repmsg, 0);
+                CDEBUG(D_NET, "mode: %o\n", body->mode);
+        }
 
-        GOTO(out, rc);
+        EXIT;
  out:
-        *req = request;
+        *request = req;
         return rc;
 }
 
 int mdc_open(struct ptlrpc_client *cl, ino_t ino, int type, int flags,
-             __u64 *fh, struct ptlrpc_request **req)
+             __u64 *fh, struct ptlrpc_request **request)
 {
-        struct ptlrpc_request *request;
-        int rc;
+        struct mds_body *body;
+        int rc, size = sizeof(*body);
+        struct ptlrpc_request *req;
 
-        request = ptlrpc_prep_req(cl, MDS_OPEN, 0, NULL, 0, NULL);
-        if (!request) {
-                CERROR("llight request: cannot pack\n");
-                rc = -ENOMEM;
-                goto out;
-        }
+        req = ptlrpc_prep_req(cl, MDS_OPEN, 1, &size, NULL);
+        if (!req)
+                GOTO(out, rc = -ENOMEM);
 
-        ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
-        request->rq_req.mds->flags = HTON__u32(flags);
-        request->rq_replen =
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        ll_ino2fid(&body->fid1, ino, 0, type);
+        body->flags = HTON__u32(flags);
 
-        rc = ptlrpc_queue_wait(cl, request);
-        rc = ptlrpc_check_status(request, rc);
+        req->rq_replen = lustre_msg_size(1, &size);
 
-        if (rc) {
-                CERROR("llight request: error in handling %d\n", rc);
-                goto out;
+        rc = ptlrpc_queue_wait(cl, req);
+        rc = ptlrpc_check_status(req, rc);
+
+        if (!rc) {
+                mds_unpack_body(req);
+                body = lustre_msg_buf(req->rq_repmsg, 0);
+                *fh = body->objid;
         }
 
-        *fh = request->rq_rep.mds->objid;
+        EXIT;
  out:
-        *req = request;
+        *request = req;
         return rc;
 }
 
-
 int mdc_close(struct ptlrpc_client *cl, ino_t ino, int type, __u64 fh,
-              struct ptlrpc_request **req)
+              struct ptlrpc_request **request)
 {
-        struct ptlrpc_request *request;
-        int rc;
+        struct mds_body *body;
+        int rc, size = sizeof(*body);
+        struct ptlrpc_request *req;
 
-        request = ptlrpc_prep_req(cl, MDS_CLOSE, 0, NULL, 0, NULL);
-        if (!request) {
-                CERROR("llight request: cannot pack\n");
-                rc = -ENOMEM;
-                goto out;
-        }
+        req = ptlrpc_prep_req(cl, MDS_CLOSE, 1, &size, NULL);
+        if (!req)
+                GOTO(out, rc = -ENOMEM);
 
-        ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
-        request->rq_req.mds->objid = fh;
-        request->rq_replen =
-                sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        ll_ino2fid(&body->fid1, ino, 0, type);
+        body->objid = fh;
 
-        rc = ptlrpc_queue_wait(cl, request);
-        rc = ptlrpc_check_status(request, rc);
+        req->rq_replen = lustre_msg_size(1, &size);
 
-        if (rc) {
-                CERROR("llight request: error in handling %d\n", rc);
-                goto out;
-        }
+        rc = ptlrpc_queue_wait(cl, req);
+        rc = ptlrpc_check_status(req, rc);
 
+        EXIT;
  out:
-        *req = request;
+        *request = req;
         return rc;
 }
 
 int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
-                 char *addr, struct ptlrpc_request **req)
+                 char *addr, struct ptlrpc_request **request)
 {
-        struct ptlrpc_request *request = NULL;
+        struct ptlrpc_request *req = NULL;
         struct ptlrpc_bulk_desc *bulk = NULL;
         struct niobuf niobuf;
-        int rc;
+        struct mds_body *body;
+        int rc, size[2] = {sizeof(*body), sizeof(struct niobuf)};
+        char *bufs[2] = {NULL, (char *)&niobuf};
 
         niobuf.addr = (__u64) (long) addr;
 
@@ -170,43 +166,40 @@ int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
                 goto out;
         }
 
-        request = ptlrpc_prep_req(cl, MDS_READPAGE, 0, NULL,
-                                  sizeof(struct niobuf), (char *)&niobuf);
-        if (!request) {
-                CERROR("%s: cannot pack\n", __FUNCTION__);
-                rc = -ENOMEM;
-                goto out;
-        }
+        req = ptlrpc_prep_req(cl, MDS_READPAGE, 2, size, bufs);
+        if (!req)
+                GOTO(out, rc = -ENOMEM);
 
         bulk->b_buflen = PAGE_SIZE;
         bulk->b_buf = (void *)(long)niobuf.addr;
         bulk->b_portal = MDS_BULK_PORTAL;
-        bulk->b_xid = request->rq_xid;
+        bulk->b_xid = req->rq_xid;
 
         rc = ptlrpc_register_bulk(bulk);
         if (rc) {
-                CERROR("%s: couldn't setup bulk sink: error %d.\n",
-                       __FUNCTION__, rc);
-                goto out;
+                CERROR("couldn't setup bulk sink: error %d.\n", rc);
+                GOTO(out, rc);
         }
 
-        request->rq_req.mds->fid1.id = ino;
-        request->rq_req.mds->fid1.f_type = type;
-        request->rq_req.mds->size = offset;
-        request->rq_req.mds->tgtlen = sizeof(niobuf);
-        request->rq_replen = sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        body->fid1.id = ino;
+        body->fid1.f_type = type;
+        body->size = offset;
+
+        req->rq_replen = lustre_msg_size(1, size);
 
-        rc = ptlrpc_queue_wait(cl, request);
+        rc = ptlrpc_queue_wait(cl, req);
         if (rc) {
-                CERROR("mdc request: error in handling %d\n", rc);
+                CERROR("error in handling %d\n", rc);
                 ptlrpc_abort_bulk(bulk);
-                goto out;
+                GOTO(out, rc);
         }
 
-        CDEBUG(D_INODE, "mode: %o\n", request->rq_rep.mds->mode);
+        mds_unpack_body(req);
+        EXIT;
 
  out:
-        *req = request;
+        *request = req;
         if (bulk != NULL)
                 OBD_FREE(bulk, sizeof(*bulk));
         return rc;
@@ -233,8 +226,7 @@ static int request_ioctl(struct inode *inode, struct file *file,
         }
 
         err = ptlrpc_connect_client(-1, "mds",
-                                    MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
-                                    mds_pack_req, mds_unpack_rep, &cl);
+                                    MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL, &cl);
         if (err) {
                 CERROR("cannot create client\n");
                 RETURN(-EINVAL);
diff --git a/lustre/mds/Makefile.am b/lustre/mds/Makefile.am
index f985ed719edb9c03a998b0557c4105745a253560..5f676fcdcd740671716a27c605c790d3e53f38ad 100644
--- a/lustre/mds/Makefile.am
+++ b/lustre/mds/Makefile.am
@@ -9,9 +9,7 @@ MODULE = mds
 modulefs_DATA = mds.o
 EXTRA_PROGRAMS = mds
 
-LINX=mds_pack.c mds_updates.c simple.c
-mds_pack.c: 
-	ln -s ../lib/mds_pack.c .
+LINX=mds_updates.c simple.c
 mds_updates.c: 
 	ln -s ../lib/mds_updates.c .
 simple.c: 
diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c
index e0df185441b121767ad5281688ac76128e0f3bea..695a63f1d30c97724b7908e4697100db8532050c 100644
--- a/lustre/mds/handler.c
+++ b/lustre/mds/handler.c
@@ -176,111 +176,110 @@ int mds_getattr(struct ptlrpc_request *req)
 {
         struct dentry *de;
         struct inode *inode;
-        struct mds_rep *rep;
+        struct mds_body *body;
         struct mds_obd *mds = &req->rq_obd->u.mds;
-        int rc;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
                 CERROR("mds: out of memory\n");
                 req->rq_status = -ENOMEM;
                 RETURN(0);
         }
 
-        req->rq_rephdr->xid = req->rq_reqhdr->xid;
-        rep = req->rq_rep.mds;
-
-        de = mds_fid2dentry(mds, &req->rq_req.mds->fid1, NULL);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        de = mds_fid2dentry(mds, &body->fid1, NULL);
         if (IS_ERR(de)) {
-                req->rq_rephdr->status = -ENOENT;
+                req->rq_status = -ENOENT;
                 RETURN(0);
         }
 
+        body = lustre_msg_buf(req->rq_repmsg, 0);
         inode = de->d_inode;
-        rep->ino = inode->i_ino;
-        rep->generation = inode->i_generation;
-        rep->atime = inode->i_atime;
-        rep->ctime = inode->i_ctime;
-        rep->mtime = inode->i_mtime;
-        rep->uid = inode->i_uid;
-        rep->gid = inode->i_gid;
-        rep->size = inode->i_size;
-        rep->mode = inode->i_mode;
-        rep->nlink = inode->i_nlink;
-        rep->valid = ~0;
-        mds_fs_get_objid(mds, inode, &rep->objid);
+        body->ino = inode->i_ino;
+        body->generation = inode->i_generation;
+        body->atime = inode->i_atime;
+        body->ctime = inode->i_ctime;
+        body->mtime = inode->i_mtime;
+        body->uid = inode->i_uid;
+        body->gid = inode->i_gid;
+        body->size = inode->i_size;
+        body->mode = inode->i_mode;
+        body->nlink = inode->i_nlink;
+        body->valid = ~0;
+        mds_fs_get_objid(mds, inode, &body->objid);
         l_dput(de);
-        return 0;
+        RETURN(0);
 }
 
 int mds_open(struct ptlrpc_request *req)
 {
         struct dentry *de;
-        struct mds_rep *rep;
+        struct mds_body *body;
         struct file *file;
         struct vfsmount *mnt;
         __u32 flags;
-        int rc;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK)) {
                 CERROR("mds: out of memory\n");
                 req->rq_status = -ENOMEM;
                 RETURN(0);
         }
 
-        req->rq_rephdr->xid = req->rq_reqhdr->xid;
-        rep = req->rq_rep.mds;
-
-        de = mds_fid2dentry(&req->rq_obd->u.mds, &req->rq_req.mds->fid1, &mnt);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        de = mds_fid2dentry(&req->rq_obd->u.mds, &body->fid1, &mnt);
         if (IS_ERR(de)) {
-                req->rq_rephdr->status = -ENOENT;
+                req->rq_status = -ENOENT;
                 RETURN(0);
         }
-        flags = req->rq_req.mds->flags;
+        flags = body->flags;
         file = dentry_open(de, mnt, flags);
         if (!file || IS_ERR(file)) {
-                req->rq_rephdr->status = -EINVAL;
+                req->rq_status = -EINVAL;
                 RETURN(0);
         }
 
-        rep->objid = (__u64) (unsigned long)file;
-        return 0;
+        body = lustre_msg_buf(req->rq_repmsg, 0);
+        body->objid = (__u64) (unsigned long)file;
+        RETURN(0);
 }
 
 int mds_close(struct ptlrpc_request *req)
 {
         struct dentry *de;
-        struct mds_rep *rep;
+        struct mds_body *body;
         struct file *file;
         struct vfsmount *mnt;
         int rc;
+        ENTRY;
 
-        rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
+        rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) {
                 CERROR("mds: out of memory\n");
                 req->rq_status = -ENOMEM;
                 RETURN(0);
         }
 
-        req->rq_rephdr->xid = req->rq_reqhdr->xid;
-        rep = req->rq_rep.mds;
-
-        de = mds_fid2dentry(&req->rq_obd->u.mds, &req->rq_req.mds->fid1, &mnt);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        de = mds_fid2dentry(&req->rq_obd->u.mds, &body->fid1, &mnt);
         if (IS_ERR(de)) {
-                req->rq_rephdr->status = -ENOENT;
+                req->rq_status = -ENOENT;
                 RETURN(0);
         }
 
-        file = (struct file *)(unsigned long) req->rq_req.mds->objid;
-
-        req->rq_rephdr->status = filp_close(file, 0);
+        file = (struct file *)(unsigned long)body->objid;
+        req->rq_status = filp_close(file, 0);
         l_dput(de);
         mntput(mnt);
-        return 0;
+
+        RETURN(0);
 }
 
 int mds_readpage(struct ptlrpc_request *req)
@@ -289,25 +288,22 @@ int mds_readpage(struct ptlrpc_request *req)
         struct dentry *de;
         struct file *file;
         struct niobuf *niobuf;
-        struct mds_rep *rep;
-        int rc;
-
+        struct mds_body *body;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
                 CERROR("mds: out of memory\n");
                 req->rq_status = -ENOMEM;
                 RETURN(0);
         }
 
-        req->rq_rephdr->xid = req->rq_reqhdr->xid;
-        rep = req->rq_rep.mds;
-
-        de = mds_fid2dentry(&req->rq_obd->u.mds, &req->rq_req.mds->fid1, &mnt);
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        de = mds_fid2dentry(&req->rq_obd->u.mds, &body->fid1, &mnt);
         if (IS_ERR(de)) {
-                req->rq_rephdr->status = PTR_ERR(de);
+                req->rq_status = PTR_ERR(de);
                 RETURN(0);
         }
 
@@ -316,32 +312,33 @@ int mds_readpage(struct ptlrpc_request *req)
         file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
         /* note: in case of an error, dentry_open puts dentry */
         if (IS_ERR(file)) {
-                req->rq_rephdr->status = PTR_ERR(file);
+                req->rq_status = PTR_ERR(file);
                 RETURN(0);
         }
 
-        niobuf = mds_req_tgt(req->rq_req.mds);
+        niobuf = lustre_msg_buf(req->rq_reqmsg, 1);
+        if (!niobuf) {
+                req->rq_status = -EINVAL;
+                LBUG();
+                RETURN(0);
+        }
 
         /* to make this asynchronous make sure that the handling function
            doesn't send a reply when this function completes. Instead a
            callback function would send the reply */
-        rc = mds_sendpage(req, file, req->rq_req.mds->size, niobuf);
+        rc = mds_sendpage(req, file, body->size, niobuf);
 
         filp_close(file, 0);
-        req->rq_rephdr->status = rc;
+        req->rq_status = rc;
         RETURN(0);
 }
 
 int mds_reint(struct ptlrpc_request *req)
 {
-        char *buf;
-        int rc, len;
+        int rc;
         struct mds_update_record rec;
 
-        buf = mds_req_tgt(req->rq_req.mds);
-        len = req->rq_req.mds->tgtlen;
-
-        rc = mds_update_unpack(buf, len, &rec);
+        rc = mds_update_unpack(req, &rec);
         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
                 CERROR("invalid record\n");
                 req->rq_status = -EINVAL;
@@ -356,28 +353,22 @@ int mds_handle(struct obd_device *dev, struct ptlrpc_service *svc,
                struct ptlrpc_request *req)
 {
         int rc;
-        struct ptlreq_hdr *hdr;
-
         ENTRY;
 
-        hdr = (struct ptlreq_hdr *)req->rq_reqbuf;
-
-        if (NTOH__u32(hdr->type) != PTL_RPC_REQUEST) {
-                CERROR("lustre_mds: wrong packet type sent %d\n",
-                       NTOH__u32(hdr->type));
-                rc = -EINVAL;
-                GOTO(out, rc);
-        }
-
-        rc = mds_unpack_req(req->rq_reqbuf, req->rq_reqlen,
-                            &req->rq_reqhdr, &req->rq_req);
+        rc = lustre_unpack_msg(req->rq_reqbuf, req->rq_reqlen);
+        req->rq_reqmsg = (struct lustre_msg *)req->rq_reqbuf;
         if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_HANDLE_UNPACK)) {
                 CERROR("lustre_mds: Invalid request\n");
                 GOTO(out, rc);
         }
 
-        switch (req->rq_reqhdr->opc) {
+        if (req->rq_reqmsg->type != PTL_RPC_REQUEST) {
+                CERROR("lustre_mds: wrong packet type sent %d\n",
+                       req->rq_reqmsg->type);
+                GOTO(out, rc = -EINVAL);
+        }
 
+        switch (req->rq_reqmsg->opc) {
         case MDS_GETATTR:
                 CDEBUG(D_INODE, "getattr\n");
                 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
@@ -419,12 +410,6 @@ int mds_handle(struct obd_device *dev, struct ptlrpc_service *svc,
         EXIT;
 out:
         if (rc) {
-                CERROR("no header\n");
-                LBUG();
-                return 0;
-        }
-
-        if( req->rq_status) {
                 ptlrpc_error(dev, svc, req);
         } else {
                 CDEBUG(D_NET, "sending reply\n");
diff --git a/lustre/mds/mds_reint.c b/lustre/mds/mds_reint.c
index cdaba1534f858784032bb002d75cdc3df7755f92..1c800aab3dabf4178efcd6b6960f0018b6f54e54 100644
--- a/lustre/mds/mds_reint.c
+++ b/lustre/mds/mds_reint.c
@@ -36,16 +36,15 @@
 #include <linux/lustre_mds.h>
 #include <linux/obd_class.h>
 
-extern struct ptlrpc_request *mds_prep_req(int size, int opcode, int namelen, char *name, int tgtlen, char *tgt);
-
-static int mds_reint_setattr(struct mds_update_record *rec, struct ptlrpc_request *req)
+static int mds_reint_setattr(struct mds_update_record *rec,
+                             struct ptlrpc_request *req)
 {
         struct mds_obd *mds = &req->rq_obd->u.mds;
         struct dentry *de;
 
         de = mds_fid2dentry(mds, rec->ur_fid1, NULL);
         if (IS_ERR(de) || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_SETATTR)) {
-                req->rq_rephdr->status = -ESTALE;
+                req->rq_status = -ESTALE;
                 RETURN(0);
         }
 
@@ -54,7 +53,7 @@ static int mds_reint_setattr(struct mds_update_record *rec, struct ptlrpc_reques
         OBD_FAIL_WRITE(OBD_FAIL_MDS_REINT_SETATTR_WRITE,
                        de->d_inode->i_sb->s_dev);
 
-        req->rq_rephdr->status = mds_fs_setattr(mds, de, NULL, &rec->ur_iattr);
+        req->rq_status = mds_fs_setattr(mds, de, NULL, &rec->ur_iattr);
 
         l_dput(de);
         RETURN(0);
@@ -63,14 +62,12 @@ static int mds_reint_setattr(struct mds_update_record *rec, struct ptlrpc_reques
 static int mds_reint_create(struct mds_update_record *rec,
                             struct ptlrpc_request *req)
 {
-        int type = rec->ur_mode & S_IFMT;
         struct dentry *de = NULL;
-        struct mds_rep *rep = req->rq_rep.mds;
         struct mds_obd *mds = &req->rq_obd->u.mds;
         struct dentry *dchild = NULL;
         struct inode *dir;
         void *handle;
-        int rc = 0;
+        int rc = 0, type = rec->ur_mode & S_IFMT;
         ENTRY;
 
         de = mds_fid2dentry(mds, rec->ur_fid1, NULL);
@@ -146,6 +143,7 @@ static int mds_reint_create(struct mds_update_record *rec,
         } else {
                 struct iattr iattr;
                 struct inode *inode = dchild->d_inode;
+                struct mds_body *body;
 
                 if (type == S_IFREG) {
                         rc = mds_fs_set_objid(mds, inode, handle, rec->ur_id);
@@ -160,19 +158,20 @@ static int mds_reint_create(struct mds_update_record *rec,
                 iattr.ia_uid = rec->ur_uid;
                 iattr.ia_gid = rec->ur_gid;
                 iattr.ia_valid = ATTR_UID | ATTR_GID | ATTR_ATIME |
-                                 ATTR_MTIME | ATTR_CTIME;
+                        ATTR_MTIME | ATTR_CTIME;
 
                 rc = mds_fs_setattr(mds, dchild, handle, &iattr);
 
-                rep->ino = inode->i_ino;
-                rep->generation = inode->i_generation;
+                body = lustre_msg_buf(req->rq_repmsg, 0);
+                body->ino = inode->i_ino;
+                body->generation = inode->i_generation;
         }
 
 out_reint_commit:
         rc = mds_fs_commit(mds, dir, handle);
 
 out_reint_create:
-        req->rq_rephdr->status = rc;
+        req->rq_status = rc;
         l_dput(dchild);
         l_dput(de);
         RETURN(0);
@@ -229,7 +228,7 @@ static int mds_reint_unlink(struct mds_update_record *rec,
         }
 
 out_unlink:
-        req->rq_rephdr->status = rc;
+        req->rq_status = rc;
         l_dput(dchild);
         l_dput(de);
         RETURN(0);
@@ -273,14 +272,13 @@ static int mds_reint_link(struct mds_update_record *rec,
         EXIT;
 
  out_link:
-        req->rq_rephdr->status = rc;
+        req->rq_status = rc;
         l_dput(dchild);
         l_dput(de_tgt_dir);
         l_dput(de_src);
         return 0;
 }
 
-
 static int mds_reint_rename(struct mds_update_record *rec,
                             struct ptlrpc_request *req)
 {
@@ -320,7 +318,7 @@ static int mds_reint_rename(struct mds_update_record *rec,
         EXIT;
 
  out_rename:
-        req->rq_rephdr->status = rc;
+        req->rq_status = rc;
         l_dput(de_new);
         l_dput(de_old);
         l_dput(de_tgtdir);
@@ -330,7 +328,7 @@ static int mds_reint_rename(struct mds_update_record *rec,
 
 typedef int (*mds_reinter)(struct mds_update_record *, struct ptlrpc_request*);
 
-static mds_reinter  reinters[REINT_MAX+1] = {
+static mds_reinter reinters[REINT_MAX+1] = {
         [REINT_SETATTR]   mds_reint_setattr,
         [REINT_CREATE]    mds_reint_create,
         [REINT_UNLINK]    mds_reint_unlink,
@@ -340,22 +338,21 @@ static mds_reinter  reinters[REINT_MAX+1] = {
 
 int mds_reint_rec(struct mds_update_record *rec, struct ptlrpc_request *req)
 {
-        int rc;
+        int rc, size = sizeof(struct mds_body);
 
-        if (rec->ur_opcode < 0 || rec->ur_opcode > REINT_MAX) {
+        if (rec->ur_opcode < 1 || rec->ur_opcode > REINT_MAX) {
                 CERROR("opcode %d not valid\n", rec->ur_opcode);
                 rc = req->rq_status = -EINVAL;
                 RETURN(rc);
         }
 
-        rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
         if (rc) {
                 CERROR("mds: out of memory\n");
                 rc = req->rq_status = -ENOMEM;
                 RETURN(rc);
         }
-        req->rq_rephdr->xid = req->rq_reqhdr->xid;
 
         rc = reinters[rec->ur_opcode](rec, req);
         return rc;
diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c
index a9fa49d36bb1edf854fa52c97a7d8ebbbb2799f3..f89d10fca1ed6128c78f2e54b2b76a68249565ae 100644
--- a/lustre/obdclass/class_obd.c
+++ b/lustre/obdclass/class_obd.c
@@ -481,7 +481,6 @@ int obd_register_type(struct obd_ops *ops, char *nm)
         OBD_ALLOC(type, sizeof(*type));
         if (!type)
                 RETURN(-ENOMEM);
-        memset(type, 0, sizeof(*type));
         INIT_LIST_HEAD(&type->typ_chain);
         MOD_INC_USE_COUNT;
         list_add(&type->typ_chain, obd_types.next);
diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c
index 2e4c6fc53479c8e28a5798e3791d117dbb87063a..bb2c613dcce4d24e999e62a41a6e3560cf9545c6 100644
--- a/lustre/osc/osc_request.c
+++ b/lustre/osc/osc_request.c
@@ -7,13 +7,13 @@
  *  See the file COPYING in this distribution
  *
  *  Author Peter Braam <braam@clusterfs.com>
- * 
+ *
  *  This server is single threaded at present (but can easily be multi
  *  threaded). For testing and management it is treated as an
  *  obd_device, although it does not export a full OBD method table
  *  (the requests are coming in over the wire, so object target
  *  modules do not have a full method table.)
- * 
+ *
  */
 
 #define EXPORT_SYMTAB
@@ -47,97 +47,90 @@
 struct ptlrpc_client *osc_con2cl(struct obd_conn *conn)
 {
         struct osc_obd *osc = &conn->oc_dev->u.osc;
-        return osc->osc_peer;
+        return osc->osc_client;
 }
 
 static int osc_connect(struct obd_conn *conn)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
         ENTRY;
-        
-        request = ptlrpc_prep_req(peer, OST_CONNECT, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
 
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
+        request = ptlrpc_prep_req(cl, OST_CONNECT, 0, NULL, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
 
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
-      
-        CDEBUG(D_INODE, "received connid %d\n", request->rq_rep.ost->connid); 
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        if (rc)
+                GOTO(out, rc);
 
-        conn->oc_id = request->rq_rep.ost->connid;
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        CDEBUG(D_INODE, "received connid %d\n", body->connid);
+
+        conn->oc_id = body->connid;
+        EXIT;
  out:
         ptlrpc_free_req(request);
-        EXIT;
         return rc;
 }
 
 static int osc_disconnect(struct obd_conn *conn)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
         ENTRY;
-        
-        request = ptlrpc_prep_req(peer, OST_DISCONNECT, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        request->rq_req.ost->connid = conn->oc_id;
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
+
+        request = ptlrpc_prep_req(cl, OST_DISCONNECT, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
+
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        body->connid = conn->oc_id;
+
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        GOTO(out, rc);
  out:
         ptlrpc_free_req(request);
-        EXIT;
         return rc;
 }
 
-
 static int osc_getattr(struct obd_conn *conn, struct obdo *oa)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        request = ptlrpc_prep_req(peer, OST_GETATTR, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        
-        memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
-        request->rq_req.ost->connid = conn->oc_id;
-        request->rq_req.ost->oa.o_valid = ~0;
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-        
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
+        request = ptlrpc_prep_req(cl, OST_GETATTR, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
 
-        CDEBUG(D_INODE, "mode: %o\n", request->rq_rep.ost->oa.o_mode); 
-        if (oa) { 
-                memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
-        }
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        memcpy(&body->oa, oa, sizeof(*oa));
+        body->connid = conn->oc_id;
+        body->oa.o_valid = ~0;
+
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        if (rc)
+                GOTO(out, rc);
 
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
+        if (oa)
+                memcpy(oa, &body->oa, sizeof(*oa));
+
+        EXIT;
  out:
         ptlrpc_free_req(request);
         return 0;
@@ -146,33 +139,33 @@ static int osc_getattr(struct obd_conn *conn, struct obdo *oa)
 static int osc_open(struct obd_conn *conn, struct obdo *oa)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        request = ptlrpc_prep_req(peer, OST_OPEN, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        
-        memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
-        request->rq_req.ost->connid = conn->oc_id;
-        if (request->rq_req.ost->oa.o_valid != (OBD_MD_FLMODE | OBD_MD_FLID))
+        request = ptlrpc_prep_req(cl, OST_OPEN, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
+
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        memcpy(&body->oa, oa, sizeof(*oa));
+        body->connid = conn->oc_id;
+        if (body->oa.o_valid != (OBD_MD_FLMODE | OBD_MD_FLID))
                 LBUG();
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-        
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
 
-        CDEBUG(D_INODE, "mode: %o\n", request->rq_rep.ost->oa.o_mode); 
-        if (oa) { 
-                memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
-        }
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        if (rc)
+                GOTO(out, rc);
+
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
+        if (oa)
+                memcpy(oa, &body->oa, sizeof(*oa));
 
+        EXIT;
  out:
         ptlrpc_free_req(request);
         return 0;
@@ -181,32 +174,31 @@ static int osc_open(struct obd_conn *conn, struct obdo *oa)
 static int osc_close(struct obd_conn *conn, struct obdo *oa)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        request = ptlrpc_prep_req(peer, OST_CLOSE, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        
-        memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
-        request->rq_req.ost->connid = conn->oc_id;
-
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-        
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
+        request = ptlrpc_prep_req(cl, OST_CLOSE, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
 
-        CDEBUG(D_INODE, "mode: %o\n", request->rq_rep.ost->oa.o_mode); 
-        if (oa) { 
-                memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
-        }
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        memcpy(&body->oa, oa, sizeof(*oa));
+        body->connid = conn->oc_id;
+
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        if (rc)
+                GOTO(out, rc);
+
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
+        if (oa)
+                memcpy(oa, &body->oa, sizeof(*oa));
 
+        EXIT;
  out:
         ptlrpc_free_req(request);
         return 0;
@@ -215,25 +207,23 @@ static int osc_close(struct obd_conn *conn, struct obdo *oa)
 static int osc_setattr(struct obd_conn *conn, struct obdo *oa)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        request = ptlrpc_prep_req(peer, OST_SETATTR, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        
-        memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
-        request->rq_req.ost->connid = conn->oc_id;
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-        
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
+        request = ptlrpc_prep_req(cl, OST_SETATTR, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
+
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        memcpy(&body->oa, oa, sizeof(*oa));
+        body->connid = conn->oc_id;
+
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        GOTO(out, rc);
 
  out:
         ptlrpc_free_req(request);
@@ -243,31 +233,34 @@ static int osc_setattr(struct obd_conn *conn, struct obdo *oa)
 static int osc_create(struct obd_conn *conn, struct obdo *oa)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        if (!oa) { 
-                CERROR("oa NULL\n"); 
-        }
-        request = ptlrpc_prep_req(peer, OST_CREATE, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
+        if (!oa) {
+                CERROR("oa NULL\n");
+                RETURN(-EINVAL);
         }
-        
-        memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
-        request->rq_req.ost->connid = conn->oc_id;
-        request->rq_req.ost->oa.o_valid = ~0;
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-        
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
-        memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
+        request = ptlrpc_prep_req(cl, OST_CREATE, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
 
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        memcpy(&body->oa, oa, sizeof(*oa));
+        body->oa.o_valid = ~0;
+        body->connid = conn->oc_id;
+
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        if (rc)
+                GOTO(out, rc);
+
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        memcpy(oa, &body->oa, sizeof(*oa));
+
+        EXIT;
  out:
         ptlrpc_free_req(request);
         return 0;
@@ -277,33 +270,36 @@ static int osc_punch(struct obd_conn *conn, struct obdo *oa, obd_size count,
                      obd_off offset)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        if (!oa) { 
-                CERROR("oa NULL\n"); 
-        }
-        request = ptlrpc_prep_req(peer, OST_PUNCH, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
+        if (!oa) {
+                CERROR("oa NULL\n");
+                RETURN(-EINVAL);
         }
-        
-        memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
-        request->rq_req.ost->connid = conn->oc_id;
-        request->rq_req.ost->oa.o_valid = ~0;
-        request->rq_req.ost->oa.o_size = offset;
-        request->rq_req.ost->oa.o_blocks = count;
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-        
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
-        memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
+        request = ptlrpc_prep_req(cl, OST_PUNCH, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
+
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        memcpy(&body->oa, oa, sizeof(*oa));
+        body->connid = conn->oc_id;
+        body->oa.o_valid = ~0;
+        body->oa.o_size = offset;
+        body->oa.o_blocks = count;
+
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        if (rc)
+                GOTO(out, rc);
 
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        memcpy(oa, &body->oa, sizeof(*oa));
+
+        EXIT;
  out:
         ptlrpc_free_req(request);
         return 0;
@@ -312,31 +308,34 @@ static int osc_punch(struct obd_conn *conn, struct obdo *oa, obd_size count,
 static int osc_destroy(struct obd_conn *conn, struct obdo *oa)
 {
         struct ptlrpc_request *request;
-        struct ptlrpc_client *peer = osc_con2cl(conn);
-        int rc; 
+        struct ptlrpc_client *cl = osc_con2cl(conn);
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
+        ENTRY;
 
-        if (!oa) { 
-                CERROR("oa NULL\n"); 
+        if (!oa) {
+                CERROR("oa NULL\n");
+                RETURN(-EINVAL);
         }
-        request = ptlrpc_prep_req(peer, OST_DESTROY, 0, NULL, 0, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        
-        memcpy(&request->rq_req.ost->oa, oa, sizeof(*oa));
-        request->rq_req.ost->connid = conn->oc_id;
-        request->rq_req.ost->oa.o_valid = ~0;
-        request->rq_replen = 
-                sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
-        
-        rc = ptlrpc_queue_wait(peer, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
-        memcpy(oa, &request->rq_rep.ost->oa, sizeof(*oa));
+        request = ptlrpc_prep_req(cl, OST_DESTROY, 1, &size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
 
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        memcpy(&body->oa, oa, sizeof(*oa));
+        body->connid = conn->oc_id;
+        body->oa.o_valid = ~0;
+
+        request->rq_replen = lustre_msg_size(1, &size);
+
+        rc = ptlrpc_queue_wait(cl, request);
+        if (rc)
+                GOTO(out, rc);
+
+        body = lustre_msg_buf(request->rq_repmsg, 0);
+        memcpy(oa, &body->oa, sizeof(*oa));
+
+        EXIT;
  out:
         ptlrpc_free_req(request);
         return 0;
@@ -389,79 +388,71 @@ int osc_brw_read(struct obd_conn *conn, obd_count num_oa, struct obdo **oa,
 {
         struct ptlrpc_client *cl = osc_con2cl(conn);
         struct ptlrpc_request *request;
-        int pages;
-        int rc; 
+        struct ost_body *body;
         struct obd_ioobj ioo;
         struct niobuf src;
-        int size1, size2 = 0; 
+        int pages, rc, i, j, size[3] = {sizeof(*body)};
         void *ptr1, *ptr2;
-        int i, j, n;
         struct ptlrpc_bulk_desc **bulk;
+        ENTRY;
 
-        size1 = num_oa * sizeof(ioo); 
+        size[1] = num_oa * sizeof(ioo);
         pages = 0;
         for (i = 0; i < num_oa; i++)
                 pages += oa_bufs[i];
-        size2 = pages * sizeof(src);
-
-        request = ptlrpc_prep_req(cl, OST_BRW, size1, NULL, size2, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        request->rq_req.ost->cmd = OBD_BRW_READ;
+        size[2] = pages * sizeof(src);
 
         OBD_ALLOC(bulk, pages * sizeof(*bulk));
-        if (bulk == NULL) {
-                CERROR("cannot alloc bulk desc vector\n");
-                return -ENOMEM;
-        }
-        memset(bulk, 0, pages * sizeof(*bulk));
-
-        n = 0;
-        ptr1 = ost_req_buf1(request->rq_req.ost);
-        ptr2 = ost_req_buf2(request->rq_req.ost);
-        for (i = 0; i < num_oa; i++) {
-                ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]); 
-                for (j = 0; j < oa_bufs[i]; j++) {
-                        bulk[n] = ptlrpc_prep_bulk(&cl->cli_server);
-                        if (bulk[n] == NULL) {
-                                CERROR("cannot alloc bulk desc\n");
-                                rc = -ENOMEM;
-                                goto out;
-                        }
+        if (bulk == NULL)
+                RETURN(-ENOMEM);
+
+        request = ptlrpc_prep_req(cl, OST_BRW, 3, size, NULL);
+        if (!request)
+                GOTO(out, rc = -ENOMEM);
+
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        body->data = OBD_BRW_READ;
+
+        ptr1 = lustre_msg_buf(request->rq_reqmsg, 1);
+        ptr2 = lustre_msg_buf(request->rq_reqmsg, 2);
+        for (pages = 0, i = 0; i < num_oa; i++) {
+                ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]);
+                for (j = 0; j < oa_bufs[i]; j++, pages++) {
+                        bulk[pages] = ptlrpc_prep_bulk(&cl->cli_server);
+                        if (bulk[pages] == NULL)
+                                GOTO(out, rc = -ENOMEM);
 
                         spin_lock(&cl->cli_lock);
-                        bulk[n]->b_xid = cl->cli_xid++;
+                        bulk[pages]->b_xid = cl->cli_xid++;
                         spin_unlock(&cl->cli_lock);
-                        bulk[n]->b_buf = kmap(buf[n]);
-                        bulk[n]->b_buflen = PAGE_SIZE;
-                        bulk[n]->b_portal = OST_BULK_PORTAL;
-                        ost_pack_niobuf(&ptr2, bulk[n]->b_buf, offset[n],
-                                        count[n], flags[n], bulk[n]->b_xid);
 
-                        rc = ptlrpc_register_bulk(bulk[n]);
+                        bulk[pages]->b_buf = kmap(buf[pages]);
+                        bulk[pages]->b_buflen = PAGE_SIZE;
+                        bulk[pages]->b_portal = OST_BULK_PORTAL;
+                        ost_pack_niobuf(&ptr2, bulk[pages]->b_buf,
+                                        offset[pages], count[pages],
+                                        flags[pages], bulk[pages]->b_xid);
+
+                        rc = ptlrpc_register_bulk(bulk[pages]);
                         if (rc)
-                                goto out;
-                        n++;
+                                GOTO(out, rc);
                 }
         }
 
-        request->rq_replen = sizeof(struct ptlrep_hdr) + sizeof(struct ost_rep);
+        request->rq_replen = lustre_msg_size(1, size);
         rc = ptlrpc_queue_wait(cl, request);
+        GOTO(out, rc);
 
  out:
         /* FIXME: if we've called ptlrpc_wait_bulk but rc != 0, we need to
          * abort those bulk listeners. */
 
-        n = 0;
-        for (i = 0; i < num_oa; i++) {
-                for (j = 0; j < oa_bufs[i]; j++) {
-                        if (bulk[n] == NULL)
+        for (pages = 0, i = 0; i < num_oa; i++) {
+                for (j = 0; j < oa_bufs[i]; j++, pages++) {
+                        if (bulk[pages] == NULL)
                                 continue;
-                        kunmap(buf[n]);
-                        OBD_FREE(bulk[n], sizeof(**bulk));
-                        n++;
+                        kunmap(buf[pages]);
+                        OBD_FREE(bulk[pages], sizeof(**bulk));
                 }
         }
 
@@ -477,77 +468,69 @@ int osc_brw_write(struct obd_conn *conn, obd_count num_oa, struct obdo **oa,
         struct ptlrpc_client *cl = osc_con2cl(conn);
         struct ptlrpc_request *request;
         struct obd_ioobj ioo;
+        struct ost_body *body;
         struct niobuf *src;
-        int pages, rc, i, j, n, size1, size2 = 0; 
+        int pages, rc, i, j, size[3] = {sizeof(*body)};
         void *ptr1, *ptr2;
+        ENTRY;
 
-        size1 = num_oa * sizeof(ioo); 
+        size[1] = num_oa * sizeof(ioo);
         pages = 0;
         for (i = 0; i < num_oa; i++)
                 pages += oa_bufs[i];
-        size2 = pages * sizeof(*src);
+        size[2] = pages * sizeof(*src);
 
-        OBD_ALLOC(src, size2);
-        if (!src) { 
-                CERROR("no src memory\n");
-                return -ENOMEM;
-        }
-        memset((char *)src, 0, size2);
+        OBD_ALLOC(src, size[2]);
+        if (!src)
+                RETURN(-ENOMEM);
 
-        request = ptlrpc_prep_req(cl, OST_BRW, size1, NULL, size2, NULL);
-        if (!request) { 
-                CERROR("cannot pack req!\n"); 
-                return -ENOMEM;
-        }
-        request->rq_req.ost->cmd = OBD_BRW_WRITE;
-
-        n = 0;
-        ptr1 = ost_req_buf1(request->rq_req.ost);
-        ptr2 = ost_req_buf2(request->rq_req.ost);
-        for (i = 0; i < num_oa; i++) {
-                ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]); 
-                for (j = 0; j < oa_bufs[i]; j++) {
-                        ost_pack_niobuf(&ptr2, kmap(buf[n]), offset[n],
-                                        count[n], flags[n], 0);
-                        n++;
+        request = ptlrpc_prep_req(cl, OST_BRW, 3, size, NULL);
+        if (!request)
+                RETURN(-ENOMEM);
+        body = lustre_msg_buf(request->rq_reqmsg, 0);
+        body->data = OBD_BRW_WRITE;
+
+        ptr1 = lustre_msg_buf(request->rq_reqmsg, 1);
+        ptr2 = lustre_msg_buf(request->rq_reqmsg, 2);
+        for (pages = 0, i = 0; i < num_oa; i++) {
+                ost_pack_ioo(&ptr1, oa[i], oa_bufs[i]);
+                for (j = 0; j < oa_bufs[i]; j++, pages++) {
+                        ost_pack_niobuf(&ptr2, kmap(buf[pages]), offset[pages],
+                                        count[pages], flags[pages], 0);
                 }
         }
-        memcpy((char *)src, (char *)ost_req_buf2(request->rq_req.ost), size2); 
+        memcpy(src, lustre_msg_buf(request->rq_reqmsg, 2), size[2]);
+
+        size[1] = pages * sizeof(struct niobuf);
+        request->rq_replen = lustre_msg_size(2, size);
 
-        request->rq_replen = sizeof(struct ptlrep_hdr) +
-                sizeof(struct ost_rep) + pages * sizeof(struct niobuf);
         rc = ptlrpc_queue_wait(cl, request);
-        if (rc) { 
-                EXIT;
-                goto out;
-        }
+        if (rc)
+                GOTO(out, rc);
 
-        ptr2 = ost_rep_buf2(request->rq_rep.ost);
-        if (request->rq_rep.ost->buflen2 != n * sizeof(struct niobuf)) {
+        ptr2 = lustre_msg_buf(request->rq_repmsg, 1);
+        if (ptr2 == NULL)
+                GOTO(out, rc = -EINVAL);
+
+        if (request->rq_repmsg->buflens[1] != pages * sizeof(struct niobuf)) {
                 CERROR("buffer length wrong (%d vs. %d)\n",
-                       request->rq_rep.ost->buflen2, n * sizeof(struct niobuf));
-                EXIT;
-                goto out;
+                       request->rq_repmsg->buflens[1],
+                       pages * sizeof(struct niobuf));
+                GOTO(out, rc = -EINVAL);
         }
 
-        n = 0;
-        for (i = 0; i < num_oa; i++) {
-                for (j = 0; j < oa_bufs[i]; j++) {
+        for (pages = 0, i = 0; i < num_oa; i++) {
+                for (j = 0; j < oa_bufs[i]; j++, pages++) {
                         struct niobuf *dst;
                         ost_unpack_niobuf(&ptr2, &dst);
-                        osc_sendpage(conn, request, dst, &src[n]);
-                        n++;
+                        osc_sendpage(conn, request, dst, &src[pages]);
                 }
         }
-        OBD_FREE(src, size2);
+        OBD_FREE(src, size[2]);
  out:
-        n = 0;
-        for (i = 0; i < num_oa; i++) {
-                for (j = 0; j < oa_bufs[i]; j++) {
+        for (pages = 0, i = 0; i < num_oa; i++)
+                for (j = 0; j < oa_bufs[i]; j++, pages++)
                         kunmap(buf[n]);
-                        n++;
-                }
-        }
 
         ptlrpc_free_req(request);
         return 0;
@@ -557,19 +540,18 @@ int osc_brw(int rw, struct obd_conn *conn, obd_count num_oa,
               struct obdo **oa, obd_count *oa_bufs, struct page **buf,
               obd_size *count, obd_off *offset, obd_flag *flags)
 {
-        if (rw == OBD_BRW_READ) {
+        if (rw == OBD_BRW_READ)
                 return osc_brw_read(conn, num_oa, oa, oa_bufs, buf, count,
                                     offset, flags);
-        } else {
+        else
                 return osc_brw_write(conn, num_oa, oa, oa_bufs, buf, count,
                                      offset, flags);
-        }
 }
 
 /* mount the file system (secretly) */
 static int osc_setup(struct obd_device *obddev, obd_count len,
                         void *buf)
-                        
+
 {
         struct osc_obd *osc = &obddev->u.osc;
         struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
@@ -577,36 +559,33 @@ static int osc_setup(struct obd_device *obddev, obd_count len,
         int dev = data->ioc_dev;
         ENTRY;
 
-        OBD_ALLOC(osc->osc_peer, sizeof(*osc->osc_peer));
-        if (osc->osc_peer == NULL)
+        OBD_ALLOC(osc->osc_client, sizeof(*osc->osc_client));
+        if (osc->osc_client == NULL)
                 RETURN(-ENOMEM);
 
         rc = ptlrpc_connect_client(dev, "ost",
-                                   OST_REQUEST_PORTAL,
-                                   OSC_REPLY_PORTAL,  
-                                   ost_pack_req,
-                                   ost_unpack_rep,
-                                   osc->osc_peer);
+                                   OST_REQUEST_PORTAL, OSC_REPLY_PORTAL,
+                                   osc->osc_client);
 
         if (rc == 0)
                 MOD_INC_USE_COUNT;
         RETURN(rc);
-} 
+}
 
 static int osc_cleanup(struct obd_device * obddev)
 {
         struct osc_obd *osc = &obddev->u.osc;
 
-        if (osc->osc_peer != NULL)
-                OBD_FREE(osc->osc_peer, sizeof(*osc->osc_peer));
+        if (osc->osc_client != NULL)
+                OBD_FREE(osc->osc_client, sizeof(*osc->osc_client));
 
         MOD_DEC_USE_COUNT;
         return 0;
 }
 
-struct obd_ops osc_obd_ops = { 
+struct obd_ops osc_obd_ops = {
         o_setup:   osc_setup,
-        o_cleanup: osc_cleanup, 
+        o_cleanup: osc_cleanup,
         o_create: osc_create,
         o_destroy: osc_destroy,
         o_getattr: osc_getattr,
@@ -632,7 +611,7 @@ static void __exit osc_exit(void)
 
 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC) v1.0");
-MODULE_LICENSE("GPL"); 
+MODULE_LICENSE("GPL");
 
 module_init(osc_init);
 module_exit(osc_exit);
diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c
index 29f57a4969af0e5d63acb5eeb41cac9306d8a2a7..b5f57cecc706e72a7d85371c072fa74d3dd59d80 100644
--- a/lustre/ost/ost_handler.c
+++ b/lustre/ost/ost_handler.c
@@ -49,240 +49,220 @@
 static int ost_destroy(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-
-        req->rq_rep.ost->result = obd_destroy(&conn, &req->rq_req.ost->oa);
 
+        req->rq_status = obd_destroy(&conn, &body->oa);
         RETURN(0);
 }
 
 static int ost_getattr(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body, *repbody;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-        req->rq_rep.ost->oa.o_id = req->rq_req.ost->oa.o_id;
-        req->rq_rep.ost->oa.o_valid = req->rq_req.ost->oa.o_valid;
-
-        req->rq_rep.ost->result =  obd_getattr(&conn, &req->rq_rep.ost->oa);
 
+        repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
+        req->rq_status = obd_getattr(&conn, &repbody->oa);
         RETURN(0);
 }
 
 static int ost_open(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body, *repbody;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-        req->rq_rep.ost->oa.o_id = req->rq_req.ost->oa.o_id;
-        req->rq_rep.ost->oa.o_valid = req->rq_req.ost->oa.o_valid;
-
-        req->rq_rep.ost->result =  obd_open(&conn, &req->rq_rep.ost->oa);
 
+        repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
+        req->rq_status = obd_open(&conn, &repbody->oa);
         RETURN(0);
 }
 
 static int ost_close(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body, *repbody;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-        req->rq_rep.ost->oa.o_id = req->rq_req.ost->oa.o_id;
-        req->rq_rep.ost->oa.o_valid = req->rq_req.ost->oa.o_valid;
-
-        req->rq_rep.ost->result =  obd_close(&conn, &req->rq_rep.ost->oa);
 
+        repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
+        req->rq_status = obd_close(&conn, &repbody->oa);
         RETURN(0);
 }
 
-
 static int ost_create(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body, *repbody;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-
-        memcpy(&req->rq_rep.ost->oa, &req->rq_req.ost->oa,
-               sizeof(req->rq_req.ost->oa));
-
-        req->rq_rep.ost->result =obd_create(&conn, &req->rq_rep.ost->oa);
 
+        repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
+        req->rq_status = obd_create(&conn, &repbody->oa);
         RETURN(0);
 }
 
 static int ost_punch(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body, *repbody;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-
-        memcpy(&req->rq_rep.ost->oa, &req->rq_req.ost->oa,
-               sizeof(req->rq_req.ost->oa));
-
-        req->rq_rep.ost->result = obd_punch(&conn, &req->rq_rep.ost->oa,
-                                            req->rq_rep.ost->oa.o_size,
-                                            req->rq_rep.ost->oa.o_blocks);
 
+        repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
+        req->rq_status = obd_punch(&conn, &repbody->oa,
+                                   repbody->oa.o_size, repbody->oa.o_blocks);
         RETURN(0);
 }
 
-
 static int ost_setattr(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body, *repbody;
+        int rc, size = sizeof(*body);
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-
-        memcpy(&req->rq_rep.ost->oa, &req->rq_req.ost->oa,
-               sizeof(req->rq_req.ost->oa));
-
-        req->rq_rep.ost->result = obd_setattr(&conn, &req->rq_rep.ost->oa);
 
+        repbody = lustre_msg_buf(req->rq_repmsg, 0);
+        memcpy(&repbody->oa, &body->oa, sizeof(body->oa));
+        req->rq_status = obd_setattr(&conn, &repbody->oa);
         RETURN(0);
 }
 
 static int ost_connect(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
         ENTRY;
 
         conn.oc_dev = ost->ost_tgt;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
 
-        req->rq_rep.ost->result = obd_connect(&conn);
+        req->rq_status = obd_connect(&conn);
 
         CDEBUG(D_IOCTL, "rep buffer %p, id %d\n", req->rq_repbuf, conn.oc_id);
-        req->rq_rep.ost->connid = conn.oc_id;
+        body = lustre_msg_buf(req->rq_repmsg, 0);
+        body->connid = conn.oc_id;
         RETURN(0);
 }
 
 static int ost_disconnect(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-
+        struct ost_body *body;
+        int rc, size = sizeof(*body);
         ENTRY;
 
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
-        conn.oc_id = req->rq_req.ost->connid;
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-        CDEBUG(D_IOCTL, "Disconnecting %d\n", conn.oc_id);
-        req->rq_rep.ost->result = obd_disconnect(&conn);
 
+        CDEBUG(D_IOCTL, "Disconnecting %d\n", conn.oc_id);
+        req->rq_status = obd_disconnect(&conn);
         RETURN(0);
 }
 
 static int ost_get_info(struct ost_obd *ost, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-        int vallen;
-        void *val;
-        char *ptr;
-
+        struct ost_body *body;
+        int rc, size[2] = {sizeof(*body)};
+        char *bufs[2] = {NULL, NULL}, *ptr;
         ENTRY;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        conn.oc_id = body->connid;
         conn.oc_dev = ost->ost_tgt;
 
-        ptr = ost_req_buf1(req->rq_req.ost);
-        req->rq_rep.ost->result = obd_get_info(&conn, req->rq_req.ost->buflen1,
-                                               ptr, &vallen, &val);
+        ptr = lustre_msg_buf(req->rq_reqmsg, 1);
+        if (!ptr)
+                RETURN(-EINVAL);
+
+        req->rq_status = obd_get_info(&conn, req->rq_reqmsg->buflens[1], ptr,
+                                      &(size[1]), (void **)&(bufs[1]));
 
-        rc = ost_pack_rep(val, vallen, NULL, 0, &req->rq_rephdr,
-                          &req->rq_rep, &req->rq_replen, &req->rq_repbuf);
+        rc = lustre_pack_msg(2, size, bufs, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
         if (rc)
                 CERROR("cannot pack reply\n");
 
@@ -291,71 +271,62 @@ static int ost_get_info(struct ost_obd *ost, struct ptlrpc_request *req)
 
 static int ost_brw_read(struct ost_obd *obddev, struct ptlrpc_request *req)
 {
-        struct ptlrpc_bulk_desc **bulk_vec = NULL;
-        struct ptlrpc_bulk_desc *bulk = NULL;
+        struct ptlrpc_bulk_desc **bulk_vec = NULL, *bulk = NULL;
         struct obd_conn conn;
-        int rc;
-        int i, j;
-        int objcount, niocount;
-        char *tmp1, *tmp2, *end2;
-        int cmd;
+        void *tmp1, *tmp2, *end2;
         struct niobuf *nb, *dst, *res = NULL;
         struct obd_ioobj *ioo;
-        struct ost_req *r = req->rq_req.ost;
-
+        struct ost_body *body;
+        int rc, cmd, i, j, objcount, niocount, size = sizeof(*body);
         ENTRY;
 
-        tmp1 = ost_req_buf1(r);
-        tmp2 = ost_req_buf2(r);
-        end2 = tmp2 + req->rq_req.ost->buflen2;
-        objcount = r->buflen1 / sizeof(*ioo);
-        niocount = r->buflen2 / sizeof(*nb);
-        cmd = r->cmd;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
+        tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
+        end2 = (char *)tmp2 + req->rq_reqmsg->buflens[2];
+        objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
+        niocount = req->rq_reqmsg->buflens[2] / sizeof(*nb);
+        cmd = body->data;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        conn.oc_id = body->connid;
         conn.oc_dev = req->rq_obd->u.ost.ost_tgt;
 
         for (i = 0; i < objcount; i++) {
-                ost_unpack_ioo((void *)&tmp1, &ioo);
+                ost_unpack_ioo(&tmp1, &ioo);
                 if (tmp2 + ioo->ioo_bufcnt > end2) {
                         LBUG();
                         rc = -EFAULT;
                         break;
                 }
                 for (j = 0; j < ioo->ioo_bufcnt; j++)
-                        ost_unpack_niobuf((void *)&tmp2, &nb);
+                        ost_unpack_niobuf(&tmp2, &nb);
         }
 
-        rc = ost_pack_rep(NULL, 0, NULL, 0,
-                          &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
         OBD_ALLOC(res, sizeof(*res) * niocount);
         if (res == NULL)
                 RETURN(-ENOMEM);
 
         /* The unpackers move tmp1 and tmp2, so reset them before using */
-        tmp1 = ost_req_buf1(r);
-        tmp2 = ost_req_buf2(r);
-        req->rq_rep.ost->result = obd_preprw
-                (cmd, &conn, objcount, (struct obd_ioobj *)tmp1,
-                 niocount, (struct niobuf *)tmp2, res);
+        tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
+        tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
+        req->rq_status = obd_preprw(cmd, &conn, objcount,
+                                    tmp1, niocount, tmp2, res);
 
-        if (req->rq_rep.ost->result)
+        if (req->rq_status)
                 GOTO(out, 0);
 
         for (i = 0; i < niocount; i++) {
                 bulk = ptlrpc_prep_bulk(&req->rq_peer);
                 if (bulk == NULL) {
                         CERROR("cannot alloc bulk desc\n");
-                        rc = -ENOMEM;
-                        GOTO(out, rc);
+                        GOTO(out, rc = -ENOMEM);
                 }
 
-                dst = &((struct niobuf *)tmp2)[i];
+                dst = &(((struct niobuf *)tmp2)[i]);
                 bulk->b_xid = dst->xid;
                 bulk->b_buf = (void *)(unsigned long)res[i].addr;
                 bulk->b_buflen = PAGE_SIZE;
@@ -372,20 +343,11 @@ static int ost_brw_read(struct ost_obd *obddev, struct ptlrpc_request *req)
                 bulk = NULL;
         }
 
-#if 0
-        /* Local delivery */
-        dst = &((struct niobuf *)tmp2)[i];
-        memcpy((void *)(unsigned long)dst->addr,
-               (void *)(unsigned long)src->addr, PAGE_SIZE);
-#endif
-        barrier();
-
         /* The unpackers move tmp1 and tmp2, so reset them before using */
-        tmp1 = ost_req_buf1(r);
-        tmp2 = ost_req_buf2(r);
-        req->rq_rep.ost->result = obd_commitrw
-                (cmd, &conn, objcount, (struct obd_ioobj *)tmp1,
-                 niocount, res);
+        tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
+        tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
+        req->rq_status = obd_commitrw(cmd, &conn, objcount,
+                                      tmp1, niocount, res);
 
         EXIT;
  out:
@@ -394,10 +356,9 @@ static int ost_brw_read(struct ost_obd *obddev, struct ptlrpc_request *req)
         if (bulk != NULL)
                 OBD_FREE(bulk, sizeof(*bulk));
         if (bulk_vec != NULL) {
-                for (i = 0; i < niocount; i++) {
+                for (i = 0; i < niocount; i++)
                         if (bulk_vec[i] != NULL)
                                 OBD_FREE(bulk_vec[i], sizeof(*bulk));
-                }
                 OBD_FREE(bulk_vec, niocount * sizeof(*bulk_vec));
         }
 
@@ -437,26 +398,22 @@ static int ost_brw_write_cb(struct ptlrpc_bulk_desc *bulk, void *data)
 static int ost_brw_write(struct ost_obd *obddev, struct ptlrpc_request *req)
 {
         struct obd_conn conn;
-        int rc;
-        int i, j;
-        int objcount, niocount;
-        char *tmp1, *tmp2, *end2;
-        char *res;
-        int cmd;
         struct niobuf *nb, *dst;
         struct obd_ioobj *ioo;
-        struct ost_req *r = req->rq_req.ost;
-
+        struct ost_body *body;
+        int cmd, rc, i, j, objcount, niocount, size[2] = {sizeof(*body)};
+        void *tmp1, *tmp2, *end2, *res;
         ENTRY;
 
-        tmp1 = ost_req_buf1(r);
-        tmp2 = ost_req_buf2(r);
-        end2 = tmp2 + req->rq_req.ost->buflen2;
-        objcount = r->buflen1 / sizeof(*ioo);
-        niocount = r->buflen2 / sizeof(*nb);
-        cmd = r->cmd;
+        body = lustre_msg_buf(req->rq_reqmsg, 0);
+        tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
+        tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
+        end2 = (char *)tmp2 + req->rq_reqmsg->buflens[2];
+        objcount = req->rq_reqmsg->buflens[1] / sizeof(*ioo);
+        niocount = req->rq_reqmsg->buflens[2] / sizeof(*nb);
+        cmd = body->data;
 
-        conn.oc_id = req->rq_req.ost->connid;
+        conn.oc_id = body->connid;
         conn.oc_dev = req->rq_obd->u.ost.ost_tgt;
 
         for (i = 0; i < objcount; i++) {
@@ -469,23 +426,21 @@ static int ost_brw_write(struct ost_obd *obddev, struct ptlrpc_request *req)
                         ost_unpack_niobuf((void *)&tmp2, &nb);
         }
 
-        rc = ost_pack_rep(NULL, 0, NULL, niocount * sizeof(*nb),
-                          &req->rq_rephdr, &req->rq_rep,
-                          &req->rq_replen, &req->rq_repbuf);
-        if (rc) {
-                CERROR("cannot pack reply\n");
+        size[1] = niocount * sizeof(*nb);
+        rc = lustre_pack_msg(2, size, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
                 RETURN(rc);
-        }
-        res = ost_rep_buf2(req->rq_rep.ost);
+
+        res = lustre_msg_buf(req->rq_repmsg, 1);
 
         /* The unpackers move tmp1 and tmp2, so reset them before using */
-        tmp1 = ost_req_buf1(r);
-        tmp2 = ost_req_buf2(r);
-        req->rq_rep.ost->result = obd_preprw
-                (cmd, &conn, objcount, (struct obd_ioobj *)tmp1,
-                 niocount, (struct niobuf *)tmp2, (struct niobuf *)res);
+        tmp1 = lustre_msg_buf(req->rq_reqmsg, 1);
+        tmp2 = lustre_msg_buf(req->rq_reqmsg, 2);
+        req->rq_status = obd_preprw(cmd, &conn, objcount,
+                                    tmp1, niocount, tmp2, res);
 
-        if (req->rq_rep.ost->result)
+        if (req->rq_status)
                 GOTO(out, 0);
 
         for (i = 0; i < niocount; i++) {
@@ -493,17 +448,14 @@ static int ost_brw_write(struct ost_obd *obddev, struct ptlrpc_request *req)
                 struct ptlrpc_service *srv = req->rq_obd->u.ost.ost_service;
 
                 bulk = ptlrpc_prep_bulk(&req->rq_peer);
-                if (bulk == NULL) {
-                        CERROR("cannot alloc bulk desc\n");
-                        rc = -ENOMEM;
-                        GOTO(out, rc);
-                }
+                if (bulk == NULL)
+                        GOTO(out, rc = -ENOMEM);
 
                 spin_lock(&srv->srv_lock);
                 bulk->b_xid = srv->srv_xid++;
                 spin_unlock(&srv->srv_lock);
 
-                dst = &((struct niobuf *)res)[i];
+                dst = &(((struct niobuf *)res)[i]);
                 dst->xid = HTON__u32(bulk->b_xid);
 
                 bulk->b_buf = (void *)(unsigned long)dst->addr;
@@ -515,15 +467,7 @@ static int ost_brw_write(struct ost_obd *obddev, struct ptlrpc_request *req)
                 rc = ptlrpc_register_bulk(bulk);
                 if (rc)
                         GOTO(out, rc);
-
-#if 0
-                /* Local delivery */
-                src = &((struct niobuf *)tmp2)[i];
-                memcpy((void *)(unsigned long)dst->addr,
-                       (void *)(unsigned long)src->addr, src->len);
-#endif
         }
-        barrier();
 
         EXIT;
  out:
@@ -533,10 +477,9 @@ static int ost_brw_write(struct ost_obd *obddev, struct ptlrpc_request *req)
 
 static int ost_brw(struct ost_obd *obddev, struct ptlrpc_request *req)
 {
-        struct ost_req *r = req->rq_req.ost;
-        int cmd = r->cmd;
+        struct ost_body *body = lustre_msg_buf(req->rq_reqmsg, 0);
 
-        if (cmd == OBD_BRW_READ)
+        if (body->data == OBD_BRW_READ)
                 return ost_brw_read(obddev, req);
         else
                 return ost_brw_write(obddev, req);
@@ -547,28 +490,22 @@ static int ost_handle(struct obd_device *obddev, struct ptlrpc_service *svc,
 {
         int rc;
         struct ost_obd *ost = &obddev->u.ost;
-        struct ptlreq_hdr *hdr;
-
         ENTRY;
 
-        hdr = (struct ptlreq_hdr *)req->rq_reqbuf;
-        if (NTOH__u32(hdr->type) != PTL_RPC_REQUEST) {
-                CERROR("lustre_ost: wrong packet type sent %d\n",
-                       NTOH__u32(hdr->type));
-                LBUG();
-                rc = -EINVAL;
+        rc = lustre_unpack_msg(req->rq_reqbuf, req->rq_reqlen);
+        req->rq_reqmsg = (struct lustre_msg *)req->rq_reqbuf;
+        if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_HANDLE_UNPACK)) {
+                CERROR("lustre_mds: Invalid request\n");
                 GOTO(out, rc);
         }
 
-        rc = ost_unpack_req(req->rq_reqbuf, req->rq_reqlen,
-                            &req->rq_reqhdr, &req->rq_req);
-        if (rc) {
-                CERROR("lustre_ost: Invalid request\n");
-                GOTO(out, rc);
+        if (req->rq_reqmsg->type != PTL_RPC_REQUEST) {
+                CERROR("lustre_mds: wrong packet type sent %d\n",
+                       req->rq_reqmsg->type);
+                GOTO(out, rc = -EINVAL);
         }
 
-        switch (req->rq_reqhdr->opc) {
-
+        switch (req->rq_reqmsg->opc) {
         case OST_CONNECT:
                 CDEBUG(D_INODE, "connect\n");
                 OBD_FAIL_RETURN(OBD_FAIL_OST_CONNECT_NET, 0);
@@ -632,7 +569,7 @@ static int ost_handle(struct obd_device *obddev, struct ptlrpc_service *svc,
 
         EXIT;
 out:
-        req->rq_status = rc;
+        //req->rq_status = rc;
         if (rc) {
                 CERROR("ost: processing error %d\n", rc);
                 ptlrpc_error(obddev, svc, req);
diff --git a/lustre/ptlrpc/Makefile.am b/lustre/ptlrpc/Makefile.am
index d9ec67ebfd64d9fb5bab2f0467e5ac25e8c4a9d8..7c47ff29475c51e45d953d88a8fed1ed0793b06d 100644
--- a/lustre/ptlrpc/Makefile.am
+++ b/lustre/ptlrpc/Makefile.am
@@ -9,6 +9,6 @@ MODULE = ptlrpc
 modulefs_DATA = ptlrpc.o
 EXTRA_PROGRAMS = ptlrpc
 
-ptlrpc_SOURCES =  rpc.c events.c service.c client.c niobuf.c
+ptlrpc_SOURCES = rpc.c events.c service.c client.c niobuf.c pack_generic.c
 
 include $(top_srcdir)/Rules
diff --git a/lustre/ptlrpc/client.c b/lustre/ptlrpc/client.c
index e963d558fc741a279b334532efde94ef2e7861af..3e736af392060a24e88f03e4e59a601dfe4ad3cb 100644
--- a/lustre/ptlrpc/client.c
+++ b/lustre/ptlrpc/client.c
@@ -35,23 +35,17 @@
 int ptlrpc_enqueue(struct ptlrpc_client *peer, struct ptlrpc_request *req)
 {
         struct ptlrpc_request *srv_req;
-        
-        if (!peer->cli_obd) { 
-                EXIT;
-                return -1;
-        }
+
+        if (!peer->cli_obd)
+                RETURN(-1);
 
         OBD_ALLOC(srv_req, sizeof(*srv_req));
-        if (!srv_req) { 
-                EXIT;
-                return -ENOMEM;
-        }
+        if (!srv_req)
+                RETURN(-ENOMEM);
 
         CDEBUG(0, "peer obd minor %d, incoming req %p, srv_req %p\n",
                peer->cli_obd->obd_minor, req, srv_req);
 
-        memset(srv_req, 0, sizeof(*req)); 
-
         /* move the request buffer */
         srv_req->rq_reqbuf = req->rq_reqbuf;
         srv_req->rq_reqlen = req->rq_reqlen;
@@ -61,41 +55,37 @@ int ptlrpc_enqueue(struct ptlrpc_client *peer, struct ptlrpc_request *req)
         srv_req->rq_reply_handle = req;
 
         spin_lock(&peer->cli_lock);
-        list_add(&srv_req->rq_list, &peer->cli_obd->obd_req_list); 
+        list_add(&srv_req->rq_list, &peer->cli_obd->obd_req_list);
         spin_unlock(&peer->cli_lock);
         wake_up(&peer->cli_obd->obd_req_waitq);
         return 0;
 }
 
-int ptlrpc_connect_client(int dev, char *uuid, int req_portal, int rep_portal, 
-                          req_pack_t req_pack, rep_unpack_t rep_unpack,
+int ptlrpc_connect_client(int dev, char *uuid, int req_portal, int rep_portal,
                           struct ptlrpc_client *cl)
 {
-        int err; 
+        int err;
 
         memset(cl, 0, sizeof(*cl));
         spin_lock_init(&cl->cli_lock);
         cl->cli_xid = 1;
-        cl->cli_obd = NULL; 
+        cl->cli_obd = NULL;
         cl->cli_request_portal = req_portal;
         cl->cli_reply_portal = rep_portal;
-        cl->cli_rep_unpack = rep_unpack;
-        cl->cli_req_pack = req_pack;
         sema_init(&cl->cli_rpc_sem, 32);
 
         /* non networked client */
         if (dev >= 0 && dev < MAX_OBD_DEVICES) {
                 struct obd_device *obd = &obd_dev[dev];
-                
+
                 if ((!obd->obd_flags & OBD_ATTACHED) ||
-                    (!obd->obd_flags & OBD_SET_UP)) { 
+                    (!obd->obd_flags & OBD_SET_UP)) {
                         CERROR("target device %d not att or setup\n", dev);
                         return -EINVAL;
                 }
-                if (strcmp(obd->obd_type->typ_name, "ost") && 
-                    strcmp(obd->obd_type->typ_name, "mds")) { 
+                if (strcmp(obd->obd_type->typ_name, "ost") &&
+                    strcmp(obd->obd_type->typ_name, "mds"))
                         return -EINVAL;
-                }
 
                 cl->cli_obd = &obd_dev[dev];
                 return 0;
@@ -115,7 +105,6 @@ struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct lustre_peer *peer)
 
         OBD_ALLOC(bulk, sizeof(*bulk));
         if (bulk != NULL) {
-                memset(bulk, 0, sizeof(*bulk));
                 memcpy(&bulk->b_peer, peer, sizeof(*peer));
                 init_waitqueue_head(&bulk->b_waitq);
         }
@@ -123,38 +112,36 @@ struct ptlrpc_bulk_desc *ptlrpc_prep_bulk(struct lustre_peer *peer)
         return bulk;
 }
 
-struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl, 
-                                       int opcode, int namelen, char *name,
-                                       int tgtlen, char *tgt)
+struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl, int opcode,
+                                       int count, int *lengths, char **bufs)
 {
         struct ptlrpc_request *request;
         int rc;
-        ENTRY; 
+        ENTRY;
 
         OBD_ALLOC(request, sizeof(*request));
-        if (!request) { 
+        if (!request) {
                 CERROR("request allocation out of memory\n");
-                return NULL;
+                RETURN(NULL);
         }
 
-        memset(request, 0, sizeof(*request));
-
         spin_lock(&cl->cli_lock);
         request->rq_xid = cl->cli_xid++;
         spin_unlock(&cl->cli_lock);
 
-        rc = cl->cli_req_pack(name, namelen, tgt, tgtlen,
-                          &request->rq_reqhdr, &request->rq_req,
-                          &request->rq_reqlen, &request->rq_reqbuf);
-        if (rc) { 
-                CERROR("cannot pack request %d\n", rc); 
-                return NULL;
+        rc = lustre_pack_msg(count, lengths, bufs,
+                             &request->rq_reqlen, &request->rq_reqbuf);
+        if (rc) {
+                CERROR("cannot pack request %d\n", rc);
+                RETURN(NULL);
         }
-        request->rq_reqhdr->opc = opcode;
-        request->rq_reqhdr->xid = request->rq_xid;
+        request->rq_type = PTL_RPC_REQUEST;
+        request->rq_reqmsg = (struct lustre_msg *)request->rq_reqbuf;
+        request->rq_reqmsg->opc = HTON__u32(opcode);
+        request->rq_reqmsg->xid = HTON__u32(request->rq_xid);
+        request->rq_reqmsg->type = HTON__u32(request->rq_type);
 
-        EXIT;
-        return request;
+        RETURN(request);
 }
 
 void ptlrpc_free_req(struct ptlrpc_request *request)
@@ -178,7 +165,7 @@ static int ptlrpc_check_reply(struct ptlrpc_request *req)
 
         if (sigismember(&(current->pending.signal), SIGKILL) ||
             sigismember(&(current->pending.signal), SIGTERM) ||
-            sigismember(&(current->pending.signal), SIGINT)) { 
+            sigismember(&(current->pending.signal), SIGINT)) {
                 req->rq_flags = PTL_RPC_INTR;
                 GOTO(out, rc = 1);
         }
@@ -193,32 +180,27 @@ int ptlrpc_check_status(struct ptlrpc_request *req, int err)
 
         if (err != 0) {
                 CERROR("err is %d\n", err);
-                EXIT;
-                return err;
+                RETURN(err);
         }
 
         if (req == NULL) {
                 CERROR("req == NULL\n");
-                EXIT;
-                return -ENOMEM;
+                RETURN(-ENOMEM);
         }
 
-        if (req->rq_rephdr == NULL) {
-                CERROR("req->rq_rephdr == NULL\n");
-                EXIT;
-                return -ENOMEM;
+        if (req->rq_repmsg == NULL) {
+                CERROR("req->rq_repmsg == NULL\n");
+                RETURN(-ENOMEM);
         }
 
-        if (req->rq_rephdr->status != 0) {
-                CERROR("req->rq_rephdr->status is %d\n",
-                       req->rq_rephdr->status);
-                EXIT;
+        if (req->rq_repmsg->status != 0) {
+                CERROR("req->rq_repmsg->status is %d\n",
+                       req->rq_repmsg->status);
                 /* XXX: translate this error from net to host */
-                return req->rq_rephdr->status;
+                RETURN(req->rq_repmsg->status);
         }
 
-        EXIT;
-        return 0;
+        RETURN(0);
 }
 
 /* Abort this request and cleanup any resources associated with it. */
@@ -244,15 +226,15 @@ int ptlrpc_queue_wait(struct ptlrpc_client *cl, struct ptlrpc_request *req)
         if (cl->cli_obd) {
                 /* Local delivery */
                 down(&cl->cli_rpc_sem);
-                rc = ptlrpc_enqueue(cl, req); 
+                rc = ptlrpc_enqueue(cl, req);
         } else {
                 /* Remote delivery via portals. */
                 req->rq_req_portal = cl->cli_request_portal;
                 req->rq_reply_portal = cl->cli_reply_portal;
                 rc = ptl_send_rpc(req, cl);
         }
-        if (rc) { 
-                CERROR("error %d, opcode %d\n", rc, req->rq_reqhdr->opc);
+        if (rc) {
+                CERROR("error %d, opcode %d\n", rc, req->rq_reqmsg->opc);
                 up(&cl->cli_rpc_sem);
                 RETURN(-rc);
         }
@@ -261,30 +243,30 @@ int ptlrpc_queue_wait(struct ptlrpc_client *cl, struct ptlrpc_request *req)
         wait_event_interruptible(req->rq_wait_for_rep, ptlrpc_check_reply(req));
         CDEBUG(D_OTHER, "-- done\n");
         up(&cl->cli_rpc_sem);
-        if (req->rq_flags == PTL_RPC_INTR) { 
+        if (req->rq_flags == PTL_RPC_INTR) {
                 /* Clean up the dangling reply buffers */
                 ptlrpc_abort(req);
                 GOTO(out, rc = -EINTR);
         }
 
-        if (req->rq_flags != PTL_RPC_REPLY) { 
+        if (req->rq_flags != PTL_RPC_REPLY) {
                 CERROR("Unknown reason for wakeup\n");
                 /* XXX Phil - I end up here when I kill obdctl */
-                ptlrpc_abort(req); 
+                ptlrpc_abort(req);
                 GOTO(out, rc = -EINTR);
         }
 
-        rc = cl->cli_rep_unpack(req->rq_repbuf, req->rq_replen,
-                                &req->rq_rephdr, &req->rq_rep);
+        rc = lustre_unpack_msg(req->rq_repbuf, req->rq_replen);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
         if (rc) {
                 CERROR("unpack_rep failed: %d\n", rc);
                 GOTO(out, rc);
         }
-        CDEBUG(D_NET, "got rep %d\n", req->rq_rephdr->xid);
+        CDEBUG(D_NET, "got rep %d\n", req->rq_repmsg->xid);
 
-        if ( req->rq_rephdr->status == 0 )
+        if (req->rq_repmsg->status == 0)
                 CDEBUG(D_NET, "--> buf %p len %d status %d\n", req->rq_repbuf,
-                       req->rq_replen, req->rq_rephdr->status);
+                       req->rq_replen, req->rq_repmsg->status);
 
         EXIT;
  out:
diff --git a/lustre/ptlrpc/niobuf.c b/lustre/ptlrpc/niobuf.c
index 22631d7306358b05b09c608b97faa657d3be564f..c349cc9a943ce7f150a72d50c9fc4249c26f5845 100644
--- a/lustre/ptlrpc/niobuf.c
+++ b/lustre/ptlrpc/niobuf.c
@@ -214,7 +214,9 @@ int ptlrpc_reply(struct obd_device *obddev, struct ptlrpc_service *svc,
 
                 /* FIXME: we need to increment the count of handled events */
                 req->rq_type = PTL_RPC_REPLY;
-                req->rq_reqhdr->xid = req->rq_reqhdr->xid;
+                req->rq_repmsg->xid = HTON__u32(req->rq_reqmsg->xid);
+                req->rq_repmsg->status = HTON__u32(req->rq_status);
+                req->rq_reqmsg->type = HTON__u32(req->rq_type);
                 ptl_send_buf(req, &req->rq_peer, svc->srv_rep_portal);
         } else {
                 /* This is a local request that came from another thread. */
@@ -233,53 +235,42 @@ int ptlrpc_reply(struct obd_device *obddev, struct ptlrpc_service *svc,
                 wake_up_interruptible(&clnt_req->rq_wait_for_rep); 
         }
 
-        EXIT;
-        return 0;
+        RETURN(0);
 }
 
 int ptlrpc_error(struct obd_device *obddev, struct ptlrpc_service *svc,
                  struct ptlrpc_request *req)
 {
-        struct ptlrep_hdr *hdr;
-
+        int rc;
         ENTRY;
 
-        OBD_ALLOC(hdr, sizeof(*hdr));
-        if (!hdr) { 
-                EXIT;
-                return -ENOMEM;
-        }
-
-        memset(hdr, 0, sizeof(*hdr));
-
-        hdr->xid = req->rq_reqhdr->xid;
-        hdr->status = req->rq_status; 
-        hdr->type = PTL_RPC_ERR;
-
-        if (req->rq_repbuf) { 
+        if (req->rq_repbuf) {
                 CERROR("req has repbuf\n");
                 LBUG();
         }
 
-        req->rq_repbuf = (char *)hdr;
-        req->rq_replen = sizeof(*hdr); 
+        rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repbuf);
+        req->rq_repmsg = (struct lustre_msg *)req->rq_repbuf;
+        if (rc)
+                RETURN(rc);
 
-        EXIT;
-        return ptlrpc_reply(obddev, svc, req);
+        req->rq_repmsg->type = HTON__u32(PTL_RPC_ERR);
+
+        rc = ptlrpc_reply(obddev, svc, req);
+        RETURN(rc);
 }
 
 int ptl_send_rpc(struct ptlrpc_request *request, struct ptlrpc_client *cl)
 {
         ptl_process_id_t local_id;
-        struct ptlreq_hdr *hdr;
         int rc;
         char *repbuf;
 
         ENTRY;
 
-        hdr = (struct ptlreq_hdr *)request->rq_reqbuf;
-        if (NTOH__u32(hdr->type) != PTL_RPC_REQUEST) {
-                CERROR("wrong packet type sent %d\n", NTOH__u32(hdr->type));
+        if (NTOH__u32(request->rq_reqmsg->type) != PTL_RPC_REQUEST) {
+                CERROR("wrong packet type sent %d\n",
+                       NTOH__u32(request->rq_reqmsg->type));
                 LBUG();
                 RETURN(-EINVAL);
         }
diff --git a/lustre/lib/pack_generic.c b/lustre/ptlrpc/pack_generic.c
similarity index 56%
rename from lustre/lib/pack_generic.c
rename to lustre/ptlrpc/pack_generic.c
index 06a430683ea91d2ed4b83813d3863215df5377fb..ad66380904bf61ead9c9e1412bbb1b8ee710e795 100644
--- a/lustre/lib/pack_generic.c
+++ b/lustre/ptlrpc/pack_generic.c
@@ -22,27 +22,7 @@
  *
  */
 
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/major.h>
-#include <linux/sched.h>
-#include <linux/lp.h>
-#include <linux/slab.h>
-#include <linux/ioport.h>
-#include <linux/fcntl.h>
-#include <linux/delay.h>
-#include <linux/skbuff.h>
-#include <linux/proc_fs.h>
-#include <linux/fs.h>
-#include <linux/poll.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <asm/io.h>
-#include <asm/segment.h>
-#include <asm/system.h>
-#include <asm/poll.h>
-#include <asm/uaccess.h>
+#define EXPORT_SYMTAB
 
 #define DEBUG_SUBSYSTEM S_CLASS
 
@@ -53,74 +33,87 @@ int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf)
 {
         char *ptr;
         struct lustre_msg *m;
-        int size = 0;
-        int i;
+        int size = 0, i;
 
-        for (i=0 ; i<count; i++) { 
+        for (i = 0; i < count; i++)
                 size += size_round(lens[i]);
-        }
-        *len = sizeof(*m) + size; 
+
+        *len = sizeof(*m) + count * sizeof(__u32) + size;
 
         OBD_ALLOC(*buf, *len);
-        if (!*buf) {
-                EXIT;
-                return -ENOMEM;
-        }
+        if (!*buf)
+                RETURN(-ENOMEM);
 
-        memset(*buf, 0, *len); 
         m = (struct lustre_msg *)(*buf);
-        m->type = PTL_RPC_REQUEST;
-
         m->bufcount = HTON__u32(count);
-        for (i=0 ; i<count; i++) { 
+        for (i = 0; i < count; i++)
                 m->buflens[i] = HTON__u32(lens[i]);
-        }
-        
+
         ptr = *buf + sizeof(*m) + sizeof(__u32) * count;
-        for (i=0 ; i<count ; i++) { 
-                LOGL(buf[i], lens[i], ptr); 
+        for (i = 0; i < count; i++) {
+                char *tmp = NULL;
+                if (bufs)
+                        tmp = bufs[i];
+                LOGL(tmp, lens[i], ptr);
         }
 
         return 0;
 }
 
+/* This returns the size of the buffer that is required to hold a lustre_msg
+ * with the given sub-buffer lengths. */
+int lustre_msg_size(int count, int *lengths)
+{
+        int size = sizeof(struct lustre_msg), i;
+
+        for (i = 0; i < count; i++)
+                size += size_round(lengths[i]);
+
+        size += count * sizeof(__u32);
+
+        return size;
+}
+
 int lustre_unpack_msg(char *buf, int len)
 {
         struct lustre_msg *m = (struct lustre_msg *)buf;
         int required_len, i;
 
         required_len = sizeof(*m);
-        if (len < required_len) { 
+        if (len < required_len)
                 RETURN(-EINVAL);
-        }
 
-        m->bufcount = NTOH__u32(m->bufcount); 
+        m->opc = NTOH__u32(m->opc);
+        m->xid = NTOH__u32(m->xid);
+        m->status = NTOH__u32(m->status);
+        m->type = NTOH__u32(m->type);
+        m->connid = NTOH__u32(m->connid);
+        m->bufcount = NTOH__u32(m->bufcount);
 
-        required_len += m->bufcount * sizeof(__u32); 
-        if (len < required_len) { 
+        required_len += m->bufcount * sizeof(__u32);
+        if (len < required_len)
                 RETURN(-EINVAL);
-        }
 
-        for (i=0; i<m->bufcount; i++) { 
+        for (i = 0; i < m->bufcount; i++) {
                 m->buflens[i] = NTOH__u32(m->buflens[i]);
                 required_len += size_round(m->buflens[i]);
         }
 
-        if (len < required_len) { 
+        if (len < required_len) {
+                CERROR("len: %d, required_len %d\n", len, required_len);
                 RETURN(-EINVAL);
         }
 
-        EXIT;
-        return 0;
+        RETURN(0);
 }
 
-void *lustre_msg_buf(int n, struct lustre_msg *m)
+void *lustre_msg_buf(struct lustre_msg *m, int n)
 {
-        int i;
-        int offset;
+        int i, offset;
 
-        if (n >= m->bufcount || n < 0) { 
-                CERROR("referencing bad sub buffer!\n"); 
+        if (n < 0 || n >= m->bufcount) {
+                CERROR("referencing bad sub buffer!\n");
+                LBUG();
                 return NULL;
         }
 
@@ -129,8 +122,8 @@ void *lustre_msg_buf(int n, struct lustre_msg *m)
 
         offset = sizeof(*m) + m->bufcount * sizeof(__u32);
 
-        for (i=0; i < n;  i++ ) 
-                offset += size_round(m->buflens[i]); 
+        for (i = 0; i < n; i++)
+                offset += size_round(m->buflens[i]);
 
         return (char *)m + offset;
 }
diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c
index d9c2b960bdf3976b77f1a624920aa8e8d7701516..e783c70c1d5d5b06b93cae3ab63298027df4a031 100644
--- a/lustre/ptlrpc/service.c
+++ b/lustre/ptlrpc/service.c
@@ -39,10 +39,10 @@ static int ptlrpc_check_event(struct ptlrpc_service *svc)
 {
         int rc = 0;
 
-        spin_lock(&svc->srv_lock); 
+        spin_lock(&svc->srv_lock);
         if (sigismember(&(current->pending.signal), SIGKILL) ||
             sigismember(&(current->pending.signal), SIGTERM) ||
-            sigismember(&(current->pending.signal), SIGINT)) { 
+            sigismember(&(current->pending.signal), SIGINT)) {
                 svc->srv_flags |= SVC_KILLED;
                 GOTO(out, rc = 1);
         }
@@ -57,7 +57,7 @@ static int ptlrpc_check_event(struct ptlrpc_service *svc)
                 int err;
                 err = PtlEQGet(svc->srv_eq_h, &svc->srv_ev);
 
-                if (err == PTL_OK) { 
+                if (err == PTL_OK) {
                         svc->srv_flags |= SVC_EVENT;
                         GOTO(out, rc = 1);
                 }
@@ -77,7 +77,7 @@ static int ptlrpc_check_event(struct ptlrpc_service *svc)
 
         EXIT;
  out:
-        spin_unlock(&svc->srv_lock); 
+        spin_unlock(&svc->srv_lock);
         return rc;
 }
 
@@ -89,18 +89,16 @@ ptlrpc_init_svc(__u32 bufsize, int req_portal, int rep_portal, char *uuid,
         int rc, i;
         struct ptlrpc_service *service;
 
-        OBD_ALLOC(service, sizeof(*service)); 
-        if ( !service ) { 
+        OBD_ALLOC(service, sizeof(*service));
+        if (!service) {
                 LBUG();
                 RETURN(NULL);
         }
 
-        memset(service, 0, sizeof(*service)); 
-
         spin_lock_init(&service->srv_lock);
         INIT_LIST_HEAD(&service->srv_reqs);
-        init_waitqueue_head(&service->srv_ctl_waitq); 
-        init_waitqueue_head(&service->srv_waitq); 
+        init_waitqueue_head(&service->srv_ctl_waitq);
+        init_waitqueue_head(&service->srv_waitq);
 
         service->srv_thread = NULL;
         service->srv_flags = 0;
@@ -111,16 +109,16 @@ ptlrpc_init_svc(__u32 bufsize, int req_portal, int rep_portal, char *uuid,
         service->srv_handler = handler;
 
         err = kportal_uuid_to_peer(uuid, &service->srv_self);
-        if (err) { 
-                CERROR("cannot get peer for uuid %s", uuid); 
-                GOTO(err_free, NULL); 
+        if (err) {
+                CERROR("cannot get peer for uuid %s", uuid);
+                GOTO(err_free, NULL);
         }
 
         service->srv_ring_length = RPC_RING_LENGTH;
         service->srv_id.nid = PTL_ID_ANY;
         service->srv_id.pid = PTL_ID_ANY;
 
-        rc = PtlEQAlloc(service->srv_self.peer_ni, 128, 
+        rc = PtlEQAlloc(service->srv_self.peer_ni, 128,
                         server_request_callback,
                         service, &(service->srv_eq_h));
 
@@ -137,8 +135,8 @@ ptlrpc_init_svc(__u32 bufsize, int req_portal, int rep_portal, char *uuid,
                         LBUG();
                         GOTO(err_ring, NULL);
                 }
-                service->srv_ref_count[i] = 0; 
-                ptlrpc_link_svc_me(service, i); 
+                service->srv_ref_count[i] = 0;
+                ptlrpc_link_svc_me(service, i);
         }
 
         CDEBUG(D_NET, "Starting service listening on portal %d\n",
@@ -175,14 +173,14 @@ static int ptlrpc_main(void *arg)
         /* Record that the  thread is running */
         svc->srv_thread = current;
         svc->srv_flags = SVC_RUNNING;
-        wake_up(&svc->srv_ctl_waitq); 
+        wake_up(&svc->srv_ctl_waitq);
 
         /* XXX maintain a list of all managed devices: insert here */
 
         /* And now, loop forever on requests */
         while (1) {
                 wait_event(svc->srv_waitq, ptlrpc_check_event(svc));
-                
+
                 spin_lock(&svc->srv_lock);
                 if (svc->srv_flags & SVC_SIGNAL) {
                         spin_unlock(&svc->srv_lock);
@@ -196,10 +194,10 @@ static int ptlrpc_main(void *arg)
                         break;
                 }
 
-                if (svc->srv_flags & SVC_EVENT) { 
+                if (svc->srv_flags & SVC_EVENT) {
                         struct ptlrpc_request request;
                         void *start;
-                        svc->srv_flags = SVC_RUNNING; 
+                        svc->srv_flags = SVC_RUNNING;
 
                         /* FIXME: If we move to an event-driven model,
                          * we should put the request on the stack of
@@ -225,9 +223,9 @@ static int ptlrpc_main(void *arg)
                         continue;
                 }
 
-                if (svc->srv_flags & SVC_LIST) { 
+                if (svc->srv_flags & SVC_LIST) {
                         struct ptlrpc_request *request;
-                        svc->srv_flags = SVC_RUNNING; 
+                        svc->srv_flags = SVC_RUNNING;
 
                         request = list_entry(svc->srv_reqs.next,
                                              struct ptlrpc_request,
@@ -237,10 +235,10 @@ static int ptlrpc_main(void *arg)
                         rc = svc->srv_handler(obddev, svc, request);
                         continue;
                 }
-                CERROR("unknown break in service"); 
+                CERROR("unknown break in service");
                 spin_unlock(&svc->srv_lock);
                 EXIT;
-                break; 
+                break;
         }
 
         svc->srv_thread = NULL;
@@ -255,7 +253,7 @@ void ptlrpc_stop_thread(struct ptlrpc_service *svc)
         svc->srv_flags = SVC_STOPPING;
 
         wake_up(&svc->srv_waitq);
-        wait_event_interruptible(svc->srv_ctl_waitq, 
+        wait_event_interruptible(svc->srv_ctl_waitq,
                                  (svc->srv_flags & SVC_STOPPED));
 }
 
@@ -273,10 +271,10 @@ int ptlrpc_start_thread(struct obd_device *dev, struct ptlrpc_service *svc,
         init_waitqueue_head(&svc->srv_waitq);
 
         init_waitqueue_head(&svc->srv_ctl_waitq);
-        rc = kernel_thread(ptlrpc_main, (void *) &d, 
+        rc = kernel_thread(ptlrpc_main, (void *) &d,
                            CLONE_VM | CLONE_FS | CLONE_FILES);
         if (rc < 0) {
-                CERROR("cannot start thread\n"); 
+                CERROR("cannot start thread\n");
                 RETURN(-EINVAL);
         }
         wait_event(svc->srv_ctl_waitq, svc->srv_flags & SVC_RUNNING);
diff --git a/lustre/tests/llmount.sh b/lustre/tests/llmount.sh
index 07798884172e85245587c924641810165b025c2d..493d7cd0392baa58628d51195cabaf73ce6e15b5 100755
--- a/lustre/tests/llmount.sh
+++ b/lustre/tests/llmount.sh
@@ -11,7 +11,7 @@ PORT=1234
 setup
 setup_portals
 
-new_fs ext2 /tmp/ost 25000
+new_fs ext2 /tmp/ost 10000
 OST=$LOOPDEV
 MDSFS=ext2
 new_fs ${MDSFS} /tmp/mds 10000
diff --git a/lustre/tests/llmountcleanup.sh b/lustre/tests/llmountcleanup.sh
index 4bbeb8a86d37a03e80f55788e872762e87782a51..9f422d6ff1336b251952d09de04239bec461b475 100755
--- a/lustre/tests/llmountcleanup.sh
+++ b/lustre/tests/llmountcleanup.sh
@@ -5,6 +5,7 @@ SRCDIR="`dirname $0`"
 
 umount /mnt/obd
 
+killall acceptor
 rmmod llight
 rmmod mdc
 
@@ -45,7 +46,6 @@ EOF
 
 rmmod kqswnal
 rmmod ksocknal
-killall acceptor
 rmmod portals
 
 losetup -d ${LOOP}0