Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index 0279dcf..ab389d0 100644 (file)
@@ -78,8 +78,8 @@ int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
         case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return lustre_msg_check_version_v2(msg, version);
         default:
-                LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
-                return -EINVAL;
+                CERROR("incorrect message magic: %08x\n", msg->lm_magic);
+                return 0;
         }
 }
 
@@ -96,7 +96,7 @@ static inline int lustre_msg_size_v1(int count, int *lengths)
         return size;
 }
 
-static inline int lustre_msg_size_v2(int count, int *lengths)
+int lustre_msg_size_v2(int count, int *lengths)
 {
         int size;
         int i;
@@ -107,6 +107,7 @@ static inline int lustre_msg_size_v2(int count, int *lengths)
 
         return size;
 }
+EXPORT_SYMBOL(lustre_msg_size_v2);
 
 /* This returns the size of the buffer that is required to hold a lustre_msg
  * with the given sub-buffer lengths. */
@@ -128,13 +129,13 @@ int lustre_msg_size(__u32 magic, int count, int *lens)
         case LUSTRE_MSG_MAGIC_V2:
                 return lustre_msg_size_v2(count, lens);
         default:
-                CERROR("incorrect message magic: %08x\n", magic);
-                return 0;
+                LASSERTF(0, "incorrect message magic: %08x\n", magic);
+                return -EINVAL;
         }
 }
 
-static void
-lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
+static
+void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
 {
         struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
         char *ptr;
@@ -158,8 +159,8 @@ lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
         }
 }
 
-static void
-lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens, char **bufs)
+void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
+                        char **bufs)
 {
         char *ptr;
         int i;
@@ -180,32 +181,18 @@ lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens, char **bufs)
                 LOGL(tmp, lens[i], ptr);
         }
 }
+EXPORT_SYMBOL(lustre_init_msg_v2);
 
 static int lustre_pack_request_v1(struct ptlrpc_request *req,
                                   int count, int *lens, char **bufs)
 {
-        int reqlen;
+        int reqlen, rc;
 
         reqlen = lustre_msg_size_v1(count, lens);
 
-        /* See if we got it from prealloc pool */
-        if (req->rq_reqmsg) {
-                /* Cannot return error here, that would create
-                   infinite loop in ptlrpc_prep_req_pool */
-                /* In this case ptlrpc_prep_req_from_pool sets req->rq_reqlen
-                   to maximum size that would fit into this preallocated
-                   request */
-                LASSERTF(req->rq_reqlen >= reqlen, "req->rq_reqlen %d, "
-                                                   "reqlen %d\n",req->rq_reqlen,
-                                                    reqlen);
-                memset(req->rq_reqmsg, 0, reqlen);
-        } else {
-                OBD_ALLOC(req->rq_reqmsg, reqlen);
-                if (req->rq_reqmsg == NULL) {
-                        CERROR("alloc reqmsg (len %d) failed\n", reqlen);
-                        return -ENOMEM;
-                }
-        }
+        rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
+        if (rc)
+                return rc;
 
         req->rq_reqlen = reqlen;
 
@@ -216,28 +203,13 @@ static int lustre_pack_request_v1(struct ptlrpc_request *req,
 static int lustre_pack_request_v2(struct ptlrpc_request *req,
                                   int count, int *lens, char **bufs)
 {
-        int reqlen;
+        int reqlen, rc;
 
         reqlen = lustre_msg_size_v2(count, lens);
 
-        /* See if we got it from prealloc pool */
-        if (req->rq_reqmsg) {
-                /* Cannot return error here, that would create
-                   infinite loop in ptlrpc_prep_req_pool */
-                /* In this case ptlrpc_prep_req_from_pool sets req->rq_reqlen
-                   to maximum size that would fit into this preallocated
-                   request */
-                LASSERTF(req->rq_reqlen >= reqlen, "req->rq_reqlen %d, "
-                                                   "reqlen %d\n",req->rq_reqlen,
-                                                    reqlen);
-                memset(req->rq_reqmsg, 0, reqlen);
-        } else {
-                OBD_ALLOC(req->rq_reqmsg, reqlen);
-                if (req->rq_reqmsg == NULL) {
-                        CERROR("alloc reqmsg (len %d) failed\n", reqlen);
-                        return -ENOMEM;
-                }
-        }
+        rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
+        if (rc)
+                return rc;
 
         req->rq_reqlen = reqlen;
 
@@ -260,6 +232,13 @@ int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
         LASSERT(count > 0);
         LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
 
+        /* if we choose policy other than null, we have also choosed
+         * to use new message format.
+         */
+        if (magic == LUSTRE_MSG_MAGIC_V1 &&
+            req->rq_sec_flavor != SPTLRPC_FLVR_NULL)
+                magic = LUSTRE_MSG_MAGIC_V2;
+
         switch (magic) {
         case LUSTRE_MSG_MAGIC_V1:
                 return lustre_pack_request_v1(req, count - 1, lens + 1,
@@ -294,8 +273,7 @@ do {                                            \
 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
 #endif
 
-static struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc,
-                                                      int size)
+struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
 {
         struct ptlrpc_reply_state *rs = NULL;
 
@@ -314,46 +292,52 @@ static struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc
                         goto out;
                 spin_lock(&svc->srv_lock);
         }
-        
+
         rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
                         rs_list);
         list_del(&rs->rs_list);
         spin_unlock(&svc->srv_lock);
         LASSERT(rs);
-        LASSERTF(svc->srv_max_reply_size > size, "Want %d, prealloc %d\n", size,
-                 svc->srv_max_reply_size);
-        memset(rs, 0, size);
+        memset(rs, 0, svc->srv_max_reply_size);
+        rs->rs_service = svc;
         rs->rs_prealloc = 1;
 out:
         return rs;
 }
 
+void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
+{
+        struct ptlrpc_service *svc = rs->rs_service;
+
+        LASSERT(svc);
+
+        spin_lock(&svc->srv_lock);
+        list_add(&rs->rs_list, &svc->srv_free_rs_list);
+        spin_unlock(&svc->srv_lock);
+        cfs_waitq_signal(&svc->srv_free_rs_waitq);
+}
+
 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
                                 int *lens, char **bufs)
 {
         struct ptlrpc_reply_state *rs;
-        int                        msg_len;
-        int                        size;
+        int                        msg_len, rc;
         ENTRY;
 
         LASSERT (req->rq_reply_state == NULL);
 
         msg_len = lustre_msg_size_v1(count, lens);
-        size = sizeof(struct ptlrpc_reply_state) + msg_len;
-        OBD_ALLOC(rs, size);
-        if (unlikely(rs == NULL)) {
-                rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size);
-                if (!rs)
-                        RETURN (-ENOMEM);
-        }
+        rc = sptlrpc_svc_alloc_rs(req, msg_len);
+        if (rc)
+                RETURN(rc);
+
+        rs = req->rq_reply_state;
         atomic_set(&rs->rs_refcount, 1);        /* 1 ref for rq_reply_state */
         rs->rs_cb_id.cbid_fn = reply_out_callback;
         rs->rs_cb_id.cbid_arg = rs;
         rs->rs_service = req->rq_rqbd->rqbd_service;
-        rs->rs_size = size;
         CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
         CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
-        rs->rs_msg = (struct lustre_msg *)(rs + 1);
 
         req->rq_replen = msg_len;
         req->rq_reply_state = rs;
@@ -365,32 +349,27 @@ static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
         RETURN (0);
 }
 
-static int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
-                                int *lens, char **bufs)
+int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
+                         int *lens, char **bufs)
 {
         struct ptlrpc_reply_state *rs;
-        int                        msg_len;
-        int                        size;
+        int                        msg_len, rc;
         ENTRY;
 
         LASSERT(req->rq_reply_state == NULL);
 
         msg_len = lustre_msg_size_v2(count, lens);
-        size = sizeof(struct ptlrpc_reply_state) + msg_len;
-        OBD_ALLOC(rs, size);
-        if (unlikely(rs == NULL)) {
-                rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size);
-                if (!rs)
-                        RETURN (-ENOMEM);
-        }
+        rc = sptlrpc_svc_alloc_rs(req, msg_len);
+        if (rc)
+                RETURN(rc);
+
+        rs = req->rq_reply_state;
         atomic_set(&rs->rs_refcount, 1);        /* 1 ref for rq_reply_state */
         rs->rs_cb_id.cbid_fn = reply_out_callback;
         rs->rs_cb_id.cbid_arg = rs;
         rs->rs_service = req->rq_rqbd->rqbd_service;
-        rs->rs_size = size;
         CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
         CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
-        rs->rs_msg = (struct lustre_msg *)(rs + 1);
 
         req->rq_replen = msg_len;
         req->rq_reply_state = rs;
@@ -403,6 +382,7 @@ static int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
 
         RETURN(0);
 }
+EXPORT_SYMBOL(lustre_pack_reply_v2);
 
 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
                       char **bufs)
@@ -441,14 +421,14 @@ void *lustre_msg_buf_v1(void *msg, int n, int min_size)
         LASSERT(n >= 0);
 
         bufcount = m->lm_bufcount;
-        if (n >= bufcount) {
+        if (unlikely(n >= bufcount)) {
                 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
                        m, n, bufcount);
                 return NULL;
         }
 
         buflen = m->lm_buflens[n];
-        if (buflen < min_size) {
+        if (unlikely(buflen < min_size)) {
                 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
                        m, n, buflen, min_size);
                 LBUG();
@@ -470,14 +450,14 @@ void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
         LASSERT(n >= 0);
 
         bufcount = m->lm_bufcount;
-        if (n >= bufcount) {
+        if (unlikely(n >= bufcount)) {
                 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
                        m, n, bufcount);
                 return NULL;
         }
 
         buflen = m->lm_buflens[n];
-        if (buflen < min_size) {
+        if (unlikely(buflen < min_size)) {
                 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
                        m, n, buflen, min_size);
                 return NULL;
@@ -500,26 +480,24 @@ void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
         case LUSTRE_MSG_MAGIC_V2_SWABBED:
                 return lustre_msg_buf_v2(m, n, min_size);
         default:
-                LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
+                LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
                 return NULL;
         }
 }
 
-void lustre_shrink_reply_v1(struct ptlrpc_request *req, int segment,
-                            unsigned int newlen, int move_data)
+int lustre_shrink_msg_v1(struct lustre_msg_v1 *msg, int segment,
+                         unsigned int newlen, int move_data)
 {
-        struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)req->rq_repmsg;
-        char *tail = NULL, *newpos;
-        int tail_len = 0, n;
+        char   *tail = NULL, *newpos;
+        int     tail_len = 0, n;
 
-        LASSERT(req->rq_reply_state);
         LASSERT(msg);
         LASSERT(segment >= 0);
         LASSERT(msg->lm_bufcount > segment);
         LASSERT(msg->lm_buflens[segment] >= newlen);
 
         if (msg->lm_buflens[segment] == newlen)
-                return;
+                goto out;
 
         if (move_data && msg->lm_bufcount > segment + 1) {
                 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
@@ -542,23 +520,22 @@ void lustre_shrink_reply_v1(struct ptlrpc_request *req, int segment,
                 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
         }
 
-        req->rq_replen = lustre_msg_size_v1(msg->lm_bufcount, msg->lm_buflens);
+out:
+        return lustre_msg_size_v1(msg->lm_bufcount, msg->lm_buflens);
 }
 
-void lustre_shrink_reply_v2(struct ptlrpc_request *req, int segment,
-                            unsigned int newlen, int move_data)
+int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
+                         unsigned int newlen, int move_data)
 {
-        struct lustre_msg_v2 *msg = req->rq_repmsg;
-        char *tail = NULL, *newpos;
-        int tail_len = 0, n;
+        char   *tail = NULL, *newpos;
+        int     tail_len = 0, n;
 
-        LASSERT(req->rq_reply_state);
         LASSERT(msg);
         LASSERT(msg->lm_bufcount > segment);
         LASSERT(msg->lm_buflens[segment] >= newlen);
 
         if (msg->lm_buflens[segment] == newlen)
-                return;
+                goto out;
 
         if (move_data && msg->lm_bufcount > segment + 1) {
                 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
@@ -581,36 +558,37 @@ void lustre_shrink_reply_v2(struct ptlrpc_request *req, int segment,
                 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
         }
 
-        req->rq_replen = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
+out:
+        return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
 }
 
 /*
- * shrink @segment to size @newlen. if @move_data is non-zero, we also move
- * data forward from @segment + 1.
- * 
+ * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
+ * we also move data forward from @segment + 1.
+ *
  * if @newlen == 0, we remove the segment completely, but we still keep the
  * totally bufcount the same to save possible data moving. this will leave a
  * unused segment with size 0 at the tail, but that's ok.
  *
+ * return new msg size after shrinking.
+ *
  * CAUTION:
  * + if any buffers higher than @segment has been filled in, must call shrink
  *   with non-zero @move_data.
  * + caller should NOT keep pointers to msg buffers which higher than @segment
  *   after call shrink.
  */
-void lustre_shrink_reply(struct ptlrpc_request *req, int segment,
-                        unsigned int newlen, int move_data)
+int lustre_shrink_msg(struct lustre_msg *msg, int segment,
+                      unsigned int newlen, int move_data)
 {
-        switch (req->rq_repmsg->lm_magic) {
+        switch (msg->lm_magic) {
         case LUSTRE_MSG_MAGIC_V1:
-                lustre_shrink_reply_v1(req, segment - 1, newlen, move_data);
-                return;
+                return lustre_shrink_msg_v1((struct lustre_msg_v1 *) msg,
+                                            segment - 1, newlen, move_data);
         case LUSTRE_MSG_MAGIC_V2:
-                lustre_shrink_reply_v2(req, segment, newlen, move_data);
-                return;
+                return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
         default:
-                LASSERTF(0, "incorrect message magic: %08x\n",
-                         req->rq_repmsg->lm_magic);
+                LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
         }
 }
 
@@ -627,17 +605,7 @@ void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
         LASSERT (list_empty(&rs->rs_exp_list));
         LASSERT (list_empty(&rs->rs_obd_list));
 
-        if (unlikely(rs->rs_prealloc)) {
-                struct ptlrpc_service *svc = rs->rs_service;
-
-                spin_lock(&svc->srv_lock);
-                list_add(&rs->rs_list,
-                         &svc->srv_free_rs_list);
-                spin_unlock(&svc->srv_lock);
-                cfs_waitq_signal(&svc->srv_free_rs_waitq);
-        } else {
-                OBD_FREE(rs, rs->rs_size);
-        }
+        sptlrpc_svc_free_rs(rs);
 }
 
 int lustre_unpack_msg_v1(void *msg, int len)
@@ -708,7 +676,7 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
         if (len < required_len) {
                 /* can't even look inside the message */
                 CERROR("message length %d too small for lustre_msg\n", len);
-                RETURN(-EINVAL);
+                return -EINVAL;
         }
 
         flipped = lustre_msg_swabbed(m);
@@ -730,7 +698,7 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
                         len, m->lm_bufcount);
                 return -EINVAL;
         }
-
+        
         for (i = 0; i < m->lm_bufcount; i++) {
                 if (flipped)
                         __swab32s(&m->lm_buflens[i]);
@@ -1285,7 +1253,7 @@ __u32 lustre_msg_get_opc(struct lustre_msg *msg)
                 return pb->pb_opc;
         }
         default:
-                CERROR( "incorrect message magic: %08x\n", msg->lm_magic);
+                CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
                 return 0;
         }
 }
@@ -1600,15 +1568,16 @@ void lustre_swab_connect(struct obd_connect_data *ocd)
         __swab64s(&ocd->ocd_connect_flags);
         __swab32s(&ocd->ocd_version);
         __swab32s(&ocd->ocd_grant);
+        __swab64s(&ocd->ocd_ibits_known);
         __swab32s(&ocd->ocd_index);
         __swab32s(&ocd->ocd_brw_size);
-        __swab64s(&ocd->ocd_ibits_known);
         __swab32s(&ocd->ocd_nllu);
         __swab32s(&ocd->ocd_nllg);
+        __swab64s(&ocd->ocd_transno);
+        __swab32s(&ocd->ocd_group);
         CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
         CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
         CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
-        CLASSERT(offsetof(typeof(*ocd), padding4) != 0);
 }
 
 void lustre_swab_obdo (struct obdo  *o)
@@ -1679,6 +1648,11 @@ void lustre_swab_ost_last_id(obd_id *id)
         __swab64s(id);
 }
 
+void lustre_swab_generic_32s(__u32 *val)
+{
+        __swab32s(val);
+}
+
 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
 {
         __swab64s(&lvb->lvb_size);
@@ -1725,6 +1699,42 @@ void lustre_swab_mds_body (struct mds_body *b)
         __swab32s (&b->padding_4);
 }
 
+void lustre_swab_mdt_body (struct mdt_body *b)
+{
+        lustre_swab_lu_fid (&b->fid1);
+        lustre_swab_lu_fid (&b->fid2);
+        /* handle is opaque */
+        __swab64s (&b->valid);
+        __swab64s (&b->size);
+        __swab64s (&b->mtime);
+        __swab64s (&b->atime);
+        __swab64s (&b->ctime);
+        __swab64s (&b->blocks);
+        __swab64s (&b->ioepoch);
+        __swab32s (&b->fsuid);
+        __swab32s (&b->fsgid);
+        __swab32s (&b->capability);
+        __swab32s (&b->mode);
+        __swab32s (&b->uid);
+        __swab32s (&b->gid);
+        __swab32s (&b->flags);
+        __swab32s (&b->rdev);
+        __swab32s (&b->nlink);
+        __swab32s (&b->suppgid);
+        __swab32s (&b->eadatasize);
+        __swab32s (&b->aclsize);
+        __swab32s (&b->max_mdsize);
+        __swab32s (&b->max_cookiesize);
+}
+
+void lustre_swab_mdt_epoch (struct mdt_epoch *b)
+{
+        /* handle is opaque */
+         __swab64s (&b->ioepoch);
+         __swab32s (&b->flags);
+         CLASSERT(offsetof(typeof(*b), padding) != 0);
+}
+
 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
 {
         int i;
@@ -1734,7 +1744,7 @@ void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
         __swab32s(&mti->mti_flags);
         __swab32s(&mti->mti_nid_count);
         CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
-        for (i = 0; i < MTI_NIDS_MAX; i++) 
+        for (i = 0; i < MTI_NIDS_MAX; i++)
                 __swab64s(&mti->mti_nids[i]);
 }
 
@@ -1770,6 +1780,24 @@ void lustre_swab_obd_quotactl (struct obd_quotactl *q)
         lustre_swab_obd_dqblk (&q->qc_dqblk);
 }
 
+void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
+{
+        __swab32s (&p->rp_uid);
+        __swab32s (&p->rp_gid);
+        __swab32s (&p->rp_fsuid);
+        __swab32s (&p->rp_fsgid);
+        __swab32s (&p->rp_access_perm);
+};
+
+void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
+{
+        __swab32s (&p->rp_uid);
+        __swab32s (&p->rp_gid);
+        __swab32s (&p->rp_fsuid);
+        __swab32s (&p->rp_fsgid);
+        __swab32s (&p->rp_access_perm);
+};
+
 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
 {
         __swab32s (&sa->sa_opcode);
@@ -1790,12 +1818,39 @@ void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
         CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
 }
 
+void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa)
+{
+        __swab32s (&sa->sa_opcode);
+        __swab32s (&sa->sa_fsuid);
+        __swab32s (&sa->sa_fsgid);
+        __swab32s (&sa->sa_cap);
+        __swab32s (&sa->sa_suppgid);
+        __swab32s (&sa->sa_mode);
+        lustre_swab_lu_fid (&sa->sa_fid);
+        __swab64s (&sa->sa_valid);
+        __swab64s (&sa->sa_size);
+        __swab64s (&sa->sa_blocks);
+        __swab64s (&sa->sa_mtime);
+        __swab64s (&sa->sa_atime);
+        __swab64s (&sa->sa_ctime);
+        __swab32s (&sa->sa_uid);
+        __swab32s (&sa->sa_gid);
+        __swab32s (&sa->sa_attr_flags);
+        CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
+}
+
 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
 {
         __swab64s(&jr->jr_headsize);
         lustre_swab_ll_fid(&jr->jr_fid);
 }
 
+void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
+{
+        __swab64s(&jr->jr_headsize);
+        lustre_swab_lu_fid(&jr->jr_fid);
+}
+
 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
 {
         __swab32s (&cr->cr_opcode);
@@ -1816,6 +1871,26 @@ void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
         CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
 }
 
+void lustre_swab_mdt_rec_create (struct mdt_rec_create *cr)
+{
+        __swab32s (&cr->cr_opcode);
+        __swab32s (&cr->cr_fsuid);
+        __swab32s (&cr->cr_fsgid);
+        __swab32s (&cr->cr_cap);
+        __swab32s (&cr->cr_flags); /* for use with open */
+        __swab32s (&cr->cr_mode);
+        /* handle is opaque */
+        lustre_swab_lu_fid (&cr->cr_fid1);
+        lustre_swab_lu_fid (&cr->cr_fid2);
+        __swab64s (&cr->cr_time);
+        __swab64s (&cr->cr_rdev);
+        __swab64s (&cr->cr_ioepoch);
+        __swab32s (&cr->cr_suppgid1);
+        __swab32s (&cr->cr_suppgid2);
+        __swab32s (&cr->cr_bias);
+        CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
+}
+
 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
 {
         __swab32s (&lk->lk_opcode);
@@ -1833,6 +1908,23 @@ void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
         CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
 }
 
+void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
+{
+        __swab32s (&lk->lk_opcode);
+        __swab32s (&lk->lk_fsuid);
+        __swab32s (&lk->lk_fsgid);
+        __swab32s (&lk->lk_cap);
+        __swab32s (&lk->lk_suppgid1);
+        __swab32s (&lk->lk_suppgid2);
+        lustre_swab_lu_fid (&lk->lk_fid1);
+        lustre_swab_lu_fid (&lk->lk_fid2);
+        __swab64s (&lk->lk_time);
+        __swab32s (&lk->lk_bias);
+        CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
+        CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
+        CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
+}
+
 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
 {
         __swab32s (&ul->ul_opcode);
@@ -1850,6 +1942,23 @@ void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
         CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
 }
 
+void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
+{
+        __swab32s (&ul->ul_opcode);
+        __swab32s (&ul->ul_fsuid);
+        __swab32s (&ul->ul_fsgid);
+        __swab32s (&ul->ul_cap);
+        __swab32s (&ul->ul_suppgid);
+        __swab32s (&ul->ul_mode);
+        lustre_swab_lu_fid (&ul->ul_fid1);
+        lustre_swab_lu_fid (&ul->ul_fid2);
+        __swab64s (&ul->ul_time);
+        __swab32s (&ul->ul_bias);
+        CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
+        CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
+        CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
+}
+
 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
 {
         __swab32s (&rn->rn_opcode);
@@ -1867,6 +1976,23 @@ void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
         CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
 }
 
+void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
+{
+        __swab32s (&rn->rn_opcode);
+        __swab32s (&rn->rn_fsuid);
+        __swab32s (&rn->rn_fsgid);
+        __swab32s (&rn->rn_cap);
+        __swab32s (&rn->rn_suppgid1);
+        __swab32s (&rn->rn_suppgid2);
+        lustre_swab_lu_fid (&rn->rn_fid1);
+        lustre_swab_lu_fid (&rn->rn_fid2);
+        __swab64s (&rn->rn_time);
+        __swab32s (&rn->rn_mode);
+        __swab32s (&rn->rn_bias);
+        CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
+        CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
+}
+
 void lustre_swab_lov_desc (struct lov_desc *ld)
 {
         __swab32s (&ld->ld_tgt_count);
@@ -1879,6 +2005,20 @@ void lustre_swab_lov_desc (struct lov_desc *ld)
         /* uuid endian insensitive */
 }
 
+/*begin adding MDT by huanghua@clusterfs.com*/
+void lustre_swab_lmv_desc (struct lmv_desc *ld)
+{
+        __swab32s (&ld->ld_tgt_count);
+        __swab32s (&ld->ld_active_tgt_count);
+        /* uuid endian insensitive */
+}
+/*end adding MDT by huanghua@clusterfs.com*/
+void lustre_swab_md_fld (struct md_fld *mf)
+{
+        __swab64s(&mf->mf_seq);
+        __swab64s(&mf->mf_mds);
+}
+
 static void print_lum (struct lov_user_md *lum)
 {
         CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
@@ -1967,6 +2107,30 @@ void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
         EXIT;
 }
 
+
+void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
+{
+        struct lov_ost_data *lod;
+        int i;
+        ENTRY;
+        for (i = 0; i < lmm->lmm_stripe_count; i++) {
+                lod = &lmm->lmm_objects[i];
+                __swab64s(&lod->l_object_id);
+                __swab64s(&lod->l_object_gr);
+                __swab32s(&lod->l_ost_gen);
+                __swab32s(&lod->l_ost_idx);
+        }
+        __swab32s(&lmm->lmm_magic);
+        __swab32s(&lmm->lmm_pattern);
+        __swab64s(&lmm->lmm_object_id);
+        __swab64s(&lmm->lmm_object_gr);
+        __swab32s(&lmm->lmm_stripe_size);
+        __swab32s(&lmm->lmm_stripe_count);
+
+        EXIT;
+}
+
+
 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
 {
         int  i;
@@ -2128,33 +2292,52 @@ static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
 
 void _debug_req(struct ptlrpc_request *req, __u32 mask,
                 struct libcfs_debug_msg_data *data, const char *fmt, ... )
-
 {
         va_list args;
 
         va_start(args, fmt);
         libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
                            data->msg_fn, data->msg_line, fmt, args,
-                           " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl "
-                           REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
+                           " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
+                           " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
                            req, req->rq_xid, req->rq_transno,
+                           req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
                            req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
                            req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
                            req->rq_export ?
-                                (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
+                           (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
                            req->rq_import ?
-                                (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
+                           (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
                            req->rq_export ?
-                                (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
+                           (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
                            (req->rq_import && req->rq_import->imp_client) ?
-                                req->rq_import->imp_client->cli_request_portal : -1,
+                           req->rq_import->imp_client->cli_request_portal : -1,
                            req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
                            DEBUG_REQ_FLAGS(req),
-                           req->rq_reqmsg ? lustre_msg_get_flags(req->rq_reqmsg) : 0,
-                           req->rq_repmsg ? lustre_msg_get_flags(req->rq_repmsg) : 0,
+                           req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
+                           lustre_msg_get_flags(req->rq_reqmsg) : -1,
+                           req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
+                           lustre_msg_get_flags(req->rq_repmsg) : -1,
                            req->rq_status,
-                           req->rq_repmsg ? lustre_msg_get_status(req->rq_repmsg) : 0);
-        va_end(args);
+                           req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
+                           lustre_msg_get_status(req->rq_repmsg) : -1);
 }
-
 EXPORT_SYMBOL(_debug_req);
+
+void lustre_swab_lustre_capa(struct lustre_capa *c)
+{
+        lustre_swab_lu_fid(&c->lc_fid);
+        __swab64s (&c->lc_opc);
+        __swab32s (&c->lc_uid);
+        __swab32s (&c->lc_flags);
+        __swab32s (&c->lc_keyid);
+        __swab32s (&c->lc_timeout);
+        __swab64s (&c->lc_expiry);
+}
+
+void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
+{
+        __swab64s (&k->lk_mdsid);
+        __swab32s (&k->lk_keyid);
+        __swab32s (&k->lk_padding);
+}